agentleFS
WST2002WST2002/claude-code-skills/skills/flaky-test-fixer/SKILL.md

flaky-test-fixer

Skill4 starsChanged 27 days agoMITView on GitHub

Use when a test passes and fails without code changes, fails only in CI or only when run with other tests, times out intermittently, or the team is retrying, skipping or quarantining unreliable tests — unit, integration or end-to-end.

2 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Reproduce the flake: Run the test many times, alone and with the full suite:

    line 14

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Flaky Test Fixer

Overview

A flaky test has a cause that can be found: timing, shared state, order, environment or randomness. Reproduce the flake reliably, identify which of those it is, and fix the cause. Retries and longer timeouts hide the problem; they do not fix it.

Method

  1. Reproduce the flake. Run the test many times, alone and with the full suite:
    • Jest/Vitest: run in a loop, or --runInBand vs parallel.
    • pytest: pytest -x --count=50 (pytest-repeat) and random order with pytest-randomly.
    • Playwright: npx playwright test <file> --repeat-each=20 --workers=4.
    • JUnit: @RepeatedTest(50) on the test, or run the suite in a shell loop. Record the failure rate and the exact error.
  2. Classify using the table below. Compare passing and failing runs: logs, timing, order, environment.
  3. Confirm the cause with a deliberate change that makes it fail every time (shuffle order, add a delay, slow the network, change the time zone).
  4. Fix the cause, then rerun the loop until there are zero failures across many runs.
  5. Remove any retries, sleeps or skips added as workarounds.

Causes and fixes

CauseSignsFix
Timing / asyncPasses when slow, fails when fast; waitForTimeout, missing awaitAwait the real condition (event, response, visible element); add missing awaits
Shared stateFails only with other tests; order mattersFresh data per test, reset singletons, mocks and module state in beforeEach, isolate database (transaction rollback or unique data)
Test orderFails with random orderingRemove dependence on data created by earlier tests
Time and datesFails near midnight, month end, DST, other time zonesFreeze or inject the clock; use UTC; avoid new Date() in assertions
RandomnessDifferent inputs per runSeed the generator or use fixed fixtures
ConcurrencyParallel workers clash on ports, files, accountsUnique ports, temp directories, accounts per worker
External servicesNetwork calls to real third partiesMock third parties; use local containers for owned dependencies
EnvironmentOnly in CICompare versions, CPU speed, locale, time zone, screen size, env vars
Resource leaksFails late in long runsClose servers, connections, timers, listeners in afterEach

Output

Test: <name and file>
Failure rate: <before> → <after> over <N> runs
Cause: <category and the specific line or condition>
Fix: <change made>

Common mistakes

  • Adding retries or increasing timeouts and calling it fixed.
  • Running the test once after the fix.
  • Fixing the test when the flake is a real race condition in product code.
  • Quarantining tests with no owner or follow-up date.

Made by Wageesha Tripathi · LinkedIn · Email · More skills

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.