Files
swaitsandDeepSeek V4.1 Flash 986c75b31e feat(just): coverage report and floor
Coverage is a tripwire, not a correctness oracle: the proofs, the
property tests, the GnuCash cross-check and mutation testing answer
whether the books are right; a line/branch report answers whether a test
still reaches the code it used to. This adds that measurement, pinned in
mise.toml like every other tool: cargo-llvm-cov 0.9.1, and the
llvm-tools component on the pinned nightly because branch coverage is
nightly-only (-Zcoverage-options=branch).

`just coverage` runs each crate's own suite instrumented (core and
store separately, so one crate's dev-dependency code does not enter the
other's totals), writes HTML, the JSON and the plain per-file table under
target/coverage/<crate>/, and excludes src/proofs.rs (Kani-only,
cfg(kani)) plus test and bench files: it measures the library.
`just coverage-check` reads docs/coverage-floor.md and fails when a
crate's total line coverage is more than 0.5 pp below its floor; regions
and branches are recorded for context but not gated, since branch
coverage is the noisier number across compiler versions.

First measurement from the full run: ledger-core 90.01% lines (88.86%
regions, 82.65% branches), ledger-store 91.71% lines (85.27%, 80.73%).
The store measured 91.98% on an earlier run the same day; properties pick
random cases, so a few tenths move between runs and the 0.5 pp tolerance
absorbs it (the floor records the lower run). The largest holes are
findings, not fixes here: ledger-store/reconcilable.rs is 0% (the server
and viewer are its readers; the store suite never calls it), and
ledger.rs is mostly the document/payroll replay steps the store's replay
tests exercise rather than the core's own.

It is not a push gate (the instrumented suites are slow: the store alone
runs about a hundred minutes of tests once built); the weekly scheduled
workflow runs it beside the proofs. The store's tests start and kill
helper processes that inherit LLVM_PROFILE_FILE, so a killed child can
leave a truncated profraw; the run passes --failure-mode all, which
merges the test binaries' profiles and ignores such a file (it holds no
test coverage).

Co-Authored-By: DeepSeek V4.1 Flash <noreply@opencode.ai>
2026-11-08 16:05:43 -07:00

56 lines
2.0 KiB
Bash
Executable File

#!/bin/bash
# The coverage floor (docs/coverage-floor.md): `just coverage` measures the
# core's and the store's line, region and branch coverage into
# target/coverage/<crate>/; this reads those reports and fails when a
# crate's total line coverage has fallen more than 0.5 percentage points
# below its recorded floor. The report is not regenerated here on purpose:
# `just coverage-check` is the cheap gate over the last `just coverage`
# run, in the same job in CI.
#
# Usage: scripts/coverage-floor.sh
set -euo pipefail
cd "$(git rev-parse --show-toplevel)"
doc=docs/coverage-floor.md
if [ ! -f "$doc" ]; then
echo "coverage floor: $doc is missing" >&2
exit 1
fi
status=0
for crate in ledger-core ledger-store; do
summary="target/coverage/$crate/summary.txt"
if [ ! -f "$summary" ]; then
echo "coverage floor: $summary is missing; run \`just coverage\` first" >&2
exit 1
fi
# The `**Floor: ...**` line, e.g. `ledger-core` 87.34% lines.
floor=$(sed -n "s/.*\`$crate\` \([0-9][0-9]*\.[0-9][0-9]*\)% lines.*/\1/p" "$doc" | head -n 1)
if [ -z "$floor" ]; then
echo "coverage floor: $doc has no floor for $crate" >&2
exit 1
fi
# THE report table's TOTAL row: columns are Regions, Missed Regions,
# Cover, Functions, Missed Functions, Executed, Lines, Missed Lines,
# Cover, Branches, Missed Branches, Cover. $10 is line cover, $13
# branch cover, $4 region cover.
total=$(awk '$1 == "TOTAL" { print $10 }' "$summary" | tr -d '%')
if [ -z "$total" ]; then
echo "coverage floor: $summary has no TOTAL row" >&2
exit 1
fi
if awk -v actual="$total" -v floor="$floor" \
'BEGIN { exit !(actual + 0 >= floor - 0.5) }'; then
echo "coverage floor: $crate ${total}% lines (floor ${floor}%, tolerance 0.5 pp)"
else
echo "coverage floor: $crate is at ${total}% lines, more than 0.5 pp below its ${floor}% floor (docs/coverage-floor.md)" >&2
status=1
fi
done
exit "$status"