Repository navigation
feat(cli): bundle create + appendix-bundles.md (#391) - #469
Conversation
`decdn bundle create` walks a directory, BLAKE3-hashes each regular file, and emits a canonical JSON manifest. Same input dir yields byte-identical output, so the manifest's own BLAKE3 is stable across runs — single-hash bundle distribution. `bundle pull` (both `-i` and `--hash` forms) is deferred behind a missing client-side fetch primitive; the issue stays open. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Code Review
This pull request implements the decdn bundle create command, which generates deterministic JSON manifests for directory contents using BLAKE3 hashing. The changes include a new ADR appendix documenting the bundle format, the CLI implementation in crates/cli, and comprehensive integration tests. Review feedback suggests aligning the path validation logic with the ADR's requirement to reject current-directory components, utilizing the blake3 crate's update_reader method for more efficient hashing, and mitigating potential TOCTOU vulnerabilities by reusing file handles for both metadata and content reading.
There was a problem hiding this comment.
Pull request overview
Adds initial support for deterministic “directory bundles” to the decdn CLI, including a new bundle create subcommand and an appendix documenting the on-disk bundle format/spec so bundle files can be content-addressed and distributed by a single BLAKE3 hash.
Changes:
- Introduces
decdn bundle create -i <dir> -o <file>to walk a directory, hash files with BLAKE3, and emit canonical single-line JSON. - Adds extensive unit + integration coverage for determinism, exclude globs, symlink behavior, and JSON status output.
- Documents the bundle JSON v1 format, path-safety rules, and determinism contract in
adr/appendix-bundles.md.
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/common/src/cli/mod.rs | Wires the new bundle CLI namespace into shared CLI types/exports. |
| crates/common/src/cli/bundle.rs | Defines clap args/types for decdn bundle and bundle create flags. |
| crates/cli/src/main.rs | Dispatches the new Command::Bundle to the CLI implementation. |
| crates/cli/src/commands/mod.rs | Exposes the new commands::bundle module. |
| crates/cli/src/commands/bundle.rs | Implements directory walk, hashing, canonical JSON serialization, and reporting for bundle create. |
| crates/cli/tests/bundle_create.rs | Adds integration tests covering determinism, sorting, excludes, symlink rules, and --json output. |
| crates/cli/Cargo.toml | Adds CLI dependencies needed for walking, glob excludes, and BLAKE3 hashing. |
| Cargo.toml | Adds workspace dependency versions for walkdir, globset, and blake3. |
| Cargo.lock | Locks new transitive dependencies (globset, bstr, etc.). |
| adr/appendix-bundles.md | Adds the bundle file format appendix and invariants/spec for determinism and safety. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- `validate_relpath` now bails on `Component::CurDir` to match the ADR's "every component must be `Component::Normal`" rule (was silently skipping). Caught by gemini-code-assist + Copilot. - `hash_file_streaming` becomes `hash_file_at`: opens the file once and pulls both the BLAKE3 hash and the size from the open handle via `metadata()` (fstat) + `blake3::Hasher::update_reader`. Closes the TOCTOU window between the previous separate `entry.metadata()` + `File::open` calls and lets the upstream-recommended streaming primitive manage buffering and EINTR retries. `HASH_BUF_SIZE` drops out as the manual loop is gone. - `write_bundle` switches to `tempfile::NamedTempFile::new_in` + `persist`. The unique O_CREAT|O_EXCL temp avoids the predictable `<output>.partial` filename (no symlink-clobber, no concurrent- writer surprise), and `persist` is the cross-platform atomic rename-replace primitive. Tests updated for the new behavior; 90/90 nextest pass; clippy + fmt clean. PR #469. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…t test - Adds `validate_relpath_rejects_current_dir` unit test pinning the CurDir bail behavior added in 17add20. The bail itself was reachable but had no regression net; a future "simplification" to silently skip CurDir would have flipped behavior with no failing test. - Fixes the `appendix-bundles.md § Path-safety rules` heading anchor in the CurDir comment (was hyphenated "Path-safety-rules"; the actual heading uses a space). Now grep-aligned with the other three anchors in this file. - Adds `write_bundle_replaces_symlink_target_does_not_follow` (Unix) test pinning the rename(2) semantics the new docstring claims: if `--output` is a pre-existing symlink, the rename replaces the symlink with a regular file rather than following it. Two reviewers flagged the missing test; the behavior is rename(2)'s, but pinning it locally protects against a future swap to e.g. persist_noclobber. - Narrows the "crash mid-write" wording on the `write_bundle` doc to distinguish Rust-side errors (Drop guard cleans up) from hard kills (random-named temp may survive — but never under the operator- expected name, which is the actual safety property). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Code reviewFound 2 issues:
decdn/crates/cli/src/commands/bundle.rs Lines 168 to 178 in 0ec73bf
Lines 70 to 87 in 0ec73bf 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
# Conflicts: # Cargo.lock
Two doc-only inconsistencies flagged on PR #469: - bundle.rs:169-173 claimed the canonicalize-and-contain check fires "regardless of the follow flag", but with --follow-symlinks=false the symlink branch hits `continue` before reaching the check, matching appendix Rule 5's "skipped silently" semantics, not Rule 1's escape check. - appendix-bundles.md Rule 1 said "regardless of --follow-symlinks", contradicting Rule 5 and the implementation. Qualify Rule 1 to apply only when --follow-symlinks is on, and cross-link Rule 5 for the off case. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
Both confirmed and fixed in f039d6d:
|
Coverage reportTotal: 87.72% (was 87.49%, ▲ +0.23%) — 11575/13195 lines
History
|
Summary
decdn bundle create -i <dir> -o <file>subcommand. Walks the directory, BLAKE3-hashes each regular file, emits a canonical single-line JSON manifest. Determinism is the load-bearing property: same input directory → byte-identical bytes → byte-identical bundle BLAKE3, which is what makes single-hash distribution viable.adr/appendix-bundles.md(~150 lines): JSON v1 schema,b3:<hex>hash convention, path-safety rules, determinism contract, bundle-as-blob property, non-relationship to ADR 012'sDECDNMANchunk manifest.bundle pullstays deferred behind a missing client-side fetch primitive; issue stays open after merge.Test plan
cargo fmt --checkcargo clippy --workspace --all-targets -- -D warningscargo nextest run -p decdn-cli -p decdn-common— 234 tests pass (16 new integration + 13 new unit for bundle create)--jsonstatus withbundle_hash, gitignore-style--exclude, invalid-glob error message, atomic temp+rename write, symlink skip default + follow + escape rejection, directory self-loop bound🤖 Generated with Claude Code