Repository navigation
feat: Support Ruby 3.4 and 4.0 - #370
Open
dividedmind wants to merge 14 commits into
Open
dividedmind wants to merge 14 commits into
dividedmind wants to merge 14 commits into
Conversation
dividedmind
requested review from
kgilpin
and
a balanced review from Copilot
November 23, 2026 11:56
There was a problem hiding this comment.
🟡 Changes recommended
The hard-coded YAML quoting in spec/hook_spec.rb causes the expectation to fail on Ruby 3.0–3.3 despite representing the same scalar value.
1 open issue
What changed in this PR
This PR adds Ruby 3.4 support to AppMap, fixes recording of class methods that share names with instance methods, and updates tests for parser and formatting differences.
Changes:
- Adds Ruby 3.4 to supported versions and the CI matrix.
- Fixes same-name method recording and adds regression coverage.
- Replaces Diffy comparisons with RSpec equality checks and documents Prism’s recording limitation.
| File | Description |
|---|---|
test/test_helper.rb |
Removes the Diffy require. |
test/gem_test.rb |
Expects recording to start at Parser::Base.parse. |
spec/spec_helper.rb |
Adds Prism compiler detection. |
spec/record_net_http_spec.rb |
Replaces Diffy comparisons with equality checks. |
spec/hook_spec.rb |
Updates assertions, adds regression coverage, and marks the Prism case pending. |
spec/fixtures/hook/same_name_methods.rb |
Adds matching class and instance method names for regression coverage. |
README.md |
Documents the Prism limitation and parser workaround. |
lib/appmap/version.rb |
Declares Ruby 3.4 supported. |
lib/appmap/hook.rb |
Stops filtering class methods by instance method names. |
appmap.gemspec |
Removes the Diffy development dependency. |
.github/workflows/ci.yml |
Adds Ruby 3.4 to CI. |
Review effort: Balanced
It pinned Ruby 3.0.2, which nothing uses: CI sets the Ruby version explicitly for each job, and the gem supports a range of versions. With rbenv the pin makes every command in the repository fail unless 3.0.2 happens to be installed. It was untracked for the same reason once before (d051772), so also ignore it again, letting developers pin a version locally.
`File.stub` is rspec-mocks' old :should syntax, which isn't enabled explicitly and prints a deprecation warning on every run. The stub made File.write raise, so that the example would fail if the config file was written. `expect(File).not_to receive(:write)` says the same thing directly, matching the example above it. Assisted-by: Claude:claude-opus-5-5
The test suite records itself: AppMap's RSpec integration is enabled
by default, and the repository's appmap.yml (with no packages) still
turns on the builtin hooks, including Kernel#system.
Diffy locates its diff binary on first use by calling
system("diff", ...). That call is recorded, and recording it calls #to_s
on the receiver, which is the Diffy::Diff being computed. The nested
#to_s runs the diff a second time and then deletes the tempfiles, so the
outer diff runs against missing files and returns an empty string. As a
result the first Diffy comparison in every process passes no matter
what. When a single example is run on its own, it can never fail.
RSpec's eq matcher already prints a unified diff for multi-line strings,
which reads better than the diff-of-a-diff that comparing Diffy's
output to "" produced, so use it and drop the diffy dependency.
Turning off self-recording with APPMAP=false isn't an option: the
variable is inherited by the fixture apps that some specs run in
subprocesses, and those specs depend on recording.
Assisted-by: Claude:claude-opus-5-5
When a class finished loading, its singleton methods were filtered against the list of its instance methods, so a class method such as `def self.call` was never hooked if the class also defined an instance method `call`. They are different methods, and nothing else hooks the class method, so it was silently left out of recordings. This used to be partly hidden: methods defined in a `class << self` block were hooked when that block ended, before the instance methods existed. Ruby 3.4's default Prism compiler no longer fires TracePoint :class/:end events for `class << self`, so on 3.4 such methods are also affected, which broke the protected singleton method spec. This is visible in gem recordings too. For example, `Parser::Base.parse` (the documented entry point of the parser gem, which also has an instance method `parse`) is now recorded. Previously a shallow recording of the gem started at the `default_parser` call it makes internally. Assisted-by: Claude:claude-opus-5-5
Ruby 3.4 changed Hash#inspect to print `{kw3: :three}` rather than
`{:kw3=>:three}`. The new format also contains ": ", so YAML has to
quote it, and the expected event YAML differs in more than the hash.
Spell out the expected values for both formats, instead of deriving
them with Hash#to_s or Psych, so that the spec still checks the actual
output.
Assisted-by: Claude:claude-opus-5-5
Prism, the default parser since Ruby 3.4, doesn't fire the TracePoint :class and :end events for `class << self` bodies. AppMap hooks the methods defined in such a body when its :end event fires. That event is now missing, so methods defined in `class << self` outside a class or module body, such as in a `Struct.new do ... end` block, are never hooked. (Inside a class body they are still hooked when the class itself ends.) This is a Ruby bug, reported as https://bugs.ruby-lang.org/issues/22629. Mark the spec pending when running on Prism, rather than skipping it, so that it starts failing (and can be re-enabled) once Ruby is fixed. Assisted-by: Claude:claude-opus-5-5
Add 3.4 to the supported versions, so that the config validator (used by `appmap-agent-validate` and `appmap-agent-status`) no longer reports an error on it, and run CI on 3.4 too. One known limitation remains, caused by a bug in Prism, the default parser since Ruby 3.4 (https://bugs.ruby-lang.org/issues/22629): methods defined in a `class << self` (or `class << obj`) body are not recorded, unless the body runs inside the definition of that same class or module. This is documented in the README, together with the workaround of running with `--parser=parse.y`. I didn't add a workaround in AppMap itself. It would need a global hook such as BasicObject#singleton_method_added, and the affected patterns (such as `class << self` in a `Struct.new` block, or `class << SomeModule` at the top level of a file) are uncommon in application code. Assisted-by: Claude:claude-opus-5-5
dividedmind
force-pushed
the
fix/ruby-3.4
branch
from
November 23, 2026 12:22
82f601f to
1fb8332
Compare
RDoc 8 removed the options argument of RDoc::Markup::ToHtml.new, so `rake appmap:swagger` failed with an ArgumentError whenever the bundle resolved RDoc 8 (for example in Rails 8 apps, where railties pulls in RDoc through irb). Pass the options only to older RDoc versions. The Markdown conversion had no specs at all, so add one. Gemfile.lock isn't tracked, so CI resolves the latest RDoc and the spec will catch future API changes too. Assisted-by: Claude:claude-opus-5-5
`rake appmap:swagger` converts descriptions with RDoc, but rdoc was only a development dependency, relying on it being available as a default gem. Since Ruby 4.0 it's a bundled gem instead, so in a bundle that doesn't otherwise include it (such as a Rails 7.x app) the task failed with "cannot load such file -- rdoc". Make it a runtime dependency. Assisted-by: Claude:claude-opus-5-5
Ruby 4.0 moved benchmark and ostruct from default gems to bundled gems, so they're no longer loadable unless they're in the bundle. Rails 6.1 requires benchmark, and rswag-ui (in the Rails 7 app) and cucumber 3 require ostruct, so the fixture apps failed to boot. Add them to the fixture Gemfiles; they install fine on older Rubies too. Assisted-by: Claude:claude-opus-5-5
Bundler 4, which ships with Ruby 4.0, removed Bundler.with_clean_env, so every minitest test that runs a fixture app failed with Bundler::RemovedError. Use Bundler.with_unbundled_env, its replacement since Bundler 2.1 (Ruby 3.0 ships with 2.2). Assisted-by: Claude:claude-opus-5-5
Bundler 4 warns that a future version will show help instead of installing when `bundle` is run without a command. Spell out `bundle install` to silence the warning and keep working after that. Assisted-by: Claude:claude-opus-5-5
Bundler 4 warns that the :mingw, :mswin and :x64_mingw platforms are deprecated in favour of :windows. That platform isn't known to the older Bundler versions used with older Rubies, and the fixture app never runs on Windows or JRuby, so just remove the gem. Assisted-by: Claude:claude-opus-5-5
Add 4.0 to the supported versions, so that the config validator (used by `appmap-agent-validate` and `appmap-agent-status`) no longer reports an error on it, and run CI on 4.0 too. Apart from bundled gems (fixed in the previous commits), no changes were needed. The Prism limitation documented in the README for Ruby 3.4+ still applies, as the bug is not fixed in 4.0 (https://bugs.ruby-lang.org/issues/22629); the `--parser=parse.y` workaround still works. Assisted-by: Claude:claude-opus-5-5
dividedmind
force-pushed
the
fix/ruby-3.4
branch
from
November 23, 2026 13:02
d582c15 to
8a6f22e
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

feat: Support Ruby 3.4 and 4.0
This adds support for Ruby 3.4 and 4.0, and fixes the problems that came up while getting the test suite to pass on them. Each commit is self-contained, so it's easiest to review one commit at a time.
Changes
.gitignoreagain, as it was in d051772.:shouldsyntax (File.stub).appmap.ymlenables the builtinKernel#systemhook. The first time Diffy runs in a process it callssystem("diff", …). Recording that call runs#to_son the half-builtDiffy::Diff, which runs the diff again and deletes its tempfiles. As a result the first Diffy comparison in every process came back empty and passed, so an example run on its own could never fail. The specs now use RSpec'seq, which already prints a readable diff, and thediffydependency is gone.def self.callwas never hooked if an instancecallalso existed. This affects every Ruby version. It's visible in gem recordings too: shallow recordings of theparsergem now start at its entry pointParser::Base.parseinstead of the internaldefault_parsercall, andtest/gem_test.rbis updated to match.{kw3: :three}, which also has to be quoted in YAML, so the spec spells out the expected values for both formats.SUPPORTED_RUBY_VERSIONS, soappmap-agent-validateandappmap-agent-statusno longer report it as unsupported. It also adds 3.4 to the CI matrix, and adds a "Known issues" section to the README.RDoc::Markup::ToHtml.new, sorake appmap:swaggerraised anArgumentErrorwhenever the bundle resolved RDoc 8 (e.g. Rails 8 apps, where railties pulls it in via irb). This affects every Ruby version. The Markdown conversion had no specs, so this adds one; sinceGemfile.lockisn't tracked, CI resolves the latest RDoc and will catch future API changes.rdocfrom a default gem into a bundled gem, and it was only a development dependency, so the swagger task failed withcannot load such file -- rdocin bundles that don't otherwise include it (such as Rails 7.x apps). It's now a runtime dependency.benchmarkandostructinto bundled gems. Rails 6.1 needsbenchmark, and rswag-ui and cucumber 3 needostruct, so the fixture apps failed to boot until they were added to their Gemfiles.Bundler::RemovedError.Bundler.with_unbundled_envis its replacement since Bundler 2.1 (Ruby 3.0 ships with 2.2).bundlewill show help instead of installing in a future version.:mingw/:mswin/:x64_mingwplatforms in favour of:windows, which older Bundler versions don't know. The fixture never runs on Windows or JRuby, so the gem is simply removed.SUPPORTED_RUBY_VERSIONSand the CI matrix. Apart from the bundled gems and Bundler 4 changes above, no changes were needed.Known issue: Prism and
class << selfPrism, the default parser since Ruby 3.4, doesn't fire the TracePoint
:class/:endevents forclass << selfbodies (Ruby bug #22629). AppMap relies on those events, so on Prism it misses methods defined in aclass << self(orclass << obj) body, unless it is aclass << selfthat runs inside the definition of that same class or module. Examples areclass << selfinside aStruct.new do … endblock, andclass << SomeModuleat the top level of a file. Methods inclass << selfdirectly in a class body are still recorded when the class definition ends; before the fix above, that wasn't true if an instance method had the same name.I didn't add a workaround in AppMap. It would need a global hook such as
BasicObject#singleton_method_added, and the affected patterns are uncommon in application code. A scan of ~580 installed gems found them in about 3% of theclass <<bodies that define methods, mostly in library code. Instead, the README documents the limitation and the workaround of running withRUBYOPT=--parser=parse.y. The bug is still present in Ruby 4.0.7, and the workaround still works there.Testing
bundle exec rake testpasses on Ruby 3.3.12 (227 examples, 0 failures), and on Ruby 3.4.10 and 4.0.7 with the default Prism parser (227 examples, 1 pending); all minitest tests pass on all three. The 3.4.10 and 4.0.7 runs used Bundler 4 (4.0.15 and 4.0.20), the 3.3.12 run Bundler 2.6.9.bundle exec rspecalso passes withRUBYOPT=--parser=parse.yon 3.4.10, which exercises the pre-Prism code path; on 4.0.7 I only ranspec/hook_spec.rbthat way (40 examples, 0 failures, including the embedded struct spec). The new swagger spec passes with both RDoc 7.2 and 8.1. Ruby 3.0–3.2 were not tested locally; CI covers them.Assisted-by: Claude:claude-opus-5-5