@@ -391,6 +391,58 @@ def should_not_have_gems(*gems)
391391 expect ( vendored_gems ( "bin/myrackup" ) ) . not_to exist
392392 end
393393
394+ it "removes orphaned gemspecs from ABI-scoped specification dirs" , rubygems : ">= 4.1.0.dev" do
395+ gemfile <<-G
396+ source "https://gem.repo1"
397+
398+ gem "foo"
399+ G
400+
401+ bundle_config "path vendor/bundle"
402+ bundle "install"
403+
404+ abi_dir = vendored_gems ( "specifications/#{ Gem . ruby_abi } " )
405+ FileUtils . mkdir_p ( abi_dir )
406+ orphaned_gemspec = File . join ( abi_dir , "orphaned-1.0-deadbeef.gemspec" )
407+ File . write ( orphaned_gemspec , "orphaned" )
408+
409+ bundle :clean
410+
411+ expect ( File . exist? ( orphaned_gemspec ) ) . to be false
412+ should_have_gems "foo-1.0"
413+ end
414+
415+ it "does not remove gemspecs for content-addressed gems in the bundle" , :compact_index , rubygems : ">= 4.1.0.dev" do
416+ skip "Gem::ContentAddress not available" if ruby_core?
417+
418+ simulate_platform "x86_64-linux" do
419+ build_repo2 do
420+ build_gem "mygem" , "1.0" do |s |
421+ s . platform = Gem ::Platform . new ( "x86_64-linux" )
422+ s . write "lib/mygem.rb" , "MYGEM = '1.0 not_content_addressed'"
423+ end
424+ end
425+
426+ build_gem "mygem" , "1.0" , ruby_abi : Gem . ruby_abi , path : gem_repo2 ( "gems" ) do |s |
427+ s . platform = Gem ::Platform . new ( "x86_64-linux" )
428+ s . required_ruby_version = "~> #{ Gem . ruby_abi } .0"
429+ s . write "lib/mygem.rb" , "MYGEM = '1.0 content_addressed'"
430+ end
431+
432+ bundle_config "path vendor/bundle"
433+ install_gemfile <<~G , artifice : "compact_index_v2" , env : { "BUNDLER_SPEC_GEM_REPO" => gem_repo2 . to_s }
434+ source "https://gem.repo2"
435+
436+ gem "mygem"
437+ G
438+
439+ bundle :clean
440+
441+ abi_gemspecs = Dir . glob ( vendored_gems ( "specifications/#{ Gem . ruby_abi } /*.gemspec" ) . to_s )
442+ expect ( abi_gemspecs . size ) . to eq ( 1 ) , "expected content-addressed gemspec to be preserved, found: #{ abi_gemspecs } "
443+ end
444+ end
445+
394446 it "does not call clean automatically when using system gems" do
395447 bundle_config "path.system true"
396448
0 commit comments