- Home
- Skills
- Testing & Debugging
- Flaky Test Surgeon
Works with the AI Agents you already use
Flaky Test Surgeon
by Badung
Diagnose, reproduce, and deterministically fix flaky tests across Jest, Vitest, Playwright, Pytest, Go, and JUnit without blind retries or sleeps.
$3.99
Flaky Test Surgeon
Example session with this skill installed
This Playwright test fails 10% of the time in CI:
await page.goto('/dashboard');
await page.waitForTimeout(500);
expect(await page.innerText('.status')).toBe('Ready');
- Read your context and instructions
- Compiled the flaky test surgeon
🩺 Flaky Test Diagnosis: F1 (Async Race / Arbitrary Sleep) (Confidence: High)
- Target:
dashboard.spec.ts - Failure Mechanism: The fixed 500ms sleep creates a race condition. On a loaded CI runner, the dashboard hydration or API response may take longer than 500ms, causing the assertion to check a stale or empty status.
1. Root Cause Evidence
- Line / Snippet:
await page.waitForTimeout(500); - Why it passes sometimes and fails other times: On local machines, the app typically hydrates in <200ms. In GitHub Actions, CPU throttling or network congestion pushes hydration to 600ms+, causing an intermittent mismatch.
2. Deterministic Fix (No Sleeps / No Blind Retries)
- await page.waitForTimeout(500);
- expect(await page.innerText('.status')).toBe('Ready');
+ const status = page.locator('.status');
+ await expect(status).toHaveText('Ready', { timeout: 10000 });
3. Stability Proof Command
npx playwright test dashboard.spec.ts --repeat-each=20 --workers=4
4. Secondary Risks Checked
- Ensure the
.statuselement is not a generic class used by other components. - Using
expect(locator).toHaveText()utilizes Playwright's built-in web-first assertions which poll automatically, removing the need for manual timeouts.
Next steps
- Replace the
waitForTimeoutwith the web-first assertion. - Run the provided stress command to confirm 20/20 passes.
- Check
globalSetupto ensure no shared state persists between these repeated runs.
Connects securely to your tools. The creator never sees your data.
About this skill
Tests that pass locally but fail in CI waste engineering hours and erode trust in the build. Most developers "fix" flakiness by adding arbitrary sleeps or blind retries, which only masks the underlying race conditions and state leaks.
This skill treats flaky tests as logic bugs, not ghosts. It analyzes test code and CI logs to identify the exact cause of non-determinism, providing a deterministic patch that removes the instability at the root.
What it does
- Root cause classification maps failures to one of seven specific flakiness classes including async races, shared mutable state, and clock drift.
- Deterministic patching replaces brittle logic like
sleep()orwaitForTimeout()with condition-based polling, barriers, or isolated fixtures. - Stress-test generation provides specific CLI commands for Playwright, Jest, Vitest, Pytest, and Go to prove the fix holds under heavy load or parallel execution.
- Quarantine management generates bounded quarantine blocks with owners and expiry dates when immediate removal from the critical path is necessary.
How it works
- Submit artifacts by pasting a failing test snippet, a CI stack trace, or a path to a local test file.
- Diagnosis identifies the failure mechanism, such as a race against CI render latency or a leaked global mock.
- Patching produces a
Before -> Afterdiff containing the stable code and necessary teardown logic. - Verification prescribes the exact runner-specific command (e.g.,
--repeat-each=20) to validate the fix.
Frameworks & tools
Supports Jest, Vitest, Playwright, Pytest, Go (go test), and JUnit. Compatible with standard CI runners like GitHub Actions and GitLab CI.
Why this beats prompting it yourself
Standard LLMs often suggest "increasing the timeout" as a first resort, which slows down your suite. This skill is hardcoded to forbid masking flakiness, forcing architectural fixes like clock freezing, ephemeral port binding, and proper async awaiting.
Use cases
- Fix tests that only fail when running in parallel or on loaded CI runners.
- Debug "midnight" failures caused by timezone assumptions or unseeded randomness.
- Clean up shared state leaks that cause tests to pass in isolation but fail in a full suite.
- Replace arbitrary delays with semantic, role-based assertions.
Known limitations
Does not support hardware-level non-determinism or flake caused by unstable third-party environments without an available mocking layer.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scan
Security scan passed 13 days ago
- Software
- Playwright
Node.jsvitestjest
Pure SKILL.md workflow, no external installation or network dependencies required.
Permissions
No special permissions declared or detected
What's inside
Frequently Asked Questions
New in Testing & Debugging
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Testing & Debugging.