Skip to content

Vendor a gem for a Bazel hub as its archive, named by a relative file: URL - #2211

Open
Mikola Lysenko (mikolalysenko) wants to merge 8 commits into
bazel-guard/vendored-hub-locksfrom
bazel-vendored/gem-file-source
Open

Mikola Lysenko (mikolalysenko) wants to merge 8 commits into
bazel-guard/vendored-hub-locksfrom
bazel-vendored/gem-file-source

Conversation

@mikolalysenko

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

Copy link
Copy Markdown
Collaborator

Vendored mode now patches a RubyGems dependency that a rules_ruby ruby.bundle_fetch hub builds, by committing the patched gem and naming it in Gemfile and Gemfile.lock with a relative file: URL, wherever the checkout shows that Bazel builds that form; everywhere else it declines as before.

Stacked on the pull request that makes vendored mode decline beside a hub ("Decline PyPI and RubyGems vendored mode where a Bazel hub reads the lock").

Decisions for the maintainer

  1. The form itself. A relative file: source in Gemfile and Gemfile.lock, with the patched gem committed under .socket/vendor, was decided by the maintainer on 2026-11-20. Its price is that Bundler by itself does not install from that source in the same checkout (see Limits); the run says so in a warning, and hosted mode is the mode that serves both builds. The other forms that built were labels written into the ruby.bundle_fetch call, and a committed Bazel extension; neither is built here.
  2. A checkout that names no Bazel release is declined. The form relies on Bazel opening a relative file: URL. Bazel 9.1.0 fails on one (Bazel's own history: "Migrate from URL to URI" in 9.1.0, "downloader: fix opaque file URI names" in 9.1.1 and 9.2.0; read, not run). Without three numbers in .bazelversion, or in USE_BAZEL_VERSION of .bazeliskrc, nothing says that the build is not on 9.1.0, so the gem is declined and the message says what is missing. latest and a release candidate count as no release. The alternative is to go on with a warning, which can leave a broken build behind a command that exited 0.
  3. Which Bazel releases count. Every release of Bazel 7, 8 and 9 except 9.1.0. Built: 9.3.2, 8.8.2 and 7.7.2. A stricter rule (only the built releases and later ones of each line) would decline many checkouts that pin an older 7.x or 8.x.
  4. Which Bundlers count. rules_ruby installs the Bundler that the lock's BUNDLED WITH names in the hub and runs it there. The form is built with 4.0.15 and with 2.6.9, on the three Bazel releases, and both fail the build on a changed byte. A lock is taken when it names 2.6 or later of the 2 line, or a Bundler 4. A lock of Bundler 2.2 to 2.5 is declined, although rules_ruby itself builds from one: no build here ran the form with such a Bundler. To widen the rule, add an older Bundler to ruby::file_source_by_hand.
  5. The tests download one more gem from rubygems.org. Bazel fetches bundler-2.6.9.gem there, with the sha256 of rules_ruby's own table, as the three flows already fetch bundler-4.0.15.gem. No gem under test comes from a public registry.
  6. socket-patch never edits the ruby.bundle_fetch call. Where gem_checksums has an entry for the gem, the run declines until you write the sha256 of the patched gem there, and an undo leaves that value in place: the build then fails until you put the upstream one back or delete the entry. The undo says so in a warning. The alternative is to write a Bazel file.
  7. The switch keeps its meaning. --allow-vendored-in-bazel still writes the unpacked copy named by its path, also where the new form would be written without it.
  8. A hosted pin can now be taken over or ejected into this form by scan --mode vendored or vendor, where the conditions hold. On the base both were declined and the hosted pin stayed.
  9. The project must be the root of the Bazel workspace. Bazel opens the URL from the root, so a project below it is declined; that shape was not built.
  10. Size. 785 lines of code outside tests (sizes below). Most of it is one new file; the two files a build reads are written by the hosted planner that already exists. Two paths could go if size matters more: writing the gem again when the pair is in place and the ledger has no entry, and a newer patch taking the source over in place (about 40 lines together; each is a working path today).

Today

Where a ruby.bundle_fetch call of the workspace reads the project's Gemfile or Gemfile.lock, vendored mode declines the gem with vendor_gem_bazel_hub and writes nothing: the copy it commits is named by a path, rules_ruby runs bundle install in a repository of Bazel's that does not hold that path, and the build fails.

What changes

For such a gem vendored mode commits the archive the patch service serves and writes the pair that hosted mode writes, with a relative URL of the checkout in the place of the patch registry's:

gem "rack", "~> 2.2", source: "file:.socket/vendor/gem/<uuid>/"     # Gemfile

GEM                                                                 # Gemfile.lock
  remote: file:.socket/vendor/gem/<uuid>/
  specs:
    rack (2.2.3)

DEPENDENCIES
  rack (~> 2.2)!

CHECKSUMS
  rack (2.2.3) sha256=<the patched gem>

.socket/vendor/gem/<uuid>/gems/rack-2.2.3.gem                       # the patched gem

rules_ruby asks Bazel for <remote>gems/<name>-<version>.gem, Bazel opens the URL from the root of the workspace, and Bundler holds the file to the CHECKSUMS line. No file of Bazel's is written. The directory of the patch also gets the marker and a .gitignore / .gitattributes of its own (stock ignore templates name *.gem).

It is written only where all of these hold, each read from files of the checkout:

  • the checkout names a Bazel release of 7, 8 or 9 other than 9.1.0, as three numbers;
  • the project is the root of the Bazel workspace;
  • the module files are read with certainty, no WORKSPACE file defines a repository, every ruby.bundle_fetch call writes out the files it reads, and a call that reads one of the two files reads both;
  • something holds the gem to its bytes in the hub of every call that reads the two files: the lock has a CHECKSUMS section, or each such call has a gem_checksums entry for the gem;
  • every gem_checksums entry for the gem, in any of those calls, is the sha256 of the patched gem (known after the download; the message names the call and the value to write);
  • the lock's BUNDLED WITH names Bundler 2.6 or later of the 2 line, or a Bundler 4;
  • the lock holds the gem as its ruby-platform entry.

Where one does not hold the gem is declined with the same code and exit code as before, nothing is written, and the message names the condition. What vendored mode refuses for every gem (a native extension, a declaration it cannot edit) is refused first, as outside Bazel.

Nothing changes for a project outside a Bazel workspace, for a project in a workspace whose hubs read none of its files, or for any other ecosystem.

The other commands follow. A later run is in sync. vendor --check holds the committed gem to the patch and to the ledger. repair downloads it again. vendor --revert, rollback and remove take the source off the Gemfile, put the lock's entry back where Bundler sorts it with its DEPENDENCIES and CHECKSUMS lines as they were (byte for byte for a lock in Bundler's own order), and delete the directory; a pair whose source: or GEM section is no longer what the run wrote is left alone. list and vex show the gem as vendored. A person who runs the command is told to build with Bazel as the next step, not to reinstall.

