Repository navigation
Fix apply missing a gem that ships no lib/ dir - #2185
Conversation
A gem whose files sit at its root, with no lib/ and no .gemspec of its own (cassandra-web packs app.rb, app/ and bin/), was never found: the Ruby crawler took a gem dir as installed only when it held lib/ or a *.gemspec. RubyGems writes such a gem's spec only to <home>/specifications/<leaf>.gemspec, so apply exited 1 with "The targeted manifest patch matched no installed package", and scan, vex and rollback missed the gem too. A gem dir now also counts when its gem home has a gemspec for it (specifications/ or specifications/default/), the file RubyGems and Bundler load the gem by. A lib-less dir with no such spec is still not a gem. Assisted-by: Claude Code:claude-opus-5-5
A default gem's spec sits in specifications/default/, and its gems/<leaf>/ dir holds only its executables while its code lives in Ruby's own lib dir. Counting that dir as an installed copy would aim a patch at files Ruby never loads, so only the installed specifications/<leaf>.gemspec makes a lib-less dir a gem. The scan's async check now runs the same function as the PURL lookup instead of a copy of it, and comments that named only lib/ and .gemspec say what the check accepts. Assisted-by: Claude Code:claude-opus-5-5
Assisted-by: Claude Code:claude-opus-5-5
PR SummaryMedium Risk Overview
New Reviewed by Cursor Bugbot for commit 11db2f3. Configure here. |
LLM Description written by Claude Code:claude-opus-5-5
Summary
socket-patchnow finds an installed gem that ships nolib/directory and no.gemspecof its own. Before this change,applyexited 1 with "The targeted manifest patch matched no installed package", andscan,vexandrollbackdid not see the gem either.Example:
cassandra-web(every release, 0.1.0 through 0.5.0) putsapp.rb,app/andbin/at the gem root. Itsfileslist holds nolib/and no gemspec, so RubyGems writes the spec only to<home>/specifications/cassandra-web-0.5.0.gemspec. A patch toapp.rb(GHSA-8mfv-xhp5-48q9,disable :protection) could not be applied in agent mode or under--global --global-prefix <home>/gems.Root cause
verify_gem_at_path_syncand its async twinverify_gem_at_pathincrates/socket-patch-core/src/crawlers/ruby_crawler.rsaccepted agems/<leaf>/dir only when it heldlib/or a*.gemspec. Both the PURL lookup (locate_gem_dirs_sync→find_all_by_purls/find_by_purls/find_each_by_purl/find_builds) and the scan (scan_gem_dir) go through that check. The rule has been unchanged since Ruby support landed, so every release through v5.1.0 has it.The rule
A gem dir also counts as installed when its gem home has
specifications/<leaf>.gemspec, the file RubyGems and Bundler load the gem by.specifications/default/does not count. A default gem'sgems/<leaf>/dir holds only its executables, and its code lives in Ruby's own lib dir, so counting that dir would aim a patch at files Ruby never loads.Decisions:
lib/rule already accepted partially deleted dirs that still hadlib/.vexrefuses 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 leftover-dir case, whichretain_loaded_gem_buildsalready handles, and it is a wider behaviour change than this fix needs.Evidence
ruby_crawler::tests::verify_gem_lib_less_dir_listed_by_its_home_specdefault/spec. It is found byverify_gem_at_path,find_by_purlsandcrawl_alloncespecifications/<leaf>.gemspecexists.apply::gem_without_lib_dir::a_gem_with_no_lib_dir_is_patched_by_its_installed_specapply --offlinepatchesapp.rbof a lib-less gem invendor/bundle.apply::gem_without_lib_dir::a_gem_with_no_lib_dir_is_patched_under_a_global_prefix--global --global-prefix <home>/gems.apply::gem_without_lib_dir::a_lib_less_dir_with_no_installed_spec_is_not_a_gemapplystill reports the package as not installed and writes nothing.The new tests fail on
mainwith the production error and pass on this branch. The other 114ruby_crawlerunit tests and the rest of theapplytest binary pass. The only failures in that binary are two PyPI tests (in_process_variant_apply_failure) that needpython3 -m venv, which therust:1.93.1-bookwormimage lacks, so they fail with or without this change.End to end: on
ruby:2.5,gem install cassandra-web -v 0.5.0, thenapply --manifest-path … --cwd … --global --global-prefix "$GEM_HOME/gems" --offline --forcewith a one-fileapp.rbpatch:matched no installed package, exit 1.1 of 1 targeted patch applied, exit 0. The patchedapp.rbis byte-identical to the expected patched file.🤖 Generated with Claude Code