Repository navigation
Fix vendored gem revert into a hosted GEM section (#2090) - #2102
Conversation
Claim commit for #2090: a vendored gem's revert puts its spec into a hosted gem's GEM section. Assisted-by: Claude Code:claude-fable-5-2
A vendored gem's lock record names the GEM section its spec came from only when that was not the lock's first one. With none recorded, revert put the spec into whatever section is first at revert time. A hosted scan run after the vendoring adds a patch-registry section, which bundler sorts ahead of rubygems.org, so the spec landed in the hosted gem's section: a fresh bundle install failed and the hosted gem could no longer be rolled back. Revert now takes the first GEM section that is not a hosted gem's own, and vendoring records the section when the spec is lifted from a hosted one, so both sides agree on what an unrecorded section means. Fixes #2090 Assisted-by: Claude Code:claude-fable-5-2
Skipping hosted sections at revert still left a record with no remote line tied to the lock's section order: a source the user adds after vendoring can sort ahead of rubygems.org just as a hosted gem's section does. Vendoring now records the remote line of the GEM section a spec is lifted from whenever the section has one, so revert finds it by name. Records written before this keep the positional rule, minus hosted sections. When the recorded remote is gone and the lock has exactly one upstream GEM section, the spec goes there, as it did before; with several, the lock is reported as drifted. A hosted section is now recognised by the gem patch-registry path only, and the new end-to-end test is gated on Bundler 2.2, the first to write one GEM section per source. Refs #2090 Assisted-by: Claude Code:claude-fable-5-2
|
[agent] bugbot run Generated by Claude Code |
PR SummaryMedium Risk Overview Vendoring now always records the lifted spec’s source Adds unit coverage for hosted sections sorting ahead of upstream, merged Bundler < 2.2 layouts, renamed sources, and legacy record shapes, plus an ignored e2e that exercises Reviewed by Cursor Bugbot for commit 0271a02. Configure here. |
The previous commit recorded the source section's remote line for every vendored gem. vendor_ledger_schema_e2e requires a new ledger to hold the same wiring originals an older binary wrote, and CI's coverage job failed on it. Go back to recording the remote only for a section that is not the lock's first or is a hosted gem's own. Revert of a record with no remote still skips hosted gems' sections, which is the fix for the reported bug and needs no change to the ledger. Kept from that commit: a hosted section is recognised by the gem patch-registry path only, the end-to-end test is gated on Bundler 2.2, and the unit fixture checks both of its replacements. Refs #2090 Assisted-by: Claude Code:claude-fable-5-2
LLM Description written by Claude Code:claude-fable-5-2
Fixes #2090
Summary
With one gem vendored and another hosted, un-vendoring the first (
rollback,remove <purl>,vendor --revert) put its spec into the hosted gem'sGEMsection ofGemfile.lock. A freshbundle installthen failed (it looked for the gem on the patch registry) and the hosted gem could no longer be rolled back. After this change the spec goes back to the section it came from, androllbackreturns the pre-scan pair byte for byte.Two files change:
crates/socket-patch-core/src/vendor/gem.rs(about 40 lines of code, the rest is tests) and one new end-to-end test ine2e_redirect_gem_build.rs.Root cause
A vendored gem's
gemfile_lock_specledger record named theGEMsection its spec was lifted from only when that was not the lock's firstGEMsection. With nothing recorded, revert used whatever section was first at revert time (record_gem_section). Section order is not stable: a hosted scan adds a patch-registry section, and Bundler sorts it ahead ofhttps://rubygems.org/.The change
GEMsection that is not a hosted gem's own, instead of the lock's first section. A hosted section is one whose remotes are all…/patch-registry/gem/<token>/<uuid>/URLs, on any origin, since revert isn't told which patch server the scan used. A Bundler < 2.2 merged section (patch-registry and upstream remotes together) is not skipped. The same rule decides whether a lock already holds the reverted state.The ledger format does not change: existing ledgers revert correctly without being rewritten, and new ledgers have the shape older binaries wrote (
vendor_ledger_schema_e2echecks this).Evidence
Red before the fix, green after:
vendor::gem::tests::revert_lock_text_skips_a_hosted_gem_section(unit, #2090)gem_vendored_unwind_beside_a_hosted_gem_restores_the_upstream_section(e2e, real Bundler 4.0.18,rollbackandremove)hosted_restore_refused … does not lock exactly tiny-dep (1.0.0), exit 1 (the issue's error)bundle installsucceedsThe e2e test follows the issue's steps: vendor one gem, host another, check the hosted section is first in the lock, then unwind. Its
removeleg also checks the intermediate state (one gem un-vendored, the other still hosted) installs frozen from a cold checkout.Other new unit tests: a merged section, a lock with only hosted sections (drift, no guess), an upstream source whose URL has another Socket path shape, and a spec lifted from a hosted section.
Commands run locally (Ruby 3.3.6, Bundler 4.0.18):
cargo test -p socket-patch-core --lib vendor::: 3066 passed.cargo test -p socket-patch-cli --test e2e_redirect_gem_build --test e2e_vendor_gem_build --test e2e_gem_native_ext_build -- --ignored: 43 + 11 + 4 passed.cargo test -p socket-patch-cli --test vendor_ledger_schema_e2e --test vendor_revert_tamper_e2e --test e2e_vex_vendor: 62 passed.cargo clippy --locked --workspace --all-features -- -D warnings(CI's command): clean.cargo test -p socket-patch-core --librun had one failure,utils::process::tests::build_output_within_kills_the_process_group_at_the_deadline, a process-group timing test in code this PR doesn't touch.cargo clippy --all-targetsreports errors in test files this PR doesn't touch (tests/prebuilt_common,tests/repair, others) and none in the two changed files.Review notes
/code-review highran on the first commit. Fixed: the hosted-section test was wider than gem patch registries, the e2e asserted a per-source lock layout on Bundler < 2.2 (now skipped there with a message; the scenario needs per-source sections), and a test fixture guard could pass vacuously.Not fixed, with reasons:
mainand is not what Reverting a vendored gem while another gem is hosted puts its spec in the hosted gem'sGEMsection: freshbundle installfails androllbackcan no longer undo either gem #2090 reports. The second commit fixed it by recording the sourceremote:line for every gem, and CI'scoverage (1)failed onvendor_ledger_schema_e2e::server_artifacts_preserve_legacy_wiring_shape_and_originals, which requires new ledgers to keep the originals older binaries wrote. The third commit backs that out. Closing this gap means changing what the ledger records, which is a maintainer's call (see Follow-ups).GenerationGemsetup that four other tests in that file also repeat. Sharing it means editing those tests, a refactor outside this fix.The history has three commits because of that back-out; the net diff is the first commit plus the three review fixes.
Follow-ups
gemfile_lock_specrecord always carry its source section'sremote:line? It would make revert independent of section order, at the cost of new ledgers differing from the ones older binaries wrote (thevendor_ledger_schema_e2einvariant would need a stated exception, aspypi-requirementshas).https://claude.ai/code/session_011f9aePuhQymCjTDT6u4HbP
Generated by Claude Code