fixing-flaky-tests

fixing-flaky-tests is a skill for Claude Code, Codex from porcupine-md/jonggrang. It costs 26 tokens per session (810 once invoked), scanned A, original, MIT.

A guide for finding and fixing flaky tests, which pass or fail unpredictably without a code change. It covers timing dependencies, shared test data, and asynchronous work that continues after a test ends.

In plain words
What is it for?
Use it when tests fail intermittently or behave differently depending on timing or order. It helps diagnose race conditions, isolate test data, wait for asynchronous results, and close unfinished work.
Why use it?
It replaces fragile delays and shared state with checks for real conditions and proper cleanup. This makes test results more repeatable and prevents one test from affecting another.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it when tests fail intermittently or behave differently depending on timing or order. It helps diagnose race conditions, isolate test data, wait for asynchronous results, and close unfinished work.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/porcupine-md/jonggrang/fixing-flaky-tests
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add porcupine-md/jonggrang --skill fixing-flaky-tests
Clone the repo
git clone --depth 1 https://github.com/porcupine-md/jonggrang

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for fixing-flaky-tests

README.md
[![agentmods](https://agentmods.dev/badge/skills/porcupine-md/jonggrang/fixing-flaky-tests/github.svg)](https://agentmods.dev/skills/porcupine-md/jonggrang/fixing-flaky-tests)
Your own site
<a href="https://agentmods.dev/skills/porcupine-md/jonggrang/fixing-flaky-tests"><img src="https://agentmods.dev/badge/skills/porcupine-md/jonggrang/fixing-flaky-tests/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for fixing-flaky-tests

Your own site · 80×15
<a href="https://agentmods.dev/skills/porcupine-md/jonggrang/fixing-flaky-tests"><img src="https://agentmods.dev/badge/skills/porcupine-md/jonggrang/fixing-flaky-tests.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 26 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 810 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe. Third-party audits
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00026 $0.00810
Opus 5 $0.00013 $0.00405
Sonnet 5 $0.00005 $0.00162
Haiku 4.5 $0.00003 $0.00081

Measured 10d ago against content hash f4455e9790df, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-10, from the pricing page.

Security

Grade A, and why

fixing-flaky-tests scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 10d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/library/testing/fixing-flaky-tests/SKILL.md · 116 lines

How it starts

The opening of the file, as written. The whole thing — 116 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Root Cause Categories

1. Timing Dependency

// BUG: assumes operation completes within 100ms
await new Promise(r => setTimeout(r, 100));
expect(result).toBe('done');

// FIX: wait for the actual condition
await vi.waitFor(() => expect(result).toBe('done'), { timeout: 5000 });
// or
await waitFor(() => screen.getByText('Done'));

2. Test Pollution (Shared State)

// BUG: test 1 creates user, test 2 fails because user already exists
it('test 1', () => createUser({ email: '[email protected]' }));
it('test 2', () => createUser({ email: '[email protected]' })); // CONFLICT

// FIX: clean up after each test
afterEach(async () => {
  await db.user.deleteMany({ where: { email: '[email protected]' } });
});

// BETTER FIX: use unique values per test
const email = `test-${Date.now()}@example.com`;

3. Async Leak

// BUG: async operation continues after test ends
it('fetches data', () => {
  const result = [];
  fetchData().then(data => result.push(data)); // not awaited!
  // test ends, but fetchData is still running
  // it might complete and affect the next test
});

// FIX: always await async operations
it('fetches data', async () => {
  const data = await fetchData();
  expect(data).toBeDefined();
});

4. Global State / Singleton Pollution

// BUG: EventEmitter accumulates listeners across tests
const emitter = new EventEmitter(); // global singleton

// FIX: reset global state in beforeEach/afterEach
beforeEach(() => { emitter.removeAllListeners(); });

// BETTER: inject dependencies instead of using singletons

5. Order Dependency

// BUG: test B relies on state set by test A
describe('CartService', () => {
  it('test A: adds item', () => { cart.add(item); });
  it('test B: removes item', () => { cart.remove(item.id); }); // fails if A didn't run
});

// FIX: each test is self-contained
describe('CartService', () => {
  beforeEach(() => { cart = new Cart(); }); // fresh state
  it('test B: removes item that exists', () => {
    cart.add(item);       // set up in this test
    cart.remove(item.id);
    expect(cart.items).toHaveLength(0);
  });
});

Read the full file on GitHub · 116 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 10d ago First seen · 116 lines · 26 tokens per session scan A f4455e9790df

Subscribe to this mod's changes

fixing-flaky-tests is a skill published in the GitHub repository porcupine-md/jonggrang (11 stars, last pushed 2d ago), licensed MIT. It adds 26 tokens to every session and 810 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories