From d5eb740df44387a90ea5d16e8a175f299bcabf5b Mon Sep 17 00:00:00 2001 From: Mikola Lysenko Date: Mon, 16 Nov 2026 16:08:09 -0500 Subject: [PATCH 1/2] Pin a vendored Maven patch in the modules that select its version A vendored pin was only ever written in a local root pom, which every module of the reactor inherits. Where the modules select different versions of one artifact, a root pin moved the ones that select another version (5.1.0), or no pin was written at all and a module that selects the base version only through other artifacts stayed unpatched (the previous commit). The pin now goes in the highest pom whose modules all select the patch's base version or do not resolve the artifact: the local root when every module that inherits it agrees, else the poms below it that do, down to one module's own pom.xml. A module that resolves another version is never reached by a pin, and patches for two versions of one artifact are each pinned in the modules that select them. A pin an earlier run wrote in a pom that would move a module is taken out and written where it belongs. A pom that manages the artifact itself takes no pin, and a module whose selection is not certain gets no new pin and keeps the one it has. The fallback repository stays in each local root. A literal -socket. of another patch of the same artifact is no longer reported as conflicting_literal_version when a second patch is planned, and the version_not_selected degraded reason is gone: a sibling that selects another version is not a degradation. Reactors whose modules agree and single-module projects are planned byte for byte as before. Refs #595, #882. Co-Authored-By: Claude Fable 5.2 --- crates/socket-patch-cli/CLI_CONTRACT.md | 22 +- .../tests/e2e_vendor_maven_build.rs | 200 ++++++++++ .../tests/maven_mediation_common/mod.rs | 86 ++++- .../src/vendor/jvm/maven_reactor.rs | 359 +++++++++++++----- docs/design/maven-vendoring.md | 42 +- 5 files changed, 582 insertions(+), 127 deletions(-) diff --git a/crates/socket-patch-cli/CLI_CONTRACT.md b/crates/socket-patch-cli/CLI_CONTRACT.md index 172e105bd..9303b5b06 100644 --- a/crates/socket-patch-cli/CLI_CONTRACT.md +++ b/crates/socket-patch-cli/CLI_CONTRACT.md @@ -2742,16 +2742,20 @@ range. | Mode | The build selects another version, or does not resolve the artifact | The selection is not certain | |---|---|---| | hosted | `redirect_maven_version_not_selected` (warning); nothing written | a declaration that names the base version is rewritten where it stands (that replaces the version in place and moves nothing); otherwise `redirect_maven_selection_undetermined` (warning), nothing written | -| vendored | `vendor_maven_version_not_selected` (`skipped`, exit 0), decided before any download; nothing written | a declaration that names the base version is rewritten; no root is pinned (`vendor_jvm_degraded`, `reason: selection_undetermined`), and a pin already there is kept. With no such declaration: `vendor_maven_selection_undetermined` (`skipped`, exit 0), nothing written | +| vendored | `vendor_maven_version_not_selected` (`skipped`, exit 0), decided before any download; nothing written | a declaration that names the base version is rewritten; a module whose selection is not certain gets no new pin (`vendor_jvm_degraded`, `reason: selection_undetermined`, naming it), and a pin already there is kept. With no such declaration and no module that is certain: `vendor_maven_selection_undetermined` (`skipped`, exit 0), nothing written | | agent | not applicable: the cached jar is patched in place under its own coordinates, which cannot change what a build resolves. A version whose directory in the local repository holds its pom and no jar (Maven read the pom while mediating and never downloaded the artifact) is not a package agent mode can patch: the scan leaves it out instead of failing it as a targeted patch that matched no installed package | | -In a vendored reactor a local root is pinned only when every module that -inherits it resolves the artifact at the base version or not at all. A module -that resolves another version leaves the root unpinned (`vendor_jvm_degraded`, -`reason: version_not_selected`, naming the module and its version); a patch -that then reaches no pom is refused as `nothing_wired` with that reason. -`vendor --check` accepts the pins a run with the local repository's current -answer writes and the pins a run with no such answer writes. +In a vendored reactor the pin goes in the highest pom whose modules all +resolve the artifact at the base version or not at all: a local root when +every module that inherits it agrees, else the poms below it that do, down to +a single module's own `pom.xml`. A module that resolves another version is +never reached by a pin and resolves what it resolved before; patches for two +versions of one artifact are each pinned in the modules that select them. A +pin an earlier run wrote in a pom that would move a module is taken out and +written where it belongs. A pom that manages the artifact itself takes no pin +(its own entry is rewritten when it names the base version). `vendor --check` +accepts the pins a run with the local repository's current answer writes and +the pins a run with no such answer writes (every local root). The not-selected line reads `Maven selects : in this build, not , so the patch for has nothing to patch here` (or `no module @@ -3102,7 +3106,7 @@ with `reason: : `: |---|---|---| | `vendor_jvm_shape_unsupported` | refusal, nothing written | `gradle_below_6_8`, `android_or_kmp` (also `available-at` module redirects), `gradle_exclusive_content_conflict` (a user rule claiming the module, in any script), `gradle_range_excludes_vendored` (no declared selector admits the vendored version), `gradle_classifier_computed` (a declaration of the module names its classifier through a variable, such as `${osdetector.classifier}`: the vendored repository would claim that jar without holding it), `gradle_verification_unparseable`, `gradle_index_unreadable`, `build_file_unreadable` (including a non-UTF-8 settings file), `build_file_outside_root`, `not_build_root` (run from a directory an ancestor settings file includes or may include, from a project with no settings file of its own below one, or below an ancestor settings file that is not UTF-8; `repair` refuses there too), `no_build_file` (no `pom.xml`, Gradle, sbt or scala-cli build at the root), `legacy_maven_root` (the root's ledger still holds a pre-v5 single-POM `maven_pom_repository` entry; the whole root is refused until `vendor --revert`, then vendor again) | | `vendor_jvm_upstream_unavailable` | refusal | `classifier_unavailable` (a declared classifier jar no cache or registry has), `module_unavailable` (the pom declares Gradle module metadata that cannot be sourced), `pom_unavailable`, `verification_metadata_unavailable`; for a suffixed Maven / sbt pom also `suffix_unavailable` (the upstream pom computes its own version), `parent_unavailable` (a first vendoring whose upstream parent poms are in no local cache and cannot be fetched, so the suffixed pom cannot be checked) and `inherited_version_unresolvable` (a parent pom names `${project.version}` where the suffixed pom cannot declare the base version instead: in a profile, a management key or a repository URL) | -| `vendor_jvm_degraded` | applied, VEX withheld | `gradle_unscanned_build_logic`, `unwired_build_logic` (a nonliteral included build), `settings_plugins_unwired`, `classifier_unpatched_copy` (a classifier jar carries an unpatched copy of a patched member), `verification_parent_chain_unhandled`, `gradle_lock_overrides_vendored` (a dependency lock of the build, buildscript and settings classpath locks included, pins the module at a version no vendored row serves), `gradle_settings_lock_unrouted` (a `settings-gradle.lockfile` locks the module but that build's settings script does not hold the in-block repository entry for it), `gradle_lock_unreadable` (a lock file, or a followed custom `lockFile`, is missing, unreadable, outside the checkout or not UTF-8), `gradle_custom_lock_file` (a `lockFile` location that cannot be followed statically: anything but a literal `file(…)` in a project's own build script), `gradle_wiring_uncommitted` (VEX liveness only, never reported by `vendor`: the committed settings files, index, derived `maven-metadata.xml`, script or verification file lack wiring a re-plan would write, such as a removed apply line or in-block entry; the git hygiene files do not count), `conflicting_managed_version` / `management_unresolved` (Maven reactor: an imported BOM or an out-of-checkout parent manages the artifact at another version, or its POM is unavailable; that local root is not pinned), `version_not_selected` / `selection_undetermined` (Maven reactor: a module under that local root resolves the artifact at another version than the patch's base, so the root is not pinned; or what a module resolves cannot be read, so the root's pin is left as it is. See [Maven version selection](#maven-version-selection-hosted-and-vendored-maven)) | +| `vendor_jvm_degraded` | applied, VEX withheld | `gradle_unscanned_build_logic`, `unwired_build_logic` (a nonliteral included build), `settings_plugins_unwired`, `classifier_unpatched_copy` (a classifier jar carries an unpatched copy of a patched member), `verification_parent_chain_unhandled`, `gradle_lock_overrides_vendored` (a dependency lock of the build, buildscript and settings classpath locks included, pins the module at a version no vendored row serves), `gradle_settings_lock_unrouted` (a `settings-gradle.lockfile` locks the module but that build's settings script does not hold the in-block repository entry for it), `gradle_lock_unreadable` (a lock file, or a followed custom `lockFile`, is missing, unreadable, outside the checkout or not UTF-8), `gradle_custom_lock_file` (a `lockFile` location that cannot be followed statically: anything but a literal `file(…)` in a project's own build script), `gradle_wiring_uncommitted` (VEX liveness only, never reported by `vendor`: the committed settings files, index, derived `maven-metadata.xml`, script or verification file lack wiring a re-plan would write, such as a removed apply line or in-block entry; the git hygiene files do not count), `conflicting_managed_version` / `management_unresolved` (Maven reactor: an imported BOM or an out-of-checkout parent manages the artifact at another version, or its POM is unavailable; that local root is not pinned), `selection_undetermined` (Maven reactor: what a module resolves cannot be read, so no pin is written for it and one already there is left as it is. See [Maven version selection](#maven-version-selection-hosted-and-vendored-maven)) | | `vendor_jvm_note` | applied, informational | `range_declared` (a range, prefix or rich selector lists versions from the derived `maven-metadata.xml`), `ide_sources_unavailable` | | `vendor_jvm_upstream_unverified` | warning | Upstream metadata was taken offline, or from a local cache while the registry published no checksum for it (a parent pom from a corporate repository), and not authenticated against registry checksums. | | `vendor_jvm_unattested` | warning (`vendor --check`) | A Maven reactor entry is intact and wired, but a declaration may still build the base release (an executable classifier or type copy, a version a property, profile or unpinned local root may move), so `vex` does not attest it. The entry stays `verified`; the detail names the purl and the declarations (`:`). | diff --git a/crates/socket-patch-cli/tests/e2e_vendor_maven_build.rs b/crates/socket-patch-cli/tests/e2e_vendor_maven_build.rs index f22f81f0f..5efaa9a81 100644 --- a/crates/socket-patch-cli/tests/e2e_vendor_maven_build.rs +++ b/crates/socket-patch-cli/tests/e2e_vendor_maven_build.rs @@ -54,6 +54,7 @@ mod prebuilt_common; #[path = "vex_e2e_common/mod.rs"] mod vex_e2e_common; +use std::collections::BTreeMap; use std::path::{Path, PathBuf}; use maven_build_common::*; @@ -683,6 +684,205 @@ mod mediation { std::fs::write(proj.join(".socket/blobs").join(git_sha256(&after)), after).unwrap(); } + /// A second patch, for the newer victim. + const NEWER_UUID: &str = "8192a3b4-c5d6-4e7f-9081-92a3b4c5d6e7"; + + /// The manifest record `get` saves for a patch of the victim at + /// `version`, with its after-hash blob. + fn stage_all(proj: &Path, patches: &[(&str, &str)]) { + let mut records = serde_json::Map::new(); + std::fs::create_dir_all(proj.join(".socket/blobs")).unwrap(); + for (version, uuid) in patches { + let (before, after) = ( + fixture::pristine_member(fixture::VICTIM, version), + fixture::patched_member_of(version), + ); + records.insert( + format!("pkg:maven/{}/{}@{version}", fixture::GROUP, fixture::VICTIM), + serde_json::json!({ + "uuid": uuid, + "exportedAt": "2026-01-01T00:00:00Z", + "files": { fixture::MEMBER: { + "beforeHash": git_sha256(&before), + "afterHash": git_sha256(&after), + } }, + "vulnerabilities": { "GHSA-mediation-maven-vendored": { + "cves": ["CVE-2026-7204"], "summary": "s", "severity": "high", + "description": "d" + } }, + "description": "maven mediation capstone", + "license": "MIT", + "tier": "free", + }), + ); + std::fs::write(proj.join(".socket/blobs").join(git_sha256(&after)), after).unwrap(); + } + std::fs::write( + proj.join(".socket/manifest.json"), + serde_json::to_string_pretty(&serde_json::json!({ "patches": records })).unwrap(), + ) + .unwrap(); + } + + /// The table's V3: in a reactor each module keeps the version it + /// selects. A patch of the base version is pinned in the modules that + /// select it (one through other artifacts, one by its own + /// declaration) and never in the parent they share with a module that + /// resolves a newer version, which Maven resolves exactly as before. A + /// patch of that newer version is then pinned in its module beside the + /// first, and the revert restores every pom. + #[test] + #[ignore = "real Maven + Maven Central (dependency plugin); run with --ignored"] + fn maven_vendored_reactor_pins_each_module_at_the_version_it_selects() { + let Some(mvn) = Mvn::detect(SUITE) else { + return; + }; + let tmp = tempfile::tempdir().unwrap(); + let root: PathBuf = tmp.path().canonicalize().unwrap(); + let m2 = root.join("m2"); + let settings = root.join("settings.xml"); + write_settings(&settings, &[]); + let server = Server::start(); + fixture::publish(&server); + let proj = root.join("reactor"); + fixture::write_reactor(&proj, &server); + let poms = ["pom.xml", "a/pom.xml", "b/pom.xml", "c/pom.xml"]; + let read_poms = |proj: &Path| -> Vec> { + poms.iter() + .map(|rel| std::fs::read(proj.join(rel)).unwrap()) + .collect() + }; + let pristine = read_poms(&proj); + let vendor = |args: &[&str]| { + let mut all = vec!["vendor"]; + all.extend_from_slice(args); + all.extend_from_slice(&["--json", "--cwd", proj.to_str().unwrap()]); + socket(&proj, &m2, &all) + }; + let Some(before) = + fixture::resolve_reactor(SUITE, &mvn, &proj, &m2, &settings, "target/before") + else { + return; + }; + for (module, selects) in fixture::REACTOR_MODULES { + assert!( + before[module].contains_key(&fixture::victim_jar_name(selects)), + "{module} selects {selects}: {:?}", + before[module].keys() + ); + } + let base_sv = suffixed(); + let newer_sv = format!("{}-socket.{}", fixture::NEWER, &NEWER_UUID[..8]); + let resolved = |out_rel: &str| { + fixture::resolve_reactor(SUITE, &mvn, &proj, &m2, &settings, out_rel) + .expect("the local repository is warm") + }; + // What each module must resolve once `patched` versions are + // vendored: the same artifacts, the patched ones in their patched + // build, everything else byte for byte. + let assert_follows = |after: &BTreeMap>>, + patched: &[(&str, &str)]| { + for (module, selects) in fixture::REACTOR_MODULES { + let (was, now) = (&before[module], &after[module]); + assert_eq!( + fixture::unsuffixed(now.keys()), + was.keys().cloned().collect(), + "{module} resolves the artifacts it resolved before" + ); + let pristine_name = fixture::victim_jar_name(selects); + match patched.iter().find(|(version, _)| *version == selects) { + Some((version, sv)) => { + let jar = now.get(&fixture::victim_jar_name(sv)).unwrap_or_else(|| { + panic!("{module} resolves the patched {version}: {:?}", now.keys()) + }); + assert_eq!( + jar_member(jar, fixture::MEMBER), + Some(fixture::patched_member_of(version)), + "{module}: the patched jar" + ); + } + None => assert_eq!( + now.get(&pristine_name), + was.get(&pristine_name), + "{module} keeps the pristine {selects}" + ), + } + for (name, bytes) in was { + if *name != pristine_name { + assert_eq!(now.get(name), Some(bytes), "{module}: {name} is untouched"); + } + } + } + }; + + // The patch of the base version: pinned in `a` and `c`, never in + // the parent, and `b` is left exactly as it was. + stage_all(&proj, &[(fixture::BASE, UUID)]); + let (code, env, stderr) = vendor(&["--offline"]); + assert_eq!(code, Some(0), "vendor: {env}\n{stderr}"); + assert_eq!(env["summary"]["applied"], 1, "{env}"); + assert_eq!(env["summary"]["failed"], 0, "{env}"); + let after = read_poms(&proj); + let text = |bytes: &[u8]| String::from_utf8_lossy(bytes).into_owned(); + assert!( + !text(&after[0]).contains("-socket."), + "the parent takes no pin:\n{}", + text(&after[0]) + ); + assert!( + text(&after[1]).contains(&format!("{base_sv}")), + "{}", + text(&after[1]) + ); + assert_eq!(after[2], pristine[2], "b/pom.xml is untouched"); + assert!( + text(&after[3]).contains(&format!("{base_sv}")), + "{}", + text(&after[3]) + ); + assert_follows(&resolved("target/after-base"), &[(fixture::BASE, &base_sv)]); + + // The patch of the version `b` selects joins it. + stage_all( + &proj, + &[(fixture::BASE, UUID), (fixture::NEWER, NEWER_UUID)], + ); + let (code, env, stderr) = vendor(&["--offline"]); + assert_eq!(code, Some(0), "second vendor: {env}\n{stderr}"); + assert_eq!(env["summary"]["failed"], 0, "{env}"); + let both = read_poms(&proj); + assert!(!text(&both[0]).contains("-socket."), "{}", text(&both[0])); + assert_eq!(both[1], after[1], "a/pom.xml keeps its pin"); + assert!( + text(&both[2]).contains(&format!("{newer_sv}")), + "{}", + text(&both[2]) + ); + assert!(!text(&both[2]).contains(&base_sv)); + assert_eq!(both[3], after[3], "c/pom.xml keeps its pin"); + assert_follows( + &resolved("target/after-both"), + &[(fixture::BASE, &base_sv), (fixture::NEWER, &newer_sv)], + ); + + // In sync, checked, and reverted byte for byte. + let wired = fixture::snapshot(&proj); + let (code, env, stderr) = vendor(&["--offline"]); + assert_eq!(code, Some(0), "re-vendor: {env}\n{stderr}"); + assert_eq!( + fixture::snapshot(&proj), + wired, + "a third run is a no-op: {env}" + ); + let (code, env, stderr) = vendor(&["--check"]); + assert_eq!(code, Some(0), "vendor --check: {env}\n{stderr}"); + let (code, env, stderr) = vendor(&["--revert"]); + assert_eq!(code, Some(0), "revert: {env}\n{stderr}"); + assert_eq!(read_poms(&proj), pristine, "the revert restores every pom"); + assert!(!proj.join(".socket/vendor/maven2").exists(), "{env}"); + assert!(!proj.join(".mvn").exists(), "{env}"); + } + fn skip_of<'e>(env: &'e serde_json::Value) -> Option<&'e serde_json::Value> { env["events"] .as_array() diff --git a/crates/socket-patch-cli/tests/maven_mediation_common/mod.rs b/crates/socket-patch-cli/tests/maven_mediation_common/mod.rs index 097e67ef5..ba542775c 100644 --- a/crates/socket-patch-cli/tests/maven_mediation_common/mod.rs +++ b/crates/socket-patch-cli/tests/maven_mediation_common/mod.rs @@ -165,7 +165,12 @@ pub fn pristine_member(artifact: &str, version: &str) -> Vec { /// What the patch makes of the base victim's [`MEMBER`]. pub fn patched_member() -> Vec { - let mut out = pristine_member(VICTIM, BASE); + patched_member_of(BASE) +} + +/// What a patch of the victim at `version` makes of its [`MEMBER`]. +pub fn patched_member_of(version: &str) -> Vec { + let mut out = pristine_member(VICTIM, version); out.extend_from_slice(format!("{MARKER}\n").as_bytes()); out } @@ -258,6 +263,85 @@ pub fn project_pom(shape: Shape, server: &Server) -> String { ) } +/// The modules of [`write_reactor`], and the victim version each selects. +pub const REACTOR_MODULES: [(&str, &str); 3] = [("a", BASE), ("b", NEWER), ("c", BASE)]; + +/// Write a reactor into `dir` (the table's V3): a parent pom that three +/// modules inherit, `a` reaching the base version two levels down, `b` a +/// newer version through another artifact, `c` declaring the base version +/// itself. +pub fn write_reactor(dir: &Path, server: &Server) { + let modules: String = REACTOR_MODULES + .iter() + .map(|(name, _)| format!(" {name}\n")) + .collect(); + std::fs::create_dir_all(dir).unwrap(); + std::fs::write( + dir.join("pom.xml"), + format!( + "\n\ + \n \ + 4.0.0\n com.example\n \ + parent\n 1.0.0\n \ + pom\n \n{modules} \n \ + \n \n fixture\n \ + {}{REPO_ROUTE}\n \n \n\n", + server.uri() + ), + ) + .unwrap(); + for (name, deps) in [ + ("a", dependency("lib-deep", "1.0", "")), + ("b", dependency("lib-new", "1.0", "")), + ("c", dependency(VICTIM, BASE, "")), + ] { + std::fs::create_dir_all(dir.join(name)).unwrap(); + std::fs::write( + dir.join(name).join("pom.xml"), + format!( + "\n\ + \n \ + 4.0.0\n \n \ + com.example\n parent\n \ + 1.0.0\n \n {name}\n \ + \n{deps} \n\n" + ), + ) + .unwrap(); + } +} + +/// The jars Maven resolves for each module of the reactor at `proj` +/// (see [`resolve`]), by module name. +pub fn resolve_reactor( + suite: &str, + mvn: &Mvn, + proj: &Path, + m2: &Path, + settings: &Path, + out_rel: &str, +) -> Option>>> { + for (module, _) in REACTOR_MODULES { + let _ = std::fs::remove_dir_all(proj.join(module).join(out_rel)); + } + let out = with_central_fallback(suite, "reactor resolution", settings, |s, extra| { + copy_dependencies(mvn, proj, m2, s, out_rel, extra) + }); + if !ok(&out) { + crate::maven_build_common::skip( + suite, + &format!("resolving {} failed:\n{}", proj.display(), dump(&out)), + ); + return None; + } + Some( + REACTOR_MODULES + .iter() + .map(|(module, _)| (module.to_string(), copied(&proj.join(module), out_rel))) + .collect(), + ) +} + /// Write the project of `shape` into `dir`. pub fn write_project(dir: &Path, shape: Shape, server: &Server) { std::fs::create_dir_all(dir).unwrap(); diff --git a/crates/socket-patch-core/src/vendor/jvm/maven_reactor.rs b/crates/socket-patch-core/src/vendor/jvm/maven_reactor.rs index cbc1a992a..71a000f00 100644 --- a/crates/socket-patch-core/src/vendor/jvm/maven_reactor.rs +++ b/crates/socket-patch-core/src/vendor/jvm/maven_reactor.rs @@ -208,17 +208,21 @@ pub fn plan_with_external( plan_with_selection(read, list, patch, config_enabled, external, None) } -/// [`plan_with_external`] that pins a local root only where Maven selects -/// the patch's base version already. A `` pin makes -/// every occurrence of the artifact that version, in the root and in every -/// module that inherits it, so it is written only when each of those -/// modules resolves the artifact at the base version (or not at all) by -/// `selection`. A module that resolves another version leaves the root -/// unpinned (`version_not_selected`); one whose answer is not certain -/// leaves the root as it is, pin or no pin (`selection_undetermined`). A +/// [`plan_with_external`] that puts the pin where Maven selects the +/// patch's base version already. A `` pin makes +/// every occurrence of the artifact that version, in its pom and in every +/// module that inherits it, so it goes in the highest pom whose modules +/// all resolve the artifact at the base version (or not at all) by +/// `selection`: a local root when the whole reactor under it agrees, else +/// the poms below it that do, down to a single module's own. A module +/// that resolves another version is thus never reached by a pin, and +/// patches for two versions of one artifact are each pinned in the +/// modules that select them. A module whose answer is not certain gets no +/// new pin and keeps the one it has (`selection_undetermined`). A /// declaration that names the base version is rewritten either way: that /// replaces the version where it stands, and moves nothing. `None` plans -/// without the check (callers that only probe a shape). +/// without the check and pins every local root (callers that only probe a +/// shape). pub fn plan_with_selection( read: ReadFn<'_>, list: ListFn<'_>, @@ -308,56 +312,39 @@ pub fn plan_with_selection( } } - // Roots whose pin stays as it is: nothing says what their modules - // select. + // Where the pin goes, and the poms whose pin stays as it is because + // nothing says what their modules select. + let mut pins: BTreeSet = BTreeSet::new(); let mut held: BTreeSet = BTreeSet::new(); - if let Some(selection) = selection { - for root in reactor.wired_roots() { - if unpinned.contains(&root) || managed_roots.contains(&root) { - continue; - } - let (mut selected, mut other, mut undetermined) = (false, None, None); - for rel in reactor - .reactor - .iter() - .filter(|rel| reactor.local_root(rel) == root) - { - match selection.verdict(rel, g, a, v) { - Verdict::Selected => selected = true, - Verdict::Other(version) => { - other.get_or_insert((rel.clone(), version)); - } - Verdict::Absent => {} - Verdict::Undetermined(why) => { - undetermined.get_or_insert((rel.clone(), why)); - } - } + let mut undetermined: BTreeMap = BTreeMap::new(); + for root in reactor.wired_roots() { + let open = !unpinned.contains(&root) && !managed_roots.contains(&root); + match selection { + None if open => { + pins.insert(root); } - if let Some((rel, version)) = other { - warnings.push(degraded( - "version_not_selected", - format!( - "{rel} resolves {g}:{a} at {version}, not {v}; {root} is not pinned, \ - since a pin there would change the version {rel} resolves" - ), - )); - unpinned.insert(root); - } else if let Some((rel, why)) = undetermined { - warnings.push(degraded( - "selection_undetermined", - format!( - "which version of {g}:{a} {rel} resolves cannot be told ({why}); the \ - pin of {root} is left as it is" - ), - )); - held.insert(root); - } else if !selected { - // No module under this root resolves the artifact: nothing - // would read a pin there. - unpinned.insert(root); + None => {} + Some(selection) => { + let mut placing = Placing { + selection, + patch, + pins: &mut pins, + held: &mut held, + undetermined: &mut undetermined, + }; + reactor.place(&root, open, &mut placing, 0); } } } + for (module, why) in undetermined { + warnings.push(degraded( + "selection_undetermined", + format!( + "which version of {g}:{a} {module} resolves cannot be told ({why}); no pin \ + is written for it, and one already there is left as it is" + ), + )); + } let banning = reactor .scope @@ -373,27 +360,31 @@ pub fn plan_with_selection( )); } let mut records: Vec = Vec::new(); - for root in reactor.wired_roots() { - let doc = &reactor.poms[&root].doc; - let file_edits = edits.entry(root.clone()).or_default(); - let pinned = !unpinned.contains(&root) && !managed_roots.contains(&root); + for rel in &reactor.scope { + let doc = &reactor.poms[rel].doc; + let file_edits = edits.entry(rel.clone()).or_default(); + let pinned = pins.contains(rel); match pin_of(doc, patch) { - _ if held.contains(&root) => {} + _ if held.contains(rel) => {} Some(pin) if !pinned => file_edits.push(Edit::plain(pin.start, pin.end, "")), Some(pin) if pin.uuid == patch.uuid => {} Some(pin) => { - records.push(adopt(&root, POM_FRAGMENT_KIND, "pin_section")); + records.push(adopt(rel, POM_FRAGMENT_KIND, "pin_section")); file_edits.push(pin_update(doc, &pin, patch)); } None if pinned => { let (edit, section) = pin_edit(doc, patch, &sv); if !section { - records.push(adopt(&root, POM_FRAGMENT_KIND, "pin_section")); + records.push(adopt(rel, POM_FRAGMENT_KIND, "pin_section")); } file_edits.push(edit); } None => {} } + } + for root in reactor.wired_roots() { + let doc = &reactor.poms[&root].doc; + let file_edits = edits.entry(root.clone()).or_default(); if banning.is_none() { if has_fallback_repository(doc) { records.push(adopt(&root, POM_FRAGMENT_KIND, "repository")); @@ -652,12 +643,11 @@ pub fn references_checked( /// The degraded reasons that leave a declaration or a root alone; the /// repository and config notes (and a mixed root's Gradle warnings) say /// nothing about why a reactor is unwired. -const UNWIRING: [&str; 9] = [ +const UNWIRING: [&str; 8] = [ "property_unresolved", "conflicting_literal_version", "conflicting_managed_version", "management_unresolved", - "version_not_selected", "selection_undetermined", "range", "coordinates_overridden", @@ -1282,6 +1272,84 @@ pub fn external_poms_needed( need } +/// What [`Reactor::place`] decides for one patch. +struct Placing<'p> { + selection: &'p MavenSelection, + patch: &'p JvmPatch<'p>, + /// The poms that get the pin. + pins: &'p mut BTreeSet, + /// The poms whose pin stays as it is. + held: &'p mut BTreeSet, + /// The modules whose selection cannot be told, and why. + undetermined: &'p mut BTreeMap, +} + +/// Deepest chain of local parents a pin is placed down. +const MAX_PLACING_DEPTH: usize = 64; + +impl Reactor { + /// Place the patch's pin at or below `rel`: in `rel` itself when every + /// reactor module that inherits it (or is it) resolves the artifact at + /// the base version or not at all, and one of them does resolve it; + /// else in the poms below it for which that holds. A pom some module + /// of which cannot be told is held, and gets no new pin. `open` is + /// false for a pom that takes no pin of its own (a local root a + /// declaration ruled out, or one that manages the artifact itself). + fn place(&self, rel: &str, open: bool, placing: &mut Placing<'_>, depth: usize) { + let (g, a, v) = ( + placing.patch.group_id, + placing.patch.artifact_id, + placing.patch.version, + ); + let (mut selected, mut other, mut unknown) = (false, false, false); + for module in &self.reactor { + if !self.chain(module).any(|p| p == rel) { + continue; + } + match placing.selection.verdict(module, g, a, v) { + Verdict::Selected => selected = true, + Verdict::Other(_) => other = true, + Verdict::Absent => {} + Verdict::Undetermined(why) => { + unknown = true; + placing.undetermined.entry(module.clone()).or_insert(why); + } + } + } + if unknown { + placing.held.insert(rel.to_string()); + } + if !unknown && !other { + // The user's own management on the chain already decides the + // version here: a base one was rewritten in place. + if selected && open && !self.manages(rel, g, a) { + placing.pins.insert(rel.to_string()); + } + return; + } + if depth >= MAX_PLACING_DEPTH { + return; + } + for child in &self.scope { + if self.local_parent.get(child).map(String::as_str) == Some(rel) { + self.place(child, true, placing, depth + 1); + } + } + } + + /// Whether `rel` or a local parent of it manages `g:a`'s main jar in + /// its own top-level `` (a pin vendoring wrote + /// is not such an entry). + fn manages(&self, rel: &str, g: &str, a: &str) -> bool { + self.chain(rel).any(|p| { + let doc = &self.poms[p].doc; + self.keyed_declarations(p, g, a) + .iter() + .any(|(dep, _)| doc.is_top_level_managed(*dep) && doc.is_main_jar(*dep)) + }) + } +} + /// One pom outside the checkout, parsed. struct ExternalPom { gav: Gav, @@ -2440,13 +2508,19 @@ impl Reactor { format!("{at}: {ga} version {declared} is left as is, probably unpatched"), )); } else { - warnings.push(degraded( - "conflicting_literal_version", - format!( - "{at}: {ga} is declared at {declared}, not {}; {root} is not pinned", - patch.version - ), - )); + // Another patch's wiring of the same artifact (a module + // that selects another version, patched too) is no + // conflict to report: this patch is pinned where its own + // version is selected. + if crate::formats::maven::split_socket_version(&resolved).is_none() { + warnings.push(degraded( + "conflicting_literal_version", + format!( + "{at}: {ga} is declared at {declared}, not {}; {root} is not pinned", + patch.version + ), + )); + } unpinned.insert(root); } } @@ -5117,37 +5191,119 @@ mod tests { } } - /// The table's V3 at the root: a pin there would move the module that - /// resolves another version, so none is written. + /// The table's V3: a pin in the shared parent would move the module + /// that resolves another version, so it goes in the module that + /// selects the base version, and nowhere else. #[test] - fn a_root_is_not_pinned_when_a_module_selects_another_version() { + fn a_pin_goes_in_the_module_when_a_sibling_selects_another_version() { let files = two_modules(); let selection = selecting(Some(Ok("1.10.0")), Some(Ok("1.11.0"))); let plan = run_selecting(&files, &selection); let after = applied(&files, &plan); - for rel in ["pom.xml", "a/pom.xml", "b/pom.xml"] { - assert!(!text(&after, rel).contains(SV), "{rel}"); - } - assert!(reasons(&plan).contains(&"version_not_selected".to_string())); - let warning = plan - .warnings - .iter() - .find(|w| w.detail.starts_with("reason: version_not_selected: ")) - .unwrap(); - assert_eq!( - warning.detail, - "reason: version_not_selected: b/pom.xml resolves \ - org.apache.commons:commons-text at 1.11.0, not 1.10.0; pom.xml is not pinned, \ - since a pin there would change the version b/pom.xml resolves" - ); - let refusal = left_unwired(&files, &plan).expect("nothing wired"); - assert_eq!(refusal_reason(&refusal), "nothing_wired"); assert!( - refusal.detail.contains("version_not_selected"), + text(&after, "a/pom.xml").contains(&format!("{SV}")), "{}", - refusal.detail + text(&after, "a/pom.xml") + ); + assert!(text(&after, "a/pom.xml").contains(PIN_TAG)); + assert!(!text(&after, "pom.xml").contains(SV)); + assert_eq!(after["b/pom.xml"], files["b/pom.xml"]); + assert!(!reasons(&plan).contains(&"selection_undetermined".to_string())); + assert!(left_unwired(&files, &plan).is_none()); + assert!(run_selecting(&after, &selection).writes.is_empty()); + + // The revert takes the module's pin out again, byte for byte. + let read = |rel: &str| after.get(rel).cloned(); + let undo = unplan(&read, &lister(&after), &patch().coords(), &plan.records); + let a = undo.changes.iter().find(|(r, _)| r == "a/pom.xml").unwrap(); + assert_eq!(a.1.as_deref(), Some(files["a/pom.xml"].as_slice())); + } + + /// The pin goes in the highest pom whose modules all agree: a parent + /// two modules share, under a root that a third module rules out. + #[test] + fn a_pin_goes_in_the_highest_pom_whose_modules_all_select_the_base() { + let under = |parent: &str, name: &str, extra: &str| { + format!( + "\n 4.0.0\n \n \ + t\n {parent}\n \ + 1\n \n {name}\n{extra}\ + \n" + ) + }; + let files = fs(&[ + ( + "pom.xml", + &PARENT_OF_TWO.replace("a", "mid"), + ), + ( + "mid/pom.xml", + &under( + "root", + "mid", + " pom\n \n m1\n \ + m2\n \n", + ), + ), + ("mid/m1/pom.xml", &under("mid", "m1", "")), + ("mid/m2/pom.xml", &under("mid", "m2", "")), + ("b/pom.xml", &inheriting("b")), + ]); + let ga = |pom: &'static str, version: &'static str| (pom, GA.0, GA.1, Ok(version)); + let selection = MavenSelection::answering( + &[ + "pom.xml", + "mid/pom.xml", + "mid/m1/pom.xml", + "mid/m2/pom.xml", + "b/pom.xml", + ], + &[ga("mid/m1/pom.xml", "1.10.0"), ga("b/pom.xml", "1.11.0")], ); - assert!(!unwired_by_selection_alone(&plan)); + let plan = run_selecting(&files, &selection); + let after = applied(&files, &plan); + assert!(text(&after, "mid/pom.xml").contains(&format!("{SV}"))); + for rel in ["pom.xml", "mid/m1/pom.xml", "mid/m2/pom.xml", "b/pom.xml"] { + assert!(!text(&after, rel).contains(SV), "{rel}"); + } + assert!(run_selecting(&after, &selection).writes.is_empty()); + } + + /// Patches for two versions of one artifact are each pinned in the + /// module that selects them, and neither plan undoes the other. + #[test] + fn patches_for_two_versions_are_each_pinned_where_they_are_selected() { + const OTHER_UUID: &str = "2e4d2ae3-6f70-4b8c-9dae-1f203b4c5d6e"; + const OTHER_SV: &str = "1.11.0-socket.2e4d2ae3"; + let other = JvmPatch { + version: "1.11.0", + uuid: OTHER_UUID, + upstream_pom: b"\n\n \ + org.apache.commons\n commons-text\n \ + 1.11.0\n\n", + ..patch() + }; + let selection = selecting(Some(Ok("1.10.0")), Some(Ok("1.11.0"))); + let plan_of = |files: &Fs, patch: &JvmPatch<'_>| { + let read = |p: &str| files.get(p).cloned(); + plan_with_selection(&read, &lister(files), patch, true, None, Some(&selection)) + .expect("plan") + }; + let files = two_modules(); + let first = applied(&files, &plan_of(&files, &patch())); + let both = applied(&first, &plan_of(&first, &other)); + assert!(text(&both, "a/pom.xml").contains(&format!("{SV}"))); + assert!(!text(&both, "a/pom.xml").contains(OTHER_SV)); + assert!(text(&both, "b/pom.xml").contains(&format!("{OTHER_SV}"))); + assert!(!text(&both, "b/pom.xml").contains(SV)); + assert!(!text(&both, "pom.xml").contains("-socket.")); + for patch in [patch(), other] { + assert!( + plan_of(&both, &patch).writes.is_empty(), + "{}", + patch.version + ); + } } /// No module resolves the artifact: a pin would be read by nothing. @@ -5155,8 +5311,10 @@ mod tests { fn a_root_no_module_resolves_the_artifact_under_is_not_pinned() { let files = two_modules(); let plan = run_selecting(&files, &selecting(None, None)); - assert!(!text(&applied(&files, &plan), "pom.xml").contains(SV)); - assert!(!reasons(&plan).contains(&"version_not_selected".to_string())); + let after = applied(&files, &plan); + for rel in ["pom.xml", "a/pom.xml", "b/pom.xml"] { + assert!(!text(&after, rel).contains(SV), "{rel}"); + } } /// What Maven selects cannot be told: no pin is written on a guess, @@ -5185,19 +5343,22 @@ mod tests { } /// A pin written before the selection was read (or before the build - /// moved on) goes once a module is known to resolve another version. + /// moved on) leaves the pom of a module it moves, for the pom of the + /// module that selects the base version. #[test] - fn a_pin_that_moves_a_module_is_removed() { + fn a_pin_that_moves_a_module_goes_to_the_module_it_belongs_in() { let files = two_modules(); let (_, pinned) = vendor(&files); assert!(text(&pinned, "pom.xml").contains(SV)); - let plan = run_selecting(&pinned, &selecting(Some(Ok("1.10.0")), Some(Ok("1.11.0")))); - let after = applied(&pinned, &plan); + let selection = selecting(Some(Ok("1.10.0")), Some(Ok("1.11.0"))); + let after = applied(&pinned, &run_selecting(&pinned, &selection)); assert!( !text(&after, "pom.xml").contains(SV), "{}", text(&after, "pom.xml") ); + assert!(text(&after, "a/pom.xml").contains(&format!("{SV}"))); + assert_eq!(after["b/pom.xml"], files["b/pom.xml"]); } /// A declaration that names the base version is rewritten whatever diff --git a/docs/design/maven-vendoring.md b/docs/design/maven-vendoring.md index 40ed9027e..f00377f1e 100644 --- a/docs/design/maven-vendoring.md +++ b/docs/design/maven-vendoring.md @@ -72,7 +72,9 @@ The backend writes: jar, suffixed POM, SHA-1 sidecars, and an ownership marker. - `.socket/vendor/maven2/.gitattributes`: disables line-ending conversion of committed repository bytes. -- A shared file repository and dependency-management pins in each local root. +- A shared file repository in each local root, and dependency-management pins + where Maven selects the patched version (the local root, or the modules + that select it when their siblings do not; see below). - Rewrites of conflicting base-version literals and resolved local properties, including profiles and local parent POMs outside the module list. - Two lines in `.mvn/maven.config`: offline file protocol access and the local @@ -142,23 +144,27 @@ project once and vendor again). A re-run after a BOM bump drops the pin the same way. `vendor --check` reads that metadata from the local repository only and accepts either decision when some of it is missing. -A pin makes every occurrence of the artifact one version, in the root and in -every module that inherits it, so a local root is pinned only when Maven -selects the patch's base version in each of those modules already (or the -module does not resolve the artifact). The selection is read from the -reactor's poms and the poms the Maven local repository holds: nearest -declaration first, the first declared on a tie, the module's own management -over every transitive version, ``, `optional`, scopes and version -ranges as Maven 3's resolver applies them. A module that resolves another -version leaves its root unpinned (`version_not_selected`); when no module of -the build selects the base version the patch is skipped before anything is -downloaded (`vendor_maven_version_not_selected`, exit 0, naming the version -Maven selects). When the selection cannot be read (a pom the local repository -lacks, a profile that may change the graph, a Maven 4 build), no root is -pinned and an existing pin is left alone (`selection_undetermined`); a -declaration that names the base version is rewritten either way, since that -replaces a version where it stands. `vendor --check` accepts the pins either -answer writes. +A pin makes every occurrence of the artifact one version, in its pom and in +every module that inherits it, so it is written only where Maven selects the +patch's base version already. The selection is read from the reactor's poms +and the poms the Maven local repository holds: nearest declaration first, the +first declared on a tie, the module's own management over every transitive +version, ``, `optional`, scopes and version ranges as Maven 3's +resolver applies them. The pin goes in the highest pom whose modules all +select the base version or do not resolve the artifact: the local root when +the whole reactor under it agrees, else the poms below it that do, down to one +module's own `pom.xml`. A module that resolves another version is never +reached by a pin, and a patch for that other version is pinned in that module +beside the first. A pom that manages the artifact itself takes no pin. When no +module of the build selects the base version the patch is skipped before +anything is downloaded (`vendor_maven_version_not_selected`, exit 0, naming +the version Maven selects). When a module's selection cannot be read (a pom +the local repository lacks, a profile that may change the graph, a Maven 4 +build), it gets no new pin and an existing one is left alone +(`selection_undetermined`); a declaration that names the base version is +rewritten either way, since that replaces a version where it stands. +`vendor --check` accepts the pins either answer writes. The fallback +repository stays in each local root, whichever pom holds the pin. Maven 3.9.2+ can read the repository tail without copying jars into `~/.m2` and without routing through mirrors. Older Maven versions use the fallback file From 104f968b052f7bef00bdc8e8a9dcd353b119364a Mon Sep 17 00:00:00 2001 From: Mikola Lysenko Date: Mon, 16 Nov 2026 17:35:19 -0500 Subject: [PATCH 2/2] Never hold a pin that moves a module, and attest only wired modules Review fixes for the per-module placement of vendored Maven pins. - A pom was held (its pin kept) whenever any module under it could not be told, even when another module under it was certain to resolve another version. A pin that moves a module now goes whatever its siblings are; only a pom with doubt and no dissent is held, and a root a declaration rules out is never held. - vex attested a patch as soon as any pom wired it. A pin can sit in one module's pom, so the patch is now attested only when every module that resolves the base version (or may: its selection cannot be told) is reached by a pin, by the project's own management at the patched version, or by a declaration at it. `vendor --check` does not ask this. - A pin moved out of a pom carries the record of the section the first run created for it, so the revert takes the empty shell out again and restores the pom byte for byte. - A parent pom that resolves the base version itself above a module that resolves another cannot be pinned without moving that module, and Maven has no management that reaches a parent and not its children. It takes no pin and the plan says so (pin_would_move_module); when it is the only pom that selects the base version the patch is the vendor_maven_pin_would_move_module skip instead of nothing_wired. - A sibling that declares another version itself is no conflicting_literal_version once the selection says it resolves that version. - Undetermined modules are reported in one line, naming the first and counting the rest. - A root a declaration rules out no longer keeps the modules below it from their pins: it is descended like a root with a dissenting module. - A plan made without a selection keeps the pins the poms already hold, in whichever pom they are, instead of pulling them up into the roots. - Each module is asked for its selection once per plan and the answer marked up its chain. - Tests: one manifest staging helper, one table for the reactor fixture. Co-Authored-By: Claude Fable 5.2 --- crates/socket-patch-cli/CLI_CONTRACT.md | 22 +- .../tests/e2e_vendor_maven_build.rs | 376 +++++------ .../tests/maven_mediation_common/mod.rs | 51 +- .../socket-patch-core/src/vendor/jvm/apply.rs | 13 + .../src/vendor/jvm/maven_reactor.rs | 595 +++++++++++++++--- .../src/vendor/jvm/sbt_gate.rs | 31 +- docs/design/maven-vendoring.md | 8 +- 7 files changed, 772 insertions(+), 324 deletions(-) diff --git a/crates/socket-patch-cli/CLI_CONTRACT.md b/crates/socket-patch-cli/CLI_CONTRACT.md index cdf5b3baf..23a19cd43 100644 --- a/crates/socket-patch-cli/CLI_CONTRACT.md +++ b/crates/socket-patch-cli/CLI_CONTRACT.md @@ -1998,6 +1998,7 @@ command's integration tests check its output. | `vendor_gem_version_not_locked` | `skipped` (benign; exit 0) | vendor / scan / get `--mode vendored` (gem): no section of the project's `Gemfile.lock` resolves the gem at this version (typically a gem Ruby ships in the gem home, or another project's copy in a shared gem home, which the crawl of that gem home returns). Decided before any download: the patch is not fetched, the Gemfile and lock stay byte-identical, and nothing is written. Human: `[skip] (vendor_gem_version_not_locked): …` in the download phase of `scan` / `get` (both identifier paths) and in their dry run, `Skipping : …` in `vendor`. The vendored twin of `redirect_gem_version_not_locked`. | | `vendor_maven_version_not_selected` | `skipped` (benign; exit 0) | vendor / scan / get `--mode vendored` (Maven): no module of the build resolves the artifact at the patch's base version; the reason names the versions Maven selects instead (a nearer declaration, the project's own declaration or management, an ``, a version range), or says that no module resolves the artifact. Decided before any download: the patch is not fetched and no file is written, except that a pin an earlier run wrote for that version is taken out of the poms (the reason says so), since it would keep forcing a version the build no longer selects. Human: `[skip] (vendor_maven_version_not_selected): …` in the download phase of `scan` / `get` and in their dry run, `Skipping : …` in `vendor`. The vendored twin of `redirect_maven_version_not_selected`. See [Maven version selection](#maven-version-selection-hosted-and-vendored-maven). | | `vendor_maven_selection_undetermined` | `skipped` (benign; exit 0) | vendor / scan / get `--mode vendored` (Maven): what the build selects for the artifact cannot be read (the reason says why: typically a pom the local repository does not hold, because the project was never resolved) and no declaration names the patch's base version, so nothing is pinned on a guess and no file is written. The reason carries the remedy that fits its cause (resolve the project once and re-run when a pom is missing from the local repository; otherwise declare the artifact at the base version). The vendored twin of `redirect_maven_selection_undetermined`. | +| `vendor_maven_pin_would_move_module` | `skipped` (benign; exit 0) | vendor / scan / get `--mode vendored` (Maven reactor): the only poms that resolve the artifact at the patch's base version are parent poms above a module that resolves another version. A `` pin in the parent is inherited by that module and would move it, and Maven has no management that reaches a parent and not its children, so nothing is pinned and no file is written; the reason names the parent, the module and its version. When a sibling module does select the base version it is pinned and the same sentence is the `vendor_jvm_degraded` reason `pin_would_move_module`. | | `vendor_prebuilt_pending` / `vendor_prebuilt_unavailable` | `skipped` | vendor / scan / get `--mode vendored` (every ecosystem, #954, #1235): the package is already vendored at another patch uuid, and the patch service has no prebuilt artifact for the selected (superseding) uuid — still building (`pending_build`) / not served (`build_failed`, `not_found`, `withdrawn`, no usable artifact). Nothing is touched: the older patch's artifact, wiring and ledger entry stay in force, the detail names both uuids (`kept the vendored patch : prebuilt is still building for patch `, where `` is the backend's artifact kind: `artifact` for the npm family, `.gem`, `crate`, `module zip`, `dist zip`, `wheel`, `.jar`, `.nupkg`, …), and the run does not fail (exit 0), the way hosted mode keeps its pin and lists the upgrade in `redirect.skipped[]`. A re-run picks the new patch up once the service serves it. A package with no vendored patch to keep still fails (`failed`, error `prebuilt is still building` / `prebuilt unavailable: `; outside the npm family under `vendor_prebuilt_required`), as does a request/transport failure. | | `unsafe_coordinates` | `failed` | vendor: purl/uuid would escape `.socket/vendor/` (tampered manifest/state); refused before any write. | | `revert_failed` | `failed` | vendor --revert: a recorded entry could not be reverted. | @@ -2754,8 +2755,23 @@ a single module's own `pom.xml`. A module that resolves another version is never reached by a pin and resolves what it resolved before; patches for two versions of one artifact are each pinned in the modules that select them. A pin an earlier run wrote in a pom that would move a module is taken out and -written where it belongs. A pom that manages the artifact itself takes no pin -(its own entry is rewritten when it names the base version). +written where it belongs, even while a sibling's selection cannot be told. A +pom that manages the artifact itself takes no pin (its own entry is rewritten +when it names the base version), and neither does a local root a conflicting +declaration rules out; the modules below either are still pinned where they +select the base version. A parent pom that resolves the base version itself, +above a module that resolves another, cannot be pinned without moving that +module: it takes no pin (`pin_would_move_module`, naming both), and when it is +the only pom that selects the base version the patch is the +`vendor_maven_pin_would_move_module` skip. A plan made without a selection +(`repair`, a probe) keeps the committed pins in whichever pom they are. + +`vex` attests a vendored Maven patch only when every module that resolves the +base version is wired: reached by a pin on its parent chain, the project's own +management at the patched version, or a declaration at it. A module a pin does +not reach that resolves the base version, or whose selection cannot be told on +the machine that runs `vex`, withholds the attestation, with the module named. +`vendor --check` does not ask this. Where the pins go is decided when a patch is first wired, and the committed poms are the record of it. A later run over poms that already wire the patch (a @@ -3129,7 +3145,7 @@ with `reason: : `: |---|---|---| | `vendor_jvm_shape_unsupported` | refusal, nothing written | `gradle_below_6_8`, `android_or_kmp` (also `available-at` module redirects), `gradle_exclusive_content_conflict` (a user rule claiming the module, in any script), `gradle_range_excludes_vendored` (no declared selector admits the vendored version), `gradle_classifier_computed` (a declaration of the module names its classifier through a variable, such as `${osdetector.classifier}`: the vendored repository would claim that jar without holding it), `gradle_verification_unparseable`, `gradle_index_unreadable`, `build_file_unreadable` (including a non-UTF-8 settings file), `build_file_outside_root`, `not_build_root` (run from a directory an ancestor settings file includes or may include, from a project with no settings file of its own below one, or below an ancestor settings file that is not UTF-8; `repair` refuses there too), `no_build_file` (no `pom.xml`, Gradle, sbt or scala-cli build at the root), `legacy_maven_root` (the root's ledger still holds a pre-v5 single-POM `maven_pom_repository` entry; the whole root is refused until `vendor --revert`, then vendor again) | | `vendor_jvm_upstream_unavailable` | refusal | `classifier_unavailable` (a declared classifier jar no cache or registry has), `module_unavailable` (the pom declares Gradle module metadata that cannot be sourced), `pom_unavailable`, `verification_metadata_unavailable`; for a suffixed Maven / sbt pom also `suffix_unavailable` (the upstream pom computes its own version), `parent_unavailable` (a first vendoring whose upstream parent poms are in no local cache and cannot be fetched, so the suffixed pom cannot be checked) and `inherited_version_unresolvable` (a parent pom names `${project.version}` where the suffixed pom cannot declare the base version instead: in a profile, a management key or a repository URL) | -| `vendor_jvm_degraded` | applied, VEX withheld | `gradle_unscanned_build_logic`, `unwired_build_logic` (a nonliteral included build), `settings_plugins_unwired`, `classifier_unpatched_copy` (a classifier jar carries an unpatched copy of a patched member), `verification_parent_chain_unhandled`, `gradle_lock_overrides_vendored` (a dependency lock of the build, buildscript and settings classpath locks included, pins the module at a version no vendored row serves), `gradle_settings_lock_unrouted` (a `settings-gradle.lockfile` locks the module but that build's settings script does not hold the in-block repository entry for it), `gradle_lock_unreadable` (a lock file, or a followed custom `lockFile`, is missing, unreadable, outside the checkout or not UTF-8), `gradle_custom_lock_file` (a `lockFile` location that cannot be followed statically: anything but a literal `file(…)` in a project's own build script), `gradle_wiring_uncommitted` (VEX liveness only, never reported by `vendor`: the committed settings files, index, derived `maven-metadata.xml`, script or verification file lack wiring a re-plan would write, such as a removed apply line or in-block entry; the git hygiene files do not count), `conflicting_managed_version` / `management_unresolved` (Maven reactor: an imported BOM or an out-of-checkout parent manages the artifact at another version, or its POM is unavailable; that local root is not pinned), `selection_undetermined` (Maven reactor: what a module resolves cannot be read, so no pin is written for it and one already there is left as it is. See [Maven version selection](#maven-version-selection-hosted-and-vendored-maven)) | +| `vendor_jvm_degraded` | applied, VEX withheld | `gradle_unscanned_build_logic`, `unwired_build_logic` (a nonliteral included build), `settings_plugins_unwired`, `classifier_unpatched_copy` (a classifier jar carries an unpatched copy of a patched member), `verification_parent_chain_unhandled`, `gradle_lock_overrides_vendored` (a dependency lock of the build, buildscript and settings classpath locks included, pins the module at a version no vendored row serves), `gradle_settings_lock_unrouted` (a `settings-gradle.lockfile` locks the module but that build's settings script does not hold the in-block repository entry for it), `gradle_lock_unreadable` (a lock file, or a followed custom `lockFile`, is missing, unreadable, outside the checkout or not UTF-8), `gradle_custom_lock_file` (a `lockFile` location that cannot be followed statically: anything but a literal `file(…)` in a project's own build script), `gradle_wiring_uncommitted` (VEX liveness only, never reported by `vendor`: the committed settings files, index, derived `maven-metadata.xml`, script or verification file lack wiring a re-plan would write, such as a removed apply line or in-block entry; the git hygiene files do not count), `conflicting_managed_version` / `management_unresolved` (Maven reactor: an imported BOM or an out-of-checkout parent manages the artifact at another version, or its POM is unavailable; that local root is not pinned), `selection_undetermined` (Maven reactor: what one or more modules resolve cannot be read, so no pin is written where that is so and one already there is left as it is; one event however many modules, naming the first and counting the rest), `pin_would_move_module` (Maven reactor: a parent pom resolves the base version itself above a module that resolves another version, so the parent takes no pin. See [Maven version selection](#maven-version-selection-hosted-and-vendored-maven)) | | `vendor_jvm_note` | applied, informational | `range_declared` (a range, prefix or rich selector lists versions from the derived `maven-metadata.xml`), `ide_sources_unavailable` | | `vendor_jvm_upstream_unverified` | warning | Upstream metadata was taken offline, or from a local cache while the registry published no checksum for it (a parent pom from a corporate repository), and not authenticated against registry checksums. | | `vendor_jvm_unattested` | warning (`vendor --check`) | A Maven reactor entry is intact and wired, but a declaration may still build the base release (an executable classifier or type copy, a version a property, profile or unpinned local root may move), so `vex` does not attest it. The entry stays `verified`; the detail names the purl and the declarations (`:`). | diff --git a/crates/socket-patch-cli/tests/e2e_vendor_maven_build.rs b/crates/socket-patch-cli/tests/e2e_vendor_maven_build.rs index b356b684f..6c27c2ea7 100644 --- a/crates/socket-patch-cli/tests/e2e_vendor_maven_build.rs +++ b/crates/socket-patch-cli/tests/e2e_vendor_maven_build.rs @@ -653,224 +653,9 @@ mod mediation { format!("{}-socket.{}", fixture::BASE, &UUID[..8]) } - /// What `get` saves for the patch of the base victim: the manifest - /// record and the after-hash blob. + /// What `get` saves for the patch of the base victim. fn stage(proj: &Path) { - let (before, after) = ( - fixture::pristine_member(fixture::VICTIM, fixture::BASE), - fixture::patched_member(), - ); - let record = serde_json::json!({ - "uuid": UUID, - "exportedAt": "2026-01-01T00:00:00Z", - "files": { fixture::MEMBER: { - "beforeHash": git_sha256(&before), - "afterHash": git_sha256(&after), - } }, - "vulnerabilities": { "GHSA-mediation-maven-vendored": { - "cves": ["CVE-2026-7204"], "summary": "s", "severity": "high", "description": "d" - } }, - "description": "maven mediation capstone", - "license": "MIT", - "tier": "free", - }); - let manifest = serde_json::json!({ "patches": { fixture::purl(): record } }); - std::fs::create_dir_all(proj.join(".socket/blobs")).unwrap(); - std::fs::write( - proj.join(".socket/manifest.json"), - serde_json::to_string_pretty(&manifest).unwrap(), - ) - .unwrap(); - std::fs::write(proj.join(".socket/blobs").join(git_sha256(&after)), after).unwrap(); - } - - /// The committed wiring is the record of where a patch is pinned: it - /// checks clean and a re-run leaves it alone on any machine, whatever - /// that machine's local repository holds. A project whose parent pom - /// comes from a repository is vendored on a machine that never - /// resolved it (what Maven selects cannot be told there, so the - /// declaration is rewritten and no pin is written). On a machine that - /// did resolve it, `vendor --check` passes, a second `vendor` changes - /// no byte, and Maven builds the patched jar. - #[test] - #[ignore = "real Maven + Maven Central (dependency plugin); run with --ignored"] - fn maven_vendored_wiring_checks_clean_and_stays_put_on_any_machine() { - let Some(mvn) = Mvn::detect(SUITE) else { - return; - }; - let tmp = tempfile::tempdir().unwrap(); - let root: PathBuf = tmp.path().canonicalize().unwrap(); - let (warm, cold) = (root.join("m2-warm"), root.join("m2-cold")); - let settings = root.join("settings.xml"); - write_settings(&settings, &[]); - let server = Server::start(); - fixture::publish(&server); - let proj = root.join("proj"); - std::fs::create_dir_all(&proj).unwrap(); - std::fs::write(proj.join("pom.xml"), fixture::parented_pom(&server)).unwrap(); - let Some(before) = fixture::resolve(SUITE, &mvn, &proj, &warm, &settings, "target/before") - else { - return; - }; - assert!(before.contains_key(&fixture::victim_jar_name(fixture::BASE))); - // The other machine holds the installed victim and nothing else of - // this build: not the parent pom its selection hangs on. - let installed = fixture::victim_dir(&cold, fixture::BASE); - std::fs::create_dir_all(&installed).unwrap(); - for entry in std::fs::read_dir(fixture::victim_dir(&warm, fixture::BASE)).unwrap() { - let entry = entry.unwrap(); - std::fs::copy(entry.path(), installed.join(entry.file_name())).unwrap(); - } - let vendor = |m2: &Path, args: &[&str]| { - let mut all = vec!["vendor"]; - all.extend_from_slice(args); - all.extend_from_slice(&["--json", "--cwd", proj.to_str().unwrap()]); - socket(&proj, m2, &all) - }; - - stage(&proj); - let (code, env, stderr) = vendor(&cold, &["--offline"]); - assert_eq!(code, Some(0), "vendor on the cold machine: {env}\n{stderr}"); - assert_eq!(env["summary"]["applied"], 1, "{env}"); - let sv = suffixed(); - let pom = std::fs::read_to_string(proj.join("pom.xml")).unwrap(); - assert!(pom.contains(&format!("{sv}")), "{pom}"); - assert!( - !pom.contains("