Repository navigation
Make vendored mode work for a NuGet package of a rules_csharp hub, or decline it - #2223
Conversation
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>
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>
…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>
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
…b on real Bazel
Tests only. rules_csharp's `nuget.from_lock` downloads every package of
`packages.lock.json` from the package sources of `nuget.config` and holds
each file to the lock's `contentHash`. The real-Bazel NuGet flows ran
hosted mode in that workspace, and vendored mode in none.
nuget::vendored_from_lock records what vendored mode does there today, on
the machine that restored the project:
- `scan --mode vendored --yes` exits 0 with status `success` and reports
the package vendored. It downloads the patched package from the patch
service once and keeps it at
`.socket/vendor/nuget/<uuid>/<id>.<version>.nupkg`, names that folder
as a package source in `nuget.config`
(`<add key="socket-patch-<uuid>" value=".socket/vendor/nuget/<uuid>" />`,
with a source mapping) and re-pins the lock to the patched package.
`vex` attests the package.
- The next `bazel build` fails. NuGet takes a folder as a package source;
the hub reads the same line as the URL of a feed. Bazel 9.3.2 crashes in
the module extension (exit 37, "NullPointerException thrown during
Starlark evaluation"); Bazel 8.8.2 and 7.7.2 refuse the URL ("Bad URL:
.socket/vendor/nuget/<uuid>"). Bazel asks no host for the package and
changes no file.
- `vendor --revert` puts every file back, and the build with them.
The flow records a defect: a command that exits 0 leaves a build broken.
It is here so that the change which removes the defect shows as a change
of this test's expectations.
The grant names the patched package by its URL on the patch host, and
vendored mode downloads it itself, so the flow passes `--patch-server-url`
with the loopback stand-in, which serves the package under the path of
that URL. No build and no command reaches nuget.org or a Socket host.
Run on Bazel 9.3.2, 8.8.2 and 7.7.2 on macOS arm64: the flow passes on
each, in about ten seconds. The workflow's comments name the flow.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… decline it
Vendored mode commits the patched package under
`.socket/vendor/nuget/<uuid>/`, names that folder as a package source in
`nuget.config` and re-pins the lock. NuGet takes a folder as a source.
rules_csharp's `nuget.from_lock` reads the same line as the URL of a feed:
after `scan --mode vendored` had exited 0 and reported the package
vendored, the next `bazel build` crashed Bazel 9.3.2 in the module
extension (exit 37) and failed on 8.8.2 and 7.7.2 with `Bad URL:
.socket/vendor/nuget/...`. That is the flow of the previous commit.
What the hub does take
A feed `file:<folder>`, which Bazel reads from the root of the workspace,
with the package at `<folder>/<id>/<version>/<id>.<version>.nupkg`; and
the last `nuget.from_lock` that has `feeds` decides the hub's sources
(`_nuget_impl` in csharp/extensions.bzl at 0.5.0). So in the root of a
Bazel workspace whose one `nuget.from_lock` reads the project's lock,
`scan --mode vendored`, `get --mode vendored` and `vendor` now write:
- the package at
`.socket/vendor/nuget/<uuid>/<idLower>/<version>/<idLower>.<version>.nupkg`,
the one copy;
- `nuget.config` with that directory as the source, so `dotnet restore`
outside Bazel takes the same file, and the lock as before;
- one block at the end of the root `MODULE.bazel`, after one blank line:
# >>> socket-patch: NuGet patches for Bazel (managed block: socket-patch writes and removes it) >>>
socket_patch_nuget = use_extension("@rules_csharp//csharp:extensions.bzl", "nuget")
socket_patch_nuget.from_lock(
feeds = [
"file:.socket/vendor/nuget/<uuid>",
"https://api.nuget.org/v3/index.json",
],
packages_lock_json = "//:packages.lock.json",
)
# <<< socket-patch <<<
A second tag of the same hub, after every tag of the user's: the folder
of each vendored patch, then the sources the hub had without the block
(those of the tag's `nuget_config`, read line by line as the ruleset
reads them, or else its `feeds`), with the label of the user's
`use_extension`, their `packages_lock_json`, and the hub's `name` where
the tag gives one. No call of the user's is edited.
On Bazel 9.3.2, 8.8.2 and 7.7.2 with rules_csharp 0.5.0 the build then
prints the patched marker and asks no host for the package, also with the
stand-in stopped, a new output base and the package in no repository
cache. One changed byte of the committed package fails the build
("Checksum was ... but wanted ...") and `vendor --check`. `bazel query
//...` lists what it listed. `vendor --check`, `list` and `vex` see the
package as any vendored NuGet package, and a later vendored run keeps the
block in step with the tag (a source added to `nuget.config` reaches it).
The undo
`vendor --revert`, `rollback` and `remove` take the folder of a patch out
of the block, and the block goes with its last folder: `MODULE.bazel` is
then byte for byte what it was. With one vendored patch every other file
is too. With several, `nuget.config` can keep the source mapping that the
first of them created: once another patch has changed the file, the
config revert takes out only the two elements of its own patch, as it
does without Bazel.
A block that was changed by hand cannot be taken out. Reverting the lock
and the config beside it would leave the hub holding the committed
package to the upstream `contentHash`, and the build would fail after an
undo that exited 0. So the undo checks the block before its first write
and fails with nothing changed (`revert_failed` from `vendor --revert`,
`vendor_revert_failed` from `rollback` and `remove`, exit 1). The message
names the line of the block and the two ways on: put the block back as
socket-patch wrote it, or delete it, and run the command again.
Where it declines
The block is written only where the checkout shows that it works.
Otherwise the package is refused with `vendor_nuget_bazel_workspace`
through `vendor::refusals::bazel_workspace_refusals`, the dispatch that
Composer's refusal uses: before any download, a `failed` event, exit 1; a
dry run of `scan` or `get` lists it and exits 0; a hosted pin stays, and
its eject says `kept hosted: ...`. The detail names the reason, with file
and line where there is one, and `--mode hosted`. The reasons:
- the project is below the root of its workspace, or another workspace
lies above it in the checkout (built from there, Bazel reads the folder
from the other root);
- more than one `nuget.from_lock`, or tags that cannot be read with
certainty; a tag that is not a call of its own with every argument
written out, or on an isolated or dev-dependency `use_extension`;
- `local_package_dirs`, which the hub asks before every feed, and
`netrc` or `auth_patterns`, which the block was not built with;
- a `nuget_config` that cannot be read, a source that cannot stand in a
string;
- `feeds` beside a `nuget_config` that has no package source. The run
names its folder in that file (and nuget.org, where NuGet had it by
default), rules_csharp takes the sources of a `nuget_config` in place
of `feeds`, and so would the next run: it would write the block
without the tag's feeds, and a package that only they hold would fail
the build after a run that exited 0. Hosted mode withholds in the same
shape, with the same way on: name the feeds in the file;
- `MODULE.bazel.lock` does not show that Bazel selected rules_csharp
0.5.0;
- the checkout does not name Bazel 9.3.2, 8.8.2 or 7.7.2 (`.bazelversion`,
`.bazeliskrc`). The block rests on Bazel reading a relative `file:` URL
from the root of the workspace, which Bazel does not document, and
9.1.0 has other code for such a URL than 9.0.2 and 9.1.1
(DownloadManager.java), so no release is taken for its neighbour's
sake;
- an rc file names `--repository_disable_download` or `--vendor_dir`, or
a directory at the root holds `VENDOR.bazel`;
- an rc file names a remote downloader
(`--experimental_remote_downloader`), which takes no `file:` feed. Read
in Bazel's source and not built: 7.7.2 hands the feed to the
downloader, which cannot read the folder, and 8.8.2 and 9.3.2 download
every package of the lock without it
(GrpcRemoteDownloader.java);
- `MODULE.bazel` is a symbolic link, or its block was changed by hand.
`--allow-vendored-in-bazel` (SOCKET_ALLOW_VENDORED_IN_BAZEL) lifts the
refusal, and the package is vendored as in a project without Bazel. The
help text, the contract and the docs said that Composer's was the one
refusal the switch lifts; they now name both. A package that is wired
already passes without the switch, as Composer's does.
Nothing changes for a NuGet project in no Bazel workspace, and for one
whose locks no `nuget.from_lock` reads: the same files, byte for byte,
and no line of `MODULE.bazel`.
Hosted mode beside the block: the block's tag is the hub's last one, so
hosted mode writes nothing for another package of the project
(`redirect_bazel_nuget_config_undeclared`) and now says to vendor that
package too or to take the vendored ones out, instead of telling the user
to edit the block.
How
- bazel/nuget.rs: `vendored` reads the tags (without the block), the
ruleset's release, the Bazel release and the rc files through the
existing readers, and gives the block's contents or the reason;
`with_folder` and `without_folder` edit the block.
- bazel/block.rs is new and holds what the Maven block and this one
share, moved out of bazel/maven.rs: finding a block by its first line,
putting one at the end of a file in the file's line break, cutting it
out to the byte, and the file as it reads without it. `proxy` (the
label of a `use_extension`), `asked` and the stale check of a ruleset's
release are shared from maven.rs as they are.
- vendor/nuget_feed.rs decides the layout, writes the block after the
lock, records it in the ledger (`nuget_bazel_feed`, which may name the
root `MODULE.bazel` alone) and reverts it; a failed block write unwinds
the config and the locks, and a revert asks the block before it writes.
- vex/discover/nuget.rs and vendor/path.rs read the package below
`<idLower>/<version>` as well.
Limits, all in docs/ecosystems.md "Bazel workspaces: NuGet": the block
works in the root module only; a module this one depends on with its own
`nuget.from_lock` sources replaces the block's feeds; `--nofetch`, in an
rc file or on a command line, and a vendor directory made before the
patch, can build the unpatched package with exit 0; a machine whose
repository cache holds the package under the sha256 of Bazel's lock
builds the cached, patched file and does not read a changed or missing
copy, which `vendor --check` catches; a checkout deleted and made again
under a running Bazel server does not find the package until the server
restarts; a frozen lock fails right after the run, as in hosted mode;
three WARNING lines per other package and vendored patch when the
extension runs. An earlier release does not know the layout or the
block: on a checkout this one vendored its `vendor --check` fails, its
vendored run writes a second copy, and its `vendor --revert` exits 0 and
leaves the block and the package beside the restored lock, so the Bazel
build fails (measured on 9.3.2); undo with the release that vendored.
Built on macOS arm64, with packages that carry no signature.
"Bazel workspaces: what is supported" in the same file follows: the
NuGet row of its table says vendored mode is supported with the Bazel
release in `.bazelversion`, and VEX with a vendored patch as well; the
list of what was tested names the shape; NuGet leaves the known problem
"vendored mode ... the next Bazel build fails" for an entry of its own
(the switch, a package an earlier release vendored, and the two shapes
the checkout does not show); the build that may not fetch is listed
among those that pass on the unpatched package; and "Bazel workspaces:
VEX" names the vendored flow and the cases in which the document says
`not_affected` of a package whose block is not in `MODULE.bazel`.
Tests: nuget::vendored_from_lock now holds the flow above on real Bazel,
with one decline (a checkout that names no release: nothing written, the
build still passes on the upstream package) and the document of `vex`,
which names the package.
nuget::vendored_mode_keeps_the_block_or_declines runs the commands
through the binary without Bazel: the unchanged layout without a hub,
the block and its three undos, the three undos beside a block that was
changed by hand (exit 1, no file changed, then the undo once the block is
deleted), the declines, the eject and the switch.
Unit tests cover the gate row by row, the block's text and its byte-exact
undo, the ledger record, the revert beside a changed block wherever its
record stands, and the path git is asked about for a hub's package. The
`bazel` group of the line budget follows the code, 3337 to 3758.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
main gained the gem_checksums withhold and the scan of a pinned Maven hub. Two conflicts: - crates/socket-patch-core/src/bazel/maven.rs, the imports: main's `build_maven_purl` is kept; the line-ending helper is no longer imported there, because this branch moved the code of the managed block, its only user outside the tests, into bazel/block.rs. - scripts/loc-budget.json: the cap of the `bazel` group is the count of the merged tree, 4036. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…atch and a second run Four defects of vendored mode for a NuGet package of a rules_csharp hub, each with a unit test. An undo that leaves `nuget.config` wired took the block out. When the config was written anew since the vendored run and still names the folder, the undo keeps the config, the lock pin and the package (`vendor_lock_entry_drifted`). The block went first all the same, so the hub read the folder in `nuget.config` as the URL of a feed and the Bazel build failed on a package that built before the undo. The block now goes last, after the lock and the config, and stays where the config is left wired. A lock that cannot be restored leaves the block too, so the build is as it was for the retry. A later patch of the same package left the earlier patch's folder in the block. The config keeps the earlier patch's source with its pattern set aside; the folder that source names is now taken out of the block when the later patch is written into it, so the block names the later folder alone and goes with it on the undo. The first run for a tag whose `nuget_config` has no package source wrote a block without nuget.org, and the second run added it: the run gives such a config nuget.org beside the folder, and the block was read before that. The block is now read from the tag after the config is written, so a second run writes no file. A lock that spells the package's version otherwise than NuGet writes it (`1.2.3.0` for `1.2.3`) was vendored, and the hub did not find the package: rules_csharp 0.5.0 asks a feed for the lock's `resolved` as it is written. Such a package is declined with `vendor_nuget_bazel_workspace`, by the backend and by the refusal every way in asks first. The refusal looked for the project's locks before it knew that the project is in a Bazel workspace; it asks for the workspace first. Also: one function for the folder of a hub's package in place of the two places of the backend that wrote it out, and the real-Bazel NuGet legs start on a push to main that changes the ledger or the artifact paths of vendored mode (vendor/state.rs, vendor/path.rs), which hold the record of the block and the place of a hub's package. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
PR SummaryHigh Risk Overview Shared Docs/CLI describe the new refusal and layout; CI bazel-nuget paths include vendored flow files; real-Bazel and hermetic e2e tests cover vendored success, decline, revert, and tamper cases. Reviewed by Cursor Bugbot for commit fadf0e9. Configure here. |
…hub-locks Three files conflicted. The RubyGems tests of e2e_bazel_build keep one `Served` (this branch's `Served::to`, with main's `neighbour_gem`), one `run` and every test of both sides; main's tests beside a `gem_checksums` use them, and its `checkout` is `checkout_with`, which this branch's `checkout` is built on. docs/ecosystems.md keeps the entries of both sides, and its paragraph on hosted mode beside a `gem_checksums` entry now says what hosted mode does there since main. The `bazel` cap of scripts/loc-budget.json is the count of the merged tree, 3740. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…hub-locks No file conflicted. Main's change to hosted pnpm pins adds to bazel/pnpm.rs, so the `bazel` cap of scripts/loc-budget.json is the count of the merged tree again, 3858. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The tests of a package of a rules_csharp hub start from a `nuget.config` that names nuget.org, through a helper of the test module that was held to Unix for the file-mode tests it was written for. The hub tests are not held to Unix, so the test build of the core crate failed on Windows (`cannot find function preexisting_cfg`). The helper is a string and now builds everywhere. Test only. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…gnore 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>
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>
|
[agent] PR shepherd: review brief for the approver What it does. In vendored mode, a NuGet package that a rules_csharp Risk: medium. It writes the user's root Look here
Verified
Changes I made. I updated the stale Open questions. Not blocking; the description already lists this. Make a second patch of the same package, then Update for
One leg fails: Generated by Claude Code |
Resolve the conflicts with the vendored Maven hub (#2207): keep both the uncache and cached harness helpers, keep with_patch on the shared block module and make it public as main needs, dispatch the Maven hub refusals next to the Composer and NuGet ones, and raise the bazel line budget by both sides' growth. Assisted-by: Claude Code:claude-opus-5-5
…hub-locks Two files conflicted. vendor/refusals.rs keeps every refusal of both sides in the one dispatch of `bazel_workspace_refusals`, which is still asked once and before any fetch: Composer's, then this branch's for a PyPI or RubyGems project whose lock a hub reads, then main's for a Maven jar that only a rules_jvm_external hub builds. Its docs say which of them the user's word lifts. The `bazel` cap of scripts/loc-budget.json is the count of the merged tree, 4042. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Wenxin Jiang (Wenxin-Jiang)
left a comment
There was a problem hiding this comment.
[agent] Approving; one inline note on a fail-open path. The red cargo / bazel (9.3.2, e9) check is the @platforms flake that #2227 fixes.
Main added an agent-mode NuGet flow and VEX attestation for Bazel hubs (#2224); this branch adds vendored mode for NuGet. Both are kept: - bazel-nuget.yml: the path lists are the union of both sides; the comments describe the agent, VEX and vendored flows together. - e2e_bazel_build/nuget.rs: vendored_from_lock and agent_from_lock both stay, with their helpers. - docs/ecosystems.md: the NuGet row keeps this branch's vendored column and main's VEX column; the VEX paragraph keeps both additions; the vendored-NuGet caveat keeps this branch's text, since vendored mode now builds with the block in MODULE.bazel. - loc-budget.json: bazel group at the merged count, 4432 (+426 here, +89 on main). Assisted-by: Claude Code:claude-opus-5-5
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>
|
[agent] A local session is working on this branch right now (merging main and making the change the open review thread asks for). Please do not push to it until the |
Main gained "Keep the Bazel support from changing a project that Bazel does not build" (#2228): the off switch `SOCKET_NO_BAZEL`, a doubt of the workspace reader about a file that is there and was not read as a whole (`Workspace::unread`), the Composer refusal by section of the lock, and the "Experimental" marks of the CLI contract. Five files had conflicts. Each is resolved by keeping both sides: - `bazel/mod.rs`: main's switch (`OFF_ENV`, `off`, `root_of`) and this branch's `mod block`, `root_above` and `roots_in` stand together. `bazel_root` is main's, so the switch holds for the NuGet gate as for every other caller; `root_in` keeps this branch's body over `roots_in` and takes main's doc line. `root_above` is asked only after `bazel_root` found a workspace, so it does not ask the switch itself. - `vendor/refusals.rs`: one sentence of the module docs. It lists the Composer and the NuGet refusal, as this branch has it, and says of Composer's what main now says (a vendored copy in `packages` or in the package's section lets a package through). - `CLI_CONTRACT.md`: the row of `--allow-vendored-in-bazel` and the row of its variable carry main's "Experimental" mark and name both refusals; the row of the flag has main's sentence on when a Composer package meets its refusal. The Composer code row is main's. The NuGet code row is this branch's, with the same mark, and names `SOCKET_NO_BAZEL=1` beside the flag among the runs that are not refused, as main's Composer row does. - `docs/ecosystems.md`: the list of known problems keeps this branch's entry on vendored NuGet and takes main's new wording of the entry on a hosted Cargo pin. - `scripts/loc-budget.json`: the cap of `bazel` is the count of the merged tree, 4468 (4432 here, and 36 lines more on main). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…hub-locks Five files conflicted. bazel/built.rs keeps main's hubs for Cargo and NuGet and what `unbuilt` says of them, and this branch's `reader` for the two vendored refusals, on one set of helpers: `reader` goes through every extension of a hub, `file` knows the name a `WORKSPACE` file gives the main repository, and the call it finds carries the hub's remedy. `unbuilt` is main's: the rule that passes over a `WORKSPACE` file under Bazel 9 is `reader`'s alone. vendor/refusals.rs, CLI_CONTRACT.md and docs/ecosystems.md keep the entries of both sides. The contract and the docs mark this branch's two codes experimental as main marks the others, name them among the codes only a Bazel workspace gives, and say that `SOCKET_NO_BAZEL` turns them off, which a new test of each holds (`off_is_without_bazel`). The `bazel` cap of scripts/loc-budget.json is the count of the merged tree, 4184. Outside the conflicts: - main's new test of e2e_bazel_build/ruby.rs calls this branch's `Served::to` and `checkout_with`; - a unit test of vendor/bazel_hub.rs stood a Poetry and a PDM project on an empty lock. Main no longer wires a lock that resolves no package beside a `requirements.txt`, so the test's lock now resolves the package, as main's own tests of that change do, and a row holds that the empty lock is declined like no lock; - the docs and the contract say that such a lock is not what is wired. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…r a hub Two changes of main say something of every package that a Bazel hub builds, and were written before vendored mode kept a block for a rules_csharp hub. The merges took both as they are. This brings their statements in line with the block and tests what they do beside it. No product code changes. The VEX answer for a hub that builds from the lock. Three places said that no test builds a vendored NuGet package under its hub, so nothing is said of one: the paragraph on vendored copies in "Bazel workspaces: VEX", the `vex_bazel_not_in_build` row of the CLI contract, and two comments of `bazel/built.rs`. A flow does build one now, through the block. They say that, and that `vex` does not read the block, so the statement is the same where the block is missing and the build fails (the list of documents that are still wrong has that entry, and now says why that build fails). `nuget::vendored_mode_keeps_the_block_or_declines` asks `vex` after the vendored run in the hub's checkout, on a machine that restored nothing: one `not_affected` statement through the committed copy, and no warning. The switch for a project that Bazel does not build (`SOCKET_NO_BAZEL`). It holds for the NuGet gate through `bazel_root`, and the undo of the block never asked for the workspace. The same flow holds both: with the switch a vendored scan is the scan of the same checkout without its Bazel files, to the byte, where the block would be written and where the package would be declined; and `vendor --revert` with the switch set takes the folder out of the block and leaves every file as it was. The docs section on a project that Bazel does not build and the section on experimental Bazel support of the CLI contract name the NuGet block and its refusal among what the switch turns off, and the undo of the block among what stays on. The module docs of the NuGet flows name the three modes they run. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ck unseen For a NuGet package of a rules_csharp hub, vendored mode keeps a block in the root `MODULE.bazel`, or declines the package where it cannot show that the block works. Where it found no `nuget.from_lock` that reads a lock of the project, it vendored the package as without Bazel, in the folder of the patch alone. In two cases a hub reads the lock all the same. The package is then in none of its feeds: the next Bazel build fetches the upstream package and fails on the `contentHash` that the run re-pinned, after a command that exited 0. - The tag may be hidden. A `MODULE.bazel` that cannot be read (a link that leads out of the workspace, a file over the reader's 1 MiB) read as an empty file, and what the reader could not read was asked only once a tag was found. Where no tag is found, the package is now declined when a file of the workspace that is there was not read as a whole (`Workspace::unread`), since it may be the one that names the ruleset, and when the reader has any doubt in a workspace that names rules_csharp. A doubt in a workspace of other rulesets whose files were all read is about no hub, as it is for a Maven hub since #2228: a project there that Bazel does not build keeps its vendored run. - The tag is gone and the block is still there. The reader does not see the block, so it found no tag, and a second package was written outside the block that still hands the lock to the hub. The package is now declined when the block's own `packages_lock_json` names a lock of the project. A block for the lock of another project of the workspace changes nothing for this one. Both are the refusal this gate already has, `vendor_nuget_bazel_workspace`: exit 1, nothing asked of the patch service and nothing written, a dry run of `scan` and `get` lists the package, `--allow-vendored-in-bazel` and `SOCKET_NO_BAZEL` lift it, and a package that is already wired for the hub stays as it is, with the reason as a warning. The reason names what could not be read, in the words the gate has for a doubt beside a tag, or the line of the block and the two ways on: put the tag back, or `socket-patch vendor --revert`. In the code, `reads` shares the lock a label names with the check of the block (`named`), the words for a doubt are one function (`unsure`), and `bazel/maven.rs` shares its test for a workspace that names a ruleset (`names`). The cap of `bazel` in the line budget follows: 4468 to 4496. Tests, each of which fails without the change it holds: - `bazel/nuget.rs`: the gate over files in memory (a doubt in a workspace of the ruleset, the same doubt where nothing names it, a file that is there and is not read, the root file itself), and `vendored` on disk (the block without its tag, the same block for a project below the root, a `MODULE.bazel` over 1 MiB, and on Unix one that links out of the workspace). - `vendor/nuget_feed.rs`: after a vendored run, with the tag taken out, a later patch is refused with nothing written, by the backend and by the dispatch that every way in asks first, and the wired package keeps its files and gets the warning. - `nuget::vendored_mode_keeps_the_block_or_declines`, through the binary: both shapes are declined by `scan` and `get`, listed by a dry run and told to a person; with the flag and with its variable they are vendored as without Bazel; and with `SOCKET_NO_BAZEL=1` the run is the one of the same checkout without its Bazel files, to the byte. One expectation of this branch changes. The test of a project whose lock no tag reads held a workspace of rules_csharp with a use of the extension's proxy that is no call of a tag to the run without Bazel. It is declined now, and the row moved to the new test of the gate. The docs section "Vendored mode under a rules_csharp hub", the entry of the section on a project that Bazel does not build and the contract row of the refusal say the same. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Main gained "Name each patched package as a VEX product so Trivy and Grype match it" (#2243). No file has a conflict. That change is to the VEX document and to the test harness that reads one, which the NuGet flows of this branch go through where they hold `vex` to a vendored package. They pass on the merged tree: `nuget::vendored_mode_keeps_the_block_or_declines` finds the vendored package as a product of its own in the document, beside the project. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The docs entry on a tag that may be hidden said that such a hub takes the upstream package and fails on the re-pinned lock. That is one of two ways. A hub whose tag names the project's `nuget.config` reads the folder that vendored mode names there as the URL of a feed, and fails on that, as measured for a flat vendored run under a hub on Bazel 9.3.2, 8.8.2 and 7.7.2. The entry names both. Docs only. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…a NuGet hub `bazel-guard/vendored-hub-locks` declines PyPI and RubyGems vendored mode where a Bazel hub reads the lock, and passes over a `WORKSPACE` file where the checkout names Bazel 9 or later. It lands on main before this branch, so its conflicts with this branch are resolved here. Seven files had conflicts, and each keeps what both sides say. - `vendor/refusals.rs`: the one dispatch of the refusals that rest on a Bazel workspace asks every backend once, before any fetch: Composer's, the PyPI and RubyGems one of that branch (`bazel_hub::refusals`), NuGet's (`nuget_feed::bazel_refusals`) and Maven's. The module docs and the docs of the dispatch list them all, and the unit tests of both sides stand. - `bazel/built.rs`: two comments on what a hub builds of a vendored copy. They say of rules_ruby what that branch measured (a vendored gem builds only where the call lists the copy among its `srcs`) and of rules_csharp what this branch built (through the block of vendored mode). - `bazel/maven.rs`: the imports of both. - `args.rs`: the help text of `--allow-vendored-in-bazel` names the three kinds of refusal the flag lifts. - `CLI_CONTRACT.md`: the row of the flag, the list of experimental codes and the list of what `SOCKET_NO_BAZEL` turns off name the refusals of both sides; the table of vendored artifacts has that branch's PyPI row and this branch's NuGet row; both new code rows stand. The row of `vex_bazel_not_in_build` had no marker and said that no test builds a vendored gem under its hub: it now says what that branch measured. - `docs/ecosystems.md`: the known problem "Vendored mode for PyPI, RubyGems and NuGet" is gone. That branch took PyPI and RubyGems out of it, since vendored mode declines them now, and this branch took NuGet out, which has an entry of its own for the cases its refusal does not see. The list of what the Bazel support does for a project, the sentence on the switch in the Composer section, the paragraph on vendored copies in the VEX section and the list of documents that are still wrong each hold the entry of both. - `scripts/loc-budget.json`: the cap of the `bazel` group is 5300, the one value every open change of this series sets, so that they stop conflicting on that line; the count of this tree is 4638. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Main gained the PyPI and RubyGems vendored refusals (#2208) and the reason of a failed apply in its telemetry and `--json` events (#2247). #2208 is the squash of the branch that the merge before this one brought in. Main's tree is that branch merged with #2247, so the seven files that conflicted there conflict here again, with the same two sides: `vendor/refusals.rs`, `bazel/built.rs`, `bazel/maven.rs`, `args.rs`, `CLI_CONTRACT.md`, `docs/ecosystems.md` and `scripts/loc-budget.json`. Each is what the merge before this one made of it, and #2247 touches none of them. So this tree is the last one with #2247 added and nothing else: 16 files, none of which this branch changes. The cap of the `bazel` group in `scripts/loc-budget.json` stays 5300, the one value every open change of this series sets so that they stop conflicting on that line; the count of this tree is 4638. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Main now passes over a `WORKSPACE` file where the checkout names Bazel 9 or later: Bazel reads none there, so the file is no reader of a lock and no doubt (#2208). The gate of vendored mode for a rules_csharp hub never counted that file on any release. rules_csharp has no form for it, the tags are read from the module files alone, and the reader keeps what it makes of a `WORKSPACE` file apart from its doubts and from the file it names as not read (`Workspace::legacy`), which the gate does not ask. The test of a tag that may be hidden holds that now. A `WORKSPACE` file that cannot be read, and one that defines something, decline nothing where no tag is found and leave the block as it is beside a tag, in a checkout that names Bazel 9.3.2 and in one that names 7.7.2. Test only. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Main brought the pnpm route under a rules_js hub. One conflict, in the contract: both sides add to the same sentences of the section on Bazel workspaces (the experimental list, the off switch, what stays on). Each keeps the words of both. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Main brought the VEX answer for a Maven patch beside a pinned hub. Two conflicts. In the Maven hub reader, main's `proxy` now says whether a usage is isolated for certain; this branch had opened it to the NuGet reader: it is main's function, visible to that reader, which takes a usage that is not shared as it did. In the contract both sides add to the same sentences of the section on Bazel workspaces: each keeps the words of both. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Vendored mode now works for a NuGet package that a rules_csharp
nuget.from_lockhub builds under Bazel: it keeps the package where the hub finds it and one managed block in the rootMODULE.bazel, and where the checkout does not show that the block works it declines the package withvendor_nuget_bazel_workspaceand writes nothing.Based on main, in eight commits of its own and merges of main. The first commit is tests only and records what main did before; the second is the change, with the expectations of the first changed to match; the third holds the fixes of the code review below; the fourth lets the hub tests build on Windows. After the merge of main at #2228, the fifth brings two changes of main in line with the block and tests them beside it (the off switch
SOCKET_NO_BAZELof #2228 and the VEX answer for a hub of #2224), the sixth is the one request of the review (the last entry of the code review section), the seventh corrects one sentence of the docs, and the eighth is a test that holds the gate apart from aWORKSPACEfile (see the merges below).All of the Bazel support, this included, is labelled experimental in the docs and in the CLI contract (#2222 and #2228, both merged).
Decisions for the maintainer
MODULE.bazel: the block adds a secondnuget.from_locktag. Vendored mode appends one managed block there and removes it byte for byte, as hosted mode does for Maven. Unlike the Maven block, which overrides one repository, this one is a tag of the user's own hub: itsfeedsname the folder of each vendored patch and then the sources the hub had. It writes no other file of Bazel's. The alternative is to decline every NuGet package of a hub.MODULE.bazel.lockshows it, and Bazel 9.3.2, 8.8.2 or 7.7.2, named in.bazelversionor.bazeliskrc. A checkout on any other release, or one that names none, is declined. The block rests on Bazel reading a relativefile:URL from the root of the workspace, which Bazel does not document, and 9.1.0 has other code for such a URL than its neighbours. Taking ranges of releases is a small change, and a risk this change does not take.failed, exit 1, like the Composer refusal; a dry run ofscanorgetlists the package and exits 0. The alternative is a warning with exit 0.--allow-vendored-in-bazellifts the decline, and the Bazel build then fails. With the switch the package is vendored as in a project without Bazel, which the hub reads as a bad URL. That is for a project whose lock a tag names and which Bazel does not build. The alternative is that the switch does nothing for NuGet.vendor --revertand a new vendored run.vendor --revert,rollbackandremoveexit 1 and name the line of the block. The alternative is to revert the lock andnuget.configand leave the block with a warning: that exits 0 and leaves a Bazel build that fails on the committed package, with no command of socket-patch that gets out of it.vendor --revertexits 0, restores the lock and leaves the block and the package. The docs say to undo with the release that vendored. Whether the ledger should make an earlier release refuse such an entry is open; this change does not do it.--nofetchin an rc file does not. The first is read in Bazel's source and not built. With the second the build lags until the project's next fetch, as after any change of a lock, so it is a documented limit and no refusal. The same holds for a vendor directory made before the patch: socket-patch declines when it sees--vendor_dirin an rc file or a directory withVENDOR.bazelat the root, and it cannot see one named on a command line. In both cases the build takes the unpatched package and exits 0 with a warning of Bazel's.name, a tag withfeedsof its own, a tag withoutnuget_config, and two patches in one block. Each was built by hand on Bazel 9.3.2 and 7.7.2 and printed the patched marker; unit tests cover what is written for them. The cautious alternative is to decline them until a committed test builds each.vexdoes not read the block. For a vendored package whose block is not inMODULE.bazel(the switch, an earlier release, a block taken out by hand) it saysnot_affectedwhile the Bazel build fails. The docs list this. With the block in place it saysnot_affectedtoo, which a test now holds against main's new answer for a hub that builds from the lock (Attest a Cargo or NuGet patch as affected in VEX where a Bazel hub builds the package from the lock #2224)..socket/vendor/nuget/<uuid>/<id>/<version>/<id>.<version>.nupkg(the id in lower case), the shape of a folder feed, andnuget.confignames<uuid>as before: one copy serves NuGet and Bazel. Every other NuGet project keeps the flat file. The alternative, one layout everywhere, changes what every vendored NuGet project commits.--allow-vendored-in-bazelor setsSOCKET_NO_BAZEL.socket-patch vendor --revert.What main does without this change
scan --mode vendored,get --mode vendoredandvendorcommit the patched package under.socket/vendor/nuget/<uuid>/, name that folder as a package source innuget.configand re-pinpackages.lock.json. NuGet takes a folder as a source. rules_csharp'snuget.from_lockreads the same line as the URL of a feed.So in a workspace whose hub reads the project's lock, the command exits 0 and reports the package vendored, and the next
bazel buildfails. Bazel 9.3.2 crashes in the module extension (exit 37,NullPointerException thrown during Starlark evaluation). Bazel 8.8.2 and 7.7.2 stop atBad URL: .socket/vendor/nuget/<uuid>. The first commit adds a real-Bazel test that records exactly this; the second changes its expectations.What changes
In the root of a Bazel workspace whose one
nuget.from_lockreads the project's lock, the three commands write:.socket/vendor/nuget/<uuid>/<id>/<version>/<id>.<version>.nupkg, with the id in lower case. It is the only copy.nuget.configwith that directory as the source, sodotnet restoreoutside Bazel takes the same file, and the lock as before.MODULE.bazel, after one blank line:The block is a second
nuget.from_lockof the same hub, after every tag of the user's. Itsfeedsare the folder of each vendored patch, which Bazel reads from the root of the workspace, and then the sources the hub had without the block: those of the tag'snuget_config, read line by line as the ruleset reads them, or else the tag'sfeeds. It carries the label of the user'suse_extension, theirpackages_lock_json, and the hub'snamewhere the tag gives one. No call of the user's is edited, and nothing is written to.bazelrcor.bazelignore.The build then takes the committed package and asks no host for it.
vendor --check,listandvexsee the package as any vendored NuGet package. A later vendored run keeps the block in step with the tag, so a source added tonuget.configreaches the hub once socket-patch has run again. A later patch of the same package takes the place of the earlier one's folder in the block.The undo.
vendor --revert,rollbackandremovetake the folder of a patch out of the block, and the block goes with its last folder:MODULE.bazelis then byte for byte what it was. With one vendored patch every other file is too. With several,nuget.configcan keep the source mapping that the first of them created, as it does without Bazel.The block goes last, after the lock and the config. A
nuget.configthat was written anew since the vendored run and still names the folder is left as it is with a warning (vendor_lock_entry_drifted), as without Bazel: its lock pin and its package stay, and so does the block, through which alone the hub takes that package.A block that was changed by hand is not taken out, and then nothing is. The three commands fail with exit 1 (
revert_failedfromvendor --revert,vendor_revert_failedfromrollbackandremove), nameMODULE.bazel:<line>and leave every file as it is: with the lock restored beside such a block the hub would hold the committed package to the upstreamcontentHash, and the build would fail. Put the block back as socket-patch wrote it, or delete it, and run the command again.Where it declines. The package is refused with
vendor_nuget_bazel_workspace, through the dispatch that the Composer refusal uses: before any download,failed, exit 1, nothing written. A hosted pin stays, and its eject sayskept hosted: .... The message names the reason, with file and line where there is one, and--mode hosted. The reasons:nuget.from_lock, or tags that cannot be read with certainty;use_extension;local_package_dirs, which the hub asks before every feed, ornetrcorauth_patterns;nuget_configthat cannot be read, or a source that cannot stand in a string;feedsbeside anuget_configthat has no package source. The run names its folder in that file, rules_csharp takes the sources of anuget_configin place offeeds, and the next run would write the block without the tag's feeds: a package that only they hold would then fail the build. Name the feeds in the file;MODULE.bazel.lockdoes not show that Bazel selected rules_csharp 0.5.0;--repository_disable_downloador--vendor_dir, or a directory at the root holdsVENDOR.bazel;--experimental_remote_downloader), which takes nofile:feed;MODULE.bazelis a symbolic link, or its block was changed by hand;MODULE.bazeland thenuget.from_lockit was written beside is gone. The block still hands the lock to the hub, with the folders of the packages vendored before as its feeds, and a package vendored now would not be among them. Put the tag back, or runsocket-patch vendor --revert;MODULE.bazelor a file it includes is there and is not read as a whole (a link that leads out of the workspace, a file over 1 MiB, one that is not UTF-8 or cannot be parsed, anincludethat is not followed), or the workspace names rules_csharp and a part of those files is not read with certainty. The message names what could not be read;1.2.3.0for1.2.3): the hub asks its feeds for the lock's spelling, and the folder holds the onedotnet restorewrites.--allow-vendored-in-bazel(SOCKET_ALLOW_VENDORED_IN_BAZEL) lifts the refusal. The help text, the contract and the docs name it beside the two refusals the switch lifts on main: Composer's, and the one of PyPI and RubyGems beside a hub that reads the lock (#2208). A package that is wired already passes without the switch: where the block can no longer be shown to work it stays as it is, with the reason as a warning.SOCKET_NO_BAZEL=1, main's switch for a project that Bazel does not build (#2228), switches all of it off: a vendored scan is then the scan of the same checkout without its Bazel files, to the byte. The undo stays on:vendor --revert,rollbackandremovetake the folder out of the block with the switch set.Hosted mode beside the block. The block's tag is the hub's last one, so hosted mode writes nothing for another package of the project (
redirect_bazel_nuget_config_undeclared). It now says to vendor that package too, or to take the vendored ones out.Nothing changes for a NuGet project in no Bazel workspace, and for one whose locks neither a
nuget.from_locknor the block reads, where no tag can be hidden: the same files byte for byte, and no line ofMODULE.bazel. That includes a workspace that does not name rules_csharp and whose files are all read as a whole, whatever else in them is not read with certainty.Limits
nuget.from_lockwith sources of its own. The hub takes that tag after the block, and the build fails on the re-pinned lock. Hosted mode fails the same way.--nofetchin an output base that built the unpatched project, and a build from a vendor directory made before the patch, build the unpatched package and exit 0, with a warning of Bazel's. Such a build still rewritesMODULE.bazel.lockto the pins of the patched package. socket-patch sees--vendor_dirand--repository_disable_downloadin an rc file and a vendor directory at the root; it does not see--nofetch, in an rc file or on a command line.MODULE.bazel.lockrecords: Bazel builds the cached file there, which is the patched one.vendor --checkcatches the change on every machine.MODULE.bazel.lockis stale right after the run, as after a hosted run: a build with--lockfile_mode=errorfails until a build that may update the lock has run.WARNING: Download from file:...lines for every other package of the lock, for each vendored patch, when the module extension runs.nuget.configreaches the hub only after socket-patch has run again.vendor --checkfails (vendor_check_failed), its vendored run writes a second copy of the package in the folder of the patch, and itsvendor --revertexits 0, restores the lock and leaves the block and the package: the Bazel build then fails on the lock'scontentHash(measured by hand on Bazel 9.3.2). Undo with the release that vendored.Each of these but the last is in docs/ecosystems.md, "Vendored mode under a rules_csharp hub". The last follows from what that section says of a workspace that does not name rules_csharp.
Code review
A review of the whole change at the first merge gave seven findings. Each was checked against the code, and those about the hub against the source of rules_csharp 0.5.0. The third commit holds the fixes.
Fixed:
nuget.configwired took the block out. Where the config was written anew and still names the folder, the undo keeps the config, the lock pin and the package. The block went first all the same, so the hub read the folder innuget.configas the URL of a feed, and the Bazel build failed on a package that built before the undo. The block now goes last and stays where the config is left wired. A lock that cannot be restored leaves the block too.nuget_confighas no package source. The run gives such a config nuget.org beside the folder, and the block was read before that. It is now read from the tag after the config is written.resolvedas it is written. Such a package is declined, by the backend and by the refusal that every way in asks first.dotnet restorewrites the normalized version, so this needs a lock written by hand.Fixed in part:
vendor/path.rsandvendor/state.rs, which this change touches for the layout and the ledger record. Both are in the push list now. They are not in the pull request list: every ecosystem's vendored mode shares them, and the workflow keeps shared engine code out of that list by its own rule.Not fixed:
MODULE.bazel, its lock and the rc files. An answer kept across packages would have to be dropped after every write of the block, and a stale one writes a wrong block; the cost did not seem worth that.Each of the four behaviour fixes has a unit test. The tests were not run against the code of before the fixes.
After the approval, one request of the review, fixed in de7cc74:
MODULE.bazelthat cannot be read (a link that leads out of the workspace, a file over the reader's 1 MiB) read as an empty file, and what the reader could not read was asked only once a tag was found. And with the block there and the user's own tag removed, the block is hidden from the reader, so a second package was written outside the block that still hands the lock to the hub. Either way the next Bazel build fetched the upstream package against the re-pinnedcontentHash. Both are declined now, with the gate's own code, and the switch lifts them. It is narrower than the request in one point (decision 12): a doubt declines where a hub may be behind it, not in a workspace of other rulesets whose files were all read. Each case has a unit test and a row of the flow through the binary, and each was seen to fail without its part of the fix.Contents
Against main at #2208 (0a7e7a0, the main this branch holds): 18 files, +3456 −230 lines.
bazel/nuget.rsbazel/block.rs(new)bazel/maven.rsblock.rs; shares the label of ause_extension, the release check of a ruleset and the test for a workspace that names onebazel/mod.rsbazel/built.rsvendor/nuget_feed.rsvendor/refusals.rs,path.rs,state.rs,mod.rsvex/discover/nuget.rs<id>/<version>args.rstests/e2e_bazel_build/nuget.rs,harness.rsdocs/ecosystems.md,CLI_CONTRACT.mdSOCKET_NO_BAZELturns off and leaves onbazel-nuget.yml,scripts/loc-budget.jsonbazelcap, 5300, the one value every open change of this series sets (the count is 4638; main's is 4184)Of that, the fifth commit (6b67c81) is +75 −19 in four files and changes no product code. The sixth (de7cc74, the request of the review) is +339 −53 in seven files:
bazel/nuget.rs+196 −26, which is 28 code lines more and otherwise comments and unit tests,bazel/maven.rs+10 −7, a test of the backend (+57), the flow through the binary (+53 −14), the docs and the contract row (+22 −5), and the cap. A docs-only commit (4dde8a2, +4 −2) corrects one sentence of the new docs entry, and a test-only commit after the last merge (3bf2266, +25 −2) adds the rows on aWORKSPACEfile.What it proves, and where
Everything below ran on macOS arm64, with rules_csharp 0.5.0 and packages that carry no signature. No build and no command reached nuget.org or a Socket host.
nuget::vendored_from_lock: a checkout that names no release is declined and its build stays on the upstream package. With.bazelversion, the scan writes the layout and the block;vendor --checkpasses;vexnames the package;bazel query //...lists what it listed. The build prints the patched marker with no request for the package, and again with the registry stand-in stopped, a new output base and the package out of the repository cache. One changed byte failsvendor --checkand the build.vendor --revertrestores every file and the upstream build. The two hosted flows and main's agent flow (nuget::agent_from_lock, Attest a Cargo or NuGet patch as affected in VEX where a Bazel hub builds the package from the lock #2224) pass beside it. Bazel 8.8.2 was not run at this head; it last ran the vendored flow at the second commit. The two flows of Decline PyPI and RubyGems vendored mode where a Bazel hub reads the lock #2208 whose refusals share the dispatch with this one also ran on 9.3.2 at this head:ruby::vendored_bundle_fetch(ok, 136 s) andpypi::vendored_pip_parse(ok, 22 s).nuget::vendored_mode_keeps_the_block_or_declines, through the binary without Bazel: the unchanged layout outside a hub; the block and its three undos, and the undo withSOCKET_NO_BAZELset;vexafter the vendored run, on a machine that restored nothing (onenot_affectedstatement through the committed copy, and no warning); the three undos beside a block changed by hand (exit 1, no file changed, and the full undo once the block is deleted); the declines byscan,get, a dry run and for a person, among them the tag withfeedsbeside a config without a source, aMODULE.bazelthat is not read, and the block without its tag; the eject; the flag and its variable, which lift each of those declines; andSOCKET_NO_BAZEL=1, with which the run is the one of the same checkout without its Bazel files, to the byte, where the block would be written and wherever the package would be declined.MODULE.bazelover 1 MiB or, on Unix, one that links out of the workspace (declined, for every project of the workspace), the block without its tag (declined), and the same block for a project below the root (as without Bazel).vexmade to sayaffectedof a vendored NuGet package, the gate made deaf toSOCKET_NO_BAZEL, and the undo made to obey it. Seven are for the sixth: the gate as it was, the block without its tag as it was, that block declining whatever lock it reads, every doubt declining, a file that is not read not declining, a wired package without its warning, and the flag not lifting the two new declines. Two are for the eighth: aWORKSPACEfile that cannot be read counted as a file that may hide a tag, and as a doubt beside a tag. With the gate or the block as they were, the flow through the binary fails where it expects exit 1: the command exits 0 and vendors the package as without Bazel, which is the defect. Five more breaks were run on the code of the third commit and thirty on earlier versions; they were not run again.feedsalone, a tag withoutnuget_config, a patched package as a transitive dependency, a private source innuget.config, CRLF files and two patches each built the patched package, and the upstream build came back after the undo.e2e_bazel_buildwithout Bazel (87) and five CLI integration targets (275 tests) pass. One expectation of this branch changed with the sixth commit, and none of main's: a workspace of rules_csharp with a use of the extension's proxy that is no call of a tag, whose lock no tag reads, was held to the run without Bazel and is declined now.The merges of main, and what ran at the head
The branch holds six merges of main, and one of the branch that landed on main as #2208.
af5dd83, the first: two conflicts, the imports of
bazel/maven.rsand thebazelcap.30cb8cc and 8d6f447 brought main in up to Attest a Cargo or NuGet patch as affected in VEX where a Bazel hub builds the package from the lock #2224. The second had conflicts in the NuGet workflow, the NuGet flows,
docs/ecosystems.mdand the cap, each resolved by keeping both sides: the path lists as the union, the vendored and the agent flows one after the other, and in the support table the NuGet row with this branch's vendored cell and main's VEX cell.b84835d, main at Keep the Bazel support from changing a project that Bazel does not build #2228: five conflicts, each resolved by keeping both sides.
bazel/mod.rshas main's switch (OFF_ENV,off,root_of) and this branch'smod block,root_aboveandroots_in;bazel_rootis main's, so the switch holds for the NuGet gate.vendor/refusals.rs: one sentence of the module docs, which lists both refusals and says of Composer's what main says.CLI_CONTRACT.md: the rows of--allow-vendored-in-bazeland of its variable carry main's "Experimental" mark and name both refusals, the Composer code row is main's, and the NuGet code row has the mark and namesSOCKET_NO_BAZEL=1beside the flag.docs/ecosystems.md: the known problems keep this branch's entry on vendored NuGet and take main's wording of the entry on a hosted Cargo pin. The cap is the merged count, 4468.cc616d1, main at Name each patched package as a VEX product so Trivy and Grype match it #2243: no conflict. That change is to the VEX document and to the harness that reads one; the NuGet flows that hold
vexto a vendored package pass on the merged tree.bb5cdb2, the branch of Decline PyPI and RubyGems vendored mode where a Bazel hub reads the lock #2208 (PyPI and RubyGems vendored mode declined where a hub reads the lock) before it landed: seven conflicts, each resolved by keeping both sides.
vendor/refusals.rs: the one dispatch asks every backend once, before any fetch (Composer's, the PyPI and RubyGems one, NuGet's, Maven's), and the tests of both stand.bazel/built.rs: two comments say of rules_ruby what Decline PyPI and RubyGems vendored mode where a Bazel hub reads the lock #2208 measured and of rules_csharp what this branch builds.bazel/maven.rs: the imports of both.args.rs: the help text of the flag names the three kinds of refusal.CLI_CONTRACT.md: the row of the flag, the list of experimental codes and the list of whatSOCKET_NO_BAZELturns off name the refusals of both, and both new code rows stand.docs/ecosystems.md: the known problem "Vendored mode for PyPI, RubyGems and NuGet" is gone, since each side took its own ecosystems out of it, and four other places hold the entry of both. The cap is 5300.af5b810, main at Decline PyPI and RubyGems vendored mode where a Bazel hub reads the lock #2208: main's tree is that branch merged with Say why an apply failed in its telemetry and --json events #2247, so the same seven files conflict again with the same two sides, and each is what the merge before made of it. The tree is the one of bb5cdb2 with Say why an apply failed in its telemetry and --json events #2247 added.
The fifth commit (6b67c81) is what the merges up to #2243 left to do without a marker: three statements of main that no test built a vendored NuGet package under its hub, a test of
vexafter a vendored run, and the NuGet block and refusal in the lists of whatSOCKET_NO_BAZELturns off and leaves on, with tests of both.The eighth (3bf2266) answers a question the merge of #2208 raises. That change passes over a
WORKSPACEfile where the checkout names Bazel 9 or later, which reads none. The NuGet gate never counted such a file on any release: rules_csharp has no form for it, the tags are read from the module files, and the reader keeps aWORKSPACEfile apart from its doubts. The test of a tag that may be hidden now holds that for a checkout that names 9.3.2 and for one that names 7.7.2. One decline does look at that file's name: a directory above the workspace that holds aWORKSPACEfile counts as a Bazel workspace above it, on every release. That is not changed here.What ran at this head (3bf2266), all passing:
cargo check --locked --workspace --all-targets --all-features;cargo clippy --locked --workspace --all-features -- -D warnings;cargo clippy --locked -p socket-patch-cli --test e2e_bazel_build -- -D warnings;rustfmt --check --edition 2021on the five Rust files that the last two merges and the eighth commit edit.e2e_bazel_buildwithout Bazel: 87 passed, 34 ignored (the real-Bazel flows).in_process_vendor(157),e2e_vex_vendor(39),vendor_jvm_cli(46),e2e_bazel_maven_beside(32),contract_gradle_codes(1).scripts/loc-budget.py:bazel4638 of 5300.The longer list ran two merges earlier, at cc616d1: ten CLI test targets (704 tests), two core test targets, the script tests (423), and the workflow lint.
On real Bazel 9.3.2 at this head, macOS arm64, one flow at a time: the four
nuget::flows (4 of 4, 290 s; the vendored flow 250 s),ruby::vendored_bundle_fetch(ok, 136 s) andpypi::vendored_pip_parse(ok, 22 s). On 7.7.2 the fournuget::flows last ran at 4dde8a2 (4 of 4, 83 s).Not covered
name, a tag withfeedsof its own, a tag withoutnuget_config, two patches at once, a patched package with dependencies of its own. They were built by hand only.file:feed to the downloader; 8.8.2 and 9.3.2 download every package of the lock without it). No build ran with one.nuget.configkeeps the first patch's source mapping is main's behaviour without Bazel too, and is not changed here.dotnet restoreof the new layout ran in a test.vendor --revertthen puts back the config and the lock pin of the first patch, whose folder the second run removed. That is main's behaviour without Bazel too and is not changed here; with a hub, the block is gone as well.MODULE.bazelis not read, or whose block has lost its tag. That such a build fails after a vendored run as without Bazel is read from the source of rules_csharp 0.5.0 (the hub holds a package to the lock'scontentHash, and reads a folder innuget.configas a URL) and from what the first commit measured for such a run under a hub. It was not built for these two shapes.🤖 Generated with Claude Code