merge: the Rust ledger and the Lean model agree on random command sequences, refusals checked under D-74 (L-G5; branch t3/lean-model-differential-test; reviewed, fixes applied)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Opus 5.5 committed 2026-11-08 17:14:33 -07:00
commit 5de13d480b
5 files changed
+2139 -3

No files matched your search

+6
View File
@@ -22,6 +22,12 @@ jobs:
- uses: actions/checkout@v4
- uses: jdx/mise-action@v2
- run: just prove-slow
lean-model:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: jdx/mise-action@v2
- run: WANDERBOOKS_REQUIRE_LEAN=1 just lean-model 256
oracle:
runs-on: ubuntu-24.04
steps:
File diff suppressed because it is too large. Load diff
+4 -1
View File
@@ -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;
+30 -2
View File
@@ -831,9 +831,37 @@ Be precise about the claims:
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
checked by a differential test and, for what the test cannot say, by
review. `tests/bookspec/lean_model.rs` (`just lean-model`, P14 L-G5)
generates random command sequences (entries, balanced or not, with
zero, negative, finer-than-a-cent and unknown-account lines; invoices
and bills; 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 answers, and has the Lean model
(`bookspec-check`, built from the pinned bookspec, running
`Bookspec.Exec.step`) check the same sequence: every refusal, the
trial balance after each event, and at the end the trial balance,
balances, profit and loss and each posted entry's lines. Any mismatch
fails the test with the shrunk sequence and both answers. What it
compares is bounded by what an example can say, and so these stay by
review: a standalone `openPeriod`; a generic close with explicit
targets (only `closeToRetained` is reachable); lingering drafts
(`drafts_in_period`, `discard`: both sides draft and post in one
event, so no draft lingers); `addAccount` after setup (the chart is
the setup's); and a reversal of an event that posted nothing. So do
the model's records, and the checks it does not carry (the control
guard's refusal is skipped, by an allow-list). Where the engine and
the model refuse in different words, D-74 (owner, 2026-11-08) settles
it: a command that breaks several rules may be refused with any rule
it actually breaks, so the test checks both words with an independent
function (`word_applies`, written from the bookspec rules, reading
only the books before the command), and fails — printing the command,
that state, and both words — when a word does not apply. The older
end-to-end property tests in
`tests/properties.rs` (trial balance, balance sheet, reversals,
immutability) and the golden files.
immutability) and the golden files remain.
- **Out of scope:** currency (the ledger is single-currency, enforced
structurally), payroll, the calendar walk around
the proration kernel (`calendar::month_parts`, `assets::depreciation_schedule`,
+9
View File
@@ -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