From 1d5bcaf8c2c42dc712516b3eb2edc0111d1eaae4 Mon Sep 17 00:00:00 2001 From: ksss Date: Thu, 8 Oct 2026 14:38:41 +0000 Subject: [PATCH 1/2] Don't warn about default gems missing from Gemfile.lock Default gems are always installed with Ruby, so specifying one in `gems:` of rbs_collection.yaml without adding it to Gemfile is valid. Skip the "Cannot find gem. Using incorrect Bundler context?" warning for them. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_019wWXRc7Va2Vqk2G3BbjMWi --- .../collection/config/lockfile_generator.rb | 7 ++- sig/collection/config/lockfile_generator.rbs | 4 ++ test/rbs/collection/config_test.rb | 44 +++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/lib/rbs/collection/config/lockfile_generator.rb b/lib/rbs/collection/config/lockfile_generator.rb index ebf4ab71c3..b8881a3ab8 100644 --- a/lib/rbs/collection/config/lockfile_generator.rb +++ b/lib/rbs/collection/config/lockfile_generator.rb @@ -179,7 +179,7 @@ def generate end end else - unless NONGEM_STDLIBS.include?(name) + unless NONGEM_STDLIBS.include?(name) || default_gem?(name) RBS.logger.warn "Cannot find `#{name}` gem. Using incorrect Bundler context? (#{definition.lockfile})" end end @@ -250,6 +250,11 @@ def generate end end + # Default gems are always available without being listed in Gemfile.lock. + private def default_gem?(name) + Gem::Specification.default_stubs("#{name}-*.gemspec").any? { |stub| stub.name == name } + end + private def find_source(name:) sources = config.sources diff --git a/sig/collection/config/lockfile_generator.rbs b/sig/collection/config/lockfile_generator.rbs index 066f9f4fc3..cedad7a62a 100644 --- a/sig/collection/config/lockfile_generator.rbs +++ b/sig/collection/config/lockfile_generator.rbs @@ -55,6 +55,10 @@ module RBS # def assign_stdlib: (name: String, ?from_gem: String) -> void + # Returns `true` if a default gem with the name is installed. + # + def default_gem?: (String name) -> bool + # Find a source of a gem from ones registered in `config.sources` # # Returns `nil` if no source contains the definition of the gem. diff --git a/test/rbs/collection/config_test.rb b/test/rbs/collection/config_test.rb index bc524dfa1b..09b300997d 100644 --- a/test/rbs/collection/config_test.rb +++ b/test/rbs/collection/config_test.rb @@ -697,6 +697,50 @@ def test_generate_lockfile__gems_not_included_in_gemfile end end + def test_generate_lockfile__default_gems_not_included_in_gemfile + omit unless Gem::Specification.default_stubs("un-*.gemspec").any? { _1.name == "un" } + + mktmpdir do |tmpdir| + config_path = tmpdir / 'rbs_collection.yaml' + config_path.write <<~YAML + sources: [] + path: '.gem_rbs_collection' + gems: + - name: un + YAML + gemfile_path = tmpdir / 'Gemfile' + gemfile_path.write <<~GEMFILE + source 'https://rubygems.org' + GEMFILE + gemfile_lock_path = tmpdir / 'Gemfile.lock' + gemfile_lock_path.write <<~GEMFILE_LOCK + GEM + remote: https://rubygems.org/ + specs: + + PLATFORMS + x86_64-linux + + DEPENDENCIES + + BUNDLED WITH + 2.2.0 + GEMFILE_LOCK + + definition = Bundler::Definition.build(gemfile_path, gemfile_lock_path, false) + + log = StringIO.new + RBS.logger_output = log + begin + RBS::Collection::Config.generate_lockfile(config_path: config_path, definition: definition) + ensure + RBS.logger_output = nil + end + + refute_match(/Cannot find `un` gem/, log.string) + end + end + def test_generate_lockfile__dependency_source mktmpdir do |tmpdir| config_path = tmpdir / 'rbs_collection.yaml' From ce5ed67db550d3dc71a86437e6db2cb99242154c Mon Sep 17 00:00:00 2001 From: ksss Date: Fri, 9 Oct 2026 00:31:20 +0900 Subject: [PATCH 2/2] Fix CI for default gem warning suppression - Add `Gem::Specification.default_stubs` to the rubygems shim for Steep - `set` is a default gem on Ruby < 3.5, so the warning is no longer expected there Co-Authored-By: Claude Opus 5.5 --- sig/shims/rubygems.rbs | 6 ++++++ test/rbs/cli_test.rb | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/sig/shims/rubygems.rbs b/sig/shims/rubygems.rbs index b647e403bf..532f30f221 100644 --- a/sig/shims/rubygems.rbs +++ b/sig/shims/rubygems.rbs @@ -6,9 +6,15 @@ module Gem def self.find_by_name: (String name, *String requirements) -> instance + def self.default_stubs: (?String pattern) -> Array[StubSpecification] + def dependencies: () -> Array[Dependency] end + class StubSpecification + def name: () -> String + end + class Dependency def name: () -> String end diff --git a/test/rbs/cli_test.rb b/test/rbs/cli_test.rb index 5e4cadad6e..aeb38f787e 100644 --- a/test/rbs/cli_test.rb +++ b/test/rbs/cli_test.rb @@ -1648,7 +1648,12 @@ def test_collection_install__pathname_set bundle_install('ast', 'logger', 'tsort') _stdout, stderr = run_rbs_collection("install", bundler: true) - assert_include stderr, 'Cannot find `set` gem.' + # `set` is a default gem until Ruby 3.5, where it became a core class. + if Gem::Specification.default_stubs("set-*.gemspec").any? { _1.name == "set" } + refute_match(/Cannot find `set` gem/, stderr) + else + assert_include stderr, 'Cannot find `set` gem.' + end lockfile = RBS::Collection::Config::Lockfile.from_lockfile( lockfile_path: dir + "rbs_collection.lock.yaml",