/praxis:test-suite-consolidationfrom praxis
Clean up a test suite without changing what it proves — move fixtures and helpers that were copied across test files into shared locations behind a copy guard, or audit for unnecessary tests (orphans, phrase-pins, duplicate coverage) and delete only the scope the user approves. Every change is checked against a collected-test-ID diff.
Ships in praxis. 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.
Test suites rot in two ways that look alike from a distance. Fixtures and helpers get copied from the nearest file instead of reused, so the same body lives in a dozen places and drifts; and tests accumulate that no longer earn their keep — orphans, assertions that pin doc sentences nothing reads, and duplicate coverage. Both are cleanups with zero intended behavior change, both end in one issue and one PR, and both fail the same way: something that mattered is silently removed. This skill runs either shape with a collected-test-ID oracle and, for copies, a guard so the next change stops re-copying.
Core principle: nothing a test proves may disappear unannounced — every move is diffed against the collected test IDs, and every deletion is approved by the user and re-verified by you.
Reference map — load only when the step runs:
| File | Holds |
|---|---|
references/duplicate-audit.md | How to find copied fixtures/helpers on the base ref with a normalized-AST grouping, and the three buckets to report |
references/copy-guard.md | Copy-guard design: binding-aware equality, diff-scoped vs baseline, thresholds, checker mutation testing, CI placement |
references/pruning.md | Pruning shape: own-PR quick pass, criteria, deterministic probes (never-run map from workflow steps / in-body env guards / importorskip vs the venv's lockfile / empty-parametrize / failing-since-added), window audit of newly added tests, read-only fan-out, re-verification traps (randomized differential, forced-state simulations, uniform mocks, self-comparing differentials, copied commands judged by stdout, lane citations), parallel implementation lanes (private DBs, HEAD-checked mutations, lint with the CI linter's config file, commit split from lane result JSON), removal-vs-approved check, report (production defects split into their own fix PR first, with a post-merge rollout check), base-vs-branch lint diff when the repo has no lint config |
references/pruning.md).references/pruning.md.scripts/mutation_matrix.sh) before
gh pr create; otherwise the user asks for it after review and the anchor,
PR body and CI all need another revision.comm -13 of collected
ids at origin/<base> vs head for the files git diff origin/<base>...HEAD -- <tests> touches. A test that exercises a file the PR's diff does not
change is out of the PR's scope: flag it in the matrix report. Drop
unasked only tests you added; report prunable tests a bot pushed or the
base merge kept in the same table and ask before dropping them.git show HEAD:<f>; invoke the venv's pytest from
a shell, not from a notebook-kernel subprocess — the kernel's inherited
interpreter env can make conftest imports fail (pydantic_core /
ArgsKwargs ImportError) and the pipeline reports zero collected ids.kill_matrix.rev<N>.py) and move the previous result JSON aside: if the
change is reverted, restoring that copy gives the matching matrix at once.
Rewrite anchors with a script that asserts each anchor matches exactly once,
not by hand edits. The matrix rewrites
files in the worktree, so commit first and point any parallel reader
(review subagent) at git show HEAD:<path>, not the working tree.Pick the shape first: consolidate (Steps 1–8) or prune
(references/pruning.md). A request for both runs
pruning first, so you do not consolidate helpers for tests about to be
deleted.
Audit an extracted copy of origin/<base>, not the working tree, and group
module-level fixtures/helpers by normalized body. Report three buckets
separately: (a) copies of a definition a shared conftest/helper already has —
safe deletes; (b) identical copies with no shared home — move; (c) same name,
different bodies — leave, and say why. Grep docstrings for "same pattern as
" and run git log --diff-filter=A on the copies: that chain is the
clearest evidence for the issue. Procedure →
references/duplicate-audit.md.
Done when: every copy group is in exactly one bucket, with the copy-chain evidence quoted.
pytest_plugins
module can change override order. Say this up front — the user may read
"one package" as including fixtures.<tests>/tests_common/{sql,import_stubs,servers}.py, the Apache Airflow
tests_common shape). Scattered per-area helper modules are a transitional
step at most.read_text as _read) is acceptable only as an intermediate commit; finish
by renaming call sites in the same PR.Done when: the PR body names where fixtures and where helpers live, and every widened autouse override has its grep result stated.
set -o pipefail
pytest <tests> --collect-only -q -p no:cacheprovider | grep '::' | sort > <scratch>/before.txt
pipefail makes a collection error fail the command instead of leaving a
partial before.txt behind sort's exit 0; the file lives outside the
checkout so it never shows up in the diff. vitest/jest equivalent:
npx vitest list | LC_ALL=C sort > <scratch>/before.txt (one
file > describe > case line per test; it imports every test module, so a
broken import fails it). Vitest 5+ parses files statically by default and
then skips the imports — add --no-static-parse there. Sort both sides with LC_ALL=C and compare with
LC_ALL=C comm: shells with different locales collate non-ASCII test names
differently, and comm then reports thousands of identical lines as
added/removed. Group the removed lines by file (sed 's/ > .*//' | sort -u)
and check every file is one the change touched; IDs behind env-dependent
skipIf can appear or vanish between runs — name them, don't count them as
losses.
After every step, regenerate and diff: only additions for new tests, zero
deletions. This catches what lint does not — a re-export removed by
ruff check --fix (F401), or a broken import from a sibling test module.
Done when: before.txt exists and is taken from the unmodified branch.
tokenize (NAME tokens not preceded by
.), refusing any file where the shared name is already bound — a regex
\b_old\b also hits obj._old.from .test_x import _old, including parenthesized
multi-line imports); the rename breaks those and only collection catches it.uvx ruff@<pre-commit rev> format <files>), not the venv's.git grep <name> shows only the
definition) in their own commit.Done when: the collect-ID diff after each move shows zero deletions.
Prevent recurrence with a check, not only docs. Default design: diff-scoped
against a base revision (no baseline file), free-name-binding-aware equality,
fail on a redefinition of a shared definition or a 3rd test-module copy, run
as the last step of the existing test job plus a pre-commit hook. Mutation-test
every decision branch of the checker. Design, thresholds, the baseline
alternative and CI placement → references/copy-guard.md.
Done when: each checker decision point has a mutation that fails at least one test, and a historical replay includes one positive control that reports a real copy.
Add a "shared locations" table to the repo's agent guide (AGENTS.md /
CLAUDE.md testing section): what lives where, the import form, and how the
guard works. Agents read that file; it is the non-CI half of "stop local
fixes".
Done when: every shared module created or used by this PR appears in the table.
paths: (both pull_request and
push) — the new conftest, and the shared helper package once a test they
run imports from it. Otherwise a change to the shared file never triggers
the only job that runs it.git worktree add --detach <scratch> HEAD, merge origin/<base> there,
run the checker) — a base-branch merge can bring a new copy. Fix by merging
origin/<base> into the branch (a merge commit, never a force-push), moving
the copy to the nearest common conftest, and collect-ID-diffing that
directory.git fetch the head first and lint
their diff with the repo config: CI linters often lint only changed files,
so a docstring past the line limit fails there and nowhere locally.Done when: the collect-ID diff is additions-only, the gated subsets ran in their own environment, and the blast-radius count is in the PR body.
Split pre-existing format debt (files not clean under the pinned formatter on
the base) into a first style(...) commit, then one commit per logical move,
the guard, and docs. Report whether CI speed changed — consolidation usually
does not, because session-scoped setup already ran once. If asked, measure the
touched subset base vs branch in a throwaway worktree (2 rounds, drop the cold
first), and note that editing any conftest.py cold-starts a change-selection
cache keyed on **/conftest.py once after merge.
When asked whether the result is "top-tier", answer in a table with a source
per row: the pytest conftest hierarchy / pytest_plugins docs, the
PHPStan/detekt baseline model ("the life goal of a baseline is to not exist"),
and Airflow's single tests_common package. Name the remaining gaps (aliases,
scattered helper modules, a custom detector vs pylint/jscpd) and offer to
close them in the same PR.
Done when: git log shows the style commit first and no commit mixes a move
with unrelated format changes.
| Symptom | Cause | Fix |
|---|---|---|
| Consumers fail collection after a clean lint | ruff --fix F401 deleted an import a module only re-exported | Import from the shared module at each consumer instead of re-exporting; the collect-ID diff catches it |
| Another test module breaks after a rename/move | It imported the helper or fixture from its old module | Grep import .*\b<name>\b and multi-line import lists across the tests tree; drop the fixture from those imports once a conftest provides it |
| F401 / F811 on a shared fixture | The fixture was imported into another test module | Share fixtures through a conftest; import the module-local classes the body uses into that conftest — same module object, unchanged behavior |
| Pre-commit copy check fails on an unrelated commit | The tree holds a copy (e.g. from a base merge); pre-commit sees HEAD + staged | Commit the copy fix first; check git show --stat HEAD and split with git reset --soft HEAD~1 if a failed commit left files staged |
| A "format-only" commit contains deletions | git rm stages immediately | Check git diff --cached --name-status before every split commit; redo with git reset --soft HEAD~1 (local, unpushed) |
| pre-commit refuses to commit | .pre-commit-config.yaml has unstaged edits | Commit the config with the hook it adds, or restore it from HEAD temporarily for earlier commits |
| An edit did not happen | A chained command was blocked or denied, so none of its parts ran | Re-run the state-changing step alone before re-posting |
Answer the question as asked: when the user asks whether "the method in " is right, evaluate that file's mechanism (CI placement, runner cost), not adjacent logic.
test-suite-speedup — when the goal is time. Neither consolidation nor
pruning is a speedup by itself; measure before claiming one.surface-enumeration — when a pruned test was the only case for an input
variant, it is not a duplicate.What SKILL.md sets; muted values are Claude Code's defaults
Triggers on "test consolidation", "copied fixtures", "duplicate test helpers", "prune tests", "unnecessary tests", "테스트 정리", "불필요한 테스트". Do NOT activate on a slow suite with no duplication or pruning ask (that is `test-suite-speedup`).
Other plugins' skills for the same job
16 skills in this plugin
/cmux-delegateHand off an existing independent issue that surfaced mid-task to its own Claude Code session in a new cmux workspace, with auto-collected context; that session runs issue→worktree→PR alone. Not for splitting the current task./cmux-recover-sessionsBulk recover Claude Code sessions after a crash, power loss, OOM kill, or reboot by scanning the .jsonl files Claude Code persists automatically. Interactive interview chooses recovery scope and layout. Use this when sessions died and you need them back. The .jsonl scan reflects each session's real final state, so no snapshot taken before the crash is needed.
/codex-review-wrapWorktree-aware wrapper for /codex:review. Forces explicit worktree selection when several worktrees are active, preventing silent cwd mismatch, then gates every returned finding: premise verification before fact-modifying edits, flip detection halting A→B→A oscillation, sibling cross-checks for a port or parallel hotfix, a diminishing-returns advisory (PRAXIS_DIMINISHING_RETURNS_N), and a per-finding approval ask. It also reaps leaked openai-codex brokers (PRAXIS_CODEX_REAP=1).
/merge-briefingBrief and ask before merging any PR: probe CI, reviews and inline threads, grade every open finding by its blocking decoration, carry the anchor's `Unverified` gaps, write the six-part briefing, and end on the approve-ask.
/perf-leak-reviewPoint at performance-defect and memory-leak candidates in a diff — a read-only LLM reviewer reads the change plus the repository around it and reports candidates in a closed list of six classes. Report-only: nothing is executed, nothing is written, no finding is a proven defect.
/reset-strikesReset the current session's strike counter to 0 and clear the recorded violation list. Required after a 3rd strike block before Claude can respond again.npx claudepluginhub devseunggwan/praxis --plugin praxis