From 1912c3a0b8b5af2dd374872be86978f5c89f3005 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Tue, 25 Aug 2026 23:23:27 -0400 Subject: [PATCH] Fix Bootsnap version hash override Use the same instance variable in the getter and writer so explicit version hash assignments remain effective after the first read. Add regression coverage. --- lib/require-hooks/mode/bootsnap.rb | 2 +- spec/require-hooks/bootsnap_spec.rb | 9 +++++++++ .../fixtures/bootsnap-version-hash.rb | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 spec/require-hooks/fixtures/bootsnap-version-hash.rb diff --git a/lib/require-hooks/mode/bootsnap.rb b/lib/require-hooks/mode/bootsnap.rb index fca7f4a..57359b4 100644 --- a/lib/require-hooks/mode/bootsnap.rb +++ b/lib/require-hooks/mode/bootsnap.rb @@ -93,7 +93,7 @@ def load_iseq(path) class << self def version_hash - @version_key ||= RequireHooks.contexts.values.map(&:to_cache_key).join("-") + @version_hash ||= RequireHooks.contexts.values.map(&:to_cache_key).join("-") end attr_writer :version_hash diff --git a/spec/require-hooks/bootsnap_spec.rb b/spec/require-hooks/bootsnap_spec.rb index b2845fb..c1fe94b 100644 --- a/spec/require-hooks/bootsnap_spec.rb +++ b/spec/require-hooks/bootsnap_spec.rb @@ -36,6 +36,15 @@ end end + it "allows overriding a previously read version hash" do + run_ruby( + File.join(__dir__, "fixtures", "bootsnap-version-hash.rb").to_s, + env: {"REQUIRE_HOOKS_MODE" => "bootsnap"} + ) do |_status, output, _err| + output.should include("custom\n") + end + end + it "re-raises syntax errors" do run_ruby( File.join(__dir__, "fixtures", "bootsnap-syntax-error.rb").to_s, diff --git a/spec/require-hooks/fixtures/bootsnap-version-hash.rb b/spec/require-hooks/fixtures/bootsnap-version-hash.rb new file mode 100644 index 0000000..501e310 --- /dev/null +++ b/spec/require-hooks/fixtures/bootsnap-version-hash.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +require "bootsnap" +Bootsnap.setup( + cache_dir: File.join(__dir__, "tmp/cache"), + development_mode: true, + compile_cache_iseq: true +) + +require "require-hooks/setup" + +RequireHooks::Bootsnap.version_hash +RequireHooks::Bootsnap.version_hash = "custom" +puts RequireHooks::Bootsnap.version_hash