deflake

Stabilize flaky tests with minimal assertion-preserving fixes that remove nondeterminism.

27.5k|3.0k|Updated Jun 26, 2025
One-click install
npx skills add https://github.com/QwenLM/qwen-code --skill deflake
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: deflake
Source: https://github.com/QwenLM/qwen-code/tree/main/.qwen/skills/deflake
Command: npx skills add https://github.com/QwenLM/qwen-code --skill deflake

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Flaky tests that pass and fail on the same commit erode trust in CI and waste developer time on reruns. This Skill diagnoses the nondeterminism behind a named flaky test and applies the smallest fix that makes it deterministic without weakening or deleting any assertion.

Core Features & Use Cases

  • Four allowed fix strategies: raise timeout or poll budgets, replace fixed sleeps with explicit condition waits, make randomness and time deterministic via seeded RNG or fake timers, and isolate shared resources like ports or tempdirs.
  • Strict guardrails: never skips, deletes, or loosens a test; if the failure looks like a real product bug, it writes a failure report and stops for human review.
  • Verification loop: reruns the test file repeatedly with vitest to prove determinism, then runs the standard build, typecheck, and lint gate.
  • Use Case: A vitest test times out under CI contention because it polls with a fixed count of setImmediate turns; the Skill replaces the loop with a real wall-clock budget and confirms the test passes on repeated runs.

Quick Start

Ask the agent to deflake the named failing test from the issue, keeping every assertion intact and verifying it passes on repeated runs.

Frequently Asked Questions about deflake

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix a flaky test without deleting it?

Identify the source of nondeterminism, then apply the smallest targeted fix: raise the timeout budget, await the real condition instead of sleeping, seed randomness or fake timers, or isolate shared resources. Every assertion and input stays exactly as written.

How to fix vitest tests that time out in CI?

Give the test a generous per-test testTimeout as the third argument to it(), or replace a fixed-iteration poll loop with a real wall-clock budget. Fixed counts of setImmediate turns elapse in milliseconds and race real I/O under CI contention.

Why is adding a retry wrapper around a flaky test a bad idea?

Retries hide the flake instead of fixing it and can mask a real intermittent product bug. The correct approach is to remove the nondeterminism itself through timing, randomness, or isolation fixes while preserving every assertion.

Can fake timers make time-dependent tests deterministic?

Yes. Using vi.useFakeTimers(), mocking Date.now, or seeding the RNG pins values that would otherwise drift with the real clock or Math.random, making the test produce the same result on every run.

What should I do when a flaky test failure is actually a real bug?

Stop and document the finding in a failure report instead of patching the test. If none of the four allowed fixes applies or the failure looks like genuine intermittent product behavior, a human should investigate the underlying bug.