From 07337df09250e807b82265dc566b0ed1a45731a7 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Wed, 22 Jul 2026 15:09:34 +0900 Subject: [PATCH] Fail `bundle check` when frozen mode needs lockfile changes `BUNDLE_FROZEN=1 bundle check` reported that dependencies are satisfied and exited 0 even when the lockfile was missing CHECKSUMS entries, because `write_lock` only warns in frozen mode. Run the same frozen validation as `bundle install` so `bundle check` fails consistently. https://github.com/ruby/rubygems/issues/9546 Co-Authored-By: Claude Fable 5 --- lib/bundler/cli/check.rb | 4 +-- spec/commands/check_spec.rb | 52 +++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/lib/bundler/cli/check.rb b/lib/bundler/cli/check.rb index 493eb3ec6a5a..eb2c49ddd207 100644 --- a/lib/bundler/cli/check.rb +++ b/lib/bundler/cli/check.rb @@ -12,6 +12,7 @@ def run Bundler.settings.set_command_option_if_given :path, options[:path] definition = Bundler.definition + definition.ensure_equivalent_gemfile_and_lockfile definition.validate_runtime! begin @@ -28,9 +29,6 @@ def run not_installed.each {|s| Bundler.ui.error " * #{s.name} (#{s.version})" } Bundler.ui.warn "Install missing gems with `bundle install`" exit 1 - elsif !Bundler.default_lockfile.file? && Bundler.frozen_bundle? - Bundler.ui.error "This bundle has been frozen, but there is no #{SharedHelpers.relative_lockfile_path} present" - exit 1 else definition.lock(true) unless options[:"dry-run"] Bundler.ui.info "The Gemfile's dependencies are satisfied" diff --git a/spec/commands/check_spec.rb b/spec/commands/check_spec.rb index 7fe6897ae3b5..e168141d1d8c 100644 --- a/spec/commands/check_spec.rb +++ b/spec/commands/check_spec.rb @@ -257,6 +257,58 @@ bundle :check, raise_on_error: false expect(last_command).to be_failure + expect(err).to include("Frozen mode is set, but there's no lockfile") + end + + it "fails when frozen is set and the lockfile is missing a CHECKSUMS entry" do + system_gems "myrack-1.0.0", path: default_bundle_path + + gemfile <<-G + source "https://gem.repo1" + gem "myrack" + G + + lockfile <<-L + GEM + remote: https://gem.repo1/ + specs: + myrack (1.0.0) + + PLATFORMS + #{lockfile_platforms} + + DEPENDENCIES + myrack + + CHECKSUMS + + BUNDLED WITH + #{Bundler::VERSION} + L + + bundle :check, env: { "BUNDLE_FROZEN" => "true" }, raise_on_error: false + expect(exitstatus).to eq(16) + expect(err).to include("Your lockfile is missing a CHECKSUMS entry for \"myrack\", but can't be updated because frozen mode is set") + expect(out).not_to include("The Gemfile's dependencies are satisfied") + end + + it "fails when frozen is set and the Gemfile has changed" do + install_gemfile <<-G + source "https://gem.repo1" + gem "myrack" + G + + gemfile <<-G + source "https://gem.repo1" + gem "myrack" + gem "rails" + G + + bundle :check, env: { "BUNDLE_FROZEN" => "true" }, raise_on_error: false + expect(exitstatus).to eq(16) + expect(err).to include("frozen mode is set") + expect(err).to include("* rails") + expect(out).not_to include("The Gemfile's dependencies are satisfied") end describe "when locked" do