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
File diff suppressed because it is too large.
Load diff
@@ -36,7 +36,9 @@
|
||||
//! `events` (applying an event), `queries/` (each query family's answers
|
||||
//! and checks), `engine` (the `Engine` impl), `check` and `run` (the
|
||||
//! per-expectation and per-example drivers), and the tests by area
|
||||
//! (`examples`, `loader_tests`, `sources`, `rules_md`).
|
||||
//! (`examples`, `loader_tests`, `sources`, `rules_md`). `lean_model` is
|
||||
//! apart: random command sequences, checked against the Lean model of the
|
||||
//! ledger (`just lean-model`).
|
||||
|
||||
pub(crate) use std::borrow::Borrow;
|
||||
pub(crate) use std::collections::{BTreeMap, BTreeSet};
|
||||
@@ -85,6 +87,7 @@ mod common;
|
||||
mod engine;
|
||||
mod events;
|
||||
mod examples;
|
||||
mod lean_model;
|
||||
mod loader_tests;
|
||||
mod pin;
|
||||
mod queries;
|
||||
|
||||
Reference in new issue
Block a user