Skip to content

[FEAT]: Automated quality gate for AI-generated Rails code #5654

Description

@rodrigovirgilio

Thank you for taking the time to help us improve the app!

  • I have searched the existing issues

Is there a pain point in the app driving this feature request?

Human Essentials is a large monolith (70+ controllers, 60+ models, 60+ services) with a lot of code generated and maintained with the help of AI coding assistants. Today the only automated safeguards are CI runs of RuboCop (with most Metrics cops disabled via Standard), Brakeman (no threshold) and RSpec. There is no single command an AI agent or contributor can run to know whether a change is safe to ship beyond "the tests pass".

Desired Behavior

Implement an automated quality gate for the Rails app, following the "Rails Playbook" described by Paulo Tarso (CodeMiner42):

  1. Test coverage (SimpleCov) — line and branch coverage with a ratcheted threshold.
  2. Complexity / method & module sizes (RuboCop Metrics cops + Flog) — ceiling on cyclomatic complexity, ABC size, method/class/module length for new code.
  3. Mutation testing (Mutant) — kill ratio as the "truth detector" for whether tests assert real behavior; threshold ratcheted from the first run.
  4. Security (Brakeman) — JSON report parsed into the gate with a hard warnings_max threshold.
  5. N+1 detection (Bullet) — Bullet.raise = true wired into the spec suite so N+1s fail the gate.

All of it collapses into one command: bin/rake quality, with a fast local variant (bin/rake quality:local, everything except mutation) and a full CI variant. A config/quality_thresholds.yml holds every threshold, ratcheted on first run. Diff-aware execution (e.g. mutant --since main) should be used where full-suite runs are infeasible for a codebase this size.

Criteria for Completion

  • bin/rake quality runs coverage, rubocop metrics, flog, mutation, brakeman and reports a pass/fail table with thresholds from config/quality_thresholds.yml
  • bin/rake quality:local runs everything except mutation (~15s) for fast AI/contributor iteration
  • Thresholds are ratcheted on first run (no hardcoded impossible numbers on a codebase this size)
  • Bullet enabled in the test suite and N+1 regressions fail the gate
  • Brakeman warnings are gated (new warnings fail) via JSON parsing
  • GitHub Actions workflow runs the full gate on PRs and uploads tmp/quality/ artifacts for inspection
  • CLAUDE.md documents that the gate must be run before declaring a task complete

Anything else?

Reference articles (the playbook this issue implements):

The follow-up post also documents two gates the author deliberately removed (suite-wide allocations via GC.stat and per-action SQL counts via ActiveSupport::Notifications) because they are "continuous-drift" numbers that only produce threshold-bumping rituals — those should NOT be implemented. Packwerk/dependency-structure gates were also skipped by the author as architecture-theatre for a Rails monolith.

  • I've read the Code of Conduct and understand my responsibilities as a member of the Ruby for Good community

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions