Repository navigation
Fix gem dir with no gemspec counted as installed (#2087) - #2124
Mikola Lysenko (mikolalysenko) merged 5 commits into
Conversation
Refs #2087. 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_011f9aeSRKgiJ4152hMeivxR
Failing tests for #2087. A gem home lists the ruby-platform build of a gem version and holds the dir of a precompiled build it has no gemspec for (what the stale-install remedy leaves behind). Nothing loads that dir, yet the crawler returns it as an installed copy and vex refuses the patched gem over it (not_applied). 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_011f9aeSRKgiJ4152hMeivxR
The Ruby crawler counted every gems/<name>-<version>[-<platform>] dir with a lib/ as an installed copy. RubyGems and Bundler load a gem by its specifications entry alone, so the dir of a build whose gemspec is gone is one nothing loads. The hosted scan's remedy for a stale precompiled build (rm its gemspec and archive, then bundle install) leaves exactly that beside the patched ruby-platform build, and vex then refused the gem as not_applied. A build's dir is now skipped when its gem home has no gemspec for it but has one for another build of the same version. A version the home lists no build of is not judged, so nothing changes where the home does not say what is installed. The scan's discovery follows the same rule, so it never names a dir the lookups skip. Fixes #2087. 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_011f9aeSRKgiJ4152hMeivxR
The first fix skipped a leftover build dir in the crawler, which every mode resolves through. Review found that too wide: rollback and remove would stop restoring such a dir after agent mode had patched it, a standalone bundle can still load it through bundler/setup.rb, and is_file() took any stat error for an absent gemspec. The crawler is back to what main has. is_leftover_gem_build is now applied where vex and apply --check collect copies, beside the filters of #1098 and #599, so the write paths see every dir as before. It calls a dir a leftover only on proof: the gemspec is not found (no other stat error counts), another build of the version is listed, and no standalone setup.rb names the dir. Adds the hosted-mode vex test for the state #2087 reports, for a bundle path inside the project and one outside it. Fixes #2087. 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_011f9aeSRKgiJ4152hMeivxR
Second review pass on the verify-only filter: - The listed build had to exist only as a gemspec. With its dir missing, a gem could lose every copy and the hosted lock pin would attest with nothing hashed. The filter now takes the copies of one gem version and drops a dir only when another of them in the same home has its gemspec. - A standalone setup.rb was looked for two levels above the home only, and matched only with a slash after the dir. A flat home keeps it in <home>/bundler, and a gem loaded from its root has no slash. - A dir whose parent is not gems/ is not judged. - The probes run in one blocking task per gem. Refs #2087. 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_011f9aeSRKgiJ4152hMeivxR
|
bugbot run Generated by Claude Code |
PR SummaryMedium Risk Overview The core adds Edge cases stay conservative: dirs are kept when they are the last copy in a home, when gemspec presence cannot be proven (non– Reviewed by Cursor Bugbot for commit 640b52b. 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 640b52b. Configure here.
|
[agent] PR shepherd: review brief for the approver What it does. Fixes #2087. After a project switches a gem from a precompiled build to the Risk: low. The change only affects the two read-only checks. It drops a copy only when there is proof: the gemspec stat must return "not found" (any other error keeps the dir), the gem keeps at least one listed copy in that home, and a standalone Look here
Verified
Changes I made. None. Open questions. None. The follow-ups listed under "Not in this PR" ( Generated by Claude Code |
LLM Description written by Claude Code:claude-fable-5-2
Fixes #2087
Summary
socket-patch vexandapply --checkno longer count the leftover directory of a gem build that is not installed. After a project moves a gem from its precompiled build to therubyplatform build (the path hosted mode sends people down) and runs the scan's ownrm -f <gemspec> <archive> && bundle installremedy,gems/nokogiri-1.16.0-x86_64-linux/is left with no gemspec beside the patchedgems/nokogiri-1.16.0/.vexjudged it as an installed copy, found the original bytes and exited 1 withnot_applied. It now attests the gem.The change is read-only:
apply,rollback,removeand the scan resolve gem dirs exactly as before.Root cause
The Ruby crawler returns every
gems/<name>-<version>[-<platform>]/dir that has alib/as a copy (#1092, so that a platform build installed beside therubyone is patched and verified). It never asks whether the gem home has a gemspec for the dir. RubyGems and Bundler load a gem byspecifications/<leaf>.gemspecalone, so a dir without one is not installed, and the verification gates were refusing a patched gem over files nothing can load.The rule
retain_loaded_gem_builds(ruby_crawler.rs) takes the copies of one gem version and drops a dir when its gem home has no gemspec for it (specifications/orspecifications/default/) and another of those copies in the same home has its own.find_manifest_package_copies_reusing(ecosystem_dispatch.rs), the one functionvexandapply --checkcollect copies through, applies it next to the existing #1098 and #599 filters.Everything short of proof keeps the dir a copy, so a gem is never attested on a guess:
bundle install --standalonetree loads dirs by the paths inbundler/setup.rb, so a dir that file names (or an unreadable file might name) stays a copy;applypatches only the ruby-platformx-1.0/dir when ax-1.0-x86_64-linux-gnu/sibling is also installed, so Bundler loads the unpatched platform gem whilevexattestsnot_affected#1092 is unchanged, and tested).Evidence
e2e_vex_redirect::gem_hosted_ref_is_attested_beside_a_leftover_platform_dir_with_no_gemspecrubybuild, unpatched platform dir with no gemspec), for a bundle path inside the project and one outside it.vexattests; with the gemspec back it exits 1.apply::in_process_gem_multicopy::the_leftover_dir_of_an_unlisted_platform_build_is_not_a_copyvexandapply --checkpass, both refuse once the gemspec is back, andapply/rollbackstill write and restore the dir.ruby_crawler::tests::retain_loaded_gem_builds_*(4)gems/, a gemspec that cannot be probed, and a standalonesetup.rb(scoped and flat homes, with and without a require path).Both CLI tests fail without the filter (
vexexits 1,not_applied) and pass with it. The first commit holds theapply-suite test alone, failing.Run locally on Ruby 3.3.6 / Bundler 4.0.18, all passing (CI: all 88 checks pass on 640b52b, Bugbot found no issues):
cargo clippy --locked --workspace --all-features -- -D warnings(CI's command)cargo test -p socket-patch-corecargo test -p socket-patch-cli --lib --test apply --test e2e_vex --test e2e_vex_redirect --test e2e_redirect_gem_build --test e2e_vendor_gem_build --test e2e_gem_native_ext_build --test e2e_redirect_gem_stale_install --test in_process_gem_apply --test in_process_gem_multi_platform -- --include-ignoredcargo clippy -p <crate> --all-targetsreports lints in test code onmaintoo (CI's clippy does not lint test targets); none are in lines this PR adds.Review
/code-review highran twice. The first pass was on a version that filtered inside the crawler:rollback/removewould no longer restore a leftover dir agent mode had patched. Fixed: the rule moved out of the crawler into the verify-only copy filter, as With Bun's isolated linker,vexrefuses every hosted patch as not_applied after the usual in-placebun install, because it checks orphanednode_modules/.bunregistry entries that Bun never removes (regression from #496) #599 did for Bun. Tested.bundler/setup.rbguard. Tested.is_file()reads any stat error as "absent". Fixed: only "not found" counts. Tested.specifications/. Requiring a listed copy beside the dir keeps the change to the one state the remedy produces.The second pass was on the verify-only filter:
setup.rbwas looked for in the scoped layout only, and matched only with a trailing slash. Fixed: flat homes are covered and an entry for a gem loaded from its root matches. Tested.run_blockingper gem with more than one copy.<home>/specifications/<leaf>.gemspecderivation withis_default_gem_copyandhome_spec. Not done: those useis_file(), which is the stat-error behavior this rule must avoid, and unifying the callers is a refactor of its own. Thegems/parent guard the finding asked for is in.applystill walks the leftover dir, so it can fail withno matching variant foundwhereapply --checknow passes; the hosted scan's stale-install guard looks at the first dir only. Both are howmainbehaves and neither is what Standalonevexrefuses a hosted gem asnot_appliedbecause of a leftover<gem>-<version>-x86_64-linuxdirectory that has no gemspec, after the scan's ownrm -f … && bundle installremedy #2087 reports. Listed below.Not in this PR
bundle installinstead of the remedy, the old platform build keeps its gemspec. RubyGems can load it, sovexstill refuses it (Gem agentapplypatches only the ruby-platformx-1.0/dir when ax-1.0-x86_64-linux-gnu/sibling is also installed, so Bundler loads the unpatched platform gem whilevexattestsnot_affected#1092), and the warning still does not name the directory orbundle clean --force. Naming the path in thevexomission is a message change worth its own PR.bundle clean --forceremoves it;docs/ecosystems.mdnow says so).applystill treats a leftover dir as a copy: it patches it when the bytes match and fails withno matching variant foundwhen they match no manifest variant. Changing whatapplywrites needs its own look atrollback(see the first review finding).find_each_by_purl), so in the reverse case (a leftoverrubydir beside an installed platform build) it judges the leftover.https://claude.ai/code/session_011f9aeSRKgiJ4152hMeivxR
Generated by Claude Code