Skip to content

Assert the VEX document in the Bazel flows that build patched - #2139

Merged
Mikola Lysenko (mikolalysenko) merged 8 commits into
mainfrom
bazel-vex/01-assert-document
Nov 19, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 8 commits into
mainfrom
bazel-vex/01-assert-document

Conversation

@mikolalysenko

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

Copy link
Copy Markdown
Collaborator

No user-visible change.

What this is

The first pull request of VEX support under Bazel. It holds tests, one docs section and four workflow path lists. No file under crates/*/src changes: git diff --name-only against the base lists none.

Stacked on #2123 (the vendored and agent Go flows on real Bazel, and the .bazelignore fix). The base of this pull request is that pull request's branch, so the diff here is this pull request's two commits: the assertions, and what a code review of them changed (see "Code review"). It moves onto main when #2123 has landed.

socket-patch vex, and --vex on scan and apply, read what socket-patch wrote and what the project's own package manager installed. They read no MODULE.bazel, WORKSPACE or BUILD file. So in a Bazel workspace a document says what was patched, and that is what Bazel builds only where Bazel builds from the files socket-patch rewrote. Elsewhere a document can say not_affected for a package that Bazel builds unpatched. Before the product is changed to tell the two apart, this pull request records on real Bazel where the document and the build agree today, and fixes what must stay the same for a project that Bazel does not build.

Contents

File Lines What
crates/socket-patch-cli/tests/e2e_bazel_build/harness.rs +386 −7 What a document must say (Claim, How), the arguments of the forms, a place for documents beside the workspace copy, a checkout that Bazel has not built in (Cell::unbuilt; Cell::twin now uses it), the six checks the flows share, the two comparisons they rest on (wording of two documents, undated of two trees) and a hermetic test of those two
.../e2e_bazel_build/go.rs +73 −14 The checks in the hosted flow and in the vendored and agent flow; the fixture check holds the product of go.mod
.../e2e_bazel_build/npm.rs +65 −33 The checks in the hosted and the vendored flow; the looser vex check that was there is replaced; the fixture check holds the product of package.json
.../e2e_bazel_build/pypi.rs +24 −3 The checks in the hosted flow
.../e2e_bazel_build/ruby.rs +25 −3 The checks in the hosted flow
.../e2e_bazel_build/main.rs +17 Module docs
crates/socket-patch-cli/tests/e2e_vex_lockfile/bazel_beside.rs +213 (new) Two hermetic tests: beside a Bazel workspace that does not build the project, vex says what it says without Bazel
.../e2e_vex_lockfile/main.rs +1 The new module
docs/ecosystems.md +35 Section "Bazel workspaces: VEX"
.github/workflows/bazel-{go,npm,pypi,ruby}.yml +54 −22 Pull request and push paths gain crates/socket-patch-core/src/vex/** and crates/socket-patch-cli/src/commands/vex*.rs; the comment of each list says why

Product code: 0 lines. Tests: +804 −60. Docs: +35. Workflows: +54 −22. Fixtures: 0. Of that, the review commit is tests +223 −33, docs +4 −1 and workflows +54 −26.

What it proves, and where

Each of the eight flows whose Bazel build is patched now also asserts the VEX document, in nine places:

  1. The command of the mode, given --vex, writes the document of its own run, in the checkout Bazel has already built in.
  2. vex writes one after that command, before the patched build.
  3. vex writes one after the patched build.
  4. vex --no-verify writes one.
  5. After the undo vex writes none and removes the last one.
  6. In a checkout with the same files that Bazel has not built in, the command with --vex writes the same document, and it leaves the files of the checkout that built patched, byte for byte but for one field: vendoredAt, the time in the marker file of a vendored copy (socket-patch.vendor.json).
  7. vex writes the same document there.
  8. The documents are held to each other. Every document read in a checkout must equal the first one read there in every string but the document id, the timestamps and the ; not verified on disk mark of --no-verify, and the documents of the checkout Bazel has not built in must equal those of the one it has.
  9. vex --output <file> with no --product, as a user types it, runs once after the patched build, beside Bazel's links.

A document is held to exactly one statement: not_affected, inline_mitigations_already_exist, the advisory of the patch record, the package as the one subcomponent of the product, and an impact statement that names the patch of this run. The patch id is new for every run, so no document of an earlier run can pass. The envelope is held to its exit code, its one verified event and its exact list of warnings. Every form but the run of item 9 is told one product.

Flow Impact statement After the undo
Go, hosted, gazelle go_deps.from_file Patched via Socket patch <id> (redirected) exit 2, manifest_not_found
Go, vendored ... <id> (vendored) exit 2, manifest_not_found
Go, vendored, the module ships a BUILD file ... <id> (vendored) exit 2, manifest_not_found
Go, agent mode (also from apply --vex) Patched via Socket patch <id> exit 1, no_patches (the rollback keeps its emptied manifest)
npm, hosted, aspect_rules_js npm_translate_lock (also from the second scan) ... <id> (redirected) exit 2, manifest_not_found
npm, vendored (also from the second scan, which reports already_vendored) ... <id> (vendored) exit 2, manifest_not_found
PyPI, hosted, rules_python pip.parse ... <id> (redirected) exit 2, manifest_not_found
RubyGems, hosted, rules_ruby bundle_fetch without gem_checksums ... <id> (redirected) exit 2, manifest_not_found

Under --no-verify each impact statement ends with ; not verified on disk, and the run warns vex_not_verified.

Without --product (item 9):

Flows What vex does
npm, both exit 0, no warning, the same document for pkg:npm/socket-fixture@0.0.0: the name and the version of the checkout's own package.json, which Bazel's links show a second time
Go, all four exit 0, no warning, the same document for pkg:golang/example.com/consumer: the module of the checkout's own go.mod, which records no version
PyPI, RubyGems exit 2, product_undetected, no document: the fixtures have no file a product is read from

At the head of this pull request the Go and npm flows pass on Bazel 9.3.2, 8.8.2 and 7.7.2, and the PyPI and RubyGems flows on 9.3.2, on macOS arm64, run the way the workflow's run step runs them. The PyPI and RubyGems flows passed on 8.8.2 and 7.7.2 at the first commit and were not run again after the review commit. Seconds per test, from one loaded machine:

Test 9.3.2 8.8.2 7.7.2
go::hosted_go_deps 77 59 57
go::vendored_go_deps 59 60 42
go::agent_go_deps 76 60 50
go::vendored_go_deps_module_with_a_build_file 60 60 41
npm::hosted_npm_translate_lock 33 17 18
npm::vendored_npm_translate_lock 27 18 18
pypi::hosted_pip_parse 20 21 (first commit) 23 (first commit)
ruby::hosted_bundle_fetch 34 44 (first commit) 44 (first commit)

The socket-patch runs the first commit added take 0.2 to 0.5 seconds per test; the review adds one more vex run per flow, which was not timed on its own. On Linux, on GitHub's runners, all twelve Bazel legs of this pull request pass at its head (Go, npm, PyPI and RubyGems on Bazel 9.3.2, 8.8.2 and 7.7.2; 95 to 280 seconds per leg), with the other 59 checks.

Each check was shown to bite on Bazel 9.3.2. With each of these changes all eight tests fail: a document expected to hold two statements; the patch id of another run expected; vex skipped where an earlier document is at the path, with the check of its document kept; the "no document" check moved before the undo. The mutations of what the review added are under "Code review".

The new hermetic module holds what later changes must keep. A pnpm project in web/ sits beside a root MODULE.bazel (with a BUILD.bazel) or a root WORKSPACE that builds Java and names none of the project's files. For a hosted pin and for a patch in node_modules, vex --json, vex and apply --vex give the exit code, both output streams and the document they give in the same checkout without Bazel, byte for byte after the path of the checkout and the timestamps are replaced; each form is told the id of its document (--doc-id, and --vex-doc-id for apply). The comparison bites: with another pin or another installed file beside Bazel only, both tests fail. These tests are part of the workspace tests. On a pull request that is not a draft the Linux leg runs them (the coverage job of ci.yml); a draft runs none, and the Windows and macOS legs run in the nightly schedule and on dispatch. A later change that makes one fail, or that needs an edit to that file, has changed the answer for a project Bazel does not build.

What it shows about the release

  • In these eight shapes the document is right in every form, on all three Bazel releases: the build prints the patched package, and the document names that package and that patch. No expectation had to follow a wrong document.
  • The forms spell everything alike. The document of the run, of vex and of vex --no-verify, in the checkout Bazel has built in and in the one it has not, name the product, the package, the advisory with its aliases and the status with the same strings; for npm every form writes the scope as %40. No expectation had to differ per form.
  • The document does not depend on whether Bazel has built: a checkout Bazel has built in and one it has not give the same statement.
  • Without --product, vex beside Bazel's links finds the product of the project's own package.json or go.mod and no second one behind the links. Where a checkout has no such file it writes no document and says which option to pass.
  • For a hosted pin no form hashes a file. The patched bytes come with the next build, and vex never reads Bazel's output, so 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 patched build or after it. Both are now asserted.
  • vex reads no Bazel file. With Bazel files that do name the project's lock, the output is the same as without Bazel today, also for a patch that is only in node_modules, which rules_js never builds. That is why the docs now list the shapes that are tested and the ones measured to be wrong.

Code review

A review of the first commit found eight things. The second commit, "Hold the VEX documents of the Bazel flows to each other after review", holds what changed: tests, one docs sentence and the workflow path lists.

  • No document was compared with another. Each was checked alone, and its package through a normalising function, so the %40 and the @ spelling of an npm scope both passed. Now the documents are held to each other (items 6 to 8); the check of each document alone is unchanged. On Bazel 9.3.2: with the @ spelling in the stand-alone document both npm flows fail; with another alias of the advisory there, a field no single-document check reads, all eight fail; with the documents of the unbuilt checkout worded apart, alike among themselves, all eight fail.
  • The docs listed PyPI under pip.parse without the stale lock. "Bazel workspaces: VEX" now 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 a build that may update the lock has run, and the updated lock has to be committed. The PyPI flow already asserts both.
  • A pull request that changes VEX code started no Bazel leg. The first commit added crates/socket-patch-core/src/vex/** to the push lists only, while the flows hold exact VEX output. That pattern and crates/socket-patch-cli/src/commands/vex*.rs (it matches vex.rs, vex_consumed.rs and vex_sources.rs, the files of the command, and nothing else) are now in the pull request list and the push list of all four callers. Each pull request list is still a subset of its push list, and its comment says that VEX code starts the legs of every ecosystem because the flows hold the document. actionlint and scripts/check-tool-pins.py pass.
  • vex without --product no longer ran in a checkout Bazel has built in. It runs once per flow after the patched build (item 9 and its table). The outcome was measured first with one run per ecosystem and is asserted in all eight flows, in two to four lines each. On 9.3.2: with another product expected all eight fail, and so do the two fixture checks that hold the product names to package.json and go.mod; with the run given a product after all, the npm, PyPI and RubyGems flows fail (not run on Go).
  • The marker of a vendored copy was left out of the comparison whole. It is compared as JSON without vendoredAt, its one time field, so another purl, patch id or advisory in it fails. On 9.3.2: with another advisory in the marker of the unbuilt checkout the three vendored flows fail (npm vendored, both Go vendored); under the filter of the first commit the same marker passes (run on npm), which was the gap.
  • The hermetic module had not run on Windows, and this description said pull-request jobs run on Linux. Corrected here, and a Windows run was started by dispatch: both tests pass there (see "Not claimed"). The tests are not gated off Windows.
  • The ; not verified on disk mark was hard-coded. The harness uses the constant the product exports, socket_patch_core::vex::NOT_VERIFIED_SUFFIX. With the mark expected on the verified forms instead, the PyPI flow fails. Left open: the other strings of a document that the harness spells out (the context URL, not_affected, inline_mitigations_already_exist, Patched via Socket patch, (redirected), (vendored), openvex-0.2.0).
  • A hand-written lock and regular expressions compiled per call in bazel_beside.rs. vex has an option that pins the document id, so each form is told one (--doc-id, --vex-doc-id) and the id is no longer rewritten in the output; one of the two expressions is gone. Without the option on the first form both tests fail. Left open: the hand-written pnpm lock, and the expression for timestamps, still compiled per call.

A hermetic test in the harness holds the two comparisons themselves: two spellings of a scope are two wordings, a marker that names another package is another tree, and no other file is read for a time. It fails when wording also drops the products and when undated also drops the purl.

Gate at the head: cargo fmt --check; cargo clippy --workspace --all-features -- -D warnings; clippy on the e2e_bazel_build target; that target without Bazel (28 passed, 8 ignored); the two hermetic tests of bazel_beside; --test cli --test spawn_env_hygiene (98 and 21 passed); actionlint and scripts/check-tool-pins.py on the four callers. One pattern in the Go lists matches no tracked file, crates/*/src/**/*golang*/**; main has it there and in go-compatibility.yml, and this pull request leaves it as it is.

Not claimed

  • Nothing for real Bazel on Windows: those tests are Unix-only. The two hermetic tests of bazel_beside pass on Windows, in a run of the workspace tests started by dispatch on this branch (run 44407451977). 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 (lib/python3.12/site-packages), which is not where a Windows virtualenv keeps its packages.
  • macOS on a GitHub runner: the macOS legs run nightly and on dispatch, not on a pull request.
  • PyPI and RubyGems on Bazel 8.8.2 and 7.7.2 after the review commit. The mutations of what the review added ran on 9.3.2 only.
  • Nothing outside the eight shapes: no WORKSPACE shape, no other ruleset or ruleset version than the fixtures', no Bazel release but the three, no Gemfile.lock without a CHECKSUMS section.
  • vex without --product in a checkout that has a git origin remote. Detection reads that remote first, and the workspace copies of the flows are in no git checkout. A run of these tests with the temp directory inside a clone would detect the clone's remote and fail item 9.
  • Not that vex checked the bytes Bazel built. The marker the build prints and the document are two observations of one checkout.
  • The runs used the product code of main with Keep Go module copies under .socket out of Bazel packages #2123, built from this branch, not the published 5.1.0 binary.
  • The seconds are from one machine that was busy with other work; identical runs differed by up to a factor of two.

What follows

  1. Withhold the statement, with a warning that names the Bazel file and what to do, where a Bazel module hub does not build the patched copy (a patch in node_modules, a virtualenv or a gem home; a vendored PyPI or gem artifact), and where a lock that Bazel reads holds the package without the patch.
  2. The same answers under WORKSPACE files, and for Go where a go_repository rule supplies the module or gazelle may select another version.
  3. Count a hosted pin only when the lock pins the patch's own bytes, report hubs that cannot be read as not verified, judge a gem by its gem_checksums entry, and then Maven, Cargo and NuGet.

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>
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review November 18, 2026 22:01
@cursor

cursor Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Changes are confined to tests, workflow path filters, and documentation; no runtime VEX or Bazel behavior is modified in this diff.

Overview
Adds test-only coverage so Bazel patch compatibility flows prove OpenVEX output matches patched builds—and documents where that holds. No application src changes.

The Bazel e2e harness gains shared VEX checks (Claim / How, --vex wiring, documents outside the workspace copy, Cell::unbuilt, and comparisons that ignore ids, timestamps, and NOT_VERIFIED_SUFFIX). Go, npm, PyPI, and Ruby flow tests now exercise --vex on scan/apply, stand-alone vex (with and without --no-verify / --product), rollback “no document” behavior, and parity between Bazel-built and never-built checkouts.

New hermetic bazel_beside tests lock in that vex beside a Java-only Bazel workspace matches a plain checkout. Docs add a “Bazel workspaces: VEX” section (agreement shapes, stale MODULE.bazel.lock, known mismatches). CI path filters on bazel-{go,npm,pypi,ruby}.yml now include vex/** and vex*.rs so VEX wording/build changes re-run every ecosystem leg.

Reviewed by Cursor Bugbot for commit d12790f. Configure here.

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: review brief for the approver

What it does. Each of the eight real-Bazel flows (Go, npm, PyPI, Ruby) now checks the full OpenVEX document at about nine points:

  • the run's own --vex document, and vex before and after the patched build;
  • vex --no-verify, and vex without --product;
  • no document after the undo;
  • a checkout Bazel never built in.

A new hermetic test shows vex gives byte-identical output whether or not a Bazel workspace sits beside a pnpm project. Only tests, docs and the workflows' path lists change.

Risk: low. No product code changes. The real-Bazel flows are #[ignore] and cfg(unix), and the new hermetic tests pass. The workflows only gain two path globs each; no new tool, action SHA or permission is added.

Stacked: the base is bazel-small/21-go-bazelignore (#2123), which carries agent:needs-human. This should land after #2123. I left auto-merge off, because an approval would otherwise squash it into #2123's branch rather than main.

Look here

  • [crates/socket-patch-cli/tests/e2e_bazel_build/harness.rs:1093](https://github.com/SocketDev/socket-patch/blob/d12790ff5c9c4457a9405f371507487686ac3d46/crates/socket-patch-cli/tests/e2e_bazel_build/harness.rs#L1093) attests: an exact match on context, status, justification, products and impact statement.
  • crates/socket-patch-cli/tests/e2e_bazel_build/harness.rs:187 wording: strips only ids, timestamps and the no-verify suffix.
  • [crates/socket-patch-cli/tests/e2e_bazel_build/harness.rs:1166](https://github.com/SocketDev/socket-patch/blob/d12790ff5c9c4457a9405f371507487686ac3d46/crates/socket-patch-cli/tests/e2e_bazel_build/harness.rs#L1166) detects_product.
  • [crates/socket-patch-cli/tests/e2e_vex_lockfile/bazel_beside.rs:126](https://github.com/SocketDev/socket-patch/blob/d12790ff5c9c4457a9405f371507487686ac3d46/crates/socket-patch-cli/tests/e2e_vex_lockfile/bazel_beside.rs#L126) says_the_same_beside_bazel.
  • docs/ecosystems.md:2276 "Bazel workspaces: VEX".

Verified

Changes I made: none.

Open questions (minor, none blocking):

  • detects_product (item 9) relies on the temp workspace not sitting inside a git clone with an origin remote. Should it pin TMPDIR so a local run with TMPDIR inside a clone can't fail falsely?
  • Nits: bazel-pypi.yml still lists vex/discover/pypi_other.rs, which the new vex/** glob already covers. docs/ecosystems.md also has an odd line break around line 2304.

Generated by Claude Code

@mikolalysenko Mikola Lysenko (mikolalysenko) added the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Nov 19, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[agent] Reviewed at d12790f. No product source changes. The new assertions are not vacuous: attests exact-matches the whole statement including the per-run patch id, and the hermetic self-test shows wording still tells two purl spellings and two patch ids apart. All 12 real-Bazel legs passed on this head. Non-blocking: detects_product may fail falsely on a local run when TMPDIR sits inside a git clone with an origin remote (not reproduced). Lands after #2123.

Base automatically changed from bazel-small/21-go-bazelignore to main November 19, 2026 20:40
…ocument

# Conflicts:
#	.github/workflows/bazel-go.yml
#	crates/socket-patch-cli/tests/e2e_bazel_build/go.rs
#	crates/socket-patch-cli/tests/e2e_bazel_build/harness.rs
Merged via the queue into main with commit 821f97e Nov 19, 2026
79 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the bazel-vex/01-assert-document branch November 19, 2026 21:00
Mikola Lysenko (mikolalysenko) pushed a commit that referenced this pull request Nov 19, 2026
The parent branches landed on main as squash commits (#2123, #2139,
#2148), so this re-applies only this PR's own changes on top of main.

main (#2155) turned build_document_with into the one builder, taking an
Attested struct and adding code_not_present; this PR had added a
separate build_document_with_affected. The affected PURLs are now an
`affected` field of Attested, handled by build_document_with:

- an affected PURL still gets a statement of its own with status
  `affected` and its action statement;
- a not_affected statement keeps main's justification rule
  (vulnerable_code_not_present only when no subcomponent is patched);
- `vex` passes both code_not_present and affected.

Tests of the affected statements now go through build_document_with.
CLI_CONTRACT.md keeps main's folded warning text and adds this PR's
partialFailure-on-affected sentence. The bazel LOC budget is main's
plus this PR's growth.

Assisted-by: Claude Code:claude-opus-5-5
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.

2 participants