---
name: "regression-test-writer"
description: "Turn a reported bug into the smallest test that fails for the real reason before the fix and passes afterward. Use when reproducing a defect, reviewing a bug fix with no guard test, converting an incident into permanent coverage, or preventing a previously fixed edge case from returning."
allowed-tools: "Read, Grep, Glob, Edit, Bash"
version: 1.0.0
---

Produce a minimal, trustworthy test that fails on the bug and protects the behavior after the fix.

## Workflow

1. **Restate the invariant.** Convert the report into one sentence: under input and state X, behavior Y must occur and Z must not occur. Separate symptoms from the actual contract.
2. **Trace the failing path.** Read the production code, existing tests, logs, issue text, and recent changes. Identify the smallest entry point that still crosses the component responsible for the failure.
3. **Choose the lowest reliable layer.** Prefer unit, then component/integration, then contract, then end-to-end. Do not choose a low layer if mocks remove the database, serializer, concurrency, timezone, or framework behavior that caused the bug.
4. **Minimize the fixture.** Keep only state required to trigger the defect. Use existing builders and factories. Replace timestamps, randomness, network, and concurrency with controlled inputs without changing the failure mechanism.
5. **Write the test against behavior.** Name the bug condition and expected outcome. Assert outputs, persisted state, side-effect count, or observable error—not private method calls or incidental implementation.
6. **Prove the test is red.** Run the focused test against the broken state when available. Confirm it fails at the intended assertion, not from setup, missing dependencies, or an unrelated error. Record the failure signal.
7. **Apply or verify the fix.** If the requested scope includes implementation, make the smallest fix and rerun. Otherwise leave the failing test and report that it correctly reproduces the bug.
8. **Check for false confidence.** Temporarily weaken or remove the production fix when safe, or otherwise demonstrate the test distinguishes broken from correct behavior. Run the relevant surrounding suite to catch fixture pollution.

> [!WARNING]
> A test that was never observed failing may document the fixed implementation without guarding the defect. Prove red for the expected reason before trusting green.

## Output

Report:

- the behavioral invariant and chosen test layer
- the new or updated test file
- the focused command used to reproduce it
- red-state evidence: expected assertion and observed failure
- green-state and surrounding-suite results when a fix is present
- any part of the original report that could not be reproduced

---

_Source: https://agentscamp.com/skills/testing/regression-test-writer — Skill on AgentsCamp._
