Skip to content

Commit 098ea8e

Browse files
soutaroclaude
andcommitted
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) <noreply@anthropic.com>
1 parent ce47189 commit 098ea8e

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed

lib/rbs/collection/config/lockfile_generator.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ class LockfileGenerator
2121
"pstore" => nil,
2222
}
2323

24+
NONGEM_STDLIBS = Set[
25+
"cgi-escape",
26+
"coverage",
27+
"monitor",
28+
"objspace",
29+
"pathname",
30+
"pty",
31+
"ripper",
32+
"socket",
33+
]
34+
2435
class GemfileLockMismatchError < StandardError
2536
def initialize(expected:, actual:)
2637
@expected = expected
@@ -168,7 +179,9 @@ def generate
168179
end
169180
end
170181
else
171-
RBS.logger.warn "Cannot find `#{name}` gem. Using incorrect Bundler context? (#{definition.lockfile})"
182+
unless NONGEM_STDLIBS.include?(name)
183+
RBS.logger.warn "Cannot find `#{name}` gem. Using incorrect Bundler context? (#{definition.lockfile})"
184+
end
172185
end
173186
end
174187

sig/collection/config/lockfile_generator.rbs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ module RBS
66
#
77
ALUMNI_STDLIBS: Hash[String, String?]
88

9+
NONGEM_STDLIBS: Set[String]
10+
911
class GemfileLockMismatchError < StandardError
1012
@expected: Pathname
1113

test/rbs/cli_test.rb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,6 +1491,54 @@ def test_collection_install__pathname_set
14911491
end
14921492
end
14931493

1494+
def test_collection_install__nongem_stdlib_no_warning
1495+
Dir.mktmpdir do |dir|
1496+
Dir.chdir(dir) do
1497+
dir = Pathname(dir)
1498+
dir.join(RBS::Collection::Config::PATH).write(<<~YAML)
1499+
sources:
1500+
- name: ruby/gem_rbs_collection
1501+
remote: https://github.com/ruby/gem_rbs_collection.git
1502+
revision: b4d3b346d9657543099a35a1fd20347e75b8c523
1503+
repo_dir: gems
1504+
1505+
path: #{dir.join('gem_rbs_collection')}
1506+
1507+
gems:
1508+
- name: socket
1509+
- name: pathname
1510+
YAML
1511+
1512+
bundle_install('ast', 'logger', 'tsort')
1513+
1514+
# First install creates the lockfile with socket as stdlib
1515+
_stdout, stderr = run_rbs_collection("install", bundler: true)
1516+
1517+
lockfile = RBS::Collection::Config::Lockfile.from_lockfile(
1518+
lockfile_path: dir + "rbs_collection.lock.yaml",
1519+
data: YAML.safe_load((dir + "rbs_collection.lock.yaml").read)
1520+
)
1521+
1522+
assert_instance_of RBS::Collection::Sources::Stdlib, lockfile.gems["socket"][:source]
1523+
assert_instance_of RBS::Collection::Sources::Stdlib, lockfile.gems["pathname"][:source]
1524+
1525+
# Second install with existing lockfile should not warn about nongem stdlibs
1526+
_stdout, stderr = run_rbs_collection("install", bundler: true)
1527+
1528+
refute_match(/Cannot find `socket` gem/, stderr)
1529+
refute_match(/Cannot find `pathname` gem/, stderr)
1530+
1531+
lockfile = RBS::Collection::Config::Lockfile.from_lockfile(
1532+
lockfile_path: dir + "rbs_collection.lock.yaml",
1533+
data: YAML.safe_load((dir + "rbs_collection.lock.yaml").read)
1534+
)
1535+
1536+
assert_instance_of RBS::Collection::Sources::Stdlib, lockfile.gems["socket"][:source]
1537+
assert_instance_of RBS::Collection::Sources::Stdlib, lockfile.gems["pathname"][:source]
1538+
end
1539+
end
1540+
end
1541+
14941542
def test_collection_install__set_pathname__manifest
14951543
Dir.mktmpdir do |dir|
14961544
Dir.chdir(dir) do

0 commit comments

Comments
 (0)