diff --git a/crates/socket-patch-cli/CLI_CONTRACT.md b/crates/socket-patch-cli/CLI_CONTRACT.md index 579a8f8c6..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. | @@ -2744,14 +2745,33 @@ 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. +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, 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 @@ -2762,7 +2782,8 @@ is a no-op. `vendor --check` does not judge where a pin belongs at all; it takes every pin, and every absence of one, as committed. Two things still change a wired pom. A pin of a superseded patch of the same version moves to the new suffix where it stands. And a pin that is certain to move a module to -another version than Maven selects for it is taken out: when no module selects +another version than Maven selects for it is taken out, and the pins are +placed afresh for the build as it is: when no module selects the pinned version any more (a dependency was added or upgraded since), the run removes the pin from the poms, reports the `vendor_maven_version_not_selected` skip saying so, and leaves the ledger entry and tree for `vendor --revert` or @@ -3124,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), `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 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 5e320104c..6c27c2ea7 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::*; @@ -652,132 +653,224 @@ 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 } }); + stage_all(proj, &[(fixture::BASE, UUID)]); + } + + /// 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( + fixture::purl_of(version), + 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(&manifest).unwrap(), + serde_json::to_string_pretty(&serde_json::json!({ "patches": records })).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. + /// 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_wiring_checks_clean_and_stays_put_on_any_machine() { + 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 (warm, cold) = (root.join("m2-warm"), root.join("m2-cold")); + 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("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; + 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() }; - 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 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) + 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"); + } + } + } }; - stage(&proj); - let (code, env, stderr) = vendor(&cold, &["--offline"]); - assert_eq!(code, Some(0), "vendor on the cold machine: {env}\n{stderr}"); + // 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}"); - let sv = suffixed(); - let pom = std::fs::read_to_string(proj.join("pom.xml")).unwrap(); - assert!(pom.contains(&format!("{sv}")), "{pom}"); + assert_eq!(env["summary"]["failed"], 0, "{env}"); + let after = read_poms(&proj); + let text = |bytes: &[u8]| String::from_utf8_lossy(bytes).into_owned(); assert!( - !pom.contains("