2 Commits
Author SHA1 Message Date
swaitsandClaude e86510489f fix(scripts): the raw-arithmetic detector reads a package with no library
`scripts/raw-decimal-arith.sh ledger-cli` stopped with cargo's error
("no library targets found"): the script asked clippy for `--lib`, and
ledger-cli is its programs alone. It now asks for the library and the
programs where there is a library, and the programs where there is not.

With that the count of money arithmetic outside the kernel is complete
for the outer crates: ledger-gui 137, ledger-import 22, ledger-mcp 19,
ledger-package 13, ledger-store 8, ledger-config 2, and none in
ledger-cli, ledger-host, ledger-reader and ledger-vault.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-11-09 19:50:40 -07:00
swaitsandClaude 95ae7717db test(core): a script that lists Decimal arithmetic done outside the kernel
The bar's first rule is that money arithmetic lives in `kernel/` and the
engine never gets a second copy: Kani and Lean prove the accounting laws
over the kernel's functions, so a sum or a sign flip written anywhere else
is arithmetic nothing has proved. Until now nothing measured how much of
it there is.

`scripts/raw-decimal-arith.sh [package [file.rs ...]]` lists every place
in a crate's own source, outside `kernel/` and the proof harnesses, that
does `Decimal` arithmetic without the kernel: raw operators, rust_decimal's
own `checked_*` and rounding methods, and `Iterator::sum`/`product`.

ledger-core today: 210 places. 101 raw operators, 104 calls to
rust_decimal's inherent `checked_add`/`sub`/`mul`/`div`, 4 `rescale`, one
`.sum()`. The earlier count of 100 saw only the operators, because
clippy's arithmetic lint does not look at method calls.

The method calls matter as much as the operators. `a.checked_add(b)` on a
`Decimal` is rust_decimal's method, not the kernel's, even with `Amount`
in scope, and rust_decimal rounds a result that needs more than 96 bits
where the kernel (K-U10) refuses it. A total that was rounded on the way
is not the sum of its lines, which is the one thing a ledger may not get
wrong quietly.

How it finds them: clippy cannot limit `arithmetic_side_effects` to one
type, so the script runs it twice, once flagging every type and once with
`Decimal` allowed, and keeps what drops out. The methods come from
`disallowed_methods`, which is exact about the type. A place under an
`#[allow]` for either lint is not listed; the last line counts those, so
a waiver cannot arrive unseen.

Not a gate yet: it exits 1 while the count is above zero, and `just check`
does not call it. K-U11 brings ledger-core to zero, then it goes in.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-11-09 16:22:31 -07:00