Skip to content

Support Ruby procedural modifications#231

Merged
acrmp merged 40 commits intoSWE-bench:mainfrom
cosgroveb:ruby-procedural-modifiers
Mar 9, 2026
Merged

Support Ruby procedural modifications#231
acrmp merged 40 commits intoSWE-bench:mainfrom
cosgroveb:ruby-procedural-modifiers

Conversation

@cosgroveb
Copy link
Copy Markdown
Contributor

@cosgroveb cosgroveb commented Mar 3, 2026

Adds 20 procedural bug modifiers, 22 repo profiles, and 40 tests for Ruby.

Builds on the Ruby tree-sitter adapter (#34, @acrmp). With these changes, SWE-smith can generate bugs for Ruby repos end-to-end.

Modifiers

20 tree-sitter-based modifiers across 5 modules:

Module Modifier Description
control_flow ctrl_invert_if Swap if/else branches
ctrl_shuffle Reorder top-level statements
guard_clause_invert Flip ifunless on guard clauses
nil_introduction safe_nav_removal Replace &. with .
or_default_removal Strip || default fallbacks
presence_strip Remove .presence calls
bang_method_strip find!find (allowlisted methods only)
or_equals_removal ||==
nil_guard_removal Remove return if x.nil? guards
operations op_change Replace operator within category (+*)
flip_operators Flip to opposite (==!=, ><)
op_swap Swap operands (a > bb > a)
op_break_chains Collapse chained expressions (a + b + ca)
op_change_const Off-by-one on integer literals
remove remove_loop Remove while/until/for blocks
remove_cond Remove if/unless blocks
remove_assign Remove assignments
remove_rescue_ensure Remove rescue/ensure blocks
ruby_specific symbol_string_swap :foo"foo"
block_mutation Strip block parameters or yield arguments

nil_introduction and ruby_specific target idioms that don't exist in other languages: safe navigation, memoization via ||=, symbols, blocks.

Validated on RuboCop: 75.4% pass rate

Tested on rubocop/rubocop (519206df) with 175 generated patches:

Modifier Gen Valid Pass%
ctrl_invert_if 12 12 100.0%
or_default_removal 5 5 100.0%
guard_clause_invert 12 11 91.7%
op_change 12 11 91.7%
flip_operators 11 9 81.8%
op_change_const 11 9 81.8%
op_swap 11 8 72.7%
safe_nav_removal 5 3 60.0%
symbol_string_swap 6 3 50.0%
remove_assign 15 7 46.7%
op_break_chains 12 5 41.7%
ctrl_shuffle 11 4 36.4%
nil_guard_removal 5 1 20.0%
remove_loop 4 1 25.0%
remove_cond 12 2 16.7%
Total 175 132 75.4%

Operator and control-flow modifiers have the highest pass rates. Removal modifiers sit lower because deleting code tends to break compilation or cause cascading failures.

Repo profiles

22 profiles (3 existing + 19 new), including 3 SWE-bench_Multilingual eval_sets repos:

Repo Framework eval_set
faker-ruby/faker Minitest
rubocop/rubocop RSpec
jekyll/jekyll RSpec
fluent/fluentd Minitest SWE-bench_Multilingual
fastlane/fastlane RSpec SWE-bench_Multilingual
jordansissel/fpm Minitest SWE-bench_Multilingual
ruby-grape/grape RSpec
thoughtbot/factory_bot RSpec
varvet/pundit RSpec
Shopify/liquid Minitest
jnunemaker/httparty RSpec
rack/rack RSpec
presidentbeef/brakeman Minitest
ddollar/foreman Minitest
sinatra/sinatra Minitest
ruby-concurrency/concurrent-ruby RSpec
hashie/hashie RSpec
dry-rb/dry-validation RSpec
dry-rb/dry-types RSpec
pry/pry RSpec
ruby/csv Minitest
simplecov-ruby/simplecov RSpec

Log parsers handle RSpec JSON (--format json) and Minitest/test-unit verbose output with auto-detection. _is_test_path overridden to recognize spec/ directories and _spec.rb files.

Tests

40 tests across 7 files:

tests/bug_gen/procedural/ruby/test_ruby_control_flow.py    — 5 tests
tests/bug_gen/procedural/ruby/test_ruby_nil_introduction.py — 8 tests
tests/bug_gen/procedural/ruby/test_ruby_operations.py       — 6 tests
tests/bug_gen/procedural/ruby/test_ruby_remove.py           — 5 tests
tests/bug_gen/procedural/ruby/test_ruby_specific.py         — 5 tests
tests/bug_gen/adapters/test_ruby_properties.py              — 4 tests (via conftest)
tests/profiles/test_profiles_ruby.py                        — 11 tests (log parsers, delegation, eval_sets)
$ pytest tests/bug_gen/procedural/ruby/ tests/profiles/test_profiles_ruby.py tests/bug_gen/adapters/test_ruby_properties.py -v
40 passed

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 999703407c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@cosgroveb cosgroveb force-pushed the ruby-procedural-modifiers branch from 9997034 to 6c1b18d Compare March 3, 2026 03:38
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 3, 2026

Codecov Report

❌ Patch coverage is 93.11314% with 98 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
swesmith/bug_gen/procedural/ruby/operations.py 80.37% 42 Missing ⚠️
...esmith/bug_gen/procedural/ruby/nil_introduction.py 89.69% 17 Missing ⚠️
swesmith/bug_gen/procedural/ruby/control_flow.py 89.92% 14 Missing ⚠️
swesmith/profiles/ruby.py 94.35% 14 Missing ⚠️
swesmith/bug_gen/procedural/ruby/base.py 89.83% 6 Missing ⚠️
swesmith/bug_gen/procedural/ruby/ruby_specific.py 92.18% 5 Missing ⚠️
Files with missing lines Coverage Δ
swesmith/bug_gen/adapters/ruby.py 97.47% <100.00%> (+1.53%) ⬆️
swesmith/bug_gen/procedural/__init__.py 100.00% <100.00%> (ø)
swesmith/bug_gen/procedural/ruby/__init__.py 100.00% <100.00%> (ø)
swesmith/bug_gen/procedural/ruby/remove.py 100.00% <100.00%> (ø)
swesmith/profiles/__init__.py 100.00% <100.00%> (ø)
swesmith/profiles/base.py 82.86% <ø> (ø)
tests/bug_gen/adapters/test_ruby_properties.py 100.00% <100.00%> (ø)
.../bug_gen/procedural/ruby/test_ruby_control_flow.py 100.00% <100.00%> (ø)
..._gen/procedural/ruby/test_ruby_nil_introduction.py 100.00% <100.00%> (ø)
...ts/bug_gen/procedural/ruby/test_ruby_operations.py 100.00% <100.00%> (ø)
... and 9 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@john-b-yang john-b-yang requested a review from acrmp March 3, 2026 06:02
@cosgroveb
Copy link
Copy Markdown
Contributor Author

021fbac addresses codecov

@acrmp acrmp self-assigned this Mar 4, 2026
Copy link
Copy Markdown
Collaborator

@acrmp acrmp left a comment

Choose a reason for hiding this comment

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

Hi @cosgroveb,

This is awesome! Thanks for opening this PR! It's great to see support for Ruby-specific language features too.

I haven't had a chance to look through the whole PR yet but here's some initial feedback.

@cosgroveb
Copy link
Copy Markdown
Contributor Author

@acrmp thanks for the review. LLMs have such a frustrating time with ruby. Hopefully this helps make the world a better place in a small way :). Let me know if you need any further changes.

