From 22dbe67a3153a8c5220c0b48e110c879ed2c5c52 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 01:02:39 +0000 Subject: [PATCH 1/3] Start vlt-heal-unchecked-direction Opens the branch for #2254: the vlt heal reports a copy it could not check with the hosted flow's text after a rollback or a takeover. Refs #2254. Assisted-by: Claude Code From ce1df8a678ea471739f898e39fedb9b847c096f2 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 01:05:24 +0000 Subject: [PATCH 2/3] Report an unchecked vlt copy as the run it follows The vlt heal runs after a hosted rewrite, after rollback or remove restore the registry pins, and after a hosted to vendored takeover. A copy it could not check (node_modules is a link, or vlt's hidden lock is missing or unreadable) was reported with one text for all three: "vlt-lock.json pins Socket-patched packages ... run vlt ci to be sure the patched packages are installed". After a rollback that is false twice over: the run has just taken the pin out, and the copy that may still be installed is the patched one. The rollback now says the registry pins were restored and that vlt ci makes sure the registry packages are installed. The takeover says the packages were vendored. The hosted rewrite's text is unchanged, as are the warning code, the command to run and the exit codes. Fixes #2254. Assisted-by: Claude Code --- .../socket-patch-cli/src/commands/vlt_heal.rs | 100 +++++++++++++++--- .../in_process_vendor_bun_takeover/vlt.rs | 32 ++++++ .../tests/rollback/rollback_render.rs | 57 ++++++++++ 3 files changed, 177 insertions(+), 12 deletions(-) diff --git a/crates/socket-patch-cli/src/commands/vlt_heal.rs b/crates/socket-patch-cli/src/commands/vlt_heal.rs index 9b891aeab..aa879c9a4 100644 --- a/crates/socket-patch-cli/src/commands/vlt_heal.rs +++ b/crates/socket-patch-cli/src/commands/vlt_heal.rs @@ -158,11 +158,13 @@ fn reinstall_detail(tally: &HealTally) -> String { held, ) } else if tally.undeterminable > 0 { - with_optional_kept( - undeterminable_detail(tally.undeterminable), - tally.optional_left, - held, - ) + let mut detail = unchecked_detail( + "vlt-lock.json pins Socket-patched packages", + tally.undeterminable, + "patched", + ); + detail.push('.'); + with_optional_kept(detail, tally.optional_left, held) } else if tally.invalidated > 0 { let mut detail = with_optional_kept( format!( @@ -201,7 +203,11 @@ fn rollback_detail(tally: &HealTally, restored: usize) -> Option { tally.stale_left ) } else if tally.undeterminable > 0 { - undeterminable_detail(tally.undeterminable) + unchecked_detail( + &format!("restored registry pins for {restored} packages"), + tally.undeterminable, + "registry", + ) } else if tally.invalidated > 0 && tally.optional_left > 0 { format!( "restored registry pins for {restored} packages; removed {} patched installed \ @@ -235,7 +241,11 @@ fn takeover_detail(tally: &HealTally, vendored: usize) -> Option { tally.stale_left ) } else if tally.undeterminable > 0 { - undeterminable_detail(tally.undeterminable) + unchecked_detail( + &format!("vendored {vendored} hosted-pinned packages"), + tally.undeterminable, + "vendored", + ) } else if tally.invalidated > 0 && tally.optional_left > 0 { format!( "vendored {vendored} hosted-pinned packages; removed {} hosted installed copies, so \ @@ -259,11 +269,15 @@ fn takeover_detail(tally: &HealTally, vendored: usize) -> Option { Some(with_optional_kept(detail, tally.optional_left, held)) } -fn undeterminable_detail(n: usize) -> String { +/// The arm for copies the heal could not judge and so kept. `did` is what +/// the run did to the lock and `installs` the kind of package the lock now +/// installs: a rollback's lock no longer pins a Socket patch, so it must +/// not ask for the patched packages the hosted rewrite asks for. +fn unchecked_detail(did: &str, unchecked: usize, installs: &str) -> String { format!( - "vlt-lock.json pins Socket-patched packages, but socket-patch could not check {n} \ - installed copies (node_modules is a link, or node_modules/.vlt-lock.json is missing \ - or unreadable); run `vlt ci` to be sure the patched packages are installed." + "{did}, but socket-patch could not check {unchecked} installed copies (node_modules \ + is a link, or node_modules/.vlt-lock.json is missing or unreadable); run `vlt ci` to \ + be sure the {installs} packages are installed" ) } @@ -465,6 +479,63 @@ mod tests { assert!(reinstall_detail(&tally).contains("still holds 3 unpatched copies and")); } + /// A copy the heal could not check is reported in the direction of the + /// run, like every other arm: after a rollback the lock no longer pins + /// a Socket-patched package, and after a takeover the hosted pin is + /// gone. + #[test] + fn an_unchecked_copy_is_reported_in_the_direction_of_the_run() { + let tally = HealTally { + undeterminable: 1, + ..HealTally::default() + }; + let unchecked = "socket-patch could not check 1 installed copies (node_modules is a \ + link, or node_modules/.vlt-lock.json is missing or unreadable)"; + assert_eq!( + reinstall_detail(&tally), + format!( + "vlt-lock.json pins Socket-patched packages, but {unchecked}; run `vlt ci` to \ + be sure the patched packages are installed." + ) + ); + assert_eq!( + rollback_detail(&tally, 2).unwrap(), + format!( + "restored registry pins for 2 packages, but {unchecked}; run `vlt ci` to be \ + sure the registry packages are installed" + ) + ); + assert_eq!( + takeover_detail(&tally, 2).unwrap(), + format!( + "vendored 2 hosted-pinned packages, but {unchecked}; run `vlt ci` to be sure \ + the vendored packages are installed" + ) + ); + + // The kept optional copies follow as their own sentence. + let tally = HealTally { + optional_left: 3, + ..tally + }; + let rollback = rollback_detail(&tally, 2).unwrap(); + assert!( + rollback.contains( + "be sure the registry packages are installed. node_modules also still holds 3 \ + patched copies of optional dependencies; " + ), + "{rollback}" + ); + let takeover = takeover_detail(&tally, 2).unwrap(); + assert!( + takeover.contains( + "be sure the vendored packages are installed. node_modules also still holds 3 \ + installed copies of the vendored optional dependencies; " + ), + "{takeover}" + ); + } + #[test] fn kept_optional_copies_are_reported_alongside_every_variant() { let optional = |invalidated, stale_left, undeterminable| HealTally { @@ -505,7 +576,12 @@ mod tests { ); assert_eq!( reinstall_detail(&optional(0, 0, 1)), - format!("{} {unpatched}", undeterminable_detail(1)) + format!( + "vlt-lock.json pins Socket-patched packages, but socket-patch could not check 1 \ + installed copies (node_modules is a link, or node_modules/.vlt-lock.json is \ + missing or unreadable); run `vlt ci` to be sure the patched packages are \ + installed. {unpatched}" + ) ); assert_eq!( diff --git a/crates/socket-patch-cli/tests/in_process_vendor_bun_takeover/vlt.rs b/crates/socket-patch-cli/tests/in_process_vendor_bun_takeover/vlt.rs index c8c0a227d..b7f6974d1 100644 --- a/crates/socket-patch-cli/tests/in_process_vendor_bun_takeover/vlt.rs +++ b/crates/socket-patch-cli/tests/in_process_vendor_bun_takeover/vlt.rs @@ -542,6 +542,38 @@ async fn vlt_failed_vendor_after_the_takeover_revert_keeps_the_hosted_pin() { ); } +/// A takeover that cannot check the hosted store copy (no hidden lock) +/// keeps it and reports it as a takeover: the package is vendored now, so +/// the advisory does not speak of a pin in `vlt-lock.json`. +#[tokio::test(flavor = "multi_thread")] +async fn vlt_hosted_then_vendored_takeover_reports_an_unchecked_copy_as_a_takeover() { + let tmp = tempfile::tempdir().unwrap(); + let root = tmp.path(); + let server = MockServer::start().await; + mock_api(&server).await; + hosted_project(root, &server).await; + std::fs::remove_file(root.join("node_modules/.vlt-lock.json")).unwrap(); + + let (code, env, stderr) = scan(root, &server, "vendored", &[]); + + assert_eq!(code, 0, "{env:#}\n{stderr}"); + assert!( + hosted::read(root, "vlt-lock.json").contains(&rel()), + "{env:#}" + ); + assert_eq!( + detail_of(&env, "redirect_vlt_reinstall_required"), + "vendored 1 hosted-pinned packages, but socket-patch could not check 1 installed copies \ + (node_modules is a link, or node_modules/.vlt-lock.json is missing or unreadable); run \ + `vlt ci` to be sure the vendored packages are installed" + ); + assert_eq!( + std::fs::read(hosted::store_dir(root, TILDE_ID).join("index.js")).unwrap(), + PATCHED, + "a copy the heal cannot judge is kept" + ); +} + /// An optional hosted pin taken over by `scan --mode vendored`: the /// hosted store copy stays (vlt would not reinstall a removed optional /// node), and the advisory says how to refresh it. diff --git a/crates/socket-patch-cli/tests/rollback/rollback_render.rs b/crates/socket-patch-cli/tests/rollback/rollback_render.rs index e0bcaf07d..60208e2ad 100644 --- a/crates/socket-patch-cli/tests/rollback/rollback_render.rs +++ b/crates/socket-patch-cli/tests/rollback/rollback_render.rs @@ -1146,6 +1146,63 @@ fn vlt_hosted_rollback_dry_run_keeps_the_store_and_wet_human_run_heals() { assert!(!root.join("node_modules/.vlt-lock.json").exists()); } +/// A rollback that cannot check an installed copy (vlt's hidden lock is +/// gone, as after a heal that removed another package's stale copy) keeps +/// the copy and reports it as a rollback, in human and `--json` mode: the +/// registry pins are restored and `vlt ci` installs the registry packages. +/// The hosted flow's "vlt-lock.json pins Socket-patched packages" is false +/// here, since the run has just taken the pin out. +#[test] +fn vlt_hosted_rollback_reports_an_unchecked_copy_as_a_rollback() { + let unchecked = "restored registry pins for 1 packages, but socket-patch could not check 1 \ + installed copies (node_modules is a link, or node_modules/.vlt-lock.json \ + is missing or unreadable); run `vlt ci` to be sure the registry packages \ + are installed"; + let registry = NpmRegistry::start(&[("left-pad", "1.3.0")]); + for json in [false, true] { + let tmp = tempfile::tempdir().unwrap(); + let root = tmp.path(); + let store = write_vlt_hosted_fixture(root); + std::fs::remove_file(root.join("node_modules/.vlt-lock.json")).unwrap(); + + let mut args = vec!["rollback", "--yes"]; + if json { + args.push("--json"); + } + let (code, stdout, stderr) = run_hosted(root, &args, Some(®istry)); + assert_eq!(code, 0, "json={json}\n{stdout}\n{stderr}"); + let restored = std::fs::read_to_string(root.join("vlt-lock.json")).unwrap(); + assert!( + restored.contains(UPSTREAM_INTEGRITY) && !restored.contains("patch.socket.dev"), + "json={json}: the registry pin is back:\n{restored}" + ); + assert!( + store.join("index.js").exists(), + "json={json}: a copy the heal cannot judge is kept" + ); + if json { + let doc = common::envelope::parse_json_envelope(&stdout); + let details: Vec<&str> = doc["warnings"] + .as_array() + .into_iter() + .flatten() + .filter(|w| w["code"] == "redirect_vlt_reinstall_required") + .filter_map(|w| w["detail"].as_str()) + .collect(); + assert_eq!(details, [unchecked], "{doc:#}"); + } else { + assert!( + stderr.contains(&format!("Warning: {unchecked}")), + "the advisory speaks of the rollback, not of a pin:\n{stderr}" + ); + assert!( + !stderr.contains("vlt-lock.json pins Socket-patched packages"), + "{stderr}" + ); + } + } +} + /// Human twin of `manifest_write_failure_warns_and_exits_one`: the failed /// manifest update prints the "Error: Failed to update the manifest:" /// stderr line, exit 1, manifest byte-identical — after the file restore From 4a03aa89caad557b1948332f088508210bd4b9bb Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 01:21:27 +0000 Subject: [PATCH 3/3] List the unchecked-copy tests in the vlt map From review. docs/testing/vlt-coverage.json names the tests behind each variant of the reinstall advisory. Its "copies could not be checked" entry listed only hosted scans, so the two tests of that arm after a rollback and after a takeover could be deleted without the map's checker noticing. Refs #2254. Assisted-by: Claude Code --- docs/testing/vlt-coverage.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/testing/vlt-coverage.json b/docs/testing/vlt-coverage.json index 990569b0e..afa168ee4 100644 --- a/docs/testing/vlt-coverage.json +++ b/docs/testing/vlt-coverage.json @@ -121,7 +121,9 @@ ], "redirect_vlt_reinstall_required: copies could not be checked": [ "scan_redirect_vlt_heal_undeterminable_node_modules_symlink_not_deleted", - "scan_redirect_vlt_undeterminable_vex_not_attested" + "scan_redirect_vlt_undeterminable_vex_not_attested", + "vlt_hosted_rollback_reports_an_unchecked_copy_as_a_rollback", + "vlt_hosted_then_vendored_takeover_reports_an_unchecked_copy_as_a_takeover" ], "redirect_vlt_reinstall_required: none stale": [ "scan_redirect_vlt_rerun_does_not_invalidate_healthy_tree"