Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
fd06421
Pin a Maven patch only where Maven selects its base version
mikolalysenko Nov 16, 2026
abfabe0
Restore the line breaks of two vendored Maven warnings
mikolalysenko Nov 16, 2026
6c1467a
Read a dependency a pom declares twice as Maven does
mikolalysenko Nov 16, 2026
d5eb740
Pin a vendored Maven patch in the modules that select its version
mikolalysenko Nov 16, 2026
82d9239
Keep vendored Maven pins where they were committed, on every machine
mikolalysenko Nov 16, 2026
fbe0982
Merge the review fixes of the Maven selection work
mikolalysenko Nov 16, 2026
104f968
Never hold a pin that moves a module, and attest only wired modules
mikolalysenko Nov 16, 2026
cf3353c
Keep a Maven selection only while every read it was made from still h…
mikolalysenko Nov 16, 2026
a8d8045
Merge branch 'fix/maven-pin-follows-mediation' into fix/maven-pin-per…
mikolalysenko Nov 16, 2026
7795510
Let a deeper range the model cannot resolve hold the selection back
claude Nov 17, 2026
905c05b
Plan hosted Maven pins over a reactor, and wire ${property} versions
mikolalysenko Nov 17, 2026
9b79a5d
Find and restore hosted Maven pins in every pom of a reactor
mikolalysenko Nov 17, 2026
6ee38a8
Test hosted Maven reactors and property versions against real Maven
mikolalysenko Nov 17, 2026
8d4fbb8
Let a later hosted scan pin the Maven modules an earlier one could no…
mikolalysenko Nov 17, 2026
c377458
Never fail a hosted run on a Maven module pom that cannot be read
mikolalysenko Nov 17, 2026
d879384
Read an earlier release's Maven pin by its shape only in a single pom
mikolalysenko Nov 17, 2026
36c418f
Write a hosted Maven plan whole or not at all, over a reactor read once
mikolalysenko Nov 17, 2026
56ae4ee
Test the hosted Maven invariant against real Maven, and document it
mikolalysenko Nov 17, 2026
7e1f39c
test(maven): pin the hosted property and reactor rewrites in the gold…
mikolalysenko Nov 17, 2026
14ffdc7
Ask a hosted Maven repository only for the version it serves
mikolalysenko Nov 18, 2026
c2fd330
Test against real Maven what a hosted Socket repository is asked for
mikolalysenko Nov 18, 2026
2ce982c
Merge origin/main into fix/maven-hosted-reactors-and-properties
mikolalysenko Nov 18, 2026
56377bf
Merge fix/maven-hosted-reactors-and-properties (with main) into fix/m…
mikolalysenko Nov 18, 2026
dc3ccc2
Never take a reactor pom that is not UTF-8 text for a missing one
mikolalysenko Nov 18, 2026
89bbf72
Merge fix/maven-hosted-reactors-and-properties into fix/maven-hosted-…
mikolalysenko Nov 18, 2026
3b8dd67
Merge origin/main into fix/maven-hosted-reactors-and-properties
mikolalysenko Nov 18, 2026
39eb8e2
Merge fix/maven-hosted-reactors-and-properties into fix/maven-hosted-…
mikolalysenko Nov 19, 2026
2f75e07
Fix the review findings on the Maven repository filter
mikolalysenko Nov 19, 2026
7bdc058
Merge origin/main into fix/maven-hosted-reactors-and-properties
mikolalysenko Nov 19, 2026
234f1f7
Merge the base branch's last head into fix/maven-hosted-repo-scoping
mikolalysenko Nov 19, 2026
81000f2
Merge origin/main into fix/maven-hosted-repo-scoping
mikolalysenko Nov 19, 2026
c14138f
Name the Maven filter directory as the checksums directory is named
mikolalysenko Nov 19, 2026
17393a7
Never let the Maven repository filter refuse a run or fail a build
mikolalysenko Nov 19, 2026
b7ad56f
Merge origin/main into fix/maven-hosted-repo-scoping
mikolalysenko Dec 1, 2026
b7bd13e
Test where a planned Maven dependency drops its stale checksum lines
mikolalysenko Dec 1, 2026
e289ba5
Name the filter's key where the contract's mirror section names the r…
mikolalysenko Dec 1, 2026
7250581
Expect the Maven repository filter in the tests main added for a pinn…
mikolalysenko Dec 1, 2026
5c019c5
Merge origin/main into fix/maven-hosted-repo-scoping
mikolalysenko Dec 1, 2026
1af632f
Keep the Maven repository filter from refusing a run, and give its li…
mikolalysenko Dec 1, 2026
deb5bcf
Merge origin/main into fix/maven-hosted-repo-scoping
mikolalysenko Dec 1, 2026
22d663a
Keep the Maven filter's files from confirming a patch, refusing an ej…
mikolalysenko Dec 1, 2026
42e730c
Mend a Maven filter file that is not text for a pin in place
mikolalysenko Dec 1, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
195 changes: 192 additions & 3 deletions crates/socket-patch-cli/CLI_CONTRACT.md