Copy link
Copy Markdown
Collaborator

@acrmp acrmp left a comment

Choose a reason for hiding this comment

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

@cosgroveb Thanks for making those changes. Looks great!

Here's some more feedback/questions I had reviewing the remainder of the modifiers.

@cosgroveb
Copy link
Copy Markdown
Contributor Author

@acrmp let me know if I missed anything from your second round. Cheers!

Copy link
Copy Markdown
Collaborator

@acrmp acrmp left a comment

Choose a reason for hiding this comment

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

@cosgroveb Thanks for making those changes! Looks good.

I set Claude to work looking for correctness issues and the main one found was treatment of nested binary expressions by the OperationSwapOperandsModifier. There's also a general issue with removal of inline conditionals/loops/rescues.

@cosgroveb cosgroveb force-pushed the ruby-procedural-modifiers branch 3 times, most recently from f0926e1 to a9ee66f Compare March 6, 2026 03:54
@cosgroveb
Copy link
Copy Markdown
Contributor Author

@acrmp I rebased and addressed today's feedback

cosgroveb and others added 12 commits March 6, 2026 13:15
tree-sitter-based modifiers across 5 modules: control_flow (if/else
invert, shuffle lines, guard clause invert), nil_introduction (safe
navigation, or-default, presence, bang method, or-equals, nil guard),
operations (change, flip, swap operands, break chains, change constants),
remove (loops, conditionals, assignments, rescue/ensure), and
ruby_specific (symbol/string swap, block mutation). Includes base class
with _remove_matching_nodes helper and Ruby adapter property analysis.
Profiles for Faker, RuboCop, Jekyll, and 19 new repos including 3
SWE-bench_Multilingual eval_set repos (fluentd, fastlane, fpm). RSpec
JSON and Minitest/test-unit log parsers with auto-detection. RSpec test
path detection (_is_test_path override for spec/ and _spec.rb).
40 tests: 29 modifier tests (parametrized remove and guard clause tests,
deterministic seeds, specific content assertions), 4 property analysis
tests via conftest fixture, 11 profile tests covering both log parsers,
parser delegation, eval_sets, and RSpec test path detection.
@cosgroveb cosgroveb force-pushed the ruby-procedural-modifiers branch from c32d1fd to 7805146 Compare March 6, 2026 13:15
@cosgroveb
Copy link
Copy Markdown
Contributor Author

Thanks for your attention in getting this PR in shape @acrmp. Replied/rebased again this morning.

Copy link
Copy Markdown
Collaborator

@acrmp acrmp left a comment

Choose a reason for hiding this comment

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

@cosgroveb I think we're just about there, thanks for your patience!

I just left a couple of questions about the test parsing.

@cosgroveb
Copy link
Copy Markdown
Contributor Author

Cool. Thanks again @acrmp for the review.

@acrmp
Copy link
Copy Markdown
Collaborator

acrmp commented Mar 9, 2026

@cosgroveb Thanks! I left a comment on an edge case with OrDefaultRemovalModifier checking it's in a conditional context.

@acrmp acrmp merged commit 6dbf962 into SWE-bench:main Mar 9, 2026
1 check passed
@acrmp
Copy link
Copy Markdown
Collaborator

acrmp commented Mar 9, 2026

@cosgroveb Merged! Thank you! 💎

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.

2 participants