agentleFS
Maxrall-IncMaxrall-Inc/nexrall-skills/skills/flaky-test-detector/SKILL.md

flaky-test-detector

Skill0 starsChanged 3 months agoMITView on GitHub

Diagnose tests that pass and fail non-deterministically, instead of blaming the code under test or "fixing" the test. Use when a test fails sometimes but not others, when the user says a test is "flaky", "unstable", "passes locally but fails in CI", or when the same test gives different results on repeated runs.

3 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

5 rules. 0 are common, 4 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 3 edited versions we read keep these.

  • 4

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Run the failing test in isolation, several times, and record the outcomes.

    line 20
  2. Distinctive:

    Do not change the assertion to something looser just to make it green.

    line 67
  3. Very specific:

    Do not skip the test (it.skip, .only on another, pytest.mark.skip).

    line 68
  4. Distinctive:

    Do not delete the test. A flaky test still guards something.

    line 69
  5. Distinctive:

    If you genuinely cannot reproduce the flake after several isolated runs, say so and report what you ran — do not invent a cause.

    line 81

“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “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 Detector

A test that fails intermittently is worse than a test that always fails: it erodes trust in the whole suite, and the natural instinct — "tweak it until it passes" — usually hides a real race, a shared-state bug, or a broken assumption. This skill diagnoses why a test is flaky before anything is changed.

First: prove it is flaky before touching anything

Run the failing test in isolation, several times, and record the outcomes. A single failure is not flakiness — it may be a genuine bug that only manifests on a particular input.

for i in 1 2 3 4 5; do <run-just-this-test>; echo "exit=$?"; done
  • Fails every time → not flaky; treat it as a real bug (use the test-integrity-guard skill instead of loosening it).
  • Passes/fails inconsistently → flaky; continue below.

The three causes, in order of likelihood

1. Shared state between tests

The most common cause. Tests that mutate a shared store, cache, database, or in-process singleton leak into each other. Evidence to look for:

  • The test passes in isolation but fails when the whole file/suite runs.
  • Two tests write to the same fixture, temp file, or module-level variable.
  • An eviction/cache keyed by insertion order (LRU) that a "touched" entry doesn't refresh — the test count looks wrong because entries weren't evicted in the order assumed.

Fix the isolation, not the assertion: give each test its own fixture/DB/ temp dir, or reset shared state in a beforeEach/afterEach.

2. Timing or ordering assumptions

  • The test waits a fixed sleep instead of an event/condition.
  • It assumes async work finishes by the time the next line runs.
  • Two tests race on the same resource and the winner varies.

Fix by waiting on a condition or sequencing explicitly — not by lengthening the sleep (that only lowers the failure rate, it doesn't remove it).

3. Environment nondeterminism

  • Iteration order of a hash map / object keys that isn't guaranteed.
  • Reliance on locale, timezone, clock, or filesystem readdir order.
  • A value derived from a real network/clock that changes between runs.

Fix by pinning the source of nondeterminism (sort before asserting, inject a fixed clock, freeze the map order).

What NOT to do

  • Do not change the assertion to something looser just to make it green.
  • Do not skip the test (it.skip, .only on another, pytest.mark.skip).
  • Do not delete the test. A flaky test still guards something; silencing it removes the guard.

Output format

Diagnosis: shared state | timing | environment
Evidence: <the specific line or behavior that proves it>
Root cause: <one sentence>
Fix: <change to isolation/sequencing/determinism — not to the assertion>

If you genuinely cannot reproduce the flake after several isolated runs, say so and report what you ran — do not invent a cause.

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.