Large diffs are not rendered by default.

51 changes: 51 additions & 0 deletions crates/socket-patch-cli/src/commands/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1994,6 +1994,24 @@ impl EjectSnapshot {
.iter()
.map(|s| s.to_string()),
);
// A hosted Maven pin's restore also removes the repository filter
// files hosted mode keeps for it, one per patch: its own regular
// files only. Anything else in that directory (a subdirectory, a
// link, a file of the user's) is not the restore's to touch, and
// must not be read as a file here. Nor is one of its own files
// that cannot be read: the restore leaves such a file where it is,
// and it must not refuse the eject of every pin.
let disk = socket_patch_core::vendor::lock_inventory::ProjectView::Disk(root);
let filters = socket_patch_core::patch::redirect::hosted_maven_filter_dir(&disk).await;
for rel in filters.owned {
let path = root.join(&rel);
if socket_patch_core::utils::fs::read_regular_to_bytes(&path)
.await
.is_ok()
{
planned.insert(rel);
}
}
let mut files = std::collections::BTreeMap::new();
for rel in root_files.iter().chain(planned.iter()) {
if files.contains_key(rel) {
Expand Down Expand Up @@ -9312,6 +9330,39 @@ mod eject_snapshot_tests {
let err = taken.err().expect("a FIFO must fail the snapshot");
assert_eq!(err.kind(), std::io::ErrorKind::InvalidInput);
}

/// The snapshot takes hosted Maven's own filter files, which the
/// restore of a hosted pin removes, and nothing else of that
/// directory: a subdirectory or a FIFO there (not hosted mode's, and
/// not a file) must not fail the eject of every ecosystem.
#[cfg(unix)]
#[tokio::test]
async fn snapshot_takes_only_hosted_maven_filter_files_of_their_directory() {
let tmp = tempfile::tempdir().unwrap();
let dir = tmp.path().join(".mvn/socket-patch");
std::fs::create_dir_all(dir.join("notes")).unwrap();
let ours = "prefixes-socket-patch-77777777-7777-4777-8777-777777777777.txt";
std::fs::write(dir.join(ours), "## repository-prefixes/2.0\n").unwrap();
std::fs::write(dir.join("prefixes-central.txt"), "/org\n").unwrap();
let fifo = dir.join("prefixes-socket-patch-88888888-8888-4888-8888-888888888888.txt");
let c = std::ffi::CString::new(fifo.to_str().unwrap()).unwrap();
assert_eq!(unsafe { libc::mkfifo(c.as_ptr(), 0o644) }, 0);
let snapshot = tokio::time::timeout(
std::time::Duration::from_secs(10),
EjectSnapshot::take(tmp.path(), &[]),
)
.await
.expect("nothing in the filter directory wedges the snapshot")
.expect("nor fails it");
let taken: Vec<&str> = snapshot
.planned
.iter()
.map(String::as_str)
.filter(|rel| rel.starts_with(".mvn/socket-patch/"))
.collect();
assert_eq!(taken, [format!(".mvn/socket-patch/{ours}").as_str()]);
assert!(snapshot.files[&format!(".mvn/socket-patch/{ours}")].is_some());
}
}

#[cfg(test)]
Expand Down
53 changes: 38 additions & 15 deletions crates/socket-patch-cli/tests/e2e_bazel_build/maven.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,25 @@ const PLACEHOLDER: &str = "http://socket-fixture.invalid/maven2";
/// The route prefixes of the stand-in, one per host it plays.
const UPSTREAM: &str = "maven2";
const PATCH_HOST: &str = "patch.socket.dev";
/// The file of the block, and the files hosted mode writes in a checkout
/// that Maven builds too: those of a Maven pin, and that one.
/// The file of the block.
const MODULE: &str = "MODULE.bazel";
const PINNED: [&str; 4] = [
".mvn/checksums/checksums.sha256",
".mvn/maven.config",
MODULE,
"pom.xml",
];
/// The warning of the run that switches Maven's repository filter on, which
/// the first Maven pin of a checkout does.
const FILTER_ENABLED: &str = "redirect_maven_repository_filter_enabled";

/// The files hosted mode writes for the patch `uuid` in a checkout that
/// Maven builds too: those of a Maven pin (the pom, the Trusted Checksums
/// and the repository filter file of the patch's own repository), and the
/// file of the block.
fn pinned_files(uuid: &str) -> [String; 5] {
[
".mvn/checksums/checksums.sha256".to_string(),
".mvn/maven.config".to_string(),
format!(".mvn/socket-patch/prefixes-socket-patch-{uuid}.txt"),
MODULE.to_string(),
"pom.xml".to_string(),
]
}
/// What the command says after its reason when it writes no entry.
const KEEPS: &str = "socket-patch wrote nothing to MODULE.bazel for it, so the Bazel build keeps \
the upstream jar";
Expand Down Expand Up @@ -692,16 +702,29 @@ impl Pinned {
self.pinned(&get, &self.patch, before, files)
}

/// [`Pinned::pins`] in a checkout that Maven builds too: the command
/// writes the files of a Maven pin and the block ([`pinned_files`]).
fn pins_the_pom_too(&self, before: &Tree) -> Tree {
let files = pinned_files(&self.patch.uuid);
self.pins(before, &files.each_ref().map(String::as_str))
}

/// What a finished hosted command did for `patch`: it reports the
/// patch applied, rewrote `files` and no other file of `before`, and
/// gave no warning. `MODULE.bazel` is the one of before with the block
/// after one blank line, and nothing has asked for the patched jar
/// yet. Gives the files of the checkout.
/// gave no warning but the one of a Maven pin that switches Maven's
/// repository filter on ([`FILTER_ENABLED`]). `MODULE.bazel` is the one
/// of before with the block after one blank line, and nothing has
/// asked for the patched jar yet. Gives the files of the checkout.
fn pinned(&self, ran: &Ran, patch: &Granted, before: &Tree, files: &[&str]) -> Tree {
let (test, said) = (&self.cell.test, &ran.dump);
let purl = format!("pkg:maven/{GROUP}/{VICTIM}@{}", patch.version);
let pinned = self.cell.pinned_by(ran, &purl, &patch.uuid, before, files);
assert_eq!(ran.envelope["warnings"], Value::Null, "{test}: {said}");
let warned: &[&str] = match files.contains(&"pom.xml") {
true => &[FILTER_ENABLED],
false => &[],
};
let warnings = &ran.envelope["warnings"];
assert_eq!(codes_in(warnings), warned, "{test}: {said}");
let text = |tree: &Tree| String::from_utf8(tree[MODULE].clone()).expect("a text file");
let with_block = format!("{}\n{}", text(before), block(patch));
assert_eq!(text(&pinned), with_block, "{test}: {said}");
Expand Down Expand Up @@ -849,8 +872,8 @@ fn a_pom_patch_beside_a_pinned_hub() {
flow.builds_upstream();
let before = flow.names_its_bazel();

// The three files of a Maven pin, and the block for the hub.
let pinned = flow.pins(&before, &PINNED);
// The files of a Maven pin, and the block for the hub.
let pinned = flow.pins_the_pom_too(&before);
flow.builds_patched(&pinned);

let undo = flow.socket_patch(&["rollback", "--yes"]);
Expand Down Expand Up @@ -1522,7 +1545,7 @@ fn an_agent_patch_beside_a_pinned_hub() {

// (d) What the documents say to run: the build is patched, and the
// document says so.
let pinned = flow.pins(&patched, &PINNED);
let pinned = flow.pins_the_pom_too(&patched);
flow.builds_patched(&pinned);
let run = |cell: &Cell, args: &[&str]| flow.socket_patch_in(cell, &flow.standin, args);
let hosted = Claim::new(PURL, &flow.patch.uuid, How::Hosted);
Expand Down
58 changes: 41 additions & 17 deletions crates/socket-patch-cli/tests/e2e_bazel_maven_beside.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,12 +685,19 @@ fn a_hub_only_tree_says_why_the_hub_is_not_patched() {
}
}

/// The files of a Maven pin, and the block's.
const POM_FILES: [&str; 3] = [
/// The files of a Maven pin, and the block's. The pin's repository filter
/// file is named for the patch ([`UUID`]).
const POM_FILES: [&str; 4] = [
"proj/.mvn/checksums/checksums.sha256",
"proj/.mvn/maven.config",
"proj/.mvn/socket-patch/prefixes-socket-patch-5e0a7c1d-7b4e-4c1a-9f0e-2a3b4c5d6e7f.txt",
"proj/pom.xml",
];
/// What the run that writes the first Maven pin of a checkout warns of: it
/// switched Maven's repository filter on in `.mvn/maven.config`. It comes
/// before what the run says of the hub, and a run that writes for the hub
/// alone does not give it.
const FILTER_ENABLED: &str = "redirect_maven_repository_filter_enabled";
const MODULE: &str = "proj/MODULE.bazel";

#[test]
Expand Down Expand Up @@ -720,7 +727,9 @@ fn a_pinned_hub_gets_its_block_and_the_undo_takes_it_out() {
"{dry:?}"
);

// The run: applied, no warning, the block after one blank line.
// The run: applied, no warning of the hub (a Maven pin says that
// it switched the repository filter on), the block after one blank
// line.
let get = machine.step(COMMANDS[0]);
let envelope = get.envelope();
assert_eq!(get.code, Some(0), "{get:?}");
Expand All @@ -730,7 +739,11 @@ fn a_pinned_hub_gets_its_block_and_the_undo_takes_it_out() {
json!(rewritten),
"{get:?}"
);
assert_eq!(envelope["warnings"], Value::Null, "{get:?}");
assert_eq!(
warning_codes(&envelope),
[FILTER_ENABLED][..usize::from(maven)],
"{get:?}"
);
assert_eq!(get.wrote.keys().collect::<Vec<_>>(), files, "{get:?}");
assert_eq!(
String::from_utf8_lossy(&get.wrote[MODULE]),
Expand Down Expand Up @@ -855,7 +868,8 @@ fn a_hosted_run_removes_the_jar_vendored_mode_kept_for_the_hub() {
vendored(&machine, true);
let ran = machine.step(command);
assert_eq!(ran.code, Some(0), "{ran:?}");
assert_eq!(ran.envelope()["warnings"], Value::Null, "{ran:?}");
// (Nothing of the hub: the run pins the Maven build beside it.)
assert_eq!(warning_codes(&ran.envelope()), [FILTER_ENABLED], "{ran:?}");
let with_block = format!("{HUB}\n{BLOCK}");
assert_eq!(
String::from_utf8_lossy(&ran.wrote[MODULE]),
Expand Down Expand Up @@ -961,14 +975,14 @@ fn the_hub_gets_its_block_whatever_the_maven_pin_is() {
vec![("pom.xml", root.to_string()), ("app/pom.xml", module)],
&["app/pom.xml", "pom.xml"],
None,
&[],
&[FILTER_ENABLED],
),
(
"a property",
vec![("pom.xml", property)],
&["pom.xml"],
None,
&[],
&[FILTER_ENABLED],
),
(
"a mirror",
Expand Down Expand Up @@ -996,12 +1010,12 @@ fn the_hub_gets_its_block_whatever_the_maven_pin_is() {
"{shape}: {get:?}"
);
assert_eq!(warning_codes(&envelope), warns, "{shape}: {get:?}");
// The block, the poms of the pin, and the checksum files of a
// Maven pin when there is one.
// The block, the poms of the pin, and the `.mvn` files of a Maven
// pin when there is one: its checksums and its repository filter.
let pin: Vec<&str> = [&["MODULE.bazel"], pinned_poms].concat();
let mut wrote: Vec<String> = pin.iter().map(|file| format!("proj/{file}")).collect();
let checksums = &POM_FILES[..2 * usize::from(!pinned_poms.is_empty())];
wrote.extend(checksums.iter().map(|file| file.to_string()));
let mvn = &POM_FILES[..3 * usize::from(!pinned_poms.is_empty())];
wrote.extend(mvn.iter().map(|file| file.to_string()));
wrote.sort_unstable();
assert_eq!(
get.wrote.keys().collect::<Vec<_>>(),
Expand Down Expand Up @@ -1124,8 +1138,11 @@ fn a_decline_writes_nothing_for_the_hub_and_says_why() {
files,
"{code}: {ran:?}"
);
assert_eq!(warning_codes(&envelope), [*code], "{ran:?}");
let detail = envelope["warnings"][0]["detail"]
// The Maven pin that lands says its own line first.
let codes = [FILTER_ENABLED, *code];
let of_the_hub = 1 - usize::from(maven);
assert_eq!(warning_codes(&envelope), codes[of_the_hub..], "{ran:?}");
let detail = envelope["warnings"][usize::from(maven)]["detail"]
.as_str()
.expect("its text");
let said = detail.starts_with(PURL) && detail.contains(why) && detail.ends_with(KEEPS);
Expand Down Expand Up @@ -1233,13 +1250,17 @@ fn a_decline_names_the_entry_of_another_patch_that_remains() {
assert_eq!(ran.code, Some(0), "{ran:?}");
assert_eq!(event_for(&envelope, PURL)["action"], action, "{ran:?}");
assert_eq!(ran.wrote.keys().collect::<Vec<_>>(), wrote, "{ran:?}");
assert_eq!(warning_codes(&envelope), ["maven_bazel_release"], "{ran:?}");
// The Maven pin that lands says its own line first.
let codes = [FILTER_ENABLED, "maven_bazel_release"];
let of_the_hub = 1 - usize::from(maven);
assert_eq!(warning_codes(&envelope), codes[of_the_hub..], "{ran:?}");
let remains = format!(
"{PURL}: {NO_RELEASE}. socket-patch wrote nothing to MODULE.bazel for it: the entry \
of patch {other} remains there, and where the block is in effect the Bazel build \
takes that patch's jar"
);
assert_eq!(envelope["warnings"][0]["detail"], remains, "{ran:?}");
let said = &envelope["warnings"][usize::from(maven)]["detail"];
assert_eq!(*said, remains, "{ran:?}");
}
}

Expand Down Expand Up @@ -1647,7 +1668,7 @@ fn a_hosted_scan_takes_a_stale_entry_out_of_the_block() {
// Beside a `pom.xml` that still selects the release: the pin of the
// Maven build stays, and the entry alone goes.
machine.make(&pinned(), true, false);
assert_eq!(machine.step(COMMANDS[0]).wrote.len(), 4);
assert_eq!(machine.step(COMMANDS[0]).wrote.len(), 1 + POM_FILES.len());
std::fs::write(machine.root.join("proj/maven_install.json"), &moved).expect("the lock");
let scan = machine.step(&SCAN);
assert_eq!(scan.wrote.keys().collect::<Vec<_>>(), [MODULE], "{scan:?}");
Expand Down Expand Up @@ -1822,8 +1843,11 @@ fn a_hosted_scan_leaves_a_stale_entry_of_vendored_mode() {
};
let purls = event_triples(&said).into_iter().map(|(purl, ..)| purl);
assert_eq!(purls.collect::<Vec<_>>(), pins, "{maven}: {scan:?}");
// (Nothing of the hub: beside it the scan pins the Maven build.)
let codes = warning_codes(&said);
assert_eq!((scan.code, codes), (Some(0), vec![]), "{maven}: {scan:?}");
let pin = [FILTER_ENABLED][..usize::from(maven)].to_vec();
assert_eq!(scan.code, Some(0), "{maven}: {scan:?}");
assert_eq!(codes, pin, "{maven}: {scan:?}");
assert_eq!(of_the_hub(&machine), held, "{maven}: {scan:?}");
}
}
Expand Down
Loading
Loading