From 098ea8e3f2e0bfdf2b2b196294beb746a8e70685 Mon Sep 17 00:00:00 2001 From: Soutaro Matsumoto Date: Thu, 9 Apr 2026 23:25:07 +0900 Subject: [PATCH] Suppress spurious warning for non-gem stdlib libraries When running `rbs collection install` with an existing lockfile that includes non-gem standard libraries (like socket, pathname), the lockfile generator would emit a misleading warning: Cannot find `socket` gem. Using incorrect Bundler context? This happens because these libraries are part of Ruby's standard library but are not distributed as gems, so they never appear in Bundler's gem specifications. With an existing lockfile, the code path bypasses stdlib detection and falls through to the gem_hash lookup, which fails and triggers the warning. Add NONGEM_STDLIBS constant listing all non-gem standard libraries that have type definitions in stdlib/, and skip the warning for them. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../collection/config/lockfile_generator.rb | 15 +++++- sig/collection/config/lockfile_generator.rbs | 2 + test/rbs/cli_test.rb | 48 +++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/lib/rbs/collection/config/lockfile_generator.rb b/lib/rbs/collection/config/lockfile_generator.rb index 1f6575573f..ebf4ab71c3 100644 --- a/lib/rbs/collection/config/lockfile_generator.rb +++ b/lib/rbs/collection/config/lockfile_generator.rb @@ -21,6 +21,17 @@ class LockfileGenerator "pstore" => nil, } + NONGEM_STDLIBS = Set[ + "cgi-escape", + "coverage", + "monitor", + "objspace", + "pathname", + "pty", + "ripper", + "socket", + ] + class GemfileLockMismatchError < StandardError def initialize(expected:, actual:) @expected = expected @@ -168,7 +179,9 @@ def generate end end else - RBS.logger.warn "Cannot find `#{name}` gem. Using incorrect Bundler context? (#{definition.lockfile})" + unless NONGEM_STDLIBS.include?(name) + RBS.logger.warn "Cannot find `#{name}` gem. Using incorrect Bundler context? (#{definition.lockfile})" + end end end diff --git a/sig/collection/config/lockfile_generator.rbs b/sig/collection/config/lockfile_generator.rbs index d3387ad45c..066f9f4fc3 100644 --- a/sig/collection/config/lockfile_generator.rbs +++ b/sig/collection/config/lockfile_generator.rbs @@ -6,6 +6,8 @@ module RBS # ALUMNI_STDLIBS: Hash[String, String?] + NONGEM_STDLIBS: Set[String] + class GemfileLockMismatchError < StandardError @expected: Pathname diff --git a/test/rbs/cli_test.rb b/test/rbs/cli_test.rb index 9dc3b59251..a9becac114 100644 --- a/test/rbs/cli_test.rb +++ b/test/rbs/cli_test.rb @@ -1491,6 +1491,54 @@ def test_collection_install__pathname_set end end + def test_collection_install__nongem_stdlib_no_warning + Dir.mktmpdir do |dir| + Dir.chdir(dir) do + dir = Pathname(dir) + dir.join(RBS::Collection::Config::PATH).write(<<~YAML) + sources: + - name: ruby/gem_rbs_collection + remote: https://github.com/ruby/gem_rbs_collection.git + revision: b4d3b346d9657543099a35a1fd20347e75b8c523 + repo_dir: gems + + path: #{dir.join('gem_rbs_collection')} + + gems: + - name: socket + - name: pathname + YAML + + bundle_install('ast', 'logger', 'tsort') + + # First install creates the lockfile with socket as stdlib + _stdout, stderr = run_rbs_collection("install", bundler: true) + + lockfile = RBS::Collection::Config::Lockfile.from_lockfile( + lockfile_path: dir + "rbs_collection.lock.yaml", + data: YAML.safe_load((dir + "rbs_collection.lock.yaml").read) + ) + + assert_instance_of RBS::Collection::Sources::Stdlib, lockfile.gems["socket"][:source] + assert_instance_of RBS::Collection::Sources::Stdlib, lockfile.gems["pathname"][:source] + + # Second install with existing lockfile should not warn about nongem stdlibs + _stdout, stderr = run_rbs_collection("install", bundler: true) + + refute_match(/Cannot find `socket` gem/, stderr) + refute_match(/Cannot find `pathname` gem/, stderr) + + lockfile = RBS::Collection::Config::Lockfile.from_lockfile( + lockfile_path: dir + "rbs_collection.lock.yaml", + data: YAML.safe_load((dir + "rbs_collection.lock.yaml").read) + ) + + assert_instance_of RBS::Collection::Sources::Stdlib, lockfile.gems["socket"][:source] + assert_instance_of RBS::Collection::Sources::Stdlib, lockfile.gems["pathname"][:source] + end + end + end + def test_collection_install__set_pathname__manifest Dir.mktmpdir do |dir| Dir.chdir(dir) do