Skip to content

Conversation

@Rohit-BM18
Copy link
Collaborator

@Rohit-BM18 Rohit-BM18 commented May 5, 2025

Added helper functions to find preceding snapshots.

Part of the planned enhancements for the diff command.

Added the helper methods to fetch preceding snapshots. These helpers will be consumed to enhance the CLI for the existing diff command implementation.

  • Method to fetch the immediately preceding snapshot manifest given a snapshot ID
  • Method to fetch the two latest snapshot manifests for a given source

Also added relevant unit tests for the above methods:

  • In order to test GetPrecedingSnapshot, first the method is invoked with a wrong snapshotID and an error is expected. Next a snapshot is saved and the method is invoked again, since there is only a single snapshot in the repo, an error is expected. Subsequently more snapshots are saved and the method is invoked and the immediately preceding snapshot based on timestamp is expected
  • In order to test GetTwoLatestSnapshotsForASource, a similar strategy is used. The method is invoked with insufficient snapshots stored in the repo and errors are expected. Eventually more snapshots are saved and when the method is invoked the two most recent manifests for snapshot based on start time are expected

@Rohit-BM18 Rohit-BM18 requested a review from julio-lopez May 5, 2025 23:51
@codecov
Copy link

codecov bot commented May 6, 2025

Codecov Report

Attention: Patch coverage is 80.55556% with 7 lines in your changes missing coverage. Please review.

Project coverage is 76.39%. Comparing base (cb455c6) to head (39c0a14).
Report is 511 commits behind head on master.

Files with missing lines Patch % Lines
internal/diff/diff.go 79.41% 5 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4559      +/-   ##
==========================================
+ Coverage   75.86%   76.39%   +0.53%     
==========================================
  Files         470      527      +57     
  Lines       37301    40091    +2790     
==========================================
+ Hits        28299    30629    +2330     
- Misses       7071     7447     +376     
- Partials     1931     2015      +84     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@julio-lopez julio-lopez changed the title feat(cli): Added kopia diff helper functions to get preceding snapshots feat(cli): helper functions to get preceding snapshots for diff May 12, 2025
@julio-lopez julio-lopez requested a review from Copilot May 13, 2025 01:09
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces helper functions to fetch preceding snapshots for the diff command, enhancing the CLI functionality of kopia diff.

  • Added helper functions (GetPreceedingSnapshot and GetTwoLatestSnapshotsForASource) in diff.go to retrieve snapshots based on timestamps.
  • Updated usage in snapshotfs/objref.go to export the FindSnapshotByRootObjectIDOrManifestID function and ensure consistency.
  • Added comprehensive unit tests in diff_test.go to validate error conditions and proper snapshot ordering.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
snapshot/snapshotfs/objref.go Updated exported function name and comment capitalization for clarity.
internal/diff/diff.go Introduced two new helper functions for fetching snapshots and sorting them.
internal/diff/diff_test.go Added unit tests covering error handling and snapshot order retrieval.
Comments suppressed due to low confidence (1)

internal/diff/diff.go:413

  • The function name 'GetPreceedingSnapshot' appears to be misspelled; consider renaming it to 'GetPrecedingSnapshot' to match the PR title and standard spelling.
func GetPreceedingSnapshot(ctx context.Context, rep repo.Repository, snapshotID string) (*snapshot.Manifest, error) {

@julio-lopez julio-lopez enabled auto-merge (squash) May 13, 2025 03:53
// - Add a snapshot, expect an error from GetPreceedingSnapshot since there is
// only a single snapshot in the repo;
// - Subsequently add more snapshots and GetPreceedingSnapshot theimmediately
// preceding with no error.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rohit-BM18 Added comments to this test and the one below. PTAL.

latestSnapshotManifestID := mustSaveSnapshot(t, env.RepositoryWriter, manifests["latest_snapshot"])
gotManID2, err := diff.GetPrecedingSnapshot(ctx, env.RepositoryWriter, string(latestSnapshotManifestID))
require.NoError(t, err)
require.Equal(t, intermediateSnapshotManifestID, gotManID2.ID)
Copy link
Collaborator

@julio-lopez julio-lopez May 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rohit-BM18

What is the expected behavior when a single snapshot is added for a different snapshot source ({host,user,path} tuple)? when:

  • getting the 2 most recent snapshots for the source that has a single snapshot
  • getting the 2 most recent snapshots for the source that has more than one snapshot

Can you create another PR with these test cases please?

Thanks.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When either of the methods are invoked on a source with insufficient snapshots, it should result in an error.
PR incoming with these tests.

@julio-lopez julio-lopez merged commit dbf5bac into kopia:master May 13, 2025
27 checks passed
@julio-lopez julio-lopez deleted the kopia-diff-helpers-to-get-preceding-snapshots branch May 13, 2025 04:14
@kopia kopia deleted a comment from Rohit-BM18 May 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants