CtrlK
BlogDocsLog inGet started
Tessl Logo
PluginPublic

trysac/diff-coverage

Measure test coverage of only the lines a change adds, by joining a unified diff with a Cobertura XML or coverage.py JSON report. Use when asked for diff coverage, patch coverage, or whether the new lines of a PR are tested.

Quality

95%

Does it follow best practices?

Run evals on this skill

Adds up to 20 points to the overall score

View guide
SecuritybySnyk

Low

Low-risk findings worth noting

Overview
Quality
Evals
Security
Files
name:
diff-coverage
description:
Measure test coverage of only the lines a change adds, by joining a unified diff with a Cobertura XML or coverage.py JSON report. Use when asked for diff coverage, patch coverage, or whether the new lines of a PR are tested.
license:
MIT
compatibility:
Needs Python 3.10 or newer (standard library only). No network access. Reads only the diff and report files you name; never runs git.

diff-coverage

Answer "are the lines this change adds actually tested?" Whole-project coverage hides a poorly tested patch; this skill measures only the added lines. The bundled script works on its own: nothing to install or build.

When to use

  • A user asks for diff coverage or patch coverage of a branch or pull request.
  • A review needs to know which new lines have no test.
  • CI should fail when less than N percent of the changed lines are covered.

Workflow

  1. Produce the two inputs with the project's own tools.

    • A unified diff of the change: git diff origin/main...HEAD > change.patch.
    • A coverage report from the test run, either Cobertura XML (coverage.xml) or coverage.py JSON (coverage.json). With coverage.py: coverage run -m pytest, then coverage xml or coverage json. Other ecosystems that can export Cobertura XML also work.
  2. Run:

    python3 scripts/diff_coverage.py --diff change.patch --coverage coverage.xml --fail-under 80

    Options: --format text|markdown (default text; json is also accepted) and --fail-under PERCENT. The coverage format is detected from the first character: < is Cobertura XML, { is coverage.py JSON.

  3. Read the output. Text format:

    src/m.py 1/2 missing 3
    Diff coverage: 50.0%

    Each file shows covered/executable changed lines and the missing line numbers (ranges such as 3-5, 9). The percentage is rounded half up to one decimal. With no executable changed lines the result is "no executable changed lines" and the run passes.

  4. Report: the overall percentage, each file with missing lines, and any file the report could not measure. Then open the missing lines in the code and say what test would exercise each one. Use --format markdown to paste a table into a pull request.

  5. Exit codes: 0 passed (or no threshold), 1 below --fail-under, 2 usage, I/O or parse error.

Details on matching, inputs and edge cases are in references/how-it-works.md.

Reading results correctly

  • Only lines that the coverage report lists as executable count. Comments, blank lines and signatures that the tool does not track are skipped, not counted as missing.
  • A line is covered when any class entry in a Cobertura report has hits above zero.
  • A changed file with no matching path in the report is unmeasured: check that the report was produced from the same checkout and that source paths line up with the diff paths.
  • Deleted files (+++ /dev/null) are ignored; only added lines count, not removed ones.

Limits

  • Line coverage only: no branch coverage, no LCOV or JaCoCo input.
  • The script never runs git, never writes files, never uses the network and never reads environment variables.
  • XML containing <!DOCTYPE or <!ENTITY is refused before parsing.

Source

This skill bundles a standard-library copy of the logic implemented by the diff-coverage package: https://github.com/Trysac/u293-diff-coverage

Workspace
trysac
Visibility
Public
Created
Last updated
Source
CLI
Repository
No repository linked. Set repository in the plugin manifest, or publish from a GitHub Action to verify it.
Badge
trysac/diff-coverage badge