Limits

The run says the first two in a warning (vendor_gem_bazel_file_source):

  • Bundler by itself does not install from that source. bundle install on a machine that has not installed the gem fails, and so does every bundle lock --update. On a machine that installed the gem before the patch, bundle install passes and the program runs that unpatched copy, with no error. The checkout then builds its gems through Bazel only. Hosted mode serves both builds.
  • Bazel does not watch the committed gem. An output base that fetched the gems before keeps building what it fetched when only the gem changes; it never builds the changed bytes. The other way too: one that fetched a damaged gem keeps failing after repair until it fetches the hub again. A change of Gemfile.lock or a new output base fetches again.
  • An undo leaves the gem_checksums entry you wrote. After vendor --revert, rollback or remove the build fails on it (Checksum was ... but wanted ...) until it holds the upstream sha256 again or is deleted. The undo warns (vendor_gem_bazel_checksum_left).
  • The gem's bytes are held by the lock's CHECKSUMS line or by gem_checksums, and by nothing else; with neither the gem is declined. vex holds the committed gem to its patched files; vendor --check and a fresh build hold it to its bytes.
  • A dry run downloads nothing, so it does not show the decline for a gem_checksums entry that holds other bytes.
  • The Bazel release is the one the checkout names. A release that a machine's environment names instead is not seen.
  • A hub that Bazel does not fetch again (pinned in a vendor directory made before the patch, or built with --nofetch) keeps the gems it has, in every mode.
  • The form rests on Bazel's server opening a relative URL from the root of the workspace, which Bazel documents nowhere.

Contents

Lines
Code outside tests +1125 / -54 (785 lines of code): vendor/gem/bazel.rs (new: the conditions, the write, the undo and its warning, the archive check) 664; lock discovery 32; the gem backend's hooks 28; the refusal layer 21; the hosted planner's entry point 15; the workspace reader 11; repair and vendor --check 9; the next-step line of the CLI 5
Unit tests in the same files +803 / -5
Real-Bazel and hermetic tests (e2e_bazel_build/ruby.rs) +681 / -103
Docs (docs/ecosystems.md, CLI_CONTRACT.md) +183 / -22
Workflow paths, loc budget +7 / -4

