协作头脑风暴
brainstorming
在实现前澄清需求、探索设计选择,并形成清晰的开发方向。
test-coverage【开发与工程】Generate unit tests for untested branches and edge cases. Use when coverage is low, CI flags gaps, or a release needs hardening. Not for integration/E2E suites, framework migrations, or fixing production bugs.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Expand unit test coverage by targeting untested branches and edge cases.
Detect the project's language from its manifest file and use the matching commands throughout the Workflow below:
| Manifest | Stack | Coverage command | Test framework |
|---|---|---|---|
package.json | JavaScript/TypeScript | npx jest --coverage or npx vitest --coverage | Jest, Vitest, Mocha |
pyproject.toml | Python | pytest --cov=. --cov-report=term-missing | pytest, unittest |
go.mod | Go | go test -coverprofile=coverage.out ./... | testing, testify |
Cargo.toml | Rust | cargo tarpaulin or cargo llvm-cov | built-in test framework |
If none of these manifests is found, see Edge Cases — "No test framework detected".
Before creating/updating/deleting files in an existing repository, sync the current branch with remote. First save git status --porcelain as the pre-sync list; Step 4 never stages those paths.
branch="$(git rev-parse --abbrev-ref HEAD)"
git fetch origin
git pull --rebase origin "$branch"
If the working tree is not clean, stash first, sync, then restore:
git stash push -u -m "pre-sync"
branch="$(git rev-parse --abbrev-ref HEAD)"
git fetch origin && git pull --rebase origin "$branch"
git stash pop
If origin is missing, pull is unavailable, or rebase/stash conflicts occur, stop and ask the user before continuing.
Before making any changes:
git rev-parse --abbrev-ref HEAD. If it prints a branch other than main or master that was created for this task, skip to Step 1.git branch -a and note the prefix most existing branches use (e.g., feat/, feature/, test/).feat/test-coverage.Run the coverage command for the detected Stack above. Record the total coverage percentage and the pass/fail counts as the baseline. If any test fails, stop here (see Edge Cases).
From the report, identify:
Review the low-coverage code for:
references/unit-test-quality.md.Decision: with the test's code and failure output. The run can still be COMPLETE; name the bug in the Result: line. That test becomes the regression test for the fix.pytest tests/test_parser.py, go test ./internal/store -count=1 -run '^TestKey', cargo test key_). If a new test fails in either run, it depends on test order, shared state, or timing. Fix it once from the flakiness table in references/unit-test-quality.md and repeat items 1 and 2. If it still fails, remove it and list it under Uncertainty:.git add tests/test_parser.py); never git add -A, git add . or git commit -a, which would sweep in user work Repo Sync restored. Never stage a path on the pre-sync list. Stage a changed manifest or lockfile (Coverage tool not installed) only with its reason in the commit message. Check git diff --cached --name-only before committing. Under Uncertainty:, list each changed file left unstaged, or every new test file when the commit is skipped (failed suite or regression).Result: — COMPLETE, PARTIAL — reason, or BLOCKED — reason — followed by:
Evidence: the commands that ran, with before/after totals, pass/fail counts, and the item 2 rerun resultUncertainty: what was not checked (e.g., excluded paths, CI not run, covered lines without output assertions)Decision: the action that needs approval, or No approval needed, then any remaining user action (e.g., push the branch, open a PR)After a successful run on a Python project, the final verification report shows:
Result: COMPLETE — coverage 61% → 84%, all tests pass
Evidence: pytest --cov=. --cov-report=term-missing (before): 61% (47/77 statements), 47 passed
same command (after): 84% (65/77 statements), 56 passed, 0 failed
9 new tests run on their own, twice: 9 passed both runs
Uncertainty: CI not run; src/vendor/ excluded from coverage
Decision: No approval needed. Next: push feat/test-coverage and open a PR.
New tests added: 9
Files improved:
- src/parser.py 52% → 91% (+7 tests: null input, empty string, unicode overflow)
- src/auth.py 71% → 88% (+2 tests: expired token, missing header)
A run passes when all of the following are true:
jest --coverage, pytest --cov, go test -cover).sleep(), or a real database other than a test-database fixture the existing unit tests already use.npm test, pytest, go test ./..., etc.), and the new tests pass when run on their own, twice.Decision:. No assertion was loosened to match the code.feat/test-coverage), never on main/master.If any item fails, the final report says PARTIAL or BLOCKED and names the reason.
The final report must also be understandable:
COMPLETE, PARTIAL or BLOCKED and the reason.Evidence: (commands run and their observed totals) is separate from Uncertainty: (assumptions and unchecked behavior).Decision: names the approval needed or says No approval needed, and names any remaining user action.These are instruction checks. Without reviewer feedback, human understanding of the report stays unconfirmed; agent inspection cannot confirm it.
package.json, pyproject.toml, Cargo.toml, or go.mod for test dependencies; if none found, asks the user which framework to use before writing any tests.pytest-cov, nyc, cargo tarpaulin, etc.) and rerun the command once. If it fails again, stop and report BLOCKED with the error output.BLOCKED with the names of the failing tests.COMPLETE with the baseline as evidence and stop.node_modules/, vendor/, dist/, build/, files with a generated-code header) out of the Step 2 gap list, and list them under Uncertainty:.pytest-asyncio or Jest fake timers). Never use a bare sync wrapper, and never sleep() to wait for async work.monkeypatch on the name the module under test imports, jest.spyOn or vi.spyOn, or Jest or Vitest fake timers for time. If no such tool reaches it, do not refactor production code to add a seam. Leave that gap untested and list it under Uncertainty:.After completing each major step, output a status report in this format:
◆ [Step Name] ([step N of M] — [context])
··································································
[Check 1]: √ pass
[Check 2]: √ pass (note if relevant)
[Check 3]: × fail — [reason]
[Check 4]: √ pass
[Criteria]: √ N/M met
____________________________
Result: PASS | FAIL | PARTIAL
Adapt the check names to match what the step actually validates. Use √ for pass, × for fail, and — to add brief context. The "Criteria" line summarizes how many acceptance criteria were met. The "Result" line gives the overall verdict.
Branch Setup phase checks: Feature branch created, Base coverage measured
Analysis phase checks: Coverage report parsed, Gaps identified, Priority ranked
Test Writing phase checks: Tests written, Self-check passed, No network, DB, clock, randomness, or sleep, Framework conventions followed
Verification phase checks: Tests pass, New tests pass on their own, Coverage improved, No regressions
_test.go, a Rust #[cfg(test)] module) or in its unit-test directory. Never add them to an integration or E2E suite.