Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 28, 2025

Plan to fix Ruby 4.0 compatibility issue

  • Identify the issue: Ruby 4.0 requires benchmark to be explicitly added as a dependency
  • Add benchmark gem to development dependencies in twiglet.gemspec
  • Update required_ruby_version upper bound to < 4.1 (was < 5.0)
  • Add cgi gem for Ruby 4.0 compatibility with simplecov
  • Explicitly add minitest to Gemfile to ensure proper loading in Ruby 4.0
  • Run code review (no issues found)
  • Run security scan (no vulnerabilities found)

Summary

Successfully added Ruby 4.0 support to the twiglet gem with the following changes:

Ruby 4.0 Bundled Gems Compatibility

Ruby 4.0 moved several gems from the standard library to "bundled gems", requiring explicit declaration:

  1. benchmark gem: Added as development dependency. Required for rubocop to run.

  2. cgi gem: Added as development dependency. Required for simplecov-html (used by simplecov 0.17.1).

  3. minitest gem:

    • Added version constraint >= 5.0 in gemspec
    • Explicitly declared in Gemfile to ensure bundler loads it before Ruby's bundled_gems.rb intercepts requires
    • This resolves the minitest/mock LoadError

Other Changes

  1. Updated required_ruby_version: Changed upper bound from < 5.0 to < 4.1 to maintain the pattern of only claiming support for tested versions (3.1-4.0).

  2. Updated CI workflows: Added Ruby 4.0 to test matrices in both ruby.yml and gem-publish.yml.

  3. Updated documentation: Updated TRUSTED_PUBLISHING.md to reflect Ruby 4.0 support.

The gem now properly supports Ruby versions 3.1 through 4.0 while maintaining backward compatibility. All Ruby 4.0 compatibility issues in the CI pipeline have been resolved.

Original prompt

Upgrade to support ruby 4.0


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: addersuk <131964+addersuk@users.noreply.github.com>
Copilot AI changed the title [WIP] Upgrade project to support Ruby 4.0 Add Ruby 4.0 support Dec 28, 2025
Copilot AI requested a review from addersuk December 28, 2025 22:27
@addersuk
Copy link
Member

@copilot Fix this
/opt/hostedtoolcache/Ruby/4.0.0/x64/lib/ruby/gems/4.0.0/gems/rubocop-1.62.1/exe/rubocop:14: warning: benchmark used to be loaded from the standard library, but is not part of the default gems since Ruby 4.0.0.
You can add benchmark to your Gemfile or gemspec to fix this error.
bundler: failed to load command: rubocop (/opt/hostedtoolcache/Ruby/4.0.0/x64/bin/rubocop)
/opt/hostedtoolcache/Ruby/4.0.0/x64/lib/ruby/4.0.0/bundled_gems.rb:60:in 'Kernel.require': cannot load such file -- benchmark (LoadError)
from /opt/hostedtoolcache/Ruby/4.0.0/x64/lib/ruby/4.0.0/bundled_gems.rb:60:in 'block (2 levels) in Kernel#replace_require'
from /opt/hostedtoolcache/Ruby/4.0.0/x64/lib/ruby/gems/4.0.0/gems/rubocop-1.62.1/exe/rubocop:14:in '<top (required)>'
from /opt/hostedtoolcache/Ruby/4.0.0/x64/lib/ruby/4.0.0/rubygems.rb:303:in 'Kernel#load'
from /opt/hostedtoolcache/Ruby/4.0.0/x64/lib/ruby/4.0.0/rubygems.rb:303:in 'Gem.activate_and_load_bin_path'
from /opt/hostedtoolcache/Ruby/4.0.0/x64/bin/rubocop:25:in '<top (required)>'
from /opt/hostedtoolcache/Ruby/4.0.0/x64/lib/ruby/4.0.0/bundler/cli/exec.rb:61:in 'Kernel.load'
from /opt/hostedtoolcache/Ruby/4.0.0/x64/lib/ruby/4.0.0/bundler/cli/exec.rb:61:in 'Bundler::CLI::Exec#kernel_load'
from /opt/hostedtoolcache/Ruby/4.0.0/x64/lib/ruby/4.0.0/bundler/cli/exec.rb:24:in 'Bundler::CLI::Exec#run'
from /opt/hostedtoolcache/Ruby/4.0.0/x64/lib/ruby/4.0.0/bundler/cli.rb:500:in 'Bundler::CLI#exec'
from /opt/hostedtoolcache/Ruby/4.0.0/x64/lib/ruby/4.0.0/bundler/vendor/thor/lib/thor/command.rb:28:in 'Bundler::Thor::Command#run'
from /opt/hostedtoolcache/Ruby/4.0.0/x64/lib/ruby/4.0.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in 'Bundler::Thor::Invocation#invoke_command'
from /opt/hostedtoolcache/Ruby/4.0.0/x64/lib/ruby/4.0.0/bundler/vendor/thor/lib/thor.rb:538:in 'Bundler::Thor.dispatch'
from /opt/hostedtoolcache/Ruby/4.0.0/x64/lib/ruby/4.0.0/bundler/cli.rb:35:in 'Bundler::CLI.dispatch'
from /opt/hostedtoolcache/Ruby/4.0.0/x64/lib/ruby/4.0.0/bundler/vendor/thor/lib/thor/base.rb:584:in 'Bundler::Thor::Base::ClassMethods#start'
from /opt/hostedtoolcache/Ruby/4.0.0/x64/lib/ruby/4.0.0/bundler/cli.rb:29:in 'Bundler::CLI.start'
from /opt/hostedtoolcache/Ruby/4.0.0/x64/lib/ruby/gems/4.0.0/gems/bundler-4.0.3/exe/bundle:28:in 'block in <top (required)>'
from /opt/hostedtoolcache/Ruby/4.0.0/x64/lib/ruby/4.0.0/bundler/friendly_errors.rb:118:in 'Bundler.with_friendly_errors'
from /opt/hostedtoolcache/Ruby/4.0.0/x64/lib/ruby/gems/4.0.0/gems/bundler-4.0.3/exe/bundle:20:in '<top (required)>'
from /opt/hostedtoolcache/Ruby/4.0.0/x64/lib/ruby/4.0.0/rubygems.rb:303:in 'Kernel#load'
from /opt/hostedtoolcache/Ruby/4.0.0/x64/lib/ruby/4.0.0/rubygems.rb:303:in 'Gem.activate_and_load_bin_path'
from /opt/hostedtoolcache/Ruby/4.0.0/x64/bin/bundle:25:in '

