Prompt file imported from mwill20/Governed_AI_Pipeline (
.claude/commands/test-gen.md). Fill in{{arguments}}before use. Copyright stays with the author.
/test-gen — Test Generation for Changed Files
Generate or extend tests for the code changed in the current diff, then run them.
Identify what changed
Changed files:
!git diff --name-only HEAD
Target override (if provided): {{arguments}}
Procedure
- For each changed Python source file (skip files already under
tests/), locate or create the matching test module (tests/test_<name>.py, following the project's existing layout). - Write tests that cover, in priority order:
- Security-relevant behavior — input validation, boundary/trust checks, error paths.
- The happy path.
- Edge cases — empty input, wrong type, oversized input.
- Follow the existing test style in
tests/(fixtures, naming, assertions). Read a nearby test first; do not invent a new convention. - Run the suite for the changed files, with coverage if
pytest-covis available:python3 -m pytest tests/ -q --cov=<changed_package> --cov-report=term-missing(fall back to plainpython3 -m pytest tests/ -qifpytest-covis not installed). - If tests fail, fix the test if the test is wrong, or report the source bug — do not weaken an assertion just to make it pass.
Output
- List of test files created/updated.
- Pytest result (pass/fail counts).
- Coverage for the changed files (percentage + which lines are still uncovered), or a note
that
pytest-covis not installed and how to add it. - Any source bug the tests surfaced.
A change is not done until its tests pass. Report honestly if they do not.