Skip to content

Commit 07337df

Browse files
hsbtclaude
andcommitted
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. #9546 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent e920104 commit 07337df

2 files changed

Lines changed: 53 additions & 3 deletions

File tree

lib/bundler/cli/check.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def run
1212
Bundler.settings.set_command_option_if_given :path, options[:path]
1313

1414
definition = Bundler.definition
15+
definition.ensure_equivalent_gemfile_and_lockfile
1516
definition.validate_runtime!
1617

1718
begin
@@ -28,9 +29,6 @@ def run
2829
not_installed.each {|s| Bundler.ui.error " * #{s.name} (#{s.version})" }
2930
Bundler.ui.warn "Install missing gems with `bundle install`"
3031
exit 1
31-
elsif !Bundler.default_lockfile.file? && Bundler.frozen_bundle?
32-
Bundler.ui.error "This bundle has been frozen, but there is no #{SharedHelpers.relative_lockfile_path} present"
33-
exit 1
3432
else
3533
definition.lock(true) unless options[:"dry-run"]
3634
Bundler.ui.info "The Gemfile's dependencies are satisfied"

spec/commands/check_spec.rb

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,58 @@
257257

258258
bundle :check, raise_on_error: false
259259
expect(last_command).to be_failure
260+
expect(err).to include("Frozen mode is set, but there's no lockfile")
261+
end
262+
263+
it "fails when frozen is set and the lockfile is missing a CHECKSUMS entry" do
264+
system_gems "myrack-1.0.0", path: default_bundle_path
265+
266+
gemfile <<-G
267+
source "https://gem.repo1"
268+
gem "myrack"
269+
G
270+
271+
lockfile <<-L
272+
GEM
273+
remote: https://gem.repo1/
274+
specs:
275+
myrack (1.0.0)
276+
277+
PLATFORMS
278+
#{lockfile_platforms}
279+
280+
DEPENDENCIES
281+
myrack
282+
283+
CHECKSUMS
284+
285+
BUNDLED WITH
286+
#{Bundler::VERSION}
287+
L
288+
289+
bundle :check, env: { "BUNDLE_FROZEN" => "true" }, raise_on_error: false
290+
expect(exitstatus).to eq(16)
291+
expect(err).to include("Your lockfile is missing a CHECKSUMS entry for \"myrack\", but can't be updated because frozen mode is set")
292+
expect(out).not_to include("The Gemfile's dependencies are satisfied")
293+
end
294+
295+
it "fails when frozen is set and the Gemfile has changed" do
296+
install_gemfile <<-G
297+
source "https://gem.repo1"
298+
gem "myrack"
299+
G
300+
301+
gemfile <<-G
302+
source "https://gem.repo1"
303+
gem "myrack"
304+
gem "rails"
305+
G
306+
307+
bundle :check, env: { "BUNDLE_FROZEN" => "true" }, raise_on_error: false
308+
expect(exitstatus).to eq(16)
309+
expect(err).to include("frozen mode is set")
310+
expect(err).to include("* rails")
311+
expect(out).not_to include("The Gemfile's dependencies are satisfied")
260312
end
261313

262314
describe "when locked" do

0 commit comments

Comments
 (0)