Skip to content

feat: add Ruby on Rails CLI support (rspec, rubocop, bundle, rails)#1

Closed
navidemad wants to merge 1 commit intomasterfrom
feat/ruby-rails-support
Closed

feat: add Ruby on Rails CLI support (rspec, rubocop, bundle, rails)#1
navidemad wants to merge 1 commit intomasterfrom
feat/ruby-rails-support

Conversation

@navidemad
Copy link
Owner

@navidemad navidemad commented Feb 28, 2026

Rust
Ruby
Rails
Lines
Tests
Files

Summary

Adds comprehensive Ruby on Rails ecosystem support to RTK with 4 new command modules covering the full Rails development workflow, plus shared infrastructure and discover registry integration.

New Commands

Command Strategy Token Savings
rtk rspec JSON (--format json injection) with text fallback RSpec RSpec text
rtk rubocop JSON (--format json injection) with text fallback RuboCop
rtk bundle list/outdated/install/update Text parsing, subcommand dispatch Bundle
rtk rails test/routes/db:migrate/db:migrate:status/db:rollback/generate Sub-enum, text parsing per subcommand Rails

Shared Infrastructure

  • ruby_exec() in utils.rs — Auto-detects bundle exec when Gemfile declares the tool gem. Prevents forcing globally-installed tools through bundler. gemfile_mentions_gem() avoids false positives (e.g., guardrailsrails)
  • fallback_tail() in utils.rs — Last-resort filter fallback showing final N lines with diagnostic logging
  • count_tokens() in utils.rs — Shared test helper for token savings assertions (deduplicated from 4 modules)
  • exit_code_from_output() — Signal-aware exit code extraction: returns 128 + signal on Unix per convention, logs signal number

Hook Integration

.claude/hooks/rtk-rewrite.sh rewrites:

  • rspec, bundle exec rspec, bin/rspecrtk rspec
  • rubocop, bundle exec rubocoprtk rubocop
  • bundle list/outdated/install/updatertk bundle ...
  • rails test/routes/db:migrate/db:migrate:status/db:rollback/generatertk rails ...
  • rake routes/db:migrate/db:migrate:status/db:rollbackrtk rails ...
  • bin/rails, bundle exec rails variants

Discover Registry

  • Patterns use non-capturing groups (?:bundle\s+exec\s+)? so the subcommand lands in capture group 1
  • db:migrate:status ordered before db:migrate to avoid prefix match
  • Subcommand-specific savings: test 50%, routes 50%, db:migrate:status 40%, db:migrate 40%, db:rollback 40%, generate/g 20%

Key Design Decisions

  1. JSON injection for rspec/rubocop — Injects --format json unless user specified -f/--format. Detects autocorrect mode (-a, -A) in rubocop to skip JSON
  2. 3-tier JSON fallback in rspec — Strip noise → parse JSON → try original → text parser → fallback_tail(). Logs serde error on final fallback for debugging
  3. Safe JSON fallback in rubocop — JSON parse failure uses fallback_tail() instead of feeding JSON through the text parser
  4. Sub-enum for rails, flat dispatch for bundle — Rails has 6 subcommands with different output formats; Bundle has 4 with shared structure. Mirrors existing patterns (Go uses sub-enum, Ruff uses flat args)
  5. Defensive arithmeticsaturating_sub throughout, extract_count returns Option<usize> to distinguish 0 from parse error
  6. ANSI stripping in bundle liststrip_ansi() at filter entry point to handle colored terminal output

Changes by File

File Lines Description
src/rspec_cmd.rs +974 RSpec filter: JSON/text parsers, noise stripping, 27 tests
src/rails_cmd.rs +1452 Rails sub-enum: test/routes/migrate/status/rollback/generate, 35 tests
src/rubocop_cmd.rs +661 RuboCop filter: JSON/text parsers, severity ordering, 20 tests
src/bundle_cmd.rs +637 Bundle filter: list/outdated/install/update with ANSI handling, 15 tests
scripts/test-rails.sh +334 E2E smoke test (creates real Rails app, exercises all commands)
src/discover/registry.rs +236 Pattern matching + subcommand savings for Ruby ecosystem
src/utils.rs +142 ruby_exec(), fallback_tail(), count_tokens(), signal handling
src/main.rs +114 Command routing for rspec, rubocop, bundle, rails
.claude/hooks/rtk-rewrite.sh +48 Hook rewrites for Ruby/Rails commands
scripts/test-all.sh +32 Smoke test additions
README.md +37 Documentation
CLAUDE.md +16 Module table, hook docs, architecture notes
ARCHITECTURE.md +21 Module table entry

PR Review Fixes (2 rounds, 27 issues addressed)

