Skip to content

Commit 4341167

Browse files
Make vendored mode work for a NuGet package of a rules_csharp hub, or decline it (#2223)
* Test PyPI and RubyGems vendored mode beside a Bazel hub on real Bazel Tests only. rules_python's `pip.parse` and rules_ruby's `ruby.bundle_fetch` hand a lock of the checkout to Bazel. The real-Bazel flows ran hosted mode beside both hubs, and vendored mode beside the Python one (pypi::vendored_pip_parse, which holds `vex` to saying that the build is not the patched one). No flow ran vendored mode for a gem, and the PyPI flow did not build between its undo and its hosted scan. ruby::vendored_bundle_fetch records what the command does today, in the fixture of the hosted flow (rules_ruby 1.0.0-rc2; the call names the `Gemfile` and the `Gemfile.lock` of the root). `scan --mode vendored --yes` exits 0 with status `success` and one package applied. It commits the unpacked gem with its specification and the ledger under `.socket/vendor/gem/<uuid>`, gives the gem's declaration in `Gemfile` a `path:`, and moves the gem's entry of `Gemfile.lock` into a `PATH` section. The next `bazel build` fails in the `bundle install` action of the hub. rules_ruby copies the two files into a repository of Bazel's and runs Bundler there, which stops with The path `<execroot>/external/<hub>/.socket/vendor/gem/<uuid>/sp-victim-1.0.0` does not exist. `vex` attests the gem as patched meanwhile: it reads the committed copy, and what rules_ruby builds from one is not judged. `vendor --revert` puts every file back, and the build with them. pypi::vendored_pip_parse now names the failure it asserts. rules_python makes the name of a repository from the path of the vendored line, and Bazel stops with `invalid user-provided repo name 'pip_311__/_socket/vendor/pypi/<uuid>/spvictim_1_0_0_py2_py3_none_any_whl'`. The flow also builds right after `vendor --revert`: the unpatched build is back before hosted mode pins the patch. Both flows pass on Bazel 9.3.2 with the product code as it is. Each compares the tool's message without white space: Bundler breaks its message at the width of the console it runs in, which differs from one machine to the next. The two Ruby flows share their stand-in. `Served::to` builds the gems of a run, serves them, grants the patch and routes Bazel's downloads, as the hosted flow did inline. The grant now holds what the patch service grants for a gem: the patched gem with a sha512, and its specification. Vendored mode downloads both, and hosted mode neither. The record of the patch holds the hashes of the gem's one file, in place of the placeholders of the shared stand-in. bazel-ruby.yml says in its header that the legs run both modes, and a pull request that changes vendor/gem.rs now starts them: the file was in the list of the pushes to main alone. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Decline PyPI and RubyGems vendored mode where a Bazel hub reads the lock rules_python's `pip.parse` and rules_ruby's `ruby.bundle_fetch` build the packages of a lock in repositories of Bazel's own. Vendored mode makes that lock name the patched copy by a path under `.socket/vendor`, and neither ruleset builds from such a lock. The command exited 0 with status `success`, and the next `bazel build` failed for everything the hub serves (Bazel 9.3.2, 8.8.2 and 7.7.2, the flows of the previous commit): - PyPI: rules_python 2.5.0-rc4 makes the name of a repository from the path of the vendored line, `invalid user-provided repo name 'pip_311__/_socket/vendor/pypi/<uuid>/<wheel>'`. - RubyGems: rules_ruby 1.0.0-rc2 runs `bundle install` in a repository that holds the Gemfile and its lock and not the copy, `The path .../.socket/vendor/gem/<uuid>/<name>-<version> does not exist.` Vendored mode now declines such a package before it downloads or writes anything, with `vendor_pypi_bazel_hub` or `vendor_gem_bazel_hub`. The refusal rests on what the files of the workspace say and on what the run would write, so it is for a run that would write a file a hub reads, and for no other. When it declines. The project is in a Bazel workspace (`bazel::bazel_root`), and a call of its files names, by a label written out as a string, a file of the project that the run for the package would point at a copy: - a `pip.parse` whose `requirements_lock`, `requirements_by_platform`, `requirements_darwin`, `requirements_linux`, `requirements_windows` or `uv_lock` names a requirements file of the project that the run would write (`requirements.txt` or a file it includes with `-r`), or the `uv.lock` of a uv project; - a `ruby.bundle_fetch` whose `gemfile` or `gemfile_lock` names the project's `Gemfile` or `Gemfile.lock`; - a call of a `WORKSPACE` file that passes one of those attributes, which is how the older form of either ruleset is called there (`pip_parse`, `rb_bundle_fetch`). Which files a PyPI run writes is asked of the backend's own router (`vendor::pypi::hub_files`). A project with no tool lock is wired through its requirements files, so they count. A uv, Pipenv or PEP 751 lock is wired together with a pin of the package in the requirements files beside it, so they count for a package they name (a pin, a hosted pin that a takeover restores first, or the vendored line of an earlier patch) and not for one they do not name. A Poetry or PDM lock is wired alone: such a project is not declined beside a hub that reads the requirements file exported from its lock, and is vendored as it is without Bazel. Every such call counts, also one that may not run (in a comprehension). Every package whose run would write a file the call names is declined, since the lock is the project's, but one that is already vendored (below). What an uncertain reading does. Where the files of the workspace cannot be read with certainty and a call of the hub may be behind that, every package whose run would write such a file is declined, in every project of the workspace: - a call of the hub whose file is not a plain string, or that passes `*` or `**`, and a hub proxy handed to anything but `use_repo` or `inject_repo`; - a module file that is missing or cannot be read, or a statement of one that cannot be read, where the workspace calls the hub or a file that was read names its ruleset (a `bazel_dep` on it, or a `use_extension` of the hub's `.bzl` file under any repository name); - a root `MODULE.bazel` or a `WORKSPACE` file that cannot be read at all. The last two matter because Bazel builds files that are not read here: one byte that is not UTF-8 is enough, in a comment too, and so is a file over 1 MiB. Without them the call in such a file was not seen and the run went on. Going on there can leave a broken build behind a command that exited 0, and declining costs a vendored run that the switch brings back. A workspace whose root `MODULE.bazel` and `WORKSPACE` file were read or are not there, and in which no file that was read calls the hub or names its ruleset, is never declined for it, whatever else cannot be read. Where nothing changes. Outside a Bazel workspace, in a workspace that calls neither hub, and for a package whose run writes no file that a call names (a project beside the one a hub reads, one whose `requirements.txt` is not the file the hub is given, a Poetry or PDM project whose exported requirements the hub reads), vendored mode prints what it printed and writes what it wrote. Other ecosystems, hosted mode and agent mode are not touched. Where it is asked. `bazel::built` already says for `vex` which hub reads which lock; `reader` there answers this question from the same table and the same reader of workspace files, and takes `uv_lock` as one more attribute. `vendor::bazel_hub::refusals` asks it about the files the run of each package would write and words the refusal. `vendor::refusals::bazel_workspace_refusals`, the one answer every vendored entry point takes for a refusal that rests on the Bazel workspace, returns it beside the Composer refusal. So it reaches `scan --mode vendored`, `get --mode vendored`, `vendor` for a patch the manifest records, the takeover of a hosted pin by a vendored scan, and the eject of one by `vendor`, which asks once and before it fetches a record. No command's own code changes. The package is a `failed` event and the run exits 1 (`partialFailure`; for the eject `eject_refused`, detail `kept hosted: ...`). A dry run of `scan` or `get` lists the package as one the run would refuse and exits 0; `vendor --dry-run` reports the refusal and exits 1, as it does for any package it could not vendor. Nothing is written, no patch is downloaded, and a hosted pin stays. These are the exit codes of the Composer refusal. The detail names the call with its file and line, the lock, the Bazel root and hosted mode: `pip.parse` (MODULE.bazel:15) of the Bazel workspace at /repo names requirements.txt; vendored mode makes the lock name the patched copy by a path under .socket/vendor, and rules_python fails the build on such a lock; use `--mode hosted`, which names the patched package by a URL that rules_python fetches, or pass `--allow-vendored-in-bazel` if no build takes the packages of this project from rules_python For a doubt it names the file, the line and the reason in the place of the call. Hosted mode pins the patch in the same file, and both rulesets build it: the two flows end with that build. For a gem the detail adds the condition under which rules_ruby builds a hosted pin, "where its call passes no `gem_checksums`": with an entry for the gem there the hosted build fails, which the docs list as a known problem. `--allow-vendored-in-bazel` (SOCKET_ALLOW_VENDORED_IN_BAZEL) lifts the refusal, as it lifts the Composer one: for a hub that no build uses, a `WORKSPACE` file that the Bazel in use does not read, or a `ruby.bundle_fetch` that is given the files of the copy as `srcs`. Its help text, its row in CLI_CONTRACT.md and the sentence of docs/ecosystems.md that named Composer as the one refusal it lifts now name the three. `vendor --revert` is not refused. Neither is a package that is already vendored, as for Composer. What is declined is the write of the path into the lock the hub reads, so a package that the file the call names already names by the copy of the same patch (`.socket/vendor/pypi/<uuid>/`, `.socket/vendor/gem/<uuid>/`, outside a comment) is let through: the run adds nothing to what the hub reads. A project vendored with the switch, or by an earlier release, keeps passing its in-sync runs without the switch, a `scan` or `get` that names no mode included, which runs in vendored mode there. A new patch for that package, and any other package, is declined as before. It is the named file that decides, not any file of the project: a uv project whose lock names the copy while the hub reads a requirements file that still pins the registry's release would have that file rewritten by the run, and is declined. That file is read as a lock of the workspace is (`built::lock_text`): up to 64 MiB, and not through a link that leads out of the Bazel root, so such a link lets nothing through. Where the reading is in doubt no file is known to be the hub's, so nothing is let through there. Such a run passing does not make the build the patched one: for PyPI `vex` says `affected` of that state. No line a person reads is new: the refusal prints where every refused vendored package does. Tests: - pypi::vendored_pip_parse and ruby::vendored_bundle_fetch (real Bazel) now hold the command to the refusal: exit 1, the code, a detail that names the call, the lock, `--mode hosted` and the switch, no file changed and no request for the patched wheel or gem. The same build passes on the upstream package. With the switch the expectations of the previous commit are back: the package is vendored, the build fails with the ruleset's message, and `vendor --revert` restores the build. Hosted mode then builds the patched package. - Hermetic tests of both files, on steps the harness now holds for both: every command that would vendor declines and writes nothing, the dry runs and the eject among them; vendored mode goes on with the switch and with its variable, a later run without them passes and writes nothing, a scan that names no mode included, and `vendor --revert` needs neither; it goes on with no switch in a workspace whose hub reads another file, in a project beside the one it reads, and in no workspace; a hub whose file is not written out declines. For PyPI also: a Poetry project beside a hub that reads its exported `requirements.txt` is vendored with no switch, that file stays as it is and the later runs pass; and a `MODULE.bazel` with one byte that is not UTF-8 declines. - Unit tests of `built::reads` (each attribute, a call that may not run, `uv_lock`, another project, another repository, a doubt of the call, of the proxy and of the workspace, a hub that is not called, the `WORKSPACE` file; a root module file, an included file and a `WORKSPACE` file that cannot be read, with a root that names the ruleset as a dependency, by its extension, or not at all), of the refusal (codes, words, the switch, a file brought in with `-r`, the `Gemfile` alone, no workspace; a package the named lock already names by the patch's copy, and the same copy named in a comment, in another file, behind a link out of the root or under a doubt; a Poetry and a PDM lock, and a uv and a Pipenv lock beside a requirements file that names the package or does not) and of its dispatch. Four tests of pypi.rs vendored a wheel beside the hub that reads the requirements, to hold `vex` to what it says of that state. The command that writes the line now has the switch there, and they assert what they asserted; the in-sync runs after it have none, as before. Docs: docs/ecosystems.md "Bazel workspaces: PyPI and RubyGems vendored mode", the two rows of the matrix, and what "Bazel workspaces: VEX" says of a vendored gem, which a build has now shown; the rows of the two codes, of the switch and of the vendored table in CLI_CONTRACT.md. In "Bazel workspaces: what is supported" the two vendored cells stay "Not supported", and the note on that word now says that the command declines there. The entry of the known problems for vendored mode listed commands that exit 0 and leave a failing build: PyPI and RubyGems leave it, and so does Composer, which declines since the change before this one; NuGet stays. bazel-pypi.yml and bazel-ruby.yml start their legs for a change to vendor/bazel_hub.rs and vendor/refusals.rs, and bazel-pypi.yml for one to vendor/pypi.rs. The `bazel` group of scripts/loc-budget.json follows the 69 lines added to built.rs. Not covered: a hub call in a `.bzl` file that a `WORKSPACE` file loads, a hub of another Bazel module, another tag or ruleset that reads the same file under Bzlmod, a `WORKSPACE` call that hides its arguments behind `**`, a Bazel root above the git checkout, and a hub whose call and whose `bazel_dep` are both in an included file that cannot be read while the files that were read name neither: vendored mode goes on there as before. A package of a uv, Pipenv or PEP 751 project that the hub's requirements file names in a form that is not wired with the lock (a range, extras) is declined although the run would leave that file alone. `vex` still attests a gem that was vendored with the switch as patched, while its build fails. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Close three ways a vendored run could still write a file a Bazel hub reads A review of the PyPI and RubyGems vendored declines found three states in which the run was let through and would write a file that a hub of the Bazel workspace reads: - A Poetry or PDM project whose exported requirements file holds the package by a URL, which is what a hosted pin is. The lock of such a project is wired alone, so its requirements files did not count, but a vendored run that takes a hosted pin over restores that line. The files now count for a package they hold by a URL. A package they pin from the registry is vendored as before. - A `WORKSPACE` call that names the lock through the name the file gives the main repository (`@shop//api:requirements.txt` beside `workspace(name = "shop")`). The label was taken for another repository's. It is the main repository now, for the calls of that file. - A package that is already vendored, where the calls name more than one file of the project. Only the first file a call names was read, so a `uv.lock` locked again beside a vendored requirements file let the package pass, and the run rewrote the lock. Each file a call names that holds the package now has to name the copy; one that cannot be read may hold it. Also from the review: the requirements file is no longer listed twice, the gem's two files are the gem backend's own constants, and the files of a package are chosen by its ecosystem and not by the text of its purl type. The docs and the contract row say what was imprecise: the requirements files of a project with no tool lock count as one set, also for a package a file of the set does not pin, because a file the hub reads can bring in the rewritten one with `-r`; and the `pip_install(requirements = ...)` of an older rules_python is not seen. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Decline a vendored run where a hub reads a parent file or is in doubt Two states in which a vendored PyPI run was still let through and would write a file a Bazel hub reads: - A hub that names a requirements file which brings the project's own in with `-r` (`all.txt` with `-r requirements.txt`). The files a run writes are walked down from `requirements.txt`, so the file the hub named was not among them and nothing was declined. A requirements file a call names now counts as naming each file its `-r` includes reach, read inside the Bazel root as any lock is, and the refusal names it. - An already-vendored package whose other files a call may name where the reading is in doubt: a second attribute that is not written out, or a call that may be behind a file that could not be read. Only a certain answer had that file read; a doubt was dropped and the package let through. A doubt now has the file read as well, so the package is declined where that file holds it and not by the copy. The `bazel` line budget goes from 2574 to 2611. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011f9aeQFeU3sKRPzawaNLsm Assisted-by: Claude Code:claude-opus-5-5 * Test what vendored mode does for a NuGet package of a rules_csharp hub 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> * Make vendored mode work for a NuGet package of a rules_csharp hub, or 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> * Keep the block of a rules_csharp hub right through an undo, a later patch 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> * Build the NuGet hub tests on Windows 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> * Accept either unseen repository where a Cargo flow comments out the ignore line `cargo::vendored_from_cargo_with_config` comments out the line the scan wrote in `.bazelignore` and expects `bazel cquery //...` and `bazel query 'deps(//...)'` to fail on a repository that the main repository does not see. It looked for the hub's repository (`@crates__...`) alone. The build file that cargo-bazel writes into the committed copy names `@platforms` as well, and Bazel reports the first one it meets: on a Linux runner with Bazel 9.3.2 the query named `@platforms` and the flow failed on its own check. The flow now takes either name for that failure. Test only: nothing the command does changes. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Hold the unseen repository to Bazel's own words, and say so in the docs The check of the commands that fail once the ignore line is commented out now reads the name out of Bazel's message and takes it only when the message is about the main repository's view: `platforms`, or a repository of the crate hub. The same words about another repository's view, or about another name, are a different failure and no longer pass for the expected one. A test without Bazel holds the check to the two messages that were seen and to three it must not take. The module docs, the comment at the call and the section on the build file in a vendored crate said the commands end on the dependency's repository alone. They now name `platforms` as well, which is what a user who comments the line out can see. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Pass over a WORKSPACE file where the checkout names Bazel 9 or later Vendored mode declines a PyPI or RubyGems package whose lock a Bazel hub reads, and it counted a call of a `WORKSPACE` file that names the lock as such a hub (`pip_parse`, `rb_bundle_fetch`). Bazel 9 never reads a `WORKSPACE` file. One that a move to Bzlmod left behind can still name `requirements.txt` or `Gemfile.lock`, so in a checkout that Bazel 9 builds, a vendored run that worked before exited 1 with `vendor_pypi_bazel_hub` or `vendor_gem_bazel_hub`, with no hub that takes the lock. Where the checkout names a Bazel release of 9 or later, a `WORKSPACE`, `WORKSPACE.bazel` or `WORKSPACE.bzlmod` file now counts for nothing in these two refusals: a call of it is no reader of the lock, a call of it that is not written out is no doubt, and neither is a file that cannot be read. The run does what it does without the file. The exception for a package that is already vendored asks the same reader, so it agrees. The release is read as the Maven reader reads it (`rc::declared_release`: `USE_BAZEL_VERSION` of `.bazeliskrc`, else `.bazelversion`, and only three numbers name one). One rule, `rc::reads_workspace_file`, holds "before 9, or not named", and the Maven reader now asks it in the place of its own closure. So a checkout that names 7.x or 8.x, `latest`, a release candidate or no release keeps the refusal: a Bazel 7 or 8 may build it. What `vex` says is not changed: `built::unbuilt` still says nothing beside a `WORKSPACE` file. Tests: unit rows in bazel/rc.rs and bazel/built.rs (the lock a call names, the call that is not written out and the file that cannot be read, under nine ways to name a release), and one test each in e2e_bazel_build/ruby.rs and pypi.rs that runs the built binary without Bazel. With `.bazelversion` 9.3.2, 9.0.0 or 10.0.0 beside a retained `WORKSPACE` that names the lock, `scan --mode vendored` vendors the package and writes the files it writes without that file; with 7.7.2, 8.8.2, no file or `latest` it is declined as before. With the rule switched off, the test of built.rs and both of those fail on their first 9.x row. docs/ecosystems.md and the contract row of the two codes say when the file counts. The `bazel` cap of scripts/loc-budget.json is the new count, 4047. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Hold the off switch and the VEX answer to a NuGet package vendored for 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> * Decline a NuGet package for vendored mode where a hub may read the lock 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> * Say both ways a hub that is not seen fails after a flat vendored run 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> * Hold the NuGet vendored gate apart from a WORKSPACE file 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> --------- Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
1 parent 4ecfd4f commit 4341167

17 files changed

Lines changed: 3455 additions & 229 deletions

File tree

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

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ name: Bazel patch compatibility (NuGet)
33
# The NuGet flows of the real-Bazel tests (`nuget::` in `e2e_bazel_build`):
44
# hosted mode for a package that rules_csharp's `nuget.from_lock` reads from
55
# `packages.lock.json` and `nuget.config`, for a tag that names no
6-
# `nuget_config`, and agent mode for the copy of the package in NuGet's
7-
# global packages folder, on each Bazel release below.
6+
# `nuget_config`, agent mode for the copy of the package in NuGet's
7+
# global packages folder, and vendored mode for the same package, through
8+
# the block it keeps in `MODULE.bazel`, on each Bazel release below.
89
# bazel-compatibility.yml holds the legs and what every ecosystem shares;
910
# this file says when the NuGet legs run and on which releases.
1011
#
@@ -40,10 +41,15 @@ on:
4041
# files, the upstream restore of `rollback`, and the hosted scan's check
4142
# of that folder. Then what reads the tag in `MODULE.bazel`: the reader
4243
# of the workspace files, which every ecosystem's flow shares
43-
# (bazel/mod.rs, starlark.rs and workspace.rs), and what hosted mode
44-
# makes of the tag (bazel/nuget.rs).
45-
# vendor/nuget_feed.rs is the vendored backend; it is here for the
46-
# version and folder helpers that every one of those files calls.
44+
# (bazel/mod.rs, starlark.rs and workspace.rs), and what hosted and
45+
# vendored mode make of the tag (bazel/nuget.rs).
46+
# vendor/nuget_feed.rs is the vendored backend, which the vendored flow
47+
# runs; every one of those files calls its version and folder helpers.
48+
# The vendored flow also runs through the block of `MODULE.bazel`
49+
# (bazel/block.rs), what bazel/maven.rs shares with it (the label of a
50+
# `use_extension` and the release of a ruleset), what names the Bazel
51+
# release and the rc files (bazel/rc.rs), and the dispatch of the
52+
# refusals of vendored mode (vendor/refusals.rs).
4753
# patch/sidecars/nuget.rs is what agent mode does to a package in
4854
# NuGet's folder beyond its files. Last, the VEX code: `vex/` of the
4955
# core, the files of the `vex` command, and what `vex` makes of the tag
@@ -78,9 +84,13 @@ on:
7884
- 'crates/socket-patch-core/src/vex/discover/nuget.rs'
7985
- 'crates/socket-patch-core/src/patch/redirect/upstream/nuget.rs'
8086
- 'crates/socket-patch-cli/src/commands/scan/hosted/nuget.rs'
87+
- 'crates/socket-patch-core/src/vendor/refusals.rs'
88+
- 'crates/socket-patch-core/src/bazel/block.rs'
8189
- 'crates/socket-patch-core/src/bazel/built.rs'
90+
- 'crates/socket-patch-core/src/bazel/maven.rs'
8291
- 'crates/socket-patch-core/src/bazel/mod.rs'
8392
- 'crates/socket-patch-core/src/bazel/nuget.rs'
93+
- 'crates/socket-patch-core/src/bazel/rc.rs'
8494
- 'crates/socket-patch-core/src/bazel/starlark.rs'
8595
- 'crates/socket-patch-core/src/bazel/workspace.rs'
8696
- 'crates/socket-patch-core/src/patch/sidecars/nuget.rs'
@@ -92,8 +102,11 @@ on:
92102
# root of the test target (it changes when an ecosystem's module is
93103
# added; ci.yml builds the target and runs its hermetic tests on every
94104
# pull request), the shared engine code and test helpers the flows run
95-
# through, and the toolchain files. A main push outside this list waits
96-
# for the nightly run below.
105+
# through, the ledger and the artifact paths of vendored mode
106+
# (vendor/state.rs and vendor/path.rs, which every ecosystem shares:
107+
# they hold the record of the block and the place of a hub's package),
108+
# and the toolchain files. A main push outside this list waits for the
109+
# nightly run below.
97110
paths:
98111
- '.github/workflows/bazel-nuget.yml'
99112
- '.github/workflows/bazel-compatibility.yml'
@@ -109,9 +122,13 @@ on:
109122
- 'crates/socket-patch-core/src/vex/discover/nuget.rs'
110123
- 'crates/socket-patch-core/src/patch/redirect/upstream/nuget.rs'
111124
- 'crates/socket-patch-cli/src/commands/scan/hosted/nuget.rs'
125+
- 'crates/socket-patch-core/src/vendor/refusals.rs'
126+
- 'crates/socket-patch-core/src/bazel/block.rs'
112127
- 'crates/socket-patch-core/src/bazel/built.rs'
128+
- 'crates/socket-patch-core/src/bazel/maven.rs'
113129
- 'crates/socket-patch-core/src/bazel/mod.rs'
114130
- 'crates/socket-patch-core/src/bazel/nuget.rs'
131+
- 'crates/socket-patch-core/src/bazel/rc.rs'
115132
- 'crates/socket-patch-core/src/bazel/starlark.rs'
116133
- 'crates/socket-patch-core/src/bazel/workspace.rs'
117134
- 'crates/socket-patch-core/src/patch/sidecars/nuget.rs'
@@ -120,6 +137,8 @@ on:
120137
- 'crates/socket-patch-cli/tests/e2e_bazel_build/main.rs'
121138
- 'crates/socket-patch-core/src/patch/redirect/**'
122139
- 'crates/socket-patch-core/src/hosted/**'
140+
- 'crates/socket-patch-core/src/vendor/path.rs'
141+
- 'crates/socket-patch-core/src/vendor/state.rs'
123142
- 'crates/socket-patch-cli/src/commands/**'
124143
- 'crates/socket-patch-cli/tests/common/**'
125144
- 'crates/socket-patch-cli/tests/hosted_memory_common/**'

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

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

‎crates/socket-patch-cli/src/args.rs‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -430,13 +430,15 @@ pub struct GlobalArgs {
430430
/// a package by default: a Composer package
431431
/// (`vendor_composer_bazel_workspace`), whose lock names the copy by a
432432
/// path that a Bazel rule running `composer install` in another
433-
/// directory does not find, and a PyPI or RubyGems package whose lock
434-
/// a rules_python or rules_ruby hub of the workspace reads
433+
/// directory does not find; a PyPI or RubyGems package whose lock a
434+
/// rules_python or rules_ruby hub of the workspace reads
435435
/// (`vendor_pypi_bazel_hub`, `vendor_gem_bazel_hub`), which builds
436-
/// nothing from a lock that names a copy under `.socket/vendor`. Pass
437-
/// it when the build does find the copy, or does not take the
438-
/// project's packages from that lock. Other subcommands accept it
439-
/// silently.
436+
/// nothing from a lock that names a copy under `.socket/vendor`; and a
437+
/// NuGet package of a rules_csharp hub where the `MODULE.bazel` block
438+
/// that makes the hub take the copy cannot be shown to work
439+
/// (`vendor_nuget_bazel_workspace`). Pass it when the build does find
440+
/// the copy, does not take the project's packages from that lock, or
441+
/// does not build the project. Other subcommands accept it silently.
440442
#[arg(
441443
help_heading = GLOBAL_OPTIONS,
442444
long = "allow-vendored-in-bazel",

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,21 @@ impl Cell {
968968
self.downloads = Some(rules.to_vec());
969969
}
970970

971+
/// Take the file whose sha256 is `sha256` out of the repository cache,
972+
/// which the tests of a leg and every twin share: whether it was
973+
/// there. Bazel then has to fetch that file again from where its URLs
974+
/// lead, as on a machine that never had it.
975+
pub fn uncache(&self, sha256: &str) -> bool {
976+
let cache = &self.scratch.repository_cache;
977+
let entry = cache.join("content_addressable/sha256").join(sha256);
978+
let held = entry.join("file").is_file();
979+
if held {
980+
std::fs::remove_dir_all(&entry)
981+
.unwrap_or_else(|e| panic!("remove {}: {e}", entry.display()));
982+
}
983+
held
984+
}
985+
971986
/// Whether the repository cache of this cell, which its twins share,
972987
/// holds a download with the sha256 `sha256`: what Bazel's downloader
973988
/// keeps of a file it fetched under a checksum.

0 commit comments

Comments
 (0)