Skip to content

feat: add Ruby and Rails CLI support (rspec, rubocop, bundle, rails)#292

Open
navidemad wants to merge 1 commit intortk-ai:masterfrom
navidemad:feat/ruby-rails-support
Open

feat: add Ruby and Rails CLI support (rspec, rubocop, bundle, rails)#292
navidemad wants to merge 1 commit intortk-ai:masterfrom
navidemad:feat/ruby-rails-support

Conversation

@navidemad
Copy link

@navidemad navidemad commented Mar 1, 2026

Ruby Rails

📝 Summary

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

Includes 97 unit tests across the 4 new modules and an E2E smoke test script (scripts/test-rails.sh) that creates a real Rails app and exercises all commands.

🚀 New Commands

Command Supported Subcommands / Formats Token Savings Notes
rtk rspec JSON, Text fallback RSpec JSON RSpec text Injects --format json automatically. Falls back to text parsing when user specifies a custom format.
rtk rubocop Standard, Autocorrect RuboCop Injects --format json, groups offenses by cop name and severity. Skips JSON in autocorrect mode (-a, -A).
rtk bundle list, outdated, install, update Bundle Text parsing with subcommand dispatch. ANSI stripping at entry point.
rtk rails test, routes, db:migrate, db:migrate:status, db:rollback, generate Rails Sub-enum with per-subcommand parsers. Minitest parser for test, route grouping for routes, migration summaries for db:*.
🛠 Key Design Decisions (Click to expand)
  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. Signal-aware exit codesexit_code_from_output returns 128 + signal on Unix per convention, ANSI stripping at filter entry points.
🏗 Shared Infrastructure & Registry (Click to expand)

Shared Infrastructure (utils.rs)

  • ruby_exec() — Auto-detects bundle exec when Gemfile declares the tool gem. gemfile_mentions_gem() avoids false positives (e.g., guardrailsrails).
  • fallback_tail() — Last-resort filter fallback showing final N lines with diagnostic logging.
  • count_tokens() — 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.

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 / db:rollback: 40%
    • generate/g: 20%

🪝 Hook Integration

The .claude/hooks/rtk-rewrite.sh file now correctly rewrites the following commands:

Rewritten to From input
rtk rspec rspec, bundle exec rspec, bin/rspec
rtk rubocop rubocop, bundle exec rubocop
rtk bundle … bundle list|outdated|install|update
rtk rails … rails test|routes|db:migrate|…
rtk rails … rake routes|db:migrate|db:rollback|…
rtk rails … bin/rails …, bundle exec rails …

🧪 How to Test

Tip

Running the E2E smoke tests requires Ruby, Bundler, and the Rails gem to be installed locally.

# 1. Run unit tests (No Ruby required)
cargo test --all

# 2. Build and install locally
cargo install --path .

# 3. Run E2E smoke tests (~60-120s execution time)
bash scripts/test-rails.sh

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 changed the title feat: add Ruby on Rails CLI support (rspec, rubocop, bundle, rails) feat: add Ruby and Rails CLI support (rspec, rubocop, bundle, rails) Mar 1, 2026
@benoittgt
Copy link

benoittgt commented Mar 1, 2026

Partially duplicate of #198

But great additions !

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