Two commits. The first is tests only: a flow that writes the three files by hand and builds them, which passes on the code as it was. The second is the change, with the flow of vendored mode rewritten to hold the command to those files.

What it proves, and where

  • Real Bazel 9.3.2, 8.8.2 and 7.7.2, macOS arm64, at the head of this pull request. Written by hand: a second machine with a new output base, no patch host and no copy of the gem in the repository cache prints the patched marker, and one changed byte fails a third machine's build (Bundler found mismatched checksums); the same again on two machines whose lock names Bundler 2.6.9, where the hub holds that Bundler. Written by the command: the same three files byte for byte, the next build prints the patched marker with no request for a patched or an upstream gem, vendor --check passes and catches one changed byte, a second machine's build fails on it, vendor --revert restores every file and the upstream build, and the VEX documents are held to the patched build. In a checkout that names no release the command declines and the build stays as it was. The legs of bazel-ruby.yml run the three releases.
  • With the change taken out (a binary of the parent), the flow of vendored mode fails on Bazel 9.3.2, and so do three of the five tests without Bazel.
  • Without Bazel, through the binary: the run, its dry run, in-sync runs, vendor --check, repair, the three undos with the warning for an entry left in the call, the next step a person is given, a lock of Bundler 2.6.9, the switch, a hosted scan over the vendored gem, the takeover of a hosted pin, and every condition that declines, a second call that reads the same two files among them.
  • Do no harm: for 40 runs in four places without a hub that reads the project's files, a binary of this change and a binary of its base print the same output, exit the same and leave the same files, byte for byte.
  • Unit tests: one case per condition; two calls over the same pair; the undo over a declared gem, an undeclared one, CRLF files and a lock without CHECKSUMS; the warning of the undo; a newer patch that follows an older one; a pair that drifted; a ledger record that names another gem's line; the backend against a stand-in for the patch service; lock discovery.
  • Deliberate breaks of the code. Four were run on the final code and each was caught by the test written for it. Sixteen more are written and were not run on the final code.

Not covered

  • rb_bundle_fetch in a WORKSPACE file, a project below the Bazel root, a gem locked as platform gems and a lock of a Bundler older than 2.6: declined.
  • Windows, releases of rules_ruby other than 1.0.0-rc2, and a Bundler other than 4.0.15 and 2.6.9 inside the hub: not run. Local runs were on macOS only.
  • A gem that the Gemfile does not declare builds patched by hand on Bazel 9.3.2; no test here builds one. A newer patch that follows an older one is tested without Bazel only.
  • Two ruby.bundle_fetch calls over the same pair: the conditions are tested without Bazel. No test here builds two hubs.
  • Measured by hand and not by a test here: the failing build after an undo with a gem_checksums entry (9.3.2), plain Bundler on the vendored checkout (4.0.15), a hub pinned in a vendor directory and --nofetch (9.3.2).
  • vex still says nothing of a gem vendored by its path with --allow-vendored-in-bazel, whose build fails, as before.

Code review

Nine findings, each checked against the code. Six are fixed in one commit on top ("Close six gaps of a gem vendored for a Bazel hub that a review found"), each with a test except the second:

  • The gate did not read the rc files. A .bazelrc, or a file it imports, that names --experimental_remote_downloader, --repository_disable_download or --vendor_dir now declines the gem, as does an rc file that cannot be read. Under the first a remote downloader is handed the URL in the place of Bazel's own (read in Bazel's source: 9.3.2 keeps a file: URL to itself, 7.7.2 does not); none of the three was built.
  • A dry run showed a gem that the run then refused, where git ignores the directory. The check now comes before the download and before the dry run returns. No test was added for the order.
  • An undo wedged on a half-restored pair. With one of Gemfile and Gemfile.lock put back by hand, every undo warned and left the other file and the gem. The other file now goes back by itself.
  • A planner refusal named a way on that is hosted mode's. The decline now says so.
  • The closing step named the Bazel build only when every package was such a gem. A run that vendored other packages too adds a line for it.
  • The two wiring kinds were not among the kinds whose file the ledger checks.

The real-Bazel flow also builds the unpacked copy under --allow-vendored-in-bazel again, and asserts the failing bundle install: the rewrite of the flow had dropped the one build that shows what the decline is for.

