Skip to content

Commit 4ecfd4f

Browse files
Attest a Maven patch as affected in VEX where a pinned Bazel hub fetches the jar from its lock (#2236)
* Test PyPI and RubyGems vendored mode beside a Bazel hub on real Bazel Tests only. rules_python's `pip.parse` and rules_ruby's `ruby.bundle_fetch` hand a lock of the checkout to Bazel. The real-Bazel flows ran hosted mode beside both hubs, and vendored mode beside the Python one (pypi::vendored_pip_parse, which holds `vex` to saying that the build is not the patched one). No flow ran vendored mode for a gem, and the PyPI flow did not build between its undo and its hosted scan. ruby::vendored_bundle_fetch records what the command does today, in the fixture of the hosted flow (rules_ruby 1.0.0-rc2; the call names the `Gemfile` and the `Gemfile.lock` of the root). `scan --mode vendored --yes` exits 0 with status `success` and one package applied. It commits the unpacked gem with its specification and the ledger under `.socket/vendor/gem/<uuid>`, gives the gem's declaration in `Gemfile` a `path:`, and moves the gem's entry of `Gemfile.lock` into a `PATH` section. The next `bazel build` fails in the `bundle install` action of the hub. rules_ruby copies the two files into a repository of Bazel's and runs Bundler there, which stops with The path `<execroot>/external/<hub>/.socket/vendor/gem/<uuid>/sp-victim-1.0.0` does not exist. `vex` attests the gem as patched meanwhile: it reads the committed copy, and what rules_ruby builds from one is not judged. `vendor --revert` puts every file back, and the build with them. pypi::vendored_pip_parse now names the failure it asserts. rules_python makes the name of a repository from the path of the vendored line, and Bazel stops with `invalid user-provided repo name 'pip_311__/_socket/vendor/pypi/<uuid>/spvictim_1_0_0_py2_py3_none_any_whl'`. The flow also builds right after `vendor --revert`: the unpatched build is back before hosted mode pins the patch. Both flows pass on Bazel 9.3.2 with the product code as it is. Each compares the tool's message without white space: Bundler breaks its message at the width of the console it runs in, which differs from one machine to the next. The two Ruby flows share their stand-in. `Served::to` builds the gems of a run, serves them, grants the patch and routes Bazel's downloads, as the hosted flow did inline. The grant now holds what the patch service grants for a gem: the patched gem with a sha512, and its specification. Vendored mode downloads both, and hosted mode neither. The record of the patch holds the hashes of the gem's one file, in place of the placeholders of the shared stand-in. bazel-ruby.yml says in its header that the legs run both modes, and a pull request that changes vendor/gem.rs now starts them: the file was in the list of the pushes to main alone. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Decline PyPI and RubyGems vendored mode where a Bazel hub reads the lock rules_python's `pip.parse` and rules_ruby's `ruby.bundle_fetch` build the packages of a lock in repositories of Bazel's own. Vendored mode makes that lock name the patched copy by a path under `.socket/vendor`, and neither ruleset builds from such a lock. The command exited 0 with status `success`, and the next `bazel build` failed for everything the hub serves (Bazel 9.3.2, 8.8.2 and 7.7.2, the flows of the previous commit): - PyPI: rules_python 2.5.0-rc4 makes the name of a repository from the path of the vendored line, `invalid user-provided repo name 'pip_311__/_socket/vendor/pypi/<uuid>/<wheel>'`. - RubyGems: rules_ruby 1.0.0-rc2 runs `bundle install` in a repository that holds the Gemfile and its lock and not the copy, `The path .../.socket/vendor/gem/<uuid>/<name>-<version> does not exist.` Vendored mode now declines such a package before it downloads or writes anything, with `vendor_pypi_bazel_hub` or `vendor_gem_bazel_hub`. The refusal rests on what the files of the workspace say and on what the run would write, so it is for a run that would write a file a hub reads, and for no other. When it declines. The project is in a Bazel workspace (`bazel::bazel_root`), and a call of its files names, by a label written out as a string, a file of the project that the run for the package would point at a copy: - a `pip.parse` whose `requirements_lock`, `requirements_by_platform`, `requirements_darwin`, `requirements_linux`, `requirements_windows` or `uv_lock` names a requirements file of the project that the run would write (`requirements.txt` or a file it includes with `-r`), or the `uv.lock` of a uv project; - a `ruby.bundle_fetch` whose `gemfile` or `gemfile_lock` names the project's `Gemfile` or `Gemfile.lock`; - a call of a `WORKSPACE` file that passes one of those attributes, which is how the older form of either ruleset is called there (`pip_parse`, `rb_bundle_fetch`). Which files a PyPI run writes is asked of the backend's own router (`vendor::pypi::hub_files`). A project with no tool lock is wired through its requirements files, so they count. A uv, Pipenv or PEP 751 lock is wired together with a pin of the package in the requirements files beside it, so they count for a package they name (a pin, a hosted pin that a takeover restores first, or the vendored line of an earlier patch) and not for one they do not name. A Poetry or PDM lock is wired alone: such a project is not declined beside a hub that reads the requirements file exported from its lock, and is vendored as it is without Bazel. Every such call counts, also one that may not run (in a comprehension). Every package whose run would write a file the call names is declined, since the lock is the project's, but one that is already vendored (below). What an uncertain reading does. Where the files of the workspace cannot be read with certainty and a call of the hub may be behind that, every package whose run would write such a file is declined, in every project of the workspace: - a call of the hub whose file is not a plain string, or that passes `*` or `**`, and a hub proxy handed to anything but `use_repo` or `inject_repo`; - a module file that is missing or cannot be read, or a statement of one that cannot be read, where the workspace calls the hub or a file that was read names its ruleset (a `bazel_dep` on it, or a `use_extension` of the hub's `.bzl` file under any repository name); - a root `MODULE.bazel` or a `WORKSPACE` file that cannot be read at all. The last two matter because Bazel builds files that are not read here: one byte that is not UTF-8 is enough, in a comment too, and so is a file over 1 MiB. Without them the call in such a file was not seen and the run went on. Going on there can leave a broken build behind a command that exited 0, and declining costs a vendored run that the switch brings back. A workspace whose root `MODULE.bazel` and `WORKSPACE` file were read or are not there, and in which no file that was read calls the hub or names its ruleset, is never declined for it, whatever else cannot be read. Where nothing changes. Outside a Bazel workspace, in a workspace that calls neither hub, and for a package whose run writes no file that a call names (a project beside the one a hub reads, one whose `requirements.txt` is not the file the hub is given, a Poetry or PDM project whose exported requirements the hub reads), vendored mode prints what it printed and writes what it wrote. Other ecosystems, hosted mode and agent mode are not touched. Where it is asked. `bazel::built` already says for `vex` which hub reads which lock; `reader` there answers this question from the same table and the same reader of workspace files, and takes `uv_lock` as one more attribute. `vendor::bazel_hub::refusals` asks it about the files the run of each package would write and words the refusal. `vendor::refusals::bazel_workspace_refusals`, the one answer every vendored entry point takes for a refusal that rests on the Bazel workspace, returns it beside the Composer refusal. So it reaches `scan --mode vendored`, `get --mode vendored`, `vendor` for a patch the manifest records, the takeover of a hosted pin by a vendored scan, and the eject of one by `vendor`, which asks once and before it fetches a record. No command's own code changes. The package is a `failed` event and the run exits 1 (`partialFailure`; for the eject `eject_refused`, detail `kept hosted: ...`). A dry run of `scan` or `get` lists the package as one the run would refuse and exits 0; `vendor --dry-run` reports the refusal and exits 1, as it does for any package it could not vendor. Nothing is written, no patch is downloaded, and a hosted pin stays. These are the exit codes of the Composer refusal. The detail names the call with its file and line, the lock, the Bazel root and hosted mode: `pip.parse` (MODULE.bazel:15) of the Bazel workspace at /repo names requirements.txt; vendored mode makes the lock name the patched copy by a path under .socket/vendor, and rules_python fails the build on such a lock; use `--mode hosted`, which names the patched package by a URL that rules_python fetches, or pass `--allow-vendored-in-bazel` if no build takes the packages of this project from rules_python For a doubt it names the file, the line and the reason in the place of the call. Hosted mode pins the patch in the same file, and both rulesets build it: the two flows end with that build. For a gem the detail adds the condition under which rules_ruby builds a hosted pin, "where its call passes no `gem_checksums`": with an entry for the gem there the hosted build fails, which the docs list as a known problem. `--allow-vendored-in-bazel` (SOCKET_ALLOW_VENDORED_IN_BAZEL) lifts the refusal, as it lifts the Composer one: for a hub that no build uses, a `WORKSPACE` file that the Bazel in use does not read, or a `ruby.bundle_fetch` that is given the files of the copy as `srcs`. Its help text, its row in CLI_CONTRACT.md and the sentence of docs/ecosystems.md that named Composer as the one refusal it lifts now name the three. `vendor --revert` is not refused. Neither is a package that is already vendored, as for Composer. What is declined is the write of the path into the lock the hub reads, so a package that the file the call names already names by the copy of the same patch (`.socket/vendor/pypi/<uuid>/`, `.socket/vendor/gem/<uuid>/`, outside a comment) is let through: the run adds nothing to what the hub reads. A project vendored with the switch, or by an earlier release, keeps passing its in-sync runs without the switch, a `scan` or `get` that names no mode included, which runs in vendored mode there. A new patch for that package, and any other package, is declined as before. It is the named file that decides, not any file of the project: a uv project whose lock names the copy while the hub reads a requirements file that still pins the registry's release would have that file rewritten by the run, and is declined. That file is read as a lock of the workspace is (`built::lock_text`): up to 64 MiB, and not through a link that leads out of the Bazel root, so such a link lets nothing through. Where the reading is in doubt no file is known to be the hub's, so nothing is let through there. Such a run passing does not make the build the patched one: for PyPI `vex` says `affected` of that state. No line a person reads is new: the refusal prints where every refused vendored package does. Tests: - pypi::vendored_pip_parse and ruby::vendored_bundle_fetch (real Bazel) now hold the command to the refusal: exit 1, the code, a detail that names the call, the lock, `--mode hosted` and the switch, no file changed and no request for the patched wheel or gem. The same build passes on the upstream package. With the switch the expectations of the previous commit are back: the package is vendored, the build fails with the ruleset's message, and `vendor --revert` restores the build. Hosted mode then builds the patched package. - Hermetic tests of both files, on steps the harness now holds for both: every command that would vendor declines and writes nothing, the dry runs and the eject among them; vendored mode goes on with the switch and with its variable, a later run without them passes and writes nothing, a scan that names no mode included, and `vendor --revert` needs neither; it goes on with no switch in a workspace whose hub reads another file, in a project beside the one it reads, and in no workspace; a hub whose file is not written out declines. For PyPI also: a Poetry project beside a hub that reads its exported `requirements.txt` is vendored with no switch, that file stays as it is and the later runs pass; and a `MODULE.bazel` with one byte that is not UTF-8 declines. - Unit tests of `built::reads` (each attribute, a call that may not run, `uv_lock`, another project, another repository, a doubt of the call, of the proxy and of the workspace, a hub that is not called, the `WORKSPACE` file; a root module file, an included file and a `WORKSPACE` file that cannot be read, with a root that names the ruleset as a dependency, by its extension, or not at all), of the refusal (codes, words, the switch, a file brought in with `-r`, the `Gemfile` alone, no workspace; a package the named lock already names by the patch's copy, and the same copy named in a comment, in another file, behind a link out of the root or under a doubt; a Poetry and a PDM lock, and a uv and a Pipenv lock beside a requirements file that names the package or does not) and of its dispatch. Four tests of pypi.rs vendored a wheel beside the hub that reads the requirements, to hold `vex` to what it says of that state. The command that writes the line now has the switch there, and they assert what they asserted; the in-sync runs after it have none, as before. Docs: docs/ecosystems.md "Bazel workspaces: PyPI and RubyGems vendored mode", the two rows of the matrix, and what "Bazel workspaces: VEX" says of a vendored gem, which a build has now shown; the rows of the two codes, of the switch and of the vendored table in CLI_CONTRACT.md. In "Bazel workspaces: what is supported" the two vendored cells stay "Not supported", and the note on that word now says that the command declines there. The entry of the known problems for vendored mode listed commands that exit 0 and leave a failing build: PyPI and RubyGems leave it, and so does Composer, which declines since the change before this one; NuGet stays. bazel-pypi.yml and bazel-ruby.yml start their legs for a change to vendor/bazel_hub.rs and vendor/refusals.rs, and bazel-pypi.yml for one to vendor/pypi.rs. The `bazel` group of scripts/loc-budget.json follows the 69 lines added to built.rs. Not covered: a hub call in a `.bzl` file that a `WORKSPACE` file loads, a hub of another Bazel module, another tag or ruleset that reads the same file under Bzlmod, a `WORKSPACE` call that hides its arguments behind `**`, a Bazel root above the git checkout, and a hub whose call and whose `bazel_dep` are both in an included file that cannot be read while the files that were read name neither: vendored mode goes on there as before. A package of a uv, Pipenv or PEP 751 project that the hub's requirements file names in a form that is not wired with the lock (a range, extras) is declined although the run would leave that file alone. `vex` still attests a gem that was vendored with the switch as patched, while its build fails. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Close three ways a vendored run could still write a file a Bazel hub reads A review of the PyPI and RubyGems vendored declines found three states in which the run was let through and would write a file that a hub of the Bazel workspace reads: - A Poetry or PDM project whose exported requirements file holds the package by a URL, which is what a hosted pin is. The lock of such a project is wired alone, so its requirements files did not count, but a vendored run that takes a hosted pin over restores that line. The files now count for a package they hold by a URL. A package they pin from the registry is vendored as before. - A `WORKSPACE` call that names the lock through the name the file gives the main repository (`@shop//api:requirements.txt` beside `workspace(name = "shop")`). The label was taken for another repository's. It is the main repository now, for the calls of that file. - A package that is already vendored, where the calls name more than one file of the project. Only the first file a call names was read, so a `uv.lock` locked again beside a vendored requirements file let the package pass, and the run rewrote the lock. Each file a call names that holds the package now has to name the copy; one that cannot be read may hold it. Also from the review: the requirements file is no longer listed twice, the gem's two files are the gem backend's own constants, and the files of a package are chosen by its ecosystem and not by the text of its purl type. The docs and the contract row say what was imprecise: the requirements files of a project with no tool lock count as one set, also for a package a file of the set does not pin, because a file the hub reads can bring in the rewritten one with `-r`; and the `pip_install(requirements = ...)` of an older rules_python is not seen. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Decline a vendored run where a hub reads a parent file or is in doubt Two states in which a vendored PyPI run was still let through and would write a file a Bazel hub reads: - A hub that names a requirements file which brings the project's own in with `-r` (`all.txt` with `-r requirements.txt`). The files a run writes are walked down from `requirements.txt`, so the file the hub named was not among them and nothing was declined. A requirements file a call names now counts as naming each file its `-r` includes reach, read inside the Bazel root as any lock is, and the refusal names it. - An already-vendored package whose other files a call may name where the reading is in doubt: a second attribute that is not written out, or a call that may be behind a file that could not be read. Only a certain answer had that file read; a doubt was dropped and the package let through. A doubt now has the file read as well, so the package is declined where that file holds it and not by the copy. The `bazel` line budget goes from 2574 to 2611. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011f9aeQFeU3sKRPzawaNLsm Assisted-by: Claude Code:claude-opus-5-5 * Test agent mode for Cargo and NuGet beside a Bazel hub that builds from the lock Two flows on real Bazel, tests only, that record what socket-patch does today in a workspace where a ruleset builds a package from the project's lock and agent mode patches the copy a package manager unpacked outside the checkout: - `cargo::agent_from_cargo_with_config`: rules_rust's `crate.from_cargo(cargo_lockfile = "//:Cargo.lock", ...)`, and the crate in `$CARGO_HOME/registry/src`, as after `cargo fetch`. - `nuget::agent_from_lock`: rules_csharp's `nuget.from_lock(packages_lock_json = "//:packages.lock.json", ...)`, and the package in NuGet's global packages folder, as after `dotnet restore`. In both, `scan --mode agent --yes` exits 0 with the patch applied to that copy and writes nothing into the checkout but `.socket/`, and `apply` passes. `bazel build` and `bazel run //:consumer` print the unpatched marker before the command and after it: each hub has Bazel download the package the lock pins, and no build reads a cargo home or NuGet's folder. The build right after the command is a warm one, which looks at nothing outside the checkout again, so each flow ends with a build on a second machine: a copy of the checkout without `MODULE.bazel.lock` and with an empty output base, whose Bazel has the patched cargo home or NuGet folder in its environment and evaluates the hub anew. It prints the unpatched marker too. Meanwhile `scan --mode agent --vex`, `apply --vex`, `vex` and `vex --no-verify` each write an OpenVEX document whose one statement says the package is `not_affected`, "Patched via Socket patch <uuid>". That document is false for what Bazel builds. The flows assert it as it is today and mark it KNOWN GAP, with what a fix changes in the test. The copy in the cargo home is the one the hub's own cargo unpacked there where the ruleset runs that cargo with the home of the environment (rules_rust 0.56.0), and is laid out by the test where it does not (0.75.0); NuGet's folder is laid out as the hosted flow already does. No cargo and no dotnet runs. The Bazel commands of the NuGet flow get the two variables of the .NET home that `socket-patch` gets (`NUGET_PACKAGES`, `DOTNET_CLI_HOME`), so a build that read the folder would find it. What the flows share is in the harness: `Cell::patches_outside`, and `Cell::builds_anew` for the second machine, which removes the first workspace copy before it builds where the repository cache outlives that copy. The grant helpers of the two modules are split so that a patch record can carry the file contents agent mode patches from, and in the Cargo module the helper that names the hosts of a child takes its cargo home as well; the hosted and vendored flows call them as before and assert what they asserted. The two workflows say that their legs now run agent mode, and start on a pull request that changes the VEX code (`vex/` of the core, the `vex` command) or, for NuGet, agent mode's own file. Both flows pass on Bazel 9.3.2 (macOS arm64) with no change to the product: NuGet in 14 s, Cargo in 92 s with an empty repository cache. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Attest a Cargo or NuGet patch as affected in VEX where a Bazel hub builds the package from the lock Agent mode patches a crate in the cargo home (`$CARGO_HOME/registry/src`) and a NuGet package in NuGet's global packages folder. In a Bazel workspace neither copy is built: rules_rust's `crate.from_cargo(cargo_lockfile = ...)` and rules_csharp's `nuget.from_lock(packages_lock_json = ...)` have Bazel download what the project's lock pins. The flows of the commit before this one measured it on Bazel 9.3.2: `scan --mode agent` exits 0 with the patch applied, `bazel build` prints the upstream marker before and after, also on a second machine that evaluates the hub anew, and `scan --vex`, `apply --vex`, `vex` and `vex --no-verify` each attest the package as `not_affected`. That document is false for what Bazel builds. Cargo and NuGet join the table of hubs in `bazel/built.rs`, so what main does for npm, PyPI and RubyGems holds for them too. When a call that is a statement of its own names the project's own `Cargo.lock` or `packages.lock.json` in a plain string, and that lock lists the package at the patched version without the patch, the document says `affected` of the package, with an action statement that names the lock, the call and its line, and what to run. `vex --json` reports a `skipped` event with `vex_bazel_not_in_build` and `details.status: "affected"`, the envelope is `partialFailure` and the exit code is 0, as on main. `--no-bazel` / `--vex-no-bazel` / `SOCKET_VEX_NO_BAZEL` leaves Bazel out of it. What the table holds for the two: - rules_rust: the extension by both files that define it at 0.56.0 and 0.75.0 (the constant of `bazel/cargo.rs`), the tag `from_cargo`, the attribute `cargo_lockfile`. Of the lock, the crates of a registry that no `[replace]` swaps out: those are the ones Bazel downloads. A call with a cargo-bazel lock (`lockfile`) is passed over, because the hub renders its crates from that file until a repin. So is one without `cargo_lockfile`, which names no lock. - rules_csharp: the extension as `bazel/nuget.rs` names it, the tag `from_lock`, the attribute `packages_lock_json`. A `packages.lock.json` never names a patch (a hosted pin there is a hash), and rules_csharp 0.5.0 makes one hub of all the `nuget.from_lock` calls: the sources of the last call that has any serve every package, and the first lock that names a package pins it. So a project patched in agent mode can be built patched through the hosted pin of another project of the workspace (measured on Bazel 9.3.2 with two calls). The `nuget_config` of every call is therefore searched for the id of the patch together with the lock. Where one names it, or is not a plain label, or cannot be read, or a call passes `*` or `**`, nothing is said of the hub. The locks are still read one call at a time, and `feeds` and `local_package_dirs` are not read. The action statement names the modes that a flow of this repository builds patched on real Bazel under that hub, so a hub carries its own sentence: hosted mode with the attribute it needs of the call (`cargo_config`, `nuget_config`), and for a crate vendored mode as well. The sentence of the three hubs on main is the same bytes as before, and their calls are judged one at a time as before. Left as main has them: a hosted pin (the caller hands none over, and whether a hub takes one is for `bazel/cargo.rs` and `bazel/nuget.rs` to say), a vendored crate (rules_rust builds it), a vendored NuGet package (no test builds one under its hub), a project whose lock no call names, a workspace that is not read with certainty, and a project in no Bazel workspace. Tests: unit tests of the table (what a lock lists, which calls are passed over, the hub of several `nuget.from_lock` calls, a doubt on the hub by either file of the rules_rust extension, the sentence of each hub). Two tests without Bazel per ecosystem run the binary in a checkout of the fixture: one runs the scans the action statement names and holds the document after each to `not_affected`; the other holds `vex`, wherever the hub decides nothing and with `--no-bazel`, to what it gives in the same checkout without its `MODULE.bazel` (exit code, both streams, the document), through `Cell::keeps_its_statement` of the harness. For NuGet one of those hubs has a second call whose `nuget_config` names the patch. The two agent flows now expect `affected` from the run, from `apply`, from `vex` and from `vex --no-verify`, and `not_affected` from `vex --no-bazel`, while the build still prints the upstream marker, on the second machine too. No assertion of the hosted and vendored flows is edited. One existing unit test took a Cargo purl for a package of no hub; it takes a Go module now. Docs: the VEX cells of Cargo and NuGet in "Bazel workspaces: what is supported", the section "Bazel workspaces: VEX" and the `vex_bazel_not_in_build` row of the CLI contract. The two workflows start their legs on a change to `bazel/built.rs` and to the reader of the workspace files, each by its path. The size budget of `bazel/` follows the code (3337 to 3403 lines). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Read a NuGet lock below the run's directory as the project's own in the Bazel VEX answer A NuGet project is every project file below the directory a command runs in, each with a `packages.lock.json` beside it: agent mode patches what any of them restored, and hosted mode and `vex` read a pin in each of their locks. The hub table took only the lock in the run's own directory for the project's, as it does for the other ecosystems. So for a run at the root of a solution, where `nuget.from_lock` names `//src/App:packages.lock.json`, the document kept `not_affected` for a package that Bazel downloads unpatched. The NuGet hub now takes a lock at or below the directory of the run. The other hubs are as they were: a lock below the run is still the lock of another project there. Three smaller changes to the same function, none of which changes what is said of a workspace that Bazel can load: - Whether every `nuget_config` of the hub is a plain label was a comparison of two counts: the labels that resolve, and the calls that give the attribute. A dict counts once as given and once per key as resolved, so the counts could be equal while a config was not read. Each call is now asked on its own: no `nuget_config`, or one string that names a file of the main repository. - The attributes with which a call can take its packages from a file that is not read (`uv_lock`, `lockfile`) were one list for every hub. Each hub now has its own. - The configs of a rules_csharp hub were read again for every lock. They are read once for the hub, when the first lock asks. The docs and the contract row say which lock is the project's own for NuGet, and the list of statements that stay wrong names the member of a Cargo workspace, whose `Cargo.lock` lies above it. The `bazel` line budget is the new count, 3704. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Accept either unseen repository where a Cargo flow comments out the ignore line `cargo::vendored_from_cargo_with_config` comments out the line the scan wrote in `.bazelignore` and expects `bazel cquery //...` and `bazel query 'deps(//...)'` to fail on a repository that the main repository does not see. It looked for the hub's repository (`@crates__...`) alone. The build file that cargo-bazel writes into the committed copy names `@platforms` as well, and Bazel reports the first one it meets: on a Linux runner with Bazel 9.3.2 the query named `@platforms` and the flow failed on its own check. The flow now takes either name for that failure. Test only: nothing the command does changes. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Accept either unseen repository where a Cargo flow comments out the ignore line `cargo::vendored_from_cargo_with_config` comments out the line the scan wrote in `.bazelignore` and expects `bazel cquery //...` and `bazel query 'deps(//...)'` to fail on a repository that the main repository does not see. It looked for the hub's repository (`@crates__...`) alone. The build file that cargo-bazel writes into the committed copy names `@platforms` as well, and Bazel reports the first one it meets: on a Linux runner with Bazel 9.3.2 the query named `@platforms` and the flow failed on its own check. The flow now takes either name for that failure. Test only: nothing the command does changes. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Hold the unseen repository to Bazel's own words, and say so in the docs The check of the commands that fail once the ignore line is commented out now reads the name out of Bazel's message and takes it only when the message is about the main repository's view: `platforms`, or a repository of the crate hub. The same words about another repository's view, or about another name, are a different failure and no longer pass for the expected one. A test without Bazel holds the check to the two messages that were seen and to three it must not take. The module docs, the comment at the call and the section on the build file in a vendored crate said the commands end on the dependency's repository alone. They now name `platforms` as well, which is what a user who comments the line out can see. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Hold the unseen repository to Bazel's own words, and say so in the docs The check of the commands that fail once the ignore line is commented out now reads the name out of Bazel's message and takes it only when the message is about the main repository's view: `platforms`, or a repository of the crate hub. The same words about another repository's view, or about another name, are a different failure and no longer pass for the expected one. A test without Bazel holds the check to the two messages that were seen and to three it must not take. The module docs, the comment at the call and the section on the build file in a vendored crate said the commands end on the dependency's repository alone. They now name `platforms` as well, which is what a user who comments the line out can see. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Test agent mode for Maven beside a Bazel hub that fetches the jar from its lock Two tests, no product change, that record what socket-patch does today in a workspace where a pinned rules_jvm_external hub (`maven.install(lock_file = "//:maven_install.json", ...)`) fetches an artifact and agent mode patches the jar of that artifact in the Maven local repository: - `maven::an_agent_patch_beside_a_pinned_hub`, on real Bazel: the checkout has a `pom.xml` that declares the artifact, and the jar is in the Maven local repository as a Maven build leaves it. `scan --mode agent --yes` exits 0, puts the patch service's jar in its place and writes nothing into the checkout but `.socket/`; `apply` passes and warns `maven_bazel_hub_unpatched`. `bazel build` and `bazel run //:consumer` print the upstream marker before the command and after it: the hub fetches the jar its lock pins, at the lock's sha256, and no build reads the Maven local repository. - `maven::an_installed_jar_is_attested_beside_a_hub_that_fetches_its_own`, without Bazel: the same step in a checkout whose lock is written by the test, in the format rules_jvm_external 7.2 writes. In both, `scan --mode agent --vex`, `apply --vex`, `vex` and `vex --no-verify` each write an OpenVEX document whose one statement says the artifact is `not_affected`, "Patched via Socket patch <uuid>". That document is false for what Bazel builds. The tests assert it as it is today and mark it KNOWN GAP, with what a fix changes. What the tests share is in the Maven module: step 0 of a flow is split into the layout of the checkout and the ruleset's pin, so that a checkout no Bazel builds in can have the same stand-in, grants and local repository; `Pinned::patches_the_installed_jar` runs the agent step. `Cell::patches_outside` of the harness compares the installed file as bytes, since a jar is no text; the Cargo and NuGet flows call it as before. The real-Bazel flow passes on Bazel 9.3.2 and 7.7.2 (macOS arm64) with no change to the product, in about 20 s each. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Attest a Maven patch as affected in VEX where a pinned Bazel hub fetches the jar from its lock Agent mode patches the jar of a Maven artifact where a build tool installed it (the Maven local repository, a Gradle or Coursier cache). In a Bazel workspace a pinned rules_jvm_external hub does not build that jar: it takes the one its lock (`maven_install.json`) pins, at the lock's sha256. `apply` already warns of it (`maven_bazel_hub_unpatched`). The tests of the commit before this one measured the rest on Bazel 9.3.2 and 7.7.2: `bazel build` prints the upstream marker before and after `scan --mode agent`, and `scan --vex`, `apply --vex`, `vex` and `vex --no-verify` each attest the artifact as `not_affected`. That document is false for what Bazel builds. The document now says `affected` of such an artifact, as it does for npm, PyPI, RubyGems, Cargo and NuGet: one statement of the package's own, whose action statement names the lock of the hub, the `maven.install` with its file and line, and the command that patches a pinned hub, `socket-patch get <purl> --mode hosted` at the Bazel root, or with `--mode vendored`. It ends with the `--no-bazel` sentence. The warning is `vex_bazel_not_in_build`, `vex --json` reports a `skipped` event with `details.status: "affected"`, the envelope is `partialFailure`, the exit code is 0, and `--no-bazel`, `--vex-no-bazel` and `SOCKET_VEX_NO_BAZEL` leave Bazel out of the document, all through the code those ecosystems already run. The command comes with a condition, in brackets: "a `maven_bazel_*` warning of that run means that the Bazel build keeps the upstream jar". Hosted and vendored mode write no entry for a hub where they cannot show from the checkout that one works (Bazel before 7.4.0, an unknown release of the ruleset, an rc file, a jar the lock lists under no repository, an isolated `use_extension`). The command then exits 0 with such a warning, and beside a `pom.xml` it has still pinned or vendored the patch for the Maven build, which `vex` attests as `not_affected`. That statement is wrong for the Bazel build. It is the one hosted mode leaves there without an agent patch before it, so it is not new; it is in the docs' list of where the document is still wrong, and the action statement must not send a reader there without a word. Where the answer comes from. The table of hubs in `bazel/built.rs` decides by the project's own lock: where it lies from the project, what it lists, and whether its text names the patch. None of that fits a Maven hub. Its lock is no project's own and never names a patch (the patch of a hub is an entry of the block in the root `MODULE.bazel`), and whether a hub fetches a jar takes what `bazel/maven.rs` already reads for hosted and vendored mode: the tags that make a hub of one name, the lock in format 2 or 3 with its skipped and local artifacts, a `maven.override`, a `maven_install` of a `WORKSPACE` file, the block. A second reader could disagree with that one. So `built::unbuilt` asks `maven::upstream`, new, which reads the hubs once with `Hubs::read` and says for each jar what `Hubs::sure` and the block say: - a pinned hub fetches the plain jar at that version, every hub of the workspace was read, and the block holds no entry for the jar: the hub, for a statement that says `affected`; - anything else: nothing, and the statement stays the one of a project without Bazel. That is a jar no hub fetches, a jar the block patches, and every case in which something was not read: a hub without a `lock_file`, a tag or a lock that cannot be read, a `maven.override` of the artifact, a `maven_install` of a `WORKSPACE` file that Bazel may read, a block that was changed by hand. `Hubs::sure`, not `Hubs::built`, because a block that was changed by hand may still patch the jar, and its entries are not read. So `apply` can warn `maven_bazel_hub_unpatched` (it asks `Hubs::built`) where the document keeps `not_affected`: beside a hub that was not read. The docs say so. The warning and the statement share the check of the block (`Hubs::patches`). Two things follow from taking that reader, and the docs say both: - A `WORKSPACE` file. For the hubs of the table any such file that defines a repository leaves the statement as without Bazel. The Maven reader takes one for a doubt only when it calls `maven_install` or cannot be read, and only while the checkout names no Bazel 9 or later, which is the rule hosted mode writes its entries by. So beside a `WORKSPACE` file that defines other repositories a Maven jar is `affected`. - `m2local`. A lock with it takes a jar that no repository lists from the Maven local repository, at the lock's sha256. Such a jar counts as fetched, and its statement says `affected`: the patched jar does not have that sha256 (read from the ruleset's source at 7.2 and 6.5, not built here). The lock's sha256 is not compared with the patch. `Unbuilt::remedy` is a `String` now, since the Maven command names the package. A hosted or vendored entry of the block keeps its statement: the caller hands over no hosted pin, and a committed copy is not asked about. Nothing is read without a Maven jar among the patched packages, and nothing outside a Bazel workspace. Tests. Unit tests of `maven::upstream` (each case above; another version, a classifier and another packaging of the jar; a block's entry for another version of the artifact; a `WORKSPACE` file without `maven_install`; a jar under `m2local`) and of `built::unbuilt` on disk (the sentence, a project below the Bazel root, a committed copy, the block's entry). The two tests of the commit before now expect `affected` with the action statement. Without Bazel, each of the two modes the statement names is run after agent mode in a checkout of its own: where the command writes its entry it gives no `maven_bazel_*` warning and `vex` then says `not_affected`; in a checkout that names Bazel 7.3.0 it writes none and warns `maven_bazel_release`, and the `not_affected` that `vex` then writes is held as the known limit it is. A second test holds `vex`, with `--no-bazel` and beside four hubs of which nothing is said, to what it gives in the same checkout without `MODULE.bazel` (exit code, both streams, the document), and `apply --vex` to the line a person reads. On real Bazel the flow goes on after the documents: the hosted command pins the Maven build and the hub, the same build prints the marker of the patched jar, and `vex` says `not_affected`. Docs: the Maven cell of "Bazel workspaces: what is supported", the agent paragraph and the last limit of "Bazel workspaces: Maven", the section "Bazel workspaces: VEX" (the table of calls, the kinds of patch, the action statement and its condition, what changes nothing, what is tested, what is still wrong) and the rows `vex_bazel_not_in_build` and `maven_bazel_hub_unpatched` of the CLI contract. Two things that held before are now said. `--vex-no-bazel` is about the document, and what `scan`, `apply` and `vendor` themselves say in a Bazel workspace stays, such as `maven_bazel_hub_unpatched`: a sentence of the docs and of the contract's paragraph on the installed tree is narrowed to that. And a patch is judged only where the run found it in place, so `vex` on a machine whose installed jar is not the patched one ends as it does without Bazel. The Maven workflow names the agent flow and starts its legs on a change to the VEX code and to the two files agent mode patches a jar with. The size budget of `bazel/` follows the code (4006 to 4051 lines). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Hold every Maven patch to the Bazel hub in VEX, whichever mode holds it `vex` and `--vex` say `affected` of a Maven artifact that agent mode patched in an installed jar while a pinned rules_jvm_external hub fetches that jar from its lock. This change makes the statement hold in the cases around it where the document was still false, or said less than socket-patch knows. A patch in any mode. A hub reads no `pom.xml`, no Gradle file and no vendored tree, so a hosted pin or a vendored copy of a Maven or Gradle build is in the Bazel build only through an entry of the block in the root `MODULE.bazel`. Hosted and vendored mode write no entry where they cannot show that one works: they exit 0 with a `maven_bazel_*` warning and pin or vendor for the other build. `vex` then attested that patch as `not_affected` while the hub fetched the upstream jar, and the action statement of an agent patch sent a reader into that state. The Bazel step of `vex` now asks about every Maven patch, also one with a hosted pin or a committed copy, so the document after a command that declined still says `affected`. The statement is one for every mode: "the patch is only in what Maven or Gradle builds from", and "If what you ship is what Maven or Gradle builds and not what Bazel builds, pass `--no-bazel`". The statements of the other ecosystems are word for word what they were, and a hosted pin of another ecosystem is left alone as before. The hub that fetches the jar, not every hub. `maven::upstream` asked `Hubs::sure`, which is the rule for writing an entry: any doubt, also one about another hub, gave nothing. So beside a second hub without a lock `apply` warned that the Bazel build stays unpatched while the document of the same run said `not_affected`. It now asks `Hubs::built`: a pinned hub that was read fetches the jar, and no `maven.override` names the artifact. A block that was changed by hand may hold an entry, so it still gives nothing. An entry of this patch. Any entry of the block for the jar counted as "Bazel builds the patch". The entry of another patch than the one the document attests does not: the statement is `affected`, and names that entry first. Whether Bazel reads `MODULE.bazel`. Nothing is said where the checkout does not show that it does: `.bazeliskrc` or `.bazelversion` names a Bazel before 7.0; neither names a release while a `WORKSPACE` file defines a repository; or an rc file names an option that switches Bzlmod off or drops tags of the root, or cannot be read. Such an option is found on whatever line, so it may hold for one `--config` alone: with it neither the hub nor an entry of the block is certain, which is why an entry of hosted mode is not attested there either. Before, a checkout that switched Bzlmod off got `affected` from a file that Bazel does not read. While a release from 7.0 on is named, Maven keeps its finer rule for a `WORKSPACE` file: a `maven_install` there is another hub, and changes nothing for the hub that was read. What to do. The action statement named `get <purl> --mode hosted` whether or not that command would write an entry. `upstream` now gives the remedy with the hub. Where hosted or vendored mode writes the entry (`Hubs::label` and `settings`, as for a run) it is the command. Where they do not, it is "Hosted and vendored mode write no entry for this hub (`<code>`): <reason>.", with the code and the reason of the warning that the command gives. One helper builds the command for the statement and for the `maven_bazel_hub_unpatched` warning, from the coordinates of the jar: a purl with qualifiers (`?type=jar&...`) no longer puts `?` and `&` into a command for a shell. `"maven.install"` and the sentence moved from `bazel/built.rs` to `bazel/maven.rs` with it. `built::unbuilt` no longer parses the workspace for its table of hubs in a run that has only Maven packages. The hubs and their locks are still read once more than lock discovery reads them for the block: the two are different layers of a run, and a read is one `MODULE.bazel` with the locks it names. Tests. `maven::upstream` has one unit test with a line per case above. Without Bazel, `e2e_bazel_build` runs agent mode and then the hosted and the vendored command in three checkouts: where the command writes its entry (`not_affected` after it), and under Bazel 7.3.0 and beside a second hub without a lock (`affected` before and after, with the code and the reason in the place of the command). It holds the statement of a project without Bazel beside an rc file that names `--noenable_bzlmod` for one config, beside a `WORKSPACE` file with no release named, and under Bazel 6. No existing test expected `not_affected` for a hosted or vendored Maven patch whose hub got no entry: each of them writes the entry, and passes as it was. docs/ecosystems.md, the CLI contract and the line budget of `bazel/` (4051 to 4084 implementation lines) follow. The contract's row of `vex_bazel_not_in_build` no longer says that a `--no-bazel` run reads no Bazel file: the option is about the document, and `apply` still reads the workspace for its own warning. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Start the Maven Bazel legs for the jar manifest reader The path lists of the Maven real-Bazel workflow name the files agent mode patches a jar with, because one of its flows does that. They had `patch/jvm_jar.rs` and `patch/jar_members.rs`. The second calls `patch/jar_manifest.rs`, which was missing, so a change to how the manifest of a signed jar is rewritten did not start the legs. It is in both lists now. Two kinds of entry said nothing: `vex/**` covers `vex/discover/maven.rs` and `vex/discover/bazel_maven.rs`, and in the push list `commands/**` covers `commands/vex*.rs`. They are removed, and the comment says that lock discovery is under `vex/`. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Say affected beside what is left of a block that overrides nothing `maven::upstream` gave nothing whenever the block of `MODULE.bazel` was changed by hand, because such a block may hold an entry. For a block that can hold one, that check decided nothing: an `override_repo` outside the block as socket-patch writes it is a call the workspace reader does not follow, so no hub is read beside it, and nothing is said of any jar. What the check did decide is a block that overrides nothing any more (its first and its last line, say). That one holds no entry and the hub fetches the upstream jar: `apply` warns `maven_bazel_hub_unpatched` there, and the document said `not_affected`. The check is removed. Such a checkout gets `affected`, and the statement says why no mode patches the hub, in the words of the hosted command's warning: the block was changed by hand (`maven_bazel_unreadable`). The unit test of `upstream` holds both blocks, and the docs and the CLI contract say which one keeps the statement of a project without Bazel. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Pass over a WORKSPACE file where the checkout names Bazel 9 or later Vendored mode declines a PyPI or RubyGems package whose lock a Bazel hub reads, and it counted a call of a `WORKSPACE` file that names the lock as such a hub (`pip_parse`, `rb_bundle_fetch`). Bazel 9 never reads a `WORKSPACE` file. One that a move to Bzlmod left behind can still name `requirements.txt` or `Gemfile.lock`, so in a checkout that Bazel 9 builds, a vendored run that worked before exited 1 with `vendor_pypi_bazel_hub` or `vendor_gem_bazel_hub`, with no hub that takes the lock. Where the checkout names a Bazel release of 9 or later, a `WORKSPACE`, `WORKSPACE.bazel` or `WORKSPACE.bzlmod` file now counts for nothing in these two refusals: a call of it is no reader of the lock, a call of it that is not written out is no doubt, and neither is a file that cannot be read. The run does what it does without the file. The exception for a package that is already vendored asks the same reader, so it agrees. The release is read as the Maven reader reads it (`rc::declared_release`: `USE_BAZEL_VERSION` of `.bazeliskrc`, else `.bazelversion`, and only three numbers name one). One rule, `rc::reads_workspace_file`, holds "before 9, or not named", and the Maven reader now asks it in the place of its own closure. So a checkout that names 7.x or 8.x, `latest`, a release candidate or no release keeps the refusal: a Bazel 7 or 8 may build it. What `vex` says is not changed: `built::unbuilt` still says nothing beside a `WORKSPACE` file. Tests: unit rows in bazel/rc.rs and bazel/built.rs (the lock a call names, the call that is not written out and the file that cannot be read, under nine ways to name a release), and one test each in e2e_bazel_build/ruby.rs and pypi.rs that runs the built binary without Bazel. With `.bazelversion` 9.3.2, 9.0.0 or 10.0.0 beside a retained `WORKSPACE` that names the lock, `scan --mode vendored` vendors the package and writes the files it writes without that file; with 7.7.2, 8.8.2, no file or `latest` it is declined as before. With the rule switched off, the test of built.rs and both of those fail on their first 9.x row. docs/ecosystems.md and the contract row of the two codes say when the file counts. The `bazel` cap of scripts/loc-budget.json is the new count, 4047. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Count an entry of the block only where it reaches the hub that fetches the jar `maven::upstream` took an entry of the patch in the block of `MODULE.bazel` for "Bazel builds the patch" and said nothing of the jar, so `vex` attested `not_affected`. It did not ask whether the entry's `override_repo` reaches the hub. The block overrides a repository of the shared usage of the ruleset's extension, which reaches no hub whose `use_extension` is an isolated one (`isolate = True`). `Hubs::label`, by which hosted and vendored mode write an entry, declines such a hub, but it was asked only where the block holds no entry. Measured on Bazel 9.3.2 with a temporary flow: after the hosted command wrote its entry, the hub's `use_extension` was given `isolate = True`. Under `--experimental_isolated_extension_usages`, without which Bazel does not take `isolate` at all, the build passes with the entry in place and `//:consumer` prints the upstream jar. The document said `not_affected` of it. An entry of the patch now counts only where no pinned hub that fetches the jar is on an isolated usage. Otherwise the statement is `affected` for that hub, also where another hub does take the entry. It says first that "the entry that MODULE.bazel holds for this patch does not reach this hub", and then why hosted and vendored mode write none that does, with the code and the reason of their warning (`maven_bazel_unreadable`), as for the other declines. Only what is certain. `Hub::proxy` is `None` for a usage that is isolated and for one that cannot be read: an `isolate` that is neither `True` nor `False`, a label that is no plain string. The second kind may be a shared usage, which the entry reaches. So the reader keeps the two apart (`Hub::isolated`: each tag of the hub is on a usage with `isolate = True`), and beside a usage that cannot be read the entry stands and the statement stays `not_affected`. Without an entry nothing changes: the hub fetches the upstream jar whatever its usage is, and the statement was `affected` already. Tests. The unit test of `upstream` has the rows: an entry beside an isolated hub, beside a usage that cannot be read, beside two hubs of which one is isolated (that one is named), and a hub with tags on both kinds of usage. Without Bazel, `e2e_bazel_build` runs the hosted and the vendored command, sees `not_affected`, makes the hub's usage an isolated one and sees `affected` with those words. Every existing test of an entry that reaches its hub passes unchanged. The line budget of `bazel/` goes from 4084 to 4096. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Hold the Maven statement to the switch for a project that Bazel does not build Main gained `SOCKET_NO_BAZEL`, which makes every command do what it does for a project in no Bazel workspace, and this branch gained a statement that a Maven patch gets from any project of the workspace: a `maven_install.json` names no project, so a Maven service that Bazel does not build is `affected` too, beside a hub that pins the same artifact. That is the project the switch is for. The judgement goes through the workspace lookup, so the switch already turns it off. A test now holds it: beside the hub that fetches the jar, `apply --vex` with `SOCKET_NO_BAZEL=1` is the run of the same checkout without its Bazel files, in exit code, output and files, and is not the run beside the hub. The docs say it in both places: the list of what a Bazel workspace changes for a project names the Maven statement, and the Maven limits name the switch beside `--no-bazel`. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
1 parent c1489a1 commit 4ecfd4f

8 files changed

Lines changed: 1140 additions & 143 deletions

File tree

‎.github/workflows/bazel-maven.yml‎

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ name: Bazel patch compatibility (Maven)
1212
# mode that repository is a directory of the checkout with the committed
1313
# jar: the flows hold the build from the checkout alone with no host to
1414
# ask, the audit of the committed jar, the undo, and the way from hosted
15-
# to vendored and back. bazel-compatibility.yml holds the legs and what
15+
# to vendored and back. Agent mode patches the jar in the Maven local
16+
# repository and no hub: its flow holds the build to the upstream jar,
17+
# every VEX document to `affected` with the command that patches the hub,
18+
# and after that command the build and the document to the patched jar.
19+
# bazel-compatibility.yml holds the legs and what
1620
# every ecosystem
1721
# shares; this file says when the Maven legs run and on which releases.
1822
#
@@ -62,15 +66,20 @@ on:
6266
# rewriter's index of a pom, the model of what Maven selects with the
6367
# pom walk under it (the hosted lane pins only where Maven selects the
6468
# patch's version), the crawler that says where the Maven local
65-
# repository is, lock discovery and the upstream restore of `rollback`
69+
# repository is, the upstream restore of `rollback`
6670
# (for a pom and for the block of MODULE.bazel), the vendored Maven
6771
# backend, which writes the hub's jar and its entry, the dispatch that
6872
# hands a vendored command the hub's declines (vendor/refusals.rs), and what
6973
# socket-patch reads and writes only in a Bazel workspace (`bazel/`: the
7074
# hubs of MODULE.bazel, their locks and the block). Nothing another
7175
# ecosystem's flow owns is here but that dispatch, which the Composer
7276
# legs watch too, so a change to one ecosystem starts that ecosystem's
73-
# legs only.
77+
# legs only. Last, what the agent flow runs through: the three files
78+
# with which agent mode patches a jar, and the VEX code (`vex/` of the
79+
# core, where lock discovery is too, and the files of the `vex`
80+
# command). That flow holds the exact
81+
# document socket-patch writes about its build, so a change to how a
82+
# document is built or worded starts the legs of every ecosystem.
7483
#
7584
# What it does not cover: shared engine code (`rewrite_maven_pom` is in
7685
# patch/redirect/mod.rs, the file of every ecosystem's rewriter; hosted/,
@@ -92,13 +101,16 @@ on:
92101
- 'crates/socket-patch-core/src/crawlers/maven_selection.rs'
93102
- 'crates/socket-patch-core/src/crawlers/maven_scope.rs'
94103
- 'crates/socket-patch-core/src/crawlers/maven_crawler.rs'
95-
- 'crates/socket-patch-core/src/vex/discover/maven.rs'
96-
- 'crates/socket-patch-core/src/vex/discover/bazel_maven.rs'
97104
- 'crates/socket-patch-core/src/patch/redirect/upstream/maven.rs'
98105
- 'crates/socket-patch-core/src/patch/redirect/upstream/bazel_maven.rs'
99106
- 'crates/socket-patch-core/src/vendor/maven_repo.rs'
100107
- 'crates/socket-patch-core/src/vendor/refusals.rs'
101108
- 'crates/socket-patch-core/src/bazel/**'
109+
- 'crates/socket-patch-core/src/patch/jvm_jar.rs'
110+
- 'crates/socket-patch-core/src/patch/jar_members.rs'
111+
- 'crates/socket-patch-core/src/patch/jar_manifest.rs'
112+
- 'crates/socket-patch-core/src/vex/**'
113+
- 'crates/socket-patch-cli/src/commands/vex*.rs'
102114
push:
103115
branches: [main]
104116
# The pull request paths, and what only a push to main covers: the
@@ -120,13 +132,15 @@ on:
120132
- 'crates/socket-patch-core/src/crawlers/maven_selection.rs'
121133
- 'crates/socket-patch-core/src/crawlers/maven_scope.rs'
122134
- 'crates/socket-patch-core/src/crawlers/maven_crawler.rs'
123-
- 'crates/socket-patch-core/src/vex/discover/maven.rs'
124-
- 'crates/socket-patch-core/src/vex/discover/bazel_maven.rs'
125135
- 'crates/socket-patch-core/src/patch/redirect/upstream/maven.rs'
126136
- 'crates/socket-patch-core/src/patch/redirect/upstream/bazel_maven.rs'
127137
- 'crates/socket-patch-core/src/vendor/maven_repo.rs'
128138
- 'crates/socket-patch-core/src/vendor/refusals.rs'
129139
- 'crates/socket-patch-core/src/bazel/**'
140+
- 'crates/socket-patch-core/src/patch/jvm_jar.rs'
141+
- 'crates/socket-patch-core/src/patch/jar_members.rs'
142+
- 'crates/socket-patch-core/src/patch/jar_manifest.rs'
143+
- 'crates/socket-patch-core/src/vex/**'
130144
- 'crates/socket-patch-cli/tests/e2e_bazel_build/main.rs'
131145
- 'crates/socket-patch-core/src/patch/redirect/**'
132146
- 'crates/socket-patch-core/src/hosted/**'

‎crates/socket-patch-cli/CLI_CONTRACT.md‎

Lines changed: 3 additions & 3 deletions
Large diffs are not rendered by default.

‎crates/socket-patch-cli/src/commands/vex.rs‎

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1916,17 +1916,13 @@ const BAZEL_NOT_IN_BUILD: &str = "vex_bazel_not_in_build";
19161916
const AFFECTED_REASON: &str = "attested as affected, not as patched: Bazel does not build the \
19171917
patched copy of this package; the run warning names what it builds from";
19181918

1919-
/// The closing sentence of the action statement, and so of the run warning,
1920-
/// of a package that is affected because its patch is in the installed copy
1921-
/// alone.
1922-
const INSTALLED_TREE_SHIPS: &str = "If what you ship is the installed tree and not what Bazel \
1923-
builds, pass `--no-bazel` (`--vex-no-bazel` on scan, apply and vendor).";
1924-
19251919
/// In a Bazel workspace, a hub of aspect_rules_js, rules_python,
1926-
/// rules_ruby, rules_rust or rules_csharp builds a package from the lock a
1927-
/// workspace file names, never from the copy a package manager installed,
1928-
/// and rules_python builds nothing from a line that points at a copy under
1929-
/// `.socket/vendor` ([`socket_patch_core::bazel::built`]). A patch that is
1920+
/// rules_ruby, rules_rust, rules_csharp or rules_jvm_external builds a
1921+
/// package from the lock a workspace file names, never from the copy a
1922+
/// package manager installed (a jar of the Maven local repository only at
1923+
/// the lock's sha256), and rules_python builds nothing from a line
1924+
/// that points at a copy under `.socket/vendor`
1925+
/// ([`socket_patch_core::bazel::built`]). A patch that is
19301926
/// only in such a copy is in no build of Bazel's, so its package is not
19311927
/// attested as patched: it leaves `outcome.applied` and is returned with
19321928
/// what to do about it, for statements that say `affected`
@@ -1941,6 +1937,10 @@ const INSTALLED_TREE_SHIPS: &str = "If what you ship is the installed tree and n
19411937
/// be read with certainty: the statement stays the one of a project
19421938
/// without Bazel. So is a patch whose record names no advisory: no run
19431939
/// writes a statement for it, and it is left out for that reason alone.
1940+
/// A Maven patch is asked about whichever mode recorded it: no file of a
1941+
/// project decides what a rules_jvm_external hub fetches, so a pin of a
1942+
/// `pom.xml` or a Gradle file, and a copy vendored for such a build, are
1943+
/// in the Bazel build only through an entry of the root `MODULE.bazel`.
19441944
///
19451945
/// With `--no-bazel` / `--vex-no-bazel` (`params.no_bazel`) the user has
19461946
/// said that the document is about the installed tree, which is what the
@@ -1964,7 +1964,8 @@ async fn unbuilt_by_bazel(
19641964
}
19651965
let patched = |purl: &String| {
19661966
let record = plan.view.patches.get(purl)?;
1967-
let judged = !plan.hosted.contains_key(purl) && !record.vulnerabilities.is_empty();
1967+
let pinned = plan.hosted.contains_key(purl) && !purl.starts_with(MAVEN);
1968+
let judged = !pinned && !record.vulnerabilities.is_empty();
19681969
judged.then(|| Patched {
19691970
purl: purl.clone(),
19701971
uuid: record.uuid.clone(),
@@ -1989,32 +1990,49 @@ async fn unbuilt_by_bazel(
19891990
affected
19901991
}
19911992

1993+
/// The start of a Maven purl.
1994+
const MAVEN: &str = "pkg:maven/";
1995+
19921996
/// The action statement for `package`, whose patch Bazel does not build:
19931997
/// what `call` builds the package from, and what to run so that the build
19941998
/// holds the patch. For an installed copy that is the hub's own remedy
19951999
/// ([`Unbuilt::remedy`]). Hosted and vendored mode write in the project
1996-
/// they run in, so it names the directory of the lock.
2000+
/// they run in, so it names the directory of the lock, and for a Maven jar
2001+
/// the Bazel root, where the patch of a hub is written, or what keeps
2002+
/// those modes from writing it.
19972003
///
19982004
/// For an installed copy it ends with the way out of a repository that
19992005
/// ships the installed tree and keeps the hub for something else: the
20002006
/// option, in both spellings, since the statement is the same whichever
2001-
/// command wrote the document. Not for a committed PyPI copy: there the
2007+
/// command wrote the document. A Maven patch has the same statement in
2008+
/// every mode, a committed copy included, in words that hold for each:
2009+
/// the patch is in what Maven or Gradle builds from, and that build is
2010+
/// what such a repository ships. Not for a committed PyPI copy: there the
20022011
/// build is broken or takes the registry's package, and the installed tree
20032012
/// is not the patched one either.
20042013
fn bazel_build_action(package: &Patched, call: &Unbuilt) -> String {
2005-
let Patched { uuid, pins, .. } = package;
2014+
let Patched { purl, uuid, pins } = package;
20062015
let Unbuilt {
20072016
call: tag,
20082017
file,
20092018
line,
20102019
lock,
20112020
remedy,
20122021
} = call;
2013-
match pins {
2022+
let maven = purl.starts_with(MAVEN);
2023+
let (only, ships) = match maven {
2024+
true => (
2025+
"what Maven or Gradle builds from",
2026+
"what Maven or Gradle builds",
2027+
),
2028+
false => ("the installed copy", "the installed tree"),
2029+
};
2030+
match pins.as_ref().filter(|_| !maven) {
20142031
None => format!(
20152032
"Bazel builds this package from {lock} (`{tag}`, {file}:{line}), which does not \
2016-
name Socket patch {uuid}: the patch is only in the installed copy. {remedy} \
2017-
{INSTALLED_TREE_SHIPS}"
2033+
name Socket patch {uuid}: the patch is only in {only}. {remedy} If what you ship \
2034+
is {ships} and not what Bazel builds, pass `--no-bazel` (`--vex-no-bazel` on scan, \
2035+
apply and vendor)."
20182036
),
20192037
Some(_) => format!(
20202038
"Bazel builds no package from the line of {lock} that points at the copy of Socket \

‎crates/socket-patch-cli/tests/e2e_bazel_build/harness.rs‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,7 +1726,7 @@ impl Cell {
17261726

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

17581759
let again = self.document("apply");
17591760
let apply = run(self, &[&["apply"][..], &with_vex(&again)].concat());

0 commit comments

Comments
 (0)