Repository navigation
Fix revert of a vendored gem whose Gemfile line was edited (#2338) - #2470
Mikola Lysenko (mikolalysenko) wants to merge 3 commits into
Conversation
Refs #2338. Assisted-by: Claude Code:claude-fable-5-2
The vendored gem revert found the Gemfile line it wired by the exact text vendor wrote, allowing only for a changed trailing comment. An option added to that line, a move into a `group` block or switched quotes read as drift, so `rollback`, `remove` and `vendor --revert` kept the gem on every run, while `scan`, `vendor --check` and Bundler all took the line as the gem's wiring. The revert now reads such a line argument by argument. When it is the gem's one declaration, pins the vendored version and its `path:` names this patch's copy, the `path:` comes off, the pre-vendor version requirement goes back and the rest of the line stays as the user has it. The managed block of a transitive gem goes whole with an edit of its line. A line that pins another version, carries a statement modifier or a second statement, or sits in a block that picks its gems' source is still drift, and neither file is written. Fixes #2338. Assisted-by: Claude Code:claude-fable-5-2 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011f9aePN8sXX1PS6fywq5ub
Review fixes for the edited-line revert: - a string-keyed option (`"require" => false`) is an option, not a second version constraint; - another gem's line that only names this gem is not a second declaration of it; - an original line with a `;` in a string, or one ending its statement, is restorable; - the spacing the original had after `gem` comes back when the user left the head as vendor wrote it; - the contract names the blocks a moved line may sit in. Refs #2338. Assisted-by: Claude Code:claude-fable-5-2 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011f9aePN8sXX1PS6fywq5ub
|
bugbot run Generated by Claude Code |
PR SummaryMedium Risk Overview Gem revert in Lines that change the pin, add statement modifiers or extra declarations, sit under Reviewed by Cursor Bugbot for commit 237b439. Configure here. |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 237b439. Configure here.
|
[agent] PR shepherd: review brief for the approver What it does Risk: medium. This rewrites a user's Gemfile on revert. It only does so in a narrow, conservative case: the gem has one declaration, pinned to the vendored version, with a Look here
Verified
Changes I made: none. Open questions
Generated by Claude Code |
LLM Description written by Claude Code:claude-fable-5-2
Fixes #2338
Summary
A vendored gem could not be rolled back or removed once the user edited
its
Gemfileline: an option added (require: false,group: :web), theline moved into a
groupblock, or the quotes switched. Bundler,scan --mode vendoredandvendor --checkall took the edited line as thegem's wiring, but
rollback,removeandvendor --revertcalled itdrift and kept the gem on every run, and none of the remedies they named
did anything.
The revert now undoes such a line around the user's edit:
path:option comes off and the pre-vendor version requirement goesback;
indentation (a move into a
group,platformsor conditional block),quotes, and a comment they changed;
line (the block is vendor's own text; the gem had no declaration before).
The lock is restored as before, so the pair moves together.
Root cause
revert_gemfile_record(crates/socket-patch-core/src/vendor/gem.rs)found the wired line by the exact text vendor wrote, allowing only for a
changed trailing comment. Vendor's own reader and
vendor --checkjudgethe wiring by what the line means: the gem's declaration, with a
path:to the entry's copy. The two disagreed on every other edit.
What still reads as drift (neither file is written)
The edited line is restored only when it is the gem's one declaration,
pins the vendored version, and its
path:names this patch's copy, withkeyword options around them. It stays drift when:
argument;
… if ENV["X"]) or a second statement;source/git/github/pathblock: restored there,the gem would resolve from a source the restored lock does not name;
(
OwnGem::rewrite_refusal), which is unchanged.Evidence
Red before the fix, green after (
cargo test -p socket-patch-core --lib -- vendor::gem::tests::revert_):revert_edited_wired_gemfile_line_restores_the_pair_and_keeps_the_editgroup:added, moved into agroupblock, quotes switched; also a conditional block, a hash-rocket and a string-keyed option, an option beforepath:, changed spacingrevert_edited_wired_gemfile_line_follows_the_users_optionsrevert_edited_wired_gemfile_line_reads_the_original_as_vendor_did;, a tab aftergem, and another gem's line that names this onerevert_edited_wired_gemfile_line_keeps_crlfrevert_edited_managed_block_line_removes_the_blockrevert_still_wired_but_unreadable_gemfile_writes_neither_fileEach test also re-runs vendor over the edited Gemfile and asserts it is
read as in sync, so the revert and vendor agree.
revert_still_wired_but_edited_gemfile_writes_neither_fileasserted thereported behavior for two of these edits (
require: falseadded, a commentadded to the managed line). It is replaced by the last test in the table,
which holds the same "neither file is written" guarantee for the forms that
are still drift.
End to end, with real Bundler (
e2e_vendor_gem_build, new testgem_vendor_edited_gemfile_line_is_undone_by_every_undo_command): vendor,edit the line,
bundle installplain and frozen (lock unchanged),vendor --checkexit 0, thenvendor --revert/rollback/remove:exit 0, no drift warning, the copy and ledger record gone, the Gemfile as
expected, the lock byte for byte the pre-vendor one, and a frozen install
passes.
Local runs (Ruby 3.3.6, Bundler 4.0.18):
cargo clippy -p socket-patch-core --all-targetsreports lints in testtargets on
mainas well (two of them invendor/gem.rs, both in codethis PR does not touch); this PR adds none.
CLI_CONTRACT.md(thevendor --revertdrift rule) is updated. The npm,PyPI and gem wrappers need no change.
Review
/code-review highfindings, all in the new code:"require" => false) made the edited linedrift; another gem's line that only names this gem counted as a second
declaration; an original with a
;was refused; the original's spacingafter
gemwas not restored; the contract named onlygroupblocks.had edited (
RewireOurskeeps its bytes), the new ledger entry records aline whose options differ from the carried-forward original, and the
revert refuses the record ("puts back Gemfile text that is not one plain
declaration…"). Accepting it means loosening the ledger integrity rule
that
revert_refuses_records_that_are_not_this_gems_pair_editholds("an option the vendored line does not carry"), which is a maintainer's
call. This PR leaves that rule as it is.
Follow-ups
groupblock is refusedby vendor as an indented declaration (also pre-existing).
https://claude.ai/code/session_011f9aePN8sXX1PS6fywq5ub
Generated by Claude Code