`bundle lock --add-checksums` writes blank `CHECKSUMS` entries on the first run when a source's gems are only in optional or excluded groups

オープン
#10,083 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
1〜2日
初心者へのやさしさ
55/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
ruby
領域
build-system

調査の方向性

Start with Definition#add_checksums, LockfileGenerator#add_checksums, and the specs.each materialization path described in the report. Trace how optional and excluded groups affect checksum fetching and fallback calculation, then compare that with the specs written from definition.resolve. Done means the first bundle lock --add-checksums run writes populated checksums for every locked gem, including the reported optional and excluded group cases.

索引モデルが issue の本文から書いたものです。

説明

Describe the problem as clearly as you can

When migrating an existing Gemfile.lock without a CHECKSUMS section via bundle lock --add-checksums, Bundler writes blank checksum lines (for example rack (3.1.12)) for any gem source whose gems are all in an unrequested optional: true group or a BUNDLE_WITHOUT-excluded group (such as a scoped source inside an optional group, or a zero-runtime-dependency gemspec project with BUNDLE_WITHOUT=development). A subsequent BUNDLE_FROZEN=true install that includes the group fails with exit code 16 (Your lockfile has an empty CHECKSUMS entry). Running bundle lock --add-checksums a second time populates the sha256=... digest.

When no re-resolution is needed, Definition#add_checksums calls specs.each (materialize(requested_dependencies)), which skips unrequested optional: true and without groups (both for triggering Source::Rubygems compact-index fetches and for computing fallback checksums from installed .gem packages on disk), whereas LockfileGenerator#add_checksums emits CHECKSUMS entries for every spec in definition.resolve. On the second run, check_lockfile sees the blank entry in CHECKSUMS, sets @locked_spec_with_empty_checksums, and forces a remote re-resolution.

Did you try upgrading rubygems & bundler?

Yes. Reproduced on RubyGems / Bundler 4.1.0 (Ruby 4.0.9) and on ruby/rubygems master (5879ffe34b, 4.2.0.dev).

Post steps to reproduce the problem
mkdir /tmp/repro-opt-checksum && cd /tmp/repro-opt-checksum

cat > Gemfile << 'EOF'
source "https://rubygems.org"

group :opt, optional: true do
  gem "rack", "3.1.12"
end
EOF

BUNDLE_LOCKFILE_CHECKSUMS=false bundle lock
bundle lock --add-checksums
cat Gemfile.lock
BUNDLE_FROZEN=true BUNDLE_WITH=opt BUNDLE_PATH=vendor/bundle bundle install
bundle lock --add-checksums
cat Gemfile.lock
Which command did you run?

bundle lock --add-checksums

What were you expecting to happen?

The first bundle lock --add-checksums run should populate sha256=... checksums for all locked gems in Gemfile.lock (https://bundler.io/man/bundle-lock.1.html), matching the second run, so BUNDLE_FROZEN=true BUNDLE_WITH=opt bundle install succeeds.

What happened instead?
$ BUNDLE_LOCKFILE_CHECKSUMS=false bundle lock
Writing lockfile to /tmp/repro-opt-checksum/Gemfile.lock
Fetching gem metadata from https://rubygems.org/..
Resolving dependencies...
$ bundle lock --add-checksums
Writing lockfile to /tmp/repro-opt-checksum/Gemfile.lock
$ cat Gemfile.lock
GEM
  remote: https://rubygems.org/
  specs:
    rack (3.1.12)

PLATFORMS
  ruby
  x86_64-linux

DEPENDENCIES
  rack (= 3.1.12)

CHECKSUMS
  rack (3.1.12)

BUNDLED WITH
  4.1.0
$ BUNDLE_FROZEN=true BUNDLE_WITH=opt BUNDLE_PATH=vendor/bundle bundle install
Your lockfile has an empty CHECKSUMS entry for "rack", but can't be updated
because frozen mode is set

Run `bundle install` elsewhere and add the updated Gemfile.lock to version
control.
$ bundle lock --add-checksums
Fetching gem metadata from https://rubygems.org/..
Resolving dependencies...
Writing lockfile to /tmp/repro-opt-checksum/Gemfile.lock
$ cat Gemfile.lock
GEM
  remote: https://rubygems.org/
  specs:
    rack (3.1.12)

PLATFORMS
  ruby
  x86_64-linux

DEPENDENCIES
  rack (= 3.1.12)

CHECKSUMS
  rack (3.1.12) sha256=00d83055c89273eb13679ab562767b8826955aa6c4371d7d161deb975c50c540

BUNDLED WITH
  4.1.0
If not included with the output of your command, run bundle env and paste the output below
## Environment

```
Bundler       4.1.0
  Platforms   ruby, x86_64-linux
Ruby          4.0.9p0 (2026-10-23 revision 3e93b23afcec3433f6aecc34b5d832799d754238) [x86_64-linux]
  Full Path   /opt/ruby-4.0.9/bin/ruby
  Config Dir  /opt/ruby-4.0.9/etc
RubyGems      4.1.0
  Gem Home    /opt/ruby-4.0.9/lib/ruby/gems/4.0.0
  Gem Path    /tmp/repro-opt-home/.local/share/gem/ruby/4.0.0:/opt/ruby-4.0.9/lib/ruby/gems/4.0.0
  User Home   /tmp/repro-opt-home
  User Path   /tmp/repro-opt-home/.local/share/gem/ruby/4.0.0
  Bin Dir     /opt/ruby-4.0.9/bin
Git           2.39.5
```

## Bundler Build Metadata

```
Timestamp  2026-11-16
Git SHA    9af9267
```

## Gemfile

### Gemfile

```ruby
source "https://rubygems.org"

group :opt, optional: true do
  gem "rack", "3.1.12"
end
```

### Gemfile.lock

```
GEM
  remote: https://rubygems.org/
  specs:
    rack (3.1.12)

PLATFORMS
  ruby
  x86_64-linux

DEPENDENCIES
  rack (= 3.1.12)

CHECKSUMS
  rack (3.1.12)

BUNDLED WITH
  4.1.0
```

Credit: https://ucsbplse.github.io/

主要言語
Ruby
スター
4k
フォーク
2k
平均マージ
1日 20時間
マージ済み PR(30日)
75

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

ruby/rubygems のほかの issue

ruby/rubygems の issue をすべて見る

似ている issue

Ruby の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。