Add SHA-1 sync compare mode#92
Open
goanpeca wants to merge 40 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new sha1 compare mode to the sync engine so it can detect same-size/same-mtime content drift by comparing (normalized) SHA-1 values, hashing local files when needed. This extends the existing sync policy surface (CompareMode) and updates scanners, tests, and example documentation accordingly.
Changes:
- Extend
CompareModewith'sha1'and propagate SHA-1 metadata throughSyncPath/B2 scanning. - Implement SHA-1-based comparison in
filesAreDifferent, and hash local files during paired comparisons insynchronize. - Add regression tests for SHA-1 mode and update sync example docs/env var descriptions.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/sync/types.ts | Adds sha1 to CompareMode and introduces optional contentSha1 on SyncPath. |
| src/sync/synchronizer.ts | Hashes local files for paired comparisons when compareMode === 'sha1'. |
| src/sync/synchronizer.test.ts | Adds integration coverage for sha1-mode upload/skip behavior. |
| src/sync/sync.test.ts | Adds unit coverage for SHA-1 compare semantics (match/diff/unavailable). |
| src/sync/scanners/b2.ts | Includes contentSha1 in scanned B2SyncPath entries. |
| src/sync/policies/compare.ts | Implements SHA-1 comparison with normalization/validation. |
| examples/README.md | Documents sha1 as a supported sync compare mode. |
| examples/node-sync-cli.ts | Updates usage comment to include sha1 mode. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
sha1toCompareModeandSyncPath.contentSha1for content-hash comparison.string | nullreader contracts.null, classify invalid strings as untrusted, treat multipartfileInfo.large_file_sha1as untrusted, verify untrusted B2 bytes by selectedfileId, and avoid treating forged or unverified metadata as successful equality.contentSha1as equality material without full remote downloads; untrusted B2 verification uses a bounded idle/read timeout, surfaces per-file errors on stalls, and does not run during dry-runs.compare.bytesHashed, and expose B2 verification downloads ascompare.bytesVerifiedwhile keepingcompare.sizestable at0.contentSha1states, scan diagnostics, and upload retry risks.retryResponseBodyFailures: true.trustServerPartSha1s: truefor trusted-writer buckets to skip matching parts.SYNC_MODEandSYNC_CONCURRENCYin the example CLI and avoid real-example cleanup races by skipping freshsdk-examples-*buckets from overlapping CI jobs.wsto8.21.0andmarkdown-itto14.2.0with exact lockfile pins.Linked issue
Closes #29
Tests run
pnpm exec vitest run src/sync/sync.test.ts src/sync/synchronizer.test.ts src/sync/scanners/scanners.node.test.ts src/sync/compare.node.test.ts src/sync/local-sha1.node.test.tspnpm testpnpm test:coveragepnpm lintpnpm lint:docspnpm lint:spellingpnpm typecheckpnpm typecheck:examplespnpm buildpnpm run docspnpm run verify:metadatapnpm run verify:exportspnpm audit --prod=falsegh pr checks 92 --repo backblaze-labs/b2-sdk-typescriptFollow-up notes
sha1mode with a surfaced event; usemodtime/sizemode or ensure remote objects carry verifiable digests when that tradeoff is not acceptable.