From 5883227bfe52325b2a4a6fac6768e218f3af36a9 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 09:22:53 +0000 Subject: [PATCH 1/4] Start fix for vendored unwind of hosted gem Refs #2083 Assisted-by: Claude Code:claude-fable-5-2 Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_011f9aeQ4raW21EPjpN9cP36 From 00096191e005909811cf8665c16b0f4d7c3a64e7 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 09:28:17 +0000 Subject: [PATCH 2/4] Test vendored unwind of a hosted-patched gem Three of the four tests fail: rollback, remove and vendor --revert of a gem that went hosted, then vendored, leave the installed copy and its gem-home archive on the patched build and say nothing. Refs #2083 Assisted-by: Claude Code:claude-fable-5-2 Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_011f9aeQ4raW21EPjpN9cP36 --- .../tests/e2e_redirect_gem_stale_install.rs | 248 ++++++++++++++++++ 1 file changed, 248 insertions(+) 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 6e68f5af5..3cb847343 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 @@ -2783,3 +2783,251 @@ async fn refresh_is_not_run_by_a_hosted_to_vendored_takeover() { } } } + +/// A project whose gem went hosted, then vendored: the hosted scan +/// replaced the project's installed copy and its gem-home archive with the +/// patched build, and the takeover (`scan --mode vendored`) left them +/// alone. Returns the installed gem dir and that archive. +async fn hosted_then_vendored(server: &MockServer, proj: &Path) -> (PathBuf, PathBuf) { + let (patched, upstream) = (real_gem(PATCHED_LIB), real_gem(UPSTREAM_LIB)); + mount_api_for(server, None, &sha256_of(&patched)).await; + serve_patched_gem(server, patched.clone()).await; + serve_upstream_gem(server, &upstream).await; + mount_vendored_grant(server, &patched).await; + std::fs::create_dir_all(proj).unwrap(); + write_manifest_pair(proj); + let home = project_home(proj); + let gem_dir = install_real_gem(&home, UPSTREAM_LIB); + let archive = home.join("cache").join(format!("{DEP}-{DEP_VERSION}.gem")); + + let uri = server.uri(); + let (code, _, stderr) = common::run_with_env(proj, &scan_args(proj, &uri, &["--json"]), &[]); + assert_eq!(code, 0, "hosted scan:\n{stderr}"); + std::fs::write(proj.join("Gemfile.lock"), converged_lock(&uri)).unwrap(); + let (code, stdout, stderr) = unwind_run( + proj, + &uri, + &["scan", "--mode", "vendored", "--yes", "--json"], + ); + assert_eq!(code, 0, "takeover:\n{stdout}\n{stderr}"); + let gemfile = std::fs::read_to_string(proj.join("Gemfile")).unwrap(); + assert!( + gemfile.contains(".socket/vendor/gem/"), + "premise:\n{gemfile}" + ); + assert_eq!(installed_lib(&gem_dir), PATCHED_LIB, "premise"); + assert_eq!(std::fs::read(&archive).unwrap(), patched, "premise"); + (gem_dir, archive) +} + +/// Run `args` in `proj` against the mock API, with rubygems.org's stand-in. +fn unwind_run(proj: &Path, uri: &str, args: &[&str]) -> (i32, String, String) { + let rubygems = format!("{uri}/upstream"); + let mut args = args.to_vec(); + args.extend([ + "--cwd", + proj.to_str().unwrap(), + "--api-url", + uri, + "--org", + ORG, + "--api-token", + "fake", + "--patch-server-url", + uri, + ]); + common::run_with_env(proj, &args, &[("SOCKET_RUBYGEMS_URL", rubygems.as_str())]) +} + +/// The commands that unwind a vendored gem. +const VENDORED_UNWINDS: [&[&str]; 3] = [ + &["rollback", "--yes"], + &["remove", PURL, "--yes"], + &["vendor", "--revert", "--yes"], +]; + +/// #2083: once a vendored gem is unwound, Bundler loads the installed copy +/// again. If a hosted scan made that copy the patched build before the +/// gem was vendored, the unwind puts the upstream gem back, as the hosted +/// unwind does: otherwise the app keeps running the patch under an +/// upstream lock, and `bundle pristine` fails on the upstream checksum. +#[tokio::test(flavor = "multi_thread")] +async fn vendored_unwind_restores_an_install_a_hosted_scan_patched() { + for unwind in VENDORED_UNWINDS { + let server = MockServer::start().await; + let tmp = tempfile::tempdir().unwrap(); + let proj = tmp.path().join("proj"); + let (gem_dir, archive) = hosted_then_vendored(&server, &proj).await; + + let mut args = unwind.to_vec(); + args.push("--json"); + let (code, stdout, stderr) = unwind_run(&proj, &server.uri(), &args); + let env = common::parse_json_envelope(&stdout); + assert_eq!(code, 0, "{unwind:?}: {env}\nstderr:\n{stderr}"); + let pair = format!( + "{}{}", + std::fs::read_to_string(proj.join("Gemfile")).unwrap(), + std::fs::read_to_string(proj.join("Gemfile.lock")).unwrap() + ); + assert!( + !pair.contains(".socket/vendor/") && !pair.contains("/patch-registry/"), + "{unwind:?}: the gem is back on its upstream entry:\n{pair}" + ); + assert_eq!( + installed_lib(&gem_dir), + UPSTREAM_LIB, + "{unwind:?}: the installed copy is the upstream build again: {env}" + ); + assert_eq!( + std::fs::read(&archive).unwrap(), + real_gem(UPSTREAM_LIB), + "{unwind:?}: so is the archive `bundle pristine` reinstalls from: {env}" + ); + let text = env.to_string(); + assert!( + text.contains("upstream_gem_install_refreshed") + && !text.contains("upstream_gem_stale_install"), + "{unwind:?}: {env}" + ); + } +} + +/// The human run says what it replaced, and its "keeps its patched bytes" +/// note no longer counts the gem. +#[tokio::test(flavor = "multi_thread")] +async fn vendored_unwind_reports_the_refresh_in_a_human_run() { + let server = MockServer::start().await; + let tmp = tempfile::tempdir().unwrap(); + let proj = tmp.path().join("proj"); + let (gem_dir, _) = hosted_then_vendored(&server, &proj).await; + + let (code, stdout, stderr) = unwind_run(&proj, &server.uri(), &["rollback", "--yes"]); + assert_eq!(code, 0, "{stdout}\n{stderr}"); + assert_eq!(installed_lib(&gem_dir), UPSTREAM_LIB); + let reverted = stdout + .find(&format!("Reverted vendoring for {PURL}")) + .unwrap_or_else(|| panic!("{stdout}")); + let replaced = stdout + .find(&format!( + "Replaced the installed copy of 1 gem with the upstream build: {DEP} {DEP_VERSION}." + )) + .unwrap_or_else(|| panic!("{stdout}")); + assert!(reverted < replaced, "{stdout}"); + assert!( + !stdout.contains("patched bytes in installed trees"), + "nothing is left for a reinstall:\n{stdout}" + ); +} + +/// A copy the unwind may not or cannot refresh is left exactly as it was +/// and named with a remedy that works: `--no-gem-install-refresh`, and an +/// upstream gem that cannot be downloaded. +#[tokio::test(flavor = "multi_thread")] +async fn vendored_unwind_names_an_install_it_leaves_on_the_patched_build() { + for (unwind, opt_out) in VENDORED_UNWINDS + .into_iter() + .flat_map(|unwind| [(unwind, true), (unwind, false)]) + { + let server = MockServer::start().await; + let tmp = tempfile::tempdir().unwrap(); + let proj = tmp.path().join("proj"); + let (gem_dir, archive) = hosted_then_vendored(&server, &proj).await; + let home = project_home(&proj); + let held_before = snapshot(&home); + if !opt_out { + // rubygems.org names the upstream sha256 but its download fails. + Mock::given(method("GET")) + .and(path(format!("/upstream/gems/{DEP}-{DEP_VERSION}.gem"))) + .respond_with(ResponseTemplate::new(503)) + .with_priority(1) + .mount(&server) + .await; + } + + let mut args = unwind.to_vec(); + args.push("--json"); + if opt_out { + args.push("--no-gem-install-refresh"); + } + let (code, stdout, stderr) = unwind_run(&proj, &server.uri(), &args); + let env = common::parse_json_envelope(&stdout); + let case = format!("{unwind:?} opt_out={opt_out}"); + assert_eq!(code, 0, "{case}: {env}\nstderr:\n{stderr}"); + assert!( + snapshot(&home) == held_before, + "{case}: the gem home changed: {env}" + ); + let text = env.to_string(); + let spec = home + .join("specifications") + .join(format!("{DEP}-{DEP_VERSION}.gemspec")); + for needle in [ + "upstream_gem_stale_install", + gem_dir.to_str().unwrap(), + spec.to_str().unwrap(), + archive.to_str().unwrap(), + "bundle install", + ] { + // The envelope JSON-escapes a Windows path's backslashes. + let needle = needle.replace('\\', "\\\\"); + assert!(text.contains(&needle), "{case}: no {needle:?} in {env}"); + } + assert!( + !text.contains("upstream_gem_install_refreshed"), + "{case}: {env}" + ); + } +} + +/// A gem that was only ever vendored still has the upstream build +/// installed: its unwind changes nothing in the gem home, downloads no +/// gem and raises nothing about it. +#[tokio::test(flavor = "multi_thread")] +async fn vendored_unwind_leaves_an_upstream_install_alone() { + for unwind in VENDORED_UNWINDS { + let server = MockServer::start().await; + let (patched, upstream) = (real_gem(PATCHED_LIB), real_gem(UPSTREAM_LIB)); + mount_api_for(&server, None, &sha256_of(&patched)).await; + serve_upstream_gem(&server, &upstream).await; + mount_vendored_grant(&server, &patched).await; + let tmp = tempfile::tempdir().unwrap(); + let proj = tmp.path().join("proj"); + std::fs::create_dir_all(&proj).unwrap(); + write_manifest_pair(&proj); + let home = project_home(&proj); + install_real_gem(&home, UPSTREAM_LIB); + let uri = server.uri(); + let (code, stdout, stderr) = unwind_run( + &proj, + &uri, + &["scan", "--mode", "vendored", "--yes", "--json"], + ); + assert_eq!(code, 0, "vendored scan:\n{stdout}\n{stderr}"); + let held_before = snapshot(&home); + let requests_before = server.received_requests().await.unwrap_or_default().len(); + + let mut args = unwind.to_vec(); + args.push("--json"); + let (code, stdout, stderr) = unwind_run(&proj, &uri, &args); + let env = common::parse_json_envelope(&stdout); + assert_eq!(code, 0, "{unwind:?}: {env}\nstderr:\n{stderr}"); + assert!( + snapshot(&home) == held_before, + "{unwind:?}: the gem home changed: {env}" + ); + let fetched: Vec = server.received_requests().await.unwrap_or_default() + [requests_before..] + .iter() + .map(|r| r.url.path().to_string()) + .filter(|path| path.contains("/gems/")) + .collect(); + assert!(fetched.is_empty(), "{unwind:?}: downloaded {fetched:?}"); + let text = env.to_string(); + for code in [ + "upstream_gem_install_refreshed", + "upstream_gem_stale_install", + ] { + assert!(!text.contains(code), "{unwind:?}: {code} in {env}"); + } + } +} From 8808ee6ee2aa3d147649d75d257d229fc5cbe102 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 09:39:38 +0000 Subject: [PATCH 3/4] Refresh installed gem after a vendored unwind A hosted scan replaces the project's installed copy of a gem with the patched build. A hosted to vendored takeover leaves that copy, because Bundler loads the vendored one instead. Once rollback, remove or vendor --revert unwinds the vendored gem, Bundler loads the installed copy again, and it was still the patched build: the app kept running the patch under the upstream lock, and bundle pristine failed on the upstream checksum (exit 37). The shared vendored revert now runs the hosted unwind's upstream refresh for the installed copies of the gems it unwired, under the same limits (project-local gem homes, --no-gem-install-refresh, --offline), and warns upstream_gem_stale_install for a copy it leaves. A gem that was only ever vendored has the upstream archive in its gem home, so nothing is downloaded or changed for it. An unwind's stale-install warning no longer suggests a re-run without --no-gem-install-refresh: a second unwind has nothing left to unwind. Fixes #2083 Assisted-by: Claude Code:claude-fable-5-2 Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_011f9aeQ4raW21EPjpN9cP36 --- crates/socket-patch-cli/CLI_CONTRACT.md | 12 +- .../src/commands/gem_refresh.rs | 162 ++++++++++++++---- .../socket-patch-cli/src/commands/remove.rs | 7 + .../socket-patch-cli/src/commands/rollback.rs | 16 ++ .../socket-patch-cli/src/commands/vendor.rs | 15 ++ .../src/commands/vendored_backend/mod.rs | 75 +++++++- .../tests/e2e_redirect_gem_build.rs | 124 ++++++++++++++ .../tests/e2e_redirect_gem_stale_install.rs | 90 +++++++--- docs/ecosystems.md | 5 +- 9 files changed, 447 insertions(+), 59 deletions(-) diff --git a/crates/socket-patch-cli/CLI_CONTRACT.md b/crates/socket-patch-cli/CLI_CONTRACT.md index 11ff110b6..6f702b1d8 100644 --- a/crates/socket-patch-cli/CLI_CONTRACT.md +++ b/crates/socket-patch-cli/CLI_CONTRACT.md @@ -117,7 +117,7 @@ Every subcommand accepts the same set of "global" flags via a single shared `Glo | `--no-trust-lockfile-config` | — | `SOCKET_NO_TRUST_LOCKFILE_CONFIG` | `false` | bool | Opt out of hosted mode's automatic `trustLockfile: true` write to `pnpm-workspace.yaml` (see the pnpm trust-config note under the scan arguments) | | `--no-npm-allow-remote-config` | — | `SOCKET_NO_NPM_ALLOW_REMOTE_CONFIG` | `false` | bool | Opt out of hosted mode's automatic `allow-remote=all` write to the project `.npmrc` (see the npm allow-remote note under the scan arguments). Read by `scan --mode hosted` and `get --mode hosted`; other subcommands accept it silently | | `--no-vlt-install-cleanup` | — | `SOCKET_NO_VLT_INSTALL_CLEANUP` | `false` | bool | Opt out of hosted mode's warm-tree heal for vlt: stale installed copies (`node_modules/.vlt-lock.json` and the stale `node_modules/.vlt/` entries) are left in place after `vlt-lock.json` is repointed (`scan`/`get --mode hosted`) or restored (`rollback`/`remove`), and the `redirect_vlt_reinstall_required` advisory tells you to run `vlt ci` instead. Stale copies of optional dependencies are always left in place (see `redirect_vlt_reinstall_required`). Other subcommands accept it silently | -| `--no-gem-install-refresh` | — | `SOCKET_NO_GEM_INSTALL_REFRESH` | `false` | bool | Opt out of hosted mode's gem stale-install refresh: the gems Bundler already holds for the project (an installed gem under the project and its cached `.gem`, an archive in `vendor/cache`) are left as they are after `Gemfile.lock` is repointed (`scan`/`get --mode hosted`) or restored (`rollback`/`remove`), and the `redirect_gem_stale_install` / `upstream_gem_stale_install` warning names the files to remove by hand instead (see the "Gem stale-install guard" section). Other subcommands accept it silently | +| `--no-gem-install-refresh` | — | `SOCKET_NO_GEM_INSTALL_REFRESH` | `false` | bool | Opt out of hosted mode's gem stale-install refresh: the gems Bundler already holds for the project (an installed gem under the project and its cached `.gem`, an archive in `vendor/cache`) are left as they are after `Gemfile.lock` is repointed (`scan`/`get --mode hosted`) or restored (`rollback`/`remove`, of a hosted pin or of a vendored gem; `vendor --revert`), and the `redirect_gem_stale_install` / `upstream_gem_stale_install` warning names the files to remove by hand instead (see the "Gem stale-install guard" section). Other subcommands accept it silently | | `--gem-refresh-shared` | — | `SOCKET_GEM_REFRESH_SHARED` | `false` | bool | Extend the gem stale-install refresh to gem homes OUTSIDE the project (the system gems, `~/.gem`, an rbenv or asdf home) and to project bundle or cache paths that resolve outside the project directory. Off by default: another project on the machine may pin the other build of the same gem version, and its `bundle pristine` then fails on the replaced archive's checksum (see the "Gem stale-install guard" section). Other subcommands accept it silently | **`--download-mode` removed (v5.0, MAJOR).** The global `--download-mode` flag and its `SOCKET_DOWNLOAD_MODE` binding are gone, with no alias: passing the flag is a usage error (exit 2) and the env var is ignored. Patch content is always fetched as per-file blobs (`.socket/blobs/`); `.socket/diffs/` archives are obsolete, never read, and removed by the cleanup sweeps. @@ -456,9 +456,11 @@ The rewriter reads a fixed set of candidate files from the project root: the npm - A human run prints ONE warning for all of them: how many gems, which gems in which gem home (or why they were not refreshed), why in one sentence, and the remedy as a command. - A stale-flagged purl is additionally **excluded from the same run's `--vex` `assume_applied` set** — the envelope must never attest a CVE its own warning says is live; the purl falls back to normal installed-tree verification (a patched install still attests, a stale one is omitted). A same-run `--vex` may still fail on "nothing to attest" per the embedded-VEX contract. -*The unwind direction.* After a hosted unwind — `rollback` / `remove` of a hosted pin, scan's withdrawn-patch restore, `vendor --revert` of a package vendored over hosted wiring before v5 — put a gem back on its upstream registry entry, its installed copies and archives hold the PATCHED gem, with the same consequences in reverse: the patched code keeps running, and on bundler ≥ 2.6 `bundle pristine` fails on the restored upstream checksum. The unwind applies the same refresh with the upstream gem: the sha256 is the restored lock's `CHECKSUMS` entry, else the rubygems.org compact index; the archive is taken from disk, else downloaded from rubygems.org when the lock resolves the gem from it (a gem from another remote is refreshed only from an archive already on disk). An installed copy is stale when its `/cache/.gem` is readable and is not the upstream archive (ruby-platform gems only: the lock's checksum names that archive). Notes are `upstream_gem_install_refreshed` / `upstream_gem_install_would_refresh`; an installed copy left on the patched build is `upstream_gem_stale_install` (one consolidated warning in a human run), and an archive left in bundler's cache dir keeps its `upstream_gem_stale_cache` warning. A gem whose installed copies were refreshed is not counted in rollback's "keep their patched bytes" note. +*The unwind direction.* After a hosted unwind — `rollback` / `remove` of a hosted pin, scan's withdrawn-patch restore, `vendor --revert` of a package vendored over hosted wiring before v5 — put a gem back on its upstream registry entry, its installed copies and archives hold the PATCHED gem, with the same consequences in reverse: the patched code keeps running, and on bundler ≥ 2.6 `bundle pristine` fails on the restored upstream checksum. The unwind applies the same refresh with the upstream gem: the sha256 is the restored lock's `CHECKSUMS` entry, else the rubygems.org compact index; the archive is taken from disk, else downloaded from rubygems.org when the lock resolves the gem from it (a gem from another remote is refreshed only from an archive already on disk). An installed copy is stale when its `/cache/.gem` is readable and is not the upstream archive (ruby-platform gems only: the lock's checksum names that archive). Notes are `upstream_gem_install_refreshed` / `upstream_gem_install_would_refresh`; an installed copy left on the patched build is `upstream_gem_stale_install` (one consolidated warning in a human run), and an archive left in bundler's cache dir keeps its `upstream_gem_stale_cache` warning. A gem whose installed copies were refreshed is not counted in rollback's "keep their patched bytes" note. The warning names no re-run: the unwind already removed the wiring a second run would look for, so its remedy is the files to remove before `bundle install`. -*What never refreshes.* A hosted → vendored takeover (`vendor`, `scan` / `get --mode vendored` over a hosted pin) puts the gem on its upstream entry only on its way to the vendored `path:` source, which is what Bundler loads from then on. The copies Bundler already holds are unused leftovers there, so the takeover changes none of them and downloads no gem for them: resetting the installed copy to the upstream build would cost a registry download in the mode that needs none, and would turn a patched leftover into an unpatched one that `vex` reports against the vendored artifact (`vendored_tree_out_of_sync`, whose gem wording names the copy and how to remove it). Its `upstream_gem_stale_cache` advisory about a patched cache-dir archive is as before. A vendored unwind (`remove`, `rollback`, `vendor --revert`, `scan --prune`, `vendor`'s reconcile of a vendored gem) likewise only names that archive. +*What never refreshes.* A hosted → vendored takeover (`vendor`, `scan` / `get --mode vendored` over a hosted pin) puts the gem on its upstream entry only on its way to the vendored `path:` source, which is what Bundler loads from then on. The copies Bundler already holds are unused leftovers there, so the takeover changes none of them and downloads no gem for them: resetting the installed copy to the upstream build would cost a registry download in the mode that needs none, and would turn a patched leftover into an unpatched one that `vex` reports against the vendored artifact (`vendored_tree_out_of_sync`, whose gem wording names the copy and how to remove it). Its `upstream_gem_stale_cache` advisory about a patched cache-dir archive is as before. A vendored unwind (`remove`, `rollback`, `vendor --revert`, `scan --prune`, `vendor`'s reconcile of a vendored gem) likewise only names that archive, and never replaces it. + +*A vendored unwind after a hosted scan.* Once a vendored gem is unwound, Bundler loads its installed copy again, so the leftover is in use: if a hosted scan made that copy the patched build before the gem was vendored, the patched code would keep running under the upstream lock, and on bundler ≥ 2.6 `bundle pristine` would fail on the upstream checksum. A wet `rollback`, `remove`, `vendor --revert` or `vendor` reconcile that put a vendored gem back on its upstream entry therefore applies the unwind direction's refresh to the gem's INSTALLED copies, under the same rules (staleness judged by `/cache/.gem` against the upstream sha256; a project-local gem home only, unless `--gem-refresh-shared`; `--no-gem-install-refresh`; an archive on disk, else rubygems.org unless `--offline`), with the same `upstream_gem_install_refreshed` note and `upstream_gem_stale_install` warning. `--json` carries them where the command carries a vendored revert's advisories (rollback `warnings[]`; `remove` / `vendor` advisory events); a human run prints the progress line after the gem's own line and one warning for the gems left on the patched build. The upstream sha256 is looked up only for a gem that has an installed copy with its archive, so the unwind of a gem that is not installed needs no network. A gem that was only ever vendored has the upstream archive there: nothing is downloaded or changed. A `--dry-run` does not preview this (the lock on disk is still the vendored one), and `scan --prune` does not refresh. **Pipenv hosted redirect (`Pipfile.lock`, pipfile-spec 6)**: every category other than `_meta` (`default`, `develop`, and Pipenv 2022+ named categories) that pins the package at the patched version is rewritten to the hosted reference — `{"file" | "path": "#sha256=", "hashes": ["sha256:"]}` with `markers`/`extras`/`index` kept exactly as Pipenv wrote them (present or absent: whether Pipenv records `index` depends on its release, the Pipfile spelling and the locking environment, so only the entry itself knows) and `version` dropped; `_meta` (the Pipfile content hash) and the Pipfile itself are never touched, so `pipenv install --deploy`/`sync`/`verify` keep passing. The reference KEY depends on the installing Pipenv: releases 7–11 only install `path` references, 2018 and later `file` ones (0–6 write pipfile-spec < 6 and are refused). The release is probed once per command with `pipenv --version`, resolved on ABSOLUTE `PATH` entries only (a relative entry would run a `pipenv` planted in the scanned repository; `.bat`/`.cmd` shims are found through `PATHEXT` on Windows), only when a pypi patch actually targets an entry of the lock, and `SOCKET_PIPENV_MAJOR=` pins the answer without spawning anything. An unknown installer selects `file` and warns `redirect_pipenv_installer_unknown` only when the lock was rewritten. **Refusal scope**: a pin/source CONFLICT (another version pinned, a foreign `file`/`path` source, a VCS/editable dependency) refuses the whole dependency atomically across categories as `redirect_pipenv_refused` AND vetoes the sibling Python rewriters (requirements.txt / uv.lock / pyproject) for that patch — the project's Pipenv install could not pick the patch up, so a half-redirected checkout is refused; anything else (no entry for the package, an old pipfile-spec, an unparseable lock, a digest-less patch) is `redirect_pipenv_skipped` and leaves the siblings alone (a stale Pipfile.lock in a uv/Poetry/requirements project must not block them). The veto applies to a LIVE lock only: a `Pipfile.lock` with no `Pipfile` beside it is abandoned, so its conflict refuses that file but never the siblings. Hash enforcement at install time is split by era — the `#sha256=` URL fragment is what Pipenv 2023+ verifies, the `hashes` list what 2018–2022 verify, Pipenv 11 either — so both are load-bearing. **Pipenv stale-install guard**: Pipenv never reinstalls a release that is already present (`pipenv install`, `install --deploy` and `sync` all exit 0 and keep the installed bytes — measured on 11.10.4, 2018.11.26 and 2026.8.0, hosted and vendored), so after the rewrite the run probes the Python crawler's site-packages (VIRTUAL_ENV, `./.venv`, `./venv`, Pipenv's out-of-tree `WORKON_HOME` venv; `--global`/`--global-prefix` honoured) for each confirmed Pipfile.lock redirect with the Python stale-install guard's evidence (the pinned patched wheel, else the patch record; STALE needs positive evidence, read-only, skipped on `--dry-run`, stale purls excluded from the same-run `--vex` `assume_applied` set) and the Python stale-install guard (`redirect_pypi_stale_install`, see above) names the site-packages dir and the Pipenv-specific verified remedy: `pipenv run pip uninstall -y && pipenv sync` (or `pipenv --rm && pipenv sync`), with the `sync` arguments following the lock, since plain `pipenv sync` installs only `default`: the targeted form re-syncs the categories that pin the package (`--dev` for `develop`, `--categories ""` for a named category) and the `--rm` form re-syncs every non-empty category — NOT `pipenv uninstall`, which rewrites the Pipfile and re-locks the patch away. The vendored backend emits the twin `pypi_pipenv_stale_install` (`skipped` warning event). **Rollback** (v5.0, upstream restore): each hosted entry gets its registry shape back — `"version": "=="`, the entry's own `index` carried back unchanged (refused unless it — and the Pipfile's explicit `index`, if any — names a PyPI source in `_meta.sources`), and every release file's sha256 from PyPI's JSON API (`SOCKET_PYPI_JSON_API`), sorted by filename as Pipenv records them; an entry that pins another version beside the hosted reference is refused with the `git checkout` remedy (see "Hosted unwind coverage"). A Pipfile names no project, so a same-run `--vex` on a Pipenv project needs `--vex-product` (or a git remote) to detect a product purl. **Discovery**: `Pipfile.lock` is part of the lockfile inventory (every category's `==` pins, with the lock's digest set as `Sha256AnyOf` integrity so a lock-only checkout can be vendored by fetching the pure wheel through PyPI's JSON API — only when `_meta.sources` name the public index; a private-index lock stays discovery-only and never reaches pypi.org), and Socket's own hosted / vendored references stay discoverable as the package they replace, so a re-scan of an already-redirected or already-vendored lock-only checkout re-confirms it (`--vex` attests, vendored reports `already_vendored`) instead of finding nothing. @@ -2238,8 +2240,8 @@ command's integration tests check its output. | `redirect_gem_stale_install` | `warnings[]` (warning) | scan / get `--mode hosted` (gem): a stale UNPATCHED materialization (installed gem, or committed archive in bundler's cache dir — `vendor/cache` unless `cache_path` moves it) that `bundle install` will reuse instead of fetching the redirected patch, and that the run did not refresh: it is in a shared gem home, or the refresh could not be done (the detail says why) or is turned off. The detail carries the remedy. A human run prints one warning for all of them. Full rules and flavors: the "Gem stale-install guard" section. | | `redirect_gem_install_refreshed` | `warnings[]` (note) | scan / get `--mode hosted` (gem): a stale materialization the run replaced with the sha256-verified patched gem (the detail names the purl and the path). A human run prints a progress line instead. See the "Gem stale-install guard" section. | | `redirect_gem_install_would_refresh` | `warnings[]` (note) | scan / get `--mode hosted --dry-run` (gem): a stale materialization a wet run would replace. Nothing was written or downloaded. | -| `upstream_gem_stale_install` | `warnings[]` (warning) | rollback / remove / a withdrawn-patch restore (gem): an installed copy of a gem that is back on its upstream entry still holds the PATCHED gem and was not refreshed (a shared gem home, a failed or disabled refresh). Bundler keeps using it. The detail carries the remedy; a human run prints one warning for all of them. | -| `upstream_gem_install_refreshed` | `warnings[]` (note) | rollback / remove / a withdrawn-patch restore (gem): an installed copy or cache-dir archive the unwind replaced with the sha256-verified upstream gem. A human run prints a progress line instead. | +| `upstream_gem_stale_install` | `warnings[]` (warning); remove / `vendor --revert` / `vendor` (manifest reconcile) advisory events for a vendored unwind | rollback / remove / a withdrawn-patch restore (gem), and a wet vendored gem unwind (`rollback`, `remove`, `vendor --revert`, `vendor`'s reconcile; #2083): an installed copy of a gem that is back on its upstream entry still holds the PATCHED gem and was not refreshed (a shared gem home, a failed or disabled refresh). Bundler keeps using it. The detail carries the remedy; a human run prints one warning for all of them. | +| `upstream_gem_install_refreshed` | `warnings[]` (note); remove / `vendor --revert` / `vendor` (manifest reconcile) advisory events for a vendored unwind | rollback / remove / a withdrawn-patch restore (gem): an installed copy or cache-dir archive the unwind replaced with the sha256-verified upstream gem. A wet vendored gem unwind (#2083): an installed copy only. A human run prints a progress line instead. | | `upstream_gem_install_would_refresh` | `warnings[]` (note) | the same on `--dry-run`: what a wet unwind would replace. | | `redirect_gem_version_not_locked` | `warnings[]` (warning) | scan `--mode hosted` (gem): the crawled gem version is installed on the machine but no `GEM` section of the project's lock resolves it (another project's copy in the shared gem home). The gem is skipped and the Gemfile and lock stay byte-identical. | | `redirect_gem_no_checksums_section` | `warnings[]` (warning) | scan/get `--mode hosted` (gem): the lock has no `CHECKSUMS` section (Bundler < 2.6 does not write one), so it cannot record the sha256 of the patched gems. They are redirected all the same (manifest and lock converged, frozen installs accept the pair) and pinned by source alone. Reported once per run, naming the gems; relock with Bundler ≥ 2.6 (`bundle lock --add-checksums`) and re-run to pin the checksums too. | diff --git a/crates/socket-patch-cli/src/commands/gem_refresh.rs b/crates/socket-patch-cli/src/commands/gem_refresh.rs index 03fc059f5..372820008 100644 --- a/crates/socket-patch-cli/src/commands/gem_refresh.rs +++ b/crates/socket-patch-cli/src/commands/gem_refresh.rs @@ -339,10 +339,13 @@ fn display_list(paths: &[PathBuf]) -> String { .join(", ") } -/// How a refresh that did not happen is retried. +/// How a refresh that did not happen is retried. An unwind can't be: its +/// first run removed the wiring a second one would look for. fn retry_hint(direction: Direction, why: Option<&Why>) -> &'static str { match (why, direction) { - (Some(Why::Disabled), _) => "Re-run without `--no-gem-install-refresh`, or ", + (Some(Why::Disabled), Direction::Patched) => { + "Re-run without `--no-gem-install-refresh`, or " + } (Some(Why::Failed(_)), Direction::Patched) => "Re-run `socket-patch scan` to retry, or ", _ => "", } @@ -603,35 +606,24 @@ pub(crate) fn report( out } -/// The stale materializations of the gems a hosted unwind just put back on -/// their upstream entries, judged like the hosted scan's guard, with the -/// roles swapped: an installed copy (ruby platform) is stale when the -/// archive RubyGems installed it from, `/cache/.gem`, is -/// readable and is not the upstream one, and so is such an archive in -/// Bundler's cache dir. `upstream` is each purl's upstream sha256; a purl -/// without one is not judged. -async fn stale_after_restore( - common: &GlobalArgs, - upstream: &BTreeMap, -) -> Vec { +/// The installed copies (ruby platform) of `purls` in the gem homes Bundler +/// installs the project's gems into, each with the archive RubyGems +/// installed it from, `/cache/.gem`. +async fn installed_with_archives(common: &GlobalArgs, purls: &[String]) -> Vec { use socket_patch_core::crawlers::types::CrawlerOptions; use socket_patch_core::crawlers::RubyCrawler; - use socket_patch_core::vendor::file_sha256_hex; - let purls: Vec = upstream.keys().cloned().collect(); let crawler = RubyCrawler::new(); let options = CrawlerOptions { cwd: common.cwd.clone(), global: common.global, global_prefix: common.global_prefix.clone(), }; - let app_cache = - socket_patch_core::crawlers::ruby_crawler::bundler_app_cache_dir(&common.cwd).await; let mut out = Vec::new(); for home in crawler.bundler_install_homes(&options).await { - let found = crawler.find_each_by_purl(&home.gems_dir, &purls).await; + let found = crawler.find_each_by_purl(&home.gems_dir, purls).await; for (purl, pkg) in purls.iter().zip(found) { - let (Some(pkg), Some(sha)) = (pkg, upstream.get(purl)) else { + let Some(pkg) = pkg else { continue; }; let Some((_, name, version)) = socket_patch_core::utils::purl::purl_parts(purl) else { @@ -646,17 +638,71 @@ async fn stale_after_restore( let Some(archive) = home_cache_archive(&pkg.path) else { continue; }; - match file_sha256_hex(&archive).await { - Some(got) if &got != sha => out.push(StaleGem { - purl: purl.clone(), - leaf, - installed: Some((pkg.path.clone(), home.project_local)), - cache_archive: None, - }), - _ => {} - } + out.push(InstalledCopy { + purl: purl.clone(), + leaf, + dir: pkg.path.clone(), + project_local: home.project_local, + archive, + }); } } + out +} + +/// One installed copy [`installed_with_archives`] found. +struct InstalledCopy { + purl: String, + leaf: String, + dir: PathBuf, + project_local: bool, + archive: PathBuf, +} + +/// Which materializations an unwind's refresh covers. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +enum Scope { + /// Installed copies and the archives in Bundler's cache dir. + All, + /// Installed copies only. + Installed, +} + +/// The stale materializations of the gems an unwind just put back on +/// their upstream entries, judged like the hosted scan's guard, with the +/// roles swapped: an installed copy (ruby platform) is stale when the +/// archive RubyGems installed it from, `/cache/.gem`, is +/// readable and is not the upstream one, and so is (in [`Scope::All`]) +/// such an archive in Bundler's cache dir. `upstream` is each purl's +/// upstream sha256; a purl without one is not judged. +async fn stale_after_restore( + common: &GlobalArgs, + upstream: &BTreeMap, + scope: Scope, +) -> Vec { + use socket_patch_core::vendor::file_sha256_hex; + + let purls: Vec = upstream.keys().cloned().collect(); + let mut out = Vec::new(); + for copy in installed_with_archives(common, &purls).await { + let Some(sha) = upstream.get(©.purl) else { + continue; + }; + match file_sha256_hex(©.archive).await { + Some(got) if &got != sha => out.push(StaleGem { + purl: copy.purl, + leaf: copy.leaf, + installed: Some((copy.dir, copy.project_local)), + cache_archive: None, + }), + _ => {} + } + } + if scope == Scope::Installed { + return out; + } + let app_cache = + socket_patch_core::crawlers::ruby_crawler::bundler_app_cache_dir(&common.cwd).await; for (purl, sha) in upstream { let Some((_, name, version)) = socket_patch_core::utils::purl::purl_parts(purl) else { continue; @@ -676,7 +722,8 @@ async fn stale_after_restore( out } -/// What the hosted unwind's refresh did, for [`crate::commands::hosted_unwind`]. +/// What an unwind's refresh did, for [`crate::commands::hosted_unwind`] +/// and the vendored unwind ([`crate::commands::vendored_backend`]). #[derive(Debug, Default)] pub(crate) struct RestoreRefresh { pub(crate) report: Report, @@ -698,6 +745,42 @@ pub(crate) async fn after_restore( common: &GlobalArgs, restored: &[String], staged: &BTreeMap>, +) -> RestoreRefresh { + refresh_restored(common, restored, staged, Scope::All).await +} + +/// After a wet vendored unwind put the gems `unwound` back on their +/// upstream entries (the lock on disk says so): Bundler loads their +/// installed copies again, and a copy that a hosted scan replaced with the +/// patched build before the gem was vendored is still that build (#2083). +/// Those copies are brought back to the upstream gem exactly as +/// [`after_restore`] does it. An archive in Bundler's cache dir is not +/// touched: the vendored unwind names it (`upstream_gem_stale_cache`). +/// +/// A gem with no installed copy to judge costs no registry lookup: a +/// vendored unwind then needs no network, as before. +pub(crate) async fn after_vendored_unwind( + common: &GlobalArgs, + unwound: &[String], +) -> RestoreRefresh { + let installed: BTreeSet = installed_with_archives(common, unwound) + .await + .into_iter() + .filter(|copy| copy.archive.is_file()) + .map(|copy| copy.purl) + .collect(); + if installed.is_empty() { + return RestoreRefresh::default(); + } + let installed: Vec = installed.into_iter().collect(); + refresh_restored(common, &installed, &BTreeMap::new(), Scope::Installed).await +} + +async fn refresh_restored( + common: &GlobalArgs, + restored: &[String], + staged: &BTreeMap>, + scope: Scope, ) -> RestoreRefresh { use socket_patch_core::patch::redirect::upstream::gem_upstream_archive; @@ -719,7 +802,7 @@ pub(crate) async fn after_restore( if shas.is_empty() { return RestoreRefresh::default(); } - let stale = stale_after_restore(common, &shas).await; + let stale = stale_after_restore(common, &shas, scope).await; if stale.is_empty() { return RestoreRefresh::default(); } @@ -739,7 +822,7 @@ pub(crate) async fn after_restore( }; let pass = attempt(&stale, wanted, &source, &policy, direction).await; let still = if pass.changed(&policy) { - stale_after_restore(common, &shas).await + stale_after_restore(common, &shas, scope).await } else { stale }; @@ -1047,5 +1130,22 @@ mod tests { "{}", out.warnings[1].1 ); + + // An unwind names no re-run: nothing is left for one to unwind. + let out = report(Direction::Upstream, &gems, &tried, &policy_off); + assert!( + out.warnings[1] + .1 + .contains("`--no-gem-install-refresh` is set") + && !out.warnings[1].1.contains("Re-run") + && out.warnings[1].1.contains("and run `bundle install`"), + "{}", + out.warnings[1].1 + ); + let summary = out.summary.expect("stale gems").paragraph(); + assert!( + !summary.contains("Re-run without") && summary.contains("Run `rm -f "), + "{summary}" + ); } } diff --git a/crates/socket-patch-cli/src/commands/remove.rs b/crates/socket-patch-cli/src/commands/remove.rs index 01e49f4cd..348dd6f2d 100644 --- a/crates/socket-patch-cli/src/commands/remove.rs +++ b/crates/socket-patch-cli/src/commands/remove.rs @@ -1411,6 +1411,7 @@ async fn revert_vendored_matches( for RevertedEntry { key, warnings, + progress, step, .. } in reverted @@ -1525,6 +1526,12 @@ async fn revert_vendored_matches( return Err(1); } } + if loud { + for line in &progress { + println!("{line}"); + leg.printed = true; + } + } } Ok(leg) } diff --git a/crates/socket-patch-cli/src/commands/rollback.rs b/crates/socket-patch-cli/src/commands/rollback.rs index 16f16057b..d312d38ba 100644 --- a/crates/socket-patch-cli/src/commands/rollback.rs +++ b/crates/socket-patch-cli/src/commands/rollback.rs @@ -1002,6 +1002,10 @@ struct VendoredLegOutcome { /// could not be saved. failed: Vec<(String, &'static str, String)>, warnings: Vec<(String, String)>, + /// The gems (ledger keys) whose installed copies the unwind brought + /// back to the upstream build: nothing of theirs is left for a + /// reinstall. + refreshed_installs: std::collections::BTreeSet, /// `removed` / `vendor_orphan_removed` events for the orphan uuid /// dirs (no ledger entry) swept, also on dry-run. orphans_removed: Vec, @@ -1033,10 +1037,15 @@ async fn run_vendored_leg( for RevertedEntry { key, warnings, + progress, + gem_install_refreshed, step, .. } in reverted { + if gem_install_refreshed { + out.refreshed_installs.insert(key.clone()); + } for w in &warnings { if loud { eprintln!("Warning: {}", w.detail); @@ -1097,6 +1106,11 @@ async fn run_vendored_leg( out.failed.push((key, "vendor_state_write_failed", why)); } } + if loud { + for line in &progress { + println!("{line}"); + } + } } out } @@ -2844,6 +2858,7 @@ async fn run_project(args: RollbackArgs, below: BelowNotes) -> i32 { // A gem the hosted leg already brought back to // its upstream build. && !hosted_leg.refreshed_installs.contains(key.as_str()) + && !vendored_leg.refreshed_installs.contains(key.as_str()) }) .count(); if still_patched > 0 { @@ -6675,6 +6690,7 @@ mod tests { "boom".to_string(), )], warnings: Vec::new(), + refreshed_installs: Default::default(), orphans_removed: Vec::new(), }; let hosted = HostedLegOutcome { diff --git a/crates/socket-patch-cli/src/commands/vendor.rs b/crates/socket-patch-cli/src/commands/vendor.rs index 459663d5d..19c3557ef 100644 --- a/crates/socket-patch-cli/src/commands/vendor.rs +++ b/crates/socket-patch-cli/src/commands/vendor.rs @@ -635,6 +635,16 @@ fn takeover_detail(code: &str, detail: &str) -> String { } } +/// A reverted entry's progress lines ([`RevertedEntry::progress`]), for a +/// human run. +fn print_progress(common: &GlobalArgs, lines: &[String]) { + if !common.silent && !common.json { + for line in lines { + println!("{line}"); + } + } +} + pub(crate) fn record_warning( env: &mut Envelope, purl: &str, @@ -4713,6 +4723,7 @@ pub(crate) async fn reconcile_dropped( for RevertedEntry { key: purl, warnings, + progress, step, .. } in reverted @@ -4778,6 +4789,7 @@ pub(crate) async fn reconcile_dropped( ); } } + print_progress(common, &progress); } (had_error, Ok(state)) } @@ -4820,7 +4832,9 @@ async fn run_revert(args: &VendorArgs, env: &mut Envelope) -> i32 { key: purl, flavor, warnings, + progress, step, + .. } in reverted { let purl = &purl; @@ -4875,6 +4889,7 @@ async fn run_revert(args: &VendorArgs, env: &mut Envelope) -> i32 { ); } } + print_progress(common, &progress); } // `--revert` returns to UPSTREAM: a package vendored over hosted wiring diff --git a/crates/socket-patch-cli/src/commands/vendored_backend/mod.rs b/crates/socket-patch-cli/src/commands/vendored_backend/mod.rs index 50dff7be9..fa9b006f8 100644 --- a/crates/socket-patch-cli/src/commands/vendored_backend/mod.rs +++ b/crates/socket-patch-cli/src/commands/vendored_backend/mod.rs @@ -158,12 +158,17 @@ impl<'a> VendoredBackend<'a> { stop_on_failure: bool, ) -> Vec { let mut out = Vec::with_capacity(keys.len()); + // The gems a wet revert put back on their upstream entries: the + // index of each one's element in `out`, and its purl. + let mut unwound_gems: Vec<(usize, String)> = Vec::new(); for key in keys { let Some(entry) = state.entries.get(key).cloned() else { out.push(RevertedEntry { key: key.clone(), flavor: None, warnings: Vec::new(), + progress: Vec::new(), + gem_install_refreshed: false, step: VendorRevertStep::Missing, }); continue; @@ -221,21 +226,77 @@ impl<'a> VendoredBackend<'a> { &mut warnings, ) .await; + if is_gem(&entry.ecosystem) { + unwound_gems.push((out.len(), entry.base_purl.clone())); + } } } out.push(RevertedEntry { key: key.clone(), flavor, warnings, + progress: Vec::new(), + gem_install_refreshed: false, step, }); if stop_on_failure && hard_failure { break; } } + self.refresh_unwound_gems(&unwound_gems, &mut out).await; out } + /// Bundler loads the installed copies of the unwound gems again. One + /// that a hosted scan replaced with the patched build before the gem + /// was vendored still is that build, so the app would keep running the + /// patch under an upstream lock, and `bundle pristine` would fail on + /// the upstream checksum (#2083). Bring those copies back to the + /// upstream gem as the hosted unwind does, and name what is left (the + /// "Gem stale-install guard" section of CLI_CONTRACT.md). + /// + /// `--json` gets a note per refreshed copy and a warning per stale + /// one, on the entry of its gem. A human run gets the progress lines on + /// the last unwound gem's entry, so they print once every revert is + /// reported, and ONE warning for the gems still on their patched build. + async fn refresh_unwound_gems(&self, unwound: &[(usize, String)], out: &mut [RevertedEntry]) { + let Some((first, _)) = unwound.first() else { + return; + }; + let (first, last) = (*first, unwound[unwound.len() - 1].0); + let purls: Vec = unwound.iter().map(|(_, purl)| purl.clone()).collect(); + let refresh = + crate::commands::gem_refresh::after_vendored_unwind(&self.common, &purls).await; + for (index, purl) in unwound { + if refresh.refreshed_installs.contains(purl) { + out[*index].gem_install_refreshed = true; + } + } + let report = refresh.report; + if self.common.json { + for (code, detail) in report.warnings { + // Each detail starts with the purl it is about. + let index = unwound + .iter() + .find(|(_, purl)| { + detail + .strip_prefix(purl.as_str()) + .is_some_and(|rest| rest.starts_with([' ', ':'])) + }) + .map_or(first, |(index, _)| *index); + out[index].warnings.push(VendorWarning::new(code, detail)); + } + return; + } + out[last].progress = report.progress; + if let Some(summary) = &report.summary { + out[first].warnings.push(VendorWarning::new( + crate::commands::gem_refresh::Direction::Upstream.stale_code(), + summary.paragraph(), + )); + } + } + /// Dropping a vendored Go `replace` leaves a committed /// vendor/modules.txt still recording it, which breaks every default /// build until `go mod vendor` runs. The undo commands @@ -273,6 +334,11 @@ impl<'a> VendoredBackend<'a> { } } +/// Whether a ledger entry's `ecosystem` is RubyGems. +fn is_gem(ecosystem: &str) -> bool { + socket_patch_core::vendor::jvm::layout::ledger_ecosystem(ecosystem) == "gem" +} + /// Name a patched `-.gem` left in Bundler's cache dir once /// the vendored ledger entry of `ecosystem` for `base_purl` is unwired: a /// `bundle cache` taken while a hosted pin was live keeps it there through @@ -285,7 +351,7 @@ pub(crate) async fn push_gem_stale_cache( offline: bool, warnings: &mut Vec, ) { - if socket_patch_core::vendor::jvm::layout::ledger_ecosystem(ecosystem) != "gem" { + if !is_gem(ecosystem) { return; } if let Some((code, detail)) = @@ -307,6 +373,13 @@ pub(crate) struct RevertedEntry { pub(crate) flavor: Option, /// The backend's advisories. pub(crate) warnings: Vec, + /// Lines a human run prints to stdout after its own line for the + /// entry: what the gem refresh replaced in the installed tree. + pub(crate) progress: Vec, + /// The gem's installed copies were brought back to the upstream build, + /// with none left on the patched one: nothing of it is left for a + /// reinstall. + pub(crate) gem_install_refreshed: bool, pub(crate) step: VendorRevertStep, } diff --git a/crates/socket-patch-cli/tests/e2e_redirect_gem_build.rs b/crates/socket-patch-cli/tests/e2e_redirect_gem_build.rs index dd31ec3fc..dccb08328 100644 --- a/crates/socket-patch-cli/tests/e2e_redirect_gem_build.rs +++ b/crates/socket-patch-cli/tests/e2e_redirect_gem_build.rs @@ -5613,6 +5613,130 @@ async fn gem_vendored_unwind_names_a_patched_archive_in_vendor_cache() { } } +/// #2083 through one vendored unwind `command`: the project installed the +/// hosted pin, so its installed gem and the archive RubyGems keeps beside +/// it are the PATCHED build. A hosted → vendored takeover leaves them (the +/// vendored copy is loaded instead), and the later unwind puts the pair +/// back on the upstream `GEM` entry, where bundler loads the installed +/// copy again. The unwind must put the upstream gem back: the app then +/// loads the upstream code, and every kind of reinstall succeeds and +/// keeps it. +fn vendored_unwind_restores_the_installed_gem(fx: &RedirectFixture, command: &str) { + let dir = stage_fresh_checkout(fx, &format!("vendored-install-{command}")); + let install = bundle(&dir, &["install"]); + assert!( + install.status.success(), + "{command}: hosted install:\n{}", + String::from_utf8_lossy(&install.stderr) + ); + let installed = fresh_installed_lib(&dir, &format!("{DEP}-{DEP_VERSION}"), "vuln_gem.rb"); + assert!( + std::fs::read(&installed).unwrap() == patched_lib().into_bytes(), + "{command}: premise" + ); + + let api = fx._server.uri(); + let upstream = format!("{api}/upstream"); + let cwd = dir.to_str().expect("utf8 tmp path"); + let common = [ + "--json", + "--cwd", + cwd, + "--api-url", + &api, + "--org", + ORG, + "--api-token", + "fake", + "--patch-server-url", + &api, + ]; + let envs = [("SOCKET_RUBYGEMS_URL", upstream.as_str())]; + let mut takeover = vec!["get", UUID, "--mode", "vendored", "--yes"]; + takeover.extend(common); + let (code, stdout, stderr) = run_socket_env(&dir, &takeover, &envs); + assert_eq!( + code, 0, + "{command}: takeover:\nstdout:\n{stdout}\nstderr:\n{stderr}" + ); + let vendored = bundle(&dir, &["install"]); + assert!( + vendored.status.success(), + "{command}: vendored install:\n{}", + String::from_utf8_lossy(&vendored.stderr) + ); + assert!( + std::fs::read(&installed).unwrap() == patched_lib().into_bytes(), + "{command}: premise: the takeover and its install leave the installed copy" + ); + + let mut argv: Vec<&str> = match command { + "vendor --revert" => vec!["vendor", "--revert", "--yes"], + "remove" => vec!["remove", PURL, "--yes"], + _ => vec![command, PURL], + }; + argv.extend(common); + let (code, stdout, stderr) = run_socket_env(&dir, &argv, &envs); + let env: serde_json::Value = serde_json::from_str(&stdout).unwrap_or_else(|e| { + panic!("{command}: not JSON: {e}\nstdout:\n{stdout}\nstderr:\n{stderr}") + }); + assert_eq!(code, 0, "{command}: {env}\nstderr:\n{stderr}"); + assert!( + env.to_string().contains("upstream_gem_install_refreshed") + && !env.to_string().contains("upstream_gem_stale_install"), + "{command}: {env}" + ); + assert!( + std::fs::read(&installed).unwrap() == orig_lib().into_bytes(), + "{command}: the installed copy is the upstream build again: {env}" + ); + + let redownload = if fx.bundler.at_least(2, 0) { + "--redownload" + } else { + "--force" + }; + let probe = "require \"vuln_gem\"; print VulnGem.status"; + for args in [&["install"][..], &["install", redownload], &["pristine"]] { + let out = bundle(&dir, args); + assert!( + out.status.success(), + "{command}: bundle {args:?} after the unwind:\nstdout:\n{}\nstderr:\n{}", + String::from_utf8_lossy(&out.stdout), + String::from_utf8_lossy(&out.stderr) + ); + let run = bundle(&dir, &["exec", "ruby", "-e", probe]); + assert_eq!( + String::from_utf8_lossy(&run.stdout), + "VULNERABLE", + "{command}: bundle {args:?} leaves the upstream code loaded:\n{}", + String::from_utf8_lossy(&run.stderr) + ); + } +} + +#[tokio::test(flavor = "multi_thread")] +#[ignore = "host capstone: shells out to a real ruby/gem/bundler (>= 1.17); the unpinned `test` \ + job skips it, an e2e job with a pinned toolchain runs it via --ignored"] +async fn gem_vendored_unwind_restores_an_install_the_hosted_scan_patched() { + let Some(fx) = redirect_scanned_project( + "vendored-install-unwind", + Spelling::Gemfile, + false, + true, + None, + Driver::ScanVex, + ) + .await + else { + return; + }; + mount_vendored_grant(&fx).await; + for command in ["remove", "rollback", "vendor --revert"] { + vendored_unwind_restores_the_installed_gem(&fx, command); + } +} + /// #1831: a hosted redirect over a CRLF Gemfile (a Windows checkout, or /// `core.autocrlf=true`) keeps it CRLF throughout: the edit is the option /// alone, the real bundler installs the pair frozen and has nothing to 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 3cb847343..8da83bbc0 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 @@ -2892,31 +2892,42 @@ async fn vendored_unwind_restores_an_install_a_hosted_scan_patched() { } } -/// The human run says what it replaced, and its "keeps its patched bytes" -/// note no longer counts the gem. +/// The human run says what it replaced, after its own line for the gem, +/// and rollback's "keeps its patched bytes" note no longer counts the gem. #[tokio::test(flavor = "multi_thread")] async fn vendored_unwind_reports_the_refresh_in_a_human_run() { - let server = MockServer::start().await; - let tmp = tempfile::tempdir().unwrap(); - let proj = tmp.path().join("proj"); - let (gem_dir, _) = hosted_then_vendored(&server, &proj).await; + let own_lines = [ + format!("Reverted vendoring for {PURL}"), + format!("Reverted vendoring for {PURL}"), + "Reverted 1 vendored package".to_string(), + ]; + for (unwind, own_line) in VENDORED_UNWINDS.into_iter().zip(own_lines) { + let server = MockServer::start().await; + let tmp = tempfile::tempdir().unwrap(); + let proj = tmp.path().join("proj"); + let (gem_dir, _) = hosted_then_vendored(&server, &proj).await; - let (code, stdout, stderr) = unwind_run(&proj, &server.uri(), &["rollback", "--yes"]); - assert_eq!(code, 0, "{stdout}\n{stderr}"); - assert_eq!(installed_lib(&gem_dir), UPSTREAM_LIB); - let reverted = stdout - .find(&format!("Reverted vendoring for {PURL}")) - .unwrap_or_else(|| panic!("{stdout}")); - let replaced = stdout - .find(&format!( + let (code, stdout, stderr) = unwind_run(&proj, &server.uri(), unwind); + assert_eq!(code, 0, "{unwind:?}: {stdout}\n{stderr}"); + assert_eq!(installed_lib(&gem_dir), UPSTREAM_LIB, "{unwind:?}"); + let replaced = format!( "Replaced the installed copy of 1 gem with the upstream build: {DEP} {DEP_VERSION}." - )) - .unwrap_or_else(|| panic!("{stdout}")); - assert!(reverted < replaced, "{stdout}"); - assert!( - !stdout.contains("patched bytes in installed trees"), - "nothing is left for a reinstall:\n{stdout}" - ); + ); + assert_eq!(stdout.matches(&replaced).count(), 1, "{unwind:?}: {stdout}"); + assert!(stdout.contains(&own_line), "{unwind:?}: {stdout}"); + if unwind[0] != "vendor" { + assert!( + stdout.find(&own_line) < stdout.find(&replaced), + "{unwind:?}: {stdout}" + ); + } + assert!( + !stdout.contains("patched bytes in installed trees") + && !stderr.contains("upstream_gem") + && !stderr.contains("Warning:"), + "{unwind:?}: nothing is left to warn about:\n{stdout}\n{stderr}" + ); + } } /// A copy the unwind may not or cannot refresh is left exactly as it was @@ -2979,6 +2990,43 @@ async fn vendored_unwind_names_an_install_it_leaves_on_the_patched_build() { } } +/// The human run of the same: one warning with the remedy as a command, +/// and rollback's reinstall note still counts the gem. +#[tokio::test(flavor = "multi_thread")] +async fn vendored_unwind_warns_once_in_a_human_run() { + for unwind in VENDORED_UNWINDS { + let server = MockServer::start().await; + let tmp = tempfile::tempdir().unwrap(); + let proj = tmp.path().join("proj"); + let (gem_dir, archive) = hosted_then_vendored(&server, &proj).await; + + let mut args = unwind.to_vec(); + args.push("--no-gem-install-refresh"); + let (code, stdout, stderr) = unwind_run(&proj, &server.uri(), &args); + assert_eq!(code, 0, "{unwind:?}: {stdout}\n{stderr}"); + assert_eq!(installed_lib(&gem_dir), PATCHED_LIB, "{unwind:?}"); + let warning = "Warning: 1 gem still holds the patched build on disk after the switch \ + back to the upstream registry"; + assert_eq!(stderr.matches(warning).count(), 1, "{unwind:?}: {stderr}"); + assert!( + stderr.contains(&format!("rm -f {}", project_home(&proj).display())) + && stderr.contains(&format!("{} && bundle install", archive.display())), + "{unwind:?}: {stderr}" + ); + assert!( + !stderr.contains("Re-run"), + "{unwind:?}: a second unwind has nothing to unwind: {stderr}" + ); + assert!(!stdout.contains("Replaced the installed copy"), "{stdout}"); + if unwind[0] == "rollback" { + assert!( + stdout.contains("1 unwired package keeps its patched bytes"), + "{stdout}" + ); + } + } +} + /// A gem that was only ever vendored still has the upstream build /// installed: its unwind changes nothing in the gem home, downloads no /// gem and raises nothing about it. diff --git a/docs/ecosystems.md b/docs/ecosystems.md index 6de6d91b6..a3a2c1fb5 100644 --- a/docs/ecosystems.md +++ b/docs/ecosystems.md @@ -1958,7 +1958,10 @@ owns the installed copy, and swapped in once it has compiled; with no such Ruby, `--no-gem-native-rebuild`, it is left alone. After the scan `bundle exec` runs the patched code, and every kind of reinstall keeps it. `rollback` and `remove` do the same with the upstream gem. Vendoring a gem that was hosted (`vendor`, `scan --mode vendored`) leaves the installed copies as -they are: Bundler loads the vendored copy from then on. +they are: Bundler loads the vendored copy from then on. When that vendored gem is later unwound +(`rollback`, `remove`, `vendor --revert`), Bundler loads the installed copy again, so the unwind +puts the upstream gem back there too. A gem that was only ever vendored still has the upstream +build installed, and its unwind changes nothing in the gem home. Nothing is changed when the patched gem cannot be downloaded or verified: the run still exits 0 and warns (`redirect_gem_stale_install`), naming the files to remove by hand. `--dry-run` only From 1fb6e8355954857ddd1034628b3e7d3a91a0869b Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 09:57:36 +0000 Subject: [PATCH 4/4] Judge only rubygems.org gems after an unwind Review follow-ups for the vendored unwind's gem refresh. An entry vendored over hosted wiring before v5 reverts to its hosted pin, whose CHECKSUMS sha256 is the patched gem's. Judging the installed copy against it would call a correct upstream install stale. The refresh now covers only a gem the lock resolves from rubygems.org; the hosted unwind that follows restores such a pin and refreshes then. remove prints the refresh's progress line before it aborts on a failed ledger save, since the gem home was already changed. Refs #2083 Assisted-by: Claude Code:claude-fable-5-2 Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_011f9aeQ4raW21EPjpN9cP36 --- crates/socket-patch-cli/CLI_CONTRACT.md | 4 ++-- .../socket-patch-cli/src/commands/gem_refresh.rs | 14 ++++++++++++-- crates/socket-patch-cli/src/commands/remove.rs | 6 ++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/crates/socket-patch-cli/CLI_CONTRACT.md b/crates/socket-patch-cli/CLI_CONTRACT.md index 6f702b1d8..72e92a1e2 100644 --- a/crates/socket-patch-cli/CLI_CONTRACT.md +++ b/crates/socket-patch-cli/CLI_CONTRACT.md @@ -456,11 +456,11 @@ The rewriter reads a fixed set of candidate files from the project root: the npm - A human run prints ONE warning for all of them: how many gems, which gems in which gem home (or why they were not refreshed), why in one sentence, and the remedy as a command. - A stale-flagged purl is additionally **excluded from the same run's `--vex` `assume_applied` set** — the envelope must never attest a CVE its own warning says is live; the purl falls back to normal installed-tree verification (a patched install still attests, a stale one is omitted). A same-run `--vex` may still fail on "nothing to attest" per the embedded-VEX contract. -*The unwind direction.* After a hosted unwind — `rollback` / `remove` of a hosted pin, scan's withdrawn-patch restore, `vendor --revert` of a package vendored over hosted wiring before v5 — put a gem back on its upstream registry entry, its installed copies and archives hold the PATCHED gem, with the same consequences in reverse: the patched code keeps running, and on bundler ≥ 2.6 `bundle pristine` fails on the restored upstream checksum. The unwind applies the same refresh with the upstream gem: the sha256 is the restored lock's `CHECKSUMS` entry, else the rubygems.org compact index; the archive is taken from disk, else downloaded from rubygems.org when the lock resolves the gem from it (a gem from another remote is refreshed only from an archive already on disk). An installed copy is stale when its `/cache/.gem` is readable and is not the upstream archive (ruby-platform gems only: the lock's checksum names that archive). Notes are `upstream_gem_install_refreshed` / `upstream_gem_install_would_refresh`; an installed copy left on the patched build is `upstream_gem_stale_install` (one consolidated warning in a human run), and an archive left in bundler's cache dir keeps its `upstream_gem_stale_cache` warning. A gem whose installed copies were refreshed is not counted in rollback's "keep their patched bytes" note. The warning names no re-run: the unwind already removed the wiring a second run would look for, so its remedy is the files to remove before `bundle install`. +*The unwind direction.* After a hosted unwind — `rollback` / `remove` of a hosted pin, scan's withdrawn-patch restore, `vendor --revert` of a package vendored over hosted wiring before v5 — put a gem back on its upstream registry entry, its installed copies and archives hold the PATCHED gem, with the same consequences in reverse: the patched code keeps running, and on bundler ≥ 2.6 `bundle pristine` fails on the restored upstream checksum. The unwind applies the same refresh with the upstream gem: the sha256 is the restored lock's `CHECKSUMS` entry, else the rubygems.org compact index; the archive is taken from disk, else downloaded from rubygems.org when the lock resolves the gem from it (a gem from another remote is refreshed only from an archive already on disk). An installed copy is stale when its `/cache/.gem` is readable and is not the upstream archive (ruby-platform gems only: the lock's checksum names that archive). Notes are `upstream_gem_install_refreshed` / `upstream_gem_install_would_refresh`; an installed copy left on the patched build is `upstream_gem_stale_install` (one consolidated warning in a human run), and an archive left in bundler's cache dir keeps its `upstream_gem_stale_cache` warning. A gem whose installed copies were refreshed is not counted in rollback's "keep their patched bytes" note. A copy left by `--no-gem-install-refresh` or a failed refresh is named with the files to remove before `bundle install`, and no re-run: the unwind already removed the wiring a second run would look for. *What never refreshes.* A hosted → vendored takeover (`vendor`, `scan` / `get --mode vendored` over a hosted pin) puts the gem on its upstream entry only on its way to the vendored `path:` source, which is what Bundler loads from then on. The copies Bundler already holds are unused leftovers there, so the takeover changes none of them and downloads no gem for them: resetting the installed copy to the upstream build would cost a registry download in the mode that needs none, and would turn a patched leftover into an unpatched one that `vex` reports against the vendored artifact (`vendored_tree_out_of_sync`, whose gem wording names the copy and how to remove it). Its `upstream_gem_stale_cache` advisory about a patched cache-dir archive is as before. A vendored unwind (`remove`, `rollback`, `vendor --revert`, `scan --prune`, `vendor`'s reconcile of a vendored gem) likewise only names that archive, and never replaces it. -*A vendored unwind after a hosted scan.* Once a vendored gem is unwound, Bundler loads its installed copy again, so the leftover is in use: if a hosted scan made that copy the patched build before the gem was vendored, the patched code would keep running under the upstream lock, and on bundler ≥ 2.6 `bundle pristine` would fail on the upstream checksum. A wet `rollback`, `remove`, `vendor --revert` or `vendor` reconcile that put a vendored gem back on its upstream entry therefore applies the unwind direction's refresh to the gem's INSTALLED copies, under the same rules (staleness judged by `/cache/.gem` against the upstream sha256; a project-local gem home only, unless `--gem-refresh-shared`; `--no-gem-install-refresh`; an archive on disk, else rubygems.org unless `--offline`), with the same `upstream_gem_install_refreshed` note and `upstream_gem_stale_install` warning. `--json` carries them where the command carries a vendored revert's advisories (rollback `warnings[]`; `remove` / `vendor` advisory events); a human run prints the progress line after the gem's own line and one warning for the gems left on the patched build. The upstream sha256 is looked up only for a gem that has an installed copy with its archive, so the unwind of a gem that is not installed needs no network. A gem that was only ever vendored has the upstream archive there: nothing is downloaded or changed. A `--dry-run` does not preview this (the lock on disk is still the vendored one), and `scan --prune` does not refresh. +*A vendored unwind after a hosted scan.* Once a vendored gem is unwound, Bundler loads its installed copy again, so the leftover is in use: if a hosted scan made that copy the patched build before the gem was vendored, the patched code would keep running under the upstream lock, and on bundler ≥ 2.6 `bundle pristine` would fail on the upstream checksum. A wet `rollback`, `remove`, `vendor --revert` or `vendor` reconcile that put a vendored gem back on its upstream entry therefore applies the unwind direction's refresh to the gem's INSTALLED copies when the lock now resolves the gem from rubygems.org (a gem from another remote is not judged: nothing proves its entry is the upstream one), under the same rules (staleness judged by `/cache/.gem` against the upstream sha256; a project-local gem home only, unless `--gem-refresh-shared`; `--no-gem-install-refresh`; an archive on disk, else rubygems.org unless `--offline`), with the same `upstream_gem_install_refreshed` note and `upstream_gem_stale_install` warning. `--json` carries them where the command carries a vendored revert's advisories (rollback `warnings[]`; `remove` / `vendor` advisory events); a human run prints the progress line after the gem's own line and one warning for the gems left on the patched build. The upstream sha256 is looked up only for a gem that has an installed copy with its archive, so the unwind of a gem that is not installed needs no network. A gem that was only ever vendored has the upstream archive there: nothing is downloaded or changed. A `--dry-run` does not preview this (the lock on disk is still the vendored one), and `scan --prune` does not refresh. **Pipenv hosted redirect (`Pipfile.lock`, pipfile-spec 6)**: every category other than `_meta` (`default`, `develop`, and Pipenv 2022+ named categories) that pins the package at the patched version is rewritten to the hosted reference — `{"file" | "path": "#sha256=", "hashes": ["sha256:"]}` with `markers`/`extras`/`index` kept exactly as Pipenv wrote them (present or absent: whether Pipenv records `index` depends on its release, the Pipfile spelling and the locking environment, so only the entry itself knows) and `version` dropped; `_meta` (the Pipfile content hash) and the Pipfile itself are never touched, so `pipenv install --deploy`/`sync`/`verify` keep passing. The reference KEY depends on the installing Pipenv: releases 7–11 only install `path` references, 2018 and later `file` ones (0–6 write pipfile-spec < 6 and are refused). The release is probed once per command with `pipenv --version`, resolved on ABSOLUTE `PATH` entries only (a relative entry would run a `pipenv` planted in the scanned repository; `.bat`/`.cmd` shims are found through `PATHEXT` on Windows), only when a pypi patch actually targets an entry of the lock, and `SOCKET_PIPENV_MAJOR=` pins the answer without spawning anything. An unknown installer selects `file` and warns `redirect_pipenv_installer_unknown` only when the lock was rewritten. **Refusal scope**: a pin/source CONFLICT (another version pinned, a foreign `file`/`path` source, a VCS/editable dependency) refuses the whole dependency atomically across categories as `redirect_pipenv_refused` AND vetoes the sibling Python rewriters (requirements.txt / uv.lock / pyproject) for that patch — the project's Pipenv install could not pick the patch up, so a half-redirected checkout is refused; anything else (no entry for the package, an old pipfile-spec, an unparseable lock, a digest-less patch) is `redirect_pipenv_skipped` and leaves the siblings alone (a stale Pipfile.lock in a uv/Poetry/requirements project must not block them). The veto applies to a LIVE lock only: a `Pipfile.lock` with no `Pipfile` beside it is abandoned, so its conflict refuses that file but never the siblings. Hash enforcement at install time is split by era — the `#sha256=` URL fragment is what Pipenv 2023+ verifies, the `hashes` list what 2018–2022 verify, Pipenv 11 either — so both are load-bearing. **Pipenv stale-install guard**: Pipenv never reinstalls a release that is already present (`pipenv install`, `install --deploy` and `sync` all exit 0 and keep the installed bytes — measured on 11.10.4, 2018.11.26 and 2026.8.0, hosted and vendored), so after the rewrite the run probes the Python crawler's site-packages (VIRTUAL_ENV, `./.venv`, `./venv`, Pipenv's out-of-tree `WORKON_HOME` venv; `--global`/`--global-prefix` honoured) for each confirmed Pipfile.lock redirect with the Python stale-install guard's evidence (the pinned patched wheel, else the patch record; STALE needs positive evidence, read-only, skipped on `--dry-run`, stale purls excluded from the same-run `--vex` `assume_applied` set) and the Python stale-install guard (`redirect_pypi_stale_install`, see above) names the site-packages dir and the Pipenv-specific verified remedy: `pipenv run pip uninstall -y && pipenv sync` (or `pipenv --rm && pipenv sync`), with the `sync` arguments following the lock, since plain `pipenv sync` installs only `default`: the targeted form re-syncs the categories that pin the package (`--dev` for `develop`, `--categories ""` for a named category) and the `--rm` form re-syncs every non-empty category — NOT `pipenv uninstall`, which rewrites the Pipfile and re-locks the patch away. The vendored backend emits the twin `pypi_pipenv_stale_install` (`skipped` warning event). **Rollback** (v5.0, upstream restore): each hosted entry gets its registry shape back — `"version": "=="`, the entry's own `index` carried back unchanged (refused unless it — and the Pipfile's explicit `index`, if any — names a PyPI source in `_meta.sources`), and every release file's sha256 from PyPI's JSON API (`SOCKET_PYPI_JSON_API`), sorted by filename as Pipenv records them; an entry that pins another version beside the hosted reference is refused with the `git checkout` remedy (see "Hosted unwind coverage"). A Pipfile names no project, so a same-run `--vex` on a Pipenv project needs `--vex-product` (or a git remote) to detect a product purl. **Discovery**: `Pipfile.lock` is part of the lockfile inventory (every category's `==` pins, with the lock's digest set as `Sha256AnyOf` integrity so a lock-only checkout can be vendored by fetching the pure wheel through PyPI's JSON API — only when `_meta.sources` name the public index; a private-index lock stays discovery-only and never reaches pypi.org), and Socket's own hosted / vendored references stay discoverable as the package they replace, so a re-scan of an already-redirected or already-vendored lock-only checkout re-confirms it (`--vex` attests, vendored reports `already_vendored`) instead of finding nothing. diff --git a/crates/socket-patch-cli/src/commands/gem_refresh.rs b/crates/socket-patch-cli/src/commands/gem_refresh.rs index 372820008..4c6958b3b 100644 --- a/crates/socket-patch-cli/src/commands/gem_refresh.rs +++ b/crates/socket-patch-cli/src/commands/gem_refresh.rs @@ -757,8 +757,9 @@ pub(crate) async fn after_restore( /// [`after_restore`] does it. An archive in Bundler's cache dir is not /// touched: the vendored unwind names it (`upstream_gem_stale_cache`). /// -/// A gem with no installed copy to judge costs no registry lookup: a -/// vendored unwind then needs no network, as before. +/// Only a gem the lock now resolves from rubygems.org is judged. A gem +/// with no installed copy to judge costs no registry lookup: a vendored +/// unwind then needs no network, as before. pub(crate) async fn after_vendored_unwind( common: &GlobalArgs, unwound: &[String], @@ -795,6 +796,15 @@ async fn refresh_restored( if let Some((sha, url)) = gem_upstream_archive(&common.cwd, staged, purl, common.offline).await { + // A vendored revert does not prove where the lock resolves the + // gem from: an entry vendored over hosted wiring before v5 + // reverts to its hosted pin, whose `CHECKSUMS` sha256 is the + // patched gem's (the hosted unwind restores that pin next, and + // refreshes then). Only a gem the lock resolves from + // rubygems.org is known to be back on its upstream entry. + if scope == Scope::Installed && url.is_none() { + continue; + } shas.insert(purl.clone(), sha); urls.insert(purl.clone(), url); } diff --git a/crates/socket-patch-cli/src/commands/remove.rs b/crates/socket-patch-cli/src/commands/remove.rs index 348dd6f2d..1a79c5247 100644 --- a/crates/socket-patch-cli/src/commands/remove.rs +++ b/crates/socket-patch-cli/src/commands/remove.rs @@ -1517,6 +1517,12 @@ async fn revert_vendored_matches( ); } VendorRevertStep::LedgerWriteFailed(e) => { + // The revert landed, and so did the gem refresh after it. + if loud { + for line in &progress { + println!("{line}"); + } + } emit_error_envelope( args.common.json, args.common.dry_run,