Skip to content

Commit d5310be

Browse files
hsbtclaude
andcommitted
Prove the plugin source test by the side effect it prevents
The fixture left the plugin index without load paths, so removing the guard failed on a missing path rather than on the plugin running. Give the plugin something to load and assert it never wrote its marker. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 674ed3f commit d5310be

2 files changed

Lines changed: 27 additions & 10 deletions

File tree

lib/rubygems/request_set.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,10 +406,10 @@ def load_lockfile(lock_file) # :nodoc:
406406
parser.dependencies.each_value do |dep|
407407
requirements = dep.requirement.as_list
408408

409-
# A dependency marked `!` in the DEPENDENCIES section carries no version
410-
# requirement, so pin it to the version its own section resolved. For a
411-
# PATH section that is the version of the gemspec on disk, not the one
412-
# the lockfile records.
409+
# A dependency the lockfile ties to a source replaces whatever it asks
410+
# for with the version that source resolved, the way the parser this
411+
# replaced did. For a PATH section that is the version of the gemspec on
412+
# disk, not the one the lockfile records.
413413
if dep.source && (version = locked_versions[dep.name])
414414
requirements = [version]
415415
end

test/rubygems/test_gem_request_set.rb

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -553,31 +553,43 @@ def test_load_lockfile_does_not_load_plugins_for_a_plugin_source_section
553553
require "bundler"
554554
require "bundler/plugin"
555555

556-
FileUtils.mkdir_p File.join(@tempdir, ".bundle", "plugin", "plugins", "evil")
556+
plugin = File.join @tempdir, ".bundle", "plugin", "plugins", "example"
557+
loaded = File.join @tempdir, "plugin-was-loaded"
558+
559+
FileUtils.mkdir_p File.join(plugin, "lib")
560+
557561
File.open File.join(@tempdir, "Gemfile"), "w" do |io|
558562
io.puts 'source "https://rubygems.org"'
559563
end
560-
File.open File.join(@tempdir, ".bundle", "plugin", "plugins", "evil", "plugins.rb"), "w" do |io|
561-
io.puts "raise 'plugin code must not run while parsing a lockfile'"
564+
565+
File.open File.join(plugin, "plugins.rb"), "w" do |io|
566+
io.puts "File.write #{loaded.dump}, \"loaded\""
567+
io.puts "class ExampleSource"
568+
io.puts " include Bundler::Plugin::API::Source"
569+
io.puts "end"
570+
io.puts 'Bundler::Plugin::API.source("example_type", ExampleSource)'
562571
end
572+
563573
File.open File.join(@tempdir, ".bundle", "plugin", "index"), "w" do |io|
564574
io.puts <<~INDEX
565575
---
566576
commands:
567577
hooks:
568578
load_paths:
579+
example:
580+
- plugins/example/lib
569581
plugin_paths:
570-
evil: plugins/evil
582+
example: plugins/example
571583
sources:
572-
evil_type: evil
584+
example_type: example
573585
INDEX
574586
end
575587

576588
File.open "gem.deps.rb.lock", "w" do |io|
577589
io.puts <<~LOCKFILE
578590
PLUGIN SOURCE
579591
remote: https://gems.example/
580-
type: evil_type
592+
type: example_type
581593
specs:
582594
a (1)
583595
@@ -589,10 +601,15 @@ def test_load_lockfile_does_not_load_plugins_for_a_plugin_source_section
589601
LOCKFILE
590602
end
591603

604+
Bundler::Plugin.reset!
605+
592606
rs = Gem::RequestSet.new
593607
rs.load_lockfile "gem.deps.rb.lock"
594608

609+
assert_path_not_exist loaded
595610
assert_equal [dep("a")], rs.dependencies
611+
ensure
612+
Bundler::Plugin.reset!
596613
end
597614

598615
def test_load_lockfile_keeps_bundler_root_when_it_cannot_be_swapped

0 commit comments

Comments
 (0)