Round 1 (issues 1-14)
# Severity Fix
1 Critical saturating_sub in build_rspec_summary (prevents underflow panic)
2 Critical RuboCop JSON fallback uses fallback_tail() instead of text parser
3 Bug Removed dead output.status.success() check in signal handler
4 Bug bundle_cmd::run_passthrough uses exit_code_from_output
5 Bug extract_count returns Option<usize> (0 vs parse error)
6 Bug Discover registry: non-capturing groups, added db:rollback/generate/g
7 Docs Qualified savings claims (RSpec: 60%+/30%+; Bundle: 10-30%)
8-10 Test ANSI handling tests for all 4 modules, text fallback truncation
11 Test Empty migration table test
12 Test RuboCop 10-file cap test
13-14 Docs Inline comments (bundle ruby_exec skip, migrate direction docs)
Round 2 (issues 1-13, skipping 9)
# Severity Fix
1 Registry Added db:migrate:status to discover PATTERNS and subcmd_savings + test
2 Bug Removed spurious starts_with(") ") in rspec text parser
3 Diagnostics RSpec JSON fallback now logs the serde error message
4 Diagnostics Minitest error count sanity check (parallel to failure count check)
5 Bug Signal termination returns 128 + signal on Unix (was hardcoded 1)
6 Bug strip_ansi() in filter_bundle_list() + improved ANSI test assertions
7 Docs exit_code_from_output doc comment reflects 128 + signal behavior
8 Cleanup Deduplicated count_tokens to shared utils.rs (removed from 4 modules)
9 Skip Run boilerplate refactor deferred (functions have enough variation)
10 Docs compact_ruby_path doc comment accurately describes behavior
11 Docs Bundle savings "5-30%" → "10-30%" in CLAUDE.md and ARCHITECTURE.md
12 Docs Added rake variants to hook integration docs
13 Test Added Header → FailedExamples transition test for rspec text parser

Testing

cargo fmt --all --check   → clean
cargo clippy --all-targets → 0 new warnings
cargo test --all           → 527 passed, 2 ignored

Test Plan

  • cargo fmt --all --check && cargo clippy --all-targets && cargo test --all passes
  • Build release binary and verify filtered output on a real Rails project
  • Verify hook rewrites in a Claude Code session (rspecrtk rspec)
  • Run scripts/test-rails.sh on a machine with Ruby/Rails
  • Verify rtk gain --history records Ruby/Rails usage
  • Test format flag: rtk rspec -fdocumentation uses text fallback
  • Test failure path: rtk rspec in empty dir shows "FAILED" message
  • Verify rtk rails db:migrate:status, db:rollback, generate work correctly
  • Verify rtk discover detects rails db:migrate:status as supported

🤖 Generated with Claude Code

@navidemad navidemad changed the title feat: add Ruby on Rails CLI support feat: add Ruby on Rails CLI support (rspec, rubocop, bundle, rails) Feb 28, 2026
navidemad added a commit that referenced this pull request Mar 1, 2026
- Remove fragile byte_offset tracking in filter_bundle_install, use
  string search instead (issue #1)
- Add signal-killed process diagnostics (eprintln when code() is None)
  across all 7 occurrences in 4 Ruby modules (issue rtk-ai#2)
- Remove diagnostic note from stdout in rspec JSON fallback path —
  the eprintln on the line above already logs to stderr (issue rtk-ai#3)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@navidemad navidemad force-pushed the feat/ruby-rails-support branch from 326fa9e to 29566d1 Compare March 1, 2026 00:52
Add 4 new command modules for the Ruby on Rails ecosystem with
shared infrastructure, discover registry integration, and hook
rewrites. 96+ unit tests, 527 total passing.

New commands:
- rtk rspec: JSON parsing with text fallback (60%+ / 30%+ savings)
- rtk rubocop: JSON parsing, group by cop/severity (60%+ savings)
- rtk bundle list/outdated/install/update: text parsing (10-30%)
- rtk rails test/routes/db:migrate/status/rollback/generate (40-50%+)

Shared infrastructure:
- ruby_exec() auto-detects bundle exec when Gemfile declares gem
- fallback_tail() last-resort filter with diagnostic logging
- count_tokens() shared test helper (deduplicated from 4 modules)
- exit_code_from_output() returns 128+signal on Unix

Hook rewrites cover rspec, rubocop, bundle, rails, rake, and
bin/bundle exec variants via .claude/hooks/rtk-rewrite.sh.
@navidemad navidemad force-pushed the feat/ruby-rails-support branch from 29566d1 to 4c22082 Compare March 1, 2026 00:57
@navidemad
Copy link
Owner Author

Moved to rtk-ai#292

@navidemad navidemad closed this Mar 1, 2026
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.

1 participant