Used by the Bug Fixer agent - procedure for proving a bug fix - a failing test that reproduces the bug first, the smallest fix, then reverting the fix to prove the test guards the bug. Covers condition-based waiting instead of sleeps, finding a polluting test, and flaky tests. Use when fixing a bug or a flaky test, not for general test writing.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Bug Fixer Regression Test?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/mhdaljuboori-bug-fixer-regression-test)
---
name: bug-fixer-regression-test
description: Used by the Bug Fixer agent - procedure for proving a bug fix - a failing test that reproduces the bug first, the smallest fix, then reverting the fix to prove the test guards the bug. Covers condition-based waiting instead of sleeps, finding a polluting test, and flaky tests. Use when fixing a bug or a flaky test, not for general test writing.
---
# Writing regression tests
A fix without a test is a guess that happens to pass today. The regression test is the proof that the bug existed, that the fix removes it, and that it will not come back unnoticed.
## The cycle
1. **Red.** Write a test that reproduces the bug. Run it. It fails.
2. **Check the failure.** Read the failure message. It must fail because of the bug: the wrong value, the exception from the report. A failure from a typo, a missing import or a broken fixture proves nothing. Fix the test until it fails for the right reason.
3. **Green.** Make the smallest change at the root cause. Run the test. It passes.
4. **Prove the guard.** Revert only the fix (keep the test). Run the test: it must fail again. Restore the fix: it passes. If the test passes with the fix reverted, it does not test the bug. Rewrite it.
5. **Wider check.** Run the tests near the change, then the full suite, then the type checker and linter the project uses. Compare with the results before your change so you report only what you caused.
How to revert and restore safely (the one place this lives):
- If the fixed file was clean before you started: `p=$(mktemp)`, `git diff -- <fixed file> > "$p"`, `git apply -R "$p"`, run the test, `git apply "$p"`, run again.
- If the file already had the user's own changes before you started, a file diff would capture theirs too. Do the revert proof by hand: undo only your hunk, run, put it back, run.
- Never use `git stash` (it is shared across worktrees and sessions) and never commit just to test.
## Writing the test
- **Place it where its neighbours live.** Same folder, naming and framework as the existing tests for that code. Read two or three of them first and copy their style.
- **Name it after the behaviour,** not the ticket: `returns empty list when user has no orders`, not `test bug 1234`. A link to the issue in a comment is fine.
- **Use the bug's real input.** The exact value, request or sequence from the minimal repro. Then add the nearest edge cases if cheap (empty, one, boundary).
- **Go through the real code path.** Mock only what is slow, external or random (network, clock, randomness). A test that mocks the function under test proves nothing.
- **Assert the outcome, specifically.** The exact value, the exact error type and message, the state after. Not "does not throw" when the bug was a wrong value. Not a snapshot regenerated without reading it.
- **The lowest level that shows the bug.** A unit test if the bug lives in one function; an integration test if it lives between components. An end-to-end test only when nothing smaller can show it.
- **Deterministic.** Fix the clock, seed the randomness, isolate the file system and database state. Clean up what you create.
## Waiting for things: conditions, not sleeps
A test that sleeps a fixed time is either slow or flaky, usually both.
- Wait for the **condition** you need: the element exists, the file is written, the queue is empty, the promise resolved, the log line appeared. Poll with a short interval and a generous overall timeout, and fail with a message that says what never happened.
- Prefer the framework's own wait helpers (`waitFor`, `expect.poll`, `eventually`, `assertEventually`, awaiting the returned promise or future).
- Fake time instead of waiting for it: fake timers, an injectable clock.
- A fixed delay is acceptable only when the behaviour under test is itself time based (a debounce, a timeout), and then document why that duration.
## Order-dependent failures
A test that passes alone but fails in the suite (or the reverse) is being affected by another test.
1. Confirm: run it alone, run the whole file, run the whole suite, run with randomised order if the runner supports it.
2. Find the polluter by bisecting the tests that run before it: run the first half of them plus the victim, then the half that still breaks it, until one test is left.
3. Look for the shared state it leaks: globals and singletons, module caches, environment variables, the current directory, files and database rows not cleaned up, fake timers or mocks not restored, servers left listening.
4. Fix the leak at the polluter (proper setup and teardown), and make the victim not depend on state it did not create.
More on timing, races and flaky tests: `reference/flaky-tests.md` in this skill's directory.
## Never
- Delete or loosen an assertion to make a test pass.
- Skip, quarantine or mark a test as expected-to-fail as the fix.
- Add retries or raise a sleep to hide a race.
- Change a test to match buggy behaviour.
- Claim it passes without running it and reading the output.
## When a test is truly impractical
Some bugs cannot be captured in an automated test at a sane cost: the repo has no test setup, the bug is in config, build, visuals or infrastructure, or it needs production-only conditions. Then say so plainly, explain why, and give the strongest other proof, named as such: a repro script run before and after, before/after output, an assertion added in the code. Never add a test framework or dependency to get a test; say so and use a repro script. Never silently skip the proof.