Skip to content

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
fix/sweep-bugfixes-and-test-harnessfrom
fix/coverage-gaps
Closed

fix(setup,scan): fail closed on corrupt manifests, JSON envelopes on every hosted failure; fetch_stage unit tests#152
Mikola Lysenko (mikolalysenko) wants to merge 1 commit into
fix/sweep-bugfixes-and-test-harnessfrom
fix/coverage-gaps

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

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:

  1. setup --exclude clobbered a corrupt manifestpersist_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 (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.

  2. scan --redirect --json emitted 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).

  3. fetch_stage.rs had 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_blobs overlay promotion (late downloads can't pollute the cache), overlay_dir semantics, and the bad --download-mode hard failure.

Verification

  • Both regression tests RED-verified against the unfixed code, then green with the fixes.
  • All 7 fetch_stage unit tests green; neighboring vendor/scan/redirect suites green.
  • cargo clippy --workspace --all-targets -- -D warnings and cargo fmt --check clean.

🤖 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 --exclude no longer treats a unreadable or corrupt .socket/manifest.json as “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_stage gains in-module unit tests for offline staging, read-only .socket/, disk vs vendor diff-archive policy, writable_blobs overlay promotion, overlay_dir, and invalid --download-mode.

Reviewed by Cursor Bugbot for commit 078fa1f. Configure here.

…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>
@mikolalysenko

Copy link
Copy Markdown
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).

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.

1 participant