Files
wanderbooks/crates/ledger-core/tests/bookspec/main.rs
T
swaitsandDeepSeek V4.1 Flash e431791bbc build(lean): verify/lean requires bookspec's Lean; the laws live once
D-69 puts the accounting laws in one place: bookspec's Lean, namespace
`Bookspec`. L-F1 landed there every file of `verify/lean/Wanderbooks/`.
Before deleting the copies, each was checked: comments stripped, namespace
normalised, blank lines dropped, and diffed against its bookspec peer --
all ten are identical (Basic, Entry, Statements, Closing, Ledger,
Apportion, Parties, Prorate, Deductible, Documents). There is nothing
wanderbooks-only left to keep.

So `verify/lean/lakefile.toml` now `[[require]]`s bookspec as a git
dependency at 77e046334eea29e082b53bbe907017d9ffef5a0a -- the same rev
`crates/ledger-core/Cargo.toml` pins the Rust checker to -- with
`subDir = "lean"`. The generated `lake-manifest.json` is committed, because
Lake builds from it and it must not float.

`Wanderbooks.lean` is now a thin local target that imports `Bookspec`:
`lake build` builds and checks the whole law set, and the file says where
a law is edited and how wanderbooks picks it up (move the pin). The
duplicated modules and the `Wanderbooks/` directory are gone.

`Audit.lean` imports `Bookspec` and audits all 151 theorems (the 118
headline laws plus the 33 named laws in `Laws.lean` that cite them) --
the whole set bookspec itself audits. `just prove` still checks standard
axioms only; its summary now says "theorems", since the set is more than
headline ones.

The new `tests/bookspec/pin.rs` reads the rev out of the lakefile, the
manifest, and both crates' Cargo.toml, and fails unless all four name the
same repository at the same commit, and bookspec's `lean/` package. Without
it the Lean laws and the Rust checker could silently be different spec
versions.

Verified: `lake build` from a clean `.lake` (fetches and builds in 7 s);
`just prove` 871 s (Kani 53 harnesses, then 151 theorems, standard axioms
only); `cargo test -p ledger-core --test bookspec pin`; `cargo fmt --check`;
`cargo clippy -p ledger-core --tests -D warnings`.

Co-Authored-By: DeepSeek V4.1 Flash <noreply@opencode.ai>
2026-11-08 11:35:07 -07:00

94 lines
4.4 KiB
Rust

//! The bookspec examples (`bookspec/examples/*.toml`, P13, D-34), checked
//! against the engine on every run, so they can't rot. This is the one
//! place every example is loaded.
//!
//! Each example is a setup, events and expected values worked by hand from
//! its cited source (`bookspec/README.md` gives the shape). Every example
//! must load, whatever it asks or whichever appendix it is in: its shape,
//! its accounts, fixed assets, schedules, parties, members, payees,
//! payees' dated 1099 decisions and payment methods, every event (an
//! entry, a reversal, a close, a bill, or a command that posts what is
//! due: a depreciation run, a disposal, a schedule run or registration),
//! each accepted or refused as it says, with the parties, payee and
//! payment method it is tagged with, and every change that posts no entry
//! (a rename, a policy, an asset's correction). The books are the
//! engine's own store (`ledger_store::Store`, in a directory of their
//! own), so every event goes through the command the books take it by,
//! journaled, and the books must replay to what was kept
//! (`Store::verify`). The queries the
//! core answers (`cash_flow`, `trial_balance`, `profit_and_loss`,
//! `vendor_1099_paid`, `vendor_1099`, `entry`, `balances`,
//! `members_equity`, `k1`, `k1_tax_basis`, `k1_reconciliation`,
//! `party_part`, `party_totals`, `party_tin_last4`, `period`, `day`,
//! `calendar_year`, `account_names`, `uncategorized_accounts`, `run`,
//! `disposal`, `depreciation_schedule`, `schedule_plan`, `register_row`,
//! `register_totals`, `asset_basis`) are then checked value by value, and
//! the commands it tries (`rename_account`, `add_account`,
//! `set_tax_category`) accepted or refused on a copy of the books, each
//! after the event it names (`after`) or the last; the formats appendix's
//! (`iif_lines`, `iif_changes`) are checked by ledger-package
//! (`the_bookspec_iif_example_matches_the_engine`), and a query no crate
//! answers is refused. A key the shape doesn't have is refused too, never
//! ignored.
//!
//! The adapter is split by area: `common` (the shared vocabulary and the
//! date and refusal rules), `books` (an example's books and their setup),
//! `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`).
pub(crate) use std::borrow::Borrow;
pub(crate) use std::collections::{BTreeMap, BTreeSet};
pub(crate) use std::path::Path;
pub(crate) use chrono::{Datelike, NaiveDate};
pub(crate) use ledger_core::calendar::{PeriodDefaults, period_defaults};
pub(crate) use ledger_core::parties::{Basis, MoneyAccounts};
pub(crate) use ledger_core::settings::{Company, Source};
pub(crate) use ledger_core::tax_capital::TaxCapitalRow;
pub(crate) use ledger_core::{
AccountType, AssetId, CashFlowParams, CashFlowSection, CashFlowStatement, CloseTo, Currency,
Dated1099, Decision1099, DocumentLine, EntryId, EntryStatus, ExemptReason, Form1099,
InstrumentId, InstrumentKind, Ledger, LedgerError, MemberCapital, MemberClose, Money, NewAsset,
NewSchedule, PartyId, PartyMember, PartyShare, PaymentAccounts, ReconcilingKind, Role,
ScheduleConvention, ScheduleId, ScheduleKind, Share, Side, TinFacts, TinType, VendorId,
W9Facts, cash_flow, members_equity, profit_and_loss_for_period, trial_balance_as_of,
vendor_1099_report,
};
pub(crate) use ledger_store::{DepreciationRun, DisposalPreview, Store, StoreError};
pub(crate) use rust_decimal::Decimal;
pub(crate) use bookspec_checker::{
AccountSpec, Area, BasisSpec, ChangeSpec, Claims, DocumentLineSpec, Engine, Event, Example,
Expect, Query, Refusal, RuleId, ScheduleSpec, Setup, Values,
};
pub(crate) use ledger_import::IifField;
pub(crate) use ledger_package::export_iif;
pub(crate) use serde_json::Value;
pub(crate) use books::*;
pub(crate) use check::check;
pub(crate) use common::*;
pub(crate) use queries::assets::*;
pub(crate) use queries::commands::*;
pub(crate) use queries::dates::*;
pub(crate) use queries::formats::*;
pub(crate) use queries::parties::*;
pub(crate) use queries::statements::*;
pub(crate) use queries::tax::*;
pub(crate) use run::{load, run};
mod books;
mod check;
mod common;
mod engine;
mod events;
mod examples;
mod loader_tests;
mod pin;
mod queries;
mod rules_md;
mod run;
mod sources;