'

Co-authored-by: addersuk <131964+addersuk@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 28, 2025

@copilot Fix this
/opt/hostedtoolcache/Ruby/4.0.0/x64/lib/ruby/gems/4.0.0/gems/rubocop-1.62.1/exe/rubocop:14: warning: benchmark used to be loaded from the standard library, but is not part of the def...

Fixed in commit 47f80de. Added benchmark gem as a development dependency since Ruby 4.0 moved it from default gems to bundled gems, requiring explicit declaration in the gemspec.

@addersuk
Copy link
Member

@copilot twiglet.gemspec:28 less then 4.1

Co-authored-by: addersuk <131964+addersuk@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 28, 2025

@copilot twiglet.gemspec:28 less then 4.1

Updated in commit 03951ae. Changed required_ruby_version upper bound from < 5.0 to < 4.1 to only claim support for tested versions (3.1-4.0).

@addersuk
Copy link
Member

/dobby version minor

@addersuk
Copy link
Member

@copilot fix Run bundle exec rake test
/opt/hostedtoolcache/Ruby/4.0.0/x64/bin/ruby -w -I"lib:test" /opt/hostedtoolcache/Ruby/4.0.0/x64/lib/ruby/gems/4.0.0/gems/rake-13.3.1/lib/rake/rake_test_loader.rb "test/test_coverage.rb" "test/error_serialiser_test.rb" "test/formatter_test.rb" "test/hash_extensions_test.rb" "test/logger_test.rb" "test/message_test.rb" "test/validator_test.rb" "examples/rack/request_logger_test.rb"
/opt/hostedtoolcache/Ruby/4.0.0/x64/lib/ruby/gems/4.0.0/gems/simplecov-html-0.10.2/lib/simplecov-html.rb:2: warning: CGI library is removed from Ruby 4.0. Please use cgi/escape instead for CGI.escape and CGI.unescape features.
If you need to use the full features of CGI library, Please install cgi gem.
SimpleCov failed with exit 1/opt/hostedtoolcache/Ruby/4.0.0/x64/lib/ruby/4.0.0/bundled_gems.rb:60:in 'Kernel.require': cannot load such file -- minitest/mock (LoadError)
from /opt/hostedtoolcache/Ruby/4.0.0/x64/lib/ruby/4.0.0/bundled_gems.rb:60:in 'block (2 levels) in Kernel#replace_require'
from /home/runner/work/twiglet-ruby/twiglet-ruby/test/error_serialiser_test.rb:4:in '<top (required)>'
from /opt/hostedtoolcache/Ruby/4.0.0/x64/lib/ruby/4.0.0/bundled_gems.rb:60:in 'Kernel.require'
from /opt/hostedtoolcache/Ruby/4.0.0/x64/lib/ruby/4.0.0/bundled_gems.rb:60:in 'block (2 levels) in Kernel#replace_require'
from /opt/hostedtoolcache/Ruby/4.0.0/x64/lib/ruby/gems/4.0.0/gems/rake-13.3.1/lib/rake/rake_test_loader.rb:21:in 'block in

