Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
9bd7d4f
Test PyPI and RubyGems vendored mode beside a Bazel hub on real Bazel
mikolalysenko Nov 23, 2026
9c9f202
Decline PyPI and RubyGems vendored mode where a Bazel hub reads the lock
mikolalysenko Nov 23, 2026
2d652c5
Close three ways a vendored run could still write a file a Bazel hub …
mikolalysenko Nov 23, 2026
9a022a8
Decline a vendored run where a hub reads a parent file or is in doubt
claude Nov 24, 2026
224f39d
Test agent mode for Cargo and NuGet beside a Bazel hub that builds fr…
mikolalysenko Nov 24, 2026
a60599c
Attest a Cargo or NuGet patch as affected in VEX where a Bazel hub bu…
mikolalysenko Nov 24, 2026
84b126d
Merge main into the VEX answer for Cargo and NuGet under a Bazel hub
mikolalysenko Nov 24, 2026
5a5cdc4
Read a NuGet lock below the run's directory as the project's own in t…
mikolalysenko Nov 24, 2026
541644f
Accept either unseen repository where a Cargo flow comments out the i…
mikolalysenko Nov 24, 2026
ac313c0
Merge remote-tracking branch 'origin/main' into bazel-guard/vendored-…
mikolalysenko Nov 24, 2026
66d9cd1
Merge remote-tracking branch 'origin/main' into bazel-guard/vendored-…
mikolalysenko Nov 24, 2026
23398b6
Accept either unseen repository where a Cargo flow comments out the i…
mikolalysenko Nov 24, 2026
46eacb8
Hold the unseen repository to Bazel's own words, and say so in the docs
mikolalysenko Nov 24, 2026
f3e5623
Hold the unseen repository to Bazel's own words, and say so in the docs
mikolalysenko Nov 24, 2026
916924b
Merge main into bazel-vex/04-cargo-nuget-installed
claude Nov 25, 2026
ec60674
Merge remote-tracking branch 'origin/main' into bazel-guard/vendored-…
mikolalysenko Nov 25, 2026
6e78f04
Test agent mode for Maven beside a Bazel hub that fetches the jar fro…
mikolalysenko Nov 25, 2026
7e63062
Attest a Maven patch as affected in VEX where a pinned Bazel hub fetc…
mikolalysenko Nov 25, 2026
1aad23c
Hold every Maven patch to the Bazel hub in VEX, whichever mode holds it
mikolalysenko Nov 25, 2026
7f549ab
Start the Maven Bazel legs for the jar manifest reader
mikolalysenko Nov 25, 2026
6016a39
Say affected beside what is left of a block that overrides nothing
mikolalysenko Nov 25, 2026
a76793d
Merge main into bazel-vex/05-maven-installed
claude Nov 25, 2026
4fe3b14
Pass over a WORKSPACE file where the checkout names Bazel 9 or later
mikolalysenko Nov 25, 2026
752c70b
Count an entry of the block only where it reaches the hub that fetche…
mikolalysenko Nov 25, 2026
a085179
Merge main into bazel-vex/05-maven-installed
mikolalysenko Nov 25, 2026
7bb34cc
Hold the Maven statement to the switch for a project that Bazel does …
mikolalysenko Nov 25, 2026
49b963e
Merge remote-tracking branch 'origin/main' into bazel-guard/vendored-…
mikolalysenko Nov 25, 2026
0d836f1
Merge main into bazel-vex/05-maven-installed
mikolalysenko Nov 25, 2026
2ca5a19
Merge the vendored-hub guard into bazel-vex/05-maven-installed
mikolalysenko Nov 25, 2026
3817e34
Merge main into bazel-vex/05-maven-installed
mikolalysenko Nov 25, 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
Prev Previous commit
Next Next commit
Test agent mode for Maven beside a Bazel hub that fetches the jar fro…
…m its lock

Two tests, no product change, that record what socket-patch does today
in a workspace where a pinned rules_jvm_external hub
(`maven.install(lock_file = "//:maven_install.json", ...)`) fetches an
artifact and agent mode patches the jar of that artifact in the Maven
local repository:

