Skip to content

Commit c6a345d

Browse files
committed
Vendor compact_index under a dedicated namespace
Gem::Indexer (rubygems-generate_index) loads the V1-only CompactIndex constants, either from the compact_index gem or from its own embedded copy, so the artifice's copy of rubygems.org's V2-only implementation can never share that name safely. Check in a copy of rubygems.org's lib/compact_index, renamed to the VendoredCompactIndex namespace, under spec/support/vendor/compact_index, and load it from the artifice with a plain require. Checking the copy in (rather than downloading it during the test run) keeps the suite hermetic and offline, makes the namespace rewrite visible in review, and lets parallel workers and CI runners that skip the test-deps setup load it without falling back to the incompatible gem. Refresh the copy with `rake vendor:compact_index`; `rake vendor:compact_index_check` fails if the checked-in copy drifts from the pinned upstream ref. Assisted-By: devx/8309afec-0948-41c8-a29d-3b1ea27ef32a
1 parent 01c8c4f commit c6a345d

20 files changed

Lines changed: 277 additions & 67 deletions

.rubocop.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ AllCops:
1414
- tmp/**/*
1515
- lib/rubygems/vendor/**/*
1616
- lib/bundler/vendor/**/*
17+
- spec/support/vendor/**/*
1718
CacheRootDirectory: tmp/rubocop
1819
MaxFilesInCache: 5000
1920

Rakefile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,46 @@ namespace :vendor do
164164
error_message: "Vendored gems are out of sync. Please update the vendored lib patches."
165165
)
166166
end
167+
168+
# Pinned upstream revision of rubygems/rubygems.org that the vendored
169+
# compact_index copy is generated from. Bump this (or pass COMPACT_INDEX_REF)
170+
# and re-run the task to refresh.
171+
COMPACT_INDEX_REF = "bdf05e24cd381402822387240f1697c0193ad171"
172+
COMPACT_INDEX_FILES = %w[
173+
lib/compact_index.rb
174+
lib/compact_index/dependency.rb
175+
lib/compact_index/gem.rb
176+
lib/compact_index/gem_version.rb
177+
lib/compact_index/versions_file.rb
178+
].freeze
179+
180+
desc "Vendor spec-suite compact_index from rubygems.org (COMPACT_INDEX_REF to override ref)"
181+
task :compact_index do
182+
require "open-uri"
183+
require "fileutils"
184+
185+
ref = ENV["COMPACT_INDEX_REF"] || COMPACT_INDEX_REF
186+
dest_root = File.expand_path("spec/support/vendor/compact_index", __dir__)
187+
188+
COMPACT_INDEX_FILES.each do |path|
189+
url = "https://raw.githubusercontent.com/rubygems/rubygems.org/#{ref}/#{path}"
190+
contents = URI.parse(url).open(&:read).gsub("CompactIndex", "VendoredCompactIndex")
191+
192+
target = File.join(dest_root, path)
193+
FileUtils.mkdir_p(File.dirname(target))
194+
File.write(target, contents)
195+
end
196+
197+
puts "Vendored compact_index from rubygems.org@#{ref} into #{dest_root}"
198+
end
199+
200+
desc "Check vendored compact_index is up to date"
201+
task compact_index_check: :compact_index do
202+
Spec::Rubygems.check_source_control_changes(
203+
success_message: "Vendored compact_index is in sync",
204+
error_message: "Vendored compact_index is out of sync. Run `rake vendor:compact_index`."
205+
)
206+
end
167207
end
168208

169209
namespace :rubocop do

spec/support/artifice/compact_index_concurrent_download.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class CompactIndexConcurrentDownload < CompactIndexAPI
2121
etag_response do
2222
file = tmp("versions.list")
2323
FileUtils.rm_f(file)
24-
file = CompactIndex::VersionsFile.new(file.to_s)
24+
file = VendoredCompactIndex::VersionsFile.new(file.to_s)
2525
file.create(gems)
2626
file.contents
2727
end

spec/support/artifice/compact_index_partial_update_bad_digest.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def partial_update_bad_digest
2121
partial_update_bad_digest do
2222
file = tmp("versions.list")
2323
FileUtils.rm_f(file)
24-
file = CompactIndex::VersionsFile.new(file.to_s)
24+
file = VendoredCompactIndex::VersionsFile.new(file.to_s)
2525
file.create(gems)
2626
file.contents([], calculate_info_checksums: true)
2727
end
@@ -30,7 +30,7 @@ def partial_update_bad_digest
3030
get "/info/:name" do
3131
partial_update_bad_digest do
3232
gem = gems.find {|g| g.name == params[:name] }
33-
CompactIndex.info(gem ? gem.versions : [])
33+
VendoredCompactIndex.info(gem ? gem.versions : [])
3434
end
3535
end
3636
end

spec/support/artifice/compact_index_partial_update_no_digest_not_incremental.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def partial_update_no_digest
1616
partial_update_no_digest do
1717
file = tmp("versions.list")
1818
FileUtils.rm_f(file)
19-
file = CompactIndex::VersionsFile.new(file.to_s)
19+
file = VendoredCompactIndex::VersionsFile.new(file.to_s)
2020
file.create(gems)
2121
lines = file.contents([], calculate_info_checksums: true).split("\n")
2222
name, versions, checksum = lines.last.split(" ")
@@ -29,7 +29,7 @@ def partial_update_no_digest
2929
get "/info/:name" do
3030
partial_update_no_digest do
3131
gem = gems.find {|g| g.name == params[:name] }
32-
lines = CompactIndex.info(gem ? gem.versions : []).split("\n")
32+
lines = VendoredCompactIndex.info(gem ? gem.versions : []).split("\n")
3333

3434
# shuffle versions so new versions are not appended to the end
3535
[lines.first, lines.last, *lines[1..-2]].join("\n")

spec/support/artifice/compact_index_precompiled_before.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class CompactIndexPrecompiledBefore < CompactIndexAPI
66
get "/info/:name" do
77
etag_response do
88
gem = gems.find {|g| g.name == params[:name] }
9-
move_ruby_variant_to_the_end(CompactIndex.info(gem ? gem.versions : []))
9+
move_ruby_variant_to_the_end(VendoredCompactIndex.info(gem ? gem.versions : []))
1010
end
1111
end
1212

spec/support/artifice/compact_index_range_ignored.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def not_modified?(_checksum)
2828
etag_response do
2929
file = tmp("versions.list")
3030
FileUtils.rm_f(file)
31-
file = CompactIndex::VersionsFile.new(file.to_s)
31+
file = VendoredCompactIndex::VersionsFile.new(file.to_s)
3232
file.create(gems)
3333
file.contents
3434
end

spec/support/artifice/compact_index_rate_limited.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def self.deq
3232
if RequestCounter.size == 1
3333
etag_response do
3434
gem = gems.find {|g| g.name == params[:name] }
35-
CompactIndex.info(gem ? gem.versions : [])
35+
VendoredCompactIndex.info(gem ? gem.versions : [])
3636
end
3737
else
3838
status 429

spec/support/artifice/compact_index_wrong_dependencies.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class CompactIndexWrongDependencies < CompactIndexAPI
77
etag_response do
88
gem = gems.find {|g| g.name == params[:name] }
99
gem.versions.each {|gv| gv.dependencies.clear } if gem
10-
CompactIndex.info(gem ? gem.versions : [])
10+
VendoredCompactIndex.info(gem ? gem.versions : [])
1111
end
1212
end
1313
end

spec/support/artifice/compact_index_wrong_gem_checksum.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class CompactIndexWrongGemChecksum < CompactIndexAPI
1111
checksum = ENV.fetch("BUNDLER_SPEC_#{name.upcase}_CHECKSUM") { "IiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiI=" }
1212
versions = gem ? gem.versions : []
1313
versions.each {|v| v.checksum = checksum }
14-
CompactIndex.info(versions)
14+
VendoredCompactIndex.info(versions)
1515
end
1616
end
1717
end

0 commit comments

Comments
 (0)