/testectomy:testectomyfrom testectomy
Gates new/changed tests at write time and prunes test suites on request. Writes SPEC.md files for intent, keeps only tests that external boundaries, money, security, concurrency, parsers, real regressions, or public contracts require.
Ships in testectomy. 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.
Tests that restate the implementation are a second, worse copy of the logic.
Intent is not: it lives in requirements, not in code, and nothing in the code
can validate it. This skill moves intent into SPEC.md files that humans own
and agents read, and keeps executable tests only where reading code cannot
replace running it.
Three layers, cheapest first:
| Layer | What it holds | Who checks it |
|---|---|---|
SPEC.md | Rules, examples, non-goals, open questions | Agent reads it before and after every change |
| Types / schemas | Shapes, exhaustiveness, nullability | Compiler |
| Executable tests | Only rules that pass the keep bar | Test runner, scoped to touched rules |
For the spec file format, read spec-format.md. For expect-test tooling per language, read expect-tests.md.
| Mode | When | What it does |
|---|---|---|
| Gate | Any time you write, change or review a test | Rejects low-value tests before they land. Never deletes. |
| Pass | The user asks to audit, prune or rebuild tests for a repo or path | The workflow: specs, verdicts, deletions, gaps, report |
| Campaign | The user asks to prune one whole subsystem in a large repo | The pass, split into lanes with a ledger and an independent preservation review. Read CAMPAIGN.md first. |
Pass and campaign delete tests, so they run only when the user asked for them. The gate applies on its own.
Before adding or changing any test, answer these. A missing answer means don't add it yet:
SPEC.md, name the rule ID; a test with no
Check: test rule needs one first, and the rule must meet the
keep bar.Two requests produce junk by reflex. When asked to remove or move something, don't add tests asserting it's gone. When a test is flaky, don't add a sleep, a retry or a longer timeout: find the race and await the real signal.
Fixing a test counts as changing it, so the questions above apply: if it guards no rule in the area's spec, add the rule (with its source) or flag it as an open question. Bite-check every new test and every changed assertion; a change that only replaces how the test waits keeps its assertion, so running it on the fixed and broken code once is enough.
Then check it against every junk pattern. A match fails the gate unless the keep bar names the contract it independently guards. A test that would break under a behavior-preserving refactor asserts implementation: rewrite it at the owning boundary before it lands.
A bug regression test must fail on the pre-fix code for the intended reason and pass after the fix. One that never demonstrably failed proves the mock, not the fix. One regression at the owner boundary covers the bug; don't replay it at every layer it crosses. When a fix makes an expected-failure test pass, remove its marker in the same change. Prefer a new row in that test over a new test.
If the user explicitly asks for a test the gate rejects, say once why, and offer the alternative that guards the same thing (usually a row in an existing boundary test). If they still want it, write it: it's their repo.
pytest.mark.xfail(strict=True), test.fails,
#[should_panic]-style, or a skip that names the rule ID), and report it under
Bugs. During a pass or campaign, don't fix production code unless the user
asked; when the task itself is the fix, fix it. If the intent is only
partly clear, split it: the firm part becomes a rule ("never negative"), and
the unclear part goes under ## Open questions ("0 or 499?").Source: current behavior (unconfirmed), and list it as an open question.Phase7, Leftover, Fixes) often hold real
behavior: judge each test, and CONVERT good ones into their owner suite.Before starting, tell the user what a pass produces and ask which parts they
want: pruning (always), area specs, and the test policy in AGENTS.md. With
pruning only, skip steps 4 and 8, record each rule and its source in the
ledger instead of a spec, and classify against the keep bar directly.
Copy this checklist and track it:
- [ ] 1. Baseline
- [ ] 2. Inventory
- [ ] 3. Gather intent
- [ ] 4. Write SPEC.md per area
- [ ] 5. Classify every test
- [ ] 6. Apply: delete, convert, fill gaps
- [ ] 7. Prove kept tests bite
- [ ] 8. Write the test policy into AGENTS.md
- [ ] 9. Validate and report
Read the root and scoped AGENTS.md/CLAUDE.md, the CI config and the
package scripts. Take the test, format and changed-files commands from there,
and obey any rules the repo sets for agents and test runs (how many agents,
which model, how often the full suite may run).
Run the full suite once and record: pass, fail and skip counts, wall time, flaky tests, test and production line counts. Then check the numbers make sense:
Never edit source or tests while a test watcher is running in the checkout.
Find the tests yourself; no fixed pattern works across stacks. Tests can be in any language, any folder, with any name. Use what the repo already says:
Cargo.toml,
package.json, pyproject.toml, Gradle, Bazel).--collect-only, --list,
-list-tests, a dry run). It counts cases more reliably than reading files.Write down what you found and how: test locations, number of files, lines and
cases, and the command that lists them. Then choose the areas from the
production code, not from the test layout: an area is one cohesive behavior
(pricing, payments, auth). When most tests sit in one folder, group them by
the production owner they exercise. Several areas can share one SPEC.md
with different ID prefixes when they live in the same module. On large repos,
run one area per pass and land each separately, or switch to
campaign mode.
For each area, collect intent sources before opening its tests. Write down
the source of each rule (README#pricing, #412, commit a1b2c3, user).
A rule with no source except the current code goes under
## Open questions, not ## Rules. The one exception is a public contract
with an existing test (see Ground rules): that becomes a rule marked
unconfirmed and an open question. One sentence of intent may yield several
rules when it has distinct failure modes ("never charge twice": sequential and
concurrent).
When intent is thin, ask the user a short batch of concrete questions
("Should a discount larger than the subtotal give 0 or an error?").
Don't guess. If you can't ask (a subagent, a headless run), take the narrowest
reading, put the question under ## Open questions, and list it in the report.
Put it next to the code it governs (src/billing/SPEC.md), unless the repo
already has a specs/ convention. When the code is organized by layer
(models, services, views) instead of by feature, use one specs/<area>.md per
area at the app root. Follow spec-format.md.
Every rule gets an ID (BILL-3) and a Check: level:
type: the type system or a schema already enforces it.read: an agent verifies it by reading the diff against the rule.test: it passes the keep bar and needs an executable test.Default to read. Promote to test only through the keep bar.
Read each test in full, including parameter tables, and give each declaration
exactly one verdict. A table test (it.each, parametrize) is one declaration
unless its rows need different verdicts.
| Verdict | When | Action |
|---|---|---|
| KEEP | Guards a Check: test rule at its public boundary, even if it needs a rename or a mock swapped for a fake | Put the rule ID in the test name |
| FIX | Guards a test rule, but an assertion can't fail (a negative that passes when only one of several items is missing, a check the production path never reaches), or it passes only by sleeping, retrying or a raised timeout | Repair the assertion or await the real signal, then bite-check it |
| CONVERT | Guards a test rule through many hand-written field asserts, mocks or private calls, or duplicates a stronger suite | Rewrite as one expect test at the boundary, or move its unique assertion into the keeper |
| FOLD | Its input → output pair illustrates a sourced read rule well | Move the example into that rule's table, then delete the test |
| DELETE | Matches a junk pattern and guards no keep-bar rule | Delete |
Every DELETE needs one evidence line: what failure the test could actually detect, and the stronger proof that remains (or why no contract exists). A missing line means it isn't ready to delete. Evidence that says no other proof remains contradicts a DELETE: that test is KEEP or FIX. KEEP evidence names the regression ("fails if reconcile overwrites member notes"); a label ("mirror sync") isn't evidence. A rule ID is valid only with a source other than the code: never invent one to justify a verdict.
Test names carry the rule ID in a form the runner accepts and can filter on:
"BILL-3: …" with -t BILL-3 (Vitest, Jest, Bun), test_BILL_3_… with
-k BILL_3 (pytest), TestBILL3… with -run BILL3 (Go).
When unsure between KEEP and DELETE, keep it and list it in the report with the reason. Deletion count is not the goal.
A test you haven't read in full yet is UNREAD, never a verdict. An UNREAD row means the classification isn't finished.
Check: test rule with no test gets one: an expect test at
the boundary, named with the rule ID.For every new, fixed or converted test, and a sample of the KEEP ones: break the
behavior the rule describes in production code (flip a condition, drop a
branch), run that test, confirm it fails for that reason, then revert.
It has to be an assertion failure: a syntax, import or setup error proves
nothing. A test that stays green guards nothing: fix it or delete it. For an
expected-failure test, the bite check runs the other way: temporarily fix the
bug and confirm the test passes (strict mode then reports XPASS). Then run
git diff on production code to make sure every mutation was reverted.
Add or replace the testing section with this, adjusted to the repo's commands:
## Tests and specs
- Each area's intent lives in its `SPEC.md`. Read it before changing that area.
- After a change, check every rule your diff touches. For `Check: read` rules,
state in your summary that you re-checked them. For `Check: test` rules, run
only the tests that cite those rule IDs (`<runner filter> BILL-3`).
- A new test needs a `Check: test` rule that meets at least one of: external
boundary, money/auth/data-loss/security, concurrency/time/ordering, large
input space (parsers, formatters), a real past regression, or a public
contract others depend on. Everything else is checked by reading. No tests
for private helpers, restated constants, or mock call arguments.
- A bug-fix regression test must fail on the code before the fix.
- Removing or moving code needs no test that it's gone.
- No sleeps, retries or raised timeouts in tests. Await the operation or its
signal, and fake the network so unexpected requests fail.
- Behavior changes start in the spec: update the rule, then the code.
- If code and spec disagree, stop and ask. Don't edit the spec to match the code.
If the stack has a linter that can enforce part of the gate, wire it: rules
against fixed sleeps, retries, raised timeouts and mocks that replace behavior
exist for several ecosystems (for TypeScript, landmines). Adopt them in an
existing codebase with a per-file allowance of current violations that may
only shrink, so the count ratchets down instead of blocking the merge.
git diff --check.git diff --numstat; count production and tooling lines separately
from tests and test support.Report in this format:
## testectomy: <repo or area>
Before → after: <N> tests / <T>s → <N> tests (<x> expected-failure) / <T>s
Lines: tests <a> → <b>, production <c> → <d> (tests can go up when gaps outnumber deletions)
Baseline: <green/red, flaky tests, typecheck/lint state>
Specs written: <paths> (<n> rules: <x> test, <y> read, <z> type)
Bugs (<n>): <rule ID: intent vs actual behavior>, test marked expected-failure
Kept (<n>): <rule ID → test>, one line each with the keep-bar reason
Fixed (<n>): <test: the assertion that couldn't fail, and the repair>
Converted (<n>): <old tests → new expect test or keeper>
Gaps filled (<n>): <rule ID → new test>
Bite check: <n> mutations, all failed on an assertion and were reverted (git diff clean)
Deleted (<n>): grouped by junk pattern, with counts
Kept on purpose: <tests that looked like junk but guard a contract, and which>
Open questions: <code vs intent disagreements needing a human call>
Production cleanup: <test-only seams and dead code removed>
AGENTS.md: <added / updated test policy, filter command>
Proof run: <commands actually run and their results>
Follow-ups: <next areas, PR state>
Commit, push or open a PR only when the user asked, using the repo's PR flow. Land one coherent area per PR. After it lands, refresh from the default branch and rerun the inventory before starting the next area.
A rule gets Check: test only if at least one of these holds. Write which one
next to the rule.
A source-inspection test (grepping a file) passes only when it's the cheapest independent guard: it fails when the contract changes (the user-facing key, byte or path) and survives a rename of identifiers.
Everything else is read.
Ask what the test depends on. A test worth keeping depends on intended behavior: it changes only when that behavior changes, and fails only when it regresses. The gate rejects a new test that matches a pattern below; a pass deletes an existing one unless the keep bar names the contract it guards.
It asserts that removed or moved code stays gone. Bringing it back would be a decision, not a regression.
Agents write these when asked to remove something ("so it can't come back"). Removing code never needs a test proving it's gone.
No change to the code under test can make it fail.
It changes whenever the code does, even when behavior didn't.
-u.These guard real behavior, so the verdict is FIX, not DELETE. A test that only passes on rerun is a bug in the test or the code.
| Hides the flake by | Fix |
|---|---|
| Waiting a fixed real-time delay (sleep, timer) | Await the operation, or a promise or signal its handler resolves. To move time, control the clock (fake timers) and advance it |
| Polling state until a deadline | Have the code that records the event resolve a signal, and await it. A deadline-bound poll fails under load |
| Retrying on failure | Find the race and await what the test depends on. If it can't be fixed now, record it where the repo tracks flaky tests; don't retry it |
| Raising its timeout | Await the real event, or move slow shared setup to suite-level setup |
| Letting network requests through, or answering them silently | Fake at the network boundary with a handler for every request the test makes, and make any other request fail the test |
| Being disabled or skipped on every run | Fix it and re-enable it, or delete it. A disabled test costs build time and proves nothing |
AGENTS.md tells the next agent how to use it.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
test-audit, test-pruning, spec-files, expect-tests, test-quality
npx claudepluginhub felipebasurto/testectomy --plugin testectomyOther plugins' skills for the same job