- `maven::an_agent_patch_beside_a_pinned_hub`, on real Bazel: the
  checkout has a `pom.xml` that declares the artifact, and the jar is in
  the Maven local repository as a Maven build leaves it.
  `scan --mode agent --yes` exits 0, puts the patch service's jar in its
  place and writes nothing into the checkout but `.socket/`; `apply`
  passes and warns `maven_bazel_hub_unpatched`. `bazel build` and
  `bazel run //:consumer` print the upstream marker before the command
  and after it: the hub fetches the jar its lock pins, at the lock's
  sha256, and no build reads the Maven local repository.
- `maven::an_installed_jar_is_attested_beside_a_hub_that_fetches_its_own`,
  without Bazel: the same step in a checkout whose lock is written by
  the test, in the format rules_jvm_external 7.2 writes.

In both, `scan --mode agent --vex`, `apply --vex`, `vex` and
`vex --no-verify` each write an OpenVEX document whose one statement
says the artifact is `not_affected`, "Patched via Socket patch <uuid>".
That document is false for what Bazel builds. The tests assert it as it
is today and mark it KNOWN GAP, with what a fix changes.

What the tests share is in the Maven module: step 0 of a flow is split
into the layout of the checkout and the ruleset's pin, so that a
checkout no Bazel builds in can have the same stand-in, grants and
local repository; `Pinned::patches_the_installed_jar` runs the agent
step. `Cell::patches_outside` of the harness compares the installed
file as bytes, since a jar is no text; the Cargo and NuGet flows call it
as before.

The real-Bazel flow passes on Bazel 9.3.2 and 7.7.2 (macOS arm64) with
no change to the product, in about 20 s each.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
  • Loading branch information
