write-tests-100-coverage
Write tests that keep agentic-platform at 100% branch coverage without gaming the metric.
- License 许可
- MIT
- 最近更新
- 2026-09-21
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- write-tests-100-coverage
- description
- Write tests that keep agentic-platform at 100% branch coverage without gaming the metric.
03 SKILL.md 正文
Write tests to maintain 100% branch coverage
This repo enforces --cov-fail-under=100 with branch = true. This skill
describes how to hit that bar honestly.
Process
-
After writing/changing code, run:
python -m pytest --cov-report=term-missingThe
Missingcolumn shows exact uncovered line numbers and, for partial branches,line->linebranch pairs (e.g.67->76means the branch from line 67 to line 76 was never taken). -
For a missing line: write a test that exercises that code path directly. Prefer the smallest, most targeted test — one assertion, one scenario — over a large end-to-end test that happens to touch the line.
-
For a missing branch (
X->Yin the report): you need a test where the condition takes the other path than your existing tests cover. Common cases in this codebase:- An
if/elif/elsechain ineval/framework.py— write one test per branch (seetest_eval_framework.pyfor the pattern: one test per verdict path). - A
try/except— write a test that triggers the exception (e.g.test_graph_handles_blocked_tool_callintest_graph.py). - A loop that sometimes runs zero times — test the empty-input case.
- An
-
When a branch is genuinely unreachable (defensive code that cannot be triggered given the function's own invariants — e.g. see the comment above the
whileloop inrag/pipeline.py), mark it explicitly:while start < len(words): # pragma: no branch - loop always exits via the break belowAlways include a one-line justification in the pragma comment. Never add a blanket
# pragma: no coverto a function just to make coverage pass — that hides real gaps. Only use it on lines you can justify are truly unreachable or untestable (e.g. an optional dependency's import line ineval/mlflow_tracking.py). -
Test placement:
tests/unit/— one module in isolation, all collaborators faked/mocked.tests/integration/— two or more real modules wired together (e.g. the graph + a realHybridRetriever+MockLLMClient).tests/e2e/— through the FastAPITestClient, full HTTP round-trip.
-
Use
MockLLMClient(settings, canned_responses={...})for deterministic LLM behavior in tests — never call a real LLM API in the test suite. -
Run
make ci(lint + typecheck + test) before finishing — a change that hits 100% coverage but fails ruff/mypy is not done.
04 同仓库更多 Skills
write-tests-100-coverage
Write tests that keep agentic-platform at 100% branch coverage without gaming the metric.
add-rag-source
Add a new document source into the HybridRetriever knowledge base in agentic-platform.
add-fastapi-endpoint
Add a new endpoint to the agentic-platform FastAPI service in src/agentic_platform/api/main.py.
add-agent-node
Add a new node (agent role) to the multi-agent SimpleGraph in agentic-platform, with routing and tests.
add-rag-source
Add a new document source into the HybridRetriever knowledge base in agentic-platform.
add-fastapi-endpoint
Add a new endpoint to the agentic-platform FastAPI service in src/agentic_platform/api/main.py.