Skip to content
Skills Library
Programming · Testing

flaky-test-detangler

/flaky-test-detangler

Root-causes intermittently failing tests and eliminates the hidden dependency at its source instead of retrying around it. Use when a test passes locally but fails in CI, goes green on a CI re-run, fails roughly one run in ten, or is already tagged "flaky." Do NOT use when the task is to design the fake or stub that replaces a real dependency - use mock-stub-designer instead.

Repository
skills ↗
Licence
MIT
Last repository change
13.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 13.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Root-causes intermittently failing tests and eliminates the hidden dependency at its source instead of retrying around it. Use when a test passes locally but fails in CI, goes green on a CI re-run, fails roughly one run in ten, or is already tagged "flaky." Do NOT use when the task is to design the fake or stub that replaces a real dependency - use mock-stub-designer instead.

Triggers from the description

flaky.
Original author description

Root-causes intermittently failing tests and eliminates the hidden dependency at its source instead of retrying around it. Use when a test passes locally but fails in CI, goes green on a CI re-run, fails roughly one run in ten, or is already tagged "flaky." Do NOT use when the task is to design the fake or stub that replaces a real dependency - use mock-stub-designer instead.

How it works

  1. Workflow
  2. Worked example
  3. Deliverable
  4. Quality bar
  5. Do NOT
Original SKILL.md headings · 55 lines, 765 words
SKILL.md preview
---
name: flaky-test-detangler
description: Root-causes intermittently failing tests and eliminates the hidden dependency at its source instead of retrying around it. Use when a test passes locally but fails in CI, goes green on a CI re-run, fails roughly one run in ten, or is already tagged "flaky." Do NOT use when the task is to design the fake or stub that replaces a real dependency - use mock-stub-designer instead.
metadata:
  title: "Flaky Test Detangler"
---
# Flaky Test Detangler

A flaky test is not random - it is a hidden dependency on something you did not control (order, timing, shared state, a real clock, or a real network). Your job is to name that dependency and remove it, never to add a retry.

## Workflow

1. **Reproduce before theorizing.** Never diagnose from a single failure. Run the suspect test 100x in isolation, then 100x inside the full suite. Failing only in the suite means cross-test contamination; failing alone means the test owns the flake.
2. **Randomize order and capture the seed.** Run with randomized order (Jest `--shuffle`, RSpec `--order random`, pytest-randomly) and record the failing seed plus the order so the failure is reproducible. This seed is your gating evidence - do not accept any fix until it makes the captured seed pass deterministically.
3. **Kill fixed-time waits.** The top cause is waiting on a sleep instead of a condition. Replace `setTimeout`/`sleep` with explicit waits on observable state: Playwright auto-waiting locators and `expect.poll`, Cypress retry-ability, awaitility on the JVM. Never assert immediately after firing an async action.
4. **Isolate shared mutable state.** Tests that pass alone but fail together share a singleton, a module-level cache, a seeded row, an unrolled-back transaction, an env var, or the system clock. Make each test set up and tear down its own world: wrap DB tests in a per-test transaction that rolls back, or truncate between tests.
5. **Freeze the clock and cut the network.** Pin time with fake timers (`jest.useFakeTimers`, sinon, freezegun) so midnight and DST cannot break a test. Replace live outbound HTTP with a controlled stub - a test hitting a real endpoint is flaky by definition. When the stub or fixture itself needs designing, hand that off to mock-stub-designer; here you only require that the dependency is no longer real.
6. **Remove order assumptions.** Never assume insertion order from a hash, set, or unordered query - sort before asserting.
7. **Quarantine only what you cannot yet fix.** Tag a confirmed-flaky test as skipped-but-still-running (non-blocking) with a linked ticket, an owner, and a deadline, so you keep collecting failure data. Quarantine is a holding cell, not a verdict.
8. **Stop at the root cause.** Close the case when you can name the dependency and the captured seed passes deterministically. If 500x of looping yields no repro and the test guards critical behavior, ship structured logging and the failing seed to CI artifacts instead of deleting it. Delete a test only when it asserts nothing meaningful or duplicates coverage.

## Worked example

The most common flake, and its fix:

Bad - passes whenever the save completes within 2 seconds, fails on a loaded CI runner:

```js
fireEvent.click(saveButton);
await new Promise((r) => setTimeout(r, 2000)); // "give it time to save"
expect(screen.getByText('Saved')).toBeInTheDocument();
```

Good - waits on the observable condition, fails only when saving is actually broken:

```js
fireEvent.click(saveButton);
await waitFor(() => expect(screen.getByText('Saved')).toBeInTheDocument());
```

The bad version encodes a hidden timing dependency ("the save always finishes in under 2s on my machine"). The good version removes the dependency instead of padding it - no sleep survives, and the test's pass/fail now tracks the behavior it names.

## Deliverable

Produce a fix PR plus a short root-cause note that names the hidden dependency in one sentence (order / timing / shared state / clock / network), records the captured failing seed and order, and shows the rerun evidence (e.g. 100/100 passes on the previously failing seed). If the test is quarantined instead of fixed, the note carries the ticket link, owner, and deadline.

## Quality bar

- You can name the controlled dependency in one sentence (order / timing / shared state / clock / network).
- The previously failing seed and shuffled order now pass deterministically across at least 100 reruns.
- The fix removed a hidden dependency; it added no new `sleep`, no new retry, and no widened timeout.
- Any quarantined test has a ticket, an owner, and a deadline - not an open-ended skip.

## Do NOT

- Do NOT add an auto-retry or rerun as the fix. CI auto-retry is a last-resort bandage that hides cost; track retry rate as a quality metric, never as the solution.
- Do NOT add or extend arbitrary `sleep`/`setTimeout` to "stabilize" a test - ban this in review.
- Do NOT diagnose or declare a fix from a single run without a captured failing seed.
- Do NOT delete a flaky test that guards real behavior just to make CI green.
- Do NOT design the replacement mock/stub/fixture here - that is mock-stub-designer's job.

Versions

The database has no other skills named flaky-test-detangler.

Database snapshot: 13.11.2026 · package version 6381d44a7980 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 90fix-flaky-test
    Use when a ticket reports an intermittently failing test — passes sometimes, fails others, or fails in CI but not locally. Invoke for "this test is flaky", "fix the intermittent failure in X", or "the suite is non-deterministic". Fix the root cause — in the test or in the…
  • 100fix-flaky-tests
    Use when a test fails intermittently in CI — classify the intermittency, work from the real CI error, fix the root cause systemically, and verify with a green CI build rather than local runs.
  • 100fix-flaky-test
    Find and fix the cause of a test that fails only sometimes, such as on CI, on a slow machine or in a certain order. Use this for any intermittent failure, timeout in a test or "passes on rerun" situation. It replaces retries and longer sleeps with a proven fix.
  • 90debug-a-failing-test
    Finds out why a test fails and fixes the cause, not the test: reproduce it alone, read the error, narrow it down, fix, and prove it with a run. Use when a test fails, a check is red, a test is flaky, or the owner says the tests broke.
  • 100fix-flaky-tests
    Investigate and fix flaky or intermittently-failing tests in any framework and CI system — detects the framework, CI provider, and app profile, then applies the matching classification and fix patterns. Triggers on a flaky-test issue or CI URL, a test that "passes on retry" or…
  • 90Flaky Test Detector
    Detect, analyze, and fix flaky tests across any test runner. Use when tests intermittently fail in CI, tests pass locally but fail on CI, tests fail non-deterministically, or need to stabilize a flaky test suite. Also for 'flaky test', 'flaky', 'intermittent failure', 'unstable…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.