mikolalysenko and claude committed Nov 25, 2026
commit 6e78f046b5d018eef3d9286dff429854a05d154d
9 changes: 5 additions & 4 deletions crates/socket-patch-cli/tests/e2e_bazel_build/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1452,7 +1452,7 @@ impl Cell {

/// Agent mode in this checkout, through `run`, for a package that its
/// package manager keeps outside the checkout, where `installed` is a
/// file of that copy: `scan --mode agent --yes` gives the file the text
/// file of that copy: `scan --mode agent --yes` gives the file the bytes
/// `patched`, from the record of the patch, and writes nothing into the
/// checkout but its own `.socket` directory, and the `apply` of a later
/// run passes. Then what the two say with `--vex`, and what `vex` and
Expand All @@ -1462,7 +1462,7 @@ impl Cell {
&self,
run: impl Fn(&Cell, &[&str]) -> Ran,
installed: &Path,
patched: &str,
patched: impl AsRef<[u8]>,
claim: &Claim,
) -> Tree {
let test = &self.test;
Expand All @@ -1478,8 +1478,9 @@ impl Cell {
let mut wrote = changed(&before, &left);
wrote.retain(|file| !file.starts_with(".socket/"));
assert_eq!(wrote, NOTHING, "{test}: {said}");
let holds = std::fs::read_to_string(installed).unwrap_or_default();
assert_eq!(holds, patched, "{test}: {}", installed.display());
let holds = std::fs::read(installed).unwrap_or_default();
let (at, shown) = (installed.display(), String::from_utf8_lossy(&holds));
assert!(holds == patched.as_ref(), "{test}: {at} holds:\n{shown}");

let again = self.document("apply");
let apply = run(self, &[&["apply"][..], &with_vex(&again)].concat());
Expand Down
228 changes: 184 additions & 44 deletions crates/socket-patch-cli/tests/e2e_bazel_build/maven.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@
//! hosted command then takes the vendored entry, its directory and its
//! ledger entry out again, and the checkout is the one the first hosted
//! command left; `rollback` undoes a vendored patch to the byte.
//! - [`an_agent_patch_beside_a_pinned_hub`]: agent mode in a checkout that
//! Maven builds too. `scan --mode agent --yes` puts the patched jar in
//! the Maven local repository and patches no hub: the build prints the
//! upstream marker before and after. The document of the run, of
//! `apply`, of `vex` and of `vex --no-verify` says that the artifact is
//! not affected, which is false for what Bazel builds (KNOWN GAP).
//!
//! A command that writes the block gives no warning. One that does not
//! gives one, in the place of "no pom.xml", with the reason and the words
Expand Down Expand Up @@ -127,9 +133,10 @@ use sha2::{Digest, Sha256, Sha512};
use socket_patch_core::bazel::maven::{Lock, Pinned as Jar};
use socket_patch_core::hash::git_sha256::compute_git_sha256_from_bytes as git_sha256;

use crate::envelope::{event_for, event_triples};
use crate::envelope::{codes_in, event_for, event_triples};
use crate::harness::{
changed, rewrite, Cell, Claim, Fixture, How, Ran, StandIn, Tree, CONSUMER, NOTHING,
cell_without_bazel, changed, fixture_path, rewrite, Cell, Claim, Fixture, How, Ran, StandIn,
Tree, CONSUMER, NOTHING,
};
use crate::hosted_memory_common::{Patch, ORG};

Expand Down Expand Up @@ -431,15 +438,68 @@ struct Pinned {
}

impl Pinned {
/// Step 0 of every flow: the fixture's checkout for `test`, with a
/// Step 0 of every flow: the fixture's checkout for `test`
/// ([`Pinned::laid_out`]), pinned by the ruleset against its stand-in.
/// `None` when no Bazel runs here.
fn open(test: &str, maven: bool, prepare: &dyn Fn(&Cell, &mut String)) -> Option<Pinned> {
let flow = Pinned::laid_out(Cell::open(test, &FIXTURE)?, maven, prepare);
let (cell, repository) = (&flow.cell, flow.repository());

// The ruleset's own relock. The lock it writes holds the victim,
// which `MODULE.bazel` does not name, at the sha256 of this run's
// jar, in the format of the era.
let pin = cell.bazel_env("run", &[&format!("@{HUB}//:pin")], &[("REPIN", "1")]);
assert!(pin.ok(), "{test}: {}", pin.dump());
let lock = std::fs::read_to_string(cell.path("maven_install.json")).expect("the lock");
let raw: Value = serde_json::from_str(&lock).expect("the lock is JSON");
// Nothing else is in it: no other Bazel module added to the hub,
// and its one repository is the stand-in.
let keys = |of: &str| {
let map = raw[of].as_object().expect("a map of the lock");
map.keys().map(String::as_str).collect::<Vec<_>>().join(" ")
};
assert_eq!(
(keys("artifacts"), keys("repositories")),
(
format!("{GROUP}:consumer {GROUP}:{VICTIM}"),
format!("{repository}/")
),
"{test}: {raw:#}"
);
let lock = Lock::parse(&lock).unwrap_or_else(|why| panic!("{test}: {why}:\n{lock}"));
let format = if cell.numbers() >= (9, 0, 0) { 3 } else { 2 };
let jar = Jar {
version: VERSION.to_string(),
jar_sha256: Some(sha256_hex(&flow.upstream_jar())),
fetched: true,
};
assert_eq!(
(lock.format, lock.plain_jar(GROUP, VICTIM)),
(format, Some(&jar)),
"{test}: {lock:?}"
);
Some(flow)
}

/// The repository of the hub: the stand-in's.
fn repository(&self) -> String {
format!("{}/{UPSTREAM}", self.standin.origin())
}

/// The upstream jar of the victim that the stand-in serves.
fn upstream_jar(&self) -> Vec<u8> {
victim(&format!("PRISTINE {}", self.run))
}

/// The checkout `cell` of the fixture before its hub is pinned, with a
/// `pom.xml` that declares the victim when `maven` is set and with
/// what `prepare` adds to its files and to the text of `MODULE.bazel`,
/// pinned by the ruleset against a stand-in that has the two
/// artifacts, the patched jar and the grant of its patch. `None` when
/// no Bazel runs here.
fn open(test: &str, maven: bool, prepare: &dyn Fn(&Cell, &mut String)) -> Option<Pinned> {
/// against a stand-in that has the two artifacts, the patched jar and
/// the grant of its patch. The lock is the empty file the ruleset's
/// documentation starts from.
fn laid_out(mut cell: Cell, maven: bool, prepare: &dyn Fn(&Cell, &mut String)) -> Pinned {
let started = Instant::now();
let mut cell = Cell::open(test, &FIXTURE)?;
let test = cell.test.clone();
// The cache of the Coursier that pins. Before 7.2 the ruleset
// leaves the choice to Coursier, which without this takes the home
// directory from the system, whatever `HOME` says.
Expand Down Expand Up @@ -493,41 +553,8 @@ impl Pinned {
std::fs::write(&file, bytes).expect("write the local repository");
}

// The ruleset's own relock. The lock it writes holds the victim,
// which `MODULE.bazel` does not name, at the sha256 of this run's
// jar, in the format of the era.
let pin = cell.bazel_env("run", &[&format!("@{HUB}//:pin")], &[("REPIN", "1")]);
assert!(pin.ok(), "{test}: {}", pin.dump());
let lock = std::fs::read_to_string(cell.path("maven_install.json")).expect("the lock");
let raw: Value = serde_json::from_str(&lock).expect("the lock is JSON");
// Nothing else is in it: no other Bazel module added to the hub,
// and its one repository is the stand-in.
let keys = |of: &str| {
let map = raw[of].as_object().expect("a map of the lock");
map.keys().map(String::as_str).collect::<Vec<_>>().join(" ")
};
assert_eq!(
(keys("artifacts"), keys("repositories")),
(
format!("{GROUP}:consumer {GROUP}:{VICTIM}"),
format!("{repository}/")
),
"{test}: {raw:#}"
);
let lock = Lock::parse(&lock).unwrap_or_else(|why| panic!("{test}: {why}:\n{lock}"));
let format = if cell.numbers() >= (9, 0, 0) { 3 } else { 2 };
let jar = Jar {
version: VERSION.to_string(),
jar_sha256: Some(sha256_hex(&upstream_jar)),
fetched: true,
};
assert_eq!(
(lock.format, lock.plain_jar(GROUP, VICTIM)),
(format, Some(&jar)),
"{test}: {lock:?}"
);
let upstream = format!("OUT: PRISTINE {run}");
Some(Pinned {
Pinned {
cell,
standin,
tools,
Expand All @@ -537,7 +564,7 @@ impl Pinned {
upstream,
upstream_route: format!("/{UPSTREAM}/{}", repo_path(VICTIM, VERSION, "jar")),
started,
})
}
}

/// Step 1: the build prints the upstream marker, from a jar Bazel
Expand Down Expand Up @@ -574,8 +601,18 @@ impl Pinned {
/// the patched jar from the URL the grant has for it on the patch host:
/// that host is the stand-in here.
fn vendored(&self, args: &[&str]) -> Ran {
self.serviced(&self.cell, args)
}

/// [`Pinned::vendored`] in the checkout `cell`. Agent mode takes the
/// patched jar from that URL as well.
fn serviced(&self, cell: &Cell, args: &[&str]) -> Ran {
let origin = self.standin.origin();
self.socket_patch(&[args, &["--patch-server-url", &origin]].concat())
self.socket_patch_in(
cell,
&self.standin,
&[args, &["--patch-server-url", &origin]].concat(),
)
}

/// The command where it writes no entry for the hub, in a tree without
Expand Down Expand Up @@ -1352,6 +1389,109 @@ fn the_users_own_override_of_the_artifact() {
);
}

/// The warning of an agent run for an artifact that a pinned hub fetches:
/// the command patches no hub.
const HUB_UNPATCHED: &str = "maven_bazel_hub_unpatched";

impl Pinned {
/// Without a Bazel: the checkout of [`Pinned::open`] beside a `pom.xml`,
/// in a workspace copy that no Bazel has built in. No ruleset pins it,
/// so the lock is written here: the two artifacts under the stand-in's
/// repository, in the format the ruleset of Bazel 9.3.2 writes.
fn unbuilt() -> Pinned {
let cell = cell_without_bazel("9.3.2");
let module = fixture_path(FIXTURE.dir).join("e9").join(MODULE);
cell.write(MODULE, std::fs::read(module).expect(MODULE));
cell.write(".git/HEAD", "ref: refs/heads/main\n");
let flow = Pinned::laid_out(cell, true, &|_, _| {});
let sums = |jar: &[u8]| json!({ "jar": sha256_hex(jar) });
let keys = [format!("{GROUP}:consumer"), format!("{GROUP}:{VICTIM}")];
let lock = json!({
"artifacts": {
&keys[0]: { "shasums": sums(&jar(&[])), "version": "2.0" },
&keys[1]: { "shasums": sums(&flow.upstream_jar()), "version": VERSION },
},
"repositories": { format!("{}/", flow.repository()): keys },
"version": "3",
});
flow.cell.write("maven_install.json", format!("{lock:#}\n"));
flow
}

/// Agent mode in the checkout ([`Cell::patches_outside`]). The victim's
/// jar is in the Maven local repository, as a Maven build of the
/// checkout's `pom.xml` leaves it: `scan --mode agent --yes` puts the
/// jar of the patch service in its place and writes nothing into the
/// checkout but its `.socket` directory, and each of the four
/// documents says `claim`. A later `apply` warns that it patches no hub
/// ([`HUB_UNPATCHED`]). Gives the files of the checkout.
fn patches_the_installed_jar(&self, claim: &Claim) -> Tree {
let test = &self.cell.test;
let installed = self.tools.path().join("m2");
let installed = installed.join(repo_path(VICTIM, VERSION, "jar"));
let patched = victim(&format!("PATCHED {}", self.patch.uuid));
let run = |cell: &Cell, args: &[&str]| self.serviced(cell, args);
let left = self.cell.patches_outside(run, &installed, &patched, claim);
let apply = self.serviced(&self.cell, &["apply"]);
let warned = codes_in(&apply.envelope["warnings"]);
assert_eq!(warned, [HUB_UNPATCHED], "{test}: {}", apply.dump);
left
}
}

/// Agent mode beside a pinned hub that fetches the artifact.
///
/// - (a) `bazel build` and `bazel run //:consumer` print the upstream
/// marker.
/// - (b) `scan --mode agent --yes` patches the jar in the Maven local
/// repository and warns that it patches no hub, and `apply` passes
/// ([`Pinned::patches_the_installed_jar`]). Both, `vex` and
/// `vex --no-verify` exit 0 and write a document that says the artifact
/// is not affected, through the patch.
/// - (c) The same two Bazel commands print the upstream marker again and
/// change no file: the hub fetches the jar its lock pins, at the lock's
/// sha256, and no build reads the Maven local repository.
///
/// KNOWN GAP: the documents of (b) are false for what Bazel builds. A fix
/// makes each say that the artifact is affected, with what Bazel builds it
/// from and the command that patches the hub.
#[test]
#[ignore = "real Bazel; run with --ignored"]
fn an_agent_patch_beside_a_pinned_hub() {
let test = "maven::an_agent_patch_beside_a_pinned_hub";
let Some(flow) = Pinned::open(test, true, &|_, _| {}) else {
return;
};
// (a) The upstream build, with the jar from the stand-in.
flow.builds_upstream();

// (b) Agent mode patches the installed jar. KNOWN GAP: every document
// says not affected.
let claim = Claim::new(PURL, &flow.patch.uuid, How::Agent);
let patched = flow.patches_the_installed_jar(&claim);

// (c) The build is the one of (a): Bazel never reads the patched jar.
flow.cell.builds(&flow.upstream);
assert_eq!(changed(&patched, &flow.cell.tree()), NOTHING, "{test}");
println!(
"{test}: Bazel {} built {:?} before and after `scan --mode agent` patched {VICTIM}-\
{VERSION}.jar in the Maven local repository; every form of `vex` said the artifact is \
not affected (KNOWN GAP); {:?}",
flow.cell.release(),
flow.upstream,
flow.started.elapsed()
);
}

/// Without a Bazel: step (b) of [`an_agent_patch_beside_a_pinned_hub`] in a
/// checkout whose hub is pinned ([`Pinned::unbuilt`]). KNOWN GAP, as there.
#[test]
fn an_installed_jar_is_attested_beside_a_hub_that_fetches_its_own() {
let flow = Pinned::unbuilt();
let claim = Claim::new(PURL, &flow.patch.uuid, How::Agent);
flow.patches_the_installed_jar(&claim);
}

/// Without a Bazel: the fixture's directories and the legs of its workflow
/// are those of the table, each era's `MODULE.bazel` has a hub of its own
/// name with the one repository a flow replaces, and a jar made here holds
Expand Down