Skip to content

Pin a Maven patch for a pinned rules_jvm_external hub with override_repo - #2163

Merged
Mikola Lysenko (mikolalysenko) merged 27 commits into
mainfrom
bazel-maven/02-override-repo
Nov 19, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 27 commits into
mainfrom
bazel-maven/02-override-repo

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Hosted mode now patches a Maven artifact that a pinned rules_jvm_external hub of a Bazel workspace builds: socket-patch get <purl> --mode hosted at the Bazel root appends one managed block to MODULE.bazel (Bazel's override_repo), the build takes the patched jar at its sha256, and rollback / remove take the block out byte for byte.

Stacked. This pull request is on top of #2157 ("Say when a rules_jvm_external hub builds a Maven artifact that a patch does not reach"), whose branch bazel-maven/01-hub-notice is its base; below that is #2148; #2139 and #2123, which were below it, have landed. It moves onto main when those have landed. The diff here is five commits, and the merges that brought main in through the stack: tests that record today's behaviour, the change, what a code review of it changed, a correction of what a run reports beside an entry that has no effect, and a fix of the Maven undo that the merge with main made necessary (see "After the merge with main").

What the code does today

A rules_jvm_external hub builds the jars its own lock (maven_install.json) pins and reads no pom.xml. So no Maven patch reaches a Bazel build. The first commit holds this on real Bazel, with the product code of the base:

  • In a tree that only Bazel builds, get --mode hosted reports the patch skipped (redirect_unconfirmed), writes nothing, and warns redirect_maven_no_pom and maven_bazel_hub_unpatched. The build prints the upstream marker before and after. rollback then exits 1 with manifest_not_found.
  • Beside a pom.xml, the command pins the pom, reports applied, and the Bazel build still takes the upstream jar.
  • After the checkout bumps the artifact to 1.11.0 and relocks, the build takes the new upstream jar. Nothing stops it.
  • With the user's own maven.override of the artifact, the command warns maven_bazel_unreadable and the build prints the override's target.

What changes

The block

The hub fetches each jar through a repository of its own, named after group, artifact and version. override_repo (Bazel 7.4.0 and later) puts another repository in its place. socket-patch appends this to the root MODULE.bazel, after one blank line:

# >>> socket-patch: Maven patches for Bazel (managed block: socket-patch writes and removes it) >>>
socket_patch_http_file = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")

socket_patch_maven = use_extension("<the label of the hub's own use_extension>", "maven")

# pkg:maven/<group>/<artifact>@<version>, Socket patch <uuid>
socket_patch_http_file(
    name = "socket_patch_<repository>",
    downloaded_file_path = "v1/<group path>/<artifact>/<version>/<artifact>-<version>.jar",
    sha256 = "<sha256 of the patched jar>",
    urls = ["<the patched jar on the Socket patch host>"],
)

# If Bazel stops at the next line ("does not generate repository"), the hub's lock no longer pins
# <group>:<artifact> at <version>: run `socket-patch rollback pkg:maven/<group>/<artifact>@<version>`.
# Do not change it to inject_repo(): the build would pass without the patch.
override_repo(
    socket_patch_maven,
    <repository> = "socket_patch_<repository>",
)
# <<< socket-patch <<<
  • One entry per patch, sorted by repository name, each with its own override_repo, so Bazel names the line of the one entry that went stale.
  • The hub, maven_install.json, every label and MODULE.bazel.lock stay as they are.
  • The block is socket-patch's when it is, byte for byte, what socket-patch writes for the patches it names, in the line break of its own lines. A block that was changed by hand, also in its first line alone, is neither written to nor read as a pin.
  • A new block is written in the line break of the file; in a file with both, in the more frequent one.
  • The undo takes an entry out; with the last entry the block and the blank line before it go. The file is then byte for byte what it was: in LF and CRLF files, in a file with both, with and without a last line break.

When it is written

Everything is read from the checkout; no Bazel runs. The block is written only when all of this holds:

  • the project is the Bazel root;
  • a pinned hub's lock holds the plain jar at the patch's version, and nothing about the workspace's hubs is in doubt;
  • the lock lists a repository for the jar;
  • the hub is on a shared (not isolated) use_extension;
  • Bazel is known to be 7.4.0 or later, and the rules_jvm_external release Bazel builds with is known to be one of 6.4 to 7.2;
  • no rc file of the checkout makes the block ineffective or the download impossible;
  • the patch is one of the plain jar, and comes with its served version and a sha256.

The rc files are .bazelrc and what it imports, up to 32 files: import, try-import and, from Bazel 8.7.0, try-import-if-bazel-version, whose condition is not evaluated; by a path under %workspace%/, or by a relative one, which is read from the Bazel root. Each file is read as Bazel reads one (rc_file.cc and the tokenizer in util/strings.cc at 7.4.0, 7.7.2, 8.8.2 and 9.3.2): a backslash before a line break joins two lines, a # outside quotes starts a comment, a word loses its quotes and the backslash before an escaped character, and the first word of a line is its command. A line with a quote that is never closed, or a backslash that nothing follows, makes the file one that cannot be read. An option counts as on or off the way Bazel's boolean converter reads it on those releases (false, 0, no, f, n in any case, or no before the name). A word that is neither for certain counts as the harmful one.

The release of the ruleset is the one whose source.json MODULE.bazel.lock holds, checked against what the root asks for, as Bazel takes it: a single_version_override with a version pins that release, whatever the bazel_dep line says; without one, the bazel_dep version is the least Bazel selects. Versions are compared in Bazel's order (7.2 is below 7.2.1).

Every decline

Otherwise the run writes nothing for the hub and gives one warning. Each says why, and ends with what the block of the root holds for the jar. The root is read for a project below it too, whose warning names the file as "the MODULE.bazel at the root".

  • Nothing: "socket-patch wrote nothing to MODULE.bazel for it, so the Bazel build keeps the upstream jar".
  • The entry of this patch, from an earlier run: "socket-patch left the entry that MODULE.bazel holds for it as it is".
  • The entry of another patch of the same jar: "socket-patch wrote nothing to MODULE.bazel for it: the entry of patch remains there, and where the block is in effect the Bazel build takes that patch's jar".
Code When
maven_bazel_not_at_root The project is below the Bazel root. Run the command there.
maven_bazel_not_pinned A hub has no lock_file, also beside a pinned hub that holds the jar. The message names the hub's line and the command that pins it (REPIN=1 bazel run @<the hub's name>//:pin).
maven_bazel_unreadable Something could not be read with certainty: a computed name or lock_file, two locks for one hub, a lock that is missing, empty, not format 2 or 3, no JSON or over 16 MiB, a WORKSPACE file that calls maven_install while Bazel may read it, an isolated use_extension, an rc file that cannot be read (also one that an import takes from outside the workspace by a relative path, and one with a line that has a quote that is never closed or a backslash that nothing follows; the message names the line), a MODULE.bazel that is a symbolic link, a block that was changed by hand.
maven_bazel_release .bazeliskrc or .bazelversion names a Bazel before 7.4.0; or neither names a release and MODULE.bazel.lock is missing or older than the format Bazel 7.5.0 writes; or MODULE.bazel.lock does not hold the source.json of exactly one rules_jvm_external release, that release is outside 6.4 to 7.2, or it is another one than MODULE.bazel now takes (older than the bazel_dep line, or any other than the one a single_version_override pins); or an archive_override, git_override, local_path_override or multiple_version_override of the ruleset, or a single_version_override whose version is no plain string, leaves the release unknown (the message names the override's line).
maven_bazel_artifact A character other than letters, digits, ., _, - in group, artifact or version (the repository's name is then not known); the lock lists no repository for the jar (m2local); the patch lacks its served version or sha256.
maven_bazel_no_effect The build would pass on the upstream jar: a maven.override of the artifact, or an rc file of the checkout gives --ignore_dev_dependency without switching it off, or gives enable_bzlmod other than switched on while the checkout names no Bazel 9 or later.
maven_bazel_download An rc file of the checkout gives a downloader config, --repository_disable_download or --vendor_dir.

What a run reports

  • Written: exit 0, applied, redirect.rewrittenFiles holds MODULE.bazel, no warning about the hub. Beside a pom.xml the same run pins both builds: a single pom, the poms of a reactor, a version that a property sets. Where the Maven side writes no pin and says why (for one, a mirror of the machine's Maven settings that would take the Socket repository), the hub still gets its block and the patch is applied.
  • Declined, tree only Bazel builds: exit 0, skipped / redirect_unconfirmed, the one warning, in the place of redirect_maven_no_pom.
  • Declined, beside a pom.xml that was pinned: exit 0, applied, the same warning.
  • Declined, and the block of the root already holds the patch's entry from an earlier run: the entry stays, the patch is applied, and the warning says that the entry was left. This holds at the root and for a project below it. The exception is a decline for a reason that leaves an entry without effect (maven_bazel_no_effect): the patch is then not applied, and the warning says that the Bazel build keeps the upstream jar.
  • Declined, and the block holds the entry of another patch of the jar: that entry stays, the warning names its patch id, and the event is the one of the same run without the hub.
  • rollback / remove: the entry goes. list shows the pin with MODULE.bazel as its file. vex attests it while a pinned hub fetches that version and no rc file of the checkout switches the entry off, on any line, or cannot be read.
  • A version bump of a patched artifact: the relock passes; then Bazel stops at the entry's override_repo( line until socket-patch rollback <purl> has run. vex attests nothing for such an entry.
  • maven_bazel_hub_unpatched: a hosted run no longer gives it. Vendored and agent runs still do, with a text that names the hosted command, and not for a jar the block patches.
  • Vendored runs leave the block alone. vendor, scan / get --mode vendored and vendor --revert take over the other files of a hosted pin (a pom.xml, a Gradle build) and leave its entry in the block as it is, so the Bazel build keeps the patched jar; rollback and remove take the entry out. Without this, a vendor beside such an entry exited 0, took the entry out and said only that the Bazel build "stays unpatched" (seen in a run against a loopback stand-in of the API).

What does not change

  • A project in no Bazel workspace: nothing is read beyond the lookup of a workspace file, and output and written files are byte for byte those of the base.
  • A Maven project beside a Bazel workspace whose hubs do not hold the artifact at the patch's version: the same.
  • A patch of a jar with a classifier, or of another packaging than jar: the same, also when a patch of the plain jar of the same artifact is in the same run. A lock names the plain jar by group and artifact alone, so such a patch is not looked at for the hub.
  • --global. Vendored and agent mode patch no hub, as before; apart from the notice's text and the block they leave in place, they are the runs they were. list, rollback, remove and vex read the block whatever mode wrote the rest.

After the merge with main

main was merged into this branch through the stack below it, with no textual conflict. Between the two bases main changed hosted Maven pinning and its undo: reactors and ${property} versions (#2114), the mirror gate (#2135) and the Trusted Checksums line (#2145). One thing broke, and one commit on top of the merge fixes it.

What broke. rollback of a patch that a hosted run had pinned in pom.xml and in the block took the entry out of MODULE.bazel and left pom.xml and the two .mvn files pinned. It exited 0 and reported the patch as rolled back. The hosted get still pinned both.

Why. A hosted pin is one patch of one package in every file that wires it. Each file format has its own restorer, which is handed the pins that have a file of its format. #2114 turned the Maven restorer from a loop over its files into a loop over its pins, and took every file of a pin for one of its poms. A pin with a file that the Maven restorer was not handed, here MODULE.bazel, was passed over without a refusal. The restorer of the other file took its part out, so the run called the pin restored.

This is not particular to Bazel. On main today, a checkout that sbt builds beside Maven holds a patch in socket-patch.sbt and in pom.xml, and its rollback leaves the pom pinned in the same way. A new unit test shows that on the existing sbt/redirect/pom-also-present fixture, with no Bazel file in it.

The fix is in a file this pull request did not touch before, crates/socket-patch-core/src/patch/redirect/upstream/maven.rs (one more implementation line): the poms of a pin are those of its files that the Maven restorer was handed. Every other file of the pin belongs to the restorer of its own format. A pin that only poms hold is read exactly as before, so what #2114 holds for a reactor stands: a pin is restored in every pom that carries part of it or in none, and a pom that cannot be read refuses it. The existing tests of the Maven undo pass unedited. The same line fixes the sbt case on main.

What else was checked, because a clean merge says nothing about behaviour. Each row is now held by a test without Bazel:

Beside a pinned hub Result
A reactor: the pin in the module that selects the version, the repository in the root pom One run pins both builds. list shows one pin with MODULE.bazel, app/pom.xml and pom.xml; vex states it once; a second run writes nothing; rollback leaves the tree byte for byte as it was.
A version that a property sets The same, with the property pinned.
A mirror in the machine's Maven settings that would take the Socket repository The pom gets no pin and the run warns redirect_maven_mirror_captures_repository, as on main. The hub still gets its block, because Bazel fetches the jar of an entry by its URL and through no Maven mirror. The patch is applied, and the pin is the block's alone. Without a pom.xml no Maven settings are read, and the run is the one it was.
vendor after a hosted run pinned the poms of a reactor and the block vendor takes the poms' part of the pin over and leaves the entry, and so does vendor --revert. Events, warnings and every other file are those of the same run without the workspace.

Read, and unchanged: where the hub decides a patch, "no pom.xml" is still not said of it; the Trusted Checksums files are written with a Maven pin beside the block and go with it in the undo; the respelling of an earlier release's .mvn/maven.config touches that file alone; the sbt, Gradle and Bazel restorers each take only their own file.

One thing to know. In the mirror row the run reports applied because of the hub's entry, while the text of main's warning ends "the dep is not counted as redirected", which is said of the Maven build. vex then attests the patch by the hub's entry although the Maven build of the same checkout is unpatched on that machine. This is the mirror image of the pom.xml-only case under "Not covered", and it follows from the rule here that a hub's entry confirms a patch whatever another build of the checkout took.

Checked at the new head, on one macOS arm64 machine:

  • The unit suite of the core crate (8,178 tests), the Maven, Gradle, sbt, vendor, rollback and vex test targets, the three targets that main's Maven changes touched (in_process_scan, scan_rollout_e2e, common_selftests), clippy with -D warnings and cargo check of every target all pass.
  • Real Bazel passes on 9.3.2, 8.8.2, 7.7.2 and 7.4.0: four flows each, 508 requests behind the logging proxy, none to a public Maven host.
  • Three single changes of the product each fail a named test: the fix taken out (the two new unit tests and the two tests of the undo in e2e_bazel_maven_beside, and nothing else in the core unit suite); the hub standing back behind a mirror (the mirror row); a vendored run taking nothing over of a pin that the block holds too (the new vendor case).
  • Not run: CI and Windows at this head, and main's real-Maven tests in e2e_redirect_maven_build, which need Maven Central.

Code review

The third commit applies a code review of the second. One bullet per finding:

  • Two patches of the same coordinates in one run. The verdicts of a run were looked up by group, artifact and version, so beside a patch of the plain jar, a patch of a jar with a classifier could take the plain jar's entry or be reported as pinned by the hub. Fixed: one function names the patches a hub can take, from the purl of each, and a verdict belongs to one patch id. A unit test runs both patches in both orders.
  • vex attested an entry that an rc file switches off. Only the first thing the rc reading met was looked at, so an rc file that cannot be read, or an earlier option about downloads, hid a later --noenable_bzlmod. Fixed: every line is read; an option that switches the entry off, on any line, and an rc file that cannot be read withhold the statement, and the diagnostic names the reason. An option about downloads alone still attests: such a build takes the patched jar or fails.
  • A run below the Bazel root said "keeps the upstream jar" when the root's block already held the patch. Fixed: the root's block is read for such a project too; the run reports applied and says that the entry at the root was left, as the same case at the root does.
  • A decline beside the entry of another patch said "keeps the upstream jar". Fixed: the warning names that patch and says that its entry remains. It adds "where the block is in effect", because the decline may be about an rc file that switches the block off.
  • A root that pins the ruleset lower was declined for ever. Any bazel_dep version above the lock's was taken for a stale lock, also under a single_version_override, and a version of three numbers took the same branch; an override that replaces the ruleset's source got the advice to build once. Fixed as described under "When it is written" and in the maven_bazel_release row.
  • Options that Bazel reads and socket-patch did not see. Option names were matched against the blank-separated words of each physical line. Fixed: lines are joined and words are read as Bazel reads them; what Bazel's own source calls an oversight (a quote that is never closed, a backslash that nothing follows) makes the file one that cannot be read. As a result an option behind a # no longer counts, and an import whose path is quoted is followed.
  • Decline codes chosen by the wording of a message. The kind of a doubt is now a value beside its text, and the hub's name a field. The pom rewriter asks whether a hub decides a patch before it says "no pom.xml"; the hub lane no longer takes that warning back by its code. Every message is byte for byte what it was. Cost: about 24 code lines.
  • Three copies of how a Maven patch's group and artifact are derived. One function now, used by the pom rewriter and the hub lane. No behaviour change; the Maven redirect tests pass unedited.
  • A second rule for the line break of a file with both. The block now uses the helper the other writers that keep CRLF use (the more frequent line break). The undo holds byte for byte for every file shape of the unit test.
  • The hubs of a workspace are read again in each discovery. Left as it is, with a measurement: beside a 4.9 MiB lock, in a debug build, a hosted get reads the hubs twice (66 to 91 ms in all of a 102 to 152 ms run) and scan, list, vex and rollback once each (32 to 45 ms). Nearly all of a read is the JSON parse of the lock. Sharing that parse inside a run needs process-wide state keyed by the lock's content, about 15 code lines, to save one parse per get.

A fourth commit corrects one thing the review's changes left: a run that declined for a jar whose entry was already in the block reported the patch as applied whatever the reason. For maven_bazel_no_effect (an rc file that switches the block off, a maven.override of the jar) the entry is there and the Bazel build takes the upstream jar, so such a run no longer reports applied, and its warning ends "and while that stands the entry has no effect: the Bazel build keeps the upstream jar". A unit test holds both endings.

Contents and sizes

23 files, +4,837 −348 against the base, after the merge with main (first commit: 6 files, +260 −55; second: 18 files, +3,719 −325; third: 9 files, +1,035 −438; the commit after the merge: 4 files, +286 −18).

Part Files Lines
Implementation bazel/maven.rs (the block, the conditions, the lane, what discovery reads), bazel/rc.rs (MODULE.bazel.lock, rc files), hosted/engine.rs, patch/redirect/mod.rs, patch/redirect/upstream/bazel_maven.rs, vex/discover/bazel_maven.rs, two mod.rs, commands/vendor.rs, and patch/redirect/upstream/maven.rs (the fix after the merge) +1,352 −63 outside cfg(test) items; 909 code lines by scripts/loc-budget.py (the third commit: 75; the commit after the merge: 1)
Unit tests in the same files +1,851 −6
CLI tests e2e_bazel_build/maven.rs, e2e_bazel_maven_beside.rs, vendor_jvm_cli.rs +1,416 −210
Fixture three MODULE.bazel, reformatted to what bazel mod tidy keeps +27 −6
Docs docs/ecosystems.md, CLI_CONTRACT.md +159 −48
Workflow, scripts bazel-maven.yml, bazel-pins.txt, loc-budget.json +32 −15

scripts/loc-budget.json: bazel 1459 → 2234. lock-readers and lock-writers grow by 48 and 76 code lines; both were over their caps before, and the caps are not touched.

What it proves, and where

Real Bazel, four flows on each release, macOS arm64, at the head after the merge with main:

Bazel rules_jvm_external Result Seconds per flow (tree only Bazel builds, pom beside the hub, the user's override, version bump) Requests to a public Maven host
9.3.2 7.2 4 pass 76.3, 65.9, 19.1, 23.5 (empty repository cache) 0 of 173
8.8.2 6.9 4 pass 72.9, 57.6, 16.0, 21.2 (empty repository cache) 0 of 113
7.7.2 6.5 4 pass 69.8, 56.3, 16.9, 21.4 (empty repository cache) 0 of 128
7.4.0 6.5 4 pass 51.0, 28.4, 43.9, 73.7 (the cache of 7.7.2) 0 of 94

The flows hold:

  • the block's exact text in MODULE.bazel;
  • the same build prints the marker of the patched jar, with this run's id, fetched from the patch host;
  • a --lockfile_mode=error build passes; the ruleset's relock leaves the lock as it is; bazel mod tidy leaves the file as it is;
  • rollback restores every file byte for byte, and the upstream build;
  • a second machine whose patch host serves other bytes fails with "Checksum was … but wanted …" and does not go to the upstream jar;
  • after a bump to 1.11.0 the build stops at MODULE.bazel:46, the entry's line, until rollback <purl>;
  • a hub with the user's own maven.override is declined and builds as before;
  • on 7.4.0, a checkout without .bazelversion is declined until it has one.

With a binary of the base's product code all four flows fail on 9.3.2 (run on the second commit; not repeated on the third).

Without Bazel:

  • one row per decline and its text, with each spelling Bazel reads as "off", each kind of rc import, each override of the ruleset, and versions of two and three numbers;
  • the rc tokenizer, row by row under the line of Bazel's source it rests on: blanks, comments, quotes, escapes, joined lines, and the two shapes that are not read;
  • the block added, added again and taken out over nine file shapes (LF, CRLF, both in one file; with and without a last line break; blank lines at the end);
  • the reader with and without the block, and with a block whose first line was touched;
  • two patches of the same coordinates in one run, in both orders, and what a decline says of the block at the root and below it;
  • discovery, the restore, and the CLI end to end: the pin and its undo, also in a reactor, through a property and behind a Maven mirror; each decline, a decline beside an entry of an earlier run, a run below the root beside the root's entry, a decline beside another patch's entry, a block changed by hand under rollback and list, a patch of a classifier jar, vendor and vendor --revert beside an entry, also one whose patch the poms of a reactor hold too.

Each finding of the code review was first shown by a test that failed on the second commit: five unit tests and two CLI tests.

Single changes of the product, each of which fails a named test: three for the commit after the merge with main, run on its head (see "After the merge with main"); 22 for the third commit, run on the head before that merge, one per new or changed check (the plain-jar test, a verdict per patch id, every rc line for vex, an unreadable rc file, the root's block below the root, the other patch's entry, a pinned release, the version order, each kind of override, joined lines, quotes, escapes, comments, an open quote, the blanks around a line, %workspace%//, the kind of a doubt, the hub's name, the pom lane, the line break of a file with both). Before them: 16 for an earlier review and 41 during development, which were not repeated on the final head.

Do no harm, measured on the head before the merge with main against a binary of the base, and not repeated after it: 272 runs over 8 checkouts (no Bazel file, another ruleset's hub, a pinned hub that holds the artifact at another version; each with a pom.xml, without one, and two with a Gradle build) of hosted get in JSON, human and dry-run form, list, vex, scan, rollback, remove, apply, vendor, vendor --check, vendor --revert and scan --mode vendored. 269 are byte for byte equal in stdout, stderr, exit code and written files; the other three differ only in the random id and the time of the VEX document. The vendor runs of that comparison end in the same refusal on both binaries; a vendor that succeeds beside a workspace is held by the two hub tests of vendor_jvm_cli.rs.

Three existing expectations changed in the second commit, all because of the behaviour above: a hosted run beside a hub it cannot patch gives the decline's code in the place of maven_bazel_hub_unpatched; a tree only Bazel builds gives that code alone, without "no pom.xml" (that test is renamed); the text of maven_bazel_hub_unpatched in three tests. The third commit changes expectations of the second commit's own unit tests only: an option behind a # is no longer found; a quoted import, and one joined over a line break, are followed where they were refused; a quoted option is named without its quotes; a decline beside another patch's entry names it; and "no pom.xml" is held at the pom rewriter, not at the hub lane.

What starts on main

  • bazel-maven.yml gets a fourth Linux leg: Bazel 7.4.0 with the fixture era of Bazel 7. 7.4.0 is the first release with override_repo, so the oldest Bazel the change accepts is one CI builds. Its two digests in scripts/bazel-pins.txt are from the release's published .sha256 files.
  • The new leg shares the repository cache of the 7.7.2 leg. Cold caches measured here: 404 MB (9.3.2), 352 MB (8.8.2), 333 MB (7.7.2); the 7.4.0 leg added 1 MB to the cache of 7.7.2.
  • No leg asks a public Maven repository. Every run here was behind a logging proxy that refuses such hosts: 508 requests over the four legs of the head after the merge with main, none refused (the Bazel registry, GitHub, Bazel's mirror, the JDK's CDN and, on Bazel 9, go.dev). The patched jar comes from the test's loopback server, to which a downloader config on Bazel's command line sends the patch host.
  • On Linux, on GitHub's runners, the four Maven legs of this pull request pass at its head, after the merge with main and the fix: Bazel 9.3.2 in 178 seconds, 8.8.2 in 156, 7.7.2 in 149 and 7.4.0 in 159, with the other checks (110 in all). The local runs were on one macOS arm64 machine.
  • On Windows the real-Bazel tests do not run (they are Unix-only). The tests without Bazel passed there before the merge with main (the unit tests of bazel::maven and bazel::rc and what were then the thirteen tests of e2e_bazel_maven_beside; the tests added after the merge have not run on Windows), in a run of the workspace tests started by dispatch on this branch (run 44571237392). That run is red for one other test, scan_project_discovery_e2e::agent_scan_names_a_python_project_below_with_its_own_venv, in a file this pull request does not touch: it builds a virtualenv with the Unix layout.

Not covered

  • scan does not find the artifacts of a hub. It pins a hub's jar only for a package it found elsewhere (a pom.xml, a Gradle build). It does not take a stale entry out; rollback and remove do.
  • Vendored and agent mode patch no hub. After a vendored takeover beside a hub entry the package is vendored for Maven or Gradle and hosted for Bazel.
  • A hub without a lock, a maven_install of a WORKSPACE file, Bazel before 7.4.0, rules_jvm_external before 6.4 or after 7.2, a ruleset that an override takes from outside a registry: declined with a reason. A patch of a jar with a classifier or of another packaging: not looked at, and nothing is said of the hub.
  • A single_version_override that patches the ruleset (patches, patch_cmds) is taken as the release it names. If such a patch changes how the ruleset names a jar's repository, Bazel stops at the entry.
  • vex still attests a patch that only a pom.xml pin carries, although the Bazel build beside it is unpatched.
  • A hub or an override that another Bazel module declares, the command line (also --override_module), the rc files of the machine and of the home directory, and an rc file imported by an absolute path are not seen.
  • The rules for rc files, for the ruleset's overrides and for versions are held without Bazel (unit rows, and Bazel's sources read at four tags), not by a Bazel build.
  • maven_bazel_download names no remedy: while an rc file of the checkout gives one of those options no entry is written, whatever the downloader config allows.
  • For a block that was changed by hand, the warning of a hosted run still ends "the Bazel build keeps the upstream jar", although what such a block does for the build is not known. rollback, remove and list give the shared hosted_wiring_contested text, whose first advice (scan --mode hosted) does nothing here; the second (git checkout -- MODULE.bazel) is the remedy. The shared text is not changed.
  • A scanner that reads only maven_install.json keeps reporting the advisory: the lock names the upstream version on purpose.
  • The human "Next steps" after a hosted run still say "Reinstall from the updated lockfile"; for Bazel the next build is enough.
  • The hubs of a workspace are read once per discovery, so twice in a hosted get (measured under "Code review").

What follows

  1. scan finds the artifacts a pinned hub builds, and takes a stale entry out.
  2. VEX: withhold the statement of a patch that a hub builds unpatched.
  3. Vendored mode: a committed jar behind the same block.
  4. Agent mode.

Decisions for the owner

Appending a block to MODULE.bazel was decided ("great, do it"). These are taken as recommended, and each can still be overruled:

  1. A version bump of a patched artifact stops the build until socket-patch runs. Taken. The other choice is not to patch pinned hubs at all: nothing softer was found that is not silent.
  2. A build that cannot be shown safe from the checkout is declined, also where it would probably work. Taken, with one narrowing: enable_bzlmod switched on is accepted. The other choice trusts the bazel_dep version and only warns about rc files.
  3. Agent mode will use the vendored form. Not in this pull request: agent and vendored runs patch no hub yet and say so. The other choice is a decline that names vendored mode.
  4. The committed URL holds the patch's token, as a hosted pin in pom.xml does. Taken. The other choice is to wait for vendored mode.
  5. A patch that a hub builds unpatched still counts as applied when a pom or Gradle build took it, with the warning. Taken. The other choice reports skipped, which changes a contract for projects that pass today.
  6. The lock keeps naming the upstream version. Taken: the patch shows in MODULE.bazel and in vex. The other choice edits the lock, which the next relock undoes in silence.
  7. Hubs without a lock and WORKSPACE hubs are declined, not built. Taken. The other choice builds them by routes that were measured to be unsafe.
  8. A Bazel 7.4.0 leg. Taken. The other choice leaves the floor untested in CI.

Further choices made here:

  • The comment in the block names socket-patch rollback <purl>, not socket-patch scan, because scan does not take a stale entry out yet. The comment is part of how the block is recognised, so a later change of its wording must keep reading this one.
  • A hub without a lock beside the pinned hub that holds the jar declines. The other choice writes the block and names the other hub.
  • A block that was changed by hand makes rollback, remove and list refuse for the project until the file is restored, as other hosted wiring that cannot be attributed does.
  • A vendored takeover leaves the hub's entry hosted. The other choice takes the entry out and warns that the Bazel build lost its patch.
  • A patch of a classifier jar is not looked at for the hub. The other choice is a decline with maven_bazel_artifact, which needs the classifier entries of the lock read.
  • A decline for a patch whose entry is already in the block reports applied and leaves the entry, at the root and below it. The other choice reports skipped, as before, though the pin is there. One case of it deserves a look: when the decline is about an rc file that switches the block off, the run says applied with that warning while the build takes the upstream jar; vex attests nothing then.
  • For vex, an rc option under which the download of the patched jar may fail does not withhold the statement: such a build takes the patched jar or fails. The other choice withholds it for every rc finding.
  • A single_version_override that patches the ruleset is accepted. The other choice declines it, which turns away every checkout that patches rules_jvm_external.

Generated by Claude Code

`scan --mode vendored` and agent mode (`scan --mode agent`, `apply`)
patch a Go module by keeping a patched copy of it in the checkout, under
`.socket/vendor/golang` or `.socket/go-patches`, and pointing `go.mod`
at it with a directory `replace`. Only the hosted flow had a test on a
real Bazel. This adds the two other modes for the same gazelle `go_deps`
workspace, on Bazel 9.3.2, 8.8.2 and 7.7.2, and records what the code
does there today.

The next build is patched in both modes, and the undo is clean
(`vendor --revert`) or leaves only the emptied `.socket/manifest.json`
(`rollback`). The user's next step breaks the build:

- `bazel run //:gazelle` writes a BUILD.bazel into the copy. gazelle's
  `go_deps` copies the directory with that file, and every target that
  uses the module fails to load:
  `No repository visible as '@rules_go'`.
- When the module ships a BUILD file of its own, `bazel build //...`
  fails right after the command: the copy is a package of the checkout
  whose load of `@io_bazel_rules_go` nothing maps.

Each test asserts that break by its error, so that the commit that
fixes it has to change the expectation.

The fixture gains a `gazelle` target, and its BUILD file is now the one
gazelle writes, so a gazelle run on the unpatched checkout changes
nothing and what a later run writes comes from the patch. Agent mode
copies the module from the user's module cache; the test lays that
directory out itself, so the runner needs no Go toolchain beyond the one
rules_go downloads. gazelle is built from Go modules of its own: a flow
that runs it has proxy.golang.org last in its GOPROXY list, after the
stand-in that serves the module under test.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Vendored and agent mode patch a Go module by keeping a copy of it under
the project's `.socket` directory and pointing `go.mod` at it with a
directory `replace`. In a Bazel workspace that copy is a directory
Bazel and gazelle walk like any other. The next build is patched, and
then the user's ordinary steps break it, on Bazel 9.3.2, 8.8.2 and
7.7.2 with gazelle's `go_deps`:

- `bazel run //:gazelle` writes a BUILD.bazel into the copy, `go_deps`
  copies the directory with it, and every target that uses the module
  fails to load (`No repository visible as '@rules_go'`);
- when the module ships a BUILD file of its own, `bazel build //...`
  fails right after the command.

One line in the `.bazelignore` at the root of the workspace prevents
both, and socket-patch now writes it. This is the first Bazel file
socket-patch writes.

Where it applies

A project is in a Bazel workspace when its directory, or one above it
up to the root of its git checkout, holds a regular file `MODULE.bazel`,
`REPO.bazel`, `WORKSPACE` or `WORKSPACE.bazel`. Those are the names
Bazel's client looks for from the working directory up
(`WorkspaceLayout::InWorkspace`, src/main/cpp/workspace_layout.cc line
36 at the tags 7.7.2, 8.8.2 and 9.3.2). The nearest such directory is
the Bazel root; a directory of that name does not count. Without such a
file nothing is read or written, and the run writes the same files as
before, byte for byte.

The checkout is the one `repo_root::find_git_repo` finds, and it
counts only when its `.git` belongs to a trusted owner
(`GitRepo::trusted`: the user, root, or the user sudo ran for; a root
process trusts any), which is the rule the `socket.yml` lookup has for
the repository root. Without it, another user's `/tmp/.git` and
`/tmp/MODULE.bazel` on a shared machine would make a command in
`/tmp/job/proj` create `/tmp/.bazelignore`. A project in no such
checkout (a Docker build context, an unpacked source archive, a
checkout of another user) is looked for in its own directory only:
nothing above it is read, so a workspace file there gives no line and
no warning. Neither does a Bazel root above the root of the checkout (a
git submodule, several checkouts below one workspace): this repository
reads no project file outside the checkout, so a look there could see
the workspace file and not whether the line is in place, and its
warning would never end.

The nearest directory with a workspace file is the root. In a workspace
that is nested in a larger one the line is therefore in the inner file,
which a run from the outer workspace does not read. Measured on Bazel
9.3.2 with gazelle 0.54.0, outside the committed tests: from the outer
root `bazel build //...` loads the packages of the inner tree, a BUILD
file in the copy among them, and `bazel run //:gazelle` writes a
BUILD.bazel into the copy, after which the inner build fails as above;
with the line in the outer file, by its path from the outer root,
neither happens. The writes are not widened for that. The docs name
these limits and the line to add by hand.

What is written

- While `<project>/.socket/vendor/golang` or
  `<project>/.socket/go-patches` exists, the root's `.bazelignore`
  names it by its path from the root, on a line of its own under the
  comment line `# socket-patch: patched Go module copies, not Bazel
  packages (to opt out, comment out the next line)`. The pair is added
  at the end of the file, in the file's line breaks, and the file is
  created when missing. Never `.socket` alone: other things live there.
- Nothing is added when a line already covers the directory: the path
  or a directory above it, with or without a trailing `/` or a leading
  `./`. Bazel reads a line literally, so a line with a blank before or
  after it, a pattern or a string prefix covers nothing.
- Nothing is added either when the user declined the pair: the comment
  line with the path line commented out under it (`#`, blanks, the
  path, which may end in one `/` or start with `./` as in a line that
  covers). No command adds a line for that directory, warns about it or
  touches the two lines again, on removal either. Deleting the pair is
  no opt-out: the next command writes it back. Neither is commenting
  out both lines, or a path line changed in another way.
- socket-patch knows its pair by the start of the comment line,
  `# socket-patch:`, not by the whole sentence: a path line under a
  line that starts so is its own, and that path line commented out is
  the opt-out. A later release can reword the comment without leaving
  the pairs of this one behind.
- Only a directory that is not found is gone. One that cannot be probed
  (a directory above it that may not be searched, a transient error)
  keeps its pair, and gets none.
- Once the directory is gone the pair is removed, and the file is the
  one of before, byte for byte. A file whose last line has no line
  break gets a line break and the pair without a final one, and loses
  that line break again with the pair: exactly the one the comment line
  ends in, which is the one that was written before it, so that a last
  byte that is a carriage return on its own stays. Bazel and gazelle
  honour a last line without a line break: the agent test on real Bazel
  has one.
  A file left empty is deleted, an empty one the user had included:
  it cannot be told from one socket-patch created. Only a line under
  such a comment line is ever removed.
- The line follows the directory, not the `replace`:
  `rollback --preserve-state` drops the `replace` and keeps the
  vendored copy, whose BUILD files would be back in the workspace
  without the line.
- A read-only file is neither replaced nor deleted. The file is opened
  for appending before any change, a removal included, because a
  rename or an unlink succeeds in a writable directory.
- A file that is not updated is the new warning
  `bazelignore_not_updated`: it could not be read or written (a
  directory or a symbolic link in its place, a read-only directory, a
  read-only file). The detail names the line to add, or says that the
  lines of a copy that is gone can be deleted. The command succeeds as
  before.
- A human run reads `Updated <path>` or `Removed <path>` on stdout when
  the file changed, once for each file, in words that hold for lines
  that came and for lines that went, and the warning on stderr. Under
  `--json` the warning is a run-level `warnings[]` entry; there is no
  new field.

Which commands

`commands::sync_bazelignore` is the one place the CLI asks for the
file, behind one gate: not in a dry run and not in a `--global` run.
Each command that can write or remove a copy calls it once, after its
last step that can change a copy or take one back: `apply` (and with
it `scan --mode agent` and `get`), the vendored step of `scan` and
`get`, `vendor`, `vendor --revert`, `rollback`, `remove`, `repair`
(also when it failed), and a hosted scan that took the lock, since a
takeover removes the vendored copy. A hosted scan that took no lock may
write nothing (`patches.enabled: false` in `socket.yml`, a rollout cap,
no granted reference) and leaves this file alone too. The eject of a
hosted project calls it after its rollback, so that an eject which
vendored the Go module and was then rolled back leaves no pair for a
copy that is gone again. `apply` and `vendor` in a project with no
manifest end before that step.

A run whose `--ecosystems` leaves `golang` out adds no line. It still
takes away the pair of a copy that is gone, because `remove` of a Go
patch and `vendor --revert` remove the Go copy whatever that option
says.

With a `--manifest-path` into another project the agent copies are
those of `--cwd` and the vendored ones those of the manifest's project,
so the helper brings the file of each project's Bazel root in line.

`scan --prune` comes to the file a second time, after a pass that
reverted a vendored entry or swept an orphan directory, which can
remove the last copy after the scan's own step. That second call only
takes a pair away: it adds no line and gives no warning, so the run
warns once and no state is kept between the two. What it costs: a
warning the scan's own step gave for a copy the pass then removed is
out of date, and a file the pass cannot write is reported by the next
command. The scan's own call cannot be left to that pass instead: the
pass also follows the nested apply of `scan --mode agent --prune`, and
it does not run at all when it cannot take the apply lock.

The file is written after the commands' group commits, outside them:
it is no part of a commit journal. A run that dies in between leaves a
copy without its line, which the next command adds; a command that
fails after it removed a copy can leave the pair behind, which ignores
nothing, until the next command.

A file several projects share

Two projects under one Bazel root share the file, and each command
holds only its own project's apply lock. So the edit, from its read to
its write, is made under an advisory lock on the root directory itself:
`fs2` on a handle to the directory, with contention told as the apply
lock tells it (`apply_lock::is_lock_contended`). No lock file is made,
in the workspace or anywhere else. A run that finds nothing to change
takes no lock, also when the file cannot be read and the project has no
copy to name in it. Where the directory cannot be locked (Windows, where
it cannot be opened this way; a file system without such locks), or the
lock stays held for a second, the edit is made without it: an add is
still one appending write, which keeps what another project adds at that
moment, and a removal replaces the file and can then lose such a pair
until the next command in that project. With the lock, a removal in one
project against an add in its sibling keeps the added pair in every one
of 25 rounds of a unit test, which asserts that half on Unix only;
without the lock that test fails.

What a run costs

The Bazel root and the bound of the checkout come from one walk up
(`search_dirs`), which runs with the rest of the edit on the blocking
pool. For a project outside a Bazel workspace, `d` directories below
the root of its checkout, that is 2 path canonicalisations, `d + 2`
stats of `.git` and `4 (d + 1)` stats of the four names, and nothing
else. In a Bazel workspace it adds two stats of the copy directories
and one read of `.bazelignore`; the lock and the write come only when
something changes. (Counted from the code, not traced.)

A side effect

The line does more than keep gazelle out. Bazel leaves an ignored
directory out of every `glob()` of a package above it (9.3.2, 8.8.2 and
7.7.2), so a target that hands the project's Go files to a `go` command
of its own through such a glob no longer receives the copies. Built on
Bazel 9.3.2 with a genrule that runs the Go SDK's `go build` over
`glob(["**/*.go", "**/go.mod", "**/go.sum"])`, outside the committed
tests: without the line it builds patched until the first
`bazel run //:gazelle`, whose BUILD file in the copy takes the copy out
of the glob in the same way, and then fails (`replacement directory
./.socket/vendor/golang/... does not exist`) together with every
rules_go target that uses the module. With the line the rules_go
targets build, and that genrule fails with the same error from the
start; it builds when it names the copy's files as labels beside the
glob, or runs outside the sandbox. A workspace that has such a target
and never runs gazelle can decline the line as above.

Not covered

Only Go module copies get a line. Other ecosystems keep unpacked
packages under `.socket/vendor/<ecosystem>` too (a crate can ship a
BUILD.bazel); nothing was measured for them under Bazel, so nothing is
written for them. A BUILD file that gazelle wrote into a copy before
the line existed stays there: the next `scan --mode vendored` rebuilds
the copy, and in agent mode the BUILD files under `.socket/go-patches`
have to be deleted by hand. A project directory whose path from the
root starts with `#` or white space, or holds `*`, `?` or `[`, cannot
be named in `.bazelignore`: its line is written, and Bazel or gazelle
does not honour it. `ignore_directories` in REPO.bazel is not read; a
workspace that has it gets the line too.

Tests

The real-Bazel tests now assert the fixed outcome: the build prints
the patched marker after the command and `bazel build //...` passes,
the two tests of a module without a BUILD file build it again after
`bazel run //:gazelle`, which writes nothing, and the undo takes the
line away. The agent test starts from a `.bazelignore` of the user's
whose last line has no line break, and ends with that file as it was.

Tests without Bazel hold: the root finder (each of the four names, a
directory of such a name, a link, a file above the checkout, a checkout
of an owner that is not trusted and a project in no checkout, which
both reach no further than the project); the line rules (what covers,
the opt-out and what is none, a pair under another wording of the
comment, the pair in LF and CRLF files and after a last line without a
line break, the removal that leaves the file of before, a last
carriage return included, a run that leaves Go out); the write
(appended to the file that is there, a read-only file and a link left
alone on an add and on a removal, a copy directory that cannot be
probed, the lock on the root directory and none where nothing can
change); two edits at once; and through the built binary each
command's call: that a dry run of ten commands writes nothing in either
mode, that a declined pair stays declined over scan, repair, apply,
rollback and revert, that a rolled-back eject leaves the project as it
was, that a prune pass and a hosted takeover take the line away with
the last copy, that `--ecosystems npm` adds no line and takes the pair
of a copy it removed away, that a scan which `socket.yml` lets write
nothing leaves the file alone in every mode, that a manifest in another
project brings both files in line, that a file which cannot be written
is one warning for each command (in the envelope, and on stderr for a
scan whose prune pass comes to the file a second time), what a human
run prints for lines that came, lines that went and a file that went,
that a project in no git checkout below a Bazel root gets no line and
no warning, and that the same run in a project with no Bazel workspace
file writes the same files, byte for byte but for the time in a
vendored copy's marker, and no `.bazelignore`. No test depends on what
lies above the temp directory: they pass with it inside a git checkout
and outside one.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
`vex` and `--vex` read what socket-patch wrote and what the project's
package manager installed. They read no Bazel file, so under Bazel a
document can say `not_affected` for a package Bazel builds unpatched.
Before the product learns to tell, this records where the document and
the build agree today. It changes tests, one docs section and four
workflow path lists; no file under `crates/*/src`.

Each of the eight real-Bazel flows whose build is patched (Go hosted,
vendored, agent, and vendored with a module that ships a BUILD file; npm
hosted and vendored; PyPI hosted; RubyGems hosted) now also asserts:

- the command of the mode, given `--vex`, writes the document of its own
  run in the checkout Bazel has built in;
- `vex` writes one before the patched build and one after it, and one
  with `--no-verify`;
- after the undo `vex` writes none and removes the last: exit 2
  `manifest_not_found`, or exit 1 `no_patches` after an agent rollback,
  which keeps its emptied manifest;
- the command and `vex` write the same two documents in a checkout that
  no Bazel has built in, whose files outside `.socket/` are those of the
  checkout that built patched.

A document is held to one statement: `not_affected`,
`inline_mitigations_already_exist`, the advisory of the record, the
package as the one subcomponent of the product, and `Patched via Socket
patch <id>` with the id of this run, ` (redirected)` or ` (vendored)`
by mode, and `; not verified on disk` exactly under `--no-verify`. The
envelope is held to its exact warnings. Agent mode's `apply --vex` and
the second scan of the npm flows are held to the same.

All of it passes on Bazel 9.3.2, 8.8.2 and 7.7.2 (macOS arm64) as the
product is: no expectation had to follow a wrong document. One thing a
reader of such a document should know is now asserted. For a hosted pin
no form hashes a file, since the bytes come with the next build and
`vex` never reads Bazel's output: the statement rests on the lock entry
and the patch record. The scan says so (`vex_hosted_unverified` in
`vex.warnings`); stand-alone `vex` gives no warning, before the build
or after it. The added socket-patch runs take 0.2 to 0.5 seconds per
flow.

`e2e_vex_lockfile/bazel_beside.rs` holds what later changes must keep.
A pnpm project in `web/`, beside a root `MODULE.bazel` or `WORKSPACE`
that builds Java and names none of its files, gets from `vex --json`,
`vex` and `apply --vex` the exit code, both streams and the document
it gets without Bazel, byte for byte but for the checkout's path, the
document id and the time, for a hosted pin and for an installed patch.
With Bazel files that do name the project's lock the output is the same
today as well (tried, not kept): that is the case later work changes.

In the harness a VEX document goes beside the workspace copy, so no
comparison of a checkout's files sees one, and `Cell::twin` is a
shutdown plus the new `Cell::unbuilt`. The push paths of the four
Bazel workflows gain `crates/socket-patch-core/src/vex/**`.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A code review of the VEX assertions in the real-Bazel flows found gaps
in what the tests hold. This closes them. It changes tests, one docs
sentence and the path lists of the four Bazel workflows; no file under
`crates/*/src`.

- The documents of a flow are compared with each other. Each one was
  checked alone, and its package through a normalising function, so the
  `%40` and the `@` spelling of an npm scope both passed and nothing
  showed that the forms write the same document. Now every document
  read in a checkout (of the run, of `vex`, of `vex --no-verify`) must
  equal the first one read there in every string but the document id,
  the timestamps and the `; not verified on disk` mark, and the
  documents of the checkout that Bazel has not built in must equal
  those of the one it has. The check of each document alone stays. The
  product spells all of it alike in all eight flows on Bazel 9.3.2,
  8.8.2 and 7.7.2: no expectation had to differ per form.
- `vex --output <file>` with no `--product`, the command a user types,
  runs once after the patched build in every flow. In the npm and the
  Go checkouts it exits 0 without a warning and writes the same
  document for the product of the project's own file, beside Bazel's
  links: `pkg:npm/socket-fixture@0.0.0` from `package.json`,
  `pkg:golang/example.com/consumer` from `go.mod`. The PyPI and the
  RubyGems fixture have no file a product is read from: there it exits
  2 with `product_undetected` and writes no document.
- The marker of a vendored copy is compared between the two checkouts
  as well, as JSON without `vendoredAt`, its one time field. The whole
  file was left out before, so a marker with another purl, patch id or
  advisory passed.
- The `; not verified on disk` mark is the constant the product
  exports, `socket_patch_core::vex::NOT_VERIFIED_SUFFIX`.
- The two hermetic tests of `e2e_vex_lockfile/bazel_beside.rs` tell
  each form the id of its document (`--doc-id`, and `--vex-doc-id` for
  `apply`) in place of rewriting the ids in what a run printed.
- `docs/ecosystems.md` says that for PyPI on Bazel 8.5 and later a
  hosted scan leaves `MODULE.bazel.lock` stale: a build with
  `--lockfile_mode=error` fails until the lock is updated and
  committed. The PyPI flow already asserts both.
- The pull request path lists of the four Bazel workflows gain
  `crates/socket-patch-core/src/vex/**` and
  `crates/socket-patch-cli/src/commands/vex*.rs`, the three files of
  the `vex` command. The flows hold exact VEX output, and the first
  commit added the core directory to the push lists only: a pull
  request that changed VEX code started no Bazel leg and could break
  all eight flows on main unseen.

One hermetic test holds the two comparisons themselves: two spellings
of a scope are two wordings, and a marker that names another package
is another tree. The fixture checks hold the two product names to the
fixtures' `package.json` and `go.mod`. Each new or changed assertion
fails under one mutation, the real-Bazel ones on Bazel 9.3.2.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Whether a patch reaches a Bazel build depends on which file the
workspace's rules read: `npm.npm_translate_lock(pnpm_lock = ...)`,
`pip.parse(requirements_lock = ..., requirements_by_platform = {...})`,
`ruby.bundle_fetch(gemfile_lock = ..., gem_checksums = {...})`,
`go_deps.from_file(go_mod = ...)`. socket-patch has no reader of Bazel
files. This adds one, as library code in
`crates/socket-patch-core/src/bazel/` beside `bazel_root`. Nothing calls
it yet and no command changes: its first caller is the VEX step that
withholds a statement for a copy Bazel does not build.

What it reads

`starlark.rs` lists every call `name(...)` and `a.b(...)` of a file, at
any depth: the callee as written, its line and bytes, and each argument,
positional, by keyword, `*` or `**`. An argument is a string literal
(either quote, tripled or raw, decoded as Bazel's lexer decodes it), a
list of strings, a dict from strings to strings or lists of strings, a
bare name, or "other". A call says whether it is a whole statement, an
argument of another call, in a comprehension; only the first says that
it runs, and once. Beside the calls it lists what each statement binds
(`x = f(...)`, `x = y`, the symbols of a `load` with their aliases) and
every other place a name stands, marked where the name may be given a
value there: a tuple target, the variable of a comprehension. A name
means what the last statement before it bound it to. That is how these
files run: Bazel allows no `if`, `for` or `def` statement and no
`lambda` in them (`DotBazelFileSyntaxChecker`, the same at 7.7.2, 8.8.2
and 9.3.2). Tokens end where Bazel's lexer ends them: a name that ends a
line and a parenthesis that starts the next are two statements, and the
`for` of `0for` is a word of its own.

`workspace.rs` reads MODULE.bazel and the files it includes, through a
view: a function from a path below the Bazel root to text, absent or
unreadable, so the same code serves a checkout on disk and files held in
memory. `disk()` is the view of a checkout and opens nothing outside the
Bazel root. `Workspace::tags(extension, tag)` returns the calls of one
tag of one module extension, with the file and line of each. An
extension is known by the module and the `.bzl` file that define it
(through the name a `bazel_dep(repo_name = ...)` gives the module, or
the root module itself), never by the name of its proxy: rules_go's
`go_sdk.from_file` and gazelle's `go_deps.from_file` take the same
`go_mod`. `Workspace::label` reads a label of a tag as Bazel does: from
the root package, whichever file the tag is written in
(`StarlarkBazelModule.create`), with the root module's own repository
name as the main repository. `include` is read by Bazel's rules
(`CompiledModuleFile.checkModuleFileSyntax`,
`ModuleFileFunction.advanceHorizon`; it exists from 7.2.0): a statement
of its own with one string that starts with `//` and ends in
`.MODULE.bazel`.

Why nothing is evaluated, and what is reported instead

To evaluate Starlark is to run the workspace's code and its rulesets'.
The reader states what the text says outright and says where it cannot,
as doubts: those of the workspace (`Workspace::doubts`), which are about
every answer, and those of one answer (`Tags::doubts`). With neither,
the calls listed are the calls of that tag which the files of a
workspace Bazel accepts can make. That is held by tests, one for each
way found so far to write a call that would not be listed, and not
proven; what Bazel is told outside the files (a flag, an override on the
command line) is not known to the reader. A doubt is:

- a file that is missing, cannot be read, is not UTF-8, is over 1 MiB,
  is reached through a path or a link that leaves the Bazel root, or
  includes itself; a 257th file, or text past 8 MiB in all;
- a string or a bracket that is never closed, which Bazel refuses too;
- an `include`, `use_extension`, `module` or `bazel_dep` whose label or
  name is not written as a plain string, or that may not run: one that
  gives a name or a file and is not a whole statement (behind `and`, in
  a conditional, in a comprehension);
- an `include` with a second argument (9.3.2 takes `dev_dependency`);
- one of those four names, `use_repo` or `inject_repo` used other than
  to call it: under such a name, `getattr` calls a tag;
- `True`, `False` or `None` where the file may give it another value:
  Bazel then reads `repo_name = None` otherwise;
- for the extension asked about, a proxy used for anything but calling
  a tag on it or as the whole first argument of `use_repo` or
  `inject_repo`. `override_repo` is such a use: it puts another
  repository in the place of one the extension makes.

A computed argument is no doubt: the call is listed and the argument is
"other", never a guess. A label can name a target of a BUILD file
instead of a file; the reader gives its path, and whether the file
exists is for the caller to ask. WORKSPACE files and the `.bzl` files
they load are not read yet; `load` bindings and labels relative to a
package are there for them, and what a name is bound to inside a
function of a `.bzl` file is not told yet.

The reader takes any bytes and panics on none. It makes one pass over
the bytes and one over the tokens, with no recursion, a name bound again
shares what it stands for, and a query looks at each call, binding and
use once, so the work grows with the size of the files. The tests hold
that with the largest file that is read in each shape that nests or
repeats, with one long symbol, call or label that many names stand for,
and with a sample file cut and altered at every byte.

Measured, outside the tree, on the 17,842 MODULE.bazel, *.MODULE.bazel,
WORKSPACE, WORKSPACE.bazel, WORKSPACE.bzlmod and .bzl files of 35
repositories (rulesets with their examples, Bazel itself, the Bazel
Central Registry): 17,841 are read and one is refused, a fixture with
an unclosed string. Of 13,664 directories with a MODULE.bazel, 13,653
are read without a doubt. The four lookups find 941
`go_deps.from_file`, 389 `npm_translate_lock`, 984 `pip.parse` and 42
`bundle_fetch` calls; a second reading of the same files with regular
expressions finds the same calls with the same string arguments in
every directory, and 66 of them were compared by eye. What a person
can read there and the reader reports as a doubt: an include through a
directory link that leaves the Bazel root (8 directories), and a
`repo_name` given as a constant (1). What it lists without a value: 18
lock arguments that are computed, each in a comprehension. The largest
of those workspaces is 55 KiB in 70 files. A workspace made to be
costly, 8 MiB of nothing but names, takes about 1 GiB for under a
second.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The reader of `MODULE.bazel` files in
`crates/socket-patch-core/src/bazel/` still has no caller. This closes
the cases where a caller would have got a certain answer that was
wrong, or a reader that held far more than its input. No command
changes.

What a reader holds is bounded

The bounds were 1 MiB for a file, 256 files and 8 MiB of text for a
workspace. That bounds the text, not the index: every call, argument
and use owns its strings and vectors. `MODULE.bazel` and seven included
files of 1 MiB of `f(a,b,c,d)` lines made a release build hold 541 MiB
of live allocations (790 MiB resident), nested `f(f(f(` 1,082 MiB, and
one `tags()` query over a proxy that is used on every line 749 MiB.

Now a file may have 131,072 tokens (`starlark::MAX_TOKENS`), and so may
the files of one workspace together: `index` refuses a file with more,
and `Workspace::read` hands each file what the ones before it left. A
file that does not fit is a doubt about every answer ("it is too large
to read with certainty ...") and takes nothing from what is left, so a
smaller file after it is still read. An index holds at most one call,
argument, binding, use or string for a token; a test asserts that for
27 shapes. Two things grew with the input beside the index and are
bounded too. A list of doubts keeps its first 1,024: a file that names
`use_repo` on every line held 180 MiB, most of it doubts. And the label
of an included file may be 4,096 bytes long, because every doubt names
the path of its file.

Measured in a release build as peak live allocations, with the resident
size in brackets, for the largest workspace of each shape that is still
read:

  calls `f(a,b,c,d)`               14.7 MiB (20.6)
  arguments `f(a,a,...)`           13.9 MiB (19.2)
  uses `a a a`                     13.4 MiB (20.8)
  bindings `a=b`                   12.3 MiB (18.3)
  nested calls `f(f(f(`            27.0 MiB (31.1)
  strings of a list                 6.9 MiB  (8.9)
  a proxy used on every line,
  with one query                   13.4 MiB (21.1)
  nested calls, and seven files
  of one 1 MiB name each           34.0 MiB (43.3)
  255 files of 32 KB of calls      10.3 MiB (15.9)

The seven-file inputs above are now refused, and take 6 to 7 MiB. The
bound is far from real files: the largest of 13,664 real workspaces has
4,669 tokens in 70 files, 28 times fewer; the largest `MODULE.bazel`
has 3,316; and the largest of 17,842 files of any kind, a 289 KB `.bzl`
file that no workspace reads yet, has 39,954.

A WORKSPACE file beside MODULE.bazel is reported

Bazel 7 takes repositories from a `WORKSPACE` file beside
`MODULE.bazel` by default, Bazel 8 under `--enable_workspace`, Bazel 9
never: the flag defaults to true at 7.7.2 and to false at 8.8.2
(`BuildLanguageOptions.java` 7.7.2:265, 8.8.2:289) and is a no-op at
9.3.2 (`BazelRulesModule.java`:880), which has no
`WorkspaceFileFunction`. The reader said nothing of that file: a
`MODULE.bazel` without a pip tag beside a `WORKSPACE` that calls
`pip_parse(requirements_lock = ...)` gave no call and no doubt.

`Workspace::read` now asks the view for the file Bazel would take:
`WORKSPACE.bzlmod`, else `WORKSPACE.bazel`, else `WORKSPACE`
(`WorkspaceFileFunction.compute` 7.7.2:124-137, 8.8.2:132-145;
`BazelSkyframeExecutorConstants.java` 7.7.2:51, 8.8.2:32). Bazel takes
the first that is a file (`ExternalPackageHelper.checkWorkspaceFile`
7.7.2:69, 8.8.2:75), so a directory of that name is passed over: a
disk that folds case has one for `workspace`. When the file holds a
call other than `workspace(...)`, `Workspace::legacy` holds its name
and its index, or why it could not be read.

It is a field of its own and no doubt, because whether Bazel reads the
file is not in these files. A caller that knows the release, from a
`.bazelversion`, can pass over it; a caller that looks for one ruleset
can see whether the file calls it; and both can tell it from a
`MODULE.bazel` that could not be read, which is a doubt whatever the
release. Without either, an answer is certain only when the field is
`None` too. The file is read with or without a `MODULE.bazel`, last,
and within the bounds of the workspace.

Of the 13,664 real workspaces 137 have such a file, 22 of them one that
defines something, and 4 of those call a rule that reads a lock or
names packages: `maven_install` twice, `go_repository`, and a gazelle
repository macro. None calls `pip_parse`, `npm_translate_lock` or
`bundle_fetch`.

Statements Bazel refuses are doubts

A call in the body of an `if`, `for` or `def` statement was listed as a
statement that runs, with no doubt: `if False:` and an indented
`pip.parse(...)` came back as a call that runs. Bazel refuses such a
`MODULE.bazel` (`DotBazelFileSyntaxChecker.java`, identical at 7.7.2,
8.8.2 and 9.3.2: `visit(DefStatement)` :120, `visit(ForStatement)`
:138, `visit(IfStatement)` :149, and `visit(LoadStatement)` :110 for a
file that may not load, which a module file is:
`CompiledModuleFile.java` 7.7.2:96, 8.8.2:111, 9.3.2:109), and the
reading rested on that alone. `starlark::File::blocks` now lists the
statements that start with one of the three words, and in a module
file each is a doubt about every answer. So is a `load`. None of the
13,787 real module files has either, so no real workspace gains a
doubt.

`disk()` reads what the run has written

A later caller writes `MODULE.bazel` and reads the workspace in the
same run. `disk()` opened files itself, so it did not see a write that
a group commit still holds in memory. It now asks the group commit
first, for a path made of plain names only, and puts what it gets
through the same size and UTF-8 checks. A file the run has removed is
absent.

`disk()` also reads one byte more than the bound of a file, and refuses
a file that has it. Before, a file that grew after its size was taken
was cut at 1 MiB and parsed as if it ended there. The root is resolved
once, when the view is made, and no longer for every file. Its doc now
says what is not guaranteed: another process that swaps a directory for
a link between the resolving of a path and its opening is not seen.

Smaller changes

- The bindings of `load` (`Bound::Loaded`) are gone: 18 code lines and
  two tests. Bazel takes no `load` in a module file, no reader used
  them, and they come back with the reader of `WORKSPACE` files that
  needs them. `load` stays a call in the index.
- `tags()` takes the `use_repo` arguments of each file from
  `Workspace::read` instead of collecting them again for every query,
  and passes over a file that does not ask for the extension.
- A file with a byte that is not UTF-8 is still refused, although Bazel
  builds one whose byte is in a comment: 0 of 17,842 real files have
  one, and the module doc now names the limit.

Checked

- 17,842 real Bazel files: 17,841 indexed, the same one refused, no
  panic. 13,664 workspaces: none gains a doubt, and the files read and
  the hub calls with every argument are the same as before in all of
  them. An independent reading by regular expressions agrees on every
  hub call.
- 161 hand-written hostile cases give the same output as before, but
  for the four new doubts of one case. 82,000 fuzz inputs: no panic,
  none over 200 ms.
- 20 mutations, at least one for each new check: each is caught by a
  named test.
- The `bazel::` unit tests are 75, from 69. The two files hold 937 code
  lines, from 888, and the cap of the `bazel` group in
  scripts/loc-budget.json follows the code: 1,131, from 1,082.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Windows refuses to open a directory with "Access is denied", so the
regular-file check after the open never ran there: a WORKSPACE.bazel
directory became a doubt instead of being passed over for WORKSPACE,
and the_checkout_on_disk_is_read_through_the_same_code failed on the
Windows test shard. Check for a directory before opening.

Assisted-by: Claude Code:claude-opus-5-5
A rules_jvm_external hub (`maven.install` with a `lock_file` in
MODULE.bazel) builds each jar that its own lock, maven_install.json,
names, at the sha256 the lock holds. It reads no pom.xml, no Gradle file
and no Maven local repository, so nothing socket-patch does for a Maven
artifact reaches a Bazel build. No test held that, and Maven had no
real-Bazel leg.

This adds Maven's module of the real-Bazel tests, its fixture and its
workflow, with two flows that assert what the code does today:

- maven::a_pom_patch_beside_a_pinned_hub: a checkout that Maven builds
  too. `get <purl> --mode hosted --yes` pins the artifact in pom.xml
  (three files), reports it applied and gives no warning. `bazel run
  //:consumer` prints the upstream marker before and after, and Bazel
  never asks for the patched jar. `rollback --yes` restores every file.
- maven::a_tree_only_bazel_builds: the same checkout without a pom.xml.
  The command writes nothing, reports the patch skipped
  (redirect_unconfirmed) and explains it with redirect_maven_no_pom, "no
  pom.xml present".

Both pass on Bazel 9.3.2 (macOS arm64) with the product code of this
commit, from empty caches; the other two releases were not run for this
commit.

The fixture, tests/fixtures/bazel/rules_jvm_external/bzlmod, has one era
per Bazel release, because the ruleset decides the format of the lock:
rules_jvm_external 7.2 on Bazel 9 (format 3), 6.9 on Bazel 8 and 6.5 on
Bazel 7 (format 2). No lock is committed. A flow writes its loopback
server into MODULE.bazel as the hub's one repository and pins with the
ruleset's own `REPIN=1 bazel run @fixture_maven//:pin`, so the lock is
the one that release writes. Cell::bazel_env is the harness's part of
it: a Bazel command with variables of its own.

No flow asks a public Maven repository, for a pin or for a build:

- The hub is named fixture_maven. A hub named maven, the default, also
  takes the artifacts that other Bazel modules of the build add to a hub
  of that name; protobuf does, in the module graph of every era. A pin
  resolves those from the repositories the root gives the hub, so such
  a fixture has to list Maven Central, and every pin of every run asks
  it, with the empty Coursier cache a test gives its pin. Nothing but
  the fixture adds to fixture_maven.
- Its one repository is the loopback server. The two artifacts are made
  by the test under the group dev.socket.fixture, which only the owner
  of socket.dev can publish to Maven Central, with an id of the run in
  the jar: Coursier resolves them from that server, the pinned lock
  holds the sha256 of this run's jar, the build takes it from that
  server, and no cache can supply a jar of the run.
- The hub named maven that protobuf still declares is never fetched.
  The ruleset's extension keeps one entry per hub name and only declares
  repositories (private/extensions/maven.bzl at 6.5, 6.9 and 7.2: it
  reads files of the workspace and of other modules, and downloads and
  runs nothing). Coursier runs in the repository rule of an unpinned hub
  (_coursier_fetch_impl in private/rules/coursier.bzl), which Bazel runs
  when a label of that repository is asked for, and neither
  `@fixture_maven//:pin` nor //:consumer asks for one of that hub.

A flow asserts that the lock its pin wrote names the two artifacts and
the loopback repository and nothing else. The test that runs without
Bazel asserts that each era's MODULE.bazel has that hub name and no
other URL. The jar under test holds one text file, which //:consumer
prints, so no class file is generated or committed.

Measured on Bazel 9.3.2, 8.8.2 and 7.7.2, each from empty caches, with
the flows of the next commit (the fixture is this one) and every child
of the tests behind a loopback proxy that logs each request and refuses
the hosts of public Maven repositories: no request to such a host on any
release, and of the repositories of the ruleset's extension Bazel
fetched the fixture's hub, its unpinned twin and the two jars only. The
proxy does see the Coursier that pins: on each release, a pin that was
given a second repository on such a host, and an artifact the loopback
server lacks, was refused there and failed.

Each era's .bazelrc names one JDK for every Java role, the one its
rules_java runs javac on, so a build takes no Java from the machine and
downloads one JDK. A cold leg on Bazel 9.3.2 downloaded 397 MB into its
repository cache: JDK 25 at 215 MB, java_tools 50 MB, the archive of
rules_kotlin (a Bazel module the ruleset depends on) 46 MB, Coursier 41
MB, a Python toolchain 18 MB, and the archives of the other modules. It
was 345 MB on 8.8.2 and 327 MB on 7.7.2. With only the run-time JDK
named it was 777 MB on 9.3.2, for three JDKs. The Coursier that pins
gets a cache directory of the test: before 7.2 the ruleset leaves the
choice to Coursier, which takes the home directory from the system, not
from HOME, and would write the developer's own cache.

bazel-maven.yml is bazel-npm.yml for Maven: its own path lists, the
nightly minute 27 5, three Linux legs and the macOS leg on 9.3.2. Era e7
starts Coursier with the Java of JAVA_HOME, else of PATH; that the
runner images have one is not known until the legs have run in CI.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…h does not reach

A pinned rules_jvm_external hub builds the jar its lock names, whatever
a pom.xml, a Gradle build or an installed jar holds. So in a checkout
that Bazel builds too, `get --mode hosted` pinned pom.xml, reported the
patch applied, and the Bazel build kept the upstream jar without a word;
in a tree that only Bazel builds, the same command explained its skip
with "no pom.xml present". The flows of the previous commit hold both.

socket-patch still does not patch a hub. From now on it says so, for
each Maven artifact of a run that a hub builds:

- maven_bazel_hub_unpatched: a pinned hub of the root MODULE.bazel
  fetches the jar at the patch's version. The warning names the lock, the
  hub and the file and line of its `maven.install`.
- maven_bazel_unreadable: whether a hub builds the jar could not be
  told. The warning names the file, the line and the reason.
  - When no hub that was read holds the jar: a hub without `lock_file`,
    tags of one hub that name different locks, a lock that is missing,
    empty, not format 2 or 3, over 16 MiB or no JSON, or the WORKSPACE
    file Bazel would take (WORKSPACE.bzlmod, else WORKSPACE.bazel, else
    WORKSPACE) when it calls `maven_install` or cannot be read, unless
    .bazeliskrc or .bazelversion names Bazel 9 or later, which reads no
    such file.
  - Whether or not a hub's lock holds the jar: a `maven.install` whose
    `name` or `lock_file` is not a plain string or that is not a
    statement of its own, and a doubt of the workspace reader. The
    ruleset takes a hub's lock from the last of its root tags, so a tag
    that was not read may change the lock of any hub, and no lock is
    named beside one.
  - When a hub's lock holds the jar: a `maven.override` of the artifact,
    which puts a target of the checkout in the jar's place, or one whose
    `coordinates` are no string. It is matched as the ruleset matches
    it, by the name of the artifact's target, for every hub.

Nothing else changes. Events, exit codes and every written file are
those of the same run without the workspace. In a hosted run of a tree
without pom.xml the warning takes the place of redirect_maven_no_pom
when a hub is named for every Maven patch of the run; otherwise both are
given. Nothing is said for a project outside a Bazel workspace, for an
artifact that no hub holds as a plain jar at that version, or under
--global, and no Bazel file is looked for in a run without a Maven
patch.

bazel/maven.rs reads the hubs (the `install` tags of the ruleset's
`maven` extension, through the workspace reader, so under any name for
the ruleset or the proxy and in included files), their locks and the
`override` tags, once per run, and bazel/rc.rs the Bazel release a
launcher is told. A hub's `name` is taken only when it is made of what a
repository name is made of, because a warning prints it. The WORKSPACE
file is the one the reader reports (Workspace::legacy); a
`maven_install` in it is a call of that name, or of the name a `load` of
the file gives the symbol. Nothing is evaluated, no Bazel is run and
nothing is written. The reader gains disk_up_to: the same view of the
checkout with a bound of the caller's, because a lock is data and can be
larger than the 1 MiB of a Starlark file. `disk` is that view at 1 MiB,
as before.

commands::bazel_maven_notices is called from three places, which cover
every command that pins or applies: the hosted flow (`get` and `scan`
with --mode hosted), VendoredBackend::apply (`vendor`, an eject, `get`
and `scan` with --mode vendored) and the apply run (`apply`, and the
agent `get` and `scan` that end in one). A vendored or agent `get` that
fails before it patches anything says what it said before, `apply` says
nothing for a patch whose package it does not find, and `vex` does not
look at the hub yet.

Tests:

- The two real-Bazel flows now expect the warning, with its exact text,
  and read the lock through Lock::parse. They pass on Bazel 9.3.2
  (rules_jvm_external 7.2, lock format 3), 8.8.2 (6.9, format 2) and
  7.7.2 (6.5, format 2), macOS arm64, each from empty caches: the build
  prints the upstream marker before and after the command, and the
  patched jar is never asked for. With the product code of the previous
  commit they fail at the warning.
- The fixture's hub has a name of its own (previous commit), so the
  flows read a lock of the fixture's two artifacts and expect the hub
  "fixture_maven" in the warning. A hub of the default name, `maven`,
  whose lock also holds an artifact that another Bazel module added to
  it, under two repositories, is what tests/e2e_bazel_maven_beside.rs
  writes for its checkouts, and the unit tests read a hub whose tag has
  no `name`.
- tests/e2e_bazel_maven_beside.rs holds "nothing else changes" without a
  Bazel: a hosted `get` and an agent `apply`, as JSON, as a person reads
  them and as a dry run, print the same bytes and write the same files
  in a checkout without a Bazel file, in one whose workspace has only
  another ruleset's hub beside a lock that holds the artifact, and in
  one whose pinned hub holds the artifact at another version. A hub that
  builds it adds exactly one warning; a tree only Bazel builds gets it
  in the place of redirect_maven_no_pom, and beside it when the hub
  cannot be read; a --global run says nothing. vendor_jvm_cli.rs has the
  same twin for `vendor`, as JSON and as a person reads it.
- Unit tests in bazel/maven.rs and bazel/rc.rs, over cut-down copies of
  the ruleset's own locks at its tags 6.9 and 7.2.

The `bazel` group of scripts/loc-budget.json goes from 1134 to 1441
lines, the code of the two new files and of disk_up_to.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The previous commit made get, scan, vendor and apply say when a pinned
rules_jvm_external hub of a Bazel workspace builds the jar of a Maven
patch. This one corrects eight things in it. No event and no exit code
changes, and a checkout without a Bazel workspace, or one whose hubs do
not hold the artifact, gets the output it got.

What a run reports

- The notice is added to a hosted run's warnings and no other warning is
  removed for it. In a tree without pom.xml the run used to drop
  `redirect_maven_no_pom` when a hub was named for every Maven patch, by
  matching the code as text and comparing counts. Now it gives both: "no
  pom.xml present" and, after it, the hub. Both are true.
- The notice no longer goes into the lock rewriters' own list. The human
  "(see the warning below)" pointer counts that list, so a package
  without a lock entry was pointed at a hub warning that does not
  explain it. The notice now joins the run's merged warnings after the
  rewriters' ones. scan/hosted.rs loses 19 lines and gains 6.
- `vendor --ecosystems npm` no longer warns about a Maven patch of the
  manifest that the run did not vendor: the notice is asked for the
  purls the run vendors, not for every record.
- A human `vendor` prints the notice above its closing summary and "Next
  steps:", not below them. The call moved from the vendored backend into
  the vendoring engine, beside the Go audit that prints the same way,
  and `bazel_maven_notices` prints for a site that asks it to (`tell`),
  never under --json or --silent. apply and hosted mode print the
  warnings of their run themselves and pass `false`. A `vendor` that is
  refused before it vendors anything (an unreadable ledger, a ledger
  that git ignores) says what it said before the notice existed.

What is read (crates/socket-patch-core/src/bazel)

- A hub is also made by `maven.artifact` and `maven.from_toml` tags
  (`private/extensions/maven.bzl` of the ruleset at 6.5, 6.9 and 7.2;
  `from_toml` from 6.9). A hub that only those tags make has no lock and
  Bazel resolves it when it builds, so a patch for an artifact now gets
  `maven_bazel_unreadable` with the tag's file and line, as a
  `maven.install` without `lock_file` does. Before, it got nothing. Such
  a tag that cannot be read is a doubt; it names no lock, so the hubs
  that were read stay. A pinned hub with such tags stays pinned.
  `override` and `amend_artifact` make no hub.
- A lock with `m2local`, in format 2 and 3: the ruleset takes a jar that
  no repository of the lock lists from the Maven local repository, at
  the lock's sha256 (`download_pinned_deps.bzl`). Such a jar now counts
  as one the hub builds. The docs no longer say that a hub reads no
  Maven local repository.
- `.bazeliskrc` and `.bazelversion` are read as bazelisk v1.30.0 reads
  them (config/config.go, core/core.go, versions/versions.go): the last
  `USE_BAZEL_VERSION` line wins, the blanks around the key and the value
  are dropped, an empty value leaves it to `.bazelversion`, whose first
  line is taken as it is written, and only three numbers name a release.
  The old reader took the first line that began `USE_BAZEL_VERSION=` and
  trimmed `.bazelversion`, so it could name Bazel 9 where bazelisk runs
  Bazel 7, and then pass over a `WORKSPACE` file that Bazel reads. The
  variable of the environment and the `.bazeliskrc` of the home
  directory are not read: socket-patch does not run in the environment
  of the build.
- `MODULE.bazel`, the files it includes, the `WORKSPACE` file and the
  two release files are read through the reader's own view of 1 MiB
  again, and only a hub's lock through the one of 16 MiB. One view
  served both, so a `MODULE.bazel` of 15 MiB was read whole before it
  was refused, and with another reason than the reader gives.

Tests

Each change failed a unit or a hermetic test before it was made, and 26
single changes to the product each fail a named test.

- bazel::maven: three new tests (the two tag classes, `m2local` in both
  lock formats, a file over 1 MiB). One existing expectation changes: in
  `a_hub_is_a_tag_of_the_rulesets_maven_extension` (renamed) the
  `artifact` tag of the fixture now makes a second hub, without a lock.
- bazel::rc: two tables, each row under the lines of bazelisk's source
  it rests on. One existing row changes: a `.bazelversion` line with
  blanks around the release names none.
- tests/e2e_bazel_maven_beside.rs: the tree without pom.xml expects both
  warnings, and one pointer above them.
- tests/vendor_jvm_cli.rs: where a human `vendor` prints the notice,
  --silent and --json, and `--ecosystems npm`.
- tests/e2e_bazel_build/maven.rs: the flow of a tree that only Bazel
  builds expects `redirect_maven_no_pom` and then the hub. Both flows
  pass on Bazel 9.3.2, 8.8.2 and 7.7.2 on macOS, and that one fails with
  the binary of the previous commit.

scripts/loc-budget.json: the cap of the bazel group follows the code,
1441 to 1459.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The tests of e2e_bazel_maven_beside.rs start socket-patch with an
environment built from nothing and hold each run to the files it wrote
in the project. A binary built for coverage writes its profile where
LLVM_PROFILE_FILE names, and without the variable into the working
directory, which is that project: in the coverage job every run then
"wrote" a default_*.profraw and the four tests failed.

The variable is now among the few that reach the child. Outside a
coverage build it is not set and nothing changes.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…xternal hub

Tests only. They record what `socket-patch get <purl> --mode hosted` does
today in a Bazel workspace whose rules_jvm_external hub builds the
artifact from a pinned lock, for the shapes the next commit changes. In
all of them the command writes nothing a Bazel build reads, and the build
takes the jar the hub's lock pins.

The flows of `maven::` in `e2e_bazel_build`, on real Bazel:

- `a_tree_only_bazel_builds` (a checkout without pom.xml) gains two
  steps. `bazel mod tidy` passes and leaves MODULE.bazel byte for byte as
  it is. `rollback --yes` after the skipped patch exits 1 with
  `manifest_not_found` and changes no file: nothing was pinned.
- `a_version_bump_of_the_patched_artifact` is new. After the command
  skipped the patch, the checkout names the artifact at 1.11.0 beside the
  artifact that depends on it, the test serves that release, and the
  ruleset's own relock (`REPIN=1 bazel run @fixture_maven//:pin`) takes it
  into the lock. The build then prints the marker of the 1.11.0 jar.
  Nothing stops it.
- `the_users_own_override_of_the_artifact` is new. The hub has a
  `maven.override` that puts a `java_library` of the checkout in the
  artifact's place. The build prints that target's marker before and after
  the command, which reports the patch skipped, writes nothing, and names
  the override's line in `maven_bazel_unreadable` after "no pom.xml".
- `a_pom_patch_beside_a_pinned_hub` is unchanged.

The checkout setup is shared: `Pinned::open` takes what a flow adds to the
files and to MODULE.bazel before the pin, `serve_upstream` puts a release
in the test's Maven repository, and `skips` holds what the command says
and leaves in a tree without pom.xml.

The fixture's three MODULE.bazel files are now in the layout `bazel mod
tidy` keeps: `module(...)` and `single_version_override(...)` one
argument per line, a blank line before the override. Before, tidy rewrote
those two calls on every release tried, so "tidy leaves the file as it
is" could not be held. No call and no argument changed.

A fourth leg: Bazel 7.4.0 with the era of Bazel 7 (rules_jvm_external
6.5, lock format 2). 7.4.0 is the first release that has `override_repo`,
which the next commit writes, so the oldest Bazel it accepts is one that
CI builds. scripts/bazel-pins.txt gets the two digests from the release's
published `.sha256` files; the darwin-arm64 binary downloaded from the
GitHub release matched its digest before it ran.

Run on macOS arm64 with the product code of this commit, every child
behind a logging proxy that refuses public Maven hosts: the four flows
pass on Bazel 9.3.2 (36 s for the four, two at a time) and on 7.4.0 from
an empty repository cache (333 MB after the run; 404 MB on 9.3.2). No
request to a public Maven host on either (162 and 117 connections logged
on the cold runs: the Bazel registry, GitHub, Bazel's mirror, the JDK's
CDN and, on Bazel 9, go.dev).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A rules_jvm_external hub of a Bazel workspace builds the jars its own
lock pins, so until now no Maven patch reached a Bazel build: hosted mode
pinned a pom.xml beside the hub, or nothing, and said so. With this
commit `socket-patch get <purl> --mode hosted`, run at the Bazel root,
patches a pinned hub, and `rollback` and `remove` undo it.

How

The hub fetches each jar through a repository of its own, named after
group, artifact and version, and Bazel's `override_repo` (7.4.0 and
later) puts another repository in its place. socket-patch appends one
block to the root MODULE.bazel, after one blank line: per patch an
`http_file` with the URL of the patched jar on the Socket patch host and
its sha256, and an `override_repo` of the hub's repository. The hub, its
lock, every label and MODULE.bazel.lock stay as they are.

  # >>> socket-patch: Maven patches for Bazel (managed block: ...) >>>
  socket_patch_http_file = use_repo_rule("@bazel_tools//...:http.bzl", "http_file")

  socket_patch_maven = use_extension("<the label of the hub's own use_extension>", "maven")

  # pkg:maven/<group>/<artifact>@<version>, Socket patch <uuid>
  socket_patch_http_file(
      name = "socket_patch_<repository>",
      downloaded_file_path = "v1/<path of the upstream jar>",
      sha256 = "<of the patched jar>",
      urls = ["<the patched jar>"],
  )

  # If Bazel stops at the next line ("does not generate repository"), ...
  # <group>:<artifact> at <version>: run `socket-patch rollback <purl>`.
  # Do not change it to inject_repo(): the build would pass without the patch.
  override_repo(
      socket_patch_maven,
      <repository> = "socket_patch_<repository>",
  )
  # <<< socket-patch <<<

The block is recognised by its text alone: it is socket-patch's when it
is, byte for byte, what socket-patch writes for the patches it names.
One that is not was changed by hand, and is neither written to nor read
as a pin; so is one whose first line alone was touched (a blank after
it). The undo takes an entry out, and with the last entry the block and
the blank line before it: the file is then byte for byte what it was, in
LF and CRLF files and in a file with both, with and without a last line
break. A block is compared in the line break of its own lines.

When it is written

Everything is read from the checkout; no Bazel runs. An entry is written
only when all of this holds, and otherwise the run writes nothing for
the hub and gives one warning that says why and that the Bazel build
keeps the upstream jar:

- maven_bazel_not_at_root: the project is the Bazel root.
- maven_bazel_not_pinned: no hub of the workspace is without a lock.
- maven_bazel_unreadable: every hub and lock was read, no hub is on an
  isolated `use_extension`, MODULE.bazel is no symbolic link, no rc file
  is unreadable, and the block was not changed by hand.
- maven_bazel_release: `.bazeliskrc` or `.bazelversion` names Bazel 7.4.0
  or later, or MODULE.bazel.lock has the format Bazel 7.5.0 writes; and
  MODULE.bazel.lock holds the `source.json` of exactly one
  rules_jvm_external release, one of 6.4 to 7.2, not older than the
  `bazel_dep` line. The `bazel_dep` line alone is not taken: Bazel can
  select a newer release, and the name of a jar's repository is the
  ruleset's (read at each tag: `escape(coordinates)` to 6.7,
  `to_repository_name` from 6.8; they agree for coordinates of letters,
  digits, `.`, `_` and `-`).
- maven_bazel_artifact: the coordinates have only those characters, a
  repository of the lock lists the jar (a jar that only `m2local` gives
  has a repository on some machines and none on others), and the patch
  comes with its served version and a sha256.
- maven_bazel_no_effect: no `maven.override` of the artifact, and no rc
  file of the checkout names `--ignore_dev_dependency` without switching
  it off, or names `enable_bzlmod` other than switched on (below a
  declared Bazel 9): the build would pass on the upstream jar.
- maven_bazel_download: no rc file of the checkout names a downloader
  config, `--repository_disable_download` or `--vendor_dir`.

The rc files are `.bazelrc` and what it imports, up to 32 files, as
Bazel's rc_file.cc takes an import (read at 7.4.0, 7.7.2, 8.8.2 and
9.3.2): `import`, `try-import` and, from Bazel 8.7.0,
`try-import-if-bazel-version`, whose condition is not evaluated; by a
path under `%workspace%/`, or by a relative one, which Bazel opens from
where it runs and which is read from the root. An option is on or off as
Bazel's BooleanConverter reads it on those four releases: `false`, `0`,
`no`, `f`, `n` in any case, or a `no` before the name. A word that is
neither for certain counts as the harmful one. Not seen: the rc files of
the machine and of the home directory, an import of an absolute path,
and the command line.

A jar that no hub holds, and a project in no Bazel workspace, get
nothing of this: no file is read further, and the run is the one it was.
So does a patch of a jar with a classifier, or of another packaging: a
lock names the plain jar by group and artifact alone.

What a run reports

- The hub lane runs after the pom lane (`bazel::maven::rewrite`), from
  what the engine read of the checkout (`bazel::maven::site`, handed over
  under a synthetic candidate key as the sbt and Go answers are). A patch
  whose entry is in the block is `applied`, whatever a pom.xml or Gradle
  build beside the hub pins; `redirect.rewrittenFiles` holds
  MODULE.bazel. A patch that only a pom.xml took is `applied` too, with
  the hub's warning beside it.
- In a tree that only Bazel builds, a decline is `skipped` /
  `redirect_unconfirmed` with the hub's warning in the place of
  `redirect_maven_no_pom`.
- A decline for a patch whose entry an earlier run wrote leaves that
  entry where it is: the patch is still `applied`, and the warning ends
  "socket-patch left the entry that MODULE.bazel holds for it as it is".
- The previous `maven_bazel_hub_unpatched` is no longer given by a hosted
  run. Vendored and agent runs still give it, with a text that names the
  hosted command, and not for a jar the block patches.
- Vendored mode takes no hub over. `vendor`, `scan` / `get --mode
  vendored` and `vendor --revert` restore the other files of a hosted
  pin and leave its entry in the block as it is (`takeover_pins` in
  commands/vendor.rs), so the Bazel build keeps the patched jar; a pin
  that only the block wires is none of their pins. Without this a
  `vendor` beside such an entry exits 0, takes the entry out and says
  only that the Bazel build "stays unpatched" (seen in a run against a
  loopback stand-in of the API).
- Lockfile discovery reads the block (`vex/discover/bazel_maven.rs`), so
  `list`, `rollback`, `remove` and `vex` see the pin through the code
  they share. An entry whose jar a pinned hub no longer fetches at that
  version, or that an rc file switches off, is kept for the undo and
  withheld from attestation.

A version bump of a patched artifact

The relock passes. Then Bazel stops at the entry's `override_repo(` line
("does not generate repository ..., yet it is overridden via
override_repo()"), where the block names the command that takes the
entry out. Nothing softer exists: with `inject_repo`, which Bazel's
message suggests, the build passes on the upstream jar.

Tests

The flows of the previous commit now hold, on real Bazel: the block's
exact text; the same build prints the marker of the patched jar, fetched
from the patch host; a `--lockfile_mode=error` build passes; the
ruleset's relock leaves the lock and `bazel mod tidy` leaves the file as
they are; `rollback` restores every file byte for byte and the upstream
build; a second machine whose patch host serves other bytes fails on the
sha256 ("Checksum was ... but wanted ...") and does not go to the
upstream jar; after a bump to 1.11.0 the build stops at the entry's line
until `rollback <purl>`; a hub with the user's own `maven.override` is
declined and builds as before; a checkout of Bazel 7.4.0 without a
`.bazelversion` is declined until it has one. A pom.xml beside the hub
is pinned in the same run.

Run on macOS arm64 with the tree of this commit, every child behind a
logging proxy that refuses public Maven hosts, four flows per leg, each
leg from an empty repository cache but the last: Bazel 9.3.2 with
rules_jvm_external 7.2 (97 s, 404 MB), 8.8.2 with 6.9 (89 s, 352 MB),
7.7.2 with 6.5 (92 s, 333 MB), 7.4.0 with 6.5 on the cache of 7.7.2
(40 s). No request to a public Maven host on any leg (518 connections
in all: the Bazel registry, GitHub, Bazel's mirror, the JDK's CDN and,
on Bazel 9, go.dev). With a binary of the previous commit's product code
all four flows fail on 9.3.2.

Against that binary, 272 runs in checkouts without a Bazel file, with
another ruleset's hub, and with a pinned hub that holds the artifact at
another version (hosted get, list, vex, scan, rollback, remove, apply,
vendor and its check and revert) are byte for byte the same in output
and written files, but for the random id and the time of three VEX
documents.

Hermetic: one row per decline and its text, the block added, added
again and taken out over nine file shapes, the reader with and without
the block, discovery, the restore, and the CLI in
tests/e2e_bazel_maven_beside.rs (also: a decline beside an entry of an
earlier run, a block changed by hand under `rollback` and `list`, a
patch of a classifier jar) and in tests/vendor_jvm_cli.rs (`vendor` and
`vendor --revert` beside an entry). Three existing expectations change
there and in two other tests: a hosted run beside a hub that it cannot
patch now gives the decline's code in the place of
`maven_bazel_hub_unpatched`, a tree only Bazel builds gives it alone
(no "no pom.xml"), and the text of `maven_bazel_hub_unpatched` names
the hosted command.

Not here: `scan` does not find the artifacts of a hub, and does not
take a stale entry out; vendored and agent mode patch no hub; a hub
without a lock and a `maven_install` of a WORKSPACE file are declined.

scripts/loc-budget.json: bazel 1459 -> 2149.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Hosted mode writes one entry per Maven patch into a block of the root
MODULE.bazel, for a jar that a pinned rules_jvm_external hub builds, and
declines where it cannot show from the checkout that the entry works.
This closes cases in which it wrote, attested or said something that
the build does not bear out.

A verdict is that of one patch. The verdicts of a run were looked up by
group, artifact and version. In a run with a patch of the plain jar and
a patch of a jar with a classifier (or of another packaging) of the
same coordinates, the second took the first one's entry, or was
reported as pinned by the hub. bazel::maven::jars now names the patches
a hub can take, by the purl of each, and the verdicts are keyed by
patch id: a patch that is not among them gets no entry and no
confirmation.

The rc files are read as Bazel reads them. bazel::rc::mentions matched
option names against the blank-separated words of each physical line.
Bazel joins a line that ends in a backslash with the next one, takes
quotes and backslash escapes out of a word, ends a line at a # outside
quotes and takes the first word as the command (rc_file.cc, and
Tokenize in util/strings.cc, the same at 7.4.0, 7.7.2, 8.8.2 and
9.3.2). So "common --noenable_\" before "bzlmod", and
--noenable_"bzl"mod, were options that Bazel read and socket-patch did
not, and an option behind a # was one that socket-patch read and Bazel
does not. A line with a quote that is never closed, or with a backslash
that nothing follows, which Bazel's source calls an oversight, makes
the file one that cannot be read: maven_bazel_unreadable, with the
line. An import whose path is quoted is followed now, and so is
%workspace%//path.

VEX attests an entry only when nothing in the rc files stands against
it. Discovery took the first thing the rc reading tripped on, and
withheld the statement only when that was an option that switches the
entry off. So an rc file that could not be read, or an earlier option
about downloads, hid a later --noenable_bzlmod, and `vex` said
not_affected for a build that ignores MODULE.bazel. Every line is read
now. An option that switches the entry off, on any line, and an rc file
that cannot be read withhold the statement, and the diagnostic names
them. An option under which the download may fail still attests: such
a build takes the patched jar or fails.

A warning ends with what the block of the root holds for the jar. It
always ended "the Bazel build keeps the upstream jar", which was false
in two cases. Below the Bazel root the root's block is read now: when
it holds the entry of this patch, the run reports the patch as applied
and says that the entry stands, as a decline at the root does. When the
block holds the entry of another patch of the same jar, the warning
names that patch and says that its entry remains.

The release of the ruleset follows the root's overrides. A bazel_dep
version above the one that MODULE.bazel.lock holds was taken for a
stale lock. A root that pins the ruleset lower with
single_version_override was therefore declined for ever, with a remedy
that could not work, and so was a bazel_dep of three numbers. Now a
single_version_override with a version names the release the lock must
hold, older or newer; versions compare in Bazel's order; and an
override that takes the ruleset from no registry or keeps several
releases of it (archive_override, git_override, local_path_override,
multiple_version_override, a pinned version that is no string) declines
with the line of the override, because the release cannot be known.

Couplings that were held by matching text are gone. The kind of a doubt
(a hub without a lock, a maven.override, something unread) is a value
beside its text, and the hub's name a field: the decline code was
chosen by the wording of the doubt. The pom rewriter asks the verdicts
whether a hub decides a patch before it says "no pom.xml": the hub
lane took that warning back by its code afterwards. And the group, the
artifact and the maven2 override of a Maven patch come from one
function, redirect::maven_coordinates, for the pom rewriter and the
hub lane, where there were three copies.

A new block is written in the line break that utils::line_endings
gives for the file, as the other writers that keep CRLF do: in a file
with both, the more frequent one, where the block had a rule of its
own (CRLF if any). The undo is byte for byte as before, for every file
shape of the unit test.

Not changed: each command reads the hubs of a workspace again, and a
hosted get reads them twice (measured beside a 4.9 MiB lock in a debug
build: about 40 ms per read, nearly all of it the JSON parse of the
lock). Sharing that parse would take process-wide state to save one
parse per run.

The size budget of the bazel group moves from 2149 to 2230 code lines.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A hosted run that declines for a jar whose entry is already in the block
confirmed the patch and reported it `applied`, whatever the reason of
the decline. For `maven_bazel_no_effect` that is false: an rc file that
switches the block off, or a `maven.override` of the jar, leaves the
entry in MODULE.bazel while the Bazel build takes the upstream jar.

Such a run no longer confirms the patch. Its warning ends "socket-patch
left the entry that MODULE.bazel holds for it as it is, and while that
stands the entry has no effect: the Bazel build keeps the upstream jar".
Every other decline beside the patch's own entry is as it was. The docs
say both endings, and the `bazel` budget follows the four added lines.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review November 19, 2026 16:53
@cursor

cursor Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

PR Summary

High Risk
Changes hosted Maven/Bazel integration, MODULE.bazel rewriting, and CI compatibility legs—incorrect hub or rc handling could leave Bazel on upstream jars or break builds silently until checksum failure.

Overview
Hosted mode now patches jars that a pinned rules_jvm_external hub would otherwise take only from maven_install.json, by appending a managed block to the root MODULE.bazel (http_file + override_repo, Bazel ≥7.4.0). Successful runs rewrite MODULE.bazel (and Maven files when present); rollback/remove strip entries byte-for-byte. Discovery, upstream restore, and vex treat the block as hosted wiring.

The hosted engine wires hub analysis into discovery/rewrite (confirmed_bazel_maven_uuids, shared maven_coordinates). Vendored runs no longer “take over” pins that exist only in the block (takeover_pins drops MODULE.bazel). Hosted scan stops duplicating hub warnings via bazel_maven_notices (the hub lane owns declines). bazel/rc.rs gains MODULE.bazel.lock ruleset selection and .bazelrc parsing aligned with Bazel.

New maven_bazel_* warning codes document declines (release, unpinned hub, overrides, rc options, etc.); maven_bazel_hub_unpatched is narrowed to vendored/agent. CI adds Bazel 7.4.0, expands workflow path triggers, and docs/CLI_CONTRACT are updated. E2E and CLI tests cover real Bazel builds, tampered patch hosts, version bumps, and block lifecycle.

Reviewed by Cursor Bugbot for commit b79af8f. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit b79af8f. Configure here.

…s too

After the merge with main, `rollback` of a Maven patch that a hosted run
pinned in `pom.xml` and in the block of a Bazel hub in `MODULE.bazel`
took the entry out of the block and left `pom.xml` and the two `.mvn`
files pinned. It exited 0 and reported the patch as rolled back
(`a_pinned_hub_gets_its_block_and_the_undo_takes_it_out` in
`e2e_bazel_maven_beside`).

What met what. A hosted pin is one patch of one package in every file
that wires it: discovery groups what it finds by purl and patch id, and
the restore hands the restorer of each format the pins that have a file
of that format, and those files. "Patch Maven reactors and ${property}
versions in hosted mode" (#2114) turned the Maven restorer from a loop
over its files into a loop over its pins, and took every file of a pin
for one of its poms. A pin with a file the restorer was not handed was
then passed over as one whose file could not be read, with no refusal;
the restorer of the other file claimed the pin, so the run called it
restored.

The block is such a second file, and not the only one. On main alone, a
checkout that sbt builds beside Maven holds the patch in
`socket-patch.sbt` as well as in `pom.xml`, and its rollback left the
pom pinned in the same way: the new unit test of the Maven restorer
shows that on the `sbt/redirect/pom-also-present` fixture, with no
Bazel file in it. The index of a hosted Gradle build beside a `pom.xml`
is a second file of the same kind (read, not run).

The fix is in the Maven restorer (`upstream/maven.rs`, one more
implementation line): the poms of a pin are those of its files that the
restorer was handed. Every other file of the pin is the restorer's of
its own format, as the dispatch of the restore already has it. A pin
that only poms hold is read as before, so the rules for a reactor stand
as they are: a pin is restored in every pom that carries part of it or
in none, and a pom that cannot be read refuses it. The existing tests of
the Maven undo pass unedited.

Tests:
- `upstream/maven.rs`: the sbt fixture, discovered and rolled back to
  its input, byte for byte.
- `upstream/bazel_maven.rs`: discovery reads one pin from `pom.xml` and
  the block, and the restore leaves both files as they were.
- `e2e_bazel_maven_beside`: beside a pinned hub, a hosted `get` in a
  reactor, with a `${property}` version, and behind a mirror of the
  machine's Maven settings that would take the Socket repository (the
  pom then gets no pin and the run says so; the hub still gets its
  block). `list` and `vex` show one pin, in the block and in every pom
  that holds part of it, and `rollback` leaves the tree as it was.
- `vendor_jvm_cli`: `vendor` beside an entry whose patch a hosted run
  also pinned in the poms of a reactor takes the poms' part of the pin
  over and leaves the entry, as it leaves an entry that stands alone.

With the fix taken out, the two unit tests and the two tests of the
undo in `e2e_bazel_maven_beside` fail, and nothing else in the unit
suite of the core crate does.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…tice

# Conflicts:
#	crates/socket-patch-cli/CLI_CONTRACT.md
#	crates/socket-patch-cli/src/commands/mod.rs
#	crates/socket-patch-core/src/bazel/mod.rs
#	crates/socket-patch-core/src/bazel/workspace.rs
#	scripts/loc-budget.json
@mikolalysenko Mikola Lysenko (mikolalysenko) added the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Nov 19, 2026
Base automatically changed from bazel-maven/01-hub-notice to main November 19, 2026 21:46
…e-repo

The parent branch landed on main as #2157. Taking its last tip first lets
the merge with main below see what the squash already holds.

Assisted-by: Claude Code:claude-opus-5-5
The parent branch landed on main squashed (#2157), so every file it added
conflicted add/add. The merge takes the parent's last tip as its base, so
only what main changed since then is merged in: #2159's VEX attestation,
#2153's terminal UI and the rest.

- scan/hosted.rs: keep this branch's removal of the hub notice from the
  hosted run. A hosted run patches a pinned hub or says why not among its
  rewriters' warnings, so the notice would repeat or contradict them.
- scripts/loc-budget.json: the bazel group's cap is 2486, the count after
  the merge (this branch's 775 lines over main's 1711).

cargo clippy -D warnings, the core lib tests, vendor_jvm_cli,
e2e_bazel_maven_beside and the Maven CLI tests pass.

Assisted-by: Claude Code:claude-opus-5-5
Merged via the queue into main with commit 6579162 Nov 19, 2026
119 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the bazel-maven/02-override-repo branch November 19, 2026 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants