merge: a coverage report and floor; rust_decimal checked against exact rationals (V-D; branch t3/decimal-exact-coverage-floor, e6fe6e29; reviewed, fix applied)

Cargo.toml: both the dev-dependencies for decimal_exact and the bookspec
comment's new path kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Opus 5.5 committed 2026-11-08 17:11:27 -07:00
commit 4de03c1eaa
10 files changed
+750 -9

No files matched your search

+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
+25 -6
View File
@@ -804,12 +804,31 @@ Be precise about the claims:
written out and proved equal to the model's charge), and the bridge
property tests tie the `Decimal` (and `i128`) instantiation to the
`i64` (and `i32`) one Kani checked.
- **`Decimal` itself is trusted.** `rust_decimal` is exact for these
sizes: 96-bit integers scaled by a power of ten. With lines capped at
one quadrillion and ten decimal places, every sum is exact while the
total of all amounts stays below 7.9 × 10^18. Kani can't explore
`Decimal` arithmetic directly: a single symbolic add runs for more than
ten minutes.
- **`Decimal` itself is trusted, and now probed against exact
rationals.** `rust_decimal` is exact for these sizes: 96-bit integers
scaled by a power of ten. With lines capped at one quadrillion and ten
decimal places, every sum is exact while the total of all amounts stays
below 7.9 × 10^18. `crates/ledger-core/tests/decimal_exact.rs` checks
the operations the money paths use against `num_rational`/`num_bigint`
(an independent exact reference): `checked_add` and `checked_sub` over
signed line amounts to 1e15 at 0–10 places; 1,000-line sums; `checked_mul`
for ordinary quantities/rates and at the top of the line range while the
true product's mantissa fits 28 digits; `round_dp_with_strategy` for
every strategy the engine uses (`MidpointAwayFromZero`,
`MidpointNearestEven`, `ToZero`, `ToNegativeInfinity`) at every scale
0–28; `rescale`'s half-away rounding; `normalize`; comparison and equality
across scales (1.0 = 1.00); and `from_str`/`to_string` round trips at
every scale, including 28-digit mantissas and negative ties. It also pins
the one inexact edge: when a product's *scale* does not fit,
`checked_mul` rounds to 28 decimal places, ties to even, rather than
failing (`None` comes only when the integer part cannot fit). That case
is reachable through `Ledger::add_line_fx`, whose foreign amount and rate
are unbounded positive `Decimal`s; the base amount is then rounded to the
currency's minor unit. What is still trusted: the 96-bit representation
and `rust_decimal`'s implementation beyond the sampled properties (they
are tests, not a proof, and the edge cases are hand-written); Kani still
cannot explore `Decimal` arithmetic directly (a single symbolic add runs
for more than ten minutes).
- **The state machine is a model of `Ledger`'s checks**, not a proof
about `ledger.rs` line by line. Its correspondence to the code is
checked by review and by the end-to-end property tests in