Not changed:

  • The rules_ruby release is not part of the gate. The finding feared an older ruleset that does not ask the lock's remote for the gem. Every release that has bundle_fetch (0.5.0 to 1.0.0-rc2) downloads <remote>gems/<name>-<version>.gem with Bazel's downloader (read in the ruleset's source); hosted mode rests on the same line and has no such gate. Built with 1.0.0-rc2 only.
  • The refusals of every vendored gem answer first, also where the committed gem would not need them (a declaration inside a group block, a gem with a native extension, a patch without a stub specification). They are false declines, not broken builds; narrowing them is a change of its own.
  • The workspace is read more than once per gem. Time only.
  • The remote a ledger record names for the undo is not checked against where the gem came from. It needs a changed state.json, which is a committed file, and the record's lines for the gem are checked.

Generated by Claude Code

Tests only. rules_ruby's `ruby.bundle_fetch` copies `Gemfile` and
`Gemfile.lock` into a repository of Bazel's, has Bazel download
`<remote>gems/<name>-<version>.gem` for every gem of a `GEM` section, and
runs `bundle install --local` there. Vendored mode names its copy by a
path, which that repository does not hold, so beside such a hub the
command declines (ruby::vendored_bundle_fetch, which stays as it is).

ruby::file_source_by_hand shows a vendored form that this hub does
build, written by hand in the fixture of the two other flows (rules_ruby
1.0.0-rc2, a lock with a `CHECKSUMS` section, no `gem_checksums`). It is
the pair hosted mode writes, with a relative `file:` URL of the checkout
in the place of the patch registry's:

    gem "sp-victim", "1.0.0", source: "file:.socket/vendor/gem/<uuid>/"

    GEM
      remote: file:.socket/vendor/gem/<uuid>/
      specs:
        sp-victim (1.0.0)

    DEPENDENCIES
      sp-victim (= 1.0.0)!

    CHECKSUMS
      sp-victim (1.0.0) sha256=<the patched gem>

and the patched gem committed at
`.socket/vendor/gem/<uuid>/gems/sp-victim-1.0.0.gem`, where rules_ruby
asks that source for it. No file of Bazel's is written. Bazel's server
runs in the root of the workspace and opens the URL from there, and
Bundler holds the file to the lock's `CHECKSUMS` line.

The flow builds the unpatched checkout, writes the three files, and
builds them on a second machine: a new output base (on Bazel 9 a new
contents cache too), a downloader config that sends nothing to a patch
host and refuses its URLs, and a repository cache that holds no copy of
the patched gem. `bazel build` and `bazel run //:consumer` print the
patched marker, Bazel changes no file, a `--lockfile_mode=error` build
passes, and the stand-in was asked for no patched gem and for no
further upstream one. On a third machine the last byte of the committed
gem is another one. That byte is padding of the tar, so RubyGems still
reads the file, and the build fails in the `bundle install` action with
"Bundler found mismatched checksums", which names the sha256 of the
lock and the one of the file.

rules_ruby installs the Bundler that the lock's `BUNDLED WITH` names in
the hub and runs it there. The fixture's lock names 4.0.15, and most
locks today name a Bundler of the 2 line, so a fourth and a fifth
machine do both again with 2.6.9 in the lock: the hub holds
`@bundle//:bundler-2.6.9`, the build prints the patched marker, and the
changed byte fails it with the same message. Bazel downloads that
Bundler from rubygems.org with the sha256 of rules_ruby's own table, as
it does the 4.0.15 of the other flows.

The flow passes on Bazel 9.3.2 with the product code as it is, and on
8.8.2 and 7.7.2 with the change that follows, which it does not use
(macOS arm64).

The downloader rules of a flow are now a function (`routes`), so that a
machine without a patch host keeps the two rules for the gems of
rubygems.org. Bundler's message is compared without white space in one
place for both flows.

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

Vendored mode declined every gem whose `Gemfile` or lock a
`ruby.bundle_fetch` call of the Bazel workspace reads
(`vendor_gem_bazel_hub`): the copy it commits is named by a path, and
rules_ruby runs `bundle install` in a repository of Bazel's that does not
hold it. It now vendors such a gem in a form that the hub builds, where
the files of the checkout show that it builds, and declines everywhere
else as before.

The form. The patched gem is committed as the archive the patch service
serves, at `.socket/vendor/gem/<uuid>/gems/<name>-<version>.gem`, and the
two files name it as hosted mode names a patch registry, with the
relative URL `file:.socket/vendor/gem/<uuid>/` in the registry's place:
a `source:` option on the gem's declaration (or the line hosted mode
adds for a gem the Gemfile does not declare), a `GEM` section of the
gem's own with that remote, a source-pinned `DEPENDENCIES` entry, and
the sha256 of the patched gem in `CHECKSUMS`. These are the three files
of ruby::file_source_by_hand, byte for byte. rules_ruby asks Bazel for
`<remote>gems/<name>-<version>.gem`; Bazel's server runs in the root of
the workspace and opens the URL from there; Bundler holds the file to
the `CHECKSUMS` line. No file of Bazel's is written. Beside the gem the
directory of the patch holds the marker and a `.gitignore` (`!*`) and
`.gitattributes` of its own, because stock ignore templates name
`*.gem`, and the ledger records the archive with its sha256 and size.

