Repository navigation
Fix agent mode reading gemrc gem directories Ruby does not load (#2317) - #2459
Mikola Lysenko (mikolalysenko) wants to merge 4 commits into
Conversation
Refs #2317. 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_011f9aeNtgNFdDtdR3SwZfjU
The gem command applies the gemrc keys gemhome and gempath to its own directories. Ruby and Bundler never read them, so under such a gemrc `gem env` names a directory the project loads nothing from. Three tests that fail on main: - core, crawler_ruby_e2e: with a gem that answers as the real one does under a gemrc, the project and the global paths are Ruby's Gem.dir and Gem.path. - CLI, apply suite: apply and apply --check act on the copy Ruby loads, and leave a copy in the gemrc's directory alone. - CLI, e2e_gem_native_ext_build: the same with the real gem and ruby, a GEMRC file and GEM_HOME. Refs #2317. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011f9aeNtgNFdDtdR3SwZfjU Assisted-by: Claude Code:claude-fable-5-2
A Bundler project with no bundle path of its own, and a --global run, find the gem directories with `gem env gemdir` and `gem env gempath`. The gem command applies the gemrc keys gemhome and gempath to its own directories. Ruby and Bundler never read them: require, bundle install and bundle exec load from Gem.dir and Gem.path as the environment gives them. With either key in a gemrc, the run read a directory the project loads nothing from and skipped the ones it does. An installed gem was reported as not installed, and a copy of the same version in the gemrc's directory was patched, checked and attested in place of the unpatched one the application loads. Both questions now pass --norc, which answers with Gem.dir and Gem.path. GEM_HOME and GEM_PATH are the environment's and count as before. Every caller shares the one probe: the project fallback, the global paths, the hosted stale-install probe and the rollback lookup. Fixes #2317. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011f9aeNtgNFdDtdR3SwZfjU Assisted-by: Claude Code:claude-fable-5-2
A gem command that gives no answer to `gem env <key> --norc` (one too old to know the flag, or a wrapper that refuses it) left a system-gems project with no gem directory at all: every gem read as not installed, and apply --check passed over unpatched code. Such a gem is now asked again without the flag, which is the question every earlier release asked. Its answer is right wherever no gemrc sets gemhome or gempath. Found by the review of this branch. The new test fails on the previous commit. Refs #2317. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011f9aeNtgNFdDtdR3SwZfjU Assisted-by: Claude Code:claude-fable-5-2
|
bugbot run Generated by Claude Code |
PR SummaryMedium Risk Overview CLI contract documents the new probing behavior (#2317). Tests cover gemrc fixtures (in-process apply, core crawler path resolution, ignored host e2e with real Reviewed by Cursor Bugbot for commit 4b2e385. Configure here. |
|
[agent] The
The other legs that were cancelled the same way were re-run with it. I have not re-run this job a second time. Generated by Claude Code |
|
[agent] PR shepherd: review brief for the approver What it does Risk: medium. The one-line probe change feeds every gem caller (project fallback, Look here
Verified
Changes I made: none. Open questions: whether gemrc-only directories should later be read as a "found but never written" copy class for Generated by Claude Code |
LLM Description written by Claude Code:claude-fable-5-2
Fixes #2317
Summary
With
gemhomeorgempathin a gemrc (~/.gemrc, the system gemrc, aGEMRCfile), agent mode read gem directories the application does not load from and skipped the ones it does. An installed gem was reported as not installed (applyandapply --checkexited 0 without patching), and a copy of the same version in the gemrc's directory was patched, checked and attested byvexwhile the application kept loading unpatched code.scan -gfound no gems.The fix is one line of behavior: the two questions are now asked as
gem env gemdir --norcandgem env gempath --norc, which answer with Ruby's ownGem.dirandGem.path.GEM_HOMEandGEM_PATHcount as before. A project with no such gemrc gets the same answer as onmain.Root cause
run_gem_env(corecrawlers/ruby_crawler.rs) rangem env <key>. Thegemcommand applies the gemrc keysgemhomeandgempathto its own process;require,bundle installandbundle execnever read them. Every caller shares that one probe (the project fallback, the global paths, the hosted stale-install probe, the rollback lookup), so the fix is at the probe.Checked with the real tools (Ruby 3.3.6, RubyGems 3.5.22), with
gemhome: <dir>in aGEMRCfile:gem env gemdir/gempathgem env gemdir --norc/gempath --norcGEM_HOMEwhen set)ruby -e 'puts Gem.dir, Gem.path'--norcDo-no-harm notes for the reviewer
gemthat gives no answer with--norc(one too old to know the flag, or a wrapper that refuses it) is asked the plain question again, so such a machine behaves as onmainand does not lose its gem directories.gemscripts of the existing suites match on the first two arguments, so they answer the new question unchanged.Evidence
Red to green (commit fc201bc adds the first three tests before the fix; each fails on
main):crawler_ruby_e2e::get_gem_paths_reads_rubys_gem_dirs_not_the_gemrcs: agemthat answers as the real one does under a gemrc; the project paths and the--globalpaths are Ruby's, and only the copies Ruby loads are found (states 1, 2 and 4 of the issue).applysuite,a_gemrc_gemhome_does_not_hide_the_copy_ruby_loadsanda_copy_in_the_gemrc_gemhome_is_not_patched_in_place_of_rubys:apply --checkexits 1 over the unpatched copy Ruby loads,applypatches it and leaves the gemrc's copy alone, and a patched copy in the gemrc's directory does not make the check pass (states 1 to 3).gemandruby,e2e_gem_native_ext_build::a_gemrc_gemhome_is_not_read_in_place_of_rubys_gem_dirs(--ignored, the pinned-Ruby legs): aGEMRCfile andGEM_HOME; it first asserts the premise from the tools themselves, then the same outcome.get_gem_paths_asks_a_gem_without_norc_the_plain_question: fails on the commit before the fallback.Run locally on this branch (Ruby 3.3.6, Bundler 4.0.18):
cargo test -p socket-patch-core --test crawler_ruby_e2ecargo test -p socket-patch-core --lib rubycargo test -p socket-patch-cli --test apply --test scan --test get --test e2e_redirect_gem_stale_install --test in_process_gem_apply --test in_process_gem_multi_platformcargo test -p socket-patch-cli --test e2e_redirect_gem_build --test e2e_vendor_gem_build --test e2e_gem_native_ext_build -- --include-ignoredcargo clippy --locked --workspace --all-features -- -D warnings(the CI command)cargo clippy --all-targetsreports errors in test code onmainas well (none in the lines this PR adds); CI does not run it that way.Review
/code-review highran on the diff. Fixed: agemthat rejects--norcleft a system-gems project with no gem directory (the fallback above, with its test).Not fixed, with reasons:
rollbackorremove. Those commands look whereapplylooks, which no longer includes that directory. The copy is one Ruby does not load, it keeps the patched bytes, andgem pristine <gem>puts the upstream ones back. Reading the gemrc's directories as a class of unloaded copies (found byrollback, never written or attested) is the change the issue leaves to a maintainer: "they can be added after Ruby's own, never in place of them". It touches the copy classes ofapply,vexandrollback, so it is a follow-up and not part of this fix.--globalno longer lists gems that only the gemrc's directory holds. A Ruby program cannot load them unlessGEM_HOMEorGEM_PATHnames that directory too, in which case it is read. Same maintainer question as above.CI
ci-okandclippyare green on 4b2e385. Cursor Bugbot reviewed that commit and reported no findings.The nokogiri compatibility workflow (not required for merge) was started twice for this head, and the second start cancelled seven jobs of the first. I re-ran them once: six passed.
jruby-9.4 / nokogiri 1.18.10 java / ubuntu-latestis red because its runner "lost communication with the server" (no log kept). Its first attempt had finished withPASS: 49 checksone second before it was cancelled; see the comment on this PR.Docs
CLI_CONTRACT.md, gem discovery: how the question is asked and why a directory only a gemrc names is not read.Not checked
The system gemrc, Windows, JRuby and TruffleRuby (
--norcskips every gemrc through one code path in RubyGems; read, not run).https://claude.ai/code/session_011f9aeNtgNFdDtdR3SwZfjU
Generated by Claude Code