From a66f8d7b13eed4d47a95ebc08021327d78925f04 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 3 Dec 2026 13:24:39 +0000 Subject: [PATCH 1/4] Start fix for per-platform gem refusal lines Refs #2436. Assisted-by: Claude Code:claude-fable-5-2 From ced9ae9f7338598156738cf6825a7e7996c443d7 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 3 Dec 2026 13:44:12 +0000 Subject: [PATCH 2/4] Test one lock refusal per gem in vendored scan A gem that Gemfile.lock locks for the ruby platform beside platform gems, with a patch for each build, must be refused once: one failed event, one [error] line, one would-refuse row and a count of one. Fails on main, which reports the refusal for every patch (#2436). Assisted-by: Claude Code:claude-fable-5-2 --- .../tests/in_process_vendor.rs | 169 ++++++++++++++++++ 1 file changed, 169 insertions(+) diff --git a/crates/socket-patch-cli/tests/in_process_vendor.rs b/crates/socket-patch-cli/tests/in_process_vendor.rs index 543555bb37..21b6fe09b0 100644 --- a/crates/socket-patch-cli/tests/in_process_vendor.rs +++ b/crates/socket-patch-cli/tests/in_process_vendor.rs @@ -3717,6 +3717,175 @@ async fn scan_vendor_gem_refuses_a_gitignored_ledger() { } } +/// The demo gem locked for the ruby platform beside two platform gems, +/// which vendored mode refuses (`platform_gem_unsupported`). +const GEM_LOCK_RUBY_BESIDE_PLATFORMS: &str = "GEM\n remote: https://rubygems.org/\n specs:\n demo-gem (1.0.0)\n demo-gem (1.0.0-arm64-darwin)\n demo-gem (1.0.0-x86_64-linux)\n\nPLATFORMS\n arm64-darwin\n ruby\n x86_64-linux\n\nDEPENDENCIES\n demo-gem (~> 1.0)\n\nBUNDLED WITH\n 4.1.1\n"; + +/// Discovery for the demo gem with a patch for the ruby gem and one for +/// each of two platform gems, as the patch service publishes them. No view +/// is mounted: a gem the lock refuses is refused before any view is asked +/// for. +async fn mount_gem_platform_patches(mock: &wiremock::MockServer) { + use wiremock::matchers::{method, path}; + use wiremock::{Mock, ResponseTemplate}; + const PLATFORM_PATCHES: [(&str, &str); 3] = [ + ("ruby", GEM_UUID), + ("arm64-darwin", GEM_UUID2), + ("x86_64-linux", "37373737-3737-4737-8737-373737373737"), + ]; + let patches: Vec = PLATFORM_PATCHES + .iter() + .map(|(platform, uuid)| { + json!({ + "uuid": uuid, + "purl": format!("{GEM_PURL}?platform={platform}"), + "tier": "free", + "cveIds": ["CVE-2026-0002"], + "ghsaIds": [], + "severity": "high", + "title": "gem vendor target" + }) + }) + .collect(); + Mock::given(method("POST")) + .and(path("/v0/orgs/test-org/patches/batch")) + .respond_with(ResponseTemplate::new(200).set_body_json(json!({ + "packages": [{ "purl": GEM_PURL, "patches": patches }], + "canAccessPaidPatches": false, + }))) + .mount(mock) + .await; + let listed: Vec = PLATFORM_PATCHES + .iter() + .map(|(platform, uuid)| { + json!({ + "uuid": uuid, + "purl": format!("{GEM_PURL}?platform={platform}"), + "publishedAt": "2026-01-01T00:00:00Z", + "description": "gem vendor patch", + "license": "MIT", + "tier": "free", + "vulnerabilities": {} + }) + }) + .collect(); + Mock::given(method("GET")) + .and(path( + "/v0/orgs/test-org/patches/by-package/pkg%3Agem%2Fdemo-gem%401.0.0", + )) + .respond_with(ResponseTemplate::new(200).set_body_json(json!({ + "patches": listed, + "canAccessPaidPatches": false, + }))) + .mount(mock) + .await; +} + +/// The arguments of a vendored scan of `root` against `mock_uri`, less +/// `--json`. +fn scan_vendor_argv<'a>(root: &'a Path, mock_uri: &'a str) -> Vec<&'a str> { + vec![ + "scan", + "--mode", + "vendored", + "--yes", + "--api-url", + mock_uri, + "--api-token", + "fake-token", + "--org", + "test-org", + "--cwd", + root.to_str().unwrap(), + ] +} + +/// A refusal `Gemfile.lock` gives for a gem is the gem's, whichever of its +/// builds a patch is for: a gem with a patch per locked build is refused +/// once, under the patch of its ruby gem, and counted as one failure +/// (#2436). Nothing is written. +#[tokio::test] +async fn scan_vendor_gem_lock_refusal_is_reported_once_per_gem() { + let mock = wiremock::MockServer::start().await; + mount_gem_platform_patches(&mock).await; + let fx = gem_fixture(); + std::fs::write(fx.lock_path(), GEM_LOCK_RUBY_BESIDE_PLATFORMS).unwrap(); + let uri = mock.uri(); + + let (code, env) = run_scan_vendor(fx.root(), &uri, &[]); + assert_eq!(code, 1, "{env:#}"); + let failed: Vec<&Value> = env["events"] + .as_array() + .unwrap() + .iter() + .filter(|e| e["action"] == "failed") + .collect(); + assert_eq!(failed.len(), 1, "one refusal for the gem: {env:#}"); + assert_eq!(failed[0]["purl"], GEM_PURL_QUALIFIED, "{env:#}"); + assert_eq!(failed[0]["uuid"], GEM_UUID, "{env:#}"); + assert_eq!( + failed[0]["errorCode"], "platform_gem_unsupported", + "{env:#}" + ); + assert_eq!(env["summary"]["failed"], 1, "{env:#}"); + + let (code, stdout, stderr) = run_cli(fx.root(), &scan_vendor_argv(fx.root(), &uri), &[]); + assert_eq!(code, 1, "stdout:\n{stdout}\nstderr:\n{stderr}"); + let refusals: Vec<&str> = stderr + .lines() + .filter(|line| line.contains("platform_gem_unsupported")) + .collect(); + assert_eq!(refusals.len(), 1, "stdout:\n{stdout}\nstderr:\n{stderr}"); + assert!( + refusals[0].contains(&format!("[error] {GEM_PURL_QUALIFIED} (")), + "{refusals:?}" + ); + let all = format!("{stdout}{stderr}"); + assert!( + all.contains("Nothing was vendored: 1 patch failed (see above)."), + "stdout:\n{stdout}\nstderr:\n{stderr}" + ); + + // The dry run previews the same single refusal. + let mut argv = scan_vendor_argv(fx.root(), &uri); + argv.push("--dry-run"); + let (code, stdout, stderr) = run_cli(fx.root(), &argv, &[]); + assert_eq!(code, 0, "stdout:\n{stdout}\nstderr:\n{stderr}"); + let previewed: Vec<&str> = stdout + .lines() + .filter(|line| line.contains("[would-refuse]")) + .collect(); + assert_eq!(previewed.len(), 1, "stdout:\n{stdout}\nstderr:\n{stderr}"); + assert!( + previewed[0].contains(&format!( + "[would-refuse] {GEM_PURL_QUALIFIED} (platform_gem_unsupported)" + )), + "{previewed:?}" + ); + argv.push("--json"); + let (code, stdout, stderr) = run_cli(fx.root(), &argv, &[]); + assert_eq!(code, 0, "stdout:\n{stdout}\nstderr:\n{stderr}"); + let env: Value = serde_json::from_str(stdout.trim()).unwrap(); + let skipped: Vec<&Value> = env["events"] + .as_array() + .unwrap() + .iter() + .filter(|e| e["errorCode"] == "platform_gem_unsupported") + .collect(); + assert_eq!(skipped.len(), 1, "{env:#}"); + assert_eq!(skipped[0]["purl"], GEM_PURL_QUALIFIED, "{env:#}"); + + assert!(!fx.root().join(".socket/vendor").exists()); + assert_eq!( + std::fs::read_to_string(fx.lock_path()).unwrap(), + GEM_LOCK_RUBY_BESIDE_PLATFORMS + ); + assert_eq!( + std::fs::read_to_string(fx.gemfile_path()).unwrap(), + GEM_GEMFILE + ); +} + /// A gem `scan --mode vendored` run at patch A, then the bytes of the /// files that wiring owns: Gemfile, lock, ledger and the vendored lib. async fn gem_vendored_at_a() -> (GemFixture, [Vec; 4]) { From eaf847732d5c85fe146df1d1de1f27df22ba8f87 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 3 Dec 2026 13:44:12 +0000 Subject: [PATCH 3/4] Report a gem's lock refusal once per gem A vendored scan selects a patch for each build of a gem the lock names, and a refusal read from Gemfile.lock is the same for all of them. The download phase and the dry-run preview reported it for every patch and counted each as a failure: nine identical lines for nokogiri on a default Bundler 4 lock. The refusal is now reported under one patch of the gem, the ruby gem's where it is refused, else the first. The other patches stay refused (not downloaded, no rollout slot) with no line, event or count of their own. Refs #2436. Assisted-by: Claude Code:claude-fable-5-2 --- crates/socket-patch-cli/CLI_CONTRACT.md | 2 +- .../src/commands/agent_download.rs | 14 +++ .../src/commands/scan/vendor_flow.rs | 54 +++++++++- .../socket-patch-core/src/vendor/refusals.rs | 100 ++++++++++++++++++ docs/ecosystems.md | 2 +- 5 files changed, 169 insertions(+), 3 deletions(-) diff --git a/crates/socket-patch-cli/CLI_CONTRACT.md b/crates/socket-patch-cli/CLI_CONTRACT.md index a14c8e6816..3b57a8605d 100644 --- a/crates/socket-patch-cli/CLI_CONTRACT.md +++ b/crates/socket-patch-cli/CLI_CONTRACT.md @@ -2934,7 +2934,7 @@ command's integration tests check its output. | `vendor_uuid_mismatch` | `skipped` | repair: the manifest's patch uuid moved past the vendored artifact — a re-vendor (`vendor` / `scan --mode vendored`) is pending; repair does not cross patch generations. | | `content_mismatch_overwritten` | `skipped` (warning) | apply (explicit `--allow-patch-conflicts` / `--force`): a file matched NEITHER beforeHash nor afterHash and was overwritten with the full verified patched content. This includes a file the patch adds (empty beforeHash) that already exists with other content. `--strict` turns this case into a `failed` event instead. Agent-mode `get` / `scan --json` carry it as a `(content_mismatch_overwritten) …` `warnings[]` entry (#1004). | | `vendor_lock_checksums_unsupported` / `vendor_stale_lock_checksum` | `failed` | vendor (gem): an ambiguous/platform CHECKSUMS entry, or a v1-wired lock whose stale token blocks the hot path (run `vendor --revert` + re-vendor). | -| `platform_gem_unsupported` | `failed` | vendor / scan / get `--mode vendored` (gem): a precompiled platform gem that cannot be vendored. `Gemfile.lock` pins the gem as platform gems (`nokogiri (1.18.10-x86_64-linux-gnu)`) and also holds the plain ` ()` entry of the `ruby` platform, which no platform tree serves (the detail names it and each locked platform that keeps it, `ruby` or one that none of the gem's platform gems serves, with the `bundle lock --remove-platform ` command that drops them); or it pins the gem as platform gems and its `BUNDLED WITH` is absent or names a Bundler older than 2.3, the oldest the vendored layout is verified on (the detail names the version needed; `bundle update --bundler` re-locks); or the installed copy is a platform gem and the lock names no platform for the gem; or the patch record is for one platform's gem (`?platform=`) and is not vendored as part of its fix: the lock does not pin the gem as platform gems. Nothing is written. A locked platform with no patch of the fix is not this failure: see `vendor_prebuilt_platform_pending`. | +| `platform_gem_unsupported` | `failed` | vendor / scan / get `--mode vendored` (gem): a precompiled platform gem that cannot be vendored. `Gemfile.lock` pins the gem as platform gems (`nokogiri (1.18.10-x86_64-linux-gnu)`) and also holds the plain ` ()` entry of the `ruby` platform, which no platform tree serves (the detail names it and each locked platform that keeps it, `ruby` or one that none of the gem's platform gems serves, with the `bundle lock --remove-platform ` command that drops them); or it pins the gem as platform gems and its `BUNDLED WITH` is absent or names a Bundler older than 2.3, the oldest the vendored layout is verified on (the detail names the version needed; `bundle update --bundler` re-locks); or the installed copy is a platform gem and the lock names no platform for the gem; or the patch record is for one platform's gem (`?platform=`) and is not vendored as part of its fix: the lock does not pin the gem as platform gems. Nothing is written. In `scan` / `get --mode vendored`, a refusal the lock gives for the gem is reported once however many of the gem's platform gems have a selected patch: one `failed` event and one `[error]` line (one `skipped` event and one `[would-refuse]` line under `--dry-run`), under the patch of the ruby gem, or under the first of the gem's refused patches in purl order where the ruby gem's is not one of them; the gem's other patches are refused with it and have no event, line or count of their own (#2436). A locked platform with no patch of the fix is not this failure: see `vendor_prebuilt_platform_pending`. | | `redirect_unattributable` | `skipped` (hosted event) | scan/get `--mode hosted`: the rewriters would pin the patch, but lockfile discovery over the result reads that pin as contested (another lock or requirements file resolves the same version elsewhere, or the pin is not one the package manager consumes), so `vex`, `rollback`, `remove` and `vendor` would refuse it. The candidate is left out of the rewrite, so nothing is written for it; the detail carries discovery's findings. Exit code unchanged. | | `redirect_mirror_unsupported` / `redirect_mirror_url_refused` | `skipped` (hosted event) + `warnings[]` | **Experimental** (patch mirror). scan/get `--mode hosted` with `--patch-mirror-url`: the patch's ecosystem cannot be served through a mirror (`redirect_mirror_unsupported`: Cargo, NuGet; use `--mode vendored`), or its reference could not be moved onto the mirror (`redirect_mirror_url_refused`). Nothing is written for it. See "Patch mirror (experimental)". | | `redirect_mirror_unavailable` | `skipped` (hosted event) + `warnings[]` | **Experimental** (patch mirror). scan/get `--mode hosted` with `--patch-mirror-url`: the mirror did not serve the reference the run asked it for, or could not be reached. That reference is skipped and nothing is written for it. One warning per package, or a single warning about the mirror when it served none of the references it was asked about. | diff --git a/crates/socket-patch-cli/src/commands/agent_download.rs b/crates/socket-patch-cli/src/commands/agent_download.rs index 02661a20d2..67d94655ec 100644 --- a/crates/socket-patch-cli/src/commands/agent_download.rs +++ b/crates/socket-patch-cli/src/commands/agent_download.rs @@ -1408,6 +1408,20 @@ pub(crate) async fn fetch_selected_patches( } else { (selected, Vec::new()) }; + // A refusal that is the gem's (what its lock says) is reported under + // one patch of the gem, not once for each of its builds' patches: the + // others are refused with it and have no line, event or count of + // their own. + let repeats = socket_patch_core::vendor::refusals::repeated_gem_refusals( + selected.iter().filter_map(|sr| { + let refusal = refusals.get(&sr.purl)?; + Some((sr.purl.as_str(), refusal.code, refusal.detail.as_str())) + }), + ); + let selected: Vec = selected + .into_iter() + .filter(|sr| !repeats.contains(&sr.purl)) + .collect(); status.finish(); prefetched.extend(views); // The callers have already listed the patches (`scan`'s rows, `get`'s diff --git a/crates/socket-patch-cli/src/commands/scan/vendor_flow.rs b/crates/socket-patch-cli/src/commands/scan/vendor_flow.rs index 86a33d3f24..885d2d4021 100644 --- a/crates/socket-patch-cli/src/commands/scan/vendor_flow.rs +++ b/crates/socket-patch-cli/src/commands/scan/vendor_flow.rs @@ -113,6 +113,11 @@ pub(crate) struct PreviewRow { #[derive(Debug, Clone, Default)] pub(crate) struct VendorPreview { pub(crate) rows: Vec, + /// The patches refused with another patch of their gem, whose row + /// reports the refusal for the gem + /// ([`socket_patch_core::vendor::refusals::repeated_gem_refusals`]): + /// refused, with no row of their own. + refused_with_their_gem: HashSet, } impl VendorPreview { @@ -141,6 +146,7 @@ impl VendorPreview { .iter() .filter(|r| matches!(r.verdict, PreviewVerdict::WouldRefuse { .. })) .map(|r| r.purl.clone()) + .chain(self.refused_with_their_gem.iter().cloned()) .collect() } @@ -399,7 +405,21 @@ async fn preview_vendor_with( }) .collect(); rows.sort_by(|a, b| a.purl.cmp(&b.purl)); - VendorPreview { rows } + // As the wet run reports it: a gem's refusal has one row. + let refused_with_their_gem = + socket_patch_core::vendor::refusals::repeated_gem_refusals(rows.iter().filter_map(|row| { + match &row.verdict { + PreviewVerdict::WouldRefuse { code, detail } => { + Some((row.purl.as_str(), code.as_str(), detail.as_str())) + } + _ => None, + } + })); + rows.retain(|row| !refused_with_their_gem.contains(&row.purl)); + VendorPreview { + rows, + refused_with_their_gem, + } } /// The PyPI purls of `selected` the vendor backend's prelude refuses @@ -1646,6 +1666,38 @@ mod preview_tests { ); } + /// #2436: a gem refused alike under each of its builds' patches has + /// one would-refuse row, under the ruby gem's patch. The others stay + /// refused for the rollout plan, so none of them takes a slot. + #[tokio::test] + async fn preview_reports_a_gems_refusal_once() { + let tmp = tempfile::tempdir().unwrap(); + let purls = [ + "pkg:gem/preview-gem@1.0.0?platform=arm64-darwin", + "pkg:gem/preview-gem@1.0.0?platform=ruby", + "pkg:gem/preview-gem@1.0.0?platform=x86_64-linux", + ]; + let selected: Vec = purls.iter().map(|purl| sel(UUID, purl)).collect(); + let refusals: HashMap = purls + .iter() + .map(|purl| (purl.to_string(), ("vendor_test_refusal", "why".to_string()))) + .collect(); + let preview = preview_vendor_with(tmp.path(), &selected, &[], &refusals).await; + let rows: Vec<&str> = preview.rows.iter().map(|r| r.purl.as_str()).collect(); + assert_eq!(rows, [purls[1]]); + assert_eq!(preview.refused_count(), 1); + assert_eq!( + preview.dry_run_line(), + "[dry-run] Would download and vendor 0 of 1 patch (1 would be refused). \ + No changes made." + ); + let refused = preview.refused_purls(); + assert!( + purls.iter().all(|purl| refused.contains(*purl)), + "{refused:?}" + ); + } + const UUID: &str = "11111111-1111-4111-8111-111111111111"; const OLD_UUID: &str = "00000000-0000-4000-8000-000000000000"; const NPM: &str = "pkg:npm/preview-bun@1.0.0"; diff --git a/crates/socket-patch-core/src/vendor/refusals.rs b/crates/socket-patch-core/src/vendor/refusals.rs index d45480bd0e..a8183de69f 100644 --- a/crates/socket-patch-core/src/vendor/refusals.rs +++ b/crates/socket-patch-core/src/vendor/refusals.rs @@ -293,6 +293,48 @@ async fn gem_refusals( gem::gem_lock_refusals(project_root, &gems).await } +/// The gem purls of `refused` (each a refused patch purl with the code +/// and detail of its refusal) whose refusal another patch of their gem +/// reports: a refusal is the gem's when patches of it are refused for the +/// same reason in the same words (what `Gemfile.lock` says of the gem is +/// true of its ruby gem and of each of its platform gems), and a run with +/// a patch for each locked build reports it once (#2436). It is reported +/// under the patch of the ruby gem where that one is refused, else under +/// the first of the gem's refused patches; the rest are returned. They +/// stay refused: a caller leaves them out of what it downloads, prints +/// and counts. +pub fn repeated_gem_refusals<'a>( + refused: impl Iterator, +) -> HashSet { + use crate::utils::purl::{gem_platform_qualifier, purl_parts}; + // `(name, version, code, detail)` of a refusal → the patch that + // reports it. + let mut reported: HashMap<(String, String, &str, &str), &str> = HashMap::new(); + let mut repeats = HashSet::new(); + for (purl, code, detail) in refused { + let Some((ecosystem, name, version)) = purl_parts(purl) else { + continue; + }; + if ecosystem != "gem" { + continue; + } + match reported.entry((name, version, code, detail)) { + std::collections::hash_map::Entry::Vacant(first) => { + first.insert(purl); + } + std::collections::hash_map::Entry::Occupied(mut first) => { + let ruby_gem_takes_over = gem_platform_qualifier(purl).is_none() + && gem_platform_qualifier(first.get()).is_some(); + repeats.insert(match ruby_gem_takes_over { + true => first.insert(purl).to_string(), + false => purl.to_string(), + }); + } + } + } + repeats +} + fn refuse(out: &mut VendorRefusals, purl: &str, code: &'static str, detail: &str) { out.entry(purl.to_string()) .or_insert_with(|| VendorRefusal { @@ -456,6 +498,64 @@ pub async fn pristine_fetch_is_verifiable( mod tests { use super::*; + fn refusals_of(rows: &[(&str, &'static str, &str)]) -> VendorRefusals { + rows.iter() + .map(|(purl, code, detail)| { + let detail = detail.to_string(); + (purl.to_string(), VendorRefusal { code, detail }) + }) + .collect() + } + + /// One refusal for a gem whose patches are all refused alike, under + /// the ruby gem's patch where it is one of them (#2436). + #[test] + fn a_gems_refusal_is_reported_under_one_patch() { + const CODE: &str = "platform_gem_unsupported"; + let sorted = |refusals: &VendorRefusals| { + let refused = refusals + .iter() + .map(|(purl, refusal)| (purl.as_str(), refusal.code, refusal.detail.as_str())); + let mut repeats: Vec = repeated_gem_refusals(refused).into_iter().collect(); + repeats.sort(); + repeats + }; + // The ruby gem's patch sorts after the platform gems' and reports. + let refusals = refusals_of(&[ + ("pkg:gem/nokogiri@1.19.7?platform=arm64-darwin", CODE, "why"), + ("pkg:gem/nokogiri@1.19.7?platform=ruby", CODE, "why"), + ("pkg:gem/nokogiri@1.19.7?platform=x86_64-linux", CODE, "why"), + ]); + assert_eq!( + sorted(&refusals), + [ + "pkg:gem/nokogiri@1.19.7?platform=arm64-darwin", + "pkg:gem/nokogiri@1.19.7?platform=x86_64-linux" + ] + ); + // No patch of the ruby gem: the first platform's patch reports. + let refusals = refusals_of(&[ + ("pkg:gem/ffi@1.17.2?platform=arm64-darwin", CODE, "why"), + ("pkg:gem/ffi@1.17.2?platform=x86_64-linux", CODE, "why"), + ]); + assert_eq!( + sorted(&refusals), + ["pkg:gem/ffi@1.17.2?platform=x86_64-linux"] + ); + // Another gem, another version, another reason and another + // ecosystem each keep their own report. + let refusals = refusals_of(&[ + ("pkg:gem/ffi@1.17.2?platform=arm64-darwin", CODE, "why"), + ("pkg:gem/ffi@1.17.3?platform=arm64-darwin", CODE, "why"), + ("pkg:gem/ffi@1.17.2?platform=x86_64-linux", CODE, "other"), + ("pkg:gem/ffi@1.17.2", "another_code", "why"), + ("pkg:gem/rack@3.2.9", CODE, "why"), + ("pkg:pypi/six@1.16.0?artifact_id=a", CODE, "why"), + ("pkg:pypi/six@1.16.0?artifact_id=b", CODE, "why"), + ]); + assert!(sorted(&refusals).is_empty()); + } + /// #2269: a native gem that already holds the patch in hosted or /// agent mode is an expected skip; the refusal of one that does not /// is still a failure. diff --git a/docs/ecosystems.md b/docs/ecosystems.md index 1425438fab..95b09ca17e 100644 --- a/docs/ecosystems.md +++ b/docs/ecosystems.md @@ -5813,7 +5813,7 @@ that can patch the gem, or the change that lets vendored mode take it: | `gemfile_declaration_not_editable` ("is indented") | is declared inside a block: `group :test do`, `platforms … do`, a conditional. Every Rails Gemfile declares its development and test gems this way. | Move the declaration to the top level (for a plain `group` block the error spells the option that replaces it, `group: :test`), or patch the gem with `--mode hosted`, which edits a declaration where it is. Inside a `source`, `git`, `github` or `path` block hosted mode refuses the gem too, and the error names `--mode agent`. | | `gemfile_declaration_not_editable` ("as a direct dependency") | is a direct dependency the Gemfile declares out of sight: in a gemspec (a gem library's development dependency), an `eval_gemfile`d file, a loop. | Declare it with one literal `gem ""` line in the Gemfile (above `gemspec`, where the Gemfile has that directive), in place of any other `gem` call that declares it, or patch the gem with `--mode agent`. Hosted mode refuses a gem declared in those places too. | | `native_extensions_unsupported` | builds a native extension (puma, bootsnap). | `--mode hosted` or `--mode agent`. Both build the extension. Only `--mode agent` when the declaration picks the gem's source (a `source`, `git`, `github` or `path` block or option), which hosted mode refuses. | -| `platform_gem_unsupported` | is locked for the `ruby` platform alone while the installed copy is a precompiled platform build (`nokogiri-1.18.3-x86_64-linux-gnu`); or is locked as precompiled platform gems in a lock that also holds the gem's plain `nokogiri (1.18.10)` entry, or that a Bundler older than 2.3 wrote. | For the installed build, `--mode agent`. For the plain entry, the `bundle lock --remove-platform ` that drops it; for the old lock, a re-lock with Bundler 2.3 or later (`bundle update --bundler`). A gem the lock pins only as platform gems is not refused: it is vendored when one fix has a patch for every platform the lock names, and skipped otherwise (`vendor_prebuilt_platform_pending`, the run does not fail), see [Ruby gems: native extensions](#ruby-gems-native-extensions). | +| `platform_gem_unsupported` | is locked for the `ruby` platform alone while the installed copy is a precompiled platform build (`nokogiri-1.18.3-x86_64-linux-gnu`); or is locked as precompiled platform gems in a lock that also holds the gem's plain `nokogiri (1.18.10)` entry, or that a Bundler older than 2.3 wrote. A gem with a patch for each of its locked platform gems is refused once, under the patch of its ruby gem (under the patch of its first platform gem where the run has none for the ruby gem), and counts as one failed patch. | For the installed build, `--mode agent`. For the plain entry, the `bundle lock --remove-platform ` that drops it; for the old lock, a re-lock with Bundler 2.3 or later (`bundle update --bundler`). A gem the lock pins only as platform gems is not refused: it is vendored when one fix has a patch for every platform the lock names, and skipped otherwise (`vendor_prebuilt_platform_pending`, the run does not fail), see [Ruby gems: native extensions](#ruby-gems-native-extensions). | To patch one gem in another mode, name it: `socket-patch get --mode hosted`. A whole-project `scan --mode hosted` leaves vendored gems as they are, but it moves the vendored patches of the From 086034e1050a4cd88b1877a4e9b3ee8d5f064dcf Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 3 Dec 2026 13:56:50 +0000 Subject: [PATCH 4/4] Keep expected gem skips per patch; guard repeats Review follow-ups to the once-per-gem refusal: an expected skip (a gem version the lock does not resolve) keeps its line and event for each patch, a purl listed twice is not dropped with its own repeat, and the contract states the rule for every failing gem refusal, not for one code. Refs #2436. Assisted-by: Claude Code:claude-fable-5-2 --- crates/socket-patch-cli/CLI_CONTRACT.md | 2 +- .../src/commands/scan/vendor_flow.rs | 4 +++- .../socket-patch-core/src/vendor/refusals.rs | 20 +++++++++++++++++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/crates/socket-patch-cli/CLI_CONTRACT.md b/crates/socket-patch-cli/CLI_CONTRACT.md index 3b57a8605d..23cdf83e3d 100644 --- a/crates/socket-patch-cli/CLI_CONTRACT.md +++ b/crates/socket-patch-cli/CLI_CONTRACT.md @@ -2934,7 +2934,7 @@ command's integration tests check its output. | `vendor_uuid_mismatch` | `skipped` | repair: the manifest's patch uuid moved past the vendored artifact — a re-vendor (`vendor` / `scan --mode vendored`) is pending; repair does not cross patch generations. | | `content_mismatch_overwritten` | `skipped` (warning) | apply (explicit `--allow-patch-conflicts` / `--force`): a file matched NEITHER beforeHash nor afterHash and was overwritten with the full verified patched content. This includes a file the patch adds (empty beforeHash) that already exists with other content. `--strict` turns this case into a `failed` event instead. Agent-mode `get` / `scan --json` carry it as a `(content_mismatch_overwritten) …` `warnings[]` entry (#1004). | | `vendor_lock_checksums_unsupported` / `vendor_stale_lock_checksum` | `failed` | vendor (gem): an ambiguous/platform CHECKSUMS entry, or a v1-wired lock whose stale token blocks the hot path (run `vendor --revert` + re-vendor). | -| `platform_gem_unsupported` | `failed` | vendor / scan / get `--mode vendored` (gem): a precompiled platform gem that cannot be vendored. `Gemfile.lock` pins the gem as platform gems (`nokogiri (1.18.10-x86_64-linux-gnu)`) and also holds the plain ` ()` entry of the `ruby` platform, which no platform tree serves (the detail names it and each locked platform that keeps it, `ruby` or one that none of the gem's platform gems serves, with the `bundle lock --remove-platform ` command that drops them); or it pins the gem as platform gems and its `BUNDLED WITH` is absent or names a Bundler older than 2.3, the oldest the vendored layout is verified on (the detail names the version needed; `bundle update --bundler` re-locks); or the installed copy is a platform gem and the lock names no platform for the gem; or the patch record is for one platform's gem (`?platform=`) and is not vendored as part of its fix: the lock does not pin the gem as platform gems. Nothing is written. In `scan` / `get --mode vendored`, a refusal the lock gives for the gem is reported once however many of the gem's platform gems have a selected patch: one `failed` event and one `[error]` line (one `skipped` event and one `[would-refuse]` line under `--dry-run`), under the patch of the ruby gem, or under the first of the gem's refused patches in purl order where the ruby gem's is not one of them; the gem's other patches are refused with it and have no event, line or count of their own (#2436). A locked platform with no patch of the fix is not this failure: see `vendor_prebuilt_platform_pending`. | +| `platform_gem_unsupported` | `failed` | vendor / scan / get `--mode vendored` (gem): a precompiled platform gem that cannot be vendored. `Gemfile.lock` pins the gem as platform gems (`nokogiri (1.18.10-x86_64-linux-gnu)`) and also holds the plain ` ()` entry of the `ruby` platform, which no platform tree serves (the detail names it and each locked platform that keeps it, `ruby` or one that none of the gem's platform gems serves, with the `bundle lock --remove-platform ` command that drops them); or it pins the gem as platform gems and its `BUNDLED WITH` is absent or names a Bundler older than 2.3, the oldest the vendored layout is verified on (the detail names the version needed; `bundle update --bundler` re-locks); or the installed copy is a platform gem and the lock names no platform for the gem; or the patch record is for one platform's gem (`?platform=`) and is not vendored as part of its fix: the lock does not pin the gem as platform gems. Nothing is written. In `scan` / `get --mode vendored`, this refusal, like any other pre-download refusal that fails a gem with the same code and detail for several of its selected patches (an expected skip such as `vendor_gem_version_not_locked` stays per patch), is reported once however many of the gem's platform gems have a selected patch: one `failed` event and one `[error]` line (one `skipped` event and one `[would-refuse]` line under `--dry-run`), under the patch of the ruby gem, or under the first of the gem's refused patches in purl order where the ruby gem's is not one of them; the gem's other patches are refused with it and have no event, line or count of their own (#2436). A locked platform with no patch of the fix is not this failure: see `vendor_prebuilt_platform_pending`. | | `redirect_unattributable` | `skipped` (hosted event) | scan/get `--mode hosted`: the rewriters would pin the patch, but lockfile discovery over the result reads that pin as contested (another lock or requirements file resolves the same version elsewhere, or the pin is not one the package manager consumes), so `vex`, `rollback`, `remove` and `vendor` would refuse it. The candidate is left out of the rewrite, so nothing is written for it; the detail carries discovery's findings. Exit code unchanged. | | `redirect_mirror_unsupported` / `redirect_mirror_url_refused` | `skipped` (hosted event) + `warnings[]` | **Experimental** (patch mirror). scan/get `--mode hosted` with `--patch-mirror-url`: the patch's ecosystem cannot be served through a mirror (`redirect_mirror_unsupported`: Cargo, NuGet; use `--mode vendored`), or its reference could not be moved onto the mirror (`redirect_mirror_url_refused`). Nothing is written for it. See "Patch mirror (experimental)". | | `redirect_mirror_unavailable` | `skipped` (hosted event) + `warnings[]` | **Experimental** (patch mirror). scan/get `--mode hosted` with `--patch-mirror-url`: the mirror did not serve the reference the run asked it for, or could not be reached. That reference is skipped and nothing is written for it. One warning per package, or a single warning about the mirror when it served none of the references it was asked about. | diff --git a/crates/socket-patch-cli/src/commands/scan/vendor_flow.rs b/crates/socket-patch-cli/src/commands/scan/vendor_flow.rs index 885d2d4021..035acb50f9 100644 --- a/crates/socket-patch-cli/src/commands/scan/vendor_flow.rs +++ b/crates/socket-patch-cli/src/commands/scan/vendor_flow.rs @@ -153,7 +153,9 @@ impl VendorPreview { /// Keep only the rows of `selected` (the patches the rollout plan left /// in the run), so a preview computed before planning renders exactly /// what this run would vendor. Every verdict is per patch, so a row - /// does not depend on which other patches were previewed with it. + /// does not depend on which other patches were previewed with it (but + /// for a gem's refusal, which has one row for the patches refused + /// alike; the plan never takes a refused patch out of the run). pub(crate) fn retain_selected(&mut self, selected: &[PatchSearchResult]) { let keep: HashSet<(&str, &str)> = selected .iter() diff --git a/crates/socket-patch-core/src/vendor/refusals.rs b/crates/socket-patch-core/src/vendor/refusals.rs index a8183de69f..795417b8ba 100644 --- a/crates/socket-patch-core/src/vendor/refusals.rs +++ b/crates/socket-patch-core/src/vendor/refusals.rs @@ -302,7 +302,8 @@ async fn gem_refusals( /// under the patch of the ruby gem where that one is refused, else under /// the first of the gem's refused patches; the rest are returned. They /// stay refused: a caller leaves them out of what it downloads, prints -/// and counts. +/// and counts. Only a refusal that fails the run is folded: an expected +/// skip ([`refusal_is_benign`]) is left as it is. pub fn repeated_gem_refusals<'a>( refused: impl Iterator, ) -> HashSet { @@ -315,13 +316,17 @@ pub fn repeated_gem_refusals<'a>( let Some((ecosystem, name, version)) = purl_parts(purl) else { continue; }; - if ecosystem != "gem" { + // An expected skip keeps its line and event for each patch. + if ecosystem != "gem" || refusal_is_benign(code) { continue; } match reported.entry((name, version, code, detail)) { std::collections::hash_map::Entry::Vacant(first) => { first.insert(purl); } + // The same purl again (another patch of one build) is not a + // repeat: dropping it by purl would drop the report as well. + std::collections::hash_map::Entry::Occupied(first) if *first.get() == purl => {} std::collections::hash_map::Entry::Occupied(mut first) => { let ruby_gem_takes_over = gem_platform_qualifier(purl).is_none() && gem_platform_qualifier(first.get()).is_some(); @@ -512,6 +517,8 @@ mod tests { #[test] fn a_gems_refusal_is_reported_under_one_patch() { const CODE: &str = "platform_gem_unsupported"; + const GEM_SKIP: &str = crate::vendor::gem::GEM_VERSION_NOT_LOCKED; + assert!(refusal_is_benign(GEM_SKIP)); let sorted = |refusals: &VendorRefusals| { let refused = refusals .iter() @@ -552,8 +559,17 @@ mod tests { ("pkg:gem/rack@3.2.9", CODE, "why"), ("pkg:pypi/six@1.16.0?artifact_id=a", CODE, "why"), ("pkg:pypi/six@1.16.0?artifact_id=b", CODE, "why"), + // An expected skip is not folded. + ("pkg:gem/rake@13.2.1?platform=java", GEM_SKIP, "why"), + ("pkg:gem/rake@13.2.1?platform=ruby", GEM_SKIP, "why"), ]); assert!(sorted(&refusals).is_empty()); + // One purl listed twice is reported, not dropped with its repeat. + let twice = [ + ("pkg:gem/rack@3.2.9", CODE, "why"), + ("pkg:gem/rack@3.2.9", CODE, "why"), + ]; + assert!(repeated_gem_refusals(twice.into_iter()).is_empty()); } /// #2269: a native gem that already holds the patch in hosted or