The pair is not written by new code: it is the hosted planner's own
edit (`plan_gem_source` hands `plan_gem_redirect` the URL and the sum),
so it is what hosted mode writes for the same project, in the lock's own
line endings.

Where it is written (`vendor::gem::bazel::gate`). Only for a gem whose
`Gemfile` or lock a call of the hub names, and only where each of these
holds. All of them are read from the files of the checkout, through the
readers of `bazel/`; no Bazel is run:

- The checkout names a Bazel release of 7, 8 or 9 other than 9.1.0
  (`bazel::rc::declared_release`: `.bazelversion`, or
  `USE_BAZEL_VERSION` in `.bazeliskrc`). Bazel's history says that
  `repository_ctx.download` fails on such a URL in 9.1.0 ("Migrate from
  URL to URI") and that 9.1.1 and 9.2.0 fixed it ("downloader: fix
  opaque file URI names"); that is read, not run. A checkout that names
  no release, or one that is not three numbers, is declined: 9.1.0 may
  build it, or a release to come.
- The project is the root of the Bazel workspace: Bazel opens the URL
  from the root, and the gem lies under the project.
- The module files are read with certainty, no `WORKSPACE` file defines
  a repository, every call of the hub writes out the files it reads, and
  a call that reads the `Gemfile` or the lock of the project reads both.
- Something holds the gem to its bytes in the hub of every call that
  reads the two files: the lock has a `CHECKSUMS` section, or the
  `gem_checksums` of each such call (a dict of strings that is written
  out) have an entry for the gem. With neither, any bytes at that path
  would build in that hub. Two calls may read the same pair, each for a
  hub of its own, and the detail names the call without an entry.
- The lock names a Bundler that a hub was built with (`BUNDLED WITH`):
  2.6 or later of the 2 line, or one of the 4 line. rules_ruby installs
  the lock's Bundler in the hub and runs it; ruby::file_source_by_hand
  builds the form with 2.6.9 and 4.0.15, and both fail the build on a
  changed byte. An older Bundler, and a lock that names none, is
  declined; every lock that passes has one `GEM` section per source.
- The lock holds the gem as its ruby-platform entry.

One more condition is known only once the patched gem is downloaded:
every `gem_checksums` entry for the gem, in any call that reads the two
files, has to hold it to the patched gem, because rules_ruby hands that
sha256 to Bazel. An entry for other bytes declines the gem after the
download and before any write, with the same code, and the detail names
the call, the entry and the sha256 to write there. socket-patch does
not edit the call. A dry run downloads nothing and does not show this
one.

Before any of that the gem meets what vendored mode refuses for every
gem, in the same order as outside Bazel: the refusals of the lock, of
the declaration and of the stub gemspec (a native extension, a
declaration in a `group` block, and the rest).

What declines says so. The refusal keeps its code, its exit code and
its place (before a download, a takeover or an eject), and the detail
names the condition in the place of the sentence about the path:

    `ruby.bundle_fetch` (MODULE.bazel:15) of the Bazel workspace at
    /repo names Gemfile.lock; vendored mode commits the patched gem for
    such a call and names it by a relative `file:` URL, which is not
    known to build here: the checkout names no Bazel release as three
    numbers (`.bazelversion`, or `USE_BAZEL_VERSION` in `.bazeliskrc`),
    and not every release opens such a URL; use `--mode hosted`, ...

A doubt of the reader declines as it did, in the words it had.

What a run that works says. One warning per gem,
`vendor_gem_bazel_file_source`, with what the form costs: Bundler by
itself does not install from such a source (`bundle install` on a
machine without the gem and `bundle lock --update` fail; on a machine
that installed the gem before the patch, `bundle install` passes and
the program runs that unpatched copy; measured with Bundler 4.0.15), so
the checkout builds its gems through Bazel only, and hosted mode serves
both; and Bazel does not watch the gem, so an output base that fetched
the hub before keeps what it fetched. A person who ran the command is
told to build with Bazel as the next step, where a run that vendored
anything else is told to reinstall.

Every entry point. The refusal layer (`vendor::bazel_hub::refusals`)
asks the gate where it declined, so `scan`, `get` and `vendor`, their
dry runs, the takeover of a hosted pin and the eject of one all go on
where it holds. The backend (`vendor_gem`) asks it again and takes the
gem in `vendor::gem::bazel::vendor`; the download plan asks for the
archive and its stub gemspec and stages no tree.

The undo. `vendor --revert`, `rollback` and `remove` take the source
off the `Gemfile` (the option, or the added line, with the helpers the
hosted unwind uses), move the lock's entry back into the section it
came from, where Bundler sorts it, and put its `DEPENDENCIES` entry and
its `CHECKSUMS` line back as the ledger recorded them, then delete the
directory. Both files go back or neither, byte for byte where the
lock's entries are in Bundler's own order: a pair whose `source:` or
`GEM` section is no longer what the run wrote is left alone with the gem
(`vendor_lock_entry_drifted`), and so is a ledger record that would put
back a line that is not this gem's. A pair that names the source nowhere
has been put back by hand, and only the directory goes.

The undo does not edit the call either. Where a `gem_checksums` entry
still holds the gem to the sha256 of the patched gem, which is the
value the run asked for, Bazel fails the download of the upstream gem
that the lock names again (`Checksum was ... but wanted ...`). The undo
says so in a warning, `vendor_gem_bazel_checksum_left`, that names the
call and the entry; the decline that asks for the value says that no
undo puts the old one back.

The other commands. A later run is in sync, with or without the switch.
`vendor --check` holds the committed gem to the patch (the patched
files in it) and to the sha256 of the ledger; `repair` downloads it
again, and so does a run that finds the pair in place and the gem gone.
A newer patch of the gem takes the source over in place. `list` shows
the gem as vendored. Lock discovery reads a `GEM` section whose one
remote is the patch's directory, spelled exactly as written, as a
vendored reference to that archive where the manifest gives the gem the
same source, so `vex` attests the gem as it attests every vendored one:
`not_affected`, which ruby::vendored_bundle_fetch now holds to the
patched build. `vex` holds the committed gem to its patched files, as it
holds every vendored archive; `vendor --check` holds it to its bytes as
well. What `vex` says of a gem vendored by its path is unchanged
(nothing: its build is not judged).

A ledger artifact counts as one committed file by its place,
`<dir>/gems/<file>.gem`, and not by the suffix alone: a copy vendored by
its path is a directory named for its gem and version, and a version
may end in `.gem`.

The switch. `--allow-vendored-in-bazel` means what it meant: with it
vendored mode writes the copy of every other project, named by its
path, also where the archive would be written without it.

Where nothing changes. Outside a Bazel workspace, and in a workspace
whose hubs read none of the project's files, the gem backend takes the
path it took: for 40 scenarios in four such places (scan, check,
rescan, revert, dry runs, `get`, `vendor`, the eject and the takeover,
as JSON and as a person reads them) a binary of this commit prints what
a binary of its parent prints, exits as it does and leaves the same
files, byte for byte.

Tests:

- ruby::vendored_bundle_fetch (real Bazel): the checkout names no
  release, the command declines and the build stays the upstream one;
  with the release in `.bazelversion` it writes the files of the flow
  written by hand, the next build prints the patched marker on a
  machine whose Bazel reaches no patch host, with no request for a
  patched or an upstream gem, `vendor --check` passes, one changed byte
  fails `vendor --check` and the build of a second machine,
  `vendor --revert` restores every file and the upstream build, and
  hosted mode still patches it. The documents of `--vex`, `vex` and
  `vex --no-verify` are held to that build.
- Without a Bazel, through the binary: the run, the dry run, the
  in-sync runs, `vendor --check`, `repair`, the three undos, the switch,
  a hosted scan over the vendored gem and the takeover of a hosted pin;
  the next step a person is given; a lock that names Bundler 2.6.9; and
  each condition that declines, with nothing written and no gem
  fetched: an older Bundler, a second call without an entry, the entry
  for other bytes in the first call and in a second one. With the entry
  for the patched gem the gem is vendored with and without a
  `CHECKSUMS` section, and each of the three undos puts every file back
  and names the entry it leaves.
- Unit tests of the gate, one case per condition; of the undo over the
  planner's own pairs (a declared gem with its requirement, options and
  comment, an undeclared one, CRLF, a lock with no `CHECKSUMS`), of a
  patch that follows another, of a pair that drifted and of a ledger
  record that names another gem's line; of the archive check; of the
  backend against a stand-in for the patch service; and of discovery.

