Files
ruflo/plugins/ruflo-testgen
ruv 1b336e9ced feat(testgen): Test-Driven Repair via headless claude -p (ADR-175-inspired)
Adds a new ruflo-testgen surface that closes the loop the existing TDD
plugins didn't — we generate tests, this fixes the code to satisfy them.
Inspired by agent-harness-generator/packages/darwin-mode ADR-175 Test-
Driven Repair mode, but implemented via headless `claude -p` instead of
wrapping `metaharness-darwin evolve`. Rationale:

  1. `claude -p` already in our stack (no new optional dep)
  2. Bounded cost via --max-budget-usd (first-class flag)
  3. Capability-restricted via --allowedTools Read,Edit,Bash
  4. Test exit code IS the fitness function (no LLM-as-judge)
  5. Resumable via --session-id

Surface:
  - plugins/ruflo-testgen/scripts/tdd-repair/tdd-repair.mjs (script)
  - plugins/ruflo-testgen/skills/tdd-repair/SKILL.md       (skill)
  - v3/@claude-flow/cli/src/mcp-tools/testgen-tools.ts     (MCP tool:
                                                             testgen_tdd_repair)

Pipeline (Test-Driven mode):
  1. Pre-flight: run the test command. Refuse if already passing.
  2. Spawn `claude -p` with focused prompt (read failing test, fix
     source, don't touch test, verify by running it).
  3. Re-run test to verify the fix; emit per-attempt receipts incl.
     usage.cost_usd from claude's --output-format json.
  4. If green: success. If red after --max-attempts: emit failure
     receipts; workspace left as-modified for review.

Safety (mirrors ADR-153 conventions):
  - --confirm REQUIRED (dry-run otherwise)
  - --max-budget-usd hard cap (default $5, divided across attempts)
  - --allowedTools restricts spawned claude to Read/Edit/Bash
  - --permission-mode acceptEdits (auto-accept within the allowed set)
  - 15 min hard timeout
  - Pre-flight catches --test-command typos before any spend

Conformant mode (--no-test-oracle, agent writes own repro via MCTS)
is scoped for a follow-up ADR — current --no-test-oracle returns
config error with a clear hint.

Smoke verification (docs/benchmarks/tdd-repair/SMOKE-2026-06-22.md):
  Built minimal failing-test fixture: add(a,b) returns a-b instead of
  a+b. Pre-repair: 2/2 tests fail. After `tdd-repair --confirm`:
  source patched to a+b, 2/2 tests pass. Verified by re-running.

Version bump 3.13.3 → 3.14.0 (MINOR per semver — backward-compatible
new MCP tool + new skill). Published with all three dist-tags (latest,
alpha, v3alpha) for @claude-flow/cli, claude-flow, ruflo.

Co-Authored-By: RuFlo <ruv@ruv.net>
2026-06-22 17:15:32 -04:00
..

ruflo-testgen

Test gap detection, coverage analysis, and automated test generation. SPARC Refinement-phase canonical owner.

Install

/plugin marketplace add ruvnet/ruflo
/plugin install ruflo-testgen@ruflo

What's Included

  • Coverage Gap Detection: Identify untested code paths with prioritized gap analysis
  • Coverage-Aware Routing: Route tasks to agents based on test coverage needs
  • Test Generation: Automated test scaffolding for uncovered modules
  • TDD Support: London School (mock-first) test patterns with agent coordination
  • testgaps Worker: Background worker for continuous coverage analysis
  • Integration: Works with hooks system for post-edit test suggestions

Requires

  • ruflo-core plugin (provides MCP server)

Compatibility

  • CLI: pinned to @claude-flow/cli v3.6 major+minor.
  • Verification: bash plugins/ruflo-testgen/scripts/smoke.sh is the contract.

testgaps worker + coverage CLI surface

This plugin's two MCP/CLI surfaces:

Surface Invocation
MCP: dispatch the testgaps worker mcp tool call hooks_worker-dispatch --json -- '{"trigger":"testgaps"}'
CLI: coverage-gaps (table of gaps) npx @claude-flow/cli@latest hooks coverage-gaps --format table --limit 20
CLI: coverage-route (route a task by gap) npx @claude-flow/cli@latest hooks coverage-route --task "add auth tests"
CLI: coverage-suggest (suggest tests for a path) npx @claude-flow/cli@latest hooks coverage-suggest --path src/

testgaps is one of 12 background workers documented in ruflo-loop-workers ADR-0001.

SPARC Refinement-phase ownership

This plugin owns the Refinement phase per ruflo-sparc ADR-0001 §"Phase-to-plugin alignment". When SPARC's sparc-refine skill runs, it composes:

  1. This plugin — coverage gap detection + TDD test generation
  2. ruflo-jujutsu — diff-aware refactor recommendations

Together they enforce the Refinement gate: ≥80% coverage on new code + diff risk score below threshold.

Namespace coordination

This plugin owns the test-gaps AgentDB namespace (kebab-case, follows the convention from ruflo-agentdb ADR-0001 §"Namespace convention"). Reserved namespaces (pattern, claude-memories, default) MUST NOT be shadowed.

test-gaps indexes detected gaps by file + priority + last-seen timestamp. Accessed via memory_* (namespace-routed).

Verification

bash plugins/ruflo-testgen/scripts/smoke.sh
# Expected: "10 passed, 0 failed"

Architecture Decisions

  • ruflo-loop-workers — defines the testgaps background worker
  • ruflo-sparc — Refinement-phase canonical handoff
  • ruflo-jujutsu — diff-aware refactor companion in the Refinement gate
  • ruflo-agentdb — namespace convention owner