From ea4d8bc86e6dff43b65bbdda5f78e8241fa94aea Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Mon, 9 Nov 2026 00:16:28 -0700 Subject: [PATCH 01/15] test(core): the adapter runs settlements, recoveries, numbers and vendor references bookspec's X-H1b examples state BS-arap-4, -6 and -10 to -14 through new events and queries; the adapter runs each through the real API, none reimplemented. - settlement: `Store::settle` with the applications, the fee and the deposit account; the party is the first document's customer or vendor, so the engine itself finds an invoice mixed with a bill, two customers, a document twice, more than a document owes, a discount that needs a reason, a discount on an asset bill and a fee above the cash. Each engine error is read as the examples' word (the fee case from the one InvalidSettlement error that can arise from exact inputs). - recovery (BS-arap-11, reverse-then-plain-entry): in the write-off's fiscal year `Store::reverse_entry` of the write-off then `Store::receive_payment`; in a later year a plain entry, deposit debited and the recoveries account credited, naming the invoice. The engine has no recovery command; the two calls are the pick's own procedure. - a bill's vendor reference and duplicate reason go to `BillFields`, so `Ledger::check_vendor_ref` is what refuses a second bill; each invoice is numbered with `Ledger::next_invoice_number`; a line's own account goes to `DocumentLine`. - queries `document` (`Ledger::invoice_state`/`bill_state`) and `invoice_numbers` (the number the engine stored, read as its place in the order of issue). Wanderbooks passes all 80 examples it runs. The runner skips eleven for the options it did not pick (six new: documents-kept-apart, compare-exactly, recovery-movement, net-of-expected-discount, net-against-the-deposit, apportion-across-the-lines), so the pinned count is 11. No engine disagreed with an example. Co-Authored-By: Claude Sonnet 5.5 --- crates/ledger-core/tests/bookspec/check.rs | 8 +- crates/ledger-core/tests/bookspec/common.rs | 16 +++ crates/ledger-core/tests/bookspec/events.rs | 131 +++++++++++++++++- crates/ledger-core/tests/bookspec/examples.rs | 13 +- .../tests/bookspec/queries/documents.rs | 83 +++++++++++ .../ledger-core/tests/bookspec/queries/mod.rs | 2 + 6 files changed, 242 insertions(+), 11 deletions(-) diff --git a/crates/ledger-core/tests/bookspec/check.rs b/crates/ledger-core/tests/bookspec/check.rs index 194088fe..019a21a6 100644 --- a/crates/ledger-core/tests/bookspec/check.rs +++ b/crates/ledger-core/tests/bookspec/check.rs @@ -38,7 +38,11 @@ pub(crate) fn check(b: &Books<'_>, x: &Expect) -> Option<&'static str> { ); only(x.basis.is_some(), "basis", &["party_totals"]); only(x.payee.is_some(), "payee", &["vendor_1099"]); - only(x.document.is_some(), "document", &["document_dates"]); + only( + x.document.is_some(), + "document", + &["document_dates", "document"], + ); only(x.of.is_some(), "of", &["aging"]); only( x.code.is_some(), @@ -105,6 +109,8 @@ pub(crate) fn check(b: &Books<'_>, x: &Expect) -> Option<&'static str> { "project" => check_project(b, x), "aging" => check_aging(b, x), "document_dates" => check_document_dates(b, x), + "document" => check_document(b, x), + "invoice_numbers" => check_invoice_numbers(b, x), q => { let &(_, by) = FORMAT_QUERIES .iter() diff --git a/crates/ledger-core/tests/bookspec/common.rs b/crates/ledger-core/tests/bookspec/common.rs index 5befdcfc..eaa2b261 100644 --- a/crates/ledger-core/tests/bookspec/common.rs +++ b/crates/ledger-core/tests/bookspec/common.rs @@ -144,6 +144,22 @@ pub(crate) fn refusal(e: &LedgerError) -> String { LedgerError::InvalidSchedule(_) => "invalid_schedule", LedgerError::UntaggedControlLine { .. } => "untagged_control_line", LedgerError::PaymentBeforeDocument { .. } => "payment_before_document", + LedgerError::DuplicateVendorRef { .. } => "duplicate_vendor_reference", + // An invoice with a bill, and documents of two parties, are the one + // refusal: a customer and a vendor are two parties (BS-arap-6). + LedgerError::SettlementMixedKinds(_) | LedgerError::SettlementPartiesDiffer(..) => { + "settlement_mixes_parties" + } + LedgerError::SettlementDuplicateDocument(_) => "settlement_repeats_a_document", + LedgerError::Overpayment(..) => "application_above_owed", + LedgerError::DiscountNeedsReason { .. } => "discount_needs_reason", + LedgerError::DiscountOnAssetBill { .. } => "discount_on_asset_bill", + // The cash and the discounts the adapter hands over always cover the + // applications exactly, so the one way the engine's exactness check + // fails is a fee above the cash (BS-arap-6). + LedgerError::InvalidSettlement(why) if why.contains("the fee is above the cash") => { + "fee_above_cash" + } LedgerError::UnbalancedEntry { .. } => "unbalanced", LedgerError::TooFewLines => "too_few_lines", LedgerError::NegativeAmountLine => "negative_amount", diff --git a/crates/ledger-core/tests/bookspec/events.rs b/crates/ledger-core/tests/bookspec/events.rs index 00eba781..82a35e55 100644 --- a/crates/ledger-core/tests/bookspec/events.rs +++ b/crates/ledger-core/tests/bookspec/events.rs @@ -14,6 +14,8 @@ impl Books<'_> { ("invoice", e.invoice.is_some()), ("write_off", e.write_off.is_some()), ("payment", e.payment.is_some()), + ("settlement", e.settlement.is_some()), + ("recovery", e.recovery.is_some()), ("run_depreciation", e.run_depreciation.is_some()), ("dispose_asset", e.dispose_asset.is_some()), ("run_schedules", e.run_schedules.is_some()), @@ -22,7 +24,7 @@ impl Books<'_> { match kinds.iter().filter(|(_, given)| *given).collect::>()[..] { [(kind, _)] => kind, _ => panic!( - "{} event {n}: an event is one of lines, reverses, close, bill, invoice, write_off, payment, run_depreciation, dispose_asset, run_schedules or register_schedule", + "{} event {n}: an event is one of lines, reverses, close, bill, invoice, write_off, payment, settlement, recovery, run_depreciation, dispose_asset, run_schedules or register_schedule", self.ex.id ), } @@ -36,7 +38,11 @@ impl Books<'_> { // disposal is dated; the other commands date their own entries, // and every command describes its own. let own = matches!(kind, "lines" | "reverses" | "close" | "bill" | "invoice"); - let dated = own || matches!(kind, "dispose_asset" | "write_off" | "payment"); + let dated = own + || matches!( + kind, + "dispose_asset" | "write_off" | "payment" | "settlement" | "recovery" + ); assert_eq!( e.date.is_some(), dated, @@ -74,8 +80,8 @@ impl Books<'_> { "{ex} event {n}: {kind} is tagged with no parties or payment method" ); assert!( - e.refused.is_none() || !matches!(kind, "close" | "bill" | "invoice"), - "{ex} event {n}: refused is for a reversal, an entry or a command, which the books take whole or not at all" + e.refused.is_none() || !matches!(kind, "close" | "invoice"), + "{ex} event {n}: refused is for a reversal, an entry, a bill or a command, which the books take whole or not at all" ); assert!( !(e.older && e.refused.is_some()), @@ -89,6 +95,14 @@ impl Books<'_> { e.payment.is_none() || kind == "payment", "{ex} event {n}: a payment is its own event" ); + assert!( + e.settlement.is_none() || kind == "settlement", + "{ex} event {n}: a settlement is its own event" + ); + assert!( + e.recovery.is_none() || kind == "recovery", + "{ex} event {n}: a recovery is its own event" + ); } /// Take event `n` as the books take it, keep what it posted and tag it @@ -197,9 +211,18 @@ impl Books<'_> { "{what}: entry {id}, which it made, is posted" ); } - if (own || matches!(kind, "write_off" | "payment")) && e.refused.is_none() { + if (own || matches!(kind, "write_off" | "payment" | "settlement")) && e.refused.is_none() { assert_eq!(posted.len(), 1, "{what}: {kind} posts one entry"); } + // A recovery posts one entry or two, as the engine's pick under + // BS-arap-11 says: a plain entry, or the write-off's reversal and + // the payment. + if kind == "recovery" && e.refused.is_none() { + assert!( + matches!(posted.len(), 1 | 2), + "{what}: a recovery posts one entry or two" + ); + } } /// The terms a document's example gives, and the due date the books take @@ -230,6 +253,20 @@ impl Books<'_> { (due, Some(parsed)) } + /// The invoice or bill event `event` posted, and its customer or vendor. + pub(crate) fn document_of(&self, event: usize, what: &str) -> (ledger_core::DocRef, u64) { + let entry = self.entry_of(event, what); + let l = self.l(); + match ( + l.invoices().into_iter().find(|i| i.entry_id == entry), + l.bills().into_iter().find(|b| b.entry_id == entry), + ) { + (Some(i), _) => (ledger_core::DocRef::Invoice(i.id), i.customer_id), + (None, Some(b)) => (ledger_core::DocRef::Bill(b.id), b.vendor_id), + (None, None) => panic!("{what}: event {event} posted no invoice or bill"), + } + } + /// An invoice's or bill's lines: `amount` (one line, described as the /// event) or `lines`, exactly one; each project a `setup.projects` /// name. @@ -264,7 +301,7 @@ impl Books<'_> { panic!("{what}: project {p:?} not in setup.projects") }) }), - account: None, + account: l.account.as_deref().map(|code| self.id(code)), quantity: None, unit_price: None, }) @@ -410,6 +447,8 @@ impl Books<'_> { lines, BillFields { terms, + vendor_ref: b.vendor_ref.clone(), + duplicate_reason: b.duplicate_reason.clone(), ..BillFields::default() }, ) @@ -427,6 +466,9 @@ impl Books<'_> { } }; let (due, terms) = self.terms_due(i.terms.as_deref(), day(), what); + // The books number every invoice in order of issue (BS-arap-4), + // as their invoicing settings default to. + let number = self.l().next_invoice_number("INV-", 1); self.store .create_invoice_with( customer, @@ -434,6 +476,7 @@ impl Books<'_> { due, lines, InvoiceFields { + number: Some(number), terms, ..InvoiceFields::default() }, @@ -515,6 +558,82 @@ impl Books<'_> { } } } + "settlement" => { + let st = e.settlement.as_ref().expect("checked: a settlement"); + let first = &st.applications[0]; + let (first_doc, party) = self.document_of(first.document, what); + let applications: Vec = st + .applications + .iter() + .map(|a| ledger_core::Application { + doc: self.document_of(a.document, what).0, + cash: exact(&a.cash, what), + discount: a + .discount + .as_deref() + .map_or(Decimal::ZERO, |d| exact(d, what)), + discount_reason: a.discount_reason.clone(), + }) + .collect(); + debug_assert_eq!(applications[0].doc, first_doc); + let params = ledger_core::SettleParams { + date: day(), + description: String::new(), + cash_account: self.id(&st.account), + party, + applications, + fee: st.fee.as_deref().map(|f| ledger_core::Fee { + amount: exact(f, what), + account: None, + vendor: None, + }), + instrument: None, + reference: None, + }; + self.store.settle(params).map(drop) + } + "recovery" => { + // BS-arap-11, the pick reverse-then-plain-entry: in the tax + // year of the write-off the write-off is reversed and the + // money is recorded as any payment; in a later year a plain + // entry debits the deposit account and credits the recoveries + // account, naming the invoice. + let r = e.recovery.as_ref().expect("checked: a recovery"); + let amount = exact(&r.amount, what); + let (cash, income) = (self.id(&r.account), self.id(&r.income_account)); + let write_off = self.entry_of(r.write_off, what); + let written = &self.ex.events[r.write_off - 1]; + let invoice_event = written + .write_off + .as_ref() + .map(|w| w.invoice) + .unwrap_or_else(|| panic!("{what}: event {} is no write-off", r.write_off)); + let (doc, _) = self.document_of(invoice_event, what); + let ledger_core::DocRef::Invoice(invoice) = doc else { + panic!("{what}: a write-off is of an invoice") + }; + let written_on = date(written.date.as_deref().expect("a write-off is dated"), what); + let year = + |d| ledger_core::calendar::fiscal_year_start_on(fiscal_year_start(self.ex), d); + if year(written_on) == year(day()) { + self.store.reverse_entry( + write_off, + day(), + "Recovered: the write-off is reversed", + )?; + self.store + .receive_payment(invoice, day(), amount, cash) + .map(drop) + } else { + let entry = self + .store + .create_entry(day(), &format!("Recovery of invoice {invoice}"))?; + let money = Money::new(amount, self.currency); + self.store.add_line(entry, cash, Side::Debit, money)?; + self.store.add_line(entry, income, Side::Credit, money)?; + self.store.post_entry(entry) + } + } "run_depreciation" => { let r = e.run_depreciation.as_ref().expect("checked: a run"); let asset = self.asset(&r.asset, what); diff --git a/crates/ledger-core/tests/bookspec/examples.rs b/crates/ledger-core/tests/bookspec/examples.rs index a8e5b0be..c1d34691 100644 --- a/crates/ledger-core/tests/bookspec/examples.rs +++ b/crates/ledger-core/tests/bookspec/examples.rs @@ -146,6 +146,8 @@ pub(crate) fn every_bookspec_example_holds() { ("project", 6), ("aging", 4), ("document_dates", 8), + ("document", 8), + ("invoice_numbers", 1), ] { let n = checked.get(q).copied().unwrap_or(0); assert!(n >= at_least, "{q} ran {n} times, fewer than {at_least}"); @@ -157,11 +159,14 @@ pub(crate) fn every_bookspec_example_holds() { skipped.len() ); // The examples for an option wanderbooks did not pick: the other option - // of BS-arap-7, -8 and -9, BS-prepaid-2's equal-months and BS-ledger-20's - // refuse (each option's example, so no allow-list grows). + // of BS-arap-2 (documents-kept-apart), -7, -8, -9, -10 (compare-exactly), + // -11 (recovery-movement), -12 (net-of-expected-discount), -13 + // (net-against-the-deposit) and -14 (apportion-across-the-lines), + // BS-prepaid-2's equal-months and BS-ledger-20's refuse (each option's + // example, so no allow-list grows). assert_eq!( skipped.len(), - 5, - "the five unpicked-option examples: {skipped:?}" + 11, + "the eleven unpicked-option examples: {skipped:?}" ); } diff --git a/crates/ledger-core/tests/bookspec/queries/documents.rs b/crates/ledger-core/tests/bookspec/queries/documents.rs index ff40d161..e47bd5fd 100644 --- a/crates/ledger-core/tests/bookspec/queries/documents.rs +++ b/crates/ledger-core/tests/bookspec/queries/documents.rs @@ -63,6 +63,63 @@ impl Books<'_> { ("discount_by".to_string(), discount_by), ])) } + + /// What the ledger lines tagged with the document event `document` come + /// to as of the day (BS-arap-2), straight from the engine's `DocState`: + /// `total`, `paid`, `discounted`, `written_off` and `owes` (its + /// `outstanding`). The engine keeps no recovery movement (BS-arap-11 + /// reverse-then-plain-entry), so it gives no `recovered`. + pub(crate) fn answer_document(&self, q: &Query) -> Result { + let n = q.document.ok_or_else(|| self.missing("document"))?; + let as_of = self.q_day(q)?; + let (doc, _) = self.document_of(n, "a document query"); + let state = match doc { + ledger_core::DocRef::Invoice(id) => self.l().invoice_state(id, as_of), + ledger_core::DocRef::Bill(id) => self.l().bill_state(id, as_of), + } + .map_err(|e| engine_refusal(RuleId::new(Area::Arap, 2), e))? + .ok_or_else(|| self.missing("document, dated by the day asked"))?; + Ok(json_figures([ + ("total".to_string(), figure(state.total)), + ("paid".to_string(), figure(state.paid)), + ("discounted".to_string(), figure(state.discounted)), + ("written_off".to_string(), figure(state.written_off)), + ("owes".to_string(), figure(state.outstanding)), + ])) + } + + /// The place of each invoice in the order of issue, and of the next + /// (BS-arap-4): read from the number the engine stored at issue, + /// `INV-0003` being the third, a voided invoice keeping its own. + pub(crate) fn answer_invoice_numbers(&self, _q: &Query) -> Result { + let place = |number: &str| -> String { + let digits: String = number.chars().filter(char::is_ascii_digit).collect(); + digits.trim_start_matches('0').to_string() + }; + let l = self.l(); + let mut m = JsonMap::new(); + for (i, e) in self.ex.events.iter().enumerate() { + if e.invoice.is_none() || i >= self.posted.len() { + continue; + } + let entry = self.entry_or_refuse(i + 1)?; + let invoice = l + .invoices() + .into_iter() + .find(|inv| inv.entry_id == entry) + .ok_or_else(|| self.missing("invoice"))?; + let number = invoice + .number + .as_deref() + .ok_or_else(|| self.missing("invoice number"))?; + m.insert((i + 1).to_string(), Value::String(place(number))); + } + m.insert( + "next".to_string(), + Value::String(place(&l.next_invoice_number("INV-", 1))), + ); + Ok(Value::Object(m)) + } } /// Check an `aging` expectation: every figure the engine gives, and no @@ -71,6 +128,32 @@ pub(crate) fn check_aging(b: &Books<'_>, x: &Expect) { check_figures(b, x, b.answer_aging(&x.query())); } +/// Check a `document` expectation: the figures it names, as the engine's +/// document figures give them. +pub(crate) fn check_document(b: &Books<'_>, x: &Expect) { + let answer = b.answer_document(&x.query()); + let Value::Object(got) = + answer.unwrap_or_else(|r| panic!("{}: {}: {}", b.ex.id, x.query, r.reason)) + else { + panic!("{}: {} answers a table", b.ex.id, x.query) + }; + for (key, want) in x.figures(&b.ex.id) { + assert_eq!( + got.get(key).and_then(Value::as_str), + Some(want.as_str()), + "{}: {} {key}", + b.ex.id, + x.query + ); + } +} + +/// Check an `invoice_numbers` expectation: every invoice and the next, +/// and no other. +pub(crate) fn check_invoice_numbers(b: &Books<'_>, x: &Expect) { + check_figures(b, x, b.answer_invoice_numbers(&x.query())); +} + /// Check a `document_dates` expectation: `due` and `discount_by`, both /// given. pub(crate) fn check_document_dates(b: &Books<'_>, x: &Expect) { diff --git a/crates/ledger-core/tests/bookspec/queries/mod.rs b/crates/ledger-core/tests/bookspec/queries/mod.rs index a1e6a4aa..8ad9af2c 100644 --- a/crates/ledger-core/tests/bookspec/queries/mod.rs +++ b/crates/ledger-core/tests/bookspec/queries/mod.rs @@ -87,6 +87,8 @@ impl Books<'_> { "project" => self.answer_project(q), "aging" => self.answer_aging(q), "document_dates" => self.answer_document_dates(q), + "document" => self.answer_document(q), + "invoice_numbers" => self.answer_invoice_numbers(q), "run" => self.answer_run(q), "disposal" => self.answer_disposal(q), "depreciation_schedule" => self.answer_depreciation_schedule(q), From b78b5e9f39caca7eca8988da34c5454478f0e5b9 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Mon, 9 Nov 2026 00:16:28 -0700 Subject: [PATCH 02/15] docs(claims): the arap Checked lines name the X-H1b examples B-38, B-40, B-41 and B-42 list the new bookspec examples the adapter runs for the options wanderbooks picked, and those it skips for the options it did not (BS-arap-2, -10, -11, -12, -13, -14). B-40 records that wanderbooks' vendor-reference comparison also drops hyphens, which BS-arap-10's option (case and spaces) does not say; no example distinguishes them yet. B-41 notes the allowance method of BS-arap-5 still has no example (it needs a provision event). Co-Authored-By: Claude Sonnet 5.5 --- docs/spec/claims/arap.md | 42 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/docs/spec/claims/arap.md b/docs/spec/claims/arap.md index 0e7e0b1a..b1afe2d7 100644 --- a/docs/spec/claims/arap.md +++ b/docs/spec/claims/arap.md @@ -74,7 +74,12 @@ Kani `bounds_check_matches_definition`, `bounds_kept_is_the_definition_on_books_ Lean `Documents.control_agrees`, `Documents.Step.document_unattached`, `Documents.Step.reverse_moves`, `Documents.Reachable.unattached_zero` (through role assignments and releases), -`Documents.Reachable.control_is_documents`. The model's limits: it +`Documents.Reachable.control_is_documents`; bookspec examples +`arap-hand-control-posting-refused` (BS-arap-2 `lines-that-stand`: the +hand line is refused, the line an earlier version wrote still reads right), +run by the adapter, and `arap-a-hand-line-on-receivables-is-taken` +(`documents-kept-apart`), which names the option wanderbooks did not pick +and is skipped for it. The model's limits: it starts from empty books (legacy lines are covered by the identity `Documents.control_agrees` alone), it names documents by one id space (an injective coding of `DocRef`), and an account becoming a control account by its @@ -182,6 +187,11 @@ behind the feature `documents_v2`. **Checked:** **Pick:** a vendor's invoice reference is compared after the normalization that drops case and spaces (`Ledger::check_vendor_ref`); the old text names no separate decision for it. **Pick (BS-arap-10):** `ignore-case-and-spaces`; a vendor's invoice reference is compared after the normalization that drops case and spaces. +wanderbooks goes one step past the option: it also drops hyphens, so +"ACME-123", "acme 123" and "Acme123" are one reference (`Ledger::check_vendor_ref`, +pinned by `duplicate_vendor_ref_refused_unless_a_reason_is_given`); the record's option +names case and spaces only, and none of its examples distinguishes the two. + **Enforced:** `Ledger::next_invoice_number`, `Ledger::check_vendor_ref`, `PartySnapshot::from_party` (the snapshots at issue, D-55); `Store::create_invoice_issued` (feature `documents_v2`); @@ -195,7 +205,14 @@ every amount through `amount_parts`). `tests/arap_standing.rs` (`documents_v2_waits_for_the_upgrade`, `issued_pdf_is_filed_with_the_invoice_or_nothing_is`); over the wire `crates/ledger-cli/tests/documents.rs` (`an_invoice_from_issue_to_paid`, -`duplicate_vendor_invoice_refused`); the page `ledger-import` +`duplicate_vendor_invoice_refused`); bookspec examples +`arap-invoice-numbers-run-in-order-and-are-kept` (the adapter numbers each +invoice with `Ledger::next_invoice_number` and reads the place back from the +number the engine stored), `arap-a-vendor-invoice-is-entered-once` +(the refusal of a second bill, from `Ledger::check_vendor_ref`) and, for +BS-arap-10, `arap-a-vendor-reference-differing-in-case-and-spaces-is-a-duplicate`; +`arap-a-vendor-reference-differing-in-case-and-spaces-is-not-a-duplicate` +names `compare-exactly` and is skipped; the page `ledger-import` `tests/spec_import.rs::invoice_pdf_prints_what_it_should` and the unit tests `labels_are_data`, `an_invoice_renders_deterministically`, `two_hundred_lines_paginate`; the viewer @@ -260,7 +277,14 @@ item. `tests/arap_props.rs` (`status_is_a_function_of_journal_and_date` with write-offs); over the wire `crates/ledger-cli/tests/documents.rs` (`write_off_then_recovery`, `write_off_needs_evidence`); bookspec -`bad-debt-direct-write-off`; Lean `Documents.Step.writeOff_unattached`, +`bad-debt-direct-write-off` (BS-arap-5 `direct-write-off`; the allowance +method has no example yet, it needs a provision event) and, for BS-arap-11, +`arap-a-recovery-reverses-the-write-off-in-its-year` (the adapter reverses +the write-off with `Store::reverse_entry` and takes the money with +`Store::receive_payment` in the write-off's tax year, and posts a plain +entry in a later one); +`arap-a-recovery-is-a-movement-on-the-document` names `recovery-movement` +and is skipped; Lean `Documents.Step.writeOff_unattached`, `Documents.writeOff_within_bounds`; the viewer `a_write_off_shows_on_the_timeline`; the item `a_write_off_is_flagged_for_the_cpa`. @@ -324,7 +348,17 @@ check_discount}`, `arap::{Application, Fee, SettleParams, SettlementRow}`, `ledger-store` `tests/arap_standing.rs` (`a_settlement_names_its_lines_and_replays`, `settlement_waits_for_documents_v2`, `legacy_payment_events_keep_the_positional_rule`), `tests/arap_props.rs`; -`ledger-cli` `tests/documents.rs`; `ledger-package`'s aging tie-out test. +`ledger-cli` `tests/documents.rs`; `ledger-package`'s aging tie-out test; +bookspec examples `arap-a-settlement-pays-several-documents-and-names-each-line` +and `arap-a-settlement-that-is-not-exact-is-refused` (BS-arap-6, through +`Store::settle`, each refusal read off the engine's own error), and one per +option picked: `arap-a-discount-taken-is-booked-when-it-is-taken` (BS-arap-12), +`arap-a-processors-fee-is-posted-gross` (BS-arap-13) and +`arap-a-discount-on-an-asset-bill-is-refused` (BS-arap-14); the examples +`arap-a-discount-expected-is-booked-with-the-document`, +`arap-a-processors-fee-is-not-shown-against-the-deposit` and +`arap-a-discount-on-an-asset-bill-is-apportioned` name the options not picked +and are skipped. The Lean step is the document constructor of the Lean documents model, with every control line tagged (`Documents.settle_unattached`); no new step constructor. From d35775922b83038d93eeebf18ab4f420c1c91bf3 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Mon, 9 Nov 2026 00:58:02 -0700 Subject: [PATCH 03/15] docs(claims): BS-arap-10's pick is ignore-case-spaces-and-hyphens, as the plan decided The engine has always dropped hyphens too (plan P4b S4, the owner: "(vendor, normalized vendor_ref) (lower-case, spaces and hyphens removed)", pinned by duplicate_vendor_ref_refused_unless_a_reason_is_given); bookspec's record lost the hyphens in transcription and is corrected, so there is no divergence to note. PICKS and the claims file name the option ignore-case-spaces-and-hyphens, "spaces" being any whitespace, and the example ids follow the record's rename. Co-Authored-By: Claude Sonnet 5.5 --- crates/ledger-core/tests/bookspec/engine.rs | 2 +- docs/spec/claims/arap.md | 13 ++++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/crates/ledger-core/tests/bookspec/engine.rs b/crates/ledger-core/tests/bookspec/engine.rs index f9a4e9f3..60185e0e 100644 --- a/crates/ledger-core/tests/bookspec/engine.rs +++ b/crates/ledger-core/tests/bookspec/engine.rs @@ -120,7 +120,7 @@ pub(crate) const PICKS: &[(Area, u32, &str)] = &[ (Area::Arap, 7, "due-today-is-current"), (Area::Arap, 8, "as-of-the-day"), (Area::Arap, 9, "refuse-a-payment-before-its-document"), - (Area::Arap, 10, "ignore-case-and-spaces"), + (Area::Arap, 10, "ignore-case-spaces-and-hyphens"), (Area::Arap, 11, "reverse-then-plain-entry"), (Area::Arap, 12, "gross-when-taken"), (Area::Arap, 13, "gross"), diff --git a/docs/spec/claims/arap.md b/docs/spec/claims/arap.md index b1afe2d7..4c30327b 100644 --- a/docs/spec/claims/arap.md +++ b/docs/spec/claims/arap.md @@ -184,13 +184,8 @@ behind the feature `documents_v2`. **Checked:** **Claims:** yes -**Pick:** a vendor's invoice reference is compared after the normalization that drops case and spaces (`Ledger::check_vendor_ref`); the old text names no separate decision for it. -**Pick (BS-arap-10):** `ignore-case-and-spaces`; a vendor's invoice reference is compared after the normalization that drops case and spaces. - -wanderbooks goes one step past the option: it also drops hyphens, so -"ACME-123", "acme 123" and "Acme123" are one reference (`Ledger::check_vendor_ref`, -pinned by `duplicate_vendor_ref_refused_unless_a_reason_is_given`); the record's option -names case and spaces only, and none of its examples distinguishes the two. +**Pick:** a vendor's invoice reference is compared after the normalization that drops case, spaces and hyphens (`Ledger::check_vendor_ref`), so "ACME-123", "acme 123" and "Acme123" are one reference (pinned by `duplicate_vendor_ref_refused_unless_a_reason_is_given`); plan P4b S4 (the owner) specifies it. +**Pick (BS-arap-10):** `ignore-case-spaces-and-hyphens`; a vendor's invoice reference is compared after the normalization that drops case, spaces (any whitespace) and hyphens. **Enforced:** `Ledger::next_invoice_number`, `Ledger::check_vendor_ref`, `PartySnapshot::from_party` (the snapshots at issue, D-55); @@ -210,8 +205,8 @@ every amount through `amount_parts`). invoice with `Ledger::next_invoice_number` and reads the place back from the number the engine stored), `arap-a-vendor-invoice-is-entered-once` (the refusal of a second bill, from `Ledger::check_vendor_ref`) and, for -BS-arap-10, `arap-a-vendor-reference-differing-in-case-and-spaces-is-a-duplicate`; -`arap-a-vendor-reference-differing-in-case-and-spaces-is-not-a-duplicate` +BS-arap-10, `arap-a-vendor-reference-differing-in-case-spaces-and-hyphens-is-a-duplicate`; +`arap-a-vendor-reference-differing-in-case-spaces-and-hyphens-is-not-a-duplicate` names `compare-exactly` and is skipped; the page `ledger-import` `tests/spec_import.rs::invoice_pdf_prints_what_it_should` and the unit tests `labels_are_data`, `an_invoice_renders_deterministically`, From 0ffb0935fe323c08446a0c0f7238c7b25776c706 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Mon, 9 Nov 2026 01:53:36 -0700 Subject: [PATCH 04/15] fix(core): a fee above the cash is its own refusal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A processor cannot keep more than it was paid. The engine already refused a settlement whose fee is above its cash, but as InvalidSettlement, one message for two causes ("the cash and discounts don't cover the applications exactly, or the fee is above the cash"), so the bookspec adapter had to read the refusal out of the message's prose. Settlement now checks fee > Σ cash itself, in the same place as before (after the per-application checks, before kernel::settle), and returns the typed LedgerError::FeeAboveCash { fee, cash }. InvalidSettlement keeps what remains (a sum too large, a negative fee, a fee that leaves no deposit), and its message no longer claims the fee case. The adapter matches the variant like every sibling. The refusal's precedence is unchanged, and nothing was journaled by a refused settlement before or now (the store journals only a settlement that succeeded); no stored data changes. The only output change is the error text of a fee above the cash and of the leftover InvalidSettlement cases; no golden or test asserted either text, and no caller matched the variant (ledger-mcp, ledger-store, ledger-cli pass them on as text). a_fee_above_the_cash_is_refused_and_changes_nothing encodes the rule (150.00 of cash, a fee of 150.01 refused, books untouched; a fee equal to the cash is the other refusal; a fee of 3.00 posts, deposit 147.00). Co-Authored-By: Claude Sonnet 5.5 --- crates/ledger-core/src/error.rs | 21 ++++++- crates/ledger-core/src/ledger.rs | 15 ++++- crates/ledger-core/tests/bookspec/common.rs | 7 +-- crates/ledger-core/tests/spec_documents.rs | 69 +++++++++++++++++++++ docs/spec/claims/arap.md | 4 +- 5 files changed, 105 insertions(+), 11 deletions(-) diff --git a/crates/ledger-core/src/error.rs b/crates/ledger-core/src/error.rs index bb437d0d..72d434a5 100644 --- a/crates/ledger-core/src/error.rs +++ b/crates/ledger-core/src/error.rs @@ -749,9 +749,24 @@ pub enum LedgerError { #[error("{0}")] InvalidFee(String), - /// A settlement's figures can't be exact: the cash and discounts - /// don't cover the applications, or the fee leaves a negative deposit - /// (BS-arap-6 INVARIANT 1). + /// A processor's fee is above the cash it was withheld from: a + /// processor cannot keep more than it was paid (BS-arap-6). A fee equal + /// to the cash is [`LedgerError::InvalidSettlement`]: the deposit would + /// be nothing. + #[error( + "the processor's fee of {fee} is above the cash of {cash}: a processor can't keep more than it was paid" + )] + FeeAboveCash { + /// The fee asked for. + fee: Decimal, + /// The settlement's cash, summed over its applications. + cash: Decimal, + }, + + /// A settlement's figures can't be exact (BS-arap-6 INVARIANT 1): an + /// amount too large to add, a negative fee, or a fee that leaves + /// nothing to deposit; a fee above the cash is + /// [`LedgerError::FeeAboveCash`]. #[error("{0}")] InvalidSettlement(String), diff --git a/crates/ledger-core/src/ledger.rs b/crates/ledger-core/src/ledger.rs index e5a0c005..77b0877b 100644 --- a/crates/ledger-core/src/ledger.rs +++ b/crates/ledger-core/src/ledger.rs @@ -6701,9 +6701,22 @@ impl Ledger { discounts.push(app.discount); } let fee_amount = params.fee.as_ref().map_or(Decimal::ZERO, |f| f.amount); + // A fee above the cash is its own refusal; the kernel would also + // answer `None` for it, with no way to say which of its refusals it + // was. A sum that overflows is left to the kernel (too large). + if let Some(total_cash) = cash + .iter() + .try_fold(Decimal::ZERO, |sum, c| sum.checked_add(*c)) + && fee_amount > total_cash + { + return Err(LedgerError::FeeAboveCash { + fee: fee_amount, + cash: total_cash, + }); + } let settlement = kernel::settle(&cash, &discounts, fee_amount).ok_or_else(|| { LedgerError::InvalidSettlement( - "the cash and discounts don't cover the applications exactly, or the fee is above the cash" + "the settlement's figures aren't exact: an amount is too large, or the fee is negative" .into(), ) })?; diff --git a/crates/ledger-core/tests/bookspec/common.rs b/crates/ledger-core/tests/bookspec/common.rs index eaa2b261..7b0f42f4 100644 --- a/crates/ledger-core/tests/bookspec/common.rs +++ b/crates/ledger-core/tests/bookspec/common.rs @@ -154,12 +154,7 @@ pub(crate) fn refusal(e: &LedgerError) -> String { LedgerError::Overpayment(..) => "application_above_owed", LedgerError::DiscountNeedsReason { .. } => "discount_needs_reason", LedgerError::DiscountOnAssetBill { .. } => "discount_on_asset_bill", - // The cash and the discounts the adapter hands over always cover the - // applications exactly, so the one way the engine's exactness check - // fails is a fee above the cash (BS-arap-6). - LedgerError::InvalidSettlement(why) if why.contains("the fee is above the cash") => { - "fee_above_cash" - } + LedgerError::FeeAboveCash { .. } => "fee_above_cash", LedgerError::UnbalancedEntry { .. } => "unbalanced", LedgerError::TooFewLines => "too_few_lines", LedgerError::NegativeAmountLine => "negative_amount", diff --git a/crates/ledger-core/tests/spec_documents.rs b/crates/ledger-core/tests/spec_documents.rs index 1986e901..66d5bf46 100644 --- a/crates/ledger-core/tests/spec_documents.rs +++ b/crates/ledger-core/tests/spec_documents.rs @@ -2553,3 +2553,72 @@ fn discount_on_an_asset_bill_is_refused_with_the_remedy() { ); b.ties(d(2026, 4, 5)); } + +/// A processor cannot keep more than it was paid: a fee above the cash is +/// refused as its own refusal (`FeeAboveCash`, BS-arap-6) and changes +/// nothing. A fee equal to the cash is a different refusal (the deposit +/// would be nothing), and a fee within the cash still posts. +#[test] +fn a_fee_above_the_cash_is_refused_and_changes_nothing() { + use ledger_core::{Application, DocRef, Fee, SettleParams}; + let mut b = books(); + let first = b.invoice(d(2026, 4, 1), 10_000); + let second = b.invoice(d(2026, 4, 2), 5_000); + let params = |fee: i64| SettleParams { + date: d(2026, 4, 5), + description: "Card payment".into(), + cash_account: b.bank, + party: b.customer, + applications: vec![ + Application { + doc: DocRef::Invoice(first), + cash: cents(10_000), + discount: Decimal::ZERO, + discount_reason: None, + }, + Application { + doc: DocRef::Invoice(second), + cash: cents(5_000), + discount: Decimal::ZERO, + discount_reason: None, + }, + ], + fee: Some(Fee { + amount: cents(fee), + account: None, + vendor: None, + }), + instrument: None, + reference: None, + }; + let posted_before = b.l.posted_entries().count(); + let first_before = b.state(DocRef::Invoice(first), d(2026, 4, 5)); + let second_before = b.state(DocRef::Invoice(second), d(2026, 4, 5)); + // The cash is 150.00 across two applications; a fee of 150.01 is above it. + let refused = b.l.settle(params(15_001)); + assert!( + matches!( + refused, + Err(LedgerError::FeeAboveCash { fee, cash }) + if fee == cents(15_001) && cash == cents(15_000) + ), + "{refused:?}" + ); + assert_eq!(b.l.posted_entries().count(), posted_before); + assert_eq!(b.state(DocRef::Invoice(first), d(2026, 4, 5)), first_before); + assert_eq!( + b.state(DocRef::Invoice(second), d(2026, 4, 5)), + second_before + ); + assert_eq!(b.l.account_balance(b.bank).unwrap(), Decimal::ZERO); + // The fee equal to the cash is the other refusal, not this one. + assert!(matches!( + b.l.settle(params(15_000)), + Err(LedgerError::InvalidSettlement(_)) + )); + assert_eq!(b.l.posted_entries().count(), posted_before); + // A fee within the cash posts: 150.00 gross, 3.00 fee, 147.00 deposit. + b.l.settle(params(300)).unwrap(); + assert_eq!(b.l.account_balance(b.bank).unwrap(), cents(14_700)); + b.ties(d(2026, 4, 5)); +} diff --git a/docs/spec/claims/arap.md b/docs/spec/claims/arap.md index 4c30327b..0bf59ffa 100644 --- a/docs/spec/claims/arap.md +++ b/docs/spec/claims/arap.md @@ -338,7 +338,9 @@ check_discount}`, `arap::{Application, Fee, SettleParams, SettlementRow}`, (`bill_on_terms_with_discount`, `late_discount_needs_a_reason`, `discount_on_an_asset_bill_is_refused_with_the_remedy`, `a_fee_posts_gross_to_receivables_and_net_to_the_bank`, -`a_settlement_names_its_lines_and_refuses_a_document_twice`), +`a_settlement_names_its_lines_and_refuses_a_document_twice`, +`a_fee_above_the_cash_is_refused_and_changes_nothing`: the refusal is +`LedgerError::FeeAboveCash`, its own variant), `tests/kernel_bridge/main.rs::settle_agrees`; Kani `settle_is_exact`; `ledger-store` `tests/arap_standing.rs` (`a_settlement_names_its_lines_and_replays`, `settlement_waits_for_documents_v2`, From 609e4e6b269fac80ec4e5a251c71743c7c96d2a3 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Mon, 9 Nov 2026 03:09:18 -0700 Subject: [PATCH 05/15] build: pin bookspec at bc92cf3, settlements and the shares law bookspec main now carries X-H1b (settlements, recoveries, invoice numbers, vendor references and their examples; BS-arap-10 ignores hyphens as plan P4b S4 decided) and K-U3's law 42. The checker and the Lean move together (tests/bookspec/pin.rs): Lean 179 theorems, standard axioms only; 80 of 91 examples run and pass, the other 11 are for options wanderbooks did not pick. Co-Authored-By: Claude Opus 5.5 --- Cargo.lock | 4 ++-- crates/ledger-core/Cargo.toml | 4 ++-- crates/ledger-package/Cargo.toml | 2 +- verify/lean/lake-manifest.json | 4 ++-- verify/lean/lakefile.toml | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ed5a3bfd..31d4bad4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -788,7 +788,7 @@ dependencies = [ [[package]] name = "bookspec-checker" version = "0.1.0" -source = "git+https://git.swaits.com/swaits/bookspec?rev=6e1b99d5da3aa56c6476b6951aaa739ae0af8d97#6e1b99d5da3aa56c6476b6951aaa739ae0af8d97" +source = "git+https://git.swaits.com/swaits/bookspec?rev=bc92cf3f69c392cefc9bd319b103994b3bfb0d76#bc92cf3f69c392cefc9bd319b103994b3bfb0d76" dependencies = [ "chrono", "include_dir", @@ -801,7 +801,7 @@ dependencies = [ [[package]] name = "bookspec-runner" version = "0.1.0" -source = "git+https://git.swaits.com/swaits/bookspec?rev=6e1b99d5da3aa56c6476b6951aaa739ae0af8d97#6e1b99d5da3aa56c6476b6951aaa739ae0af8d97" +source = "git+https://git.swaits.com/swaits/bookspec?rev=bc92cf3f69c392cefc9bd319b103994b3bfb0d76#bc92cf3f69c392cefc9bd319b103994b3bfb0d76" dependencies = [ "bookspec-checker", "serde_json", diff --git a/crates/ledger-core/Cargo.toml b/crates/ledger-core/Cargo.toml index c13b2e4c..52c43fb9 100644 --- a/crates/ledger-core/Cargo.toml +++ b/crates/ledger-core/Cargo.toml @@ -33,8 +33,8 @@ num-rational = "0.4" toml = "1" # The specification lives in its own repository (P13 step 6, D-34, D-65), # pinned to a commit. -bookspec-checker = { git = "https://git.swaits.com/swaits/bookspec", rev = "6e1b99d5da3aa56c6476b6951aaa739ae0af8d97" } -bookspec-runner = { git = "https://git.swaits.com/swaits/bookspec", rev = "6e1b99d5da3aa56c6476b6951aaa739ae0af8d97" } +bookspec-checker = { git = "https://git.swaits.com/swaits/bookspec", rev = "bc92cf3f69c392cefc9bd319b103994b3bfb0d76" } +bookspec-runner = { git = "https://git.swaits.com/swaits/bookspec", rev = "bc92cf3f69c392cefc9bd319b103994b3bfb0d76" } ledger-package = { path = "../ledger-package" } ledger-import = { path = "../ledger-import" } ledger-store = { path = "../ledger-store" } diff --git a/crates/ledger-package/Cargo.toml b/crates/ledger-package/Cargo.toml index 222dd469..7900b730 100644 --- a/crates/ledger-package/Cargo.toml +++ b/crates/ledger-package/Cargo.toml @@ -21,7 +21,7 @@ zip = "9.0.1" workspace = true [dev-dependencies] -bookspec-checker = { git = "https://git.swaits.com/swaits/bookspec", rev = "6e1b99d5da3aa56c6476b6951aaa739ae0af8d97" } +bookspec-checker = { git = "https://git.swaits.com/swaits/bookspec", rev = "bc92cf3f69c392cefc9bd319b103994b3bfb0d76" } proptest = "1" tempfile = "3" toml = "1" diff --git a/verify/lean/lake-manifest.json b/verify/lean/lake-manifest.json index 34933d5b..67758aee 100644 --- a/verify/lean/lake-manifest.json +++ b/verify/lean/lake-manifest.json @@ -5,10 +5,10 @@ "type": "git", "subDir": "lean", "scope": "", - "rev": "6e1b99d5da3aa56c6476b6951aaa739ae0af8d97", + "rev": "bc92cf3f69c392cefc9bd319b103994b3bfb0d76", "name": "bookspec", "manifestFile": "lake-manifest.json", - "inputRev": "6e1b99d5da3aa56c6476b6951aaa739ae0af8d97", + "inputRev": "bc92cf3f69c392cefc9bd319b103994b3bfb0d76", "inherited": false, "configFile": "lakefile.toml"}], "name": "wanderbooks", diff --git a/verify/lean/lakefile.toml b/verify/lean/lakefile.toml index 84073995..a8e66645 100644 --- a/verify/lean/lakefile.toml +++ b/verify/lean/lakefile.toml @@ -9,7 +9,7 @@ packagesDir = ".lake/packages" [[require]] name = "bookspec" git = "https://git.swaits.com/swaits/bookspec" -rev = "6e1b99d5da3aa56c6476b6951aaa739ae0af8d97" +rev = "bc92cf3f69c392cefc9bd319b103994b3bfb0d76" subDir = "lean" [[lean_lib]] From e41cc3a1610c93083d8db2858d51def456733042 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Mon, 9 Nov 2026 03:30:06 -0700 Subject: [PATCH 06/15] docs: sub-references name bookspec's statements, invariants and scenarios Unit S-E rewrote each `B-n` citation to its bookspec id but kept the sub-reference after it ("item 7", "rule 11", "INVARIANT 2"). Those numbers counted parts of the retired rules.md text, so `BS-statement-5 item 7` pointed at finished and abandoned projects, not at the snapshot it meant. Bookspec numbers a record's parts from 1 as `statement`, `invariant` and `scenario`; every sub-reference now says so. The map was built by content, not by position: each old item, INVARIANT or SCENARIO was read in `git show ca8d676d5^:docs/spec/rules.md` (the last full rule text), found in the pinned records (bookspec bc92cf3) and in docs/spec/claims/, and each reference was read in its context before it was mapped. Where the old numbering still survives as the "Rule n" labels inside bookspec's statements (the cash flow, party totals) the new number is that statement's position; where a record carries the whole rule differently (the asset depreciation, the IIF file, the arap invariants) the reference follows the content. Where bookspec keeps no counterpart, the product rule that states it is cited instead: WB-statement-5 (a project's facts and names), -7 (the snapshot), WB-arap-4 (the document_standing feature), -8 (the issued PDF), -15 (a payment event names its line), WB-ledger-15 (BS-ledger-12 is retired). A reference that had pointed at the wrong part is corrected, for example the discount-reason references that said BS-arap-6 INVARIANT 2 (a bound) now say invariant 6 (the discount cap and date). Only the reference tokens and their sentence change; no paragraph is reflowed. A reference wrapped across a comment prefix keeps its wrap. Co-Authored-By: Claude Sonnet 5.5 --- crates/ledger-cli/tests/documents.rs | 8 ++-- crates/ledger-cli/tests/evidence.rs | 2 +- crates/ledger-cli/tests/format_upgrade.rs | 2 +- crates/ledger-cli/tests/mcp_journeys.rs | 2 +- crates/ledger-cli/tests/oracle_mcp.rs | 2 +- crates/ledger-cli/tests/projects_parity.rs | 4 +- crates/ledger-cli/tests/spec_assets.rs | 4 +- crates/ledger-cli/tests/spec_parties.rs | 2 +- crates/ledger-cli/tests/spec_projects.rs | 6 +-- crates/ledger-core/src/arap.rs | 8 ++-- crates/ledger-core/src/assets.rs | 4 +- crates/ledger-core/src/cashflow.rs | 18 ++++---- crates/ledger-core/src/error.rs | 16 +++---- crates/ledger-core/src/kernel/allocate.rs | 4 +- crates/ledger-core/src/kernel/entries.rs | 40 ++++++++--------- crates/ledger-core/src/kernel/mod.rs | 2 +- crates/ledger-core/src/ledger.rs | 45 +++++++++---------- crates/ledger-core/src/parties.rs | 6 +-- crates/ledger-core/src/proofs/allocate.rs | 2 +- crates/ledger-core/src/proofs/mod.rs | 18 ++++---- crates/ledger-core/src/reports.rs | 12 ++--- crates/ledger-core/src/shares.rs | 4 +- crates/ledger-core/src/tax_capital.rs | 4 +- .../tests/bookspec/queries/assets.rs | 2 +- .../tests/bookspec/queries/parties.rs | 4 +- crates/ledger-core/tests/form1099.rs | 2 +- crates/ledger-core/tests/invariants.rs | 2 +- .../ledger-core/tests/kernel_bridge/main.rs | 4 +- crates/ledger-core/tests/properties.rs | 10 ++--- crates/ledger-core/tests/spec_asset_tags.rs | 4 +- crates/ledger-core/tests/spec_cash_flow.rs | 45 +++++++++---------- .../tests/spec_document_projects.rs | 10 ++--- crates/ledger-core/tests/spec_documents.rs | 28 ++++++------ crates/ledger-core/tests/spec_parties.rs | 2 +- crates/ledger-core/tests/spec_party_totals.rs | 20 ++++----- crates/ledger-core/tests/spec_projects.rs | 6 +-- crates/ledger-core/tests/spec_reports.rs | 4 +- crates/ledger-core/tests/statements.rs | 4 +- crates/ledger-gui/src/attention.rs | 2 +- crates/ledger-gui/src/demo.rs | 4 +- crates/ledger-gui/src/pages/entry.rs | 4 +- crates/ledger-gui/src/pages/parties.rs | 4 +- crates/ledger-gui/src/pages/projects.rs | 4 +- crates/ledger-gui/src/pages/reports.rs | 2 +- crates/ledger-gui/tests/parties.rs | 6 +-- crates/ledger-gui/tests/projects.rs | 6 +-- crates/ledger-import/tests/spec_import.rs | 8 ++-- crates/ledger-mcp/src/handbook.rs | 8 ++-- crates/ledger-mcp/src/tools/documents.rs | 2 +- crates/ledger-mcp/src/tools/helpers.rs | 2 +- crates/ledger-mcp/src/tools/parties.rs | 2 +- crates/ledger-mcp/src/tools/projects.rs | 4 +- crates/ledger-mcp/src/tools/reports.rs | 2 +- crates/ledger-mcp/src/tools/write_offs.rs | 2 +- crates/ledger-mcp/src/types.rs | 2 +- crates/ledger-package/src/attention.rs | 4 +- crates/ledger-package/src/iif.rs | 2 +- crates/ledger-package/src/reports.rs | 2 +- crates/ledger-package/tests/p3_seams.rs | 18 ++++---- crates/ledger-package/tests/package.rs | 10 ++--- crates/ledger-store/src/error.rs | 2 +- crates/ledger-store/src/format.rs | 2 +- crates/ledger-store/src/store.rs | 12 ++--- crates/ledger-store/tests/arap_props.rs | 7 ++- crates/ledger-store/tests/arap_standing.rs | 15 +++---- crates/ledger-store/tests/asset_tags.rs | 2 +- .../ledger-store/tests/document_projects.rs | 4 +- crates/ledger-store/tests/store.rs | 2 +- docs/mcp-interface.md | 22 ++++----- docs/parity.md | 2 +- docs/parties-and-attachments.md | 2 +- docs/spec/README.md | 4 +- docs/spec/claims/partner.md | 2 +- docs/spec/claims/statement.md | 2 +- docs/spec/sources/fasb-asc.md | 10 ++--- docs/spec/sources/intuit-iif.md | 6 +-- docs/testing.md | 38 ++++++++-------- docs/verification.md | 4 +- 78 files changed, 298 insertions(+), 302 deletions(-) diff --git a/crates/ledger-cli/tests/documents.rs b/crates/ledger-cli/tests/documents.rs index 83f450b3..8daa8312 100644 --- a/crates/ledger-cli/tests/documents.rs +++ b/crates/ledger-cli/tests/documents.rs @@ -989,7 +989,7 @@ mod paying_on_terms { /// One deposit settles two invoices of one customer: one entry, one /// receivable line per invoice, each tagged with its own invoice, and the - /// output names both documents (BS-arap-6 INVARIANTS 1 and 3). + /// output names both documents (BS-arap-6 invariant 3 and WB-arap-15). #[test] fn one_payment_settles_two_invoices() { let mut s = setup("settle-two"); @@ -1046,7 +1046,7 @@ mod paying_on_terms { } /// A discount outside the document's terms needs a reason; with one the - /// payment is taken and recorded (BS-arap-6 INVARIANT 2; the terms are S4.3's + /// payment is taken and recorded (BS-arap-6 invariant 6; the terms are S4.3's /// to journal, so this bill states none). #[test] fn late_discount_needs_a_reason() { @@ -1075,7 +1075,7 @@ mod paying_on_terms { } /// A fee posts gross (A-4): the deposit gets the net, the fee its expense, - /// and A/R is credited the gross (BS-arap-6 INVARIANT 1). + /// and A/R is credited the gross (BS-arap-6 invariant 3). #[test] fn a_fee_posts_gross_to_receivables_and_net_to_the_bank() { let mut s = setup("fee-gross"); @@ -1445,7 +1445,7 @@ mod bad_debts { assert_eq!(check["agrees"], json!(true), "{check}"); } - /// P4b S7: no evidence, no write-off (BS-arap-5 INVARIANT 1): the tool refuses + /// P4b S7: no evidence, no write-off (BS-arap-5 statement 10): the tool refuses /// with neither or both, and an attachment already filed is linked /// instead of a new file. #[test] diff --git a/crates/ledger-cli/tests/evidence.rs b/crates/ledger-cli/tests/evidence.rs index 96d43735..56df3b61 100644 --- a/crates/ledger-cli/tests/evidence.rs +++ b/crates/ledger-cli/tests/evidence.rs @@ -318,7 +318,7 @@ fn annotations_and_searches() { assert_eq!(answer_of(&r).unwrap()["status"], "ok"); } -/// Plan P6 step 4 and BS-ledger-12 item 5: consolidation never leaves an +/// Plan P6 step 4 and WB-ledger-15 INVARIANT 3: consolidation never leaves an /// entry the receipt policy covers with no evidence. #[test] fn consolidation_never_removes_an_entrys_only_evidence() { diff --git a/crates/ledger-cli/tests/format_upgrade.rs b/crates/ledger-cli/tests/format_upgrade.rs index 6e339317..1ade8a9c 100644 --- a/crates/ledger-cli/tests/format_upgrade.rs +++ b/crates/ledger-cli/tests/format_upgrade.rs @@ -845,7 +845,7 @@ fn books_p2_served_cut_over_whole() { ), // An invoice carrying documents_v2's fields (terms: P4b S4.4) and // its line naming its project (document_line_projects, - // BS-statement-5 item 8). + // BS-statement-5 statement 6). ( "books.create_invoice", json!({"customer": "1", "date": "2026-02-10", "terms": "Net 30", diff --git a/crates/ledger-cli/tests/mcp_journeys.rs b/crates/ledger-cli/tests/mcp_journeys.rs index be51718a..353feb0e 100644 --- a/crates/ledger-cli/tests/mcp_journeys.rs +++ b/crates/ledger-cli/tests/mcp_journeys.rs @@ -2419,7 +2419,7 @@ fn cash_flow_reads_its_account_roles_from_the_books_settings() { } } -/// BS-statement-3 rule 2: roles that contradict the chart are refused, +/// BS-statement-3 statement 3: roles that contradict the chart are refused, /// naming the setting and the fix, never a statement on a wrong partition. #[test] fn cash_flow_refuses_contradictory_roles() { diff --git a/crates/ledger-cli/tests/oracle_mcp.rs b/crates/ledger-cli/tests/oracle_mcp.rs index a21503a5..fe8d4bf2 100644 --- a/crates/ledger-cli/tests/oracle_mcp.rs +++ b/crates/ledger-cli/tests/oracle_mcp.rs @@ -1546,7 +1546,7 @@ fn iif_declares_accounts_by_role_and_balances_every_transaction() { ); } -/// BS-format-2 item 7 through the server: an entry with lines on both the +/// BS-format-2 statement 7 through the server: an entry with lines on both the /// receivables and payables control accounts makes `books.export` iif and /// `books.export_cpa_package` refuse, naming the entry, rather than hand /// over a file QuickBooks Desktop will not import. diff --git a/crates/ledger-cli/tests/projects_parity.rs b/crates/ledger-cli/tests/projects_parity.rs index d94c686b..355492d0 100644 --- a/crates/ledger-cli/tests/projects_parity.rs +++ b/crates/ledger-cli/tests/projects_parity.rs @@ -1,4 +1,4 @@ -//! A project's snapshot (BS-statement-5 item 7) in the viewer and from the +//! A project's snapshot (WB-statement-7) in the viewer and from the //! books server, on the same books: `books.project`'s strings are the //! figures the viewer's page draws (its `PageFigures` and `Snap`), to the //! cent, to date, by account, by month with the running net, and for the @@ -208,7 +208,7 @@ fn a_projects_snapshot_is_the_same_in_the_viewer_and_from_the_server() { assert_eq!(period["net"], "-722.22", "a refund and costs, no sale"); } -/// BS-statement-5 item 8: a project's invoiced revenue and billed costs, +/// BS-statement-5 statement 6: a project's invoiced revenue and billed costs, /// made through the books server's own tools, read the same in the viewer /// (its snapshot, and the invoice's and bill's pages: each line's /// project) and from the server (books.project, books.get_entry). diff --git a/crates/ledger-cli/tests/spec_assets.rs b/crates/ledger-cli/tests/spec_assets.rs index 6c378ebb..685cd384 100644 --- a/crates/ledger-cli/tests/spec_assets.rs +++ b/crates/ledger-cli/tests/spec_assets.rs @@ -1199,7 +1199,7 @@ fn acquired_date_comes_from_the_acquisition_entry() { ); } -// ------------------------------- posted and scheduled (BS-asset-1 rule 8) +// ------------------------------- posted and scheduled (BS-asset-1 statement 28) /// Named regression 1 (the brief's reproduction 1, its figures made up): a /// $1,440.00 laptop, 36 months, in service 2026-05-15, nothing run. As of @@ -1501,7 +1501,7 @@ fn dispose_args(x: u64, date: &str, proceeds: &str) -> Value { /// days, 500.00 (the final depreciation); accumulated 5,500.00, book value /// 6,500.00, gain 500.00. Afterwards books.asset_schedule ends there, and /// books.list_assets lists it as gone: not held, every figure 0.00 (it -/// left the books with its disposal; BS-asset-1 rule 8). Before P3 the +/// left the books with its disposal; BS-asset-1 statement 28). Before P3 the /// schedule showed June 7,000.00, accumulated 12,000.00, book value 0.00. #[test] fn a_disposed_asset_lists_what_it_depreciated_through_its_disposal() { diff --git a/crates/ledger-cli/tests/spec_parties.rs b/crates/ledger-cli/tests/spec_parties.rs index c753af0c..6b54728d 100644 --- a/crates/ledger-cli/tests/spec_parties.rs +++ b/crates/ledger-cli/tests/spec_parties.rs @@ -963,7 +963,7 @@ fn party_totals_for_a_customer_a_member_and_a_prepaid() { // A prepaid bought with a member's card: an asset, paid through what // the members advanced. That is money when it is a financing account - // (BS-partner-3 item 5, P3 defect 24); unlisted, Due to Members is a + // (BS-partner-3 statement 7, P3 defect 24); unlisted, Due to Members is a // promise like any other liability, counted when the member is paid // back. let prepaid = |m: &mut Mcp| { diff --git a/crates/ledger-cli/tests/spec_projects.rs b/crates/ledger-cli/tests/spec_projects.rs index 9633291a..e25e5f32 100644 --- a/crates/ledger-cli/tests/spec_projects.rs +++ b/crates/ledger-cli/tests/spec_projects.rs @@ -585,7 +585,7 @@ fn project_to_date_counts_lines_before_the_period() { assert_eq!(zeta["to_date"]["net"], "3200.00"); } -/// The snapshot's figures (BS-statement-5 item 7), as the viewer shows +/// The snapshot's figures (WB-statement-7), as the viewer shows /// them: net is the contribution before overhead, margin_pct its share /// of revenue, to_date.by_account the direct costs by category, and each /// month's net_to_date the running net, the last being to_date's. @@ -1202,7 +1202,7 @@ fn l4( ) } -/// BS-statement-5 item 8: each invoice and bill line takes a project (by +/// BS-statement-5 statement 6: each invoice and bill line takes a project (by /// name or id); the entry's revenue or expense side is one line per /// project, the untagged lines' as one, the receivable or payable line /// and the payments untagged; books.project, profit_and_loss_by_class, @@ -1408,7 +1408,7 @@ fn a_document_for_a_finished_project_says_so() { ); } -/// BS-statement-5 items 4 and 8: an invoice line naming an on-spec project is taken +/// BS-statement-5 statements 5 and 6: an invoice line naming an on-spec project is taken /// and its result asks whether there is now an agreement (a hoped-for /// payment is no receivable); a bill's cost for one is an expense like any /// other, so a bill gets no such note. diff --git a/crates/ledger-core/src/arap.rs b/crates/ledger-core/src/arap.rs index 5f92f1ae..e054aac0 100644 --- a/crates/ledger-core/src/arap.rs +++ b/crates/ledger-core/src/arap.rs @@ -203,7 +203,7 @@ pub enum DocStatus { /// Less than nothing owed: more paid against it than it is for, a /// credit balance owed back (to the customer on an invoice, by the /// vendor on a bill). Only in books an earlier version left out of - /// bounds (BS-arap-2 INVARIANT 2); never a receivable or a payable, so + /// bounds (BS-arap-2 invariant 6); never a receivable or a payable, so /// never aged. Overpaid, /// Its own entry stands but carries no line tagged with it (an older @@ -263,7 +263,7 @@ pub struct DocState { impl DocState { /// It owes less than nothing or more than its total: books an earlier - /// version left out of bounds (BS-arap-2 INVARIANT 2; plan P4b.14 item 3), + /// version left out of bounds (BS-arap-2 invariant 6; plan P4b.14 item 3), /// which the control check lists for attention. pub fn out_of_bounds(&self) -> bool { self.outstanding < Decimal::ZERO || self.outstanding > self.total @@ -1144,8 +1144,8 @@ pub type DocumentPartKey = (Option, Option); /// GOAL: a document's lines post to their accounts and count toward their /// projects, and a document whose lines name neither posts exactly /// as before. -/// SOURCE: BS-statement-5 item 3 (job costing: the revenue and -/// direct costs identified with one job) and item 8 (an +/// SOURCE: BS-statement-5 statement 2 (job costing: the revenue and +/// direct costs identified with one job) and statement 4 (an /// invoice's or bill's line names its project); BS-arap-3 and plan /// P4b S4.1 A-10 (every bill line names its account). /// INVARIANTS: diff --git a/crates/ledger-core/src/assets.rs b/crates/ledger-core/src/assets.rs index a11a7968..97961fa1 100644 --- a/crates/ledger-core/src/assets.rs +++ b/crates/ledger-core/src/assets.rs @@ -11,7 +11,7 @@ //! — and postings go through the normal entry machinery, so every //! accounting invariant holds. //! -//! Two figures of accumulated depreciation, never confused (BS-asset-1 rule 8): +//! Two figures of accumulated depreciation, never confused (BS-asset-1 statement 28): //! what the schedule says is due through a date //! ([`accumulated_scheduled_through`]) and what the books carry, the runs //! posted and not reversed ([`crate::Ledger::accumulated_posted`]). Book @@ -743,7 +743,7 @@ fn schedule_months(asset: &Asset, through: NaiveDate) -> Result, /// (inclusive), exact to the minor unit ([`depreciation_schedule`]): the /// tools' `accumulated_scheduled_through`. What the books carry is /// [`crate::Ledger::accumulated_posted`]; the two agree once every month -/// due is posted (BS-asset-1 rule 8). +/// due is posted (BS-asset-1 statement 28). pub fn accumulated_scheduled_through( asset: &Asset, as_of: NaiveDate, diff --git a/crates/ledger-core/src/cashflow.rs b/crates/ledger-core/src/cashflow.rs index 3ca95f19..da271eb3 100644 --- a/crates/ledger-core/src/cashflow.rs +++ b/crates/ledger-core/src/cashflow.rs @@ -77,7 +77,7 @@ pub enum OperatingClass { /// (e) Interest paid. InterestPaid, /// (f) Income taxes paid. No tax category marks an entity-level income - /// tax yet, so nothing is filed here (BS-statement-3 rule 5). + /// tax yet, so nothing is filed here (BS-statement-3 statement 7). IncomeTaxesPaid, /// (g) Other operating cash payments. OtherPayments, @@ -178,7 +178,7 @@ pub struct CashFlowLine { /// The cash, + in. pub amount: Decimal, /// Of `amount`, what a member or a lender paid or received for the - /// company with no cash account moving (BS-statement-3 rule 11, D-42): + /// company with no cash account moving (BS-statement-3 statement 16, D-42): /// a constructive receipt or payment. Zero for most lines. pub on_behalf: Decimal, /// Codes of this kind's accounts the entry moved, sorted. @@ -295,7 +295,7 @@ pub struct OperatingReconciliation { pub net_cash_from_operating: Decimal, } -/// The footing check (BS-statement-3 rule 9). +/// The footing check (BS-statement-3 statement 14). #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct CashFlowFooting { /// Operating + investing + financing. @@ -440,8 +440,8 @@ pub enum RoleList { Investing, } -/// A contradiction among the cash flow account roles (BS-statement-3 rule -/// 2): the statement refuses rather than guess. +/// A contradiction among the cash flow account roles (BS-statement-3 statement +/// 3): the statement refuses rather than guess. #[derive(Clone, Debug, PartialEq, Eq)] pub enum RoleProblem { /// An account of the wrong type in a list. @@ -547,14 +547,14 @@ impl RoleProblem { } /// Every contradiction among the cash flow account roles (BS-statement-3 -/// rule 2), in a fixed order. Codes the chart lacks are the caller's to +/// statement 3), in a fixed order. Codes the chart lacks are the caller's to /// report. The one check behind both the statement's refusal and the /// settings' problems, so the two never drift apart. /// /// ```text /// GOAL: the statement's account roles partition the chart, so every /// account is in exactly one section. -/// SOURCE: BS-statement-3 rule 2 (ASC 230-10-45-10: every cash receipt and +/// SOURCE: BS-statement-3 statement 3 (ASC 230-10-45-10: every cash receipt and /// payment is investing, financing or operating). /// INVARIANTS: /// 1. Cash and investing accounts MUST be assets; financing accounts @@ -639,7 +639,7 @@ pub fn role_problems( out } -/// BS-statement-3 rule 9, on its own so the check is tested directly (it +/// BS-statement-3 statement 14, on its own so the check is tested directly (it /// cannot fail on posted entries): the sections sum to the change in /// cash, or nothing is produced. pub fn foot(sections_sum: Decimal, net_change: Decimal) -> Result { @@ -978,7 +978,7 @@ impl<'a> Roles<'a> { } /// The liabilities that hold distributions declared by `end` ( -/// BS-statement-3 rule 2), among the accounts `open` leaves to be placed: each +/// BS-statement-3 statement 3), among the accounts `open` leaves to be placed: each /// credited, in the posted entries dated on or before `end` (closes and /// reversals aside), only by entries whose debits are all to equity (Dr /// Distributions / Cr Distributions Payable; a corporation's Dr Retained diff --git a/crates/ledger-core/src/error.rs b/crates/ledger-core/src/error.rs index 72d434a5..ab09ed05 100644 --- a/crates/ledger-core/src/error.rs +++ b/crates/ledger-core/src/error.rs @@ -505,7 +505,7 @@ pub enum LedgerError { end: String, }, - /// The statement of cash flows would not foot (BS-statement-3 rule 9): + /// The statement of cash flows would not foot (BS-statement-3 statement 14): /// an engine error, never output. It cannot happen on balanced books /// (Lean `cashflow_sections_sum_to_cash_change`); if it does, the /// engine is wrong, and nothing is shown rather than a wrong figure. @@ -523,7 +523,7 @@ pub enum LedgerError { }, /// The cash flow statement's account roles (cash, financing, investing) - /// contradict each other or the chart (BS-statement-3 rule 2). The text + /// contradict each other or the chart (BS-statement-3 statement 3). The text /// names the setting and says what to change. #[error("cash flow account roles: {0}")] CashFlowRoles(String), @@ -695,13 +695,13 @@ pub enum LedgerError { SettlementMixedKinds(String), /// A settlement's documents don't all belong to the one party it - /// names (BS-arap-6 INVARIANT 1). + /// names (BS-arap-6 invariant 4). #[error("{0} is not {1}'s: a settlement covers one party only")] SettlementPartiesDiffer(String, u64), /// A discount needs a reason: none is stated in the document's terms, /// or it is larger than its terms allow, or it is taken after the - /// discount date (BS-arap-6 INVARIANT 2). + /// discount date (BS-arap-6 invariant 6). #[error( "{doc}: the discount of {discount} needs a reason ({because}); pass discount_reason with the payment" )] @@ -763,7 +763,7 @@ pub enum LedgerError { cash: Decimal, }, - /// A settlement's figures can't be exact (BS-arap-6 INVARIANT 1): an + /// A settlement's figures can't be exact (BS-arap-6 invariant 3): an /// amount too large to add, a negative fee, or a fee that leaves /// nothing to deposit; a fee above the cash is /// [`LedgerError::FeeAboveCash`]. @@ -796,7 +796,7 @@ pub enum LedgerError { }, /// Receivables or payables can't move to an account holding lines - /// that are no document's (BS-arap-2 INVARIANT 1): they would + /// that are no document's (BS-arap-2 statement 12): they would /// become hand lines on a control account. #[error( "account {code} \"{name}\" holds lines no invoice or bill carries (entry {entry} first), \ @@ -843,7 +843,7 @@ pub enum LedgerError { }, /// A reversal or payment would leave a document owing less than nothing - /// or more than its total at some date (BS-arap-2 INVARIANT 2): the + /// or more than its total at some date (BS-arap-2 invariant 6): the /// message says which document, when, and what to reverse first. #[error("{0}")] DocumentBounds(String), @@ -882,7 +882,7 @@ pub enum LedgerError { #[error("{0}")] InvalidSend(String), /// A bad debt can't be written off on cash-basis books ( - /// BS-arap-5 INVARIANT 3; IRC §166(a); Treas. Reg. §1.166-1(e)): the + /// BS-arap-5 statement 6; IRC §166(a); Treas. Reg. §1.166-1(e)): the /// invoice was never counted as income, so there is no basis to /// deduct. #[error( diff --git a/crates/ledger-core/src/kernel/allocate.rs b/crates/ledger-core/src/kernel/allocate.rs index ece8d6ba..74573c07 100644 --- a/crates/ledger-core/src/kernel/allocate.rs +++ b/crates/ledger-core/src/kernel/allocate.rs @@ -43,7 +43,7 @@ pub enum Leftover { /// SOURCE: BS-partner-1 (partners share by the agreement; capital accounts /// carry the allocations), BS-partner-3 (a party's part of an /// entry), BS-partner-4 (the K-1 worksheet), BS-1099-1 (a payment -/// split by the parties' shares), BS-statement-3 rule 5 (the +/// split by the parties' shares), BS-statement-3 statement 8 (the /// government's part of a payment), BS-arap-3 (a document line's /// exact amount). /// INVARIANTS: @@ -173,7 +173,7 @@ const MAX_CORRECTION_STEPS: usize = 4096; /// SOURCE: BS-partner-1 (partners share by the agreement; the largest /// remainder is the owner's choice, 2026-10-13), BS-partner-3 (a /// party's part of an entry), BS-partner-4 (the K-1 worksheet's -/// shares), BS-1099-1 (a payment's buckets), BS-statement-3 rule 5 +/// shares), BS-1099-1 (a payment's buckets), BS-statement-3 statement 8 /// (the government's part), BS-arap-3 (a document line's exact /// amount), BS-ledger-1 (a whole number of smallest units). /// INVARIANTS: diff --git a/crates/ledger-core/src/kernel/entries.rs b/crates/ledger-core/src/kernel/entries.rs index 1f6288f8..9bee0a70 100644 --- a/crates/ledger-core/src/kernel/entries.rs +++ b/crates/ledger-core/src/kernel/entries.rs @@ -391,7 +391,7 @@ pub fn net(lines: impl IntoIterator) -> Option { /// ```text /// GOAL: an early-payment discount never takes more than its percentage /// says, in exact money. -/// SOURCE: BS-arap-3 INVARIANT 2, BS-arap-6; plan/served.md +/// SOURCE: BS-arap-3 invariant 2, BS-arap-6; plan/served.md /// 8.3.13; CHOICE: the gross method, A-8 (the discount is /// booked when taken, never estimated). /// INVARIANTS: @@ -1047,8 +1047,8 @@ pub fn apportion_cumulative( Some(()) } -/// Where a line falls on the statement of cash flows (BS-statement-3 rule -/// 2): a cash account, or one of the three sections. +/// Where a line falls on the statement of cash flows (BS-statement-3 statement +/// 3): a cash account, or one of the three sections. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] pub enum Flow { /// A cash account: what the statement explains the change in. @@ -1063,7 +1063,7 @@ pub enum Flow { impl Flow { /// The three sections, in the order cash is applied to them ( - /// BS-statement-3 rule 3): operating, investing, financing. + /// BS-statement-3 statement 4): operating, investing, financing. pub const SECTIONS: [Flow; 3] = [Flow::Operating, Flow::Investing, Flow::Financing]; } @@ -1116,7 +1116,7 @@ pub fn take(remaining: T, movement: T) -> Option { /// ```text /// GOAL: split an entry's cash among the parts it settled, without /// inventing or losing any. -/// SOURCE: BS-statement-3 rule 3 (ASC 230-10-50-5: only the cash portion +/// SOURCE: BS-statement-3 statement 4 (ASC 230-10-50-5: only the cash portion /// of a part-cash transaction is a cash flow; the order is a /// CONVENTION, the ASC is silent). /// INVARIANTS: @@ -1143,7 +1143,7 @@ pub fn apply_cash(cash: T, movements: &[T], applied: &mut [T]) -> Opt (remaining == T::ZERO).then_some(()) } -/// An entry's cash flows (BS-statement-3 rule 3): the net movement of its +/// An entry's cash flows (BS-statement-3 statement 4): the net movement of its /// cash lines, applied to the sections moving against it in the order /// operating, investing, financing, each up to its own movement; what is /// left of a section's movement is the part no cash settled. `None` when @@ -1244,7 +1244,7 @@ fn credits_and_debits(movements: &[T]) -> Option<(T, T)> { } /// Which way money a member or a lender handled for the company went -/// (BS-statement-3 rule 11, D-42). +/// (BS-statement-3 statement 16, D-42). #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub enum OnBehalf { /// Paid for the company: sources credited (borrowed, contributed) @@ -1258,7 +1258,7 @@ pub enum OnBehalf { impl OnBehalf { /// The other way: what an entry's reversal does. /// - /// SOURCE: BS-statement-3 rule 11 (what a member or lender paid or + /// SOURCE: BS-statement-3 statement 16 (what a member or lender paid or /// received for the company is mirrored by its reversal). /// /// INVARIANTS: @@ -1273,7 +1273,7 @@ impl OnBehalf { /// What a member or a lender paid, or received, for the company with no /// cash account moving: a constructive receipt and disbursement ( -/// BS-statement-3 rule 11, D-42). `sources` are what is left unsettled of the +/// BS-statement-3 statement 16, D-42). `sources` are what is left unsettled of the /// entry's kinds that can pay or receive for the company (a financing /// liability, a member's equity), `uses` of the kinds they can pay or /// receive for, each debit-positive. [`OnBehalf::Paid`]: `amount = @@ -1289,7 +1289,7 @@ impl OnBehalf { /// GOAL: show money a member or lender handled for the company as the /// company's own, borrowed (or contributed) and spent, without /// inventing or losing a cent. -/// SOURCE: BS-statement-3 rule 11 (D-42; ASC 230 is silent, PwC Viewpoint +/// SOURCE: BS-statement-3 statement 16 (D-42; ASC 230 is silent, PwC Viewpoint /// FSP 6.9.3.1, Deloitte DART Roadmap 7.2, BDO Blueprint 3.4). /// INVARIANTS: /// 1. The parts net to zero: Σ from + Σ to = 0, so the entry's cash @@ -1322,7 +1322,7 @@ pub fn constructive( } /// How much of an entry is an exchange inside investing and financing -/// that no cash settled (BS-statement-3 rule 7, ASC 230-10-50-4: debt +/// that no cash settled (BS-statement-3 statement 12, ASC 230-10-50-4: debt /// converted to equity, one asset traded for another). `debits` and /// `credits` are the net debits and net credits of the entry's investing /// and financing balance-sheet accounts (each account netted first; both @@ -1449,7 +1449,7 @@ fn least(a: T, b: T) -> T { } /// What an entry's parties split and what of it counts (BS-partner-3 -/// item 3, every case but a close and a reversal, which the caller +/// statement 3, every case but a close and a reversal, which the caller /// handles: a close is its parties' own-account movement with direction /// neither, a reversal is [`reverse_target`] of its original's). /// @@ -1553,7 +1553,7 @@ pub fn party_target( }) } -/// A reversal's target from its original's (BS-partner-3 item 3; BS-ledger-5: a +/// A reversal's target from its original's (BS-partner-3 statement 3; BS-ledger-5: a /// correction is the opposite entry): every amount negated (never to a /// negative zero), paid and received swapped. An involution. `None` past /// the type's range. @@ -2043,12 +2043,12 @@ pub fn basis_figures( } /// A project's unrecovered cost from its tagged revenue and expenses to -/// date: what it would take to be repaid in full (BS-statement-5 item 4). +/// date: what it would take to be repaid in full (BS-statement-5 statement 5). /// /// ```text /// GOAL: the "if repaid" figure of work done on spec, from one function /// the tools, the viewer and bookspec share. -/// SOURCE: BS-statement-5 item 4 (ASC 450-30-25-1: a hoped-for +/// SOURCE: BS-statement-5 statement 5 (ASC 450-30-25-1: a hoped-for /// payment is a gain contingency, never recorded before it is /// received; so this is a figure, never a receivable). /// INVARIANTS: @@ -2087,7 +2087,7 @@ pub enum Bounds { /// ```text /// GOAL: one definition of "a document is never overpaid and never owes /// more than it is for", at every date, not only at the end. -/// SOURCE: BS-arap-2 INVARIANT 2 (0 <= outstanding(d, D) +/// SOURCE: BS-arap-2 invariant 6 (0 <= outstanding(d, D) /// <= total(d) at every D); plan/served.md P4b.3 (Bounds). /// INVARIANTS: /// 1. Within exactly when every prefix sum of `deltas` is within @@ -2134,7 +2134,7 @@ fn out_of_bounds(total: T, running: T) -> Option<(T, bool)> { /// GOAL: a command never puts a document out of bounds, yet books an /// earlier version left out of bounds (a void under a payment that /// stands) take the step that mends them. -/// SOURCE: BS-arap-2 INVARIANT 2, BS-entry-4 (replay accepts what +/// SOURCE: BS-arap-2 invariant 6, BS-entry-4 (replay accepts what /// was written; the bound is the commands'); plan/served.md /// P4b.14 item 3 (the remedy: reverse the payment). /// INVARIANTS: @@ -2179,7 +2179,7 @@ pub fn bounds_kept(total: T, before: &[T], after: &[T]) -> Bounds { mod tests { use super::*; - /// BS-statement-3 rule 3, by hand. Equipment 1,000 for 300 cash and a + /// BS-statement-3 statement 4, by hand. Equipment 1,000 for 300 cash and a /// 700 note: investing takes the 300, the note's 700 and the rest of /// the equipment's are the noncash part. #[test] @@ -2225,7 +2225,7 @@ mod tests { assert_eq!(apply_cash(10, &[-3], &mut out), None); } - /// The exchange measure (BS-statement-3 rule 7) on the review's + /// The exchange measure (BS-statement-3 statement 12) on the review's /// hand-checked cases. #[test] fn exchanged_matches_the_hand_checked_cases() { @@ -2247,7 +2247,7 @@ mod tests { assert_eq!(exchanged(1000i64, 1000, 1000, 1000), Some(0)); } - /// BS-statement-3 rule 11 (D-42), by hand. + /// BS-statement-3 statement 16 (D-42), by hand. #[test] fn constructive_pays_and_receives_for_the_company() { use OnBehalf::{Paid, Received}; diff --git a/crates/ledger-core/src/kernel/mod.rs b/crates/ledger-core/src/kernel/mod.rs index c392f9b8..bbb4eaac 100644 --- a/crates/ledger-core/src/kernel/mod.rs +++ b/crates/ledger-core/src/kernel/mod.rs @@ -42,7 +42,7 @@ //! to zero, and a reversal's parts are the original's negated (BS-statement-3); //! * what a member or lender paid or received for the company, with no //! cash account moving, is split among the kinds it settled, netting to -//! zero, and mirrored by a reversal (BS-statement-3 rule 11); +//! zero, and mirrored by a reversal (BS-statement-3 statement 16); //! * a party's part of an entry is signed as a line on the party's own //! account would be, a reversal's is its original's negated, and what of //! it counts as money or as property never exceeds it (BS-partner-3); diff --git a/crates/ledger-core/src/ledger.rs b/crates/ledger-core/src/ledger.rs index 4b565462..027a52b2 100644 --- a/crates/ledger-core/src/ledger.rs +++ b/crates/ledger-core/src/ledger.rs @@ -1368,7 +1368,7 @@ impl Ledger { /// - SHOULD refuse (RoleAccountHasHandLines), naming the entry /// - NEVER make a hand line a control account's /// BECAUSE no command adds an untagged control line (BS-arap-2 - /// INVARIANT 1). Replay never refuses (BS-entry-4). + /// invariant 2). Replay never refuses (BS-entry-4). /// An account the role moves off keeps its documents' lines, and /// stays guarded while it holds them (Self::control_role_of). /// ``` @@ -1632,7 +1632,7 @@ impl Ledger { /// no other: a chart's own account at a role's default code /// (1200 Equipment, a card at 2000) is anyone's until a document /// posts there. - /// SOURCE: BS-ledger-8, BS-arap-2 INVARIANT 1. + /// SOURCE: BS-ledger-8, BS-arap-2 statement 9. /// INVARIANTS: /// 1. Some(role) when the role is assigned to the account, or the /// account holds a line tagged with one of the role's documents @@ -1735,7 +1735,7 @@ impl Ledger { /// ```text /// GOAL: no command adds a line on a control account that is no /// document's; one only takes a legacy one away. - /// SOURCE: BS-arap-2 INVARIANT 1 and item 3 (the + /// SOURCE: BS-arap-2 invariant 2 and statement 11 (the /// exemption). /// INVARIANTS: /// 1. A tagged line passes. @@ -2284,7 +2284,7 @@ impl Ledger { /// - NEVER refuse reversing a payment, which only reopens its /// document /// BECAUSE 0 <= outstanding <= total at every date (BS-arap-2 - /// INVARIANT 2). Replay never refuses (BS-entry-4). + /// invariant 6). Replay never refuses (BS-entry-4). /// ``` pub fn check_reversal(&self, entry: EntryId, date: NaiveDate) -> Result<(), LedgerError> { let original = self @@ -2489,7 +2489,7 @@ impl Ledger { self.replay_add_line(id, line.account, kernel::flip(line.side), line.amount)?; // The reversal offsets the original line for line: carry the // class so divisional P&L nets correctly, and the document so - // it moves by exactly the opposite (BS-arap-2 INVARIANT 3). + // it moves by exactly the opposite (BS-arap-2 invariant 4). if line.class_id.is_some() { self.set_line_class(id, idx, line.class_id)?; } @@ -3214,7 +3214,7 @@ impl Ledger { /// ```text /// GOAL: a run the books record is the entry that posted it, no more /// and no less, so accumulated_posted is what the books carry. - /// SOURCE: BS-asset-1 rules 6 and 8, BS-asset-3; BS-entry-4 (new commands are bounded; replay checks + /// SOURCE: BS-asset-1 statements 14 and 28, BS-asset-3; BS-entry-4 (new commands are bounded; replay checks /// only what every journaled run passed: /// record_depreciation_run). /// ``` @@ -5771,7 +5771,7 @@ impl Ledger { /// line per (account, project) part the lines name, the parts /// naming neither as one (arap::document_parts), each revenue line /// tagged with its project; the receivable line never ( - /// BS-statement-5 item 8). + /// BS-statement-5 statement 6). /// 2. The receivable line MUST carry the invoice (Origin), in the /// step that posts it: the invoice starts Open, owing its total. /// 3. A refusal MUST leave the books unchanged. @@ -5906,7 +5906,7 @@ impl Ledger { /// with the vendor (1099s): one line per (account, project) part /// the lines name, the parts naming neither as one /// (arap::document_parts), each tagged with its project; the - /// payable line never (BS-statement-5 item 8). + /// payable line never (BS-statement-5 statement 6). /// 2. The payable line MUST carry the bill (Origin), in the step that /// posts it. /// 3. A refusal MUST leave the books unchanged. @@ -6267,7 +6267,7 @@ impl Ledger { /// GOAL: every figure about a document (paid, outstanding, status, /// overdue) is read from its tagged lines, so a reversal, a void /// or a bounced payment is right by construction. - /// SOURCE: BS-arap-2 (INVARIANTS 1-4), BS-ledger-5, BS-ledger-6, BS-arap-1; + /// SOURCE: BS-arap-2 (invariants 1, 4, 6 and 7), BS-ledger-5, BS-ledger-6, BS-arap-1; /// ASC 310-10 (receivables), ASC 405-20-40-1 (payables). /// INVARIANTS: /// 1. outstanding = the signed sum of every posted line tagged with @@ -6417,7 +6417,7 @@ impl Ledger { /// Refuse a step that would move `doc` by `extra` (dated movements) /// if, at some date, it would then owe less than nothing or more than /// its total where it didn't before ([`kernel::bounds_kept`]; - /// BS-arap-2 INVARIANT 2). Books an earlier version left out of bounds + /// BS-arap-2 invariant 6). Books an earlier version left out of bounds /// (a void under a payment that stands) take any step that makes no /// date worse, so the remedy (reversing the payment) is accepted. fn check_item_bounds( @@ -6478,7 +6478,7 @@ impl Ledger { /// The least `doc` owes on any day from `date` on (from its own date, /// for a date before it): what a payment may be, and what a write-off /// may be, so no later day ends out of bounds (BS-arap-2 - /// INVARIANT 2, BS-arap-5 INVARIANT 1). + /// invariant 6, BS-arap-5 invariant 3). fn least_owed_from(&self, doc: arap::DocRef, date: NaiveDate) -> Result { let (doc_date, ..) = self.doc_header(doc)?; let from = date.max(doc_date); @@ -7138,7 +7138,7 @@ impl Ledger { /// 3. 0 < amount <= the least the invoice owes on any day from /// `date` on (on the day, when nothing later lowers it): a /// partial write-off is allowed (§1.166-3(a)), and no day may - /// owe less than nothing (BS-arap-2 INVARIANT 2). + /// owe less than nothing (BS-arap-2 invariant 6). /// 4. The day MUST be in the calendar, in an open period, and not /// before the invoice. /// 5. A refusal MUST leave the books unchanged. @@ -7152,7 +7152,7 @@ impl Ledger { /// 4. IF it is dated before the invoice or in a closed period: /// SHOULD refuse. /// 5. Half paid, the rest written off: Written off, with 50 paid and - /// 50 written off (BS-arap-2 SCENARIO 7). + /// 50 written off (BS-arap-2 scenario 7). /// ``` pub fn write_off( &mut self, @@ -7257,7 +7257,7 @@ impl Ledger { /// ```text /// GOAL: a document that should never have existed (a duplicate, the /// wrong customer) is undone by an opposite entry, never erased. - /// SOURCE: BS-ledger-5, BS-ledger-6, BS-period-2, BS-arap-2 (scenarios 2, 3); + /// SOURCE: BS-ledger-5, BS-ledger-6, BS-period-2, BS-arap-2 (scenarios 2 and 3); /// plan/served.md P4b.5, P4b.6; ASC 250 (an immaterial error is /// corrected in the period found). /// INVARIANTS: @@ -7325,7 +7325,7 @@ impl Ledger { /// ```text /// GOAL: show that receivables and payables equal their documents, and /// list every line that is no document's. - /// SOURCE: BS-ledger-8, BS-arap-2 INVARIANT 1: + /// SOURCE: BS-ledger-8, BS-arap-2 invariant 1: /// GL(A, D) = Σ_docs outstanding(d, D) + unattached(A, D). /// INVARIANTS: /// 1. balance sums every posted line on the account dated on or @@ -7561,8 +7561,7 @@ impl Ledger { } } - /// Tag the line a new payment event names (plan P4b S6; BS-arap-6 - /// INVARIANT 3): line `index` of `entry`, when it is on the role's + /// Tag the line a new payment event names (plan P4b S6; WB-arap-15): line `index` of `entry`, when it is on the role's /// account, on the side the movement posts, untagged, and for `amount`. /// Otherwise it stays untagged and the control check lists it; replay /// never refuses (BS-entry-4). @@ -7771,7 +7770,7 @@ impl Ledger { } /// [`Self::replay_invoice_payment`] with the line a new event names and - /// the discount it took (plan P4b S6; BS-arap-6 INVARIANT 3). A + /// the discount it took (plan P4b S6; WB-arap-15). A /// line the event names but that can't be matched (no such line, the /// wrong account or side, or already tagged) stays untagged, and the /// control check lists it: replay never refuses (BS-entry-4). @@ -7922,7 +7921,7 @@ impl Ledger { /// /// ```text /// GOAL: what each customer owes as of a day, by how overdue. - /// SOURCE: BS-arap-1, BS-arap-2 INVARIANT 5. + /// SOURCE: BS-arap-1, BS-arap-2 invariant 8. /// INVARIANTS: /// 1. Each invoice issued by `as_of` that owes something then /// (Self::doc_state's outstanding) is in exactly one bucket, at @@ -9311,7 +9310,7 @@ impl Ledger { /// /// ```text /// GOAL: a new class under a name no other class has. - /// SOURCE: BS-statement-5 item 1. + /// SOURCE: WB-statement-5. /// SCENARIOS: /// 1. IF the name is blank: SHOULD refuse (EmptyClassName). /// 2. IF it is longer than a line, holds a control character or a @@ -9333,7 +9332,7 @@ impl Ledger { /// /// ```text /// GOAL: one rule for every name a command gives a class. - /// SOURCE: BS-statement-5 item 1; BS-partner-2 (no full TIN). + /// SOURCE: WB-statement-5; BS-partner-2 (no full TIN). /// SCENARIOS: /// 1. IF `except` is a class and the name is its own, exactly: SHOULD /// keep it as stored, unchecked, so a fact-only change never @@ -9482,7 +9481,7 @@ impl Ledger { /// ```text /// GOAL: refuse any project record the books can't take, before a /// line is written. - /// SOURCE: BS-statement-5 item 1 (and BS-partner-2: no full TIN). + /// SOURCE: WB-statement-5 (and BS-partner-2: no full TIN). /// SCENARIOS: /// 1. IF the class doesn't exist: SHOULD refuse (UnknownClass). /// 2. IF the name is blank, too long, or another class has it @@ -9561,7 +9560,7 @@ impl Ledger { } } -/// A class name as names compare (BS-statement-5 item 1): trimmed, in +/// A class name as names compare (WB-statement-5): trimmed, in /// lower case (Unicode's, so `Éclair` and `éCLAIR` are one name). fn fold_class_name(name: &str) -> String { name.trim().to_lowercase() diff --git a/crates/ledger-core/src/parties.rs b/crates/ledger-core/src/parties.rs index dbb6fb40..7cb0db7f 100644 --- a/crates/ledger-core/src/parties.rs +++ b/crates/ledger-core/src/parties.rs @@ -850,7 +850,7 @@ impl PartyField { } } -/// Which of a party's totals to report (BS-partner-3 item 4). Not the +/// Which of a party's totals to report (BS-partner-3 statement 5). Not the /// books' accounting method (`books.accounting_basis`): party totals count /// what moved, whichever method the books keep. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] @@ -981,7 +981,7 @@ impl MoneyAccounts { /// ```text /// GOAL: a card is known from what the books record, and a promise (a /// gift card sold) or a member's own card is never the company's. -/// SOURCE: BS-partner-3 item 5 (DECISION, owner, 2026-10-20: money is +/// SOURCE: BS-partner-3 statement 7 (DECISION, owner, 2026-10-20: money is /// cash, cards, the members' financing and loans), BS-1099-1 (payment /// methods, plan P3 defect 12). /// INVARIANTS: @@ -1376,7 +1376,7 @@ pub fn activity_with( } let shares = ledger.entry_parties(id); // The target first: an entry that counts nothing is never - // unresolved for shares that don't fit it (BS-partner-3 item 4). + // unresolved for shares that don't fit it (BS-partner-3 statement 5). let Ok(t) = crate::shares::target(ledger, id, shares, money) else { a.unresolved.insert(id); continue; diff --git a/crates/ledger-core/src/proofs/allocate.rs b/crates/ledger-core/src/proofs/allocate.rs index 25fea242..7785a9c1 100644 --- a/crates/ledger-core/src/proofs/allocate.rs +++ b/crates/ledger-core/src/proofs/allocate.rs @@ -17,7 +17,7 @@ //! is the callers' answer rather than a division by zero. //! SOURCE: BS-partner-1 (partners share by the agreement; largest //! remainder), BS-1099-1 (a payment's buckets), BS-statement-3 -//! rule 5 (the government's part), BS-arap-3 (a document line's +//! statement 8 (the government's part), BS-arap-3 (a document line's //! exact amount), BS-ledger-1 (whole smallest units). //! INVARIANTS: //! 1. The parts sum to the whole, for every policy. diff --git a/crates/ledger-core/src/proofs/mod.rs b/crates/ledger-core/src/proofs/mod.rs index 52e4caae..4a4d7ad4 100644 --- a/crates/ledger-core/src/proofs/mod.rs +++ b/crates/ledger-core/src/proofs/mod.rs @@ -968,7 +968,7 @@ fn apply_cash_mirrors() { /// An accepted entry always has cash flows, and they explain its cash /// exactly: the sections' cash sums to the entry's cash, and what no cash /// settled (each section's movement plus its cash) sums to zero -/// (BS-statement-3 rules 3 and 9: the statement foots, entry by entry). +/// (BS-statement-3 statements 4 and 14: the statement foots, entry by entry). #[kani::proof] #[kani::unwind(5)] fn entry_flows_sum_to_cash() { @@ -1043,7 +1043,7 @@ fn entry_flows_are_bounded() { /// A reversal's cash flows are its original's, negated, part by part: /// what lets an entry and its reversal in one period drop out of the -/// statement together (BS-statement-3 rule 6). End to end, on entries of +/// statement together (BS-statement-3 statement 11). End to end, on entries of /// up to two lines: at three (`NF`) one run went past half an hour at /// four jobs on a busy machine (2026-10-21), so three lines are proved in /// two halves, `entry_movements_of_a_reversal_mirror` and @@ -1228,7 +1228,7 @@ fn any_way() -> kernel::OnBehalf { } /// What a member or a lender paid or received for the company ( -/// BS-statement-3 rule 11, D-42) invents and loses nothing: the parts net to zero, +/// BS-statement-3 statement 16, D-42) invents and loses nothing: the parts net to zero, /// so an entry's flows still sum to its cash; each part settles its own /// movement toward zero, never past it; and as much is settled as can be. #[kani::proof] @@ -1276,7 +1276,7 @@ fn constructive_nets_to_zero() { /// The other way, minus the sources and minus the uses give minus the /// parts: a reversal of a payment made on the company's behalf mirrors it -/// (BS-statement-3 rule 6), so the two drop out together. +/// (BS-statement-3 statement 11), so the two drop out together. #[kani::proof] #[kani::unwind(4)] fn constructive_mirrors() { @@ -1320,7 +1320,7 @@ fn any_party_inputs() -> (Option<(i64, i64)>, i64, i64, i64) { (capital, any_amount(), any_amount(), debits) } -/// BS-partner-3 items 1-4: the direction is the sign of what counts (paid above +/// BS-partner-3 statements 1-5: the direction is the sign of what counts (paid above /// zero, received below), neither exactly when nothing counts; cash and /// in kind each carry the whole's sign and together never exceed it; a /// money target is all cash; a contribution counts all of itself; a @@ -1393,7 +1393,7 @@ fn direction_of_is_the_sign() { kani::cover!(amount == 0, "nothing moved"); } -/// BS-partner-3 item 3 and BS-ledger-5: the target is odd. Negating the lines negates the +/// BS-partner-3 statement 3 and BS-ledger-5: the target is odd. Negating the lines negates the /// capital movement, the money net and the own-account movement, and the /// property comes from the other side, so it keeps its size: the result /// is the original's reverse_target, whenever it isn't the debits fallback @@ -1837,7 +1837,7 @@ fn basis_figures_laws() { ); } -/// `kernel::unrecovered_cost` (BS-statement-5 item 4), for every revenue +/// `kernel::unrecovered_cost` (BS-statement-5 statement 5), for every revenue /// and expense a line could carry: never below zero; the shortfall when /// expenses exceed revenue, else zero; never above max(expenses, 0) when /// revenue isn't negative (expenses may be negative: a reimbursement @@ -1859,7 +1859,7 @@ fn unrecovered_cost_laws() { kani::cover!(u == 0 && revenue > expenses, "repaid, and more"); } -/// `kernel::running_bounds` (BS-arap-2 INVARIANT 2; the bounds every +/// `kernel::running_bounds` (BS-arap-2 invariant 6; the bounds every /// document command and reversal checks), for every total and every /// sequence of up to `N` dated movements a line could carry: it says /// Within exactly when every running balance is in `0 ..= total`, and @@ -1899,7 +1899,7 @@ fn bounds_check_matches_definition() { } /// `kernel::bounds_kept` (the check every document command and reversal -/// runs, BS-arap-2 INVARIANT 2): on books in bounds at every date it +/// runs, BS-arap-2 invariant 6): on books in bounds at every date it /// is the definition (`running_bounds` of the books after the step); and /// whenever it says Within, no running balance after the step is further /// outside `0 ..= total` than before it, so a step that mends books an diff --git a/crates/ledger-core/src/reports.rs b/crates/ledger-core/src/reports.rs index dc4062c4..b3769f90 100644 --- a/crates/ledger-core/src/reports.rs +++ b/crates/ledger-core/src/reports.rs @@ -533,7 +533,7 @@ fn profit_and_loss_counted( )) } -/// A project's figures (BS-statement-5 item 3): the period's statement and +/// A project's figures (BS-statement-5 statement 2): the period's statement and /// months, and its figures to date. #[derive(Clone, Debug)] pub struct ProjectFigures { @@ -592,7 +592,7 @@ pub struct ProjectToDate { impl ProjectToDate { /// Revenue less expenses: the project's contribution before overhead - /// (BS-statement-5 item 7), since only its own tagged lines count. + /// (WB-statement-7), since only its own tagged lines count. pub fn net(&self) -> Decimal { self.revenue - self.expenses } @@ -611,11 +611,11 @@ impl ProjectToDate { } /// Contribution as a percent of revenue, to one place (half to even), or -/// `None` without revenue to divide by (BS-statement-5 item 7). +/// `None` without revenue to divide by (WB-statement-7). /// /// ```text /// GOAL: one margin the tools and the viewer print alike. -/// SOURCE: BS-statement-5 item 7 (revenue less the costs traced +/// SOURCE: WB-statement-7 (revenue less the costs traced /// to the project, fixed and variable alike: Garrison's segment /// margin, as a ratio; not Horngren's variable-cost contribution /// margin; a presentation choice, not GAAP). @@ -650,7 +650,7 @@ pub const PROJECT_MONTHS: u32 = 240; /// ```text /// GOAL: what a project earned and cost, from one function the tools, the /// viewer and bookspec share, so their figures never drift. -/// SOURCE: BS-statement-5 item 3 (job costing), BS-period-1, BS-statement-3. +/// SOURCE: BS-statement-5 statement 2 (job costing), BS-period-1, BS-statement-3. /// INVARIANTS: /// 1. MUST be profit_and_loss_for_period with the project's class: only /// revenue and expense lines tagged to it, closing entries left out. @@ -748,7 +748,7 @@ pub fn project_to_date( /// Every entry with a line tagged to the project (drafts included), /// newest first (by date, then id), with its project amount: its tagged /// revenue lines less its tagged expense lines, each on its normal side. -/// A tagged balance-sheet line counts zero (BS-statement-5 item 3). +/// A tagged balance-sheet line counts zero (BS-statement-5 statement 2). pub fn project_entries(ledger: &Ledger, id: ClassId) -> Vec<(crate::EntryId, Decimal)> { let mut out: Vec<(NaiveDate, crate::EntryId, Decimal)> = Vec::new(); for eid in 1..ledger.next_entry_id() { diff --git a/crates/ledger-core/src/shares.rs b/crates/ledger-core/src/shares.rs index 269d1ed7..a304ffc6 100644 --- a/crates/ledger-core/src/shares.rs +++ b/crates/ledger-core/src/shares.rs @@ -22,7 +22,7 @@ //! part; DECISION, owner, 2026-10-20: a member's entry counts what //! moved their capital). //! DEFINITIONS: -//! target (target(), BS-partner-3 item 3): what the shares split, +//! target (target(), BS-partner-3 statement 3): what the shares split, //! signed debit-positive as a line on the parties' own account would //! be (positive: the company paid or gave; negative: it received), //! with its direction (paid, received, neither) and what of it moved @@ -317,7 +317,7 @@ pub struct Target { pub in_kind: Decimal, /// Which side the parts count on in a party's totals: the direction /// of the entry's root original (itself, unless it is a reversal), so - /// a reversal nets what it reverses (BS-partner-3 item 4). + /// a reversal nets what it reverses (BS-partner-3 statement 5). pub counts_as: Direction, } diff --git a/crates/ledger-core/src/tax_capital.rs b/crates/ledger-core/src/tax_capital.rs index ab417ab8..e36cbceb 100644 --- a/crates/ledger-core/src/tax_capital.rs +++ b/crates/ledger-core/src/tax_capital.rs @@ -89,9 +89,9 @@ use rust_decimal::Decimal; /// `[start, end]`: its lines on the asset's depreciation expense account, /// debit-positive (the depreciation still due through the disposal day, /// or, negative, what the month's run posted past it, credited back: -/// BS-asset-1 rule 5). With the runs +/// BS-asset-1 statement 9). With the runs /// (`Ledger::depreciation_posted_between`) it is the asset's depreciation -/// expense in the span, the P&L's and the cash flow's (BS-statement-3 rule 8). +/// expense in the span, the P&L's and the cash flow's (BS-statement-3 statement 13). /// The disposal entry is the posted entry dated the disposal day that /// credits the asset's cost account by its cost (`Store::dispose_asset` /// posts it so). diff --git a/crates/ledger-core/tests/bookspec/queries/assets.rs b/crates/ledger-core/tests/bookspec/queries/assets.rs index 2f4f0baf..55734397 100644 --- a/crates/ledger-core/tests/bookspec/queries/assets.rs +++ b/crates/ledger-core/tests/bookspec/queries/assets.rs @@ -364,7 +364,7 @@ pub(crate) fn check_schedule_plan(b: &Books<'_>, x: &Expect) { } /// Check one `register_row` expectation: the asset's row of the fixed -/// asset register as of `as_of` (BS-asset-1 rules 7 and 8, BS-asset-3): +/// asset register as of `as_of` (BS-asset-1 statements 23, 24 and 28, BS-asset-3): /// `acquired` and `in_service` (`YYYY-MM-DD`), `cost`, /// `accumulated_scheduled` (the schedule's), `accumulated_posted` (what /// the books carry), `unposted` (the one less the other), `book_value` diff --git a/crates/ledger-core/tests/bookspec/queries/parties.rs b/crates/ledger-core/tests/bookspec/queries/parties.rs index a8089a6f..fb33da31 100644 --- a/crates/ledger-core/tests/bookspec/queries/parties.rs +++ b/crates/ledger-core/tests/bookspec/queries/parties.rs @@ -299,7 +299,7 @@ pub(crate) fn check_vendor_1099(b: &Books<'_>, x: &Expect) { /// The money party shares resolve against: the cash accounts (every /// asset account but receivables when none are named), the cards and the -/// financing accounts (BS-partner-3 item 5). +/// financing accounts (BS-partner-3 statement 7). pub(crate) fn party_money(ex: &Example, l: &Ledger) -> MoneyAccounts { ledger_core::parties::money_accounts( l, @@ -368,7 +368,7 @@ pub(crate) fn check_party_part(b: &Books<'_>, x: &Expect) { /// Check one `party_totals` expectation: what was `paid` to and /// `received` from the party from `from` through `to` on `basis` (`cash`: /// money; `all`: money and property in kind), each entry's part on its -/// root original's side (BS-partner-3 item 4); both given. +/// root original's side (BS-partner-3 statement 5); both given. pub(crate) fn check_party_totals(b: &Books<'_>, x: &Expect) { let (ex, l) = (b.ex, b.l()); assert!( diff --git a/crates/ledger-core/tests/form1099.rs b/crates/ledger-core/tests/form1099.rs index 27f1ef33..479e372c 100644 --- a/crates/ledger-core/tests/form1099.rs +++ b/crates/ledger-core/tests/form1099.rs @@ -2317,7 +2317,7 @@ proptest! { } } - /// BS-partner-3 item 9: party totals and the 1099 worksheet never + /// BS-partner-3 statement 11: party totals and the 1099 worksheet never /// contradict. For books whose cash accounts are named, whose company /// card is recorded as a business-card payment method (or that have /// no card at all: without the method, 2050's name says nothing, so diff --git a/crates/ledger-core/tests/invariants.rs b/crates/ledger-core/tests/invariants.rs index dbcd1203..23aece74 100644 --- a/crates/ledger-core/tests/invariants.rs +++ b/crates/ledger-core/tests/invariants.rs @@ -798,7 +798,7 @@ fn cash_flow_reconciles_to_change_in_cash() { // Operating, by the direct method: collected 1,500 (class (a)); paid // 2,500 for equipment (not a registered asset: operating, - // BS-statement-3 rule 12's limits) and 800 rent (class (d)) = -1,800. Reconciled: + // BS-statement-3 statement 17's limits) and 800 rent (class (d)) = -1,800. Reconciled: // 3,200 net income - 2,500 increase in AR (4,000 billed - 1,500 // collected) - 2,500 increase in equipment = -1,800. // Financing: +10,000 owner contribution. Sum = 8,200. Reconciles. diff --git a/crates/ledger-core/tests/kernel_bridge/main.rs b/crates/ledger-core/tests/kernel_bridge/main.rs index e91c8b54..31e1090e 100644 --- a/crates/ledger-core/tests/kernel_bridge/main.rs +++ b/crates/ledger-core/tests/kernel_bridge/main.rs @@ -278,7 +278,7 @@ proptest! { } } - /// BS-statement-3 rule 3: the statement of cash flows' per-entry split + /// BS-statement-3 statement 4: the statement of cash flows' per-entry split /// (`kernel::entry_flows`, Kani `entry_flows_*`) is the same at both /// instantiations, on balanced and unbalanced lines alike. #[test] @@ -325,7 +325,7 @@ proptest! { ); } - /// BS-statement-3 rule 11: `kernel::constructive` (what a member or + /// BS-statement-3 statement 16: `kernel::constructive` (what a member or /// lender paid or received for the company; Kani /// `constructive_nets_to_zero`, `constructive_mirrors`) agrees at both /// instantiations. diff --git a/crates/ledger-core/tests/properties.rs b/crates/ledger-core/tests/properties.rs index 900b4fab..cb1140eb 100644 --- a/crates/ledger-core/tests/properties.rs +++ b/crates/ledger-core/tests/properties.rs @@ -680,7 +680,7 @@ proptest! { prop_assert_eq!(scheduled_book_value(a, on).unwrap(), want.book_value); } - /// BS-asset-1 rule 3 (defect 22), against arithmetic written here: through + /// BS-asset-1 statement 4 (defect 22), against arithmetic written here: through /// any day k of the life's final month (its d days), accumulated is C + /// (D − C) × k / d rounded half up to the cent, C the exact charge of /// the months before (D × each month's days held over its days, over @@ -719,7 +719,7 @@ proptest! { } } - /// BS-asset-1 rule 4 (depreciation_schedule INVARIANT 6; P3 depreciation brief 2.3, R1, R8): through every + /// BS-asset-1 statement 6 (depreciation_schedule INVARIANT 6; P3 depreciation brief 2.3, R1, R8): through every /// month end of the life, the schedule is the pre-P3 running total /// (USD, a two-place currency), except where the exact cumulative is a /// half-cent tie, which the old 28-digit Decimal quotients could round @@ -937,7 +937,7 @@ proptest! { proptest! { #![proptest_config(ProptestConfig::with_cases(256))] - /// BS-statement-5 item 3: for any tags and any period, the projects' + /// BS-statement-5 statement 2: for any tags and any period, the projects' /// figures plus the untagged lines' are the period's profit and loss /// (no line counted twice or lost), each through /// ledger_core::project_figures. @@ -1002,7 +1002,7 @@ proptest! { prop_assert_eq!(exp_sum + untagged_exp, all.total_expenses); } - /// BS-statement-5 item 7: the snapshot's contribution is + /// WB-statement-7: the snapshot's contribution is /// project_to_date's net, revenue less direct costs, whatever the /// tags and sides (a refund debits revenue, a reimbursement credits an /// expense below zero): the accounts sum to the totals, each month's @@ -1091,7 +1091,7 @@ proptest! { } } - /// BS-statement-5 item 3: project_entries codes its own signs, so the + /// BS-statement-5 statement 2: project_entries codes its own signs, so the /// posted entries' project amounts must sum to project_to_date's net /// (with no entry dated after the day), whatever the tags, the sides, /// a tagged balance-sheet line, or drafts beside them. diff --git a/crates/ledger-core/tests/spec_asset_tags.rs b/crates/ledger-core/tests/spec_asset_tags.rs index 8f4e3307..a5ac5189 100644 --- a/crates/ledger-core/tests/spec_asset_tags.rs +++ b/crates/ledger-core/tests/spec_asset_tags.rs @@ -1088,8 +1088,8 @@ fn register_of_no_assets_is_empty() { /// 1,000.00 and June's 10/30: 5,333.33 scheduled. Before P3 the disposed /// schedule ended in a plug, so the register showed 12,000.00 and 0.00. /// The same in the life's final month: on 2026-12-15, 11,483.87. Book -/// value is cost less what the books carry (defect 13, BS-asset-1 rule -/// 8): the fixture's runs, January to March, 3,000.00, so 9,000.00. +/// value is cost less what the books carry (defect 13, BS-asset-1 statement +/// 28): the fixture's runs, January to March, 3,000.00, so 9,000.00. #[test] fn register_as_of_a_day_before_a_same_month_disposal_is_prorated() { let (mut l, _, laptop, _) = register_fixture(); diff --git a/crates/ledger-core/tests/spec_cash_flow.rs b/crates/ledger-core/tests/spec_cash_flow.rs index f7b9f476..9fd04052 100644 --- a/crates/ledger-core/tests/spec_cash_flow.rs +++ b/crates/ledger-core/tests/spec_cash_flow.rs @@ -168,7 +168,7 @@ fn s(t: &str) -> String { t.to_string() } -/// The laws every statement keeps (BS-statement-3 rules 8 and 9): each +/// The laws every statement keeps (BS-statement-3 statements 13 and 14): each /// section is its lines, and its kinds; the sections are the change in /// cash; net income and the reconciling items are operating. fn foots(cf: &CashFlowStatement) { @@ -205,7 +205,7 @@ fn no_distribution(cf: &CashFlowStatement) { /// The minimal reproduction of defect 1. Property contributed (Dr /// Equipment 2,340 / Cr Capital), the asset registered, the entry reversed /// the same day. No cash moved, and the entry and its reversal cancel -/// (BS-statement-3 rules 1, 6): every section 0.00, no lines, no +/// (BS-statement-3 statements 2 and 11): every section 0.00, no lines, no /// disclosures, footing 0 / 0 / 0. Before the fix: investing −2,340.00 /// against a change in cash of 0.00 (the reversal's credit to the /// equipment account belonged to no section). @@ -876,7 +876,7 @@ fn a_property_contribution_is_a_noncash_disclosure() { assert_eq!(n.label, format!("Laptop contributed (#{e})")); } -/// D-42, BS-statement-3 rule 11 (ASC 230 is silent on a payment a third +/// D-42, BS-statement-3 statement 16 (ASC 230 is silent on a payment a third /// party makes on the entity's behalf; PwC FSP 6.9.3.1, DART Roadmap 7.2 /// and BDO Blueprint 3.4 present it by substance, as constructive receipt /// and disbursement). An expense a member pays personally (Dr Supplies @@ -1011,7 +1011,7 @@ fn equipment_a_lender_paid_for_is_borrowed_and_invested() { assert_eq!(cf.net_change_in_cash, x("-500.00")); } -/// The expense-to-capital case (BS-statement-3 rule 11): a member pays a +/// The expense-to-capital case (BS-statement-3 statement 16): a member pays a /// vendor for the company and the books credit the member's capital (Dr /// Supplies 80 / Cr Capital — Member A), no cash. The member paid cash to /// a third party on the company's behalf, as through 2100; only the form @@ -1150,7 +1150,7 @@ fn equipment_on_the_sellers_credit_stays_noncash_and_flagged() { assert!(w.message.contains("borrowed and spent"), "{}", w.message); } -/// BS-statement-3 rule 6 with rule 11: a payment a member made for the +/// BS-statement-3 statement 11 with statement 16: a payment a member made for the /// company and its reversal, both in February, drop out together (their /// flows, constructive cash included, are exact negatives: Kani /// `constructive_mirrors`); no line, no disclosure, no total moves. The @@ -1351,7 +1351,7 @@ fn interest_and_guaranteed_payments_charged_to_a_creditor_stay_noncash() { ); } -/// BS-statement-3 rule 6 (BS-ledger-5: a correction undoes what it corrects): an +/// BS-statement-3 statement 11 (BS-ledger-5: a correction undoes what it corrects): an /// entry and its reversal both in the period drop out of every line and /// disclosure, and no total moves (their flows are exact negatives, Kani /// `entry_flows_of_a_reversal_mirror`). @@ -1390,7 +1390,7 @@ fn an_entry_and_its_reversal_in_the_period_drop_out() { assert_eq!(cf.net_change_in_cash, before.net_change_in_cash); } -/// BS-statement-3 rule 6: a reversal shown alone (its original in an +/// BS-statement-3 statement 11: a reversal shown alone (its original in an /// earlier period) is labelled "Reversal of #N — " and /// listed under its original's kind, never as a distribution (D1-c). #[test] @@ -1414,7 +1414,7 @@ fn a_reversal_alone_is_labelled_reversal_of() { no_distribution(&cf); } -/// BS-statement-3 rules 4 and 6: a reversal takes its chain root's +/// BS-statement-3 statements 5 and 11: a reversal takes its chain root's /// sections, class and kind, with its own sign. Reversing January's cash /// sale at a 300 gain in February: investing −500 under "Proceeds from /// sales of property and equipment", G +300 (the gain, reversed, is still @@ -1766,7 +1766,7 @@ fn operating_classes_follow_asc_230_10_45_25() { /// ASC 230-10-45-28(b): depreciation is an item of net income with no /// cash effect, a reconciling item; it is not an investing or financing -/// activity, so nothing is disclosed (BS-statement-3 rule 7). +/// activity, so nothing is disclosed (BS-statement-3 statement 12). #[test] fn depreciation_is_reconciling_not_disclosed() { let mut b = funded(); @@ -1862,7 +1862,7 @@ fn operating_reconciliation_ties_to_operating_cash() { ); } -/// BS-period-1 and BS-statement-3 rule 10: a period close moves earnings into +/// BS-period-1 and BS-statement-3 statement 15: a period close moves earnings into /// equity; it earns and spends nothing, so it is never in the statement. #[test] fn closing_entries_never_appear() { @@ -1881,7 +1881,7 @@ fn closing_entries_never_appear() { assert!(!text.contains(&format!("entry: {close},"))); } -/// The period is [start, end] inclusive (BS-statement-3 rule 1): a +/// The period is [start, end] inclusive (BS-statement-3 statement 2): a /// contribution on the start date is a flow, not opening cash. #[test] fn cash_flow_starts_counting_on_the_start_date() { @@ -1921,8 +1921,7 @@ fn a_transfer_between_cash_accounts_is_not_a_flow() { assert!(cf.noncash_disclosures.is_empty()); } -/// Review round 2, footing in odd shapes (BS-statement-3 rules 1, 6, 9, -/// 11), by hand: +/// Review round 2, footing in odd shapes (BS-statement-3 statements 2, 11, 14 and 16), by hand: /// - two cash accounts in one entry, a transfer less its fee (Dr Savings /// 99, Dr Supplies 1 / Cr Cash 100): only the net, −1, moves cash, /// operating (d); no investing or financing; @@ -2217,7 +2216,7 @@ fn financing_lists_each_members_contributions_and_distributions() { /// "at a minimum" apart from the other classes, so an entry's operating /// cash is classed kind by kind: its interest lines are (b) or (e) /// whatever else it settles, the rest by its structure (BS-statement-3 -/// rule 5). By hand: +/// statement 7). By hand: /// - a payment of 900 on a loan the settings leave operating, with 100 /// interest (Dr 2500 900, Dr 6200 100 / Cr cash 1,000): (d) −900 and /// (e) −100, not (e) −1,000; @@ -2547,7 +2546,7 @@ fn a_reversed_bill_payment_leaves_the_purchase_unpaid() { } // --------------------------------------------------------------------------- -// Role refusals (BS-statement-3 rule 2) and the footing check (rule 9). +// Role refusals (BS-statement-3 statement 3) and the footing check (statement 14). // --------------------------------------------------------------------------- fn refused(b: &Books, cash: &[&str], financing: &[&str], investing: &[&str]) -> String { @@ -2617,7 +2616,7 @@ fn a_registered_asset_account_cannot_be_cash() { assert!(m.contains("a registered fixed asset's account"), "{m}"); } -/// BS-statement-3 rule 9: any difference between the sections and the +/// BS-statement-3 statement 14: any difference between the sections and the /// change in cash is an engine error, never a statement. #[test] fn foot_refuses_any_difference() { @@ -3244,7 +3243,7 @@ fn a_disposals_depreciation_credit_back_is_depreciation() { assert_eq!(cf.cash_from_investing, x("975.00")); } -/// BS-statement-3 rule 5 (the P3 cutover review's open point 2): ASC +/// BS-statement-3 statement 8 (the P3 cutover review's open point 2): ASC /// 230-10-45-17(c), "Cash payments to governments for taxes, duties, /// fines, and other fees or penalties", is not 45-17(b)'s "Cash payments /// to other suppliers and employees": a state's filing fee booked to an @@ -3316,7 +3315,7 @@ fn a_payment_to_a_government_is_other_operating() { assert_eq!((line.class, line.amount), (Some(OtherPayments), x("75.00"))); } -/// BS-statement-3 rule 5: the payee decides on any account, and the tax +/// BS-statement-3 statement 8: the payee decides on any account, and the tax /// category still does without one: a license on `taxes_licenses` with no /// party is (g). An entry naming a government and a supplier together /// (half each) is split by their shares, as ASC 230-10-45-22 has each @@ -3371,7 +3370,7 @@ fn a_government_payee_moves_a_fee_on_any_account() { assert_eq!(classes(&cf, shared), [(OtherPayments, x("-100.00"))]); } -/// BS-statement-3 rule 5: a split by shares that leaves an odd cent rounds +/// BS-statement-3 statement 8: a split by shares that leaves an odd cent rounds /// the government's part half to even, the supplier's the rest, so the /// line still sums to the payment; its reversal next month mirrors it to /// the cent. Fixed amounts split as given. @@ -3450,7 +3449,7 @@ fn a_shared_government_payment_splits_to_the_cent() { ); } -/// BS-statement-3 rule 5: a reversal takes its original's payee, so the +/// BS-statement-3 statement 8: a reversal takes its original's payee, so the /// pair always lands in one class and nets. A state's fee paid in /// February and reversed in March: (g) both. The books keep a reversal /// chain's parties one (Ledger::set_entry_parties INVARIANT 5): tagging @@ -3500,7 +3499,7 @@ fn a_reversal_takes_its_originals_payee() { assert_eq!(classes(&b), both(ToSuppliersAndEmployees)); } -/// BS-statement-3 rules 5 and 11: a payment shared between a state and an +/// BS-statement-3 statements 8 and 16: a payment shared between a state and an /// agent that a member paid personally (Dr 6000 137.00 / Cr 2100, the /// members' financing account) is borrowed and spent, and its spending is /// split by the parties' shares as a bank payment's is, the part no bank @@ -3577,7 +3576,7 @@ fn a_shared_government_payment_a_member_paid_splits_both_ways() { assert_eq!(cf.net_change_in_cash, Decimal::ZERO); } -/// BS-statement-3 rule 5 (CONVENTION): payroll keeps its structure. Taxes +/// BS-statement-3 statement 9 (CONVENTION): payroll keeps its structure. Taxes /// withheld from employees and remitted to the tax agency are the /// employees' pay (45-17(b), "Cash payments to other suppliers and /// employees"), and the payroll payables mix them with the employer's @@ -3636,7 +3635,7 @@ fn a_payroll_remittance_to_a_tax_agency_stays_pay() { assert_eq!(class(employer), Some(OtherPayments)); } -/// BS-statement-3 rule 5: a government selling goods or services is a +/// BS-statement-3 statement 8: a government selling goods or services is a /// supplier (45-17(b), "for other goods or services"), not 45-17(c)'s /// taxes, fees or penalties: the post office named with the `vendor` /// role, postage stays (d). The roles decide, so a post office given the diff --git a/crates/ledger-core/tests/spec_document_projects.rs b/crates/ledger-core/tests/spec_document_projects.rs index 0e2089b3..01c823c0 100644 --- a/crates/ledger-core/tests/spec_document_projects.rs +++ b/crates/ledger-core/tests/spec_document_projects.rs @@ -1,12 +1,12 @@ -//! An invoice's or bill's lines name their projects (BS-statement-5 item -//! 8): the posted entry's revenue or expense side is one line per project, +//! An invoice's or bill's lines name their projects (BS-statement-5 statement +//! 6): the posted entry's revenue or expense side is one line per project, //! the untagged lines' as one; the receivable or payable line, and the //! payments, never take one. //! //! ```text //! GOAL: a client project's invoiced revenue and a contractor's billed //! cost count toward the project, every other figure as before. -//! SOURCE: BS-statement-5 items 3 and 8 (job costing), BS-statement-3 (the +//! SOURCE: BS-statement-5 statements 2 and 6 (job costing), BS-statement-3 (the //! projects with the untagged lines partition the P&L), BS-1099-1 and //! BS-partner-3 (1099 and party figures follow the money, not the tags). //! ``` @@ -170,7 +170,7 @@ fn a_bills_cost_is_one_line_per_project_and_the_payable_none() { } /// Reversing a tagged invoice's or bill's entry carries each line's -/// project to the reversal (BS-statement-5 item 3: each line on its normal side), so +/// project to the reversal (BS-statement-5 statement 2: each line on its normal side), so /// every project nets back to zero; a partial payment, cash against the /// receivable, moves no project figure. #[test] @@ -295,7 +295,7 @@ fn a_line_naming_an_unknown_project_is_refused_whole() { } /// Finished and abandoned projects still take a document's lines (BS-statement-5 -/// item 5: a late cost, a final invoice). +/// statement 7: a late cost, a final invoice). #[test] fn a_finished_project_still_takes_an_invoice() { let mut b = books(); diff --git a/crates/ledger-core/tests/spec_documents.rs b/crates/ledger-core/tests/spec_documents.rs index 66d5bf46..cf3e8879 100644 --- a/crates/ledger-core/tests/spec_documents.rs +++ b/crates/ledger-core/tests/spec_documents.rs @@ -110,7 +110,7 @@ impl Books { } /// Every control account's tie-out holds: no difference (BS-arap-2 - /// INVARIANT 1). + /// invariant 1). fn ties(&self, on: NaiveDate) { for c in self.l.control_check(on).unwrap() { assert_eq!(c.difference, Decimal::ZERO, "{c:?}"); @@ -1067,7 +1067,7 @@ fn out_of_bounds_documents_are_listed_not_aged() { /// Reversing a legacy hand line takes it off; reversing that reversal /// would put it back, and is refused: no command adds an untagged control -/// line (BS-arap-2 INVARIANT 1 and item 3; first review of S1). +/// line (BS-arap-2 invariant 2 and statement 11; first review of S1). #[test] fn putting_back_a_removed_hand_line_is_refused() { let mut b = books(); @@ -1204,7 +1204,7 @@ fn a_chain_counts_in_order() { // Write-offs (plan P4b S7; BS-arap-5) // --------------------------------------------------------------------------- -/// BS-arap-2 SCENARIO 7 and BS-arap-5 INVARIANT 1: half of an invoice paid, the rest +/// BS-arap-2 scenario 7 and BS-arap-5 invariant 1: half of an invoice paid, the rest /// written off, reads Written off with 50 paid and 50 written off, and /// receivables falls by the write-off alone. #[test] @@ -1261,7 +1261,7 @@ fn half_paid_rest_written_off_is_written_off() { assert!(check.iter().all(|c| c.difference.is_zero())); } -/// BS-arap-5 INVARIANT 3: a cash-basis company never counted the invoice as +/// BS-arap-5 invariant 5: a cash-basis company never counted the invoice as /// income, so it has no basis to deduct (IRC §166; Treas. Reg. /// §1.166-1(e)). #[test] @@ -1308,7 +1308,7 @@ fn write_off_refused_on_cash_basis() { ); } -/// BS-arap-5 INVARIANT 1: at most what is owed, a partial write-off allowed +/// BS-arap-5 invariant 2 and statement 3: at most what is owed, a partial write-off allowed /// (Treas. Reg. §1.166-3(a)); more is refused, naming what is owed, and /// nothing changes. #[test] @@ -1351,7 +1351,7 @@ fn write_off_above_outstanding_refused() { assert_eq!((st.paid, st.written_off), (cents(4_000), cents(6_000))); } -/// D-49's same-year recovery, and BS-arap-5 INVARIANT 2: reversing the +/// D-49's same-year recovery, and BS-arap-5 invariant 4: reversing the /// write-off re-instates the debt (it is not a new movement), and the /// payment then recorded settles it; a recovery is income, never a /// payment event. @@ -1502,7 +1502,7 @@ fn days(b: &Books) -> Vec { proptest! { #![proptest_config(ProptestConfig::with_cases(256))] - /// BS-arap-2 INVARIANTS 1, 2 and 6 over random histories of creates, + /// BS-arap-2 invariants 1, 6 and 9 over random histories of creates, /// payments, voids, reversals of any entry and refused hand lines: at /// every date the control accounts equal their documents (no /// difference, nothing unattached: no command adds a hand line), each @@ -1538,9 +1538,9 @@ proptest! { } } - /// BS-arap-2 INVARIANT 5: the aging as of a day partitions what the + /// BS-arap-2 invariant 8: the aging as of a day partitions what the /// documents owe then (in books these commands write, none owes less - /// than nothing). INVARIANT 4 (Store, replay and Snapshot agree) is + /// than nothing). Invariant 7 (Store, replay and Snapshot agree) is /// ledger-store's `status_is_a_function_of_journal_and_date`. #[test] fn aging_partitions_what_documents_owe(ops in prop::collection::vec(arb_op(), 0..30)) { @@ -1562,7 +1562,7 @@ proptest! { } } - /// BS-arap-2 INVARIANT 3: reversing a tagged entry moves its documents by + /// BS-arap-2 invariant 4: reversing a tagged entry moves its documents by /// exactly the opposite of the entry's own tagged lines from the /// reversal's day (read from the entry reversed, not from the mirror, /// so a mirror that lost its tag is caught); reversing that reversal @@ -1725,7 +1725,7 @@ fn terms_derive_due_dates() { assert!(Terms::new(TermsKind::NetEom(3_651), None).is_err()); } -/// BS-arap-3 INVARIANT 2: the discount's bound, its date, and the terms that +/// BS-arap-3 invariant 2: the discount's bound, its date, and the terms that /// cannot carry one. #[test] fn discount_bounds_and_late_reason() { @@ -1795,7 +1795,7 @@ fn discount_bounds_and_late_reason() { assert_eq!(kernel::discount_max(cents(-1), 200), None); } -/// BS-arap-3 INVARIANT 3: the canonical spellings read back as they print. +/// BS-arap-3 invariant 3: the canonical spellings read back as they print. #[test] fn terms_describe_and_parse_round_trip() { for text in [ @@ -2286,7 +2286,7 @@ fn bill_on_terms_with_discount() { } /// A discount taken after the discount date needs a reason (BS-arap-6 -/// INVARIANT 2); a bill with an asset or prepaid line refuses one with the +/// invariant 6); a bill with an asset or prepaid line refuses one with the /// D-49 remedy, and none of the refusals changes the books. #[test] fn late_discount_needs_a_reason() { @@ -2433,7 +2433,7 @@ fn a_fee_posts_gross_to_receivables_and_net_to_the_bank() { /// A payment that settles more than one document names its lines in /// application order, and two applications on one document are refused: -/// each document's bound is one bound (BS-arap-6 INVARIANTS 1 and 2). +/// each document's bound is one bound (BS-arap-6 invariants 4 and 5). #[test] fn a_settlement_names_its_lines_and_refuses_a_document_twice() { use ledger_core::{Application, DocRef, SettleParams}; diff --git a/crates/ledger-core/tests/spec_parties.rs b/crates/ledger-core/tests/spec_parties.rs index 3d0897de..4f0cb729 100644 --- a/crates/ledger-core/tests/spec_parties.rs +++ b/crates/ledger-core/tests/spec_parties.rs @@ -1919,7 +1919,7 @@ mod shares { assert_eq!((a.paid, a.received), (Decimal::ZERO, Decimal::ZERO)); } - /// BS-partner-3 item 3 (capital first): a members' entry counts what + /// BS-partner-3 statement 3 (capital first): a members' entry counts what /// moved their capital, not other money on it: 300.00 in, 200.00 of it /// Tobin's capital and 100.00 an expense refunded, is Tobin's 200.00 /// received (cash) and nothing of Morgan's. (Before P3 the 300.00 net diff --git a/crates/ledger-core/tests/spec_party_totals.rs b/crates/ledger-core/tests/spec_party_totals.rs index a90cd3f0..bd7bf69a 100644 --- a/crates/ledger-core/tests/spec_party_totals.rs +++ b/crates/ledger-core/tests/spec_party_totals.rs @@ -550,7 +550,7 @@ fn defect14_shares_take_the_partys_side_and_reversals_flip() { ); } -/// BS-partner-3 item 4: on the member-only entries, basis all is the statement of +/// BS-partner-3 statement 6: on the member-only entries, basis all is the statement of /// members' equity (contributions and distributions, the same dates), and /// basis cash is the K-1 worksheet's cash contributions. #[test] @@ -655,7 +655,7 @@ fn defect24_an_accrual_through_another_liability_counts_once() { assert_eq!(b.totals(c, Basis::All), (Decimal::ZERO, d("1200.00"))); } -/// Defect 24 and BS-partner-3 item 6: a credit to what the company owes a party +/// Defect 24 and BS-partner-3 statement 8: a credit to what the company owes a party /// itself never counts as paying it. A fee on the issuer's own card is a /// bill from the issuer (counted when the card is paid); a distribution /// still owed to a member counts when it is paid; equipment bought on the @@ -778,7 +778,7 @@ fn a_distribution_owed_counts_twice_until_the_members_are_named_its_creditors() /// again when paid (400.00); now it counts nothing until it is paid, then /// 200.00, once, on both bases (Helvering v. Price; party_target /// INVARIANT 2). The statement of members' equity counts it when declared: -/// party totals catch up when it is paid (BS-partner-3 item 4's conditions). +/// party totals catch up when it is paid (BS-partner-3 statement 6's conditions). #[test] fn defect24_a_distribution_declared_to_a_payable_counts_once_when_paid() { let mut b = books(); @@ -829,7 +829,7 @@ fn defect24_a_distribution_declared_to_a_payable_counts_once_when_paid() { assert_eq!(b.totals(t, Basis::Cash), (d("300.00"), Decimal::ZERO)); } -/// BS-partner-3 item 3: a distribution's cash is the money it paid and its in +/// BS-partner-3 statement 3: a distribution's cash is the money it paid and its in /// kind the property it gave. Equipment carried at 1,000.00 less 300.00 /// depreciated, and 100.00 in cash, distributed: 100.00 cash and 700.00 /// in kind (it read 800.00 in kind and no cash, the equipment's cost @@ -868,7 +868,7 @@ fn a_distribution_of_money_and_depreciated_property_splits_by_what_moved() { assert_eq!(b.resolved(gain).1, vec![part(t, "900.00", "0", "900.00")]); } -/// Defect 24 and the card rule (BS-partner-3 item 5): a gift card the company +/// Defect 24 and the card rule (BS-partner-3 statement 7): a gift card the company /// sold is deferred revenue, a promise, though its account's name says /// "card". It counted as received when sold and again when redeemed /// (200.00); now once, when the money came in. A card the company pays @@ -892,7 +892,7 @@ fn defect24_a_gift_card_sold_is_received_once() { assert_eq!(b.totals(c, Basis::All), (Decimal::ZERO, d("100.00"))); } -/// BS-partner-3 item 5 and `parties::card_accounts` INVARIANTS 1-4: one rule for +/// BS-partner-3 statement 7 and `parties::card_accounts` INVARIANTS 1-4: one rule for /// what a card is. Before any business card is recorded, the liabilities /// whose names say "card" but not "gift" (2050 Business Card; never 2410 /// Gift Card Liability), less a member's card's account; once one is @@ -958,7 +958,7 @@ fn a_card_is_a_recorded_business_card_else_a_liability_named_card() { assert_eq!(b.resolved(on_2050).0.direction, Direction::Neither); } -/// BS-partner-3 item 3, case 3: E is the movement of equity other than retained +/// BS-partner-3 statement 3, case 3: E is the movement of equity other than retained /// earnings, so a members' entry reads as the statement of members' equity /// reads it. Retained earnings given up for equipment moves no member's /// capital: neither, as the statement shows no distribution. Retained @@ -1035,7 +1035,7 @@ fn a_refund_is_received_from_the_vendor() { assert_eq!(b.totals(v, Basis::Cash), (d("100.00"), d("20.00"))); } -/// BS-partner-3 item 3 (capital first): a mixed contribution is split into money +/// BS-partner-3 statement 3 (capital first): a mixed contribution is split into money /// and property exactly as the K-1 worksheet splits it (its SCENARIO 3), /// whichever member the shares list first; an expense a member pays /// straight to capital is cash, as on the K-1 (k1 INVARIANT 3); a debt @@ -1168,7 +1168,7 @@ fn a_members_entry_keeps_its_reading_after_they_leave() { ); } -/// BS-partner-3 item 3, case 1: a period's closing entry moves nothing with +/// BS-partner-3 statement 3, case 1: a period's closing entry moves nothing with /// anyone: direction neither, its members' part their income allocated /// (credited to their capital: negative), counted in no total. #[test] @@ -1661,7 +1661,7 @@ proptest! { /// account converted to capital, some through their distributions /// accounts, some declared to distributions payable and paid later, /// and reverse some of it later in the year. For each member, over - /// every span from the year's start to any date (BS-partner-3 item 4's + /// every span from the year's start to any date (BS-partner-3 statement 6's /// conditions hold: a reversal in such a span always has its original /// in it): basis all is the statement of members' equity's /// contributions and distributions, but for a distribution declared diff --git a/crates/ledger-core/tests/spec_projects.rs b/crates/ledger-core/tests/spec_projects.rs index ff902ac9..d50ecc45 100644 --- a/crates/ledger-core/tests/spec_projects.rs +++ b/crates/ledger-core/tests/spec_projects.rs @@ -534,7 +534,7 @@ fn a_reversal_nets_a_project_to_zero() { let entries = project_entries(&b.l, c); assert_eq!(entries, vec![(r, cents(180_000)), (e, cents(-180_000))]); // Nothing left on an account, but two lines tagged: it breaks even, - // it isn't untagged (BS-statement-5 item 7). + // it isn't untagged (WB-statement-7). assert!(t.expenses_by_account.is_empty()); assert_eq!((t.revenue_lines, t.expenses_lines), (0, 2)); assert!(t.any_tagged()); @@ -652,7 +652,7 @@ fn differs_from_names_projects() { assert_eq!(a.l.differs_from(&before), vec!["projects"]); } -/// BS-statement-5 item 7: the margin is the contribution's share of +/// WB-statement-7: the margin is the contribution's share of /// revenue, one place, half to even, and none without revenue. #[test] fn contribution_margin_is_one_place_and_none_without_revenue() { @@ -671,7 +671,7 @@ fn contribution_margin_is_one_place_and_none_without_revenue() { assert_eq!(pct(Decimal::MAX, cents(1)), None, "never panics"); } -/// BS-statement-5 item 7: each month's net to date opens on the lines +/// WB-statement-7: each month's net to date opens on the lines /// before the months (a deposit last year) and ends on the net to date; /// a reimbursement credited above its cost leaves the expense below zero. #[test] diff --git a/crates/ledger-core/tests/spec_reports.rs b/crates/ledger-core/tests/spec_reports.rs index 6d737ec0..be8adb6e 100644 --- a/crates/ledger-core/tests/spec_reports.rs +++ b/crates/ledger-core/tests/spec_reports.rs @@ -2505,9 +2505,9 @@ proptest! { /// the cash part of the equity and designated-debt movements: each /// entry's cash applied to the sections moving against it, operating, /// investing, financing, each up to its own movement (BS-statement-3 - /// rule 3), then to the kinds within each section in their order; + /// statement 4), then to the kinds within each section in their order; /// plus what the loan or a member's capital paid or received for the - /// company (rule 11, D-42): the loan pays for operating lines (the + /// company (statement 16, D-42): the loan pays for operating lines (the /// balance-sheet ones first) and receives for revenue and expense; /// capital pays and receives for revenue and expense only. Written /// here apart from the kernel. diff --git a/crates/ledger-core/tests/statements.rs b/crates/ledger-core/tests/statements.rs index 2e61b748..9bec545b 100644 --- a/crates/ledger-core/tests/statements.rs +++ b/crates/ledger-core/tests/statements.rs @@ -1444,7 +1444,7 @@ fn lines(ls: &[ledger_core::reports::CashFlowLine]) -> Vec<(String, Decimal)> { /// amounts borrowed"): borrowing and repayment are separate lines, one /// per entry, borrowing first (each lender's, by code), then repayments. /// The software the owner paid personally is borrowed from the owner and -/// spent on its date (BS-statement-3 rule 11, D-42: constructive receipt +/// spent on its date (BS-statement-3 statement 16, D-42: constructive receipt /// and disbursement). Financing: +100 + 1,000 − 100 − 400 = 600; nothing /// is disclosed. #[test] @@ -1487,7 +1487,7 @@ fn a_loan_the_entity_makes_is_investing_gross() { assert_eq!(cf.cash_from_investing, dec(-300)); } -/// Oracle: D-42 (BS-statement-3 rule 11; ASC 230 is silent on a payment +/// Oracle: D-42 (BS-statement-3 statement 16; ASC 230 is silent on a payment /// made on the entity's behalf, PwC FSP 6.9.3.1 and DART Roadmap 7.2 /// present it as constructive receipt and disbursement). The owner paying /// software personally is cash the company borrowed (financing +100) and diff --git a/crates/ledger-gui/src/attention.rs b/crates/ledger-gui/src/attention.rs index 662fdb53..ea0b1741 100644 --- a/crates/ledger-gui/src/attention.rs +++ b/crates/ledger-gui/src/attention.rs @@ -151,7 +151,7 @@ mod tests { .unwrap() } - /// INVARIANT 2's cash flow items (BS-statement-3 rule 12, D-35): a + /// INVARIANT 2's cash flow items (BS-statement-3 statement 17, D-35): a /// sale of equipment for an IOU is a Todo naming the entry, with the /// statement's fix; equipment bought on an operating card is Info; a /// sale for cash asks nothing. diff --git a/crates/ledger-gui/src/demo.rs b/crates/ledger-gui/src/demo.rs index e669aa31..72b0579b 100644 --- a/crates/ledger-gui/src/demo.rs +++ b/crates/ledger-gui/src/demo.rs @@ -247,7 +247,7 @@ pub fn build(dir: &Path, today: NaiveDate) -> Result<(), StoreError> { "Client work", &ledger_core::ProjectFacts { // Its invoices' lines and the contractors it pays are tagged - // to it (BS-statement-5 item 8), so its snapshot is its + // to it (BS-statement-5 statement 6), so its snapshot is its // revenue less its direct costs. description: Some( "Design work for the studio's clients: every client invoice, and the contractors who work on it." @@ -306,7 +306,7 @@ pub fn build(dir: &Path, today: NaiveDate) -> Result<(), StoreError> { .map(|n| s.add_customer(n)) .collect::>()?; // Work on spec for a customer, hoping they adopt it: its costs are - // expenses, and nothing is receivable (BS-statement-5 item 4). + // expenses, and nothing is receivable (BS-statement-5 statement 5). let tidepool_started = start + Months::new(13); let tidepool = s.add_project( "Tidepool app", diff --git a/crates/ledger-gui/src/pages/entry.rs b/crates/ledger-gui/src/pages/entry.rs index 08c7c29c..3da52ffd 100644 --- a/crates/ledger-gui/src/pages/entry.rs +++ b/crates/ledger-gui/src/pages/entry.rs @@ -302,7 +302,7 @@ pub fn detail(ui: &mut Ui, b: &Books, e: &EntryInfo, shell: &mut Shell<'_>) { ui.add_space(18.0); // The invoice or bill it records: its lines as the document - // gives them, each project a link (BS-statement-5 item 8). + // gives them, each project a link (BS-statement-5 statement 6). if let Some(doc) = document_of(b, e.id) { section(ui, &doc.title); document_lines(ui, &doc, &class_names, total_w, amt_w, shell); @@ -756,7 +756,7 @@ mod tests { /// A tagged line keeps its project tag inside its cell, in a narrow /// pane too: the name is cut to leave the tag room, so the amounts /// stay in their columns (an invoice's revenue line and its document - /// line, each tagged; BS-statement-5 item 8). + /// line, each tagged; BS-statement-5 statement 6). #[test] fn a_tagged_line_keeps_its_amounts_in_their_column() { use ledger_core::arap::DocumentLine; diff --git a/crates/ledger-gui/src/pages/parties.rs b/crates/ledger-gui/src/pages/parties.rs index 79061150..d1612a68 100644 --- a/crates/ledger-gui/src/pages/parties.rs +++ b/crates/ledger-gui/src/pages/parties.rs @@ -561,7 +561,7 @@ pub fn show_list(ui: &mut Ui, b: &Books, shell: &mut Shell<'_>) { } /// The party's totals with property in kind (basis all, BS-partner-3 -/// item 4), when it gave or took any in the period: "With property +/// statement 5), when it gave or took any in the period: "With property /// contributed or distributed: paid $X, received $Y". None when nothing /// moved in kind (the cash totals are then the whole story). pub fn in_kind_text(flow: &crate::books::PartyFlow) -> Option { @@ -775,7 +775,7 @@ pub fn show_party(ui: &mut Ui, b: &Books, id: PartyId, shell: &mut Shell<'_>) { r.context_menu(|ui| widgets::copy_item(ui, "Copy amount", &v.to_string())); } }); - // Basis all (BS-partner-3 item 4): property in kind, when any. + // Basis all (BS-partner-3 statement 5): property in kind, when any. if let Some(text) = in_kind_text(&flow) { ui.add_space(6.0); ui.add( diff --git a/crates/ledger-gui/src/pages/projects.rs b/crates/ledger-gui/src/pages/projects.rs index bfedd8cb..81de2de5 100644 --- a/crates/ledger-gui/src/pages/projects.rs +++ b/crates/ledger-gui/src/pages/projects.rs @@ -1,7 +1,7 @@ //! Projects: every class, with its facts (what it is, where it stands, who //! it is for), and one project completely: its snapshot (revenue, direct //! costs, contribution before overhead and its margin, to date or this -//! fiscal year, BS-statement-5 item 7), revenue and costs by month with the +//! fiscal year, WB-statement-7), revenue and costs by month with the //! running net, costs by category and by account, its entries, documents, //! decisions and history (BS-statement-5). Every figure is ledger-core's (`project_figures`, //! `project_to_date`, `project_entries`), the same the server's @@ -419,7 +419,7 @@ impl Snap { } /// The note on contribution: what it counts and what it leaves out. -pub const CONTRIBUTION_NOTE: &str = "Revenue less this project's direct costs: every expense line tagged to it, fixed and variable alike (what management accounting calls a segment margin, not a variable-cost contribution margin). Company overhead that isn't tagged to a project (rent, software, insurance, the owner's time) isn't counted, so a project in the black can still leave the company in the red. A management-accounting view (BS-statement-5 items 2 and 4), not a GAAP figure."; +pub const CONTRIBUTION_NOTE: &str = "Revenue less this project's direct costs: every expense line tagged to it, fixed and variable alike (what management accounting calls a segment margin, not a variable-cost contribution margin). Company overhead that isn't tagged to a project (rent, software, insurance, the owner's time) isn't counted, so a project in the black can still leave the company in the red. A management-accounting view (WB-statement-7), not a GAAP figure."; /// The snapshot: a header with where it stands to date and the to date / /// fiscal year switch, then its tiles (`shown`: to date, or for `year`, diff --git a/crates/ledger-gui/src/pages/reports.rs b/crates/ledger-gui/src/pages/reports.rs index 34fe33ba..2cee3259 100644 --- a/crates/ledger-gui/src/pages/reports.rs +++ b/crates/ledger-gui/src/pages/reports.rs @@ -2719,7 +2719,7 @@ mod tests { // The figures, by hand: the loan (not a financing setting) is an // operating receipt, 2,500.00; what the members paid personally // (85.00 and 216.40, 301.40) is borrowed from them through 2100 - // and spent (D-42, BS-statement-3 rule 11); the members' + // and spent (D-42, BS-statement-3 statement 16); the members' // contributions are financing, each named (1,200.00 and 800.00); // the reimbursement repays 2100 (301.40); the tablet is disclosed // (630.00), the reversed laptop gone. diff --git a/crates/ledger-gui/tests/parties.rs b/crates/ledger-gui/tests/parties.rs index b4645385..38f8c8fa 100644 --- a/crates/ledger-gui/tests/parties.rs +++ b/crates/ledger-gui/tests/parties.rs @@ -282,7 +282,7 @@ fn fixture(tag: &str) -> Fixture { let e = pay(&mut s, d(2026, 1, 20), "Old Co", cash, 12_300); s.set_entry_party(e, Some(old)).unwrap(); s.update_party(old, PartyField::Archived(true)).unwrap(); - // What the members advanced is money (BS-partner-3 item 5): Due to + // What the members advanced is money (BS-partner-3 statement 7): Due to // Shareholders is a financing account; the cash account stays the // books' (the settings file names both). journal_settings( @@ -356,7 +356,7 @@ fn each_partys_totals_are_the_books_numbers() { // (BS-1099-1); the card's charge is no payment out of cash. assert_eq!(line.paid, cents(150_000)); assert_eq!(line.undetermined, cents(30_000)); - // Party totals count all of it as paid to Sam (BS-partner-3 item 9): the + // Party totals count all of it as paid to Sam (BS-partner-3 statement 11): the // 1099's buckets, and the card's 200 (no business card is recorded, // so the worksheet lists it nowhere). assert_eq!( @@ -1490,7 +1490,7 @@ fn the_party_page_shows_the_basis_and_in_kind() { } /// The viewer's what-for reads a reversal as parties::flow does, the -/// opposite of its original (BS-partner-3 item 3; design §1.4): a member +/// opposite of its original (BS-partner-3 statement 3; design §1.4): a member /// paying the card from their own funds (Dr card / Cr 2100), tagged with /// the issuer, then reversed, is nothing on the issuer's page, paid or /// what for. Its lines alone read as a second payment. diff --git a/crates/ledger-gui/tests/projects.rs b/crates/ledger-gui/tests/projects.rs index faf13ee0..70cb3829 100644 --- a/crates/ledger-gui/tests/projects.rs +++ b/crates/ledger-gui/tests/projects.rs @@ -603,7 +603,7 @@ fn a_long_party_name_keeps_to_its_card() { } } -// ------------------------------------------------- the snapshot (BS-statement-5 item 7) +// ------------------------------------------------- the snapshot (WB-statement-7) /// Books holding one project of `kind`, started `started_on`, with /// `posts`: (date, debit code, credit code, cents), the line that isn't @@ -1253,7 +1253,7 @@ proptest::proptest! { } } -/// BS-statement-5 item 8: an invoice's or bill's page (its entry's) lists +/// BS-statement-5 statement 6: an invoice's or bill's page (its entry's) lists /// the document's lines, each project a link that opens it; an untagged /// line has none. The entry's own lines show the tagged revenue or cost /// line too. @@ -1373,7 +1373,7 @@ fn an_invoice_and_a_bill_show_each_lines_project() { } /// The demo's "Client work" project carries every client invoice ( -/// BS-statement-5 item 8): its revenue to date is the invoices' total, its direct +/// BS-statement-5 statement 6): its revenue to date is the invoices' total, its direct /// costs the contractors tagged to it. #[test] fn the_demos_client_work_counts_every_client_invoice() { diff --git a/crates/ledger-import/tests/spec_import.rs b/crates/ledger-import/tests/spec_import.rs index 1722141f..6786381a 100644 --- a/crates/ledger-import/tests/spec_import.rs +++ b/crates/ledger-import/tests/spec_import.rs @@ -1813,7 +1813,7 @@ fn iif_refuses_an_undeclared_account() { ); } -/// iif INVARIANT 8 (BS-format-2 item 7): an entry with a line on one +/// iif INVARIANT 8 (BS-format-2 statement 26): an entry with a line on one /// accounts receivable account still writes one transaction, and the entry /// is named to the human so they can add QuickBooks' customer or vendor. #[test] @@ -1855,7 +1855,7 @@ fn iif_writes_an_entry_on_one_receivable_or_payable_account() { assert_eq!(iif.receivable_payable, [e]); } -/// iif INVARIANT 8 (BS-format-2 item 7): an entry with lines on both the +/// iif INVARIANT 8 (BS-format-2 statement 7): an entry with lines on both the /// receivables and payables control accounts is refused, naming its id: /// QuickBooks Desktop records at most one A/R or A/P account a /// transaction, and splitting the entry would change what it says. @@ -1912,7 +1912,7 @@ fn iif_refuses_an_entry_on_two_receivable_or_payable_accounts() { ); } -/// iif INVARIANT 8 (BS-format-2 item 7): two distinct receivable accounts +/// iif INVARIANT 8 (BS-format-2 statement 7): two distinct receivable accounts /// in one entry are refused too (its `qb_type` decides, whatever the /// callers call them), and every offending entry is named. #[test] @@ -5077,7 +5077,7 @@ fn iif_writes_each_lines_class_and_declares_the_classes_first() { } /// iif INVARIANT 9: a class's NAME is written as an account's own level -/// is (BS-format-2 rules 3, 4): plain ASCII, a colon a '-' (a colon starts a +/// is (BS-format-2 statements 10 and 18): plain ASCII, a colon a '-' (a colon starts a /// subclass, the `!CLASS` header help), trimmed, at most NAME_MAX; names /// alike ignoring case once written get " (id)", round after round, as /// accounts get their codes; and each name written differently is a diff --git a/crates/ledger-mcp/src/handbook.rs b/crates/ledger-mcp/src/handbook.rs index c26b5217..dd771edf 100644 --- a/crates/ledger-mcp/src/handbook.rs +++ b/crates/ledger-mcp/src/handbook.rs @@ -31,7 +31,7 @@ //! 6. A section says an invoice's or bill's lines take a project only //! for books that declared the journal feature //! `document_line_projects`; for the rest, that they wait for their -//! format upgrade (BS-format-1, BS-statement-5 item 8). +//! format upgrade (BS-format-1, BS-statement-5 statement 6). //! ``` use crate::settings::Settings; @@ -186,8 +186,8 @@ pub fn period_rule() -> String { ) } -/// How an invoice's or bill's lines reach a project (BS-statement-5 item -/// 8), for books that declared the journal feature +/// How an invoice's or bill's lines reach a project (BS-statement-5 statement +/// 6), for books that declared the journal feature /// `document_line_projects` or not yet (INVARIANT 6). pub fn document_projects_rule(declared: bool) -> &'static str { if declared { @@ -591,7 +591,7 @@ mod tests { with.contains("books.create_invoice and books.create_bill take class on each line") ); assert!(!with.contains("takes no project")); - // The owner's decision (BS-statement-5 item 8, D-43): one project or none a + // The owner's decision (BS-statement-5 statement 4, D-43): one project or none a // line, no percentage split, a shared cost by the allocation // convention. assert!(with.contains("Each line names one project or none")); diff --git a/crates/ledger-mcp/src/tools/documents.rs b/crates/ledger-mcp/src/tools/documents.rs index f5320020..d6c61f54 100644 --- a/crates/ledger-mcp/src/tools/documents.rs +++ b/crates/ledger-mcp/src/tools/documents.rs @@ -78,7 +78,7 @@ fn document_lines( /// A document's notes, each project once, in the order first named: its /// late-tag note ([`projects::late_tag_note`]) for a finished or abandoned /// project, and on an invoice ([`projects::on_spec_invoice_note`]) one for -/// an on-spec project (BS-statement-5 items 4, 5 and 8). +/// an on-spec project (BS-statement-5 statements 5, 6 and 7). fn document_notes( ledger: &ledger_core::Ledger, lines: &[DocumentLine], diff --git a/crates/ledger-mcp/src/tools/helpers.rs b/crates/ledger-mcp/src/tools/helpers.rs index bbcd608d..373314a2 100644 --- a/crates/ledger-mcp/src/tools/helpers.rs +++ b/crates/ledger-mcp/src/tools/helpers.rs @@ -141,7 +141,7 @@ pub(crate) fn settings_problems(ledger: &Ledger, cfg: &Settings) -> Vec let how = " with books.set_setting"; // The cash flow roles: codes the chart lacks here; the rest is the // engine's own check, the one the statement refuses on (BS-statement-3 - // rule 2), so the two never disagree. + // statement 3), so the two never disagree. let lists = [ ( ledger_core::RoleList::Cash, diff --git a/crates/ledger-mcp/src/tools/parties.rs b/crates/ledger-mcp/src/tools/parties.rs index 7f5d07e8..711083a6 100644 --- a/crates/ledger-mcp/src/tools/parties.rs +++ b/crates/ledger-mcp/src/tools/parties.rs @@ -144,7 +144,7 @@ fn party_document( } /// A party-totals `basis` from a tool: "cash" (the default) or "all" -/// (BS-partner-3 item 4); any other word is refused. +/// (BS-partner-3 statement 5); any other word is refused. fn parse_basis(basis: Option<&str>) -> Result { match basis { None => Ok(ledger_core::parties::Basis::default()), diff --git a/crates/ledger-mcp/src/tools/projects.rs b/crates/ledger-mcp/src/tools/projects.rs index b33fe568..637d634a 100644 --- a/crates/ledger-mcp/src/tools/projects.rs +++ b/crates/ledger-mcp/src/tools/projects.rs @@ -144,7 +144,7 @@ fn by_name(ledger: &Ledger) -> Vec { } /// The note `books.add_line` and `books.record_payout` give for a line tagged to a finished or -/// abandoned project (BS-statement-5 item 5). +/// abandoned project (BS-statement-5 statement 7). pub(super) fn late_tag_note(ledger: &Ledger, id: ClassId) -> Option { let f = ledger.project_facts(id)?; if !f.status.is_over() { @@ -162,7 +162,7 @@ pub(super) fn late_tag_note(ledger: &Ledger, id: ClassId) -> Option { } /// The note `books.create_invoice` gives for a line naming an on-spec -/// project (BS-statement-5 items 4 and 8): on spec, a hoped-for payment is +/// project (BS-statement-5 statements 5 and 6): on spec, a hoped-for payment is /// no receivable and no income until received, so an invoice for one /// means there is now an agreement, or it shouldn't be an invoice. pub(super) fn on_spec_invoice_note(ledger: &Ledger, id: ClassId) -> Option { diff --git a/crates/ledger-mcp/src/tools/reports.rs b/crates/ledger-mcp/src/tools/reports.rs index 1062aad9..30ccf3f4 100644 --- a/crates/ledger-mcp/src/tools/reports.rs +++ b/crates/ledger-mcp/src/tools/reports.rs @@ -729,7 +729,7 @@ impl BooksServer { checked.push(format!("{n} stored files match their SHA-256")); } // Receivables and payables equal their documents (BS-arap-2 - // INVARIANT 1): an identity, so a difference is an engine error. + // invariant 1): an identity, so a difference is an engine error. let checks = store .ledger() .control_check(chrono::NaiveDate::MAX) diff --git a/crates/ledger-mcp/src/tools/write_offs.rs b/crates/ledger-mcp/src/tools/write_offs.rs index 3e566035..eff299b5 100644 --- a/crates/ledger-mcp/src/tools/write_offs.rs +++ b/crates/ledger-mcp/src/tools/write_offs.rs @@ -65,7 +65,7 @@ impl BooksServer { Some(a) => parse_amount(a)?, None => owed, }; - // The evidence is the point of a write-off (BS-arap-5 INVARIANT 1): one + // The evidence is the point of a write-off (BS-arap-5 statement 9): one // of the two, and the preview says so too rather than posting // without it later. match (p.upload_id.is_some(), p.existing_attachment_id.is_some()) { diff --git a/crates/ledger-mcp/src/types.rs b/crates/ledger-mcp/src/types.rs index 1f7862f2..867199bc 100644 --- a/crates/ledger-mcp/src/types.rs +++ b/crates/ledger-mcp/src/types.rs @@ -3764,7 +3764,7 @@ pub struct AgingDocumentOut { } /// The aging's account against its documents (the control check, BS-ledger-8, -/// BS-arap-2 INVARIANT 1). +/// BS-arap-2 invariant 1). #[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] pub struct AgingControlOut { /// "1200 Accounts Receivable" or "2000 Accounts Payable". diff --git a/crates/ledger-package/src/attention.rs b/crates/ledger-package/src/attention.rs index caa75a04..055b4670 100644 --- a/crates/ledger-package/src/attention.rs +++ b/crates/ledger-package/src/attention.rs @@ -71,7 +71,7 @@ //! amortization: no counterparty by nature) (one item: Info under //! suggest, Todo under require; its prompt names //! books.set_entry_party); each warning of the fiscal year's -//! statement of cash flows (BS-statement-3 rule 12: equipment sold for +//! statement of cash flows (BS-statement-3 statement 17: equipment sold for //! an IOU, Todo; bought on an operating payable, Info; one per //! entry, its detail the warning's fix); a filed PDF whose text //! extraction failed (Todo, one per file: a human must read its @@ -1342,7 +1342,7 @@ pub fn find_with( } // The statement of cash flows' warnings this fiscal year ( - // BS-statement-3 rule 12, D-35): equipment sold for an IOU, flagged with its fix + // BS-statement-3 statement 17, D-35): equipment sold for an IOU, flagged with its fix // (Todo); equipment bought on an operating payable, following how the // payable is classified (Info). A statement the settings can't give // (no cash accounts yet) has none. diff --git a/crates/ledger-package/src/iif.rs b/crates/ledger-package/src/iif.rs index 561913c2..82797604 100644 --- a/crates/ledger-package/src/iif.rs +++ b/crates/ledger-package/src/iif.rs @@ -19,7 +19,7 @@ //! imported close would zero its period's profit. The file's //! balances are the trial balance as of as_of without the closes. //! 3. Every class (project) in the books is declared, and each line -//! carries its class (BS-format-2 rule 8). +//! carries its class (BS-format-2 statements 27 and 28). //! ``` use chrono::NaiveDate; diff --git a/crates/ledger-package/src/reports.rs b/crates/ledger-package/src/reports.rs index 509e38e6..e2fd8c5e 100644 --- a/crates/ledger-package/src/reports.rs +++ b/crates/ledger-package/src/reports.rs @@ -16,7 +16,7 @@ //! 2. The cash flow statement needs at least one cash account, and //! every code it is given must be in the chart; account lists a call //! leaves empty default to the settings' roles. It foots, or it is -//! refused (an engine error, never a figure: BS-statement-3 rule 9); +//! refused (an engine error, never a figure: BS-statement-3 statement 14); //! roles that contradict each other or the chart are refused by the //! engine, naming the setting, so the viewer and the server refuse //! alike. Members are named on their contributions and diff --git a/crates/ledger-package/tests/p3_seams.rs b/crates/ledger-package/tests/p3_seams.rs index 8a68815b..02e35421 100644 --- a/crates/ledger-package/tests/p3_seams.rs +++ b/crates/ledger-package/tests/p3_seams.rs @@ -127,8 +127,8 @@ fn pnl_depreciation(l: &Ledger, end: NaiveDate) -> Decimal { pnl_expense(l, "6500", end) } -/// The members' figures agree on every date as BS-partner-1, BS-partner-3 items 4 and 8 -/// and BS-statement-3 rule 11 say: the statement of members' equity and the K-1 +/// The members' figures agree on every date as BS-partner-1, BS-partner-3 statements 6 and 10 +/// and BS-statement-3 statement 16 say: the statement of members' equity and the K-1 /// worksheet are one roll-forward; party totals on basis all are the /// statement's contributions, on basis cash the K-1's cash /// contributions; the cash flow statement's contributions are the K-1's @@ -178,7 +178,7 @@ fn the_members_figures_agree_on_every_date() { m.contributions, k.contributions_cash + k.contributions_property ); - // Party totals (BS-partner-3 item 4). + // Party totals (BS-partner-3 statement 6). let a = activity(&b, party, end); assert!(a.unresolved.is_empty(), "{name} {end}: {:?}", a.unresolved); assert_eq!(a.totals(Basis::All).1, m.contributions, "{name} {end}"); @@ -188,7 +188,7 @@ fn the_members_figures_agree_on_every_date() { "{name} {end}" ); assert_eq!(a.received_in_kind, k.contributions_property, "{name} {end}"); - // The cash flow (BS-statement-3 rule 11, BS-partner-3 item 8). + // The cash flow (BS-statement-3 statement 16, BS-partner-3 statement 10). assert_eq!( kind( &cf, @@ -208,7 +208,7 @@ fn the_members_figures_agree_on_every_date() { // A distribution declared to Distributions Payable is a // distribution on the statement of members' equity when declared // and on the cash flow statement and in party totals when paid - // (BS-statement-3 rule 2, BS-partner-3 item 4). + // (BS-statement-3 statement 3, BS-partner-3 statement 6). distributions_paid -= kind( &cf, CashFlowSection::Financing, @@ -281,7 +281,7 @@ fn the_members_figures_agree_on_every_date() { dec("2400.00") ); // Mid-year, the declaration is unpaid: the statement counts it, party - // totals and the cash flow don't yet (BS-partner-3 item 4's second condition). + // totals and the cash flow don't yet (BS-partner-3 statement 6's second condition). let mid = d("2026-06-30"); assert_eq!( activity(&b, b.ana, mid).totals(Basis::Cash).0, @@ -296,7 +296,7 @@ fn the_members_figures_agree_on_every_date() { ); } -/// BS-statement-3 rule 2, from the seam review: a distribution declared to a +/// BS-statement-3 statement 3, from the seam review: a distribution declared to a /// liability and paid later is a financing outflow when paid (ASC /// 230-10-45-15(a)), its declaration a noncash financing activity; before /// the fix it was "Cash paid to suppliers and employees". @@ -349,7 +349,7 @@ fn a_distribution_declared_then_paid_is_financing_when_paid() { ); } -/// BS-partner-3 item 9 and BS-1099-1: for a payee every entry of which names it alone, +/// BS-partner-3 statement 11 and BS-1099-1: for a payee every entry of which names it alone, /// party totals' paid less received (basis cash) is the 1099 worksheet's /// paid + excluded card + undetermined + not reportable, less what the /// worksheet lists as received for something else; and the worksheet @@ -445,7 +445,7 @@ fn iif_dates(iif: &str) -> Vec { .collect() } -/// Depreciation is one figure everywhere (BS-asset-1 rule 8, BS-statement-3 rule 8, +/// Depreciation is one figure everywhere (BS-asset-1 statement 28, BS-statement-3 statement 13, /// BS-partner-4): the P&L's expense, the cash flow reconciliation's add-back, the /// tax-basis K-1's open item, the IIF's, and the runs plus what the /// disposal posted; the balance sheet's accumulated depreciation is the diff --git a/crates/ledger-package/tests/package.rs b/crates/ledger-package/tests/package.rs index 9323462c..3c2423b6 100644 --- a/crates/ledger-package/tests/package.rs +++ b/crates/ledger-package/tests/package.rs @@ -1717,7 +1717,7 @@ fn one_list_of_cash_accounts_per_package() { assert_eq!(text(&plain, "1099-worksheet-2026.csv"), tool(&cash)); } -/// BS-format-2 rule 8 (P3 cutover review, open point 1): the +/// BS-format-2 statements 27-30 (P3 cutover review, open point 1): the /// package's QuickBooks file declares every project as a class and /// carries each line's project in CLASS; a project name written /// differently is listed in the warnings and the README, whose IIF line @@ -1776,7 +1776,7 @@ fn the_package_iif_carries_each_lines_project() { ); } -/// BS-format-2 rule 8 with BS-statement-5 item 8: an invoice's or a bill's +/// BS-format-2 statement 27 with BS-statement-5 statement 6: an invoice's or a bill's /// lines carry their projects into CLASS through the entry they post, /// the revenue or expense line of each project tagged, an untagged /// part and the receivable or payable line left without a class. @@ -1921,7 +1921,7 @@ fn the_readme_lists_what_the_iif_writes_differently() { assert!(!text(&p, "README.txt").contains("Written differently")); } -/// BS-format-2 rule 7 (P3 review round 2): the file names no customer or vendor +/// BS-format-2 statement 26 (P3 review round 2): the file names no customer or vendor /// (Intuit states no such need for an IIF journal; QuickBooks Desktop asks /// for one on a journal entry to accounts receivable or payable, and takes /// one such account a transaction: sources/intuit-iif.md), so the README @@ -2022,7 +2022,7 @@ fn the_readme_names_the_entries_on_receivables_and_payables() { assert!(!text(&p, "README.txt").contains("customer or vendor")); } -/// BS-format-2 item 7: an entry with lines on both the receivables and +/// BS-format-2 statement 7: an entry with lines on both the receivables and /// payables control accounts is refused, naming its id, and the package is /// not built: QuickBooks Desktop records at most one A/R or A/P account a /// transaction, and splitting the entry would change what it says. @@ -2481,7 +2481,7 @@ fn the_k1_worksheet_reports_tax_basis_capital() { /// The CPA package's aging CSVs are the agings, one row per open document /// and a tie-out line that equals the control account (plan P4b S6, -/// 8.3.10; BS-ledger-8, BS-arap-2 INVARIANT 1). +/// 8.3.10; BS-ledger-8, BS-arap-2 invariant 1). #[test] fn the_aging_csvs_tie_to_the_control_check() { let dir = tempfile::Builder::new() diff --git a/crates/ledger-store/src/error.rs b/crates/ledger-store/src/error.rs index e162707a..e8c253d8 100644 --- a/crates/ledger-store/src/error.rs +++ b/crates/ledger-store/src/error.rs @@ -152,7 +152,7 @@ pub enum StoreError { #[error("store not found at {0}")] NotFound(String), - /// A write-off with no evidence (BS-arap-5 INVARIANT 1): a bad + /// A write-off with no evidence (BS-arap-5 statement 10): a bad /// debt is deducted on evidence that it is worthless (Treas. Reg. /// §1.166-2), so the books take the write-off only with its file. #[error( diff --git a/crates/ledger-store/src/format.rs b/crates/ledger-store/src/format.rs index 210b9d56..f6230dc1 100644 --- a/crates/ledger-store/src/format.rs +++ b/crates/ledger-store/src/format.rs @@ -179,7 +179,7 @@ pub const ASSET_BASIS: &str = "asset_basis"; pub const PROJECTS: &str = "projects"; /// Feature: an `invoice.created` or `bill.created` line naming its project -/// (`class_id`, BS-statement-5 item 8). An older version would restore the +/// (`class_id`, BS-statement-5 statement 6). An older version would restore the /// document without its lines' projects, silently. Its own feature, not /// `projects`': books that consented to projects before it existed must /// consent again before a document names one. diff --git a/crates/ledger-store/src/store.rs b/crates/ledger-store/src/store.rs index 8ccc35d0..2e324fb6 100644 --- a/crates/ledger-store/src/store.rs +++ b/crates/ledger-store/src/store.rs @@ -507,7 +507,7 @@ struct AttachRequest<'a> { } /// The evidence a bad-debt write-off files (plan P4b S7; BS-arap-5 -/// INVARIANT 1): the file that shows the debt is worthless — collection +/// statement 9): the file that shows the debt is worthless — collection /// correspondence, a bankruptcy notice (Treas. Reg. §1.166-2). Given as /// bytes to file in the same call, or as an attachment already in the /// books that is linked to the write-off's entry and its invoice. @@ -3446,7 +3446,7 @@ impl Store { } /// The issued copy of an invoice, filed in the call that issues it - /// (plan P4b S4.3 item 11, A-7; BS-arap-4 item 3): the entry, then + /// (plan P4b S4.3 item 11, A-7; BS-arap-4 invariant 3 and WB-arap-8): the entry, then /// `invoice.created`, then `receipt.attached` on the entry /// (`INV-0007.pdf`, `application/pdf`, "Issued invoice"), then /// `attachment.linked` to the invoice. The server renders the PDF @@ -3462,7 +3462,7 @@ impl Store { /// GOAL: the copy sent is kept with the invoice, or nothing is. /// SOURCE: IRS Pub. 583 (keep invoices); Rev. Proc. 98-25 (the audit /// trail keeps the record as issued); plan P4b S4.3, 8.3.11; - /// BS-arap-4 item 3. + /// BS-arap-4 invariant 3 and WB-arap-8. /// INVARIANTS: /// 1. Every refusal (an unknown customer, an invalid line or due /// date, a duplicate number, a closed period, a feature the books @@ -4534,7 +4534,7 @@ impl Store { /// ```text /// GOAL: a project in one command, journaled as two events only when /// it has facts, so a name-only project is a plain class. - /// SOURCE: BS-statement-5 item 1; BS-format-1 (journal feature + /// SOURCE: WB-statement-5; BS-format-1 (journal feature /// `projects`). /// INVARIANTS: /// 1. A refusal journals nothing: the whole record is rehearsed, and @@ -6848,7 +6848,7 @@ fn document_line_json(l: &DocumentLine) -> Value { "amount": l.amount.to_string(), }); // Its project, behind the feature document_line_projects ( - // BS-format-1, BS-statement-5 item 8); a line naming none is written as before it. + // BS-format-1, BS-statement-5 statement 6); a line naming none is written as before it. if let Some(c) = l.class_id { v["class_id"] = json!(c); } @@ -6927,7 +6927,7 @@ fn invoice_fields_json(payload: &mut Value, fields: &arap::InvoiceFields) { } /// Add a bill's new fields to its `bill.created` payload, each key only when -/// set. A duplicate's reason is journaled for the record (BS-arap-4 item +/// set. A duplicate's reason is journaled for the record (BS-arap-4 invariant /// 4); the bill itself keeps none. fn bill_fields_json(payload: &mut Value, fields: &arap::BillFields) { if let Some(r) = &fields.vendor_ref { diff --git a/crates/ledger-store/tests/arap_props.rs b/crates/ledger-store/tests/arap_props.rs index 2a2e5c51..bd613da8 100644 --- a/crates/ledger-store/tests/arap_props.rs +++ b/crates/ledger-store/tests/arap_props.rs @@ -1,5 +1,4 @@ -//! Documents through the store, at random (BS-arap-2 INVARIANTS 1, 2, -//! 4 and 6; plan P4b.15): histories of invoices, bills, payments (with a +//! Documents through the store, at random (BS-arap-2 invariants 1, 6, 7 and 9; plan P4b.15): histories of invoices, bills, payments (with a //! payment method and a reference, or none), voids, reversals of any //! entry, closed months and refused hand lines, run through `Store`, then //! replayed (the books reopened) and read by a `Snapshot`. @@ -9,7 +8,7 @@ //! the live books, their replay and a viewer's snapshot agree on //! every figure, at every date, and the control accounts equal //! their documents. -//! SOURCE: BS-entry-4 (replay), BS-arap-2 INVARIANTS 1, 2, 4, 6. +//! SOURCE: BS-entry-4 (replay), BS-arap-2 invariants 1, 6, 7 and 9. //! ``` use chrono::NaiveDate; @@ -417,7 +416,7 @@ fn agree(live: &Ledger, dir: &Path, docs: &[DocRef]) -> Result<(), TestCaseError proptest! { #![proptest_config(ProptestConfig::with_cases(32))] - /// BS-arap-2 INVARIANT 4 (and 1, 2, 6 through the store): a document's + /// BS-arap-2 invariant 7 (and 1, 6, 9 through the store): a document's /// state is a function of the journal and the day. Half the history, /// then the books reopened and compared; the rest on the reopened /// books, compared again. diff --git a/crates/ledger-store/tests/arap_standing.rs b/crates/ledger-store/tests/arap_standing.rs index a466b7f3..c9c53932 100644 --- a/crates/ledger-store/tests/arap_standing.rs +++ b/crates/ledger-store/tests/arap_standing.rs @@ -377,7 +377,7 @@ fn legacy_reversal_now_counts() { assert_eq!(trial_balance_json(&again), g["trial_balance"]); } -/// BS-arap-2 scenario 5 and item 7 in books an earlier version keeps: the +/// BS-arap-2 scenario 5 and WB-arap-4 in books an earlier version keeps: the /// right payment after the wrong one was reversed waits for the journal /// feature document_standing (an older version would count both), /// refused and journaling nothing until the owner's upgrade; a payment @@ -831,7 +831,7 @@ fn no_new_fields_journals_byte_for_byte() { } /// The issued copy is filed with the invoice or nothing is (plan P4b S4.3 -/// item 11, A-7; BS-arap-4 item 3): a refusal leaves the journal, the +/// item 11, A-7; BS-arap-4 invariant 3 and WB-arap-8): a refusal leaves the journal, the /// ledger and the allocators exactly as they were; an issue journals the /// entry, `invoice.created`, `receipt.attached` on that entry /// (`INV-0007.pdf`, `application/pdf`, "Issued invoice") and @@ -1247,8 +1247,7 @@ fn mark_sent_on_void_refused() { /// A settlement of two invoices, a discount and a processor's fee: one /// entry whose events name the lines they tag, every figure derived, and -/// the books replaying to the same lines (plan P4b S6; BS-arap-6 -/// INVARIANTS 1 and 3). +/// the books replaying to the same lines (plan P4b S6; BS-arap-6 invariant 3 and WB-arap-15). #[test] fn a_settlement_names_its_lines_and_replays() { use ledger_core::{Application, DocRef, Fee, SettleParams}; @@ -1422,7 +1421,7 @@ fn settlement_waits_for_documents_v2() { /// Legacy payment events carry no `line`, so replay keeps the positional /// rule: the first untagged control line for the payment's amount, in the -/// order the events come (plan P4b S6; BS-arap-6 INVARIANT 3). +/// order the events come (plan P4b S6; WB-arap-15). #[test] fn legacy_payment_events_keep_the_positional_rule() { use ledger_core::{DocRef, Movement}; @@ -1582,7 +1581,7 @@ fn write_off_waits_for_documents_v2() { /// A write-off is journaled as its entry and one `invoice.written_off`, /// and replay derives the same figures and the projection agrees: the /// invoice reads Written off, the bad-debt expense is on 6990, and the -/// control account still equals its documents (BS-arap-5, BS-arap-2 INVARIANT 1). +/// control account still equals its documents (BS-arap-5, BS-arap-2 invariant 1). #[test] fn write_off_replays_and_projects() { let dir = test_dir("write-off-replay"); @@ -1600,7 +1599,7 @@ fn write_off_replays_and_projects() { ) .unwrap(); // Half paid, the rest written off: the invoice reads Written off with - // 50 paid and 50 written off (BS-arap-2 SCENARIO 7). + // 50 paid and 50 written off (BS-arap-2 scenario 7). s.receive_payment(inv, d(2026, 4, 20), cents(5_000), bank) .unwrap(); let from = journal_len(&dir.0); @@ -1683,7 +1682,7 @@ fn write_off_replays_and_projects() { s.verify().unwrap(); } -/// No evidence, no write-off (BS-arap-5 INVARIANT 1; Treas. Reg. +/// No evidence, no write-off (BS-arap-5 statement 10; Treas. Reg. /// §1.166-2(a)): refused, journaling nothing; an attachment already filed /// is linked instead, to the entry and the invoice. #[test] diff --git a/crates/ledger-store/tests/asset_tags.rs b/crates/ledger-store/tests/asset_tags.rs index 2473719a..dfd14ed1 100644 --- a/crates/ledger-store/tests/asset_tags.rs +++ b/crates/ledger-store/tests/asset_tags.rs @@ -1175,7 +1175,7 @@ fn reversing_a_linked_acquisition_still_opens_and_verifies() { Store::open(&dir).unwrap().verify().unwrap(); } -// ------------------------------------------------- depreciation runs (BS-asset-1 rules 6 and 8) +// ------------------------------------------------- depreciation runs (BS-asset-1 statements 14 and 28) /// A run is the books' record of what they carry for an asset /// (Ledger::accumulated_posted): recorded live, replayed from the journal, diff --git a/crates/ledger-store/tests/document_projects.rs b/crates/ledger-store/tests/document_projects.rs index d0e43f7e..eef6fa81 100644 --- a/crates/ledger-store/tests/document_projects.rs +++ b/crates/ledger-store/tests/document_projects.rs @@ -1,4 +1,4 @@ -//! An invoice's or bill's lines in the journal (BS-statement-5 item 8, +//! An invoice's or bill's lines in the journal (BS-statement-5 statement 6, //! BS-format-1): a line naming its project carries `class_id` (journal feature //! `document_line_projects`), and the entry's revenue or expense line for //! that project is tagged by `entry.line_class_set` right after its @@ -9,7 +9,7 @@ //! ```text //! GOAL: a document's projects are journaled once, replay exactly, and //! never reach books whose owner hasn't consented to the format. -//! SOURCE: BS-statement-5 item 8, BS-format-1, BS-entry-4; plan/served.md +//! SOURCE: BS-statement-5 statement 6, BS-format-1, BS-entry-4; plan/served.md //! D-39 (the owner's upgrade). //! ``` diff --git a/crates/ledger-store/tests/store.rs b/crates/ledger-store/tests/store.rs index ed3156c9..c6e54f20 100644 --- a/crates/ledger-store/tests/store.rs +++ b/crates/ledger-store/tests/store.rs @@ -2636,7 +2636,7 @@ fn every_figure_of(l: &ledger_core::Ledger) -> (usize, usize) { tally(reports::general_ledger(l, start, end).map(|_| ())); tally(reports::members_equity(l, start, end, &members).map(|_| ())); // The statement of cash flows foots on every book, or is refused - // for a reason: never an engine error (BS-statement-3 rule 9). + // for a reason: never an engine error (BS-statement-3 statement 14). let cf = reports::cash_flow( l, &reports::CashFlowParams { diff --git a/docs/mcp-interface.md b/docs/mcp-interface.md index 121e36b4..c8e8a0f7 100644 --- a/docs/mcp-interface.md +++ b/docs/mcp-interface.md @@ -636,14 +636,14 @@ every tool over every book in ledger-store's `tests/fixtures/old-books`. kind. An entry's interest is its own operating class, (b) or (e), apart from the rest of its operating cash. A payment to a party with the `government_agency` or `tax_agency` role is `other_payments`, (g), - on any account (BS-statement-3 rule 5; payroll remittances excepted); + on any account (BS-statement-3 statements 8 and 9; payroll remittances excepted); one shared between such a party and a supplier gives two operating lines for the one entry, `other_payments` and `to_suppliers_and_employees`, split by the parties' shares and summing to the payment. What a member or a lender paid or received for the company with no cash account moving is cash borrowed (or contributed) and spent, on the entry's date (D-42, BS-statement-3 - rule 11): an expense a member paid personally through Due to Members + statement 16): an expense a member paid personally through Due to Members is a "Proceeds from borrowing — " line and an operating line, each with `on_behalf`, the part of its amount so handled (absent when none; an entry's `on_behalf` parts net to zero). @@ -1295,7 +1295,7 @@ Vendor and customer follow the records and are never set by hand. A `tax_agency` or `government_agency` payee also classes the company's payments to it on the cash flow statement: other operating cash payments, never cash paid to suppliers (`books.cash_flow`, BS-statement-3 -rule 5). +statement 8). **Rules the engine enforces** (each refusal changes nothing, the journal byte for byte): no party field holds a full TIN (a run of nine digits, @@ -1443,7 +1443,7 @@ BS-partner-3): Both `"0.00"` for `neither`; `resolved − cash − in_kind` is a promise, counted on neither basis. All four are null exactly when the shares don't resolve (`parties_error` says why). -- What the shares split (BS-partner-3 item 3): a close, its parties' own-account +- What the shares split (BS-partner-3 statement 3): a close, its parties' own-account movement, neither; a reversal, its original's negated; an entry naming only members that moves equity, what moved their capital (a contribution received: the property in it, asset accounts that are @@ -1462,7 +1462,7 @@ BS-partner-3): record (bills and their payments); its customer record's invoices and the payments received on them; and reversals of any of these. Only posted entries dated in the year count. -- *Money accounts* (BS-partner-3 item 5, P3 defect 24): the `[books] +- *Money accounts* (BS-partner-3 statement 7, P3 defect 24): the `[books] cash_accounts` (every asset account but receivables when none are set), the cards (the business-card payment methods' liability accounts, `books.instruments`; while the books record none, the liability @@ -1490,7 +1490,7 @@ BS-partner-3): (and the payments of distributions declared to them) is the statement of members' equity's contributions and distributions, and basis `cash` their contributions is the K-1 worksheet's cash contributions (BS-partner-3 - item 4 gives the conditions: a distribution declared and not yet paid + statement 6 gives the conditions: a distribution declared and not yet paid is in the statement only). The year is the whole calendar year; the viewer's party page and directory show these same numbers, labelled "cash basis", with the in-kind figures beside them. @@ -1914,7 +1914,7 @@ posting. get " (id)", a name already written differently from the books (made safe or tagged) yielding first, so a class's own name stands wherever it can: "Café" beside "Cafe" is written "Cafe (1)" and "Cafe" is - kept, BS-format-2 rule 8). No line names a customer or vendor (no + kept, BS-format-2 statement 30). No line names a customer or vendor (no NAME column; see the package's README). `warnings` (absent when there are none) says what the file writes differently from the books, for the human: each account's name, number and place and each @@ -2403,7 +2403,7 @@ snapshots; see plan 8.2 S4. code, name, balance, documents_total, unattached: [{ entry_id, line, date, amount }], difference, attention: [{ kind, id, status, total, outstanding }] }] }`. Receivables and payables tied to their documents - (BS-ledger-8, BS-arap-2 INVARIANT 1): `difference` is always `0.00`; `agrees` when + (BS-ledger-8, BS-arap-2 invariant 1): `difference` is always `0.00`; `agrees` when there is no unattached line and nothing needing attention. `books.verify` checks the same identity and `books.digest` lists its problems (`control_problems`). @@ -2413,7 +2413,7 @@ snapshots; see plan 8.2 S4. discounted, outstanding, bucket, days_overdue }], control: { account, balance, documents_total, unattached, difference } }` (`as_of` omitted: today). `detail: true` adds one row per open invoice; `control` is the - receivables account's tie-out (BS-ledger-8, BS-arap-2 INVARIANT 1), `difference` + receivables account's tie-out (BS-ledger-8, BS-arap-2 invariant 1), `difference` always `0.00`. - `books.ap_aging { as_of?, detail? }` → same, per vendor and bill. - `books.bills_due { through?, as_of? }` → `{ as_of, through, bills: @@ -2507,7 +2507,7 @@ until the owner upgrades them. project (every class), by name ignoring capitals; `to_date` counts every posted revenue and expense line tagged to it through today in the company's time zone, closing entries left out; `net` is its - contribution before overhead (BS-statement-5 item 7: revenue less every cost + contribution before overhead (WB-statement-7: revenue less every cost tagged to it, fixed and variable alike, no company overhead allocated: a segment margin in Garrison's sense, not a variable-cost contribution margin); `margin_pct` is net as a percent of revenue to one place, half @@ -2549,7 +2549,7 @@ until the owner upgrades them. project); its result gains `notes`, one per finished or abandoned project tagged, as `books.add_line`'s `note`. - An invoice's or bill's lines take a project too (`books.create_invoice` - and `books.create_bill`, `class` on a line, BS-statement-5 item 8), in + and `books.create_bill`, `class` on a line, BS-statement-5 statement 6), in books that declared the journal feature `document_line_projects`; the handbook's projects section says which these books are. Their payments take none. diff --git a/docs/parity.md b/docs/parity.md index 5c6ef791..93440f2e 100644 --- a/docs/parity.md +++ b/docs/parity.md @@ -39,7 +39,7 @@ in CI that the floor never falls between commits. | A/R invoices + payments + aging | Business → Invoices | done | R-FUTURE-5; since P4b S1 (D-45) a document's paid, outstanding and status are read from its tagged ledger lines, hand lines on the receivables account are refused, `books.void_document` and `books.control_check` tie the subledger to the control account (BS-arap-2); S2 `books.documents`/`books.document` and the viewer pages; S3 the invoice PDF; S4.1-S4.3 terms, numbers, line accounts, the issued PDF filed at issue (behind `documents_v2`, the owner's next upgrade); numbers, terms, line accounts, the party snapshots and the issued PDF filed with the invoice, through `books.create_invoice`'s preview and confirm (P4b S4.4); S4.5 the issued PDF carries the number, terms, PO, quantity and price, the bill-to's contact block and ship-to, the ways to pay with QR codes, the memo and the footer, and the viewer shows the number, terms, bill-to and PO and saves the issued copy | | A/P bills + payments + aging | Business → Bills | done | R-FUTURE-5; the same S1 derivation and control guard on the payables account; S4.1-S4.3 the vendor's invoice number, terms, every line on its own account (behind `documents_v2`); the vendor's own invoice number (a duplicate refused), terms, line accounts and the vendor's invoice filed as the bill's evidence, through `books.create_bill`'s preview and confirm (P4b S4.4); S4.5 the viewer shows the vendor's number, the day received, terms and memo, and the handbook's procedure (numbers, terms, line accounts) | | Payroll runs (accounting only, no tax tables) + tax remittance | Payroll | done | — | -| Tracking classes (divisional P&L) | Class tracking | done | invoice and bill lines take a class too (projects, BS-statement-5 item 8; QBO/Xero class or tracking per line) | +| Tracking classes (divisional P&L) | Class tracking | done | invoice and bill lines take a class too (projects, BS-statement-5 statement 6; QBO/Xero class or tracking per line) | | CPA handoff package (TB + GL xlsx, P&L + BS pdf, zip) | Reports → export | done | — | | Budgets | Budgets | todo | R-FUTURE-6 (declined as bloat) | | Scheduled transactions (recurring entries → drafts) | Scheduled txns / Recurring transactions | partial | hand-verified fixture incl. month-end dates; drafts only, by design | diff --git a/docs/parties-and-attachments.md b/docs/parties-and-attachments.md index c985b33f..d491d987 100644 --- a/docs/parties-and-attachments.md +++ b/docs/parties-and-attachments.md @@ -154,7 +154,7 @@ derived. Spec: `ledger_core::shares`. entry has balanced lines, and `post_entry` refuses (`party_shares`) until they do. Replay never consults settings. - **Money:** `parties::activity_with` counts each party's part on two - bases (BS-partner-3 item 4): cash (its money: cash, a card, the members' + bases (BS-partner-3 statement 5): cash (its money: cash, a card, the members' financing, a loan) and all (adding property contributed or distributed in kind), the viewer labelling the first "cash basis". Money accounts are the cash accounts, the cards and `[books] financing_accounts`; any diff --git a/docs/spec/README.md b/docs/spec/README.md index 4a4269df..914db727 100644 --- a/docs/spec/README.md +++ b/docs/spec/README.md @@ -75,9 +75,9 @@ each checked again against the same sources in the P3 review (numbers, pages and wording hold). Open: 105-10-05-1 to 05-3, read only in their 2009 text (ASU 2009-01, and as Wiley GAAP 2020 quotes them); their current wording is unconfirmed. Also open (P3 surface review, 2026-10-21): ASC 230-10-45-15(f) (debt -issue costs, cited by BS-statement-3 rule 11) is in neither list above; ASC +issue costs, cited by BS-statement-3 statement 16) is in neither list above; ASC 606-10-25-31, 25-32 and 55-20 (BS-prepaid-1's over-time method) are not yet read; -BS-asset-1 rule 6 cites ASC 250 with no paragraph; BS-revenue-1's 606-10-55-39 is in +BS-asset-1 statement 16 cites ASC 250 with no paragraph; BS-revenue-1's 606-10-55-39 is in neither list. Each is to be read in the ASC basic view and listed in `sources/fasb-asc.md` before it is relied on further. Also open (plan P4b, 2026-10-23): BS-arap-2 cites ASC 310-10, 405-20-40-1 and 606-10-45-4, diff --git a/docs/spec/claims/partner.md b/docs/spec/claims/partner.md index 66fc3d27..55313a03 100644 --- a/docs/spec/claims/partner.md +++ b/docs/spec/claims/partner.md @@ -374,7 +374,7 @@ the 1099 worksheet together, labelled, and neither is read for the other: `books.get_entry` gives each part's `resolved`, `direction`, `cash` and `in_kind`; `books.party` gives both a party's totals (`basis` cash or all) and its worksheet figures, labelled; the known -limits of BS-partner-3 rule 7 are stated in the tools' text; the +limits of BS-partner-3 statement 9 are stated in the tools' text; the viewer's party pages and entry page show the same parts. **Enforced:** `ledger-mcp` `books.get_entry`, `books.party`, diff --git a/docs/spec/claims/statement.md b/docs/spec/claims/statement.md index ba360b74..9c567d29 100644 --- a/docs/spec/claims/statement.md +++ b/docs/spec/claims/statement.md @@ -327,7 +327,7 @@ contribution_margin_pct}`, `ProjectToDate::margin_pct`. **Checked:** **WB-statement-8** The statement's words and groupings are wanderbooks' product strings, not accounting (the accounting is -BS-statement-3's rules 4, 6 and 8): a reversal shown alone reads +BS-statement-3's statements 5, 11 and 13): a reversal shown alone reads "Reversal of #N — " and a reinstatement "Reinstatement of #A (reverses #B)", both listed under the original's kind; a financing inflow under a borrowing reads "Proceeds from borrowing — diff --git a/docs/spec/sources/fasb-asc.md b/docs/spec/sources/fasb-asc.md index 14911fd0..928236b3 100644 --- a/docs/spec/sources/fasb-asc.md +++ b/docs/spec/sources/fasb-asc.md @@ -69,7 +69,7 @@ Quotes are short; the rest is paraphrase. - **230-10-10-1** (EY p. 1): the statement's primary objective is "to provide relevant information about the cash receipts and cash payments - of an entity during a period." → BS-statement-3 rule 1. + of an entity during a period." → BS-statement-3 statement 2. - **230-10-45-1** (EY p. 1): the statement "shall report the cash effects during a period of an entity's operations, its investing transactions, and its financing transactions." (It says nothing of reconciling @@ -275,7 +275,7 @@ basic view: check it there at the next reading. A contingency that might result in a gain "usually should not be reflected in the financial statements because to do so might be to recognize revenue before its realization." -→ BS-statement-5 item 4: a payment hoped for from work done on spec is recorded +→ BS-statement-5 statement 5: a payment hoped for from work done on spec is recorded neither as a receivable nor as income until it is received; the unrecovered cost is a figure, never an asset. @@ -289,12 +289,12 @@ contract or an anticipated contract the entity can specifically identify; they generate or enhance resources used in satisfying performance obligations in the future; and they "are expected to be recovered." -→ BS-statement-5 item 4 (with BS-asset-2): on-spec work has no contract it is expected +→ BS-statement-5 statement 5 (with BS-asset-2): on-spec work has no contract it is expected to recover its costs from, so its costs are expensed as incurred. ## 340-40-25-7 (Costs that relate directly to a contract) -Added 2026-10-22 for BS-statement-5 item 8 as the DART revenue roadmap sets it +Added 2026-10-22 for BS-statement-5 statement 6 as the DART revenue roadmap sets it out; not re-read in the ASC basic view: check it there at the next reading. The costs that "relate directly to a contract" (25-5(a)) are (a) direct labor, (b) direct materials, (c) allocations of costs that @@ -314,7 +314,7 @@ the contract), costs of wasted materials, labor or other resources not reflected in the contract's price, costs that relate to satisfied (or partly satisfied) performance obligations, and costs the entity cannot tell apart between satisfied and unsatisfied obligations. -→ BS-statement-5 item 8 (with 25-7): a cost traceable to one job (25-7(a), (b), +→ BS-statement-5 statement 6 (with 25-7): a cost traceable to one job (25-7(a), (b), (d), (e)) is that job's, whole, on the document's line; a cost that relates to several jobs reaches them only by an allocation on a stated basis (25-7(c)), which the books record as the allocation convention's diff --git a/docs/spec/sources/intuit-iif.md b/docs/spec/sources/intuit-iif.md index ac41461a..62ee382d 100644 --- a/docs/spec/sources/intuit-iif.md +++ b/docs/spec/sources/intuit-iif.md @@ -89,7 +89,7 @@ Cited (not quoted, but for the lines below): the Class list's keyword is CLASS; > If the class is a subclass of another class, the name includes the name of the parent classes, beginning with the highest level class. If you are creating an import file, use a colon (:) to separate subclass names. -So a class's NAME, like an account's, is one level per colon: the books, whose classes have no parents, write a colon in a class's name as '-', as in an account's (BS-format-2 rule 8). The page states no length limit and nothing about case. +So a class's NAME, like an account's, is one level per colon: the books, whose classes have no parents, write a colon in a class's name as '-', as in an account's (BS-format-2 statement 29). The page states no length limit and nothing about case. ### IIF Example Files: list declarations SHA-256 of `IIF Import Kit/IIF Example Files/QB 2007 & Enterprise 7.0 and later/Import First - List Declarations (Not Version Specific).iif` (the same bytes in each version's folder): `13c730b23bcb8c142621b04206e3628241d83051442c9b14ea2416d21163439c` @@ -180,7 +180,7 @@ Searched 2026-10-20. What Intuit says: Not Intuit, for the record: a third-party IIF vendor answering on Intuit's community (BigRedConsulting, 14 April 2020, ) wrote that "a NAME is required for any AR row", about a bill, not a journal; QuickBooks Desktop sync tools quote the refusal "Transaction split lines to accounts receivable must include a customer on that split line" (Acctivate, ). -No Intuit source says what an IIF journal import does with an A/R or A/P line that has no NAME (refuses it, imports it, or asks). So the books write no NAME (writing names would need the customer and vendor lists declared too, with a name unique across them) and the package README names the entries with an A/R or A/P line, so the CPA can add the name in QuickBooks if it asks (BS-format-2 rule 7). +No Intuit source says what an IIF journal import does with an A/R or A/P line that has no NAME (refuses it, imports it, or asks). So the books write no NAME (writing names would need the customer and vendor lists declared too, with a name unique across them) and the package README names the entries with an A/R or A/P line, so the CPA can add the name in QuickBooks if it asks (BS-format-2 statement 26). ## How long a class's name may be @@ -203,7 +203,7 @@ Not Intuit, for the record: Conductor's QuickBooks Desktop API reference (a serv > Maximum length: 31 characters. -So the books hold a class's NAME to 31 characters, as an account's own level (Intuit's own limit for a class, above), and keep no two alike ignoring case (Conductor: case-insensitive; BS-format-2 rule 8). +So the books hold a class's NAME to 31 characters, as an account's own level (Intuit's own limit for a class, above), and keep no two alike ignoring case (Conductor: case-insensitive; BS-format-2 statements 29 and 30). ## What QuickBooks does with an over-long name (not Intuit) Source: Thomson Reuters, Accounting CS help, "Export payroll journal entries", diff --git a/docs/testing.md b/docs/testing.md index 4915a52c..974039d6 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -1288,9 +1288,9 @@ no mutation run here; what P12 must cover is at the end. | The audit's table (F36, F37), row by row: resolved, direction, cash, in kind; reversals the exact opposite; bills and invoices signed; totals on both bases | `ledger-core/tests/spec_party_totals.rs` `defect14_shares_take_the_partys_side_and_reversals_flip` | BS-partner-3, by hand | | Basis all is the members' equity statement, cash the K-1's cash contributions | `basis_all_is_the_members_equity_statement_and_cash_the_k1s`; property `member_totals_are_the_members_equity_statement` (members contributing and taking out money and property, alone and jointly, subject to a loan, through 2100 then converted, through their distributions accounts, depreciated property with money, declared to distributions payable and paid later, reversed later in the year; checked over every span from the year's start and, received less paid, over every span) | `reports::members_equity`, `k1::k1_detail` | | A reversed member card payment nets to zero (brief §1.4) | `defect14_a_reversed_member_card_payment_nets_to_zero` | BS-ledger-5 | -| Accruals through another liability count once (defect 24) | `defect24_an_accrual_through_another_liability_counts_once` | BS-partner-3 item 5 | -| A credit to a party's own liability never pays it: a card fee, a distribution owed, a seller's note, property subject to a loan | `defect24_a_credit_to_a_partys_own_liability_never_pays_it`; the documented limit, pinned: `a_distribution_owed_counts_twice_until_the_members_are_named_its_creditors` | BS-partner-3 item 6; Treas. Reg. §1.704-1(b)(2)(iv)(b)(2); Helvering v. Price | -| Review, 2026-10-21: a distribution declared to distributions payable counts once, when paid (it counted twice); a distribution of money and depreciated property splits by what moved (the money read as property); a gift card sold is received once (it was a "card": twice); a refund is received; tin_last4 never shows more than four digits | `defect24_a_distribution_declared_to_a_payable_counts_once_when_paid`, `a_distribution_of_money_and_depreciated_property_splits_by_what_moved`, `defect24_a_gift_card_sold_is_received_once`, `a_refund_is_received_from_the_vendor`, `defect11_a_partys_tin_last4_is_its_tin_facts_else_its_w9s` (SCENARIO 6) | BS-partner-3 items 3, 5; BS-partner-2 | +| Accruals through another liability count once (defect 24) | `defect24_an_accrual_through_another_liability_counts_once` | BS-partner-3 statement 7 | +| A credit to a party's own liability never pays it: a card fee, a distribution owed, a seller's note, property subject to a loan | `defect24_a_credit_to_a_partys_own_liability_never_pays_it`; the documented limit, pinned: `a_distribution_owed_counts_twice_until_the_members_are_named_its_creditors` | BS-partner-3 statement 8; Treas. Reg. §1.704-1(b)(2)(iv)(b)(2); Helvering v. Price | +| Review, 2026-10-21: a distribution declared to distributions payable counts once, when paid (it counted twice); a distribution of money and depreciated property splits by what moved (the money read as property); a gift card sold is received once (it was a "card": twice); a refund is received; tin_last4 never shows more than four digits | `defect24_a_distribution_declared_to_a_payable_counts_once_when_paid`, `a_distribution_of_money_and_depreciated_property_splits_by_what_moved`, `defect24_a_gift_card_sold_is_received_once`, `a_refund_is_received_from_the_vendor`, `defect11_a_partys_tin_last4_is_its_tin_facts_else_its_w9s` (SCENARIO 6) | BS-partner-3 statements 3 and 7; BS-partner-2 | | A mixed contribution splits as the K-1 does, ties to the first member | `a_members_mixed_entry_splits_as_the_k1_does` | k1 INVARIANTS 3, 4 | | Read from journaled facts: an archived member, a one-member company | `a_members_entry_keeps_its_reading_after_they_leave` | review R2 | | A close is neither; a basis is cash or all; creditor_of's checks; tin_last4's five scenarios; the kernel's cases | `a_close_tagged_with_its_members_is_neither`, `a_basis_is_cash_or_all`, `a_creditor_is_named_only_on_a_liability_with_one_owner`, `defect11_a_partys_tin_last4_is_its_tin_facts_else_its_w9s`, `party_target_cases_by_hand` | specs | @@ -1392,9 +1392,9 @@ must cover is at the end. | What | Where | Oracle | |---|---|---| -| One rule for what a card is: the recorded business cards' liabilities, else (none recorded) liabilities named "card", not "gift"; never a member's card, a member's check or a platform; a debit card on the bank is none; money follows it | `ledger-core` `tests/spec_party_totals.rs` `a_card_is_a_recorded_business_card_else_a_liability_named_card` | BS-partner-3 item 5, `parties::card_accounts` INVARIANTS 1-4 | -| Party totals and the 1099 worksheet never contradict: paid less received is the worksheet's paid + excluded_card + undetermined + not_reportable plus its other receipts, for a vendor named alone, whatever the methods, refunds and reversals | property `party_totals_are_the_1099s_buckets` (`ledger-core` `tests/form1099.rs`; `PROPTEST_CASES`, default 256; 2,000 run clean; dropping a bucket from the sum fails at once) | BS-partner-3 item 9, by hand | -| The same, one year by hand: a member's check, a member's card, a member's payment of unknown method, a company card charge and a company check to one contractor, then the member reimbursed | `bookspec/examples/1099-and-party-totals-for-a-members-payment.toml` | BS-partner-3 item 9; Treas. Reg. §1.6041-1(e)(1), (a)(1)(iv) | +| One rule for what a card is: the recorded business cards' liabilities, else (none recorded) liabilities named "card", not "gift"; never a member's card, a member's check or a platform; a debit card on the bank is none; money follows it | `ledger-core` `tests/spec_party_totals.rs` `a_card_is_a_recorded_business_card_else_a_liability_named_card` | BS-partner-3 statement 7, `parties::card_accounts` INVARIANTS 1-4 | +| Party totals and the 1099 worksheet never contradict: paid less received is the worksheet's paid + excluded_card + undetermined + not_reportable plus its other receipts, for a vendor named alone, whatever the methods, refunds and reversals | property `party_totals_are_the_1099s_buckets` (`ledger-core` `tests/form1099.rs`; `PROPTEST_CASES`, default 256; 2,000 run clean; dropping a bucket from the sum fails at once) | BS-partner-3 statement 11, by hand | +| The same, one year by hand: a member's check, a member's card, a member's payment of unknown method, a company card charge and a company check to one contractor, then the member reimbursed | `bookspec/examples/1099-and-party-totals-for-a-members-payment.toml` | BS-partner-3 statement 11; Treas. Reg. §1.6041-1(e)(1), (a)(1)(iv) | | The CPA package's 1099 worksheet is `books.vendor_1099`'s CSV for the package's accounts (the request's, else the settings', R18) through its as_of, byte for byte; without `through` the files differ; a `through` outside the year and an unknown account are refused | `ledger-cli` `oracle_mcp.rs` `cpa_package_holds_the_year_and_its_evidence`; `ledger-package` `tests/package.rs` `payments_to_a_vendor_come_from_the_packages_accounts`, `one_list_of_cash_accounts_per_package`, `the_1099_worksheet_stops_at_as_of` | BS-statement-4; mcp-interface.md | | A feature is asked for before a command's first line: `books.update_party` with a field and the first creditor, in P2's books waiting for their format upgrade, is refused whole (nothing journaled, never the field without the creditor); once upgraded, as in books this version made, it journals the field, then the creditor, declaring nothing | `ledger-cli` `tests/spec_party_totals.rs` `update_party_asks_for_the_creditor_feature_before_its_first_line` | BS-format-1 | | One bookspec loader for every example, the parties' and the 1099s' with them: `setup.parties`, `setup.members` (`distributions_account`), `setup.payees` (a party's vendor record), `setup.status_changes`, `setup.instruments`, events' `parties` and `instrument`, and the queries `vendor_1099`, `k1`, `party_part`, `party_totals`, `party_tin_last4`; refused: a party or payment method not in the setup, a reversal naming parties, party totals without a basis, a 1099 line leaving a figure out, a wrong direction or status | `ledger-core` `tests/bookspec/` (`every_bookspec_example_holds`, `a_party_not_in_the_setup_is_refused`, `a_party_parts_direction_is_checked`, `a_reversal_naming_parties_is_refused`, `party_totals_without_a_basis_are_refused`, `a_vendor_1099_line_leaving_a_figure_out_is_refused`, `a_vendor_1099_status_is_checked`, `a_payment_method_not_in_the_setup_is_refused`) | bookspec/README.md | @@ -1743,9 +1743,9 @@ bookspec's rules / `docs/spec/claims/` say why not. Mutation runs wait for P12 ( - **Engine** (`ledger-package/tests/p3_seams.rs`): `the_members_figures_agree_on_every_date` (members' equity, the K-1 worksheet, party totals on both bases, the cash flow's contributions, - advances and distributions, BS-partner-3 items 4 and 8), + advances and distributions, BS-partner-3 statements 6 and 10), `a_distribution_declared_then_paid_is_financing_when_paid`, - `the_1099_worksheet_ties_to_party_totals_and_the_ledger` (BS-partner-3 item 9, + `the_1099_worksheet_ties_to_party_totals_and_the_ledger` (BS-partner-3 statement 11, BS-1099-1), `depreciation_is_one_figure_everywhere` (the P&L, the cash flow add-back, the tax-basis K-1's open item, the IIF, the register posted and scheduled, the balance sheet), `every_statement_foots_on_every_date`, @@ -1759,14 +1759,14 @@ bookspec's rules / `docs/spec/claims/` say why not. Mutation runs wait for P12 ( `books.vendor_1099` through each date, `books.party` on both bases. - **Found and fixed** (each test fails before its fix): a distribution declared to a payable and paid later read as cash paid to suppliers - (BS-statement-3 rule 2; `a_distribution_declared_then_paid_is_a_distribution_paid` + (BS-statement-3 statement 3; `a_distribution_declared_then_paid_is_a_distribution_paid` in `ledger-core/tests/spec_cash_flow.rs`, with the property `prop_cf_financing_is_equity_plus_designated_debt`'s model extended); a disposal's depreciation credit-back was in the cash flow's gain or - loss, not its depreciation (BS-statement-3 rule 8; + loss, not its depreciation (BS-statement-3 statement 13; `a_disposals_depreciation_credit_back_is_depreciation`), and the tax-basis K-1's book depreciation left it out (BS-partner-4); `books.list_assets` - as of a day said "disposed" for a later disposal (BS-asset-1 rule 8). + as of a day said "disposed" for a later disposal (BS-asset-1 statement 28). ## P3: the surface review (2026-10-21) @@ -1975,7 +1975,7 @@ feature check; the decision `projects` omit-when-empty; The owner's ask: a "mini financial snapshot" of one project on its page, overhead left out, so it shows at a glance whether the project is in the -black or the red, with charts (BS-statement-5 item 7: contribution before +black or the red, with charts (WB-statement-7: contribution before overhead, revenue less every traced cost, a segment margin in Garrison's sense; a presentation choice, not GAAP). Every figure is ledger-core's: `ProjectToDate::{net, margin_pct, any_tagged, revenue_by_account, @@ -2085,7 +2085,7 @@ rounding strategy; `project_figures`' opening net and running sum; ## Invoices and bills take a project (2026-10-22) -BS-statement-5 item 8: each invoice and bill line takes an optional project +BS-statement-5 statement 6: each invoice and bill line takes an optional project (`books.create_invoice` / `books.create_bill` `class`); the entry's revenue or expense side is one line per project (`arap::document_parts`), the receivable or payable and the payments untagged; journaled as the line's @@ -2201,7 +2201,7 @@ The P3 cutover review's open points 1 (the IIF left CLASS empty) and 2 the tax-basis member split) waits for the owner: nothing is posted before the year-end close. No mutation run (D-33). -**Point 1, the IIF's classes** (BS-format-2 rule 8): `ledger-import` +**Point 1, the IIF's classes** (BS-format-2 statements 27-33): `ledger-import` `tests/spec_import.rs` `iif_writes_each_lines_class_and_declares_the_classes_first` (the file exact: the `!CLASS` list after the accounts, before `!TRNS`, every class @@ -2234,7 +2234,7 @@ and the property. The property found (seed in name yield to a changed one ("Café" twice beside "Cafe (1)" and "Cafe (1) (1)"); the cap is gone, a tag that changes nothing is skipped instead. -**Point 2, payments to governments** (BS-statement-3 rule 5): `ledger-core` +**Point 2, payments to governments** (BS-statement-3 statement 8): `ledger-core` `tests/spec_cash_flow.rs` `a_payment_to_a_government_is_other_operating` (a filing fee on an organization-costs account paid to a government agency, and a penalty on supplies paid to a tax agency, are (g); the @@ -2528,7 +2528,7 @@ accounting question), CHANGE (a source says otherwise; work pending). | 6 | Reconciliation balances | CONFIRMED | Signed by the account's normal side (a card reads as owed), as statements show it; `reconciling_a_card_reads_its_normal_side_...` | | 7 | A member's ending on one equity statement may differ by a cent from the next statement's beginning | CHANGED 2026-10-13; CHANGED P3 | A capital account is one running balance (Treas. Reg. §1.704-1(b)(2)(iv)(b); the Item L quote this row once gave was misread, P3 review R-4). Undistributed earnings now split cumulatively as of each date, so each member's capital chains exactly (`each_members_capital_chains_across_statements`; it fails on the old code); since P3 the split is what the count's next close would give, so a date's capital never moves when its month is closed (D-38; `each_members_capital_chains_and_holds_through_closes`); BS-partner-1 | | 8 | Cash flow nets one line per account; investing comes only from registered assets | CHANGED 2026-10-13 | ASC 230-10-45-7: gross receipts and payments "more relevant" than net; 45-8 limits netting to quick-turnover items. Financing and investing are now gross; loans made and investments bought are investing (230-10-20, 45-13) via `[books] investing_accounts`. Owner-advanced expenses: PwC 6.9.3.1 constructive treatment via `[books] financing_accounts` (BS-statement-3) | -| 8a | Cash flow by the indirect method; member-paid expenses as constructive receipts | CHANGED 2026-10-20 | The direct method with the reconciliation as a separate schedule (ASC 230-10-45-25, 45-30); noncash investing and financing activities disclosed, only the cash portion reported (50-3, 50-5). Member-paid expenses stay constructive receipts and disbursements, now gross and on each payment's date, and the same for a lender's payments and an expense paid into capital: a choice (D-42, after a day as noncash under D-35), since ASC 230 doesn't address payments made on the entity's behalf and the firm guides present them so (PwC 6.9.3.1, DART 7.2, BDO 3.4, EY 4.6.2; KPMG Q8.3.10 also accepts noncash for property a lender pays for). BS-statement-3 rule 11, P3 defect 1 | +| 8a | Cash flow by the indirect method; member-paid expenses as constructive receipts | CHANGED 2026-10-20 | The direct method with the reconciliation as a separate schedule (ASC 230-10-45-25, 45-30); noncash investing and financing activities disclosed, only the cash portion reported (50-3, 50-5). Member-paid expenses stay constructive receipts and disbursements, now gross and on each payment's date, and the same for a lender's payments and an expense paid into capital: a choice (D-42, after a day as noncash under D-35), since ASC 230 doesn't address payments made on the entity's behalf and the firm guides present them so (PwC 6.9.3.1, DART 7.2, BDO 3.4, EY 4.6.2; KPMG Q8.3.10 also accepts noncash for property a lender pays for). BS-statement-3 statement 16, P3 defect 1 | | 9 | An asset's life ends at purchase + life months, that day not held; day-count proration | CONVENTION | Exactly N months of service; day proration and the mid-month convention are both accepted book policies (ASC 360-10-35-4, read 2026-10-14: any systematic and rational allocation) | | 10 | A payroll entry has one line per account total | CONFIRMED | The per-employee detail the IRS requires ("Amounts and dates of all wage ... payments", Employment Tax Recordkeeping) is kept in the run; a summary entry is standard | | 11 | A period with exactly the dates of an existing one is allowed | DESIGN | Nothing governs duplicate periods; harmless (the second close locks only). Refusing exact duplicates is an option | @@ -2624,7 +2624,7 @@ the wiring into verify, the digest and Needs attention) is part B. `a_payment_journals_its_method_and_reference` (a plain payment's payload field for field as before), `legacy_documents_replay_with_tags`); `tests/arap_props.rs` `status_is_a_function_of_journal_and_date` (BS-arap-2 - INVARIANT 4: random invoices, bills, payments with and without a + invariant 7: random invoices, bills, payments with and without a method and reference, voids, reversals of any entry, closed months and refused hand lines through `Store`; at half time and at the end the books are reopened and read by a `Snapshot`, and `differs_from`, every @@ -3356,10 +3356,10 @@ collected leaves the receivables as a deduction, with its evidence filed in the same call. - **ledger-core, `tests/spec_documents.rs`:** - `half_paid_rest_written_off_is_written_off` (BS-arap-2 SCENARIO 7: 50 paid, + `half_paid_rest_written_off_is_written_off` (BS-arap-2 scenario 7: 50 paid, 50 written off, one balanced entry Dr 6990 / Cr 1200, the receivable line tagged `WriteOff`, receivables down by exactly the write-off); - `write_off_refused_on_cash_basis` (BS-arap-5 INVARIANT 3: refused, the + `write_off_refused_on_cash_basis` (BS-arap-5 invariant 5: refused, the snapshot unchanged, no draft left); `write_off_above_outstanding_refused` (the bound at the day, a zero and a negative amount, then the exact amount owed taken); `write_off_then_recovery_same_year` (D-49: the diff --git a/docs/verification.md b/docs/verification.md index 715ff6b5..456848b3 100644 --- a/docs/verification.md +++ b/docs/verification.md @@ -485,7 +485,7 @@ one kernel function, `kernel::basis_figures`, for every rule: ### A project's unrecovered cost (P3, projects) -The "if repaid" figure of work done on spec (BS-statement-5 item 4) is +The "if repaid" figure of work done on spec (BS-statement-5 statement 5) is one kernel function, `kernel::unrecovered_cost`: 32. **Never below zero, the shortfall exactly, and no overflow**: the @@ -879,7 +879,7 @@ Be precise about the claims: entries out of the sections but not out of the cash accounts' balances; the two agree because a close moves only revenue, expense and equity (`Ledger::validate_close_to`) and cash accounts must be - assets (BS-statement-3 rule 2). The Lean model's close step lets a + assets (BS-statement-3 statement 3). The Lean model's close step lets a target be any balance-sheet account, so `Reachable.cashflow_foots` takes any selection of entries with the cash over the same selection, and `Reachable.cashflow_is_change_in_cash` counts every entry, closes From d26a75b2aededbfe26f8894fd18def88b8a1b743 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Mon, 9 Nov 2026 03:30:06 -0700 Subject: [PATCH 07/15] test(core): every sub-reference names a part its record has `sub_refs` scans every tracked file outside plan/ and checks each `BS-- statement k`, `invariant k` and `scenario k` (a list, a range, a parenthesised or comment-wrapped form, or a continuation on the same id such as "invariant 2 and statement 11") against the pinned record: k must lie within the length of that list. It also fails the old vocabulary after a bookspec id (item, rule, INVARIANT, SCENARIO, r, or a miscased word) when a number follows, so S-E's leftover forms cannot creep back. The number of references checked is printed (328) and floored (320); the self-tests refuse `BS-entry-1 statement 99`, a list or range with one bad number, a wrapped reference, a bad continuation and every old form, and accept the forms the records do have. Co-Authored-By: Claude Sonnet 5.5 --- crates/ledger-core/tests/bookspec/main.rs | 1 + crates/ledger-core/tests/bookspec/sub_refs.rs | 422 ++++++++++++++++++ 2 files changed, 423 insertions(+) create mode 100644 crates/ledger-core/tests/bookspec/sub_refs.rs diff --git a/crates/ledger-core/tests/bookspec/main.rs b/crates/ledger-core/tests/bookspec/main.rs index a8555432..f83efdfb 100644 --- a/crates/ledger-core/tests/bookspec/main.rs +++ b/crates/ledger-core/tests/bookspec/main.rs @@ -96,4 +96,5 @@ mod rules_md; mod run; mod source_refs; mod sources; +mod sub_refs; mod traceability; diff --git a/crates/ledger-core/tests/bookspec/sub_refs.rs b/crates/ledger-core/tests/bookspec/sub_refs.rs new file mode 100644 index 00000000..d88663f4 --- /dev/null +++ b/crates/ledger-core/tests/bookspec/sub_refs.rs @@ -0,0 +1,422 @@ +//! The sub-reference checks (unit S-E3). +//! +//! Unit S-E rewrote every `B-n` citation to its bookspec id and kept the +//! sub-reference after it ("item 7", "rule 11", "INVARIANT 2") as it was, +//! but those numbers counted parts of the retired rules.md text, not of +//! bookspec's records. S-E3 mapped each by content, and this check keeps +//! them true: every `BS-- statement k`, `invariant k` or +//! `scenario k` in any tracked file outside `plan/` names a part its +//! pinned record has (k from 1 to the length of that list), and the old +//! vocabulary (`item`, `rule`, `INVARIANT`, `SCENARIO`, `r`, or any +//! other word that is not exactly `statement`, `invariant` or +//! `scenario`) after a bookspec id, followed by a number, fails. +//! +//! A reference may be a list ("statements 5, 11 and 13"), a range +//! ("statements 27-30"), parenthesised, wrapped across lines behind a +//! comment prefix, or continued on the same id ("invariant 2 and +//! statement 11"); each number is one reference checked. The number +//! checked is floored and printed. This file is not scanned: its +//! self-tests quote the forms they must refuse. + +use crate::*; + +fn repo_root() -> PathBuf { + Path::new(env!("CARGO_MANIFEST_DIR")).join("../..") +} + +/// How many references the scan must find, at least. Raise it, in the +/// same commit, when references are added; it never falls. +const CHECKED_FLOOR: usize = 320; + +/// The tracked file this check does not scan: its own self-tests quote +/// the forms it refuses. +const SELF: &str = "crates/ledger-core/tests/bookspec/sub_refs.rs"; + +/// The parts a record has: its statements, invariants and scenarios. +#[derive(Clone, Copy)] +struct Parts { + statements: usize, + invariants: usize, + scenarios: usize, +} + +fn record_parts() -> BTreeMap { + bookspec_checker::records() + .iter() + .map(|r| { + ( + r.id.to_string(), + Parts { + statements: r.statement.len(), + invariants: r.invariants.len(), + scenarios: r.scenarios.len(), + }, + ) + }) + .collect() +} + +/// The text with each line's comment prefix and indentation dropped and +/// the lines joined by one space, so a reference wrapped across lines +/// reads as one; and the byte offset where each line starts in it. +fn flatten(text: &str) -> (String, Vec) { + let mut flat = String::with_capacity(text.len()); + let mut starts = Vec::new(); + for line in text.lines() { + starts.push(flat.len()); + let mut rest = line.trim_start(); + for prefix in ["///", "//!", "//", "#", "*", ">"] { + if let Some(after) = rest.strip_prefix(prefix) { + rest = after.trim_start(); + break; + } + } + flat.push_str(rest.trim_end()); + flat.push(' '); + } + (flat, starts) +} + +fn line_at(starts: &[usize], offset: usize) -> usize { + starts.partition_point(|&s| s <= offset) +} + +/// The kind a word names: `Some(true)` for the new vocabulary, exactly +/// `statement`, `invariant`, `scenario` (or the plural); `Some(false)` +/// for any old or miscased word; `None` for a word that is no part word. +fn part_word(word: &str) -> Option<(Option, bool)> { + let lower = word.to_ascii_lowercase(); + let singular = lower.strip_suffix('s').unwrap_or(&lower); + let kind = match singular { + "statement" => 's', + "invariant" => 'i', + "scenario" => 'c', + "item" | "rule" => 'o', + _ if lower == "r" => 'o', + _ => return None, + }; + let new = kind != 'o' + && matches!( + word, + "statement" | "statements" | "invariant" | "invariants" | "scenario" | "scenarios" + ); + Some((if kind == 'o' { None } else { Some(kind) }, new)) +} + +fn is_id_char(c: char) -> bool { + c.is_ascii_alphanumeric() || c == '-' || c == '_' +} + +/// The numbers after a part word: `5`, `5, 11 and 13`, `27-30`. +/// Returns each (low, high) and the chars consumed. +fn number_list(tail: &[char], start: usize) -> (Vec<(usize, usize)>, usize) { + let mut at = start; + let mut out = Vec::new(); + loop { + // One element: digits, optionally `-` or an en dash and digits. + let mut j = at; + while j < tail.len() && tail[j].is_ascii_digit() { + j += 1; + } + let len = j - at; + if len == 0 || (!out.is_empty() && len > 3) || len > 4 { + break; + } + let low: usize = tail[at..j].iter().collect::().parse().unwrap_or(0); + let mut high = low; + let mut end = j; + if end + 1 < tail.len() + && (tail[end] == '-' || tail[end] == '–') + && tail[end + 1].is_ascii_digit() + { + let mut k = end + 1; + while k < tail.len() && tail[k].is_ascii_digit() { + k += 1; + } + if k - (end + 1) <= 3 { + high = tail[end + 1..k] + .iter() + .collect::() + .parse() + .unwrap_or(0); + end = k; + } + } + // A date or a number glued to letters is no part number. + if !out.is_empty() + && end < tail.len() + && (tail[end].is_ascii_alphanumeric() + || (tail[end] == '-' && end + 1 < tail.len() && tail[end + 1].is_ascii_digit())) + { + break; + } + out.push((low, high)); + at = end; + // A separator and another number: `, `, ` and `, `, and `, ` or `. + let mut k = at; + let mut sep = false; + for word in [", and ", ", ", " and ", " or "] { + let w: Vec = word.chars().collect(); + if tail.len() >= k + w.len() && tail[k..k + w.len()] == w[..] { + k += w.len(); + sep = true; + break; + } + } + if !sep || k >= tail.len() || !tail[k].is_ascii_digit() { + break; + } + at = k; + } + (out, at) +} + +/// Scan `text`; returns the references checked and the problems found. +fn scan(text: &str, at: &str, parts: &BTreeMap) -> (usize, Vec) { + let (flat, starts) = flatten(text); + let mut checked = 0usize; + let mut problems = Vec::new(); + for (pos, _) in flat.match_indices("BS-") { + if flat[..pos].chars().next_back().is_some_and(is_id_char) { + continue; + } + let rest: Vec = flat[pos + 3..].chars().take(240).collect(); + // BS-- + let mut i = 0; + while i < rest.len() && (rest[i].is_ascii_lowercase() || rest[i].is_ascii_digit()) { + i += 1; + } + if i == 0 || i >= rest.len() || rest[i] != '-' { + continue; + } + let area: String = rest[..i].iter().collect(); + i += 1; + let digits_from = i; + while i < rest.len() && rest[i].is_ascii_digit() { + i += 1; + } + if i == digits_from { + continue; + } + let number: String = rest[digits_from..i].iter().collect(); + let id = format!("BS-{area}-{number}"); + let line = line_at(&starts, pos); + // Optional 's, optional comma, spaces, optional parenthesis. + if rest.get(i) == Some(&'\'') && rest.get(i + 1) == Some(&'s') { + i += 2; + } + if rest.get(i) == Some(&',') { + i += 1; + } + let spaces_from = i; + while rest.get(i) == Some(&' ') { + i += 1; + } + if i == spaces_from { + continue; + } + if rest.get(i) == Some(&'(') { + i += 1; + } + // A reference, then continuations on the same id. + let mut first = true; + loop { + let word_from = i; + while i < rest.len() && rest[i].is_ascii_alphabetic() { + i += 1; + } + let word: String = rest[word_from..i].iter().collect(); + let Some((kind, new)) = part_word(&word) else { + break; + }; + if rest.get(i) != Some(&' ') || !rest.get(i + 1).is_some_and(|c| c.is_ascii_digit()) { + break; + } + let (nums, end) = number_list(&rest, i + 1); + let shown: String = rest[word_from..end].iter().collect(); + if !new { + problems.push(format!( + "{at}:{line}: {id} {shown}: the old vocabulary; say `statement`, `invariant` or `scenario` k, as bookspec numbers its parts" + )); + } else if let Some(p) = parts.get(&id) { + let (have, name) = match kind { + Some('s') => (p.statements, "statements"), + Some('i') => (p.invariants, "invariants"), + _ => (p.scenarios, "scenarios"), + }; + for (low, high) in &nums { + checked += 1; + if *high != *low { + checked += 1; + } + if *low < 1 || *high < 1 || *low > have || *high > have { + problems.push(format!( + "{at}:{line}: {id} {shown}: the record has {have} {name}" + )); + } + } + } else { + checked += nums.len(); + problems.push(format!("{at}:{line}: {id} {shown}: no such rule")); + } + i = end; + // `, and`, `and`, `with`, `,` and then another part word. + let mut k = i; + let mut moved = false; + for sep in [", and ", ", ", " and ", " with "] { + let w: Vec = sep.chars().collect(); + if rest.len() >= k + w.len() && rest[k..k + w.len()] == w[..] { + k += w.len(); + moved = true; + break; + } + } + if !moved { + break; + } + i = k; + first = false; + } + let _ = first; + } + (checked, problems) +} + +fn tracked_text_files(root: &Path) -> Vec<(String, String)> { + let output = std::process::Command::new("git") + .args(["ls-files", "-z"]) + .current_dir(root) + .output() + .expect("git ls-files"); + assert!(output.status.success(), "git ls-files succeeds"); + let listing = String::from_utf8_lossy(&output.stdout).into_owned(); + let mut files = Vec::new(); + for rel in listing.split('\0').filter(|s| !s.is_empty()) { + if rel.starts_with("plan/") || rel == SELF { + continue; + } + let Ok(text) = std::fs::read_to_string(root.join(rel)) else { + continue; + }; + if text.contains('\0') { + continue; + } + files.push((rel.to_string(), text)); + } + files +} + +#[test] +pub(crate) fn every_sub_reference_names_a_part_its_record_has() { + let parts = record_parts(); + assert!(!parts.is_empty(), "the pinned bookspec has records"); + let root = repo_root(); + let mut checked = 0usize; + let mut bad = Vec::new(); + for (rel, text) in tracked_text_files(&root) { + let (n, problems) = scan(&text, &rel, &parts); + checked += n; + bad.extend(problems); + } + println!("sub-references checked: {checked}"); + assert!( + checked >= CHECKED_FLOOR, + "sub-references were found ({checked}, floor {CHECKED_FLOOR})" + ); + assert!( + bad.is_empty(), + "every sub-reference names a part its record has, in bookspec's words:\n{}", + bad.join("\n") + ); +} + +fn problems_in(text: &str) -> Vec { + scan(text, "t", &record_parts()).1 +} + +#[test] +pub(crate) fn a_statement_the_record_lacks_fails() { + // BS-entry-1 has four statements, four invariants and one scenario. + assert_eq!(problems_in("BS-entry-1 statement 99").len(), 1); + assert_eq!(problems_in("BS-entry-1 statement 5").len(), 1); + assert_eq!(problems_in("BS-entry-1 statement 0").len(), 1); + assert_eq!(problems_in("BS-entry-1 invariant 5").len(), 1); + assert_eq!(problems_in("BS-entry-1 scenario 2").len(), 1); + assert_eq!(problems_in("BS-nosuch-9 statement 1").len(), 1); + assert_eq!( + scan("BS-entry-1 statement 4", "t", &record_parts()), + (1, vec![]) + ); + assert_eq!( + scan("BS-entry-1 invariant 4", "t", &record_parts()), + (1, vec![]) + ); + assert_eq!( + scan("BS-entry-1 scenario 1", "t", &record_parts()), + (1, vec![]) + ); +} + +#[test] +pub(crate) fn lists_ranges_wraps_and_continuations_are_each_checked() { + let parts = record_parts(); + // Every number of a list or range, in the parentheses a comment gives. + assert_eq!( + scan("(BS-entry-1 statements 1, 2 and 4)", "t", &parts), + (3, vec![]) + ); + assert_eq!(problems_in("(BS-entry-1 statements 1, 2 and 9)").len(), 1); + assert_eq!(problems_in("BS-entry-1 statements 2-9").len(), 1); + assert_eq!(scan("BS-entry-1 statements 1-4", "t", &parts).0, 2); + // A reference wrapped across a comment prefix reads as one. + assert_eq!(problems_in("/// (BS-entry-1\n/// statement 99)").len(), 1); + assert_eq!(problems_in("//! BS-entry-1 statement\n//! 99").len(), 1); + // A continuation on the same id is checked too, and one in the old + // vocabulary fails. + assert_eq!( + scan("BS-entry-1 invariant 1 and statement 3", "t", &parts), + (2, vec![]) + ); + assert_eq!( + problems_in("BS-entry-1 invariant 1 and statement 30").len(), + 1 + ); + assert_eq!(problems_in("BS-entry-1 invariant 1 and item 3").len(), 1); + // A date or a number after a list is no reference. + assert_eq!( + scan("BS-entry-1 statement 2, 2026-11-08", "t", &parts), + (1, vec![]) + ); + // Prose that merely follows an id is no sub-reference. + assert_eq!( + scan("BS-entry-1 states that a rule holds", "t", &parts), + (0, vec![]) + ); + assert_eq!( + scan("BS-entry-1 rule: debits equal credits", "t", &parts), + (0, vec![]) + ); +} + +#[test] +pub(crate) fn the_old_vocabulary_fails() { + for old in [ + "BS-entry-1 item 2", + "BS-entry-1 items 1 and 2", + "BS-entry-1 rule 2", + "BS-entry-1, rule 2", + "BS-entry-1's rules 1, 2", + "BS-entry-1 INVARIANT 2", + "BS-entry-1 INVARIANTS 1-2", + "BS-entry-1 SCENARIO 1", + "BS-entry-1 r 2", + "BS-entry-1 Statement 2", + "(BS-entry-1 item 2)", + "// BS-entry-1\n// INVARIANT 2", + ] { + assert_eq!(problems_in(old).len(), 1, "{old:?} fails"); + } + // A product-rule id is no bookspec id, and a bare word is no reference. + assert_eq!(problems_in("WB-entry-1 item 2").len(), 0); + assert_eq!(problems_in("the INVARIANT 2 of kernel::settle").len(), 0); +} From 7b40d243a66008f06347d2ff2c57b7e53cad9871 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Mon, 9 Nov 2026 03:31:29 -0700 Subject: [PATCH 08/15] docs(plan): S-C8, bookspec's records cite their own parts by position S-E3 found two records still using the old words inside bookspec: BS-format-2's statements cite each other as items, and BS-statement-3's and BS-partner-3's statements carry Rule n labels that no longer equal their positions. Co-Authored-By: Claude Opus 5.5 --- plan/p14-bookspec.md | 1 + 1 file changed, 1 insertion(+) diff --git a/plan/p14-bookspec.md b/plan/p14-bookspec.md index 8b8975f8..6c88b36b 100644 --- a/plan/p14-bookspec.md +++ b/plan/p14-bookspec.md @@ -84,6 +84,7 @@ workers have been faster). | **K-U1..U9** | The sweep (`plan/kernel-sweep-audit.md` section 3), in value order: U1 FX, U3 shares (six copies to one; legacy replay policies only named, never changed), U2 rounding, U5 schedules (D-72), U4 totals (the raw-operator panic class), U6 ratios, U7 payroll, U8 control and aging, U9 display rounding. Each: kernel functions, Kani, bridge, its law in bookspec's Lean, its rule cited by BS id | K-U0; Lean laws after L-F2 | its own `kernel/.rs`, `proofs/.rs`, bridge module, call sites | S-M each | | **S-E2** | The 13 rule citations S-E kept in program output move to BS ids together: the eight B-43 evidence-source strings in `ledger.rs`, the two lines recording them in `ledger-store/tests/golden/draft_states_and_evidence_gate.json` (a string-only golden edit, verified by hand and explained in the commit), `ledger-package/src/package.rs` (CPA package text), `ledger-mcp/src/tools/settlements.rs` (a tool description), and the GUI `CONTRIBUTION_NOTE` (`rules.md B-37 item 7`). First establish whether any of these strings is stored in a journal or the store (then old books must still read: replay keeps the old text, new writes the new); then shrink `source_refs.rs`'s kept-string allow-list to zero (S-E review, 2026-11-08) | S-E merged | those six files, the golden, `tests/bookspec/source_refs.rs` | S | | **S-E3** | The sub-references S-E carried over move to bookspec's numbering: S-E rewrote `B-37 item 7` as `BS-statement-5 item 7`, but the old items were the rules.md text's and bookspec's records number their statements, invariants and scenarios their own way (S-E2 found `BS-statement-5 item 7` now means finished or abandoned projects; the document lines are item 6). 261 such references outside `plan/` (`BS-statement-3 rule n` 67+, `BS-statement-5 item n` 57, `BS-partner-3 item n` 44, `BS-arap-2 INVARIANT n` 17, and others). Build the map from the last rules.md that held the text (before S-D0) to each record's statements, rewrite each reference, and add a test that every `BS-- k` names one the pinned record has (S-E2, 2026-11-09) | S-E2 merged | the files that cite them, `tests/bookspec/source_refs.rs` | M | +| **S-C8** | bookspec's records cite their own parts by position: BS-format-2's statements cite each other as "(item 22)", "(item 18)", "(item 24)" (the old word, though the number is the position), and BS-statement-3's and BS-partner-3's statements open with "Rule n" labels that no longer equal their positions (BS-statement-3 statement 16 is "Rule 11"). Rewrite the cross-references as "statement k", and drop the labels or keep them only where an outside text cites them (then say so); extend the checker so a record's internal "statement k" names a part it has (found by S-E3, 2026-11-09) | S-E3 merged | bookspec `rules/format/BS-format-2.toml`, `rules/statement/BS-statement-3.toml`, `rules/partner/BS-partner-3.toml`, the checker | S | | **K-U10** | `impl Amount for Decimal`'s `checked_add` and `checked_mul` exact or None (BS-ledger-1: a product the arithmetic can't hold MUST be refused; BS-entry-4): `checked_mul` rounds a product whose mantissa passes 96 bits (K-U1's fix, 2026-11-08: `1050000010.0000000001 × 9.9999999999` books 10500000099.90 for an exact 10500000099.8949…, both inputs within D-75's ten places; pinned by `the_mantissa_edge_is_outside_the_precondition_and_pinned`), and `checked_add`: `rust_decimal` rounds dust away within one unit of `Decimal::MAX` (`MAX + 0.4` gives `Some(MAX)`), breaking the kernel's exact-or-None contract (found by K-U4, 2026-11-08; pinned by the canary `finding_decimal_add_rounds_dust_at_the_edge`): refuse a sum whose result scale fell below the operands'; after the sweep units merge (the file is shared). Also from K-U3's review (2026-11-09): `split_by_weights_into` ranks remainders by Decimal's rounded quotient, so an exact tie is decided by the 28th digit, not given to the earlier part as the docs and the Lean model say (20.00 by 4/1/1 gives 13.33, 3.34, 3.33 where exact ranking gives 13.34, 3.33, 3.33); the pre-U3 sites did the same, and K-U3 kept it and pinned both cases. Ranking by the exact integer remainder (`whole x w - part x total`, as `share_floor_with` does) moves a cent between parties in reports recomputed for past periods: an owner decision, put with the cents it moves before it lands | K-U4 merged | `kernel/entries.rs`, the canary, the bridge | S | | **V-D** | Coverage report and floor; `rust_decimal` checked against exact rationals (task D) | none | in flight 2026-11-08 | S | | **V-D2** | Tests where coverage is thinnest (the V-D findings, `docs/coverage-floor.md`): `ledger-store` `reconcilable.rs` (0% from the store's own suite), `ledger-core` `evidence.rs` (34% lines, 9% branches from the core's suite), `ledger.rs`'s command steps (`mark_sent_steps`, `settle_steps`, `run_payroll_steps`, …) and refusal arms, `conventions.rs` and `settings.rs` validation refusals, `audit.rs` branches; each test encodes the rule it covers; the floor rises with them | V-D | the crates' tests | M | From 8c57046c53eb7dc50f890c78df9b9c089ef5bd72 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Mon, 9 Nov 2026 03:44:13 -0700 Subject: [PATCH 09/15] test(core): the adapter runs drafts and evidence bookspec's examples for BS-entry-5, BS-entry-6 and BS-ledger-17 are run through the real Store, none reimplemented: a draft is made by `Store::create_entry` and `add_line` (tried on a clone first, so a line the engine refuses on a header account leaves no half-made draft in the journal), posted by `post_entry_checked` when the example states an evidence policy (the server's gate; the primitive otherwise), given its state by `set_draft_state`, its document by `attach_receipt` and thrown away by `discard_draft`. A close a draft holds back is tried on a clone too. The two queries are read off the engine: a draft's state from the entry itself, and the evidence decision from `evidence::requirement`, its sentence of exemption read into the examples' closed words. The refusals are read off the engine's errors: a placeholder account is `header_account`, the receipt gate `evidence_required`, a draft's command on an entry that is no draft `not_drafted`, a close with a draft in its period `drafts_in_period`. Wanderbooks passes every example for its picks (check-when-line-added, reversal-evidence-is-originals); the two examples for the other options are skipped, so the pinned skip count goes from 11 to 13. Co-Authored-By: Claude Sonnet 5.5 --- crates/ledger-core/tests/bookspec/books.rs | 15 ++ crates/ledger-core/tests/bookspec/check.rs | 8 +- crates/ledger-core/tests/bookspec/common.rs | 14 ++ crates/ledger-core/tests/bookspec/events.rs | 221 +++++++++++++++--- crates/ledger-core/tests/bookspec/examples.rs | 8 +- .../tests/bookspec/loader_tests.rs | 58 +++++ crates/ledger-core/tests/bookspec/main.rs | 1 + .../tests/bookspec/queries/documents.rs | 2 +- .../tests/bookspec/queries/drafts.rs | 80 +++++++ .../ledger-core/tests/bookspec/queries/mod.rs | 3 + 10 files changed, 378 insertions(+), 32 deletions(-) create mode 100644 crates/ledger-core/tests/bookspec/queries/drafts.rs diff --git a/crates/ledger-core/tests/bookspec/books.rs b/crates/ledger-core/tests/bookspec/books.rs index 90e50947..1e5f4030 100644 --- a/crates/ledger-core/tests/bookspec/books.rs +++ b/crates/ledger-core/tests/bookspec/books.rs @@ -502,6 +502,21 @@ impl<'a> Books<'a> { "{what}: twice" ); } + // The evidence policy the example assumes (BS-entry-5): the books' + // own setting, as an engine holds it (BS-ledger-9). An example that + // states none has no policy, and its drafts post by the primitive. + if let Some(over) = &s.evidence_over { + use ledger_core::settings::Change; + let change = Change { + key: "policy.evidence.threshold".into(), + value: Some(serde_json::json!(over)), + }; + took( + self.store + .change_settings(&[change], &bookspec_source(&ex.id)), + &format!("{}: the evidence policy", ex.id), + ); + } self.members = members; self.party_members = party_members; self.parties = parties; diff --git a/crates/ledger-core/tests/bookspec/check.rs b/crates/ledger-core/tests/bookspec/check.rs index 019a21a6..b3411743 100644 --- a/crates/ledger-core/tests/bookspec/check.rs +++ b/crates/ledger-core/tests/bookspec/check.rs @@ -18,7 +18,11 @@ pub(crate) fn check(b: &Books<'_>, x: &Expect) -> Option<&'static str> { queries.join(" and ") ); }; - only(x.entry.is_some(), "entry", &["entry", "party_part"]); + only( + x.entry.is_some(), + "entry", + &["entry", "party_part", "draft_state", "evidence"], + ); only(x.event.is_some(), "event", &["run"]); only( x.asset.is_some(), @@ -111,6 +115,8 @@ pub(crate) fn check(b: &Books<'_>, x: &Expect) -> Option<&'static str> { "document_dates" => check_document_dates(b, x), "document" => check_document(b, x), "invoice_numbers" => check_invoice_numbers(b, x), + "draft_state" => check_draft_state(b, x), + "evidence" => check_evidence(b, x), q => { let &(_, by) = FORMAT_QUERIES .iter() diff --git a/crates/ledger-core/tests/bookspec/common.rs b/crates/ledger-core/tests/bookspec/common.rs index 7b0f42f4..780fa2d3 100644 --- a/crates/ledger-core/tests/bookspec/common.rs +++ b/crates/ledger-core/tests/bookspec/common.rs @@ -163,6 +163,17 @@ pub(crate) fn refusal(e: &LedgerError) -> String { LedgerError::ParentTypeMismatch { .. } => "parent_type_mismatch", LedgerError::EntryAlreadyReversed(..) => "already_reversed", LedgerError::ClosedPeriod(..) => "period_closed", + // A line on a header account (a placeholder takes no postings), + // BS-entry-1 and BS-entry-6. + LedgerError::PlaceholderAccount(_) => "header_account", + // A close with a draft dated in its period (BS-period-2). + LedgerError::DraftsInPeriod(_) => "drafts_in_period", + // A draft's command on an entry that is no draft: it is posted + // already (a post, a state, a discard), or was discarded and is + // gone (BS-entry-5). + LedgerError::EntryAlreadyPosted(_) + | LedgerError::PostedEntryImmutable + | LedgerError::UnknownEntry(_) => "not_drafted", other => return format!("another refusal: {other}"), } .to_string() @@ -173,6 +184,8 @@ pub(crate) fn refusal(e: &LedgerError) -> String { pub(crate) fn store_refusal(e: &StoreError) -> String { match e { StoreError::Ledger(e) => refusal(e), + // The evidence gate (BS-entry-5): the entry needs a document. + StoreError::ReceiptRequired(_) => "evidence_required".to_string(), other => format!("another refusal: {other}"), } } @@ -210,6 +223,7 @@ pub(crate) fn exact(s: &str, what: &str) -> Decimal { pub(crate) fn store_refusal_obj(e: &StoreError) -> Refusal { match e { StoreError::Ledger(e) => Refusal::of_reason(refusal(e)), + StoreError::ReceiptRequired(_) => Refusal::of_reason("evidence_required"), other => Refusal::of_reason(format!("another refusal: {other}")), } } diff --git a/crates/ledger-core/tests/bookspec/events.rs b/crates/ledger-core/tests/bookspec/events.rs index 82a35e55..6958fdc7 100644 --- a/crates/ledger-core/tests/bookspec/events.rs +++ b/crates/ledger-core/tests/bookspec/events.rs @@ -20,11 +20,15 @@ impl Books<'_> { ("dispose_asset", e.dispose_asset.is_some()), ("run_schedules", e.run_schedules.is_some()), ("register_schedule", e.register_schedule.is_some()), + ("post_draft", e.post_draft.is_some()), + ("set_draft_state", e.set_draft_state.is_some()), + ("attach_receipt", e.attach_receipt.is_some()), + ("discard_draft", e.discard_draft.is_some()), ]; match kinds.iter().filter(|(_, given)| *given).collect::>()[..] { [(kind, _)] => kind, _ => panic!( - "{} event {n}: an event is one of lines, reverses, close, bill, invoice, write_off, payment, settlement, recovery, run_depreciation, dispose_asset, run_schedules or register_schedule", + "{} event {n}: an event is one of lines, reverses, close, bill, invoice, write_off, payment, settlement, recovery, run_depreciation, dispose_asset, run_schedules, register_schedule, post_draft, set_draft_state, attach_receipt or discard_draft", self.ex.id ), } @@ -80,8 +84,20 @@ impl Books<'_> { "{ex} event {n}: {kind} is tagged with no parties or payment method" ); assert!( - e.refused.is_none() || !matches!(kind, "close" | "invoice"), - "{ex} event {n}: refused is for a reversal, an entry, a bill or a command, which the books take whole or not at all" + e.refused.is_none() || kind != "invoice", + "{ex} event {n}: refused is for a reversal, an entry, a bill, a command or a close, which the books take whole or not at all" + ); + assert!( + !e.draft || matches!(kind, "lines" | "reverses"), + "{ex} event {n}: draft is an entry's lines or a reversal, prepared and not yet posted" + ); + assert!( + !e.draft + || (e.parties.is_empty() + && e.instrument.is_none() + && e.payee.is_none() + && !e.older), + "{ex} event {n}: a draft carries no payee, parties or payment method" ); assert!( !(e.older && e.refused.is_some()), @@ -204,11 +220,19 @@ impl Books<'_> { &self.posted[n - 1], "{what}: what the event posted is kept" ); + // What a draft event made stands as a draft (until a `post_draft` + // posts it); what any other event made is posted. + let made = if e.draft { + EntryStatus::Draft + } else { + EntryStatus::Posted + }; for &id in &posted { assert_eq!( self.l().get_entry(id).map(|x| x.status()), - Some(EntryStatus::Posted), - "{what}: entry {id}, which it made, is posted" + Some(made), + "{what}: entry {id}, which it made, is {}", + if e.draft { "a draft" } else { "posted" } ); } if (own || matches!(kind, "write_off" | "payment" | "settlement")) && e.refused.is_none() { @@ -333,6 +357,100 @@ impl Books<'_> { }; let day = || when.expect("checked: dated"); match kind { + // A draft (BS-entry-5, BS-entry-6): the entry prepared, and posted + // by nothing here. The engine refuses a line on a header account + // as it is added (it picks check-when-line-added), and the books + // take an entry whole or not at all, so the draft is tried on a + // clone first: a refusal leaves no half-made draft in the journal. + "lines" if e.draft => { + let lines: Vec<_> = e + .lines + .iter() + .map(|line| { + let side = match line.side.as_str() { + "debit" => Side::Debit, + "credit" => Side::Credit, + other => panic!("{what}: side {other:?}"), + }; + let class = line.project.as_ref().map(|p| { + *self.projects.get(p).unwrap_or_else(|| { + panic!("{what}: project {p:?} not in setup.projects") + }) + }); + ( + self.id(&line.account), + side, + Money::new(money(&line.amount), self.currency), + class, + ) + }) + .collect(); + let mut probe = self.store.ledger().clone(); + let entry = probe.try_create_entry(day(), description)?; + for (i, &(account, side, amount, class)) in lines.iter().enumerate() { + probe.add_line(entry, account, side, amount)?; + if class.is_some() { + probe.set_line_class(entry, i, class)?; + } + } + let entry = self.store.create_entry(day(), description)?; + for (i, &(account, side, amount, class)) in lines.iter().enumerate() { + self.store.add_line(entry, account, side, amount)?; + if class.is_some() { + self.store.set_line_class(entry, i, class)?; + } + } + Ok(()) + } + "reverses" if e.draft => panic!( + "{what}: wanderbooks has no draft reversal: it picks reversal-evidence-is-originals (BS-ledger-17), under which a reversal posts at once" + ), + "post_draft" => { + let p = e.post_draft.as_ref().expect("checked: a post"); + let entry = self.entry_of(p.entry, what); + // With an evidence policy the post is the gate's: the + // server's path for a hand-made draft; without one, the + // primitive. + if self.has_policy() { + self.store.post_entry_checked(entry) + } else { + self.store.post_entry(entry) + } + } + "set_draft_state" => { + let s = e.set_draft_state.as_ref().expect("checked: a state"); + let entry = self.entry_of(s.entry, what); + let state = match (s.state.as_str(), &s.note) { + ("building", None) => ledger_core::DraftState::Building, + ("awaiting_evidence", Some(note)) => { + ledger_core::DraftState::AwaitingEvidence { note: note.clone() } + } + other => panic!("{what}: draft state {other:?}"), + }; + self.store.set_draft_state(entry, state) + } + "attach_receipt" => { + let r = e.attach_receipt.as_ref().expect("checked: a receipt"); + let entry = self.entry_of(r.entry, what); + // The document, by its reference: its own bytes, so that two + // references are two documents (identical bytes are one file, + // plan P6 step 4). + let bytes = format!("%PDF-1.4\n{}\n%%EOF\n", r.receipt); + self.store + .attach_receipt( + Some(entry), + &format!("{}.pdf", r.receipt.replace([' ', ',', '/'], "-")), + "application/pdf", + bytes.as_bytes(), + Some(&r.receipt), + ) + .map(drop) + } + "discard_draft" => { + let d = e.discard_draft.as_ref().expect("checked: a discard"); + let entry = self.entry_of(d.entry, what); + self.store.discard_draft(entry, &d.reason) + } "lines" if e.refused.is_some() => { // The books take an entry whole or not at all, so a // refused one leaves no draft behind: it is tried on a @@ -355,6 +473,27 @@ impl Books<'_> { probe.set_line_class(entry, i, Some(class))?; } } + // The evidence gate, as the server's post runs it: a hand entry + // the policy covers has no document, and an event cannot + // attach one before the entry exists. + if self.has_policy() { + let draft = probe.get_entry(entry).expect("just drafted").clone(); + let settings = probe.settings(); + if let ledger_core::evidence::Requirement::Required { reason } = + ledger_core::evidence::requirement(&probe, &draft, settings) + { + let policy = ledger_core::evidence::Policy::from_settings(settings); + return Err(StoreError::ReceiptRequired(Box::new( + ledger_store::error::ReceiptRequiredInfo { + entry_id: entry, + debits: ledger_core::evidence::Policy::entry_debits(&draft).ok(), + policy: policy.describe(), + split_group: policy.split_group(&probe, entry, &draft), + reason, + }, + ))); + } + } Ok(probe.post_entry(entry)?) } "lines" => { @@ -377,7 +516,11 @@ impl Books<'_> { this.store.set_line_class(entry, i, Some(class))?; } } - this.store.post_entry(entry) + if this.has_policy() { + this.store.post_entry_checked(entry) + } else { + this.store.post_entry(entry) + } }; if e.older { ledger_core::parties::replaying(|| post(self)) @@ -399,30 +542,20 @@ impl Books<'_> { "close" => { let c = e.close.as_ref().expect("checked: a close"); let start = date(&c.start, what); + if e.refused.is_some() { + // A close the books refuse (a draft stands in the period, + // BS-period-2) opens no period and posts nothing: it is + // tried on a clone, with the same close below. + let mut probe = self.store.ledger().clone(); + let p = probe.create_period(&format!("event {n}"), start, day())?; + return Ok(probe + .close_period_to(p, &self.close_to(c, what)) + .map(drop)?); + } let p = self .store .create_period(&format!("event {n}"), start, day())?; - let members: Vec = self - .members - .iter() - .map(|m| MemberClose { - capital: m.capital_account, - share: m.share, - distributions: None, - }) - .collect(); - if c.to == "members" { - assert!( - !members.is_empty() && members.iter().all(|m| m.share > Decimal::ZERO), - "{what}: a close to the members needs their shares" - ); - } - let to = match (c.to.as_str(), c.rounding.as_deref()) { - ("members", None) => CloseTo::Members(members), - ("members", Some("per-close")) => CloseTo::MembersPerClose(members), - ("retained_earnings", None) => CloseTo::RetainedEarnings { sweep: vec![] }, - other => panic!("{what}: close {other:?}"), - }; + let to = self.close_to(c, what); let closed = self.store.close_period_to(p, &to)?; assert!(closed.is_some(), "{what}: the close has nothing to close"); Ok(()) @@ -694,6 +827,40 @@ impl Books<'_> { } } } +impl Books<'_> { + /// Whether the example states an evidence policy (`setup.evidence_over`): + /// the books' own setting, which the server's post gate reads. + pub(crate) fn has_policy(&self) -> bool { + self.ex.setup.evidence_over.is_some() + } + + /// Where a close sends the period's income: to retained earnings, or to + /// the members by their shares. + pub(crate) fn close_to(&self, c: &bookspec_checker::CloseSpec, what: &str) -> CloseTo { + let members: Vec = self + .members + .iter() + .map(|m| MemberClose { + capital: m.capital_account, + share: m.share, + distributions: None, + }) + .collect(); + if c.to == "members" { + assert!( + !members.is_empty() && members.iter().all(|m| m.share > Decimal::ZERO), + "{what}: a close to the members needs their shares" + ); + } + match (c.to.as_str(), c.rounding.as_deref()) { + ("members", None) => CloseTo::Members(members), + ("members", Some("per-close")) => CloseTo::MembersPerClose(members), + ("retained_earnings", None) => CloseTo::RetainedEarnings { sweep: vec![] }, + other => panic!("{what}: close {other:?}"), + } + } +} + impl Books<'_> { /// Make a change that posts no entry (after event `after`). /// Make a change that posts no entry (after event `after`), or say why diff --git a/crates/ledger-core/tests/bookspec/examples.rs b/crates/ledger-core/tests/bookspec/examples.rs index c1d34691..dee2e120 100644 --- a/crates/ledger-core/tests/bookspec/examples.rs +++ b/crates/ledger-core/tests/bookspec/examples.rs @@ -163,10 +163,12 @@ pub(crate) fn every_bookspec_example_holds() { // -11 (recovery-movement), -12 (net-of-expected-discount), -13 // (net-against-the-deposit) and -14 (apportion-across-the-lines), // BS-prepaid-2's equal-months and BS-ledger-20's refuse (each option's - // example, so no allow-list grows). + // example, so no allow-list grows), BS-entry-6's check-only-when-posting + // and BS-ledger-17's reversal-needs-its-own (wanderbooks refuses a line on + // a header as it is added, and a reversal needs no evidence of its own). assert_eq!( skipped.len(), - 11, - "the eleven unpicked-option examples: {skipped:?}" + 13, + "the thirteen unpicked-option examples: {skipped:?}" ); } diff --git a/crates/ledger-core/tests/bookspec/loader_tests.rs b/crates/ledger-core/tests/bookspec/loader_tests.rs index 1cae99f9..ae615071 100644 --- a/crates/ledger-core/tests/bookspec/loader_tests.rs +++ b/crates/ledger-core/tests/bookspec/loader_tests.rs @@ -629,3 +629,61 @@ pub(crate) fn an_invoice_lines_project_is_what_the_project_counts() { }, ); } + +/// A draft's state the engine does not hold is a failure, not a pass: the +/// example says the entry is still `building` after it posted. +#[test] +#[should_panic(expected = "state")] +pub(crate) fn a_wrong_draft_state_fails() { + run_edited( + "entry-a-draft-waits-on-its-evidence-and-posts-once-it-has-it.toml", + |t| t.replacen("state = \"posted\"", "state = \"building\"", 1), + ); +} + +/// An evidence decision the engine does not give is a failure. +#[test] +#[should_panic(expected = "decision")] +pub(crate) fn a_wrong_evidence_decision_fails() { + run_edited("entry-evidence-is-decided-in-one-place.toml", |t| { + t.replacen("decision = \"required\"", "decision = \"exempt\"", 1) + }); +} + +/// A post the gate refuses is a refusal the example must say: leaving it out +/// is a failure (the engine refused an event the example takes). +#[test] +#[should_panic(expected = "post_draft")] +pub(crate) fn a_post_without_its_evidence_must_be_marked_refused() { + run_edited( + "entry-a-draft-waits-on-its-evidence-and-posts-once-it-has-it.toml", + |t| t.replacen("refused = \"evidence_required\"\n", "", 1), + ); +} + +/// A discard of a posted entry is refused: saying it is accepted fails. +#[test] +#[should_panic(expected = "discard_draft")] +pub(crate) fn a_discard_of_a_posted_entry_must_be_marked_refused() { + run_edited( + "entry-a-drafts-state-is-a-note-and-a-posted-entry-has-none.toml", + |t| { + t.replacen( + "discard_draft = { entry = 1, reason = \"Posted by mistake\" }\nrefused = \"not_drafted\"", + "discard_draft = { entry = 1, reason = \"Posted by mistake\" }", + 1, + ) + }, + ); +} + +/// A close the books hold back for a draft in its period is refused and +/// changes nothing: saying it is accepted fails. +#[test] +#[should_panic(expected = "draft entries exist")] +pub(crate) fn a_close_with_a_draft_in_its_period_must_be_marked_refused() { + run_edited( + "period-a-draft-holds-its-period-open-until-it-is-discarded.toml", + |t| t.replacen("refused = \"drafts_in_period\"\n", "", 1), + ); +} diff --git a/crates/ledger-core/tests/bookspec/main.rs b/crates/ledger-core/tests/bookspec/main.rs index a8555432..aeed82e2 100644 --- a/crates/ledger-core/tests/bookspec/main.rs +++ b/crates/ledger-core/tests/bookspec/main.rs @@ -76,6 +76,7 @@ pub(crate) use queries::assets::*; pub(crate) use queries::commands::*; pub(crate) use queries::dates::*; pub(crate) use queries::documents::*; +pub(crate) use queries::drafts::*; pub(crate) use queries::formats::*; pub(crate) use queries::parties::*; pub(crate) use queries::statements::*; diff --git a/crates/ledger-core/tests/bookspec/queries/documents.rs b/crates/ledger-core/tests/bookspec/queries/documents.rs index e47bd5fd..3a8a5b7b 100644 --- a/crates/ledger-core/tests/bookspec/queries/documents.rs +++ b/crates/ledger-core/tests/bookspec/queries/documents.rs @@ -160,7 +160,7 @@ pub(crate) fn check_document_dates(b: &Books<'_>, x: &Expect) { check_figures(b, x, b.answer_document_dates(&x.query())); } -fn check_figures(b: &Books<'_>, x: &Expect, answer: Result) { +pub(crate) fn check_figures(b: &Books<'_>, x: &Expect, answer: Result) { let ex = b.ex; let Value::Object(got) = answer.unwrap_or_else(|r| panic!("{}: {}: {}", ex.id, x.query, r.reason)) diff --git a/crates/ledger-core/tests/bookspec/queries/drafts.rs b/crates/ledger-core/tests/bookspec/queries/drafts.rs new file mode 100644 index 00000000..de7f8897 --- /dev/null +++ b/crates/ledger-core/tests/bookspec/queries/drafts.rs @@ -0,0 +1,80 @@ +use crate::*; + +impl Books<'_> { + /// Where the entry event `q.entry` made stands (BS-entry-5), read from + /// the engine's own books: a draft's state (with its note when it awaits + /// evidence), posted (a posted entry has no state of its own), or gone + /// (a discarded draft leaves the ledger). + pub(crate) fn answer_draft_state(&self, q: &Query) -> Result { + let n = q.entry.ok_or_else(|| self.missing("entry"))?; + let id = self.entry_or_refuse(n)?; + let mut m = JsonMap::new(); + let state = match self.l().get_entry(id) { + None => "discarded", + Some(e) if e.status() == EntryStatus::Posted => "posted", + Some(e) => match e.draft_state() { + ledger_core::DraftState::Building => "building", + ledger_core::DraftState::AwaitingEvidence { note } => { + m.insert("note".to_string(), Value::String(note.clone())); + "awaiting_evidence" + } + }, + }; + m.insert("state".to_string(), Value::String(state.to_string())); + Ok(Value::Object(m)) + } + + /// The engine's one decision whether the entry event `q.entry` made + /// needs evidence (`ledger_core::evidence::requirement`, BS-entry-5): the + /// decision as the engine gives it, its reason or exemption read into + /// the examples' closed words. + pub(crate) fn answer_evidence(&self, q: &Query) -> Result { + use ledger_core::evidence::{Requirement, requirement}; + let n = q.entry.ok_or_else(|| self.missing("entry"))?; + let id = self.entry_or_refuse(n)?; + let entry = self + .l() + .get_entry(id) + .ok_or_else(|| self.missing("entry"))?; + let (decision, because) = match requirement(self.l(), entry, self.l().settings()) { + Requirement::Required { .. } => ("required", "policy"), + Requirement::Exempt { source } => ( + "exempt", + // The engine words the source of an exemption in sentences; + // the examples' words are the closed list of BS-entry-5. + match source { + s if s.starts_with("the receipt policy") => "policy", + s if s.starts_with("a reversal") => "reversal", + s if s.starts_with("a period's closing entry") => "closing_entry", + s if s.starts_with("a schedule month's posting") => "schedule_posting", + s if s.starts_with("a depreciation run") => "depreciation_run", + s if s.starts_with("an asset's disposal") => "asset_disposal", + s if s.starts_with("a document's entry") || s.starts_with("a payroll") => { + "document_entry" + } + other => { + return Err(engine_refusal( + RuleId::new(Area::Entry, 5), + format!("an exemption with no word in the examples: {other}"), + )); + } + }, + ), + }; + Ok(json_figures([ + ("decision".to_string(), decision.to_string()), + ("because".to_string(), because.to_string()), + ])) + } +} + +/// Check a `draft_state` expectation: the state, and the note when the draft +/// awaits evidence, and nothing else. +pub(crate) fn check_draft_state(b: &Books<'_>, x: &Expect) { + check_figures(b, x, b.answer_draft_state(&x.query())); +} + +/// Check an `evidence` expectation: the decision and why, both given. +pub(crate) fn check_evidence(b: &Books<'_>, x: &Expect) { + check_figures(b, x, b.answer_evidence(&x.query())); +} diff --git a/crates/ledger-core/tests/bookspec/queries/mod.rs b/crates/ledger-core/tests/bookspec/queries/mod.rs index 8ad9af2c..87abcf98 100644 --- a/crates/ledger-core/tests/bookspec/queries/mod.rs +++ b/crates/ledger-core/tests/bookspec/queries/mod.rs @@ -4,6 +4,7 @@ pub(crate) mod assets; pub(crate) mod commands; pub(crate) mod dates; pub(crate) mod documents; +pub(crate) mod drafts; pub(crate) mod formats; pub(crate) mod parties; pub(crate) mod statements; @@ -89,6 +90,8 @@ impl Books<'_> { "document_dates" => self.answer_document_dates(q), "document" => self.answer_document(q), "invoice_numbers" => self.answer_invoice_numbers(q), + "draft_state" => self.answer_draft_state(q), + "evidence" => self.answer_evidence(q), "run" => self.answer_run(q), "disposal" => self.answer_disposal(q), "depreciation_schedule" => self.answer_depreciation_schedule(q), From d889f2e7fba75fbfc3ebe96cd6c7c1c7cdb9f422 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Mon, 9 Nov 2026 03:44:13 -0700 Subject: [PATCH 10/15] docs(claims): the draft and evidence examples are checked lines B-1 (BS-entry-1, BS-entry-6), B-43 (BS-entry-5) and B-20 (BS-ledger-7, BS-ledger-17) name the bookspec examples that now show their rules, the real engine functions each runs through, and the examples for the options wanderbooks did not pick, which are skipped. Co-Authored-By: Claude Sonnet 5.5 --- docs/spec/claims/entry.md | 17 +++++++++++++++-- docs/spec/claims/ledger.md | 7 ++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/docs/spec/claims/entry.md b/docs/spec/claims/entry.md index b311d1e2..42ecf20b 100644 --- a/docs/spec/claims/entry.md +++ b/docs/spec/claims/entry.md @@ -21,7 +21,13 @@ more lines, debits = credits exactly); `Ledger::add_line` for the account check at line-adding time (`a_line_on_an_unknown_or_placeholder_account_is_refused_when_added`). **Checked:** Kani `check_lines_is_exact`, `accepted_entry_nets_to_zero`; Lean -`Accepted.net_zero`; property `prop_posted_entries_balance`. +`Accepted.net_zero`; property `prop_posted_entries_balance`; bookspec example +`entry-a-line-on-a-header-is-refused-when-it-is-added` (BS-entry-6, the option +picked: a draft with a line on a header account is refused as the draft is +made, through `Ledger::try_create_entry` and `Ledger::add_line`, and the +refusal read off the engine's `LedgerError::PlaceholderAccount`); the example +`entry-a-line-on-a-header-is-refused-when-the-entry-posts` names the option +not picked and is skipped. ### Product rules @@ -209,7 +215,14 @@ pinned; every tool over every old book). (`draft_states_replay_and_project`, `drafts_v2_waits_for_the_upgrade`, `posted_seq_is_the_posting_lines_seq`); `ledger-cli` `tests/drafts.rs` (`a_draft_waits_for_its_receipt_and_posts`, `a_reversal_needs_no_receipt_of_its_own`, `gui_and_server_gate_agree`, -`stale_preview_refused`). +`stale_preview_refused`); bookspec examples, through `Store::post_entry_checked`, +`Store::set_draft_state`, `Store::attach_receipt`, `Store::discard_draft` and +`ledger_core::evidence::requirement`, each answer read off the engine: +`entry-a-draft-waits-on-its-evidence-and-posts-once-it-has-it`, +`entry-a-discarded-draft-leaves-the-books-unchanged`, +`entry-a-drafts-state-is-a-note-and-a-posted-entry-has-none`, +`period-a-draft-holds-its-period-open-until-it-is-discarded` (BS-period-2's +`LedgerError::DraftsInPeriod`) and `entry-evidence-is-decided-in-one-place`. ### Product rules diff --git a/docs/spec/claims/ledger.md b/docs/spec/claims/ledger.md index 3d642908..cffad93e 100644 --- a/docs/spec/claims/ledger.md +++ b/docs/spec/claims/ledger.md @@ -164,7 +164,12 @@ None. (`a_draft_waits_for_its_receipt_and_posts`, `a_reversal_needs_no_receipt_of_its_own`); `ledger-store` `tests/store.rs` (`draft_states_replay_and_project`, -`drafts_v2_waits_for_the_upgrade`). +`drafts_v2_waits_for_the_upgrade`); bookspec example +`ledger-a-reversal-needs-no-evidence-of-its-own` (BS-ledger-17, the option +picked: a reversal of a 40.00 entry under a policy of over 25.00 posts at once +and `ledger_core::evidence::requirement` exempts it as a reversal); the example +`ledger-a-reversal-carries-its-own-evidence` names the option not picked and is +skipped. ### Product rules From 74fc5532722fcdb684a87d8b3864a4230420889d Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Mon, 9 Nov 2026 04:01:09 -0700 Subject: [PATCH 11/15] docs: the sub-references the review found land on the part that states the claim A review of S-E3 against the pinned bc92cf3 records found citations one part off, and old vocabulary the test could not see. Each is checked against the record's own text: - BS-statement-5: the partition of the P&L is statement 3 (not 2, and not BS-statement-3, the cash-flow statement); the ASC 340-40-25-7/-8 trail (a cost traceable to one job is that job's, several only by a stated allocation) is statement 4, not 6. - BS-asset-1: "one figure everywhere" is statement 31 (28 is the two figures, schedule and books); "disposed only for a disposal dated by then" is statement 30 (and 7 where the schedule stops). - BS-arap-6: one receivable line per invoice, each tagged, is statements 1-2 and invariant 4 (one application per document). - BS-asset-1 statements 8 and 9 for the true-up and the credit back. - BS-arap-2: "nothing unattached, no command adds a hand line" is invariants 2 and 3, beside 1, 6 and 9. - BS-format-2: a class name written differently and reported adds 32. - BS-arap-5: the cash-basis refusal is statement 6, everywhere. - BS-partner-3: statement 3's cases are lettered (a)-(e), not numbered. - BS-asset-1 "rules 23-24 / 25-26" in the claims, "BS-arap-3 SCENARIOS:" and "WB-ledger-15 INVARIANT 3" are in the new vocabulary. Co-Authored-By: Claude Sonnet 5.5 --- crates/ledger-cli/tests/documents.rs | 2 +- crates/ledger-cli/tests/evidence.rs | 2 +- crates/ledger-cli/tests/spec_assets.rs | 2 +- crates/ledger-core/src/tax_capital.rs | 2 +- crates/ledger-core/tests/properties.rs | 2 +- crates/ledger-core/tests/spec_document_projects.rs | 2 +- crates/ledger-core/tests/spec_documents.rs | 9 +++++---- crates/ledger-core/tests/spec_parties.rs | 4 ++-- crates/ledger-core/tests/spec_party_totals.rs | 4 ++-- crates/ledger-package/tests/p3_seams.rs | 2 +- crates/ledger-package/tests/package.rs | 2 +- crates/ledger-store/tests/arap_props.rs | 4 ++-- docs/spec/claims/asset.md | 4 ++-- docs/spec/sources/fasb-asc.md | 4 ++-- docs/testing.md | 4 ++-- 15 files changed, 25 insertions(+), 24 deletions(-) diff --git a/crates/ledger-cli/tests/documents.rs b/crates/ledger-cli/tests/documents.rs index 8daa8312..7d274a24 100644 --- a/crates/ledger-cli/tests/documents.rs +++ b/crates/ledger-cli/tests/documents.rs @@ -989,7 +989,7 @@ mod paying_on_terms { /// One deposit settles two invoices of one customer: one entry, one /// receivable line per invoice, each tagged with its own invoice, and the - /// output names both documents (BS-arap-6 invariant 3 and WB-arap-15). + /// output names both documents (BS-arap-6 statements 1-2 and invariant 4; WB-arap-15, the rows in application order). #[test] fn one_payment_settles_two_invoices() { let mut s = setup("settle-two"); diff --git a/crates/ledger-cli/tests/evidence.rs b/crates/ledger-cli/tests/evidence.rs index 56df3b61..addd1031 100644 --- a/crates/ledger-cli/tests/evidence.rs +++ b/crates/ledger-cli/tests/evidence.rs @@ -318,7 +318,7 @@ fn annotations_and_searches() { assert_eq!(answer_of(&r).unwrap()["status"], "ok"); } -/// Plan P6 step 4 and WB-ledger-15 INVARIANT 3: consolidation never leaves an +/// Plan P6 step 4 and WB-ledger-15 invariant 3: consolidation never leaves an /// entry the receipt policy covers with no evidence. #[test] fn consolidation_never_removes_an_entrys_only_evidence() { diff --git a/crates/ledger-cli/tests/spec_assets.rs b/crates/ledger-cli/tests/spec_assets.rs index 685cd384..1ed3e3ca 100644 --- a/crates/ledger-cli/tests/spec_assets.rs +++ b/crates/ledger-cli/tests/spec_assets.rs @@ -1501,7 +1501,7 @@ fn dispose_args(x: u64, date: &str, proceeds: &str) -> Value { /// days, 500.00 (the final depreciation); accumulated 5,500.00, book value /// 6,500.00, gain 500.00. Afterwards books.asset_schedule ends there, and /// books.list_assets lists it as gone: not held, every figure 0.00 (it -/// left the books with its disposal; BS-asset-1 statement 28). Before P3 the +/// left the books with its disposal; BS-asset-1 statements 7 and 30). Before P3 the /// schedule showed June 7,000.00, accumulated 12,000.00, book value 0.00. #[test] fn a_disposed_asset_lists_what_it_depreciated_through_its_disposal() { diff --git a/crates/ledger-core/src/tax_capital.rs b/crates/ledger-core/src/tax_capital.rs index e36cbceb..8cb33d22 100644 --- a/crates/ledger-core/src/tax_capital.rs +++ b/crates/ledger-core/src/tax_capital.rs @@ -89,7 +89,7 @@ use rust_decimal::Decimal; /// `[start, end]`: its lines on the asset's depreciation expense account, /// debit-positive (the depreciation still due through the disposal day, /// or, negative, what the month's run posted past it, credited back: -/// BS-asset-1 statement 9). With the runs +/// BS-asset-1 statements 8 and 9). With the runs /// (`Ledger::depreciation_posted_between`) it is the asset's depreciation /// expense in the span, the P&L's and the cash flow's (BS-statement-3 statement 13). /// The disposal entry is the posted entry dated the disposal day that diff --git a/crates/ledger-core/tests/properties.rs b/crates/ledger-core/tests/properties.rs index cb1140eb..f759a9c9 100644 --- a/crates/ledger-core/tests/properties.rs +++ b/crates/ledger-core/tests/properties.rs @@ -937,7 +937,7 @@ proptest! { proptest! { #![proptest_config(ProptestConfig::with_cases(256))] - /// BS-statement-5 statement 2: for any tags and any period, the projects' + /// BS-statement-5 statement 3: for any tags and any period, the projects' /// figures plus the untagged lines' are the period's profit and loss /// (no line counted twice or lost), each through /// ledger_core::project_figures. diff --git a/crates/ledger-core/tests/spec_document_projects.rs b/crates/ledger-core/tests/spec_document_projects.rs index 01c823c0..124db74c 100644 --- a/crates/ledger-core/tests/spec_document_projects.rs +++ b/crates/ledger-core/tests/spec_document_projects.rs @@ -6,7 +6,7 @@ //! ```text //! GOAL: a client project's invoiced revenue and a contractor's billed //! cost count toward the project, every other figure as before. -//! SOURCE: BS-statement-5 statements 2 and 6 (job costing), BS-statement-3 (the +//! SOURCE: BS-statement-5 statements 2, 3 and 6 (job costing, and the //! projects with the untagged lines partition the P&L), BS-1099-1 and //! BS-partner-3 (1099 and party figures follow the money, not the tags). //! ``` diff --git a/crates/ledger-core/tests/spec_documents.rs b/crates/ledger-core/tests/spec_documents.rs index cf3e8879..151f33cc 100644 --- a/crates/ledger-core/tests/spec_documents.rs +++ b/crates/ledger-core/tests/spec_documents.rs @@ -1261,7 +1261,7 @@ fn half_paid_rest_written_off_is_written_off() { assert!(check.iter().all(|c| c.difference.is_zero())); } -/// BS-arap-5 invariant 5: a cash-basis company never counted the invoice as +/// BS-arap-5 statement 6: a cash-basis company never counted the invoice as /// income, so it has no basis to deduct (IRC §166; Treas. Reg. /// §1.166-1(e)). #[test] @@ -1502,7 +1502,7 @@ fn days(b: &Books) -> Vec { proptest! { #![proptest_config(ProptestConfig::with_cases(256))] - /// BS-arap-2 invariants 1, 6 and 9 over random histories of creates, + /// BS-arap-2 invariants 1, 2, 3, 6 and 9 over random histories of creates, /// payments, voids, reversals of any entry and refused hand lines: at /// every date the control accounts equal their documents (no /// difference, nothing unattached: no command adds a hand line), each @@ -1691,8 +1691,9 @@ fn custom_terms_are_due_on_the_date_they_give() { assert!(serde_json::from_value::(stray).is_err()); } -/// BS-arap-3 SCENARIOS: Net 30, Net 15 EOM, a leap day, due on receipt, a -/// custom date, and the 9999-12 bound refused instead of panicking. +/// BS-arap-3 scenarios 1-5 (Net 30, Net 15 EOM, a leap day, due on receipt, +/// and the 9999-12 bound refused instead of panicking) and statement 1 (a +/// custom date). #[test] fn terms_derive_due_dates() { let net30 = Terms::new(TermsKind::Net(30), None).unwrap(); diff --git a/crates/ledger-core/tests/spec_parties.rs b/crates/ledger-core/tests/spec_parties.rs index 4f0cb729..a1db34d4 100644 --- a/crates/ledger-core/tests/spec_parties.rs +++ b/crates/ledger-core/tests/spec_parties.rs @@ -1461,10 +1461,10 @@ fn entry_flow_takes_across_in_order_until_used_up() { ); } -/// Oracle: shares::target DEFINITIONS, case 3 (BS-partner-3): members +/// Oracle: shares::target DEFINITIONS (BS-partner-3 statement 3 (c)): members /// named on an entry moving no money split what moved equity, E (here /// −4.00 of a draft not yet balanced), received, in kind (the equipment's -/// 10.00, at most |E|); case 5: with a party named who isn't a member, +/// 10.00, at most |E|); (e): with a party named who isn't a member, /// the total debits, direction neither, counting nothing. #[test] fn a_share_target_without_money_is_the_capital_or_the_debits() { diff --git a/crates/ledger-core/tests/spec_party_totals.rs b/crates/ledger-core/tests/spec_party_totals.rs index bd7bf69a..c08450ab 100644 --- a/crates/ledger-core/tests/spec_party_totals.rs +++ b/crates/ledger-core/tests/spec_party_totals.rs @@ -958,7 +958,7 @@ fn a_card_is_a_recorded_business_card_else_a_liability_named_card() { assert_eq!(b.resolved(on_2050).0.direction, Direction::Neither); } -/// BS-partner-3 statement 3, case 3: E is the movement of equity other than retained +/// BS-partner-3 statement 3 (c): E is the movement of equity other than retained /// earnings, so a members' entry reads as the statement of members' equity /// reads it. Retained earnings given up for equipment moves no member's /// capital: neither, as the statement shows no distribution. Retained @@ -1168,7 +1168,7 @@ fn a_members_entry_keeps_its_reading_after_they_leave() { ); } -/// BS-partner-3 statement 3, case 1: a period's closing entry moves nothing with +/// BS-partner-3 statement 3 (a): a period's closing entry moves nothing with /// anyone: direction neither, its members' part their income allocated /// (credited to their capital: negative), counted in no total. #[test] diff --git a/crates/ledger-package/tests/p3_seams.rs b/crates/ledger-package/tests/p3_seams.rs index 02e35421..9d310a3d 100644 --- a/crates/ledger-package/tests/p3_seams.rs +++ b/crates/ledger-package/tests/p3_seams.rs @@ -445,7 +445,7 @@ fn iif_dates(iif: &str) -> Vec { .collect() } -/// Depreciation is one figure everywhere (BS-asset-1 statement 28, BS-statement-3 statement 13, +/// Depreciation is one figure everywhere (BS-asset-1 statement 31, BS-statement-3 statement 13, /// BS-partner-4): the P&L's expense, the cash flow reconciliation's add-back, the /// tax-basis K-1's open item, the IIF's, and the runs plus what the /// disposal posted; the balance sheet's accumulated depreciation is the diff --git a/crates/ledger-package/tests/package.rs b/crates/ledger-package/tests/package.rs index 3c2423b6..c5a9a420 100644 --- a/crates/ledger-package/tests/package.rs +++ b/crates/ledger-package/tests/package.rs @@ -1717,7 +1717,7 @@ fn one_list_of_cash_accounts_per_package() { assert_eq!(text(&plain, "1099-worksheet-2026.csv"), tool(&cash)); } -/// BS-format-2 statements 27-30 (P3 cutover review, open point 1): the +/// BS-format-2 statements 27-30 and 32 (P3 cutover review, open point 1): the /// package's QuickBooks file declares every project as a class and /// carries each line's project in CLASS; a project name written /// differently is listed in the warnings and the README, whose IIF line diff --git a/crates/ledger-store/tests/arap_props.rs b/crates/ledger-store/tests/arap_props.rs index bd613da8..3d56f14c 100644 --- a/crates/ledger-store/tests/arap_props.rs +++ b/crates/ledger-store/tests/arap_props.rs @@ -1,4 +1,4 @@ -//! Documents through the store, at random (BS-arap-2 invariants 1, 6, 7 and 9; plan P4b.15): histories of invoices, bills, payments (with a +//! Documents through the store, at random (BS-arap-2 invariants 1, 2, 3, 6, 7 and 9; plan P4b.15): histories of invoices, bills, payments (with a //! payment method and a reference, or none), voids, reversals of any //! entry, closed months and refused hand lines, run through `Store`, then //! replayed (the books reopened) and read by a `Snapshot`. @@ -8,7 +8,7 @@ //! the live books, their replay and a viewer's snapshot agree on //! every figure, at every date, and the control accounts equal //! their documents. -//! SOURCE: BS-entry-4 (replay), BS-arap-2 invariants 1, 6, 7 and 9. +//! SOURCE: BS-entry-4 (replay), BS-arap-2 invariants 1, 2, 3, 6, 7 and 9. //! ``` use chrono::NaiveDate; diff --git a/docs/spec/claims/asset.md b/docs/spec/claims/asset.md index 8c6cb606..cbf513c7 100644 --- a/docs/spec/claims/asset.md +++ b/docs/spec/claims/asset.md @@ -78,14 +78,14 @@ dates, `accumulated_posted` and its edges, ### Product rules -**WB-asset-1** The bounds `BS-asset-1` states (rules 25-26: a new link to +**WB-asset-1** The bounds `BS-asset-1` states (statements 25-26: a new link to an entry dated after the in-service date or the disposal is refused, as is a new in-service date before the linked entry's date, and a disposal dated before the acquired date is refused) are the commands', never replay's (B-28): a journal an earlier version wrote replays as written, whatever those dates say. (That depreciation starts on the in-service date and that the register holds the asset from the acquired date are `BS-asset-1` -rules 23-24.) +statements 23-24.) *Enforced:* `set_asset_acquisition` / `replay_set_asset_acquisition`, `Ledger::asset_acquired_date`, `dispose_asset`, `Ledger::set_asset_acquisition`. *Checked:* `ledger-core` `tests/spec_asset_basis.rs` (each bound and its diff --git a/docs/spec/sources/fasb-asc.md b/docs/spec/sources/fasb-asc.md index 928236b3..bef5b33c 100644 --- a/docs/spec/sources/fasb-asc.md +++ b/docs/spec/sources/fasb-asc.md @@ -294,7 +294,7 @@ to recover its costs from, so its costs are expensed as incurred. ## 340-40-25-7 (Costs that relate directly to a contract) -Added 2026-10-22 for BS-statement-5 statement 6 as the DART revenue roadmap sets it +Added 2026-10-22 for BS-statement-5 statement 4 as the DART revenue roadmap sets it out; not re-read in the ASC basic view: check it there at the next reading. The costs that "relate directly to a contract" (25-5(a)) are (a) direct labor, (b) direct materials, (c) allocations of costs that @@ -314,7 +314,7 @@ the contract), costs of wasted materials, labor or other resources not reflected in the contract's price, costs that relate to satisfied (or partly satisfied) performance obligations, and costs the entity cannot tell apart between satisfied and unsatisfied obligations. -→ BS-statement-5 statement 6 (with 25-7): a cost traceable to one job (25-7(a), (b), +→ BS-statement-5 statement 4 (with 25-7): a cost traceable to one job (25-7(a), (b), (d), (e)) is that job's, whole, on the document's line; a cost that relates to several jobs reaches them only by an allocation on a stated basis (25-7(c)), which the books record as the allocation convention's diff --git a/docs/testing.md b/docs/testing.md index 974039d6..9613fc4f 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -1766,7 +1766,7 @@ bookspec's rules / `docs/spec/claims/` say why not. Mutation runs wait for P12 ( loss, not its depreciation (BS-statement-3 statement 13; `a_disposals_depreciation_credit_back_is_depreciation`), and the tax-basis K-1's book depreciation left it out (BS-partner-4); `books.list_assets` - as of a day said "disposed" for a later disposal (BS-asset-1 statement 28). + as of a day said "disposed" for a later disposal (BS-asset-1 statement 30). ## P3: the surface review (2026-10-21) @@ -3359,7 +3359,7 @@ in the same call. `half_paid_rest_written_off_is_written_off` (BS-arap-2 scenario 7: 50 paid, 50 written off, one balanced entry Dr 6990 / Cr 1200, the receivable line tagged `WriteOff`, receivables down by exactly the write-off); - `write_off_refused_on_cash_basis` (BS-arap-5 invariant 5: refused, the + `write_off_refused_on_cash_basis` (BS-arap-5 statement 6: refused, the snapshot unchanged, no draft left); `write_off_above_outstanding_refused` (the bound at the day, a zero and a negative amount, then the exact amount owed taken); `write_off_then_recovery_same_year` (D-49: the From dfdb066245f7c30d2ca698c18b2f62522701db60 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Mon, 9 Nov 2026 04:01:09 -0700 Subject: [PATCH 12/15] test(core): the sub-reference test sees every old form, and checks product rules - An id closed by a backtick before the part word (`BS-asset-1` rules 23), the filler "states (rules 25-26", and a bare spec-block word on the id's line (BS-arap-3 SCENARIOS:) now fail as old vocabulary; each has a self-test. - Product rules (WB--) are checked: the numbered INVARIANTS: and SCENARIOS: lists in docs/spec/claims/*.md are parsed (a list that does not count 1, 2, 3 fails the parse), and WB-ledger-15 invariant 3 is checked like a bookspec part. A product rule with no list takes no sub-number, and has no statements. - Counting: every member of a range and every number of a list is one reference ("27-30" is 4); a backwards range fails. The floor is exactly the number found, 361. Co-Authored-By: Claude Sonnet 5.5 --- crates/ledger-core/tests/bookspec/sub_refs.rs | 265 ++++++++++++++++-- 1 file changed, 236 insertions(+), 29 deletions(-) diff --git a/crates/ledger-core/tests/bookspec/sub_refs.rs b/crates/ledger-core/tests/bookspec/sub_refs.rs index d88663f4..9e94b461 100644 --- a/crates/ledger-core/tests/bookspec/sub_refs.rs +++ b/crates/ledger-core/tests/bookspec/sub_refs.rs @@ -9,13 +9,21 @@ //! pinned record has (k from 1 to the length of that list), and the old //! vocabulary (`item`, `rule`, `INVARIANT`, `SCENARIO`, `r`, or any //! other word that is not exactly `statement`, `invariant` or -//! `scenario`) after a bookspec id, followed by a number, fails. +//! `scenario`) after a bookspec id fails, whether a number follows it or +//! the word stands bare (`BS-arap-3 SCENARIOS: ...`, on the id's line). +//! +//! A product rule's id (`WB--`) takes the same check against the +//! parts its own claim states: the numbered `INVARIANTS:` and +//! `SCENARIOS:` lists of its spec block in `docs/spec/claims/*.md`. A +//! product rule with no such list takes no sub-number, and has no +//! statements (those are bookspec's). //! //! A reference may be a list ("statements 5, 11 and 13"), a range //! ("statements 27-30"), parenthesised, wrapped across lines behind a -//! comment prefix, or continued on the same id ("invariant 2 and -//! statement 11"); each number is one reference checked. The number -//! checked is floored and printed. This file is not scanned: its +//! comment prefix, backticked after the id (`` `BS-asset-1` statements +//! 23-24 ``), or continued on the same id ("invariant 2 and statement +//! 11"); each number, each member of a range, is one reference checked. +//! The count is floored and printed. This file is not scanned: its //! self-tests quote the forms they must refuse. use crate::*; @@ -24,16 +32,17 @@ fn repo_root() -> PathBuf { Path::new(env!("CARGO_MANIFEST_DIR")).join("../..") } -/// How many references the scan must find, at least. Raise it, in the -/// same commit, when references are added; it never falls. -const CHECKED_FLOOR: usize = 320; +/// How many references the scan must find, at least: exactly the number +/// found when it was last set, so none can vanish silently. Raise it, in +/// the same commit, when references are added; it never falls. +const CHECKED_FLOOR: usize = 361; /// The tracked file this check does not scan: its own self-tests quote /// the forms it refuses. const SELF: &str = "crates/ledger-core/tests/bookspec/sub_refs.rs"; /// The parts a record has: its statements, invariants and scenarios. -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Default)] struct Parts { statements: usize, invariants: usize, @@ -56,6 +65,84 @@ fn record_parts() -> BTreeMap { .collect() } +/// The parts each product rule `WB--` states in +/// `docs/spec/claims/*.md`: under its `**WB-…**` paragraph, the numbered +/// items (` 1. …`) below `INVARIANTS:` and below `SCENARIOS:`. A list +/// must count 1, 2, 3, … : an irregular one is a failure, not a guess. +fn product_rule_parts(root: &Path) -> BTreeMap { + let dir = root.join("docs/spec/claims"); + let mut files: Vec = std::fs::read_dir(&dir) + .expect("docs/spec/claims exists") + .map(|e| e.expect("a directory entry").path()) + .filter(|p| p.extension().is_some_and(|x| x == "md")) + .collect(); + files.sort(); + let mut out: BTreeMap = BTreeMap::new(); + for file in files { + let text = std::fs::read_to_string(&file).expect("a claims file reads"); + let mut current: Option = None; + // 'i' under INVARIANTS:, 'c' under SCENARIOS:, none elsewhere. + let mut mode: Option = None; + for line in text.lines() { + if let Some(rest) = line.strip_prefix("**WB-") { + let id: String = rest.chars().take_while(|c| *c != '*').collect(); + current = Some(format!("WB-{id}")); + out.entry(format!("WB-{id}")).or_default(); + mode = None; + continue; + } + if line.starts_with('#') { + current = None; + mode = None; + continue; + } + let Some(id) = ¤t else { continue }; + if line == "INVARIANTS:" { + mode = Some('i'); + } else if line == "SCENARIOS:" { + mode = Some('c'); + } else if line.starts_with("```") + || line.split_once(':').is_some_and(|(head, _)| { + !head.is_empty() && head.chars().all(|c| c.is_ascii_uppercase()) + }) + { + mode = None; + } else if let Some(kind) = mode { + let digits: String = line + .strip_prefix(" ") + .unwrap_or("") + .chars() + .take_while(|c| c.is_ascii_digit()) + .collect(); + if !digits.is_empty() && line[2 + digits.len()..].starts_with(". ") { + let p = out.get_mut(id).expect("the rule was entered"); + let count = if kind == 'i' { + &mut p.invariants + } else { + &mut p.scenarios + }; + assert_eq!( + digits.parse::().ok(), + Some(*count + 1), + "{}: {id}'s numbered list counts 1, 2, 3, ...: {line:?}", + file.display() + ); + *count += 1; + } + } + } + } + out +} + +/// Every id a part can be cited on: bookspec's records and the product +/// rules of the claims. +fn all_parts() -> BTreeMap { + let mut parts = record_parts(); + parts.extend(product_rule_parts(&repo_root())); + parts +} + /// The text with each line's comment prefix and indentation dropped and /// the lines joined by one space, so a reference wrapped across lines /// reads as one; and the byte offset where each line starts in it. @@ -171,17 +258,32 @@ fn number_list(tail: &[char], start: usize) -> (Vec<(usize, usize)>, usize) { (out, at) } +/// How many references a list of (low, high) numbers is: each number, each +/// member of a range, once. A range that runs backwards is one. +fn count_of(nums: &[(usize, usize)]) -> usize { + nums.iter() + .map(|&(low, high)| if high >= low { high - low + 1 } else { 1 }) + .sum() +} + /// Scan `text`; returns the references checked and the problems found. fn scan(text: &str, at: &str, parts: &BTreeMap) -> (usize, Vec) { let (flat, starts) = flatten(text); let mut checked = 0usize; let mut problems = Vec::new(); - for (pos, _) in flat.match_indices("BS-") { + let mut hits: Vec<(usize, &str)> = ["BS-", "WB-"] + .iter() + .flat_map(|prefix| flat.match_indices(prefix).map(|(pos, _)| (pos, *prefix))) + .collect(); + hits.sort(); + for (pos, prefix) in hits { if flat[..pos].chars().next_back().is_some_and(is_id_char) { continue; } - let rest: Vec = flat[pos + 3..].chars().take(240).collect(); - // BS-- + let after = &flat[pos + 3..]; + let rest: Vec = after.chars().take(240).collect(); + let offsets: Vec = after.char_indices().map(|(b, _)| b).take(240).collect(); + // -- let mut i = 0; while i < rest.len() && (rest[i].is_ascii_lowercase() || rest[i].is_ascii_digit()) { i += 1; @@ -199,9 +301,13 @@ fn scan(text: &str, at: &str, parts: &BTreeMap) -> (usize, Vec) -> (usize, Vec = filler.chars().collect(); + if rest.len() >= i + w.len() && rest[i..i + w.len()] == w[..] { + i += w.len(); + break; + } + } if rest.get(i) == Some(&'(') { i += 1; } @@ -230,6 +343,17 @@ fn scan(text: &str, at: &str, parts: &BTreeMap) -> (usize, Vec 1 && word == word.to_ascii_uppercase(); + if first && kind.is_some() && !new && upper && shown_line == Some(line) { + problems.push(format!( + "{at}:{line}: {id} {word}: the old vocabulary; say `statements`, `invariants` or `scenarios` k-m, as bookspec numbers its parts" + )); + } break; } let (nums, end) = number_list(&rest, i + 1); @@ -244,19 +368,16 @@ fn scan(text: &str, at: &str, parts: &BTreeMap) -> (usize, Vec (p.invariants, "invariants"), _ => (p.scenarios, "scenarios"), }; + checked += count_of(&nums); for (low, high) in &nums { - checked += 1; - if *high != *low { - checked += 1; - } - if *low < 1 || *high < 1 || *low > have || *high > have { + if *low < 1 || *high < *low || *high > have { problems.push(format!( "{at}:{line}: {id} {shown}: the record has {have} {name}" )); } } } else { - checked += nums.len(); + checked += count_of(&nums); problems.push(format!("{at}:{line}: {id} {shown}: no such rule")); } i = end; @@ -277,7 +398,6 @@ fn scan(text: &str, at: &str, parts: &BTreeMap) -> (usize, Vec Vec<(String, String)> { #[test] pub(crate) fn every_sub_reference_names_a_part_its_record_has() { - let parts = record_parts(); + let parts = all_parts(); assert!(!parts.is_empty(), "the pinned bookspec has records"); let root = repo_root(); let mut checked = 0usize; @@ -331,7 +451,7 @@ pub(crate) fn every_sub_reference_names_a_part_its_record_has() { } fn problems_in(text: &str) -> Vec { - scan(text, "t", &record_parts()).1 + scan(text, "t", &all_parts()).1 } #[test] @@ -344,22 +464,22 @@ pub(crate) fn a_statement_the_record_lacks_fails() { assert_eq!(problems_in("BS-entry-1 scenario 2").len(), 1); assert_eq!(problems_in("BS-nosuch-9 statement 1").len(), 1); assert_eq!( - scan("BS-entry-1 statement 4", "t", &record_parts()), + scan("BS-entry-1 statement 4", "t", &all_parts()), (1, vec![]) ); assert_eq!( - scan("BS-entry-1 invariant 4", "t", &record_parts()), + scan("BS-entry-1 invariant 4", "t", &all_parts()), (1, vec![]) ); assert_eq!( - scan("BS-entry-1 scenario 1", "t", &record_parts()), + scan("BS-entry-1 scenario 1", "t", &all_parts()), (1, vec![]) ); } #[test] pub(crate) fn lists_ranges_wraps_and_continuations_are_each_checked() { - let parts = record_parts(); + let parts = all_parts(); // Every number of a list or range, in the parentheses a comment gives. assert_eq!( scan("(BS-entry-1 statements 1, 2 and 4)", "t", &parts), @@ -367,7 +487,15 @@ pub(crate) fn lists_ranges_wraps_and_continuations_are_each_checked() { ); assert_eq!(problems_in("(BS-entry-1 statements 1, 2 and 9)").len(), 1); assert_eq!(problems_in("BS-entry-1 statements 2-9").len(), 1); - assert_eq!(scan("BS-entry-1 statements 1-4", "t", &parts).0, 2); + // A range counts each of its members; a list each of its numbers. + assert_eq!(scan("BS-entry-1 statements 1-4", "t", &parts), (4, vec![])); + assert_eq!( + scan("BS-entry-1 statements 1-2 and 4", "t", &parts), + (3, vec![]) + ); + assert_eq!(problems_in("BS-entry-1 statements 3-2").len(), 1); + assert_eq!(problems_in("BS-nosuch-9 statements 1-3").len(), 1); + assert_eq!(scan("BS-nosuch-9 statements 1-3", "t", &parts).0, 3); // A reference wrapped across a comment prefix reads as one. assert_eq!(problems_in("/// (BS-entry-1\n/// statement 99)").len(), 1); assert_eq!(problems_in("//! BS-entry-1 statement\n//! 99").len(), 1); @@ -416,7 +544,86 @@ pub(crate) fn the_old_vocabulary_fails() { ] { assert_eq!(problems_in(old).len(), 1, "{old:?} fails"); } - // A product-rule id is no bookspec id, and a bare word is no reference. - assert_eq!(problems_in("WB-entry-1 item 2").len(), 0); + // A bare word with no number is no better. + assert_eq!(problems_in("BS-arap-3 SCENARIOS: Net 30, Net 15").len(), 1); + assert_eq!( + problems_in("/// BS-arap-3 INVARIANTS: the due date").len(), + 1 + ); + assert_eq!(problems_in("BS-arap-3 SCENARIO").len(), 1); + // But only on the id's own line, as the text of a spec block runs on + // from its SOURCE line to the next heading. + assert_eq!( + problems_in("SOURCE: BS-arap-3\nSCENARIOS:\n 1. a").len(), + 0 + ); + assert_eq!(problems_in("SOURCE: BS-arap-3.\nINVARIANTS:").len(), 0); +} + +#[test] +pub(crate) fn the_old_vocabulary_fails_after_a_closing_backtick() { + for old in [ + "`BS-asset-1` rules 23-24", + "(… are `BS-asset-1` rules 23-24.)", + "`BS-asset-1` states (rules 25-26: the dates)", + "`BS-asset-1`'s item 3", + "`BS-asset-1`, INVARIANT 2", + ] { + assert_eq!(problems_in(old).len(), 1, "{old:?} fails"); + } + // The new vocabulary behind a backtick is checked like any other. + let parts = all_parts(); + assert_eq!( + scan("`BS-asset-1` statements 23-24", "t", &parts), + (2, vec![]) + ); + assert_eq!( + scan( + "`BS-asset-1` states (statements 25-26: the dates)", + "t", + &parts + ), + (2, vec![]) + ); + assert_eq!(problems_in("`BS-asset-1` statements 23-99").len(), 1); + // Prose after a backticked id is no reference. + assert_eq!( + scan("`BS-asset-1` states that a rule holds", "t", &parts), + (0, vec![]) + ); +} + +#[test] +pub(crate) fn product_rule_parts_are_the_numbered_lists_of_their_claims() { + let parts = all_parts(); + // WB-ledger-15 states six invariants and seven scenarios. + let p = parts + .get("WB-ledger-15") + .expect("WB-ledger-15 is a product rule"); + assert_eq!((p.invariants, p.scenarios, p.statements), (6, 7, 0)); + assert_eq!(scan("WB-ledger-15 invariant 3", "t", &parts), (1, vec![])); + assert_eq!( + scan("WB-ledger-15 invariants 1-6 and scenario 7", "t", &parts), + (7, vec![]) + ); + assert_eq!(problems_in("WB-ledger-15 invariant 7").len(), 1); + assert_eq!(problems_in("WB-ledger-15 scenario 8").len(), 1); + // A product rule has no statements of bookspec's kind. + assert_eq!(problems_in("WB-ledger-15 statement 1").len(), 1); + // The old vocabulary fails here too. + assert_eq!(problems_in("WB-ledger-15 INVARIANT 3").len(), 1); + assert_eq!(problems_in("WB-ledger-15 item 2").len(), 1); + assert_eq!(problems_in("`WB-ledger-15` rule 2").len(), 1); + // A product rule that states no list takes no sub-number. + let (id, p) = parts + .iter() + .find(|(id, p)| id.starts_with("WB-") && p.invariants == 0 && p.scenarios == 0) + .expect("some product rule states no list"); + assert_eq!(problems_in(&format!("{id} invariant 1")).len(), 1, "{id}"); + assert_eq!((p.statements, p.invariants), (0, 0)); + // And one that does not exist takes none either. + assert_eq!(problems_in("WB-nosuch-9 invariant 1").len(), 1); + // A bare product-rule id is no sub-reference. + assert_eq!(problems_in("WB-ledger-15").len(), 0); assert_eq!(problems_in("the INVARIANT 2 of kernel::settle").len(), 0); } From 56461c1bb6fab6db70d32996d1748742aa45afd3 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Mon, 9 Nov 2026 04:23:10 -0700 Subject: [PATCH 13/15] test(core): the adapter's refused hand entries go through a real Store, and payroll is its own source A hand entry the example says is refused when posted at once was made on a clone of the Ledger and the receipt-gate error hand-built from `evidence::requirement`, as `Store::post_entry_checked` builds it: the adapter, not the engine, produced the refusal. A store journals a draft the moment it is made, so the entry is now made, lined and posted on a rehearsal: the books replayed from their journal into a Store of their own (the journal and blobs copied, opened as any store is), and posted through `post_entry_checked` under a policy, `post_entry` otherwise. The refusal is the engine's own (ReceiptRequired included) and the example's books keep nothing. A payroll run or tax remittance is exempt by its own source, so the engine's "a payroll ..." sentence now reads as bookspec's new `payroll_posting`, not `document_entry`. A draft reversal, which wanderbooks has no path for, is returned as an unsupported-operation error (reported as "another refusal"), not a panic that takes the harness down with it. The claims for B-43 name the new example, entry-only-a-draft-can-be-posted-or- discarded (a posted entry or a discarded draft is no draft), and the rehearsal. Needs bookspec's x-h1c commits (payroll_posting, the new example, the 25.00 threshold example); the pin moves when they land. Co-Authored-By: Claude Sonnet 5.5 --- crates/ledger-core/tests/bookspec/books.rs | 65 +++++++++++++++++++ crates/ledger-core/tests/bookspec/events.rs | 52 +++++++-------- .../tests/bookspec/queries/drafts.rs | 7 +- docs/spec/claims/entry.md | 9 ++- 4 files changed, 100 insertions(+), 33 deletions(-) diff --git a/crates/ledger-core/tests/bookspec/books.rs b/crates/ledger-core/tests/bookspec/books.rs index 1e5f4030..29c794a5 100644 --- a/crates/ledger-core/tests/bookspec/books.rs +++ b/crates/ledger-core/tests/bookspec/books.rs @@ -216,6 +216,50 @@ pub(crate) fn new_schedule( } } +/// A store of the books as they stood (see [`Books::rehearsal`]), and the +/// directory it lives in, which goes with it. +pub(crate) struct Rehearsal { + store: Store, + _dir: tempfile::TempDir, +} + +impl std::ops::Deref for Rehearsal { + type Target = Store; + fn deref(&self) -> &Store { + &self.store + } +} + +impl std::ops::DerefMut for Rehearsal { + fn deref_mut(&mut self) -> &mut Store { + &mut self.store + } +} + +/// Copy the directory `from` to `to`, the entries `keep` names (by file +/// name) only, subdirectories whole. +fn copy_tree( + from: &std::path::Path, + to: &std::path::Path, + keep: &dyn Fn(&str) -> bool, +) -> std::io::Result<()> { + std::fs::create_dir_all(to)?; + for entry in std::fs::read_dir(from)? { + let entry = entry?; + let name = entry.file_name(); + if !keep(&name.to_string_lossy()) { + continue; + } + let target = to.join(&name); + if entry.file_type()?.is_dir() { + copy_tree(&entry.path(), &target, &|_| true)?; + } else { + std::fs::copy(entry.path(), target)?; + } + } + Ok(()) +} + impl<'a> Books<'a> { /// The books an example sets up, before any event: its shape checked, /// its accounts, fixed assets, schedules, parties, members, payees, @@ -559,6 +603,27 @@ impl<'a> Books<'a> { /// The entry event `event` (counting from 1) posted: an event applied /// already, that posted exactly one. + /// The books as they stand, replayed from their journal into a store of + /// their own (a copy of the journal and the blobs, opened as any store + /// is), for a step the books must refuse without keeping a trace: a store + /// journals a draft the moment it is made, so a refused entry is made on + /// this and dropped with it. The directory lives as long as the store. + pub(crate) fn rehearsal(&self, what: &str) -> Rehearsal { + let from = self._dir.path().join("books"); + let dir = tempfile::tempdir().unwrap(); + let to = dir.path().join("books"); + // The journal is the books; the database is derived, and the lock is + // this process's own. + copy_tree(&from, &to, &|name| { + name != ledger_store::store::LOCK_FILE + && !ledger_store::store::is_database_file(name) + && !name.contains(".db-") + }) + .unwrap_or_else(|e| panic!("{what}: copying the books for a rehearsal: {e}")); + let store = took(Store::open(&to), &format!("{what}: the rehearsal")); + Rehearsal { store, _dir: dir } + } + pub(crate) fn entry_of(&self, event: usize, what: &str) -> EntryId { assert!( event >= 1 && event <= self.posted.len(), diff --git a/crates/ledger-core/tests/bookspec/events.rs b/crates/ledger-core/tests/bookspec/events.rs index 6958fdc7..6d8fdf08 100644 --- a/crates/ledger-core/tests/bookspec/events.rs +++ b/crates/ledger-core/tests/bookspec/events.rs @@ -402,9 +402,14 @@ impl Books<'_> { } Ok(()) } - "reverses" if e.draft => panic!( - "{what}: wanderbooks has no draft reversal: it picks reversal-evidence-is-originals (BS-ledger-17), under which a reversal posts at once" - ), + // Not a panic: the example fails as an engine refusal (`another + // refusal: ...`), and the harness goes on to report it. + "reverses" if e.draft => Err(StoreError::Io(std::io::Error::new( + std::io::ErrorKind::Unsupported, + format!( + "{what}: wanderbooks has no draft reversal: it picks reversal-evidence-is-originals (BS-ledger-17), under which a reversal posts at once" + ), + ))), "post_draft" => { let p = e.post_draft.as_ref().expect("checked: a post"); let entry = self.entry_of(p.entry, what); @@ -453,10 +458,16 @@ impl Books<'_> { } "lines" if e.refused.is_some() => { // The books take an entry whole or not at all, so a - // refused one leaves no draft behind: it is tried on a - // clone, which is how the engine refuses it. - let mut probe = self.store.ledger().clone(); - let entry = probe.create_entry(day(), description); + // refused one leaves no draft behind. The store journals a + // draft the moment it is made, so the entry is made, lined + // and posted on a rehearsal: the same books, replayed from + // their journal into a store of their own, which the engine + // refuses through its own gate (`post_entry_checked` under a + // policy, the server's path for a hand entry) and which is + // then thrown away. The refusal is the engine's, never + // rebuilt here. + let mut rehearsal = self.rehearsal(what); + let entry = rehearsal.create_entry(day(), description)?; for (i, line) in e.lines.iter().enumerate() { let side = match line.side.as_str() { "debit" => Side::Debit, @@ -465,36 +476,19 @@ impl Books<'_> { }; let amount = Money::new(money(&line.amount), self.currency); let account = self.id(&line.account); - probe.add_line(entry, account, side, amount)?; + rehearsal.add_line(entry, account, side, amount)?; if let Some(p) = &line.project { let class = *self.projects.get(p).unwrap_or_else(|| { panic!("{what}: project {p:?} not in setup.projects") }); - probe.set_line_class(entry, i, Some(class))?; + rehearsal.set_line_class(entry, i, Some(class))?; } } - // The evidence gate, as the server's post runs it: a hand entry - // the policy covers has no document, and an event cannot - // attach one before the entry exists. if self.has_policy() { - let draft = probe.get_entry(entry).expect("just drafted").clone(); - let settings = probe.settings(); - if let ledger_core::evidence::Requirement::Required { reason } = - ledger_core::evidence::requirement(&probe, &draft, settings) - { - let policy = ledger_core::evidence::Policy::from_settings(settings); - return Err(StoreError::ReceiptRequired(Box::new( - ledger_store::error::ReceiptRequiredInfo { - entry_id: entry, - debits: ledger_core::evidence::Policy::entry_debits(&draft).ok(), - policy: policy.describe(), - split_group: policy.split_group(&probe, entry, &draft), - reason, - }, - ))); - } + rehearsal.post_entry_checked(entry) + } else { + rehearsal.post_entry(entry) } - Ok(probe.post_entry(entry)?) } "lines" => { let post = |this: &mut Self| -> Result<(), StoreError> { diff --git a/crates/ledger-core/tests/bookspec/queries/drafts.rs b/crates/ledger-core/tests/bookspec/queries/drafts.rs index de7f8897..c32d279b 100644 --- a/crates/ledger-core/tests/bookspec/queries/drafts.rs +++ b/crates/ledger-core/tests/bookspec/queries/drafts.rs @@ -49,9 +49,10 @@ impl Books<'_> { s if s.starts_with("a schedule month's posting") => "schedule_posting", s if s.starts_with("a depreciation run") => "depreciation_run", s if s.starts_with("an asset's disposal") => "asset_disposal", - s if s.starts_with("a document's entry") || s.starts_with("a payroll") => { - "document_entry" - } + // A payroll command's posting (a run, or the tax + // remittance) is its own source, not a document's. + s if s.starts_with("a payroll") => "payroll_posting", + s if s.starts_with("a document's entry") => "document_entry", other => { return Err(engine_refusal( RuleId::new(Area::Entry, 5), diff --git a/docs/spec/claims/entry.md b/docs/spec/claims/entry.md index 42ecf20b..c1556792 100644 --- a/docs/spec/claims/entry.md +++ b/docs/spec/claims/entry.md @@ -222,7 +222,14 @@ pinned; every tool over every old book). `entry-a-discarded-draft-leaves-the-books-unchanged`, `entry-a-drafts-state-is-a-note-and-a-posted-entry-has-none`, `period-a-draft-holds-its-period-open-until-it-is-discarded` (BS-period-2's -`LedgerError::DraftsInPeriod`) and `entry-evidence-is-decided-in-one-place`. +`LedgerError::DraftsInPeriod`), `entry-evidence-is-decided-in-one-place` and +`entry-only-a-draft-can-be-posted-or-discarded` (`LedgerError::EntryAlreadyPosted` +and `LedgerError::UnknownEntry`, through `Store::post_entry` and `Store::discard_draft`). An entry the example +says is refused when posted at once is made, lined and posted on a rehearsal: +the books replayed from their journal into a `Store` of their own (the +journal and the blobs copied, `Store::open`), so the refusal, an evidence +refusal included, is `Store::post_entry_checked`'s own and the example's books +keep no draft the engine would have journaled. ### Product rules From ef9995ebedfa55395b98639966446edb04143dd1 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Mon, 9 Nov 2026 04:34:41 -0700 Subject: [PATCH 14/15] test(core): the sub-reference self-tests read their bounds from the record They hard-coded BS-entry-1's four statements and one scenario; X-H1c moved a choice's statement out of BS-entry-1, an authority rule, into BS-entry-6, which owns it, and the self-tests broke on the merge. They now take a record's counts from the pinned bookspec and test one past each, so a record that gains or loses a part moves them with it. Co-Authored-By: Claude Opus 5.5 --- crates/ledger-core/tests/bookspec/sub_refs.rs | 72 ++++++++++--------- 1 file changed, 39 insertions(+), 33 deletions(-) diff --git a/crates/ledger-core/tests/bookspec/sub_refs.rs b/crates/ledger-core/tests/bookspec/sub_refs.rs index 9e94b461..774b6630 100644 --- a/crates/ledger-core/tests/bookspec/sub_refs.rs +++ b/crates/ledger-core/tests/bookspec/sub_refs.rs @@ -456,25 +456,31 @@ fn problems_in(text: &str) -> Vec { #[test] pub(crate) fn a_statement_the_record_lacks_fails() { - // BS-entry-1 has four statements, four invariants and one scenario. - assert_eq!(problems_in("BS-entry-1 statement 99").len(), 1); - assert_eq!(problems_in("BS-entry-1 statement 5").len(), 1); - assert_eq!(problems_in("BS-entry-1 statement 0").len(), 1); - assert_eq!(problems_in("BS-entry-1 invariant 5").len(), 1); - assert_eq!(problems_in("BS-entry-1 scenario 2").len(), 1); - assert_eq!(problems_in("BS-nosuch-9 statement 1").len(), 1); - assert_eq!( - scan("BS-entry-1 statement 4", "t", &all_parts()), - (1, vec![]) - ); - assert_eq!( - scan("BS-entry-1 invariant 4", "t", &all_parts()), - (1, vec![]) - ); - assert_eq!( - scan("BS-entry-1 scenario 1", "t", &all_parts()), - (1, vec![]) - ); + // The bounds come from the pinned record, so a record that gains or + // loses a part moves them with it (BS-entry-1 lost a statement and its + // scenario in X-H1c; a hard-coded four would have broken here). + let parts = all_parts(); + let id = "BS-arap-2"; + let p = parts[id]; + let (s, i, c) = (p.statements, p.invariants, p.scenarios); + assert!(s > 1 && i > 1 && c > 1, "{id} has every kind of part"); + for text in [ + format!("{id} statement {}", s + 50), + format!("{id} statement {}", s + 1), + format!("{id} statement 0"), + format!("{id} invariant {}", i + 1), + format!("{id} scenario {}", c + 1), + "BS-nosuch-9 statement 1".to_string(), + ] { + assert_eq!(problems_in(&text).len(), 1, "{text}"); + } + for text in [ + format!("{id} statement {s}"), + format!("{id} invariant {i}"), + format!("{id} scenario {c}"), + ] { + assert_eq!(scan(&text, "t", &parts), (1, vec![]), "{text}"); + } } #[test] @@ -482,46 +488,46 @@ pub(crate) fn lists_ranges_wraps_and_continuations_are_each_checked() { let parts = all_parts(); // Every number of a list or range, in the parentheses a comment gives. assert_eq!( - scan("(BS-entry-1 statements 1, 2 and 4)", "t", &parts), + scan("(BS-arap-2 statements 1, 2 and 4)", "t", &parts), (3, vec![]) ); - assert_eq!(problems_in("(BS-entry-1 statements 1, 2 and 9)").len(), 1); - assert_eq!(problems_in("BS-entry-1 statements 2-9").len(), 1); + assert_eq!(problems_in("(BS-arap-2 statements 1, 2 and 99)").len(), 1); + assert_eq!(problems_in("BS-arap-2 statements 2-99").len(), 1); // A range counts each of its members; a list each of its numbers. - assert_eq!(scan("BS-entry-1 statements 1-4", "t", &parts), (4, vec![])); + assert_eq!(scan("BS-arap-2 statements 1-4", "t", &parts), (4, vec![])); assert_eq!( - scan("BS-entry-1 statements 1-2 and 4", "t", &parts), + scan("BS-arap-2 statements 1-2 and 4", "t", &parts), (3, vec![]) ); - assert_eq!(problems_in("BS-entry-1 statements 3-2").len(), 1); + assert_eq!(problems_in("BS-arap-2 statements 3-2").len(), 1); assert_eq!(problems_in("BS-nosuch-9 statements 1-3").len(), 1); assert_eq!(scan("BS-nosuch-9 statements 1-3", "t", &parts).0, 3); // A reference wrapped across a comment prefix reads as one. - assert_eq!(problems_in("/// (BS-entry-1\n/// statement 99)").len(), 1); - assert_eq!(problems_in("//! BS-entry-1 statement\n//! 99").len(), 1); + assert_eq!(problems_in("/// (BS-arap-2\n/// statement 99)").len(), 1); + assert_eq!(problems_in("//! BS-arap-2 statement\n//! 99").len(), 1); // A continuation on the same id is checked too, and one in the old // vocabulary fails. assert_eq!( - scan("BS-entry-1 invariant 1 and statement 3", "t", &parts), + scan("BS-arap-2 invariant 1 and statement 3", "t", &parts), (2, vec![]) ); assert_eq!( - problems_in("BS-entry-1 invariant 1 and statement 30").len(), + problems_in("BS-arap-2 invariant 1 and statement 99").len(), 1 ); - assert_eq!(problems_in("BS-entry-1 invariant 1 and item 3").len(), 1); + assert_eq!(problems_in("BS-arap-2 invariant 1 and item 3").len(), 1); // A date or a number after a list is no reference. assert_eq!( - scan("BS-entry-1 statement 2, 2026-11-08", "t", &parts), + scan("BS-arap-2 statement 2, 2026-11-08", "t", &parts), (1, vec![]) ); // Prose that merely follows an id is no sub-reference. assert_eq!( - scan("BS-entry-1 states that a rule holds", "t", &parts), + scan("BS-arap-2 states that a rule holds", "t", &parts), (0, vec![]) ); assert_eq!( - scan("BS-entry-1 rule: debits equal credits", "t", &parts), + scan("BS-arap-2 rule: debits equal credits", "t", &parts), (0, vec![]) ); } From f74eccddfc46a47f24657f0e638fc668ff8be75a Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Mon, 9 Nov 2026 04:34:41 -0700 Subject: [PATCH 15/15] build: pin bookspec at c597c8f, drafts and evidence bookspec main now carries X-H1c: drafts, receipts, discards and the evidence decision as examples, BS-entry-1 without the choice it never owned, payroll its own exemption source. Lean 179 theorems, standard axioms only; 88 of 101 examples run and pass, the other 13 are for options wanderbooks did not pick. Co-Authored-By: Claude Opus 5.5 --- Cargo.lock | 4 ++-- crates/ledger-core/Cargo.toml | 4 ++-- crates/ledger-package/Cargo.toml | 2 +- verify/lean/lake-manifest.json | 4 ++-- verify/lean/lakefile.toml | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 31d4bad4..b9bec485 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -788,7 +788,7 @@ dependencies = [ [[package]] name = "bookspec-checker" version = "0.1.0" -source = "git+https://git.swaits.com/swaits/bookspec?rev=bc92cf3f69c392cefc9bd319b103994b3bfb0d76#bc92cf3f69c392cefc9bd319b103994b3bfb0d76" +source = "git+https://git.swaits.com/swaits/bookspec?rev=c597c8f845377d9eb868f0f4486759baf16eb5ea#c597c8f845377d9eb868f0f4486759baf16eb5ea" dependencies = [ "chrono", "include_dir", @@ -801,7 +801,7 @@ dependencies = [ [[package]] name = "bookspec-runner" version = "0.1.0" -source = "git+https://git.swaits.com/swaits/bookspec?rev=bc92cf3f69c392cefc9bd319b103994b3bfb0d76#bc92cf3f69c392cefc9bd319b103994b3bfb0d76" +source = "git+https://git.swaits.com/swaits/bookspec?rev=c597c8f845377d9eb868f0f4486759baf16eb5ea#c597c8f845377d9eb868f0f4486759baf16eb5ea" dependencies = [ "bookspec-checker", "serde_json", diff --git a/crates/ledger-core/Cargo.toml b/crates/ledger-core/Cargo.toml index 52c43fb9..6ca7faa8 100644 --- a/crates/ledger-core/Cargo.toml +++ b/crates/ledger-core/Cargo.toml @@ -33,8 +33,8 @@ num-rational = "0.4" toml = "1" # The specification lives in its own repository (P13 step 6, D-34, D-65), # pinned to a commit. -bookspec-checker = { git = "https://git.swaits.com/swaits/bookspec", rev = "bc92cf3f69c392cefc9bd319b103994b3bfb0d76" } -bookspec-runner = { git = "https://git.swaits.com/swaits/bookspec", rev = "bc92cf3f69c392cefc9bd319b103994b3bfb0d76" } +bookspec-checker = { git = "https://git.swaits.com/swaits/bookspec", rev = "c597c8f845377d9eb868f0f4486759baf16eb5ea" } +bookspec-runner = { git = "https://git.swaits.com/swaits/bookspec", rev = "c597c8f845377d9eb868f0f4486759baf16eb5ea" } ledger-package = { path = "../ledger-package" } ledger-import = { path = "../ledger-import" } ledger-store = { path = "../ledger-store" } diff --git a/crates/ledger-package/Cargo.toml b/crates/ledger-package/Cargo.toml index 7900b730..f1b1fde4 100644 --- a/crates/ledger-package/Cargo.toml +++ b/crates/ledger-package/Cargo.toml @@ -21,7 +21,7 @@ zip = "9.0.1" workspace = true [dev-dependencies] -bookspec-checker = { git = "https://git.swaits.com/swaits/bookspec", rev = "bc92cf3f69c392cefc9bd319b103994b3bfb0d76" } +bookspec-checker = { git = "https://git.swaits.com/swaits/bookspec", rev = "c597c8f845377d9eb868f0f4486759baf16eb5ea" } proptest = "1" tempfile = "3" toml = "1" diff --git a/verify/lean/lake-manifest.json b/verify/lean/lake-manifest.json index 67758aee..89a6f304 100644 --- a/verify/lean/lake-manifest.json +++ b/verify/lean/lake-manifest.json @@ -5,10 +5,10 @@ "type": "git", "subDir": "lean", "scope": "", - "rev": "bc92cf3f69c392cefc9bd319b103994b3bfb0d76", + "rev": "c597c8f845377d9eb868f0f4486759baf16eb5ea", "name": "bookspec", "manifestFile": "lake-manifest.json", - "inputRev": "bc92cf3f69c392cefc9bd319b103994b3bfb0d76", + "inputRev": "c597c8f845377d9eb868f0f4486759baf16eb5ea", "inherited": false, "configFile": "lakefile.toml"}], "name": "wanderbooks", diff --git a/verify/lean/lakefile.toml b/verify/lean/lakefile.toml index a8e66645..9bf639fc 100644 --- a/verify/lean/lakefile.toml +++ b/verify/lean/lakefile.toml @@ -9,7 +9,7 @@ packagesDir = ".lake/packages" [[require]] name = "bookspec" git = "https://git.swaits.com/swaits/bookspec" -rev = "bc92cf3f69c392cefc9bd319b103994b3bfb0d76" +rev = "c597c8f845377d9eb868f0f4486759baf16eb5ea" subDir = "lean" [[lean_lib]]