QA Flaky Detector
Purpose
Identify and classify flaky tests from CI history and test execution data. Flaky tests pass and fail intermittently for the same code, wasting CI time and masking real failures. This skill detects flakiness, classifies root causes into four patterns, and suggests targeted fixes.
Trigger Phrases
- "Find flaky tests" / "Identify flaky tests"
- "Analyze CI history for flakiness" / "Flaky test report"
- "Why does this test fail sometimes?" / "Intermittent test failures"
- "Classify flaky test [name]" / "Flaky test patterns"
- "Suggested fixes for flaky tests" / "Fix flaky [test name]"
4-Pattern Classification
| Pattern |
Description |
Typical Causes |
Suggested Fixes |
| 1. Race conditions |
Async timing, DOM not ready, API response order |
Missing awaits, no explicit waits, parallel execution |
Add explicit waits, await chains, waitForSelector |
| 2. Shared state |
Test order dependency, global state mutation, DB leftover |
Global vars, singletons, uncleared DB/cache |
Isolate tests, beforeEach cleanup, transactional rollback |
| 3. Time-dependency |
Timezone, date/time mocking, daylight saving |
new Date(), Date.now(), hardcoded dates |
Mock time (Jest useFakeTimers, freezegun), use fixed dates |
| 4. External dependencies |
Network calls, third-party APIs, file system |
Live HTTP, external services, temp files |
Mock/stub APIs, use fixtures, deterministic file paths |
See references/flaky-patterns.md for detailed patterns with code examples and fixes.
Detection Methods
1. CI History Analysis
- Same test, different results across runs (pass/fail flip)
- Compare JUnit XML, Allure, or CI job logs over N runs
- Threshold: pass rate < 100% over 10+ runs → flag as flaky
2. Statistical Analysis
- Pass rate per test:
passes / (passes + failures) over recent runs
- Confidence: more runs → higher confidence in flakiness
- Minimum runs: recommend 10+ for reliable detection
3. Pattern Matching (Code-Based)
- Scan test code for known flaky signatures:
- No
await on async operations
setTimeout/setInterval without cleanup
new Date() or Date.now() without mocking
- Direct HTTP calls, file I/O
- Shared globals, singletons
- Missing
beforeEach/afterEach cleanup
See references/ci-analysis.md for CI history analysis methods.
Workflow
- Input — CI artifacts (JUnit XML, Allure, GitHub Actions logs), test execution history, or test file paths
- Collect — Parse results from N runs; build pass/fail matrix per test
- Detect — Identify tests with pass rate < 100%
- Classify — Map each flaky test to one or more of the 4 patterns (code scan + heuristics)
- Suggest — Generate fix recommendations per pattern
- Output — Flaky test report, prioritized fix list
Output Deliverables
Flaky Test Report
# Flaky Test Report — [Project/Branch]
## Summary
| Test | Failure Rate | Runs | Classification | Priority |
|------|--------------|------|----------------|----------|
| auth.login.spec.ts:42 | 23% | 26 | Race condition | High |
| checkout.flow.spec.ts:15 | 12% | 18 | Shared state | High |
| utils.date.spec.ts:8 | 8% | 12 | Time-dependency | Medium |
## Detailed Findings
### auth.login.spec.ts:42 — "should redirect after login"
- **Failure rate:** 6/26 (23%)
- **Classification:** Race condition
- **Likely cause:** DOM not ready before assertion
- **Suggested fix:** Add `await page.waitForSelector('#dashboard')` before assertion
Prioritized Fix List
- High — High failure rate, critical path, or easy fix
- Medium — Moderate rate, non-critical
- Low — Low rate, edge cases
Integration with Other Skills
| Need |
Skill |
Usage |
| Parse JUnit/Allure |
qa-test-reporter |
Aggregate results from multiple runs |
| Fix broken selectors |
qa-test-healer |
Apply suggested waits/selectors |
| Create fix tasks |
qa-task-creator |
Generate tasks for flaky test fixes |
| Test strategy |
qa-test-strategy |
Document flaky mitigation in strategy |
Scope
Can do (autonomous):
- Parse CI/test results (JUnit XML, Allure, common formats)
- Compute pass rate per test over N runs
- Classify flaky tests into 4 patterns
- Scan test code for flaky signatures
- Produce flaky report and prioritized fix list
- Suggest fixes per pattern (from reference patterns)
Cannot do (requires confirmation):
- Modify test code directly (suggest only; qa-test-healer can apply)
- Access private CI systems without credentials
- Override classification without evidence
Will not do (out of scope):
- Execute tests or run CI
- Deploy or change production
- Guarantee fix effectiveness (suggestions are heuristic-based)
Quality Checklist
Troubleshooting
| Symptom |
Likely Cause |
Fix |
| No flaky tests found |
Too few runs, or tests truly stable |
Increase run count; verify CI artifacts parsed |
| All tests flagged |
Threshold too strict |
Raise pass-rate threshold; exclude known-broken tests |
| Wrong classification |
Heuristics insufficient |
Review code manually; add custom pattern to references |
| Missing CI data |
Format not supported |
Check qa-test-reporter; add parser for format |
| Fix doesn't work |
Root cause different |
Re-classify; try alternative pattern fixes |
| Pass rate 0% |
Test always fails |
Exclude from flaky report; treat as broken |
Reference Files
| Topic |
Reference |
| Flaky patterns with code examples and fixes |
references/flaky-patterns.md |
| CI history analysis methods |
references/ci-analysis.md |
1---2name: qa-flaky-detector3description: Analyze CI history and test execution data to identify flaky tests using 4-pattern classification -- race conditions, shared state, time-dependency, external dependencies -- with suggested fixes.4---56# QA Flaky Detector78## Purpose910Identify and classify flaky tests from CI history and test execution data. Flaky tests pass and fail intermittently for the same code, wasting CI time and masking real failures. This skill detects flakiness, classifies root causes into four patterns, and suggests targeted fixes.1112## Trigger Phrases1314- "Find flaky tests" / "Identify flaky tests"15- "Analyze CI history for flakiness" / "Flaky test report"16- "Why does this test fail sometimes?" / "Intermittent test failures"17- "Classify flaky test [name]" / "Flaky test patterns"18- "Suggested fixes for flaky tests" / "Fix flaky [test name]"1920## 4-Pattern Classification2122| Pattern | Description | Typical Causes | Suggested Fixes |23|---------|-------------|----------------|-----------------|24| **1. Race conditions** | Async timing, DOM not ready, API response order | Missing awaits, no explicit waits, parallel execution | Add explicit waits, `await` chains, `waitForSelector` |25| **2. Shared state** | Test order dependency, global state mutation, DB leftover | Global vars, singletons, uncleared DB/cache | Isolate tests, `beforeEach` cleanup, transactional rollback |26| **3. Time-dependency** | Timezone, date/time mocking, daylight saving | `new Date()`, `Date.now()`, hardcoded dates | Mock time (Jest `useFakeTimers`, `freezegun`), use fixed dates |27| **4. External dependencies** | Network calls, third-party APIs, file system | Live HTTP, external services, temp files | Mock/stub APIs, use fixtures, deterministic file paths |2829See `references/flaky-patterns.md` for detailed patterns with code examples and fixes.3031## Detection Methods3233### 1. CI History Analysis3435- Same test, different results across runs (pass/fail flip)36- Compare JUnit XML, Allure, or CI job logs over N runs37- Threshold: pass rate < 100% over 10+ runs → flag as flaky3839### 2. Statistical Analysis4041- Pass rate per test: `passes / (passes + failures)` over recent runs42- Confidence: more runs → higher confidence in flakiness43- Minimum runs: recommend 10+ for reliable detection4445### 3. Pattern Matching (Code-Based)4647- Scan test code for known flaky signatures:48 - No `await` on async operations49 - `setTimeout`/`setInterval` without cleanup50 - `new Date()` or `Date.now()` without mocking51 - Direct HTTP calls, file I/O52 - Shared globals, singletons53 - Missing `beforeEach`/`afterEach` cleanup5455See `references/ci-analysis.md` for CI history analysis methods.5657## Workflow58591. **Input** — CI artifacts (JUnit XML, Allure, GitHub Actions logs), test execution history, or test file paths602. **Collect** — Parse results from N runs; build pass/fail matrix per test613. **Detect** — Identify tests with pass rate < 100%624. **Classify** — Map each flaky test to one or more of the 4 patterns (code scan + heuristics)635. **Suggest** — Generate fix recommendations per pattern646. **Output** — Flaky test report, prioritized fix list6566## Output Deliverables6768### Flaky Test Report6970```markdown71# Flaky Test Report — [Project/Branch]7273## Summary74| Test | Failure Rate | Runs | Classification | Priority |75|------|--------------|------|----------------|----------|76| auth.login.spec.ts:42 | 23% | 26 | Race condition | High |77| checkout.flow.spec.ts:15 | 12% | 18 | Shared state | High |78| utils.date.spec.ts:8 | 8% | 12 | Time-dependency | Medium |7980## Detailed Findings8182### auth.login.spec.ts:42 — "should redirect after login"83- **Failure rate:** 6/26 (23%)84- **Classification:** Race condition85- **Likely cause:** DOM not ready before assertion86- **Suggested fix:** Add `await page.waitForSelector('#dashboard')` before assertion87```8889### Prioritized Fix List90911. **High** — High failure rate, critical path, or easy fix922. **Medium** — Moderate rate, non-critical933. **Low** — Low rate, edge cases9495## Integration with Other Skills9697| Need | Skill | Usage |98|------|-------|-------|99| Parse JUnit/Allure | qa-test-reporter | Aggregate results from multiple runs |100| Fix broken selectors | qa-test-healer | Apply suggested waits/selectors |101| Create fix tasks | qa-task-creator | Generate tasks for flaky test fixes |102| Test strategy | qa-test-strategy | Document flaky mitigation in strategy |103104## Scope105106**Can do (autonomous):**107- Parse CI/test results (JUnit XML, Allure, common formats)108- Compute pass rate per test over N runs109- Classify flaky tests into 4 patterns110- Scan test code for flaky signatures111- Produce flaky report and prioritized fix list112- Suggest fixes per pattern (from reference patterns)113114**Cannot do (requires confirmation):**115- Modify test code directly (suggest only; qa-test-healer can apply)116- Access private CI systems without credentials117- Override classification without evidence118119**Will not do (out of scope):**120- Execute tests or run CI121- Deploy or change production122- Guarantee fix effectiveness (suggestions are heuristic-based)123124## Quality Checklist125126- [ ] Pass rate calculated over sufficient runs (≥10 recommended)127- [ ] Each flaky test classified into at least one pattern128- [ ] Suggested fixes match pattern and reference examples129- [ ] Report includes test name, file:line, failure rate, classification130- [ ] Prioritized fix list ordered by impact131- [ ] No hardcoded credentials; CI access from user/env132133## Troubleshooting134135| Symptom | Likely Cause | Fix |136|---------|--------------|-----|137| No flaky tests found | Too few runs, or tests truly stable | Increase run count; verify CI artifacts parsed |138| All tests flagged | Threshold too strict | Raise pass-rate threshold; exclude known-broken tests |139| Wrong classification | Heuristics insufficient | Review code manually; add custom pattern to references |140| Missing CI data | Format not supported | Check qa-test-reporter; add parser for format |141| Fix doesn't work | Root cause different | Re-classify; try alternative pattern fixes |142| Pass rate 0% | Test always fails | Exclude from flaky report; treat as broken |143144## Reference Files145146| Topic | Reference |147|-------|-----------|148| Flaky patterns with code examples and fixes | `references/flaky-patterns.md` |149| CI history analysis methods | `references/ci-analysis.md` |