/ceh-testing:test-a-bug-fixfrom ceh-testing
Load this skill when a bug, crash, or regression is being fixed, before writing the fix: the smallest failing test first, proven red without the fix. Trigger on "fix this bug", fixing a fix record, a stack trace, a bug-fix PR with no test, or a first test for a reported bug.
Ships in ceh-testing. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
A bug is proof that a test was missing. The fix is the cheap half; the test that would have caught it is the deliverable. Write it first — a test written after the fix is written against the new code, not against the bug, and routinely passes on the broken version too.
The task is done when the reproducer failed with the bug's symptom before the fix, passes with it, fails again with the fix removed, and ships in the same commit as the fix.
Writing and running the tests that prove the fix is part of the fix, so the procedure below applies without being asked: the reproducer, the stash check, the sibling cases, and a bisect on the reproducer. Only a slow or paid run waits for a request: the full suite, coverage, mutation testing, or repeated passes over the whole suite. When one of those would help and was not requested, name the command and what it would reveal, and state what stays unverified.
Smallest input that triggers it. No fix on disk yet.
def test_parse_duration_rejects_bare_number():
with pytest.raises(ValueError):
parse_duration("30") # bug: silently returned timedelta(seconds=30)
Put it at the lowest level that reproduces it — unit if a unit reproduces it, integration only if the bug lives in the interaction. If it only reproduces end-to-end, say so: that usually means the unit boundary is in the wrong place, and it is worth reporting even if you do not move it.
At that level, call the code the way its callers do, through the public function or endpoint, and assert a literal expected value. A reproducer aimed at a private helper can go green while the caller still sees the bug.
It must fail, and fail with the bug's actual symptom. A test that errors on a typo, a missing fixture, or an import is not a reproduction — it is a broken test that happens to be red.
If it passes: you have not reproduced the bug. Do not proceed. Your model of the cause is wrong, the input is not the triggering one, or the bug needs state the test does not set up.
Minimal change that turns the test green. Fix only what the reproducer covers.
The step that gets skipped, and the only one that proves the test has value:
git stash # remove the fix, keep the test
<run the test> # MUST fail
git stash pop
Green with the fix removed means the test does not actually detect the bug — it asserts something that was already true. Rewrite it.
The reported input is one member of a class. Add the siblings from the same class — if "30"
failed, so will "", "abc", "30x", "-5m". One test per distinct class, not per value; see
design-test-cases for how to draw the classes.
Stop there. A bug fix is not a licence to test the whole module.
Same commit. A bug-fix commit with no test is incomplete — flag it in review.
In the hand-over, give the reproducer and each sibling a value line: <test> — protects: <behavior>; fails_when: <the defect returns>; why_new: <why no existing test caught it>. The
reproducer's why_new is the gap that let the bug ship.
The commit carries the footer Refs: fix/<stem>, the fix record's whole file stem, in the format
in references/fix-record-schema.md, when the cause is in this repo's code or config. Look for
the open record of the bug's functionality, status: diagnosed, in
.agents_workspace/product/fix/*.yaml (and the older fixes/ beside it), found as the format's
"Finding the record of a functionality" says, or a *.md with no YAML beside it, which
ceh-coding-conduct:find-root-cause leaves:
fix-record/v3 .yaml: run
uv run --script ${CLAUDE_SKILL_DIR}/scripts/artifact.py check <the record>.yaml first, and
stop on exit 1 with its errors. On the issue this fix closes, set fix, one tests item per
value line and status: fixed, set the record's status to the one its issues derive, then run
the same command with render, which writes the .md, and fix the YAML for each error it
lists. Never edit the generated .md.fix-record/v2 .yaml, which reports unchecked (exit 3): set fix, one tests item
per value line and status: fixed in its own form, and say in the reply that it went unchecked..md with no .yaml beside it (fix-record/v1): fill its Fix section with the value
lines and set status: fixed, in the v1 form.With none, create a new record,
.agents_workspace/product/fix/<YYYYMMDD-HHMMSS>-<functionality-slug>.yaml with the time from
one date +%Y%m%d-%H%M%S call, from assets/fix-record.template.yaml, holding one fixed issue
with the reproducer as its symptom and diagnosis.known_from_report naming where the report
gives the cause, previous: set to a closed record of the functionality, and plan: set from the
fixed file:line as the format says, then render it. On exit 2 or 3, or without uv, say in the reply that the record went unchecked and unrendered. The
commit says what changed, and the record keeps why, for whoever touches this code next.
A reproducer is not only a test; it is a decision procedure. If the behavior was correct at some earlier point, do not read the diff hoping to spot the cause — let git find the commit:
git bisect start HEAD <last-known-good-tag-or-sha>
git bisect run pytest tests/unit/test_parse_duration.py::test_parse_duration_rejects_bare_number
# TypeScript: git bisect run vitest run src/parse-duration.test.ts -t "rejects bare number"
git bisect reset
git bisect run needs an exit code, so the reproducer must be runnable at every commit in the
range — keep it in a file the bisect does not check out, or pass it via --rootdir / a stash-free
copy. Bisecting on a manual "does it look wrong" judgement instead of a scripted test is where this
technique goes wrong: dozens of steps, each one a chance to mark a commit incorrectly.
The commit it names is where the behavior changed, which is not always where the bug is — a commit can expose a latent defect written months earlier. Fix the defect, not the commit.
Two cases that need care: if the range spans a dependency or lockfile change, add uv sync (or the
equivalent) to the run command, otherwise every commit is tested against today's dependencies; and
mark commits that cannot build with git bisect skip rather than guessing good or bad.
Timing, ordering, concurrency, and environment bugs often will not fail on demand. Do not give up and ship untested — instead:
pytest --count=50, vitest --repeat 50) or under
randomized order/seed. Intermittent red is still a reproduction.close-test-risk-gaps for the concurrency and
idempotency recipes.Name the test after the behavior that was wrong, not the ticket or the fix.
| Bad | Good |
|---|---|
test_fix_1234 | test_parse_duration_rejects_bare_number |
test_bug_regression | test_refund_of_zero_leaves_balance_unchanged |
test_null_check | test_lookup_returns_none_for_unknown_key |
The name is what a future reader sees when the test breaks. test_fix_1234 tells them nothing and
invites deletion.
What SKILL.md sets; muted values are Claude Code's defaults
9 skills in this plugin
/close-test-risk-gapsLoad this skill when a feature works and is about to be called done: triage what a passing suite misses (concurrency, contract drift, performance, authorization, migrations). Trigger on "is this ready", "before I open the PR", "race condition"./design-test-casesLoad this skill when deciding which inputs and scenarios a test should cover, not how to wire the runner: partitions, boundaries, state transitions, properties, fuzzing, failing dependencies. Trigger on "what should I test", "cover the edge cases", or a test file with only a happy path./explore-app-for-bugsOther plugins' skills for the same job
npx claudepluginhub cheneeheng/ceh-claude-code-library --plugin ceh-testing