# Flaky Test Surgeon

> Diagnose, reproduce, and deterministically fix flaky tests across Jest, Vitest, Playwright, Pytest, Go, and JUnit without blind retries or sleeps.

Flaky Test Surgeon is a paid AI agent skill on Agensi by Badung, in Testing & Debugging. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: $3.99 (one-time purchase)
- Creator: [Badung](https://www.agensi.io/creators/badung)
- Category: [Testing & Debugging](https://www.agensi.io/skills/testing-debugging)
- Version: 1.0
- Last updated: 2026-11-22
- Security: scan passed (2026-11-22); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/flaky-test-surgeon
- Tags: testing, jest, playwright, pytest, vitest, ci-cd, debugging, qa

## 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()` or `waitForTimeout()` 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
1. **Submit artifacts** by pasting a failing test snippet, a CI stack trace, or a path to a local test file.
2. **Diagnosis** identifies the failure mechanism, such as a race against CI render latency or a leaked global mock.
3. **Patching** produces a `Before -> After` diff containing the stable code and necessary teardown logic.
4. **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.

## Requires

- Playwright
- Node.js
- vitest
- jest

Pure SKILL.md workflow, no external installation or network dependencies required.

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the Flaky Test Surgeon skill from Agensi" and describe your task.
3. Buy it on the listing or let your agent ask you first; your agent then loads it from Agensi when it needs it. Every paid skill has a money-back guarantee: https://www.agensi.io/docs/money-back-guarantee

## Frequently asked questions

### How does this skill fix flakiness without just increasing timeouts or adding retries?

The skill uses logic-based patching to replace arbitrary sleeps and retries with deterministic solutions like condition-based polling, clock freezing, and isolated fixtures that address the root race condition.

### Which testing frameworks and languages are supported?

It provides native support for Jest, Vitest, Playwright, Pytest, Go, and JUnit, making it compatible with most modern web and backend testing stacks.

### Do I need to give the agent full access to my repository to use this skill?

Simply provide the failing test code and the associated CI logs; the skill will then classify the failure type and generate a precise 'Before -> After' code diff for you to apply.

### Can this skill help me prove a test is actually fixed before I commit the code?

Yes, the skill generates framework-specific stress-test commands (such as --repeat-each for Playwright) to help you verify that the fix remains stable under heavy load.

### Are there any types of test failures that this skill cannot resolve?

This skill is designed for software-level logic bugs; it cannot fix flakiness caused by unstable third-party APIs or hardware-level issues where a mocking layer is not available.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
