Skip to content

Measure library code coverage in CI, at a 98% floor - #5

Merged
ndreno merged 2 commits into
mainfrom
chore/code-coverage
Sep 11, 2026
Merged

ndreno merged 2 commits into
mainfrom
chore/code-coverage

Conversation

@ndreno

@ndreno ndreno commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Why

You asked whether we check code coverage. We didn't — the existing CI "coverage" jobs (parse / operator / @rx) measure rule-language coverage across CRS, not how much of the engine's own code the tests run. Then you asked for more than 98%.

What

  1. A coverage job using cargo-llvm-cov (source-based instrumentation): runs the instrumented library tests once with all features, posts a summary to the run page, uploads lcov.info, and enforces a line-coverage floor.
  2. The tests to reach 98.6% line coverage (from 90.5% when the job first ran), and the floor set to 98.

Coverage

TOTAL   lines 98.6%   regions 97.7%   functions 97.9%

Measured locally with the exact CI command sequence; the 98 floor passes with headroom. 242 unit tests (was 172).

Most of the gap was code with no direct test, not untestable code:

File Added
collections.rs Had no test module. Resolve every collection/scalar, count and *_NAMES forms, combined-size, XML XPath forms, name/regex/whole-collection exclusions, macro context.
transaction.rs Response phases, accessors, every ctl: directive, the urlencoded/cookie parsers.
action.rs / operator.rs / parse.rs / engine.rs Parse error branches, metadata/disruptive/ctl arms, default-action resolution, chain-link compilation.
matcher.rs DirDataLoader read path, v4-mapped IP folding, bracketed-v6 and host:port address forms, empty operands.
transform / xml / multipart / rule Remaining decoder and parser edge cases.

What remains uncovered is defensive arms and a few unreachable-by-construction branches, not behaviour.

Matches the coverage setup added to barbacane, so both repos measure code coverage the same way.

The CI checked rule-language coverage (parse, operator and @rx coverage across
CRS) but never measured how much of the engine's own code the tests exercise.

Adds a coverage job using cargo-llvm-cov, source-based instrumentation, run
once over the library with all features and formatted three ways: a summary
posted to the run page, an lcov artifact, and a floor check. The floor is 88,
just under the current 90.5% line coverage, so ordinary variation does not fail
a build. Raise it when the real number rises; do not lower it to turn a red
build green.
The coverage job landed at 90.5% and an 88% floor. This adds the tests that
were missing to reach 98.6% line coverage, and raises the floor to 98.

Most of the gap was code with no direct test rather than untestable code:

- collections.rs had no test module at all. Added one that resolves every
  collection and scalar, the count and *_NAMES forms, combined-size, the XML
  XPath forms, regex and whole-collection exclusions, and the macro context.
- transaction.rs gained tests for the response phases, the accessors, every
  ctl: directive (ruleRemoveById/ByTag, ruleRemoveTarget*, requestBodyProcessor,
  ruleEngine Off/DetectionOnly, auditEngine), and the urlencoded/cookie parsers.
- action.rs, operator.rs, engine.rs, parse.rs gained tests for the parse error
  branches and the metadata/disruptive/ctl arms.
- matcher.rs gained the DirDataLoader read path, the v4-mapped IP folding, the
  bracketed-v6 and host:port address forms, and empty-operand handling.
- transform, xml, multipart, rule gained their remaining decoder and parser
  edge cases.

242 tests pass. What remains uncovered is defensive arms and a few
unreachable-by-construction branches, not behaviour.
@ndreno ndreno changed the title Measure library code coverage in CI Measure library code coverage in CI, at a 98% floor Sep 11, 2026
@ndreno
ndreno merged commit 109855b into main Sep 11, 2026
9 checks passed
@ndreno
ndreno deleted the chore/code-coverage branch September 11, 2026 08:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant