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>
This commit is contained in:
swaitsandDeepSeek V4.1 Flash committed 2026-11-08 16:05:43 -07:00
1 parent b10804fb07
commit 986c75b31e
6 files changed
+222 -3

No files matched your search

+10
View File
@@ -28,6 +28,16 @@ jobs:
- uses: actions/checkout@v4
- uses: jdx/mise-action@v2
- run: just oracle
# Line, region and branch coverage of the core and the store, against the
# floor in docs/coverage-floor.md (docs/testing.md). Not a push gate: the
# instrumented suites are slow, so they run weekly, beside the proofs.
coverage:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: jdx/mise-action@v2
- run: just coverage
- run: just coverage-check
fuzz:
runs-on: ubuntu-24.04
strategy:
+75
View File
@@ -0,0 +1,75 @@
# Coverage floor
Line, region and branch coverage of the two crates every other crate is
built on, measured from their own test suites. `just coverage` writes the
HTML and a per-file table for each crate under `target/coverage/<crate>/`
(`summary.txt` is the table: regions, functions, lines and branches, with
missed counts and percentages); `just coverage-check` reads that report and
fails when a crate's **total line coverage** is more than 0.5 percentage
points below its recorded floor.
Why a floor, not a target: coverage is a tripwire for silently losing what
a test used to reach. It is not a measure of correctness — the property
tests, the GnuCash oracle, mutation testing and the proofs answer that. A
change that deletes, narrows or replaces a test must not also let the
report drift down unnoticed.
- Tool: `cargo-llvm-cov` 0.9.1, pinned in `mise.toml`. Branch coverage is
nightly-only (`-Zcoverage-options=branch`), so the run uses the pinned
`nightly-2026-10-01` and its `llvm-tools` component, also in
`mise.toml`.
- Measured: `ledger-core` and `ledger-store` library sources, each from
its own suite (`cargo llvm-cov -p <crate>`). Excluded:
`src/proofs.rs` (Kani-only, `cfg(kani)`, never in the test binary),
`tests/`, `benches/` and `examples/`, and the other workspace crates a
dev-dependency compiles instrumented (the core's tests use the store,
the store's use the core).
- The floor is the total line coverage recorded on the measurement date.
Regions and branches are recorded for context but not gated (branch
coverage on a nightly flag is noisier across compiler versions; line
coverage is the stable signal). 0.5 percentage points are tolerated for
measurement movement; more means a test stopped reaching what it used
to.
**Floor: `ledger-core` 90.01% lines, `ledger-store` 91.71% lines** (2026-11-08: the first measurement, from the full `just coverage` run; `ledger-core` 16,839 of 18,708 lines, `ledger-store` 14,255 of 15,543; 256-case properties everywhere, no special shard settings. The store measured 91.98% on an earlier run the same day; properties choose random cases, so a few tenths move between runs, which the 0.5 pp tolerance absorbs. The floor records the lower run.)
| Crate | Lines | Regions | Branches | Lines (covered / total) | Measured |
|---|---|---|---|---|---|
| `ledger-core` | 90.01% | 88.86% | 82.65% | 16,839 / 18,708 | 2026-11-08 |
| `ledger-store` | 91.71% | 85.27% | 80.73% | 14,255 / 15,543 | 2026-11-08 |
## First measurement: the fifteen files with the most uncovered lines
| File | Lines | Regions | Branches | Uncovered lines |
|---|---|---|---|---|
| `crates/ledger-core/src/ledger.rs` | 86.10% | 84.69% | 80.40% | 854 |
| `crates/ledger-store/src/store.rs` | 90.39% | 78.45% | 81.93% | 641 |
| `crates/ledger-store/src/root.rs` | 86.71% | 80.21% | 73.87% | 197 |
| `crates/ledger-core/src/conventions.rs` | 78.29% | 75.95% | 78.21% | 142 |
| `crates/ledger-core/src/evidence.rs` | 33.85% | 30.05% | 8.93% | 129 |
| `crates/ledger-core/src/settings.rs` | 91.05% | 87.70% | 81.25% | 117 |
| `crates/ledger-core/src/cashflow.rs` | 91.63% | 88.55% | 87.64% | 110 |
| `crates/ledger-core/src/audit.rs` | 80.50% | 78.33% | 61.36% | 93 |
| `crates/ledger-store/src/backup.rs` | 95.16% | 94.40% | 82.88% | 83 |
| `crates/ledger-core/src/arap.rs` | 87.97% | 87.67% | 91.46% | 77 |
| `crates/ledger-store/src/reconcilable.rs` | 0.00% | 0.00% | 0.00% | 76 |
| `crates/ledger-core/src/parties.rs` | 88.37% | 86.30% | 81.40% | 67 |
| `crates/ledger-store/src/meta.rs` | 91.32% | 84.56% | 83.33% | 66 |
| `crates/ledger-store/src/describe.rs` | 81.99% | 79.89% | 76.92% | 49 |
| `crates/ledger-core/src/kernel.rs` | 95.95% | 91.34% | 88.56% | 46 |
`reconcilable.rs` is the one whole-module hole: the store exposes it,
but the server and the viewer are its readers, so the store's own suite
never calls it. `ledger.rs`'s uncovered half is mostly the replay steps
of document and payroll commands (`mark_sent_steps`, `settle_steps`,
`run_payroll_steps`, ...), which the store's replay tests exercise; the
core's own suite does not. These are findings, not tasks for this
measurement.
The doors this closes, and the ones it does not: it catches a suite that
loses its reach (a deleted test, an ignored module, a helper no longer
called) and a source file added without tests, at the granularity of total
lines per crate. It does not try to floor each file: a refactor that moves
code between files would then fail for no accounting reason. Per-file
numbers are in `target/coverage/<crate>/summary.txt`; the fifteen files
with the most uncovered lines on the first measurement are the table above.
+3 -1
View File
@@ -28,6 +28,7 @@ promise.
| Miri | undefined behavior in our use of dependencies (4) | the core's unit, bridge, invariant tests (the exhaustive calendar walk aside) | `just miri` | ~4 min | on demand |
| Golden | `tests/golden/fixture_company.json` (5) | `invariants.rs` | `just check` | <1s | every change |
| Benchmarks | a baseline (6) | `ledger-core/benches/books.rs`, `ledger-store/benches/store.rs` | `just bench` | ~2 min | none (no budget, by decision) |
| Coverage | the code lines, regions and branches the suites execute (6) | `ledger-core` and `ledger-store` library sources (`src/proofs.rs` is Kani-only and excluded, as are test and bench files) | `just coverage` (HTML and a per-file table in `target/coverage/`), `just coverage-check` (docs/coverage-floor.md's floor, 0.5 pp tolerance) | ~1–3 h (nightly branch coverage) | weekly (`scheduled.yml`) |
| Mutation | can the tests fail? | `ledger-core` (2026-10-13: 1,011 caught + 13 timeouts of 1,024 viable, 0 missed) | `just mutants` | ~3 h | weekly |
| Mutation (store) | can the tests fail? | `ledger-store` (2026-10-13: 357 caught + 1 timeout of 365 viable, from 82%; three of its seven survivors then killed; four equivalent left: `sort_value`'s two arms, `OpenFlags` `|` vs `^`, the long form of a sweepless close) | `just mutants-store` | ~12 min | weekly |
| Mutation (import) | can the tests fail? | `ledger-import` (2026-10-13: from 91 of 171 (53%) to 208 of 239 viable on the full run; the 31 survivors (XLSX layout, borders, alignment, exact-text grouping, IIF transliteration, tax-summary optional sections, day-equals-month dates) then killed by targeted tests, re-run clean but one: a blank amount cell written unbordered on an unruled row, invisible, so equivalent; 2026-10-19, the first scheduled run in CI: 375 tested, 327 caught, 42 unviable, 6 missed (the tax-basis rule marks, a heading's alignment, the totals row's blank cells, and that blank cell, after all: a ruled row writes it, an unruled one writes none), all six then caught by `rule_marks_match_their_notes`, `asset_register_xlsx_headings_and_totals_rule` and `xlsx_missing_amounts_are_cells_only_on_ruled_rows`, each checked against its mutant by hand) | `just mutants-import` | ~2 h | weekly |
@@ -38,7 +39,8 @@ promise.
CI: `.github/workflows/check.yml` runs `just check` on every push;
`two-user.yml` the self-host deployment's two-account check (P9a);
`scheduled.yml` runs the proofs, the oracle and the fuzz targets weekly. Mutation ran there in shards until 2026-10-29 (`just mutants-mcp 3/16` runs the fourth of sixteen; GitHub stops a job at six hours), and is now local only (D-59). Test timeouts are three times each run's own baseline, never under the recipe's floor, so a slower runner doesn't report false timeouts. The viewer has no mutation job. Development mutation runs are paused until the P12 max-testing pass (D-33, 2026-10-20): each unit records its targets in a **For P12** paragraph instead. Mutation testing is a local run, not a CI job (the owner, 2026-10-29, D-59): the weekly shards were removed from `scheduled.yml`, and the "weekly" in the mutation rows above is history (the 2026-10-26 run: real survivors and timeouts in every crate, the debt P12 clears).
`scheduled.yml` runs the proofs, the oracle, the coverage report and floor,
and the fuzz targets weekly. Mutation ran there in shards until 2026-10-29 (`just mutants-mcp 3/16` runs the fourth of sixteen; GitHub stops a job at six hours), and is now local only (D-59). Test timeouts are three times each run's own baseline, never under the recipe's floor, so a slower runner doesn't report false timeouts. The viewer has no mutation job. Development mutation runs are paused until the P12 max-testing pass (D-33, 2026-10-20): each unit records its targets in a **For P12** paragraph instead. Mutation testing is a local run, not a CI job (the owner, 2026-10-29, D-59): the weekly shards were removed from `scheduled.yml`, and the "weekly" in the mutation rows above is history (the 2026-10-26 run: real survivors and timeouts in every crate, the debt P12 clears).
Seeds and failure databases: proptest's `*.proptest-regressions` files
are checked in and replay on every run. The GnuCash oracle's books come
+73
View File
@@ -160,6 +160,79 @@ fuzz target="fuzz_op_sequence" seconds="300":
miri:
PROPTEST_CASES=4 MIRIFLAGS="-Zmiri-disable-isolation" cargo +nightly-2026-10-01 miri test -p ledger-core --lib --test kernel_bridge --test invariants
# Line, region and branch coverage of the core and the store, from their
# own test suites (nightly's -Zcoverage-options=branch, so every `if` has a
# taken/not-taken record too). HTML and a plain per-file table land in
# target/coverage/<crate>/; docs/coverage-floor.md records the totals and
# `coverage-check` guards them. Not a push gate (it is slow), but the
# weekly scheduled workflow runs it. `src/proofs.rs` is Kani-only (cfg(kani))
# and is excluded, as are test and bench files: this measures the library.
coverage crate="all":
#!/usr/bin/env bash
set -euo pipefail
# The shared sccache wrapper (~/.cargo/config.toml) would hand rustc to
# whatever toolchain it finds, and a `RUSTUP_TOOLCHAIN` in the caller's
# environment (1.99.1 in a session here) would beat `+nightly` for the
# rustc cargo-llvm-cov invokes. Both are overridden explicitly: branch
# coverage needs the pinned nightly. The build is its own target dir
# (`target/llvm-cov-target`), so sccache would not be shared anyway.
export RUSTC_WRAPPER=
export RUSTUP_TOOLCHAIN=nightly-2026-10-01
# Name the compiler itself: the mise shim around cargo-llvm-cov can put
# its pinned stable toolchain back, and a bare `rustc` then loses the
# nightly flag. Call the binary directly, as `fuzz` does with cargo-fuzz.
export RUSTC="$(rustup which --toolchain "$RUSTUP_TOOLCHAIN" rustc)"
llvm_cov=$(mise which cargo-llvm-cov)
mkdir -p target/coverage
# Every workspace member but the crate under measurement: a dev-dependency
# (the core's tests use the store, the store's use the core) is compiled
# instrumented too, and its files must not enter this crate's totals.
others() {
local keep=$1 member
local list=()
for member in ledger-core ledger-store ledger-config ledger-mcp \
ledger-import ledger-reader ledger-cli ledger-gui ledger-vault \
ledger-host ledger-package; do
[ "$member" = "$keep" ] || list+=("${member#ledger-}")
done
local IFS='|'
echo "crates/ledger-(${list[*]})/"
}
run() { # crate
local crate=$1 dir="target/coverage/$1"
local ignore="$(others "$crate")|/(tests|benches|examples)/|/src/proofs\\.rs$"
mkdir -p "$dir"
# One instrumented test run: the HTML comes from it; the JSON and the
# table are regenerated from the same profiles, cheaply.
# `--failure-mode all`: the store's tests start and kill server
# processes, which inherit LLVM_PROFILE_FILE; a SIGKILLed child leaves
# a truncated profraw that llvm-profdata refuses. That file has no
# test coverage in it, so it is tolerated; the test binaries' own
# profiles merge normally.
"$llvm_cov" llvm-cov -p "$crate" --branch --failure-mode all \
--ignore-filename-regex "$ignore" \
--html --output-dir "$dir"
"$llvm_cov" llvm-cov report --failure-mode all \
--ignore-filename-regex "$ignore" \
--json --output-path "$dir/coverage.json"
"$llvm_cov" llvm-cov report --failure-mode all \
--ignore-filename-regex "$ignore" > "$dir/summary.txt"
echo "coverage: $crate written to $dir/html and $dir/summary.txt"
awk -v crate="$crate" '$1 == "TOTAL" { printf "coverage: %s lines %s, regions %s, branches %s\n", crate, $10, $4, $13 }' "$dir/summary.txt"
}
case "{{crate}}" in
all) run ledger-core; run ledger-store ;;
ledger-core | ledger-store) run "{{crate}}" ;;
*) echo "coverage: unknown crate '{{crate}}' (all, ledger-core, ledger-store)" >&2; exit 2 ;;
esac
echo "coverage: floors in docs/coverage-floor.md; check them with \`just coverage-check\`"
# The coverage floor: fails when either crate's total line coverage is more
# than 0.5 percentage points below docs/coverage-floor.md's recorded number
# (reads the last `just coverage` report; it does not rerun the tests).
coverage-check:
@scripts/coverage-floor.sh
# Where cargo-mutants copies and builds the tree for each mutant (several
# GB per job): the user's cache on disk, never /tmp, which is often RAM.
# The tests it runs honor the same TMPDIR (every test's books go in
+6 -2
View File
@@ -5,8 +5,9 @@
# Workspace toolchain (clippy and rustfmt for `just check`).
rust = [
{ version = "1.99", components = "clippy,rustfmt", targets = "x86_64-pc-windows-msvc" },
# Fuzzing (cargo-fuzz) and Miri need nightly; pinned so runs repeat.
{ version = "nightly-2026-10-01", components = "miri,rust-src" },
# Fuzzing (cargo-fuzz), Miri and branch coverage need nightly; pinned so
# runs repeat. `llvm-tools` is what cargo-llvm-cov reads profiles with.
{ version = "nightly-2026-10-01", components = "miri,rust-src,llvm-tools" },
]
just = "1"
# `just deploy` runs the Netlify CLI through npx.
@@ -20,6 +21,9 @@ node = "26"
# Mutation testing and fuzzing (docs/oracle.md).
"cargo:cargo-mutants" = "27.1.0"
"cargo:cargo-fuzz" = "0.13.2"
# `just coverage`: line and branch coverage of the core and the store
# (docs/coverage-floor.md).
"cargo:cargo-llvm-cov" = "0.9.1"
# A compile cache shared by every jj workspace's target dir: point
# cargo's build.rustc-wrapper at it (~/.cargo/config.toml).
sccache = "0.18.0"
+55
View File
@@ -0,0 +1,55 @@
#!/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"