Flaky Test Analyzer — independently scanned and version-tracked by SaferSkills.
SaferSkills independently audited Flaky Test Analyzer (Agent Skill) and scored it 100/100 (green). The audit ran 55 deterministic rules across Security, Supply Chain, Maintenance, Transparency, and Community; it found 0 high-severity and 0 lower-severity findings. The full rule-by-rule trace and per-finding evidence are below. Free, methodology-open.
Findings & checks · 0 flagged
Every scanned point with the score it earned and what moved between them.
First recorded scan — no prior version to compare against.
The primary manifest — the file an agent reads to learn what this artifact does.
This skill directs the agent to diagnose flaky tests — tests that sometimes pass and sometimes fail without any code changes. It examines the test code, the code under test, and the failure patterns to identify the root cause category (timing, shared state, ordering, network, randomness, etc.) and then suggests targeted fixes that make the test deterministic.
Use this when a test is unreliable in CI, when a test passes locally but fails on the CI server, or when a test fails intermittently with no obvious pattern.
Copy this file to .agents/skills/flaky-test-analyzer/SKILL.md in your project root.
Then ask:
Provide:
Add the instructions below to your .cursorrules or paste them into the Cursor AI pane. Provide the test code and failure output.
Paste the test file, the failure message, and any relevant context. Ask Codex to follow the instructions below.
When asked to diagnose a flaky test, follow this process:
Before analyzing, ensure you have:
beforeEach, afterEach, beforeAll, and afterAll hooksIf any of these are missing, ask for them.
Check for each of these flakiness patterns in order:
Timing and async issues
setTimeout or setInterval with hardcoded delays that may not be long enoughawait on async operationsjest.useFakeTimers) mixed with real timersShared state and isolation
Test ordering dependencies
External dependencies
Race conditions in the code under test
Promise.all with side effects that interfereTest framework issues
After identifying which category applies, pinpoint the exact line(s) causing the flakiness. Explain:
Provide a concrete, specific fix. Common fixes include:
setTimeout(() => ..., 100) with waitFor(() => ...) or vi.runAllTimers()afterEach(() => { jest.clearAllMocks(); db.cleanup(); })jest.useFakeTimers() consistently and advance time explicitlyawait to async operations## Flaky Test Diagnosis
### Test
`[test name]` in `[file path]`
### Failure Pattern
[How often it fails, under what conditions]
### Root Cause Category
[Timing / Shared state / Test ordering / External dependency / Race condition / Other]
### Root Cause
[2–3 sentences explaining exactly why the test is flaky — what assumption it makes and why that assumption sometimes fails]
### The Problematic Code
[Quote the specific lines that cause the flakiness]
### Fix
[The specific change(s) to make the test deterministic, with code]
### Why This Fix Works
[1–2 sentences explaining why the fix eliminates the non-determinism]
### Prevention
[1 sentence on how to avoid this class of flakiness in future tests]Input to Agent:
"Use the Flaky Test Analyzer skill. This test fails about 1 in 4 runs in CI:
>
``ts it('sends a welcome email after registration', async () => { await registerUser({ email: '[email protected]', password: 'abc123' }); setTimeout(() => { expect(emailService.send).toHaveBeenCalledWith({ to: '[email protected]', subject: 'Welcome!' }); }, 200); }); ``"Output from Agent:
## Flaky Test Diagnosis
>
### Testsends a welcome email after registration—user.test.ts
>
### Failure Pattern Fails ~25% of runs, more often in CI than locally.
>
### Root Cause Category Timing / async issue
>
### Root Cause TheexpectinsidesetTimeoutis not awaited, so Jest considers the test done as soon asregisterUserresolves — the assertion runs 200ms later, after Jest has already moved on. When the event loop is busy (common in CI), the 200ms delay may not be enough, and even when it fires, Jest may no longer be tracking it.
>
### The Problematic Code ``ts setTimeout(() => { expect(emailService.send).toHaveBeenCalledWith(...); }, 200); ``>
### Fix ``ts it('sends a welcome email after registration', async () => { await registerUser({ email: '[email protected]', password: 'abc123' }); await waitFor(() => { expect(emailService.send).toHaveBeenCalledWith({ to: '[email protected]', subject: 'Welcome!' }); }); });`IfwaitForisn't available (non-React project), usejest.runAllTimers()withjest.useFakeTimers()` or poll manually with a small helper.
>
### Why This Fix Works waitFor repeatedly retries the assertion until it passes or a timeout is reached, making the test resilient to variable execution timing.>
### Prevention Never putexpect()calls inside a rawsetTimeout— always await the operation that triggers the side effect, or usewaitFor.
~30 seconds. Free. No account. Every finding cites a rule and a line of evidence.