testing/flaky-test-triage
Finds, isolates and fixes flaky tests by repeated runs and root-cause analysis.
- Kind
- Prompt
- Works with
- Claude Code
- Source
- Claude Code Templates @ 72e5f237f64d
- Path
- cli-tool/components/commands/testing/flaky-test-triage.md
- License
- MIT
- Jobs
- Testing, Debugging
InstallCopy it from the source repository, or sign in and let the assistant adapt it for your project.
# Flaky Test Triage
Investigate and eliminate non-deterministic behavior for: **$ARGUMENTS**
## Purpose
Isolate tests that pass and fail intermittently without code changes, determine the underlying source of non-determinism (race conditions, order coupling, timing drift, or leaked state), and apply robust deflaking fixes.
## Pre-flight
1. Confirm working tree cleanliness before running repeated test runs:
```bash
test -z "$(git status --porcelain)" || { echo "Working tree is dirty; commit or stash changes first."; exit 1; }
```
2. Identify the target test file or test case from `$ARGUMENTS`.
3. Detect the test framework in use (e.g., Jest, Vitest, Pytest, Go test, Cargo test) from project configuration.
## Triage & Stabilization Workflow
### 1. Stress Repetition to Measure Flake Frequency
Run the target test for 20 iterations without breaking early on first error so the full pass/fail ratio and flake frequency can be accurately quantified:
- **Vitest**:
```bash
passes=0; fails=0
for i in $(seq 1 20); do
if npx vitest run <path-to-test>; then ((++passes)); else ((++fails)); fi
done
echo "Vitest Results: $passes passed, $fails failed out of 20 runs"
…