test(core): the Rust ledger and the Lean model agree on random command sequences
docs/verification.md proves the accounting laws of a model of the ledger (bookspec's Bookspec.Step, run by Bookspec.Exec.step); that the model is the engine was checked by review. This makes it a machine check. tests/bookspec/lean_model.rs generates random command sequences (entries balanced or not, with zero, negative, finer-than-a-cent and unknown-account lines; invoices; reversals of anything posted, twice, of a closing entry, backdated; closes to retained earnings over nested, disjoint, partly overlapping, inverted, empty and out-of-order periods), runs each through the Rust Ledger, writes it as a bookspec example whose expected values are the engine's own answers, and has `lake exe bookspec-check` (the pinned bookspec, built in a copy under target/) check every refusal, the trial balance after each event, and at the end the trial balance, balances, P&L and each posted entry's lines. All cases of a run go to one directory and one lake call; a failure is shrunk (rounds of single-event removal, one lake call each) and printed with both answers. `just lean-model [cases]` runs it with WANDERBOOKS_REQUIRE_LEAN=1; without lake it skips unless that is set. Refusal words the checker does not list are compared through a probe (the model's own word is read from its mismatch), so every refusal is checked, not skipped; the one word the model does not have (the control guard) is an explicit allow-listed skip. The D-73 gap (a backdated plain reversal the engine still accepts and the model refuses) is rolled back and counted. Findings, all of word only (both sides refuse, the books agree): the order of checks when a command fails two. Allow-listed in KNOWN_WORD_DIFFERENCES, pinned by a test that fails when one side changes, and by #[ignore]d d_* tests that assert agreement: reversing a closing entry or an already reversed entry on a closed day, an unknown account beside another fault, a zero line beside a negative one, a close inside a closed period (the model's own word closed_period_contains_end), a finer amount on a closed day (the example reader's order). Nothing in the engine or the model is changed. docs/verification.md's "Be precise about the claims" says what is now checked and what stays by review. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8874b603b4
commit
8775d38d0d
4 files changed
+1896
-3
No files matched your search
@@ -200,6 +200,15 @@ oracle:
|
||||
docker build -q -t bookspec-gnucash-oracle "$root/gnucash/oracle"
|
||||
cargo test -p ledger-core --test oracle_gnucash -- --ignored --nocapture
|
||||
|
||||
# The Rust ledger against the Lean model of it, on random command sequences
|
||||
# Each sequence is run through the engine, written as a bookspec example whose
|
||||
# expected values are the engine's answers, and checked by the Lean model
|
||||
# (`lake exe bookspec-check`, built from the pinned bookspec): a mismatch is the
|
||||
# engine and the model disagreeing. `cases` sequences, one `lake` call for all of
|
||||
# them (crates/ledger-core/tests/bookspec/lean_model.rs); fails without lake.
|
||||
lean-model cases="64":
|
||||
WANDERBOOKS_REQUIRE_LEAN=1 PROPTEST_CASES={{cases}} cargo test -p ledger-core --test bookspec lean_model -- --nocapture
|
||||
|
||||
# Fuzz one target for some seconds (nightly; corpus in fuzz/corpus/<target>)
|
||||
fuzz target="fuzz_op_sequence" seconds="300":
|
||||
#!/usr/bin/env bash
|
||||
|
||||
Reference in new issue
Block a user