From 3cc5b2c0770e2985a58fb340beda8687ac5c0983 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 17:23:08 +0000 Subject: [PATCH 1/6] Start fix for vex hosted gem remedy (#2219) Empty commit to open the draft pull request that claims the issue. Assisted-by: Claude Code:claude-fable-5-2 Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_011f9aeQ4rKnRJHYWRr5aMyn From 36159da8ed637262ee77d1d793138cbc38d2fc91 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 17:34:50 +0000 Subject: [PATCH 2/6] Send a stale hosted gem to scan, not a reinstall When nothing can be attested because the installed copies still hold their original files, vex ends with one remedy for every ecosystem: "Reinstall from the lockfile (hosted or vendored patches)". For a hosted gem that cannot work. Bundler keeps a gem it has already installed whatever source the lock names, so bundle install changes nothing, and bundle pristine on Bundler 2.6+ removes the gems and then fails on the lock's checksum. This is what a second machine sees after it pulls the hosted Gemfile.lock onto an existing install (#2219). The hint now learns which omitted packages a hosted pin wires. A gem among them is told to run socket-patch scan, which replaces the installed copy, and names the two options for a shared gem home. Every other package keeps the reinstall wording. The end-to-end test runs the flow: pull the hosted pair onto an upstream install, vex names the scan, a scan with no --mode replaces the copy and leaves the pair alone, and vex then attests the gem. Assisted-by: Claude Code:claude-fable-5-2 Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_011f9aeQ4rKnRJHYWRr5aMyn --- crates/socket-patch-cli/CLI_CONTRACT.md | 2 +- .../src/commands/gem_refresh.rs | 3 +- crates/socket-patch-cli/src/commands/vex.rs | 161 +++++++++++++++--- .../tests/e2e_redirect_gem_stale_install.rs | 110 ++++++++++++ docs/usage.md | 7 + 5 files changed, 258 insertions(+), 25 deletions(-) diff --git a/crates/socket-patch-cli/CLI_CONTRACT.md b/crates/socket-patch-cli/CLI_CONTRACT.md index 469066b69..72f437714 100644 --- a/crates/socket-patch-cli/CLI_CONTRACT.md +++ b/crates/socket-patch-cli/CLI_CONTRACT.md @@ -3079,7 +3079,7 @@ The VEX document is JSON-LD, which collides with the standard `--json` envelope `--output -` means stdout (the first row). With `--dry-run`, a document bound for `--output` is built and verified but not written, a previous document at that path is left alone, the one-line summary reads `[dry-run] Would write OpenVEX document with N statements to `, and the envelope's `dryRun` is `true`. In every one-line summary the count reads `N statements (K affected)` when K of the statements say `affected`. A written file ends with a newline, like the stdout form. -When verification is enabled (the default) and a patch is omitted, the failed PURLs are surfaced on stderr in plain mode or as `skipped` events on the envelope in JSON mode (one per patch, sorted by PURL; `errorCode` is the tag). Plain mode prints one line per reason, largest first: `Warning: omitting 82 packages from VEX: the patched files still hold the original content (not_applied): @sigstore/core@1.1.0, @sigstore/core@2.0.0, @simple-git/argv-parser@1.1.1 and 79 more (--verbose lists them all)`; a reason with a single patch keeps the per-patch line `Warning: omitting from VEX: ()`, and `--verbose` prints that line for every patch. The run's advisories print before them, folded the same way: the first of each kind in full, then ` ... and 9 more like these: glob@10.4.5, glob@11.0.3, minimatch@3.1.2 and 6 more (--verbose lists them all)` (the packages are named where each advisory opens with one). When nothing could be attested, the `Error: No applied patches with vulnerability metadata to attest.` line is followed by the remedy for the patches that only need installing (`The patched packages are not installed yet: ... Reinstall from the lockfile (hosted or vendored patches) or run \`socket-patch apply\` (agent-mode patches), then run \`socket-patch vex\` again.`, or `N of the patched packages ...` when other reasons are among them). `--json` is unchanged: every advisory is its own `warnings[]` entry and every omission its own `skipped` event. Status becomes `partialFailure` when at least one patch was omitted but at least one was emitted. It is `partialFailure` too, with exit `0`, when a statement of the document says `affected`, also when every one does: `summary.verified` counts the packages attested as patched and no other. +When verification is enabled (the default) and a patch is omitted, the failed PURLs are surfaced on stderr in plain mode or as `skipped` events on the envelope in JSON mode (one per patch, sorted by PURL; `errorCode` is the tag). Plain mode prints one line per reason, largest first: `Warning: omitting 82 packages from VEX: the patched files still hold the original content (not_applied): @sigstore/core@1.1.0, @sigstore/core@2.0.0, @simple-git/argv-parser@1.1.1 and 79 more (--verbose lists them all)`; a reason with a single patch keeps the per-patch line `Warning: omitting from VEX: ()`, and `--verbose` prints that line for every patch. The run's advisories print before them, folded the same way: the first of each kind in full, then ` ... and 9 more like these: glob@10.4.5, glob@11.0.3, minimatch@3.1.2 and 6 more (--verbose lists them all)` (the packages are named where each advisory opens with one). When nothing could be attested, the `Error: No applied patches with vulnerability metadata to attest.` line is followed by the remedy for the patches that only need installing (`The patched packages are not installed yet: ... Reinstall from the lockfile (hosted or vendored patches) or run \`socket-patch apply\` (agent-mode patches), then run \`socket-patch vex\` again.`, or `N of the patched packages ...` when other reasons are among them). A hosted gem among them is not told to reinstall, since Bundler keeps a gem it has already installed and `bundle pristine` on Bundler 2.6+ removes the gems and then fails on the lock's checksum; its remedy is the scan that replaces the installed copy: `The patched packages are hosted gems whose installed copies are still the upstream builds. ... Run \`socket-patch scan\` here to replace the installed copies (for a gem home outside the project, run \`bundle config set --local path vendor/bundle && bundle install\` instead, or add \`--gem-refresh-shared\` to the scan), then run \`socket-patch vex\` again.` (see "Gem stale-install guard"). `--json` is unchanged: every advisory is its own `warnings[]` entry and every omission its own `skipped` event. Status becomes `partialFailure` when at least one patch was omitted but at least one was emitted. It is `partialFailure` too, with exit `0`, when a statement of the document says `affected`, also when every one does: `summary.verified` counts the packages attested as patched and no other. ## Semver policy diff --git a/crates/socket-patch-cli/src/commands/gem_refresh.rs b/crates/socket-patch-cli/src/commands/gem_refresh.rs index 2aa74e510..787a661de 100644 --- a/crates/socket-patch-cli/src/commands/gem_refresh.rs +++ b/crates/socket-patch-cli/src/commands/gem_refresh.rs @@ -360,7 +360,8 @@ fn home_spec(gem_dir: &Path) -> Option { /// The local-path remedy: Bundler then installs every gem of the project /// into the project, from the source the lock names. -const LOCAL_PATH_REMEDY: &str = "bundle config set --local path vendor/bundle && bundle install"; +pub(crate) const LOCAL_PATH_REMEDY: &str = + "bundle config set --local path vendor/bundle && bundle install"; /// The files whose removal makes `bundle install` fetch the gem again: the /// installed copy's `specifications` entry and cached archive (Bundler diff --git a/crates/socket-patch-cli/src/commands/vex.rs b/crates/socket-patch-cli/src/commands/vex.rs index 2505e0cfd..7308f880d 100644 --- a/crates/socket-patch-cli/src/commands/vex.rs +++ b/crates/socket-patch-cli/src/commands/vex.rs @@ -335,6 +335,10 @@ pub(crate) struct VexGenError { /// Patches omitted by verification, populated only for the /// `no_applicable_patches` case (so callers can list them). pub failed: Vec, + /// The purls in `failed` that a hosted pin wires. What gets such a + /// package installed depends on its package manager (see + /// [`nothing_attested_hint`]). + pub hosted: Vec, /// Advisories raised before the failure (already printed in human /// mode) — for `no_applicable_patches` often the only explanation of a /// `vendor_unwired` / `redirect_unwired` omission (the lockfile-discovery @@ -514,7 +518,7 @@ pub async fn run(args: VexArgs) -> i32 { ), _ => (e.message, 2), }; - emit_envelope_error(&args, e.code, &message, &e.failed, &run_warnings); + emit_envelope_error(&args, e.code, &message, &e.failed, &e.hosted, &run_warnings); if !args.common.json { below.print(); } @@ -1469,10 +1473,17 @@ async fn generate_vex( None => { track_vex_failed("no_applicable_patches", ¶ms.telemetry(common)).await; let message = "No applied patches with vulnerability metadata to attest.".to_string(); + let hosted = outcome + .failed + .iter() + .filter(|f| plan.hosted.contains_key(&f.purl)) + .map(|f| f.purl.clone()) + .collect(); return Err(VexGenError { code: "no_applicable_patches", message, failed: outcome.failed, + hosted, warnings: Vec::new(), }); } @@ -2394,6 +2405,7 @@ async fn generate_vex_from_manifest_path_inner( code: "manifest_not_found", message, failed: Vec::new(), + hosted: Vec::new(), warnings: Vec::new(), } } else { @@ -2429,6 +2441,7 @@ async fn fail( code, message, failed: Vec::new(), + hosted: Vec::new(), warnings: Vec::new(), } } @@ -2621,13 +2634,15 @@ async fn synthesize_go_patches( /// Emit a `vex` error to the active output channel: an error envelope on /// stdout in `--json` mode, a stderr message otherwise. `failures` lists /// patches omitted by verification (populated for `no_applicable_patches`, -/// empty everywhere else); `warnings` are the run's advisories, already on -/// stderr in human mode, folded into the envelope's `warnings[]` here. +/// empty everywhere else), `hosted` the ones of them a hosted pin wires; +/// `warnings` are the run's advisories, already on stderr in human mode, +/// folded into the envelope's `warnings[]` here. fn emit_envelope_error( args: &VexArgs, code: &str, message: &str, failures: &[FailedPatch], + hosted: &[String], warnings: &[RunWarning], ) { if args.common.json { @@ -2651,7 +2666,7 @@ fn emit_envelope_error( eprintln!(" omitted: {} ({})", f.purl, f.reason); } } else if let Some(hint) = - nothing_attested_hint(failures).filter(|_| code == "no_applicable_patches") + nothing_attested_hint(failures, hosted).filter(|_| code == "no_applicable_patches") { eprintln!("{hint}"); } @@ -2819,8 +2834,13 @@ fn omission_lines(failed: &[FailedPatch], verbose: bool) -> Vec { /// error, when patches were left out for a reason with a remedy: the /// patched packages are not installed yet (the usual case right after a /// hosted or vendored scan), or not installed at all. -fn nothing_attested_hint(failed: &[FailedPatch]) -> Option { - let count = |reason: &str| failed.iter().filter(|f| f.reason == reason).count(); +/// +/// `hosted` names the purls a hosted pin wires. A gem among them gets its +/// own remedy: Bundler keeps a gem it has already installed whatever +/// source the lock names, so no reinstall brings the patched gem in (and +/// `bundle pristine` on Bundler 2.6+ removes the gems, then fails on the +/// lock's checksum). The hosted scan is what replaces the installed copy. +fn nothing_attested_hint(failed: &[FailedPatch], hosted: &[String]) -> Option { let of = |n: usize| { if n == failed.len() { "The".to_string() @@ -2828,16 +2848,39 @@ fn nothing_attested_hint(failed: &[FailedPatch]) -> Option { format!("{n} of the") } }; - let not_applied = count("not_applied"); - if not_applied > 0 { - return Some(format!( + let not_applied = failed.iter().filter(|f| f.reason == "not_applied"); + let (gems, others): (Vec<_>, Vec<_>) = + not_applied.partition(|f| f.purl.starts_with("pkg:gem/") && hosted.contains(&f.purl)); + let mut remedies = Vec::new(); + if !others.is_empty() { + remedies.push(format!( "{} patched packages are not installed yet: the installed copies still hold their \ original files. Reinstall from the lockfile (hosted or vendored patches) or run \ - `socket-patch apply` (agent-mode patches), then run `socket-patch vex` again.", - of(not_applied) + `socket-patch apply` (agent-mode patches)", + of(others.len()) + )); + } + if !gems.is_empty() { + remedies.push(format!( + "{} patched packages are hosted gems whose installed copies are still the upstream \ + builds. Bundler keeps a gem it has already installed, so `bundle install`, `bundle \ + install --redownload` and `bundle pristine` do not bring in the patched gem. Run \ + `socket-patch scan` here to replace the installed copies (for a gem home outside \ + the project, run `{}` instead, or add `--gem-refresh-shared` to the scan)", + of(gems.len()), + crate::commands::gem_refresh::LOCAL_PATH_REMEDY + )); + } + if !remedies.is_empty() { + return Some(format!( + "{}, then run `socket-patch vex` again.", + remedies.join(". ") )); } - let missing = count("package_not_found"); + let missing = failed + .iter() + .filter(|f| f.reason == "package_not_found") + .count(); (missing > 0).then(|| { format!( "{} patched packages are not installed here. Run your package manager's install, \ @@ -3166,32 +3209,104 @@ mod tests { failed("pkg:npm/a@1.0.0", "not_applied"), failed("pkg:npm/b@1.0.0", "not_applied"), ]; + let reinstall = "The patched packages are not installed yet: the installed copies still \ + hold their original files. Reinstall from the lockfile (hosted or \ + vendored patches) or run `socket-patch apply` (agent-mode patches), \ + then run `socket-patch vex` again."; + assert_eq!(nothing_attested_hint(&all, &[]).as_deref(), Some(reinstall)); + // A hosted pin of any other package manager installs from the lock. + let hosted = ["pkg:npm/a@1.0.0".to_string(), "pkg:npm/b@1.0.0".to_string()]; assert_eq!( - nothing_attested_hint(&all).as_deref(), - Some( - "The patched packages are not installed yet: the installed copies still hold \ - their original files. Reinstall from the lockfile (hosted or vendored patches) \ - or run `socket-patch apply` (agent-mode patches), then run `socket-patch vex` \ - again." - ) + nothing_attested_hint(&all, &hosted).as_deref(), + Some(reinstall) ); let some = [ failed("pkg:npm/a@1.0.0", "not_applied"), failed("pkg:npm/b@1.0.0", "vex_pnpm_bundled_copy"), ]; - assert!(nothing_attested_hint(&some) + assert!(nothing_attested_hint(&some, &[]) .unwrap() .starts_with("1 of the patched packages are not installed yet")); assert!( - nothing_attested_hint(&[failed("pkg:npm/a@1.0.0", "package_not_found")]) + nothing_attested_hint(&[failed("pkg:npm/a@1.0.0", "package_not_found")], &[]) .unwrap() .starts_with("The patched packages are not installed here.") ); assert_eq!( - nothing_attested_hint(&[failed("pkg:npm/a@1.0.0", "hash_mismatch")]), + nothing_attested_hint(&[failed("pkg:npm/a@1.0.0", "hash_mismatch")], &[]), None ); - assert_eq!(nothing_attested_hint(&[]), None); + assert_eq!(nothing_attested_hint(&[], &[]), None); + } + + /// #2219: Bundler keeps a gem it has installed whatever source the lock + /// names, so a hosted gem is never told to reinstall from the lockfile + /// (`bundle pristine` on Bundler 2.6+ removes the gems and then fails + /// on the lock's checksum). The remedy is the scan, which replaces the + /// installed copies. + #[test] + fn nothing_attested_sends_a_hosted_gem_to_the_scan_not_to_a_reinstall() { + let gems = [ + failed("pkg:gem/rack@2.2.8", "not_applied"), + failed("pkg:gem/rake@13.2.1", "not_applied"), + ]; + let hosted = [ + "pkg:gem/rack@2.2.8".to_string(), + "pkg:gem/rake@13.2.1".to_string(), + ]; + assert_eq!( + nothing_attested_hint(&gems, &hosted).as_deref(), + Some( + "The patched packages are hosted gems whose installed copies are still the \ + upstream builds. Bundler keeps a gem it has already installed, so `bundle \ + install`, `bundle install --redownload` and `bundle pristine` do not bring in \ + the patched gem. Run `socket-patch scan` here to replace the installed copies \ + (for a gem home outside the project, run `bundle config set --local path \ + vendor/bundle && bundle install` instead, or add `--gem-refresh-shared` to the \ + scan), then run `socket-patch vex` again." + ) + ); + + // A gem that agent mode patches, or a vendored one, keeps the + // general remedy: `apply` and a reinstall do work there. + let general = nothing_attested_hint(&gems, &[]).unwrap(); + assert!( + general.contains("Reinstall from the lockfile") && !general.contains("Bundler"), + "{general}" + ); + + // Both kinds in one project: each gets its own remedy and count, + // and `vex` is named once, at the end. + let mixed = [ + failed("pkg:gem/rack@2.2.8", "not_applied"), + failed("pkg:npm/a@1.0.0", "not_applied"), + failed("pkg:npm/b@1.0.0", "hash_mismatch"), + ]; + let hint = nothing_attested_hint(&mixed, &hosted[..1]).unwrap(); + assert!( + hint.starts_with("1 of the patched packages are not installed yet") + && hint.contains("Reinstall from the lockfile") + && hint.contains( + " 1 of the patched packages are hosted gems whose installed copies are \ + still the upstream builds." + ) + && hint.contains("Run `socket-patch scan` here"), + "{hint}" + ); + assert_eq!( + hint.matches("run `socket-patch vex` again").count(), + 1, + "{hint}" + ); + + // Only a copy that still holds the original files is one the scan + // replaces: a hosted gem that is not installed keeps its own hint. + assert!(nothing_attested_hint( + &[failed("pkg:gem/rack@2.2.8", "package_not_found")], + &hosted + ) + .unwrap() + .starts_with("The patched packages are not installed here.")); } #[test] diff --git a/crates/socket-patch-cli/tests/e2e_redirect_gem_stale_install.rs b/crates/socket-patch-cli/tests/e2e_redirect_gem_stale_install.rs index 51f6f58c3..7b36cdd89 100644 --- a/crates/socket-patch-cli/tests/e2e_redirect_gem_stale_install.rs +++ b/crates/socket-patch-cli/tests/e2e_redirect_gem_stale_install.rs @@ -2320,6 +2320,116 @@ async fn refresh_replaces_a_stale_project_install_and_its_archives() { ); } +/// #2219: the machine that did not run the scan. A teammate pulls the +/// hosted `Gemfile` / `Gemfile.lock` onto a checkout whose gems are already +/// installed (or CI restores a `vendor/bundle` cache): Bundler keeps the +/// upstream copy, and standalone `vex` is the one command that notices. +/// Its remedy must be one that works. "Reinstall from the lockfile" does +/// not: `bundle install` changes nothing, and `bundle pristine` on Bundler +/// 2.6+ removes the gems and then fails on the lock's checksum. So `vex` +/// names the scan, and the scan it names, with no `--mode`, replaces the +/// installed copy without touching the committed pair, after which `vex` +/// attests the gem. +#[tokio::test(flavor = "multi_thread")] +async fn standalone_vex_sends_a_stale_hosted_gem_to_the_scan_that_replaces_it() { + use vex_e2e_common::{assert_attested, assert_not_attested, run_vex, Marker, VexRun}; + let server = MockServer::start().await; + let patched = real_gem(PATCHED_LIB); + mount_api_for(&server, None, &sha256_of(&patched)).await; + serve_patched_gem(&server, patched.clone()).await; + let uri = server.uri(); + let tmp = tempfile::tempdir().unwrap(); + + // Machine A: scan and commit the pair. + let a = tmp.path().join("a"); + std::fs::create_dir_all(&a).unwrap(); + write_manifest_pair(&a); + let (code, _, stderr) = common::run_with_env(&a, &scan_args(&a, &uri, &[]), &[]); + assert_eq!(code, 0, "{stderr}"); + + // Machine B: the same commit over gems installed before it. + let proj = tmp.path().join("b"); + std::fs::create_dir_all(&proj).unwrap(); + for file in ["Gemfile", "Gemfile.lock"] { + std::fs::copy(a.join(file), proj.join(file)).unwrap(); + } + let pair = |proj: &Path| { + ["Gemfile", "Gemfile.lock"].map(|file| std::fs::read_to_string(proj.join(file)).unwrap()) + }; + let committed = pair(&proj); + assert!( + committed[1].contains("/patch-registry/gem/"), + "the lock pulled onto machine B names the patch registry:\n{}", + committed[1] + ); + let home = project_home(&proj); + let gem_dir = install_real_gem(&home, UPSTREAM_LIB); + + let bin = vex_e2e_common::binary(); + let run = |human: bool| VexRun { + api_url: Some(uri.clone()), + api_token: Some("fake".into()), + org: Some(ORG.into()), + patch_server_url: Some(uri.clone()), + product: Some("pkg:gem/app@1.0.0".into()), + human, + ..VexRun::default() + }; + let out = run_vex(&bin, &proj, &run(false)); + assert_eq!(out.code, Some(1), "{out}"); + assert_not_attested(&out.envelope, PURL, "not_applied"); + + let out = run_vex(&bin, &proj, &run(true)); + assert_eq!(out.code, Some(1), "{out}"); + assert!( + out.stderr.contains("Run `socket-patch scan` here") + && out.stderr.contains("`bundle pristine`") + && out.stderr.contains("--gem-refresh-shared"), + "the remedy for an installed hosted gem is the scan:\n{}", + out.stderr + ); + assert!( + !out.stderr.contains("Reinstall from the lockfile") + && !out.stderr.contains("socket-patch apply"), + "no remedy that leaves or breaks the install:\n{}", + out.stderr + ); + assert_eq!(installed_lib(&gem_dir), UPSTREAM_LIB, "vex writes nothing"); + + // The scan the hint names: no `--mode`, the project's own. + let args = [ + "scan", + "--yes", + "--cwd", + proj.to_str().expect("utf8 tmp path"), + "--api-url", + &uri, + "--org", + ORG, + "--api-token", + "fake", + ]; + let (code, stdout, stderr) = common::run_with_env(&proj, &args, &[]); + assert_eq!(code, 0, "stdout:\n{stdout}\nstderr:\n{stderr}"); + assert_eq!(installed_lib(&gem_dir), PATCHED_LIB, "{stdout}\n{stderr}"); + assert_eq!( + std::fs::read(home.join("cache").join(format!("{DEP}-{DEP_VERSION}.gem"))).unwrap(), + patched, + "the archive every reinstall uses is the patched one" + ); + assert_eq!(pair(&proj), committed, "the committed pair is untouched"); + + let out = run_vex(&bin, &proj, &run(false)); + assert_eq!(out.code, Some(0), "{out}"); + assert_attested( + out.doc(), + PURL, + UUID, + Marker::Redirected, + &[(GHSA, &["CVE-2026-4444"])], + ); +} + /// The machine's platform in the platform-build arm, and one the lock also /// names (another machine's). const PLATFORM: &str = "arm64-darwin"; diff --git a/docs/usage.md b/docs/usage.md index 313910088..d63d002a0 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -269,6 +269,13 @@ Error: No applied patches with vulnerability metadata to attest. The patched packages are not installed yet: the installed copies still hold their original files. Reinstall from the lockfile (hosted or vendored patches) or run `socket-patch apply` (agent-mode patches), then run `socket-patch vex` again. ``` +For a hosted gem the last line names `socket-patch scan` instead of a reinstall. +Bundler keeps a gem it has already installed, so a checkout that had its gems before +it pulled the hosted `Gemfile.lock` still runs the upstream copies, and +`bundle install`, `bundle install --redownload` and `bundle pristine` don't change +that. The scan replaces the installed copies; see +[Ruby gems: gems already installed](ecosystems.md#ruby-gems-gems-already-installed). + `--verbose` prints a line per patch, and `--json` reports each one as its own `skipped` event. Warnings of one kind are folded the same way: the first in full, then a line naming the packages the rest are about. From 3b0fe94c55bb9fab1502dea69b46511bc82f5fb9 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 17:46:37 +0000 Subject: [PATCH 3/6] Name the scan only where it replaces the gems Review of the previous commit found three gaps in the new hint. A scan with no --mode is a hosted one only in a project with no other patch state. With agent-mode patches in the manifest it stays in agent mode and replaces no gem, and beside a vendor ledger it stops with mode_ambiguous. The hint now asks the project's own mode resolution, and there it names the files to remove before bundle install, the remedy the stale-install warning already gives. A gem the manifest records as well as the lock keeps the general remedy: apply patches it in place. The hint said to run the scan "here", which is wrong for a vex run with --cwd. The word is gone. Assisted-by: Claude Code:claude-fable-5-2 Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_011f9aeQ4rKnRJHYWRr5aMyn --- crates/socket-patch-cli/CLI_CONTRACT.md | 2 +- crates/socket-patch-cli/src/commands/vex.rs | 230 ++++++++++++++---- .../tests/e2e_redirect_gem_stale_install.rs | 34 ++- docs/usage.md | 3 + 4 files changed, 223 insertions(+), 46 deletions(-) diff --git a/crates/socket-patch-cli/CLI_CONTRACT.md b/crates/socket-patch-cli/CLI_CONTRACT.md index 72f437714..eedba0202 100644 --- a/crates/socket-patch-cli/CLI_CONTRACT.md +++ b/crates/socket-patch-cli/CLI_CONTRACT.md @@ -3079,7 +3079,7 @@ The VEX document is JSON-LD, which collides with the standard `--json` envelope `--output -` means stdout (the first row). With `--dry-run`, a document bound for `--output` is built and verified but not written, a previous document at that path is left alone, the one-line summary reads `[dry-run] Would write OpenVEX document with N statements to `, and the envelope's `dryRun` is `true`. In every one-line summary the count reads `N statements (K affected)` when K of the statements say `affected`. A written file ends with a newline, like the stdout form. -When verification is enabled (the default) and a patch is omitted, the failed PURLs are surfaced on stderr in plain mode or as `skipped` events on the envelope in JSON mode (one per patch, sorted by PURL; `errorCode` is the tag). Plain mode prints one line per reason, largest first: `Warning: omitting 82 packages from VEX: the patched files still hold the original content (not_applied): @sigstore/core@1.1.0, @sigstore/core@2.0.0, @simple-git/argv-parser@1.1.1 and 79 more (--verbose lists them all)`; a reason with a single patch keeps the per-patch line `Warning: omitting from VEX: ()`, and `--verbose` prints that line for every patch. The run's advisories print before them, folded the same way: the first of each kind in full, then ` ... and 9 more like these: glob@10.4.5, glob@11.0.3, minimatch@3.1.2 and 6 more (--verbose lists them all)` (the packages are named where each advisory opens with one). When nothing could be attested, the `Error: No applied patches with vulnerability metadata to attest.` line is followed by the remedy for the patches that only need installing (`The patched packages are not installed yet: ... Reinstall from the lockfile (hosted or vendored patches) or run \`socket-patch apply\` (agent-mode patches), then run \`socket-patch vex\` again.`, or `N of the patched packages ...` when other reasons are among them). A hosted gem among them is not told to reinstall, since Bundler keeps a gem it has already installed and `bundle pristine` on Bundler 2.6+ removes the gems and then fails on the lock's checksum; its remedy is the scan that replaces the installed copy: `The patched packages are hosted gems whose installed copies are still the upstream builds. ... Run \`socket-patch scan\` here to replace the installed copies (for a gem home outside the project, run \`bundle config set --local path vendor/bundle && bundle install\` instead, or add \`--gem-refresh-shared\` to the scan), then run \`socket-patch vex\` again.` (see "Gem stale-install guard"). `--json` is unchanged: every advisory is its own `warnings[]` entry and every omission its own `skipped` event. Status becomes `partialFailure` when at least one patch was omitted but at least one was emitted. It is `partialFailure` too, with exit `0`, when a statement of the document says `affected`, also when every one does: `summary.verified` counts the packages attested as patched and no other. +When verification is enabled (the default) and a patch is omitted, the failed PURLs are surfaced on stderr in plain mode or as `skipped` events on the envelope in JSON mode (one per patch, sorted by PURL; `errorCode` is the tag). Plain mode prints one line per reason, largest first: `Warning: omitting 82 packages from VEX: the patched files still hold the original content (not_applied): @sigstore/core@1.1.0, @sigstore/core@2.0.0, @simple-git/argv-parser@1.1.1 and 79 more (--verbose lists them all)`; a reason with a single patch keeps the per-patch line `Warning: omitting from VEX: ()`, and `--verbose` prints that line for every patch. The run's advisories print before them, folded the same way: the first of each kind in full, then ` ... and 9 more like these: glob@10.4.5, glob@11.0.3, minimatch@3.1.2 and 6 more (--verbose lists them all)` (the packages are named where each advisory opens with one). When nothing could be attested, the `Error: No applied patches with vulnerability metadata to attest.` line is followed by the remedy for the patches that only need installing (`The patched packages are not installed yet: ... Reinstall from the lockfile (hosted or vendored patches) or run \`socket-patch apply\` (agent-mode patches), then run \`socket-patch vex\` again.`, or `N of the patched packages ...` when other reasons are among them). A hosted gem among them is not told to reinstall, since Bundler keeps a gem it has already installed and `bundle pristine` on Bundler 2.6+ removes the gems and then fails on the lock's checksum; its remedy is the scan that replaces the installed copy: `The patched packages are hosted gems whose installed copies are still the upstream builds. ... Run \`socket-patch scan\` to replace the installed copies (for a gem home outside the project, run \`bundle config set --local path vendor/bundle && bundle install\` instead, or add \`--gem-refresh-shared\` to the scan), then run \`socket-patch vex\` again.` (see "Gem stale-install guard"). Where a scan with no `--mode` is not a hosted one (the project also holds agent-mode or vendored patches), that sentence names the files to remove instead: `Remove each gem's \`specifications/-.gemspec\` and \`cache/-.gem\` from its gem home (and its archive in \`vendor/cache\`, if the project keeps one), run \`bundle install\`, then run \`socket-patch vex\` again.` A gem the manifest records keeps the general remedy, since `apply` patches it in place. `--json` is unchanged: every advisory is its own `warnings[]` entry and every omission its own `skipped` event. Status becomes `partialFailure` when at least one patch was omitted but at least one was emitted. It is `partialFailure` too, with exit `0`, when a statement of the document says `affected`, also when every one does: `summary.verified` counts the packages attested as patched and no other. ## Semver policy diff --git a/crates/socket-patch-cli/src/commands/vex.rs b/crates/socket-patch-cli/src/commands/vex.rs index 7308f880d..724263f96 100644 --- a/crates/socket-patch-cli/src/commands/vex.rs +++ b/crates/socket-patch-cli/src/commands/vex.rs @@ -337,7 +337,7 @@ pub(crate) struct VexGenError { pub failed: Vec, /// The purls in `failed` that a hosted pin wires. What gets such a /// package installed depends on its package manager (see - /// [`nothing_attested_hint`]). + /// [`StaleHostedGems`]). pub hosted: Vec, /// Advisories raised before the failure (already printed in human /// mode) — for `no_applicable_patches` often the only explanation of a @@ -518,7 +518,8 @@ pub async fn run(args: VexArgs) -> i32 { ), _ => (e.message, 2), }; - emit_envelope_error(&args, e.code, &message, &e.failed, &e.hosted, &run_warnings); + let gems = StaleHostedGems::among(&common, &manifest_path, &e.failed, &e.hosted).await; + emit_envelope_error(&args, e.code, &message, &e.failed, &gems, &run_warnings); if !args.common.json { below.print(); } @@ -2634,15 +2635,15 @@ async fn synthesize_go_patches( /// Emit a `vex` error to the active output channel: an error envelope on /// stdout in `--json` mode, a stderr message otherwise. `failures` lists /// patches omitted by verification (populated for `no_applicable_patches`, -/// empty everywhere else), `hosted` the ones of them a hosted pin wires; -/// `warnings` are the run's advisories, already on stderr in human mode, -/// folded into the envelope's `warnings[]` here. +/// empty everywhere else), `gems` the hosted gems among them that the hint +/// sends to the scan; `warnings` are the run's advisories, already on +/// stderr in human mode, folded into the envelope's `warnings[]` here. fn emit_envelope_error( args: &VexArgs, code: &str, message: &str, failures: &[FailedPatch], - hosted: &[String], + gems: &StaleHostedGems, warnings: &[RunWarning], ) { if args.common.json { @@ -2666,7 +2667,7 @@ fn emit_envelope_error( eprintln!(" omitted: {} ({})", f.purl, f.reason); } } else if let Some(hint) = - nothing_attested_hint(failures, hosted).filter(|_| code == "no_applicable_patches") + nothing_attested_hint(failures, gems).filter(|_| code == "no_applicable_patches") { eprintln!("{hint}"); } @@ -2830,17 +2831,70 @@ fn omission_lines(failed: &[FailedPatch], verbose: bool) -> Vec { .collect() } +/// The omitted gems whose installed copy no reinstall replaces: Bundler +/// keeps a gem it has already installed whatever source the lock names, +/// so after the lock moved to a hosted pin `bundle install` changes +/// nothing, and `bundle pristine` on Bundler 2.6+ removes the gems and +/// then fails on the lock's checksum (#2219). The hosted scan is what +/// replaces such a copy. +#[derive(Debug, Default)] +struct StaleHostedGems { + /// The purls omitted as `not_applied` that are gems on a hosted pin + /// with no manifest record (`apply` patches a recorded one in place). + purls: Vec, + /// Whether a `scan` with no `--mode` runs in hosted mode here, the one + /// mode that replaces the copies. It does not where the project also + /// holds agent-mode or vendored patches: the bare scan then keeps that + /// mode or stops with `mode_ambiguous`, and `--mode hosted` would move + /// those patches over, so the hint names the files to remove instead. + bare_scan_is_hosted: bool, +} + +impl StaleHostedGems { + /// Those among `failed`, of which `hosted` are on a hosted pin. The + /// project's state is read only when there is such a gem. + async fn among( + common: &GlobalArgs, + manifest_path: &Path, + failed: &[FailedPatch], + hosted: &[String], + ) -> Self { + let mut purls: Vec = failed + .iter() + .filter(|f| { + f.reason == "not_applied" + && f.purl.starts_with("pkg:gem/") + && hosted.contains(&f.purl) + }) + .map(|f| f.purl.clone()) + .collect(); + if purls.is_empty() { + return Self::default(); + } + if let Ok(Some(manifest)) = + socket_patch_core::manifest::operations::read_manifest(manifest_path).await + { + purls.retain(|purl| !manifest.patches.contains_key(purl)); + } + let bare_scan_is_hosted = !purls.is_empty() + && !common.is_global() + && matches!( + crate::commands::mode_from_project_state(common).await, + Ok(crate::commands::scan::ScanMode::Hosted) + ); + Self { + purls, + bare_scan_is_hosted, + } + } +} + /// What to do about a document nothing could go into, said under the /// error, when patches were left out for a reason with a remedy: the /// patched packages are not installed yet (the usual case right after a -/// hosted or vendored scan), or not installed at all. -/// -/// `hosted` names the purls a hosted pin wires. A gem among them gets its -/// own remedy: Bundler keeps a gem it has already installed whatever -/// source the lock names, so no reinstall brings the patched gem in (and -/// `bundle pristine` on Bundler 2.6+ removes the gems, then fails on the -/// lock's checksum). The hosted scan is what replaces the installed copy. -fn nothing_attested_hint(failed: &[FailedPatch], hosted: &[String]) -> Option { +/// hosted or vendored scan), or not installed at all. The `gems` among +/// them get their own remedy, since no reinstall works for them. +fn nothing_attested_hint(failed: &[FailedPatch], gems: &StaleHostedGems) -> Option { let of = |n: usize| { if n == failed.len() { "The".to_string() @@ -2849,8 +2903,8 @@ fn nothing_attested_hint(failed: &[FailedPatch], hosted: &[String]) -> Option, Vec<_>) = - not_applied.partition(|f| f.purl.starts_with("pkg:gem/") && hosted.contains(&f.purl)); + let (gem_copies, others): (Vec<_>, Vec<_>) = + not_applied.partition(|f| gems.purls.contains(&f.purl)); let mut remedies = Vec::new(); if !others.is_empty() { remedies.push(format!( @@ -2860,15 +2914,25 @@ fn nothing_attested_hint(failed: &[FailedPatch], hosted: &[String]) -> Option-.gemspec` and \ + `cache/-.gem` from its gem home (and its archive in `vendor/cache`, \ + if the project keeps one), run `bundle install`" + .to_string() + }; remedies.push(format!( "{} patched packages are hosted gems whose installed copies are still the upstream \ builds. Bundler keeps a gem it has already installed, so `bundle install`, `bundle \ - install --redownload` and `bundle pristine` do not bring in the patched gem. Run \ - `socket-patch scan` here to replace the installed copies (for a gem home outside \ - the project, run `{}` instead, or add `--gem-refresh-shared` to the scan)", - of(gems.len()), - crate::commands::gem_refresh::LOCAL_PATH_REMEDY + install --redownload` and `bundle pristine` do not bring in the patched gem. {remedy}", + of(gem_copies.len()), )); } if !remedies.is_empty() { @@ -3213,30 +3277,28 @@ mod tests { hold their original files. Reinstall from the lockfile (hosted or \ vendored patches) or run `socket-patch apply` (agent-mode patches), \ then run `socket-patch vex` again."; - assert_eq!(nothing_attested_hint(&all, &[]).as_deref(), Some(reinstall)); - // A hosted pin of any other package manager installs from the lock. - let hosted = ["pkg:npm/a@1.0.0".to_string(), "pkg:npm/b@1.0.0".to_string()]; + let none = StaleHostedGems::default(); assert_eq!( - nothing_attested_hint(&all, &hosted).as_deref(), + nothing_attested_hint(&all, &none).as_deref(), Some(reinstall) ); let some = [ failed("pkg:npm/a@1.0.0", "not_applied"), failed("pkg:npm/b@1.0.0", "vex_pnpm_bundled_copy"), ]; - assert!(nothing_attested_hint(&some, &[]) + assert!(nothing_attested_hint(&some, &none) .unwrap() .starts_with("1 of the patched packages are not installed yet")); assert!( - nothing_attested_hint(&[failed("pkg:npm/a@1.0.0", "package_not_found")], &[]) + nothing_attested_hint(&[failed("pkg:npm/a@1.0.0", "package_not_found")], &none) .unwrap() .starts_with("The patched packages are not installed here.") ); assert_eq!( - nothing_attested_hint(&[failed("pkg:npm/a@1.0.0", "hash_mismatch")], &[]), + nothing_attested_hint(&[failed("pkg:npm/a@1.0.0", "hash_mismatch")], &none), None ); - assert_eq!(nothing_attested_hint(&[], &[]), None); + assert_eq!(nothing_attested_hint(&[], &none), None); } /// #2219: Bundler keeps a gem it has installed whatever source the lock @@ -3250,26 +3312,45 @@ mod tests { failed("pkg:gem/rack@2.2.8", "not_applied"), failed("pkg:gem/rake@13.2.1", "not_applied"), ]; - let hosted = [ - "pkg:gem/rack@2.2.8".to_string(), - "pkg:gem/rake@13.2.1".to_string(), - ]; + let stale = |purls: &[&str], bare_scan_is_hosted| StaleHostedGems { + purls: purls.iter().map(|purl| purl.to_string()).collect(), + bare_scan_is_hosted, + }; + let both = ["pkg:gem/rack@2.2.8", "pkg:gem/rake@13.2.1"]; assert_eq!( - nothing_attested_hint(&gems, &hosted).as_deref(), + nothing_attested_hint(&gems, &stale(&both, true)).as_deref(), Some( "The patched packages are hosted gems whose installed copies are still the \ upstream builds. Bundler keeps a gem it has already installed, so `bundle \ install`, `bundle install --redownload` and `bundle pristine` do not bring in \ - the patched gem. Run `socket-patch scan` here to replace the installed copies \ - (for a gem home outside the project, run `bundle config set --local path \ + the patched gem. Run `socket-patch scan` to replace the installed copies (for \ + a gem home outside the project, run `bundle config set --local path \ vendor/bundle && bundle install` instead, or add `--gem-refresh-shared` to the \ scan), then run `socket-patch vex` again." ) ); - // A gem that agent mode patches, or a vendored one, keeps the - // general remedy: `apply` and a reinstall do work there. - let general = nothing_attested_hint(&gems, &[]).unwrap(); + // Where a scan with no `--mode` is not a hosted one (the project + // holds agent-mode or vendored patches too), the hint names no + // scan: it would not replace the copies, or would need a `--mode` + // that moves the other patches. + assert_eq!( + nothing_attested_hint(&gems, &stale(&both, false)).as_deref(), + Some( + "The patched packages are hosted gems whose installed copies are still the \ + upstream builds. Bundler keeps a gem it has already installed, so `bundle \ + install`, `bundle install --redownload` and `bundle pristine` do not bring in \ + the patched gem. Remove each gem's `specifications/-.gemspec` \ + and `cache/-.gem` from its gem home (and its archive in \ + `vendor/cache`, if the project keeps one), run `bundle install`, then run \ + `socket-patch vex` again." + ) + ); + + // A gem that is not among them (agent mode patches it, or it is + // vendored) keeps the general remedy: `apply` and a reinstall do + // work there. + let general = nothing_attested_hint(&gems, &StaleHostedGems::default()).unwrap(); assert!( general.contains("Reinstall from the lockfile") && !general.contains("Bundler"), "{general}" @@ -3282,7 +3363,7 @@ mod tests { failed("pkg:npm/a@1.0.0", "not_applied"), failed("pkg:npm/b@1.0.0", "hash_mismatch"), ]; - let hint = nothing_attested_hint(&mixed, &hosted[..1]).unwrap(); + let hint = nothing_attested_hint(&mixed, &stale(&both[..1], true)).unwrap(); assert!( hint.starts_with("1 of the patched packages are not installed yet") && hint.contains("Reinstall from the lockfile") @@ -3290,7 +3371,7 @@ mod tests { " 1 of the patched packages are hosted gems whose installed copies are \ still the upstream builds." ) - && hint.contains("Run `socket-patch scan` here"), + && hint.contains("Run `socket-patch scan` to replace"), "{hint}" ); assert_eq!( @@ -3303,12 +3384,73 @@ mod tests { // replaces: a hosted gem that is not installed keeps its own hint. assert!(nothing_attested_hint( &[failed("pkg:gem/rack@2.2.8", "package_not_found")], - &hosted + &stale(&both, true) ) .unwrap() .starts_with("The patched packages are not installed here.")); } + /// Which omitted packages are stale hosted gems, and whether the scan + /// with no `--mode` is the one that replaces them. + #[tokio::test] + async fn stale_hosted_gems_are_the_unrecorded_gems_on_a_hosted_pin() { + let tmp = tempfile::tempdir().unwrap(); + let common = GlobalArgs { + cwd: tmp.path().to_path_buf(), + no_telemetry: true, + ..GlobalArgs::default() + }; + let manifest_path = common.resolved_manifest_path(); + let failures = [ + failed("pkg:gem/rack@2.2.8", "not_applied"), + failed("pkg:gem/rake@13.2.1", "not_applied"), + failed("pkg:gem/json@2.7.0", "hash_mismatch"), + failed("pkg:npm/a@1.0.0", "not_applied"), + ]; + let hosted: Vec = [ + "pkg:gem/rack@2.2.8", + "pkg:gem/json@2.7.0", + "pkg:npm/a@1.0.0", + ] + .map(String::from) + .to_vec(); + + // No patch state beside the lock: a bare scan is a hosted one. + let gems = StaleHostedGems::among(&common, &manifest_path, &failures, &hosted).await; + assert_eq!(gems.purls, ["pkg:gem/rack@2.2.8"]); + assert!(gems.bare_scan_is_hosted); + + // No such gem: nothing of the project is read. + let gems = StaleHostedGems::among(&common, &manifest_path, &failures, &[]).await; + assert!(gems.purls.is_empty() && !gems.bare_scan_is_hosted); + + // An agent-mode record of another package: the bare scan keeps + // agent mode, which replaces no gem. + let record = |purl: &str| { + serde_json::json!({ "patches": { purl: { + "uuid": "11111111-1111-4111-8111-111111111111", + "exportedAt": "2026-01-01T00:00:00Z", + "files": {}, + "vulnerabilities": {}, + "description": "", + "license": "MIT", + "tier": "free", + }}}) + .to_string() + }; + std::fs::create_dir_all(manifest_path.parent().unwrap()).unwrap(); + std::fs::write(&manifest_path, record("pkg:npm/b@1.0.0")).unwrap(); + let gems = StaleHostedGems::among(&common, &manifest_path, &failures, &hosted).await; + assert_eq!(gems.purls, ["pkg:gem/rack@2.2.8"]); + assert!(!gems.bare_scan_is_hosted); + + // A record of the gem itself: `apply` patches it in place, so it + // keeps the general remedy. + std::fs::write(&manifest_path, record("pkg:gem/rack@2.2.8")).unwrap(); + let gems = StaleHostedGems::among(&common, &manifest_path, &failures, &hosted).await; + assert!(gems.purls.is_empty() && !gems.bare_scan_is_hosted); + } + #[test] fn omission_warning_names_phrase_and_tag() { assert_eq!( diff --git a/crates/socket-patch-cli/tests/e2e_redirect_gem_stale_install.rs b/crates/socket-patch-cli/tests/e2e_redirect_gem_stale_install.rs index 7b36cdd89..9bf15bc54 100644 --- a/crates/socket-patch-cli/tests/e2e_redirect_gem_stale_install.rs +++ b/crates/socket-patch-cli/tests/e2e_redirect_gem_stale_install.rs @@ -2382,7 +2382,8 @@ async fn standalone_vex_sends_a_stale_hosted_gem_to_the_scan_that_replaces_it() let out = run_vex(&bin, &proj, &run(true)); assert_eq!(out.code, Some(1), "{out}"); assert!( - out.stderr.contains("Run `socket-patch scan` here") + out.stderr + .contains("Run `socket-patch scan` to replace the installed copies") && out.stderr.contains("`bundle pristine`") && out.stderr.contains("--gem-refresh-shared"), "the remedy for an installed hosted gem is the scan:\n{}", @@ -2396,6 +2397,37 @@ async fn standalone_vex_sends_a_stale_hosted_gem_to_the_scan_that_replaces_it() ); assert_eq!(installed_lib(&gem_dir), UPSTREAM_LIB, "vex writes nothing"); + // The same checkout with an agent-mode patch of another package: a + // scan with no `--mode` keeps agent mode there and replaces no gem, so + // the hint names the files to remove, not a scan. + let mixed = tmp.path().join("mixed"); + std::fs::create_dir_all(&mixed).unwrap(); + for file in ["Gemfile", "Gemfile.lock"] { + std::fs::copy(a.join(file), mixed.join(file)).unwrap(); + } + install_real_gem(&project_home(&mixed), UPSTREAM_LIB); + common::write_minimal_manifest( + &mixed.join(".socket"), + "pkg:npm/left-pad@1.3.0", + "22222222-2222-4222-8222-222222222222", + &[], + ); + let out = run_vex(&bin, &mixed, &run(true)); + assert_eq!(out.code, Some(1), "{out}"); + assert!( + out.stderr + .contains("Remove each gem's `specifications/-.gemspec`") + && out.stderr.contains("run `bundle install`, then run"), + "a mixed-mode project is told which files to remove:\n{}", + out.stderr + ); + assert!( + !out.stderr.contains("Run `socket-patch scan`") + && !out.stderr.contains("Reinstall from the lockfile"), + "no scan that would keep agent mode, and no reinstall:\n{}", + out.stderr + ); + // The scan the hint names: no `--mode`, the project's own. let args = [ "scan", diff --git a/docs/usage.md b/docs/usage.md index d63d002a0..83c856860 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -275,6 +275,9 @@ it pulled the hosted `Gemfile.lock` still runs the upstream copies, and `bundle install`, `bundle install --redownload` and `bundle pristine` don't change that. The scan replaces the installed copies; see [Ruby gems: gems already installed](ecosystems.md#ruby-gems-gems-already-installed). +In a project that also holds agent-mode or vendored patches, where a scan with no +`--mode` is not a hosted one, the line names the files to remove before +`bundle install` instead. `--verbose` prints a line per patch, and `--json` reports each one as its own `skipped` event. Warnings of one kind are folded the same way: the first in full, From b27da91bf2f77f2e1562cefb8d5dc3f11ac71c6d Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 17:53:21 +0000 Subject: [PATCH 4/6] Ask commands for the bare scan's mode from vex The command_module_layering test failed in CI: vex named scan::ScanMode to ask whether a scan with no --mode is a hosted one, which adds a vex -> scan edge and closes a cycle through apply and agent_download. The question moves to commands::bare_scan_is_hosted, beside bare_scan_looks_below, so vex imports no command module for it. Assisted-by: Claude Code:claude-fable-5-2 Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_011f9aeQ4rKnRJHYWRr5aMyn --- crates/socket-patch-cli/src/commands/mod.rs | 10 ++++++++++ crates/socket-patch-cli/src/commands/vex.rs | 5 +---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/crates/socket-patch-cli/src/commands/mod.rs b/crates/socket-patch-cli/src/commands/mod.rs index 28177a3eb..17a348753 100644 --- a/crates/socket-patch-cli/src/commands/mod.rs +++ b/crates/socket-patch-cli/src/commands/mod.rs @@ -194,6 +194,16 @@ pub(crate) async fn bare_scan_looks_below(common: &crate::args::GlobalArgs) -> b ) } +/// Whether a bare `scan` at `--cwd` runs in hosted mode: the project's own +/// state records no other mode ([`mode_from_project_state`]). Only a +/// hosted scan replaces the stale installed copy of a hosted gem. +pub(crate) async fn bare_scan_is_hosted(common: &crate::args::GlobalArgs) -> bool { + matches!( + mode_from_project_state(common).await, + Ok(scan::ScanMode::Hosted) + ) +} + /// The mode a `scan`/`get` run with no `--mode` uses for the project /// (CLI_CONTRACT.md, Mode resolution): the mode the project's own patch /// state already records, so a bare run never converts the project to diff --git a/crates/socket-patch-cli/src/commands/vex.rs b/crates/socket-patch-cli/src/commands/vex.rs index 724263f96..caba0f041 100644 --- a/crates/socket-patch-cli/src/commands/vex.rs +++ b/crates/socket-patch-cli/src/commands/vex.rs @@ -2878,10 +2878,7 @@ impl StaleHostedGems { } let bare_scan_is_hosted = !purls.is_empty() && !common.is_global() - && matches!( - crate::commands::mode_from_project_state(common).await, - Ok(crate::commands::scan::ScanMode::Hosted) - ); + && crate::commands::bare_scan_is_hosted(common).await; Self { purls, bare_scan_is_hosted, From 79e8f077b2cfe6f07298066291c5f2fcdab01c26 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 17:54:40 +0000 Subject: [PATCH 5/6] Warn about a shared gem home in the manual remedy Bugbot review: where a scan with no --mode is not a hosted one, the hint names the files to remove before bundle install, but it did not say what that does in a gem home outside the project. Bundler then installs the patched gem there, where other projects may load it. The sentence now names the project-local install for that case, as the scan branch of the same hint does. Assisted-by: Claude Code:claude-fable-5-2 Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_011f9aeQ4rKnRJHYWRr5aMyn --- crates/socket-patch-cli/CLI_CONTRACT.md | 2 +- crates/socket-patch-cli/src/commands/vex.rs | 15 ++++++++++----- .../tests/e2e_redirect_gem_stale_install.rs | 5 ++++- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/crates/socket-patch-cli/CLI_CONTRACT.md b/crates/socket-patch-cli/CLI_CONTRACT.md index eedba0202..330db515e 100644 --- a/crates/socket-patch-cli/CLI_CONTRACT.md +++ b/crates/socket-patch-cli/CLI_CONTRACT.md @@ -3079,7 +3079,7 @@ The VEX document is JSON-LD, which collides with the standard `--json` envelope `--output -` means stdout (the first row). With `--dry-run`, a document bound for `--output` is built and verified but not written, a previous document at that path is left alone, the one-line summary reads `[dry-run] Would write OpenVEX document with N statements to `, and the envelope's `dryRun` is `true`. In every one-line summary the count reads `N statements (K affected)` when K of the statements say `affected`. A written file ends with a newline, like the stdout form. -When verification is enabled (the default) and a patch is omitted, the failed PURLs are surfaced on stderr in plain mode or as `skipped` events on the envelope in JSON mode (one per patch, sorted by PURL; `errorCode` is the tag). Plain mode prints one line per reason, largest first: `Warning: omitting 82 packages from VEX: the patched files still hold the original content (not_applied): @sigstore/core@1.1.0, @sigstore/core@2.0.0, @simple-git/argv-parser@1.1.1 and 79 more (--verbose lists them all)`; a reason with a single patch keeps the per-patch line `Warning: omitting from VEX: ()`, and `--verbose` prints that line for every patch. The run's advisories print before them, folded the same way: the first of each kind in full, then ` ... and 9 more like these: glob@10.4.5, glob@11.0.3, minimatch@3.1.2 and 6 more (--verbose lists them all)` (the packages are named where each advisory opens with one). When nothing could be attested, the `Error: No applied patches with vulnerability metadata to attest.` line is followed by the remedy for the patches that only need installing (`The patched packages are not installed yet: ... Reinstall from the lockfile (hosted or vendored patches) or run \`socket-patch apply\` (agent-mode patches), then run \`socket-patch vex\` again.`, or `N of the patched packages ...` when other reasons are among them). A hosted gem among them is not told to reinstall, since Bundler keeps a gem it has already installed and `bundle pristine` on Bundler 2.6+ removes the gems and then fails on the lock's checksum; its remedy is the scan that replaces the installed copy: `The patched packages are hosted gems whose installed copies are still the upstream builds. ... Run \`socket-patch scan\` to replace the installed copies (for a gem home outside the project, run \`bundle config set --local path vendor/bundle && bundle install\` instead, or add \`--gem-refresh-shared\` to the scan), then run \`socket-patch vex\` again.` (see "Gem stale-install guard"). Where a scan with no `--mode` is not a hosted one (the project also holds agent-mode or vendored patches), that sentence names the files to remove instead: `Remove each gem's \`specifications/-.gemspec\` and \`cache/-.gem\` from its gem home (and its archive in \`vendor/cache\`, if the project keeps one), run \`bundle install\`, then run \`socket-patch vex\` again.` A gem the manifest records keeps the general remedy, since `apply` patches it in place. `--json` is unchanged: every advisory is its own `warnings[]` entry and every omission its own `skipped` event. Status becomes `partialFailure` when at least one patch was omitted but at least one was emitted. It is `partialFailure` too, with exit `0`, when a statement of the document says `affected`, also when every one does: `summary.verified` counts the packages attested as patched and no other. +When verification is enabled (the default) and a patch is omitted, the failed PURLs are surfaced on stderr in plain mode or as `skipped` events on the envelope in JSON mode (one per patch, sorted by PURL; `errorCode` is the tag). Plain mode prints one line per reason, largest first: `Warning: omitting 82 packages from VEX: the patched files still hold the original content (not_applied): @sigstore/core@1.1.0, @sigstore/core@2.0.0, @simple-git/argv-parser@1.1.1 and 79 more (--verbose lists them all)`; a reason with a single patch keeps the per-patch line `Warning: omitting from VEX: ()`, and `--verbose` prints that line for every patch. The run's advisories print before them, folded the same way: the first of each kind in full, then ` ... and 9 more like these: glob@10.4.5, glob@11.0.3, minimatch@3.1.2 and 6 more (--verbose lists them all)` (the packages are named where each advisory opens with one). When nothing could be attested, the `Error: No applied patches with vulnerability metadata to attest.` line is followed by the remedy for the patches that only need installing (`The patched packages are not installed yet: ... Reinstall from the lockfile (hosted or vendored patches) or run \`socket-patch apply\` (agent-mode patches), then run \`socket-patch vex\` again.`, or `N of the patched packages ...` when other reasons are among them). A hosted gem among them is not told to reinstall, since Bundler keeps a gem it has already installed and `bundle pristine` on Bundler 2.6+ removes the gems and then fails on the lock's checksum; its remedy is the scan that replaces the installed copy: `The patched packages are hosted gems whose installed copies are still the upstream builds. ... Run \`socket-patch scan\` to replace the installed copies (for a gem home outside the project, run \`bundle config set --local path vendor/bundle && bundle install\` instead, or add \`--gem-refresh-shared\` to the scan), then run \`socket-patch vex\` again.` (see "Gem stale-install guard"). Where a scan with no `--mode` is not a hosted one (the project also holds agent-mode or vendored patches), that sentence names the files to remove instead: `Remove each gem's \`specifications/-.gemspec\` and \`cache/-.gem\` from its gem home (and its archive in \`vendor/cache\`, if the project keeps one) and run \`bundle install\`. Other projects may load a gem home outside the project, so for one run \`bundle config set --local path vendor/bundle && bundle install\` instead, then run \`socket-patch vex\` again.` A gem the manifest records keeps the general remedy, since `apply` patches it in place. `--json` is unchanged: every advisory is its own `warnings[]` entry and every omission its own `skipped` event. Status becomes `partialFailure` when at least one patch was omitted but at least one was emitted. It is `partialFailure` too, with exit `0`, when a statement of the document says `affected`, also when every one does: `summary.verified` counts the packages attested as patched and no other. ## Semver policy diff --git a/crates/socket-patch-cli/src/commands/vex.rs b/crates/socket-patch-cli/src/commands/vex.rs index caba0f041..c5eabebe4 100644 --- a/crates/socket-patch-cli/src/commands/vex.rs +++ b/crates/socket-patch-cli/src/commands/vex.rs @@ -2920,10 +2920,13 @@ fn nothing_attested_hint(failed: &[FailedPatch], gems: &StaleHostedGems) -> Opti crate::commands::gem_refresh::LOCAL_PATH_REMEDY ) } else { - "Remove each gem's `specifications/-.gemspec` and \ - `cache/-.gem` from its gem home (and its archive in `vendor/cache`, \ - if the project keeps one), run `bundle install`" - .to_string() + format!( + "Remove each gem's `specifications/-.gemspec` and \ + `cache/-.gem` from its gem home (and its archive in \ + `vendor/cache`, if the project keeps one) and run `bundle install`. Other \ + projects may load a gem home outside the project, so for one run `{}` instead", + crate::commands::gem_refresh::LOCAL_PATH_REMEDY + ) }; remedies.push(format!( "{} patched packages are hosted gems whose installed copies are still the upstream \ @@ -3339,7 +3342,9 @@ mod tests { install`, `bundle install --redownload` and `bundle pristine` do not bring in \ the patched gem. Remove each gem's `specifications/-.gemspec` \ and `cache/-.gem` from its gem home (and its archive in \ - `vendor/cache`, if the project keeps one), run `bundle install`, then run \ + `vendor/cache`, if the project keeps one) and run `bundle install`. Other \ + projects may load a gem home outside the project, so for one run `bundle \ + config set --local path vendor/bundle && bundle install` instead, then run \ `socket-patch vex` again." ) ); diff --git a/crates/socket-patch-cli/tests/e2e_redirect_gem_stale_install.rs b/crates/socket-patch-cli/tests/e2e_redirect_gem_stale_install.rs index 9bf15bc54..fc64264a5 100644 --- a/crates/socket-patch-cli/tests/e2e_redirect_gem_stale_install.rs +++ b/crates/socket-patch-cli/tests/e2e_redirect_gem_stale_install.rs @@ -2417,7 +2417,10 @@ async fn standalone_vex_sends_a_stale_hosted_gem_to_the_scan_that_replaces_it() assert!( out.stderr .contains("Remove each gem's `specifications/-.gemspec`") - && out.stderr.contains("run `bundle install`, then run"), + && out.stderr.contains( + "Other projects may load a gem home outside the project, so for one run \ + `bundle config set --local path vendor/bundle && bundle install` instead", + ), "a mixed-mode project is told which files to remove:\n{}", out.stderr ); From e77fac968d43e858765a7916862e87688c011ebd Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 15:32:43 +0000 Subject: [PATCH 6/6] Keep the gem remedy over a superseded record Review note: a gem the manifest records was always left to the general remedy, which names socket-patch apply. That is right only when the record is the patch the hosted pin delivers. Where the pin superseded an agent-mode record of another patch, apply installs the old patch's files and vex still cannot attest the pin's. The hint now carries each hosted pin's patch uuid and exempts a gem only when the manifest record has the same one. Assisted-by: Claude Code:claude-fable-5-2 Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_011f9aeQ4rKnRJHYWRr5aMyn --- crates/socket-patch-cli/CLI_CONTRACT.md | 2 +- crates/socket-patch-cli/src/commands/vex.rs | 77 +++++++++++++-------- 2 files changed, 51 insertions(+), 28 deletions(-) diff --git a/crates/socket-patch-cli/CLI_CONTRACT.md b/crates/socket-patch-cli/CLI_CONTRACT.md index 330db515e..4548d78be 100644 --- a/crates/socket-patch-cli/CLI_CONTRACT.md +++ b/crates/socket-patch-cli/CLI_CONTRACT.md @@ -3079,7 +3079,7 @@ The VEX document is JSON-LD, which collides with the standard `--json` envelope `--output -` means stdout (the first row). With `--dry-run`, a document bound for `--output` is built and verified but not written, a previous document at that path is left alone, the one-line summary reads `[dry-run] Would write OpenVEX document with N statements to `, and the envelope's `dryRun` is `true`. In every one-line summary the count reads `N statements (K affected)` when K of the statements say `affected`. A written file ends with a newline, like the stdout form. -When verification is enabled (the default) and a patch is omitted, the failed PURLs are surfaced on stderr in plain mode or as `skipped` events on the envelope in JSON mode (one per patch, sorted by PURL; `errorCode` is the tag). Plain mode prints one line per reason, largest first: `Warning: omitting 82 packages from VEX: the patched files still hold the original content (not_applied): @sigstore/core@1.1.0, @sigstore/core@2.0.0, @simple-git/argv-parser@1.1.1 and 79 more (--verbose lists them all)`; a reason with a single patch keeps the per-patch line `Warning: omitting from VEX: ()`, and `--verbose` prints that line for every patch. The run's advisories print before them, folded the same way: the first of each kind in full, then ` ... and 9 more like these: glob@10.4.5, glob@11.0.3, minimatch@3.1.2 and 6 more (--verbose lists them all)` (the packages are named where each advisory opens with one). When nothing could be attested, the `Error: No applied patches with vulnerability metadata to attest.` line is followed by the remedy for the patches that only need installing (`The patched packages are not installed yet: ... Reinstall from the lockfile (hosted or vendored patches) or run \`socket-patch apply\` (agent-mode patches), then run \`socket-patch vex\` again.`, or `N of the patched packages ...` when other reasons are among them). A hosted gem among them is not told to reinstall, since Bundler keeps a gem it has already installed and `bundle pristine` on Bundler 2.6+ removes the gems and then fails on the lock's checksum; its remedy is the scan that replaces the installed copy: `The patched packages are hosted gems whose installed copies are still the upstream builds. ... Run \`socket-patch scan\` to replace the installed copies (for a gem home outside the project, run \`bundle config set --local path vendor/bundle && bundle install\` instead, or add \`--gem-refresh-shared\` to the scan), then run \`socket-patch vex\` again.` (see "Gem stale-install guard"). Where a scan with no `--mode` is not a hosted one (the project also holds agent-mode or vendored patches), that sentence names the files to remove instead: `Remove each gem's \`specifications/-.gemspec\` and \`cache/-.gem\` from its gem home (and its archive in \`vendor/cache\`, if the project keeps one) and run \`bundle install\`. Other projects may load a gem home outside the project, so for one run \`bundle config set --local path vendor/bundle && bundle install\` instead, then run \`socket-patch vex\` again.` A gem the manifest records keeps the general remedy, since `apply` patches it in place. `--json` is unchanged: every advisory is its own `warnings[]` entry and every omission its own `skipped` event. Status becomes `partialFailure` when at least one patch was omitted but at least one was emitted. It is `partialFailure` too, with exit `0`, when a statement of the document says `affected`, also when every one does: `summary.verified` counts the packages attested as patched and no other. +When verification is enabled (the default) and a patch is omitted, the failed PURLs are surfaced on stderr in plain mode or as `skipped` events on the envelope in JSON mode (one per patch, sorted by PURL; `errorCode` is the tag). Plain mode prints one line per reason, largest first: `Warning: omitting 82 packages from VEX: the patched files still hold the original content (not_applied): @sigstore/core@1.1.0, @sigstore/core@2.0.0, @simple-git/argv-parser@1.1.1 and 79 more (--verbose lists them all)`; a reason with a single patch keeps the per-patch line `Warning: omitting from VEX: ()`, and `--verbose` prints that line for every patch. The run's advisories print before them, folded the same way: the first of each kind in full, then ` ... and 9 more like these: glob@10.4.5, glob@11.0.3, minimatch@3.1.2 and 6 more (--verbose lists them all)` (the packages are named where each advisory opens with one). When nothing could be attested, the `Error: No applied patches with vulnerability metadata to attest.` line is followed by the remedy for the patches that only need installing (`The patched packages are not installed yet: ... Reinstall from the lockfile (hosted or vendored patches) or run \`socket-patch apply\` (agent-mode patches), then run \`socket-patch vex\` again.`, or `N of the patched packages ...` when other reasons are among them). A hosted gem among them is not told to reinstall, since Bundler keeps a gem it has already installed and `bundle pristine` on Bundler 2.6+ removes the gems and then fails on the lock's checksum; its remedy is the scan that replaces the installed copy: `The patched packages are hosted gems whose installed copies are still the upstream builds. ... Run \`socket-patch scan\` to replace the installed copies (for a gem home outside the project, run \`bundle config set --local path vendor/bundle && bundle install\` instead, or add \`--gem-refresh-shared\` to the scan), then run \`socket-patch vex\` again.` (see "Gem stale-install guard"). Where a scan with no `--mode` is not a hosted one (the project also holds agent-mode or vendored patches), that sentence names the files to remove instead: `Remove each gem's \`specifications/-.gemspec\` and \`cache/-.gem\` from its gem home (and its archive in \`vendor/cache\`, if the project keeps one) and run \`bundle install\`. Other projects may load a gem home outside the project, so for one run \`bundle config set --local path vendor/bundle && bundle install\` instead, then run \`socket-patch vex\` again.` A gem the manifest records under the same patch as the hosted pin keeps the general remedy, since `apply` patches it in place; a record of another patch, which the pin superseded, does not. `--json` is unchanged: every advisory is its own `warnings[]` entry and every omission its own `skipped` event. Status becomes `partialFailure` when at least one patch was omitted but at least one was emitted. It is `partialFailure` too, with exit `0`, when a statement of the document says `affected`, also when every one does: `summary.verified` counts the packages attested as patched and no other. ## Semver policy diff --git a/crates/socket-patch-cli/src/commands/vex.rs b/crates/socket-patch-cli/src/commands/vex.rs index c5eabebe4..ca33bd151 100644 --- a/crates/socket-patch-cli/src/commands/vex.rs +++ b/crates/socket-patch-cli/src/commands/vex.rs @@ -335,10 +335,10 @@ pub(crate) struct VexGenError { /// Patches omitted by verification, populated only for the /// `no_applicable_patches` case (so callers can list them). pub failed: Vec, - /// The purls in `failed` that a hosted pin wires. What gets such a - /// package installed depends on its package manager (see - /// [`StaleHostedGems`]). - pub hosted: Vec, + /// The purls in `failed` that a hosted pin wires, each with the uuid + /// of the patch the pin delivers. What gets such a package installed + /// depends on its package manager (see [`StaleHostedGems`]). + pub hosted: Vec<(String, String)>, /// Advisories raised before the failure (already printed in human /// mode) — for `no_applicable_patches` often the only explanation of a /// `vendor_unwired` / `redirect_unwired` omission (the lockfile-discovery @@ -1477,8 +1477,10 @@ async fn generate_vex( let hosted = outcome .failed .iter() - .filter(|f| plan.hosted.contains_key(&f.purl)) - .map(|f| f.purl.clone()) + .filter_map(|f| { + let wiring = plan.hosted.get(&f.purl)?; + Some((f.purl.clone(), wiring.uuid.clone())) + }) .collect(); return Err(VexGenError { code: "no_applicable_patches", @@ -2839,8 +2841,11 @@ fn omission_lines(failed: &[FailedPatch], verbose: bool) -> Vec { /// replaces such a copy. #[derive(Debug, Default)] struct StaleHostedGems { - /// The purls omitted as `not_applied` that are gems on a hosted pin - /// with no manifest record (`apply` patches a recorded one in place). + /// The purls omitted as `not_applied` that are gems on a hosted pin, + /// but for a gem the manifest records under the pin's own patch: + /// `apply` patches that one in place. A record of another patch (an + /// agent-mode record the hosted pin superseded) does not count, since + /// `apply` would install that patch's files and not the pin's. purls: Vec, /// Whether a `scan` with no `--mode` runs in hosted mode here, the one /// mode that replaces the copies. It does not where the project also @@ -2851,31 +2856,38 @@ struct StaleHostedGems { } impl StaleHostedGems { - /// Those among `failed`, of which `hosted` are on a hosted pin. The - /// project's state is read only when there is such a gem. + /// Those among `failed`, of which `hosted` are on a hosted pin (purl + /// and the pin's patch uuid). The project's state is read only when + /// there is such a gem. async fn among( common: &GlobalArgs, manifest_path: &Path, failed: &[FailedPatch], - hosted: &[String], + hosted: &[(String, String)], ) -> Self { - let mut purls: Vec = failed + let mut gems: Vec<&(String, String)> = hosted .iter() - .filter(|f| { - f.reason == "not_applied" - && f.purl.starts_with("pkg:gem/") - && hosted.contains(&f.purl) + .filter(|(purl, _)| { + purl.starts_with("pkg:gem/") + && failed + .iter() + .any(|f| f.reason == "not_applied" && &f.purl == purl) }) - .map(|f| f.purl.clone()) .collect(); - if purls.is_empty() { + if gems.is_empty() { return Self::default(); } if let Ok(Some(manifest)) = socket_patch_core::manifest::operations::read_manifest(manifest_path).await { - purls.retain(|purl| !manifest.patches.contains_key(purl)); + gems.retain(|(purl, uuid)| { + manifest + .patches + .get(purl) + .is_none_or(|record| !record.uuid.eq_ignore_ascii_case(uuid)) + }); } + let purls: Vec = gems.into_iter().map(|(purl, _)| purl.clone()).collect(); let bare_scan_is_hosted = !purls.is_empty() && !common.is_global() && crate::commands::bare_scan_is_hosted(common).await; @@ -3409,12 +3421,13 @@ mod tests { failed("pkg:gem/json@2.7.0", "hash_mismatch"), failed("pkg:npm/a@1.0.0", "not_applied"), ]; - let hosted: Vec = [ + const PIN: &str = "11111111-1111-4111-8111-111111111111"; + let hosted: Vec<(String, String)> = [ "pkg:gem/rack@2.2.8", "pkg:gem/json@2.7.0", "pkg:npm/a@1.0.0", ] - .map(String::from) + .map(|purl| (purl.to_string(), PIN.to_string())) .to_vec(); // No patch state beside the lock: a bare scan is a hosted one. @@ -3428,9 +3441,9 @@ mod tests { // An agent-mode record of another package: the bare scan keeps // agent mode, which replaces no gem. - let record = |purl: &str| { + let record = |purl: &str, uuid: &str| { serde_json::json!({ "patches": { purl: { - "uuid": "11111111-1111-4111-8111-111111111111", + "uuid": uuid, "exportedAt": "2026-01-01T00:00:00Z", "files": {}, "vulnerabilities": {}, @@ -3441,16 +3454,26 @@ mod tests { .to_string() }; std::fs::create_dir_all(manifest_path.parent().unwrap()).unwrap(); - std::fs::write(&manifest_path, record("pkg:npm/b@1.0.0")).unwrap(); + std::fs::write(&manifest_path, record("pkg:npm/b@1.0.0", PIN)).unwrap(); let gems = StaleHostedGems::among(&common, &manifest_path, &failures, &hosted).await; assert_eq!(gems.purls, ["pkg:gem/rack@2.2.8"]); assert!(!gems.bare_scan_is_hosted); - // A record of the gem itself: `apply` patches it in place, so it - // keeps the general remedy. - std::fs::write(&manifest_path, record("pkg:gem/rack@2.2.8")).unwrap(); + // A record of the gem under the pin's own patch: `apply` patches + // it in place, so it keeps the general remedy. + std::fs::write(&manifest_path, record("pkg:gem/rack@2.2.8", PIN)).unwrap(); let gems = StaleHostedGems::among(&common, &manifest_path, &failures, &hosted).await; assert!(gems.purls.is_empty() && !gems.bare_scan_is_hosted); + + // A record of the gem under another patch, which the hosted pin + // superseded: `apply` would install that patch's files, so the gem + // still gets the gem remedy (the files to remove: the manifest + // makes a scan with no `--mode` an agent one). + let superseded = "22222222-2222-4222-8222-222222222222"; + std::fs::write(&manifest_path, record("pkg:gem/rack@2.2.8", superseded)).unwrap(); + let gems = StaleHostedGems::among(&common, &manifest_path, &failures, &hosted).await; + assert_eq!(gems.purls, ["pkg:gem/rack@2.2.8"]); + assert!(!gems.bare_scan_is_hosted); } #[test]