一键导入
test-health
Audit test suite health — detect flaky tests, dead tests, coverage gaps, and missing assertions — produce a health report with fix suggestions
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Audit test suite health — detect flaky tests, dead tests, coverage gaps, and missing assertions — produce a health report with fix suggestions
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | test-health |
| description | Audit test suite health — detect flaky tests, dead tests, coverage gaps, and missing assertions — produce a health report with fix suggestions |
| argument-hint | [--flaky-runs 5 | --coverage | --quick] (default: full audit) |
| allowed-tools | Bash, Read, Write, Edit, Glob, Grep, Agent |
Audit the test suite for flaky tests, dead/trivial tests, coverage gaps on recent changes, missing assertions, and structural issues. Produce a health report with prioritized recommendations.
$ARGUMENTS may contain:
--flaky-runs N — number of times to run the suite for flaky detection (default: 5)--coverage — only run the coverage gap analysis (skip flaky/dead detection)--quick — skip flaky detection (most time-consuming), run everything elsenpx vitest --version$ARGUMENTS:
FLAKY_RUNS=N from --flaky-runs N (default: 5)COVERAGE_ONLY=true if --coverageQUICK=true if --quickfind tests/ \( -name '*.test.js' -o -name '*.test.ts' \) | sort
Skip if COVERAGE_ONLY or QUICK is set.
Run the full test suite FLAKY_RUNS times and track per-test pass/fail:
RUN_DIR=$(mktemp -d /tmp/test-health-XXXXXX)
for i in $(seq 1 $FLAKY_RUNS); do
timeout 180 npx vitest run --reporter=json > "$RUN_DIR/run-$i.json" 2>"$RUN_DIR/run-$i.err"
exit_code=$?
if [ $exit_code -eq 124 ]; then
echo '{"timeout":true}' > "$RUN_DIR/run-$i.json"
elif [ $exit_code -ne 0 ] && [ $exit_code -ne 1 ]; then
# Use jq to safely JSON-escape stderr content (may contain quotes, newlines, backslashes)
stderr_content=$(cat "$RUN_DIR/run-$i.err")
jq -n --argjson code "$exit_code" --arg stderr "$stderr_content" \
'{"error":true,"exit_code":$code,"stderr":$stderr}' > "$RUN_DIR/run-$i.json"
fi
done
For each run, parse the JSON reporter output from $RUN_DIR/run-$i.json to get per-test results.
After all runs are parsed and analysis is complete, clean up the temporary directory:
rm -rf "$RUN_DIR"
Before analyzing, exclude invalid runs: skip any run file containing {"timeout":true} or {"error":true} — these runs produced no reliable per-test data and must not be counted as "all tests failed." Require a minimum of 2 valid runs (runs with parseable vitest JSON output) for flaky detection to be conclusive. If fewer than 2 valid runs remain, report that flaky detection was inconclusive due to too many errored/timed-out runs.
A test is flaky if it passes in some valid runs and fails in others.
For each flaky test found:
setTimeout/sleepTimeout: Each full suite run gets 3 minutes (
timeout 180). Exit code 124 indicates timeout — the run is recorded as{"timeout":true}and the loop continues.
Skip if COVERAGE_ONLY is set.
Scan all test files for problematic patterns:
Search for test bodies that:
expect(), assert(), toBe(), toEqual(), or similar assertion callsconsole.log or commentsit.skip(, test.skip(, xit(, xtest(it.todo(, test.todo(Pattern: test bodies with 0 assertions = dead tests
Detect tests that assert on constants or trivially true conditions:
expect(true).toBe(true)expect(1).toBe(1)expect(result).toBeDefined() as the ONLY assertion (too weak)Search for commented-out test blocks:
// it(, // test(, /* it(, /* test(describe blocksCheck if any files in tests/fixtures/ are not referenced by any test file.
Search for duplicate test descriptions within the same describe block — these indicate copy-paste errors.
Run vitest with coverage and analyze:
npx vitest run --coverage --coverage.reporter=json-summary 2>&1
Parse coverage/coverage-summary.json and extract:
Find source files in src/ with 0% coverage (no tests touch them at all).
Find files with < 50% line coverage. For each:
domain/ or features/ (core logic — coverage matters more)codegraph complexity <file> -T — high complexity + low coverage = high riskCompare against main branch to find recently changed files:
git diff --name-only origin/main...HEAD -- src/
For each changed source file, check if:
Note: If the coverage tool is not configured or fails, skip this phase and note it in the report. Coverage is a vitest plugin — it may need
@vitest/coverage-v8installed.
Skip if COVERAGE_ONLY is set.
Analyze the test suite's structural health:
For each directory in src/:
Check for:
afterEach/afterAll missing)beforeEach resets in describe blocks that share state{ timeout: ... }Write report to generated/test-health/TEST_HEALTH_<date>.md:
# Test Health Report — <date>
## Summary
| Metric | Value |
|--------|-------|
| Total test files | N |
| Total test cases | N |
| Flaky tests | N |
| Dead/trivial tests | N |
| Skipped tests | N |
| Coverage (lines) | X% |
| Coverage (branches) | X% |
| Uncovered source files | N |
| **Health score** | **X/100** |
## Health Score Calculation
- Start at 100
- -10 per flaky test
- -3 per dead/trivial test
- -2 per skipped test (without TODO explaining why)
- -1 per uncovered source file in `domain/` or `features/`
- -(100 - line_coverage) / 5 (coverage penalty)
- Floor at 0
## Flaky Tests
<!-- For each: file, name, pass/fail ratio, likely cause, suggested fix -->
## Dead & Trivial Tests
<!-- For each: file, line, issue, recommendation -->
## Coverage Gaps
<!-- Uncovered files, low-coverage hotspots with complexity -->
## Structural Issues
<!-- Oversized files, missing cleanup, timeout issues -->
## Recommended Actions
### Priority 1 — Fix flaky tests
<!-- List with specific suggestions -->
### Priority 2 — Remove or fix dead tests
<!-- List with specific suggestions -->
### Priority 3 — Add coverage for high-risk gaps
<!-- List uncovered functions in core modules, ordered by complexity -->
### Priority 4 — Structural improvements
<!-- Split large files, add cleanup, reduce timeouts -->
After writing the report, identify tests that can be fixed immediately (< 5 min each):
.skip from tests that now pass (run them to check)Do NOT auto-fix — list these as suggestions in the report. The user decides.
@vitest/coverage-v8 — if missing, skip coverage and note itTODO or comment explaining whygenerated/test-health/ — create the directory if neededAdopt extracted helpers — find dead symbols from forge, wire them into consumers, replace duplicated inline patterns, and gate on dead-symbol delta (Titan Paradigm Phase 4.5)
Adopt extracted helpers — find dead symbols from forge, wire them into consumers, replace duplicated inline patterns, and gate on dead-symbol delta (Titan Paradigm Phase 4.5)
Validate staged changes — codegraph checks + project lint/build/test, auto-rollback on failure, pass/fail commit gate (Titan Paradigm Phase 4)
Audit codebase files against the 4-pillar quality manifesto using RECON work batches, with batch processing and context budget management (Titan Paradigm Phase 2)
Map a codebase's dependency graph, identify hotspots, name logical domains, propose work batches, and produce a ranked priority queue for autonomous cleanup (Titan Paradigm Phase 1)
Local repo maintenance — clean stale worktrees, remove dirt files, sync with main, update codegraph, prune branches, and verify repo health