Skip to content

feat(metrics): add Test gap Metric from LCOV and Cobertura XML Coverage reports - #432

Merged
avidianity merged 11 commits into
mainfrom
feat/223-test-gap
Nov 24, 2026
Merged

avidianity merged 11 commits into
mainfrom
feat/223-test-gap

Conversation

@avidianity

@avidianity avidianity commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds the Test gap Metric (test_gap), measuring the share of Production Function mass that tests do not execute, computed from user-named LCOV and Cobertura XML Coverage reports (ADR 0017).
Adds zero-dependency LCOV and hardened Cobertura XML readers with content auto-detection, longest-trailing-segment path matching with Cobertura source roots, coverage_reports in codeint.json/codeint.jsonc and repeatable --coverage-report on codeint check, per-language and per-package Test gap across TOON/JSON/Markdown/SARIF/MCP, budgets.production.test_gap enforcement, Coverage report content hashing in ResultCache, codeint diff/codeint trend omission notes, and user documentation.
Leaves all reports for repositories without Coverage reports unchanged apart from the one-line test_gap_note.

Closes #223
Closes #266
Closes #267
Closes #268
Closes #269
Closes #270
Closes #271
Closes #272
Closes #273
Closes #274
Closes #275
Closes #276
Closes #277
Closes #278
Closes #279
Closes #280
Closes #281
Closes #282
Closes #283
Closes #284
Closes #285
Closes #286
Closes #287
Closes #288
Closes #289
Closes #290
Closes #291
Closes #292
Closes #293
Closes #294
Closes #295
Closes #296

Tier

Tier 3 from the tier check (cargo run --locked -p xtask -- risk-tier --base origin/main): touches .rules (tier map rule ".rules") and crates/plugin-host/src/wasm_metric.rs (tier map rule "crates/plugin-host/**", reserving "test_gap" as a built-in Metric key).

Task

