diff --git a/lib/prebake/async_publisher.rb b/lib/prebake/async_publisher.rb index ee8d821..a3aa5ba 100644 --- a/lib/prebake/async_publisher.rb +++ b/lib/prebake/async_publisher.rb @@ -20,7 +20,7 @@ def self.enqueue(spec, backend) @mutex.synchronize { @pending_specs << [spec, backend] } end - def self.wait_for_completion(timeout: 120) + def self.publish_pending(timeout: 120) specs = @mutex.synchronize { @pending_specs.dup } return if specs.empty? diff --git a/lib/prebake/elf_inspector.rb b/lib/prebake/elf_inspector.rb index 10e32cd..936f5e2 100644 --- a/lib/prebake/elf_inspector.rb +++ b/lib/prebake/elf_inspector.rb @@ -51,19 +51,19 @@ def self.libruby_needed?(path) end def self.needed_libraries(path) - out, status = Open3.capture2e("objdump", "-p", path) + output, status = Open3.capture2e("objdump", "-p", path) return [] unless status.success? - out.scan(/NEEDED\s+(\S+)/).flatten + output.scan(/NEEDED\s+(\S+)/).flatten rescue Errno::ENOENT [] end def self.run_objdump(path) - out, status = Open3.capture2e("objdump", "-T", path) + output, status = Open3.capture2e("objdump", "-T", path) return nil unless status.success? - out + output rescue Errno::ENOENT nil end diff --git a/lib/prebake/ext_builder_patch.rb b/lib/prebake/ext_builder_patch.rb index a4f0e72..f1ec02c 100644 --- a/lib/prebake/ext_builder_patch.rb +++ b/lib/prebake/ext_builder_patch.rb @@ -27,7 +27,7 @@ def build_extensions if Prebake.optional_native_extension?(@spec.name) && !Prebake.libruby_available? Logger.warn "#{@spec.name}: native extension skipped (optional gem, libruby.so absent on static Ruby build)" - install_without_native_extension + mark_build_complete return end @@ -53,7 +53,7 @@ def build_extensions return super end - if verify_checksum(cache_key, expected_checksum, cached_gem) + if checksum_matches?(cache_key, expected_checksum, cached_gem) unless PortabilityGuard.portable_for_host?(cached_gem, spec_name: @spec.name) # Binary is valid for other hosts; don't delete from backend. return super @@ -85,11 +85,11 @@ def trigger_rebuild(cache_key) Logger.warn "No checksum available for #{cache_key}, removing cached gem" Prebake.backend.delete(cache_key) # GET triggers the worker to dispatch a rebuild via GH Actions on cache miss - trigger_path = Prebake.backend.fetch(cache_key) - FileUtils.rm_f(trigger_path) if trigger_path + leftover = Prebake.backend.fetch(cache_key) + FileUtils.rm_f(leftover) if leftover end - def verify_checksum(cache_key, expected, gem_path) + def checksum_matches?(cache_key, expected, gem_path) return true if expected.nil? actual = Digest::SHA256.file(gem_path).hexdigest @@ -101,10 +101,6 @@ def verify_checksum(cache_key, expected, gem_path) end end - def install_without_native_extension - mark_build_complete - end - def install_from_cache(gem_path) count = Extractor.install(gem_path, @spec) diff --git a/lib/prebake/extension_validator.rb b/lib/prebake/extension_layout.rb similarity index 78% rename from lib/prebake/extension_validator.rb rename to lib/prebake/extension_layout.rb index a278553..e55e017 100644 --- a/lib/prebake/extension_validator.rb +++ b/lib/prebake/extension_layout.rb @@ -4,14 +4,14 @@ require_relative "logger" module Prebake - module ExtensionValidator + module ExtensionLayout BINARY_GLOB = "*.{so,bundle,dll}" - def self.validate_all - Bundler.definition.specs.each { |spec| validate(spec) } + def self.repair_all + Bundler.definition.specs.each { |spec| repair(spec) } end - def self.validate(spec) + def self.repair(spec) ext_dir = spec.extension_dir return unless File.exist?(File.join(ext_dir, ".prebake")) @@ -30,7 +30,7 @@ def self.validate(spec) next if File.exist?(dest) FileUtils.cp(binary, dest) - Logger.info "Validator: copied #{File.basename(binary)} to #{ext_dir}" + Logger.info "Restored #{File.basename(binary)} to #{ext_dir}" end end end diff --git a/lib/prebake/extractor.rb b/lib/prebake/extractor.rb index 4e553f2..3c29019 100644 --- a/lib/prebake/extractor.rb +++ b/lib/prebake/extractor.rb @@ -27,7 +27,7 @@ def self.install(gem_path, spec) end end - # Mark this extension_dir as prebake-managed for post-install validation + # Mark this extension_dir as prebake-managed for post-install layout repair FileUtils.touch(File.join(spec.extension_dir, ".prebake")) if extracted_count.positive? Logger.info "Installed precompiled #{File.basename(gem_path)} " \ diff --git a/lib/prebake/glibc.rb b/lib/prebake/glibc.rb index b74f7d9..d9d54e3 100644 --- a/lib/prebake/glibc.rb +++ b/lib/prebake/glibc.rb @@ -37,10 +37,10 @@ def self.reset! end def self.run_ldd - out, status = Open3.capture2e("ldd", "--version") + output, status = Open3.capture2e("ldd", "--version") return nil unless status.success? - out + output rescue Errno::ENOENT nil end diff --git a/lib/prebake/hooks.rb b/lib/prebake/hooks.rb index 9c32042..bedac63 100644 --- a/lib/prebake/hooks.rb +++ b/lib/prebake/hooks.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require_relative "async_publisher" -require_relative "extension_validator" +require_relative "extension_layout" require_relative "logger" module Prebake @@ -22,11 +22,11 @@ def self.register! end Bundler::Plugin::API.hook("after-install-all") do |_deps| - ExtensionValidator.validate_all + ExtensionLayout.repair_all next unless Prebake.push_enabled? - AsyncPublisher.wait_for_completion + AsyncPublisher.publish_pending end Logger.debug "Hooks registered" diff --git a/lib/prebake/platform.rb b/lib/prebake/platform.rb index 133cb86..32f1435 100644 --- a/lib/prebake/platform.rb +++ b/lib/prebake/platform.rb @@ -9,12 +9,12 @@ module Platform [/\Aaarch64-linux(-gnu)?\z/, "aarch64-linux"] ].freeze - def self.normalize(platform_string) + def self.normalize(platform) NORMALIZATIONS.each do |pattern, normalized| - return normalized if platform_string.match?(pattern) + return normalized if platform.match?(pattern) end - platform_string + platform end def self.generalized diff --git a/lib/prebake/static_ruby.rb b/lib/prebake/static_ruby.rb index f2ffd18..71797d7 100644 --- a/lib/prebake/static_ruby.rb +++ b/lib/prebake/static_ruby.rb @@ -10,14 +10,14 @@ module StaticRuby # instead of installing a broken .so. Extend via PREBAKE_OPTIONAL_NATIVE_EXTENSIONS=gem1,gem2. # Intentionally empty: bootsnap 1.18+ requires its native extension unconditionally; # skipping the build produces a broken install. - OPTIONAL_NATIVE_EXTENSIONS_DEFAULT = %w[].freeze + DEFAULT_OPTIONAL_NATIVE_EXTENSIONS = %w[].freeze class << self def optional_native_extensions @optional_native_extensions ||= begin extra = ENV.fetch("PREBAKE_OPTIONAL_NATIVE_EXTENSIONS", "") .split(",").map(&:strip).reject(&:empty?) - (OPTIONAL_NATIVE_EXTENSIONS_DEFAULT + extra).uniq + (DEFAULT_OPTIONAL_NATIVE_EXTENSIONS + extra).uniq end end diff --git a/test/async_publisher_test.rb b/test/async_publisher_test.rb index 3cb7b4a..7d16fd8 100644 --- a/test/async_publisher_test.rb +++ b/test/async_publisher_test.rb @@ -15,7 +15,7 @@ def teardown FileUtils.rm_rf(@tmpdir) end - def mock_spec(name, version, build_args: []) + def build_spec(name, version, build_args: []) stub(name:, version: Gem::Version.new(version), build_args:) end @@ -25,8 +25,8 @@ def temp_gem_path(name = "fake") path end - def test_enqueue_and_wait_pushes_gem - spec = mock_spec("testgem", "1.0.0") + def test_enqueue_and_publish_pushes_gem + spec = build_spec("testgem", "1.0.0") gem_path = temp_gem_path pushed = [] backend = stub(exists?: false, push: -> { pushed << true }) @@ -36,26 +36,26 @@ def test_enqueue_and_wait_pushes_gem Prebake::PlatformGemBuilder.stubs(:new).with(spec).returns(builder) Prebake::AsyncPublisher.enqueue(spec, backend) - Prebake::AsyncPublisher.wait_for_completion(timeout: 5) + Prebake::AsyncPublisher.publish_pending(timeout: 5) end - def test_wait_with_no_enqueues_does_nothing - Prebake::AsyncPublisher.wait_for_completion(timeout: 1) + def test_publish_with_no_enqueues_does_nothing + Prebake::AsyncPublisher.publish_pending(timeout: 1) end def test_errors_in_build_are_rescued - spec = mock_spec("badgem", "0.1.0") + spec = build_spec("badgem", "0.1.0") backend = stub backend.stubs(:exists?).raises(StandardError, "boom") Prebake::Logger.stubs(:warn) Prebake::AsyncPublisher.enqueue(spec, backend) - Prebake::AsyncPublisher.wait_for_completion(timeout: 5) + Prebake::AsyncPublisher.publish_pending(timeout: 5) end def test_skips_push_when_built_gem_exceeds_max_glibc ENV["PREBAKE_MAX_GLIBC"] = "2.28" - spec = mock_spec("testgem", "1.0.0") + spec = build_spec("testgem", "1.0.0") gem_path = temp_gem_path backend = stub(exists?: false) backend.expects(:push).never @@ -65,14 +65,14 @@ def test_skips_push_when_built_gem_exceeds_max_glibc Prebake::ElfInspector.stubs(:required_glibc_for_gem).with(gem_path).returns("2.35") Prebake::AsyncPublisher.enqueue(spec, backend) - Prebake::AsyncPublisher.wait_for_completion(timeout: 5) + Prebake::AsyncPublisher.publish_pending(timeout: 5) ensure ENV.delete("PREBAKE_MAX_GLIBC") end def test_pushes_when_built_gem_within_max_glibc ENV["PREBAKE_MAX_GLIBC"] = "2.35" - spec = mock_spec("testgem", "1.0.0") + spec = build_spec("testgem", "1.0.0") gem_path = temp_gem_path backend = stub(exists?: false) backend.expects(:push).with(gem_path, anything, "sha") @@ -82,13 +82,13 @@ def test_pushes_when_built_gem_within_max_glibc Prebake::ElfInspector.stubs(:required_glibc_for_gem).with(gem_path).returns("2.28") Prebake::AsyncPublisher.enqueue(spec, backend) - Prebake::AsyncPublisher.wait_for_completion(timeout: 5) + Prebake::AsyncPublisher.publish_pending(timeout: 5) ensure ENV.delete("PREBAKE_MAX_GLIBC") end def test_pushes_without_check_when_max_glibc_unset - spec = mock_spec("testgem", "1.0.0") + spec = build_spec("testgem", "1.0.0") gem_path = temp_gem_path backend = stub(exists?: false) backend.expects(:push).with(gem_path, anything, "sha") @@ -98,11 +98,11 @@ def test_pushes_without_check_when_max_glibc_unset Prebake::ElfInspector.expects(:required_glibc_for_gem).never Prebake::AsyncPublisher.enqueue(spec, backend) - Prebake::AsyncPublisher.wait_for_completion(timeout: 5) + Prebake::AsyncPublisher.publish_pending(timeout: 5) end def test_skips_push_when_gem_was_compiled_with_build_options - spec = mock_spec("pg", "1.5.4", build_args: ["--with-pg-config=/opt/pg/bin/pg_config"]) + spec = build_spec("pg", "1.5.4", build_args: ["--with-pg-config=/opt/pg/bin/pg_config"]) backend = stub(exists?: false) backend.expects(:push).never @@ -110,11 +110,11 @@ def test_skips_push_when_gem_was_compiled_with_build_options Prebake::PlatformGemBuilder.stubs(:new).with(spec).returns(builder) Prebake::AsyncPublisher.enqueue(spec, backend) - Prebake::AsyncPublisher.wait_for_completion(timeout: 5) + Prebake::AsyncPublisher.publish_pending(timeout: 5) end def test_skips_push_when_built_gem_needs_libruby_on_static_ruby - spec = mock_spec("bootsnap", "1.23.0") + spec = build_spec("bootsnap", "1.23.0") gem_path = temp_gem_path backend = stub(exists?: false) backend.expects(:push).never @@ -125,13 +125,13 @@ def test_skips_push_when_built_gem_needs_libruby_on_static_ruby Prebake::ElfInspector.stubs(:libruby_needed_for_gem?).with(gem_path).returns(true) Prebake::AsyncPublisher.enqueue(spec, backend) - Prebake::AsyncPublisher.wait_for_completion(timeout: 5) + Prebake::AsyncPublisher.publish_pending(timeout: 5) refute File.exist?(gem_path), "broken gem file should be cleaned up" end def test_pushes_when_libruby_needed_but_available - spec = mock_spec("bootsnap", "1.23.0") + spec = build_spec("bootsnap", "1.23.0") gem_path = temp_gem_path backend = stub(exists?: false) backend.expects(:push).with(gem_path, anything, "sha") @@ -142,13 +142,13 @@ def test_pushes_when_libruby_needed_but_available Prebake::ElfInspector.expects(:libruby_needed_for_gem?).never Prebake::AsyncPublisher.enqueue(spec, backend) - Prebake::AsyncPublisher.wait_for_completion(timeout: 5) + Prebake::AsyncPublisher.publish_pending(timeout: 5) end def test_multiple_enqueues_all_processed pushed = [] 3.times do |i| - spec = mock_spec("gem#{i}", "1.0.#{i}") + spec = build_spec("gem#{i}", "1.0.#{i}") gem_path = temp_gem_path("gem#{i}") backend = stub(exists?: false) backend.stubs(:push).with { pushed << i } @@ -159,7 +159,7 @@ def test_multiple_enqueues_all_processed Prebake::AsyncPublisher.enqueue(spec, backend) end - Prebake::AsyncPublisher.wait_for_completion(timeout: 10) + Prebake::AsyncPublisher.publish_pending(timeout: 10) assert_equal 3, pushed.size end end diff --git a/test/ext_builder_patch_test.rb b/test/ext_builder_patch_test.rb index f364064..8a8f89e 100644 --- a/test/ext_builder_patch_test.rb +++ b/test/ext_builder_patch_test.rb @@ -24,7 +24,7 @@ def teardown Prebake.reset! end - def make_spec(**overrides) + def build_spec(**overrides) spec = mock("spec") { extensions: ["ext/test/extconf.rb"], name: "testgem", version: Gem::Version.new(overrides.delete(:version) || "1.0.0"), @@ -43,7 +43,7 @@ def fake_gem_path def build(spec) = Gem::Ext::Builder.new(spec, "").build_extensions def stub_verified_cache_hit - spec = make_spec + spec = build_spec gem_path = fake_gem_path checksum = Digest::SHA256.file(gem_path).hexdigest backend = mock("backend") @@ -61,7 +61,7 @@ def test_skips_compilation_when_cache_hit_with_valid_checksum end def test_deletes_and_triggers_rebuild_when_no_checksum_available - spec = make_spec + spec = build_spec backend = mock("backend") backend.expects(:fetch_checksum).with(cache_key).returns(nil) backend.expects(:checksums_supported?).returns(true) @@ -73,7 +73,7 @@ def test_deletes_and_triggers_rebuild_when_no_checksum_available end def test_accepts_gem_without_checksum_when_backend_does_not_support_checksums - spec = make_spec + spec = build_spec gem_path = fake_gem_path backend = mock("backend") backend.expects(:fetch_checksum).with(cache_key).returns(nil) @@ -87,7 +87,7 @@ def test_accepts_gem_without_checksum_when_backend_does_not_support_checksums end def test_falls_through_on_cache_miss - spec = make_spec + spec = build_spec backend = mock("backend") backend.stubs(:fetch_checksum).with(cache_key).returns("somechecksum") backend.expects(:fetch).with(cache_key).returns(nil) @@ -96,7 +96,7 @@ def test_falls_through_on_cache_miss end def test_skips_gems_without_extensions - spec = make_spec(extensions: []) + spec = build_spec(extensions: []) backend = mock("backend") backend.expects(:fetch).never Prebake.backend = backend @@ -104,7 +104,7 @@ def test_skips_gems_without_extensions end def test_builds_from_source_when_build_args_are_set - spec = make_spec + spec = build_spec gem_path = fake_gem_path backend = mock("backend") backend.stubs(:fetch_checksum).with(cache_key).returns(Digest::SHA256.file(gem_path).hexdigest) @@ -126,7 +126,7 @@ def test_deletes_cache_and_falls_back_when_no_binaries_in_cached_gem end def test_falls_through_when_backend_nil - spec = make_spec + spec = build_spec Prebake.backend = nil assert_raises(Gem::Ext::BuildError) { build(spec) } end @@ -190,7 +190,7 @@ def test_skips_portability_check_on_non_linux # optional native extension + static Ruby def test_skips_native_extension_for_optional_gem_on_static_ruby - spec = make_spec(name: "bootsnap") + spec = build_spec(name: "bootsnap") Prebake.stubs(:optional_native_extension?).with("bootsnap").returns(true) Prebake.stubs(:libruby_available?).returns(false) Prebake.backend = mock("backend") @@ -214,7 +214,7 @@ def test_does_not_skip_optional_gem_when_libruby_available def test_optional_gem_skip_respects_env_var ENV["PREBAKE_OPTIONAL_NATIVE_EXTENSIONS"] = "myoptionalgem" - spec = make_spec(name: "myoptionalgem") + spec = build_spec(name: "myoptionalgem") Prebake.stubs(:libruby_available?).returns(false) Prebake.backend = mock("backend") Prebake.backend.expects(:fetch).never @@ -229,7 +229,7 @@ def test_bootsnap_not_skipped_on_static_ruby_without_explicit_opt_in # bootsnap 1.18+ requires its native extension unconditionally; skipping # the build produces a broken install. Ensure it goes through the normal # cache/source-build path even on static Ruby. - spec = make_spec(name: "bootsnap") + spec = build_spec(name: "bootsnap") Prebake.stubs(:libruby_available?).returns(false) key = Prebake::CacheKey.for("bootsnap", "1.0.0", Prebake::Platform.generalized) backend = mock("backend") diff --git a/test/extension_validator_test.rb b/test/extension_layout_test.rb similarity index 90% rename from test/extension_validator_test.rb rename to test/extension_layout_test.rb index fa82b95..28defed 100644 --- a/test/extension_validator_test.rb +++ b/test/extension_layout_test.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true require "test_helper" -require "prebake/extension_validator" +require "prebake/extension_layout" require "fileutils" -class ExtensionValidatorTest < Minitest::Test +class ExtensionLayoutTest < Minitest::Test def setup @tmpdir = Dir.mktmpdir @extension_dir = File.join(@tmpdir, "extensions", "testgem-1.0.0") @@ -24,7 +24,7 @@ def test_skips_without_marker spec = mock("spec") spec.stubs(:extension_dir).returns(@extension_dir) - Prebake::ExtensionValidator.validate(spec) + Prebake::ExtensionLayout.repair(spec) refute File.exist?(File.join(@extension_dir, "foo.so")), "Should not copy binaries when .prebake marker is absent" @@ -42,7 +42,7 @@ def test_skips_correct_layout spec = mock("spec") spec.stubs(:extension_dir).returns(@extension_dir) - Prebake::ExtensionValidator.validate(spec) + Prebake::ExtensionLayout.repair(spec) refute File.exist?(File.join(@extension_dir, "bar.so")), "Should not copy nested binaries when root-level binaries already exist" @@ -58,7 +58,7 @@ def test_fixes_extension_pattern spec = mock("spec") spec.stubs(:extension_dir).returns(@extension_dir) - Prebake::ExtensionValidator.validate(spec) + Prebake::ExtensionLayout.repair(spec) dest = File.join(@extension_dir, "foo.so") assert File.exist?(dest), "Expected foo.so to be copied to extension_dir root" @@ -75,7 +75,7 @@ def test_fixes_lib_pattern spec = mock("spec") spec.stubs(:extension_dir).returns(@extension_dir) - Prebake::ExtensionValidator.validate(spec) + Prebake::ExtensionLayout.repair(spec) dest = File.join(@extension_dir, "bar.so") assert File.exist?(dest), "Expected bar.so to be copied to extension_dir root" @@ -93,7 +93,7 @@ def test_preserves_nested_lib_subdirectory spec = mock("spec") spec.stubs(:extension_dir).returns(@extension_dir) - Prebake::ExtensionValidator.validate(spec) + Prebake::ExtensionLayout.repair(spec) refute File.exist?(File.join(@extension_dir, "foo.so")), "Should not copy binaries from lib// (only direct children of lib/)" @@ -112,7 +112,7 @@ def test_skips_symlinks spec = mock("spec") spec.stubs(:extension_dir).returns(@extension_dir) - Prebake::ExtensionValidator.validate(spec) + Prebake::ExtensionLayout.repair(spec) refute File.exist?(File.join(@extension_dir, "linked.so")), "Should not copy symlinked binaries" @@ -128,7 +128,7 @@ def test_skips_empty_files spec = mock("spec") spec.stubs(:extension_dir).returns(@extension_dir) - Prebake::ExtensionValidator.validate(spec) + Prebake::ExtensionLayout.repair(spec) refute File.exist?(File.join(@extension_dir, "empty.so")), "Should not copy zero-byte binaries" @@ -144,8 +144,8 @@ def test_idempotent spec = mock("spec") spec.stubs(:extension_dir).returns(@extension_dir) - Prebake::ExtensionValidator.validate(spec) - Prebake::ExtensionValidator.validate(spec) + Prebake::ExtensionLayout.repair(spec) + Prebake::ExtensionLayout.repair(spec) dest = File.join(@extension_dir, "foo.so") assert File.exist?(dest), "Expected foo.so to exist after two runs" diff --git a/test/platform_gem_builder_test.rb b/test/platform_gem_builder_test.rb index 27c52b5..c3ef00f 100644 --- a/test/platform_gem_builder_test.rb +++ b/test/platform_gem_builder_test.rb @@ -15,7 +15,7 @@ def teardown end def test_builds_platform_gem_with_compiled_binaries - spec = create_installed_gem_with_extension + spec = build_installed_gem builder = Prebake::PlatformGemBuilder.new(spec) gem_path = builder.build @@ -33,7 +33,7 @@ def test_builds_platform_gem_with_compiled_binaries end def test_includes_so_files_in_platform_gem - spec = create_installed_gem_with_extension + spec = build_installed_gem builder = Prebake::PlatformGemBuilder.new(spec) gem_path = builder.build @@ -47,7 +47,7 @@ def test_includes_so_files_in_platform_gem end def test_computes_sha256_checksum - spec = create_installed_gem_with_extension + spec = build_installed_gem builder = Prebake::PlatformGemBuilder.new(spec) gem_path = builder.build @@ -61,7 +61,7 @@ def test_computes_sha256_checksum def test_build_does_not_change_callers_working_directory original_dir = Dir.pwd - spec = create_installed_gem_with_extension + spec = build_installed_gem builder = Prebake::PlatformGemBuilder.new(spec) gem_path = builder.build @@ -73,7 +73,7 @@ def test_build_does_not_change_callers_working_directory end def test_collects_extension_platform_abi_binaries_normalized_to_root - spec = create_installed_gem_with_extension + spec = build_installed_gem # Remove root-level binary, simulate Ruby 4.0 layout where make install # places the .so under extension/// inside extension_dir @@ -95,7 +95,7 @@ def test_collects_extension_platform_abi_binaries_normalized_to_root end def test_prefers_root_level_binary_over_nested_extension_path - spec = create_installed_gem_with_extension + spec = build_installed_gem # Both root-level and nested binaries exist — root should win ext = RUBY_PLATFORM.include?("darwin") ? "bundle" : "so" @@ -116,7 +116,7 @@ def test_prefers_root_level_binary_over_nested_extension_path private - def create_installed_gem_with_extension + def build_installed_gem gem_dir = File.join(@tmpdir, "testgem-1.0.0") extension_dir = File.join(@tmpdir, "extensions", "testgem-1.0.0") FileUtils.mkdir_p(File.join(gem_dir, "lib/testgem")) diff --git a/worker/src/build-trigger.js b/worker/src/build-trigger.js index 79075f4..9077c51 100644 --- a/worker/src/build-trigger.js +++ b/worker/src/build-trigger.js @@ -76,9 +76,9 @@ export async function triggerBuild(cacheKey, env, clientIp) { ]); if (existingPending) { - const meta = existingPending.customMetadata; - if (meta && meta.triggered_at) { - const age = Date.now() - new Date(meta.triggered_at).getTime(); + const metadata = existingPending.customMetadata; + if (metadata && metadata.triggered_at) { + const age = Date.now() - new Date(metadata.triggered_at).getTime(); if (age < 3600000) { console.log( `Build pending for ${cacheKey} (${Math.round(age / 1000)}s ago)`, @@ -88,8 +88,8 @@ export async function triggerBuild(cacheKey, env, clientIp) { } } - const valid = await validateGemVersion(gemResponse, parsed); - if (!valid) { + const isValid = await validateGemVersion(gemResponse, parsed); + if (!isValid) { if (existingPending) await env.R2_BUCKET.delete(pendingKey); return; }