The three `ruby::` flows pass on Bazel 9.3.2, 8.8.2 and 7.7.2 at this
commit (macOS arm64), and ruby::vendored_bundle_fetch fails on 9.3.2
against a binary of the parent; the legs of bazel-ruby.yml run them on
the three releases.

The test of the refusal in bazel_hub.rs asserted the sentence about the
path for a gem below the Bazel root; it now asserts the condition that
declines that gem.

Docs: docs/ecosystems.md has "Bazel workspaces: RubyGems vendored mode",
the vendored cell of the RubyGems row ("Supported with the Bazel release
named in `.bazelversion`"), four entries among the known problems (the
two costs, the entry an undo leaves in the call, and a hub that Bazel
does not fetch again), and what "Bazel workspaces: VEX" says of a
vendored gem; CLI_CONTRACT.md has the rows of the code, of the two
warnings, of the switch and of the vendored table. bazel-ruby.yml starts
its legs for vendor/gem/. The `bazel` group of scripts/loc-budget.json
follows the 11 lines added to built.rs.

Not covered: `rb_bundle_fetch` in a `WORKSPACE` file, a project below
the Bazel root, a gem locked as platform gems and a lock of a Bundler
older than 2.6 are declined. Not run: Windows, releases of rules_ruby
other than 1.0.0-rc2, and a Bundler other than 4.0.15 and 2.6.9 inside
the hub. A gem that the Gemfile does not declare was built by hand on
Bazel 9.3.2; no test here builds one. A release that the environment of
a machine names in place of the checkout's is not seen. Measured by
hand on Bazel 9.3.2 and stated in the docs, with no test here: an
output base that fetched a damaged gem keeps failing after `repair`
until it fetches the hub again, and a hub that Bazel does not fetch
again (pinned in a vendor directory, or built with `--nofetch`) keeps
the gems it has.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The pull request this one is stacked on gained a commit (a requirements
file a hub names counts for the files its `-r` includes reach; a doubt has
the hub's other file read too). Two conflicts, both additions side by side:
`bazel/built.rs` keeps this branch's `hub_calls` and that commit's
`includes_one`, and the `bazel` line budget is the count of the merged
tree, 2622.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
- The gate did not look at the rc files of the checkout. A `.bazelrc`, or
  a file it imports, that names `--experimental_remote_downloader` (a
  remote downloader is handed the URL in the place of Bazel's own),
  `--repository_disable_download` or `--vendor_dir` (a hub pinned in a
  vendor directory keeps the gems it has) now declines the gem, and so
  does an rc file that cannot be read. None of the three was built.
- A directory that git ignores was refused only after the download and
  after a dry run had returned, so a dry run showed a gem the run then
  refused. The check now comes first, dry run or not.
- An undo treated a pair of which one file had been put back by hand (a
  `git checkout` of the lock, a merge that took the other side) as
  drifted for good: every `vendor --revert`, `rollback` and `remove`
  warned and left the other file and the gem. A file that names the source
  nowhere has been put back already, and the other now goes back by
  itself. A file that still names it and no longer holds what the run
  wrote leaves both alone, as before.
- A refusal of the planner was passed on with the way on it names for a
  hosted run. The decline now says whose way on that is.
- The closing `Next steps:` named the Bazel build only when every package
  of the run was such a gem, and compared a copy of the advisory's code. A
  run that vendored other packages too now adds a line for the Bazel
  build, and the code is the core's constant.
- The two wiring kinds of this form were not among the kinds whose file
  the ledger checks.

The real-Bazel flow builds the unpacked copy under
`--allow-vendored-in-bazel` again: the failing `bundle install` there is
what the decline is for, and the rewrite of the flow had dropped it.

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

cursor Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes vendoring and lockfile wiring in Bazel workspaces where builds depend on checksums and hub config; behavior is heavily gated but affects production Ruby/Bazel flows.

Overview
Vendored mode no longer always refuses Ruby gems when a workspace ruby.bundle_fetch hub reads the project's Gemfile / Gemfile.lock. Where checkout conditions show rules_ruby can build from a relative file: source, it now commits the patched .gem under .socket/vendor/gem/<uuid>/, rewrites the pair like hosted mode but with source: "file:.socket/vendor/gem/<uuid>/" and a matching CHECKSUMS line, and advises that only Bazel reliably installs those gems.

Refusal logic in vendor/bazel_hub.rs delegates to a new vendor/gem/bazel gate: missing/unsupported Bazel pin, non-root project, WORKSPACE repos, unreadable module files, Bundler version, platform gems, gem_checksums mismatches, and similar cases still yield vendor_gem_bazel_hub. --allow-vendored-in-bazel unchanged—path-based vendoring when the user opts in.

CLI / ledger: new events vendor_gem_bazel_file_source and vendor_gem_bazel_checksum_left; vendor next-steps prefer a Bazel build when only hub-archive gems were applied; verify/repair/redownload/vex discovery treat archive-shaped gem artifacts.

Tests & CI: e2e_bazel_build/ruby.rs expanded (file_source_by_hand, updated vendored_bundle_fetch, hermetic decline matrices); workflow paths include vendor/gem/**; docs and CLI_CONTRACT.md updated.

Reviewed by Cursor Bugbot for commit dd2651e. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.

Fix All in Cursor

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

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

Reviewed by Cursor Bugbot for commit dd2651e. Configure here.

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

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: review brief for the approver

What it does. Where a rules_ruby ruby.bundle_fetch hub reads the project's Gemfile / Gemfile.lock, vendored mode now commits the patched .gem under .socket/vendor/gem/<uuid>/gems/ and points both files at it with a relative file: source, in the same form as a hosted pin. It does this only when the checkout shows that form builds: a pinned Bazel 7–9 other than 9.1.0, Bundler 2.6+ or 4, the project at the workspace root, and a CHECKSUMS line or gem_checksums entry that holds the gem to its bytes. In every other case it declines as before. Revert, rollback and remove undo both files.

Risk: high. It adds about 785 lines of new code that writes users' Gemfile and Gemfile.lock. It relies on Bazel opening a relative file: URL from the workspace root, which Bazel doesn't document. After the change, plain bundle install no longer installs that gem; the run warns about this. Outside a Bazel workspace, or where no hub reads the project's files, nothing changes.

Look here

  • gem/bazel.rs:152: the gate (which hubs, which Bundler, which Bazel). Bazel versions are at L280 and the byte-pinning rule is at L304.
  • gem/bazel.rs:515: vendor. It writes the archive, then the Gemfile, then the lock, and undoes the earlier writes if a later one fails.
  • gem/bazel.rs:850: unwire_lock puts the lock entry, the DEPENDENCIES pin and the CHECKSUMS line back. A lock that has drifted is left alone.
  • gem.rs:998: where the gem backend hands off to the new lane.
  • commands/vendor.rs:4768: the next-step text ("Build with Bazel") in the CLI.

Verified. I read the new module's non-test code: the uuid directory goes through vendor_uuid_dir_rel, CRLF locks are edited in LF form and written back with their line endings, and the CLI change only alters a printed line. Locally, cargo test -p socket-patch-core --lib vendor::gem passes (207 tests). CI on dd2651e: 107 checks pass, 0 fail (92 skipped), including ci-ok, clippy and the Windows legs. Both Bugbot threads are resolved. CHANGELOG.md is not touched.

Changes I made. None.

Open questions


Generated by Claude Code

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[agent] Reviewed the stacked diff against #2208, including the loaded Gemfile pair, checksum gate, archive verification and undo. This approval covers the gem archive change. The finding on the parent PR still applies to the stack.

…ndored/gem-file-source

This brings main in, through the two merges of the declines' branch. Four
files conflicted. The RubyGems tests of e2e_bazel_build keep every test of
this branch, of that branch and of main, with one `Served`, one `run`, one
`squeezed` and the two checkouts of that merge. patch/redirect/mod.rs keeps
`plan_gem_source` beside main's `gem_pair`. docs/ecosystems.md keeps the
entries of both sides: main's cell and sentences on hosted mode beside a
`gem_checksums`, this branch's on vendored mode. The `bazel` cap of
scripts/loc-budget.json is the count of the merged tree, 3869.

Outside the conflicts, the two `DepOverride` values that vendor/gem/bazel.rs
builds name the `npm_registry_url` main added to that type.

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>
@mikolalysenko

Mikola Lysenko (mikolalysenko) commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: updated review brief (new commits since the brief for dd2651ed8)

What it does
The PR's own change is the same as in the earlier brief. Since then the head has gained:

  • a merge of bazel-guard/vendored-hub-locks, which only brings in main;
  • two commits that make the real-Bazel vendored Cargo test accept @platforms as well as @crates__... as the repository Bazel can't see.

Those two commits are line for line the change in #2227, which is reviewed there.

Risk
Low for the new commits: test code and one docs sentence. The risk of the PR's own change is unchanged.

Look here

Verified

Open questions
The PR is approved, but it is stacked on #2208, which carries agent:needs-human. Auto-merge stays off until #2208 lands and this PR is retargeted to main.


Generated by Claude Code

…ndored/gem-file-source

This brings main in, through the merge of the declines' branch. Two files
conflicted. The docs of vendor/refusals.rs keep this branch's words on a
gem that is committed for the hub and main's item on a Maven jar that only
a rules_jvm_external hub builds; the one dispatch of
`bazel_workspace_refusals` is the merged one of that branch. The `bazel`
cap of scripts/loc-budget.json is the count of the merged tree, 4053.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[agent] Re-reviewed the commits since the last approval; no major findings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants