Repository navigation
Vendor a platform-locked gem once one platform has a patched build, with upstream's gem for the rest - #2342
Draft
Mikola Lysenko (mikolalysenko) wants to merge 14 commits into
Draft
Vendor a platform-locked gem once one platform has a patched build, with upstream's gem for the rest#2342Mikola Lysenko (mikolalysenko) wants to merge 14 commits into
Mikola Lysenko (mikolalysenko) wants to merge 14 commits into
Conversation
…atched build A gem `Gemfile.lock` names as precompiled platform gems was vendored only when every locked platform had a patched build. Bundler's default lock names eight platforms, so such a gem stayed unpatched in vendored mode until all eight had one. It is now vendored when the fix's list names a patched build for at least one locked platform. Each of the others gets the tree of the gem the patch registry lists for it: upstream's own gem, unchanged. That gem is downloaded from the patch server, checked against the sha256 the list names, and its tree carries the gemspec the gem itself holds (its `metadata.gz`, which Bundler reads like a Ruby gemspec). Hosted mode installs the same gem for such a platform. - The ledger records such a tree as a `gemBuilds` entry with no `uuid` and the sha256 of its gem. It records no files: the copy's file inventory vouches for every byte of the tree, as it does for the files of a patched tree that the patch does not name, and the digest is what a restore fetches the gem again by. - A copy that is intact asks for the fix's list (one request) and is vendored again when the list names another build for a locked platform: a patched build that was published since, or upstream's gem where the patched build was withdrawn. - A newer fix that has no patched build for a platform the vendored copy of an earlier patch holds one for is a skip: the earlier copy stays in force. - Unchanged: a lock none of whose platforms has a patched build, a platform the registry does not list, and a build the list names whose patch is not served are the skips they were. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…a build A gem vendored as platform gems is reported per tree. A tree of upstream's own gem (a locked platform with no patched build) now gets what hosted mode gives a locked build the patch registry serves as upstream's gem: - the advisory `skipped` event `gem_upstream_build_kept`, with no `uuid`, which `summary` does not count; `withdrawn: true` and the matching reason where the run put the tree in place of a patched build, and `newlyPatched: true` on a patched build the run put in place of upstream's gem; - one line per such gem under the summary line, in hosted mode's words (`nokogiri 1.19.3: patched for arm64-darwin; upstream gem kept for x86_64-linux-gnu (no patched build yet)`). A gem whose every tree is a patched build prints no line, as before; - in `vex`, the `affected` statement of that platform gem with what changes it, read from the ledger with no request. The patched trees are attested as before. `vendor --check` fails every tree of a copy that does not verify, the one of upstream's gem included, so a copy that holds upstream's gems alone still fails its check. Telemetry takes such a tree as about no patch. A dry run of `scan --mode vendored` asks the fix's list for a gem already vendored as platform gems, as the wet run does, and reports the trees the wet run would put in place when the list names other builds. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The stand-in patch service of the platform-gem tests now serves upstream's own gem for a platform it lists with no patched build, from the gem patch's registry and with the sha256 the list names. - A lock with one patched platform and one that has none: vendored, the one line, the counted and the advisory event, the ledger, a later run in step (one request), `vendor --check` and a change to the upstream tree, an offline `vex` (the patched build attested, the other stated `affected`), and revert byte for byte. - A later run that takes a published build and one that follows a withdrawal, each with its dry run first. - Every dry run (`vendor`, `scan`, `get`) says what the wet run does. - A takeover of a hosted gem with upstream's gem for a platform, by a scan and by an eject. - The tests of a gem that is left alone or stays hosted because of one platform now use a build whose patch is still being built, and a lock none of whose platforms has a patched build keeps the one-line skip. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The platform-gem capstone of the real-Bundler suite gains the mixed case: two locked platforms with a patched build (this machine's among them) and one the registry serves as upstream's own gem. The stand-in registry now serves that gem's file. The gem is vendored: two counted `applied` events and the advisory one, upstream's gem downloaded from the patch server, its tree with the YAML gemspec the gem carries. A fresh checkout installs frozen with no request to the patch service, Ruby loads the patched build of the running platform, `bundle install` and `bundle lock` regenerate the lock byte for byte, `vendor --check` passes and revert restores both files. A platform the list leaves out and a build whose patch is still being built stay the skips they were. An in-sync re-run now makes one request, and a newer patch that lacks a build the vendored copy holds is worded as hosted mode words it. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…atform `CLI_CONTRACT.md`: the gem row of the vendored layouts (the tree of upstream's gem, where it comes from, the gem's line, how a later run follows the list, the ledger entry of such a tree, its events and its `vex` statement, the dry runs), and the rows of `vendor_prebuilt_platform_pending`, `vendor_prebuilt_replaced` and `gem_upstream_build_kept`. `docs/ecosystems.md`: the vendored row of the native-extensions table and the support matrix cell. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ript The vendored scenario of `tests/nokogiri/nokogiri_e2e.rb` no longer waits for every platform. With `--pass-through` naming some of the locked platforms, the scan vendors nokogiri with the patched build of the others and upstream's own gem, served by the stand-in's registry, for those. The script checks the events, the trees and their gemspecs, where upstream's gem was asked for, the line of a later scan, the `vex` statements, and a frozen install of a fresh checkout with the service unreachable: Ruby loads the patched nokogiri where this machine's platform has a patched build, and upstream's nokogiri from the committed tree where it has none (`--pass-through own`). The next scan then takes the builds the stand-in publishes. With no patched build at all nothing is vendored, as before. The compatibility workflow runs the vendored scenario with the runner's own platform passed through as well. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…he list The line that says which platform builds of a gem are patched is printed by hosted mode and now by vendored mode. It moves, with the filter vendored mode applies to it, into the helper module `commands/gem_build_lines.rs`, so that `vendor` does not import `scan` (the command modules' layering test). The core test of the request-less preview covers a lock already wired to the patch's copy: one request (the fix's list) while the copy holds what the list names, the trees the wet run would put in place when the list names another build, and no promise when a patched build it names is not served. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Review findings on the gem backend, with the rule that an intact committed copy is never made worse and a run never fails because of something it could have left alone. - An intact copy whose list moved went through the rebuild of a missing or stale copy, where any failure but the pending skip ended the run. When the list cannot be followed (a request that fails, a build whose gem fails its digest or whose stub is not served, an upstream gem that does not unpack) the copy now stays in force: the run ends as it does for a copy in step, with one line (`vendor_gem_list_not_followed`). A build the list names that is not served yet keeps its skip. A dry run says the same. The advisory of a copy that did follow its list has a code of its own (`vendor_gem_list_followed`). - A ledger entry that names no build of its trees says nothing of a moved list: no request is made for it and the copy stands. - The package references of several patches can be asked for in one request and remembered by the client: a later read of one of them makes no request, and a request that brought no answer is not made again per patch. A run asks for the lists of the gems it finds vendored this way, and the fix's reference is read once whether or not the list moved. - Upstream's own gem is downloaded with a client that follows no redirect: a redirect the registry answers is the gem not being served. - The skips of `locked_build_sources` (a platform the list leaves out, no patched build at all, a newer fix with fewer builds) are judged before an upstream gem the list does not pin fails the gem. - The download advisory names a copy of upstream's gems alone as such and says where it came from, the `.gitignore` advisory names the gems as they are, and the registry URL of an upstream gem is built in one place. - The ledger's doc comment says what each older reader does with a tree of upstream's gem. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…t real skips Review findings on the CLI side of a gem vendored as platform gems. - The vendor loop restores a damaged copy before it reaches the backend and stopped at a restore error. A restore that is refused only because the list of the gem's fix names other builds now (`vendor_prebuilt_replaced`) goes on to the backend, which vendors the copy again from that list, as it does for an intact copy. `repair` still refuses and names the scan. A ledger edited to name another patch for a tree looks the same and is settled the same way: the list chooses what is unpacked. - The lists of the gems already vendored as platform gems are asked for in one request before the loop, and by the dry-run preview of a scan. - `VendorTally` no longer subtracts the uncounted advisory event of a tree of upstream's gem, so a package skipped beside such a gem is said. - `vex`: a tree of upstream's gem under a purl the view already attests leaves that purl alone, as a hosted build does. - The dry-run preview of a scan reports an in-step copy per tree, with the gem's line, as the real run does. - The line of a copy that could not follow its list prints as a note. Tests: a damaged copy after the list moved (either tree), an intact copy whose rebuild fails with every file compared byte for byte (dry and wet), the dry run of an in-step copy, the tally, the vex view, and the edited ledger settled by the list. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
`CLI_CONTRACT.md`: the one request for the lists of all the gems vendored as platform gems, the download of upstream's gem that follows no redirect, what a run does when the list cannot be read or cannot be followed (`vendor_gem_list_not_followed`, a note, exit 0, the copy untouched), the advisory of a copy that followed its list (`vendor_gem_list_followed`), and that a vendor run whose exact restore is refused because the list moved vendors the copy again from the list while `repair` still refuses. `docs/ecosystems.md`: the same in the vendored row of the native-extensions table. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
With `--pass-through-redirect` the stand-in registry answers the file of upstream's gem with a redirect to its upstream stand-in. Vendored mode takes that gem from the patch service alone, so the vendored scenario now checks that the scan does not vendor the gem, asks nothing of the upstream stand-in and writes nothing, and then goes on once the stand-in publishes the builds. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… the client memo Review findings on the gem backend and the API client. - A run that could not vendor an intact copy again said the copy "stays in force as it is" without looking at it. Two failures happen after the copy was changed: the new trees are in place and the uuid dir's git metadata cannot be written, or the swap of the stage fails and cannot be undone. One function, `copy_in_force`, now answers whether the recorded copy stands with its metadata in place. The in-step path and every outcome that says the copy stays in force go through it (`wired_copy_failed`); a copy that no longer stands is the failure it is for any damaged copy. A copy left in force gets its `.gitignore` and `.gitattributes` put back, as a copy in step does. - The client-wide memo of batched references is gone, and with it the remembered "no answer" that failed later reads of the same patch. The batch goes through the vendor prefetch plan: a planned download can be a position whose reference alone is read (`PlannedDownload::reference`), which shares the plan's one reference request and is never fetched ahead. - The rebuild of a copy whose list moved takes the gems that list was read to name (`BuildsFrom::Listed`), so the fix's reference is asked for once with or without a plan. - A redirect is "not found" only for the client that follows none. The client that follows redirects answers one it cannot follow as it did. - `restore` returns a structured reason (`RestoreError::list_moved`), true only when the list of the gem's fix names another build than the entry records; a reference that does not pin upstream's gem is a miss. `restore_follows_list` asks the same without downloading, for a dry run. - `follows_list` is the one rule for which copies follow a list. - Failure points for the stage swap, its undo and the uuid dir's metadata, for the tests of the two failures above (debug builds only). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…restore by its reason Review findings on the CLI side of a gem vendored as platform gems. - The collect, sort, dedup and remember block is gone from the vendor loop and from the dry-run preview of a scan. One helper, `list_follower`, says which packages follow the list of their fix; the vendor loop plans each as a position whose reference alone is read (a dry run plans nothing else), and the preview attaches the same plan for the rows in step. The plan's one reference request serves them, under its own guard. - The fall-through after a refused restore is decided by the restore's structured reason (`list_moved`), not by the prefix of a formatted error, so a reference that does not pin upstream's gem is the failure it is. - The dry run of a damaged copy whose list moved no longer reports `wouldRedownload` and stops: it asks whether the restore would be refused for a moved list and, as the wet run does, goes on to preview the copy vendored from the list. - `vex`: every tree of a vendored copy whose purl the view already attests is left to that record, as the hosted loop does, the patched ones included. Tests: each of the two failures that change the copy (the uuid dir's metadata after the trees are in place; a stage swap that cannot be undone) forced with a failure point, with what is printed and the exit code; the dry run of a damaged copy; the metadata put back by a run that leaves the copy in force; the vex view for a patched tree. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…n of a damaged copy `CLI_CONTRACT.md`: the references of the gems vendored as platform gems are positions of the run's download plan and share its one request; what an unreachable service costs; a run says a copy stays in force only after checking that it stands, with its git metadata put back; a rebuild that fails after it changed the copy is a failure; the fall-through after a refused restore is for a moved list alone, and its dry run previews the copy vendored from the list. `docs/ecosystems.md`: the same, briefly. The planner shim the tests call is compiled for tests only. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #2273. Offered for the maintainer to take or leave: #2273 does not depend on it.
What this does
A gem that
Gemfile.locknames as precompiled platform gems is vendored as soon as one locked platform has a patched build. Vendored mode then mirrors what hosted mode already does for such a lock:.gemis the one the gem patch's registry lists for the platform. It is downloaded from Socket's patch server (the registry'sgems/<name>-<version>-<platform>.gem), never from the upstream registry: the download follows no redirect, and one the registry answers is the gem not being served. It is checked against the sha256 the list names. Its tree carries the gemspec the gem itself holds (metadata.gz), which Bundler reads the way it reads a Ruby gemspec.nokogiri 1.19.3: patched for arm64-darwin; upstream gem kept for x86_64-linux-gnu (no patched build yet)appliedevent per patched build under its own patch, and the uncounted advisory eventgem_upstream_build_kept(nouuid) for a tree of upstream's gem.vexattests the patched builds from the ledger, offline, as before, and states a platform whose tree is upstream's gemaffected, with what changes that.now also patched for …), or upstream's gem where the patched build was withdrawn (upstream gem back for … (its patched build was withdrawn)). TheGemfileand the lock are not touched.Why
#2273 vendors such a gem only when every locked platform has a patched build. Bundler's default lock of nokogiri names eight platforms, so vendored mode would not patch it until all eight have builds, while hosted mode patches the lock as soon as one has.
The ledger
A tree of upstream's gem is a
gemBuildsentry with itsplatformandgemIntegrity(thesha256-…of the gem the list named) and nothing else: nouuid, nogemspecIntegrity, nofiles. That is enough because:vendor --checkandvexalready verify a tree that holds no patched file by the copy's file inventory, which covers every file of it. A changed, missing or added file fails the check.repairfetches the same gem again from the gem patch's registry and requires the recorded sha256. It refuses (vendor_prebuilt_replaced) when the list names a patched build for the platform now, or no gem.No new mechanism: one optional field in an existing entry, the registry URL the reference already carries, and the artifact download the client already has.
What a default lock commits
Bundler's default lock of nokogiri 1.19.3 names eight platforms. Measured with the real gems, the
.socket/directory plus theGemfileand the lock in a fresh repository:gc --aggressive)The two cases are the same size: a tree of upstream's gem is the same tree without the patch. One tree is 7.0 to 14.9 MB. The first scan of the mixed case downloads the seven upstream gems through the patch server (36.5 MB in 15 requests against a local run of the patch service).
What is unchanged
rubyplatform, and the refusal of a native gem locked as its source gem.vendor --revertandrollbackrestore theGemfileand the lock byte for byte.What changes for a copy that is already vendored
A run over an intact copy of a platform-locked gem made no request before. A run now makes one request for all such gems together, the references of their fixes, which is how it sees a published or withdrawn build. A service that does not answer is asked once, not once per gem.
An intact copy is never made worse, and a run never fails over one:
Note: nokogiri@1.19.3 could not be brought in step with the builds the patch registry lists (<why>); its vendored copy stays in force as it is.(vendor_gem_list_not_followedin--json).When the list has moved, the whole copy is vendored again, every tree, not only the one that changed.
A copy that is damaged after the list moved is vendored again from the current list by the next vendor or scan run. The exact restore of it is refused, because the list names another build, and the run then goes on instead of failing.
repairstill refuses and names the scan.What the maintainer must know
A copy with a tree of upstream's gem needs a CLI that reads the
gemBuildsentry of that tree:gemBuilds(the one onmaintoday) ignores the key and judges the trees it finds on disk by the files of the gem's patch. It passes a tree of upstream's gem whenever that gem ships none of the patched files, and would then attest the gem for every platform.So a release that can produce such a copy has to contain a reader that knows it (#2273 plus this change), and a project vendored this way must not be attested (
vex,vendor --check) with an older CLI.How it was tested
vendor,scanandget, dry and wet, JSON and human output, the ledger,vendor --check, an offlinevex, revert, a hosted-to-vendored takeover and an eject.bundle installandbundle lockregenerate the lock byte for byte, revert restores both files.tests/nokogiri/nokogiri_e2e.rbwith real nokogiri 1.18.10, eight locked platforms: vendored with every build patched, with the other platforms on upstream's gem, and with this machine's own platform on upstream's gem (Ruby loads upstream's nokogiri from the committed tree, then the patched one after the stand-in publishes the build). The compatibility workflow gains that last row.repairof a removed upstream tree and of a removed patched tree, a second platform build published later, that build withdrawn, and the all-patched, rebuild-window and hosted runs as regression checks.Numbers on this Mac (arm64, Bundler 4.0.15), at the head of the branch. The Rust suites ran on the last commit that changes Rust code; the two commits after it change the docs and the Ruby script.
cargo fmt --all -- --checkandcargo clippy --locked --workspace --all-features -- -D warnings: clean.cargo test -p socket-patch-core: 9,445 passed, 0 failed, 3 ignored.cargo test -p socket-patch-cli: 6,001 passed, 2 failed, 538 ignored. The two failures aree2e_vendor_cargo_buildcases that need an x86_64 toolchain this machine lacks, and fail on the base branch too.e2e_redirect_gem_build,e2e_vendor_gem_build,--ignored): 72 and 13 passed.nokogiri_e2e.rb: vendored 26, vendored with the other platforms on upstream's gem 44, vendored with this machine's platform on upstream's gem 45, the same against a registry that redirects upstream's gem 29, hosted 58 checks, all pass.Review
/code-review highof this branch's own commits returned ten findings, all fixed in the last five commits:vexcould state one product both ways when the view already attested the purl of a tree of upstream's gem.What was not run
/code-reviewhas not been run on this diff.Decisions a reviewer may want to change
Vendored mode needs every locked platformis kept for an unlisted platform and for a named build that is not served.🤖 Generated with Claude Code