Skip to content

Backport [Bug #21723]#15881

Merged
k0kubun merged 6 commits intoruby:ruby_4_0from
hsbt:backport-21723
Jan 20, 2026
Merged

Backport [Bug #21723]#15881
k0kubun merged 6 commits intoruby:ruby_4_0from
hsbt:backport-21723

Conversation

@hsbt
Copy link
Copy Markdown
Member

@hsbt hsbt commented Jan 16, 2026

osyoyu and others added 6 commits January 16, 2026 10:47
…vate()

This patch fixes a problem where `binding.irb` (= force_activate('irb'))
fails under `bundle exec` when the Gemfile does not contain `irb` and
does contain a gem which is (1) not installed in GEM_HOME (2) sourced
using `path:`/`git:`.

The original approach constructing a temporary definition fails since
it does not set the equalivent of `path:`/`git:`.

Always reconstructing a definition from a Gemfile and applying lockfile
constraints should be a more robust approach.

[Bug #21723]
Bundler::Runtime#setup requires a real existing lockfile (see
Bundler::SharedHelpers#default_lockfile).
This patch silences the "this won't work in the next version of Ruby"
warning displayed when irb is autoloaded via `binding.irb`.

    main.rb:1: warning: irb used to be loaded from the standard library, but is not part of the default gems since Ruby 4.0.0.
    You can add irb to your Gemfile or gemspec to fix this error.
    /.../irb.rb:9: warning: reline used to be loaded from the standard library, but is not part of the default gems since Ruby 4.0.0.
    You can add reline to your Gemfile or gemspec to fix this error.

    From: main.rb @ line 1 :

     => 1: binding.irb

    /.../input-method.rb:284: warning: rdoc used to be loaded from the standard library, but is not part of the default gems since Ruby 4.0.0.
    You can add rdoc to your Gemfile or gemspec to fix this error.

This warning is incorrect and misleading: users should not need to
include irb (and its dependencies) to their Gemfiles to use
`binding.irb`, even in future versions of Ruby. It is agreed that the
runtime takes care of that.
Users should add `irb` to their Gemfile.
`Gem::BUNDLED_GEMS.force_activate 'irb'` is workaround for short term.
@hsbt hsbt requested a review from k0kubun as a code owner January 16, 2026 01:49
Copilot AI review requested due to automatic review settings January 16, 2026 01:49
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR backports a fix for Bug #21723 related to bundled gems warning suppression and force_activate behavior with bundler/inline.

Changes:

  • Adds warning suppression mechanism for bundled gems using thread-local storage
  • Modifies force_activate to handle bundler/inline scenarios by conditionally setting fake BUNDLE_GEMFILE/BUNDLE_LOCKFILE environment variables
  • Adds test coverage for force_activate with bundler/inline

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
prelude.rb Adds thread-local warning suppression for 'reline' and 'rdoc' when loading IRB to prevent unwanted bundled gem warnings
lib/bundled_gems.rb Adds warning suppression check and refactors force_activate to handle bundler/inline by conditionally faking environment variables
spec/bundled_gems_spec.rb Adds test case to verify force_activate works correctly with bundler/inline and preserves LOAD_PATH

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

end

context "with bundler/inline" do
it "foo is available on LOAD_PATH" do
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test description "foo is available on LOAD_PATH" is misleading. The test is actually verifying that when force_activate is called with bundler/inline, it correctly shows the gem installation warning for the missing gem ("csv") while preserving the LOAD_PATH entries from the inline Gemfile (including "foo-1.0.0/lib"). A more accurate description would be something like "preserves LOAD_PATH from inline gemfile when force_activate fails".

Suggested change
it "foo is available on LOAD_PATH" do
it "preserves LOAD_PATH from inline gemfile when force_activate fails" do

Copilot uses AI. Check for mistakes.
@hsbt hsbt added the Backport label Jan 16, 2026
@k0kubun k0kubun merged commit 26777e8 into ruby:ruby_4_0 Jan 20, 2026
100 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants