Repository navigation
Fix hosted scan reporting a refused gem as patched (#2303) - #2408
Mikola Lysenko (mikolalysenko) wants to merge 4 commits into
Conversation
Refs #2303 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_011f9aeQC9sKL8R3MTbbsn41
A hosted gem pin is the source option on the Gemfile declaration and the gem's own GEM section in the lock. When the Gemfile loses the option and the lock keeps the section, Bundler installs the upstream gem, but the hosted scan reports the gem as patched and its --vex attests it. These tests fail until the next commit: the engine confirms the gem, the scan emits an applied event, and the VEX document holds a statement for it. Refs #2303 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_011f9aeQC9sKL8R3MTbbsn41
Hosted confirmation of a gem went by its patch registry URL occurring anywhere in the final files. The remote line of a Gemfile.lock section is such an occurrence, so a lock that kept its patch section confirmed a gem whose Gemfile no longer names the patch source, although the gem rewriter refused it. The scan then reported the gem as patched and its --vex attested it, while a frozen install fails and a plain one installs the upstream gem. The gem rewriter now reports the patches whose pair it wrote or found whole (confirmed_gem_uuids), and confirm decides a gem by that report alone, as it does for Cargo and Go. A refused gem is a skipped event (redirect_unconfirmed) and is not attested. When the lock still resolves the gem from a section of the patch registry alone, the refusal says so, says the gem is not patched, and names the way back from docs/ecosystems.md: bundle install once without frozen mode, then the hosted scan again. Fixes #2303 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_011f9aeQC9sKL8R3MTbbsn41
Review of the previous commit found that a pin which stands but which the planner refuses to plan over was now reported as skipped: a source block of socket-patch 5.0 / 5.1 that a formatter respelled, for one. The gem rewriter now also confirms a refused gem whose pair still pins it at the address this run was granted (gem_pin_stands), and uses the same check for a gem a Bazel rules_ruby hub holds in place. The orphaned-pin wording is kept to what the rewriter can know. With no declaration in sight the gem may be declared out of sight with its source still on it, so that text no longer says the gem is unpatched and keeps the out-of-sight remedy. A file: source planned for vendored mode never gets the patch registry wording. The contract and docs name the pairs that are counted and the locks the new wording applies to. Refs #2303 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_011f9aeQC9sKL8R3MTbbsn41
|
[agent] bugbot run Generated by Claude Code |
PR SummaryMedium Risk Overview Confirmation now follows the gem rewriter’s Detection/refusal adds orphaned-lock handling with clearer Reviewed by Cursor Bugbot for commit 17d3c76. Configure here. |
|
bugbot run Generated by Claude Code |
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 17d3c76. Configure here.
LLM Description written by Claude Code:claude-fable-5-2
Fixes #2303
Summary
A hosted gem pin is two things: the
source:option on the gem'sGemfiledeclaration, and the gem's ownGEMsection inGemfile.lock. When theGemfileloses the option and the lock keeps the section (a merge that took the other side of theGemfile, agit checkoutof that one file), Bundler installs the upstream gem again and a frozen install fails.Before this change a hosted scan over that state said the gem was patched: an
appliedevent, "Nothing left to patch", and anot_affectedstatement from--vex. Now the gem isskipped(redirect_unconfirmed), the same run's--vexwrites no statement for it, and the warning says what happened and how to get the patch back. The scan still writes nothing for the gem, as before, and the exit code of a plain scan stays 0.Root cause
confirm(corehosted/engine.rs) decides which patches a hosted run pinned. Gems fell to its last arm, which confirms a patch when its registry index URL occurs anywhere in the final files. Theremote:line of the lock section is such an occurrence, so the lock alone confirmed the gem, although the gem rewriter had refused it. Cargo, Go, yarn berry and others were moved off that arm earlier, each to its rewriter's own report. Gems were not.The change
RewriteResult::confirmed_gem_uuids), andconfirmdecides apkg:gem/purl by that report alone. A gem is in the set when its plan was written or found already whole, or when the plan was refused but the pair as it stands still pins the gem at the address this run was granted (gem_pin_stands). The second case keeps two pins counted that the URL probe used to count: asource … doblock from socket-patch 5.0 / 5.1 that a formatter respelled, and a pin a Bazel rules_ruby hub holds in place.redirect_gem_source_optionnow says so, says the gem is not patched, and gives the remedydocs/ecosystems.mdalready documents:bundle installonce without frozen mode, then the hosted scan again. With no declaration in sight,redirect_gem_declaration_not_visiblenames that remedy beside its own, because the declaration may be out of sight with its source still on it.CLI_CONTRACT.md(how a gem is confirmed, and the two warning rows) anddocs/ecosystems.md(the table rows and the "Keep the Gemfile and the lock together" paragraph).Every gem the new rule confirms was also confirmed by the old one, so the change can only turn a false "patched" into "skipped", never the reverse.
Evidence
The first commit holds the tests alone, and they fail there. With the fix arm switched off, the end-to-end test fails on the report from the issue:
hosted::engine::tests::a_gem_lock_pin_whose_gemfile_lost_its_source_is_not_confirmede2e_redirect_gem_stale_install::gem_hosted_rescan_over_a_gemfile_that_lost_its_source_is_not_reported_patchedskippedevent, the warning text, no VEX statement, both files byte-identical.patch::redirect::tests::gem_pin_that_stands_is_confirmed_when_its_plan_is_refusedpathblock and a twice-declared gem do not.patch::redirect::tests::gem_held_by_a_bazel_hub_is_confirmed_only_by_the_pin_that_standspatch::redirect::tests::gem_orphaned_lock_pin_is_read_only_from_a_section_of_the_patch_registry_alonepatch::redirect::tests::gem_file_source_plan_never_speaks_of_the_patch_registryCI on the head commit: all 121 checks pass, and Cursor Bugbot found no issues.
Local runs on the final tree (Ruby 3.3.6, Bundler 4.0.18):
cargo clippy --locked --workspace --all-features -- -D warnings(the CI form)cargo test -p socket-patch-core --libcargo test -p socket-patch-cli --test e2e_redirect_gem_stale_installcargo test -p socket-patch-cli --test e2e_vex_redirectcargo test -p socket-patch-cli --test e2e_redirect_gem_build -- --ignored(real Bundler)cargo test -p socket-patch-cli --test e2e_vendor_gem_build -- --ignored(real Bundler)cargo clippy --all-targetsreports lints in test code onmainwith the pinned toolchain (71 in core). None is in a line this PR adds, and CI does not run that form.Review
/code-review highran on the diff. It found one regression (a respelled 5.0 / 5.1 block would have been reported as skipped) and several documentation and test gaps. All are fixed in the third commit, each with a test where one applies.One finding is left as it is, because it is not new: a pin that a Bazel rules_ruby hub holds is reported as skipped once the grant token in its address rotates, while the warning says the earlier pin stays. The URL probe gave the same answer. Matching the address with the token wildcarded would also match a pin of a superseded patch, so it needs its own change.
Follow-ups
source:option back when the lock half is already in place. The issue leaves that open, and so does this PR.https://claude.ai/code/session_011f9aeQC9sKL8R3MTbbsn41
Generated by Claude Code