fix(setup,scan): fail closed on corrupt manifests, JSON envelopes on every hosted failure; fetch_stage unit tests - #152
Closed
Mikola Lysenko (mikolalysenko) wants to merge 1 commit into
Conversation
…every hosted failure; fetch_stage unit tests Three coverage gaps from the 2026-08-10 structure review, each with the test that pins it: * setup --exclude persistence clobbered a corrupt manifest: persist_setup_excludes flattened a read/parse error to "no manifest yet" and rewrote the file as a bare setup block, destroying every patch record a merely-corrupt manifest still held. Now fails closed (skip persistence, warn on stderr, manifest bytes untouched). RED test: exclude_persistence_fails_closed_on_corrupt_manifest. * scan --redirect --json emitted empty stdout on every failure exit (discovery-detail failure, reference-resolve failure, file/ledger write failure) — exit 1 with nothing to parse. All four bail-outs now emit the machine-readable error envelope (status/error mirror the success envelope's error fold). RED test: redirect_json_mode_failures_emit_error_envelope. * fetch_stage.rs (the offline-guard-critical download planner) had zero direct tests. In-src unit tests now pin: the read-only-.socket contract, in-place staging when fully cached, the diff-archive disk-vs-vendor staging asymmetry both module docs describe, overlay promotion for late downloads, overlay_dir semantics, and the bad --download-mode hard failure. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Collaborator
Author
|
Folded into #150 — the stack was consolidated into a single PR at the author's request; this PR's commit is included there verbatim (cherry-picked, all tests green on the consolidated head). |
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
Stacked on #150 (retarget to main once it lands). Three coverage gaps from the 2026-08-10 structure review, each fixed with the RED-first test that pins it:
setup --excludeclobbered a corrupt manifest —persist_setup_excludesflattened a read/parse error to "no manifest yet" and rewrote the file as a bare setup block, destroying every patch record a merely-corrupt (possibly hand-recoverable) manifest still held. Now fails closed: persistence is skipped with a loud stderr warning and the manifest bytes are untouched. Exit semantics deliberately unchanged (the broader setup exit-code question stays a separate product decision). RED-verified:exclude_persistence_fails_closed_on_corrupt_manifest.scan --redirect --jsonemitted empty stdout on every failure exit — discovery-detail failure, reference-resolve failure, and both write failures returned exit 1 with nothing to parse. All four bail-outs now emit the machine-readable error envelope (status/error/redirect.mode, mirroring the success envelope's error fold). RED-verified:redirect_json_mode_failures_emit_error_envelope(both legs).fetch_stage.rshad zero direct tests (443-LOC offline-guard-critical download planner). New in-src unit tests pin: the read-only-.socket/contract on the Unavailable path, in-place staging when fully cached, the documented disk-vs-vendor staging asymmetry (diff archive sufficient for apply, insufficient for vendor),writable_blobsoverlay promotion (late downloads can't pollute the cache),overlay_dirsemantics, and the bad--download-modehard failure.Verification
cargo clippy --workspace --all-targets -- -D warningsandcargo fmt --checkclean.🤖 Generated with Claude Code
Note
Medium Risk
Touches manifest persistence and hosted redirect CLI output on failure paths; changes are fail-closed and test-backed but affect data-loss and automation parsing behavior.
Overview
Closes three contract gaps with regression tests and targeted behavior fixes.
setup --excludeno longer treats a unreadable or corrupt.socket/manifest.jsonas “no manifest”: it skips persisting excludes, warns on stderr, and leaves the file byte-identical so patch records are not wiped for an exclude list.scan --redirect --json(hosted) early failures (discovery, reference resolve, lockfile write, redirect ledger write) now print a parseable JSON envelope on stdout (status: error,error,redirect.mode: hosted) instead of exit 1 with empty stdout; stderr behavior is unchanged.fetch_stagegains in-module unit tests for offline staging, read-only.socket/, disk vs vendor diff-archive policy,writable_blobsoverlay promotion,overlay_dir, and invalid--download-mode.Reviewed by Cursor Bugbot for commit 078fa1f. Configure here.