Skip to content

Fix lock-named platform gem builds warned as not installed (#2452) - #2478

Open
Mikola Lysenko (mikolalysenko) wants to merge 5 commits into
mainfrom
agent/fix-platform-only-gem-lock-resolved
Open

Mikola Lysenko (mikolalysenko) wants to merge 5 commits into
mainfrom
agent/fix-platform-only-gem-lock-resolved

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

LLM Description written by Claude Code:claude-fable-5-2

Fixes #2452

Summary

On a Bundler lock that names a gem only by its precompiled platform builds (no ruby entry: what Bundler 2.5 and 2.6 write, and Bundler 4 after bundle lock --remove-platform ruby), agent mode treated the gem as one the lock does not resolve:

  • apply, and the scan that runs it, printed Warning: N manifest patches had no matching installed package for every build that scan --all-releases recorded, on every run. With a ruby entry in the lock the same records get the calm Note: ... resolved by the project lockfile; skipped.
  • On a fresh checkout with nothing installed yet, apply exited 1 where the ruby-entry lock exits 0.
  • A global scan --prune dropped the records and blobs of such a gem from the project's manifest, though it keeps every other lockfile-listed entry of the project.
  • vex listed the omitted builds under one repeated name (nokogiri@1.19.7, nokogiri@1.19.7, ...).

Root cause

lockfile_resolved in commands/apply.rs and keep_project_entries in commands/scan/gc.rs both asked the lock inventory (ProjectContext::locks) which releases the project's locks resolve. That inventory leaves out a gem the lock holds only as platform builds, because no single .gem stands for it. Scan discovery already adds those gems back from gem_platform_only_purls; these two readers did not.

The change

  • ProjectContext::lock_resolved is the one answer to "which releases do the project's locks resolve": the inventory's entries plus the platform-only gems. apply and the global prune both read it.
  • other_project_gem_copies had its own filter for platform-only gems, needed only because the check before it did not know them. It is removed.
  • ui::build_names names the build of a gem release that is listed more than once (nokogiri@1.19.7 (arm64-darwin)), and the vex omission line uses it. A name listed once is unchanged.

No CLI contract or docs change: the contract already says lockfile-listed packages are a calm skip and are kept by a prune.

For the reviewer

  • One existing test changes its expected exit code. gem_the_lock_holds_as_a_platform_build_is_not_another_projects pinned exit 1 for the fresh checkout. It was written to show that such a gem is not reported as another project's, and it still asserts that. The exit is now 0 with the lockfile-only reason, the same as explicit_path_with_nothing_installed_is_a_calm_skip_under_a_lock beside it.
  • Matching is by release, not by build. A record for a build the lock does not name (a musl build under a lock with only gnu and darwin) also gets the note and is kept by the global prune. That is what a lock with a ruby entry already does, and what the issue asks for; the new tests include such a record.

Evidence

Test Covers Before the fix
apply suite: nothing_installed_is_a_calm_skip_under_a_platform_only_lock fresh checkout, three build records exit 1, "matched no installed package"
apply suite: other_builds_of_an_installed_gem_are_a_note_under_a_platform_only_lock the issue's repro: one build installed and patched, two not Warning: 2 manifest patches had no matching installed package
in_process_scan: scan_global_prune_keeps_a_gem_the_project_locks_only_as_platform_builds global prune both records and their blobs dropped
unit: builds_of_one_release_are_named_with_their_platform, omissions_are_one_line_per_reason the vex line new assertions

Run locally:

  • cargo test -p socket-patch-cli --lib --test apply --test in_process_scan --test in_process_gem_apply --test in_process_gem_multi_platform: 1106, 242, 3, 9 and 33 passed, 0 failed.
  • cargo clippy --locked -p socket-patch-cli --all-features -- -D warnings (the form CI runs): clean. With --all-targets it reports errors in test helpers on main that this PR does not touch; none are in the files changed here.
  • cargo fmt on the touched files.
  • Not run locally: the real-Bundler end-to-end suites (e2e_redirect_gem_build, e2e_vendor_gem_build). They cover hosted and vendored mode, which this change does not touch; CI runs them.

Review

/code-review high found no bug in the change. CI caught one thing the local runs did not: build_names tested the purl type with an inline prefix, which the purl-type convention test in socket-patch-core refuses; it now asks Ecosystem::from_purl. Fixed from the review: the quadratic name count in build_names, and the prune test now uses a gem name no machine has installed. Not changed here, as they are outside this root cause:

  • The vex line can still repeat a name for release variants that are not gems (several PyPI artifacts of one release).
  • The interactive list table shows the builds of one gem under the same name.

https://claude.ai/code/session_011f9aeSPNcmgL99sGZJpqV7


Generated by Claude Code

Refs #2452

Assisted-by: Claude Code:claude-fable-5-2
apply decides whether an uninstalled manifest patch is resolved by
the project lockfile from the lock inventory, and a global
scan --prune asks the same inventory which records the project
still accounts for. That inventory leaves out a gem the Bundler lock
names only by its precompiled platform builds, so on such a lock:

- apply warned "no matching installed package" for every build
  that scan --all-releases recorded, and failed outright on a
  fresh checkout with nothing installed yet;
- a global prune dropped the records and blobs of the gem.

Both now read one ProjectContext::lock_resolved, which adds the
platform-only gems to the inventory's entries.

The vex omission line also names the build of a gem release that
is listed more than once, so the entries can be told apart.

Fixes #2452

Assisted-by: Claude Code:claude-fable-5-2
The other-project gem skip filtered out the gems the lock holds
only as platform builds, because the lock-resolved check before it
did not know them. That check now does, so such a gem never reaches
the skip: remove the filter.

A fresh checkout whose lock names the gem only by platform builds
is now the calm lockfile-only skip (exit 0), as under a lock with a
ruby entry. The test that pinned the earlier failure for that case
keeps what it was written for: the gem is not another project's.

Refs #2452

Assisted-by: Claude Code:claude-fable-5-2
Count the repeated names once instead of rescanning the list for
each entry, and give the global prune test a gem name no machine
has installed, so an installed copy cannot keep the records for it.

Refs #2452

Assisted-by: Claude Code:claude-fable-5-2
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review December 3, 2026 09:54
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

bugbot run


Generated by Claude Code

@cursor

cursor Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes apply/scan/vex behavior for Ruby gems with platform-only locks; logic is localized and heavily tested, but it alters exit codes and prune retention for real projects.

Overview
Introduces ProjectContext::lock_resolved, which treats a gem as lock-resolved when it appears in the normal lock inventory or when the Bundler lock names it only by precompiled platform builds (no ruby entry). apply and scan global prune now use that helper instead of raw lock inventory entries, so those gems get the same calm lockfile-only skip, success exit on empty checkouts, and prune retention as lock-listed packages.

Removes the redundant platform-only filter from other_project_gem_copies, since lock resolution now covers those purls.

Adds build_names for user-facing lists so repeated gem release names are disambiguated with platform qualifiers (e.g. nokogiri@1.19.7 (arm64-darwin)); vex omission warnings use it. Tests and expectations are updated for #2452, including platform-only locks and multi-build manifests.

Reviewed by Cursor Bugbot for commit 84a8b94. Configure here.

build_names tested the purl type with an inline prefix, which the
purl-type convention test in socket-patch-core refuses. Ask
Ecosystem::from_purl, as the rest of the production code does.

Refs #2452

Assisted-by: Claude Code:claude-fable-5-2
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: review brief for the approver

What it does
On a Bundler lock that names a gem only by its precompiled platform builds (no ruby entry), apply now treats the gem's records as resolved by the lockfile, the same as a lock that has a ruby entry. It prints the calm "resolved by the project lockfile" note instead of the not-installed warning, exits 0 on a fresh checkout, and a global scan --prune keeps those records. The vex omission line also tells apart the builds of one gem (nokogiri@1.19.7 (arm64-darwin)).

Risk
Low to medium. The logic change is small and in one place: a new ProjectContext::lock_resolved adds the platform-only gems to the lock inventory, and apply and the prune both read it. It does change behavior: one exit code goes from 1 to 0, and the prune now keeps more records. Both move toward the documented contract. Matching is by release, so a build the lock does not name (a musl build under a gnu/darwin lock) also gets the note, which matches what a ruby-entry lock already does.

Look here

  • context.rs:109: lock_resolved, the new single source
  • apply.rs:5431: lockfile_resolved now reads it
  • apply.rs:3553: the platform-only filter in other_project_gem_copies is removed. This is safe because unresolved already excludes lockfile-resolved purls at both call sites.
  • gc.rs:393: global prune retention
  • [in_process_gem_fallback_home.rs:513](https://github.com/SocketDev/socket-patch/blob/6002eb60b74a5769efd138879b68e5a0791f217a/crates/socket-patch-cli/tests/apply/in_process_gem_fallback_home.rs#L513): the existing test whose expected exit goes from 1 to 0

Verified

  • Read the full diff and both apply call sites of lockfile_resolved → unresolved_purls → other_project_gem_copies.
  • Checked that PurlKey::new strips qualifiers, so platform builds match at release level.
  • Locally on 6002eb6, the new unit tests (builds_of_one_release_are_named_with_their_platform, omissions_are_one_line_per_reason) pass. The new apply platform-only-lock tests (5) and the in_process_scan prune test pass.
  • CI on 6002eb6: ci-ok and clippy green. No open review threads. CHANGELOG.md untouched.

Changes I made
None.

Open questions
None. The two follow-ups the description lists (repeated names for non-gem release variants in vex, and the list table) are outside this fix.


Generated by Claude Code

@mikolalysenko Mikola Lysenko (mikolalysenko) added the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review

Projects

None yet

2 participants