Spec #223 (Spec: Test gap, a Metric for the Function mass that tests do not execute) and sub-issues #266 through #296:

  • Part 1 (LCOV reader #266-Guide page for Test gap, with LCOV setup for each test tool #283): LCOV reader, path matcher, coverage_reports config key and schema, repeatable --coverage-report CLI flag overriding config, Code model coverage filling before Metric plugins, line-beyond-EOF exit-2 error, unmatched paths note, Production-only test_gap Metric and reserved key, uncovered-file and 0-listed-line function rules, absent form with one-line test_gap_note, per-language and per-package Test gap, heaviest-first Findings, JSON report schema (schema/codeint-report.schema.json) and codeint schema, Markdown and SARIF output, MCP tools, ResultCache content hashing, and docs/guide/test-gap.md LCOV setup guide.
  • Part 2 (Cobertura XML reader #284-Guide: Cobertura setup for PHPUnit and Pest #288): zero-dependency hardened Cobertura XML reader, format auto-detection by content, Cobertura sources and source elements path matching, hostile input rejection (DTD, XXE, entity expansion, non-XML PIs, depth cap 64, size cap 64 MiB), and PHPUnit/Pest Cobertura setup guide.
  • Part 3 (Budget for Test gap #289-A Regression limit for Test gap is a configuration error #296): budgets.production.test_gap (under/equal pass, over exit 1 with full report, absent coverage exit 2), non-production Test gap budget exit-2 error naming key, MCP over-budget reporting, codeint init starter mention, codeint diff and codeint trend one-line omission notes, and regression_limits Test gap exit-2 error naming key.

Fail-first test

  • Test: crates/metrics/src/coverage/tests.rs (10 unit tests covering LCOV, Cobertura XML, hostile XML rejection, auto-detection, path matcher, traversal rejection, line bounds), crates/metrics/src/test_gap/tests.rs (6 unit tests), crates/config/tests/test_gap.rs (8 tests), crates/plugin-host/src/wasm_metric/tests.rs (test_gap reserved key), crates/report/tests/report_schema.rs, crates/cli/tests/integration/test_gap.rs (12 process-boundary tests), and crates/cli/tests/plugins.rs (coverage_reader_metric_plugin_receives_filled_function_and_language_coverage_facts).
  • Before the change: failed before implementation and on Round 1 revision (outside-repo --coverage-report and symlink escapes were not blocked; MCP relative coverage_reports resolved against ambient CWD before target repo; SF:../../... matched via suffix).
  • After the change: passed.

Checks

Check Result
cargo fmt --all --check passed
cargo clippy --workspace --all-targets --locked -- -D warnings passed
cargo test --locked -p codeint-config -p codeint-metrics -p codeint-report -p codeint-plugin-host passed
cargo test --locked -p codeint-cli --lib --test check --test plugins --test reference passed
cargo test --locked -p codeint-cli --test integration -- test_gap:: passed (12/12)
Hook checks (lefthook pre-commit: links, secrets, format, duplicates, markdown, repository; commit-msg) passed
cargo run --locked -p xtask -- merged-result, no-comments --base origin/main, commit-message --range origin/main passed
cargo run --locked -p codeint-cli -- diff origin/main --format toon passed (exit 0, 0 regressions)

Safety proof

  • Safety fact: (1) Repositories with no Coverage reports keep identical existing Metrics, Budgets, Regressions, codeint report re-rendering of saved pre-Test-gap JSON, and ResultCache behavior, with test_gap absent and one-line test_gap_note; (2) Coverage report loading is strictly contained within the Git repository (rejecting outside paths, symlinks, DTDs, XXE, entity expansion, non-XML PIs, depth > 64, and files > 64 MiB with exit 2 without reading outside files), and Test gap is consistent across LCOV, Cobertura XML, TOON, JSON, Markdown, SARIF, --package, --owner, Budgets, MCP, WASM Metric plugins, and ResultCache.
  • Proof: Round 1 Blast Radius on 234abc4 proved Safety Fact 1 across all commands, formats, and saved-report re-rendering; Round 2 clean-rerun Independent & Blast Radius verification on 970e2ee empirically proved Safety Fact 2 across outside relative/absolute/prefix-collision/symlink probes, ResultCache symlink isolation, MCP cross-repo CWD isolation, PathMatcher parent-traversal rejection, macOS /var canonicalization, and schema/docs parity.
  • interrogate:
    • Round 1 (234abc4, FAIL): Blast Radius found 3 path-containment defects (outside --coverage-report / MCP coverage_reports traversal and symlink escape in codeint.json) plus PathMatcher matching leading ..; Independent Verifier found MCP CWD resolution bug (crates/cli/src/check/coverage.rs:54) and doc drift in docs/reference.md:1520,1556 and docs/guide/mcp.md:43. All fixed in 970e2ee with regression tests.
    • Round 2 clean rerun (970e2ee, Independent & Blast Radius Verifier on isolated worktree): verified every Round 1 fix against target/debug/codeint -> Safety Fact 2 PROVEN, Verdict: PASS (0 open verified findings).

Runtime evidence

Build revision: 970e2ee on feat/223-test-gap.
Verified against built target/debug/codeint binary across check, diff, trend, report, init, schema, doctor, and mcp (JSON, TOON, Markdown, SARIF) with LCOV, Cobertura XML, mixed-format, hostile XML, outside-repo/symlink containment, WASM Metric plugin, and ResultCache probes; verdict: PASS.

Gaps

  • Deferred coverage: none.
  • Pre-existing failures: none.
  • Environmental failures: none.

@github-actions github-actions Bot added the tier-3 Tier 3 from the tier check label Nov 24, 2026
@avidianity
avidianity marked this pull request as ready for review November 24, 2026 09:45
@avidianity
avidianity merged commit 98ab73c into main Nov 24, 2026
13 checks passed
@avidianity
avidianity deleted the feat/223-test-gap branch November 24, 2026 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment