From d8536e115e5ade6128842e0c8356c6ca228ad48f Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Mon, 1 Jun 2026 10:20:56 +0900 Subject: [PATCH 1/2] Vendor compact_index during install_test_deps The earlier `rake vendor:compact_index` hook into `dev:deps` and the hard-copy step in ruby-core.yml fell apart in ruby/ruby's test-bundler runner, which sets TMPDIR per process and does not invoke our rake tasks. Pull the fetch logic into `Spec::Rubygems.install_vendored_compact_index` and call it from `install_test_deps` so every test setup path - local `bin/rspec`, `bin/parallel_rspec`, GHA bundler.yml, and ruby/ruby's test-bundler - lands the files at `Path.tmp_root.join("compact_index")` exactly where the artifice already looks. The standalone rake task and its workflow hop are no longer needed. Co-Authored-By: Claude Opus 4.7 --- Rakefile | 32 +------------------------------- spec/support/rubygems_ext.rb | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 31 deletions(-) diff --git a/Rakefile b/Rakefile index 820656c32b87..82b22ccf3a82 100644 --- a/Rakefile +++ b/Rakefile @@ -9,7 +9,7 @@ require "rake/testtask" require_relative "spec/support/rubygems_ext" desc "Setup Rubygems dev environment" -task setup: [:"dev:deps", "vendor:compact_index"] do +task setup: [:"dev:deps"] do Dir.glob("tool/bundler/*_gems.rb").each do |file| name = File.basename(file, ".rb") next if name == "dev_gems" @@ -17,36 +17,6 @@ task setup: [:"dev:deps", "vendor:compact_index"] do end end -namespace :vendor do - # Pinned to rubygems/rubygems.org#6504 so `rake setup` stays reproducible. - # Override with REF= to test against a newer compact_index. - desc "Sync vendored compact_index from rubygems/rubygems.org" - task :compact_index do - require "open-uri" - require "fileutils" - - ref = ENV["REF"] || "7c68a7b39761c61a66f9299f85b889ec39afc02c" - repo = "rubygems/rubygems.org" - paths = %w[ - lib/compact_index.rb - lib/compact_index/dependency.rb - lib/compact_index/gem.rb - lib/compact_index/gem_version.rb - lib/compact_index/versions_file.rb - ] - - target_root = Spec::Path.tmp_root.join("compact_index") - paths.each do |path| - url = "https://raw.githubusercontent.com/#{repo}/#{ref}/#{path}" - puts "Fetching #{url}" - content = URI.parse(url).open(&:read) - target = File.join(target_root, path) - FileUtils.mkdir_p(File.dirname(target)) - File.write(target, content) - end - end -end - desc "Update Rubygems dev environment" task :update do Spec::Rubygems.dev_bundle "update", "--all" diff --git a/spec/support/rubygems_ext.rb b/spec/support/rubygems_ext.rb index cf639a660a04..7d1ca550ba95 100644 --- a/spec/support/rubygems_ext.rb +++ b/spec/support/rubygems_ext.rb @@ -73,6 +73,33 @@ def install_test_deps require_relative "helpers" Helpers.install_dev_bundler + + install_vendored_compact_index + end + + # Vendor `rubygems/rubygems.org#lib/compact_index/` under `tmp/compact_index/` + # so the artifice can serve compact-index responses without a runtime gem + # dependency. Pinned to a reviewed commit; override with COMPACT_INDEX_REF. + def install_vendored_compact_index + target_root = Path.tmp_root.join("compact_index") + return if File.exist?(target_root.join("lib/compact_index.rb")) + + require "open-uri" + require "fileutils" + + ref = ENV["COMPACT_INDEX_REF"] || "7c68a7b39761c61a66f9299f85b889ec39afc02c" + %w[ + lib/compact_index.rb + lib/compact_index/dependency.rb + lib/compact_index/gem.rb + lib/compact_index/gem_version.rb + lib/compact_index/versions_file.rb + ].each do |path| + url = "https://raw.githubusercontent.com/rubygems/rubygems.org/#{ref}/#{path}" + target = target_root.join(path) + FileUtils.mkdir_p(File.dirname(target)) + File.write(target, URI.parse(url).open(&:read)) + end end def check_source_control_changes(success_message:, error_message:) From db5d06953f5269b803b5c1e3c1def116311a522d Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Mon, 1 Jun 2026 10:25:38 +0900 Subject: [PATCH 2/2] Refresh vendored compact_index when COMPACT_INDEX_REF is set Previously the install_vendored_compact_index short-circuit only checked whether `tmp/compact_index/lib/compact_index.rb` existed, so once any ref was vendored a subsequent `COMPACT_INDEX_REF= bin/rspec ...` kept serving the stale copy. Drop the vendor tree first when the env var is explicitly set so an override always re-fetches against the requested ref. Co-Authored-By: Claude Opus 4.7 --- spec/support/rubygems_ext.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/spec/support/rubygems_ext.rb b/spec/support/rubygems_ext.rb index 7d1ca550ba95..9ff0138f2ccd 100644 --- a/spec/support/rubygems_ext.rb +++ b/spec/support/rubygems_ext.rb @@ -79,14 +79,19 @@ def install_test_deps # Vendor `rubygems/rubygems.org#lib/compact_index/` under `tmp/compact_index/` # so the artifice can serve compact-index responses without a runtime gem - # dependency. Pinned to a reviewed commit; override with COMPACT_INDEX_REF. + # dependency. Pinned to a reviewed commit; override with COMPACT_INDEX_REF + # to refresh against another ref (the existing vendor copy is discarded). def install_vendored_compact_index target_root = Path.tmp_root.join("compact_index") - return if File.exist?(target_root.join("lib/compact_index.rb")) - - require "open-uri" require "fileutils" + if ENV["COMPACT_INDEX_REF"] + FileUtils.rm_rf(target_root) + elsif File.exist?(target_root.join("lib/compact_index.rb")) + return + end + + require "open-uri" ref = ENV["COMPACT_INDEX_REF"] || "7c68a7b39761c61a66f9299f85b889ec39afc02c" %w[ lib/compact_index.rb