| name | test |
| description | Generate comprehensive test suites for existing code without modifying implementation. Trigger: add tests, test coverage, write tests for, test this module. |
| user-invocable | true |
/test — Standalone Test Generation Pipeline
You are an orchestrator dispatching agents to analyze existing code and generate comprehensive test suites. Unlike /build (which writes tests alongside implementation), /test targets code that already exists but lacks coverage. You do not modify implementation — you only add tests.
What This Skill Does
- Analyzes the codebase to identify untested or under-tested modules
- Prioritizes by risk (public APIs, auth, payments, data mutations)
- Generates test files following existing test patterns
- Validates tests pass against current implementation
- Reports coverage delta
Phase 1: COVERAGE ANALYSIS
Dispatch an Explore subagent to map test coverage:
Subagent: Task tool, subagent_type="Explore"
Prompt: Analyze the test coverage of this codebase.
1. Find all existing test files (*.test.ts, *.spec.ts, *.test.tsx, etc.)
2. For each source file, determine if it has a corresponding test file
3. For tested files, assess coverage depth:
- Does it test the happy path?
- Does it test error cases?
- Does it test edge cases (empty input, max values, concurrent access)?
- Does it test integration with dependencies?
4. Categorize each source file:
- UNTESTED: no test file exists
- SHALLOW: test file exists but only covers happy path
- ADEQUATE: covers happy path + error cases
- THOROUGH: covers happy path + errors + edge cases + integration
5. For untested/shallow files, assess risk:
- HIGH: auth, payments, data mutations, API routes, security
- MEDIUM: business logic, state management, data transformation
- LOW: UI components, utilities, constants
Return a prioritized list: highest-risk untested files first.
Phase 2: TEST PLAN
Based on the coverage analysis, create a test plan:
Prioritization order:
- HIGH risk + UNTESTED — critical gaps
- HIGH risk + SHALLOW — needs depth
- MEDIUM risk + UNTESTED — important gaps
- MEDIUM risk + SHALLOW — nice to have
- LOW risk — only if time permits
For each target file, define:
- Test file path (following existing naming convention)
- Test categories to write (unit, integration, property-based)
- Key scenarios to cover
- Mocks/fixtures needed
- Estimated test count
Phase 3: TEST GENERATION
Dispatch Ralph workers to write tests. Each worker gets a subset of test files.
Subagent: Task tool, subagent_type="general-purpose"
Prompt: You are a senior test engineer writing tests for existing code.
You MUST NOT modify any implementation files. Only create/modify test files.
[contents of references/test-writer-prompt.md]
Files to test:
[TARGET_FILE_LIST]
Existing test patterns to follow:
[EXAMPLE_TEST_FROM_CODEBASE]
For each file, write tests covering:
1. Happy path — normal expected usage
2. Error cases — invalid input, missing data, service failures
3. Edge cases — empty arrays, null values, boundary conditions
4. Integration — verify correct interaction with dependencies
After writing each test file:
1. Run: npm test [test-file-path]
2. Verify all tests PASS against current implementation
3. If a test fails, the implementation is correct — fix your test
4. Commit: test(coverage): add tests for [module-name]
Scope discipline:
- Only create test files. Never modify source files.
- If a source file has a bug that makes testing impossible, note it and move on.
- If a source file is untestable (tight coupling, no dependency injection), note it as tech debt.
Phase 4: VALIDATION
After all workers complete:
npm test
npx vitest run --coverage
Phase 5: COVERAGE REPORT
Test Coverage Delta:
Before: 42% (23/55 files tested)
After: 71% (39/55 files tested)
New test files: 16
New test cases: 147
High-risk coverage:
✓ auth/login.ts: 12 tests (was 0)
✓ api/payments/route.ts: 8 tests (was 0)
✓ lib/pipeline/summary.ts: 15 tests (was 3)
✗ api/webhooks/stripe/route.ts: skipped (untestable without refactor)
Remaining gaps:
- api/webhooks/stripe/route.ts: needs dependency injection refactor
- lib/legacy/parser.ts: complex coupling, recommend refactor first
Test Quality Standards
Tests generated by this skill must meet:
- No implementation coupling — tests should verify behavior, not internal structure
- Deterministic — no flaky tests. Mock time, random values, external services.
- Isolated — each test runs independently. No shared mutable state.
- Fast — unit tests under 100ms each. Integration tests under 1s.
- Descriptive names —
it("returns 401 when auth token is expired") not it("test 3")
- Arrange-Act-Assert — clear structure in every test
- No console.log — use proper assertions, not manual inspection