Repository navigation
Fix cleanup of a vendored gem the project dropped (#2325) - #2418
Mikola Lysenko (mikolalysenko) merged 5 commits into
Conversation
Refs #2325. Assisted-by: Claude Code:claude-fable-5-2
After bundle remove, or a move to another release, neither the Gemfile nor Gemfile.lock names the vendored copy. The gem revert still reports the entry as drift and keeps the copy and the ledger record on every run. Three of the unit tests and the end-to-end test fail until the revert learns that case. Refs #2325. Assisted-by: Claude Code:claude-fable-5-2
The gem revert called every record it could not restore drift and kept the copy and the ledger record. After bundle remove, or a move of the gem to another release, nothing can undo that drift, so rollback, remove, vendor --revert and scan --prune kept the entry for good and vendor --check stayed red. When neither the Gemfile nor Gemfile.lock names the entry's copy directory in any spelling, such a record now warns vendor_lock_entry_removed, as the other backends do. Both files stay as the user left them and the copy is removed. A file that still names the copy, or that cannot be read, keeps it as drift. Fixes #2325. Assisted-by: Claude Code:claude-fable-5-2
rollback and vendor --revert keep the manifest's patch, so the audit that follows reports it as not vendored. Only remove leaves nothing for the audit to report. Refs #2325. Assisted-by: Claude Code:claude-fable-5-2
A Gemfile and lock that route the gem through a vendored copy of another patch uuid (an interrupted re-vendor, a merge that kept an older ledger) no longer read as a dropped gem: the project is still vendored and the entry may hold the only pre-vendor originals, so the revert keeps it as drift. The removed warning no longer states one cause for every case, the contract says an unreadable file fails the revert, and the end-to-end test re-locks after bundle remove, which Bundler 2.1 and older leave to the next install. Refs #2325. Assisted-by: Claude Code:claude-fable-5-2
|
[agent] bugbot run Generated by Claude Code |
PR SummaryMedium Risk Overview Implementation in Reviewed by Cursor Bugbot for commit 1f3be36. Configure here. |
|
[agent] PR shepherd: review brief for the approver What it does Risk: low. The new path runs only when a record has already drifted and neither file mentions the copy dir or a copy of the same gem@version under any uuid, in any spelling or case. A file that can't be read counts as "still referenced". Every doubtful case keeps the copy, as before. Neither file is written on this path, so it can't break a Look here
Verified
Changes I made: none. Open questions: none. Generated by Claude Code |
Wenxin Jiang (Wenxin-Jiang)
left a comment
There was a problem hiding this comment.
[agent] Reviewed; LGTM.
LLM Description written by Claude Code:claude-fable-5-2
Fixes #2325
Summary
After
bundle remove <gem>, or after the gem is moved to another release,a gem that vendored mode patched could never be cleaned up.
rollback,remove,vendor --revertandscan --mode vendored --pruneall keptits
.socket/vendor/gem/<uuid>/directory and ledger record as "drifted",rollbackandremoveexited 1, andvendor --checkstayed red, so aCI job gating on it failed on every run.
Those commands now clean the entry up. The user's
GemfileandGemfile.lockare not written.Root cause
The gem revert reported every wiring record it could not restore as drift
(
vendor_lock_entry_drifted) and kept the copy and the ledger record. Ithad no case for a record whose fragment is gone because the project dropped
the gem. Nothing can undo that "drift", so the keep was permanent. The npm
family, uv and Pipenv already report this case as
vendor_lock_entry_removedand clean up.The change
In
revert_gem_opts(core,vendor/gem.rs), before any record isreverted, the revert reads whether
GemfileorGemfile.lockstillnames a vendored copy of the gem, in any path spelling and any case: the
entry's own
.socket/vendor/gem/<uuid>directory, or a copy of the samegem and version under another patch uuid.
vendor_lock_entry_removed. Neither file is written, and the copy andthe ledger record are removed.
copy are kept. This still covers an edited
path:line, a PATH sectionleft in the lock, and a commented-out reference.
--preserve-statereport the same and delete nothing.A false "still referenced" only keeps a copy, as before.
CLI_CONTRACT.mddocuments the gem rule beside the other backends' rules.
Evidence
Unit tests in
crates/socket-patch-core/src/vendor/gem.rs:revert_of_a_gem_the_project_dropped_removes_the_copybundle removeand the upgrade variantrevert_of_a_dropped_gem_with_checksums_removes_the_copyrevert_of_a_dropped_gem_keeps_the_copy_on_a_dry_run_and_under_keep_artifact--preserve-staterevert_of_a_dropped_gem_is_drift_while_a_file_names_the_copyrevert_keeps_an_entry_whose_gem_is_wired_to_another_uuidEnd to end with real Bundler,
gem_vendor_dropped_gem_is_cleaned_up_by_every_undo_commandincrates/socket-patch-cli/tests/e2e_vendor_gem_build.rs: vendor rack, dropit with
bundle remove(or pin another release), then runvendor --revert,rollbackorremove. It asserts exit 0, no driftreport, the copy and ledger record gone, both files byte-identical, a frozen
bundle installpassing, andvendor --checkno longer reporting theentry.
Red before the fix (commit 0d27b2b holds the tests alone):
Green on the head, locally with Ruby 3.3.6 and Bundler 4.0.18:
cargo clippy --all-targetsfails locally on test code this PR does nottouch (the same errors on
main); CI lints without--all-targets.Code review
/code-review highran on the diff. Fixed: the other-uuid guard above, theend-to-end test re-locking after
bundle remove(Bundler 2.1 and olderedit only the Gemfile), the contract's wording for an unreadable file, and
the warning text naming one cause for every case.
Not fixed here, both existed before this PR and are outside the revert:
vendor --checkstill tells the user of a dropped gem to "re-runsocket-patch vendorto rewire it". Its dependency-removed wording isreserved for npm and PyPI, whose lock readers can prove the package is
gone. The commands that work now are
scan --mode vendored --prune,rollback,removeandvendor --revert.rollbackof a dropped gem adds the genericreinstall_requiredadvisory, though nothing is left to reinstall.
Follow-ups
Gemfile.lockwith merge-conflict markersis a different cause (vendored mode does not name the conflict) and is not
changed here.
https://claude.ai/code/session_011f9aeRfGJhX51LT65r9KP2
Generated by Claude Code