Repository navigation
Fix revert of a vendored gem after a platform is removed (#2283) - #2291
Mikola Lysenko (mikolalysenko) wants to merge 4 commits into
Conversation
Refs #2283. 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_011f9aeRdzAqnWS27Kgayqvw
Three tests for a gem vendored as platform gems whose lock lost a platform to `bundle lock --remove-platform`. Two fail today: the revert of the wired pair, and the revert of a pair that is already back on the registry. The third pins what stays as it is. Refs #2283. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011f9aeRdzAqnWS27Kgayqvw Assisted-by: Claude Code:claude-fable-5-2
A gem vendored as platform gems records one spec block and one CHECKSUMS line per platform the lock held. `bundle lock --remove-platform` drops a platform's spec and its CHECKSUMS line together, and the revert read the missing line as drift: rollback, remove and `vendor --revert` kept the gem wired, and the remedy they name (a re-scan) changed nothing. A platform the lock holds nothing of any more now has nothing to restore. The lock record puts back the blocks of the platforms still locked, the checksum record skips the removed platform's line, and a pair that is already back on the registry without the platform has converged. The reverted lock is the one bundler writes for the same removal on the registry lock. A lock that keeps the platform's spec or a CHECKSUMS line for it is judged as before. The platform-gem capstone drops a platform from a copy of the vendored project with the real bundler and compares the rollback with bundler's own lock for that removal. Fixes #2283. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011f9aeRdzAqnWS27Kgayqvw Assisted-by: Claude Code:claude-fable-5-2
Review of the previous commit found three locks it read as a removed platform that are not one: another build of the gem in the removed one's place (a respelled platform), a lock with no build of the gem left, and lines of the gem the entry grammar does not read. Each made the revert drop a spec or leave a CHECKSUMS line behind and report success. One decision now serves the lock record and the checksum record. A platform counts as removed only when every spec entry and CHECKSUMS line of the gem in the lock is one the record names, and the lock still holds a spec entry of the record. Anything else is judged as before this fix. The three locks are pinned as drift. Refs #2283. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011f9aeRdzAqnWS27Kgayqvw Assisted-by: Claude Code:claude-fable-5-2
|
bugbot run Generated by Claude Code |
PR SummaryMedium Risk Overview Core ( Tests: New unit cases for removal, convergence, and half-removed drift; platform-gem e2e runs Docs: Reviewed by Cursor Bugbot for commit 2343c18. 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 2343c18. Configure here.
|
[agent]
Every other check passed, Generated by Claude Code |
|
[agent] PR shepherd: review brief for the approver What it does. After Risk: low. The change only affects the gem vendored-revert path. The new Look here
Verified
Changes I made: none. Open questions: none. Once #2280 lands, Generated by Claude Code |
LLM Description written by Claude Code:claude-fable-5-2
Fixes #2283
Summary
A gem vendored from prebuilt platform gems (sqlite3, nokogiri, thruster) could not be rolled back or removed once a platform was taken out of the lock with
bundle lock --remove-platform. That command is the remedy socket-patch itself prints for a platform gem it cannot vendor, so a default Rails 8 app runs into it.rollback,removeandvendor --revertall refused the gem as drifted, and the remedy they named (re-runscan --mode vendored) changed nothing.With this change the revert treats a platform that Bundler removed as having nothing to restore. It puts back the entries of the platforms that are still locked. The result is byte for byte the lock Bundler writes for the same removal on the unvendored lock.
Root cause
The ledger records one spec block and one
CHECKSUMSline per platform the lock held when the gem was vendored.bundle lock --remove-platformdrops a platform's spec entry and itsCHECKSUMSline together. The revert incrates/socket-patch-core/src/vendor/gem.rsassumed the lock still held every recorded platform:revert_lock_checksum_recordfound neither the bare line vendor wrote nor the registry line it replaced, and reported drift. This is the refusal in the issue.revert_lock_textput every recorded spec block back, including the removed platform's. On a lock withoutCHECKSUMSthe revert went through and re-added builds for platforms the lock no longer names.lock_record_convergedwanted every recorded block back before it called a hand-restored pair converged.The fix
One function,
removed_platforms, decides which recorded platform builds Bundler has removed, and all three places use it. A build counts as removed only when all of this holds:name (version)entry);CHECKSUMSline for the build;CHECKSUMSline of the gem that is in the lock is one the record names;Any other lock is judged exactly as before, so a hand edit, a respelled platform or an unparseable line is still drift and nothing is written.
Evidence
Real Bundler 4.0.18 and sqlite3 2.10.2 (ten platform builds) against the repository's stand-in patch service (
tests/nokogiri/patch_service.rb): vendor,bundle lock --remove-platform x86-linux-gnu x86-linux-musl, frozen install, then the command.mainrollbackremove pkg:gem/sqlite3@2.10.2vendor --revertrollbackon a lock withoutCHECKSUMSHosted mode already handled the same removal and is unchanged.
Tests, each failing before the fix commit:
a_platform_removed_from_the_lock_reverts_without_it(unit, with and withoutCHECKSUMS): the case in Vendored platform gem cannot be rolled back or removed afterbundle lock --remove-platformon a lock with CHECKSUMS, and the named re-scan remedy changes nothing #2283.a_restored_lock_without_a_removed_platform_has_converged(unit): a pair already back on the registry without the platform.gem_vendor_platform_gems_fresh_checkout_bundle_install_and_revert(e2e_vendor_gem_build): a new step drops a platform with the real Bundler, installs frozen, and comparesrollbackwith that Bundler's lock for the same removal. Run locally on Bundler 2.3.27, 2.4.22, 2.5.23, 2.6.9, 2.7.2 and 4.0.18. Bundler older than 2.5 keeps a removed platform's spec entries, and the step compares against whatever that Bundler writes.a_half_removed_platform_is_restored_or_drift(unit): pins what must not change. It holds the three locks from the review below.Local checks:
cargo clippy --locked -p socket-patch-core -p socket-patch-cli --all-features -- -D warningsclean, 8,644 core lib tests pass,e2e_vendor_gem_build20 of 20 with--include-ignored,rustfmt --checkon the touched files.Review
/code-review highon the first version of the fix found three locks it wrongly read as a removed platform: another build of the gem in the removed one's place, a lock with no build of the gem left, and lines of the gem that do not parse. All three are fixed in the last commit and pinned as drift.Behavior change to know about
On a lock without a
CHECKSUMSsection,mainalready reverted after a platform removal, and re-added the removed platform's spec entries. The revert now leaves them out, which is what Bundler 2.5 and later write.CLI_CONTRACT.md(the gemCHECKSUMSwiring row) anddocs/ecosystems.md(the vendored platform-gem row) say so.Not in this PR
bundle lock --remove-platform ruby, which does not clear thruster or nokogiri on a default Rails 8 lock from Bundler 4.1 #2284 (theplatform_gem_unsupportedremedy names only--remove-platform ruby) is a separate message fix.ci-okis expected to be red onhosted-e2euntil CI: hosted-e2e gem leg fails on every PR: production published activestorage 6.0.3 patch 146ef6aa, not in GEM_UUIDS #2270 is fixed onmain(a production patch that is not in the pinned set). That failure is not from this change.https://claude.ai/code/session_011f9aeRdzAqnWS27Kgayqvw
Generated by Claude Code