testgen
Scan the codebase for missing or hollow tests, generate unit/integration/E2E tests, and create a PR.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Scan the codebase for missing or hollow tests, generate unit/integration/E2E tests, and create a PR.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Pre-meeting B2B account research. Produces a structured account brief (company overview, recent news, tech stack, decision structure hypothesis, hypothesized pain points, approach strategy). Use before /discovery-prep.
Generates a Discovery meeting plan from an account brief — SPIN questions, MEDDIC checklist, hypothesized pain points with verification questions, objection prep, time-boxed agenda. Run after /account-brief, before the meeting.
Generates post-meeting follow-up assets — customer-facing email draft, internal action list, CRM update fields, account_brief updates, champion status tracking. Run after any sales meeting.
Converts sales-written meeting notes (discovery type) into a PRD draft for PoC building, and updates account_brief.md with newly learned facts. The bridge between sales discovery and engineering PoC. Run after a discovery meeting, before /kickoff.
Generates a closing proposal from demo meeting notes + the actual PoC + account brief. Business-value first; technical specs in appendix. Run after a demo meeting, before contract negotiation.
Analyzes and critiques business viability. Use after /brainstorm and before /prd.
| name | testgen |
| description | Scan the codebase for missing or hollow tests, generate unit/integration/E2E tests, and create a PR. |
| argument-hint | [file or directory path, or omit for full scan] |
| disable-model-invocation | false |
| allowed-tools | Read, Glob, Grep, Write, Edit, Bash(bash scripts/checkpoint.sh *), Bash(bash scripts/wt_setup.sh *), Bash(bash scripts/wt_cleanup.sh *), Bash(bash scripts/registry_edit.sh *), Bash(bash scripts/flock_edit.sh *), Bash(bash scripts/worktree.sh *), Bash(python3 scripts/*), Bash(git *), Bash(gh *), Bash(pytest *), Bash(npm *), Bash(bash ${CLAUDE_PLUGIN_ROOT}/scripts/*), Bash(python3 ${CLAUDE_PLUGIN_ROOT}/scripts/*) |
Kit root: ${CLAUDE_PLUGIN_ROOT}
scripts/ dir): prefix every kit script command with it, e.g.
bash <kit-root>/scripts/checkpoint.sh …. Absolute paths also work from worktrees.${…} placeholder above → standalone layout: run commands as written.Run these checks silently at the start. Use results to adapt behavior:
[ -f issues.md ] — if true, this project uses the sprint system. Respect issue numbering and STATUS.md.[ -f docs/sprint_state.md ] — if true and Status shows running, a sprint is active. Be aware of parallel work in worktrees.[ -f docs/prd_digest.md ] — if true, read it for quick project context before starting.gh auth status before any GitHub operation.Every phase in this skill that has a CHECKPOINT block must be verified. Run the verification command after completing each phase. Blocking gates exit non-zero on failure: STOP immediately, report, do NOT proceed. Advisory gates always exit 0 and print an ADVISORY: line on failure: report the gap, self-correct, then continue (ISSUE-031). Never skip running either tier.
Slug convention: After creating the worktree, store the branch slug (e.g., testgen/add-missing-tests) for use in checkpoint commands.
$ARGUMENTS is provided, verify it exists as a file or directory using Glob or Read.
<path>. Please provide a valid file or directory path."$ARGUMENTS is empty: scan the entire project (all source files).Algorithm:
Ensure gh authenticated (gh auth status).
Gather context — read the following docs (if they exist, skip silently if not). Read all applicable documents via parallel Read tool calls in a single message.
docs/test_plan.md — test strategy, risk matrix, critical flows for E2E prioritizationdocs/architecture.md — tech stack, modules, dependenciesScan phase — Identify test gaps: a) Detect project language(s):
pyproject.toml, setup.py, or *.py source files. Test convention: tests/test_*.py.package.json. Test convention: *.test.ts, *.spec.ts, __tests__/.
b) For the target path (or entire project), find all source files excluding:test_*, *_test.*, *.spec.*, *.test.*).json, .toml, .yaml, .yml, .md, .css, .html, .lock)node_modules/, __pycache__/, .git/, dist/, build/__init__.py files that are empty or import-only
c) For each source file, check if a corresponding test file exists:src/module.py → tests/test_module.pysrc/component.ts → src/component.test.ts or src/component.spec.ts or __tests__/component.test.ts
d) For source files that have test files, check for hollow tests:def test_ functions with assert/mock/raisesit(/test( with expect/toBe/toEqual
e) E2E gap analysis (if docs/test_plan.md exists):tests/e2e/ or e2e/ directory has test files covering those flowsPresent gap report to the user:
## Test Coverage Gap Report
### Missing Unit Tests (N files)
| Source File | Expected Test | Priority |
|-------------|--------------|----------|
| src/auth.py | tests/test_auth.py | High (auth = critical) |
### Hollow Tests (N files)
| Test File | Issue |
|-----------|-------|
| tests/test_utils.py | No assertions found |
### Missing E2E Tests (N flows)
| Critical Flow | Risk | Status |
|--------------|------|--------|
| User login | High | No E2E test |
Ask user to confirm which gaps to fill (all, or a subset).
After user approval, create worktree + auto-freeze in one step:
WT="$(bash scripts/wt_setup.sh testgen/add-missing-tests)"
wt_setup.sh creates the worktree and writes the freeze marker inside
.claude-kit/freeze-dir.txt atomically. All subsequent file operations
happen inside $WT/.
CHECKPOINT — ADVISORY (report & continue) Run:
bash scripts/checkpoint.sh --skill testgen --phase worktree --issue "$SLUG"Advisory: exits 0 even on failure, printing anADVISORY:line — report the gap, self-correct, then continue.
Generate tests inside $WT/:
For each approved gap, ask test-generator subagent to:
a) Read the source file thoroughly — understand all public functions, classes, methods
b) Read existing tests in the project to match style and patterns
c) Write test file with:
test_login_with_expired_token_returns_401
e) Mock external dependencies — no real HTTP calls or DB connections in unit tests
f) Each test must have real assertions (not pass or empty bodies)Run all generated tests inside $WT/:
pytest tests/ -q --tb=shortnpm testCHECKPOINT — MANDATORY — NEVER SKIP Run:
bash scripts/checkpoint.sh --skill testgen --phase test --issue "$SLUG"If exit code ≠ 0: STOP immediately and report the failure. Do NOT proceed.
gh issue create --title "test: add missing tests for [scope]" --body "<body>"$WT/).CHECKPOINT — ADVISORY (report & continue) Run:
bash scripts/checkpoint.sh --skill testgen --phase push --issue "$SLUG"Advisory: exits 0 even on failure, printing anADVISORY:line — report the gap, self-correct, then continue.
gh pr create --title "test: add missing tests for [scope]" --body "Closes #<issue_number>\n\n<gap report summary>"If issues.md exists in the project root, register this work in the sprint ecosystem:
issues.md to find the next available ISSUE-NNN number.bash scripts/registry_edit.sh issues.md -- bash -c '<append issue entry>'
Issue fields:
<number><pr_url>If issues.md does not exist, skip this step silently.
gh auth status fails: stop and instruct the user to run gh auth login.git push fails: check for upstream conflicts; report and stop.bash scripts/wt_cleanup.sh <branch> for safe worktree removal —
the wrapper cd's to main root and removes the worktree in a single subshell.bash scripts/wt_cleanup.sh <branch>git push origin --delete <branch> (remote cleanup, if pushed)gh pr close <pr_number> then clean up as above.IMPORTANT: Never commit issues.md, STATUS.md, or CHANGELOG.md to the feature branch.
These are registry files managed only on main. Always use bash scripts/registry_edit.sh <file> -- bash -c '<update command>' — the wrapper resolves the main repo root internally.
__init__.py, pure config, type-only files).docs/test_plan.md exists, use its framework recommendations (Playwright, Maestro, pytest).