GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||
GeezerVison is showing github.com — fix(vendor): keep artifacts and ledger when revert drift-skips the lock restore by mikolalysenko · Pull Request #205 · SocketDev/socket-patch Conversation
|
| binary | revert exit | summary | .socket/vendor after |
|---|---|---|---|
| old (main) | 0 | removed 1, skipped 0 |
empty — tarball, inventory, state.json all deleted; lock still drifted |
| this PR | 0 | removed 0, skipped 1 |
minimist-1.2.2.tgz, socket-patch.vendor.json, state.json all kept |
Synthetic E1 (hosted patch.socket.dev overlay over vendored left-pad) shows the same flip, and the recovery leg on the new binary (restore vendored lock → revert) ends with removed 1, vendor tree fully pruned, registry lock restored, yarn install exit 0 with pristine bytes.
cargo test -p socket-patch-core — clean (22/22 binaries ok)cargo test -p socket-patch-cli — cleancargo clippy --workspace --all-features -- -D warnings — cleanfix/npm-vendored-over-hosted-prerevert: touches cli vendor.rs and core redirect takeover — this PR edits run_revert/reconcile_dropped in cli vendor.rs (lines ~1319-1345, ~1366-1400) and the human summary print; expect textual overlap in crates/socket-patch-cli/src/commands/vendor.rs.fix/mode-conversion-visibility-warnings: no shared files expected (scan/mod.rs, redirect/mod.rs berry branch, CLI_CONTRACT.md).scan/mod.rs, discovery.rs, lock_inventory.rs, apply.rs, e2e_safety_yarn_pnp.rs) and PR test(yarn): version-matrix e2e capstones — yarn2/3 refusal pins, berry workspaces + pnpm-linker install proofs #200 (three new e2e_yarn* test files): no overlap — this PR does not touch those files' changed regions.🤖 Generated with Claude Code
Note
Medium Risk
Changes vendoring revert semantics and ledger persistence for drift-skipped lock restores across npm-family backends and CLI orchestration; behavior is well-tested but affects data retention and JSON summary counts on a sensitive path.
Overview
Fixes residual #131: vendor --revert used to leave drifted lock entries untouched but still delete .socket/vendor/ artifacts and prune state.json, reporting success with Removed / summary.removed instead of an honest skip.
Core: RevertOutcome adds kept_artifact plus drift_skipped() / keep_artifact() (with vendor_artifact_kept warnings). The npm-family revert backends (yarn_classic, npm_lock, pnpm, yarn_berry, bun) skip remove_tree when any wiring record was drift-skipped.
CLI: run_revert and reconcile_dropped retain ledger entries and emit a counted Skipped (vendor_revert_kept) via env.record—not Removed—and human output adds a “Kept N drifted package(s)…” line when summary.skipped > 0.
After undoing drift, a follow-up vendor --revert still completes as before (lock restored, vendor tree pruned). Tests flip the prior lossy pinning test and add e2e/in-process coverage for keep + recovery.
Reviewed by Cursor Bugbot for commit 7a2013f. Configure here.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
… (residual #131) Flip the deliberate #131 pinning test classic_vendor_revert_after_hosted_overlay_is_drift_skipped_and_lossy into the fixed contract (..._keeps_blob): when every wiring record is drift-skipped ("left alone"), the blob dir must SURVIVE the revert and the keep must be surfaced (vendor_artifact_kept) — plus a recovery leg proving a second revert completes once the drift is undone. Same contract asserted across the npm-family twins' existing drift tests (npm_lock / pnpm_lock / yarn_berry_lock / bun_lock / yarn_classic_lock: revert_leaves_drifted_* now require the artifact dir kept + the keep warning), two new CLI orchestration tests in in_process_vendor.rs (run_revert and reconcile must retain the state.json entry, record a COUNTED Skipped vendor_revert_kept — summary.skipped was 0 even when the skip event was emitted — and never a Removed), and a new yarn-classic e2e capstone leg (vendored -> hosted overlay -> vendor --revert keeps the tarball, the kept tarball still installs after the drift is undone, and the follow-up revert completes to pristine). RED: 6 core + 2 CLI + 1 e2e tests fail on current main behavior (remove_tree runs unconditionally after the restore loop; success prunes the ledger entry). Co-Authored-By: Claude Fable 5 <[email protected]>
…ck restore Residual #131 (strapi campaign, adversarially re-confirmed on main): when vendor --revert found every recorded lock entry re-resolved (a hosted patch.socket.dev overlay, a registry re-resolve — anything failing the uuid-dir ownership gate), revert_recorded_block correctly left the lock alone with vendor_lock_entry_drifted warnings, but the backend still ran remove_tree(.socket/vendor/npm/<uuid>/) unconditionally after the restore loop, and run_revert/reconcile_dropped treated the warning-only success as "removed": PatchAction::Removed + state.entries.remove + save_state. End state: the lock still pointed at the drifted target while the artifacts, the ledger entry holding the only pre-vendor originals, and the tarball the redirect ledger's recorded `original` fragments reference were all destroyed — a silent-success data loss with a delayed broken-install hazard. Fix, per the orphan sweep's invariant (never delete what something still references): - RevertOutcome grows `kept_artifact` plus drift_skipped()/keep_artifact() helpers (vendor/mod.rs). keep_artifact() pushes an honest `vendor_artifact_kept` warning naming the kept dir and the remediation. - All five npm-family backends with the unconditional remove shape (yarn_classic_lock, npm_lock, pnpm_lock, yarn_berry_lock, bun_lock) now skip the remove_tree and mark the keep whenever any wiring record was drift-skipped. - run_revert and reconcile_dropped (cli vendor.rs) honor the signal: the state.json entry is retained and the outcome is a COUNTED Skipped event (`vendor_revert_kept`) recorded via env.record — fixing the sub-bug where summary.skipped stayed 0 while skip events were emitted — never a Removed; counts stay uninflated (#166 precedent: advisory warnings keep bypassing the counters). Human output gains a "Kept N drifted package(s)" line. - Other RevertOutcome construction sites gain `kept_artifact: false` (no behavior change outside the npm family). Once the drift is undone (vendored lock restored — e.g. a future hosted revert replaying its recorded originals), the next `vendor --revert` completes exactly as before: lock restored byte-for-byte, artifacts and ledger pruned. GREEN: the 6 flipped core tests, the 2 new CLI orchestration tests, and the new yarn-classic E1 e2e capstone (drift-skip keep -> kept tarball still installs -> follow-up revert completes to pristine) all pass; cargo test -p socket-patch-core clean; clippy --workspace --all-features clean. Co-Authored-By: Claude Fable 5 <[email protected]>
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
Or push these changes by commenting:
@cursor push dfde23a211
diff --git a/crates/socket-patch-cli/src/commands/vendor.rs b/crates/socket-patch-cli/src/commands/vendor.rs --- a/crates/socket-patch-cli/src/commands/vendor.rs +++ b/crates/socket-patch-cli/src/commands/vendor.rs @@ -1568,10 +1568,13 @@ continue; } let entry = state.entries.get(&purl).cloned().expect("listed above"); - if dispatch_revert_one(&entry, &common.cwd, false) - .await - .success - { + let outcome = dispatch_revert_one(&entry, &common.cwd, false).await; + if outcome.success { + if outcome.kept_artifact { + // Drift-skip keep: backend kept the uuid dir, so the ledger + // entry must survive too (same contract as reconcile_dropped). + continue; + } state.entries.remove(&purl); out.dropped_reverted.push(purl); } else { @@ -1601,13 +1604,16 @@ out.unused_reverted.push(purl); continue; } - if !dispatch_revert_one(&entry, &common.cwd, false) - .await - .success - { + let outcome = dispatch_revert_one(&entry, &common.cwd, false).await; + if !outcome.success { out.failed.push(purl); continue; } + if outcome.kept_artifact { + // Drift-skip keep: backend kept the uuid dir, so the ledger + // entry must survive too (same contract as reconcile_dropped). + continue; + } state.entries.remove(&purl); if let Some(m) = manifest.as_mut() { let base = strip_purl_qualifiers(&entry.base_purl).to_string();
You can send follow-ups to the cloud agent here.
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 7a2013f. Configure here.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
…s are not drift
The keep gate (drift_skipped) keyed on vendor_lock_entry_drifted, but the
npm-family backends emitted that same code for records a PREVIOUS partial
revert had already restored or removed: a restored fragment's registry
value fails the uuid ownership gate ("re-resolved since vendoring"), a
removed berry resolutions entry hits "no longer exists; nothing to
remove", and a rekeyed pnpm/berry block restored under its pre-vendor key
misses the recorded-key lookup ("no longer exists; nothing to restore").
After any partial restore, every later `vendor --revert` therefore
re-classified the converged records as drift and kept the artifact dir +
ledger entry forever — the CLI's own "undo the drift and re-run `vendor
--revert` to finish" remediation could never be satisfied.
Teach every left-alone branch in the five keep-gate backends (npm, bun,
pnpm, yarn classic, yarn berry) to recognize the ALREADY-CONVERGED state
as a silent no-op before warning:
- a live fragment equal to the recorded pre-vendor `original` (restored
in place: npm/bun entries, classic/berry blocks, pnpm overrides /
importer deps / snapshot refs, berry takeover resolutions);
- for Added records with no original, the key being absent (berry
resolutions entry/table, pnpm overrides in package.json /
pnpm-workspace.yaml / the lock's overrides section);
- for the rekeying restores (berry lock entries, pnpm packages/snapshots
blocks), the recorded original block being live verbatim under its own
pre-vendor key when the recorded key no longer matches.
drift_skipped() now fires only on genuine third-party drift the user can
still undo, so the kept artifacts + ledger entry are released the moment
the drift is undone — run 2 completes the revert and prunes everything.
Tests: each backend's drift unit test gains a second-run leg (undo ONLY
the drift; already-reverted records must be silent and the revert must
complete), the CLI keep tests now drift to a value that is neither ours
nor the original, and a new CLI test pins that a lock manually restored
to the pre-vendor original converges (counted Removed, ledger pruned) on
the first revert.
Co-Authored-By: Claude Fable 5 <[email protected]>
There was an error while loading. Please reload this page.
Conflicts: - crates/socket-patch-cli/src/commands/vendor.rs: kept the branch's doc comment on the VexSummary warnings channel (code identical on both sides). - crates/socket-patch-cli/tests/in_process_vendor.rs: both sides appended tests at the same point — kept BOTH the branch's hosted_to_vendor_conversion module (#213) and main's section-12 drift-skip revert tests (#205). Co-Authored-By: Claude Fable 5 <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.