Identify flaky tests by running tests multiple times and analyzing intermittent failures. Use when investigating test reliability.
Run the test suite multiple times sequentially and identify tests that exhibit intermittent behavior (sometimes pass, sometimes fail). This helps identify unreliable tests that may cause CI failures.
Parse $ARGUMENTS as follows:
--filter, -t)Examples:
/flaky-tests → 10 runs with pnpm test --run/flaky-tests 5 → 5 runs/flaky-tests 20 --filter=worker → 20 runs with filterCreate a scratchpad directory for temporary log files:
SCRATCHPAD="$TMPDIR/flaky-tests-$(date +%s)"
mkdir -p "$SCRATCHPAD"
IMPORTANT: Tests MUST be run sequentially (one at a time), NOT in parallel. Running tests in parallel can cause resource contention that creates false flakiness signals.
For each run (1 to N):
pnpm test --run with any additional arguments$SCRATCHPAD/test-run-$i.logUse a single bash command with a for loop:
for i in {1..N}; do
echo "=== Test Run $i ==="
pnpm test --run [extra args] 2>&1 | tee "$SCRATCHPAD/test-run-$i.log"
if [ ${PIPESTATUS[0]} -eq 0 ]; then
echo "Run $i: PASSED"
else
echo "Run $i: FAILED"
fi
done
For each run, extract from the log files:
Look for patterns in vitest output:
✓ or √ = passed× or ✗ = failed↓ = skippedFAIL prefix in summary = failed test file with suite pathCategorize tests by reliability:
| Category | Definition | | ------------------------ | -------------------------------------------------------------------- | | Flaky | Failed in some runs but passed in others (0 < failures < total runs) | | Consistently Failing | Failed in ALL runs | | Consistently Passing | Passed in ALL runs | | Slow | Tests taking >1000ms that may be prone to timeouts |
For flaky tests, calculate:
Provide a structured report with all flaky tests, their failure rates, and any observable patterns.
# Flaky Test Report
## Summary
- **Total Runs**: X
- **Runs Passed**: Y (Z%)
- **Runs Failed**: W (V%)
- **Flaky Tests Found**: N
## Flaky Tests
Tests that passed in some runs but failed in others:
| Test | Failures | Rate | Package |
| ----------------- | -------- | ---- | ------------ |
| Suite > test name | X/Y | Z% | package-name |
### Detailed Analysis
#### [Test Name]
- **File**: path/to/test.spec.ts
- **Failure Rate**: X/Y runs (Z%)
- **Failed in Runs**: 2, 5, 8
- **Error Pattern**: [timeout | assertion | exception]
- **Sample Error**:
[First error message encountered]
## Consistently Failing Tests
Tests that failed in ALL runs (not flaky, just broken):
| Test | Package | Error Type |
|------|---------|------------|
| Suite > test name | package-name | timeout/assertion |
## Slow Tests (Potential Timeout Risk)
Tests taking >1000ms that may be prone to flakiness:
| Test | Avg Duration | Package |
|------|--------------|---------|
| Suite > test name | Xms | package-name |
## Run-by-Run Summary
| Run | Status | Failed Tests |
|-----|--------|--------------|
| 1 | PASS | - |
| 2 | FAIL | test-a, test-b |
| ... | ... | ... |
## Recommendations
[Suggestions for addressing the flakiness, such as:]
- Tests with timeout errors: Consider increasing timeout or optimizing
- Tests with ordering issues: May have race conditions
- Tests with assertion errors: May depend on execution order or shared state
After identifying flaky tests, investigate these common causes:
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer