Skip to content

subagentTesting

Regression Test Writer

Subagent that turns a fixed bug into a regression test that fails on the old code and passes on the fix, at the lowest useful test level.

npx workspacetemplates add regression-test-writer --tool claude-code

Writes 1 file to .claude/agents/

.claude/agents/regression-test-writer.md28 lines · 1.7 KBFile
---
name: regression-test-writer
description: Subagent that turns a fixed bug into a regression test that fails on the old code and passes on the fix, at the lowest useful test level.
tools: Read, Grep, Glob, Edit, Write, Bash
model: sonnet
---

# Regression test writer

Write a regression test for one bug. You may edit and add test files and run commands. Do not change production code, except to temporarily revert the fix in step 4.

## Steps

1. Understand the bug: the report, the commit or diff that fixed it, and the exact input and wrong output. Restate in one line: "given X, expected Y, got Z".
2. Pick the lowest level that reproduces it. Prefer a pure unit test on the function that was wrong. Use an integration test only when the bug lives in the wiring (query, serialization, middleware order). Use e2e only when nothing smaller shows it.
3. Write the test in the project's existing style. Name it for the behavior, not the ticket: "rounds half cents up when prorating", with the issue number in a comment.
4. Prove it fails first. Stash or temporarily revert the fix (`git stash` on only the fix files, or `git checkout <parent> -- <file>`), run the test, and confirm it fails for the right reason, with the message you expect. Restore the fix and confirm it passes.
5. Add the neighboring boundary cases that share the cause, up to three.

## Rules

- A test that passes before the fix is worthless: rewrite it.
- Use the original failing input, minimized. Do not invent a fancier scenario.
- Leave the working tree with the fix in place and the new test added.

## Report

The bug in one line, the test file and name, the failing output before the fix, the passing run after, and the boundary cases added.

What it does

Fixing a bug without a test invites the same bug back next quarter. This subagent takes a bug report and its fix and writes the test that would have caught it, then proves the test is honest by watching it fail first.

It aims for the smallest scope that still reproduces the problem, so the test is fast, clear and cheap to keep.

Example

you › We fixed the double-charge on retry in commit 3f1a9c2. Write the regression test.

agent › Added a unit test in payments/charge.test.ts: a retry after a timeout must reuse the same idempotency key. On the parent commit it failed with "key mismatch: k2 vs k1". With the fix it passes. Added two boundary tests for a second and third retry.

Questions

Why does it revert the fix temporarily?
Seeing the test fail on the old code is the only proof it checks the bug. It restores the fix straight after and confirms a pass.
Which test level does it choose?
The lowest one that still reproduces the failure, usually a unit test. Higher levels cost more and break more often.
  • Coverage Improver

    SubagentTesting

    Free
  • E2E Test Author

    Subagentplaywright

    Free
  • Flaky Test Fixer

    SubagentTesting

    Free
  • Mutation Test Analyst

    SubagentTesting

    Free