'
from /opt/hostedtoolcache/Ruby/4.0.0/x64/lib/ruby/gems/4.0.0/gems/rake-13.3.1/lib/rake/rake_test_loader.rb:6:in 'Array#select'
from /opt/hostedtoolcache/Ruby/4.0.0/x64/lib/ruby/gems/4.0.0/gems/rake-13.3.1/lib/rake/rake_test_loader.rb:6:in ''
rake aborted!
Command failed with status (1): [ruby -w -I"lib:test" /opt/hostedtoolcache/Ruby/4.0.0/x64/lib/ruby/gems/4.0.0/gems/rake-13.3.1/lib/rake/rake_test_loader.rb "test/test_coverage.rb" "test/error_serialiser_test.rb" "test/formatter_test.rb" "test/hash_extensions_test.rb" "test/logger_test.rb" "test/message_test.rb" "test/validator_test.rb" "examples/rack/request_logger_test.rb" ]
/opt/hostedtoolcache/Ruby/4.0.0/x64/bin/bundle:25:in ''
Tasks: TOP => test
(See full trace by running task with --trace)

Co-authored-by: addersuk <131964+addersuk@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 30, 2025

@copilot fix Run bundle exec rake test
/opt/hostedtoolcache/Ruby/4.0.0/x64/bin/ruby -w -I"lib:test" /opt/hostedtoolcache/Ruby/4.0.0/x64/lib/ruby/gems/4.0.0/gems/rake-13.3.1/lib/rake/rake_test_loader....

Fixed in commit c0b1874. Added cgi gem as a development dependency. Ruby 4.0 removed cgi from the standard library, and simplecov-html (used by simplecov 0.17.1) requires it.

@addersuk addersuk marked this pull request as ready for review December 30, 2025 12:53
@addersuk addersuk requested a review from a team as a code owner December 30, 2025 12:53
Copilot AI review requested due to automatic review settings December 30, 2025 12:53
@addersuk

This comment was marked as outdated.

Copy link
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 adds Ruby 4.0 support to the twiglet gem by addressing compatibility issues with gems that were moved from default to bundled gems in Ruby 4.0, and updating version constraints to reflect tested versions.

Key changes:

  • Added benchmark and cgi as development dependencies to resolve Ruby 4.0 compatibility issues
  • Updated required_ruby_version upper bound from < 3.5 to < 4.1 to align with tested versions
  • Added Ruby 4.0 to CI test matrices and updated documentation

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
twiglet.gemspec Updated Ruby version constraint to < 4.1 and added benchmark and cgi development dependencies
test/logger_test.rb Fixed indentation alignment in test code
lib/twiglet/version.rb Bumped version from 3.14.5 to 3.15.0 for new Ruby support
docs/TRUSTED_PUBLISHING.md Updated documentation to list Ruby 4.0 in supported versions
.github/workflows/ruby.yml Added Ruby 4.0 to test matrix
.github/workflows/gem-publish.yml Added Ruby 4.0 to test matrix

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

Co-authored-by: addersuk <131964+addersuk@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 30, 2025

@copilot Can you fix Run bundle exec rake test
/opt/hostedtoolcache/Ruby/4.0.0/x64/bin/ruby -w -I"lib:test" /opt/hostedtoolcache/Ruby/4.0.0/x64/lib/ruby/gems/4.0.0/gems/rake-13.3.1/lib/rake/rake_test_...

Fixed in commit 2f2656a. Added minitest >= 5.0 explicitly to the Gemfile. Ruby 4.0 moved minitest to bundled gems, and declaring it in the Gemfile ensures bundler loads it before Ruby's bundled_gems.rb intercepts the require.

@addersuk
Copy link
Member

/dobby version minor

@addersuk addersuk enabled auto-merge December 30, 2025 15:45
@addersuk addersuk merged commit c36627d into master Dec 30, 2025
7 checks passed
@addersuk addersuk deleted the copilot/upgrade-support-ruby-4-0 branch December 30, 2025 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants