Coverage

From swissarmyhammer/swissarmyhammer · View interactive version

Coverage is an AI agent skill from the GitHub repository swissarmyhammer/swissarmyhammer. Run tests with coverage instrumentation, identify uncovered code, and produce kanban tasks for coverage gaps. Use when the user says "coverage", "what's untested", "find coverage gaps", or wants to know what needs tests.

How to use this skill

Skill file

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

  1. 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.

  1. Scope — user decides:
  1. 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.
  1. Parse LCOV and identify gaps from lcov.info:

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.

  1. 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"]}

```

  1. Summarize: overall % for scope, per-file breakdown (file, covered, total, %), kanban task count, recommendation (lowest coverage first).

Guidelines

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:

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:

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.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.