Coverage
Run tests with coverage instrumentation, identify gaps, produce a concrete work list.
Measure — never guess or structurally deduce.
Poor coverage means inherited code lacks proper TDD. Goal: backfill the tests that should have been written, until coverage is complete.
Do NOT modify the code under test. Improve coverage only by writing new tests. Failing tests get noted, not fixed — that's a separate task.
Process
- Detect project + tool —
{"op": "detect projects"}, then follow the matching guide:
| Project type | Guide |
|--------------|-------|
| Rust (Cargo) | RUST_COVERAGE.md |
| JS/TS (npm/pnpm) | JS_TS_COVERAGE.md |
| Python (pytest) | PYTHON_COVERAGE.md |
| Dart/Flutter | DART_FLUTTER_COVERAGE.md |
| Swift (SwiftPM/Xcode) | SWIFT_COVERAGE.md |
The guide is authoritative — don't guess commands.
- Scope — user decides:
- Explicit (named files/dirs/crates/packages): coverage only for that scope; ignore branch changes.
- Default ("coverage" with no target): files changed on current branch vs
main, via{"op": "get changes"}.
- Run with coverage — commands from the guide, via Bash. Produce LCOV output. Install the tool from the guide if missing. If tests fail, note and continue with the passing ones — don't stop to fix.
- Parse LCOV and identify gaps from
lcov.info:
SF:<path>— source fileDA:<line>,<hits>— line execution count (0= uncovered)end_of_record— file block end
For each in-scope file: parse DA: lines, map uncovered lines to functions by reading the source. Files in scope but absent from coverage = 0%. Per-file metrics: lines instrumented (DA: count), lines covered (DA:<line>,N>0 count), coverage % = covered/instrumented × 100.
- Track on kanban:
```json
{"op": "init board"}
{"op": "add tag", "id": "coverage-gap", "name": "Coverage Gap", "color": "ff8800", "description": "Function or method lacking test coverage"}
{"op": "add task", "title": "Add tests for <function>", "description": "<file:lines>\n\nCoverage: <X>% (<covered>/<total> lines)\n\nUncovered lines: <ranges>\n\n<signature>\n\n<what it does and what to test>", "tags": ["coverage-gap"]}
```
- Summarize: overall % for scope, per-file breakdown (file, covered, total, %), kanban task count, recommendation (lowest coverage first).
Guidelines
- Measure with real coverage instrumentation; no structural deduction.
- Coverage comes from the unit targets. Unit tests are fast and give coverage; do not run integration targets (real models, real services) to move a coverage number.
- Don't fix failing tests — note them.
- Kanban is the single source of truth — no TodoWrite/TaskCreate.
- Report only actionable gaps. Ignore trivial getters/setters, trait-impl boilerplate, generated code.
- Tool error/no-output → fall through to the next tool in the guide; if none work, report clearly.
- To backfill the tests, use the
implementskill against the kanban tasks.
Troubleshooting
`error: no such command: llvm-cov` / `cargo: command not found: llvm-cov`
cargo-llvm-cov is not installed. Install both it and the LLVM component:
cargo install cargo-llvm-cov
rustup component add llvm-tools-preview
cargo llvm-cov --lcov --output-path lcov.info
If install fails (corporate mirror, no network), fall through to the next tool in RUST_COVERAGE.md (e.g. cargo-tarpaulin) — never fabricate coverage numbers.
`pytest: error: unrecognized arguments: --cov`
pytest-cov not in the active env. Install in the same env that runs the tests:
pip install pytest-cov
pytest --cov=<package> --cov-report=lcov:lcov.info
In a virtualenv project, activate first.
`lcov.info` is empty or missing `DA:` for expected files
Tests didn't exercise the files — filtered out, not compiled into the test binary, or instrumentation failed silently. Force a clean rebuild and verify execution:
- Rust:
cargo llvm-cov clean --workspace && cargo llvm-cov --lcov --output-path lcov.info - Python:
coverage erase && pytest --cov=<pkg> --cov-report=lcov:lcov.info - Swift:
rm -rf .build && swift test --enable-code-coverage
Then grep -c '^SF:' lcov.info — non-zero confirms instrumentation. If zero, verify tests actually ran (look for the pass/fail summary).
Coverage drops to 0% for a file you just edited
Stale instrumented build cache — common after switching between cargo test and cargo llvm-cov (different rustflags). Clear and rerun:
- Rust:
cargo llvm-cov clean --workspace - Python:
coverage erase - Swift:
rm -rf .build/*/debug/codecovthen rerunswift test --enable-code-coverage(a plainswift testrun leaves a profdata that no longer matches the binary)
Swift: `llvm-cov: command not found` or `Failed to load coverage: unsupported instrumentation profile format version`
Use the llvm-cov that matches the Swift toolchain, not a Homebrew LLVM: on macOS always invoke it as xcrun llvm-cov; on Linux use the one in the Swift toolchain's usr/bin. A version-mismatch error means a foreign llvm-cov read the profdata — same fix.