diff --git a/crates/ledger-cli/tests/audit.rs b/crates/ledger-cli/tests/audit.rs index b8cd31fd..cd3935f0 100644 --- a/crates/ledger-cli/tests/audit.rs +++ b/crates/ledger-cli/tests/audit.rs @@ -1,10 +1,10 @@ -//! Audits and attestations over the wire (plan P8; rules.md B-45, D-9): +//! Audits and attestations over the wire (plan P8; BS-ledger-13, D-9): //! a deterministic run and workpaper, claims weighed against the bar when //! asked, the CPA package that waits for a counted audit, and books that //! have not declared `audits`. //! //! Expected behavior comes from `docs/mcp-interface.md` ("Tools — audit -//! and attestations") and rules.md B-45. Every call goes through a real +//! and attestations") and BS-ledger-13. Every call goes through a real //! books server as an agent reaches it (`common.rs`). mod common; diff --git a/crates/ledger-cli/tests/documents.rs b/crates/ledger-cli/tests/documents.rs index 4c437816..f7368c28 100644 --- a/crates/ledger-cli/tests/documents.rs +++ b/crates/ledger-cli/tests/documents.rs @@ -2,7 +2,7 @@ //! (common.rs): the preview that writes nothing, the confirm that posts, //! numbers, terms, line accounts, party snapshots and the issued copy filed //! with the invoice (plan/served.md 8.2 P4b S4 item 17; docs/mcp-interface.md -//! "Tools — A/R and A/P"; rules.md B-39, B-40; D-55). +//! "Tools — A/R and A/P"; BS-arap-3, BS-arap-4; D-55). //! //! Every refusal is checked to leave the journal byte for byte as it was. @@ -218,7 +218,7 @@ fn an_invoice_from_issue_to_paid() { } /// A bill keeps the vendor's invoice, names its own accounts, and carries -/// its terms' discount dates (A-10, A-13; B-39). +/// its terms' discount dates (A-10, A-13; BS-arap-3). #[test] fn a_bill_with_its_vendor_invoice_and_terms() { let books = Books::new("documents-bill"); @@ -304,7 +304,7 @@ fn a_bill_with_its_vendor_invoice_and_terms() { } /// One vendor's invoice number, entered twice: refused unless a reason is -/// given, which is journaled with the second bill (B-40). +/// given, which is journaled with the second bill (BS-arap-4). #[test] fn duplicate_vendor_invoice_refused() { let books = Books::new("documents-duplicate"); @@ -347,7 +347,7 @@ fn duplicate_vendor_invoice_refused() { /// A line's account obeys the document's kind: revenue or a role-free /// liability on an invoice, an expense or a non-cash role-free asset on a /// bill; a role account, cash, a placeholder or none at all is refused -/// (A-10, A-11; rules.md B-39). +/// (A-10, A-11; BS-arap-3). #[test] fn a_line_account_must_be_allowed() { let books = Books::new("documents-accounts"); @@ -927,7 +927,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 (B-42 INVARIANTS 1 and 3). + /// output names both documents (BS-arap-6 INVARIANTS 1 and 3). #[test] fn one_payment_settles_two_invoices() { let mut s = setup("settle-two"); @@ -984,7 +984,7 @@ mod paying_on_terms { } /// A discount outside the document's terms needs a reason; with one the - /// payment is taken and recorded (B-42 INVARIANT 2; the terms are S4.3's + /// payment is taken and recorded (BS-arap-6 INVARIANT 2; the terms are S4.3's /// to journal, so this bill states none). #[test] fn late_discount_needs_a_reason() { @@ -1013,7 +1013,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 (B-42 INVARIANT 1). + /// and A/R is credited the gross (BS-arap-6 INVARIANT 1). #[test] fn a_fee_posts_gross_to_receivables_and_net_to_the_bank() { let mut s = setup("fee-gross"); @@ -1075,7 +1075,7 @@ mod paying_on_terms { } /// Two bills paid in one entry count once toward 1099s and the party's - /// totals (B-42; 8.3.16's multi-document risk). + /// totals (BS-arap-6; 8.3.16's multi-document risk). #[test] fn multi_document_payment_counts_once_for_1099_and_party_totals() { let mut s = setup("multi-1099"); @@ -1131,7 +1131,7 @@ mod paying_on_terms { /// The bills-due list orders by due date and gives the running total /// through each date; the agings' detail rows and their tie-out agree with - /// the control check (8.3.10; B-42). + /// the control check (8.3.10; BS-arap-6). #[test] fn bills_due_orders_by_due_and_discount() { let mut s = setup("bills-due"); @@ -1383,7 +1383,7 @@ mod bad_debts { assert_eq!(check["agrees"], json!(true), "{check}"); } - /// P4b S7: no evidence, no write-off (B-41 INVARIANT 1): the tool refuses + /// P4b S7: no evidence, no write-off (BS-arap-5 INVARIANT 1): 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/drafts.rs b/crates/ledger-cli/tests/drafts.rs index a5a4dd48..438c62d0 100644 --- a/crates/ledger-cli/tests/drafts.rs +++ b/crates/ledger-cli/tests/drafts.rs @@ -1,12 +1,12 @@ //! Drafts, the evidence gate and the preview digest over the wire (plan -//! P4; rules.md B-43, D-47, D-50): a draft waits for its receipt and +//! P4; BS-entry-5, D-47, D-50): a draft waits for its receipt and //! posts when it arrives, a discard unblocks a close, a report and the CPA //! package say when drafts are open, a reversal needs no receipt of its //! own, and every tool with `confirmed` takes the `preview` it returned //! and refuses a stale one. //! //! Expected behavior comes from `docs/mcp-interface.md` ("Tools — drafts", -//! "The preview digest") and rules.md B-43. Every call goes through a real +//! "The preview digest") and BS-entry-5. Every call goes through a real //! books server as an agent reaches it (`common.rs`). mod common; @@ -129,7 +129,7 @@ fn a_draft_waits_for_its_receipt_and_posts() { assert!(listed["drafts"].as_array().unwrap().is_empty()); } -/// B-43: the structured `receipt_required` error is the one the MCP built +/// BS-entry-5: the structured `receipt_required` error is the one the MCP built /// before the gate moved into the store. #[test] fn the_gate_moved_and_the_mcp_error_is_unchanged() { diff --git a/crates/ledger-cli/tests/evidence.rs b/crates/ledger-cli/tests/evidence.rs index a05d3cc5..96d43735 100644 --- a/crates/ledger-cli/tests/evidence.rs +++ b/crates/ledger-cli/tests/evidence.rs @@ -3,7 +3,7 @@ //! backfill command. //! //! Expected behavior comes from `docs/mcp-interface.md` ("Tools — -//! evidence", "Tools — receipts & documents") and rules.md B-44. Every +//! evidence", "Tools — receipts & documents") and BS-ledger-12. Every //! call goes through a real books server as an agent reaches it //! (`common.rs`). @@ -318,7 +318,7 @@ fn annotations_and_searches() { assert_eq!(answer_of(&r).unwrap()["status"], "ok"); } -/// Plan P6 step 4 and rules.md B-44 item 5: consolidation never leaves an +/// Plan P6 step 4 and BS-ledger-12 item 5: 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 c5b5d44a..6e339317 100644 --- a/crates/ledger-cli/tests/format_upgrade.rs +++ b/crates/ledger-cli/tests/format_upgrade.rs @@ -844,8 +844,8 @@ fn books_p2_served_cut_over_whole() { "confirmed": true}), ), // An invoice carrying documents_v2's fields (terms: P4b S4.4) and - // its line naming its project (document_line_projects, rules.md - // B-37 item 8). + // its line naming its project (document_line_projects, + // BS-statement-5 item 8). ( "books.create_invoice", json!({"customer": "1", "date": "2026-02-10", "terms": "Net 30", diff --git a/crates/ledger-cli/tests/hostile_args.rs b/crates/ledger-cli/tests/hostile_args.rs index 6cc3ca99..d02aa011 100644 --- a/crates/ledger-cli/tests/hostile_args.rs +++ b/crates/ledger-cli/tests/hostile_args.rs @@ -109,12 +109,12 @@ impl Mcp { /// Start (or restart) the server on books an earlier version wrote, /// with the fixture company's settings set as an agent sets them, one /// at a time. Books in a journal format before 2 keep no settings - /// until the owner's format upgrade (rules.md B-27, D-39): each change + /// until the owner's format upgrade (BS-format-1, D-39): each change /// is refused as `format_upgrade_pending`, and those books are served /// on the defaults (no members, no 1065, no cash accounts), as they /// would be in a data root. Books with periods closed under the /// calendar year keep it (a changed tax year needs the IRS's consent, - /// rules.md B-29), whatever their format. Any other answer fails the + /// BS-ledger-9), whatever their format. Any other answer fails the /// test when the books are first served (`first`); on a restart, /// after hostile calls that may have changed a setting and closed /// periods under it, the books may refuse a change for what they now @@ -898,7 +898,7 @@ fn hostile_tool_arguments_never_stop_the_server() { /// INVARIANT 4: whatever the calls journaled, the books open again. A /// hostile call a command accepts but replay refuses would leave books -/// that never reopen (rules.md B-28): the server is restarted on them and +/// that never reopen (BS-entry-4): the server is restarted on them and /// must answer books.chart and books.verify. fn reopens(m: Mcp, p: &Places, after: &str) { drop(m); @@ -1449,7 +1449,7 @@ fn reads_of_old_books() -> Vec<(&'static str, Value)> { } /// Books an earlier version wrote open, and every tool answers over them -/// (rules.md B-28: posted is forever; a figure the books can't compute is +/// (BS-entry-4: posted is forever; a figure the books can't compute is /// refused, never a panic). Against each fixture: the reads above, then /// OLD_BOOKS_CASES (default 3) generated calls of every tool; after them /// the server restarts and must open the books again (a call a command diff --git a/crates/ledger-cli/tests/mcp_journeys.rs b/crates/ledger-cli/tests/mcp_journeys.rs index e431e1f9..be51718a 100644 --- a/crates/ledger-cli/tests/mcp_journeys.rs +++ b/crates/ledger-cli/tests/mcp_journeys.rs @@ -1081,7 +1081,7 @@ fn mcp_import_export() { // The IIF is plain ASCII text with CR LF line endings, handed over // (D-46); what it writes differently from the books is in warnings - // (rules.md B-34). + // (BS-format-2). let iif = mcp.call( "books.export", json!({"format": "iif", "report": "journal"}), @@ -1344,7 +1344,7 @@ fn mcp_period_statements() { assert_eq!(feb["net_income"], "-0.50"); assert_eq!(feb["expense_accounts"][0]["code"], "6000"); assert_eq!(feb["expense_accounts"][0]["amount"], "3.00"); - // No start (rules.md B-30): the fiscal year that holds the end, to + // No start (BS-period-3): the fiscal year that holds the end, to // it. The fiscal year starts 02-01, so January's 4.00 of sales is // last year's, and February's 2.50 is this one's. let ytd = mcp.call("books.profit_and_loss", json!({"end": "2026-02-28"})); @@ -1616,7 +1616,7 @@ fn mcp_partnership_from_template() { ); } -/// Contract (rules.md B-13, D-10; docs/mcp-interface.md close_period and +/// Contract (BS-partner-1, D-10; docs/mcp-interface.md close_period and /// list_periods): a close to the members shows each member's running /// split, the same in the preview as once confirmed, and the periods say /// which rule they closed under. Two members at 50% each, hand-computed: @@ -1748,7 +1748,7 @@ fn close_period_shows_each_members_running_split() { assert_eq!(me["members"][1]["ending"], "0.01"); } -/// Contract (rules.md B-13, D-10; docs/mcp-interface.md list_periods and +/// Contract (BS-partner-1, D-10; docs/mcp-interface.md list_periods and /// close_period) on books an earlier version wrote: ledger-store's /// old-books fixture x_member_closes (two members at 50%, A with a /// distributions account; three closes untagged, three @@ -2214,7 +2214,7 @@ fn mcp_vendor_1099() { let r = mcp.call("books.vendor_1099", json!({"year": 2026})); assert_eq!(r["vendors"][0]["paid"], "0.00"); // A year whose threshold isn't known yet: refused, with what to do - // (rules.md B-19). An explicit threshold works. + // (BS-1099-1). An explicit threshold works. let why = mcp.call_err("books.vendor_1099", json!({"year": 2027})); for needle in [ "only through 2026", @@ -2311,7 +2311,7 @@ fn mcp_receipts_always_required_when_threshold_is_zero() { } /// `books.cash_flow` with no accounts passed reads the roles from -/// `[books]` in wanderbooks.toml (rules.md B-14): the expense the owners +/// `[books]` in wanderbooks.toml (BS-statement-3): the expense the owners /// paid through 2100 is borrowed from them and spent on its date, each /// line with `on_behalf` (D-42, rule 11); repaying the advance is /// financing; a loan to a member is investing; the statement is the direct @@ -2419,7 +2419,7 @@ fn cash_flow_reads_its_account_roles_from_the_books_settings() { } } -/// rules.md B-14 rule 2: roles that contradict the chart are refused, +/// BS-statement-3 rule 2: 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() { @@ -2727,7 +2727,7 @@ fn post_pair(mcp: &mut Mcp, date: &str, dr: &str, cr: &str, amount: &str) -> u64 id } -/// Defect 16 (rules.md B-30): one default period everywhere. On books with +/// Defect 16 (BS-period-3): one default period everywhere. On books with /// a July fiscal year and a first entry in the fiscal year before, every /// period report given only an end covers the fiscal year that holds it /// (2025-07-01 through 2026-03-31, never the first entry's day, never @@ -2858,8 +2858,8 @@ fn iif_docnums(iif: &str) -> Vec { ids } -/// The default period (rules.md B-30) against the IIF (B-34, D-36) and -/// the CPA package (B-33): a general journal asked for without dates is +/// The default period (BS-period-3) against the IIF (BS-format-2, D-36) and +/// the CPA package (BS-statement-4): a general journal asked for without dates is /// the fiscal year to date, but the IIF is never a period. Without dates /// it holds every posted entry from the first through today, under /// either name of the report, and a start or end is refused; the @@ -2956,7 +2956,7 @@ fn the_default_period_never_shortens_the_iif_or_the_package() { assert_eq!(iif_docnums(&read("general-journal.iif")), every[..3]); } -/// Defect 15 (rules.md B-31) over the real binary: books.rename_account +/// Defect 15 (BS-ledger-10) over the real binary: books.rename_account /// gives an account a new name and nothing else. The chart shows it; a /// past period's P&L export prints it; the general journal's IIF declares /// the account by it; the books verify, the journal grew by the rename @@ -3082,7 +3082,7 @@ fn rename_account_end_to_end_defect_15() { ); } -/// Review R10 (rules.md B-31): on books that name no cash accounts +/// Review R10 (BS-ledger-10): on books that name no cash accounts /// (books.cash_accounts unset, so they are picked by name), a rename that /// moves an account into or out of the cash or card accounts says so; one /// that moves nothing says nothing of them. A convention naming the old diff --git a/crates/ledger-cli/tests/oracle_mcp.rs b/crates/ledger-cli/tests/oracle_mcp.rs index 539f732d..a21503a5 100644 --- a/crates/ledger-cli/tests/oracle_mcp.rs +++ b/crates/ledger-cli/tests/oracle_mcp.rs @@ -737,7 +737,7 @@ fn pnl_and_balance_sheet_exports_equal_the_core_statements() { } /// Cash flow CSV and JSON equal `ledger_core::cash_flow` for the same -/// account roles and members, field for field (rules.md B-14; the JSON is +/// account roles and members, field for field (BS-statement-3; the JSON is /// the tool's own answer). Kills: export_cash_flow stubs and its json/csv /// switch, and any field the mapping drops. #[test] @@ -1070,7 +1070,7 @@ fn journal_exports_hold_every_posted_line() { let mut m = Mcp::start(&dir, "1000000.00"); for report in ["journal", "general_journal"] { - // Every date: the journal covers a period (rules.md B-30). + // Every date: the journal covers a period (BS-period-3). let csv = m.export_text( json!({"format": "csv", "report": report, "start": "0001-01-01", "end": "9999-12-31"}), ); @@ -1419,7 +1419,7 @@ fn xlsx_and_pdf_exports_are_real_files_with_the_books_in_them() { /// (cash accounts BANK, 1200 AR, 2000 AP, a registered asset's accounts /// FIXASSET, the rest by type), then one balanced TRNS/SPL/ENDTRNS block /// per posted entry dated on or before as_of, numbered (DOCNUM) with its -/// entry id (rules.md B-33, B-34); plain ASCII text with CR LF, what it +/// entry id (BS-statement-4, BS-format-2); plain ASCII text with CR LF, what it /// writes differently (a line break and double quotes, the engine's own em /// dashes) in warnings, grouped. Kills: export_iif's AR and AP comparisons. #[test] @@ -2505,7 +2505,7 @@ fn show_refuses_a_derived_inverted_range_defect_15() { } /// Defect 16, repro 1.1.4: books.show sends the dates it names, resolved -/// by the one default (rules.md B-30): only an end covers that end's +/// by the one default (BS-period-3): only an end covers that end's /// fiscal year to it (2025-01-01 to 2025-06-30, never today's year's /// start); no dates cover today's fiscal year to date (checked against /// the clock read before and after, R14); a report as of a day says "as @@ -3631,7 +3631,7 @@ fn cpa_package_holds_the_year_and_its_evidence() { "tin_last4", ], ); - // Through as_of (rules.md B-33), out of the package's cash account + // Through as_of (BS-statement-4), out of the package's cash account // and the settings' financing account (one list each per package). let want = core_1099_through(&ledger, 2025, None, Some(d(END))); assert_eq!(w.len(), want.vendors.len()); diff --git a/crates/ledger-cli/tests/p3_seams.rs b/crates/ledger-cli/tests/p3_seams.rs index 5280b2bf..74712e08 100644 --- a/crates/ledger-cli/tests/p3_seams.rs +++ b/crates/ledger-cli/tests/p3_seams.rs @@ -60,7 +60,7 @@ struct Expected { } /// Every figure the tools report on the seam review's books is the -/// engine's for the same accounts and dates, on every date (B-33's "the +/// engine's for the same accounts and dates, on every date (BS-statement-4's "the /// tool's for the same accounts and through"), and party totals for the /// year are the engine's on both bases. #[test] diff --git a/crates/ledger-cli/tests/projects_parity.rs b/crates/ledger-cli/tests/projects_parity.rs index 1ffd3f62..d94c686b 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 (rules.md B-37 item 7) in the viewer and from the +//! A project's snapshot (BS-statement-5 item 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"); } -/// rules.md B-37 item 8: a project's invoiced revenue and billed costs, +/// BS-statement-5 item 8: 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_1099.rs b/crates/ledger-cli/tests/spec_1099.rs index bfc788b0..7d4c3247 100644 --- a/crates/ledger-cli/tests/spec_1099.rs +++ b/crates/ledger-cli/tests/spec_1099.rs @@ -285,7 +285,7 @@ fn books(name: &str) -> Mcp { /// [`books`], as P2 left them when `p2`: journal format 2 with none of /// P3's features, books an older version wrote, waiting for their format -/// upgrade (rules.md B-27). +/// upgrade (BS-format-1). fn books_in(name: &str, p2: bool) -> Mcp { let dir = test_dir(name); if p2 { @@ -610,7 +610,7 @@ fn a_members_method_off_the_financing_accounts_warns() { assert!(out["warnings"].as_array().unwrap().is_empty(), "{out}"); } -/// B-27 and the format-upgrade gate (D-39): books.set_w9 journals the W-9 +/// BS-format-1 and the format-upgrade gate (D-39): books.set_w9 journals the W-9 /// and then the vendor's W-9 flag, a line of the vendor_1099_decisions /// feature, so it asks for the feature before the command's first line, /// never between its lines. In books waiting for their format upgrade diff --git a/crates/ledger-cli/tests/spec_assets.rs b/crates/ledger-cli/tests/spec_assets.rs index 1355b224..6c378ebb 100644 --- a/crates/ledger-cli/tests/spec_assets.rs +++ b/crates/ledger-cli/tests/spec_assets.rs @@ -5,7 +5,7 @@ //! Expected behavior comes only from the tool descriptions and parameter / //! result doc comments in `src/server.rs` and `src/types.rs` (the declared //! interface, as `tools/list` serves it), `docs/mcp-interface.md` ("Tools — -//! fixed assets"), and `docs/spec/rules.md` B-24. The harness is the +//! fixed assets"), and BS-asset-3. The harness is the //! minimal subset of `tests/spec_mcp.rs`: every success validates against //! the tool's `outputSchema`, and every refusal leaves `journal.jsonl` //! byte-identical (server invariant 2: a refused call changes nothing). @@ -441,7 +441,7 @@ fn register_with_a_bad_tag_or_serial_registers_nothing() { assert_eq!(t, "FL-0002"); } -/// A generated tag is never one any asset held (B-24). +/// A generated tag is never one any asset held (BS-asset-3). #[test] fn register_never_generates_a_released_tag() { let mut m = books("released"); @@ -624,7 +624,7 @@ fn dispose_asset_takes_the_tag_and_the_tag_stays_reserved() { confirm["receipt_attachment_ids"] = json!([doc]); m.ok("books.dispose_asset", confirm); assert_eq!(m.asset(a)["status"], "disposed"); - // B-24: a disposed asset's tag is never reused. + // BS-asset-3: a disposed asset's tag is never reused. m.refuse( "books.label_asset", json!({"asset": b.to_string(), "tag": t}), @@ -815,7 +815,7 @@ fn export_fixed_asset_register_as_of_leaves_out_later_assets() { assert!(!text.contains("LATE-1"), "{text}"); } -// ------------------------------------------------- tax basis (rules.md B-25) +// ------------------------------------------------- tax basis (BS-asset-4) // // From the `books.set_asset_tax_basis` and `books.register_asset` // descriptions, `SetAssetTaxBasisParams` / `AssetBasisOut` / @@ -1116,7 +1116,7 @@ fn register_asset_refuses_a_bad_basis_and_registers_nothing() { assert_eq!(m.assets().len(), 1, "nothing registered"); } -// ------------------------------------------- the dates (rules.md B-15) +// ------------------------------------------- the dates (BS-asset-1) /// purchase_date is an alias for in_service_date for one release, noted. #[test] @@ -1199,7 +1199,7 @@ fn acquired_date_comes_from_the_acquisition_entry() { ); } -// ------------------------------- posted and scheduled (rules.md B-15 rule 8) +// ------------------------------- posted and scheduled (BS-asset-1 rule 8) /// 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; rules.md B-15 rule 8). Before P3 the +/// left the books with its disposal; BS-asset-1 rule 8). 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_mcp.rs b/crates/ledger-cli/tests/spec_mcp.rs index 8b22fcd6..816f3ddc 100644 --- a/crates/ledger-cli/tests/spec_mcp.rs +++ b/crates/ledger-cli/tests/spec_mcp.rs @@ -1490,7 +1490,7 @@ enum Op { party: Pick, amount: String, /// The vendor's own invoice number: two bills by one vendor with - /// the same number are refused (B-40). + /// the same number are refused (BS-arap-4). vendor_ref: String, }, PayBill { @@ -2703,7 +2703,7 @@ fn db_digest(path: &Path) -> String { ledger_store::journal::sha256_hex(dump.as_bytes()) } -/// P4b S1 over the real server (rules.md B-38, D-45): a payment carries +/// P4b S1 over the real server (BS-arap-2, D-45): a payment carries /// its method and reference and answers with the invoice's derived /// figures; an invoice with a payment standing can't be voided (the /// refusal names the payment); one entered twice is voided and shows as diff --git a/crates/ledger-cli/tests/spec_parties.rs b/crates/ledger-cli/tests/spec_parties.rs index bea7d00a..c753af0c 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 - // (rules.md B-35 item 5, P3 defect 24); unlisted, Due to Members is a + // (BS-partner-3 item 5, 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_party_totals.rs b/crates/ledger-cli/tests/spec_party_totals.rs index 736c8e18..ee31f4b5 100644 --- a/crates/ledger-cli/tests/spec_party_totals.rs +++ b/crates/ledger-cli/tests/spec_party_totals.rs @@ -7,7 +7,7 @@ //! //! Expected behavior comes only from the tool descriptions and parameter / //! result doc comments in `src/server.rs` and `src/types.rs` (as -//! `tools/list` serves them) and rules.md B-35. The harness is the minimal +//! `tools/list` serves them) and BS-partner-3. The harness is the minimal //! subset of `tests/spec_mcp.rs` (copied from `tests/spec_parties.rs`): //! every success validates against the tool's `outputSchema`, and every //! refusal leaves `journal.jsonl` byte-identical. @@ -291,7 +291,7 @@ fn books(name: &str) -> Mcp { /// [`books`], as P2 left them when `p2`: journal format 2 with none of /// P3's features, books an older version wrote, waiting for their format -/// upgrade (rules.md B-27). +/// upgrade (BS-format-1). fn books_in(name: &str, p2: bool) -> Mcp { let dir = test_dir(name); if p2 { @@ -380,7 +380,7 @@ fn reverse(m: &mut Mcp, entry: u64, date: &str) -> u64 { .unwrap_or_else(|| panic!("a reversal of {entry}")) } -/// Defect 14 over the MCP (rules.md B-35): `resolved` is signed as a line +/// Defect 14 over the MCP (BS-partner-3): `resolved` is signed as a line /// on the party's own account, with its direction and its money and /// property; a reversal is the exact opposite; party totals take a basis, /// cash by default and echoed, all adding property in kind, so that a @@ -603,7 +603,7 @@ fn defect24_creditor_of_round_trips_and_a_card_fee_is_not_a_payment() { assert_eq!(m.ok("books.verify", json!({}))["status"], "ok"); } -/// rules.md B-27: `books.update_party` asks for the `party_creditors` +/// BS-format-1: `books.update_party` asks for the `party_creditors` /// feature before the first line it writes, never between them. In books /// waiting for their format upgrade (P2's), a name change with the first /// creditor is refused whole, journaling nothing (never the notes changed diff --git a/crates/ledger-cli/tests/spec_projects.rs b/crates/ledger-cli/tests/spec_projects.rs index e861fc6d..9633291a 100644 --- a/crates/ledger-cli/tests/spec_projects.rs +++ b/crates/ledger-cli/tests/spec_projects.rs @@ -1,5 +1,5 @@ -//! Spec-blind tests for the project tools of the books server (rules.md -//! B-37), driven through a real `wanderbooks server` as an agent reaches +//! Spec-blind tests for the project tools of the books server ( +//! BS-statement-5), driven through a real `wanderbooks server` as an agent reaches //! it (common.rs). //! //! Expected behavior comes only from the tool descriptions and parameter / @@ -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 (rules.md B-37 item 7), as the viewer shows +/// The snapshot's figures (BS-statement-5 item 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( ) } -/// rules.md B-37 item 8: each invoice and bill line takes a project (by +/// BS-statement-5 item 8: 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() { ); } -/// B-37 items 4 and 8: an invoice line naming an on-spec project is taken +/// BS-statement-5 items 4 and 8: 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-cli/tests/spec_tax_policy.rs b/crates/ledger-cli/tests/spec_tax_policy.rs index cc9339e4..9444e2f3 100644 --- a/crates/ledger-cli/tests/spec_tax_policy.rs +++ b/crates/ledger-cli/tests/spec_tax_policy.rs @@ -1,5 +1,5 @@ //! Tax categories at account creation, and `policy.require_tax_category` -//! (P3, defect 8; rules.md B-32), through a real books server as an +//! (P3, defect 8; BS-ledger-11), through a real books server as an //! agent reaches it (common.rs). //! //! ```text @@ -7,7 +7,7 @@ //! or the human hears that it doesn't; a company that refuses //! uncategorized accounts gets exactly that, never a refused //! invoice. -//! SOURCE: rules.md B-32; plan/served.md P3 defect 8 and "Settled in +//! SOURCE: BS-ledger-11; plan/served.md P3 defect 8 and "Settled in //! design" (warn by default, headers exempt). //! ``` //! @@ -322,7 +322,7 @@ fn require_tax_category_refuses_defect_8() { assert_eq!(out["warnings"].as_array().unwrap().len(), 2, "{out}"); } -/// rules.md B-31 for new accounts: a name another account under the same +/// BS-ledger-10 for new accounts: a name another account under the same /// parent has, ignoring capitals (top-level accounts are siblings too), /// or one holding nine digits in a row, is refused, for books.add_account /// and books.import_chart_csv alike; under another parent the name is @@ -369,7 +369,7 @@ fn a_new_account_named_like_a_sibling_is_refused() { ); } -/// rules.md B-32: a gain on business property (`form_4797_gain_loss`, the +/// BS-ledger-11: a gain on business property (`form_4797_gain_loss`, the /// disposal account a refusing company must categorize) is exported apart /// in the tax summary, JSON and CSV alike: at its book amount, with no tax /// amount, and outside income and both nets (Form 4797 figures it from diff --git a/crates/ledger-cli/tests/spec_vault.rs b/crates/ledger-cli/tests/spec_vault.rs index ed7c5274..7bde0319 100644 --- a/crates/ledger-cli/tests/spec_vault.rs +++ b/crates/ledger-cli/tests/spec_vault.rs @@ -1799,7 +1799,7 @@ fn a_locked_vault_still_builds_the_package() { assert!(w.iter().all(|r| r["tin"].is_empty())); } -/// B-26 ("No tool output, error, or log holds a full TIN"): a TIN put in +/// BS-partner-2 ("No tool output, error, or log holds a full TIN"): a TIN put in /// the wrong field is refused, and the refusal never repeats it, however /// it was written: as a party name, a bare number where a string goes, or /// a share's percent. @@ -1841,7 +1841,7 @@ fn refusals_never_echo_a_tin() { } } -/// B-26 for resource reads: a refused `resources/read` quotes the URI it +/// BS-partner-2 for resource reads: a refused `resources/read` quotes the URI it /// was given, in its message and its data, and never repeats a TIN in it, /// however the URI carries one (a receipt id, a handbook section, an /// unknown path, a digest's `since`). diff --git a/crates/ledger-cli/tests/startup.rs b/crates/ledger-cli/tests/startup.rs index cbd7dee1..334fd900 100644 --- a/crates/ledger-cli/tests/startup.rs +++ b/crates/ledger-cli/tests/startup.rs @@ -2,7 +2,7 @@ //! program holds, and books a newer wanderbooks wrote. Oracle: ledger-mcp //! local.rs INVARIANT 3 (every book is tried before the server says it is //! ready; one that won't open is reported with why, on its route and in -//! the list, and the others are served) and rules.md B-27 (newer books +//! the list, and the others are served) and BS-format-1 (newer books //! are refused as newer, never as corrupt, and left as they are). use common::{Home, Server, Wire}; @@ -80,7 +80,7 @@ fn a_held_lock_is_refused_not_waited_on_forever() { } /// Books written by a newer wanderbooks: the server won't open them, and -/// says to update it, not that the books are corrupt (rules.md B-27); it +/// says to update it, not that the books are corrupt (BS-format-1); it /// leaves them as they are. #[test] fn newer_books_are_refused_as_newer_not_corrupt() { @@ -90,7 +90,7 @@ fn newer_books_are_refused_as_newer_not_corrupt() { let mut w = ledger_store::JournalWriter::open(&dir.join(ledger_store::JOURNAL_FILE)).unwrap(); w.append("journal.format_set", json!({"format": 3, "features": []})) .unwrap(); - // The next line chains onto it, so its bytes are checked (B-27). + // The next line chains onto it, so its bytes are checked (BS-format-1). w.append( "fx.rate_set", json!({"currency": "EUR", "date": "2026-10-01", "rate": "1.10"}), diff --git a/crates/ledger-cli/tests/tin_files.rs b/crates/ledger-cli/tests/tin_files.rs index 65b3f0e0..dd6e799d 100644 --- a/crates/ledger-cli/tests/tin_files.rs +++ b/crates/ledger-cli/tests/tin_files.rs @@ -1,4 +1,4 @@ -//! Files that carry full TINs never enter the books (rules.md B-26; +//! Files that carry full TINs never enter the books (BS-partner-2; //! tin_files.rs). //! //! ```text @@ -6,7 +6,7 @@ //! (books.get_receipt would hand its bytes to any agent), however it //! comes back: the W-9 books.set_w9 read, books.get_w9's copy, a CPA //! package or a file from one, or text with a TIN in it. -//! SOURCE: rules.md B-26; DECISION (P0 review round 2, 2026-10-16). +//! SOURCE: BS-partner-2; DECISION (P0 review round 2, 2026-10-16). //! INVARIANTS (oracle): //! 1. Every file the server read or wrote with full TINs is refused by //! every way a file enters the books (books.attach_receipt and diff --git a/crates/ledger-config/src/receipt_policy.rs b/crates/ledger-config/src/receipt_policy.rs index 6df10cc4..5b9ed4d8 100644 --- a/crates/ledger-config/src/receipt_policy.rs +++ b/crates/ledger-config/src/receipt_policy.rs @@ -95,7 +95,7 @@ impl ReceiptPolicy { } /// Total debits of the entry (one side of the balanced entry). A - /// draft's lines are as journaled, of any size (rules.md B-28): a total + /// draft's lines are as journaled, of any size (BS-entry-4): a total /// past exact arithmetic is refused (TooLargeToCompute), never a panic. pub fn entry_debits(entry: &JournalEntry) -> Result { ledger_core::evidence::Policy::entry_debits(entry) @@ -363,7 +363,7 @@ mod rule_tests { } /// A draft an earlier version journaled may hold debits exact - /// arithmetic can't sum (rules.md B-28): its total is refused, never a + /// arithmetic can't sum (BS-entry-4): its total is refused, never a /// panic, and for the policy it is past any threshold: a receipt is /// required, and it is no part of a split. #[test] diff --git a/crates/ledger-core/src/account.rs b/crates/ledger-core/src/account.rs index 996ad603..1b1a4a2c 100644 --- a/crates/ledger-core/src/account.rs +++ b/crates/ledger-core/src/account.rs @@ -59,7 +59,7 @@ impl AccountType { /// The longest name a new account (or a rename) may take, in characters: /// one line that every report prints, as long as the company's own name /// may be ([`crate::settings::MAX_TEXT`]). The command's bound, never -/// replay's (rules.md B-28): a journaled name of any length replays. +/// replay's (BS-entry-4): a journaled name of any length replays. pub const MAX_ACCOUNT_NAME: usize = crate::settings::MAX_TEXT; /// A single account in the chart of accounts. @@ -151,7 +151,7 @@ impl ChartOfAccounts { /// Give an account a new name. Only the account must exist: what a /// new name may be is the command's to check - /// ([`crate::Ledger::rename_account`]), never replay's (rules.md B-28). + /// ([`crate::Ledger::rename_account`]), never replay's (BS-entry-4). pub fn set_name(&mut self, id: AccountId, name: &str) -> Result<(), LedgerError> { let a = self .accounts diff --git a/crates/ledger-core/src/analysis.rs b/crates/ledger-core/src/analysis.rs index 27953a89..4f9ec9b3 100644 --- a/crates/ledger-core/src/analysis.rs +++ b/crates/ledger-core/src/analysis.rs @@ -44,7 +44,7 @@ pub fn interval_start(d: NaiveDate, interval: Interval) -> NaiveDate { /// `[start, end]` split on calendar interval boundaries, first and last /// pieces clipped to the range. Empty when `end < start`. Never panics: /// an interval that would end past chrono's last day ends at `end` -/// (rules.md B-28: books an earlier version wrote may hold such dates). +/// (BS-entry-4: books an earlier version wrote may hold such dates). pub fn intervals( start: NaiveDate, end: NaiveDate, @@ -264,7 +264,7 @@ mod tests { } /// At chrono's last day (books an earlier version wrote may hold it): - /// the last interval ends there, never a panic (rules.md B-28). + /// the last interval ends there, never a panic (BS-entry-4). #[test] fn intervals_reach_chronos_last_day() { let y = NaiveDate::MAX.year(); diff --git a/crates/ledger-core/src/arap.rs b/crates/ledger-core/src/arap.rs index 92a8df0c..2a89a679 100644 --- a/crates/ledger-core/src/arap.rs +++ b/crates/ledger-core/src/arap.rs @@ -9,7 +9,7 @@ //! * `receive_payment`: Dr Cash, Cr A/R. //! * `pay_bill`: Dr A/P, Cr Cash. //! -//! A document keeps no figure of its own (plan P4b, D-45; rules.md B-38): +//! A document keeps no figure of its own (plan P4b, D-45; BS-arap-2): //! every ledger line on a receivables or payables account carries the //! document it belongs to ([`DocTag`]), and what is paid and still owed, //! and the document's status, are read from those lines that stand @@ -29,7 +29,7 @@ use serde::{Deserialize, Serialize}; /// The most days a payment term may run: ten years, far beyond any trade /// term, and short of the calendar's end for every document date the -/// books can hold (B-39). +/// books can hold (BS-arap-3). pub const MAX_TERMS_DAYS: u16 = 3_650; /// Opaque customer handle. @@ -198,12 +198,12 @@ pub enum DocStatus { Paid, /// Nothing owed, the last of it written off (S7). WrittenOff, - /// Its own entry doesn't stand: reversed (B-9), number kept. + /// Its own entry doesn't stand: reversed (BS-ledger-5), number kept. Void, /// 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 (B-38 INVARIANT 2); never a receivable or a payable, so + /// bounds (BS-arap-2 INVARIANT 2); 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 (B-38 INVARIANT 2; plan P4b.14 item 3), + /// version left out of bounds (BS-arap-2 INVARIANT 2; 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 @@ -275,7 +275,7 @@ impl DocState { /// ```text /// GOAL: one status from the ledger's figures, whatever happened to the /// document, its payments and their reversals. -/// SOURCE: docs/spec/rules.md B-38; plan/served.md P4b.3 ("Status as of D"); +/// SOURCE: BS-arap-2; plan/served.md P4b.3 ("Status as of D"); /// ASC 310-10 (a credit balance is not a receivable). /// INVARIANTS: /// 1. Void exactly when its own entry doesn't stand (`origin_stands` @@ -426,7 +426,7 @@ impl PaymentDetails { } } -/// One document a settlement applies to (plan P4b S6; rules.md B-42): the +/// One document a settlement applies to (plan P4b S6; BS-arap-6): the /// cash paid on it, the early-payment discount taken off it, and why a /// discount outside its terms was taken anyway. #[derive(Clone, Debug, PartialEq, Eq)] @@ -456,7 +456,7 @@ pub struct Fee { pub vendor: Option, } -/// Everything one settlement needs (plan P4b S6; rules.md B-42): its date, +/// Everything one settlement needs (plan P4b S6; BS-arap-6): its date, /// description, deposit account, the party every document belongs to, the /// applications, and the processor's fee when one was withheld. #[derive(Clone, Debug, PartialEq, Eq)] @@ -484,7 +484,7 @@ pub struct SettleParams { /// when it is a control line ([`Application`]'s payment or discount). pub type SettlementRow = (crate::AccountId, crate::Side, Decimal, Option); -/// How a document's payment terms count their days (rules.md B-39; plan +/// How a document's payment terms count their days (BS-arap-3; plan /// P4b S4.1): from the document's date, from the end of its month, or a /// date the parties agreed. #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] @@ -514,11 +514,11 @@ pub struct EarlyDiscount { } /// Payment terms: one due date, and the early-payment discount open -/// before it (rules.md B-39; plan P4b S4.1, A-2, A-8). +/// before it (BS-arap-3; plan P4b S4.1, A-2, A-8). /// /// ```text /// GOAL: terms give one due date and one discount date, exactly. -/// SOURCE: docs/spec/rules.md B-39; plan/served.md 8.3.13 (B-39); +/// SOURCE: BS-arap-3; plan/served.md 8.3.13 (BS-arap-3); /// CONVENTION: standard trade-terms notation; UCC §2-310(a) for /// goods; for services, the contract. /// INVARIANTS: @@ -976,7 +976,7 @@ pub struct DocumentLine { /// Line amount (positive). pub amount: Decimal, /// The project (a class) the line's revenue or cost belongs to, if - /// any (rules.md B-37): the posted entry's revenue or expense line for + /// any (BS-statement-5): the posted entry's revenue or expense line for /// it carries the tag; the receivable or payable line never does. /// Documents journaled before the `document_line_projects` feature /// have none. @@ -1035,7 +1035,7 @@ pub struct Invoice { pub entry_id: u64, /// The number it was issued under ("INV-0007"), from /// [`crate::Ledger::next_invoice_number`]; stored at issue, never - /// recomputed, kept by a void (A-2, B-40). None on a legacy invoice: + /// recomputed, kept by a void (A-2, BS-arap-4). None on a legacy invoice: /// it is shown as "Invoice {id}" and never counted. #[serde(default, skip_serializing_if = "Option::is_none")] pub number: Option, @@ -1061,7 +1061,7 @@ pub struct Invoice { /// The sum of a document's lines; refused (TooLargeToCompute), never a /// panic, past exact arithmetic. A document is restored from its journal -/// line as written (rules.md B-28), so its lines are bounded only by what +/// line as written (BS-entry-4), so its lines are bounded only by what /// the version that wrote it checked. pub fn document_total(lines: &[DocumentLine], what: &str) -> Result { crate::kernel::total_of(lines, |l| l.amount) @@ -1082,9 +1082,9 @@ 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: docs/spec/rules.md B-37 item 3 (job costing: the revenue and +/// SOURCE: BS-statement-5 item 3 (job costing: the revenue and /// direct costs identified with one job) and item 8 (an -/// invoice's or bill's line names its project); B-39 and plan +/// 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: /// 1. The parts sum to the document's total (conservation), and each @@ -1166,7 +1166,7 @@ pub struct Bill { /// The auto-posted journal entry. pub entry_id: u64, /// The vendor's own invoice number, when given: what a duplicate - /// check reads (B-40; [`crate::Ledger::check_vendor_ref`]). + /// check reads (BS-arap-4; [`crate::Ledger::check_vendor_ref`]). #[serde(default, skip_serializing_if = "Option::is_none")] pub vendor_ref: Option, /// The day we received the bill, when it differs from its date. @@ -1198,7 +1198,7 @@ impl Bill { /// Validate document lines: at least one, all positive amounts, each in a /// journal line's range, and a quantity and unit price that multiply to /// the amount exactly (plan P4b S4.1). For new documents; replay restores -/// them as journaled (rules.md B-28). +/// them as journaled (BS-entry-4). pub fn validate_lines(lines: &[DocumentLine]) -> Result<(), LedgerError> { if lines.is_empty() { return Err(LedgerError::EmptyDocumentLines); @@ -1251,7 +1251,7 @@ pub fn validate_lines(lines: &[DocumentLine]) -> Result<(), LedgerError> { /// Validate that due date is not before the document date, and both are /// in the calendar the books keep (P0 review round 3, S1). For new -/// documents; replay restores them as journaled (rules.md B-28). +/// documents; replay restores them as journaled (BS-entry-4). pub fn validate_due_date(date: NaiveDate, due_date: NaiveDate) -> Result<(), LedgerError> { crate::calendar::check(date)?; crate::calendar::check(due_date)?; @@ -1354,7 +1354,7 @@ pub struct AgingDocument { /// /// ```text /// GOAL: say how overdue a balance is, as of a date. -/// SOURCE: docs/spec/rules.md B-18 (bucket edges: CONVENTION, ASC +/// SOURCE: BS-arap-1 (bucket edges: CONVENTION, ASC /// 326-20-55-38 illustrative; due today is Current: DECISION, /// owner 2026-10-13). /// INVARIANTS: diff --git a/crates/ledger-core/src/assets.rs b/crates/ledger-core/src/assets.rs index 58a3c689..a11a7968 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 (rules.md B-15 rule 8): +//! Two figures of accumulated depreciation, never confused (BS-asset-1 rule 8): //! 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 @@ -72,7 +72,7 @@ pub struct Asset { pub id: AssetId, /// What it is, e.g. "2023 Sprinter van". pub description: String, - /// The day it was placed in service: depreciation starts here (B-15). + /// The day it was placed in service: depreciation starts here (BS-asset-1). /// The day the company acquired it is its acquisition entry's /// ([`crate::Ledger::asset_acquired_date`]), never later than this. #[serde(rename = "purchase_date")] @@ -274,7 +274,7 @@ pub struct AssetBasis { /// The §704(c) method chosen for it, if chosen (contributions only). #[serde(default, skip_serializing_if = "Option::is_none")] pub sec704c_method: Option, - /// Who gave the facts, when, and on what (rules.md B-29). + /// Who gave the facts, when, and on what (BS-ledger-9). #[serde(default, skip_serializing_if = "Option::is_none")] pub source: Option, } @@ -334,7 +334,7 @@ impl AssetBasis { } /// The checks every journaled `asset.basis_set` passed, which replay - /// applies (rules.md B-28): the facts fit the rule and none is + /// applies (BS-entry-4): the facts fit the rule and none is /// negative. No bound on size or places. pub fn check_journaled(&self) -> Result<(), String> { if self.rule == BasisRule::Purchase { @@ -365,7 +365,7 @@ impl AssetBasis { /// written (the rule through 2026-10-16), for a record with no value /// at contribution: a purchase takes no contributor basis; a /// contribution needs one, non-negative, in cents at most. Replay of - /// that event applies exactly these (rules.md B-28). + /// that event applies exactly these (BS-entry-4). pub fn check_legacy_journaled(&self) -> Result<(), String> { use BasisRule::*; match (self.rule, self.contributor_adjusted_basis) { @@ -610,7 +610,7 @@ struct MonthLine { /// /// ```text /// GOAL: how much of an asset's cost has been used up, month by month. -/// SOURCE: docs/spec/rules.md B-15 (straight line; salvage never +/// SOURCE: BS-asset-1 (straight line; salvage never /// depreciated; partial months by days; ASC 360-10-35-4: cost less /// salvage over the useful life "in a systematic and rational /// manner", as equitably as possible to the periods served); @@ -642,7 +642,7 @@ struct MonthLine { /// either side of one). /// 7. NEVER panics: a figure that can't be computed (a life past /// chrono's last day, amounts past exact arithmetic) is refused -/// (rules.md B-28). +/// (BS-entry-4). /// SCENARIOS: /// 1. IF $12,000 over 12 months from Jan 1, through Jun 15: /// - SHOULD end with June at 500.00 (15 of 30 days), accumulated @@ -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 (rules.md B-15 rule 8). +/// due is posted (BS-asset-1 rule 8). pub fn accumulated_scheduled_through( asset: &Asset, as_of: NaiveDate, @@ -758,7 +758,7 @@ pub fn accumulated_scheduled_through( /// the schedule's own book value (as [`ScheduleLine::book_value`]), never /// what the books carry, which is cost less /// [`crate::Ledger::accumulated_posted`] (the register's and the tools' -/// `book_value`, rules.md B-24). +/// `book_value`, BS-asset-3). pub fn scheduled_book_value(asset: &Asset, as_of: NaiveDate) -> Result { asset .cost @@ -795,9 +795,9 @@ pub struct PostedRun { /// GOAL: the catch-up rule reads the books as they stood at each month /// end: a run reversed after its month ended still carried that /// month, so running the month again would carry it twice. -/// SOURCE: docs/spec/rules.md B-9 (a mistake is corrected by an opposite -/// entry, dated when it is made), B-10 (reversing the reversal -/// re-instates), B-15 (the catch-up rule). +/// SOURCE: BS-ledger-5 (a mistake is corrected by an opposite +/// entry, dated when it is made), BS-ledger-6 (reversing the reversal +/// re-instates), BS-asset-1 (the catch-up rule). /// INVARIANTS: /// 1. Through any month's end, the effects sum to what the runs' entries /// and their reversals dated on or before it carry in the asset's @@ -1010,7 +1010,7 @@ fn cumulatives( /// SOURCE: plan/served.md P3 "Settled in design" (2026-10-20): a month of /// depreciation skipped is caught up in the month the run is made /// (an immaterial miss; a material one is restated, ASC 250, a -/// correction for a human and the CPA); docs/spec/rules.md B-15. +/// correction for a human and the CPA); BS-asset-1. /// INVARIANTS: /// 1. amount = catch_up_room for the month: kernel::catch_up over the /// month ends M from this month's through the latest month an effect @@ -1124,11 +1124,11 @@ pub struct DisposalAmounts { /// Whether an asset can be disposed of for `proceeds`: it is active and /// the proceeds aren't negative. The checks every journaled -/// disposal passed, so replaying one never depends on a figure (rules.md -/// B-28). The date's floor, the day the company acquired the asset, needs +/// disposal passed, so replaying one never depends on a figure ( +/// BS-entry-4). The date's floor, the day the company acquired the asset, needs /// its acquisition entry, so the ledger checks it for new disposals only /// (`Ledger::dispose_asset`): a disposal may fall on the in-service date -/// (one day held, accrual being inclusive, B-15), or before it once the +/// (one day held, accrual being inclusive, BS-asset-1), or before it once the /// asset is acquired (nothing accrued yet). pub fn check_disposal(asset: &Asset, proceeds: Money) -> Result<(), LedgerError> { if asset.status != AssetStatus::Active { diff --git a/crates/ledger-core/src/audit.rs b/crates/ledger-core/src/audit.rs index dabbfdf0..57f20fe8 100644 --- a/crates/ledger-core/src/audit.rs +++ b/crates/ledger-core/src/audit.rs @@ -1,4 +1,4 @@ -//! The audit's statements checks (plan P8; rules.md B-45): the books, +//! The audit's statements checks (plan P8; BS-ledger-13): the books, //! read as an auditor would, through a date, as a list of findings. //! //! ```text @@ -7,8 +7,8 @@ //! reproducible and its workpaper hashes the same twice. //! SOURCE: IRS Pub. 583 (records that support entries); Rev. Proc. 98-25 //! §5.01 (the relationship between the records and the books must -//! be demonstrable); docs/spec/rules.md B-6 to B-14 (the -//! statements), B-38 (control accounts), B-43 (evidence); +//! be demonstrable); BS-statement-1 to BS-statement-3 (the +//! statements), BS-arap-2 (control accounts), BS-entry-5 (evidence); //! DECISION D-9 (the audit and its bar), D-53 (a run, not a job). //! INVARIANTS: //! 1. Pure: reads the ledger and the facts [`AuditInput`] hands in, @@ -668,7 +668,7 @@ fn settings_problems(problems: &[String]) -> Vec { } // --------------------------------------------------------------------------- -// Scope, method and the attestation bar (rules.md B-45; D-9) +// Scope, method and the attestation bar (BS-ledger-13; D-9) // --------------------------------------------------------------------------- /// What an audit covers. @@ -761,7 +761,7 @@ impl Effort { } /// How an attestation was made, as the client says (self-reported: the -/// books record the claim, never prove it; rules.md B-45). +/// books record the claim, never prove it; BS-ledger-13). #[derive(Clone, Debug, Default, PartialEq, Eq, Serialize)] pub struct Method { /// The model that checked, as it names itself. diff --git a/crates/ledger-core/src/calendar.rs b/crates/ledger-core/src/calendar.rs index e285fffa..20715c3c 100644 --- a/crates/ledger-core/src/calendar.rs +++ b/crates/ledger-core/src/calendar.rs @@ -94,7 +94,7 @@ pub(crate) fn fiscal_year_unclamped(md: (u32, u32), d: NaiveDate) -> (NaiveDate, /// the CPA package's year, and every default period derive from. /// SOURCE: IRS Pub. 538 (docs/spec/sources/irs-periods-and-methods.md): /// "A tax year is an annual accounting period for keeping records -/// and reporting income and expenses"; rules.md B-28 (no date +/// and reporting income and expenses"; BS-entry-4 (no date /// outside the calendar). /// INVARIANTS: /// 1. For d in the calendar: FIRST_DAY <= result <= d, and d is before @@ -108,7 +108,7 @@ pub fn fiscal_year_start_on(md: (u32, u32), d: NaiveDate) -> NaiveDate { fiscal_year_start_unclamped(md, d).max(FIRST_DAY) } -/// What an omitted date means, by the kind of report (rules.md B-30): the +/// What an omitted date means, by the kind of report (BS-period-3): the /// text every tool description and date parameter shows, so none can say /// other than [`PeriodDefaults`] does. #[derive(Clone, Copy, Debug, PartialEq, Eq)] @@ -152,13 +152,13 @@ pub const YEAR_DOC: &str = "Calendar year. Omitted: this calendar year (1099s and party totals count by calendar year)."; /// The defaults an omitted date takes, today, under the company's fiscal -/// year: the one rule (rules.md B-30) the report tools, the viewer and +/// year: the one rule (BS-period-3) the report tools, the viewer and /// the tool descriptions share. Built by [`period_defaults`]. /// /// ```text /// GOAL: one meaning for "no dates", everywhere: a report asked for /// without dates covers this fiscal year so far. -/// SOURCE: rules.md B-30; IRS Pub. 538 ("an annual accounting period for +/// SOURCE: BS-period-3; IRS Pub. 538 ("an annual accounting period for /// keeping records and reporting income and expenses"); 26 U.S.C. /// §6041(a) ("in any calendar year") and §6041A(a)(2) ("during /// such calendar year") for the calendar-year counts; DECISION @@ -251,7 +251,7 @@ impl PeriodDefaults { /// The days in a month of a year chrono holds, without stepping to the /// next month, so chrono's last month (December 262142, whose next month -/// chrono can't hold) has its 31 days too (rules.md B-28: a schedule an +/// chrono can't hold) has its 31 days too (BS-entry-4: a schedule an /// earlier version accepted is computed, never a panic). pub fn days_in_month(year: i32, month: u32) -> u32 { match month { @@ -290,7 +290,7 @@ pub struct SpanPart { /// ```text /// GOAL: cut a span of days (an asset's life, a schedule's coverage) into /// the calendar months it touches, for proration by days. -/// SOURCE: docs/spec/rules.md B-15, B-16; kernel::prorate_by_days. +/// SOURCE: BS-asset-1, BS-prepaid-1; kernel::prorate_by_days. /// INVARIANTS: /// 1. The parts' days sum to the span's days; every part has 1 to its /// month's days (a valid kernel::MonthPart), and only the last is @@ -567,7 +567,7 @@ mod tests { ); } - /// The descriptions say what the resolver does (B-30), in the words + /// The descriptions say what the resolver does (BS-period-3), in the words /// every tool shows. #[test] fn the_descriptions_name_the_rule() { diff --git a/crates/ledger-core/src/cashflow.rs b/crates/ledger-core/src/cashflow.rs index e478c067..bcb5f819 100644 --- a/crates/ledger-core/src/cashflow.rs +++ b/crates/ledger-core/src/cashflow.rs @@ -1,4 +1,4 @@ -//! The statement of cash flows (rules.md B-14), by the direct method: each +//! The statement of cash flows (BS-statement-3), by the direct method: each //! entry that moved cash, in the section of the accounts it settled, gross; //! the reconciliation of net income to operating cash as a separate //! schedule; and the investing and financing activities no cash settled, @@ -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 (rules.md B-14 rule 5). + /// tax yet, so nothing is filed here (BS-statement-3 rule 5). 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 (rules.md B-14 rule 11, D-42): + /// company with no cash account moving (BS-statement-3 rule 11, 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 (rules.md B-14 rule 9). +/// The footing check (BS-statement-3 rule 9). #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct CashFlowFooting { /// Operating + investing + financing. @@ -344,7 +344,7 @@ pub struct CashFlowWarning { pub message: String, } -/// The statement of cash flows, direct method (rules.md B-14). +/// The statement of cash flows, direct method (BS-statement-3). #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct CashFlowStatement { /// Period start, inclusive. @@ -440,7 +440,7 @@ pub enum RoleList { Investing, } -/// A contradiction among the cash flow account roles (rules.md B-14 rule +/// A contradiction among the cash flow account roles (BS-statement-3 rule /// 2): the statement refuses rather than guess. #[derive(Clone, Debug, PartialEq, Eq)] pub enum RoleProblem { @@ -546,7 +546,7 @@ impl RoleProblem { } } -/// Every contradiction among the cash flow account roles (rules.md B-14 +/// 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 /// report. The one check behind both the statement's refusal and the /// settings' problems, so the two never drift apart. @@ -554,7 +554,7 @@ impl RoleProblem { /// ```text /// GOAL: the statement's account roles partition the chart, so every /// account is in exactly one section. -/// SOURCE: rules.md B-14 rule 2 (ASC 230-10-45-10: every cash receipt and +/// SOURCE: BS-statement-3 rule 2 (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 } -/// rules.md B-14 rule 9, on its own so the check is tested directly (it +/// BS-statement-3 rule 9, 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 { @@ -977,8 +977,8 @@ impl<'a> Roles<'a> { } } -/// The liabilities that hold distributions declared by `end` (rules.md -/// B-14 rule 2), among the accounts `open` leaves to be placed: each +/// The liabilities that hold distributions declared by `end` ( +/// BS-statement-3 rule 2), 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 @@ -1031,7 +1031,7 @@ type KindOrder = (u8, u8, String); /// so the payment is an investing outflow (ASC 230-10-45-13(c)). A bill /// posts to the general-expenses control today, so this is empty until a /// bill can carry an equipment line (P4b S4). A bill's payments are the -/// entries whose payables line carries it (rules.md B-38). +/// entries whose payables line carries it (BS-arap-2). #[derive(Default)] struct BillSplits { /// By (entry, line index): the investing part of that payables line, @@ -1741,15 +1741,15 @@ fn codes<'p>( Ok(out.into_iter().collect()) } -/// The statement of cash flows for a period, direct method (rules.md -/// B-14). +/// The statement of cash flows for a period, direct method ( +/// BS-statement-3). /// /// ```text /// GOAL: the statement of cash flows for a period: each entry's cash by /// section and kind, the noncash investing and financing activities, /// and net income reconciled to operating cash; footing exactly or /// not at all. -/// SOURCE: rules.md B-14 (ASC 230-10-10-1 cash receipts and payments; +/// SOURCE: BS-statement-3 (ASC 230-10-10-1 cash receipts and payments; /// 45-4, 45-5 what cash is; 45-7, 45-26 gross; 45-10 the three /// sections; 45-12 to 45-17 what each holds; 45-24 reconciles /// beginning and ending cash; 45-25 the diff --git a/crates/ledger-core/src/classes.rs b/crates/ledger-core/src/classes.rs index b23b2548..4203a43d 100644 --- a/crates/ledger-core/src/classes.rs +++ b/crates/ledger-core/src/classes.rs @@ -10,7 +10,7 @@ //! on drafts only; posted entries are immutable, so their classes are frozen. //! //! A class is also a project: the class with its facts ([`ProjectFacts`]: -//! what it is, where it stands, who it is for; rules.md B-37). Every class +//! what it is, where it stands, who it is for; BS-statement-5). Every class //! is one; a class an earlier version wrote has the default facts. use chrono::NaiveDate; @@ -28,7 +28,7 @@ pub struct Class { pub name: String, } -/// Where a project stands (rules.md B-37). +/// Where a project stands (BS-statement-5). #[derive( Clone, Copy, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize, )] @@ -85,7 +85,7 @@ impl ProjectStatus { } } -/// What kind of work a project is (rules.md B-37): it decides the +/// What kind of work a project is (BS-statement-5): it decides the /// accounting questions its costs raise. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)] pub enum ProjectKind { @@ -141,7 +141,7 @@ pub const MAX_LINKS: usize = 8; /// One link: one line of text ([`crate::settings::line_text`]'s length /// and control-character rules) with no full TIN as a web address holds /// one ([`crate::settings::holds_printed_tin_in_link`]: a printed SSN or -/// EIN is refused, a store listing's `id284882215` is not; rules.md B-26). +/// EIN is refused, a store listing's `id284882215` is not; BS-partner-2). fn link_text(l: &str) -> Result { use crate::settings::{MAX_TEXT, holds_printed_tin_in_link, line_text}; // line_text's TIN rule is a plain text's, so it sees the link with @@ -167,13 +167,13 @@ fn link_text(l: &str) -> Result { /// GOAL: say what a project is, where it stands and who it is for, in /// the few facts a job cost sheet carries, without a project /// manager's sprawl (no budgets, estimates or percent complete). -/// SOURCE: docs/spec/rules.md B-37; DECISION (owner, 2026-10-21: "Projects +/// SOURCE: BS-statement-5; DECISION (owner, 2026-10-21: "Projects /// are entities too and can have name, description, whatever /// other metadata"); job-order costing (a job cost sheet: the /// job, its customer, its dates). /// INVARIANTS: /// 1. No field holds a full taxpayer identification number -/// (settings::line_text / long_text, rules.md B-26). +/// (settings::line_text / long_text, BS-partner-2). /// 2. ended_on only when the project is finished or abandoned, and /// never before started_on. /// 3. The party, if any, is in the directory (archived allowed). diff --git a/crates/ledger-core/src/conventions.rs b/crates/ledger-core/src/conventions.rs index 65d8a794..c2f42041 100644 --- a/crates/ledger-core/src/conventions.rs +++ b/crates/ledger-core/src/conventions.rs @@ -40,7 +40,7 @@ //! 4. Decision and open-item ids are allocated in order and journaled; //! a decision supersedes at most one live decision; an item resolves //! once. -//! 5. Replay takes what was journaled (rules.md B-28): text limits and +//! 5. Replay takes what was journaled (BS-entry-4): text limits and //! chart checks are for new commands only. //! 6. No text holds a full TIN (settings INVARIANT 4). //! ``` @@ -273,7 +273,7 @@ pub struct NewDecision { pub supersedes: Option, /// The rule or document it rests on, if any. pub citation: Option, - /// The projects (classes) it is about, if any (rules.md B-37). + /// The projects (classes) it is about, if any (BS-statement-5). pub projects: Vec, } diff --git a/crates/ledger-core/src/error.rs b/crates/ledger-core/src/error.rs index eda42bce..bb437d0d 100644 --- a/crates/ledger-core/src/error.rs +++ b/crates/ledger-core/src/error.rs @@ -55,7 +55,7 @@ pub enum LedgerError { TooLargeToCompute(String), /// An amount finer than its currency's smallest unit (ISO 4217 minor - /// units): no one can pay a fraction of a cent (rules.md B-3). + /// units): no one can pay a fraction of a cent (BS-ledger-1). #[error( "amount {amount} {currency} has more than {places} decimal places; round it to the {currency} minor unit first" )] @@ -505,7 +505,7 @@ pub enum LedgerError { end: String, }, - /// The statement of cash flows would not foot (rules.md B-14 rule 9): + /// The statement of cash flows would not foot (BS-statement-3 rule 9): /// 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,13 +523,13 @@ pub enum LedgerError { }, /// The cash flow statement's account roles (cash, financing, investing) - /// contradict each other or the chart (rules.md B-14 rule 2). The text + /// contradict each other or the chart (BS-statement-3 rule 2). The text /// names the setting and says what to change. #[error("cash flow account roles: {0}")] CashFlowRoles(String), /// A report period given only a start, after today: an omitted end is - /// today (rules.md B-30), so the period would end before it starts. + /// today (BS-period-3), so the period would end before it starts. #[error( "invalid date range: start {start} is after the end, which defaults to today ({today}): pass end" )] @@ -608,12 +608,12 @@ pub enum LedgerError { /// A document line's quantity and unit price don't multiply to its /// amount, or only one of the two is given: the engine never rounds - /// one (plan P4b S4.1; rules.md B-39). + /// one (plan P4b S4.1; BS-arap-3). #[error("{0}")] LineArithmetic(String), /// A document line is on an account that kind of document can't post - /// to (plan P4b S4.1, A-10; rules.md B-39): a role account, a cash + /// to (plan P4b S4.1, A-10; BS-arap-3): a role account, a cash /// account, or a type the document's side doesn't take. #[error("account {code} \"{name}\" cannot take {kind} line: {why}")] DocumentLineAccount { @@ -628,8 +628,8 @@ pub enum LedgerError { }, /// A vendor's invoice number (normalized) already names a standing - /// bill of that vendor, and no duplicate reason was given (rules.md - /// B-40). + /// bill of that vendor, and no duplicate reason was given ( + /// BS-arap-4). #[error( "vendor invoice number '{vendor_ref}' is already on another standing bill of this vendor; \ give duplicate_reason when it really is a second bill" @@ -642,7 +642,7 @@ pub enum LedgerError { }, /// An invoice number already names an invoice: numbers are never - /// reused (rules.md B-40, A-2). + /// reused (BS-arap-4, A-2). #[error("invoice number '{0}' is already used; numbers are never reused")] DuplicateInvoiceNumber(String), @@ -654,7 +654,7 @@ pub enum LedgerError { /// An early-payment discount needs net days to be open before: it /// can't be given with due-on-receipt, end-of-month or custom terms - /// (rules.md B-39). + /// (BS-arap-3). #[error( "an early-payment discount needs net terms with a fixed number of days; it can't be given with due-on-receipt, end-of-month or custom terms" )] @@ -662,7 +662,7 @@ pub enum LedgerError { /// `invoicing.first_number` asked to move after a numbered invoice /// exists: the series has begun, and a number is never reused or - /// renumbered (rules.md B-40, A-2). The store's check lands with the + /// renumbered (BS-arap-4, A-2). The store's check lands with the /// invoice numbers it reads (P4b S4.3). #[error( "invoicing.first_number is locked: a numbered invoice already exists, so the series has begun and its numbers are never reused" @@ -695,13 +695,13 @@ pub enum LedgerError { SettlementMixedKinds(String), /// A settlement's documents don't all belong to the one party it - /// names (rules.md B-42 INVARIANT 1). + /// names (BS-arap-6 INVARIANT 1). #[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 (rules.md B-42 INVARIANT 2). + /// discount date (BS-arap-6 INVARIANT 2). #[error( "{doc}: the discount of {discount} needs a reason ({because}); pass discount_reason with the payment" )] @@ -751,7 +751,7 @@ pub enum LedgerError { /// A settlement's figures can't be exact: the cash and discounts /// don't cover the applications, or the fee leaves a negative deposit - /// (rules.md B-42 INVARIANT 1). + /// (BS-arap-6 INVARIANT 1). #[error("{0}")] InvalidSettlement(String), @@ -761,7 +761,7 @@ pub enum LedgerError { InvalidPayment(String), /// Receivables or payables can't move while their account holds a - /// balance (rules.md B-23, B-38): that balance is the documents', and + /// balance (BS-ledger-8, BS-arap-2): that balance is the documents', and /// a hand entry moving it is refused by the control guard; it moves /// with its documents (plan P4b S7). #[error( @@ -781,7 +781,7 @@ pub enum LedgerError { }, /// Receivables or payables can't move to an account holding lines - /// that are no document's (rules.md B-38 INVARIANT 1): they would + /// that are no document's (BS-arap-2 INVARIANT 1): they would /// become hand lines on a control account. #[error( "account {code} \"{name}\" holds lines no invoice or bill carries (entry {entry} first), \ @@ -814,7 +814,7 @@ pub enum LedgerError { }, /// A line on a receivables or payables control account carries no - /// document (rules.md B-23, B-38): the control account must always + /// document (BS-ledger-8, BS-arap-2): the control account must always /// equal its documents, so only the document commands post there. #[error( "account {account} is a control account (its balance is its invoices or bills): {at} can't be posted there by hand. Use books.create_invoice, books.receive_payment, books.create_bill or books.pay_bill; to void a document, books.reverse_entry of its entry" @@ -828,14 +828,14 @@ pub enum LedgerError { }, /// A reversal or payment would leave a document owing less than nothing - /// or more than its total at some date (rules.md B-38 INVARIANT 2): the + /// or more than its total at some date (BS-arap-2 INVARIANT 2): the /// message says which document, when, and what to reverse first. #[error("{0}")] DocumentBounds(String), - /// A reversal is dated before the entry it reverses (rules.md B-9, + /// A reversal is dated before the entry it reverses (BS-ledger-5, /// D-73): a correction comes after what it corrects, for every kind of - /// entry. New commands only; replay never refuses (B-28). + /// entry. New commands only; replay never refuses (BS-entry-4). #[error("entry {entry} is dated {original}: its reversal can't be dated before it, on {date}")] ReversalBeforeOriginal { /// The entry reversed. @@ -852,12 +852,12 @@ pub enum LedgerError { /// A draft's state or discard was refused: the message says why (a /// note or reason that breaks the books' text rule, no reason given). - /// Plan P4, rules.md B-43. + /// Plan P4, BS-entry-5. #[error("{0}")] InvalidDraft(String), /// A void invoice can't be recorded as sent: it was never a document - /// the customer should have received (plan P4b S5, B-38). + /// the customer should have received (plan P4b S5, BS-arap-2). #[error("invoice {0} is void: a void invoice was never sent")] DocumentVoid(u64), @@ -866,8 +866,8 @@ pub enum LedgerError { /// books' text rule). Plan P4b S5. #[error("{0}")] InvalidSend(String), - /// A bad debt can't be written off on cash-basis books (rules.md - /// B-41 INVARIANT 3; IRC §166(a); Treas. Reg. §1.166-1(e)): the + /// 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 /// invoice was never counted as income, so there is no basis to /// deduct. #[error( @@ -937,11 +937,11 @@ pub enum LedgerError { UnknownClass(u32), /// Another class (project) already has this name, ignoring capitals - /// (rules.md B-37). + /// (BS-statement-5). #[error("a project named {0:?} already exists: names are unique, ignoring capitals")] DuplicateClassName(String), - /// A project's facts the books can't take (rules.md B-37): the reason. + /// A project's facts the books can't take (BS-statement-5): the reason. #[error("{0}")] InvalidProject(String), diff --git a/crates/ledger-core/src/evidence.rs b/crates/ledger-core/src/evidence.rs index 5fc940bf..6291fc43 100644 --- a/crates/ledger-core/src/evidence.rs +++ b/crates/ledger-core/src/evidence.rs @@ -121,7 +121,7 @@ impl Annotation { } // --------------------------------------------------------------------------- -// The evidence gate (plan P4, I-5, D-47; rules.md B-43) +// The evidence gate (plan P4, I-5, D-47; BS-entry-5) // --------------------------------------------------------------------------- /// What posted an entry that the ledger's own state doesn't otherwise say: @@ -196,7 +196,7 @@ impl Policy { } /// Total debits of the entry (one side of the balanced entry). A - /// draft's lines are as journaled, of any size (rules.md B-28): a + /// draft's lines are as journaled, of any size (BS-entry-4): a /// total past exact arithmetic is refused (TooLargeToCompute), never /// a panic. pub fn entry_debits(entry: &JournalEntry) -> Result { @@ -355,14 +355,14 @@ impl Policy { } /// Whether `entry` needs evidence before it posts: the one function that -/// decides (plan P4 step 2, I-5, D-47; rules.md B-43). The store's gate, +/// decides (plan P4 step 2, I-5, D-47; BS-entry-5). The store's gate, /// the server's previews and digest, the viewer and Needs attention all /// call it. /// /// ```text /// GOAL: one answer, from what the ledger knows, to "does this entry need /// a receipt". -/// SOURCE: docs/spec/rules.md B-43; IRS Pub. 583 (supporting documents); +/// SOURCE: BS-entry-5; IRS Pub. 583 (supporting documents); /// DECISION D-47 (a reversal's evidence is its original's, D-12); /// DECISION (owner: the threshold, strictly greater than, 2026-10-12). /// INVARIANTS: diff --git a/crates/ledger-core/src/form1099.rs b/crates/ledger-core/src/form1099.rs index be357298..6f17e822 100644 --- a/crates/ledger-core/src/form1099.rs +++ b/crates/ledger-core/src/form1099.rs @@ -383,14 +383,14 @@ pub fn apply_decision(decisions: &mut Vec, new: Dated1099) -> Applied } /// The checks a new 1099 decision passes before it is recorded (replay -/// skips them: rules.md B-28): the decision ([`Decision1099::check`]), +/// skips them: BS-entry-4): the decision ([`Decision1099::check`]), /// its source, its date in the books' calendar, and that a dated decision /// records a change. Returns what recording it would do. /// /// ```text /// GOAL: no dated decision silently leaves the vendor's earlier payments /// undecided. -/// SOURCE: DECISION D-40 (owner, 2026-10-20); docs/spec/rules.md B-19. +/// SOURCE: DECISION D-40 (owner, 2026-10-20); BS-1099-1. /// SCENARIOS: /// 1. IF `new` is dated, would be recorded, and no decision other than /// undetermined is in force at any time before its date: SHOULD @@ -428,7 +428,7 @@ pub fn check_new_decision(decisions: &[Dated1099], new: &Dated1099) -> Result Option; /// `self * rhs`, or `None` when it cannot be represented exactly. /// - /// A quantity times a unit price (a document line, B-39) is the one + /// A quantity times a unit price (a document line, BS-arap-3) is the one /// use: it never rounds. fn checked_mul(self, rhs: Self) -> Option; /// `self / rhs` exactly, or `None` when `rhs` is zero or the quotient @@ -38,8 +38,8 @@ pub trait Amount: Copy + Ord { /// [`Decimal`] dollars), ties away from zero; never a negative zero. /// `None` when `rhs` is zero or the quotient cannot be represented. /// - /// The one use is a tax category's deductible amount (rules.md B-32, - /// B-21), whose shares are added exactly and rounded once, never + /// The one use is a tax category's deductible amount (BS-ledger-11, + /// BS-entry-3), whose shares are added exactly and rounded once, never /// share by share. fn checked_div_round_cent(self, rhs: Self) -> Option; /// `self` rounded to a whole multiple of `step`, in `mode`; `None` @@ -330,7 +330,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: docs/spec/rules.md B-39 INVARIANT 2, B-42; 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: @@ -360,14 +360,14 @@ pub struct Settlement { pub deposit: T, } -/// The arithmetic of a settlement (rules.md B-42; plan P4b S6): each +/// The arithmetic of a settlement (BS-arap-6; plan P4b S6): each /// document's cash and discount, and the processor's fee withheld from the /// cash that reaches the bank. /// /// ```text /// GOAL: a settlement is exact: what the documents are settled by is the /// cash plus the discounts, and the deposit is the cash less the fee. -/// SOURCE: docs/spec/rules.md B-42; plan/served.md 8.3.6, 8.3.13 (B-42); +/// SOURCE: BS-arap-6; plan/served.md 8.3.6, 8.3.13 (BS-arap-6); /// CONVENTION; DECISION: the gross method (A-8) and the fee's /// gross presentation (A-4). /// INVARIANTS: @@ -412,7 +412,7 @@ pub fn settle(cash: &[T], discounts: &[T], fee: T) -> Option(quantity: T, unit_price: T) -> Option { /// ```text /// GOAL: a category's deductible amount is its exact shares added and /// rounded once, never a sum of rounded shares. -/// SOURCE: docs/spec/rules.md B-32 (CHOICE: owner, 2026-11-07, D-67) and -/// B-21 (Form 1065 instructions: "include cents when adding the +/// SOURCE: BS-ledger-11 (CHOICE: owner, 2026-11-07, D-67) and +/// BS-entry-3 (Form 1065 instructions: "include cents when adding the /// amounts and round off only the total"); plan/served.md 10.1. /// INVARIANTS: /// 1. On Some(a), a is the exact sum S = Σ(book_i × percent_i ÷ 100) @@ -579,7 +579,7 @@ pub fn credit_line(credit: T) -> Option<(Side, T)> { } // --------------------------------------------------------------------------- -// 1099 payments: where each payment line goes (rules.md B-19) +// 1099 payments: where each payment line goes (BS-1099-1) // --------------------------------------------------------------------------- /// A line's role in a payment to a vendor, from its account. @@ -646,7 +646,7 @@ impl Bucket { /// GOAL: every payment line to a vendor counts toward its 1099, is a card /// or payment-network payment (Form 1099-K), or is unknown; never /// guessed. -/// SOURCE: docs/spec/rules.md B-19 (Treas. Reg. §1.6041-1(a)(1)(iv): a +/// SOURCE: BS-1099-1 (Treas. Reg. §1.6041-1(a)(1)(iv): a /// transaction reportable under §6050W is not reported under /// §6041; §1.6041-1(e)(1): a member writing a check at the /// company's direction doesn't make the member the payor; @@ -693,7 +693,7 @@ pub fn split_payment(lines: &[(Option, Side, T)]) -> Option<[ /// ```text /// GOAL: a card bill paid from the bank, a member reimbursed, or a loan /// paid down never counts toward a vendor's 1099. -/// SOURCE: docs/spec/rules.md B-19 (26 U.S.C. §6041(a): payments made to +/// SOURCE: BS-1099-1 (26 U.S.C. §6041(a): payments made to /// the payee; P3 review R1, 2026-10-20). /// INVARIANTS: /// 1. The buckets' sum P is kept exactly. @@ -758,8 +758,8 @@ pub fn plug_last(whole: T, parts: &mut [T]) -> Option<()> { /// ```text /// GOAL: split a whole into parts, each a whole number of units where /// possible, summing to the whole exactly, without favoring anyone. -/// SOURCE: docs/spec/rules.md B-13 (shares: 26 U.S.C. §704(a); cent -/// rounding: DECISION, owner 2026-10-13), B-21 (exact totals). +/// SOURCE: BS-partner-1 (shares: 26 U.S.C. §704(a); cent +/// rounding: DECISION, owner 2026-10-13), BS-entry-3 (exact totals). /// INVARIANTS: /// 1. MUST make the parts sum to `whole` exactly. /// 2. MUST change each part by zero or one unit (the first in order @@ -835,7 +835,7 @@ pub fn apportion(whole: T, parts: &mut [T], remainders: &[T], unit: T /// ```text /// GOAL: members' running totals that never drift a unit from their /// exact shares, whatever earlier closes did. -/// SOURCE: docs/spec/rules.md B-13 (shares: 26 U.S.C. §704(a); capital +/// SOURCE: BS-partner-1 (shares: 26 U.S.C. §704(a); capital /// accounts carry the allocations: Treas. Reg. /// §1.704-1(b)(2)(iv)(b); cent rounding: DECISION, owner /// 2026-10-13; counted from the first close: D-10, 2026-10-16). @@ -880,7 +880,7 @@ pub fn apportion_cumulative( Some(()) } -/// Where a line falls on the statement of cash flows (rules.md B-14 rule +/// Where a line falls on the statement of cash flows (BS-statement-3 rule /// 2): a cash account, or one of the three sections. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] pub enum Flow { @@ -895,8 +895,8 @@ pub enum Flow { } impl Flow { - /// The three sections, in the order cash is applied to them (rules.md - /// B-14 rule 3): operating, investing, financing. + /// The three sections, in the order cash is applied to them ( + /// BS-statement-3 rule 3): operating, investing, financing. pub const SECTIONS: [Flow; 3] = [Flow::Operating, Flow::Investing, Flow::Financing]; } @@ -938,7 +938,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: rules.md B-14 rule 3 (ASC 230-10-50-5: only the cash portion +/// SOURCE: BS-statement-3 rule 3 (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: @@ -965,7 +965,7 @@ pub fn apply_cash(cash: T, movements: &[T], applied: &mut [T]) -> Opt (remaining == T::ZERO).then_some(()) } -/// An entry's cash flows (rules.md B-14 rule 3): the net movement of its +/// An entry's cash flows (BS-statement-3 rule 3): 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 @@ -1036,7 +1036,7 @@ fn credits_and_debits(movements: &[T]) -> Option<(T, T)> { } /// Which way money a member or a lender handled for the company went -/// (rules.md B-14 rule 11, D-42). +/// (BS-statement-3 rule 11, D-42). #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub enum OnBehalf { /// Paid for the company: sources credited (borrowed, contributed) @@ -1058,8 +1058,8 @@ impl OnBehalf { } /// What a member or a lender paid, or received, for the company with no -/// cash account moving: a constructive receipt and disbursement (rules.md -/// B-14 rule 11, D-42). `sources` are what is left unsettled of the +/// cash account moving: a constructive receipt and disbursement ( +/// BS-statement-3 rule 11, 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 = @@ -1075,7 +1075,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: rules.md B-14 rule 11 (D-42; ASC 230 is silent, PwC Viewpoint +/// SOURCE: BS-statement-3 rule 11 (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 @@ -1108,7 +1108,7 @@ pub fn constructive( } /// How much of an entry is an exchange inside investing and financing -/// that no cash settled (rules.md B-14 rule 7, ASC 230-10-50-4: debt +/// that no cash settled (BS-statement-3 rule 7, 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 @@ -1123,7 +1123,7 @@ pub fn exchanged(debits: T, credits: T, inflow: T, outflow: T) -> Opt Some(d.min(c).max(T::ZERO)) } -/// Which way an entry moved value with its parties (rules.md B-35). +/// Which way an entry moved value with its parties (BS-partner-3). #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub enum Direction { /// The company paid the party, or gave it value: a line on the @@ -1172,7 +1172,7 @@ impl Direction { } /// What an entry's parties split, and what of it counts in their totals -/// (rules.md B-35). +/// (BS-partner-3). #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct PartyTarget { /// The whole, signed as a line on the parties' own account would be @@ -1216,7 +1216,7 @@ fn least(a: T, b: T) -> T { if a < b { a } else { b } } -/// What an entry's parties split and what of it counts (rules.md B-35 +/// 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 /// handles: a close is its parties' own-account movement with direction /// neither, a reversal is [`reverse_target`] of its original's). @@ -1227,7 +1227,7 @@ fn least(a: T, b: T) -> T { /// money or as property, so a property contribution and its /// reversal never read alike, and a promise is never counted as if /// it were paid. -/// SOURCE: rules.md B-35 (B-2 signs; DECISION, owner, 2026-10-20: a +/// SOURCE: BS-partner-3 (BS-entry-2 signs; DECISION, owner, 2026-10-20: a /// member's entry counts what moved their capital, money is cash, /// cards, the members' financing and loans, and a liability credit /// never counts as paying that liability's own creditor; Helvering @@ -1321,7 +1321,7 @@ pub fn party_target( }) } -/// A reversal's target from its original's (rules.md B-35 item 3; B-9: a +/// A reversal's target from its original's (BS-partner-3 item 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. @@ -1495,10 +1495,10 @@ fn round_to_unit(num: T, den: T, unit: T) -> Option { /// GOAL: how much of a total a span of days has used up by a given day, /// each day of a month bearing the same share, the whole total /// reached on the span's last day and never before. -/// SOURCE: docs/spec/rules.md B-15 (straight line, partial months by days; +/// SOURCE: BS-asset-1 (straight line, partial months by days; /// ASC 360-10-35-4: "systematic and rational", as equitably as -/// possible to the periods served), B-16 (daily schedules, D-11), -/// B-21 (exact totals). +/// possible to the periods served), BS-prepaid-1 (daily schedules, D-11), +/// BS-entry-3 (exact totals). /// INVARIANTS (W = months × MONTH_L, m = part.month_days, d = part.days): /// 1. Not the last part: round(total × (before + k × MONTH_L / m) / W): /// the monthly rate total/months times the days held over the days @@ -1520,8 +1520,8 @@ fn round_to_unit(num: T, den: T, unit: T) -> Option { /// W), or any product overflows: /// - SHOULD return None /// - NEVER panic -/// BECAUSE a figure the books can't compute is refused (rules.md -/// B-28), and symbolic parts are not a calendar. +/// BECAUSE a figure the books can't compute is refused ( +/// BS-entry-4), and symbolic parts are not a calendar. /// 2. IF 12,000.00 over 12 months from Jan 1, through Dec 15 (the last /// part, 31 days, before = 11 months): /// - SHOULD be 11,000.00 + 1,000.00 × 15/31 = 11,483.87 @@ -1584,7 +1584,7 @@ pub fn prorated_through( /// ```text /// GOAL: one month's posting of a span spread by day (depreciation, /// daily prepaid and deferred-revenue schedules). -/// SOURCE: docs/spec/rules.md B-15, B-16 (D-11), B-21; plan/served.md P3 +/// SOURCE: BS-asset-1, BS-prepaid-1 (D-11), BS-entry-3; plan/served.md P3 /// defect 9 (one shared prorate_by_days, Kani: parts sum to the /// total, each is days × rate within one unit, the last absorbs /// the remainder). @@ -1651,7 +1651,7 @@ pub fn prorate_by_days( /// SOURCE: plan/served.md P3 "Settled in design" (2026-10-20): a month of /// depreciation skipped is caught up in the month the run is made /// (an immaterial miss; a material one is restated, ASC 250); -/// docs/spec/rules.md B-15. +/// BS-asset-1. /// INVARIANTS: /// 1. The result is >= 0. /// 2. Whenever every posted[i] <= scheduled[i], posted[i] + result <= @@ -1707,7 +1707,7 @@ pub fn catch_ups(scheduled: &[T], posted: &[T], out: &mut [T]) -> Opt /// ```text /// GOAL: a disposal clears exactly what the schedule says was used up /// through its day, whatever the runs posted. -/// SOURCE: docs/spec/rules.md B-15 (a disposed asset depreciates through +/// SOURCE: BS-asset-1 (a disposed asset depreciates through /// its disposal day); Ledger::dispose_asset INVARIANT 1 (gain = /// proceeds − book value at the disposal date). /// ``` @@ -1737,7 +1737,7 @@ pub struct BasisFigures { /// ```text /// GOAL: the three tax figures of an asset, each named for what it is, /// from one function the register, the tools and the viewer share. -/// SOURCE: docs/spec/rules.md B-25: IRC §1012(a) (cost); IRC §723 (the +/// SOURCE: BS-asset-4: IRC §1012(a) (cost); IRC §723 (the /// contributor's adjusted basis carries over); Treas. Reg. /// §1.168(i)-4(b)(1) (property converted from personal use: "the /// lesser of its fair market value or its adjusted depreciable @@ -1782,12 +1782,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 (rules.md B-37 item 4). +/// date: what it would take to be repaid in full (BS-statement-5 item 4). /// /// ```text /// GOAL: the "if repaid" figure of work done on spec, from one function /// the tools, the viewer and bookspec share. -/// SOURCE: docs/spec/rules.md B-37 item 4 (ASC 450-30-25-1: a hoped-for +/// SOURCE: BS-statement-5 item 4 (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: @@ -1826,7 +1826,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: docs/spec/rules.md B-38 INVARIANT 2 (0 <= outstanding(d, D) +/// SOURCE: BS-arap-2 INVARIANT 2 (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 @@ -1873,7 +1873,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: docs/spec/rules.md B-38 INVARIANT 2, B-28 (replay accepts what +/// SOURCE: BS-arap-2 INVARIANT 2, 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: @@ -1918,7 +1918,7 @@ pub fn bounds_kept(total: T, before: &[T], after: &[T]) -> Bounds { mod tests { use super::*; - /// rules.md B-14 rule 3, by hand. Equipment 1,000 for 300 cash and a + /// BS-statement-3 rule 3, 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] @@ -1964,7 +1964,7 @@ mod tests { assert_eq!(apply_cash(10, &[-3], &mut out), None); } - /// The exchange measure (rules.md B-14 rule 7) on the review's + /// The exchange measure (BS-statement-3 rule 7) on the review's /// hand-checked cases. #[test] fn exchanged_matches_the_hand_checked_cases() { @@ -1986,7 +1986,7 @@ mod tests { assert_eq!(exchanged(1000i64, 1000, 1000, 1000), Some(0)); } - /// rules.md B-14 rule 11 (D-42), by hand. + /// BS-statement-3 rule 11 (D-42), by hand. #[test] fn constructive_pays_and_receives_for_the_company() { use OnBehalf::{Paid, Received}; @@ -2339,7 +2339,7 @@ mod tests { assert!(!i64::MIN.in_line_range()); } - /// B-9: a reversal flips every side and keeps accounts and amounts, so + /// BS-ledger-5: a reversal flips every side and keeps accounts and amounts, so /// with the original it nets every account to zero. #[test] fn a_reversal_flips_every_line_and_nets_to_zero() { diff --git a/crates/ledger-core/src/kernel/fx.rs b/crates/ledger-core/src/kernel/fx.rs index 078238fc..0707b630 100644 --- a/crates/ledger-core/src/kernel/fx.rs +++ b/crates/ledger-core/src/kernel/fx.rs @@ -54,7 +54,7 @@ use rust_decimal::Decimal; /// from ISO 4217), and its CHOICE BS-ledger-14 /// "book-in-the-smallest-unit" (the owner, 2026-10-13: book in /// the smallest unit, half away from zero); wanderbooks -/// docs/spec/claims/ledger.md B-3 states the same pick. The +/// docs/spec/claims/ledger.md BS-ledger-1 states the same pick. The /// rounding itself is kernel::round_step (BS-ledger-1, /// BS-entry-3); owner decision D-69 (the laws live once, in /// bookspec's Lean). @@ -102,7 +102,7 @@ pub fn fx_booked(foreign: T, rate: T, step: T, mode: Rounding) -> Opt /// [`fx_booked`] at a currency's minor unit, on `Decimal`: the spelling /// `Ledger::add_line_fx` books through. A currency ISO 4217 gives no /// minor unit (gold, SDRs) books the exact product, as `round_minor` -/// has always done (B-3). The result's scale is the pre-kernel +/// has always done (BS-ledger-1). The result's scale is the pre-kernel /// computation's: `round_places` keeps an amount already at or under /// the minor places unchanged, and otherwise carries exactly the minor /// places (a booked 1.50 prints "1.50", never "1.5000"). diff --git a/crates/ledger-core/src/kernel/mod.rs b/crates/ledger-core/src/kernel/mod.rs index 89632270..39d36030 100644 --- a/crates/ledger-core/src/kernel/mod.rs +++ b/crates/ledger-core/src/kernel/mod.rs @@ -12,54 +12,54 @@ //! `docs/spec/rules.md`): //! //! * a line's signed amount is `+amount` for a debit, `-amount` for a credit -//! (B-2); +//! (BS-entry-2); //! * an entry is acceptable when it has two or more lines, every amount is -//! positive and in range, and its debits equal its credits exactly (B-1, -//! B-2, B-21); -//! * an acceptable entry nets to zero, account by account summed (B-1); +//! positive and in range, and its debits equal its credits exactly (BS-entry-1, +//! BS-entry-2, BS-entry-3); +//! * an acceptable entry nets to zero, account by account summed (BS-entry-1); //! * a reversal flips every side, so it is acceptable exactly when the -//! original is, and the two together net every account to zero (B-9); +//! original is, and the two together net every account to zero (BS-ledger-5); //! * an account's balance is its movement read on its normal side, so the //! balances satisfy the accounting equation whenever movements net to -//! zero (B-5, B-7); +//! zero (BS-ledger-3, BS-statement-2); //! * a trial balance puts each movement in exactly one column, so its -//! columns differ by the net of all movements (B-6); -//! * a closing line zeroes the account it closes (B-11); +//! columns differ by the net of all movements (BS-statement-1); +//! * a closing line zeroes the account it closes (BS-period-1); //! * a payment to a vendor splits, line by line, into what counts toward //! its 1099, what a card or payment network paid, and what is unknown, -//! and money moved between the company's own sources nets out (B-19); +//! and money moved between the company's own sources nets out (BS-1099-1); //! * an early-payment discount never exceeds its stated percentage of the //! total, and a document line's amount is exactly its quantity times its -//! unit price, neither rounded (B-39); +//! unit price, neither rounded (BS-arap-3); //! * an allocation's parts sum to the whole, to the last unit, by largest -//! remainder (B-13); +//! remainder (BS-partner-1); //! * a cumulative allocation hands out exactly the new amount, and leaves //! each running total one allocation of everything allocated, so it never -//! drifts a unit from its exact share (B-13); +//! drifts a unit from its exact share (BS-partner-1); //! * an entry's cash is applied to the sections of the statement of cash //! flows moving against it, in a fixed order, each up to its own //! movement: the parts sum to the entry's cash, what no cash settled sums -//! to zero, and a reversal's parts are the original's negated (B-14); +//! 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 (B-14 rule 11); +//! zero, and mirrored by a reversal (BS-statement-3 rule 11); //! * 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 (B-35); -//! * a span prorated by days (depreciation, B-15; daily schedules, B-16) +//! it counts as money or as property never exceeds it (BS-partner-3); +//! * a span prorated by days (depreciation, BS-asset-1; daily schedules, BS-prepaid-1) //! splits into parts that sum to its total, each but the last its days //! times the monthly rate within one unit, the last the remainder; //! * a catch-up run brings the books to the schedule without ever carrying -//! more than it says at a month end already posted (B-15), and a +//! more than it says at a month end already posted (BS-asset-1), and a //! disposal trues what the books carry up or down to the schedule; //! * an asset's basis figures follow from its basis rule and facts: the //! §723 basis is the contributor's adjusted basis, the depreciable basis //! the cost, that basis, or the lesser of it and fair market value, and //! the §704(c) built-in gain is fair market value less the §723 basis -//! (B-25); +//! (BS-asset-4); //! * a tax category's deductible amount adds its accounts' exact shares and //! rounds once to the cent, half away from zero, never share by share -//! (B-32, B-21). +//! (BS-ledger-11, BS-entry-3). //! //! The kernel is a module directory so each kernel-sweep unit adds its //! arithmetic in a file of its own (`fx`, `round`, `allocate`, `total`, diff --git a/crates/ledger-core/src/kernel/round.rs b/crates/ledger-core/src/kernel/round.rs index c8809540..864491ad 100644 --- a/crates/ledger-core/src/kernel/round.rs +++ b/crates/ledger-core/src/kernel/round.rs @@ -14,7 +14,7 @@ use rust_decimal::Decimal; #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum Rounding { /// Nearest multiple; an exact half rounds away from zero - /// (2.5 -> 3, -2.5 -> -3). The FX booking rule (B-3). + /// (2.5 -> 3, -2.5 -> -3). The FX booking rule (BS-ledger-1). HalfAwayFromZero, /// Nearest multiple; an exact half rounds to the even multiple /// (2.5 -> 2, 3.5 -> 4). Rust's `Decimal::round_dp`. @@ -30,12 +30,12 @@ pub enum Rounding { /// ```text /// GOAL: one rounding primitive: money is rounded to a whole multiple of a /// unit, once, with the mode named at the call. -/// SOURCE: docs/spec/claims/ledger.md B-3 (a ledger in one money holds no +/// SOURCE: docs/spec/claims/ledger.md BS-ledger-1 (a ledger in one money holds no /// fractions of its smallest unit; FX books the base currency's -/// minor unit, half away from zero), claims/entry.md B-21 (exact +/// minor unit, half away from zero), claims/entry.md BS-entry-3 (exact /// amounts in the books; round only where a rule says to), and -/// claims/ledger.md B-32; the call sites' own rules (B-13, B-14, -/// B-15, B-16, B-19, B-35, B-36, B-37); owner decision D-69 (the +/// claims/ledger.md BS-ledger-11; the call sites' own rules (BS-partner-1, BS-statement-3, +/// BS-asset-1, BS-prepaid-1, BS-1099-1, BS-partner-3, BS-partner-4, BS-statement-5); owner decision D-69 (the /// laws live once, in bookspec's Lean). /// INVARIANTS: /// 1. Some(r) is a whole multiple of step: r = n x step for an integer @@ -96,7 +96,7 @@ pub fn round_places(amount: Decimal, places: u32, mode: Rounding) -> Option Option { match currency.minor_units() { Some(places) => round_places(amount, places, mode), diff --git a/crates/ledger-core/src/kernel/total.rs b/crates/ledger-core/src/kernel/total.rs index fe73dea8..76e77655 100644 --- a/crates/ledger-core/src/kernel/total.rs +++ b/crates/ledger-core/src/kernel/total.rs @@ -3,7 +3,7 @@ //! The sum of a collection of money figures, in one place. A raw `Decimal` //! `+`, `+=` or `.sum()` panics at `Decimal::MAX`; these return `None` //! instead, so the caller can refuse with `TooLargeToCompute` and never -//! crash a book (rules.md B-28: a replayed journal line is accepted "of +//! crash a book (BS-entry-4: a replayed journal line is accepted "of //! any size", so a restored figure is the realistic path to the edge). //! The signed sum of `(Side, amount)` lines is [`super::net`] and the pair //! of columns [`super::totals`]; they were here first and stay the one @@ -17,8 +17,8 @@ use super::Amount; /// ```text /// GOAL: a book's or report's total is the exact sum of its figures, or /// refused; no total is ever rounded, wrapped or a crash. -/// SOURCE: docs/spec/rules.md B-21 (amounts are exact; rounding is -/// confined to returns), B-28 (replayed lines are accepted "of any +/// SOURCE: BS-entry-3 (amounts are exact; rounding is +/// confined to returns), BS-entry-4 (replayed lines are accepted "of any /// size"; no input may reach a panic); bookspec BS-entry-3, /// BS-entry-4; CONVENTION. /// INVARIANTS: @@ -49,7 +49,7 @@ pub fn total(values: impl IntoIterator) -> Option { /// ```text /// GOAL: the sum of a mapped field (a row's amount, a member's share) is /// the exact sum of the mapping, or refused. -/// SOURCE: docs/spec/rules.md B-21, B-28; bookspec BS-entry-3, +/// SOURCE: BS-entry-3, BS-entry-4; bookspec BS-entry-3, /// BS-entry-4; CONVENTION. /// INVARIANTS: /// 1. total_of(items, f) = total(f(item) for item in items), exactly. @@ -69,7 +69,7 @@ pub fn total_of( /// ```text /// GOAL: the sum of a derived figure (a column's contributions less its /// distributions) is exact, or refused. -/// SOURCE: docs/spec/rules.md B-21, B-28; bookspec BS-entry-3, +/// SOURCE: BS-entry-3, BS-entry-4; bookspec BS-entry-3, /// BS-entry-4; CONVENTION. /// INVARIANTS: /// 1. total_try(items, f) = Some(Σ f(item)) exactly when every f(item) diff --git a/crates/ledger-core/src/ledger.rs b/crates/ledger-core/src/ledger.rs index 8e85a1d7..97a03a7f 100644 --- a/crates/ledger-core/src/ledger.rs +++ b/crates/ledger-core/src/ledger.rs @@ -120,7 +120,7 @@ pub const PAYMENT_PROCESSING_FEES: ControlAccount = control( AccountType::Expense, ); /// A control account; see [`ControlAccount`]. Bad-debt expense (plan P4b -/// S7, 8.3.4; rules.md B-41): where a write-off's debit goes, created on +/// S7, 8.3.4; BS-arap-5): where a write-off's debit goes, created on /// demand like the others. pub const BAD_DEBTS: ControlAccount = control( "bad_debts", @@ -276,7 +276,7 @@ pub struct Ledger { payroll_runs: HashMap, /// Classes for divisional P&L tracking. classes: HashMap, - /// The project facts set for classes (rules.md B-37); a class not here + /// The project facts set for classes (BS-statement-5); a class not here /// has the defaults. projects: std::collections::BTreeMap, next_account_id: AccountId, @@ -303,7 +303,7 @@ pub struct Ledger { /// The payment method each entry was paid with, for 1099 reporting. entry_instruments: HashMap, /// The document each receivables or payables line belongs to, by - /// (entry, line index) (rules.md B-38, plan P4b.3): written by the + /// (entry, line index) (BS-arap-2, plan P4b.3): written by the /// document commands in the step that posts the line, derived on /// replay from the document events, and copied onto a reversal's /// mirror line. Every figure about a document is read from these. @@ -493,8 +493,8 @@ impl Ledger { /// /// ```text /// GOAL: a schedule month is never recognized twice at a month end. - /// SOURCE: docs/spec/rules.md B-9 (a correction is dated when it is - /// made), B-16; P3 depreciation review R3 (a reversed month is + /// SOURCE: BS-ledger-5 (a correction is dated when it is + /// made), BS-prepaid-1; P3 depreciation review R3 (a reversed month is /// due again: when the reversal is the month's own). /// ``` pub fn schedule_month_reversed_after( @@ -645,7 +645,7 @@ impl Ledger { /// [`Self::register_recurring`] with the checks every journaled /// `recurring.registered` passed when it was written /// (schedules::validate_recurring_journaled), for replay only - /// (rules.md B-28). Never for new work. + /// (BS-entry-4). Never for new work. pub fn replay_register_recurring( &mut self, new: NewRecurring, @@ -689,7 +689,7 @@ impl Ledger { /// /// ```text /// GOAL: turn one due occurrence of a recurring entry into a draft. - /// SOURCE: docs/spec/rules.md B-12; Lean invariant Inv.draftsOpen. + /// SOURCE: BS-period-2; Lean invariant Inv.draftsOpen. /// SCENARIOS: /// 1. IF the date falls in a closed period: /// - SHOULD refuse (ClosedPeriod) @@ -732,8 +732,8 @@ impl Ledger { let (description, lines) = (r.description.clone(), r.lines.clone()); let entry = self.create_entry(date, &description); for (account, side, money) in lines { - // The template's lines as journaled: no size bound (rules.md - // B-28); a draft too large to post is refused at its post. + // The template's lines as journaled: no size bound ( + // BS-entry-4); a draft too large to post is refused at its post. if let Err(e) = self.add_line_journaled(entry, account, side, money, false) { self.entries.remove(&entry); self.next_entry_id = entry; @@ -954,11 +954,11 @@ impl Ledger { /// ```text /// GOAL: register an account under a unique code and a name no /// sibling has. - /// SOURCE: rules.md B-4 (the five elements); R-4; DECISION (owner, - /// 2026-10-13): a child has its parent's type; rules.md B-31 + /// SOURCE: BS-ledger-2 (the five elements); R-4; DECISION (owner, + /// 2026-10-13): a child has its parent's type; BS-ledger-10 /// (names: QuickBooks matches accounts by name, /// docs/spec/sources/intuit-iif.md; no full TIN in what every - /// report prints, B-26; DECISION, owner, 2026-10-20). + /// report prints, BS-partner-2; DECISION, owner, 2026-10-20). /// SCENARIOS: /// 1. IF the code is empty or taken: SHOULD refuse. /// 2. IF the parent doesn't exist: SHOULD refuse. @@ -1021,7 +1021,7 @@ impl Ledger { /// Create the account a control role posts to, at its code with its /// name (invoices, bills, payroll and closes create them when first /// needed). The engine's own names: never refused for a sibling's - /// name, and never for a missing tax category (rules.md B-32), so an + /// name, and never for a missing tax category (BS-ledger-11), so an /// invoice is never refused over a chart label. pub fn add_control_account(&mut self, c: &ControlAccount) -> Result { self.replay_add_account(c.code, c.name, c.account_type, None, false) @@ -1128,8 +1128,8 @@ impl Ledger { /// /// ```text /// GOAL: let the human rename an account without touching its history. - /// SOURCE: rules.md B-31; DECISION (owner, plan/served.md 4.9 and P3 - /// "Settled in design", 2026-10-20); rules.md B-8 (posted is + /// SOURCE: BS-ledger-10; DECISION (owner, plan/served.md 4.9 and P3 + /// "Settled in design", 2026-10-20); BS-ledger-4 (posted is /// forever: entries name accounts by id, so a name is a label). /// INVARIANTS: /// 1. Only the name changes: the account's id, code, type, parent, @@ -1140,7 +1140,7 @@ impl Ledger { /// 2. A refusal MUST leave the books unchanged. /// 3. The rules are the command's: replay takes any journaled name /// for an account that exists (Self::replay_rename_account, - /// rules.md B-28). + /// BS-entry-4). /// SCENARIOS: /// 1. IF the account is unknown: SHOULD refuse with UnknownAccount. /// 2. IF the name is blank: SHOULD refuse with EmptyAccountName. @@ -1185,7 +1185,7 @@ impl Ledger { /// Replay a journaled rename: the account must exist; the name is /// taken as journaled, whatever later versions refuse in a new one - /// (rules.md B-28). + /// (BS-entry-4). pub fn replay_rename_account( &mut self, account: AccountId, @@ -1196,8 +1196,8 @@ impl Ledger { /// Check a rename's reason before it is journaled: one to /// [`crate::settings::MAX_LONG_TEXT`] characters, line breaks and tabs - /// allowed but no other control character, and no full TIN (rules.md - /// B-26). Returns it trimmed. + /// allowed but no other control character, and no full TIN ( + /// BS-partner-2). Returns it trimmed. pub fn check_rename_reason(reason: &str) -> Result { let r = crate::settings::long_text("reason", reason, crate::settings::MAX_LONG_TEXT) .map_err(LedgerError::InvalidRenameReason)?; @@ -1210,9 +1210,9 @@ impl Ledger { } /// Whether `policy.require_tax_category` lets an account be created - /// with `category` (rules.md B-32): under `refuse`, a revenue or + /// with `category` (BS-ledger-11): under `refuse`, a revenue or /// expense account that isn't a header needs one. The command's check - /// only, never replay's (rules.md B-28); the accounts the engine + /// only, never replay's (BS-entry-4); the accounts the engine /// creates for a control role never meet it. pub fn check_tax_category_required( &self, @@ -1235,7 +1235,7 @@ impl Ledger { } /// Whether `policy.require_tax_category` lets `account`'s category be - /// set to `category` (rules.md B-32): under `refuse`, an account that + /// set to `category` (BS-ledger-11): under `refuse`, an account that /// needs one ([`crate::tax::account_needs_category`]) keeps one. The /// command's check only, never replay's. pub fn check_tax_category_kept( @@ -1328,7 +1328,7 @@ impl Ledger { /// ```text /// GOAL: let a chart keep its own numbering: the engine's roles go to /// the accounts the human picks, not only to fixed codes. - /// SOURCE: docs/spec/rules.md B-4 (the elements), B-23 (control roles); + /// SOURCE: BS-ledger-2 (the elements), BS-ledger-8 (control roles); /// DECISION (owner, 2026-10-15): roles are journaled, not /// configured, so replay never depends on a file. /// INVARIANTS: @@ -1356,7 +1356,7 @@ impl Ledger { /// freely. /// - For receivables and payables: DocumentRoleHoldsBalance /// instead, which names no hand entry (the control guard - /// refuses one, B-38): their balance moves with its documents, + /// refuses one, BS-arap-2): their balance moves with its documents, /// a later command (plan P4b S7). Only on their control account /// (Self::control_role_of): the account at the default code, /// before any document posted there, is the chart's own, and @@ -1367,8 +1367,8 @@ impl Ledger { /// would move to holds a posted line that is no document's: /// - SHOULD refuse (RoleAccountHasHandLines), naming the entry /// - NEVER make a hand line a control account's - /// BECAUSE no command adds an untagged control line (B-38 - /// INVARIANT 1). Replay never refuses (B-28). + /// BECAUSE no command adds an untagged control line (BS-arap-2 + /// INVARIANT 1). 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). /// ``` @@ -1539,7 +1539,7 @@ impl Ledger { /// /// ```text /// GOAL: start a draft entry for new work. - /// SOURCE: docs/spec/rules.md B-12; Lean invariant Inv.draftsOpen. + /// SOURCE: BS-period-2; Lean invariant Inv.draftsOpen. /// SCENARIOS: /// 0. IF the date is outside the calendar the books keep /// (crate::calendar): SHOULD refuse (DateOutOfRange). @@ -1601,7 +1601,7 @@ impl Ledger { /// post (P0 review round 3, S1); a recurring entry's draft is generated /// with the checks its template passed when it was journaled /// (`bounded` false), so a journaled `recurring.generated` always - /// replays (rules.md B-28). + /// replays (BS-entry-4). fn add_line_journaled( &mut self, entry: EntryId, @@ -1620,7 +1620,7 @@ impl Ledger { } /// The document role an account is the control account of, if any: - /// receivables or payables (rules.md B-23, B-38; a later control role + /// receivables or payables (BS-ledger-8, BS-arap-2; a later control role /// joins them). An account is one when the role is assigned to it /// ([`Self::assign_role`]), or when it holds a line of one of the /// role's documents (the role's default code, once a document has @@ -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: docs/spec/rules.md B-23, B-38 INVARIANT 1. + /// SOURCE: BS-ledger-8, BS-arap-2 INVARIANT 1. /// 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 @@ -1670,7 +1670,7 @@ impl Ledger { /// Refuse a line by hand on a control account (the control guard, /// plan P4b.3): such a line is the document commands' alone, so the - /// account always equals its documents. Replay never refuses (B-28). + /// account always equals its documents. Replay never refuses (BS-entry-4). fn check_hand_line(&self, entry: EntryId, account: AccountId) -> Result<(), LedgerError> { if crate::parties::is_replaying() || self.control_role_of(account).is_none() { return Ok(()); @@ -1730,12 +1730,12 @@ impl Ledger { /// a receivables or payables account carries its document, but the /// mirror of an untagged line in a reversal that takes it off the /// books (reversing an old hand line is how it is cleaned up). - /// Replay never refuses (B-28). + /// Replay never refuses (BS-entry-4). /// /// ```text /// GOAL: no command adds a line on a control account that is no /// document's; one only takes a legacy one away. - /// SOURCE: docs/spec/rules.md B-38 INVARIANT 1 and item 3 (the + /// SOURCE: BS-arap-2 INVARIANT 1 and item 3 (the /// exemption). /// INVARIANTS: /// 1. A tagged line passes. @@ -1793,7 +1793,7 @@ impl Ledger { /// [`Self::add_line`] without the account check added on 2026-10-13 or /// the size bound added in P0, for replaying journals written before - /// them (rules.md B-28): a draft line replays as journaled, and its post + /// them (BS-entry-4): a draft line replays as journaled, and its post /// refuses it if it is out of range. Never for new work. pub fn replay_add_line( &mut self, @@ -1829,11 +1829,11 @@ impl Ledger { /// /// ```text /// GOAL: book a foreign-currency amount in the ledger's one money. - /// SOURCE: docs/spec/rules.md B-3 (Pacioli ch. 36: one money; ASC + /// SOURCE: BS-ledger-1 (Pacioli ch. 36: one money; ASC /// 830-20-30-1: at the transaction-date rate); minor units: ISO /// 4217; rounding: DECISION (owner, 2026-10-13); the ten-place /// bound (invariant 3): DECISION D-75 (owner, 2026-11-08), - /// B-28's bound, stated in bookspec BS-entry-4. + /// BS-entry-4's bound, stated in bookspec BS-entry-4. /// INVARIANTS: /// 1. The base amount MUST be a whole number of the base currency's /// smallest unit, within half a unit of foreign * rate. @@ -1877,7 +1877,7 @@ impl Ledger { } // D-75 (owner, 2026-11-08): a new line's foreign amount and its // rate take at most MAX_LINE_SCALE places each, as a base amount - // does (B-28), so their product has at most twice that many (20, + // does (BS-entry-4), so their product has at most twice that many (20, // under Decimal's 28) and keeps its scale: the booked amount is // rounded once, not after Decimal's own rounding of the product. // (A 20-place product past about 7.9e8 still outgrows Decimal's 96 @@ -1893,7 +1893,7 @@ impl Ledger { } // Booked in the base currency's smallest unit (cents for USD), half // away from zero: a ledger in one money holds no fractions of its - // smallest unit (rules.md B-3; DECISION, owner 2026-10-13, after + // smallest unit (BS-ledger-1; DECISION, owner 2026-10-13, after // the GnuCash cross-check found the difference). The kernel's // fx_booked_minor is that computation (foreign x rate exactly, // rounded once); the rate and zero-result refusals above and @@ -1921,7 +1921,7 @@ impl Ledger { /// A foreign-currency line exactly as a journal recorded it: the base /// amount as booked (rounded or not, by the rule of its day, and of any - /// size: the bound is the command's, rules.md B-28) and the foreign + /// size: the bound is the command's, BS-entry-4) and the foreign /// original. For replay only; new work uses [`Self::add_line_fx`]. pub fn replay_add_line_fx( &mut self, @@ -1956,8 +1956,8 @@ impl Ledger { /// /// ```text /// GOAL: make a draft part of the books, once and for good. - /// SOURCE: docs/spec/rules.md B-1, B-2, B-3, B-8 (Pacioli ch. 36: write - /// only forward), B-12. + /// SOURCE: BS-entry-1, BS-entry-2, BS-ledger-1, BS-ledger-4 (Pacioli ch. 36: write + /// only forward), BS-period-2. /// INVARIANTS: /// 1. MUST post only an entry that passes JournalEntry::validate. /// 2. MUST append it to the log; NEVER reorder, change, or remove an @@ -1975,17 +1975,17 @@ impl Ledger { /// 5. IF a line is finer than its currency's minor unit (a fraction /// of a cent): SHOULD refuse (FinerThanMinorUnit) /// BECAUSE a ledger in one money holds no fractions of its - /// smallest unit (B-3); found when a payroll run posted $65.27794 + /// smallest unit (BS-ledger-1); found when a payroll run posted $65.27794 /// (the store's refusal property in CI, 2026-10-13). /// 6. IF a line is on a receivables or payables account (the role's /// account now) and carries no document: /// - SHOULD refuse (UntaggedControlLine), naming the document /// tools /// - NEVER refuse the mirror of an untagged line in a reversal - /// BECAUSE a control account must equal its documents (B-23, - /// B-38): only the document commands post there, and reversing + /// BECAUSE a control account must equal its documents (BS-ledger-8, + /// BS-arap-2): only the document commands post there, and reversing /// an old hand line is how it is cleaned up. Replay never - /// refuses (B-28). + /// refuses (BS-entry-4). /// ``` pub fn post_entry(&mut self, entry: EntryId) -> Result<(), LedgerError> { if let Some(e) = self.entries.get(&entry) { @@ -2036,13 +2036,13 @@ impl Ledger { } /// Set where a draft stands: still being built, or awaiting its - /// evidence (plan P4, rules.md B-43). A state is a note on the draft + /// evidence (plan P4, BS-entry-5). A state is a note on the draft /// and moves no figure; the draft's lines are what they were. /// /// ```text /// GOAL: let a draft say it is finished and waiting on a document, /// so it is neither lost nor mistaken for work in progress. - /// SOURCE: docs/spec/rules.md B-43 (DECISION D-47: a draft waits on + /// SOURCE: BS-entry-5 (DECISION D-47: a draft waits on /// evidence; the evidence is checked when it posts); IRS /// Pub. 583 "supporting documents". /// INVARIANTS: @@ -2064,8 +2064,8 @@ impl Ledger { Ok(()) } - /// [`Self::set_draft_state`] as journaled, for replay (rules.md - /// B-28): the state is restored on a draft that exists; a state + /// [`Self::set_draft_state`] as journaled, for replay ( + /// BS-entry-4): the state is restored on a draft that exists; a state /// naming an entry since posted or discarded is refused like the /// command, which journal order makes impossible. #[doc(hidden)] @@ -2078,7 +2078,7 @@ impl Ledger { Ok(()) } - /// Throw a draft away, with the reason (plan P4, rules.md B-43): the + /// Throw a draft away, with the reason (plan P4, BS-entry-5): the /// only way out of an open draft that will never post, and so the way /// a period it holds open can close. The draft was never in the books, /// so no balance moves; the id is spent (ids are never reused); the @@ -2087,7 +2087,7 @@ impl Ledger { /// ```text /// GOAL: remove a draft that will not post, leaving the books and /// every id as they were. - /// SOURCE: docs/spec/rules.md B-43; B-8 (a posted entry is never + /// SOURCE: BS-entry-5; BS-ledger-4 (a posted entry is never /// removed: only a draft is); Lean Step.discard. /// INVARIANTS: /// 1. Only a draft is discarded: a posted entry is refused @@ -2235,8 +2235,8 @@ impl Ledger { /// /// ```text /// GOAL: decide whether `entry` may be reversed on `date`. - /// SOURCE: docs/spec/rules.md B-9 (Pacioli ch. 31, 36), B-10 (DECISION, - /// owner 2026-10-13), B-12 (closed periods). + /// SOURCE: BS-ledger-5 (Pacioli ch. 31, 36), BS-ledger-6 (DECISION, + /// owner 2026-10-13), BS-period-2 (closed periods). /// INVARIANTS: /// 1. MUST NOT mutate anything. /// 2. NEVER accepts a reversal that `reverse_entry` would then refuse. @@ -2269,10 +2269,10 @@ impl Ledger { /// - SHOULD refuse (ReversalBeforeOriginal) /// - NEVER refuse the same day /// - NEVER refuse on replay - /// BECAUSE a correction comes after what it corrects (B-9; owner + /// BECAUSE a correction comes after what it corrects (BS-ledger-5; owner /// decision D-73, 2026-11-08; plan P4b.3, "Dating rules"). Books /// written before D-73 may hold an earlier-dated reversal and - /// reopen as they were (B-28). + /// reopen as they were (BS-entry-4). /// 7. IF reversing it would leave a document it carries owing less /// than nothing or more than its total at some date (a void /// under a payment that stands; re-instating a payment beside @@ -2281,8 +2281,8 @@ impl Ledger { /// reverse first /// - NEVER refuse reversing a payment, which only reopens its /// document - /// BECAUSE 0 <= outstanding <= total at every date (B-38 - /// INVARIANT 2). Replay never refuses (B-28). + /// BECAUSE 0 <= outstanding <= total at every date (BS-arap-2 + /// INVARIANT 2). Replay never refuses (BS-entry-4). /// ``` pub fn check_reversal(&self, entry: EntryId, date: NaiveDate) -> Result<(), LedgerError> { let original = self @@ -2372,8 +2372,8 @@ impl Ledger { /// for nothing. /// /// ```text - /// SOURCE: docs/spec/rules.md B-9 (a mistake is corrected by an - /// opposite entry), B-10 (reversed at most once; reversing the + /// SOURCE: BS-ledger-5 (a mistake is corrected by an + /// opposite entry), BS-ledger-6 (reversed at most once; reversing the /// reversal re-instates it). /// ``` pub fn in_effect(&self, entry: EntryId) -> bool { @@ -2388,7 +2388,7 @@ impl Ledger { /// ```text /// GOAL: say whether an entry counts on a given day, so a document's /// status (a void) and its aging are right as of any date. - /// SOURCE: docs/spec/rules.md B-9, B-10, B-38; plan/served.md P4b.3 + /// SOURCE: BS-ledger-5, BS-ledger-6, BS-arap-2; plan/served.md P4b.3 /// ("Standing as of a date"). /// INVARIANTS: /// 1. stands_on(e, NaiveDate::MAX) is in_effect(e). @@ -2455,7 +2455,7 @@ impl Ledger { /// [`Self::reverse_entry`] as a journal recorded it: without the /// checks later versions added for documents (a reversal's date, a /// document's bounds, the control guard), for replaying journals - /// written before them (rules.md B-28). Never for new work. + /// written before them (BS-entry-4). Never for new work. pub fn replay_reverse_entry( &mut self, entry: EntryId, @@ -2487,7 +2487,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 (B-38 INVARIANT 3). + // it moves by exactly the opposite (BS-arap-2 INVARIANT 3). if line.class_id.is_some() { self.set_line_class(id, idx, line.class_id)?; } @@ -2553,7 +2553,7 @@ impl Ledger { /// refused like one past chrono's last day (P0 review round 3, S1; P3: /// the bound is the last day held, so a life ending on 9999-12-31 is /// taken); and the cost and salvage in the currency's minor unit - /// (rules.md B-3: every depreciation and disposal line derives from + /// (BS-ledger-1: every depreciation and disposal line derives from /// them, and a line finer than a cent could never post). pub fn validate_new_asset(&self, new: &NewAsset) -> Result<(), LedgerError> { self.check_new_asset(new, true) @@ -2563,7 +2563,7 @@ impl Ledger { /// passed when it was written (the rule through 2026-10-16): /// [`Self::validate_new_asset`] without the calendar bound or the minor /// unit, the end of the life only representable. Replay applies - /// exactly these (rules.md B-28). + /// exactly these (BS-entry-4). pub fn validate_new_asset_journaled(&self, new: &NewAsset) -> Result<(), LedgerError> { self.check_new_asset(new, false) } @@ -2636,7 +2636,7 @@ impl Ledger { /// /// ```text /// GOAL: put a fixed asset on the register, to depreciate monthly. - /// SOURCE: docs/spec/rules.md B-15; B-22 (capitalize vs expense). + /// SOURCE: BS-asset-1; BS-asset-2 (capitalize vs expense). /// SCENARIOS: /// 1. IF the description is blank, cost isn't positive, salvage is /// negative or not below cost, the useful life is zero months, or the @@ -2649,8 +2649,8 @@ impl Ledger { /// [`Self::register_asset`] with the checks every journaled /// `asset.registered` passed when it was written - /// ([`Self::validate_new_asset_journaled`]), for replay only (rules.md - /// B-28). Never for new work. + /// ([`Self::validate_new_asset_journaled`]), for replay only ( + /// BS-entry-4). Never for new work. pub fn replay_register_asset(&mut self, new: NewAsset) -> Result { self.validate_new_asset_journaled(&new)?; self.insert_asset(new) @@ -2782,7 +2782,7 @@ impl Ledger { /// ```text /// GOAL: from an asset, its source document and capital entry; from /// the entry, the asset; and the day the company acquired it. - /// SOURCE: DECISION (owner, 2026-10-15); rules.md B-15 (P3, settled in + /// SOURCE: DECISION (owner, 2026-10-15); BS-asset-1 (P3, settled in /// design 2026-10-20: an asset's acquired date comes from the /// entry it is linked to). /// INVARIANTS: @@ -2790,7 +2790,7 @@ impl Ledger { /// reversed, and debits the asset's cost account. /// 2. The linked entry is dated on or before the asset's in-service /// date, and on or before its disposal: the register then holds - /// the asset exactly while the books carry its cost (B-24). + /// the asset exactly while the books carry its cost (BS-asset-3). /// 3. A refusal MUST leave the books unchanged. /// SCENARIOS: /// 1. IF the asset or entry is unknown, or the entry fails 1 or 2: @@ -2811,7 +2811,7 @@ impl Ledger { /// [`Self::set_asset_acquisition`] with the checks every journaled /// `asset.acquisition_linked` passed when it was written (INVARIANT 1, - /// without the dates of INVARIANT 2), for replay only (rules.md B-28). + /// without the dates of INVARIANT 2), for replay only (BS-entry-4). pub fn replay_set_asset_acquisition( &mut self, id: AssetId, @@ -2859,8 +2859,8 @@ impl Ledger { /// /// ```text /// GOAL: the register holds an asset from the day the books carry its - /// cost, which can be before it serves (B-24). - /// SOURCE: rules.md B-15, B-24; P3, settled in design (2026-10-20): + /// cost, which can be before it serves (BS-asset-3). + /// SOURCE: BS-asset-1, BS-asset-3; P3, settled in design (2026-10-20): /// "an asset's acquired date comes from the entry it is linked /// to". /// INVARIANTS: @@ -2993,7 +2993,7 @@ impl Ledger { /// GOAL: the register carries the tax figures beside book value, each /// named for what it is, so book and tax never get confused and /// the CPA sees both. - /// SOURCE: docs/spec/rules.md B-25; docs/spec/sources/ + /// SOURCE: BS-asset-4; docs/spec/sources/ /// irs-partnership-basis.md; DECISION D-41 (owner, 2026-10-20). /// INVARIANTS: /// 1. The record passes AssetBasis::check: a purchase takes no @@ -3034,7 +3034,7 @@ impl Ledger { /// [`Self::set_asset_basis`] with the checks every journaled /// `asset.basis_set` passed (AssetBasis::check_journaled: the facts fit /// the rule, none negative, no bound on size), for replay and the - /// projection's read-back only (rules.md B-28). The figures the line + /// projection's read-back only (BS-entry-4). The figures the line /// carries are for its readers: replay never recomputes them, so a /// later change to how a figure is derived never refuses books an /// earlier version wrote. Never for new work. @@ -3057,7 +3057,7 @@ impl Ledger { /// Replay a pre-P3 `asset.tax_basis_set` (rule and contributor basis, /// no value at contribution, which reads as the book cost): the checks /// it passed when written (AssetBasis::check_legacy_journaled), for - /// replay and the projection's read-back only (rules.md B-28). Never for + /// replay and the projection's read-back only (BS-entry-4). Never for /// new work. pub fn replay_set_asset_tax_basis( &mut self, @@ -3116,8 +3116,8 @@ impl Ledger { /// [`Self::correct_asset`] with the checks every journaled /// `asset.corrected` passed when it was written - /// ([`Self::validate_new_asset_journaled`]), for replay only (rules.md - /// B-28). Never for new work. + /// ([`Self::validate_new_asset_journaled`]), for replay only ( + /// BS-entry-4). Never for new work. pub fn replay_correct_asset( &mut self, id: AssetId, @@ -3212,7 +3212,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: rules.md B-15 rules 6 and 8, B-24; B-28 (new commands are bounded; replay checks + /// SOURCE: BS-asset-1 rules 6 and 8, BS-asset-3; BS-entry-4 (new commands are bounded; replay checks /// only what every journaled run passed: /// record_depreciation_run). /// ``` @@ -3263,7 +3263,7 @@ impl Ledger { /// Record a depreciation run (`asset.depreciation_posted`). Checks only /// that the asset and the entry exist: every run an earlier version - /// journaled replays, whatever its period or amount (rules.md B-28; a + /// journaled replays, whatever its period or amount (BS-entry-4; a /// store checks new runs first, [`Self::check_depreciation_run`]). A /// second line for the same asset, period and entry (a journal edited /// by hand; a store never writes one) is the run already recorded: one @@ -3300,7 +3300,7 @@ impl Ledger { } /// Each posted reversal's original: original entry → its reversal (an - /// entry is reversed at most once, B-10). Read once for many runs + /// entry is reversed at most once, BS-ledger-6). Read once for many runs /// ([`assets::depreciation_effects`], [`Self::accumulated_posted_all`]), /// never per run: the viewer asks it of every asset. pub(crate) fn posted_reversals(&self) -> HashMap { @@ -3333,9 +3333,9 @@ impl Ledger { /// ```text /// GOAL: book value is cost less what the books carry, never the /// schedule's figure. - /// SOURCE: rules.md B-24 (the register reconciles to the general - /// ledger); B-8, B-9, B-10 (a reversal undoes what it reverses, - /// and reversing the reversal reinstates it); B-15 (what the + /// SOURCE: BS-asset-3 (the register reconciles to the general + /// ledger); BS-ledger-4, BS-ledger-5, BS-ledger-6 (a reversal undoes what it reverses, + /// and reversing the reversal reinstates it); BS-asset-1 (what the /// catch-up rule reads, the same entries). /// INVARIANTS: /// 1. Disposed on or before as_of: 0. @@ -3439,7 +3439,7 @@ impl Ledger { /// /// ```text /// GOAL: take an asset off the books when sold or scrapped. - /// SOURCE: docs/spec/rules.md B-15; CONVENTION (gain or loss on disposal). + /// SOURCE: BS-asset-1; CONVENTION (gain or loss on disposal). /// INVARIANTS: /// 1. The gain (or loss) MUST equal proceeds minus book value at the /// disposal date. @@ -3463,7 +3463,7 @@ impl Ledger { /// [`Self::dispose_asset`] with the checks every journaled /// `asset.disposed` passed when it was written (no bound on the /// proceeds or the date beyond the disposal's own), for replay only - /// (rules.md B-28). Never for new work. + /// (BS-entry-4). Never for new work. pub fn replay_dispose_asset( &mut self, id: AssetId, @@ -3494,13 +3494,13 @@ impl Ledger { let asset = self.assets.get(&id).ok_or(LedgerError::UnknownAsset(id))?; // Activeness and the proceeds' sign; no depreciation is computed, // so a journaled disposal replays even where the figure can't be - // (rules.md B-28). + // (BS-entry-4). assets::check_disposal(asset, proceeds)?; if strict { // Never before the company acquired it. A command's bound, not // replay's: the acquired date needs the link, which a - // projection read-back restores after the disposal (rules.md - // B-28). + // projection read-back restores after the disposal ( + // BS-entry-4). let acquired = self.asset_acquired_date(id).expect("known asset"); if date < acquired { return Err(LedgerError::DisposalBeforeAcquisition { @@ -3527,7 +3527,7 @@ impl Ledger { /// /// ```text /// GOAL: name a span of days that can later be closed. - /// SOURCE: rules.md B-12 (IRS Pub. 538: tax years, calendar or fiscal); + /// SOURCE: BS-period-2 (IRS Pub. 538: tax years, calendar or fiscal); /// DECISION (owner, 2026-10-13): periods nest, never /// partially overlap. /// SCENARIOS: @@ -3569,7 +3569,7 @@ impl Ledger { /// [`Self::create_period`] without the nesting rule added on /// 2026-10-13 or the calendar bound added in P0 (only the order is /// checked, periods::validate_period_order), for replaying journals - /// written before them (rules.md B-28). + /// written before them (BS-entry-4). pub fn replay_create_period( &mut self, name: &str, @@ -3648,7 +3648,7 @@ impl Ledger { /// everything closed to these members and shares so far, to the /// currency's minor unit (odd units by largest remainder, ties to /// the member listed first), less what earlier closes gave them - /// (rules.md B-13; D-10), and their own distribution account. The + /// (BS-partner-1; D-10), and their own distribution account. The /// count starts at the first members close, or at the first since /// the members or shares last changed (`Ledger::members_regime`); /// closes to anything else are skipped. A close that posts an @@ -3664,7 +3664,7 @@ impl Ledger { /// ```text /// GOAL: close a period: zero every revenue and expense account's balance /// as of its last day into equity, and lock it. - /// SOURCE: docs/spec/rules.md B-11 (Pacioli ch. 27, 34), B-12, B-13 (26 + /// SOURCE: BS-period-1 (Pacioli ch. 27, 34), BS-period-2, BS-partner-1 (26 /// U.S.C. §704(a)); R-? Periods and close. /// INVARIANTS: /// 1. After a close, every revenue and expense account MUST have a zero @@ -3836,7 +3836,7 @@ impl Ledger { /// What a members close (`to`, closing `net`; `posts` when its entry /// posts; numbered `close_seq`) credits each member, in `to`'s order, /// and the rule it is made under: the rule journaled for replayed - /// closes, else the cumulative rule (rules.md B-13): each member's + /// closes, else the cumulative rule (BS-partner-1): each member's /// split of the count's running total, to the base currency's minor /// unit, less what the count's earlier closes gave them. A close that /// posts nothing credits nothing, so a true-up of earlier rounding @@ -3899,7 +3899,7 @@ impl Ledger { } /// The members regime a close with `members` ((capital account, share) - /// pairs) belongs to (rules.md B-13), counting only closes whose + /// pairs) belongs to (BS-partner-1), counting only closes whose /// period ends on or before `through` (all when `None`): walking the /// closes newest first by [`Period::close_seq`], members closes under /// any rule with the same SET of (capital, share) pairs (order and @@ -4354,7 +4354,7 @@ impl Ledger { /// GOAL: "no 1099" is a decision kept with its reason and who made it, /// never the same as "never decided" (plan defects 18, 23), and /// each payment takes the decision in force on its date (D-40). - /// SOURCE: docs/spec/rules.md B-19; crate::form1099::plan_decision. + /// SOURCE: BS-1099-1; crate::form1099::plan_decision. /// SCENARIOS: /// 1. IF the vendor is unknown, or the decision fails its checks: /// SHOULD refuse, changing nothing. @@ -4373,7 +4373,7 @@ impl Ledger { /// [`Self::set_vendor_1099`] as journaled: the vendor must exist, and /// the decision is recorded as the line says, without the checks a - /// new decision passes (rules.md B-28). A line written before + /// new decision passes (BS-entry-4). A line written before /// decisions were kept replays as a decision from the beginning with /// no source (a null as undetermined: plan 5.5). pub fn replay_vendor_1099( @@ -4544,7 +4544,7 @@ impl Ledger { /// /// ```text /// GOAL: the 1099 worksheet knows how each payment was made. - /// SOURCE: docs/spec/rules.md B-19; crate::instruments. + /// SOURCE: BS-1099-1; crate::instruments. /// SCENARIOS: /// 1. IF the entry or the payment method is unknown: SHOULD refuse. /// 2. Tagging MUST change no amount (it's metadata, allowed on posted @@ -4580,7 +4580,7 @@ impl Ledger { /// /// ```text /// GOAL: tag an entry with the vendor it paid, for 1099s. - /// SOURCE: docs/spec/rules.md B-19; Self::set_entry_parties + /// SOURCE: BS-1099-1; Self::set_entry_parties /// INVARIANTS 2 and 5 (the vendor tag follows the parties, never /// the other way round, on an entry naming several). /// SCENARIOS: @@ -5207,7 +5207,7 @@ impl Ledger { /// credit to it never counts as paying that party (a fee on its /// own card, interest on its own loan, a distribution still owed /// to a member: a promise, not a payment). - /// SOURCE: crate::parties INVARIANT 5; rules.md B-35 (DECISION, owner, + /// SOURCE: crate::parties INVARIANT 5; BS-partner-3 (DECISION, owner, /// 2026-10-20: "a liability credit never counts as paying that /// liability's own creditor"). /// SCENARIOS: @@ -5376,7 +5376,7 @@ impl Ledger { /// [`Self::set_entry_parties`] with the checks every journaled /// `entry.parties_set` passed when it was written /// (crate::shares::check_shares_journaled: no upper bound on an - /// amount), for replay only (rules.md B-28). Never for new work. + /// amount), for replay only (BS-entry-4). Never for new work. pub fn replay_set_entry_parties( &mut self, entry: EntryId, @@ -5566,7 +5566,7 @@ impl Ledger { /// ```text /// GOAL: never post a control role (receivables, payables, revenue, /// payroll, retained earnings) to an account of the wrong kind. - /// SOURCE: docs/spec/rules.md B-4 (the elements); DECISION (owner, + /// SOURCE: BS-ledger-2 (the elements); DECISION (owner, /// 2026-10-13): refuse with a reason, never force the chart's /// numbering. /// INVARIANTS: @@ -5668,7 +5668,7 @@ impl Ledger { /// ```text /// GOAL: a document's lines go where its kind can put them, never to a /// control, a cash account or a header. - /// SOURCE: docs/spec/rules.md B-39; plan P4b S4.1 ("Line accounts"), + /// SOURCE: BS-arap-3; plan P4b S4.1 ("Line accounts"), /// A-10 (every bill line names its account); /// ASC 606-10-45-2 (deferred revenue is a liability). /// INVARIANTS: @@ -5762,14 +5762,14 @@ impl Ledger { /// GOAL: bill a customer and recognize the revenue (accrual basis). /// SOURCE: IRS Pub. 538, accrual method (docs/spec/sources/irs-periods-and-methods.md: /// "report income in the year it is earned"); ASC 606-10-25-23; - /// control accounts: Ledger::check_controls; rules.md B-38, B-39. + /// control accounts: Ledger::check_controls; BS-arap-2, BS-arap-3. /// INVARIANTS: /// 1. MUST post one balanced entry: Dr 1200 receivables, Cr the lines' /// accounts, for the sum of the lines, dated the invoice date: one /// 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 (rules.md - /// B-37 item 8). + /// tagged with its project; the receivable line never ( + /// BS-statement-5 item 8). /// 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. @@ -5897,14 +5897,14 @@ impl Ledger { /// basis). /// SOURCE: IRS Pub. 538, accrual method ("deduct ... expenses in the year /// incurred"); control accounts: Ledger::check_controls; - /// rules.md B-38, B-39 (plan P4b S4.1, A-10). + /// BS-arap-2, BS-arap-3 (plan P4b S4.1, A-10). /// INVARIANTS: /// 1. MUST post one balanced entry: Dr the lines' accounts, Cr 2000 /// payables, for the sum of the lines, dated the bill date, tagged /// 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 (rules.md B-37 item 8). + /// payable line never (BS-statement-5 item 8). /// 2. The payable line MUST carry the bill (Origin), in the step that /// posts it. /// 3. A refusal MUST leave the books unchanged. @@ -6016,7 +6016,7 @@ impl Ledger { Ok(id) } - /// The number the next invoice is issued under (A-2, B-40): `prefix`, + /// The number the next invoice is issued under (A-2, BS-arap-4): `prefix`, /// then `first_number` plus the count of numbered invoices issued so /// far, zero-padded to four digits and wider past 9,999 (never /// truncated). Stored at issue, never recomputed; a void keeps its @@ -6032,7 +6032,7 @@ impl Ledger { } /// Refuse a vendor invoice number that already names a standing bill - /// of the same vendor (B-40), unless `duplicate_reason` says why it is + /// of the same vendor (BS-arap-4), unless `duplicate_reason` says why it is /// entered again. Case, spaces and hyphens are ignored: "ACME-123", /// "acme 123" and "Acme123" are the same number. pub fn check_vendor_ref( @@ -6072,8 +6072,8 @@ impl Ledger { /// ```text /// GOAL: record a send as a fact of the document's life, without /// touching a figure: a send moves no money. - /// SOURCE: docs/spec/rules.md B-38 (a document keeps no figure of its - /// own), B-27 (the invoice.sent line, feature documents_v2); + /// SOURCE: BS-arap-2 (a document keeps no figure of its + /// own), BS-format-1 (the invoice.sent line, feature documents_v2); /// plan P4b S5, A-4 (the books record sends; they never send). /// INVARIANTS: /// 1. The invoice MUST exist, and a send MUST NOT be dated before it. @@ -6150,7 +6150,7 @@ impl Ledger { } /// Record a send without checking it: replay support for journaling - /// stores. Nothing is validated on replay (rules.md B-28); the invoice + /// stores. Nothing is validated on replay (BS-entry-4); the invoice /// must already have been replayed from its own events. #[doc(hidden)] pub fn replay_invoice_sent( @@ -6199,8 +6199,8 @@ impl Ledger { .collect() } - /// The document a ledger line belongs to, if it carries one (rules.md - /// B-38): `(entry, line index)`. + /// The document a ledger line belongs to, if it carries one ( + /// BS-arap-2): `(entry, line index)`. pub fn line_doc(&self, entry: EntryId, line: usize) -> Option { self.line_docs.get(&(entry, line)).copied() } @@ -6258,14 +6258,14 @@ impl Ledger { } /// What a document is as of a day, read from the ledger lines tagged - /// with it (rules.md B-38; plan P4b.3, "Derived figures"). `None` for + /// with it (BS-arap-2; plan P4b.3, "Derived figures"). `None` for /// a document dated after `as_of` (it wasn't issued yet). /// /// ```text /// 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: docs/spec/rules.md B-38 (INVARIANTS 1-4), B-9, B-10, B-18; + /// SOURCE: BS-arap-2 (INVARIANTS 1-4), 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 @@ -6282,7 +6282,7 @@ impl Ledger { /// TooLargeToCompute past exact arithmetic. /// SCENARIOS: /// 1. IF an invoice of 100 was paid 100 and the payment reversed: - /// SHOULD be Open, owing 100 (scenario 1 of B-38). + /// SHOULD be Open, owing 100 (scenario 1 of BS-arap-2). /// 2. IF its own entry was reversed with nothing paid: SHOULD be Void, /// owing nothing. /// 3. IF asked between a payment and its reversal: SHOULD be Paid. @@ -6359,7 +6359,7 @@ impl Ledger { /// naming it (live or replayed). What a version before document /// standing (plan P4b S1) counts as paid, so the store knows when a /// payment needs that feature. Refused (TooLargeToCompute), never a - /// panic, past exact arithmetic: replayed amounts are any size (B-28). + /// panic, past exact arithmetic: replayed amounts are any size (BS-entry-4). pub fn payments_recorded(&self, doc: arap::DocRef) -> Result { self.payment_events .get(&doc) @@ -6414,8 +6414,8 @@ 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`]; rules.md - /// B-38 INVARIANT 2). Books an earlier version left out of bounds + /// its total where it didn't before ([`kernel::bounds_kept`]; + /// BS-arap-2 INVARIANT 2). 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( @@ -6475,8 +6475,8 @@ 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 (rules.md B-38 - /// INVARIANT 2, B-41 INVARIANT 1). + /// may be, so no later day ends out of bounds (BS-arap-2 + /// INVARIANT 2, BS-arap-5 INVARIANT 1). fn least_owed_from(&self, doc: arap::DocRef, date: NaiveDate) -> Result { let (doc_date, ..) = self.doc_header(doc)?; let from = date.max(doc_date); @@ -6546,14 +6546,14 @@ impl Ledger { } /// Settle one or more invoices or bills in one entry (plan P4b S6; - /// rules.md B-42): cash against each, an early-payment discount where + /// BS-arap-6): cash against each, an early-payment discount where /// the document's terms allow it (or a reason says why), and the /// processor's fee on a customer payment, posted gross. /// /// ```text /// GOAL: record a payment that settles several documents at once, with /// the early-payment discounts and the processor's fee, exactly. - /// SOURCE: docs/spec/rules.md B-42; plan/served.md 8.3.6, 8.3.13; + /// SOURCE: BS-arap-6; plan/served.md 8.3.6, 8.3.13; /// CONVENTION; DECISION: the gross method (A-8) and the fee's /// gross presentation (A-4). /// INVARIANTS: @@ -6978,8 +6978,8 @@ impl Ledger { /// /// ```text /// GOAL: record a customer's payment against an invoice. - /// SOURCE: IRS Pub. 538 (accrual); CONVENTION (A/R workflow); rules.md - /// B-38; plan/served.md P4b.3 ("Payment accounts"), P4b.6. + /// SOURCE: IRS Pub. 538 (accrual); CONVENTION (A/R workflow); + /// BS-arap-2; plan/served.md P4b.3 ("Payment accounts"), P4b.6. /// INVARIANTS: /// 1. MUST post Dr the deposit account, Cr 1200 receivables, for the /// amount; the receivables line carries the invoice (Payment), so @@ -6993,10 +6993,10 @@ impl Ledger { /// - SHOULD refuse (Overpayment), saying what can be paid /// - NEVER let a standing payment exceed the total /// - a reversed payment no longer counts, so the right one is - /// accepted after the wrong one is reversed (B-38 scenario 5) + /// accepted after the wrong one is reversed (BS-arap-2 scenario 5) /// 3. IF the deposit account is a control, revenue, expense or /// equity account, or holds any role: SHOULD refuse - /// (PaymentAccount; B-38 scenario 8). + /// (PaymentAccount; BS-arap-2 scenario 8). /// 4. IF dated before the invoice: SHOULD refuse (PaymentBeforeDocument). /// ``` pub fn receive_payment_with( @@ -7052,8 +7052,8 @@ impl Ledger { /// /// ```text /// GOAL: record paying a vendor's bill. - /// SOURCE: IRS Pub. 538 (accrual); CONVENTION (A/P workflow); rules.md - /// B-38; plan/served.md P4b.3, P4b.6. + /// SOURCE: IRS Pub. 538 (accrual); CONVENTION (A/P workflow); + /// BS-arap-2; plan/served.md P4b.3, P4b.6. /// INVARIANTS: /// 1. MUST post Dr 2000 payables, Cr the payer account, for the /// amount, tagged with the vendor; the payables line carries the @@ -7099,7 +7099,7 @@ impl Ledger { }) } - /// Write off an invoice as a bad debt (plan P4b S7; rules.md B-41). + /// Write off an invoice as a bad debt (plan P4b S7; BS-arap-5). /// /// ```text /// GOAL: take an invoice off the receivables when it will not be @@ -7108,7 +7108,7 @@ impl Ledger { /// §1.166-1(e) (a debt never counted as income has no basis), /// §1.166-2(a) (worthlessness on all the pertinent evidence), /// §1.166-3(a) (a partial write-off, to the extent charged - /// off); docs/spec/rules.md B-41; plan/served.md P4b S7, + /// off); BS-arap-5; plan/served.md P4b S7, /// A-5 (the direct write-off method); ASC 326-20 noted (an /// allowance is the GAAP preference; a small company's CPA /// accepts the direct method, stated). @@ -7123,7 +7123,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 (B-38 INVARIANT 2). + /// owe less than nothing (BS-arap-2 INVARIANT 2). /// 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. @@ -7137,7 +7137,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 (B-38 SCENARIO 7). + /// 50 written off (BS-arap-2 SCENARIO 7). /// ``` pub fn write_off( &mut self, @@ -7234,7 +7234,7 @@ impl Ledger { Ok(entry) } - /// Void a document: reverse its own entry (B-9), described "Void + /// Void a document: reverse its own entry (BS-ledger-5), described "Void /// invoice 7: reason". It keeps its id (and, later, its number); its /// status as of the void's date on is Void. Plain /// [`Self::reverse_entry`] of the same entry gives the same result. @@ -7242,7 +7242,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: docs/spec/rules.md B-9, B-10, B-12, B-38 (scenarios 2, 3); + /// SOURCE: BS-ledger-5, BS-ledger-6, BS-period-2, BS-arap-2 (scenarios 2, 3); /// plan/served.md P4b.5, P4b.6; ASC 250 (an immaterial error is /// corrected in the period found). /// INVARIANTS: @@ -7310,7 +7310,7 @@ impl Ledger { /// ```text /// GOAL: show that receivables and payables equal their documents, and /// list every line that is no document's. - /// SOURCE: docs/spec/rules.md B-23, B-38 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 @@ -7511,7 +7511,7 @@ impl Ledger { /// is for `amount` (any amount when `None`: a document's own entry /// has one such line). An entry with /// no such line stays untagged, and its line is listed by - /// [`Self::control_check`]: replay never refuses (B-28). + /// [`Self::control_check`]: replay never refuses (BS-entry-4). fn tag_replayed( &mut self, entry: EntryId, @@ -7546,11 +7546,11 @@ impl Ledger { } } - /// Tag the line a new payment event names (plan P4b S6; rules.md B-42 + /// 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 /// account, on the side the movement posts, untagged, and for `amount`. /// Otherwise it stays untagged and the control check lists it; replay - /// never refuses (B-28). + /// never refuses (BS-entry-4). fn tag_replayed_at( &mut self, entry: EntryId, @@ -7622,7 +7622,7 @@ impl Ledger { return Err(LedgerError::ReplayIdMismatch(id, self.next_invoice_id)); } // Restored exactly as journaled: replay checks no line or date - // (none did when it was written; rules.md B-28). Figures derived + // (none did when it was written; BS-entry-4). Figures derived // from them (the total, aging) refuse what they can't compute. self.next_invoice_id += 1; self.invoices.insert( @@ -7703,7 +7703,7 @@ impl Ledger { return Err(LedgerError::ReplayIdMismatch(id, self.next_bill_id)); } // Restored exactly as journaled: replay checks no line or date - // (none did when it was written; rules.md B-28). Figures derived + // (none did when it was written; BS-entry-4). Figures derived // from them (the total, aging) refuse what they can't compute. self.next_bill_id += 1; self.bills.insert( @@ -7744,7 +7744,7 @@ impl Ledger { /// own entry events; this tags its receivables line with the invoice /// (the first untagged one for `amount`, so several payment events /// naming one entry tag its lines in order: the ordinal rule, plan - /// P4b.3). Nothing is bounded on replay (rules.md B-28). + /// P4b.3). Nothing is bounded on replay (BS-entry-4). #[doc(hidden)] pub fn replay_invoice_payment( &mut self, @@ -7756,10 +7756,10 @@ impl Ledger { } /// [`Self::replay_invoice_payment`] with the line a new event names and - /// the discount it took (plan P4b S6; rules.md B-42 INVARIANT 3). A + /// the discount it took (plan P4b S6; BS-arap-6 INVARIANT 3). 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 (B-28). + /// control check lists it: replay never refuses (BS-entry-4). #[doc(hidden)] pub fn replay_invoice_payment_at( &mut self, @@ -7807,12 +7807,12 @@ impl Ledger { } /// Apply a write-off without posting: replay support for journaling - /// stores (plan P4b S7; rules.md B-41). The write-off's entry was + /// stores (plan P4b S7; BS-arap-5). The write-off's entry was /// already rebuilt from its own entry events; this tags its /// receivables line with the invoice (the first untagged control line /// for `amount`, on the credit side), tags the entry with the /// customer, and refreshes the invoice's figures. Nothing is bounded - /// on replay (rules.md B-28). + /// on replay (BS-entry-4). #[doc(hidden)] pub fn replay_invoice_write_off( &mut self, @@ -7903,11 +7903,11 @@ impl Ledger { /// A/R aging as of a date: one row per customer with an outstanding /// balance, bucketed by days past due. Refused (TooLargeToCompute), /// never a panic, when a sum is past exact arithmetic: documents are - /// restored as journaled (rules.md B-28). + /// restored as journaled (BS-entry-4). /// /// ```text /// GOAL: what each customer owes as of a day, by how overdue. - /// SOURCE: docs/spec/rules.md B-18, B-38 INVARIANT 5. + /// SOURCE: BS-arap-1, BS-arap-2 INVARIANT 5. /// INVARIANTS: /// 1. Each invoice issued by `as_of` that owes something then /// (Self::doc_state's outstanding) is in exactly one bucket, at @@ -8213,7 +8213,7 @@ impl Ledger { /// /// ```text /// GOAL: an account's balance on its normal side. - /// SOURCE: docs/spec/rules.md B-5. + /// SOURCE: BS-ledger-3. /// INVARIANTS: /// 1. MUST equal the account's debits minus credits for debit-normal /// types (asset, expense), and credits minus debits otherwise. @@ -8372,7 +8372,7 @@ impl Ledger { let mut paid: Vec<(crate::PartyId, Decimal)> = Vec::new(); let mut unnamed = false; for l in lines { - // A run is restored as journaled (rules.md B-28): its figures + // A run is restored as journaled (BS-entry-4): its figures // are checked, and a net past exact arithmetic refused. let net = l.net_pay()?; if net.is_zero() { @@ -8511,7 +8511,7 @@ impl Ledger { return Err(LedgerError::ReplayIdMismatch(id, self.next_payroll_run_id)); } // Restored exactly as journaled: the run's figures are checked by - // the command, not by replay (rules.md B-28). + // the command, not by replay (BS-entry-4). self.next_payroll_run_id += 1; if self.entries.contains_key(&entry_id) { self.name_payroll_parties(entry_id, &lines)?; @@ -8593,7 +8593,7 @@ impl Ledger { } /// Apply a journaled settings change (`settings.set` at `seq`): as - /// checked when made, or as replayed (shape only, rules.md B-28). + /// checked when made, or as replayed (shape only, BS-entry-4). pub fn apply_settings( &mut self, changes: &[crate::settings::Change], @@ -8645,7 +8645,7 @@ impl Ledger { } /// [`Self::annotate_attachment`] as journaled (`attachment.annotated`), - /// for replay only (rules.md B-28). + /// for replay only (BS-entry-4). pub fn replay_annotate_attachment( &mut self, annotation: crate::evidence::Annotation, @@ -8696,7 +8696,7 @@ impl Ledger { } /// [`Self::set_entry_settles`] as journaled (`entry.settles`), for - /// replay only (rules.md B-28). + /// replay only (BS-entry-4). pub fn replay_set_entry_settles( &mut self, entry: EntryId, @@ -9292,11 +9292,11 @@ impl Ledger { // ------------------------------------------------------------------ /// Add a class (division) for line-level P&L tracking: a project with - /// only its name (rules.md B-37). Returns its id. + /// only its name (BS-statement-5). Returns its id. /// /// ```text /// GOAL: a new class under a name no other class has. - /// SOURCE: docs/spec/rules.md B-37 item 1. + /// SOURCE: BS-statement-5 item 1. /// SCENARIOS: /// 1. IF the name is blank: SHOULD refuse (EmptyClassName). /// 2. IF it is longer than a line, holds a control character or a @@ -9318,7 +9318,7 @@ impl Ledger { /// /// ```text /// GOAL: one rule for every name a command gives a class. - /// SOURCE: docs/spec/rules.md B-37 item 1; B-26 (no full TIN). + /// SOURCE: BS-statement-5 item 1; 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 @@ -9395,11 +9395,11 @@ impl Ledger { /// /// ```text /// GOAL: tag a draft line with a class (or clear it). - /// SOURCE: R-? Tracking classes. + /// SOURCE: BS-statement-5 (a project is a class); R-? Tracking classes. /// SCENARIOS: /// 1. IF the entry is posted: /// - SHOULD refuse - /// - NEVER change a posted line (B-8) + /// - NEVER change a posted line (BS-ledger-4) /// 2. IF the line or class doesn't exist: SHOULD refuse. /// ``` pub fn set_line_class( @@ -9467,7 +9467,7 @@ impl Ledger { /// ```text /// GOAL: refuse any project record the books can't take, before a /// line is written. - /// SOURCE: docs/spec/rules.md B-37 item 1 (and B-26: no full TIN). + /// SOURCE: BS-statement-5 item 1 (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 @@ -9512,7 +9512,7 @@ impl Ledger { /// Replay a journaled project record: only what replay can't do /// without (the class and the party exist), never the text rules, so a /// rule tightened later never breaks old books (as - /// `AssetBasis::check_journaled`, rules.md B-25). + /// `AssetBasis::check_journaled`, BS-asset-4). #[doc(hidden)] pub fn replay_set_project( &mut self, @@ -9546,13 +9546,13 @@ impl Ledger { } } -/// A class name as names compare (rules.md B-37 item 1): trimmed, in +/// A class name as names compare (BS-statement-5 item 1): trimmed, in /// lower case (Unicode's, so `Éclair` and `éCLAIR` are one name). fn fold_class_name(name: &str) -> String { name.trim().to_lowercase() } -/// Refuse an amount finer than its currency's minor unit (rules.md B-3). +/// Refuse an amount finer than its currency's minor unit (BS-ledger-1). /// A currency with no defined minor unit (ISO 4217 "N.A.") is not checked. pub(crate) fn check_minor_units(amount: Money) -> Result<(), LedgerError> { match amount.currency.minor_units() { @@ -9585,7 +9585,7 @@ fn member_key(members: &[periods::MemberClose]) -> Vec<(AccountId, Decimal)> { } /// Two members closes' (capital account, share) lists name the same -/// members with the same shares, in any order (rules.md B-13: a reorder of +/// members with the same shares, in any order (BS-partner-1: a reorder of /// the members is not a change of members). Shares compare by value, so /// 0.5 is 0.50. fn same_member_set(a: &[(AccountId, Decimal)], b: &[(AccountId, Decimal)]) -> bool { @@ -9599,7 +9599,7 @@ fn same_member_set(a: &[(AccountId, Decimal)], b: &[(AccountId, Decimal)]) -> bo /// A vendor invoice number as the duplicate check compares it: lower case, /// with spaces and hyphens removed ("ACME-123" and "acme 123" are the -/// same number; rules.md B-40). +/// same number; BS-arap-4). fn normalize_vendor_ref(vendor_ref: &str) -> String { vendor_ref .chars() @@ -9634,7 +9634,7 @@ impl Regime { /// own order when no close has begun the count), the parts back in `members`' /// order. So a count's ties go to the same member whatever order later /// closes, statements or the settings list the members in, and a - /// reorder of the members moves no cent (rules.md B-13, D-38). + /// reorder of the members moves no cent (BS-partner-1, D-38). pub(crate) fn allocate( &self, members: &[(AccountId, Decimal)], diff --git a/crates/ledger-core/src/money.rs b/crates/ledger-core/src/money.rs index d7578b9e..c5418f8c 100644 --- a/crates/ledger-core/src/money.rs +++ b/crates/ledger-core/src/money.rs @@ -63,7 +63,7 @@ impl Currency { /// code ISO 4217 gives none (gold, SDRs), the most a line may carry /// (kernel::MAX_LINE_SCALE). Every posted amount is then a whole number /// of the unit split to, so no member's running share is ever a unit - /// from exact (rules.md B-13); split to cents, a finer amount's + /// from exact (BS-partner-1); split to cents, a finer amount's /// leftover fraction would all go to one member. pub fn allocation_places(&self) -> u32 { self.minor_units().unwrap_or(crate::kernel::MAX_LINE_SCALE) @@ -156,7 +156,7 @@ impl Money { /// The exact sum of some figures ([`crate::kernel::total`]), or /// `TooLargeToCompute` naming `what` when a running sum cannot be held: /// the engine's way to total a column without a raw `.sum()` that would -/// panic at `Decimal::MAX` (rules.md B-21, B-28). +/// panic at `Decimal::MAX` (BS-entry-3, BS-entry-4). pub fn sum_exact( values: impl IntoIterator, what: &str, @@ -213,7 +213,7 @@ impl fmt::Debug for Money { /// GOAL: depreciation and daily schedules round to the currency's own /// smallest unit (cents, whole yen, thousandths of a dinar), never a /// fixed two places. -/// SOURCE: docs/spec/rules.md B-3 (no fraction of the minor unit; ISO 4217, +/// SOURCE: BS-ledger-1 (no fraction of the minor unit; ISO 4217, /// sources/iso-4217.md). /// INVARIANTS: /// 1. amount = units × 10^-scale exactly; unit = 10^(scale − minor). diff --git a/crates/ledger-core/src/parties.rs b/crates/ledger-core/src/parties.rs index dbdd3ba8..dbb6fb40 100644 --- a/crates/ledger-core/src/parties.rs +++ b/crates/ledger-core/src/parties.rs @@ -32,7 +32,7 @@ //! not placeholders, payables or payroll withholdings: what the //! company owes that party itself on (a card's issuer, a loan's //! lender, a member for what the members advanced). A credit to one -//! never counts as paying that party (rules.md B-35; DECISION, owner, +//! never counts as paying that party (BS-partner-3; DECISION, owner, //! 2026-10-20). //! ``` @@ -305,7 +305,7 @@ impl Party { /// GOAL: one answer to "which TIN is on file for them?" wherever the /// books show a last four (defect 11: the directory showed a /// member's as missing because it read W-9 facts only). - /// SOURCE: rules.md B-26 (Treas. Reg. §301.6109-4(a): a truncated TIN + /// SOURCE: BS-partner-2 (Treas. Reg. §301.6109-4(a): a truncated TIN /// shows its last four); INVARIANT 2a (DECISION, owner, /// 2026-10-15: the two never disagree, so either answers). /// SCENARIOS: @@ -321,7 +321,7 @@ impl Party { /// ``` pub fn tin_last4(&self) -> Option<&str> { // Exactly four digits or nothing, however the facts were built - // (the setters check it; this never shows more, B-26). + // (the setters check it; this never shows more, BS-partner-2). let four = |s: &str| s.len() == 4 && s.chars().all(|c| c.is_ascii_digit()); self.tin .as_ref() @@ -596,9 +596,9 @@ std::thread_local! { /// ```text /// GOAL: books an earlier version wrote open, forever, however a later /// version widens what reads as a full TIN. -/// SOURCE: rules.md B-28 ("Replay accepts every line an earlier version +/// SOURCE: BS-entry-4 ("Replay accepts every line an earlier version /// accepted": the bounds are the commands', never replay's); -/// B-26 (no full TIN in the books). +/// BS-partner-2 (no full TIN in the books). /// INVARIANTS: /// 1. Within it, a text is refused only if P2's detector /// ([`journaled_tin_runs`]) refuses it: every name, reason and fact @@ -625,8 +625,8 @@ pub fn replaying(f: impl FnOnce() -> T) -> T { /// Whether a journaled line is being replayed now ([`replaying`]): the /// rules a later version added that refuse new work (the control guard, -/// a document's bounds, rules.md B-38) never refuse a line an earlier -/// version accepted (B-28). +/// a document's bounds, BS-arap-2) never refuse a line an earlier +/// version accepted (BS-entry-4). pub fn is_replaying() -> bool { REPLAYING.with(std::cell::Cell::get) } @@ -681,7 +681,7 @@ fn journaled_tin_runs(chars: &[char]) -> Vec<(usize, usize)> { /// `text` with every run [`has_full_tin`] finds masked: each of its /// digits becomes `•`, separators kept. For refusals that quote what they -/// were given, so no error echoes a full TIN (docs/spec/rules.md B-26). +/// were given, so no error echoes a full TIN (BS-partner-2). pub fn redact_full_tins(text: &str) -> std::borrow::Cow<'_, str> { let mut chars: Vec = text.chars().collect(); let runs = full_tin_runs(&chars); @@ -828,7 +828,7 @@ impl PartyField { ]; /// Whether `field` is a field this version knows. A `party.updated` - /// naming another was written by a newer version (rules.md B-27). + /// naming another was written by a newer version (BS-format-1). pub fn known_field(field: &str) -> bool { Self::FIELDS.contains(&field) } @@ -850,7 +850,7 @@ impl PartyField { } } -/// Which of a party's totals to report (rules.md B-35 item 4). Not the +/// Which of a party's totals to report (BS-partner-3 item 4). 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)] @@ -928,7 +928,7 @@ impl Activity { } } -/// The accounts [`entry_flow`] reads money from (rules.md B-35, defect +/// The accounts [`entry_flow`] reads money from (BS-partner-3, defect /// 24): the cash accounts (every asset account but receivables when none /// are given), and the money liabilities: the cards ([`card_accounts`]), /// what the members advanced and loans (`books.financing_accounts`). @@ -949,8 +949,8 @@ impl MoneyAccounts { /// what the company owes a party itself never counts as paying it (a /// fee charged on its own card, interest added to its own loan, /// equipment bought on its own note, a distribution still owed to a - /// member), and a debit to it is what the money paid for (rules.md - /// B-35; DECISION, owner, 2026-10-20). + /// member), and a debit to it is what the money paid for ( + /// BS-partner-3; DECISION, owner, 2026-10-20). pub fn for_parties( &self, ledger: &crate::Ledger, @@ -981,8 +981,8 @@ 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: rules.md B-35 item 5 (DECISION, owner, 2026-10-20: money is -/// cash, cards, the members' financing and loans), B-19 (payment +/// SOURCE: BS-partner-3 item 5 (DECISION, owner, 2026-10-20: money is +/// cash, cards, the members' financing and loans), BS-1099-1 (payment /// methods, plan P3 defect 12). /// INVARIANTS: /// 1. When the books record a business-card payment method: exactly @@ -1148,7 +1148,7 @@ pub fn entry_flow( ) -> Result { use crate::Side; use rust_decimal::Decimal; - // A draft's lines are as journaled, of any size (rules.md B-28): every + // A draft's lines are as journaled, of any size (BS-entry-4): every // sum is checked, and one past exact arithmetic is refused. let too_large = || crate::LedgerError::TooLargeToCompute(format!("entry {}'s money flow", entry.id())); @@ -1256,14 +1256,14 @@ pub fn entry_flow( /// The money an entry moved with the parties it names, and what for, /// read as party figures read it: a reversal's is exactly its original's -/// negated (B-9), never re-read from its own lines; and a liability owed +/// negated (BS-ledger-5), never re-read from its own lines; and a liability owed /// to a party named is not money for the entry /// ([`MoneyAccounts::for_parties`]). /// /// ```text /// GOAL: what a party's entry paid for, right for reversals too. -/// SOURCE: rules.md B-9 ("a mistake is corrected by an opposite entry"), -/// B-35. +/// SOURCE: BS-ledger-5 ("a mistake is corrected by an opposite entry"), +/// BS-partner-3. /// INVARIANTS: /// 1. An entry reversing none: entry_flow of its lines, with /// money.for_parties(the parties of `shares`). @@ -1327,8 +1327,8 @@ pub fn activity( /// get from them?" for the MCP server and the viewer alike, right /// when an entry was with several parties, for property as well as /// money, and for reversals. -/// SOURCE: docs/parties-and-attachments.md (Parties, Shares); rules.md -/// B-35 (DECISION, owner, 2026-10-15 and 2026-10-20). +/// SOURCE: docs/parties-and-attachments.md (Parties, Shares); +/// BS-partner-3 (DECISION, owner, 2026-10-15 and 2026-10-20). /// INVARIANTS: /// 1. entries: every entry Ledger::entry_parties names the party in /// (hand tags, vendor tags, bills and their payments, invoices and @@ -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 (rules.md B-35 item 4). + // unresolved for shares that don't fit it (BS-partner-3 item 4). let Ok(t) = crate::shares::target(ledger, id, shares, money) else { a.unresolved.insert(id); continue; diff --git a/crates/ledger-core/src/payouts.rs b/crates/ledger-core/src/payouts.rs index 3c9c8554..24f9a338 100644 --- a/crates/ledger-core/src/payouts.rs +++ b/crates/ledger-core/src/payouts.rs @@ -86,7 +86,7 @@ pub type PayoutPlanLine = (AccountId, Side, Decimal, Option); /// collected; fees debit expense accounts), and the payout reconciles to /// the cent. /// A zero deposit (fees and adjustments ate the sales exactly) has no -/// deposit line: every planned line is positive (B-2, docs/spec/rules.md). +/// deposit line: every planned line is positive (BS-entry-2, docs/spec/rules.md). pub fn payout_plan( payout: &Payout, chart: &ChartOfAccounts, diff --git a/crates/ledger-core/src/payroll.rs b/crates/ledger-core/src/payroll.rs index 62e02194..8cd511e8 100644 --- a/crates/ledger-core/src/payroll.rs +++ b/crates/ledger-core/src/payroll.rs @@ -50,7 +50,7 @@ impl PayrollLine { /// Gross minus all employee withholdings and deductions. Must be >= 0: /// you cannot withhold more than the employee earned. Refused /// (TooLargeToCompute), never a panic, past exact arithmetic: a run is - /// restored as journaled (rules.md B-28). + /// restored as journaled (BS-entry-4). pub fn net_pay(&self) -> Result { [ self.federal_withholding, @@ -133,7 +133,7 @@ pub fn validate_payroll_lines(lines: &[PayrollLine]) -> Result<(), LedgerError> /// Every amount of every line no larger than a journal line may be /// (kernel::MAX_LINE_AMOUNT, ten decimal places), so net pay and the run's /// totals are exact (P0 review round 3, S1). For new runs only: replay -/// restores a run as journaled (rules.md B-28). +/// restores a run as journaled (BS-entry-4). pub fn check_payroll_ranges(lines: &[PayrollLine]) -> Result<(), LedgerError> { for line in lines { for amount in [ diff --git a/crates/ledger-core/src/periods.rs b/crates/ledger-core/src/periods.rs index 8774c514..f0ba5d29 100644 --- a/crates/ledger-core/src/periods.rs +++ b/crates/ledger-core/src/periods.rs @@ -56,7 +56,7 @@ pub enum CloseTo { /// gives a member their share of everything closed to the members so /// far, to the currency's minor unit, less what earlier closes gave /// them, so no member is ever a minor unit from their exact share - /// (rules.md B-13; D-10). What new closes are made with; the books + /// (BS-partner-1; D-10). What new closes are made with; the books /// journal it as [`CloseTo::MembersCumulative`]. Members(Vec), /// [`CloseTo::Members`] as journaled: the count of members closes @@ -130,7 +130,7 @@ pub fn allocate( /// [`allocate`], refusing with `TooLargeToCompute` instead of panicking /// when a share of `amount` is beyond exact arithmetic (a replayed close -/// carries a journaled amount of any size, rules.md B-28). The same split, +/// carries a journaled amount of any size, BS-entry-4). The same split, /// to the cent, for every amount [`allocate`] accepts. pub fn try_allocate( amount: rust_decimal::Decimal, @@ -177,7 +177,7 @@ pub fn allocate_last_absorbs( /// [`allocate_last_absorbs`], refusing with `TooLargeToCompute` instead of /// panicking when `amount × share` or the plug is beyond exact arithmetic -/// (replay of a legacy close with a huge journaled amount, rules.md B-28). +/// (replay of a legacy close with a huge journaled amount, BS-entry-4). /// The same split, to the cent, for every amount [`allocate_last_absorbs`] /// accepts: this is the frozen rule, only its overflow now an error. pub fn try_allocate_last_absorbs( @@ -205,22 +205,22 @@ pub fn try_allocate_last_absorbs( /// ([`crate::Currency::allocation_places`]) instead of cents, less what /// earlier closes gave each member (`given`, in the order of `shares`). /// Each member's running total is then one split of the running total -/// (rules.md B-13; [`crate::kernel::apportion_cumulative`]). A loss is +/// (BS-partner-1; [`crate::kernel::apportion_cumulative`]). A loss is /// the negation of the same gain: it splits |total| against `given` /// negated, then negates. /// /// ```text /// GOAL: no member's running share of earnings is ever a minor unit from /// their exact share, whatever earlier closes gave them. -/// SOURCE: docs/spec/rules.md B-13 (26 U.S.C. §704(a); Treas. Reg. +/// SOURCE: BS-partner-1 (26 U.S.C. §704(a); Treas. Reg. /// §1.704-1(b)(2)(iv)(b); largest remainder: DECISION, owner -/// 2026-10-13; from the first close: D-10); B-3 (the minor unit). +/// 2026-10-13; from the first close: D-10); BS-ledger-1 (the minor unit). /// INVARIANTS: /// 1. The parts MUST sum to total − Σ given exactly. /// 2. given[i] + part[i] MUST be member i's largest-remainder split of /// total to `places` (ties to the earlier member): one split. /// 3. So when total is a whole number of units of `places` (every posted -/// line is at its currency's allocation_places: its minor unit, B-3, +/// line is at its currency's allocation_places: its minor unit, BS-ledger-1, /// or for a currency without one the finest a line carries), /// |given[i] + part[i] − total × share[i]| is under one unit (Lean /// allocW_drift, cumulative_drift; Kani @@ -326,7 +326,7 @@ pub struct Period { /// What a close under the run rule ([`CloseTo::MembersRun`], journaled /// `"cumulative"`) allocated, once closed that way. Only those closes /// have one: its serialized form is what earlier versions wrote, and - /// stays so (rules.md B-28). Every members close's split, under any + /// stays so (BS-entry-4). Every members close's split, under any /// rule, is [`Period::members_closed`]. #[serde(default)] pub member_close: Option, @@ -415,7 +415,7 @@ impl Period { /// Validate a period's date range before creation. /// [`validate_period_order`], and both ends inside the calendar the books /// keep (crate::calendar; P0 review round 3, S1). For new periods; replay -/// checks only the order (rules.md B-28). +/// checks only the order (BS-entry-4). pub fn validate_period_range(start: NaiveDate, end: NaiveDate) -> Result<(), LedgerError> { crate::calendar::check(start)?; crate::calendar::check(end)?; diff --git a/crates/ledger-core/src/proofs/mod.rs b/crates/ledger-core/src/proofs/mod.rs index f0bd759d..e127cedd 100644 --- a/crates/ledger-core/src/proofs/mod.rs +++ b/crates/ledger-core/src/proofs/mod.rs @@ -460,7 +460,7 @@ fn closing_entry_balances() { } // --------------------------------------------------------------------------- -// 1099 payments (rules.md B-19) +// 1099 payments (BS-1099-1) // --------------------------------------------------------------------------- fn any_role() -> kernel::PayRole { @@ -485,7 +485,7 @@ fn any_tag() -> kernel::Tag { } } -/// `kernel::payment_bucket` is the B-19 table, all 16 cases: a tag naming +/// `kernel::payment_bucket` is the BS-1099-1 table, all 16 cases: a tag naming /// the line's account decides (card or network: Card; otherwise Counts); /// else the role does, and with no tag naming its account a financing line /// never counts and a card account's line is always Card. @@ -726,7 +726,7 @@ fn apportion_cumulative_is_exact() { /// `cumulative_drift` carry any weights and any amounts). const DRIFT: i64 = 1 << 12; -/// **Bounded drift** (rules.md B-13) for members with these integer +/// **Bounded drift** (BS-partner-1) for members with these integer /// weights (shares w_i / W, W their sum): a cumulative members close, /// modelled as `periods::allocate_cumulative` runs it at whole minor units /// (unit 1), hands out exactly its net, and leaves every member's running @@ -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 -/// (rules.md B-14 rules 3 and 9: the statement foots, entry by entry). +/// (BS-statement-3 rules 3 and 9: 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 (rules.md B-14 rule 6). End to end, on entries of +/// statement together (BS-statement-3 rule 6). 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 @@ -1227,8 +1227,8 @@ fn any_way() -> kernel::OnBehalf { } } -/// What a member or a lender paid or received for the company (rules.md -/// B-14 rule 11, D-42) invents and loses nothing: the parts net to zero, +/// 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, /// 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 -/// (rules.md B-14 rule 6), so the two drop out together. +/// (BS-statement-3 rule 6), so the two drop out together. #[kani::proof] #[kani::unwind(4)] fn constructive_mirrors() { @@ -1300,7 +1300,7 @@ fn constructive_mirrors() { } // --------------------------------------------------------------------------- -// A party's part of an entry (rules.md B-35) +// A party's part of an entry (BS-partner-3) // --------------------------------------------------------------------------- /// The inputs `kernel::party_target` reads, any in range: a capital @@ -1320,7 +1320,7 @@ fn any_party_inputs() -> (Option<(i64, i64)>, i64, i64, i64) { (capital, any_amount(), any_amount(), debits) } -/// B-35 items 1-4: the direction is the sign of what counts (paid above +/// BS-partner-3 items 1-4: 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 @@ -1374,7 +1374,7 @@ fn party_target_direction_is_its_sign() { ); } -/// B-35 item 3 and B-9: the target is odd. Negating the lines negates the +/// BS-partner-3 item 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 @@ -1409,7 +1409,7 @@ fn party_target_is_odd() { ); } -/// B-9: reversing a reversal gives the original back, and reverse_target +/// BS-ledger-5: reversing a reversal gives the original back, and reverse_target /// never panics: past the range it refuses. #[kani::proof] fn reverse_target_is_an_involution() { @@ -1438,7 +1438,7 @@ fn reverse_target_is_an_involution() { } // --------------------------------------------------------------------------- -// Proration by days (depreciation, B-15; daily schedules, B-16) +// Proration by days (depreciation, BS-asset-1; daily schedules, BS-prepaid-1) // --------------------------------------------------------------------------- /// Most month parts the proration harnesses explore. @@ -1687,7 +1687,7 @@ fn prorated_through_refuses_malformed_input() { } // --------------------------------------------------------------------------- -// Catching up and truing up (B-15) +// Catching up and truing up (BS-asset-1) // --------------------------------------------------------------------------- /// A catch-up run posts max(0, min gap), never negative, and never carries @@ -1753,7 +1753,7 @@ fn true_up_reaches_the_target() { kani::cover!(down > 0, "depreciation past the day, credited back"); } -/// `kernel::basis_figures` (rules.md B-25), for every rule and every +/// `kernel::basis_figures` (BS-asset-4), for every rule and every /// cost, adjusted basis and value within the bounds: a purchase /// depreciates from cost with no §723 basis or built-in gain; a /// contribution's §723 basis is the adjusted basis and its built-in gain @@ -1797,7 +1797,7 @@ fn basis_figures_laws() { ); } -/// `kernel::unrecovered_cost` (rules.md B-37 item 4), for every revenue +/// `kernel::unrecovered_cost` (BS-statement-5 item 4), 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 @@ -1819,7 +1819,7 @@ fn unrecovered_cost_laws() { kani::cover!(u == 0 && revenue > expenses, "repaid, and more"); } -/// `kernel::running_bounds` (rules.md B-38 INVARIANT 2; the bounds every +/// `kernel::running_bounds` (BS-arap-2 INVARIANT 2; 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 @@ -1859,7 +1859,7 @@ fn bounds_check_matches_definition() { } /// `kernel::bounds_kept` (the check every document command and reversal -/// runs, rules.md B-38 INVARIANT 2): on books in bounds at every date it +/// runs, BS-arap-2 INVARIANT 2): 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 @@ -1996,7 +1996,7 @@ fn line_amount_is_exact() { } // --------------------------------------------------------------------------- -// Tax categories (B-32) +// Tax categories (BS-ledger-11) // --------------------------------------------------------------------------- /// `n / 100` rounded half away from zero: the reference for the one @@ -2013,7 +2013,7 @@ fn round_cent(n: i64) -> Option { } } -/// `kernel::deductible_amount` (rules.md B-32, B-21; CHOICE, owner +/// `kernel::deductible_amount` (BS-ledger-11, BS-entry-3; CHOICE, owner /// 2026-11-07, D-67) over up to three accounts in exact range: the exact /// sum of the shares (`book × percent ÷ 100`) rounded once to the nearest /// cent, ties away from zero; never the sum of per-account roundings; and diff --git a/crates/ledger-core/src/reports.rs b/crates/ledger-core/src/reports.rs index a9605507..dc4062c4 100644 --- a/crates/ledger-core/src/reports.rs +++ b/crates/ledger-core/src/reports.rs @@ -47,7 +47,7 @@ impl TrialBalance { /// /// ```text /// GOAL: the trial balance over every posted entry (see trial_balance_as_of). -/// SOURCE: docs/spec/rules.md B-6; R-7. +/// SOURCE: BS-statement-1; R-7. /// INVARIANTS: /// 1. MUST equal trial_balance_as_of on or after the last entry's date. /// 2. MUST balance (total debits == total credits). @@ -63,7 +63,7 @@ pub fn trial_balance(ledger: &Ledger) -> TrialBalance { /// ```text /// GOAL: every account's balance, in a debit or a credit column, from the /// posted entries dated on or before `as_of`. -/// SOURCE: docs/spec/rules.md B-6 (Pacioli ch. 36; IRS Pub. 583); R-7, R-9b. +/// SOURCE: BS-statement-1 (Pacioli ch. 36; IRS Pub. 583); R-7, R-9b. /// INVARIANTS: /// 1. MUST have total debits equal total credits, for any books built /// through the Ledger commands. @@ -191,7 +191,7 @@ pub struct ClassProfitAndLoss { /// ```text /// GOAL: a profit and loss per class (department, location, job), plus the /// unclassified lines. -/// SOURCE: docs/spec/rules.md B-14; R-? Tracking classes. +/// SOURCE: BS-statement-3; R-? Tracking classes. /// INVARIANTS: /// 1. The per-class P&Ls (with unclassified) MUST sum to the whole P&L, /// account by account (conservation). @@ -452,7 +452,7 @@ fn statement_lines( /// ```text /// GOAL: revenue, expenses, and net income for the entries dated from /// `start` through `end` (both inclusive), optionally one class's lines. -/// SOURCE: docs/spec/rules.md B-14, B-11; R-9. +/// SOURCE: BS-statement-3, BS-period-1; R-9. /// INVARIANTS: /// 1. MUST count only revenue and expense accounts, a line per account /// with its normal-side amount, and net income = revenue - expenses. @@ -533,7 +533,7 @@ fn profit_and_loss_counted( )) } -/// A project's figures (rules.md B-37 item 3): the period's statement and +/// A project's figures (BS-statement-5 item 3): the period's statement and /// months, and its figures to date. #[derive(Clone, Debug)] pub struct ProjectFigures { @@ -563,7 +563,7 @@ impl ProjectFigures { } /// A project's figures to date: every posted revenue and expense line -/// tagged to it through `through`, whatever its dates (rules.md B-37). +/// tagged to it through `through`, whatever its dates (BS-statement-5). #[derive(Clone, Debug, PartialEq, Eq)] pub struct ProjectToDate { /// The last day counted. @@ -592,7 +592,7 @@ pub struct ProjectToDate { impl ProjectToDate { /// Revenue less expenses: the project's contribution before overhead - /// (rules.md B-37 item 7), since only its own tagged lines count. + /// (BS-statement-5 item 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 (rules.md B-37 item 7). +/// `None` without revenue to divide by (BS-statement-5 item 7). /// /// ```text /// GOAL: one margin the tools and the viewer print alike. -/// SOURCE: docs/spec/rules.md B-37 item 7 (revenue less the costs traced +/// SOURCE: BS-statement-5 item 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: docs/spec/rules.md B-37 item 3 (job costing), B-11, B-14. +/// SOURCE: BS-statement-5 item 3 (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 (rules.md B-37 item 3). +/// A tagged balance-sheet line counts zero (BS-statement-5 item 3). 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() { @@ -796,7 +796,7 @@ pub fn project_entries(ledger: &Ledger, id: ClassId) -> Vec<(crate::EntryId, Dec /// /// ```text /// GOAL: assets, liabilities, and equity as of a date, a line per account. -/// SOURCE: docs/spec/rules.md B-7 (CON 8 ¶E62), B-11; R-8. +/// SOURCE: BS-statement-2 (CON 8 ¶E62), BS-period-1; R-8. /// INVARIANTS: /// 1. MUST balance: assets = liabilities + equity + current earnings, /// exactly. @@ -917,7 +917,7 @@ pub struct GeneralLedger { /// ```text /// GOAL: every posting from `start` through `end`, by account in code /// order, with running balances. -/// SOURCE: docs/spec/rules.md B-6; R-9a (the QuickBooks general ledger). +/// SOURCE: BS-statement-1; R-9a (the QuickBooks general ledger). /// INVARIANTS: /// 1. Each account MUST show its beginning balance (entries before /// `start`), every posting in the range in date order, and an ending @@ -1147,8 +1147,8 @@ pub fn cancelled_in_span( /// GOAL: each member's capital roll-forward for a partnership over a /// period: beginning, contributions, allocated net income, distributions, /// ending; with a total. -/// SOURCE: docs/spec/rules.md B-13 (26 U.S.C. §704(a); Treas. Reg. -/// §1.704-1(b)(2)(iv)(b); Form 1065 Schedule M-2; D-38), B-11; +/// SOURCE: BS-partner-1 (26 U.S.C. §704(a); Treas. Reg. +/// §1.704-1(b)(2)(iv)(b); Form 1065 Schedule M-2; D-38), BS-period-1; /// R-9c. /// INVARIANTS: /// 1. Each row MUST roll forward exactly: beginning + contributions + @@ -1182,7 +1182,7 @@ pub fn cancelled_in_span( /// 5. An entry dated `start` is period activity, not beginning capital. /// 6. An entry and its reversal both dated in the span cancel /// ([`cancelled_in_span`]): neither is a contribution or a -/// distribution, since the correction undoes the original (B-9: "it +/// distribution, since the correction undoes the original (BS-ledger-5: "it /// is just as if you had written nothing"). A reversal whose original /// is outside the span counts by side, like any entry. /// SCENARIOS: @@ -1501,7 +1501,7 @@ pub fn snapshot(ledger: &Ledger) -> Result { } // --------------------------------------------------------------------------- -// Cash flow statement (direct method, rules.md B-14): see `crate::cashflow`. +// Cash flow statement (direct method, BS-statement-3): see `crate::cashflow`. // --------------------------------------------------------------------------- pub use crate::cashflow::{ @@ -1700,8 +1700,8 @@ pub fn register_row( /// GOAL: one list of everything the company owns as a fixed asset: what, /// which label, cost, depreciation due and posted, book value, tax /// figures, and whether the books agree. -/// SOURCE: docs/spec/rules.md B-15 (depreciation), B-24 (the register -/// reconciles to the books), B-25 (tax figures beside book); +/// SOURCE: BS-asset-1 (depreciation), BS-asset-3 (the register +/// reconciles to the books), BS-asset-4 (tax figures beside book); /// DECISION (owner, 2026-10-15): a fully featured asset register. /// INVARIANTS: /// 1. Rows: the assets acquired on or before as_of @@ -1726,7 +1726,7 @@ pub fn register_row( /// 5. Each row's tax fields are the asset's (Asset::basis_figures), /// never re-derived here. /// 6. NEVER panics: a contributor basis is as journaled, of any size -/// (rules.md B-28), and a total past exact arithmetic, or a schedule +/// (BS-entry-4), and a total past exact arithmetic, or a schedule /// that can't be computed, is refused (TooLargeToCompute, /// DateOutOfRange). /// ``` diff --git a/crates/ledger-core/src/rules.rs b/crates/ledger-core/src/rules.rs index db5ec037..381ae12d 100644 --- a/crates/ledger-core/src/rules.rs +++ b/crates/ledger-core/src/rules.rs @@ -30,7 +30,7 @@ use chrono::NaiveDate; pub struct DatedRule { /// Plain name, e.g. "1099 reporting threshold". pub name: &'static str, - /// Its entry in docs/spec/rules.md, e.g. "B-19". + /// Its entry in docs/spec/rules.md, e.g. "BS-1099-1". pub catalog: &'static str, /// The vendored official text it comes from (a path in this repo, /// for the people who update the rule). @@ -61,11 +61,11 @@ impl DatedRule { } } -/// The 1099-NEC / 1099-MISC reporting threshold (rules.md B-19): $600 for +/// The 1099-NEC / 1099-MISC reporting threshold (BS-1099-1): $600 for /// payments through 2025, $2,000 in 2026, then indexed for inflation. pub const THRESHOLD_1099: DatedRule = DatedRule { name: "1099 reporting threshold", - catalog: "B-19", + catalog: "BS-1099-1", source: "docs/spec/sources/irs-1099-thresholds.md", authority: "26 U.S.C. §6041(a) and (h) and the IRS's yearly figure in the Instructions for Forms 1099-MISC and 1099-NEC (https://www.irs.gov/instructions/i1099mec)", known_through: 2026, diff --git a/crates/ledger-core/src/schedules.rs b/crates/ledger-core/src/schedules.rs index 139542e8..5d76e0c1 100644 --- a/crates/ledger-core/src/schedules.rs +++ b/crates/ledger-core/src/schedules.rs @@ -47,7 +47,7 @@ pub enum ScheduleKind { /// How a schedule spreads its total over the time it covers. /// /// ```text -/// SOURCE: docs/spec/rules.md B-16; plan/served.md D-11 (new schedules +/// SOURCE: BS-prepaid-1; plan/served.md D-11 (new schedules /// daily, "matching depreciation"; existing ones stay /// monthly_even), D-37 (owner, 2026-10-20: confirmed; an /// equal-months schedule starts on the 1st of a month, for @@ -173,7 +173,7 @@ pub const EXACT_LIMIT: Decimal = /// 2. NEVER panics: a schedule an earlier version journaled whose months /// run past chrono's last day is refused with DateOutOfRange, and one /// whose amounts exact arithmetic can't hold with TooLargeToCompute -/// (rules.md B-28). `months` is at least 1 (validate_schedule_shape). +/// (BS-entry-4). `months` is at least 1 (validate_schedule_shape). /// 3. NEVER rounds silently: a total of EXACT_LIMIT or more is refused /// with TooLargeToCompute. Below it every amount in cents, and every /// sum of them (none exceeds the total), fits Decimal's 28 significant @@ -232,7 +232,7 @@ pub fn amortization_plan( /// ```text /// GOAL: recognize a prepaid expense, or earn deferred revenue, as each /// day it covers passes. -/// SOURCE: docs/spec/rules.md B-16 (ASC 606-10-25-23: revenue as the +/// SOURCE: BS-prepaid-1 (ASC 606-10-25-23: revenue as the /// obligation is satisfied; ASC 340-10-05-4: a prepaid is used up /// over the time it covers); plan/served.md D-11, D-37. /// INVARIANTS: @@ -381,7 +381,7 @@ fn month_first(d: NaiveDate) -> NaiveDate { /// [`validate_schedule`] without the total's range and minor-unit checks /// added on 2026-10-13 or the calendar bound added in P0: the checks every /// journaled `schedule.registered` passed when it was written, for -/// replaying journals written before them (rules.md B-28). +/// replaying journals written before them (BS-entry-4). pub fn validate_schedule_shape( new: &NewSchedule, chart: &ChartOfAccounts, @@ -585,7 +585,7 @@ pub fn validate_recurring(new: &NewRecurring, chart: &ChartOfAccounts) -> Result /// The checks every journaled `recurring.registered` passed when it was /// written (the rule through 2026-10-16): at least two lines, positive /// amounts, postable accounts, balanced, and an end not before the start. -/// Replay applies exactly these (rules.md B-28). Sums too large for exact +/// Replay applies exactly these (BS-entry-4). Sums too large for exact /// arithmetic are refused (TooLargeToCompute), never a panic. pub fn validate_recurring_journaled( new: &NewRecurring, @@ -668,7 +668,7 @@ mod tests { /// A schedule an earlier version journaled, at chrono's last month or /// with Decimal's largest total: its plan is computed where it can be, - /// refused where it can't, never a panic (rules.md B-28). + /// refused where it can't, never a panic (BS-entry-4). #[test] fn plans_at_the_edges_are_computed_or_refused() { assert_eq!(month_end(NaiveDate::MAX), NaiveDate::MAX); diff --git a/crates/ledger-core/src/settings.rs b/crates/ledger-core/src/settings.rs index 8477eace..f7e20471 100644 --- a/crates/ledger-core/src/settings.rs +++ b/crates/ledger-core/src/settings.rs @@ -22,7 +22,7 @@ //! must hold together ([`Settings::check_whole`]), or none is made. //! 3. Replay takes any value of the right shape ([`shape`]): a check a //! later version tightens never makes older books unreadable -//! (rules.md B-28). +//! (BS-entry-4). //! 4. A setting never holds a full TIN, except the company's own EIN //! (`company.ein`, decided 2026-10-16, D-5): nine digits standing //! alone, bare or printed the way an SSN or EIN is (3-2-4 or 2-7, @@ -142,7 +142,7 @@ pub enum Kind { /// A positive whole number (a day count, the first invoice number). Count, /// Payment terms, in their one canonical spelling ([`crate::Terms`], - /// rules.md B-39). + /// BS-arap-3). Terms, /// Payment methods (A-3): a list of `{kind, label, lines, link?, qr?}`. PaymentMethods, @@ -633,7 +633,7 @@ impl Company { } /// `policy.require_tax_category`: whether a revenue or expense account -/// must map to a line of the return (rules.md B-32; DECISION, owner, +/// must map to a line of the return (BS-ledger-11; DECISION, owner, /// 2026-10-20: warn by default; a company may refuse). #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] pub enum TaxCategoryPolicy { @@ -723,7 +723,7 @@ pub fn holds_printed_tin(text: &str) -> bool { /// EIN (2-7) forms count as there, but a bare run of nine digits joined /// to a letter or to the URL punctuation `/ = ? & #` does not: it is an /// id in a path or query (an app store listing's `id284882215`), not a -/// TIN someone wrote down (rules.md B-26). +/// TIN someone wrote down (BS-partner-2). pub fn holds_printed_tin_in_link(text: &str) -> bool { printed_tin(text, true) } @@ -1936,7 +1936,7 @@ mod tests { assert_eq!(s.get("company.name").unwrap().seq, 7); } - /// policy.require_tax_category (rules.md B-32): warn or refuse, one + /// policy.require_tax_category (BS-ledger-11): warn or refuse, one /// spelling each ("required" and "require" are refuse), nothing else /// ("off" is no value: the warning is the floor); unset is warn. #[test] diff --git a/crates/ledger-core/src/shares.rs b/crates/ledger-core/src/shares.rs index 550b6ae0..d70ed17b 100644 --- a/crates/ledger-core/src/shares.rs +++ b/crates/ledger-core/src/shares.rs @@ -18,11 +18,11 @@ //! transaction is with both members, each with their share, and //! shares can be apportioned explicitly ("do you allow for //! controlled apportioning?" Yes). docs/parties-and-attachments.md -//! "Shares". rules.md B-35 (the sign, direction and money of a +//! "Shares". BS-partner-3 (the sign, direction and money of a //! part; DECISION, owner, 2026-10-20: a member's entry counts what //! moved their capital). //! DEFINITIONS: -//! target (target(), rules.md B-35 item 3): what the shares split, +//! target (target(), BS-partner-3 item 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 @@ -188,7 +188,7 @@ pub struct PartyMember { /// /// For new shares: [`check_shares_journaled`], and no amount larger than a /// line may be (kernel::MAX_LINE_AMOUNT; P0 review round 3, S1). Replay -/// checks only [`check_shares_journaled`] (rules.md B-28). +/// checks only [`check_shares_journaled`] (BS-entry-4). pub fn check_shares(shares: &[PartyShare], known: impl Fn(PartyId) -> bool) -> Result<(), String> { check_shares_journaled(shares, known)?; for s in shares { @@ -207,7 +207,7 @@ pub fn check_shares(shares: &[PartyShare], known: impl Fn(PartyId) -> bool) -> R /// The checks every journaled `entry.parties_set` passed when it was /// written (the rule through 2026-10-16): [`check_shares`] without the /// amount's upper bound. Replay applies exactly these, so books an earlier -/// version wrote always open (rules.md B-28). +/// version wrote always open (BS-entry-4). pub fn check_shares_journaled( shares: &[PartyShare], known: impl Fn(PartyId) -> bool, @@ -304,7 +304,7 @@ fn split_first(magnitude: Decimal, weights: &[Decimal]) -> Option> } /// What an entry's shares split, and what of it counts (the module's -/// DEFINITIONS: target; rules.md B-35). +/// DEFINITIONS: target; BS-partner-3). #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct Target { /// The whole, signed debit-positive as a line on the parties' own @@ -318,7 +318,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 (B-35 item 4). + /// a reversal nets what it reverses (BS-partner-3 item 4). pub counts_as: Direction, } @@ -356,7 +356,7 @@ impl Resolved { /// checked; they cover the whole reversal chain (Ledger::set_entry_parties /// INVARIANT 5). Refused (TooLargeToCompute), never a panic, when a sum is /// past exact arithmetic: a draft's lines are as journaled, of any size -/// (rules.md B-28). +/// (BS-entry-4). pub fn target( ledger: &Ledger, id: EntryId, diff --git a/crates/ledger-core/src/tax.rs b/crates/ledger-core/src/tax.rs index a6d6ac91..f8e37bb0 100644 --- a/crates/ledger-core/src/tax.rs +++ b/crates/ledger-core/src/tax.rs @@ -400,7 +400,7 @@ pub fn check_category( /// no postings, so nothing of its own reaches the return). /// /// ```text -/// GOAL: the accounts a tax category is for (rules.md B-32). +/// GOAL: the accounts a tax category is for (BS-ledger-11). /// SOURCE: IRS Pub. 583, "Your books must show your gross income, as well /// as your deductions and credits"; Rev. Proc. 98-25 §5.01, a /// relationship between "the amounts ... by account and the @@ -540,7 +540,7 @@ struct CategoryBuild { /// Build the tax summary for `[start, end]`, closing entries excluded (like /// the P&L). Each category's deductible amount is the exact sum of its /// accounts' shares (book × deductible percent ÷ 100), rounded once to -/// the cent, half away from zero (B-21: "round off only the total"); the +/// the cent, half away from zero (BS-entry-3: "round off only the total"); the /// book amounts stay exact. The share arithmetic is /// [`crate::kernel::deductible_amount`], so Kani proves the one rounding. pub fn tax_summary( diff --git a/crates/ledger-core/src/tax_capital.rs b/crates/ledger-core/src/tax_capital.rs index fc9f9fcd..aeb89a2d 100644 --- a/crates/ledger-core/src/tax_capital.rs +++ b/crates/ledger-core/src/tax_capital.rs @@ -72,7 +72,7 @@ //! 2. IF a fixed asset is in service during the span: //! - SHOULD leave the tax net income open, with the book depreciation //! posted in the span -//! BECAUSE tax depreciation is the CPA's (rules.md B-15, B-25). +//! BECAUSE tax depreciation is the CPA's (BS-asset-1, BS-asset-4). //! 3. IF nothing but cash comes in and goes out: //! - SHOULD still leave the tax net income open, the book share known //! BECAUSE income "as figured for tax purposes" is the return's. @@ -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: -/// rules.md B-15 rule 5). With the runs +/// BS-asset-1 rule 5). 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 (B-14 rule 8). +/// expense in the span, the P&L's and the cash flow's (BS-statement-3 rule 8). /// 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). @@ -215,7 +215,7 @@ pub enum Open { pub enum Note { /// Property contributed in `entry` to a prepaid account (the balance /// account of a prepaid-expense schedule: a service contract the - /// member handed over, B-13) with no fixed asset for it: its §723 + /// member handed over, BS-partner-1) with no fixed asset for it: its §723 /// basis is taken as its book amount, this member's share `book` /// (DECISION, P3 review 2026-10-21: the contract's carryover basis is /// what the books recorded for it; the CPA to confirm). @@ -342,7 +342,7 @@ fn too_large() -> LedgerError { } /// A running split of amounts among members, one split at a time, each -/// by its own weights (B-36, the odd cent as D-38 settles it): each +/// by its own weights (BS-partner-4, the odd cent as D-38 settles it): each /// member's running total is rounded afresh from their exact running /// total, so it never drifts a cent from it, and tied cents don't pile up /// on one member. The worksheet keeps one per set of members with weight @@ -354,8 +354,8 @@ fn too_large() -> LedgerError { /// distributed is a cent or more from their exact share, however /// many entries it is summed over; three equal odd-cent properties /// contributed 50/50 leave the members one cent apart, never three. -/// SOURCE: rules.md B-36 (shared within each entry as its book value is), -/// B-13 (cent rounding by largest remainder: DECISION, owner +/// SOURCE: BS-partner-4 (shared within each entry as its book value is), +/// BS-partner-1 (cent rounding by largest remainder: DECISION, owner /// 2026-10-13); DECISION D-38 (owner, 2026-10-20: odd cents /// everywhere alike, cumulative largest remainder), here for the /// tax basis by the owner's ask, 2026-10-22 (kernel:: @@ -552,7 +552,7 @@ impl RunningSplit { /// it is rounded to the cent ([`RunningSplit`] INVARIANT 4). const EXACT_PLACES: u32 = 10; -/// The four amounts an entry's members share (B-36): the property's +/// The four amounts an entry's members share (BS-partner-4): the property's /// built-in gain, its property without a basis, its prepaid at book (each /// by the members' property in it) and the property it distributes (by /// what each took). @@ -632,14 +632,14 @@ fn entry_wholes( Ok(out) } -/// Every entry's parts of the amounts it splits (B-36 with D-38), from +/// Every entry's parts of the amounts it splits (BS-partner-4 with D-38), from /// the books' first entry through `end`, whatever span the worksheet is /// asked for, so an entry's cents are the same in every span it is in. /// /// ```text /// GOAL: odd cents that run (RunningSplit) and never touch a member who /// has no part in the entry, nor change with the span asked for. -/// SOURCE: rules.md B-36; DECISION D-38; Form 1065 Item L (a partner's +/// SOURCE: BS-partner-4; DECISION D-38; Form 1065 Item L (a partner's /// capital contributed is the basis of the property that partner /// contributed). /// INVARIANTS: diff --git a/crates/ledger-core/tests/assets.rs b/crates/ledger-core/tests/assets.rs index 64892259..70f08b05 100644 --- a/crates/ledger-core/tests/assets.rs +++ b/crates/ledger-core/tests/assets.rs @@ -296,7 +296,7 @@ fn schedule_through_purchase_date_covers_one_day() { #[test] fn van_schedule_is_the_hand_computed_one() { - // Rank 1, computed by hand (rules.md B-15), replacing an unreviewed + // Rank 1, computed by hand (BS-asset-1), replacing an unreviewed // golden file (2026-10-13; every row of the old file was checked // against this computation first, and matched). // $60,000 over 60 months is $1,000 a month. Bought 2026-01-15: January diff --git a/crates/ledger-core/tests/audit.rs b/crates/ledger-core/tests/audit.rs index 8be21116..1702e2e3 100644 --- a/crates/ledger-core/tests/audit.rs +++ b/crates/ledger-core/tests/audit.rs @@ -1,4 +1,4 @@ -//! The audit's statements checks (plan P8; rules.md B-45): one test per +//! The audit's statements checks (plan P8; BS-ledger-13): one test per //! finding code, each seeding exactly the defect the code names. use std::collections::BTreeSet; diff --git a/crates/ledger-core/tests/bookspec/books.rs b/crates/ledger-core/tests/bookspec/books.rs index 0dd67492..90e50947 100644 --- a/crates/ledger-core/tests/bookspec/books.rs +++ b/crates/ledger-core/tests/bookspec/books.rs @@ -281,7 +281,7 @@ impl<'a> Books<'a> { s.rounding ); // The engine splits a close among the members by largest - // remainder (rules.md B-13): an example closing to the members + // remainder (BS-partner-1): an example closing to the members // says so. assert!( s.rounding == "largest-remainder" diff --git a/crates/ledger-core/tests/bookspec/common.rs b/crates/ledger-core/tests/bookspec/common.rs index 0a1a0085..ed7f7445 100644 --- a/crates/ledger-core/tests/bookspec/common.rs +++ b/crates/ledger-core/tests/bookspec/common.rs @@ -16,7 +16,7 @@ pub(crate) fn account_type(a: &AccountSpec, id: &str) -> AccountType { } /// The period `[from, to]` a period query covers, each date omitted -/// resolved by the one rule (rules.md B-30) on `setup.today`; panics on +/// resolved by the one rule (B-30) on `setup.today`; panics on /// `as_of`, on an omitted date without `setup.today`, and on a period the /// rule refuses. pub(crate) fn period(ex: &Example, x: &Expect) -> (NaiveDate, NaiveDate) { @@ -55,8 +55,8 @@ pub(crate) fn resolved_q_period( defaults(ex, &q.name).statement(from, to) } -/// The day an as-of query is made as of (omitted: `setup.today`, rules.md -/// B-30); panics on `from` or `to`. +/// The day an as-of query is made as of (omitted: `setup.today`, +/// BS-period-3); panics on `from` or `to`. pub(crate) fn day(ex: &Example, x: &Expect) -> NaiveDate { let q = x.query(); resolved_q_day(ex, &q).unwrap_or_else(|e| panic!("{}: {}: {e}", ex.id, x.query)) @@ -83,12 +83,12 @@ pub(crate) trait Pipe: Sized { } } impl Pipe for T {} -/// What an omitted date means for `ex` (rules.md B-30): its fiscal year +/// What an omitted date means for `ex` (B-30): its fiscal year /// on `setup.today`, which `query` needs. pub(crate) fn defaults(ex: &Example, query: &str) -> PeriodDefaults { let today = ex.setup.today.as_deref().unwrap_or_else(|| { panic!( - "{}: {query} omits a date: setup.today says what it means (rules.md B-30)", + "{}: {query} omits a date: setup.today says what it means (B-30)", ex.id ) }); diff --git a/crates/ledger-core/tests/bookspec/events.rs b/crates/ledger-core/tests/bookspec/events.rs index 7f63fa0b..96f478eb 100644 --- a/crates/ledger-core/tests/bookspec/events.rs +++ b/crates/ledger-core/tests/bookspec/events.rs @@ -411,7 +411,7 @@ impl Books<'_> { }; // Each write-off's own notice: identical bytes would be one // record (plan P6 step 4), and a receipt evidences one entry - // (B-38), so a second write-off with the first's letter is + // (BS-arap-2), so a second write-off with the first's letter is // refused before anything is journaled. let letter = format!( "%PDF-1.4\nFinal demand for invoice {invoice}: {}\n%%EOF\n", diff --git a/crates/ledger-core/tests/bookspec/loader_tests.rs b/crates/ledger-core/tests/bookspec/loader_tests.rs index f8a5234e..1cae99f9 100644 --- a/crates/ledger-core/tests/bookspec/loader_tests.rs +++ b/crates/ledger-core/tests/bookspec/loader_tests.rs @@ -218,7 +218,7 @@ pub(crate) fn a_members_close_declared_with_another_rounding_is_refused() { }); } -/// A period's dates are the rule's (rules.md B-30): an example saying the +/// A period's dates are the rule's (BS-period-3): an example saying the /// fiscal year to date starts on January 1 under a July fiscal year fails. #[test] #[should_panic(expected = "period from")] @@ -560,7 +560,7 @@ pub(crate) fn a_members_reconciliation_shows_every_cause() { } /// A project named twice in `setup.projects` is refused (names are -/// unique, rules.md B-37). +/// unique, BS-statement-5). #[test] #[should_panic(expected = "a project named")] pub(crate) fn a_project_named_twice_is_refused() { diff --git a/crates/ledger-core/tests/bookspec/queries/assets.rs b/crates/ledger-core/tests/bookspec/queries/assets.rs index 1795b43e..2f4f0baf 100644 --- a/crates/ledger-core/tests/bookspec/queries/assets.rs +++ b/crates/ledger-core/tests/bookspec/queries/assets.rs @@ -225,7 +225,7 @@ impl Books<'_> { /// Check one `run` expectation: what the `run_depreciation` event `event` /// posted (`amount`: zero when nothing was due, or the month already had /// its run) and, of it, what it caught up beyond its own month's -/// depreciation (`caught_up`), both listed (rules.md B-15). +/// depreciation (`caught_up`), both listed (BS-asset-1). pub(crate) fn check_run(b: &Books<'_>, x: &Expect) { let ex = b.ex; undated(ex, x); @@ -256,7 +256,7 @@ pub(crate) fn check_run(b: &Books<'_>, x: &Expect) { } /// Check one `disposal` expectation: what the disposal of `asset` took, as -/// the engine computed it when posting it (rules.md B-15), every figure +/// the engine computed it when posting it (BS-asset-1), every figure /// listed: `final_depreciation` (posted in its own entry before the /// disposal), `catch_up_depreciation` and `excess_depreciation` (charged, /// and credited back, in the disposal entry), `accumulated` (cleared), @@ -288,7 +288,7 @@ pub(crate) fn check_disposal(b: &Books<'_>, x: &Expect) { } /// Check one `depreciation_schedule` expectation: the schedule of `asset` -/// through `as_of` (rules.md B-15), each month named (`"YYYY-MM"`) its +/// through `as_of` (BS-asset-1), each month named (`"YYYY-MM"`) its /// depreciation, 0.00 for a month the schedule doesn't reach; /// `accumulated` and `book_value` through `as_of`; the example names the /// figures it shows. @@ -326,7 +326,7 @@ pub(crate) fn check_depreciation_schedule(b: &Books<'_>, x: &Expect) { /// Check one `schedule_plan` expectation: what the schedule's plan /// recognizes at each month end named (`"YYYY-MM-DD"`, 0.00 at a month end -/// the plan doesn't post), and `total`, all it recognizes (rules.md B-16); +/// the plan doesn't post), and `total`, all it recognizes (BS-prepaid-1); /// the example names the figures it shows. pub(crate) fn check_schedule_plan(b: &Books<'_>, x: &Expect) { let ex = b.ex; @@ -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` (rules.md B-15 rules 7 and 8, B-24): +/// asset register as of `as_of` (BS-asset-1 rules 7 and 8, 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` @@ -403,7 +403,7 @@ pub(crate) fn check_register_row(b: &Books<'_>, x: &Expect) { } /// Check one `register_totals` expectation: the fixed asset register's -/// totals as of `as_of`, over the assets held (rules.md B-24, B-25): +/// totals as of `as_of`, over the assets held (BS-asset-3, BS-asset-4): /// `total_cost`, `total_accumulated_scheduled`, `total_accumulated_posted`, /// `total_book_value`, `total_depreciable_basis`, `total_tax_basis_723`, /// `missing_basis` (how many held have none), and how it reconciles to @@ -440,7 +440,7 @@ pub(crate) fn check_register_totals(b: &Books<'_>, x: &Expect) { } /// Check one `asset_basis` expectation: the asset's basis facts and the -/// tax figures they give (rules.md B-25): `rule`, +/// tax figures they give (BS-asset-4): `rule`, /// `contributor_adjusted_basis`, `fmv_at_contribution`, `tax_basis_723`, /// `depreciable_basis`, `built_in_gain_704c` (a loss negative), each /// `"none"` where the asset has none (a purchase's §723 basis), and diff --git a/crates/ledger-core/tests/bookspec/queries/commands.rs b/crates/ledger-core/tests/bookspec/queries/commands.rs index 3747962c..a0547934 100644 --- a/crates/ledger-core/tests/bookspec/queries/commands.rs +++ b/crates/ledger-core/tests/bookspec/queries/commands.rs @@ -76,7 +76,7 @@ pub(crate) fn every_balance(l: &Ledger) -> Vec<(String, Decimal, Decimal)> { } /// Try one command on a copy of the books, as the books' own command does -/// it (the engine's checks, then the policy's: rules.md B-31, B-32), and +/// it (the engine's checks, then the policy's: BS-ledger-10, BS-ledger-11), and /// check it is accepted or refused for the reason given. pub(crate) fn check_command(ex: &Example, l: &Ledger, x: &Expect) { let mut copy = l.clone(); @@ -88,7 +88,7 @@ pub(crate) fn check_command(ex: &Example, l: &Ledger, x: &Expect) { .as_deref() .unwrap_or_else(|| panic!("{}: rename_account gives the name", ex.id)); copy.rename_account(account, name).inspect(|()| { - // A rename changes the label, nothing else (rules.md B-31). + // A rename changes the label, nothing else (BS-ledger-10). assert_eq!( copy.chart().get(account).unwrap().name, name.trim(), diff --git a/crates/ledger-core/tests/bookspec/queries/dates.rs b/crates/ledger-core/tests/bookspec/queries/dates.rs index e127cc6f..91e13709 100644 --- a/crates/ledger-core/tests/bookspec/queries/dates.rs +++ b/crates/ledger-core/tests/bookspec/queries/dates.rs @@ -1,7 +1,7 @@ use crate::*; /// Check one `period` expectation: the period a period report asked with -/// these dates covers, by the one rule (rules.md B-30), as `from` and +/// these dates covers, by the one rule (BS-period-3), as `from` and /// `to`; or the rule's refusal. pub(crate) fn check_period(ex: &Example, x: &Expect) { match (resolved_period(ex, x), &x.refused) { @@ -20,7 +20,7 @@ pub(crate) fn check_period(ex: &Example, x: &Expect) { } /// Check one `day` expectation: the day a report as of a day is made as -/// of (rules.md B-30), as `as_of`. +/// of (BS-period-3), as `as_of`. pub(crate) fn check_day(ex: &Example, x: &Expect) { exactly(ex, x, &["as_of".to_string()].into()); let want = date(&x.figures(&ex.id)["as_of"], &ex.id); @@ -28,7 +28,7 @@ pub(crate) fn check_day(ex: &Example, x: &Expect) { } /// Check one `calendar_year` expectation: the year a calendar-year count -/// (1099s, party totals) asked without one counts (rules.md B-30). +/// (1099s, party totals) asked without one counts (BS-period-3). pub(crate) fn check_calendar_year(ex: &Example, x: &Expect) { assert!( x.from.is_none() && x.to.is_none() && x.as_of.is_none(), @@ -49,8 +49,8 @@ pub(crate) fn check_calendar_year(ex: &Example, x: &Expect) { /// Check one `account_names` expectation: each account's name, by code, /// as the chart holds it and every report prints it (the trial balance -/// and the profit and loss, over every date: past periods too, rules.md -/// B-31); every account listed. +/// and the profit and loss, over every date: past periods too, +/// BS-ledger-10); every account listed. pub(crate) fn check_account_names(ex: &Example, l: &Ledger, x: &Expect) { assert!( x.from.is_none() && x.to.is_none() && x.as_of.is_none(), @@ -83,7 +83,7 @@ pub(crate) fn check_account_names(ex: &Example, l: &Ledger, x: &Expect) { /// Check one `uncategorized_accounts` expectation: every account that /// maps to a line of the return and has no tax category, with activity or -/// not, as `" "`, by code (rules.md B-32). +/// not, as `" "`, by code (BS-ledger-11). pub(crate) fn check_uncategorized_accounts(ex: &Example, l: &Ledger, x: &Expect) { assert!( x.from.is_none() && x.to.is_none() && x.as_of.is_none(), diff --git a/crates/ledger-core/tests/bookspec/queries/parties.rs b/crates/ledger-core/tests/bookspec/queries/parties.rs index b6449b4b..a8089a6f 100644 --- a/crates/ledger-core/tests/bookspec/queries/parties.rs +++ b/crates/ledger-core/tests/bookspec/queries/parties.rs @@ -192,13 +192,13 @@ impl Books<'_> { /// The 1099 report a `vendor_1099_paid` or `vendor_1099` expectation /// asks for: the calendar year of `to`, from January 1 through `to`, out /// of the cash and financing accounts, an entry's shares resolved with -/// the members who are parties (rules.md B-19, B-33). +/// the members who are parties (BS-1099-1, BS-statement-4). pub(crate) fn report_1099( b: &Books<'_>, x: &Expect, ) -> (NaiveDate, NaiveDate, ledger_core::Vendor1099Report) { let (ex, l) = (b.ex, b.l()); - // A calendar-year count, never the fiscal default (rules.md B-30): + // A calendar-year count, never the fiscal default (BS-period-3): // both dates given. assert!( x.from.is_some() && x.to.is_some(), @@ -231,7 +231,7 @@ pub(crate) fn report_1099( /// Check one `vendor_1099_paid` expectation: each payee's payments that /// count toward its 1099 ([`report_1099`]), a payment card's left out, -/// every payee listed (rules.md B-19, B-33). +/// every payee listed (BS-1099-1, BS-statement-4). pub(crate) fn check_vendor_1099_paid(b: &Books<'_>, x: &Expect) { let ex = b.ex; let (from, to, r) = report_1099(b, x); @@ -254,7 +254,7 @@ pub(crate) fn check_vendor_1099_paid(b: &Books<'_>, x: &Expect) { /// applied, and what was `paid` (counts toward its 1099), /// `excluded_card` (a card or payment network's, Form 1099-K), /// `undetermined` (its payment method not recorded) and `not_reportable` -/// (paid while decided not reportable); every one given (rules.md B-19). +/// (paid while decided not reportable); every one given (BS-1099-1). pub(crate) fn check_vendor_1099(b: &Books<'_>, x: &Expect) { let ex = b.ex; let name = x @@ -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 (rules.md B-35 item 5). +/// financing accounts (BS-partner-3 item 5). pub(crate) fn party_money(ex: &Example, l: &Ledger) -> MoneyAccounts { ledger_core::parties::money_accounts( l, @@ -320,7 +320,7 @@ pub(crate) fn expect_party(b: &Books<'_>, x: &Expect) -> PartyId { } /// Check one `party_part` expectation: entry N's part for the party -/// (rules.md B-35): `resolved`, signed as a line on the party's own +/// (BS-partner-3): `resolved`, signed as a line on the party's own /// account (debit-positive: paid or given positive, received negative), /// the entry's `direction` (`paid`, `received` or `neither`), and what /// of it moved as money (`cash`) and as property (`in_kind`); every one @@ -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 (rules.md B-35 item 4); both given. +/// root original's side (BS-partner-3 item 4); both given. pub(crate) fn check_party_totals(b: &Books<'_>, x: &Expect) { let (ex, l) = (b.ex, b.l()); assert!( @@ -421,8 +421,8 @@ pub(crate) fn check_party_totals(b: &Books<'_>, x: &Expect) { ); } -/// Check one `project` expectation (rules.md B-37): the project's -/// `revenue`, `expenses` and `net` for the period (B-30 resolving omitted +/// Check one `project` expectation (BS-statement-5): the project's +/// `revenue`, `expenses` and `net` for the period (BS-period-3 resolving omitted /// dates), the same `to_date` (every tagged line through `to`), and its /// `unrecovered_cost` (`"none"` unless it is on spec); every one given. /// Through ledger_core::project_figures, as the tools and the viewer. @@ -474,7 +474,7 @@ pub(crate) fn check_project(b: &Books<'_>, x: &Expect) { /// Check one `party_tin_last4` expectation: the last four of the party's /// TIN the books keep (its TIN facts', else its W-9's; `""` for none: -/// rules.md B-26). +/// BS-partner-2). pub(crate) fn check_party_tin_last4(b: &Books<'_>, x: &Expect) { let ex = b.ex; assert!( diff --git a/crates/ledger-core/tests/bookspec/queries/statements.rs b/crates/ledger-core/tests/bookspec/queries/statements.rs index a48b5333..ae9d6e89 100644 --- a/crates/ledger-core/tests/bookspec/queries/statements.rs +++ b/crates/ledger-core/tests/bookspec/queries/statements.rs @@ -389,7 +389,7 @@ pub(crate) fn check_cash_flow(b: &Books<'_>, x: &Expect) { /// Check one `trial_balance` expectation: each account's balance as of /// the day, debits less credits (a credit balance negative), every -/// account listed (rules.md B-6, B-33). +/// account listed (BS-statement-1, BS-statement-4). pub(crate) fn check_trial_balance(ex: &Example, l: &Ledger, x: &Expect) { let as_of = day(ex, x); let tb = trial_balance_as_of(l, as_of); @@ -411,7 +411,7 @@ pub(crate) fn check_trial_balance(ex: &Example, l: &Ledger, x: &Expect) { /// Check one `profit_and_loss` expectation: each revenue and expense /// account's activity over the period on its normal side, closing entries /// left out, and `net_income`, revenue less expenses; every revenue and -/// expense account listed (rules.md B-14, B-33). +/// expense account listed (BS-statement-3, BS-statement-4). pub(crate) fn check_profit_and_loss(ex: &Example, l: &Ledger, x: &Expect) { let (start, end) = period(ex, x); let pl = profit_and_loss_for_period(l, start, end, None) @@ -506,8 +506,8 @@ pub(crate) fn check_balances(ex: &Example, l: &Ledger, x: &Expect) { /// Check one `members_equity` expectation: the statement of changes in /// members' equity over the period, `"."` for the columns /// `beginning`, `contributions`, `net_income`, `distributions`, `other` -/// and `ending`; the figures named are the example's choice (rules.md -/// B-13). +/// and `ending`; the figures named are the example's choice ( +/// BS-partner-1). pub(crate) fn check_members_equity( ex: &Example, l: &Ledger, diff --git a/crates/ledger-core/tests/bookspec/queries/tax.rs b/crates/ledger-core/tests/bookspec/queries/tax.rs index e93a490d..188a05df 100644 --- a/crates/ledger-core/tests/bookspec/queries/tax.rs +++ b/crates/ledger-core/tests/bookspec/queries/tax.rs @@ -92,8 +92,8 @@ impl Books<'_> { } } -/// Check one `k1` expectation: the K-1 worksheet over the period (rules.md -/// B-13; Schedule K-1 Item L), `"."` for the columns +/// Check one `k1` expectation: the K-1 worksheet over the period ( +/// BS-partner-1; Schedule K-1 Item L), `"."` for the columns /// `beginning`, `contributions_cash`, `contributions_property`, /// `net_income`, `distributions`, `other` and `ending`; the figures named /// are the example's choice. It needs `cash_accounts` (what is money @@ -136,7 +136,7 @@ pub(crate) fn check_k1(ex: &Example, l: &Ledger, members: &[MemberCapital], x: & } } -/// The tax-basis capital worksheet for `[from, to]` (rules.md B-36), a +/// The tax-basis capital worksheet for `[from, to]` (BS-partner-4), a /// row a member, as `k1` reads the book one: it needs the members and /// their shares, and `cash_accounts`. pub(crate) fn tax_capital_rows(b: &Books<'_>, x: &Expect, what: &str) -> Vec { @@ -158,7 +158,7 @@ pub(crate) fn tax_capital_rows(b: &Books<'_>, x: &Expect, what: &str) -> Vec."` for the lines `beginning`, +/// (BS-partner-4), `"."` for the lines `beginning`, /// `contributions_cash`, `contributions_property`, `net_income`, `other`, /// `distributions` and `ending`, beside `k1`'s book figures; a line the /// books can't know is `"open"`, with what they know so far as @@ -201,8 +201,8 @@ pub(crate) const RECONCILING_CAUSES: [&str; 5] = [ ]; /// Check one `k1_reconciliation` expectation: each member's book capital -/// less tax-basis capital at the end of `[from, to]`, by cause (rules.md -/// B-36), `"."` for `beginning`, `built_in_gain_704c` +/// less tax-basis capital at the end of `[from, to]`, by cause ( +/// BS-partner-4), `"."` for `beginning`, `built_in_gain_704c` /// (their share of the §704(c) gain or loss at contribution), /// `property_without_basis`, `property_distributed` and `total`: the /// example names the members it shows, each with every cause. diff --git a/crates/ledger-core/tests/exact_totals.rs b/crates/ledger-core/tests/exact_totals.rs index 92d16229..d1f6f6a6 100644 --- a/crates/ledger-core/tests/exact_totals.rs +++ b/crates/ledger-core/tests/exact_totals.rs @@ -1,5 +1,5 @@ //! Totals past exact arithmetic are refused, never a panic (kernel sweep -//! unit K-U4; rules.md B-21, B-28). +//! unit K-U4; BS-entry-3, BS-entry-4). //! //! A replayed journal line is accepted "of any size", so a restored //! figure can sit at `Decimal::MAX`; every sum the engine makes of such diff --git a/crates/ledger-core/tests/form1099.rs b/crates/ledger-core/tests/form1099.rs index eabe2bdf..c45db33b 100644 --- a/crates/ledger-core/tests/form1099.rs +++ b/crates/ledger-core/tests/form1099.rs @@ -116,7 +116,7 @@ fn pay( ) -> EntryId { // As replay posts it: money from a vendor on receivables (1200) by // hand, as books an earlier version wrote can hold it; the control - // guard (rules.md B-38) refuses that as new work. + // guard (BS-arap-2) refuses that as new work. let e = ledger_core::parties::replaying(|| { let e = l.create_entry(date, "payment"); let m = Money::new(dec(amt), Currency::USD); @@ -219,7 +219,7 @@ fn cash_paid_per_vendor_and_who_is_reportable() { #[test] fn years_and_thresholds() { let l = books(); - // SOURCE: rules.md B-19 (sources/irs-1099-thresholds.md; Pub. L. + // SOURCE: BS-1099-1 (sources/irs-1099-thresholds.md; Pub. L. // 119-21 §70433(f): payments made after December 31, 2025). assert_eq!(default_threshold(2025), Ok(dec("600"))); assert_eq!(default_threshold(2026), Ok(dec("2000"))); @@ -805,7 +805,7 @@ fn a_debit_card_payment_from_the_bank_is_excluded_when_tagged() { assert_eq!((v.paid, v.excluded_card), (dec("300.00"), dec("1200.00"))); } -/// Never guessed (B-19): only a company card's account presumes a card. +/// Never guessed (BS-1099-1): only a company card's account presumes a card. /// The members' account 2100, left out of the financing accounts, carries /// a member's card; a platform's balance 1050 carries a payment platform. /// Each also pays by check or friends-and-family transfer (counting), so @@ -1511,7 +1511,7 @@ fn an_undated_old_decision_is_in_force_from_the_beginning() { assert!(b.decision_needed); } -/// kernel::payment_bucket, every one of its 16 cases against the B-19 +/// kernel::payment_bucket, every one of its 16 cases against the BS-1099-1 /// table (a complete check, not a sample). #[test] fn payment_bucket_is_the_table_in_all_16_cases() { @@ -2317,7 +2317,7 @@ proptest! { } } - /// rules.md B-35 item 9: party totals and the 1099 worksheet never + /// BS-partner-3 item 9: 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 @@ -2521,12 +2521,12 @@ fn card_accounts_are_the_company_cards_liabilities() { /// plan/golden-worksheets/1099-worksheet.md before this test was run. /// 2025 and 2026 together pin the year boundary: Dana's 300.00 on /// 2025-12-30 counts in 2025 only, and the threshold moves from 600 to -/// 2,000 (rules.md B-19). +/// 2,000 (BS-1099-1). #[test] fn golden_1099_worksheet() { let mut l = books(); // Record the card (worksheet, "With the card recorded"): Sam's 5,000 - // is then a card payment, excluded and listed (B-19). books() leaves + // is then a card payment, excluded and listed (BS-1099-1). books() leaves // it unrecorded, and other tests rely on that. let card = l.chart().find_by_code("2100").unwrap().id; l.add_instrument( diff --git a/crates/ledger-core/tests/golden_audit.rs b/crates/ledger-core/tests/golden_audit.rs index dd075bc2..2270f0bc 100644 --- a/crates/ledger-core/tests/golden_audit.rs +++ b/crates/ledger-core/tests/golden_audit.rs @@ -1,5 +1,5 @@ //! The audit workpaper's findings for one small book, hand-verified -//! (rules.md B-45; plan/golden-worksheets/audit-workpaper.md). +//! (BS-ledger-13; plan/golden-worksheets/audit-workpaper.md). //! //! The fixture is a bank, prepaid insurance, capital, two revenue and two //! expense accounts, a 12-month prepaid plan, and a vendor paid from the diff --git a/crates/ledger-core/tests/golden_reports.rs b/crates/ledger-core/tests/golden_reports.rs index 475235b3..98fe4dd4 100644 --- a/crates/ledger-core/tests/golden_reports.rs +++ b/crates/ledger-core/tests/golden_reports.rs @@ -34,7 +34,7 @@ fn post(ledger: &mut Ledger, date: NaiveDate, description: &str, lines: &[(Accou // As replay posts it: this fixture holds hand lines on the receivable // and payable control accounts (1200, 2000), which books an earlier // version wrote still hold and every report must read; the control - // guard (rules.md B-38) refuses them as new work. + // guard (BS-arap-2) refuses them as new work. ledger_core::parties::replaying(|| { let id = ledger.create_entry(date, description); for (account, side, amount) in lines { diff --git a/crates/ledger-core/tests/invariants.rs b/crates/ledger-core/tests/invariants.rs index 76bead92..dbcd1203 100644 --- a/crates/ledger-core/tests/invariants.rs +++ b/crates/ledger-core/tests/invariants.rs @@ -34,7 +34,7 @@ fn usd(amount: u64) -> Money { fn post(ledger: &mut Ledger, date: NaiveDate, description: &str, lines: &[(AccountId, Side, u64)]) { // As replay posts it: these books hold hand lines on receivables or // payables (1200, 2000), which books an earlier version wrote still - // hold and every report must read; the control guard (rules.md B-38) + // hold and every report must read; the control guard (BS-arap-2) // refuses them as new work. ledger_core::parties::replaying(|| { let id = ledger.create_entry(date, description); @@ -213,7 +213,7 @@ fn out_of_range_amount_is_rejected() { // Big enough to overflow a sum: an error, never a panic, as soon as // the line is added (a draft is summed before it posts: its debits, // its parties' shares; P0 review round 3, S1). Replayed as an earlier - // version wrote it (rules.md B-28): accepted into its draft, whose + // version wrote it (BS-entry-4): accepted into its draft, whose // post refuses it, never a panic. let id = ledger.create_entry(date(21), "Too big"); let old = ledger.create_entry(date(21), "Too big, journaled before the bound"); @@ -268,7 +268,7 @@ fn out_of_range_amount_is_rejected() { ); } -/// B-3 (DECISION, owner 2026-10-13: a ledger in one money holds no +/// BS-ledger-1 (DECISION, owner 2026-10-13: a ledger in one money holds no /// fractions of its smallest unit). Regression: a payroll run posted /// $65.27794 (found by the store's refusal property in CI, 2026-10-13). #[test] @@ -392,7 +392,7 @@ fn foreign_currency_line_is_rejected() { ); } -/// R-1 / B-3: one currency throughout an entry. Even when every line +/// R-1 / BS-ledger-1: one currency throughout an entry. Even when every line /// matches its own account's currency (a chart the ledger never builds /// today, R-5), an entry mixing currencies is refused. #[test] @@ -657,7 +657,7 @@ fn random_balanced_journals_preserve_invariants() { // As replay posts them: random lines land on receivables and // payables by hand, as books an earlier version wrote can hold them - // (the control guard, rules.md B-38, refuses them as new work). + // (the control guard, BS-arap-2, refuses them as new work). ledger_core::parties::replaying(|| { for i in 0..300u32 { let total = rng.next(100_000) + 100; @@ -755,7 +755,7 @@ fn entry_movements_sum_to_zero() { } // --------------------------------------------------------------------------- -// Cash flow statement (direct method, rules.md B-14). +// Cash flow statement (direct method, BS-statement-3). // --------------------------------------------------------------------------- use ledger_core::NewAsset; @@ -797,8 +797,8 @@ fn cash_flow_reconciles_to_change_in_cash() { assert!(r.lines.iter().all(|l| l.label != "Depreciation")); // Operating, by the direct method: collected 1,500 (class (a)); paid - // 2,500 for equipment (not a registered asset: operating, rules.md - // B-14 rule 12's limits) and 800 rent (class (d)) = -1,800. Reconciled: + // 2,500 for equipment (not a registered asset: operating, + // BS-statement-3 rule 12'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. @@ -974,7 +974,7 @@ fn cash_flow_with_registered_asset_and_disposal() { // payroll, and closes to accounts it finds by code. When an account with // that code exists but is the wrong kind, it refuses, says why, and changes // nothing, rather than posting to it or forcing the chart into its -// numbering. SOURCE: rules.md B-4 (the elements), DECISION. +// numbering. SOURCE: BS-ledger-2 (the elements), DECISION. // --------------------------------------------------------------------------- fn books_with(code: &str, name: &str, t: AccountType, placeholder: bool) -> Ledger { @@ -1110,7 +1110,7 @@ fn a_close_refuses_a_3999_that_is_not_equity() { // --------------------------------------------------------------------------- /// A child account subdivides its parent, so it is the same kind of -/// account. SOURCE: rules.md B-4; DECISION (owner, 2026-10-13). +/// account. SOURCE: BS-ledger-2; DECISION (owner, 2026-10-13). #[test] fn a_child_account_has_its_parents_type() { let mut l = Ledger::new(Currency::USD); @@ -1168,7 +1168,7 @@ fn periods_nest_but_never_partially_overlap() { } /// A line names a real, postable account when it is added, not only when -/// the entry posts. DECISION (owner, 2026-10-13); rules.md B-1. +/// the entry posts. DECISION (owner, 2026-10-13); BS-entry-1. #[test] fn a_line_on_an_unknown_or_placeholder_account_is_refused_when_added() { let c = fixture_company(); @@ -1202,7 +1202,7 @@ fn a_line_on_an_unknown_or_placeholder_account_is_refused_when_added() { ); } -/// Spec (rules.md B-3; DECISION, owner 2026-10-13, after the GnuCash +/// Spec (BS-ledger-1; DECISION, owner 2026-10-13, after the GnuCash /// cross-check): a foreign line is booked in the base currency's smallest /// unit, half away from zero; the foreign original is kept. #[test] @@ -1392,7 +1392,7 @@ fn reconciling_a_card_reads_its_normal_side_and_includes_the_statement_date() { assert_eq!(outstanding, vec![date(21), date(25)]); } -/// B-11: closing to retained earnings with nothing to close but a swept +/// BS-period-1: closing to retained earnings with nothing to close but a swept /// account's balance still sweeps it. #[test] fn a_close_sweeps_dividends_even_without_income() { @@ -1473,7 +1473,7 @@ fn a_last_absorbs_close_gives_the_rounding_to_the_last_member() { assert_eq!(got, vec![cents(32), cents(32), cents(41)]); } -/// B-12: a period whose closing date already lies in a closed period +/// BS-period-2: a period whose closing date already lies in a closed period /// can't close; the refusal names that period. #[test] fn a_period_ending_inside_a_closed_period_cannot_close() { @@ -1499,7 +1499,7 @@ fn a_period_ending_inside_a_closed_period_cannot_close() { /// Replay (for journaling stores) rebuilds invoice and bill records /// exactly: ids follow the allocator, each record tags its entry's control -/// line and each payment its entry's (rules.md B-38), vendors tag the +/// line and each payment its entry's (BS-arap-2), vendors tag the /// entries. A record replayed out of order is refused. #[test] fn replayed_documents_and_payments_rebuild_the_records() { @@ -1611,10 +1611,10 @@ fn replayed_documents_and_payments_rebuild_the_records() { } // --------------------------------------------------------------------------- -// Drafts: a state, and a way out (plan P4, rules.md B-43). +// Drafts: a state, and a way out (plan P4, BS-entry-5). // --------------------------------------------------------------------------- -/// Spec (rules.md B-43; Lean `Step.discard` and `hdrafts`): a period with +/// Spec (BS-entry-5; Lean `Step.discard` and `hdrafts`): a period with /// an open draft can't close; once the draft is discarded it can, and /// nothing posted moved: balances, order and ids are as they were. #[test] diff --git a/crates/ledger-core/tests/kernel_bridge/main.rs b/crates/ledger-core/tests/kernel_bridge/main.rs index 203c814a..f8a4ea80 100644 --- a/crates/ledger-core/tests/kernel_bridge/main.rs +++ b/crates/ledger-core/tests/kernel_bridge/main.rs @@ -133,7 +133,7 @@ proptest! { prop_assert_eq!(ri, kernel::reversal(&to_dec(&lines))); } - /// The 1099 kernel (rules.md B-19): a payment split into its buckets, + /// The 1099 kernel (BS-1099-1): a payment split into its buckets, /// and netted, the same at both types. #[test] fn payment_buckets_agree(lines in arb_lines()) { @@ -277,7 +277,7 @@ proptest! { } } - /// rules.md B-14 rule 3: the statement of cash flows' per-entry split + /// BS-statement-3 rule 3: 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] @@ -324,7 +324,7 @@ proptest! { ); } - /// rules.md B-14 rule 11: `kernel::constructive` (what a member or + /// BS-statement-3 rule 11: `kernel::constructive` (what a member or /// lender paid or received for the company; Kani /// `constructive_nets_to_zero`, `constructive_mirrors`) agrees at both /// instantiations. @@ -347,7 +347,7 @@ proptest! { prop_assert_eq!(ti.into_iter().map(dec).collect::>(), td); } - /// rules.md B-35: a party's target, and a reversal's, are the same on + /// BS-partner-3: a party's target, and a reversal's, are the same on /// i64 cents and on Decimal. #[test] fn party_target_agrees( @@ -565,7 +565,7 @@ proptest! { prop_assert_eq!(narrow.map(|n| Decimal::new(n, 4)), wide); } - /// The tax summary's one rounding (rules.md B-32, B-21): + /// The tax summary's one rounding (BS-ledger-11, BS-entry-3): /// `kernel::deductible_amount` at i64 cents (what Kani /// `deductible_amount_rounds_once` proved) and at Decimal dollars /// agree on the same accounts, and the Decimal result keeps the laws: diff --git a/crates/ledger-core/tests/kernel_bridge/round.rs b/crates/ledger-core/tests/kernel_bridge/round.rs index d0f2eb03..4967fe52 100644 --- a/crates/ledger-core/tests/kernel_bridge/round.rs +++ b/crates/ledger-core/tests/kernel_bridge/round.rs @@ -361,7 +361,7 @@ fn round_places_keeps_the_old_scale() { } /// `round_minor` picks the currency's own unit; a currency with none is -/// returned exactly (the FX rule, B-3). +/// returned exactly (the FX rule, BS-ledger-1). #[test] fn round_minor_follows_the_currency() { use ledger_core::Currency; diff --git a/crates/ledger-core/tests/model.rs b/crates/ledger-core/tests/model.rs index 6e4592ca..ad467199 100644 --- a/crates/ledger-core/tests/model.rs +++ b/crates/ledger-core/tests/model.rs @@ -55,7 +55,7 @@ struct MPeriod { struct Model { /// (id, code, type, placeholder, name). The name is outside the Lean /// model (its chart is code and type): kept here so the two agree on - /// renames' refusals, and a rename moves nothing else (rules.md B-31). + /// renames' refusals, and a rename moves nothing else (BS-ledger-10). accounts: Vec<(u64, String, AccountType, bool, String)>, drafts: Vec, posted: Vec, @@ -122,7 +122,7 @@ impl Model { self.next_account += 1; } - /// rules.md B-31: a name is free for `account` (None: a new one) when + /// BS-ledger-10: a name is free for `account` (None: a new one) when /// it isn't blank, holds no nine digits in a row, and no other account /// (all are top-level here, so all are siblings) has it, ignoring /// capitals and surrounding space. @@ -140,7 +140,7 @@ impl Model { .any(|a| Some(a.0) != account && a.4.trim().to_lowercase() == key) } - /// rules.md B-31: rename an account that exists to a free name other + /// BS-ledger-10: rename an account that exists to a free name other /// than its own; only the name changes. fn rename(&mut self, id: u64, name: &str) -> bool { let Some(i) = self.accounts.iter().position(|a| a.0 == id) else { @@ -363,7 +363,7 @@ impl Model { // --------------------------------------------------------------------------- // No 1200 or 2000: a line by hand on a receivables or payables account is -// refused (the control guard, rules.md B-38), which this model leaves to +// refused (the control guard, BS-arap-2), which this model leaves to // spec_arap.rs. const CODES: [&str; 7] = ["1000", "2100", "3000", "3999", "4000", "6000", "1900"]; /// New names: a free one, its own in other capitals and spacing, a @@ -400,7 +400,7 @@ enum Cmd { Reverse(usize, u32), CreatePeriod(u32, u32), Close(usize), - /// Rename an account (rules.md B-31): `Step.record` in the Lean model, + /// Rename an account (BS-ledger-10): `Step.record` in the Lean model, /// whose chart has no names. Rename(usize, usize), } diff --git a/crates/ledger-core/tests/odd_cent.rs b/crates/ledger-core/tests/odd_cent.rs index 768fcb3c..8f579bef 100644 --- a/crates/ledger-core/tests/odd_cent.rs +++ b/crates/ledger-core/tests/odd_cent.rs @@ -1,4 +1,4 @@ -//! The odd cent (P3 defect 17; rules.md B-13; D-10, D-38): members closes +//! The odd cent (P3 defect 17; BS-partner-1; D-10, D-38): members closes //! split earnings cumulatively, each member's share of everything closed //! to these members and shares so far less what earlier closes gave them, //! and the statement of members' equity, the K-1 worksheet and the viewer @@ -358,7 +358,7 @@ fn a_true_up_rides_on_a_distribution_sweep() { } // --------------------------------------------------------------------------- -// Where a count starts: a set of members and shares (B-13; §706(d)) +// Where a count starts: a set of members and shares (BS-partner-1; §706(d)) // --------------------------------------------------------------------------- /// A reorder of the members is not a change: [A, B] closes January's cent @@ -509,7 +509,7 @@ fn a_journaled_start_other_than_the_derived_one_is_refused() { } // --------------------------------------------------------------------------- -// The minor unit (B-3): whole yen, thousandths of a dinar +// The minor unit (BS-ledger-1): whole yen, thousandths of a dinar // --------------------------------------------------------------------------- /// P3 brief item 6: a yen book closes to its members in whole yen. 101 @@ -577,7 +577,7 @@ fn a_dinar_book_closes_to_members_in_thousandths() { /// A currency ISO 4217 gives no minor unit (gold, XAU) splits to the finest /// amount a line may carry (kernel::MAX_LINE_SCALE places), so every amount /// is a whole number of the unit it splits to and no member is ever one -/// from exact (B-13's precondition). 0.019 at 33.33% / 33.33% / 33.34% is +/// from exact (BS-partner-1's precondition). 0.019 at 33.33% / 33.33% / 33.34% is /// exactly 0.0063327 / 0.0063327 / 0.0063346: each member takes theirs. /// Split to cents instead, the floors (0.00 each) left 0.019, a cent and /// 0.009 of one, all of it to the largest remainder: C 0.019, A and B @@ -835,7 +835,7 @@ fn nth_month(i: usize) -> (i32, u32) { proptest! { #![proptest_config(ProptestConfig::with_cases(512))] - /// Oracle: rules.md B-13 and close INVARIANT 6, hand-stated: after + /// Oracle: BS-partner-1 and close INVARIANT 6, hand-stated: after /// any history (closes under the legacy rules, then months closed to /// the members in either order, to retained earnings, or left open), /// every members close hands out exactly its net; once a cumulative diff --git a/crates/ledger-core/tests/properties.rs b/crates/ledger-core/tests/properties.rs index 72571708..900b4fab 100644 --- a/crates/ledger-core/tests/properties.rs +++ b/crates/ledger-core/tests/properties.rs @@ -389,7 +389,7 @@ proptest! { /// A fiscal year start as the books may hold one: any month and day 2001 /// has (a new setting is the first of a month; replay takes any day every -/// year has, rules.md B-28). +/// year has, BS-entry-4). fn arb_fiscal_start() -> impl Strategy { (1u32..=12, 1u32..=31).prop_filter("a day 2001 has", |&(m, d)| { NaiveDate::from_ymd_opt(2001, m, d).is_some() @@ -411,7 +411,7 @@ fn arb_calendar_day() -> impl Strategy { proptest! { #![proptest_config(ProptestConfig::with_cases(5000))] - /// rules.md B-30, PeriodDefaults INVARIANTS 1-5, for every fiscal + /// BS-period-3, PeriodDefaults INVARIANTS 1-5, for every fiscal /// year start the books hold, every today in the calendar, and every /// mix of given and omitted dates: the resolved dates are the given /// ones or the defaults, never swapped; Err exactly when the resolved @@ -596,7 +596,7 @@ mod p3 { proptest! { #![proptest_config(ProptestConfig::with_cases(500))] - /// depreciation_schedule INVARIANT 5 (rules.md B-15; defect 22): accumulated depreciation never falls, + /// depreciation_schedule INVARIANT 5 (BS-asset-1; defect 22): accumulated depreciation never falls, /// never exceeds cost − salvage, is 0 before the in-service date and /// cost − salvage from the life's last day on; each schedule's lines /// sum to its accumulated and none is negative. Sampled through: every @@ -680,7 +680,7 @@ proptest! { prop_assert_eq!(scheduled_book_value(a, on).unwrap(), want.book_value); } - /// B-15 rule 3 (defect 22), against arithmetic written here: through + /// BS-asset-1 rule 3 (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! { } } - /// B-15 rule 4 (depreciation_schedule INVARIANT 6; P3 depreciation brief 2.3, R1, R8): through every + /// BS-asset-1 rule 4 (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 @@ -895,8 +895,8 @@ fn arb_basis_rule() -> impl Strategy { proptest! { #![proptest_config(ProptestConfig::with_cases(5000))] - /// kernel::basis_figures INVARIANTS 1-4 on Decimal money (rules.md - /// B-25): a purchase depreciates from cost and has no §723 basis or + /// kernel::basis_figures INVARIANTS 1-4 on Decimal money ( + /// BS-asset-4): a purchase depreciates from cost and has no §723 basis or /// built-in gain; a contribution's §723 basis is the adjusted basis, /// its built-in gain fair market value less that basis, negative /// exactly when the basis exceeds the value; carryover depreciates @@ -937,7 +937,7 @@ proptest! { proptest! { #![proptest_config(ProptestConfig::with_cases(256))] - /// rules.md B-37 item 3: for any tags and any period, the projects' + /// BS-statement-5 item 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. @@ -1002,7 +1002,7 @@ proptest! { prop_assert_eq!(exp_sum + untagged_exp, all.total_expenses); } - /// rules.md B-37 item 7: the snapshot's contribution is + /// BS-statement-5 item 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! { } } - /// rules.md B-37 item 3: project_entries codes its own signs, so the + /// BS-statement-5 item 3: 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. @@ -1145,7 +1145,7 @@ proptest! { proptest! { #![proptest_config(ProptestConfig::with_cases(2000))] - /// rules.md B-26 (P7): a TIN is found and masked however its groups + /// BS-partner-2 (P7): a TIN is found and masked however its groups /// are separated — a hyphen, a dot, a comma, a parenthesis, a slash, /// an underscore, or any run of spaces — and what merely looks like /// one is not: an amount's thousands separators (1,234,567.89 is @@ -1154,7 +1154,7 @@ proptest! { /// setting's kind (company.duns), never a party field. The ACH payment /// methods' lines get the same exemption in P4b S4's Kind; until then /// the filing scan's narrow shapes keep a bank export's routing - /// numbers out of the rule (rules.md B-26). + /// numbers out of the rule (BS-partner-2). #[test] fn tin_shapes_with_any_separator_are_found( sep in prop::sample::select(vec![ diff --git a/crates/ledger-core/tests/schedules.rs b/crates/ledger-core/tests/schedules.rs index b4cb0855..ab9a7af0 100644 --- a/crates/ledger-core/tests/schedules.rs +++ b/crates/ledger-core/tests/schedules.rs @@ -239,7 +239,7 @@ fn recurring_entries_generate_drafts_never_posts() { let _ = b.revenue; } -/// Regression (B-12, found by the store's refusal property on +/// Regression (BS-period-2, found by the store's refusal property on /// 2026-10-13): a recurring occurrence dated in a closed period is /// refused, leaves nothing behind, and is reported as needing a human. #[test] @@ -825,7 +825,7 @@ fn plan_values(plan: Vec<(NaiveDate, Decimal)>) -> Vec { /// A year of prepaid insurance at 100.00 a month (three months posted, /// 900.00 left) and three months of deferred revenue at 333.33, 333.33, /// 333.34 (the last period takes the rounding, so the three sum to -/// 1,000.00 exactly: rules.md B-16). +/// 1,000.00 exactly: BS-prepaid-1). #[test] fn golden_amortization_plans() { let mut b = books(); diff --git a/crates/ledger-core/tests/settings_units.rs b/crates/ledger-core/tests/settings_units.rs index 52a5245c..8508cbf8 100644 --- a/crates/ledger-core/tests/settings_units.rs +++ b/crates/ledger-core/tests/settings_units.rs @@ -458,7 +458,7 @@ fn counts_are_positive_whole_numbers() { } /// `Kind::Terms`: canonicalized through [`ledger_core::Terms`], so two -/// spellings of one agreement are one value (rules.md B-39). +/// spellings of one agreement are one value (BS-arap-3). #[test] fn terms_keep_one_canonical_spelling() { let terms = |s: &str| checked("invoicing.default_terms", json!(s)); @@ -575,7 +575,7 @@ fn contact_details_are_in_the_company_profile() { /// Replay checks the new kinds by shape, never by a later version's /// bounds: a count is a positive whole number, terms any string, and a -/// method list of objects with their fields (rules.md B-28). +/// method list of objects with their fields (BS-entry-4). #[test] fn replay_shapes_the_new_kinds() { let count = key("invoicing.unsent_days").unwrap(); diff --git a/crates/ledger-core/tests/spec_arap.rs b/crates/ledger-core/tests/spec_arap.rs index c38fdde5..df76984e 100644 --- a/crates/ledger-core/tests/spec_arap.rs +++ b/crates/ledger-core/tests/spec_arap.rs @@ -4,7 +4,7 @@ //! Oracles are the spec blocks in the `ledger-core` interface (doc comments //! on `Ledger::create_invoice`, `create_bill`, `receive_payment`, `pay_bill`, //! `arap::aging_bucket`, the `ControlAccount` / `ControlAccountMismatch` -//! docs) and `docs/spec/rules.md` B-18. Expected values are computed by hand +//! docs) and BS-arap-1. Expected values are computed by hand //! from those, never from the code under test. use std::str::FromStr; @@ -124,7 +124,7 @@ fn fingerprint(l: &Ledger) -> String { out } -/// Expected bucket index from rules.md B-18, written independently: +/// Expected bucket index from BS-arap-1, written independently: /// 0 Current (on or before due), 1: 1-30, 2: 31-60, 3: 61-90, 4: 90+. fn expected_bucket(due: NaiveDate, as_of: NaiveDate) -> usize { let days = (as_of - due).num_days(); @@ -288,7 +288,7 @@ fn derive_status_examples() { // ------------------------------------------------------------ aging_bucket -/// Oracle: aging_bucket SCENARIO 1 and B-18 DECISION: due today is Current. +/// Oracle: aging_bucket SCENARIO 1 and BS-arap-1 DECISION: due today is Current. #[test] fn aging_due_today_is_current() { let r = aging_bucket(d(2026, 10, 13), d(2026, 10, 13), dec("42.00")); @@ -307,7 +307,7 @@ fn aging_not_yet_due_is_current() { } /// Oracle: aging_bucket SCENARIOS 2-5 at each edge (1, 30, 31, 60, 61, 90, -/// 91 days past due), B-18. +/// 91 days past due), BS-arap-1. #[test] fn aging_boundaries_by_days_past_due() { let due = d(2026, 1, 1); @@ -795,7 +795,7 @@ fn receive_payment_partial_then_full() { } /// Oracle: receive_payment SCENARIO 1 (amount not positive) — refusal leaves -/// the books unchanged (B-8 general refusal rule, as for post_entry). +/// the books unchanged (BS-ledger-4 general refusal rule, as for post_entry). #[test] fn receive_payment_refuses_non_positive_amount() { let (mut l, cash) = books(); @@ -984,7 +984,7 @@ fn pay_bill_refuses_bad_amounts_books_unchanged() { // ------------------------------------------------------------------ aging /// Oracle: ar_aging doc (one row per customer with an outstanding balance, -/// bucketed by days past due) and B-18 buckets; fully paid customers get no +/// bucketed by days past due) and BS-arap-1 buckets; fully paid customers get no /// row. /// /// ASSUMED: rows carry the customer's name and their order is unspecified @@ -1040,7 +1040,7 @@ fn ar_aging_example() { } /// Oracle: ap_aging doc (one row per vendor with an outstanding balance) and -/// B-18 (1-30 and 61-90 buckets). +/// BS-arap-1 (1-30 and 61-90 buckets). #[test] fn ap_aging_example() { let (mut l, cash) = books(); @@ -1124,7 +1124,7 @@ proptest! { /// unchanged); DocumentStatus docs (status law); Invoice::balance doc; /// conservation (1200 balance = sum of open invoice balances, 4000 = /// sum of invoice totals, cash = sum received, since every movement on - /// them comes through invoices and payments); ar_aging doc + B-18 + /// them comes through invoices and payments); ar_aging doc + BS-arap-1 /// (each open balance in exactly one bucket; buckets sum to open /// balances; due today is Current). #[test] @@ -1215,7 +1215,7 @@ proptest! { /// Oracles: pay_bill INVARIANTS 1-2 and SCENARIO 1; DocumentStatus docs; /// Bill::balance doc; conservation (2000 = sum of open bill balances, /// 6999 = sum of bill totals, cash = -sum paid); every payment entry - /// tagged with its vendor; ap_aging doc + B-18. + /// tagged with its vendor; ap_aging doc + BS-arap-1. #[test] fn prop_bills_and_payments_conserve( docs in proptest::collection::vec(doc_strategy(), 1..6), diff --git a/crates/ledger-core/tests/spec_asset_basis.rs b/crates/ledger-core/tests/spec_asset_basis.rs index 30a923d3..8b0a74f1 100644 --- a/crates/ledger-core/tests/spec_asset_basis.rs +++ b/crates/ledger-core/tests/spec_asset_basis.rs @@ -1,6 +1,6 @@ //! Spec-derived tests for an asset's basis facts and tax figures -//! (rules.md B-25), its two dates and its two accumulated figures -//! (rules.md B-15, B-24): `BasisRule`, `Sec704cMethod`, `AssetBasis` +//! (BS-asset-4), its two dates and its two accumulated figures +//! (BS-asset-1, BS-asset-3): `BasisRule`, `Sec704cMethod`, `AssetBasis` //! (`check`, `check_journaled`, `check_legacy_journaled`), //! `Ledger::set_asset_basis` / `replay_set_asset_basis` / //! `replay_set_asset_tax_basis`, `Asset::basis_figures`, @@ -942,7 +942,7 @@ fn posted_follows_the_entries_dates() { assert_eq!(l.live_depreciation_run(id, "2026-01"), None); } -/// A reversal of the reversal reinstates the run (B-9), and the run counts +/// A reversal of the reversal reinstates the run (BS-ledger-5), and the run counts /// again: the month is not due twice (review R2). #[test] fn a_reinstated_run_counts_and_is_live() { @@ -963,7 +963,7 @@ fn a_reinstated_run_counts_and_is_live() { /// −100.00, as the trial balance does (review R2). No command can write one /// any more (D-73: a reversal is dated on or after its original, so /// `reverse_entry` refuses it), but a journal an earlier version wrote holds -/// them and replays as it was (B-28): this test replays one. +/// them and replays as it was (BS-entry-4): this test replays one. #[test] fn a_reversal_dated_before_its_run_matches_the_trial_balance() { let (mut l, a, id, e) = one_run(); diff --git a/crates/ledger-core/tests/spec_asset_tags.rs b/crates/ledger-core/tests/spec_asset_tags.rs index 2e4e3816..8f4e3307 100644 --- a/crates/ledger-core/tests/spec_asset_tags.rs +++ b/crates/ledger-core/tests/spec_asset_tags.rs @@ -1,4 +1,4 @@ -//! Spec-derived tests for asset tags and serial numbers (rules.md B-24) and +//! Spec-derived tests for asset tags and serial numbers (BS-asset-3) and //! the fixed asset register (`reports::fixed_asset_register`). //! //! Every expected value comes from the written specification: the doc @@ -6,7 +6,7 @@ //! `assets::check_asset_tag`, `assets::check_serial`, `assets::tag_key`, //! `Ledger::set_asset_tag`, `check_asset_tag_for`, `set_asset_serial`, //! `asset_by_tag`, `next_asset_tag`, `fixed_asset_register` and -//! `AssetRegister`, and `docs/spec/rules.md` B-15 and B-24. Depreciation +//! `AssetRegister`, and BS-asset-1 and BS-asset-3. Depreciation //! amounts are worked by hand (straight line, whole months) or, for //! mid-month dates, taken from the already-tested building block //! `accumulated_scheduled_through`. Nothing is read back from the code under @@ -160,7 +160,7 @@ fn check_asset_tag_accepts_the_documented_forms() { assert!(check_asset_tag(&longest).is_ok()); } -/// B-24 says 1–32 characters: the constant agrees with the rule. +/// BS-asset-3 says 1–32 characters: the constant agrees with the rule. #[test] fn max_asset_tag_len_is_32_per_b24() { assert_eq!(MAX_ASSET_TAG_LEN, 32); @@ -608,7 +608,7 @@ fn serial_ok(s: &str) -> bool { proptest! { #![proptest_config(ProptestConfig::with_cases(256))] - /// B-24 / set_asset_tag INVARIANTS 1-3 and set_asset_serial SCENARIO 1 + /// BS-asset-3 / set_asset_tag INVARIANTS 1-3 and set_asset_serial SCENARIO 1 /// over random command sequences, against a model built from the spec. #[test] fn prop_tag_commands_keep_the_invariants(cmds in proptest::collection::vec(arb_cmd(), 1..40)) { @@ -1088,7 +1088,7 @@ 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, rules.md B-15 rule +/// 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. #[test] fn register_as_of_a_day_before_a_same_month_disposal_is_prorated() { diff --git a/crates/ledger-core/tests/spec_assets_payroll.rs b/crates/ledger-core/tests/spec_assets_payroll.rs index fae46148..d8e304ec 100644 --- a/crates/ledger-core/tests/spec_assets_payroll.rs +++ b/crates/ledger-core/tests/spec_assets_payroll.rs @@ -1,8 +1,8 @@ //! Spec-derived tests for fixed assets (depreciation, disposal) and payroll. //! //! Every expected value here is a literal worked by hand from the written -//! specification (the interface doc comments, `docs/spec/rules.md` B-15 and -//! B-22, and IRS Pub. 15 in `docs/spec/sources/irs-payroll.md`), or a law the +//! specification (the interface doc comments, BS-asset-1 and +//! BS-asset-2, and IRS Pub. 15 in `docs/spec/sources/irs-payroll.md`), or a law the //! specification states. Nothing is read back from the code under test and //! then asserted. @@ -274,7 +274,7 @@ const PLAN_CASH: AccountId = 100; // ------------------------------------------------- depreciation schedule -/// Oracle: B-15 straight line, (cost − salvage) / life = 12000 / 12 = 1000.00 +/// Oracle: BS-asset-1 straight line, (cost − salvage) / life = 12000 / 12 = 1000.00 /// per full month; a purchase on the 1st makes every month full. #[test] fn full_months_each_take_one_twelfth_b15() { @@ -316,7 +316,7 @@ fn schedule_clamps_to_end_of_life() { assert_eq!(s.last().unwrap().book_value, d("0.00")); } -/// Oracle: B-15 partial months prorated by days; monthly 620/2 = 310.00. +/// Oracle: BS-asset-1 partial months prorated by days; monthly 620/2 = 310.00. /// Bought 2026-01-15: Jan holds 15..31 = 17/31 → 170.00; Feb full 310.00; /// life ends 2026-03-15 so Mar holds 1..14 = 14/31 → 140.00. 17/31 + 14/31 /// = one full month, and the total is exactly 620.00. @@ -368,7 +368,7 @@ fn last_month_trues_up_unequal_month_lengths_b15() { ); } -/// Oracle: B-15 "salvage never depreciated": cost 5000, salvage 1000, life 4 +/// Oracle: BS-asset-1 "salvage never depreciated": cost 5000, salvage 1000, life 4 /// → 1000.00/month, book value stops at 1000.00 forever. #[test] fn salvage_value_is_never_depreciated_b15() { @@ -387,7 +387,7 @@ fn salvage_value_is_never_depreciated_b15() { ); } -/// Oracle: B-21/interface "exact cents … never a penny off": 1000.00 over 3 +/// Oracle: BS-entry-3/interface "exact cents … never a penny off": 1000.00 over 3 /// months cannot split evenly; months are 333.33 or 333.34 and sum to /// exactly 1000.00. #[test] @@ -567,7 +567,7 @@ fn defect22_a_disposed_assets_schedule_stops_at_its_disposal_day() { /// cumulative 100,000 × m / 12, rounded half up to the yen (8,333.33 → /// 8,333; 16,666.67 → 16,667; 25,000; ...), so months alternate 8,333 and /// 8,334 and sum to 100,000. Every one is whole yen, so it can post (an -/// entry refuses a fraction of the minor unit, B-3). +/// entry refuses a fraction of the minor unit, BS-ledger-1). #[test] fn jpy_depreciation_posts_whole_yen() { let mut a = asset("100000", "0", 12, date(2026, 1, 1)); @@ -667,7 +667,7 @@ fn disposal_loss_is_negative() { assert_eq!(scrap.gain_loss, d("-6000.00")); } -/// Oracle: B-15 + gain law: after full life, book value = salvage 1000.00, +/// Oracle: BS-asset-1 + gain law: after full life, book value = salvage 1000.00, /// selling for 1000.00 is neither gain nor loss. #[test] fn disposal_after_full_life_at_salvage_is_break_even() { @@ -742,7 +742,7 @@ fn assert_asset_refused(new: NewAsset, l: &mut Ledger, check: impl Fn(&LedgerErr } /// Oracle: register_asset SCENARIO 1 "description is blank: SHOULD refuse"; -/// refusal leaves the books unchanged (B-8 / post_entry INVARIANT 3 spirit). +/// refusal leaves the books unchanged (BS-ledger-4 / post_entry INVARIANT 3 spirit). #[test] fn register_asset_refuses_empty_description() { let (mut l, a) = fixture(); @@ -1226,7 +1226,7 @@ fn run_payroll_refuses_zero_gross() { } /// Oracle: validate_payroll/run_payroll take a cash account; an unknown one -/// cannot be credited (B-1 / R-1 "no unknown accounts"). +/// cannot be credited (BS-entry-1 / R-1 "no unknown accounts"). /// /// ASSUMED: the refusal comes before posting; variant unspecified. #[test] @@ -1251,7 +1251,7 @@ fn run_payroll_refuses_wrong_type_control_account() { ); } -/// Oracle: B-12 "a closed period takes no new postings"; remit doc "rejects +/// Oracle: BS-period-2 "a closed period takes no new postings"; remit doc "rejects /// dates in closed periods". #[test] fn payroll_and_remit_refuse_closed_period() { @@ -1312,7 +1312,7 @@ fn period_end(p: &str) -> NaiveDate { proptest! { #![proptest_config(ProptestConfig::with_cases(256))] - /// Oracle: B-15 laws — a full schedule sums to exactly cost − salvage; + /// Oracle: BS-asset-1 laws — a full schedule sums to exactly cost − salvage; /// amounts are non-negative whole cents; accumulated is the running sum /// and non-decreasing; book value = cost − accumulated, never rises, never /// below salvage, ends at salvage; months are consecutive from the @@ -1367,7 +1367,7 @@ proptest! { prop_assert_eq!(scheduled_book_value(&a, before).unwrap(), a.cost.amount); } - /// Oracle: B-15 partial months by days + interface "the last month absorbs + /// Oracle: BS-asset-1 partial months by days + interface "the last month absorbs /// the drift". When (cost − salvage) / life is a whole number of cents M /// and the purchase is after the 1st, the middle months are each exactly /// M and the partial first and last months together are exactly M. diff --git a/crates/ledger-core/tests/spec_bounds.rs b/crates/ledger-core/tests/spec_bounds.rs index f16a5a99..56b4574d 100644 --- a/crates/ledger-core/tests/spec_bounds.rs +++ b/crates/ledger-core/tests/spec_bounds.rs @@ -4,7 +4,7 @@ //! (ledger_core::calendar), and what can't be computed exactly is refused, //! never wrapped or panicked on (P0 review round 3, finding S1: a panic //! stops the books server). The bounds are the commands' only: replay -//! accepts every line an earlier version accepted (rules.md B-28, posted +//! accepts every line an earlier version accepted (BS-entry-4, posted //! is forever; P0 review round 4), so each bound here has its pair, a //! replay of an old line past it, accepted. //! @@ -617,7 +617,7 @@ fn replayed_bases_and_shares_past_the_limit_are_accepted() { ); } -/// A replayed payment is as journaled: no bound (rules.md B-28), and no +/// A replayed payment is as journaled: no bound (BS-entry-4), and no /// refusal: it tags the line of its entry that carries it, or (an entry /// it doesn't match) nothing. The command's bound is what the invoice /// owes (Overpayment). @@ -719,7 +719,7 @@ fn disposal_proceeds_and_dates_are_bounded() { // Replay keeps what every version checked: no disposal twice, no // negative proceeds. The date floor (the acquired date, P3) is a // command's: replay accepts a disposal before it, which every earlier - // version's commands refused anyway (rules.md B-28: replay accepts + // version's commands refused anyway (BS-entry-4: replay accepts // more, never less). assert_eq!( b.ledger @@ -744,12 +744,12 @@ fn disposal_proceeds_and_dates_are_bounded() { } /// D-75 (owner, 2026-11-08): a new line's foreign amount and its rate take -/// at most ten decimal places each, as a base amount does (B-28), so the +/// at most ten decimal places each, as a base amount does (BS-entry-4), so the /// product is exact (at most twenty places, under Decimal's 28) and the /// booked amount is rounded once. Found by the K-U1 review: a 26-place /// foreign amount times 0.005 books 0.01 though the exact product is under /// half a cent, because Decimal rounded the product to 28 places first. -/// Replay is exempt (B-28): an older line keeps its figures. +/// Replay is exempt (BS-entry-4): an older line keeps its figures. #[test] fn a_foreign_amount_and_a_rate_take_at_most_ten_places() { let dec = |s: &str| s.parse::().unwrap(); @@ -963,7 +963,7 @@ fn new_asset( } } -/// B-3 (P3): a new asset's cost and salvage are in the currency's minor +/// BS-ledger-1 (P3): a new asset's cost and salvage are in the currency's minor /// unit (every depreciation and disposal line derives from them, and a /// line finer than a cent never posts). Its replay pair: an asset an /// earlier version took in tenths of a cent opens, and its schedule is @@ -998,7 +998,7 @@ fn an_asset_cost_finer_than_a_cent_is_refused() { assert_eq!(s[11].accumulated, "1200.005".parse::().unwrap()); } -/// B-28 (P3: lives past 9999, plan/served.md defect 22): a new asset's +/// BS-entry-4 (P3: lives past 9999, plan/served.md defect 22): a new asset's /// last day of depreciation is at most 9999-12-31, the calendar's last /// day, so every month of its life is one the books can post. A life /// ending on that day is taken (P0 bounded the life's exclusive end, one @@ -1040,7 +1040,7 @@ fn a_life_ending_after_it_is_refused() { } } -/// B-28 (P3): a daily schedule's last day is in the calendar: one month +/// BS-entry-4 (P3): a daily schedule's last day is in the calendar: one month /// from 9999-12-15 covers through 10000-01-14, refused; one month from /// 9999-12-01 ends on 9999-12-31, taken. Replay takes either. #[test] diff --git a/crates/ledger-core/tests/spec_cash_flow.rs b/crates/ledger-core/tests/spec_cash_flow.rs index 3874d9d3..f7b9f476 100644 --- a/crates/ledger-core/tests/spec_cash_flow.rs +++ b/crates/ledger-core/tests/spec_cash_flow.rs @@ -1,4 +1,4 @@ -//! The statement of cash flows (rules.md B-14), from the rule and its +//! The statement of cash flows (BS-statement-3), from the rule and its //! sources, never from the implementation. //! //! Every expected figure is worked by hand in the test's doc comment from @@ -53,7 +53,7 @@ impl Books { // As replay posts it: these books hold hand lines on receivables // or payables (1200, 2000), which books an earlier version wrote // still hold and every report must read; the control guard - // (rules.md B-38) refuses them as new work. + // (BS-arap-2) refuses them as new work. ledger_core::parties::replaying(|| { let e = self.l.create_entry(date, desc); for &(code, side, amount) in lines { @@ -168,7 +168,7 @@ fn s(t: &str) -> String { t.to_string() } -/// The laws every statement keeps (rules.md B-14 rules 8 and 9): each +/// The laws every statement keeps (BS-statement-3 rules 8 and 9): 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 -/// (rules.md B-14 rules 1, 6): every section 0.00, no lines, no +/// (BS-statement-3 rules 1, 6): 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). @@ -276,7 +276,7 @@ fn defect1_reversed_contributions_foot_regression() { /// | 22 | 03-20 | reverses #9 | | | /// | 23 | 03-30 | API credits on the card | 6300 42.75 | 2050 | /// -/// By hand, the year to 2026-03-31 (rules.md B-14; D-42 for what the +/// By hand, the year to 2026-03-31 (BS-statement-3; D-42 for what the /// members paid): /// - Operating: the members paid #1 85.00, #2 12.97, #3 99.00, #6 7.49, /// #21 216.40, #7 129.00 and #20 46.38 (the prepaid domain) for the @@ -876,7 +876,7 @@ fn a_property_contribution_is_a_noncash_disclosure() { assert_eq!(n.label, format!("Laptop contributed (#{e})")); } -/// D-42, rules.md B-14 rule 11 (ASC 230 is silent on a payment a third +/// D-42, BS-statement-3 rule 11 (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 (rules.md B-14 rule 11): a member pays a +/// The expense-to-capital case (BS-statement-3 rule 11): 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); } -/// rules.md B-14 rule 6 with rule 11: a payment a member made for the +/// BS-statement-3 rule 6 with rule 11: 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() { ); } -/// rules.md B-14 rule 6 (B-9: a correction undoes what it corrects): an +/// BS-statement-3 rule 6 (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); } -/// rules.md B-14 rule 6: a reversal shown alone (its original in an +/// BS-statement-3 rule 6: 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); } -/// rules.md B-14 rules 4 and 6: a reversal takes its chain root's +/// BS-statement-3 rules 4 and 6: 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 (rules.md B-14 rule 7). +/// activity, so nothing is disclosed (BS-statement-3 rule 7). #[test] fn depreciation_is_reconciling_not_disclosed() { let mut b = funded(); @@ -1862,7 +1862,7 @@ fn operating_reconciliation_ties_to_operating_cash() { ); } -/// rules.md B-11 and B-14 rule 10: a period close moves earnings into +/// BS-period-1 and BS-statement-3 rule 10: 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 (rules.md B-14 rule 1): a +/// The period is [start, end] inclusive (BS-statement-3 rule 1): a /// contribution on the start date is a flow, not opening cash. #[test] fn cash_flow_starts_counting_on_the_start_date() { @@ -1921,7 +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 (rules.md B-14 rules 1, 6, 9, +/// Review round 2, footing in odd shapes (BS-statement-3 rules 1, 6, 9, /// 11), 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, @@ -2035,7 +2035,7 @@ fn a_note_received_for_equipment_is_disclosed() { /// ASC 230-10-50-4: a trade-in. A new vehicle (2,000, on 1520) for the /// old equipment (cost 1,000 on 1500, accumulated 800, gain 300) and /// 1,500 cash: investing −1,500 and an exchange of 500 disclosed. Within -/// one cost account a trade-in nets away (a limit B-14 records). +/// one cost account a trade-in nets away (a limit BS-statement-3 records). #[test] fn a_trade_in_is_disclosed() { let mut b = funded(); @@ -2216,7 +2216,7 @@ fn financing_lists_each_members_contributions_and_distributions() { /// ASC 230-10-45-25 requires interest received (b) and interest paid (e) /// "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 (rules.md B-14 +/// whatever else it settles, the rest by its structure (BS-statement-3 /// rule 5). 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 @@ -2547,7 +2547,7 @@ fn a_reversed_bill_payment_leaves_the_purchase_unpaid() { } // --------------------------------------------------------------------------- -// Role refusals (rules.md B-14 rule 2) and the footing check (rule 9). +// Role refusals (BS-statement-3 rule 2) and the footing check (rule 9). // --------------------------------------------------------------------------- fn refused(b: &Books, cash: &[&str], financing: &[&str], investing: &[&str]) -> String { @@ -2617,7 +2617,7 @@ fn a_registered_asset_account_cannot_be_cash() { assert!(m.contains("a registered fixed asset's account"), "{m}"); } -/// rules.md B-14 rule 9: any difference between the sections and the +/// BS-statement-3 rule 9: any difference between the sections and the /// change in cash is an engine error, never a statement. #[test] fn foot_refuses_any_difference() { @@ -2638,7 +2638,7 @@ fn foot_refuses_any_difference() { } // --------------------------------------------------------------------------- -// Properties over random books (rules.md B-14; plan P3: 5,000 cases). +// Properties over random books (BS-statement-3; plan P3: 5,000 cases). // --------------------------------------------------------------------------- mod random { @@ -3011,7 +3011,7 @@ use random::*; proptest! { #![proptest_config(ProptestConfig::with_cases(cases()))] - /// rules.md B-14 over random books, reversals of reversals included: + /// BS-statement-3 over random books, reversals of reversals included: /// 1. the sections sum to the change in cash, which is the model's; /// 2. each section is its lines and its kinds, and 3. net income and /// the reconciling items are operating (`foots`); @@ -3244,7 +3244,7 @@ fn a_disposals_depreciation_credit_back_is_depreciation() { assert_eq!(cf.cash_from_investing, x("975.00")); } -/// rules.md B-14 rule 5 (the P3 cutover review's open point 2): ASC +/// BS-statement-3 rule 5 (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 +3316,7 @@ fn a_payment_to_a_government_is_other_operating() { assert_eq!((line.class, line.amount), (Some(OtherPayments), x("75.00"))); } -/// rules.md B-14 rule 5: the payee decides on any account, and the tax +/// BS-statement-3 rule 5: 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 +3371,7 @@ fn a_government_payee_moves_a_fee_on_any_account() { assert_eq!(classes(&cf, shared), [(OtherPayments, x("-100.00"))]); } -/// rules.md B-14 rule 5: a split by shares that leaves an odd cent rounds +/// BS-statement-3 rule 5: 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 +3450,7 @@ fn a_shared_government_payment_splits_to_the_cent() { ); } -/// rules.md B-14 rule 5: a reversal takes its original's payee, so the +/// BS-statement-3 rule 5: 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 +3500,7 @@ fn a_reversal_takes_its_originals_payee() { assert_eq!(classes(&b), both(ToSuppliersAndEmployees)); } -/// rules.md B-14 rules 5 and 11: a payment shared between a state and an +/// BS-statement-3 rules 5 and 11: 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 +3577,7 @@ fn a_shared_government_payment_a_member_paid_splits_both_ways() { assert_eq!(cf.net_change_in_cash, Decimal::ZERO); } -/// rules.md B-14 rule 5 (CONVENTION): payroll keeps its structure. Taxes +/// BS-statement-3 rule 5 (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 +3636,7 @@ fn a_payroll_remittance_to_a_tax_agency_stays_pay() { assert_eq!(class(employer), Some(OtherPayments)); } -/// rules.md B-14 rule 5: a government selling goods or services is a +/// BS-statement-3 rule 5: 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 @@ -3664,7 +3664,7 @@ fn a_government_selling_services_is_a_supplier() { } /// A bill whose line is equipment, paid later: the payment's cash is -/// investing, through the bill's split (D-35; rules.md B-14), not +/// investing, through the bill's split (D-35; BS-statement-3), not /// operating. Plan P4b S6 keeps this true when the bill is paid as part /// of a settlement. #[test] diff --git a/crates/ledger-core/tests/spec_document_projects.rs b/crates/ledger-core/tests/spec_document_projects.rs index 3a8402b5..0e2089b3 100644 --- a/crates/ledger-core/tests/spec_document_projects.rs +++ b/crates/ledger-core/tests/spec_document_projects.rs @@ -1,4 +1,4 @@ -//! An invoice's or bill's lines name their projects (rules.md B-37 item +//! 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, //! the untagged lines' as one; the receivable or payable line, and the //! payments, never take one. @@ -6,9 +6,9 @@ //! ```text //! GOAL: a client project's invoiced revenue and a contractor's billed //! cost count toward the project, every other figure as before. -//! SOURCE: docs/spec/rules.md B-37 items 3 and 8 (job costing), B-14 (the -//! projects with the untagged lines partition the P&L), B-19 and -//! B-35 (1099 and party figures follow the money, not the tags). +//! SOURCE: BS-statement-5 items 3 and 8 (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). //! ``` use chrono::NaiveDate; @@ -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 (B-37 item 3: each line on its normal side), so +/// project to the reversal (BS-statement-5 item 3: 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] @@ -209,7 +209,7 @@ fn reversing_a_tagged_document_takes_its_projects_to_zero() { .unwrap(); assert_eq!(to_date(&b.l, z), (cents(300_000), cents(120_000))); assert_eq!(to_date(&b.l, h), (cents(20_000), Decimal::ZERO)); - // The payment first: a void waits on the payments that stand (B-38 + // The payment first: a void waits on the payments that stand (BS-arap-2 // scenario 3); its reversal moves no project figure either. b.l.reverse_entry(pay, d(2026, 3, 30), "Bounced").unwrap(); assert_eq!(to_date(&b.l, z), (cents(300_000), cents(120_000))); @@ -294,7 +294,7 @@ fn a_line_naming_an_unknown_project_is_refused_whole() { assert!(b.l.differs_from(&before).is_empty(), "nothing changed"); } -/// Finished and abandoned projects still take a document's lines (B-37 +/// Finished and abandoned projects still take a document's lines (BS-statement-5 /// item 5: a late cost, a final invoice). #[test] fn a_finished_project_still_takes_an_invoice() { diff --git a/crates/ledger-core/tests/spec_documents.rs b/crates/ledger-core/tests/spec_documents.rs index 3bf1e1cd..2b638f36 100644 --- a/crates/ledger-core/tests/spec_documents.rs +++ b/crates/ledger-core/tests/spec_documents.rs @@ -1,12 +1,12 @@ //! Documents read their figures from the ledger lines tagged with them -//! (rules.md B-38; plan P4b S1, D-45): one test per scenario of the -//! B-38 spec block, then the properties. +//! (BS-arap-2; plan P4b S1, D-45): one test per scenario of the +//! BS-arap-2 spec block, then the properties. //! //! ```text //! GOAL: invoices and bills are the subledgers of the receivables and //! payables control accounts; every figure about a document is read //! from the ledger lines tagged with it. -//! SOURCE: docs/spec/rules.md B-8, B-9, B-10, B-18, B-23, B-28, B-38; +//! SOURCE: BS-ledger-4, BS-ledger-5, BS-ledger-6, BS-arap-1, BS-ledger-8, BS-entry-4, BS-arap-2; //! ASC 310-10, ASC 405-20-40-1, ASC 606-10-45-4. //! ``` @@ -109,7 +109,7 @@ impl Books { self.l.chart().find_by_code(code).unwrap().id } - /// Every control account's tie-out holds: no difference (B-38 + /// Every control account's tie-out holds: no difference (BS-arap-2 /// INVARIANT 1). fn ties(&self, on: NaiveDate) { for c in self.l.control_check(on).unwrap() { @@ -186,7 +186,7 @@ fn a_voided_invoice_never_ages() { Err(LedgerError::InvalidVoid(why)) => assert!(why.contains(&r.to_string()), "{why}"), other => panic!("expected InvalidVoid, got {other:?}"), } - // Reversing the void re-instates it (B-10); voiding again reverses + // Reversing the void re-instates it (BS-ledger-6); voiding again reverses // that reversal, the end of the chain. let back = b.l.reverse_entry(r, d(2026, 2, 7), "Re-instate").unwrap(); assert_eq!( @@ -500,7 +500,7 @@ fn deposit_account_must_be_cash_like() { } /// A reversal of an entry a document owns is never dated before it -/// (B-9; P4b.3, "Dating rules"). +/// (BS-ledger-5; P4b.3, "Dating rules"). #[test] fn reversal_before_original_refused_for_documents() { let mut b = books(); @@ -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 (B-38 INVARIANT 1 and item 3; first review of S1). +/// line (BS-arap-2 INVARIANT 1 and item 3; first review of S1). #[test] fn putting_back_a_removed_hand_line_is_refused() { let mut b = books(); @@ -1201,10 +1201,10 @@ fn a_chain_counts_in_order() { } // --------------------------------------------------------------------------- -// Write-offs (plan P4b S7; rules.md B-41) +// Write-offs (plan P4b S7; BS-arap-5) // --------------------------------------------------------------------------- -/// B-38 SCENARIO 7 and B-41 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())); } -/// B-41 INVARIANT 3: a cash-basis company never counted the invoice as +/// BS-arap-5 INVARIANT 3: 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() { ); } -/// B-41 INVARIANT 1: at most what is owed, a partial write-off allowed +/// BS-arap-5 INVARIANT 1: 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 B-41 INVARIANT 2: reversing the +/// D-49's same-year recovery, and BS-arap-5 INVARIANT 2: 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))] - /// B-38 INVARIANTS 1, 2 and 6 over random histories of creates, + /// BS-arap-2 INVARIANTS 1, 2 and 6 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,7 +1538,7 @@ proptest! { } } - /// B-38 INVARIANT 5: the aging as of a day partitions what the + /// BS-arap-2 INVARIANT 5: 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 /// ledger-store's `status_is_a_function_of_journal_and_date`. @@ -1562,7 +1562,7 @@ proptest! { } } - /// B-38 INVARIANT 3: reversing a tagged entry moves its documents by + /// BS-arap-2 INVARIANT 3: 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 @@ -1637,7 +1637,7 @@ fn doc_line( } } -/// B-39 SCENARIOS: Net 30, Net 15 EOM, a leap day, due on receipt, a +/// 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. #[test] fn terms_derive_due_dates() { @@ -1671,7 +1671,7 @@ fn terms_derive_due_dates() { assert!(Terms::new(TermsKind::NetEom(3_651), None).is_err()); } -/// B-39 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() { @@ -1741,7 +1741,7 @@ fn discount_bounds_and_late_reason() { assert_eq!(kernel::discount_max(cents(-1), 200), None); } -/// B-39 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 [ @@ -1899,7 +1899,7 @@ fn qty_times_price_must_equal_amount() { )); } -/// B-39 line accounts: an invoice takes revenue or deferred revenue; a +/// BS-arap-3 line accounts: an invoice takes revenue or deferred revenue; a /// bill takes an expense or a non-cash asset; roles, cash and headers are /// refused (plan P4b S4.1, A-10). #[test] @@ -1959,7 +1959,7 @@ fn document_line_account_refuses_roles_cash_and_placeholders() { assert_eq!(b.l.next_bill_id(), before); } -/// A-2, B-40: numbers run, a void keeps its number, legacy invoices are +/// A-2, BS-arap-4: numbers run, a void keeps its number, legacy invoices are /// not counted, and a number is never reused. #[test] fn numbers_run_and_voids_keep_theirs() { @@ -2033,7 +2033,7 @@ fn numbers_run_and_voids_keep_theirs() { ); } -/// B-40: four digits, wider past 9,999, never truncated. +/// BS-arap-4: four digits, wider past 9,999, never truncated. #[test] fn number_widens_past_9999() { let mut b = books(); @@ -2053,7 +2053,7 @@ fn number_widens_past_9999() { assert_eq!(b.l.next_invoice_number("INV-", 9_999), "INV-10000"); } -/// B-40: a vendor's invoice number names one standing bill; case, spaces +/// BS-arap-4: a vendor's invoice number names one standing bill; case, spaces /// and hyphens are ignored; a duplicate needs a reason (plan P4b S4.1). #[test] fn duplicate_vendor_ref_refused_unless_a_reason_is_given() { @@ -2124,13 +2124,13 @@ fn duplicate_vendor_ref_refused_unless_a_reason_is_given() { } // --------------------------------------------------------------------------- -// P4b S6: paying on terms (rules.md B-42) +// P4b S6: paying on terms (BS-arap-6) // --------------------------------------------------------------------------- /// A bill on "2/10 net 30", paid within the discount window: the gross /// method's entry is Dr A/P the full amount, Cr purchase discounts what /// was taken, Cr the bank the rest; the bill reads paid and discounted. -/// A discount larger than the terms allow needs a reason (B-42). +/// A discount larger than the terms allow needs a reason (BS-arap-6). #[test] fn bill_on_terms_with_discount() { use ledger_core::{Application, DocRef, SettleParams}; @@ -2231,7 +2231,7 @@ fn bill_on_terms_with_discount() { .unwrap(); } -/// A discount taken after the discount date needs a reason (B-42 +/// 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 /// D-49 remedy, and none of the refusals changes the books. #[test] @@ -2379,7 +2379,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 (B-42 INVARIANTS 1 and 2). +/// each document's bound is one bound (BS-arap-6 INVARIANTS 1 and 2). #[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_ledger.rs b/crates/ledger-core/tests/spec_ledger.rs index 24d46628..a0303a28 100644 --- a/crates/ledger-core/tests/spec_ledger.rs +++ b/crates/ledger-core/tests/spec_ledger.rs @@ -130,7 +130,7 @@ fn try_post( } /// [`try_post`] through the replay path, which books written before the -/// minor-unit rule (B-3, 2026-10-13) still take: for the kernel's own +/// minor-unit rule (BS-ledger-1, 2026-10-13) still take: for the kernel's own /// limits below a cent. fn try_replay_post( l: &mut Ledger, @@ -245,7 +245,7 @@ fn tb_has_code(l: &Ledger, as_of: NaiveDate, code: &str) -> bool { // add_account // --------------------------------------------------------------------------- -/// Oracle: R-4 / B-4: an added account is findable by its code with exactly +/// Oracle: R-4 / BS-ledger-2: an added account is findable by its code with exactly /// the type, parent, and placeholder flag it was given. #[test] fn an_added_account_is_registered_under_its_code() { @@ -339,7 +339,7 @@ fn a_refused_account_never_uses_up_an_id() { assert_eq!(id, announced); } -/// Oracle: add_account SCENARIO 3 (B-4 DECISION): a child of another type is +/// Oracle: add_account SCENARIO 3 (BS-ledger-2 DECISION): a child of another type is /// refused with ParentTypeMismatch and NEVER added. #[test] fn a_child_account_has_its_parents_type() { @@ -390,7 +390,7 @@ fn a_new_draft_gets_the_next_id_one_past_the_last() { assert!(e.lines().is_empty()); } -/// Oracle: try_create_entry SCENARIO 1 (B-12): a date inside a closed period, +/// Oracle: try_create_entry SCENARIO 1 (BS-period-2): a date inside a closed period, /// first and last day included, is refused with ClosedPeriod and creates /// nothing; the day after the period is accepted. #[test] @@ -444,7 +444,7 @@ fn lines_are_kept_in_the_order_added() { ); } -/// Oracle: B-1 DECISION (owner, 2026-10-13): a line on an unknown account +/// Oracle: BS-entry-1 DECISION (owner, 2026-10-13): a line on an unknown account /// is refused when added (UnknownAccount), not only at post. #[test] fn a_line_on_an_unknown_account_is_refused_when_added() { @@ -458,7 +458,7 @@ fn a_line_on_an_unknown_account_is_refused_when_added() { assert_eq!(observe(&b.l), before); } -/// Oracle: B-1 DECISION / R-4: a line on a placeholder account is refused +/// Oracle: BS-entry-1 DECISION / R-4: a line on a placeholder account is refused /// when added (PlaceholderAccount). #[test] fn a_line_on_a_placeholder_account_is_refused_when_added() { @@ -473,7 +473,7 @@ fn a_line_on_a_placeholder_account_is_refused_when_added() { assert_eq!(observe(&b.l), before); } -/// Oracle: B-3 / R-5 and the add_line doc: a foreign-currency amount is +/// Oracle: BS-ledger-1 / R-5 and the add_line doc: a foreign-currency amount is /// refused, never converted (CurrencyMismatch). #[test] fn a_foreign_currency_line_is_refused_not_converted() { @@ -493,7 +493,7 @@ fn a_foreign_currency_line_is_refused_not_converted() { assert_eq!(observe(&b.l), before); } -/// Oracle: R-3 / B-8 and the PostedEntryImmutable doc ("add lines"): a posted +/// Oracle: R-3 / BS-ledger-4 and the PostedEntryImmutable doc ("add lines"): a posted /// entry takes no more lines. #[test] fn a_posted_entry_takes_no_more_lines() { @@ -523,7 +523,7 @@ fn a_line_on_an_unknown_entry_is_refused() { assert_eq!(observe(&b.l), before); } -/// Oracle: B-3 (ASC 830-20-30-1) and the add_line_fx doc: base = foreign × +/// Oracle: BS-ledger-1 (ASC 830-20-30-1) and the add_line_fx doc: base = foreign × /// rate (100 EUR × 1.10 = 110.00 USD), the original kept; the entry then /// balances in base currency. #[test] @@ -569,7 +569,7 @@ fn a_non_positive_fx_rate_is_refused() { } } -/// Oracle: rules.md B-3 "Checked: fx_overflow_is_an_error" and B-21 (exact +/// Oracle: BS-ledger-1 "Checked: fx_overflow_is_an_error" and BS-entry-3 (exact /// amounts): a product that can't be represented is refused, never rounded /// or wrapped. #[test] @@ -584,7 +584,7 @@ fn fx_overflow_is_an_error() { assert_eq!(observe(&b.l), before); } -/// Oracle: B-1 DECISION applies to add_line_fx too: unknown account refused +/// Oracle: BS-entry-1 DECISION applies to add_line_fx too: unknown account refused /// when added. #[test] fn a_foreign_line_on_an_unknown_account_is_refused_when_added() { @@ -598,7 +598,7 @@ fn a_foreign_line_on_an_unknown_account_is_refused_when_added() { assert_eq!(observe(&b.l), before); } -/// Oracle: B-3 + line range (AmountOutOfRange: at most one quadrillion): +/// Oracle: BS-ledger-1 + line range (AmountOutOfRange: at most one quadrillion): /// a foreign line converting to 2,000,000,000,000,000 USD never posts. #[test] fn a_foreign_line_beyond_line_range_never_posts() { @@ -631,7 +631,7 @@ fn posting_an_unknown_entry_is_refused() { assert_eq!(observe(&b.l), before); } -/// Oracle: post_entry SCENARIO 2 (B-8): a posted entry is never posted +/// Oracle: post_entry SCENARIO 2 (BS-ledger-4): a posted entry is never posted /// twice (EntryAlreadyPosted), the log unchanged. #[test] fn a_posted_entry_is_never_posted_twice() { @@ -647,7 +647,7 @@ fn a_posted_entry_is_never_posted_twice() { assert_eq!(b.l.posted_entries().count(), 1); } -/// Oracle: post_entry SCENARIO 3 (B-12): an entry dated in a closed period +/// Oracle: post_entry SCENARIO 3 (BS-period-2): an entry dated in a closed period /// is refused (ClosedPeriod), even one drafted through the unchecked /// constructor. #[test] @@ -670,7 +670,7 @@ fn an_entry_dated_in_a_closed_period_never_posts() { assert_eq!(observe(&b.l), before); } -/// Oracle: R-1/B-1: fewer than two lines is refused (TooFewLines), for zero +/// Oracle: R-1/BS-entry-1: fewer than two lines is refused (TooFewLines), for zero /// lines and for one. #[test] fn an_entry_with_fewer_than_two_lines_never_posts() { @@ -690,7 +690,7 @@ fn an_entry_with_fewer_than_two_lines_never_posts() { assert_eq!(b.l.posted_entries().count(), 0); } -/// Oracle: R-1/B-1 (no epsilon): 100.00 against 99.99 is refused with the +/// Oracle: R-1/BS-entry-1 (no epsilon): 100.00 against 99.99 is refused with the /// offending totals. #[test] fn an_unbalanced_entry_is_refused_with_its_totals() { @@ -744,7 +744,7 @@ fn exact_decimal_sums_balance() { assert_eq!(r, None); } -/// Oracle: R-6 / B-2: a zero-amount line is refused (ZeroAmountLine). +/// Oracle: R-6 / BS-entry-2: a zero-amount line is refused (ZeroAmountLine). #[test] fn a_zero_amount_line_never_posts() { let mut b = books(); @@ -761,7 +761,7 @@ fn a_zero_amount_line_never_posts() { assert_eq!(b.l.posted_entries().count(), 0); } -/// Oracle: B-2: a negative amount is refused (NegativeAmountLine): the side +/// Oracle: BS-entry-2: a negative amount is refused (NegativeAmountLine): the side /// says the direction. #[test] fn a_negative_amount_line_never_posts() { @@ -799,7 +799,7 @@ fn line_range_is_one_quadrillion_and_ten_places() { ok(&mut b, "1000000000000000.01"), Some(LedgerError::AmountOutOfRange) ); - // Below a cent, new work is refused first (B-3); replayed books meet + // Below a cent, new work is refused first (BS-ledger-1); replayed books meet // the kernel's ten-place limit. assert!(matches!( ok(&mut b, "0.0000000001"), @@ -886,7 +886,7 @@ fn the_log_is_in_posting_order() { // check_reversal / reverse_entry // --------------------------------------------------------------------------- -/// Oracle: B-9 (Pacioli's storno): the reversal has the same lines with +/// Oracle: BS-ledger-5 (Pacioli's storno): the reversal has the same lines with /// sides flipped, is posted, dated as asked, linked by `reversal_of`, and /// returns every balance to what it was. #[test] @@ -917,12 +917,12 @@ fn a_reversal_mirrors_the_original_and_cancels_it() { for a in [b.exp, b.cash, b.card] { assert_eq!(b.l.account_balance(a).unwrap(), Decimal::ZERO); } - // The original is untouched (B-8): never erased. + // The original is untouched (BS-ledger-4): never erased. assert_eq!(b.l.get_entry(e).unwrap().status(), EntryStatus::Posted); assert_eq!(b.l.posted_entries().count(), 2); } -/// Oracle: B-10 / check_reversal SCENARIO 2: an entry is reversed at most +/// Oracle: BS-ledger-6 / check_reversal SCENARIO 2: an entry is reversed at most /// once (EntryAlreadyReversed(entry, by)); reversing the reversal is allowed /// and re-instates it, and does not reopen the original. #[test] @@ -986,7 +986,7 @@ fn only_posted_entries_are_reversed() { assert_eq!(observe(&b.l), before); } -/// Oracle: B-10 / check_reversal SCENARIO 3: a closing entry is never +/// Oracle: BS-ledger-6 / check_reversal SCENARIO 3: a closing entry is never /// reversed (ClosingEntryIrreversible), even dated in an open period. #[test] fn a_closing_entry_is_never_reversed() { @@ -1015,7 +1015,7 @@ fn a_closing_entry_is_never_reversed() { assert_eq!(observe(&b.l), before); } -/// Oracle: check_reversal SCENARIO 4 (B-12): a reversal dated in a closed +/// Oracle: check_reversal SCENARIO 4 (BS-period-2): a reversal dated in a closed /// period is refused (ClosedPeriod); dated after it, accepted. #[test] fn a_reversal_is_never_dated_in_a_closed_period() { @@ -1184,7 +1184,7 @@ fn assert_balanced(l: &Ledger, id: EntryId) { assert_eq!(dr, cr, "closing entry must balance"); } -/// Oracle: close INVARIANTS 1-3 and B-11: closing to retained earnings +/// Oracle: close INVARIANTS 1-3 and BS-period-1: closing to retained earnings /// zeroes revenue and expense as of Jan 31, credits 3999 (created, equity) /// with exactly the net 700.00, is dated Jan 31, balances, locks the /// period, and leaves February's 50.00 sale untouched. @@ -1296,7 +1296,7 @@ fn a_period_with_drafts_never_closes() { assert_eq!(observe(&b.l), before); } -/// Oracle: close SCENARIO 3 (B-12): closing out of order is refused +/// Oracle: close SCENARIO 3 (BS-period-2): closing out of order is refused /// (CloseOutOfOrder(id, later)). #[test] fn periods_close_in_order() { @@ -1443,7 +1443,7 @@ fn members(shares: &[(AccountId, &str, Option)]) -> CloseTo { ) } -/// Oracle: B-13 / AGENTS.md (50/50): net 700.00 splits 350.00 / 350.00; each +/// Oracle: BS-partner-1 / AGENTS.md (50/50): net 700.00 splits 350.00 / 350.00; each /// member's distributions close into their own capital. #[test] fn a_partnership_close_splits_by_share() { @@ -1488,7 +1488,7 @@ fn net_books(net: &str) -> (Books, PeriodId, AccountId) { (b, jan, cap_c) } -/// Oracle: B-13 DECISION (largest remainder, ties to the earlier member), +/// Oracle: BS-partner-1 DECISION (largest remainder, ties to the earlier member), /// hand-computed: 1.05 at 0.3/0.3/0.4 is exactly 0.315/0.315/0.42; rounded /// down 0.31/0.31/0.42 leaves one cent, remainders .005/.005/0 tie, so the /// first member gets it: 0.32/0.31/0.42. (The retired last-absorbs rule @@ -1507,7 +1507,7 @@ fn members_split_by_largest_remainder_ties_to_the_earlier() { assert_eq!(b.l.account_balance(cap_c).unwrap(), dec("0.42")); } -/// Oracle: B-13 / kernel::apportion INVARIANT 3, hand-computed: 0.07 at +/// Oracle: BS-partner-1 / kernel::apportion INVARIANT 3, hand-computed: 0.07 at /// 0.2/0.3/0.5 is exactly 0.014/0.021/0.035; rounded down 0.01/0.02/0.03 /// (sum 0.06), remainders .004/.001/.005, so the largest remainder (the /// third) gets the cent: 0.01/0.02/0.04, wherever it sits in the list. @@ -1736,7 +1736,7 @@ fn only_a_posted_line_can_clear() { // account_balance // --------------------------------------------------------------------------- -/// Oracle: account_balance INVARIANT 1 / B-5 and trial balance SCENARIO 2: +/// Oracle: account_balance INVARIANT 1 / BS-ledger-3 and trial balance SCENARIO 2: /// asset debited 100 and credited 30 is 70; credit-normal accounts read /// credits minus debits; a contra balance is negative. #[test] @@ -1818,7 +1818,7 @@ fn the_balance_of_an_unknown_account_is_refused() { // --------------------------------------------------------------------------- /// Oracle: set_line_class GOAL: a draft line is tagged (and cleared with -/// None); SCENARIO 1 (B-8): a posted line NEVER changes; SCENARIO 2: an +/// None); SCENARIO 1 (BS-ledger-4): a posted line NEVER changes; SCENARIO 2: an /// unknown line or class is refused. #[test] fn only_draft_lines_take_a_class() { @@ -2287,7 +2287,7 @@ proptest! { prop_assert_eq!(observe_but_account_ids(&f.b.l), before, "command {} changed the books ({:?})", k, r); } - /// Oracle: B-1/B-6 and post_entry INVARIANT 2 against the test's own + /// Oracle: BS-entry-1/BS-statement-1 and post_entry INVARIANT 2 against the test's own /// model: every balanced random entry posts, the log is exactly the /// posting sequence, earlier entries never change, every balance equals /// the model on its normal side, and the trial balance balances. @@ -2314,7 +2314,7 @@ proptest! { prop_assert!(trial_balance(&b.l).balanced()); } - /// Oracle: close INVARIANTS 1-4 and B-13 against the test's own model, + /// Oracle: close INVARIANTS 1-4 and BS-partner-1 against the test's own model, /// for random books closed 50/50 to members at Jan 31: revenue and /// expense are zero as of Jan 31; what remains is exactly February and /// March; the members' credits sum to January's net with A taking the @@ -2551,7 +2551,7 @@ fn renumber_refusals_leave_the_books_unchanged() { } // --------------------------------------------------------------------- -// Ledger::rename_account (P3, defect 15; rules.md B-31). +// Ledger::rename_account (P3, defect 15; BS-ledger-10). // --------------------------------------------------------------------- proptest! { @@ -2721,7 +2721,7 @@ fn a_closed_period_or_a_role_never_blocks_a_rename() { assert_eq!(l.role_account(&ledger_core::GENERAL_EXPENSES), Some(b.exp)); } -/// rename_account INVARIANT 3 (rules.md B-28's pair): replay takes a +/// rename_account INVARIANT 3 (BS-entry-4's pair): replay takes a /// journaled name the command now refuses (blank, a sibling's, nine /// digits, unchanged) for an account that exists, and refuses only an /// unknown account. @@ -2738,7 +2738,7 @@ fn a_journaled_rename_replays_past_the_command_rules() { ); } -/// add_account SCENARIOS 5-6 (rules.md B-31): a new account named like a +/// add_account SCENARIOS 5-6 (BS-ledger-10): a new account named like a /// sibling (ignoring capitals and surrounding space; top-level accounts /// are siblings) or holding a run of nine digits is refused, using up no /// id; under another parent the name is free. Replay takes them all, and @@ -2838,12 +2838,12 @@ fn a_rename_reason_is_bounded_text_without_a_tin() { assert!(Ledger::check_rename_reason(&"x".repeat(2_000)).is_ok()); } -/// add_account SCENARIOS 7-8 and rename_account SCENARIO 6 (rules.md -/// B-31): a new name is one line of at most MAX_ACCOUNT_NAME characters, +/// add_account SCENARIOS 7-8 and rename_account SCENARIO 6 ( +/// BS-ledger-10): a new name is one line of at most MAX_ACCOUNT_NAME characters, /// kept trimmed, by a new account and a rename alike: 200 characters are /// taken, 201 refused, and so is a line break, a tab or another control /// character; surrounding space is dropped the same way on both paths. -/// Replay takes any journaled name (B-28). +/// Replay takes any journaled name (BS-entry-4). #[test] fn a_new_name_is_one_trimmed_line_of_bounded_length() { use ledger_core::account::MAX_ACCOUNT_NAME; diff --git a/crates/ledger-core/tests/spec_parties.rs b/crates/ledger-core/tests/spec_parties.rs index 622f585a..3d0897de 100644 --- a/crates/ledger-core/tests/spec_parties.rs +++ b/crates/ledger-core/tests/spec_parties.rs @@ -232,7 +232,7 @@ fn redact_full_tins_masks_every_full_tin() { } /// Oracle: `check_text` refuses what `has_full_tin` finds, so a purge -/// reason or note quoting the old number with dots is refused (B-26: no +/// reason or note quoting the old number with dots is refused (BS-partner-2: no /// party field may hold a nine-digit number). #[test] fn check_text_refuses_a_dotted_tin() { @@ -1461,7 +1461,7 @@ fn entry_flow_takes_across_in_order_until_used_up() { ); } -/// Oracle: shares::target DEFINITIONS, case 3 (rules.md B-35): members +/// Oracle: shares::target DEFINITIONS, case 3 (BS-partner-3): 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, @@ -1860,7 +1860,7 @@ mod shares { assert_eq!(paid_received(&b, b.mo), (Decimal::ZERO, d("100.00"))); } - /// SCENARIO 3 (defect 14, rules.md B-35): property contributed moves + /// SCENARIO 3 (defect 14, BS-partner-3): property contributed moves /// no money; each member's part is what moved their capital, signed /// as their own account shows it: received, in kind. Basis cash /// counts nothing; basis all counts it. (Before P3 this read +500.00 @@ -1919,7 +1919,7 @@ mod shares { assert_eq!((a.paid, a.received), (Decimal::ZERO, Decimal::ZERO)); } - /// rules.md B-35 item 3 (capital first): a members' entry counts what + /// BS-partner-3 item 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 4dfae4a0..a90cd3f0 100644 --- a/crates/ledger-core/tests/spec_party_totals.rs +++ b/crates/ledger-core/tests/spec_party_totals.rs @@ -1,13 +1,13 @@ //! P3 defects 14, 24 and 11: a party's part of an entry, a party's //! totals, and the directory's TIN last four. //! -//! Oracles: rules.md B-35 (a party's part, signed as a line on its own +//! Oracles: BS-partner-3 (a party's part, signed as a line on its own //! account, with its direction and its money and property; party totals //! on basis cash or all; a member's entry counts what moved their capital; //! money is cash, cards, the members' financing and loans; a liability -//! credit never counts as paying that liability's own creditor), B-9 (a -//! correction is the opposite entry), B-13 and the K-1 worksheet (k1 -//! INVARIANT 3: what is property), B-26 (a TIN's last four), and the spec +//! credit never counts as paying that liability's own creditor), BS-ledger-5 (a +//! correction is the opposite entry), BS-partner-1 and the K-1 worksheet (k1 +//! INVARIANT 3: what is property), BS-partner-2 (a TIN's last four), and the spec //! blocks of `ledger_core::shares`, `ledger_core::parties` (`flow`, //! `activity_with`, `Party::tin_last4`) and `ledger_core::kernel` //! (`party_target`, `reverse_target`). Every expected value is worked by @@ -257,7 +257,7 @@ fn part(party: PartyId, amount: &str, cash: &str, in_kind: &str) -> Part { use Side::{Credit as Cr, Debit as Dr}; /// The audit's reproduction (F36, F37), anonymized, with what each row -/// should say (rules.md B-35): `resolved` signed as a line on the party's +/// should say (BS-partner-3): `resolved` signed as a line on the party's /// own account, a direction, and what of it was money or property; a /// reversal the exact opposite of what it reverses; totals on both bases, /// labelled. @@ -550,7 +550,7 @@ fn defect14_shares_take_the_partys_side_and_reversals_flip() { ); } -/// B-35 item 4: on the member-only entries, basis all is the statement of +/// BS-partner-3 item 4: 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 B-35 item 6: a credit to what the company owes a party +/// Defect 24 and BS-partner-3 item 6: 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 @@ -749,7 +749,7 @@ fn defect24_a_credit_to_a_partys_own_liability_never_pays_it() { assert_eq!(b.totals(m, Basis::All), (Decimal::ZERO, d("800.00"))); } -/// The known limit B-35 states (and the tool text says): when the +/// The known limit BS-partner-3 states (and the tool text says): when the /// members aren't named the creditors of their financing account, a /// distribution declared through it counts when declared and again when /// paid. Pinned so a change to it is seen. @@ -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 (B-35 item 4's conditions). +/// party totals catch up when it is paid (BS-partner-3 item 4'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)); } -/// B-35 item 3: a distribution's cash is the money it paid and its in +/// BS-partner-3 item 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 (B-35 item 5): a gift card the company +/// Defect 24 and the card rule (BS-partner-3 item 5): 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"))); } -/// B-35 item 5 and `parties::card_accounts` INVARIANTS 1-4: one rule for +/// BS-partner-3 item 5 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); } -/// B-35 item 3, case 3: E is the movement of equity other than retained +/// BS-partner-3 item 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"))); } -/// B-35 item 3 (capital first): a mixed contribution is split into money +/// BS-partner-3 item 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() { ); } -/// B-35 item 3, case 1: a period's closing entry moves nothing with +/// BS-partner-3 item 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] @@ -1343,7 +1343,7 @@ fn defect11_a_partys_tin_last4_is_its_tin_facts_else_its_w9s() { assert_eq!(by_hand.tin_last4(), None); } -/// The kernel's B-35 cases, by hand (party_target INVARIANTS 1-6) and +/// The kernel's BS-partner-3 cases, by hand (party_target INVARIANTS 1-6) and /// reverse_target an involution. #[test] fn party_target_cases_by_hand() { @@ -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 (B-35 item 4's + /// every span from the year's start to any date (BS-partner-3 item 4'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 a51b766a..ff902ac9 100644 --- a/crates/ledger-core/tests/spec_projects.rs +++ b/crates/ledger-core/tests/spec_projects.rs @@ -1,11 +1,11 @@ -//! Projects (rules.md B-37): a class with its facts; its figures are the +//! Projects (BS-statement-5): a class with its facts; its figures are the //! revenue and expense lines tagged to it. //! //! ```text //! GOAL: a project's record holds only what its rules allow, and its //! figures are exactly its tagged lines, from one function. -//! SOURCE: docs/spec/rules.md B-37 (job costing; ASC 450-30-25-1 and -//! 340-40-25-5 for on-spec work), B-11 (closes left out). +//! SOURCE: BS-statement-5 (job costing; ASC 450-30-25-1 and +//! 340-40-25-5 for on-spec work), BS-period-1 (closes left out). //! ``` use chrono::NaiveDate; @@ -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 (rules.md B-37 item 7). + // it isn't untagged (BS-statement-5 item 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"]); } -/// rules.md B-37 item 7: the margin is the contribution's share of +/// BS-statement-5 item 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"); } -/// rules.md B-37 item 7: each month's net to date opens on the lines +/// BS-statement-5 item 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_replayed_extremes.rs b/crates/ledger-core/tests/spec_replayed_extremes.rs index b2ff4815..55c69584 100644 --- a/crates/ledger-core/tests/spec_replayed_extremes.rs +++ b/crates/ledger-core/tests/spec_replayed_extremes.rs @@ -1,6 +1,6 @@ //! Figures derived from what replay accepts: computed exactly where exact //! arithmetic and chrono's calendar reach, refused (TooLargeToCompute, -//! DateOutOfRange) where they don't, never a panic (rules.md B-28; P0 +//! DateOutOfRange) where they don't, never a panic (BS-entry-4; P0 //! review round 4, 2026-10-17). //! //! ```text @@ -243,8 +243,8 @@ fn a_draft_of_decimals_largest_is_refused_where_summed() { assert!(why.contains("too large to compute"), "{why}"); assert_eq!(l.post_entry(e).unwrap_err(), LedgerError::AmountOutOfRange); } - // A member's capital moved past exact arithmetic (rules.md B-35, case - // 3, B-28): the target is refused, never a panic. + // A member's capital moved past exact arithmetic (BS-partner-3, case + // 3, BS-entry-4): the target is refused, never a panic. let e = l.create_entry(d(2026, 3, 1), "huge capital"); for _ in 0..2 { l.replay_add_line(e, cash, Side::Debit, usd(Decimal::MAX)) @@ -285,7 +285,7 @@ fn a_draft_of_decimals_largest_is_refused_where_summed() { /// A document is restored as journaled: its total is exact, or refused /// past exact arithmetic; what it owes is what the ledger lines tagged -/// with it carry (rules.md B-38), exact, whatever the journal held (paid +/// with it carry (BS-arap-2), exact, whatever the journal held (paid /// above its total included); aging refuses a document whose total it /// can't compute. #[test] @@ -363,7 +363,7 @@ fn documents_and_aging_are_exact_or_refused() { (Decimal::from(11), -Decimal::ONE) ); // A payment event naming an amount no line of its entry carries tags - // nothing, and is refused nothing (B-28). + // nothing, and is refused nothing (BS-entry-4). l.replay_invoice_payment(1, -Decimal::ONE, p).unwrap(); assert_eq!(l.get_invoice(1).unwrap().balance(), Ok(-Decimal::ONE)); // A total of lines that overflow, and its balance; aging refuses it. diff --git a/crates/ledger-core/tests/spec_reports.rs b/crates/ledger-core/tests/spec_reports.rs index 2bfc05ca..aae1ff36 100644 --- a/crates/ledger-core/tests/spec_reports.rs +++ b/crates/ledger-core/tests/spec_reports.rs @@ -42,7 +42,7 @@ fn usd(cents: i64) -> Money { fn post(l: &mut Ledger, date: NaiveDate, desc: &str, lines: &[(AccountId, Side, i64)]) -> EntryId { // As replay posts it: these books hold hand lines on receivables or // payables (1200, 2000), which books an earlier version wrote still - // hold and every report must read; the control guard (rules.md B-38) + // hold and every report must read; the control guard (BS-arap-2) // refuses them as new work. ledger_core::parties::replaying(|| { let e = l.create_entry(date, desc); @@ -1115,7 +1115,7 @@ fn me_unexplained_equity_change_goes_in_other() { /// 50.00). /// /// ASSUMED: a closing entry's credit to a member's capital account is not -/// reported as a contribution (B-11: a close moves earnings), so January's +/// reported as a contribution (BS-period-1: a close moves earnings), so January's /// statement shows contributions 1000 / 0, income 50.01 / 50.00. #[test] fn me_after_members_close_does_not_count_close_as_contribution() { @@ -1473,7 +1473,7 @@ fn cf_undesignated_liability_is_operating() { assert_eq!(cf.net_change_in_cash, c(58000)); } -/// Oracle: CF INVARIANT 5 / B-14 — closing entries never counted: after +/// Oracle: CF INVARIANT 5 / BS-statement-3 — closing entries never counted: after /// closing February into retained earnings the February statement is /// unchanged (NI still 400, 3999 not in financing). #[test] @@ -1792,7 +1792,7 @@ fn build_ordered(gens: &[Gen], scale: i64, order: &[usize], tag: bool) -> Books let mut entries = Vec::new(); // As replay posts it: these books hold hand lines on receivables or // payables (1200, 2000), which books an earlier version wrote still - // hold and every report must read; the control guard (rules.md B-38) + // hold and every report must read; the control guard (BS-arap-2) // refuses them as new work. ledger_core::parties::replaying(|| { for g in gens { @@ -1931,7 +1931,7 @@ fn opt_month() -> impl Strategy> { proptest! { #![proptest_config(ProptestConfig::with_cases(64))] - /// Oracle: TB INVARIANT 1 / B-6 — total debits equal total credits, and + /// Oracle: TB INVARIANT 1 / BS-statement-1 — total debits equal total credits, and /// each total is its column's sum, for any as-of date, with or without a /// close. #[test] @@ -2005,7 +2005,7 @@ proptest! { prop_assert_eq!(many.total_debits, one.total_debits * kk); } - /// Oracle: B-9 metamorphic — adding an entry and its reversal (same + /// Oracle: BS-ledger-5 metamorphic — adding an entry and its reversal (same /// date) leaves TB and P&L unchanged at every date. #[test] fn prop_entry_plus_reversal_leaves_tb_and_pnl_unchanged(gens in arb_books(), extra in arb_gen(), as_of in 0u32..365) { @@ -2222,7 +2222,7 @@ proptest! { proptest! { #![proptest_config(ProptestConfig::with_cases(64))] - /// Oracle: BS INVARIANT 1 / B-7 — assets = liabilities + equity (with + /// Oracle: BS INVARIANT 1 / BS-statement-2 — assets = liabilities + equity (with /// current earnings), exactly; totals are line sums; never a revenue or /// expense line; with or without a close (RE or members). #[test] @@ -2503,7 +2503,7 @@ proptest! { /// Oracle: CF INVARIANT 2 against an independent model — financing is /// 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 (rules.md B-14 + /// investing, financing, each up to its own movement (BS-statement-3 /// rule 3), 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 diff --git a/crates/ledger-core/tests/spec_roles.rs b/crates/ledger-core/tests/spec_roles.rs index bb37b576..d2d59fef 100644 --- a/crates/ledger-core/tests/spec_roles.rs +++ b/crates/ledger-core/tests/spec_roles.rs @@ -2,7 +2,7 @@ //! (receivables, revenue, payables, general expense, retained earnings, the //! seven payroll accounts) assigned to the chart's own accounts. //! -//! Oracles are `docs/spec/rules.md` B-4 (the five elements) and B-23 +//! Oracles are BS-ledger-2 (the five elements) and BS-ledger-8 //! (control roles), the spec block on `Ledger::assign_role`, the doc //! comments of `Ledger::role_account`, `role_assignment`, //! `check_assign_role`, `control_account`, `ControlAccount::key`, the spec @@ -48,7 +48,7 @@ fn line(desc: &str, amount: &str) -> DocumentLine { } } -/// The thirteen role keys, as the spec lists them (B-23, B-41's +/// The thirteen role keys, as the spec lists them (BS-ledger-8, BS-arap-5's /// bad_debts, and `UnknownRole`). const KEYS: [&str; 13] = [ "receivables", @@ -106,9 +106,9 @@ fn bal(l: &Ledger, id: AccountId) -> Decimal { /// Draft, add lines, post. Panics on any refusal (setup only). Posted as /// replay posts it: these books hold hand lines on receivables or payables -/// (moving a role's balance by hand, B-23's path before documents read +/// (moving a role's balance by hand, BS-ledger-8's path before documents read /// their lines), which books an earlier version wrote still hold; the -/// control guard (rules.md B-38) refuses them as new work. +/// control guard (BS-arap-2) refuses them as new work. fn post(l: &mut Ledger, date: NaiveDate, lines: &[(AccountId, Side, &str)]) -> EntryId { ledger_core::parties::replaying(|| { let id = l.try_create_entry(date, "test entry").unwrap(); @@ -250,7 +250,7 @@ fn alice() -> PayrollLine { // ------------------------------------------------------------ the roles -/// Oracle: B-23 (and B-41 for bad_debts) names the roles and their default +/// Oracle: BS-ledger-8 (and BS-arap-5 for bad_debts) names the roles and their default /// codes; `control_account` finds a role by its `key`; `UnknownRole` lists /// the thirteen keys. #[test] @@ -601,7 +601,7 @@ fn an_unknown_account_is_refused() { // ----------------------------------------- SCENARIO 2: type / placeholder -/// Oracle: SCENARIO 2 + INVARIANT 3 + B-4: every role refuses an account of +/// Oracle: SCENARIO 2 + INVARIANT 3 + BS-ledger-2: every role refuses an account of /// each other type with ControlAccountMismatch naming the account, the /// role, the type needed and the type found. #[test] @@ -688,7 +688,7 @@ fn none_is_refused_when_the_default_code_holds_a_wrong_typed_account() { } // The role assigned elsewhere, then 1200 taken by a wrong type (an - // assignment frees the code, B-23 / check_renumber_account): None is + // assignment frees the code, BS-ledger-8 / check_renumber_account): None is // refused, and the assignment stays. let (mut l, _) = books(); let ar = add(&mut l, "1100", "Trade Receivables", AccountType::Asset); @@ -784,7 +784,7 @@ fn none_is_refused_when_its_codes_account_fills_another_role() { // --------------------------------------------- SCENARIO 4: balances move -/// Oracle: SCENARIO 4 + B-23 ("moves only when its account holds no +/// Oracle: SCENARIO 4 + BS-ledger-8 ("moves only when its account holds no /// balance, so the bookkeeper first moves the balance with an entry"). #[test] fn receivables_cannot_move_while_holding_a_balance_but_can_once_moved_out() { @@ -814,7 +814,7 @@ fn receivables_cannot_move_while_holding_a_balance_but_can_once_moved_out() { other => panic!("expected DocumentRoleHoldsBalance, got {other:?}"), } // Moving the balance by hand is refused now (the control guard, - // rules.md B-38): until a role's balance moves with its documents + // BS-arap-2): until a role's balance moves with its documents // (plan P4b S7), a receivables role holding a balance stays put. let e = l.try_create_entry(d(2026, 3, 2), "move").unwrap(); assert!(matches!( @@ -874,7 +874,7 @@ fn every_balance_sheet_role_holds_while_its_account_has_a_balance() { ); if c.key == RECEIVABLES.key || c.key == PAYABLES.key { // No document posted there: the balance is the chart's own, - // so the role moves (B-38); it can't come back to an account + // so the role moves (BS-arap-2); it can't come back to an account // holding hand lines. l.assign_role(c.key, Some(target)).unwrap(); assert!( @@ -924,7 +924,7 @@ fn none_is_refused_while_the_assigned_balance_sheet_account_holds_a_balance() { let _ = cash; } -/// Oracle: SCENARIO 4 "Revenue and expense roles move freely"; B-23 +/// Oracle: SCENARIO 4 "Revenue and expense roles move freely"; BS-ledger-8 /// "earlier postings stay where they are"; INVARIANT 4. #[test] fn revenue_and_expense_roles_move_even_with_a_balance() { @@ -1048,7 +1048,7 @@ fn check_assign_role_agrees_and_does_not_mutate() { // ------------------------------------------- renumbering and the codes -/// Oracle: B-23 + check_renumber_account ("an assigned role frees its +/// Oracle: BS-ledger-8 + check_renumber_account ("an assigned role frees its /// code"); renumber_account SCENARIO 2 for an unassigned role's code. #[test] fn an_assigned_role_frees_its_code_for_renumbering() { diff --git a/crates/ledger-core/tests/statements.rs b/crates/ledger-core/tests/statements.rs index 0d275447..2e61b748 100644 --- a/crates/ledger-core/tests/statements.rs +++ b/crates/ledger-core/tests/statements.rs @@ -547,11 +547,11 @@ fn statement_json( /// The golden: every number in `golden/members_equity_two_member.json` was /// computed by hand, from the entries, in /// `plan/golden-worksheets/members_equity_two_member.md`, before the engine's -/// output was looked at. Rules: B-13 (capital account = contributions + +/// output was looked at. Rules: BS-partner-1 (capital account = contributions + /// allocated income − distributions; cent rounding by largest remainder, the /// odd cent to the member listed first; unclosed earnings split cumulatively) -/// and B-7 (the Total ties to balance-sheet equity). The same numbers hold -/// whether or not January is closed (B-13: a member's capital on a date never +/// and BS-statement-2 (the Total ties to balance-sheet equity). The same numbers hold +/// whether or not January is closed (BS-partner-1: a member's capital on a date never /// moves when its period closes). #[test] fn golden_members_equity_two_member() { @@ -1102,7 +1102,7 @@ fn cf_params(start: NaiveDate, end: NaiveDate, cash: AccountId) -> CashFlowParam } fn reconciles(cf: &ledger_core::CashFlowStatement) { - // B-14 / cash_flow INVARIANT 4: the three sections sum to the change in + // BS-statement-3 / cash_flow INVARIANT 4: the three sections sum to the change in // cash, exactly, and net income and its reconciling items to operating. assert_eq!( cf.cash_from_operations + cf.cash_from_investing + cf.cash_from_financing, @@ -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 (rules.md B-14 rule 11, D-42: constructive receipt +/// spent on its date (BS-statement-3 rule 11, 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 (rules.md B-14 rule 11; ASC 230 is silent on a payment +/// Oracle: D-42 (BS-statement-3 rule 11; 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 @@ -1691,7 +1691,7 @@ mod cumulative_closes { .collect() } - /// Oracle: rules.md B-13 (cumulative closes; docs/testing.md #12), + /// Oracle: BS-partner-1 (cumulative closes; docs/testing.md #12), /// hand-computed. Closing each cent on its own gives the earlier member /// every tie: A 0.03, B 0.00 after three months. Cumulatively: after /// month 1 the run's 0.01 splits A 0.01 / B 0; after month 2, 0.02 @@ -1723,7 +1723,7 @@ mod cumulative_closes { } proptest::proptest! { - /// Oracle: rules.md B-13, cumulative closes. For any run of monthly + /// Oracle: BS-partner-1, cumulative closes. For any run of monthly /// profits and losses closed into three members at 33.33% / /// 33.33% / 33.34%, each member's total from the run is within one /// cent of their exact share of everything closed. @@ -1782,7 +1782,7 @@ mod cumulative_closes { assert_eq!((a, b), (cents("0.02"), cents("0"))); } - /// The rule since P3 (rules.md B-13, D-10): a close to retained + /// The rule since P3 (BS-partner-1, D-10): a close to retained /// earnings allocates nothing to the members and is skipped, so March's /// members close continues January's count: the running 0.02 splits /// 0.01 / 0.01, and March gives B the cent. diff --git a/crates/ledger-core/tests/tax.rs b/crates/ledger-core/tests/tax.rs index ea1889fc..e4af33a9 100644 --- a/crates/ledger-core/tests/tax.rs +++ b/crates/ledger-core/tests/tax.rs @@ -165,7 +165,7 @@ fn by_value(v: &mut serde_json::Value) { /// The golden: every number in `golden/tax_summary_form_1065.json` was /// computed by hand, from the fixture's entries, in /// `plan/golden-worksheets/tax_summary_form_1065.md`, before the engine's -/// output was looked at. Rules: B-32 and `sources/irs-tax-lines.md` (the +/// output was looked at. Rules: BS-ledger-11 and `sources/irs-tax-lines.md` (the /// category-to-line map; a contra-income expense account reduces receipts; /// meals at 50% from the Schedule C line 24b instructions, so 333.33 is /// 166.665, the cent half away from zero, 166.67; fines and penalties at 0% @@ -228,7 +228,7 @@ fn category_books(category: &str, specs: &[(&str, &str, Option<&str>)]) -> Ledge l } -/// CHOICE (owner, 2026-11-07; rules.md B-32, B-21): a category rounds +/// CHOICE (owner, 2026-11-07; BS-ledger-11, BS-entry-3): a category rounds /// once, on its total. Two Meals accounts of 1.01 at 50%: each share is /// exactly 0.505, so rounding per account would give 0.51 + 0.51 = 1.02; /// the exact sum 1.01 rounds once to 1.01. Book stays exact: 2.02. @@ -441,8 +441,8 @@ fn a_sole_proprietor_cannot_deduct_a_gift_on_schedule_c() { } // --------------------------------------------------------------------------- -// Which accounts need a category, and the policy (P3, defect 8; rules.md -// B-32). +// Which accounts need a category, and the policy (P3, defect 8; +// BS-ledger-11). // --------------------------------------------------------------------------- fn set_policy(l: &mut Ledger, value: &str) { @@ -634,11 +634,11 @@ fn under_refuse_a_needed_category_is_never_cleared() { Err(LedgerError::UnknownAccount(999)) ); // The engine's own set_account_tax (which replay calls) never checks - // the policy (rules.md B-28): a journaled clear replays. + // the policy (BS-entry-4): a journaled clear replays. l.set_account_tax(software, None, None).unwrap(); } -/// rules.md B-32 (review R3): every account a tool can require has a +/// BS-ledger-11 (review R3): every account a tool can require has a /// category that fits it on every return: a disposal's gain or loss /// account (revenue or expense: Form 4797), tax-exempt income on the /// entity returns, and each control role's account. diff --git a/crates/ledger-core/tests/tax_capital.rs b/crates/ledger-core/tests/tax_capital.rs index b045549a..7d5c0f7d 100644 --- a/crates/ledger-core/tests/tax_capital.rs +++ b/crates/ledger-core/tests/tax_capital.rs @@ -1,5 +1,5 @@ //! Spec tests for the K-1 worksheet's tax-basis capital -//! (`ledger_core::tax_capital`, rules.md B-36): Item L on the tax basis +//! (`ledger_core::tax_capital`, BS-partner-4): Item L on the tax basis //! beside the book figures, every figure the books can't know left open //! and named, and the reconciliation from book to tax capital. //! @@ -223,7 +223,7 @@ fn the_year() -> (Books, EntryId, AssetId, AssetId) { (b, devices, laptop, camera) } -/// Item L on the tax basis, per member, for the year (B-36): a cash +/// Item L on the tax basis, per member, for the year (BS-partner-4): a cash /// contribution, a contribution of property, a distribution, a year of /// depreciation. #[test] @@ -748,7 +748,7 @@ fn unequal_contributors_and_a_member_with_none() { assert_eq!(none.reconciliation, Reconciliation::default()); } -/// The odd cent on the tax basis runs (B-36 with D-38; owner, 2026-10-22): +/// The odd cent on the tax basis runs (BS-partner-4 with D-38; owner, 2026-10-22): /// three devices contributed 50/50, each worth less than its basis by an /// odd number of cents, the built-in gain shared cumulatively, so the /// members' tax property ends one cent apart, never three. By hand: @@ -843,7 +843,7 @@ fn three_members(b: &mut Books) -> (AccountId, [MemberCapital; 3]) { ) } -/// A member never takes a cent of an entry they had no part in (B-36, +/// A member never takes a cent of an entry they had no part in (BS-partner-4, /// Form 1065 Item L: capital contributed is the basis of the property /// that member contributed; P4 review, 2026-10-22). Three members; by /// hand, each set of contributing members its own running split: @@ -948,7 +948,7 @@ fn a_member_outside_an_entry_never_takes_its_cents() { } /// An entry's odd cent is the same whatever span the worksheet is asked -/// for (B-36; P4 review, 2026-10-22). Tobin and Morgan, 50/50: a monitor +/// for (BS-partner-4; P4 review, 2026-10-22). Tobin and Morgan, 50/50: a monitor /// contributed 2026-01-01 (400.00, basis 412.37, gain −12.37), reversed /// 2026-07-01; a desk contributed 2026-11-01 (600.00, basis 655.91, gain /// −55.91). The reversal takes the monitor's split back out of the count, @@ -999,7 +999,7 @@ fn an_entrys_odd_cent_is_the_same_in_every_span() { /// The running split takes the entries in date order, whatever order /// they were posted in, so next year's beginning is this year's ending -/// to the cent (B-36). Tobin and Morgan, 50/50: a chair dated 2027-03-01 +/// to the cent (BS-partner-4). Tobin and Morgan, 50/50: a chair dated 2027-03-01 /// (250.00, basis 263.41) posted first, then a monitor dated 2026-01-01 /// (400.00, basis 412.37). The monitor comes first: −6.19 / −6.18, then /// the chair −6.70 / −6.71. Taken in posting order the 2027 worksheet @@ -1070,7 +1070,7 @@ fn largest_remainder(exact: &[i128], total: i128, negative: bool) -> Vec { proptest! { #![proptest_config(ProptestConfig::with_cases(5000))] - /// Law: RunningSplit INVARIANTS 1 and 2 (B-36 with D-38): for any run + /// Law: RunningSplit INVARIANTS 1 and 2 (BS-partner-4 with D-38): for any run /// of splits, wholes of either sign to the cent (a third of them a few /// cents, so the running whole often comes back to zero) and each its own /// weights among up to four members (small ratios, scaled by a cent diff --git a/crates/ledger-gui/src/app.rs b/crates/ledger-gui/src/app.rs index 8ea0ef30..7da35dea 100644 --- a/crates/ledger-gui/src/app.rs +++ b/crates/ledger-gui/src/app.rs @@ -470,7 +470,7 @@ impl App { /// /// ```text /// GOAL: the viewer shows what the agent was told it shows. - /// SOURCE: rules.md B-30 (one default period; a start after the end is + /// SOURCE: BS-period-3 (one default period; a start after the end is /// refused, never swapped); plan/served.md P3 defect 15. /// INVARIANTS: /// 1. A target's dates are taken as the server resolved them, an diff --git a/crates/ledger-gui/src/attention.rs b/crates/ledger-gui/src/attention.rs index 258f24b6..662fdb53 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 (rules.md B-14 rule 12, D-35): a + /// INVARIANT 2's cash flow items (BS-statement-3 rule 12, 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/books.rs b/crates/ledger-gui/src/books.rs index ec01a9b1..6ae5d547 100644 --- a/crates/ledger-gui/src/books.rs +++ b/crates/ledger-gui/src/books.rs @@ -29,7 +29,7 @@ pub struct EntryInfo { pub status: EntryStatus, /// Total debits; None when they can't be summed exactly (a draft's /// lines are as an earlier version journaled them, of any size: - /// rules.md B-28). + /// BS-entry-4). pub amount: Option, /// Accounts touched, debits first: "6300 Software". pub accounts: Vec, @@ -182,10 +182,10 @@ pub fn period_month(period: &str) -> Option<(i32, u32)> { /// 4. open_invoices = Σ what each of its customer record's invoices /// owes today (Books::owed_today: read from the ledger lines tagged /// with it, so a reversed payment or a void counts as it should, -/// rules.md B-38); open_bills the same for its vendor record's bills. +/// BS-arap-2); open_bills the same for its vendor record's bills. /// 4a. Each of 3 and 4 is None when it can't be summed exactly (a /// document is restored as an earlier version journaled it, of any -/// size: rules.md B-28), never a wrong number. +/// size: BS-entry-4), never a wrong number. /// 5. form_1099: its vendor record's line in Books::vendor_1099(year) /// (the server's books.vendor_1099), when it has a vendor record in /// that report and the report can be made (the year's threshold is @@ -222,7 +222,7 @@ pub struct PartyInfo { /// ```text /// GOAL: say when monthly depreciation hasn't been run, without crying /// wolf over the month still under way. -/// SOURCE: docs/spec/rules.md B-15 (monthly straight-line depreciation); +/// SOURCE: BS-asset-1 (monthly straight-line depreciation); /// CONVENTION (a month's depreciation is posted when the month /// ends: ledger-store dates it the month's last day). /// INVARIANTS: @@ -355,7 +355,7 @@ pub enum PartyPeriod { /// get back?" (owner, 2026-10-15) with the books' own numbers. /// SOURCE: ledger_core::parties::activity_with (paid, received, in kind) /// and ledger_core::parties::flow (what for), with Books::money -/// and Books::members, as PartyInfo uses them; rules.md B-35. +/// and Books::members, as PartyInfo uses them; BS-partner-3. /// INVARIANTS: /// 1. paid, received: Books::activity(party, span)'s, exactly: basis /// cash (money), books.party's default. paid_in_kind and @@ -919,8 +919,8 @@ impl Books { } /// What omitted dates mean today, for these books: the one rule the - /// server's report tools, `books.show` and the viewer share (rules.md - /// B-30). + /// server's report tools, `books.show` and the viewer share ( + /// BS-period-3). pub fn periods(&self) -> ledger_core::calendar::PeriodDefaults { ledger_core::calendar::period_defaults(&self.settings.company, self.today) } @@ -938,7 +938,7 @@ impl Books { } /// The period a report or register opens on when nobody chose one: - /// the fiscal year to date (rules.md B-30), as the agent's report + /// the fiscal year to date (BS-period-3), as the agent's report /// tools give it for no dates. pub fn default_period(&self) -> (NaiveDate, NaiveDate) { self.periods().statement_range() @@ -1320,7 +1320,7 @@ impl Books { } /// A document as of today: what it is, read from the ledger lines - /// tagged with it (ledger_core::Ledger::doc_state, rules.md B-38), the + /// tagged with it (ledger_core::Ledger::doc_state, BS-arap-2), the /// figures books.ar_aging and books.party read. One dated after today /// (a post-dated bill) is read as of its own date: what it will owe /// when it is issued, so the forward-looking views keep it; it is @@ -1763,7 +1763,7 @@ impl Books { /// their capital (a reimbursement with a distribution) leaves out the /// money that wasn't theirs. /// What moved in kind isn't what money paid for: when the party's part - /// has property in it (rules.md B-35), the property lines (asset + /// has property in it (BS-partner-3), the property lines (asset /// accounts neither cash nor receivables, the K-1 worksheet's test) /// stay out, so a property contribution, and its reversal, show /// nothing, and a distribution of money and equipment shows the @@ -2011,8 +2011,8 @@ impl Books { /// /// Every month the span touches is one activity scan, so callers clip /// the span to the months they show ([`Books::last_months`]): books - /// an earlier version wrote may run from chrono's first day (rules.md - /// B-28). Chrono's last month ends the walk, never a panic. + /// an earlier version wrote may run from chrono's first day ( + /// BS-entry-4). Chrono's last month ends the walk, never a panic. pub fn party_months(&self, party: PartyId, span: (NaiveDate, NaiveDate)) -> Vec { let mut out = Vec::new(); let mut m = span.0.with_day(1); diff --git a/crates/ledger-gui/src/demo.rs b/crates/ledger-gui/src/demo.rs index 016bc550..e669aa31 100644 --- a/crates/ledger-gui/src/demo.rs +++ b/crates/ledger-gui/src/demo.rs @@ -242,12 +242,12 @@ pub fn build(dir: &Path, today: NaiveDate) -> Result<(), StoreError> { Some("depreciation"), )?; let bank_fees = acct(&mut s, "6900", "Bank Fees", Expense, None)?; - // The projects (classes with their facts, rules.md B-37). + // The projects (classes with their facts, BS-statement-5). let client_class = s.add_project( "Client work", &ledger_core::ProjectFacts { // Its invoices' lines and the contractors it pays are tagged - // to it (rules.md B-37 item 8), so its snapshot is its + // to it (BS-statement-5 item 8), 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 (rules.md B-37 item 4). + // expenses, and nothing is receivable (BS-statement-5 item 4). let tidepool_started = start + Months::new(13); let tidepool = s.add_project( "Tidepool app", diff --git a/crates/ledger-gui/src/fmt.rs b/crates/ledger-gui/src/fmt.rs index 716739f4..f2bf3507 100644 --- a/crates/ledger-gui/src/fmt.rs +++ b/crates/ledger-gui/src/fmt.rs @@ -31,8 +31,8 @@ pub fn money(d: Decimal) -> String { } } -/// What the viewer shows for a figure the books can't compute (rules.md -/// B-28: an earlier version's draft lines, shares, or bases past exact +/// What the viewer shows for a figure the books can't compute ( +/// BS-entry-4: an earlier version's draft lines, shares, or bases past exact /// arithmetic): said in words, never a number. pub const CANT_COMPUTE: &str = "too large to compute"; @@ -233,7 +233,7 @@ mod tests { use std::str::FromStr; /// money_or / dollars_or: a figure as money_ or dollars does, and one - /// the books can't compute in words, never a number (rules.md B-28). + /// the books can't compute in words, never a number (BS-entry-4). #[test] fn a_figure_or_why_not() { let v = Decimal::new(-123_456, 2); diff --git a/crates/ledger-gui/src/pages/accounts.rs b/crates/ledger-gui/src/pages/accounts.rs index 685ff582..283e45df 100644 --- a/crates/ledger-gui/src/pages/accounts.rs +++ b/crates/ledger-gui/src/pages/accounts.rs @@ -31,7 +31,7 @@ pub struct State { #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] pub enum RegisterRange { /// What a register opens on when nobody chose dates: the fiscal year - /// to date (rules.md B-30, `Books::default_period`), its opening + /// to date (BS-period-3, `Books::default_period`), its opening /// balance carried in. #[default] Default, diff --git a/crates/ledger-gui/src/pages/assets.rs b/crates/ledger-gui/src/pages/assets.rs index bb195be3..8ea5d41a 100644 --- a/crates/ledger-gui/src/pages/assets.rs +++ b/crates/ledger-gui/src/pages/assets.rs @@ -5,11 +5,11 @@ //! `depreciation_schedule`, `Asset::basis_figures`), what is posted too //! (`Ledger::accumulated_posted`, its runs). Book value is what the books //! carry (cost less the depreciation posted), never the schedule's figure, -//! which sits beside it as "scheduled" (B-24). Book value and the federal +//! which sits beside it as "scheduled" (BS-asset-3). Book value and the federal //! tax figures sit side by side and are never confused: book cost is what //! was paid or, for a member's contribution, its fair market value; the //! §723 basis, the depreciable basis and the §704(c) built-in gain follow -//! the basis rule (docs/spec/rules.md B-25). +//! the basis rule (BS-asset-4). use super::page; use crate::app::Shell; diff --git a/crates/ledger-gui/src/pages/cash.rs b/crates/ledger-gui/src/pages/cash.rs index 108beb0f..bf369990 100644 --- a/crates/ledger-gui/src/pages/cash.rs +++ b/crates/ledger-gui/src/pages/cash.rs @@ -182,7 +182,7 @@ fn runway(ui: &mut Ui, b: &Books) { return; } // Exact or refused: books near the arithmetic's limit show a - // note, never a crash (rules.md B-28). + // note, never a crash (BS-entry-4). let Some(net) = ledger_core::kernel::total_try(&months, |&(_, _, i, o)| { ledger_core::kernel::Amount::checked_sub(i, o) }) @@ -335,7 +335,7 @@ fn coming_up(ui: &mut Ui, b: &Books, shell: &mut Shell<'_>) { let Some(inv) = b.ledger.get_invoice(id) else { continue; }; - // As of today, from the lines tagged with it (rules.md B-38): a + // As of today, from the lines tagged with it (BS-arap-2): a // reversed payment reopens it, a void closes it. let state = b.doc_today(ledger_core::DocRef::Invoice(id)); let balance = crate::books::owed_of(&state); diff --git a/crates/ledger-gui/src/pages/entry.rs b/crates/ledger-gui/src/pages/entry.rs index 30d4b3ca..08c7c29c 100644 --- a/crates/ledger-gui/src/pages/entry.rs +++ b/crates/ledger-gui/src/pages/entry.rs @@ -224,7 +224,7 @@ pub fn detail(ui: &mut Ui, b: &Books, e: &EntryInfo, shell: &mut Shell<'_>) { widgets::amount_cell(ui, "Credit", amt_w, p.muted, false, false); }); // None: past exact arithmetic (a draft line an earlier - // version journaled, of any size: rules.md B-28). + // version journaled, of any size: BS-entry-4). let (mut dr, mut cr) = (Some(Decimal::ZERO), Some(Decimal::ZERO)); for line in entry.lines() { ui.horizontal(|ui| { @@ -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 (rules.md B-37 item 8). + // gives them, each project a link (BS-statement-5 item 8). if let Some(doc) = document_of(b, e.id) { section(ui, &doc.title); document_lines(ui, &doc, &class_names, total_w, amt_w, shell); @@ -681,7 +681,7 @@ pub fn render(ui: &mut Ui, b: &Books, a: &Attachment, shell: &mut Shell<'_>, wid } } -/// A party's part of an entry in words (rules.md B-35): which way it +/// A party's part of an entry in words (BS-partner-3): which way it /// went and how much ("paid $64.00", "received $740.00, in kind"), what of /// it is still owed, the share it came from when the entry names several /// ("(50%)", "(derived)"), and a reversal said as one ("paid $1,480.00 @@ -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; rules.md B-37 item 8). + /// line, each tagged; BS-statement-5 item 8). #[test] fn a_tagged_line_keeps_its_amounts_in_their_column() { use ledger_core::arap::DocumentLine; diff --git a/crates/ledger-gui/src/pages/invoices.rs b/crates/ledger-gui/src/pages/invoices.rs index 35abff99..04410343 100644 --- a/crates/ledger-gui/src/pages/invoices.rs +++ b/crates/ledger-gui/src/pages/invoices.rs @@ -1,7 +1,7 @@ //! Invoices and bills: what customers owe the company (money in) and what //! it owes vendors (money out), each figure derived from the document's -//! ledger lines that stand (rules.md B-38), the list tied to the -//! receivables or payables account (B-23); and one document's page, with +//! ledger lines that stand (BS-arap-2), the list tied to the +//! receivables or payables account (BS-ledger-8); and one document's page, with //! its lines and its timeline. Read only (D-28): the agent issues, pays //! and voids them. diff --git a/crates/ledger-gui/src/pages/parties.rs b/crates/ledger-gui/src/pages/parties.rs index 4c573598..79061150 100644 --- a/crates/ledger-gui/src/pages/parties.rs +++ b/crates/ledger-gui/src/pages/parties.rs @@ -560,7 +560,7 @@ pub fn show_list(ui: &mut Ui, b: &Books, shell: &mut Shell<'_>) { }); } -/// The party's totals with property in kind (basis all, rules.md B-35 +/// 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 /// contributed or distributed: paid $X, received $Y". None when nothing /// moved in kind (the cash totals are then the whole story). @@ -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 (rules.md B-35 item 4): property in kind, when any. + // Basis all (BS-partner-3 item 4): property in kind, when any. if let Some(text) = in_kind_text(&flow) { ui.add_space(6.0); ui.add( @@ -1194,7 +1194,7 @@ fn records_card(ui: &mut Ui, b: &Books, party: &Party, info: &PartyInfo, go: &mu ); } -/// The projects for or with the party (rules.md B-37), by name: status +/// The projects for or with the party (BS-statement-5), by name: status /// and net to date; a row opens its project. fn projects_card(ui: &mut Ui, b: &Books, ids: &[ledger_core::ClassId], go: &mut Option) { let p = pal(ui.ctx()); @@ -1416,7 +1416,7 @@ fn documents_card(ui: &mut Ui, b: &Books, info: &PartyInfo, go: &mut Option 0); diff --git a/crates/ledger-gui/src/pages/projects.rs b/crates/ledger-gui/src/pages/projects.rs index c0dc58f9..71fb87d6 100644 --- a/crates/ledger-gui/src/pages/projects.rs +++ b/crates/ledger-gui/src/pages/projects.rs @@ -1,9 +1,9 @@ //! 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, rules.md B-37 item 7), revenue and costs by month with the +//! fiscal year, BS-statement-5 item 7), revenue and costs by month with the //! running net, costs by category and by account, its entries, documents, -//! decisions and history (rules.md B-37). Every figure is ledger-core's (`project_figures`, +//! decisions and history (BS-statement-5). Every figure is ledger-core's (`project_figures`, //! `project_to_date`, `project_entries`), the same the server's //! `books.projects` and `books.project` return; this module only arranges //! them, and never writes. @@ -29,7 +29,7 @@ use rust_decimal::Decimal; pub struct State { /// Only projects with this status (None: every one). pub status: Option, - /// A project's snapshot shows this fiscal year to date (B-30's + /// A project's snapshot shows this fiscal year to date (BS-period-3's /// omitted dates), not to date. pub fiscal: bool, } @@ -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 (rules.md B-37 item 7), 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 (B-37 item 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`, @@ -730,7 +730,7 @@ pub struct PageFigures { /// The by-month chart's span ([`chart_span`]) and figures, when /// anything tagged is posted. pub months: Option<((NaiveDate, NaiveDate), ledger_core::ProjectFigures)>, - /// The fiscal year to date (B-30's omitted dates, as `books.project`), + /// The fiscal year to date (BS-period-3's omitted dates, as `books.project`), /// only when the snapshot shows it. pub year: Option, } diff --git a/crates/ledger-gui/src/pages/reports.rs b/crates/ledger-gui/src/pages/reports.rs index 4c5016e3..34fe33ba 100644 --- a/crates/ledger-gui/src/pages/reports.rs +++ b/crates/ledger-gui/src/pages/reports.rs @@ -24,7 +24,7 @@ use std::collections::BTreeMap; /// The range a report covers. The default (a report nobody chose dates /// for) is the fiscal year to date: what an omitted date means -/// everywhere (rules.md B-30, `Books::default_period`; a test pins that +/// everywhere (BS-period-3, `Books::default_period`; a test pins that /// they agree). #[derive(Clone, Copy, Debug, PartialEq, Eq, Default)] pub enum Range { @@ -408,7 +408,7 @@ fn column_ranges(st: &State, b: &Books) -> Vec<(NaiveDate, NaiveDate, String)> { /// The period compared against, if any: None too when it falls before /// chrono's first day (a range from the books' first entry, which an -/// earlier version may have dated there: rules.md B-28). +/// earlier version may have dated there: BS-entry-4). fn prior(st: &State, s: NaiveDate, e: NaiveDate) -> Option<(NaiveDate, NaiveDate)> { match st.compare { Compare::None => None, @@ -1079,7 +1079,7 @@ fn tax(b: &Books, s: NaiveDate, e: NaiveDate) -> Table { t } -/// A report the books can't compute (rules.md B-28: books an earlier +/// A report the books can't compute (BS-entry-4: books an earlier /// version wrote may hold amounts past exact arithmetic): no figures, and a /// note saying why, never a guess. fn cant_compute(mut t: Table, why: &ledger_core::LedgerError) -> Table { @@ -1518,8 +1518,8 @@ fn report(ui: &mut Ui, b: &Books, kind: ReportKind, shell: &mut Shell<'_>, picke let e = widgets::date_picker(ui, "to", e); // The human's own pickers: a "from" set past the "to" reads // as the two in order. Never a books.show target's dates: - // App::show takes only a resolved range in order (rules.md - // B-30) and ignores any other, so this never changes what the + // App::show takes only a resolved range in order ( + // BS-period-3) and ignores any other, so this never changes what the // agent was told the viewer shows. st.range = Range::Custom(s.min(e), e.max(s)); } @@ -1555,7 +1555,7 @@ fn report(ui: &mut Ui, b: &Books, kind: ReportKind, shell: &mut Shell<'_>, picke let (s, e) = st.range.dates(b); // A split over a range from the books' first entry, which an earlier - // version may have dated thousands of years back (rules.md B-28), + // version may have dated thousands of years back (BS-entry-4), // would be more columns than anyone can read or the frame can build: // shown as one total, with a note saying so. let split_note = splittable @@ -2282,8 +2282,8 @@ fn vendor_1099(ui: &mut Ui, b: &Books, year: i32, shell: &mut Shell<'_>) { let w = match b.vendor_1099_worksheet(year) { Ok(w) => w, Err(e) => { - // Never guess a threshold or the cash accounts (rules.md - // B-19): say why there's no worksheet, in the engine's words. + // Never guess a threshold or the cash accounts ( + // BS-1099-1): say why there's no worksheet, in the engine's words. ui.label(RichText::new(e).color(p.muted)); return; } @@ -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, rules.md B-14 rule 11); the members' + // and spent (D-42, BS-statement-3 rule 11); 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/src/widgets.rs b/crates/ledger-gui/src/widgets.rs index d4054601..de58a636 100644 --- a/crates/ledger-gui/src/widgets.rs +++ b/crates/ledger-gui/src/widgets.rs @@ -618,8 +618,8 @@ pub fn fit_font( /// A date picker for `d` (`id` its egui id salt), returning the date /// picked. The picker's calendar holds years -9999 through 9999; a date -/// outside them (books an earlier version wrote may hold one, rules.md -/// B-28) is shown as text and kept, never truncated into another year. +/// outside them (books an earlier version wrote may hold one, +/// BS-entry-4) is shown as text and kept, never truncated into another year. pub fn date_picker(ui: &mut Ui, id: &str, d: chrono::NaiveDate) -> chrono::NaiveDate { use chrono::Datelike; let jiff_date = i16::try_from(d.year()) diff --git a/crates/ledger-gui/tests/edges.rs b/crates/ledger-gui/tests/edges.rs index c7bf604a..d6417528 100644 --- a/crates/ledger-gui/tests/edges.rs +++ b/crates/ledger-gui/tests/edges.rs @@ -1,5 +1,5 @@ -//! The viewer's figures at the edges P0 review round 4 checked (rules.md -//! B-28): the party period of a year chrono can't hold, the party chart's +//! The viewer's figures at the edges P0 review round 4 checked ( +//! BS-entry-4): the party period of a year chrono can't hold, the party chart's //! last months, one party's part of a split entry, an amortization //! schedule due, and the page state tests set. //! diff --git a/crates/ledger-gui/tests/newer_journal.rs b/crates/ledger-gui/tests/newer_journal.rs index 905b3357..15d37fd7 100644 --- a/crates/ledger-gui/tests/newer_journal.rs +++ b/crates/ledger-gui/tests/newer_journal.rs @@ -4,7 +4,7 @@ //! ```text //! GOAL: Tobin, Mo or the CPA, on an older viewer, learn to update it, //! not that the books are damaged. -//! SOURCE: rules.md B-27; plan/served.md 5.1 (the viewer reads the journal +//! SOURCE: BS-format-1; plan/served.md 5.1 (the viewer reads the journal //! directly, so it meets the same gate). //! ``` @@ -66,7 +66,7 @@ fn rate() -> serde_json::Value { } /// The last line can't be checked: the viewer says so, and never that the -/// books are not damaged (rules.md B-27). +/// books are not damaged (BS-format-1). fn says_newer_or_damaged(text: &str) { assert!(text.starts_with("Journal line"), "{text}"); assert!(text.contains("or the line is damaged"), "{text}"); diff --git a/crates/ledger-gui/tests/odd_cent.rs b/crates/ledger-gui/tests/odd_cent.rs index ccb84816..702007be 100644 --- a/crates/ledger-gui/tests/odd_cent.rs +++ b/crates/ledger-gui/tests/odd_cent.rs @@ -141,7 +141,7 @@ fn a_members_page_shows_the_same_capital_before_and_after_a_close() { assert_eq!(closing, [Decimal::new(3, 2), Decimal::new(3, 2)]); } -/// A member's page in a yen book splits in whole yen (B-3, B-13), as the +/// A member's page in a yen book splits in whole yen (BS-ledger-1, BS-partner-1), as the /// closes and the statement do. Ann and Bo at 50% each. "Owed to them" /// (CapitalStatement INVARIANT 5): 101 yen due to the members, 50.5 each /// exactly, the tied yen to Ann, listed first: Ann 51, Bo 50. Property diff --git a/crates/ledger-gui/tests/old_books.rs b/crates/ledger-gui/tests/old_books.rs index 9569e8da..08d01551 100644 --- a/crates/ledger-gui/tests/old_books.rs +++ b/crates/ledger-gui/tests/old_books.rs @@ -1,11 +1,11 @@ //! Books an earlier wanderbooks wrote open in the viewer, and every page -//! renders over them, never a panic (rules.md B-28: posted is forever; a +//! renders over them, never a panic (BS-entry-4: posted is forever; a //! figure the books can't compute is said, never guessed). //! //! ```text //! GOAL: the viewer shows books written under older rules, whatever they //! hold that the commands now refuse. -//! SOURCE: rules.md B-28; DECISION (P0 review round 4: replay accepts what +//! SOURCE: BS-entry-4; DECISION (P0 review round 4: replay accepts what //! main 188c90ea accepted, and derived figures refuse rather than //! panic). //! INVARIANTS: @@ -508,7 +508,7 @@ fn books_that_keep_no_settings_read_no_file_beside_them() { } } -/// rules.md B-37: the classes an earlier version wrote read as projects +/// BS-statement-5: the classes an earlier version wrote read as projects /// with the default facts (active, kind not recorded), listed by name, /// their figures ledger-core's. #[test] diff --git a/crates/ledger-gui/tests/parties.rs b/crates/ledger-gui/tests/parties.rs index 4c684569..b4645385 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 (rules.md B-35 item 5): Due to + // What the members advanced is money (BS-partner-3 item 5): Due to // Shareholders is a financing account; the cash account stays the // books' (the settings file names both). journal_settings( @@ -353,10 +353,10 @@ fn each_partys_totals_are_the_books_numbers() { assert_eq!(sam.threshold_1099, Some(r.threshold)); // Cash counts (1,000 + the bill's 500); what the owner paid for the // company through the financing account waits on how they paid - // (rules.md B-19); the card's charge is no payment out of cash. + // (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 (B-35 item 9): the + // Party totals count all of it as paid to Sam (BS-partner-3 item 9): the // 1099's buckets, and the card's 200 (no business card is recorded, // so the worksheet lists it nowhere). assert_eq!( @@ -935,7 +935,7 @@ fn party_money_by_period_and_what_for() { assert_eq!(line.paid, cents(50_000)); // 2026: the cash 1,000 and the bill's 500 paid count; the owner's // 300 through the financing account waits on how it was paid - // (rules.md B-19); the card's 200 is no payment out of cash. + // (BS-1099-1); the card's 200 is no payment out of cash. let (line, _) = b.party_1099(f.sam, 2026).unwrap(); assert_eq!(line.paid, cents(150_000)); assert_eq!(line.undetermined, cents(30_000)); @@ -1270,7 +1270,7 @@ fn entries_list_every_party_with_its_resolved_share() { vec![(m.tobin, Some(cents(5_000))), (m.mo, Some(cents(5_000)))] ); assert_eq!(e.party.as_deref(), Some("Tobin Harlow & Morgan Ellis")); - // Property (rules.md B-35): what moved each member's capital, signed + // Property (BS-partner-3): what moved each member's capital, signed // as their own account shows it: received, in kind (before P3 it read // +600.00, the sign of a payment). let e = b.entry(m.property).unwrap(); @@ -1423,7 +1423,7 @@ fn show(dir: &Path, route: Route) -> Harness<'static, App> { h } -/// The viewer shows the tools' numbers (rules.md B-35): a member's party +/// The viewer shows the tools' numbers (BS-partner-3): a member's party /// flow is books.party's activity on both bases, labelled cash basis, with /// the in-kind line under it; the entry page says each part in words, a /// property contribution "received $600.00, in kind" and its reversal @@ -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 (rules.md B-35 item 3; design §1.4): a member +/// opposite of its original (BS-partner-3 item 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. @@ -1534,7 +1534,7 @@ fn a_reversed_member_card_payment_is_nothing_on_the_issuers_page() { assert_eq!(flow.what_for, vec![], "the breakdown nets to nothing"); } -/// Screenshots of the party pages and the entry pages B-35 changed, for +/// Screenshots of the party pages and the entry pages BS-partner-3 changed, for /// eyes: set `SHOT_DIR`. #[test] fn party_basis_screenshots() { diff --git a/crates/ledger-gui/tests/projects.rs b/crates/ledger-gui/tests/projects.rs index b0b3735e..faf13ee0 100644 --- a/crates/ledger-gui/tests/projects.rs +++ b/crates/ledger-gui/tests/projects.rs @@ -1,4 +1,4 @@ -//! Projects in the viewer (rules.md B-37): the list and a project's page +//! Projects in the viewer (BS-statement-5): the list and a project's page //! show ledger-core's figures; rows, links and bars open what they name; //! the journal, books.show and the party page know projects. @@ -603,7 +603,7 @@ fn a_long_party_name_keeps_to_its_card() { } } -// ------------------------------------------------- the snapshot (B-37 item 7) +// ------------------------------------------------- the snapshot (BS-statement-5 item 7) /// Books holding one project of `kind`, started `started_on`, with /// `posts`: (date, debit code, credit code, cents), the line that isn't @@ -991,7 +991,7 @@ fn the_chart_runs_from_the_start_or_first_entry_and_caps() { ); } -/// The fiscal year switch shows books.project's default period (B-30's +/// The fiscal year switch shows books.project's default period (BS-period-3's /// omitted dates: the fiscal year to date), and switching writes nothing. #[test] fn the_fiscal_year_switch_shows_the_default_period() { @@ -1253,7 +1253,7 @@ proptest::proptest! { } } -/// rules.md B-37 item 8: an invoice's or bill's page (its entry's) lists +/// BS-statement-5 item 8: 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. @@ -1372,8 +1372,8 @@ fn an_invoice_and_a_bill_show_each_lines_project() { } } -/// The demo's "Client work" project carries every client invoice (rules.md -/// B-37 item 8): its revenue to date is the invoices' total, its direct +/// 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 /// costs the contractors tagged to it. #[test] fn the_demos_client_work_counts_every_client_invoice() { diff --git a/crates/ledger-gui/tests/show.rs b/crates/ledger-gui/tests/show.rs index 10671ab7..235effcb 100644 --- a/crates/ledger-gui/tests/show.rs +++ b/crates/ledger-gui/tests/show.rs @@ -154,7 +154,7 @@ fn day(y: i32, m: u32, d: u32) -> chrono::NaiveDate { chrono::NaiveDate::from_ymd_opt(y, m, d).unwrap() } -/// Defect 15, repros 1.1.1-1.1.2 (rules.md B-30): a target the viewer +/// Defect 15, repros 1.1.1-1.1.2 (BS-period-3): a target the viewer /// can't honour is ignored whole, never swapped or guessed: a start after /// the end (an earlier writer's, or a hand-edited ops/show.jsonl), text /// that isn't a date, an unknown split or comparison. The page, the @@ -206,7 +206,7 @@ fn show_never_swaps_an_inverted_target_defect_15() { } } -/// Defect 16, repro 1.1.4 (rules.md B-30): a report target with only an +/// Defect 16, repro 1.1.4 (BS-period-3): a report target with only an /// end covers that end's fiscal year to it (2025-01-01 to 2025-06-30, not /// the swapped 2025-06-30 to 2026-01-01); with no dates, the default (the /// fiscal year to date, named "Year to date"); dates that are a preset's diff --git a/crates/ledger-gui/tests/spec_gui.rs b/crates/ledger-gui/tests/spec_gui.rs index b05dfb68..74189d9f 100644 --- a/crates/ledger-gui/tests/spec_gui.rs +++ b/crates/ledger-gui/tests/spec_gui.rs @@ -1065,7 +1065,7 @@ fn small_books(tag: &str) -> Small { .add_account("1000", "Checking", AccountType::Asset, None, false) .unwrap(); // Mapped to the return, so books with nothing else to do have - // nothing in Needs attention (rules.md B-32 lists every expense + // nothing in Needs attention (BS-ledger-11 lists every expense // account without a category, used or not). let rent = store .add_account_with_tax( diff --git a/crates/ledger-gui/tests/view_model.rs b/crates/ledger-gui/tests/view_model.rs index 83389aac..d513270c 100644 --- a/crates/ledger-gui/tests/view_model.rs +++ b/crates/ledger-gui/tests/view_model.rs @@ -84,7 +84,7 @@ fn build(plan: &Plan, tag: &str) -> (TestDir, Source, ledger_core::Ledger) { .collect(); // As replay posts them: random lines land on receivables and payables // by hand, as books an earlier version wrote can hold them (the - // control guard, rules.md B-38, refuses them as new work), and the + // control guard, BS-arap-2, refuses them as new work), and the // overview must still read them. ledger_core::parties::replaying(|| { for &(back, dr, cr, cents) in &plan.entries { @@ -169,7 +169,7 @@ proptest! { fy = fy - Months::new(12); } prop_assert_eq!(b.fiscal_ytd(), (fy, t)); - // One default period everywhere (rules.md B-30): what a report or + // One default period everywhere (BS-period-3): what a report or // register opens on is the fiscal year to date, the server's // resolver's own answer for no dates, and party totals count this // calendar year. @@ -700,7 +700,7 @@ fn more_origins_and_parties() { assert!(!r.missing_receipt, "a remittance isn't a hand-made entry"); } -/// Defect 8, repros 1.4.2 and 1.4.3 (rules.md B-32): Needs attention lists +/// Defect 8, repros 1.4.2 and 1.4.3 (BS-ledger-11): Needs attention lists /// every revenue and expense account without a tax category, with /// activity or not: one never used, one used only last fiscal year; never /// a header, an account with a category, or an asset. Info under warn, @@ -791,7 +791,7 @@ fn needs_attention_flags_every_uncategorized_pl_account_defect_8() { assert!(item(&b).is_none()); } -/// "Show all dates" is every date (P3 settled in design, rules.md B-30): +/// "Show all dates" is every date (P3 settled in design, BS-period-3): /// the register's and the reports' all-dates range runs from the first /// posted entry through the later of today and the last, so an entry /// dated after today is never left out of it (as party totals' "All time" diff --git a/crates/ledger-import/Cargo.toml b/crates/ledger-import/Cargo.toml index 7c675ac6..f476a06e 100644 --- a/crates/ledger-import/Cargo.toml +++ b/crates/ledger-import/Cargo.toml @@ -20,7 +20,7 @@ typst-layout = "0.15.1" qrcode = { version = "0.14.1", default-features = false, features = ["svg"] } # The reader (extract.rs moved out: D-61); re-exported as `extract`. ledger-reader = { path = "../ledger-reader" } -# BSD-3-Clause: the IIF's transliteration to ASCII (iif.rs, rules.md B-34). +# BSD-3-Clause: the IIF's transliteration to ASCII (iif.rs, BS-format-2). # Pinned exactly: a new table would change what a CPA's file says. deunicode = { version = "=1.6.0", default-features = false } diff --git a/crates/ledger-import/src/asset_register.rs b/crates/ledger-import/src/asset_register.rs index da6f743f..83987e3c 100644 --- a/crates/ledger-import/src/asset_register.rs +++ b/crates/ledger-import/src/asset_register.rs @@ -51,7 +51,7 @@ //! the tax table with its note's number. //! ``` //! -//! SOURCE (7-9): docs/spec/rules.md B-25; +//! SOURCE (7-9): BS-asset-4; //! docs/spec/sources/irs-partnership-basis.md. use crate::pdf::PdfError; diff --git a/crates/ledger-import/src/iif.rs b/crates/ledger-import/src/iif.rs index 1f99475b..db1d4e11 100644 --- a/crates/ledger-import/src/iif.rs +++ b/crates/ledger-import/src/iif.rs @@ -7,7 +7,7 @@ //! saying so. //! SOURCE: docs/spec/sources/intuit-iif.md (Intuit's IIF Overview, the IIF //! Import Kit's header help and its 2007+ General Journal example); -//! rules.md B-34; Intuit's "Character limitations for fields in +//! BS-format-2; Intuit's "Character limitations for fields in //! QuickBooks" (account name 31, account number 7, memo 4,095); //! DECISION (owner, 2026-10-20, plan D-36: plain ASCII, //! transliterated and listed; CR LF line endings); the kit's @@ -348,7 +348,7 @@ impl fmt::Display for IifChange { } } -/// `text` as a warning may show it (rules.md B-26: no full TIN): each run +/// `text` as a warning may show it (BS-partner-2: no full TIN): each run /// of nine digits `ledger_core::parties::has_full_tin` finds masked (in /// any script's digits and separators: "123-45-6789"), and if the /// text still holds one once written as a field, every numeral in it diff --git a/crates/ledger-import/src/report.rs b/crates/ledger-import/src/report.rs index 9f4d7567..35407a0f 100644 --- a/crates/ledger-import/src/report.rs +++ b/crates/ledger-import/src/report.rs @@ -183,7 +183,7 @@ fn account_lines(lines: &[StatementLine]) -> impl Iterator + '_ { /// /// ```text /// GOAL: the P&L as printed, footing. -/// SOURCE: docs/spec/rules.md B-14; footing (each column adds to its +/// SOURCE: BS-statement-3; footing (each column adds to its /// printed totals) is the reader's check on any statement. /// INVARIANTS: /// 1. Revenue lines sum to "Total revenue"; expense lines to "Total @@ -221,7 +221,7 @@ pub struct YearEarnings { /// /// ```text /// GOAL: the balance sheet as printed, footing and balancing. -/// SOURCE: rules.md B-7 (the accounting equation); footing. +/// SOURCE: BS-statement-2 (the accounting equation); footing. /// INVARIANTS: /// 1. Asset lines sum to "Total assets", liability lines to "Total /// liabilities", equity lines (accounts and the earnings lines) to the @@ -317,7 +317,7 @@ pub fn balance_sheet( ) } -/// Lay out a statement of cash flows, direct method (rules.md B-14, D-35): +/// Lay out a statement of cash flows, direct method (BS-statement-3, D-35): /// operating cash one row per class ASC 230-10-45-25 requires; investing /// and financing one row per kind ("Contributions from members — Name"), /// each with its total and its transactions listed under it; then the @@ -326,7 +326,7 @@ pub fn balance_sheet( /// /// ```text /// GOAL: the statement of cash flows as printed, footing and reconciling. -/// SOURCE: rules.md B-14 (ASC 230-10-45-24, -25, -29, -30; 50-3, 50-6: +/// SOURCE: BS-statement-3 (ASC 230-10-45-24, -25, -29, -30; 50-3, 50-6: /// the noncash schedule on the same page); D-35 (layout by kind). /// INVARIANTS: /// 1. The operating class rows sum to "Net cash from operating @@ -425,7 +425,7 @@ pub fn cash_flow(cf: &CashFlowStatement) -> Statement { /// /// ```text /// GOAL: the trial balance as printed, footing. -/// SOURCE: rules.md B-6 (the trial balance balances; B-1); footing. +/// SOURCE: BS-statement-1 (the trial balance balances; BS-entry-1); footing. /// INVARIANTS: /// 1. Each column's lines sum to its total; the totals are equal for /// balanced books. @@ -462,7 +462,7 @@ pub fn trial_balance(tb: &TrialBalance, as_of: NaiveDate) -> Statement { /// /// ```text /// GOAL: each member's capital roll-forward as printed. -/// SOURCE: rules.md B-13 (Form 1065 Schedule K-1, Item L); footing. +/// SOURCE: BS-partner-1 (Form 1065 Schedule K-1, Item L); footing. /// INVARIANTS: /// 1. In every column, beginning + contributions + net income + /// distributions (printed negative) + other = ending. diff --git a/crates/ledger-import/src/workpaper.rs b/crates/ledger-import/src/workpaper.rs index ea472acc..e3ebd3bf 100644 --- a/crates/ledger-import/src/workpaper.rs +++ b/crates/ledger-import/src/workpaper.rs @@ -1,4 +1,4 @@ -//! The audit workpaper as a PDF (plan P8; rules.md B-45). +//! The audit workpaper as a PDF (plan P8; BS-ledger-13). //! //! ```text //! GOAL: one document a CPA or the owner can read that says what was diff --git a/crates/ledger-import/tests/spec_import.rs b/crates/ledger-import/tests/spec_import.rs index be8333d8..1722141f 100644 --- a/crates/ledger-import/tests/spec_import.rs +++ b/crates/ledger-import/tests/spec_import.rs @@ -554,7 +554,7 @@ proptest! { } } - /// cash_flow INVARIANTS 1-5 (direct method, rules.md B-14, D-35): the + /// cash_flow INVARIANTS 1-5 (direct method, BS-statement-3, D-35): the /// operating class rows foot to "Net cash from operating activities", /// each other section's kind rows to theirs, and each kind's /// transaction details to its kind's row; the three sum to @@ -1637,7 +1637,7 @@ proptest! { let name = if name.trim().is_empty() { "x" } else { name.as_str() }; let parent = parent.map(|p| ids[p]); // Replayed, as books written before P3 hold them: a sibling's - // name, a tab, nine digits (rules.md B-31 refuses them in a + // name, a tab, nine digits (BS-ledger-10 refuses them in a // new name, never in a journaled one). ids.push(l.replay_add_account(&code_of(i), name, AccountType::Expense, parent, false).unwrap()); } @@ -2046,8 +2046,8 @@ fn iif_writes_plain_ascii_and_lists_every_change() { ("6050", "René 😀"), ("6070", "Wide number"), ] { - // Replayed: a tab in a name is refused in a new one (rules.md - // B-31), never in one books written before P3 hold. + // Replayed: a tab in a name is refused in a new one ( + // BS-ledger-10), never in one books written before P3 hold. l.replay_add_account(code, name, AccountType::Expense, None, false) .unwrap(); } @@ -2154,7 +2154,7 @@ fn iif_every_line_ends_cr_lf() { fn iif_distinct_accounts_never_share_a_name() { let mut l = Ledger::new(Currency::USD); // Replayed, as books written before P3 hold them: siblings of one - // name (rules.md B-31 refuses one in a new name, never in a journaled + // name (BS-ledger-10 refuses one in a new name, never in a journaled // one), which the file must still keep apart. let mut add = |code: &str, name: &str, parent: Option<&str>| { let p = parent.map(|c| l.chart().find_by_code(c).unwrap().id); @@ -2546,7 +2546,7 @@ fn iif_warnings_group_the_memos_by_what_is_written_differently() { ); } -/// INVARIANT 7: no warning holds a full TIN (rules.md B-26), though entry +/// INVARIANT 7: no warning holds a full TIN (BS-partner-2), though entry /// descriptions and account names aren't checked for one: a memo's TIN /// written with en dashes shows only the dashes; one in fullwidth digits, /// one in Arabic-Indic digits, and an account name holding one, are @@ -2557,7 +2557,7 @@ fn iif_warnings_group_the_memos_by_what_is_written_differently() { fn iif_warnings_never_hold_a_tin() { let (mut l, cash, rev, _) = small_ledger(); // Replayed, as books written before P3 hold them: a name holding a - // TIN, or a tab, is refused in a new name (rules.md B-31), never in a + // TIN, or a tab, is refused in a new name (BS-ledger-10), never in a // journaled one, so the file must still mask it. l.replay_add_account( "6300", @@ -4009,7 +4009,7 @@ fn tax_summary_difference_and_schedule_k() { ); } -/// A gain on business property (rules.md B-32; ledger_core::tax +/// A gain on business property (BS-ledger-11; ledger_core::tax /// `TaxSummary::form_4797`): on a Schedule C business's summary it is in /// its own Form 4797 section, at its book amount with no tax amount, and /// outside the net, never Schedule C income. @@ -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 (B-34 rules 3, 4): plain ASCII, a colon a '-' (a colon starts a +/// is (BS-format-2 rules 3, 4): 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/handbook/invoices-and-bills.md b/crates/ledger-mcp/handbook/invoices-and-bills.md index 371a6fed..0254c848 100644 --- a/crates/ledger-mcp/handbook/invoices-and-bills.md +++ b/crates/ledger-mcp/handbook/invoices-and-bills.md @@ -5,7 +5,7 @@ revenue its lines name. A bill is a vendor's invoice to us: it posts Dr the expense or asset its lines name, and Cr Accounts Payable. A document's own figures are read from the ledger lines tagged with it, never kept on the document: a reversed payment, a void or a write-off comes out right -without another copy to correct (B-38). +without another copy to correct (BS-arap-2). {documents_v2} @@ -17,7 +17,7 @@ without another copy to correct (B-38). An abandoned preview uses up no number. - Confirm with `confirmed: true` only after the human has seen it. The invoice posts Dr Accounts Receivable / Cr each line's account, takes the - next number (B-40), and the issued PDF, the page the customer gets, is + next number (BS-arap-4), and the issued PDF, the page the customer gets, is filed with it. That filed copy never changes: a later look at the invoice (`books.document` with `pdf: true`, or the viewer's Save invoice PDF) is a re-created copy as of that day, says so, and shows what has @@ -167,7 +167,7 @@ if it was reversed, that it no longer stands). tie the aging to the trial balance before the CPA asks). - Invoice numbers are unique and sequential, voids stay visible with their number, nothing is deleted. -- Every bill is coded to its real account (the Form 1065 lines, B-32), +- Every bill is coded to its real account (the Form 1065 lines, BS-ledger-11), never a catch-all, with the vendor's invoice attached and its number recorded, and no bill is paid twice (the same vendor and number twice is refused). diff --git a/crates/ledger-mcp/src/handbook.rs b/crates/ledger-mcp/src/handbook.rs index cefc8fe9..c26b5217 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 (rules.md B-27, B-37 item 8). +//! format upgrade (BS-format-1, BS-statement-5 item 8). //! ``` use crate::settings::Settings; @@ -175,7 +175,7 @@ pub fn section_with( .map(|(_, md)| render(md)) } -/// What omitted report dates mean (rules.md B-30), in the words every +/// What omitted report dates mean (BS-period-3), in the words every /// report tool's description uses (`ledger_core::calendar::PeriodKind`). pub fn period_rule() -> String { use ledger_core::calendar::PeriodKind; @@ -186,7 +186,7 @@ pub fn period_rule() -> String { ) } -/// How an invoice's or bill's lines reach a project (rules.md B-37 item +/// How an invoice's or bill's lines reach a project (BS-statement-5 item /// 8), for books that declared the journal feature /// `document_line_projects` or not yet (INVARIANT 6). pub fn document_projects_rule(declared: bool) -> &'static str { @@ -519,7 +519,7 @@ mod tests { assert!(!text.contains("{document_projects}"), "{id}"); assert!(!text.contains("{documents_v2}"), "{id}"); } - // The default period, in the descriptions' own words (B-30). + // The default period, in the descriptions' own words (BS-period-3). assert!( section("tracing-figures", &s, "USD", true) .unwrap() @@ -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 (B-37 item 8, D-43): one project or none a + // The owner's decision (BS-statement-5 item 8, 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/server.rs b/crates/ledger-mcp/src/server.rs index 42e7333f..fe3a7e61 100644 --- a/crates/ledger-mcp/src/server.rs +++ b/crates/ledger-mcp/src/server.rs @@ -618,14 +618,14 @@ impl BooksServer { self.store.currency.code() } - /// What omitted dates mean today, for these books (rules.md B-30): the + /// What omitted dates mean today, for these books (BS-period-3): the /// one resolver every report tool, `books.show` and the viewer use. fn periods(&self) -> ledger_core::calendar::PeriodDefaults { ledger_core::calendar::period_defaults(&self.settings().company, today()) } /// A period report's range: the dates as given, each omitted one the - /// default (rules.md B-30); a start after the end, given or derived, + /// default (BS-period-3); a start after the end, given or derived, /// is refused. fn statement_range( &self, @@ -635,7 +635,7 @@ impl BooksServer { ledger_package::statement_range(&self.settings().company, start, end, today()) } - /// A point-in-time report's day: as given, else today (rules.md B-30). + /// A point-in-time report's day: as given, else today (BS-period-3). fn as_of(&self, as_of: Option<&str>) -> Result { ledger_package::as_of_date(&self.settings().company, as_of, today()) } @@ -1021,7 +1021,7 @@ impl BooksServer { { return Ok(()); } - // A draft's debits may be past exact arithmetic (rules.md B-28): + // A draft's debits may be past exact arithmetic (BS-entry-4): // then the refusal says so in place of the sum. let (total, debits) = match ReceiptPolicy::entry_debits(entry) { Ok(t) => (money(t), t.to_string()), @@ -1136,7 +1136,7 @@ fn resolve_vendor(store: &Store, vendor: &str) -> Result { /// a refusal that quotes its input (an unknown party, a bad amount, a /// parameter of the wrong type) never echoes a TIN the agent put in the /// wrong field. No tool output, error, or log holds a full TIN -/// (docs/spec/rules.md B-26); a successful result is left alone, since +/// (BS-partner-2); a successful result is left alone, since /// the one that may (`books.vendor_1099` with `include_tins`) is one. fn redact_refusal( out: Result, @@ -1161,7 +1161,7 @@ fn redact_refusal( } } -/// An error with any full TIN in its message or data masked (B-26): a +/// An error with any full TIN in its message or data masked (BS-partner-2): a /// tool's, or a resource read's, which quotes the URI it was given. fn redact_error(mut e: rmcp::ErrorData) -> rmcp::ErrorData { use ledger_core::parties::{has_full_tin, redact_full_tins}; diff --git a/crates/ledger-mcp/src/server_tests.rs b/crates/ledger-mcp/src/server_tests.rs index 108dd4bd..28b6a973 100644 --- a/crates/ledger-mcp/src/server_tests.rs +++ b/crates/ledger-mcp/src/server_tests.rs @@ -807,7 +807,7 @@ fn every_tool_is_documented_and_every_documented_tool_exists() { assert_eq!(got, ["books.chart", "books.decisions", "books.open_items"]); } -/// rules.md B-30 (defect 16): every report tool says what its omitted +/// BS-period-3 (defect 16): every report tool says what its omitted /// dates mean in the one sentence the resolver's kind gives /// (PeriodKind::describe), and each date parameter in the schema's /// own words (START_DOC, END_DOC, AS_OF_DOC, YEAR_DOC); the two tools @@ -961,7 +961,7 @@ fn data_masked(text: &str) -> usize { text.matches("•••-••-••••").count() + text.matches("•••••••••").count() } -/// redact_error (B-26): every full TIN in an error's message and data +/// redact_error (BS-partner-2): every full TIN in an error's message and data /// is masked, wherever the data holds it (a string, in an array, in a /// nested object), and what holds none is left as it was. #[test] diff --git a/crates/ledger-mcp/src/tin_files.rs b/crates/ledger-mcp/src/tin_files.rs index 00cc29b9..5b2444c6 100644 --- a/crates/ledger-mcp/src/tin_files.rs +++ b/crates/ledger-mcp/src/tin_files.rs @@ -1,11 +1,11 @@ -//! Files that carry full TINs never enter the books (rules.md B-26). +//! Files that carry full TINs never enter the books (BS-partner-2). //! //! ```text //! GOAL: a file holding a full TIN (a W-9, a 1099 worksheet, a CPA //! package or a file from one) is never filed as a receipt or //! document, where books.get_receipt would hand its bytes to any //! agent. -//! SOURCE: rules.md B-26 (no tool output holds a full TIN); DECISION (P0 +//! SOURCE: BS-partner-2 (no tool output holds a full TIN); DECISION (P0 //! review round 2, 2026-10-16): one registry, on disk, of every //! TIN-bearing file the server reads or writes, and a scan of //! every text file on its way in. @@ -39,7 +39,7 @@ //! printed 2-7 (DECISION, owner, 2026-10-17: every company //! document goes into the books, and its formation papers, //! plans and letters print its EIN; the settings already hold it -//! in full, rules.md B-29). It is the company's, no person's: (a) +//! in full, BS-ledger-9). It is the company's, no person's: (a) //! still refuses it if the vault holds it for a party. //! Full-width digits and Unicode hyphens and spaces read as their //! ASCII kin. Refused bytes are never stored. @@ -68,7 +68,7 @@ //! answers for up to 2 candidates a filing (4): an agent that files //! 50,000 refused files can find a TIN, so the access log records //! every one of those calls and the probe bound keeps each answer -//! from telling more than two guesses apart (rules.md B-26). +//! from telling more than two guesses apart (BS-partner-2). //! ``` use std::path::Path; diff --git a/crates/ledger-mcp/src/tools/assets.rs b/crates/ledger-mcp/src/tools/assets.rs index 3278aec0..1d14f8a4 100644 --- a/crates/ledger-mcp/src/tools/assets.rs +++ b/crates/ledger-mcp/src/tools/assets.rs @@ -585,7 +585,7 @@ impl BooksServer { }; // One registration is several commands: rehearse them all on a // copy first, and ask for the journal feature the basis needs - // (B-27), so a refusal anywhere (the tag, the serial, the link, the + // (BS-format-1), so a refusal anywhere (the tag, the serial, the link, the // basis, books waiting for their format upgrade) journals nothing. { let mut copy = store.ledger().clone(); @@ -742,7 +742,7 @@ impl BooksServer { cost: money(a.cost.amount), useful_life_months: a.useful_life_months, // As of as_of, like every figure here: a disposal - // after it hasn't happened yet (rules.md B-33). + // after it hasn't happened yet (BS-statement-4). status: if disposed { "disposed" } else { "active" }.to_string(), held: acquired <= as_of && !disposed, accumulated_posted: figure(|r| r.accumulated_posted), diff --git a/crates/ledger-mcp/src/tools/attachments.rs b/crates/ledger-mcp/src/tools/attachments.rs index 9b6de1cd..09a2f01a 100644 --- a/crates/ledger-mcp/src/tools/attachments.rs +++ b/crates/ledger-mcp/src/tools/attachments.rs @@ -62,7 +62,7 @@ fn check_link_to( let sub = resolve_subject(store, s)?; // A link to a subject kind an older version doesn't know needs its // journal feature, asked here, before the file is filed: a refusal - // leaves nothing half-filed (rules.md B-27). + // leaves nothing half-filed (BS-format-1). if let Some(f) = Store::subject_feature(sub) { store.ensure_feature(f).map_err(|e| e.to_string())?; } diff --git a/crates/ledger-mcp/src/tools/audit.rs b/crates/ledger-mcp/src/tools/audit.rs index b878785b..0f0055d8 100644 --- a/crates/ledger-mcp/src/tools/audit.rs +++ b/crates/ledger-mcp/src/tools/audit.rs @@ -1,4 +1,4 @@ -//! The audit group (plan P8; rules.md B-45): an audit run over the books, +//! The audit group (plan P8; BS-ledger-13): an audit run over the books, //! its workpaper, and the claims that someone checked. //! //! ```text @@ -6,7 +6,7 @@ //! that gives the same findings and the same workpaper for the same //! books, and attestations that rest on a head that has not moved. //! SOURCE: IRS Pub. 583 (records); Rev. Proc. 98-25 §5.01 (the audit -//! trail); docs/spec/rules.md B-45; DECISION D-9 (the bar), D-53 +//! trail); BS-ledger-13; DECISION D-9 (the bar), D-53 //! (an audit is a run, not a job), IZ-1k (the head). //! INVARIANTS: //! 1. `books.audit` previews (what it will check; nothing changes), @@ -356,7 +356,7 @@ impl BooksServer { /// ```text /// GOAL: the whole programme of checks over the books through a day, /// its workpaper filed, the run journaled. - /// SOURCE: plan/served.md P8; B-45; D-9, D-53. + /// SOURCE: plan/served.md P8; BS-ledger-13; D-9, D-53. /// INVARIANTS: /// 1. Without `confirmed`, a preview that lists the checks and /// changes nothing; with it, the preview's digest is required. @@ -529,7 +529,7 @@ impl BooksServer { /// ```text /// GOAL: an audit run's workpaper, whole. - /// SOURCE: plan/served.md P8 step 3; B-45. + /// SOURCE: plan/served.md P8 step 3; BS-ledger-13. /// INVARIANTS: /// 1. Read-only; the JSON is the one filed, the PDF is handed over. /// ``` @@ -581,7 +581,7 @@ impl BooksServer { /// ```text /// GOAL: a checker's claim that a receipt supports an entry. - /// SOURCE: plan/served.md P8 step 4; B-45; D-9. + /// SOURCE: plan/served.md P8 step 4; BS-ledger-13; D-9. /// INVARIANTS: /// 1. The reading is compared with the entry's amount and date; a /// difference is recorded, marked, and never counts. @@ -619,7 +619,7 @@ impl BooksServer { /// ```text /// GOAL: a checker's claim that it reviewed an entry whole. - /// SOURCE: plan/served.md P8 step 4; B-45. + /// SOURCE: plan/served.md P8 step 4; BS-ledger-13. /// ``` #[tool( name = "books.review_entry", @@ -649,7 +649,7 @@ impl BooksServer { /// ```text /// GOAL: a checker's claim that a period is right, resting on an /// audit run at the books' current head. - /// SOURCE: plan/served.md P8 step 4; B-45; D-9; IZ-1k. + /// SOURCE: plan/served.md P8 step 4; BS-ledger-13; D-9; IZ-1k. /// INVARIANTS: /// 1. Refused unless an audit through the period's end stands at /// the current head. @@ -697,7 +697,7 @@ impl BooksServer { /// ```text /// GOAL: every claim that someone checked, and whether it counts. - /// SOURCE: plan/served.md P8 step 4; B-45; D-9. + /// SOURCE: plan/served.md P8 step 4; BS-ledger-13; D-9. /// INVARIANTS: /// 1. `counted` is read against the bar as it stands now. /// ``` diff --git a/crates/ledger-mcp/src/tools/chart.rs b/crates/ledger-mcp/src/tools/chart.rs index 0efb56e6..7b0f8b57 100644 --- a/crates/ledger-mcp/src/tools/chart.rs +++ b/crates/ledger-mcp/src/tools/chart.rs @@ -241,8 +241,8 @@ impl BooksServer { let mut store = self.lock()?; let id = resolve_account(&store, &p.account)?; let reason = p.reason.as_deref().map(str::trim).filter(|r| !r.is_empty()); - // The sets the books pick by name, before and after (rules.md - // B-31: a rename moves no amount, but it can move an account into + // The sets the books pick by name, before and after ( + // BS-ledger-10: a rename moves no amount, but it can move an account into // or out of one of these). let configured_cash = self.settings().roles.cash.clone(); let picked = |ledger: &Ledger| { diff --git a/crates/ledger-mcp/src/tools/documents.rs b/crates/ledger-mcp/src/tools/documents.rs index c5cc3eda..f5320020 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 (rules.md B-37 items 4, 5 and 8). +/// an on-spec project (BS-statement-5 items 4, 5 and 8). fn document_notes( ledger: &ledger_core::Ledger, lines: &[DocumentLine], @@ -157,7 +157,7 @@ fn resolve_vendor_arg(store: &Store, vendor: &str) -> Result { /// Whether these books declared the journal feature `documents_v2`: the /// bills and invoices carrying a number, terms, snapshots, references, a -/// line's account or a quantity need it (rules.md B-27, D-52), and the +/// line's account or a quantity need it (BS-format-1, D-52), and the /// bill rules A-10, A-13 and the file apply only where it is declared. fn documents_v2(store: &Store) -> bool { store diff --git a/crates/ledger-mcp/src/tools/drafts.rs b/crates/ledger-mcp/src/tools/drafts.rs index 0688611c..92ce0bab 100644 --- a/crates/ledger-mcp/src/tools/drafts.rs +++ b/crates/ledger-mcp/src/tools/drafts.rs @@ -1,4 +1,4 @@ -//! The drafts group (plan P4; rules.md B-43): which drafts are open and +//! The drafts group (plan P4; BS-entry-5): which drafts are open and //! what they wait for, a draft's state, throwing one away, and the full //! preview of the post. Also what every report says is still open as of //! its end (`as_of_status`) and the open-draft refusal of the CPA package. @@ -7,7 +7,7 @@ //! GOAL: a draft is never lost and never mistaken for a posted entry; a //! report or a package says when drafts dated in it are missing //! from its figures. -//! SOURCE: docs/spec/rules.md B-43; plan/served.md 4.8, D-47. +//! SOURCE: BS-entry-5; plan/served.md 4.8, D-47. //! INVARIANTS: //! 1. A state is a note on the draft: no figure moves. //! 2. A discard is previewed, then confirmed with the preview's digest; diff --git a/crates/ledger-mcp/src/tools/entries.rs b/crates/ledger-mcp/src/tools/entries.rs index 6e3c7fb8..a432c28a 100644 --- a/crates/ledger-mcp/src/tools/entries.rs +++ b/crates/ledger-mcp/src/tools/entries.rs @@ -234,7 +234,7 @@ impl BooksServer { // A payment method exists only in books that declare the // payment_instruments feature (books.add_instrument needs it), so // tagging the draft with one below can't be refused for the format - // after the draft's first line (B-27). + // after the draft's first line (BS-format-1). let id = store .create_entry(date, &p.description) .map_err(|e| e.to_string())?; @@ -595,7 +595,7 @@ impl BooksServer { .iter() .map(|l| { // A draft line an earlier version journaled may name an - // account the chart doesn't have (rules.md B-28). + // account the chart doesn't have (BS-entry-4). let (code, name) = match store.ledger().chart().get(l.account) { Some(a) => (a.code.clone(), a.name.clone()), None => (String::new(), format!("(no account {})", l.account)), @@ -851,7 +851,7 @@ mod tests { /// lines_settled: posted, or a draft with lines whose debits equal its /// credits; a draft whose sides are past exact arithmetic (one an - /// earlier version journaled, rules.md B-28) is not settled. + /// earlier version journaled, BS-entry-4) is not settled. #[test] fn settled_lines_are_posted_or_balanced_drafts() { let mut l = Ledger::new(Currency::USD); diff --git a/crates/ledger-mcp/src/tools/evidence.rs b/crates/ledger-mcp/src/tools/evidence.rs index f2ebd41c..f6e69123 100644 --- a/crates/ledger-mcp/src/tools/evidence.rs +++ b/crates/ledger-mcp/src/tools/evidence.rs @@ -7,7 +7,7 @@ //! wherever they are evidence. //! SOURCE: plan/served.md P6 step 4 (defect 4) and step 5 (defect 10); //! IZ-18 (no FIFO guess: `entry.settles` only); Rev. Proc. 98-25 -//! (an audit trail); rules.md B-44. +//! (an audit trail); BS-ledger-12. //! ``` use super::*; @@ -23,7 +23,7 @@ impl BooksServer { /// ```text /// GOAL: find a filed file by its exact bytes, its receipt number, or /// what its text says. - /// SOURCE: plan/served.md P6 step 4; B-44. + /// SOURCE: plan/served.md P6 step 4; BS-ledger-12. /// INVARIANTS: /// 1. EXACTLY one of sha256, receipt_number and text is given. /// 2. Withdrawn files are listed too, marked (a duplicate is found @@ -96,7 +96,7 @@ impl BooksServer { /// ```text /// GOAL: record what a human read off a file, without touching the file /// or the ledger's amounts. - /// SOURCE: plan/served.md P6 step 5 (defect 10); B-44. + /// SOURCE: plan/served.md P6 step 5 (defect 10); BS-ledger-12. /// INVARIANTS: /// 1. Journaled as `attachment.annotated`; a refusal journals nothing. /// 2. The fields are the closed list of `AnnotationFieldsParam`; at @@ -206,7 +206,7 @@ impl BooksServer { /// GOAL: hold identical files once, linked wherever they were evidence, /// without ever leaving an entry the receipt policy covers with /// none. - /// SOURCE: plan/served.md P6 step 4 (defect 4); rules.md B-44. + /// SOURCE: plan/served.md P6 step 4 (defect 4); BS-ledger-12. /// INVARIANTS: /// 1. Records sharing one blob SHA are one set; the oldest is kept /// and linked to every subject the others had. diff --git a/crates/ledger-mcp/src/tools/helpers.rs b/crates/ledger-mcp/src/tools/helpers.rs index 967ad867..bbcd608d 100644 --- a/crates/ledger-mcp/src/tools/helpers.rs +++ b/crates/ledger-mcp/src/tools/helpers.rs @@ -57,7 +57,7 @@ pub(crate) fn receipt_required_text(e: StoreError, policy: &ReceiptPolicy) -> St split_group ) }; - // A draft's debits may be past exact arithmetic (rules.md B-28): then + // A draft's debits may be past exact arithmetic (BS-entry-4): then // the refusal says so in place of the sum. let (total, debits) = match debits { Some(t) => (money(t), t.to_string()), @@ -140,7 +140,7 @@ pub(crate) fn settings_problems(ledger: &Ledger, cfg: &Settings) -> Vec // Named as the books keep them. 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 (rules.md B-14 + // engine's own check, the one the statement refuses on (BS-statement-3 // rule 2), so the two never disagree. let lists = [ ( @@ -455,7 +455,7 @@ pub(crate) fn optional_text(s: &str) -> Option { /// The sum of `values`, each computed or refused: refused (as text) when /// one is, or when the sum is past exact arithmetic. Figures an earlier -/// version journaled are as journaled (rules.md B-28). +/// version journaled are as journaled (BS-entry-4). pub(crate) fn checked_sum( values: impl IntoIterator>, what: &str, @@ -541,7 +541,7 @@ pub(crate) fn lines_settled(entry: &JournalEntry) -> bool { if entry.status() == ledger_core::EntryStatus::Posted { return true; } - // A draft's lines are as journaled, of any size (rules.md B-28): sides + // A draft's lines are as journaled, of any size (BS-entry-4): sides // past exact arithmetic are not settled lines. let side = |s: Side| -> Option { entry @@ -644,13 +644,13 @@ pub(crate) fn resolve_class(store: &Store, class: &str) -> Result { } /// A tool description that ends with the one sentence for its kind of -/// dates (rules.md B-30), so no tool says other than the resolver does. +/// dates (BS-period-3), so no tool says other than the resolver does. pub(crate) fn described(what: &str, kind: ledger_core::calendar::PeriodKind) -> String { format!("{what} {}", kind.describe()) } /// The warning for a revenue or expense account created without a tax -/// category (rules.md B-32). +/// category (BS-ledger-11). pub(crate) fn uncategorized_warning(code: &str, name: &str) -> String { format!( "{} {} has no tax category: the tax summary will list it as uncategorized. Propose one from books.tax_categories and set it with books.set_tax_category once the human agrees.", diff --git a/crates/ledger-mcp/src/tools/instruments.rs b/crates/ledger-mcp/src/tools/instruments.rs index fd67ad55..0c870338 100644 --- a/crates/ledger-mcp/src/tools/instruments.rs +++ b/crates/ledger-mcp/src/tools/instruments.rs @@ -7,7 +7,7 @@ //! ```text //! GOAL: the agent records how each payment was made and why each vendor //! does or doesn't get a 1099, and the worksheet never guesses. -//! SOURCE: docs/spec/rules.md B-19 (Treas. Reg. §1.6041-1(a)(1)(iv), +//! SOURCE: BS-1099-1 (Treas. Reg. §1.6041-1(a)(1)(iv), //! §1.6041-3; sources/irs-1099-payment-method.md); plan/served.md //! 4.9; DECISION D-40 (owner, 2026-10-20). //! INVARIANTS: diff --git a/crates/ledger-mcp/src/tools/kept.rs b/crates/ledger-mcp/src/tools/kept.rs index ea59a77b..b4ff7aa7 100644 --- a/crates/ledger-mcp/src/tools/kept.rs +++ b/crates/ledger-mcp/src/tools/kept.rs @@ -924,7 +924,7 @@ impl BooksServer { due: i.new.due.map(|d| d.to_string()), }) .collect(); - // The projects under way, by name (rules.md B-37): at most 20. + // The projects under way, by name (BS-statement-5): at most 20. const START_PROJECTS: usize = 20; let mut projects: Vec = ledger .list_classes() diff --git a/crates/ledger-mcp/src/tools/parties.rs b/crates/ledger-mcp/src/tools/parties.rs index 854e8f8f..7f5d07e8 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" -/// (rules.md B-35 item 4); any other word is refused. +/// (BS-partner-3 item 4); any other word is refused. fn parse_basis(basis: Option<&str>) -> Result { match basis { None => Ok(ledger_core::parties::Basis::default()), @@ -589,7 +589,7 @@ impl BooksServer { fields.push(F::Email(optional_text(&v))); } // "" clears the terms; any other text is trade terms this party - // grants or is granted (B-39). + // grants or is granted (BS-arap-3). let terms = |v: String| -> Result, String> { if v.trim().is_empty() { return Ok(None); @@ -653,7 +653,7 @@ impl BooksServer { .map_err(|e| e.to_string())?; } // The journal features these lines need, asked for before this - // command's first line, never between its lines (rules.md B-27: + // command's first line, never between its lines (BS-format-1: // books waiting for their format upgrade must not be left with the // name changed and the rest not). if fields.iter().any(|f| f.needs_documents_v2()) { @@ -749,7 +749,7 @@ impl BooksServer { /// GOAL: the books know a W-9 arrived and what it said, and the full /// TIN (and the form, which shows it) is kept where it can be /// handed to the CPA and purged, never in the journal. - /// SOURCE: docs/parties-and-attachments.md "The TIN vault"; B-26; + /// SOURCE: docs/parties-and-attachments.md "The TIN vault"; BS-partner-2; /// Treas. Reg. §301.6109-4 (truncated TINs); DECISION (owner, /// 2026-10-15): full TINs only in the encrypted vault. /// INVARIANTS: @@ -852,7 +852,7 @@ impl BooksServer { let existing = store.ledger().get_party(id).and_then(|p| p.w9.clone()); let party_tin = store.ledger().get_party(id).and_then(|p| p.tin.clone()); // A new TIN with another last four replaces the party's TIN facts: - // cleared first, so the two never disagree on the record (B-26). + // cleared first, so the two never disagree on the record (BS-partner-2). let replace_tin = tin .as_ref() .is_some_and(|t| party_tin.as_ref().is_some_and(|pt| pt.last4 != t.last4())); @@ -956,7 +956,7 @@ impl BooksServer { let on_file = facts.is_some(); // The vendor record's W-9 flag follows (below): its feature is // asked for before this command's first line, never after it - // (B-27: books waiting for their format upgrade must not be left + // (BS-format-1: books waiting for their format upgrade must not be left // with the W-9 recorded and the flag not). let vendor = store.ledger().get_party(id).and_then(|p| p.vendor); if vendor @@ -991,7 +991,7 @@ impl BooksServer { /// GOAL: any party's full TIN (a member's SSN for their K-1, a payee's /// from their W-9) kept where the CPA package can carry it, and /// nowhere else. - /// SOURCE: docs/parties-and-attachments.md "The TIN vault"; B-26; + /// SOURCE: docs/parties-and-attachments.md "The TIN vault"; BS-partner-2; /// DECISION (owner, 2026-10-15): "In the vault, that's the /// WHOLE reason we built it. And it needs to be in the damn CPA /// package." @@ -1407,7 +1407,7 @@ impl BooksServer { .vendor .and_then(|v| ledger.get_vendor(v)) .map(|v| v.decision_on(today()).cloned().unwrap_or_default()); - // Documents and runs are restored as journaled (rules.md B-28): a + // Documents and runs are restored as journaled (BS-entry-4): a // total past exact arithmetic refuses the answer, never a panic. let mut payroll = Vec::new(); let (mut gross, mut net) = (Decimal::ZERO, Decimal::ZERO); diff --git a/crates/ledger-mcp/src/tools/payroll.rs b/crates/ledger-mcp/src/tools/payroll.rs index 2155b8c1..fea8bbe4 100644 --- a/crates/ledger-mcp/src/tools/payroll.rs +++ b/crates/ledger-mcp/src/tools/payroll.rs @@ -146,7 +146,7 @@ impl BooksServer { .list_payroll_runs() .into_iter() .map(|r| { - // A run is as journaled (rules.md B-28): a total past exact + // A run is as journaled (BS-entry-4): a total past exact // arithmetic refuses the list, never a panic. let total_gross = checked_sum(r.lines.iter().map(|l| Ok(l.gross_pay)), "gross pay")?; diff --git a/crates/ledger-mcp/src/tools/periods.rs b/crates/ledger-mcp/src/tools/periods.rs index 4e3e7477..469afd72 100644 --- a/crates/ledger-mcp/src/tools/periods.rs +++ b/crates/ledger-mcp/src/tools/periods.rs @@ -66,7 +66,7 @@ impl BooksServer { }) .collect() }; - // The members' split, from the closed ledger (rules.md B-13). + // The members' split, from the closed ledger (BS-partner-1). let split = |ledger: &Ledger| -> Option { let (since_close, parts) = ledger.member_close_split(p.period_id)?; let names = self.member_capitals(ledger).unwrap_or_default(); diff --git a/crates/ledger-mcp/src/tools/projects.rs b/crates/ledger-mcp/src/tools/projects.rs index fdc7693a..b33fe568 100644 --- a/crates/ledger-mcp/src/tools/projects.rs +++ b/crates/ledger-mcp/src/tools/projects.rs @@ -1,15 +1,15 @@ //! Projects through the server: `books.add_project`, -//! `books.update_project`, `books.projects` and `books.project` (rules.md -//! B-37). A project is a class with its facts: `books.add_line`'s class +//! `books.update_project`, `books.projects` and `books.project` ( +//! BS-statement-5). A project is a class with its facts: `books.add_line`'s class //! tags a line with it, and every class tool keeps working. //! //! ```text //! GOAL: the agent records what each project is and links what belongs to //! it; anyone reads what it earned and cost from the same figures //! the viewer and bookspec use. -//! SOURCE: docs/spec/rules.md B-37 (DECISION, owner, 2026-10-21; job -//! costing; ASC 450-30-25-1 for on-spec work), B-30 (omitted -//! dates), B-27 (journal feature `projects`). +//! SOURCE: BS-statement-5 (DECISION, owner, 2026-10-21; job +//! costing; ASC 450-30-25-1 for on-spec work), BS-period-3 (omitted +//! dates), BS-format-1 (journal feature `projects`). //! INVARIANTS: //! 1. Every field is checked before anything is written; a refusal //! journals nothing. @@ -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 (rules.md B-37 item 5). +/// abandoned project (BS-statement-5 item 5). 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 (rules.md B-37 items 4 and 8): on spec, a hoped-for payment is +/// project (BS-statement-5 items 4 and 8): 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 e4e975b4..1062aad9 100644 --- a/crates/ledger-mcp/src/tools/reports.rs +++ b/crates/ledger-mcp/src/tools/reports.rs @@ -549,7 +549,7 @@ impl BooksServer { .chart() .find_by_code(&code) .ok_or_else(|| format!("unknown account {code}"))?; - // The dates resolved (rules.md B-30), sent as resolved, so what + // The dates resolved (BS-period-3), sent as resolved, so what // the agent is told and what the viewer shows can't differ. let (s, e) = self .periods() @@ -728,7 +728,7 @@ impl BooksServer { if let Some(n) = blobs { checked.push(format!("{n} stored files match their SHA-256")); } - // Receivables and payables equal their documents (rules.md B-38 + // Receivables and payables equal their documents (BS-arap-2 // INVARIANT 1): an identity, so a difference is an engine error. let checks = store .ledger() @@ -956,8 +956,8 @@ impl BooksServer { return Err("iif takes as_of, not start or end: the file holds every posted entry from the first through as_of, so QuickBooks' balances match the books'".to_string()); } // As of today by default, like every other as-of export - // (rules.md B-30); never a period, so the general journal's - // default period never shortens it (D-36, B-34). + // (BS-period-3); never a period, so the general journal's + // default period never shortens it (D-36, BS-format-2). let as_of = self.as_of(p.as_of.as_deref())?; let iif = self.export_iif(as_of, &p.cash_accounts)?; let warnings = iif.warnings(); @@ -1044,7 +1044,7 @@ impl BooksServer { expenses: Decimal, } let mut by_class: HashMap, Acc> = HashMap::new(); - // A closing entry isn't income or spending (rules.md B-11): left + // A closing entry isn't income or spending (BS-period-1): left // out, as profit_and_loss_for_period leaves it out (found by // pnl_by_class_excludes_closing_entries, 2026-10-14). let closings = ledger.closing_entry_ids(); @@ -1114,7 +1114,7 @@ impl BooksServer { /// GOAL: everything the CPA needs for the return in one zip, the K-1s' /// and 1099s' TINs included, without a full TIN ever landing in /// the books (a git repository) or the conversation. - /// SOURCE: docs/mcp-interface.md; B-26; DECISION (owner, + /// SOURCE: docs/mcp-interface.md; BS-partner-2; DECISION (owner, /// 2026-10-15): "it needs to be in the damn CPA package." /// INVARIANTS: /// 1. The zip is handed over (tools/files.rs INVARIANT 6: an export @@ -1516,7 +1516,7 @@ impl BooksServer { ledger_package::export_iif(store.ledger(), cash, as_of) } /// The general journal as JSON or CSV: each entry posted in the - /// period (rules.md B-30, as the XLSX journal), in posting order. + /// period (BS-period-3, as the XLSX journal), in posting order. fn export_journal(&self, format: &str, p: &ExportParams) -> Result { let (start, end) = self.statement_range(p.start.as_deref(), p.end.as_deref())?; let store = self.lock()?; diff --git a/crates/ledger-mcp/src/tools/schedules.rs b/crates/ledger-mcp/src/tools/schedules.rs index ed28cb2f..260b8d04 100644 --- a/crates/ledger-mcp/src/tools/schedules.rs +++ b/crates/ledger-mcp/src/tools/schedules.rs @@ -6,7 +6,7 @@ use super::*; fn schedule_out(ledger: &Ledger, s: &ledger_core::AmortizationSchedule) -> ScheduleOut { // A schedule an earlier version journaled may run past the last date - // chrono holds (rules.md B-28): shown, with why its plan can't be. + // chrono holds (BS-entry-4): shown, with why its plan can't be. let plan = s.plan(); let code = |id| { ledger diff --git a/crates/ledger-mcp/src/tools/settlements.rs b/crates/ledger-mcp/src/tools/settlements.rs index 8806f052..73959f8e 100644 --- a/crates/ledger-mcp/src/tools/settlements.rs +++ b/crates/ledger-mcp/src/tools/settlements.rs @@ -1,5 +1,5 @@ //! `books.receive_payment`, `books.pay_bill`, `books.bills_due` and the -//! agings: paying on terms (plan P4b S6; rules.md B-42). A payment settles +//! agings: paying on terms (plan P4b S6; BS-arap-6). A payment settles //! one or several invoices (or bills) of one party, with the early-payment //! discounts their terms allow and the processor's fee on a customer //! payment posted gross. Split from `tools/documents.rs` so S4.4's work @@ -247,7 +247,7 @@ fn settlement( } /// What a payment settled: each document's figures after it (derived from -/// its lines that stand, rules.md B-38) and what reached or left the +/// its lines that stand, BS-arap-2) and what reached or left the /// account. fn payment_out( ledger: &Ledger, diff --git a/crates/ledger-mcp/src/tools/write_offs.rs b/crates/ledger-mcp/src/tools/write_offs.rs index a4a47d07..3e566035 100644 --- a/crates/ledger-mcp/src/tools/write_offs.rs +++ b/crates/ledger-mcp/src/tools/write_offs.rs @@ -1,12 +1,12 @@ -//! `books.write_off_invoice`'s group: bad debts (plan P4b S7; rules.md -//! B-41). A file of its own (plan 8.2 U0a) so S4.4's document tools and +//! `books.write_off_invoice`'s group: bad debts (plan P4b S7; +//! BS-arap-5). A file of its own (plan 8.2 U0a) so S4.4's document tools and //! this one land apart: a tool is added to its group's file and nowhere //! else. use super::*; /// An invoice's figures after a write-off, as the tool answers them: read -/// from its tagged lines that stand (rules.md B-38), at the end of the +/// from its tagged lines that stand (BS-arap-2), at the end of the /// books. fn write_off_out( ledger: &Ledger, @@ -50,7 +50,7 @@ impl BooksServer { let date = parse_date(&p.date)?; let mut store = self.lock()?; // The event type is new: books that haven't declared documents_v2 - // refuse it with the upgrade remedy, journaling nothing (B-27). + // refuse it with the upgrade remedy, journaling nothing (BS-format-1). store .ensure_feature(ledger_store::format::DOCUMENTS_V2) .map_err(|e| e.to_string())?; @@ -65,7 +65,7 @@ impl BooksServer { Some(a) => parse_amount(a)?, None => owed, }; - // The evidence is the point of a write-off (B-41 INVARIANT 1): one + // The evidence is the point of a write-off (BS-arap-5 INVARIANT 1): 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 60cfda8b..1f7862f2 100644 --- a/crates/ledger-mcp/src/types.rs +++ b/crates/ledger-mcp/src/types.rs @@ -3329,7 +3329,7 @@ pub struct CreateBillParams { pub confirmed: Option, } -/// One invoice or bill a payment applies to (plan P4b S6; B-42). +/// One invoice or bill a payment applies to (plan P4b S6; BS-arap-6). #[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] #[serde(deny_unknown_fields)] pub struct PaymentApplicationParam { @@ -3763,8 +3763,8 @@ pub struct AgingDocumentOut { pub days_overdue: i64, } -/// The aging's account against its documents (the control check, B-23, -/// B-38 INVARIANT 1). +/// The aging's account against its documents (the control check, BS-ledger-8, +/// BS-arap-2 INVARIANT 1). #[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] pub struct AgingControlOut { /// "1200 Accounts Receivable" or "2000 Accounts Payable". @@ -4015,7 +4015,7 @@ pub struct ListClassesOut { } // --------------------------------------------------------------------------- -// Projects (a class with its facts, rules.md B-37) +// Projects (a class with its facts, BS-statement-5) // --------------------------------------------------------------------------- // // A `project` reference is a class's id or its name (ignoring capitals), diff --git a/crates/ledger-package/src/aging.rs b/crates/ledger-package/src/aging.rs index 2d842db2..ef3c6d61 100644 --- a/crates/ledger-package/src/aging.rs +++ b/crates/ledger-package/src/aging.rs @@ -1,5 +1,5 @@ //! The receivables and payables agings as files (plan P4b S6, 8.3.10; -//! rules.md B-18, B-23): one row per open document, and a tie-out line +//! BS-arap-1, BS-ledger-8): one row per open document, and a tie-out line //! against the control account. The server's `books.export` and the CPA //! package build the same CSV from this, and its XLSX/PDF from //! [`aging_statement`], so a CPA's two copies can't differ. diff --git a/crates/ledger-package/src/attention.rs b/crates/ledger-package/src/attention.rs index e9caa242..30715f15 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 (rules.md B-14 rule 12: equipment sold for +//! statement of cash flows (BS-statement-3 rule 12: 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 @@ -87,7 +87,7 @@ //! 3. Nothing else: books with none of those yield no items, except //! that a figure behind an item that can't be computed (an //! amortization plan past chrono's last day, an aging past exact -//! arithmetic: books an earlier version wrote, rules.md B-28) is one +//! arithmetic: books an earlier version wrote, BS-entry-4) is one //! Problem item saying so, never a panic or a guess. //! 4. Every item's prompt starts "In wanderbooks," or names //! wanderbooks, and its amounts are the books' exact amounts. @@ -477,7 +477,7 @@ pub fn find_with( } // Every revenue and expense account (not a header) without a tax - // category, with activity or not (rules.md B-32): the one list the + // category, with activity or not (BS-ledger-11): the one list the // digest gives the agent too. let uncategorized: Vec = ledger_core::tax::uncategorized_accounts(ledger) .into_iter() @@ -1341,8 +1341,8 @@ pub fn find_with( }); } - // The statement of cash flows' warnings this fiscal year (rules.md - // B-14 rule 12, D-35): equipment sold for an IOU, flagged with its fix + // 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 // (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. @@ -1867,7 +1867,7 @@ fn paid_this_year( a.paid - a.received } -/// A figure the books can't compute (rules.md B-28: books an earlier +/// A figure the books can't compute (BS-entry-4: books an earlier /// version wrote may hold dates past chrono's calendar or amounts past /// exact arithmetic): a Problem saying so and why, never a guess. fn cant_compute(what: String, why: &LedgerError, target: Target) -> Attention { diff --git a/crates/ledger-package/src/iif.rs b/crates/ledger-package/src/iif.rs index 9f7fc065..561913c2 100644 --- a/crates/ledger-package/src/iif.rs +++ b/crates/ledger-package/src/iif.rs @@ -5,8 +5,8 @@ //! GOAL: the CPA imports the books through a day into QuickBooks Desktop, //! each account declared with the type QuickBooks needs, and gets //! the balances and the profit of the package's statements. -//! SOURCE: ledger_import::iif (the IIF format and account types); rules.md -//! B-33 (as of a day), B-34; DECISION (owner, 2026-10-20, plan +//! SOURCE: ledger_import::iif (the IIF format and account types); +//! BS-statement-4 (as of a day), BS-format-2; DECISION (owner, 2026-10-20, plan //! D-36: closing entries are left out). //! INVARIANTS: //! 1. The cash accounts are BANK; the receivable and payable control @@ -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 (rules.md B-34 rule 8). +//! carries its class (BS-format-2 rule 8). //! ``` use chrono::NaiveDate; diff --git a/crates/ledger-package/src/invoice.rs b/crates/ledger-package/src/invoice.rs index dcae8ae2..7c616a03 100644 --- a/crates/ledger-package/src/invoice.rs +++ b/crates/ledger-package/src/invoice.rs @@ -4,7 +4,7 @@ //! //! ```text //! GOAL: print an invoice from the books, as of a day. -//! SOURCE: plan/served.md P4b.11 (the "current" version); rules.md B-38 +//! SOURCE: plan/served.md P4b.11 (the "current" version); BS-arap-2 //! (a document's figures are its lines that stand). //! INVARIANTS: //! 1. Its figures are the invoice's derived state as of the day (as of diff --git a/crates/ledger-package/src/k1_tax.rs b/crates/ledger-package/src/k1_tax.rs index 5c14f5c4..d9776b35 100644 --- a/crates/ledger-package/src/k1_tax.rs +++ b/crates/ledger-package/src/k1_tax.rs @@ -7,7 +7,7 @@ //! line by line beside the book figures, each figure the books can't //! know left blank and named, never guessed. //! SOURCE: ledger_core::tax_capital (INVARIANTS 1-5); Instructions for Form -//! 1065 (2025), Item L, "Tax-basis method" (rules.md B-36); +//! 1065 (2025), Item L, "Tax-basis method" (BS-partner-4); //! DECISION D-41 (owner, 2026-10-20). //! INVARIANTS: //! 1. Per member, in order: the seven Item L lines (beginning; capital diff --git a/crates/ledger-package/src/package.rs b/crates/ledger-package/src/package.rs index dd0505a7..25675141 100644 --- a/crates/ledger-package/src/package.rs +++ b/crates/ledger-package/src/package.rs @@ -6,7 +6,7 @@ //! GOAL: everything the CPA needs for the return in one zip, the K-1s' //! and 1099s' TINs included when asked, built the same by the //! server and the viewer. -//! SOURCE: docs/mcp-interface.md; B-26; B-33 (as of one day); B-34 (the +//! SOURCE: docs/mcp-interface.md; BS-partner-2; BS-statement-4 (as of one day); BS-format-2 (the //! IIF); DECISION (owner, 2026-10-15): "it needs to be in the damn //! CPA package." //! INVARIANTS: @@ -38,7 +38,7 @@ //! Withdrawn files never. //! 5. Read-only (crate INVARIANT 1): the package is returned, its files //! and the zip, and written nowhere. -//! 6. As of one day (B-33): no figure, entry, receipt or worksheet row +//! 6. As of one day (BS-statement-4): no figure, entry, receipt or worksheet row //! reflects anything dated after as_of; the chart and documents/ are //! as they stand when the package is made. //! 7. One list of cash accounts and one of financing accounts per @@ -48,7 +48,7 @@ //! 8. Every account name, number or place and every memo //! general-journal.iif writes differently from the books (it holds //! plain ASCII, within QuickBooks Desktop's limits and its rule that -//! a subaccount has its parent's type: B-34) is in `warnings` and the +//! a subaccount has its parent's type: BS-format-2) is in `warnings` and the //! README, the memos grouped by what is written differently; the //! README also names the entries with a line on accounts receivable //! or payable, which the file gives no customer or vendor. @@ -134,8 +134,8 @@ pub fn build_package( let mut tin_gaps: Vec = Vec::new(); // The fiscal year to date: the tax year holding as_of (IRS Pub. 538), - // the fiscal-year fact itself, not "what omitted dates mean" (rules.md - // B-30), so the package's year never follows a default. + // the fiscal-year fact itself, not "what omitted dates mean" ( + // BS-period-3), so the package's year never follows a default. let fy = ledger_core::calendar::fiscal_year_start_on(company.fiscal_year_start, as_of); let (fy_start, as_of_s) = (fy.to_string(), as_of.to_string()); let xlsx = |r: XlsxReport<'_>| report_to_xlsx(&r, &meta).map_err(|e| e.to_string()); @@ -373,7 +373,7 @@ pub fn build_package( files.push((format!("{name}.xlsx"), xlsx(XlsxReport::Statement(st))?)); } // The receivables and payables agings, each with its tie-out line to - // the control account (B-23, 8.3.10): the same CSV books.export and + // the control account (BS-ledger-8, 8.3.10): the same CSV books.export and // the viewer make. files.push(( "ar_aging.csv".into(), @@ -432,8 +432,8 @@ pub fn build_package( worksheet_1099 = true; } // The worksheet can't be made (the year's threshold isn't known, - // or the package names no cash accounts): never guess (rules.md - // B-19); say so in the package instead. + // or the package names no cash accounts): never guess ( + // BS-1099-1); say so in the package instead. Err(e) => files.push(( format!("1099-worksheet-{year}-NOT-INCLUDED.txt"), format!("{e}\n").into_bytes(), diff --git a/crates/ledger-package/src/reports.rs b/crates/ledger-package/src/reports.rs index 337013c8..509e38e6 100644 --- a/crates/ledger-package/src/reports.rs +++ b/crates/ledger-package/src/reports.rs @@ -8,7 +8,7 @@ //! books.cash_flow, books.export_cpa_package); ASC 230-10-20 //! (financing and investing activities). //! INVARIANTS: -//! 1. A range's omitted dates are the one default (rules.md B-30, +//! 1. A range's omitted dates are the one default (BS-period-3, //! `ledger_core::calendar::PeriodDefaults`): an omitted end is //! `today`, an omitted start the first day of the fiscal year that //! holds the end; a start after the end, given or derived, is @@ -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: rules.md B-14 rule 9); +//! refused (an engine error, never a figure: BS-statement-3 rule 9); //! 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 @@ -73,7 +73,7 @@ impl<'a> Settings<'a> { /// Resolve a statement's date range (INVARIANT 1): the dates as given, /// each omitted one the books' default for `company` on `today` -/// (rules.md B-30). +/// (BS-period-3). pub fn statement_range( company: &Company, start: Option<&str>, diff --git a/crates/ledger-package/src/vendor_1099.rs b/crates/ledger-package/src/vendor_1099.rs index 4b1b3414..d66b0f75 100644 --- a/crates/ledger-package/src/vendor_1099.rs +++ b/crates/ledger-package/src/vendor_1099.rs @@ -11,7 +11,7 @@ //! SOURCE: ledger_core::form1099 (the one report: payments out of the cash //! and financing accounts, classified by payment method; an entry's //! shares resolved with the members; dated decisions); IRS -//! thresholds (rules.md B-19: never guessed); RFC 4180 (CSV). +//! thresholds (BS-1099-1: never guessed); RFC 4180 (CSV). //! INVARIANTS: //! 1. Payments come from the cash and financing accounts of the //! `Settings` given (codes the chart lacks are skipped): the books' @@ -57,7 +57,7 @@ pub fn payment_accounts(ledger: &Ledger, settings: &Settings<'_>) -> ledger_core /// CPA package and the viewer use: payments out of [`payment_accounts`], /// an entry's shares resolved with the settings' members. Given /// `through`, only the payments from January 1 through it (the CPA -/// package as of a day, rules.md B-33). +/// package as of a day, BS-statement-4). pub fn vendor_1099_report( ledger: &Ledger, settings: &Settings<'_>, diff --git a/crates/ledger-package/tests/p3_seams.rs b/crates/ledger-package/tests/p3_seams.rs index 63f88ad1..920f21f9 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 B-13, B-35 items 4 and 8 -/// and B-14 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 items 4 and 8 +/// and BS-statement-3 rule 11 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 (B-35 item 4). + // Party totals (BS-partner-3 item 4). 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 (B-14 rule 11, B-35 item 8). + // The cash flow (BS-statement-3 rule 11, BS-partner-3 item 8). 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 - // (B-14 rule 2, B-35 item 4). + // (BS-statement-3 rule 2, BS-partner-3 item 4). 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 (B-35 item 4's second condition). + // totals and the cash flow don't yet (BS-partner-3 item 4'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() { ); } -/// B-14 rule 2, from the seam review: a distribution declared to a +/// BS-statement-3 rule 2, 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() { ); } -/// B-35 item 9 and B-19: for a payee every entry of which names it alone, +/// BS-partner-3 item 9 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 @@ -421,7 +421,7 @@ fn the_1099_worksheet_ties_to_party_totals_and_the_ledger() { } } -/// The IIF's amounts on one account, through as_of (B-34: every posted +/// The IIF's amounts on one account, through as_of (BS-format-2: every posted /// entry, closes left out), debit-positive. fn iif_total(iif: &str, account: &str) -> Decimal { let mut total = Decimal::ZERO; @@ -445,8 +445,8 @@ fn iif_dates(iif: &str) -> Vec { .collect() } -/// Depreciation is one figure everywhere (B-15 rule 8, B-14 rule 8, -/// B-36): the P&L's expense, the cash flow reconciliation's add-back, the +/// Depreciation is one figure everywhere (BS-asset-1 rule 8, BS-statement-3 rule 8, +/// 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 /// register's posted figure, and posted differs from scheduled by exactly @@ -602,7 +602,7 @@ fn file<'p>(p: &'p ledger_package::Package, name: &str) -> &'p str { } /// The CPA package as of each date: every file stops at as_of, and its -/// figures are the tools' for the same accounts and dates (B-33). +/// figures are the tools' for the same accounts and dates (BS-statement-4). #[test] fn the_cpa_package_as_of_each_date_is_the_tools_figures() { let dir = tempfile::tempdir().unwrap(); diff --git a/crates/ledger-package/tests/package.rs b/crates/ledger-package/tests/package.rs index a822f0e3..9323462c 100644 --- a/crates/ledger-package/tests/package.rs +++ b/crates/ledger-package/tests/package.rs @@ -1106,7 +1106,7 @@ fn a_receipts_index_amount_is_the_entrys_debit_total_as_written() { } // --------------------------------------------------------------------------- -// As of one day (rules.md B-33), and the QuickBooks file (B-34) +// As of one day (BS-statement-4), and the QuickBooks file (BS-format-2) // --------------------------------------------------------------------------- /// The IIF's transactions in file order: each one's DOCNUM, memo, and @@ -1208,7 +1208,7 @@ fn as_of_package_iif_stops_at_as_of() { )); } -/// B-33 at its edges, through ledger_package::export_iif (the package's +/// BS-statement-4 at its edges, through ledger_package::export_iif (the package's /// own): an entry dated as_of is in and one dated the day after is not; a /// reversal after as_of leaves its original in, under the original's id; /// as of a day before the first entry the file declares the accounts and @@ -1409,7 +1409,7 @@ fn books_around(dir: &Path, as_of: NaiveDate, later: bool, desk: bool) -> Books } /// Plan P3, defect 21: "a test pins every file in an as-of package to -/// it". B-33: no figure, entry, receipt or worksheet row reflects anything +/// it". BS-statement-4: no figure, entry, receipt or worksheet row reflects anything /// dated after as_of. Two sets of books, the same through as_of, one with /// activity in the days after (a 1099 payment with its receipt, an asset /// bought, a reversal of an entry dated as_of, the members' contributions, @@ -1717,7 +1717,7 @@ fn one_list_of_cash_accounts_per_package() { assert_eq!(text(&plain, "1099-worksheet-2026.csv"), tool(&cash)); } -/// rules.md B-34 rule 8 (P3 cutover review, open point 1): the +/// BS-format-2 rule 8 (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() { ); } -/// rules.md B-34 rule 8 with B-37 item 8: an invoice's or a bill's +/// BS-format-2 rule 8 with BS-statement-5 item 8: 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")); } -/// B-34 rule 7 (P3 review round 2): the file names no customer or vendor +/// BS-format-2 rule 7 (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 @@ -1939,7 +1939,7 @@ fn the_readme_names_the_entries_on_receivables_and_payables() { s.add_account(code, name, ty, None, false).unwrap(); } // Hand lines on receivables and payables, as books an earlier version - // wrote hold them (the control guard, rules.md B-38, refuses them as + // wrote hold them (the control guard, BS-arap-2, refuses them as // new work): posted as replay posts them. let (invoiced, billed) = ledger_core::parties::replaying(|| { let invoiced = post( @@ -2114,7 +2114,7 @@ fn random_ledger( } let e = posted[pick.index(posted.len())]; let on = l.get_entry(e).unwrap().date() + chrono::Duration::days(*days); - // An entry is reversed at most once (B-10): a second pick is skipped. + // An entry is reversed at most once (BS-ledger-6): a second pick is skipped. let _ = l.reverse_entry(e, on, "Reversal"); } for m in 1..=closed { @@ -2134,7 +2134,7 @@ fn random_ledger( proptest::proptest! { #![proptest_config(proptest::prelude::ProptestConfig::with_cases(2000))] - /// B-33 and B-34 over random books, random as_of (before the first + /// BS-statement-4 and BS-format-2 over random books, random as_of (before the first /// entry, on an entry's date, after the last), reversals on either side /// of it and closed months: the IIF holds exactly the posted entries /// dated on or before as_of that aren't closes, in posting order, each @@ -2297,8 +2297,8 @@ fn the_bookspec_iif_example_matches_the_engine() { assert_eq!(checked, 2); } -/// The package's statement of cash flows is the direct method's (rules.md -/// B-14, D-35): operating by ASC 230-10-45-25 class, financing by kind +/// The package's statement of cash flows is the direct method's ( +/// BS-statement-3, D-35): operating by ASC 230-10-45-25 class, financing by kind /// with each member named, and both schedules: the reconciliation of net /// income to operating cash (45-30) and the noncash investing and /// financing activities (50-3; "None" here: every entry moved cash). @@ -2329,7 +2329,7 @@ fn the_cash_flow_carries_both_schedules() { assert!(p.files.iter().any(|(n, _)| n == "cash-flow.pdf")); } -/// The K-1 worksheet reports tax-basis capital (rules.md B-36; Form 1065 +/// The K-1 worksheet reports tax-basis capital (BS-partner-4; Form 1065 /// instructions, Item L, the tax-basis method), beside the book figures, /// with the reconciliation. By hand, per member of two at 50/50: cash in /// 1,000.00; a laptop (worth 1,440.00, adjusted basis 1,688.40) and a @@ -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; rules.md B-23, B-38 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-package/tests/seams/books.rs b/crates/ledger-package/tests/seams/books.rs index 74606a90..214ff6aa 100644 --- a/crates/ledger-package/tests/seams/books.rs +++ b/crates/ledger-package/tests/seams/books.rs @@ -511,7 +511,7 @@ pub fn books(dir: &std::path::Path) -> Books { } 4 => { // Ben pays Delta with his own check, at the company's - // direction: the company is the payor (B-19). + // direction: the company is the payor (BS-1099-1). let e = post( &mut s, &day(20), diff --git a/crates/ledger-reader/src/lib.rs b/crates/ledger-reader/src/lib.rs index 0a03f630..b00e3d6f 100644 --- a/crates/ledger-reader/src/lib.rs +++ b/crates/ledger-reader/src/lib.rs @@ -197,7 +197,7 @@ pub fn extract(bytes: &[u8], mime_type: &str, file_name: &str) -> Extracted { } // A file CALLED a PDF whose bytes are text (a text file named // .pdf): read the text, so the TIN scan and the reader see what - // it says (B-26: the scan fails closed). One with the PDF magic + // it says (BS-partner-2: the scan fails closed). One with the PDF magic // that won't read is a failed extraction. Err(_) if !magic_pdf => match plain_text(bytes, &mime, &ext) { Some(text) => found(Some(text), 1), diff --git a/crates/ledger-store/src/audit.rs b/crates/ledger-store/src/audit.rs index d4460708..43a58824 100644 --- a/crates/ledger-store/src/audit.rs +++ b/crates/ledger-store/src/audit.rs @@ -1,4 +1,4 @@ -//! The audit's journal and the integrity checks (plan P8; rules.md B-45): +//! The audit's journal and the integrity checks (plan P8; BS-ledger-13): //! `audit.run`, `receipt.attested`, `entry.reviewed` and `period.attested`, //! what "the current head" means, and the findings only the store can see. //! @@ -7,7 +7,7 @@ //! head, so the same books give the same run once, and an //! attestation rests on a head that has not moved. //! SOURCE: IRS Pub. 583 (records); Rev. Proc. 98-25 §5.01 (the audit -//! trail); docs/spec/rules.md B-45; DECISION D-9 (the bar), D-53 +//! trail); BS-ledger-13; DECISION D-9 (the bar), D-53 //! (an audit is a run, not a job), IZ-1k (the head). //! INVARIANTS: //! 1. The figure head is the seq of the last journal line that bears on diff --git a/crates/ledger-store/src/describe.rs b/crates/ledger-store/src/describe.rs index 04bb1e14..51b5e04e 100644 --- a/crates/ledger-store/src/describe.rs +++ b/crates/ledger-store/src/describe.rs @@ -8,7 +8,7 @@ //! what, and which entry it belongs to. //! SOURCE: plan/served.md P5 step 4 (the only way to "read the journal"); //! docs/receipt-store.md (the lines and their payloads); -//! docs/spec/rules.md B-26 (no output holds a full TIN). +//! BS-partner-2 (no output holds a full TIN). //! INVARIANTS: //! 1. Every line type the store writes has a sentence (test: every //! `format::EVENT_TYPES` entry). diff --git a/crates/ledger-store/src/error.rs b/crates/ledger-store/src/error.rs index c6070703..e162707a 100644 --- a/crates/ledger-store/src/error.rs +++ b/crates/ledger-store/src/error.rs @@ -36,7 +36,7 @@ pub enum StoreError { AssetDepreciationPosted(u64), /// The receipt policy covers the entry and it has no receipt (plan P4, - /// I-5; rules.md B-43): refused before anything is journaled. + /// I-5; BS-entry-5): refused before anything is journaled. #[error( "entry {} needs a receipt before it posts: {} ({}); attach one with books.attach_receipt", .0.entry_id, .0.reason, .0.policy @@ -69,7 +69,7 @@ pub enum StoreError { /// though the lines after it are the newer version's to check. When /// nothing checks it (it is the last line, or the next has no `prev` /// this version can read), it is either newer or damaged, and the - /// message says so (rules.md B-27). + /// message says so (BS-format-1). #[error("{}", newer_journal_text(*seq, event_type, need, *verified))] NewerJournal { /// The first line this version can't read. @@ -152,7 +152,7 @@ pub enum StoreError { #[error("store not found at {0}")] NotFound(String), - /// A write-off with no evidence (rules.md B-41 INVARIANT 1): a bad + /// A write-off with no evidence (BS-arap-5 INVARIANT 1): 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( @@ -162,8 +162,8 @@ pub enum StoreError { )] WriteOffNeedsEvidence, - /// An audit or an attestation the books refuse (plan P8; rules.md - /// B-45): a stale head, an entry not posted, a receipt not on the + /// An audit or an attestation the books refuse (plan P8; + /// BS-ledger-13): a stale head, an entry not posted, a receipt not on the /// entry. The words say what to do. #[error("{0}")] AuditRefused(String), diff --git a/crates/ledger-store/src/form1099.rs b/crates/ledger-store/src/form1099.rs index 3ee42e2a..4d14f1a2 100644 --- a/crates/ledger-store/src/form1099.rs +++ b/crates/ledger-store/src/form1099.rs @@ -7,7 +7,7 @@ //! GOAL: every event round-trips: decode(encode(x)) == x, and every line //! written before decisions were kept reads as it always meant. //! SOURCE: plan/served.md 5.2, 5.5 (a legacy null is undetermined); -//! rules.md B-27 (an older reader says "newer", never "corrupt"). +//! BS-format-1 (an older reader says "newer", never "corrupt"). //! INVARIANTS: //! 1. vendor.1099_set {vendor_id, form_1099: "nec"|"misc"| //! "not_reportable"|null, reason_kind?, reason?, effective?, @@ -22,7 +22,7 @@ //! 4. instrument.added {instrument_id, kind, label, last4?, //! owner_party_id?, account_id}; entry.instrument_set {entry_id, //! instrument_id|null}. Optional keys are left out when absent. -//! 5. Decoding checks shape only (rules.md B-28): what a command checks +//! 5. Decoding checks shape only (BS-entry-4): what a command checks //! (limits, the chart) stays with the command. //! ``` diff --git a/crates/ledger-store/src/format.rs b/crates/ledger-store/src/format.rs index e3224b04..210b9d56 100644 --- a/crates/ledger-store/src/format.rs +++ b/crates/ledger-store/src/format.rs @@ -12,7 +12,7 @@ //! checks ([`crate::journal::read_journal_and_format`], and //! [`crate::Snapshot`] line by line). //! -//! What every format shares is frozen (rules.md B-27): a line is the +//! What every format shares is frozen (BS-format-1): a line is the //! envelope `{seq, ts, type, payload, prev}` and nothing beside it, and //! its hash is the SHA-256 of its canonical JSON (keys sorted, no //! whitespace). A newer format adds its fields inside `payload`. So this @@ -27,7 +27,7 @@ //! The other way round, books an older version wrote are in an older //! format: this version reads them as they are, and writes nothing that //! needs a format or feature they haven't declared until the owner says -//! go (the format upgrade, rules.md B-27, plan/served.md 3.9, D-39: +//! go (the format upgrade, BS-format-1, plan/served.md 3.9, D-39: //! [`JournalFormat::upgrade`], [`current`]). New books declare this //! version's whole format as they are created. @@ -43,7 +43,7 @@ pub const SUPPORTED_JOURNAL_FORMAT: u32 = 2; /// unknown), or a field or value on an event type it knows (which it /// would misread silently). The books declare it (`journal.format_set`) /// before their first such line, so the older version stops there instead -/// (rules.md B-27). Every one is declared at once: by new books as they +/// (BS-format-1). Every one is declared at once: by new books as they /// are created, and by older books at their format upgrade ([`current`]); /// until then a write that needs one is refused. pub const KNOWN_FEATURES: &[&str] = &[ @@ -72,7 +72,7 @@ pub const KNOWN_FEATURES: &[&str] = &[ /// Feature: `period.closed` closes to members with `"rounding": /// "cumulative_since"` and `since_seq`, the count of members closes /// starting at the first since the members or shares last changed (P3 -/// defect 17, rules.md B-13). An older version would call the rounding +/// defect 17, BS-partner-1). An older version would call the rounding /// unknown, or (before the format gate) replay the close under the run /// rule, which can split it differently. pub const MEMBERS_CUMULATIVE: &str = "members_cumulative"; @@ -136,14 +136,14 @@ pub const DISPOSAL_BEFORE_SERVICE: &str = "disposal_before_service"; /// Feature: an `asset.depreciation_posted` whose amount is not its month's /// own depreciation: earlier months skipped or reversed caught up in it, or -/// a final month left over past the life (P3's run rule, B-15). An earlier +/// a final month left over past the life (P3's run rule, BS-asset-1). An earlier /// version reads every run as its month's own: it would show the caught-up /// months as not yet run, and running them post their depreciation twice /// (P3 review, 2026-10-21). pub const DEPRECIATION_CATCH_UP: &str = "depreciation_catch_up"; /// The feature `party.creditor_set` lines need: a party named the -/// creditor of a liability (rules.md B-35, P3 defect 24). +/// creditor of a liability (BS-partner-3, P3 defect 24). pub const PARTY_CREDITORS: &str = "party_creditors"; /// Payment methods (`instrument.added`) and the entries tagged with one @@ -171,7 +171,7 @@ pub const SCHEDULE_CONVENTION: &str = "schedule_convention"; /// with the value at contribution and the §704(c) method (P3, defect 13). pub const ASSET_BASIS: &str = "asset_basis"; -/// Feature: projects (rules.md B-37): `project.set`, a new event type (a +/// Feature: projects (BS-statement-5): `project.set`, a new event type (a /// class's project facts); `attachment.linked` to the subject kind /// `project` (an older version would call it corrupt); and /// `decision.recorded` with `projects` (an older version would drop them @@ -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`, rules.md B-37 item 8). An older version would restore the +/// (`class_id`, BS-statement-5 item 8). 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. @@ -187,7 +187,7 @@ pub const DOCUMENT_LINE_PROJECTS: &str = "document_line_projects"; /// Feature: an `invoice.payment_received` or `bill.paid` accepted only /// because an earlier payment on its document was reversed (plan P4b S1, -/// D-45; rules.md B-38): this version reads a document's figures from the +/// D-45; BS-arap-2): this version reads a document's figures from the /// ledger lines that stand, so a reversed payment no longer counts and the /// right one is taken. An older version adds every payment event to the /// document's paid amount, standing or not: it would replay the new @@ -211,7 +211,7 @@ pub const DOCUMENTS_V2: &str = "documents_v2"; /// payment pays back), and `attachment.withdrawn` carrying `duplicate_of`. /// An older version doesn't know those event types, or would withdraw a /// duplicate without saying what it duplicates; it stops at the -/// declaration instead (rules.md B-27, B-44). +/// declaration instead (BS-format-1, BS-ledger-12). pub const ATTACHMENT_TEXT: &str = "attachment_text"; /// Feature: `drafts_v2` (plan P4, D-52): `entry.draft_state_set` (a draft @@ -220,7 +220,7 @@ pub const ATTACHMENT_TEXT: &str = "attachment_text"; /// event types: it would refuse them as unknown, or, replaying around /// them, keep a discarded draft that blocks a period's close and call a /// waiting draft one being built; it stops at the declaration instead -/// (rules.md B-27, B-43). +/// (BS-format-1, BS-entry-5). pub const DRAFTS_V2: &str = "drafts_v2"; /// Feature: `source_revisions` (plan P5): `convention.source_revised`, @@ -229,7 +229,7 @@ pub const DRAFTS_V2: &str = "drafts_v2"; /// leaving its text as it was. An older version doesn't know those event /// types: it would refuse them as unknown, or, replaying around them, /// show the old source as the decision's authority; it stops at the -/// declaration instead (rules.md B-27). +/// declaration instead (BS-format-1). pub const SOURCE_REVISIONS: &str = "source_revisions"; /// Feature: `audits` (plan P8): `audit.run` (a programme of checks run @@ -240,7 +240,7 @@ pub const SOURCE_REVISIONS: &str = "source_revisions"; /// waits for an audit (`policy.cpa_package_requires_audit`). An older /// version doesn't know those event types or settings; it stops at the /// declaration instead of dropping the claims a handoff rests on -/// (rules.md B-27, B-45). +/// (BS-format-1, BS-ledger-13). pub const AUDITS: &str = "audits"; /// The line type that declares the journal format. @@ -364,7 +364,7 @@ impl JournalFormat { /// ```text /// GOAL: an older wanderbooks never misreads newer books, and never /// calls them corrupt. - /// SOURCE: rules.md B-27; plan/served.md 5.1 (format gate). + /// SOURCE: BS-format-1; plan/served.md 5.1 (format gate). /// INVARIANTS: /// 1. Only lines that parsed, chained and kept their seq reach the /// gate: damage stays JournalCorrupt. @@ -496,8 +496,8 @@ impl JournalFormat { } } - /// The format upgrade books in this format wait for, if any (rules.md - /// B-27, plan/served.md 3.9, D-39). + /// The format upgrade books in this format wait for, if any ( + /// BS-format-1, plan/served.md 3.9, D-39). /// /// ```text /// GOAL: books an older version wrote are never moved to a newer @@ -587,7 +587,7 @@ fn declared_knowing(line: &JournalLine, known: &[&str]) -> Result StoreError { newer(line, need) } @@ -598,7 +598,7 @@ pub(crate) fn unknown_type(line: &JournalLine) -> StoreError { } /// The gate for one line as read: a line with a key beside the envelope's -/// is newer (rules.md B-27: this version never drops a key it can't +/// is newer (BS-format-1: this version never drops a key it can't /// read), and any other goes to `admit` (JournalFormat::admit). pub(crate) fn gate( read: &ReadLine, @@ -634,7 +634,7 @@ fn newer(line: &JournalLine, need: String) -> StoreError { /// ```text /// GOAL: damage is never reported as books from a newer wanderbooks, and /// books from a newer wanderbooks never as damage. -/// SOURCE: rules.md B-27 (the envelope and its hash are frozen across +/// SOURCE: BS-format-1 (the envelope and its hash are frozen across /// formats); docs/receipt-store.md "Line format" (a line's hash is /// checked only by the next line's prev). /// INVARIANTS: @@ -848,7 +848,7 @@ mod tests { /// The version the live books run (every feature through `projects`) /// stops at a declaration of `document_line_projects` as newer, never /// restoring an invoice or bill without its lines' projects; and books - /// that declared `projects` alone still wait for it (B-27, D-39). + /// that declared `projects` alone still wait for it (BS-format-1, D-39). #[test] fn document_line_projects_is_its_own_feature() { assert!(KNOWN_FEATURES.contains(&DOCUMENT_LINE_PROJECTS)); @@ -887,7 +887,7 @@ mod tests { /// `document_line_projects`) stops at a declaration of /// `document_standing` as newer, never adding a payment taken after a /// reversal on top of the reversed one; and books that declared every - /// earlier feature still wait for it (B-27, D-39). + /// earlier feature still wait for it (BS-format-1, D-39). #[test] fn document_standing_is_its_own_feature() { assert!(KNOWN_FEATURES.contains(&DOCUMENT_STANDING)); @@ -921,7 +921,7 @@ mod tests { /// The version before P6 (every feature through `documents_v2`) stops /// at a declaration of `attachment_text` as newer, never dropping a /// file's extraction, annotations or settlements; and books that - /// declared every earlier feature still wait for it (B-27, D-39). + /// declared every earlier feature still wait for it (BS-format-1, D-39). #[test] fn attachment_text_is_its_own_feature() { assert!(KNOWN_FEATURES.contains(&ATTACHMENT_TEXT)); @@ -956,7 +956,7 @@ mod tests { /// `document_standing`) stops at a declaration of `documents_v2` as /// newer, never restoring a party's email or default terms as absent /// (or a document without its numbers, once S4.3 writes them); books - /// that declared every earlier feature still wait for it (B-27, D-39). + /// that declared every earlier feature still wait for it (BS-format-1, D-39). #[test] fn documents_v2_is_its_own_feature() { assert!(KNOWN_FEATURES.contains(&DOCUMENTS_V2)); @@ -991,7 +991,7 @@ mod tests { /// stops at a declaration of `drafts_v2` as newer, never keeping a /// discarded draft or calling a waiting one a draft being built; and /// books that declared every earlier feature still wait for it - /// (B-27, D-39). + /// (BS-format-1, D-39). #[test] fn drafts_v2_is_its_own_feature() { assert!(KNOWN_FEATURES.contains(&DRAFTS_V2)); @@ -1024,7 +1024,7 @@ mod tests { /// The version before P5 (every feature through `drafts_v2`) stops at a /// declaration of `source_revisions` as newer, and books that declared - /// every earlier feature still wait for it (B-27, D-39). + /// every earlier feature still wait for it (BS-format-1, D-39). #[test] fn source_revisions_is_its_own_feature() { assert!(KNOWN_FEATURES.contains(&SOURCE_REVISIONS)); @@ -1057,7 +1057,7 @@ mod tests { /// The version before P8 stops at a declaration of `audits` as newer, /// never dropping an attestation a handoff rests on; books that - /// declared every earlier feature still wait for it (B-27, D-39). + /// declared every earlier feature still wait for it (BS-format-1, D-39). #[test] fn audits_is_its_own_feature() { assert!(KNOWN_FEATURES.contains(&AUDITS)); @@ -1221,7 +1221,7 @@ mod tests { /// A format newer than this version reads is newer whatever shape the /// rest of its declaration takes, and however large its number: a /// newer format may define its features differently, so they are - /// judged only for a format this version reads (rules.md B-27). + /// judged only for a format this version reads (BS-format-1). #[test] fn a_newer_format_is_newer_whatever_its_features_look_like() { let mut f = JournalFormat::default(); diff --git a/crates/ledger-store/src/journal.rs b/crates/ledger-store/src/journal.rs index f8d8d9b2..de106dbb 100644 --- a/crates/ledger-store/src/journal.rs +++ b/crates/ledger-store/src/journal.rs @@ -71,7 +71,7 @@ fn sort_value(v: &Value) -> Value { } /// The keys of a journal line, the same in every journal format -/// (rules.md B-27): a newer format adds its fields inside `payload`, never +/// (BS-format-1): a newer format adds its fields inside `payload`, never /// beside it, and a line's hash is always the SHA-256 of its canonical /// JSON ([`canonical_json`]), whatever the format. pub const ENVELOPE_KEYS: [&str; 5] = ["payload", "prev", "seq", "ts", "type"]; @@ -84,7 +84,7 @@ impl JournalLine { /// hash chain covers) is a fixed point. /// SOURCE: R-2 (no floats in money paths); found by fuzz_journal_line /// (2026-10-13): a float payload re-canonicalized differently; - /// rules.md B-27 (the envelope is frozen). + /// BS-format-1 (the envelope is frozen). /// INVARIANTS: /// 1. NEVER accepts a floating-point number anywhere in the line: /// amounts are decimal strings and ids are integers. @@ -267,7 +267,7 @@ pub fn read_and_verify_journal(path: &Path) -> Result, StoreErr /// /// ```text /// GOAL: books read whole and verified, or refused with the reason. -/// SOURCE: docs/receipt-store.md "Line format"; rules.md B-27. +/// SOURCE: docs/receipt-store.md "Line format"; BS-format-1. /// INVARIANTS: /// 1. Line by line, in order: parse, seq, chain, then the format gate. /// 2. Damage before the first line this version can't read is diff --git a/crates/ledger-store/src/meta.rs b/crates/ledger-store/src/meta.rs index 876da39d..64287114 100644 --- a/crates/ledger-store/src/meta.rs +++ b/crates/ledger-store/src/meta.rs @@ -9,7 +9,7 @@ //! INVARIANTS: //! 1. A payload missing a field, or with a field of the wrong type, is //! JournalCorrupt; optional fields may be absent or null. -//! 2. Decoding checks shape only (rules.md B-28): what a command checks +//! 2. Decoding checks shape only (BS-entry-4): what a command checks //! (limits, the chart) stays with the command. //! ``` @@ -301,7 +301,7 @@ pub fn decision_recorded_of(p: &Value) -> Result<(u64, NewDecision), StoreError> /// `project.set {id, name, status, kind?, description?, party_id?, /// started_on?, ended_on?, links?, notes?}`: a class's whole project -/// record (rules.md B-37; journal feature `projects`). Every optional key +/// record (BS-statement-5; journal feature `projects`). Every optional key /// is left out when empty, so the payload is canonical. pub fn project_set(id: ClassId, name: &str, f: &ProjectFacts) -> Value { let mut o = Map::new(); @@ -322,7 +322,7 @@ pub fn project_set(id: ClassId, name: &str, f: &ProjectFacts) -> Value { /// Read a `project.set`: `(id, name, facts)`. A missing or mistyped key is /// corrupt; a status or kind this version doesn't know is newer (a newer -/// version wrote it, rules.md B-27). +/// version wrote it, BS-format-1). pub fn project_set_of( line: &crate::journal::JournalLine, ) -> Result<(ClassId, String, ProjectFacts), StoreError> { @@ -463,7 +463,7 @@ pub fn invoice_sent(invoice: u64, s: &Sent) -> Value { } /// Read an `invoice.sent`: `(invoice, send)`. A channel or kind this -/// version doesn't know is newer, never corrupt (rules.md B-27). +/// version doesn't know is newer, never corrupt (BS-format-1). pub fn invoice_sent_of(line: &JournalLine) -> Result<(u64, Sent), StoreError> { const E: &str = "invoice.sent"; let p = &line.payload; @@ -487,7 +487,7 @@ pub fn invoice_sent_of(line: &JournalLine) -> Result<(u64, Sent), StoreError> { )) } -/// A bad-debt write-off as journaled (plan P4b S7; rules.md B-41): +/// A bad-debt write-off as journaled (plan P4b S7; BS-arap-5): /// `invoice.written_off {invoice_id, entry_id, date, amount, reason}`. #[derive(Clone, Debug, PartialEq, Eq)] pub struct WrittenOff { @@ -557,7 +557,7 @@ pub fn text_extracted( /// Read an `attachment.text_extracted`: `(attachment_id, text_sha256, /// extractor, version, pages, status)`. A status this version doesn't know -/// is newer (B-27: never "corrupt" for newer). +/// is newer (BS-format-1: never "corrupt" for newer). pub fn text_extracted_of(line: &crate::journal::JournalLine) -> Result { const E: &str = "attachment.text_extracted"; let p = &line.payload; @@ -624,7 +624,7 @@ pub fn annotated(a: &Annotation) -> Value { /// Read an `attachment.annotated`. A field this version doesn't know, or a /// mistyped one, is judged by its kind: unknown is newer (a later version -/// wrote it, B-27), mistyped is corrupt. +/// wrote it, BS-format-1), mistyped is corrupt. pub fn annotated_of(line: &crate::journal::JournalLine) -> Result { const E: &str = "attachment.annotated"; let p = &line.payload; @@ -704,7 +704,7 @@ pub fn draft_state_set(id: u64, state: &DraftState) -> Value { } /// Read an `entry.draft_state_set`: `(draft, state)`. A state this -/// version doesn't know is newer, never corrupt (rules.md B-27). +/// version doesn't know is newer, never corrupt (BS-format-1). pub fn draft_state_set_of(line: &JournalLine) -> Result<(u64, DraftState), StoreError> { const E: &str = "entry.draft_state_set"; let p = &line.payload; @@ -748,7 +748,7 @@ pub fn method_json(m: &ledger_core::audit::Method) -> Value { } /// Read a method. A key or an effort this version doesn't know is newer -/// when a line is at hand (B-27), else corrupt. +/// when a line is at hand (BS-format-1), else corrupt. fn method_of( line: Option<&crate::journal::JournalLine>, m: &Value, diff --git a/crates/ledger-store/src/ops.rs b/crates/ledger-store/src/ops.rs index 72523e98..dd8e6e8f 100644 --- a/crates/ledger-store/src/ops.rs +++ b/crates/ledger-store/src/ops.rs @@ -78,7 +78,7 @@ pub enum ViewerTarget { /// Account code. code: String, /// First date, YYYY-MM-DD. `books.show` always sends both dates, - /// resolved (rules.md B-30); `None` only from an earlier writer, + /// resolved (BS-period-3); `None` only from an earlier writer, /// which the viewer resolves by the same rule. start: Option, /// Last date, YYYY-MM-DD (see `start`). @@ -91,7 +91,7 @@ pub enum ViewerTarget { /// ar_aging, ap_aging, fixed_asset_register. report: String, /// First date, YYYY-MM-DD. `books.show` always sends both dates, - /// resolved (rules.md B-30); `None` only from an earlier writer, + /// resolved (BS-period-3); `None` only from an earlier writer, /// which the viewer resolves by the same rule. start: Option, /// Last date, YYYY-MM-DD (see `start`): the as-of day of a report diff --git a/crates/ledger-store/src/schema.rs b/crates/ledger-store/src/schema.rs index bd498c87..0c75c2ae 100644 --- a/crates/ledger-store/src/schema.rs +++ b/crates/ledger-store/src/schema.rs @@ -388,7 +388,7 @@ ALTER TABLE asset_depreciation_v13 RENAME TO asset_depreciation; "#, r#" -- v15: a document keeps no figure of its own (plan P4b S1, D-45; rules.md --- B-38): what an invoice or bill has been paid, and its status, are read +-- BS-arap-2): what an invoice or bill has been paid, and its status, are read -- from the ledger lines tagged with it, as of any date, and a reversed -- payment no longer counts. The columns that summed its payment events -- (and so went on counting a reversed one) go. diff --git a/crates/ledger-store/src/store.rs b/crates/ledger-store/src/store.rs index f2b3ff3c..9e2f3f70 100644 --- a/crates/ledger-store/src/store.rs +++ b/crates/ledger-store/src/store.rs @@ -72,7 +72,7 @@ pub const LEGACY_DB_FILE: &str = "wanderbooks.db"; /// open (plan/served.md 3.9: before consent, the way back is always /// there), however far this version's projection has moved. /// SOURCE: plan/served.md 3.9, the lead's decision (2026-10-21: each -/// schema in a file of its own); rules.md B-27. +/// schema in a file of its own); BS-format-1. /// INVARIANTS: /// 1. A version opens or creates only its own schema's file (or the /// legacy file when that already holds its schema); a missing one is @@ -506,7 +506,7 @@ struct AttachRequest<'a> { description: Option<&'a str>, } -/// The evidence a bad-debt write-off files (plan P4b S7; rules.md B-41 +/// 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 /// 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 @@ -909,7 +909,7 @@ impl Store { /// /// ```text /// GOAL: books that tell every reader which format they are in. - /// SOURCE: rules.md B-27; plan/served.md 5.1 (format gate). + /// SOURCE: BS-format-1; plan/served.md 5.1 (format gate). /// SCENARIOS: /// 1. IF the format is newer than SUPPORTED_JOURNAL_FORMAT, or 0: /// SHOULD refuse (FormatRefused), journaling nothing @@ -969,7 +969,7 @@ impl Store { /// instead of misreading a line it thinks it knows, and books /// move past what their owner's older version reads only when /// the owner says so. - /// SOURCE: rules.md B-27; plan/served.md 5.1 (format gate), 3.9 and + /// SOURCE: BS-format-1; plan/served.md 5.1 (format gate), 3.9 and /// D-39 (the format upgrade). /// SCENARIOS: /// 1. IF the books declared it: SHOULD pass. @@ -1001,7 +1001,7 @@ impl Store { /// GOAL: older books move to this version's format at once, on the /// record, exactly once. /// SOURCE: plan/served.md 3.9 ("Format changes are the server's - /// gate"); D-39; rules.md B-27. + /// gate"); D-39; BS-format-1. /// INVARIANTS: /// 1. One journal line declares the whole format: the format moves /// exactly once, never feature by feature. @@ -1072,7 +1072,7 @@ impl Store { self.ensure_features(&needed)?; self.ensure_format()?; // invoicing.first_number is settable only while no numbered invoice - // exists (A-2, rules.md B-40): the series has begun, and a number is + // exists (A-2, BS-arap-4): the series has begun, and a number is // never reused or renumbered. Changing or clearing it is refused // before anything is journaled. if changes.iter().any(|c| c.key == "invoicing.first_number") @@ -1356,7 +1356,7 @@ impl Store { /// /// ```text /// GOAL: an account created with the line of the return it maps to. - /// SOURCE: rules.md B-32 (policy.require_tax_category). + /// SOURCE: BS-ledger-11 (policy.require_tax_category). /// INVARIANTS: /// 1. Rehearsed whole first: a refusal (of the account, or of its /// category) journals nothing. @@ -1512,7 +1512,7 @@ impl Store { /// ```text /// GOAL: a draft that is finished and waiting on its receipt says so, /// durably, and replays the same. - /// SOURCE: docs/spec/rules.md B-27, B-43; plan P4. + /// SOURCE: BS-format-1, BS-entry-5; plan P4. /// SCENARIOS: /// 1. IF the engine refuses it (unknown or posted entry, a note the /// books won't keep): SHOULD refuse, journaling nothing. @@ -1543,7 +1543,7 @@ impl Store { /// ```text /// GOAL: a draft that will never post can go, so it stops holding its /// period open, and the journal still says why. - /// SOURCE: docs/spec/rules.md B-8, B-43; plan P4. + /// SOURCE: BS-ledger-4, BS-entry-5; plan P4. /// SCENARIOS: /// 1. IF the entry is unknown or posted, or the reason is empty or /// breaks the books' text rule: SHOULD refuse, journaling @@ -1584,7 +1584,7 @@ impl Store { } /// [`Self::post_entry`] behind the evidence gate (plan P4, I-5, D-47; - /// rules.md B-43): refuses, journaling nothing, a draft that + /// BS-entry-5): refuses, journaling nothing, a draft that /// [`ledger_core::evidence::requirement`] says needs evidence while it /// has no receipt filed on it or linked to it. This is the path the /// server posts a hand-made draft by; [`Self::post_entry`] stays the @@ -1594,7 +1594,7 @@ impl Store { /// ```text /// GOAL: no draft the receipt policy covers posts without the /// document that supports it, decided in one place. - /// SOURCE: docs/spec/rules.md B-43; IRS Pub. 583. + /// SOURCE: BS-entry-5; IRS Pub. 583. /// SCENARIOS: /// 1. IF the entry is covered and has no receipt: SHOULD refuse /// (ReceiptRequired), NEVER journal. @@ -1748,7 +1748,7 @@ impl Store { /// ```text /// GOAL: a reversal never leaves a fixed asset's figures and its books /// apart. - /// SOURCE: docs/spec/rules.md B-9, B-15; P3 depreciation review R3. + /// SOURCE: BS-ledger-5, BS-asset-1; P3 depreciation review R3. /// SCENARIOS (the entry, or the original its reversal chain starts /// from, since reversing a reversal re-instates that original): /// 1. IF it is an asset's disposal entry: @@ -1774,7 +1774,7 @@ impl Store { /// reverses is refused for every entry, by `Ledger::check_reversal` /// with `ReversalBeforeOriginal`, D-73; it was this store's check /// for runs and schedule months alone. A journal an earlier - /// version wrote replays as it was, B-28.) + /// version wrote replays as it was, BS-entry-4.) /// 6. Otherwise: a run of an active asset is un-posted (its month is /// due again, caught up by the next run). /// ``` @@ -2142,10 +2142,10 @@ impl Store { /// depreciable_basis, built_in_gain_704c}`: the facts, and for the /// line's readers the figures as derived when written (null for a /// purchase's depreciable basis: the cost, whatever it becomes). - /// Replay reads the facts and never recomputes the figures (rules.md - /// B-28). It needs the journal feature `asset_basis`: refused, + /// Replay reads the facts and never recomputes the figures ( + /// BS-entry-4). It needs the journal feature `asset_basis`: refused, /// journaling nothing, in books that haven't declared it (books an - /// older version wrote, until their format upgrade: B-27). + /// older version wrote, until their format upgrade: BS-format-1). pub fn set_asset_basis( &mut self, id: AssetId, @@ -2287,7 +2287,7 @@ impl Store { /// /// ```text /// GOAL: the books carry the schedule through the month's end. - /// SOURCE: docs/spec/rules.md B-15; plan/served.md P3 "Settled in + /// SOURCE: BS-asset-1; plan/served.md P3 "Settled in /// design" (2026-10-20): a month skipped is caught up in the /// month the run is made (an immaterial miss; a material one is /// restated, ASC 250, by a human and the CPA). @@ -2485,8 +2485,8 @@ impl Store { /// after its month, a run reversed and re-instated after the /// disposal's month) is that run's own error and correction, dated /// when they were made, the same with or without the disposal. - /// SOURCE: docs/spec/rules.md B-15 (a disposed asset depreciates through - /// its disposal day); B-9 (a mistake is corrected by an opposite + /// SOURCE: BS-asset-1 (a disposed asset depreciates through + /// its disposal day); BS-ledger-5 (a mistake is corrected by an opposite /// entry); plan/served.md P3, settled in design (a miss is /// corrected in the period the correction is made, a material /// one restated); Ledger::dispose_asset INVARIANT 1. P3 review @@ -2589,7 +2589,7 @@ impl Store { /// ```text /// GOAL: a disposal takes exactly the depreciation of the days held, /// whatever the runs posted. - /// SOURCE: docs/spec/rules.md B-15 (the disposal day is held); + /// SOURCE: BS-asset-1 (the disposal day is held); /// Ledger::dispose_asset INVARIANTS 1, 2; P3 depreciation /// review R2. /// INVARIANTS: @@ -2986,7 +2986,7 @@ impl Store { self.rehearse(|l| l.close_period_to(id, to))?; if matches!(to, CloseTo::Members(_) | CloseTo::MembersCumulative { .. }) { // A close counted from its regime's start: an older version - // would replay it under the run rule (format gate, B-27). + // would replay it under the run rule (format gate, BS-format-1). // Refused before anything is journaled until the books // declare it. self.ensure_feature(crate::format::MEMBERS_CUMULATIVE)?; @@ -3145,7 +3145,7 @@ impl Store { /// then no-ops, which keeps replay deterministic: every account /// creation is an `account.added` event. The engine's account /// (`Ledger::add_control_account`): never refused for its name or a - /// missing tax category (rules.md B-32), so an invoice, a bill or a + /// missing tax category (BS-ledger-11), so an invoice, a bill or a /// payroll run is never refused over a chart label. fn ensure_control_account( &mut self, @@ -3234,7 +3234,7 @@ impl Store { Ok((entry_id, journaled)) } - /// The feature a document's lines need (rules.md B-27): a line naming + /// The feature a document's lines need (BS-format-1): a line naming /// a project is `document_line_projects`'s; a document naming none is /// written as every version before it wrote one. fn ensure_document_lines(&self, lines: &[DocumentLine]) -> Result<(), StoreError> { @@ -3244,7 +3244,7 @@ impl Store { Ok(()) } - /// The feature a document's new fields need (rules.md B-27): an + /// The feature a document's new fields need (BS-format-1): an /// invoice or bill naming a number, terms, a snapshot, a reference, a /// memo or a duplicate's reason, or a line naming its account, quantity /// or unit price, needs `documents_v2` (plan P4b S4.3; D-52). A @@ -3319,7 +3319,7 @@ impl Store { /// GOAL: a document's new fields are journaled with it, so replay can /// never lose them, and a document naming none is written byte /// for byte as an earlier version wrote it. - /// SOURCE: docs/spec/rules.md B-27, B-40 (plan P4b S4.3); A-2, A-13. + /// SOURCE: BS-format-1, BS-arap-4 (plan P4b S4.3); A-2, A-13. /// INVARIANTS: /// 1. A write naming a number, terms, a snapshot, a reference, a memo, /// a line account, quantity or unit price MUST need journal feature @@ -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; rules.md B-40 item 3): the entry, then + /// (plan P4b S4.3 item 11, A-7; BS-arap-4 item 3): 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; - /// rules.md B-40 item 3. + /// BS-arap-4 item 3. /// INVARIANTS: /// 1. Every refusal (an unknown customer, an invalid line or due /// date, a duplicate number, a closed period, a feature the books @@ -3811,7 +3811,7 @@ impl Store { /// ```text /// GOAL: a payment is journaled once and replays to the same figures, /// in any version that can open the books. - /// SOURCE: docs/spec/rules.md B-27, B-38; plan/served.md P4b.7 + /// SOURCE: BS-format-1, BS-arap-2; plan/served.md P4b.7 /// (document_standing). /// SCENARIOS: /// 1. IF the engine refuses it (overpaid, before the invoice, a @@ -3908,7 +3908,7 @@ impl Store { } /// Settle one or more invoices or bills in one entry (plan P4b S6; - /// rules.md B-42): the core posts it ([`ledger_core::Ledger::settle`]); + /// BS-arap-6): the core posts it ([`ledger_core::Ledger::settle`]); /// this journals its lines once and one `invoice.payment_received` or /// `bill.paid` per application, each naming the control line it tags, /// then the payment method. A single legacy-shaped payment is @@ -4026,7 +4026,7 @@ impl Store { Ok(live) } - /// Write off an invoice as a bad debt (plan P4b S7; rules.md B-41), + /// Write off an invoice as a bad debt (plan P4b S7; BS-arap-5), /// filing its evidence in the same call. The write-off's entry (Dr /// 6990 Bad Debt Expense / Cr A/R) is journaled through the standard /// entry flow, then `invoice.written_off`, then the evidence: a @@ -4038,7 +4038,7 @@ impl Store { /// GOAL: a bad debt comes off the receivables with the proof it was /// worthless, in one call that is all or nothing. /// SOURCE: IRC §166(a); Treas. Reg. §1.166-1(e), -2(a), -3(a); - /// docs/spec/rules.md B-41; plan P4b S7, 8.3.6. + /// BS-arap-5; plan P4b S7, 8.3.6. /// INVARIANTS: /// 1. A write that needs journal feature documents_v2 (the event /// type) MUST be refused in books that haven't declared it, @@ -4144,7 +4144,7 @@ impl Store { } Ok((entry_id, attachment_id)) } - /// The journal features a settlement needs (rules.md B-27, B-42): + /// The journal features a settlement needs (BS-format-1, BS-arap-6): /// `documents_v2` for more than one application, a discount or a fee /// (an older version would drop them, and the balance would be wrong), /// `document_standing` when an application pays more than an older @@ -4207,7 +4207,7 @@ impl Store { /// ```text /// GOAL: a send is journaled once and replays to the same record, in /// every version that can read the books. - /// SOURCE: docs/spec/rules.md B-27, B-38; plan P4b S5, A-4. + /// SOURCE: BS-format-1, BS-arap-2; plan P4b S5, A-4. /// SCENARIOS: /// 1. IF the engine refuses it (unknown or void invoice, a date /// before the invoice, no recipients, a text the books won't @@ -4528,13 +4528,13 @@ impl Store { Ok(live) } - /// Add a project (rules.md B-37): `class.added`, then `project.set` + /// Add a project (BS-statement-5): `class.added`, then `project.set` /// when `facts` say more than the defaults. Returns its id. /// /// ```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: docs/spec/rules.md B-37 item 1; B-27 (journal feature + /// SOURCE: BS-statement-5 item 1; BS-format-1 (journal feature /// `projects`). /// INVARIANTS: /// 1. A refusal journals nothing: the whole record is rehearsed, and @@ -5186,7 +5186,7 @@ impl Store { /// /// ```text /// GOAL: rename an account, keeping the name it had in the journal. - /// SOURCE: rules.md B-31; Rev. Proc. 98-25 (docs/spec/sources/ + /// SOURCE: BS-ledger-10; Rev. Proc. 98-25 (docs/spec/sources/ /// irs-records.md): a report printed under the old name can /// be tied to the new one. /// INVARIANTS: @@ -5251,7 +5251,7 @@ impl Store { /// Set (or clear) an account's tax category and deductible percent. /// Journaled as `account.tax_set`. Under /// `policy.require_tax_category = refuse`, an account that needs a - /// category is never left without one (rules.md B-32; + /// category is never left without one (BS-ledger-11; /// `Ledger::check_tax_category_kept`). pub fn set_account_tax( &mut self, @@ -5646,7 +5646,7 @@ impl Store { // ------------------------------------------------------------------ /// The journal feature a link to `subject` needs, if any: a subject - /// kind an older version doesn't know (a project, rules.md B-37). + /// kind an older version doesn't know (a project, BS-statement-5). /// Callers filing a file with links ask it before filing, so a refusal /// leaves nothing half-filed. pub fn subject_feature(subject: Subject) -> Option<&'static str> { @@ -6847,8 +6847,8 @@ fn document_line_json(l: &DocumentLine) -> Value { "description": l.description, "amount": l.amount.to_string(), }); - // Its project, behind the feature document_line_projects (rules.md - // B-27, B-37 item 8); a line naming none is written as before it. + // 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. 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 (rules.md B-40 item +/// set. A duplicate's reason is journaled for the record (BS-arap-4 item /// 4); the bill itself keeps none. fn bill_fields_json(payload: &mut Value, fields: &arap::BillFields) { if let Some(r) = &fields.vendor_ref { @@ -7151,7 +7151,7 @@ fn parse_side(s: &str) -> Result { /// earlier version accepted ("+10000-01-01" and "-0001-01-01" included). /// The calendar the books keep (ledger_core::calendar) bounds new /// commands, never replay: a date an earlier version journaled always -/// replays (rules.md B-28). +/// replays (BS-entry-4). fn parse_date(s: &str) -> Result { chrono::NaiveDate::parse_from_str(s, "%Y-%m-%d") .map_err(|_| StoreError::JournalCorrupt(format!("bad date {s}"))) @@ -7248,7 +7248,7 @@ fn get_opt_decimal(p: &Value, key: &str) -> Result { /// A full TIN is found as the version before P3 found one /// (`ledger_core::parties::replaying`): a name, reason or fact an earlier /// version took replays, however the commands' detector has widened since -/// (rules.md B-28). +/// (BS-entry-4). pub(crate) fn replay_line_into_ledger( ledger: &mut Ledger, line: &JournalLine, @@ -7384,7 +7384,7 @@ fn replay_line( let want = get_u64(p, "id")?; let orig = get_u64(p, "reverses")?; // As journaled: a reversal later rules would refuse (a void - // under a payment that stands) replays (rules.md B-28). + // under a payment that stands) replays (BS-entry-4). let got = ledger.replay_reverse_entry( orig, parse_date(get_str(p, "date")?)?, @@ -7400,7 +7400,7 @@ fn replay_line( let want = get_u64(p, "id")?; // No convention (every schedule before P3): equal months, as // they were posted. A convention this version doesn't know is - // newer, never corrupt (rules.md B-27). + // newer, never corrupt (BS-format-1). let convention = match p.get("convention") { None | Some(Value::Null) => ledger_core::ScheduleConvention::MonthlyEven, Some(Value::String(c)) => { @@ -7525,7 +7525,7 @@ fn replay_line( } "account.renamed" => { // Only that the account exists: the name rules are the - // command's (rules.md B-28). `code`, `previous` and `reason` + // command's (BS-entry-4). `code`, `previous` and `reason` // are the record, not state. ledger.replay_rename_account(get_u64(p, "account_id")?, get_str(p, "name")?)?; } @@ -7567,7 +7567,7 @@ fn replay_line( | "attachment.text_extracted" => { // Not accounting state; the projection records them. (The text // record is checked for shape here: an unknown status is newer, - // rules.md B-27.) + // BS-format-1.) if line.line_type == "attachment.text_extracted" { crate::meta::text_extracted_of(line)?; } @@ -7578,7 +7578,7 @@ fn replay_line( } "audit.run" => { // Not accounting state; the projection records it. Checked - // for shape here (an unknown scope is newer, rules.md B-27). + // for shape here (an unknown scope is newer, BS-format-1). crate::meta::audit_run_of(line)?; } // A claim that someone checked; no figure moves. @@ -7647,7 +7647,7 @@ fn replay_line( } "party.updated" => { // A field this version doesn't know: a newer one wrote it - // (rules.md B-27). A known field with a bad value is damage. + // (BS-format-1). A known field with a bad value is damage. if let Some(field) = p .get("change") .and_then(|c| c.get("field")) @@ -7754,7 +7754,7 @@ fn replay_line( // this line says it was the asset's run for the month, which is // what the books carry for the asset (Ledger::accumulated_posted). // Replay checks only that it is well formed and names an asset - // and entry that exist (rules.md B-28). + // and entry that exist (BS-entry-4). let amount = get_str(p, "amount")?.parse::().map_err(|_| { StoreError::JournalCorrupt("asset.depreciation_posted amount".into()) })?; @@ -8083,8 +8083,8 @@ fn optional_decimal(p: &Value, key: &str) -> Result, ()> { /// An `asset.basis_set`'s facts. A rule or §704(c) method this version /// doesn't know was written by a newer one: NewerJournal, never corrupt -/// (rules.md B-27). The figures the line carries are type-checked and -/// otherwise left to its readers: replay never recomputes them (B-28). +/// (BS-format-1). The figures the line carries are type-checked and +/// otherwise left to its readers: replay never recomputes them (BS-entry-4). fn asset_basis_from_journal( line: &JournalLine, p: &Value, @@ -8122,7 +8122,7 @@ fn asset_basis_from_journal( /// A journaled close's target. A rounding rule only a newer version /// writes (an unknown name, or a value that isn't a name) is newer, never -/// corrupt (rules.md B-27). +/// corrupt (BS-format-1). fn close_to_from_journal(line: &JournalLine, v: Option<&Value>) -> Result { let corrupt = |what: &str| StoreError::JournalCorrupt(format!("close_to: {what}")); let ids = |v: &Value| -> Result, StoreError> { @@ -9002,11 +9002,11 @@ fn apply_line_rows(conn: &Connection, line: &JournalLine) -> Result<(), StoreErr )?; } // A payment moves no document row: what a document is paid is read - // from the ledger lines tagged with it (schema v15, rules.md B-38). + // from the ledger lines tagged with it (schema v15, BS-arap-2). "invoice.payment_received" => {} // A write-off moves no document row either: written_off and the // status are derived from the tagged lines (the tag is set by - // replay; rules.md B-41). + // replay; BS-arap-5). "invoice.written_off" => {} "bill.paid" => { conn.execute( @@ -9396,8 +9396,8 @@ pub enum Subject { Schedule(u64), /// A reconciliation (its statement). Reconciliation(u64), - /// A project (its contract, spec, pitch, correspondence; rules.md - /// B-37). Journal feature `projects`. + /// A project (its contract, spec, pitch, correspondence; + /// BS-statement-5). Journal feature `projects`. Project(u64), /// The company itself (formation documents). Company, diff --git a/crates/ledger-store/tests/arap_props.rs b/crates/ledger-store/tests/arap_props.rs index 8eaf802e..2a2e5c51 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 (rules.md B-38 INVARIANTS 1, 2, +//! 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 //! payment method and a reference, or none), voids, reversals of any //! entry, closed months and refused hand lines, run through `Store`, then @@ -9,7 +9,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: docs/spec/rules.md B-28 (replay), B-38 INVARIANTS 1, 2, 4, 6. +//! SOURCE: BS-entry-4 (replay), BS-arap-2 INVARIANTS 1, 2, 4, 6. //! ``` use chrono::NaiveDate; @@ -417,7 +417,7 @@ fn agree(live: &Ledger, dir: &Path, docs: &[DocRef]) -> Result<(), TestCaseError proptest! { #![proptest_config(ProptestConfig::with_cases(32))] - /// B-38 INVARIANT 4 (and 1, 2, 6 through the store): a document's + /// BS-arap-2 INVARIANT 4 (and 1, 2, 6 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 5c7ac979..a466b7f3 100644 --- a/crates/ledger-store/tests/arap_standing.rs +++ b/crates/ledger-store/tests/arap_standing.rs @@ -1,5 +1,5 @@ //! Documents read their figures from the ledger lines tagged with them -//! (plan P4b S1, D-45; rules.md B-38): the books an earlier version wrote, +//! (plan P4b S1, D-45; BS-arap-2): the books an earlier version wrote, //! replayed, and the golden figures that version showed for them. //! //! The fixture `tests/fixtures/p4-arap-before` is a books dir written by @@ -377,7 +377,7 @@ fn legacy_reversal_now_counts() { assert_eq!(trial_balance_json(&again), g["trial_balance"]); } -/// B-38 scenario 5 and item 7 in books an earlier version keeps: the +/// BS-arap-2 scenario 5 and item 7 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 @@ -430,7 +430,7 @@ fn repaying_after_a_reversal_waits_for_document_standing() { } /// The control guard through the store, and a void under a payment: -/// refused, journaling nothing (B-38 scenarios 3 and 6). +/// refused, journaling nothing (BS-arap-2 scenarios 3 and 6). #[test] fn the_store_refuses_hand_lines_and_a_void_under_a_payment() { let dir = fixture("guard"); @@ -619,7 +619,7 @@ fn legacy_documents_replay_with_tags() { /// A document's new fields (its number, terms, snapshots, references, a /// line's account, quantity or price) wait for the journal feature -/// `documents_v2` (plan P4b S4.3; rules.md B-27): refused, +/// `documents_v2` (plan P4b S4.3; BS-format-1): refused, /// FormatUpgradePending, journaling nothing, in books that haven't declared /// it; after the owner's upgrade the same writes are taken, and the books /// replay to what was live. @@ -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; rules.md B-40 item 3): a refusal leaves the journal, the +/// item 11, A-7; BS-arap-4 item 3): 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 @@ -1166,7 +1166,7 @@ fn sends_replay_and_project() { ); } -/// A send changes no figure (plan P4b S5, B-38): on the fixture book an +/// A send changes no figure (plan P4b S5, BS-arap-2): on the fixture book an /// earlier version wrote, every report, every derived document figure and /// the invoice's whole DocState are the same before and after it. #[test] @@ -1247,7 +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; rules.md B-42 +/// the books replaying to the same lines (plan P4b S6; BS-arap-6 /// INVARIANTS 1 and 3). #[test] fn a_settlement_names_its_lines_and_replays() { @@ -1360,7 +1360,7 @@ fn a_settlement_names_its_lines_and_replays() { /// A settlement of more than one document, a discount or a fee needs /// `documents_v2`: refused, journaling nothing, in books without it, and /// accepted after the owner's upgrade, replaying to the same books (plan -/// P4b S6; rules.md B-27, B-42). +/// P4b S6; BS-format-1, BS-arap-6). #[test] fn settlement_waits_for_documents_v2() { use ledger_core::{Application, DocRef, SettleParams}; @@ -1422,7 +1422,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; rules.md B-42 INVARIANT 3). +/// order the events come (plan P4b S6; BS-arap-6 INVARIANT 3). #[test] fn legacy_payment_events_keep_the_positional_rule() { use ledger_core::{DocRef, Movement}; @@ -1460,7 +1460,7 @@ fn legacy_payment_events_keep_the_positional_rule() { } // --------------------------------------------------------------------------- -// Bad-debt write-offs (plan P4b S7; rules.md B-41) +// Bad-debt write-offs (plan P4b S7; BS-arap-5) // --------------------------------------------------------------------------- /// The evidence a write-off test files: a collection letter. @@ -1527,7 +1527,7 @@ fn a_write_off_whose_notice_is_anothers_receipt_is_refused_before_posting() { /// A write-off needs journal feature documents_v2 (its event type is new; /// an older version refuses the unknown type): refused, journaling /// nothing, until the owner's upgrade; then it is taken and replays to the -/// same books (R-A, B-27). +/// same books (R-A, BS-format-1). #[test] fn write_off_waits_for_documents_v2() { let dir = fixture("write-off-v2"); @@ -1582,7 +1582,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 (B-41, B-38 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 +1600,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 (B-38 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 +1683,7 @@ fn write_off_replays_and_projects() { s.verify().unwrap(); } -/// No evidence, no write-off (B-41 INVARIANT 1; Treas. Reg. +/// No evidence, no write-off (BS-arap-5 INVARIANT 1; 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_orders.rs b/crates/ledger-store/tests/asset_orders.rs index 142659ef..f1d4a75f 100644 --- a/crates/ledger-store/tests/asset_orders.rs +++ b/crates/ledger-store/tests/asset_orders.rs @@ -8,7 +8,7 @@ //! never carry a month twice, take exactly cost less salvage over //! the life, and dispose at proceeds less the book value of the //! days held. -//! SOURCE: docs/spec/rules.md B-9, B-10, B-15; plan/served.md P3 (settled +//! SOURCE: BS-ledger-5, BS-ledger-6, BS-asset-1; plan/served.md P3 (settled //! in design: a skipped month is caught up in the month the run is //! made); Ledger::dispose_asset INVARIANT 1. //! INVARIANTS (checked after every command, refused or not): diff --git a/crates/ledger-store/tests/asset_tags.rs b/crates/ledger-store/tests/asset_tags.rs index f688bbea..2473719a 100644 --- a/crates/ledger-store/tests/asset_tags.rs +++ b/crates/ledger-store/tests/asset_tags.rs @@ -1,14 +1,14 @@ -//! Spec-derived store tests for asset tags and serial numbers (rules.md -//! B-24): journaling (`asset.tagged` {asset_id, tag, previous_tag}, +//! Spec-derived store tests for asset tags and serial numbers ( +//! BS-asset-3): journaling (`asset.tagged` {asset_id, tag, previous_tag}, //! `asset.serial_set` {asset_id, serial | null}), replay on reopen, the v9 //! SQLite projection agreeing with the journal (`Store::verify`), books //! written before tags existed, refusals journaling nothing, and corrupt -//! `asset.serial_set` lines refused on open; and tax basis (B-25: +//! `asset.serial_set` lines refused on open; and tax basis (BS-asset-4: //! `asset.basis_set`, pre-P3 `asset.tax_basis_set` {asset_id, rule, //! contributor_basis | null} replayed, the v10 schema and v13's, corrupt //! and newer payloads). A database at an older schema under this //! version's file name is rebuilt, never migrated, and P2's own file is -//! left as it is (each schema keeps a file of its own: rules.md B-27, +//! left as it is (each schema keeps a file of its own: BS-format-1, //! tests/schema_files.rs). //! //! Expectations come from the doc comments on `Store::set_asset_tag`, @@ -405,7 +405,7 @@ fn downgrade_db_to_v8(dir: &Path) { /// A database at schema v8 under this version's own file name (what an /// older wanderbooks once migrated in place) is never migrated now: each -/// schema keeps a file of its own (rules.md B-27), so this one is damaged, +/// schema keeps a file of its own (BS-format-1), so this one is damaged, /// kept aside and rebuilt from the journal as the books open, and verifies. #[test] fn a_v8_database_migrates_and_verifies() { @@ -571,7 +571,7 @@ fn a_description_change_replays_and_verifies() { s.verify().unwrap(); } -// ------------------------------------------------- tax basis (rules.md B-25) +// ------------------------------------------------- tax basis (BS-asset-4) // // Expectations from `Store::set_asset_basis` (journaled as // `asset.basis_set`, the feature `asset_basis` declared first), @@ -822,7 +822,7 @@ fn a_basis_set_whose_figures_disagree_still_replays() { } /// A basis rule or §704(c) method this version doesn't know was written -/// by a newer one: NewerJournal, never corrupt (rules.md B-27); a figure +/// by a newer one: NewerJournal, never corrupt (BS-format-1); a figure /// or fact that isn't a decimal string (or null) is corrupt. #[test] fn an_unknown_basis_rule_or_method_is_newer() { @@ -955,7 +955,7 @@ fn downgrade_db_to_v10(dir: &Path) { /// for byte: this version builds its own file from the journal, its /// runs table keyed by entry with every run kept and the new columns /// empty, and it verifies; a basis set after then reloads from it (each -/// schema in a file of its own: rules.md B-27). +/// schema in a file of its own: BS-format-1). #[test] fn a_p2_database_is_left_and_this_versions_built_from_the_journal() { use ledger_core::BasisRule::*; @@ -1175,7 +1175,7 @@ fn reversing_a_linked_acquisition_still_opens_and_verifies() { Store::open(&dir).unwrap().verify().unwrap(); } -// ------------------------------------------------- depreciation runs (rules.md B-15 rules 6 and 8) +// ------------------------------------------------- depreciation runs (BS-asset-1 rules 6 and 8) /// A run is the books' record of what they carry for an asset /// (Ledger::accumulated_posted): recorded live, replayed from the journal, @@ -1219,7 +1219,7 @@ fn runs_replay_reload_and_verify_catches_a_tampered_run() { /// The writer and the viewer read an `asset.depreciation_posted` line the /// same way: well formed and naming an asset and an entry that exist, it -/// replays (any period an earlier version journaled, rules.md B-28); +/// replays (any period an earlier version journaled, BS-entry-4); /// otherwise both refuse it as corrupt. #[test] fn the_viewer_and_writer_agree_on_a_bad_depreciation_posted_payload() { @@ -1257,7 +1257,7 @@ fn the_viewer_and_writer_agree_on_a_bad_depreciation_posted_payload() { } } -/// B-27: books an older version wrote (format 1, declaring nothing) refuse +/// BS-format-1: books an older version wrote (format 1, declaring nothing) refuse /// a basis while they wait for the owner's format upgrade, a purchase's /// too, journaling nothing; the feature is never declared on the way (P3 /// review, 2026-10-21). diff --git a/crates/ledger-store/tests/assets.rs b/crates/ledger-store/tests/assets.rs index 36c20585..eef46c04 100644 --- a/crates/ledger-store/tests/assets.rs +++ b/crates/ledger-store/tests/assets.rs @@ -875,7 +875,7 @@ fn a_run_reinstated_after_its_rerun_was_reversed_still_counts() { Store::open(dir.path()).unwrap().verify().unwrap(); } -/// P3 review round 2: a correction comes after what it corrects (B-9). A +/// P3 review round 2: a correction comes after what it corrects (BS-ledger-5). A /// reversal of a depreciation run dated before the run (March's run, dated /// Mar 31, reversed on Feb 10) would leave January and February with /// negative depreciation, and a disposal on Feb 15 clearing what February diff --git a/crates/ledger-store/tests/audit.rs b/crates/ledger-store/tests/audit.rs index 7fd1f7e7..fb97f36b 100644 --- a/crates/ledger-store/tests/audit.rs +++ b/crates/ledger-store/tests/audit.rs @@ -1,4 +1,4 @@ -//! Audits and attestations in the store (plan P8; rules.md B-45): the +//! Audits and attestations in the store (plan P8; BS-ledger-13): the //! `audits` feature, the figure head, idempotent runs, attestations that //! rest on a head, and the integrity findings only the store can see. diff --git a/crates/ledger-store/tests/bounds.rs b/crates/ledger-store/tests/bounds.rs index c3266e67..3dcd79c2 100644 --- a/crates/ledger-store/tests/bounds.rs +++ b/crates/ledger-store/tests/bounds.rs @@ -1,7 +1,7 @@ //! The store refuses what the books can't hold, before it journals //! anything, never a panic (P0 review round 3, S1: a panic stops the books //! server). The bounds are for new commands only: books an earlier version -//! wrote past them open exactly as written (rules.md B-28; P0 review round +//! wrote past them open exactly as written (BS-entry-4; P0 review round //! 4), each bound's pair here or in tests/fixtures/old-books. //! //! ```text @@ -233,7 +233,7 @@ fn disposal_proceeds_larger_than_a_line_are_refused() { assert_eq!(old.ledger().get_entry(2).unwrap().date(), d(10000, 1, 31)); } -/// The bounds are for new commands only (rules.md B-28: posted is +/// The bounds are for new commands only (BS-entry-4: posted is /// forever). A journal line an earlier version wrote past them (a date /// after 9999, up to chrono's last day, as chrono writes it: "+10000-01-01"; /// a draft or recurring line past the line limit) opens, in the writer and the viewer alike, exactly as written. A diff --git a/crates/ledger-store/tests/document_projects.rs b/crates/ledger-store/tests/document_projects.rs index d3722ea9..d0e43f7e 100644 --- a/crates/ledger-store/tests/document_projects.rs +++ b/crates/ledger-store/tests/document_projects.rs @@ -1,5 +1,5 @@ -//! An invoice's or bill's lines in the journal (rules.md B-37 item 8, -//! B-27): a line naming its project carries `class_id` (journal feature +//! An invoice's or bill's lines in the journal (BS-statement-5 item 8, +//! 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 //! `entry.line_added`. A document naming no project is journaled exactly @@ -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: docs/spec/rules.md B-37 item 8, B-27, B-28; plan/served.md +//! SOURCE: BS-statement-5 item 8, BS-format-1, BS-entry-4; plan/served.md //! D-39 (the owner's upgrade). //! ``` @@ -479,7 +479,7 @@ fn old_invoices_and_bills_replay_unchanged() { /// A document line's `class_id` that isn't a class id is damage, never /// silently no project; null is none, and an id is taken as journaled -/// (replay checks no line, B-28). +/// (replay checks no line, BS-entry-4). #[test] fn a_document_lines_class_id_that_isnt_an_id_is_corrupt() { let journal = |dir: &Path, class: Value| { diff --git a/crates/ledger-store/tests/exact_totals.rs b/crates/ledger-store/tests/exact_totals.rs index a607e28e..60574cef 100644 --- a/crates/ledger-store/tests/exact_totals.rs +++ b/crates/ledger-store/tests/exact_totals.rs @@ -1,5 +1,5 @@ //! Documents whose lines' sum is past exact arithmetic are refused, never a -//! panic (kernel sweep unit K-U4; rules.md B-21, B-28). +//! panic (kernel sweep unit K-U4; BS-entry-3, BS-entry-4). //! //! A posted entry's lines are bounded by the line cap at the moment it //! posts, restored or new (`entry.posted` validates), so a report's sums @@ -9,8 +9,8 @@ //! ```text //! GOAL: a document whose lines sum past exact arithmetic is refused with //! a ledger error and journals nothing. -//! SOURCE: docs/spec/rules.md B-28 (a replayed line is accepted of any -//! size), B-21 (amounts are exact); bookspec BS-entry-3, +//! SOURCE: BS-entry-4 (a replayed line is accepted of any +//! size), BS-entry-3 (amounts are exact); bookspec BS-entry-3, //! BS-entry-4. //! ``` diff --git a/crates/ledger-store/tests/form1099.rs b/crates/ledger-store/tests/form1099.rs index c9726db9..1ae8af53 100644 --- a/crates/ledger-store/tests/form1099.rs +++ b/crates/ledger-store/tests/form1099.rs @@ -8,7 +8,7 @@ //! ```text //! GOAL: the decision ("no 1099" included) and how each payment was made //! are kept as records, and no version ever misreads them. -//! SOURCE: rules.md B-19, B-27; ledger_store::form1099 INVARIANTS 1-5. +//! SOURCE: BS-1099-1, BS-format-1; ledger_store::form1099 INVARIANTS 1-5. //! ``` use chrono::NaiveDate; @@ -139,7 +139,7 @@ fn types(dir: &Path) -> Vec<(String, serde_json::Value)> { .collect() } -/// B-27: a line that needs a feature is written only in books that +/// BS-format-1: a line that needs a feature is written only in books that /// declare it, and a command never declares one on the way. Books an /// older version wrote (format 1) refuse a decision and a payment method /// while they wait for their format upgrade, journaling nothing; the @@ -500,7 +500,7 @@ fn marking_a_w9_keeps_who_decided_the_1099() { assert_eq!(v.decisions_1099, [decision]); } -/// B-27: a value only a newer version writes, in a line of a type this +/// BS-format-1: a value only a newer version writes, in a line of a type this /// version knows (a 1099 decision, a reason kind, a payment method's /// kind), is newer, never corrupt; a malformed one is corrupt. #[test] diff --git a/crates/ledger-store/tests/format.rs b/crates/ledger-store/tests/format.rs index c0483b75..7e1e1e28 100644 --- a/crates/ledger-store/tests/format.rs +++ b/crates/ledger-store/tests/format.rs @@ -5,7 +5,7 @@ //! GOAL: an older wanderbooks tells the human to update, not that the //! books are damaged, and never shows books that differ from the //! record without saying so. -//! SOURCE: rules.md B-27; plan/served.md 5.1 (format gate). +//! SOURCE: BS-format-1; plan/served.md 5.1 (format gate). //! INVARIANTS: //! 1. A whole, chained line of a type this version doesn't know, or a //! journal.format_set newer than it reads, is NewerJournal: from @@ -436,7 +436,7 @@ fn edit_journal(dir: &Path, edit: impl FnOnce(&mut Vec)) { } /// A line's own hash is checked only by the next line's prev, so the -/// gate's refusal waits for it (rules.md B-27): a flipped bit in a middle +/// gate's refusal waits for it (BS-format-1): a flipped bit in a middle /// line's type, or a declared format edited from 1 to 2, reads like books /// from a newer wanderbooks until the next line shows the line changed. /// That is corruption, from the writer and the viewer alike. @@ -525,8 +525,8 @@ fn a_newer_line_the_next_line_chains_onto_is_newer_and_intact() { /// A line the gate refuses, followed by a complete line this version /// can't even parse as JSON (or a blank one), is unverified: nothing /// checks the refused line, so it is newer or damaged, never corrupt for -/// certain (a newer format may frame its lines its own way; rules.md -/// B-27), and never intact. +/// certain (a newer format may frame its lines its own way; +/// BS-format-1), and never intact. #[test] fn a_refused_line_followed_by_a_garbled_line_is_unverified() { for (i, garbled) in ["{not json", "", "[1,2]", "{\"prev\":7}"] @@ -567,7 +567,7 @@ fn append_raw(dir: &Path, bytes: &[u8]) { } /// A newer format frames the lines after its declaration its own way -/// (rules.md B-27): a float, a string seq, a key of its own. This version +/// (BS-format-1): a float, a string seq, a key of its own. This version /// reads only the next line's prev, so it never calls such books corrupt: /// the declaration is intact when that prev checks it, unverified when the /// next line has no prev it can read, and corrupt only when a prev it can @@ -632,7 +632,7 @@ fn a_newer_format_frames_its_lines_its_own_way() { } } -/// A key beside the envelope's is never dropped (rules.md B-27): the line +/// A key beside the envelope's is never dropped (BS-format-1): the line /// is refused as newer, and its hash covers the key, so the next line /// still checks it (intact), a next line hashed without the key shows it /// was added (corrupt), and as the last line it is unverified. The writer @@ -759,7 +759,7 @@ fn an_old_reader_never_repairs_newer_books() { assert_eq!(store.tail_repairs().unwrap().len(), 1); } -/// B-27 ("a cut-off last line is set aside only when the lines before it +/// BS-format-1 ("a cut-off last line is set aside only when the lines before it /// pass"; Store::open SCENARIO 3): a complete line that chains and passes /// the gate but can't be applied (a post of an entry that doesn't exist), /// or a first line that isn't store.created, refuses the open with the @@ -803,7 +803,7 @@ fn a_bad_complete_line_before_a_torn_tail_leaves_the_journal_as_it_was() { )); } -/// The viewer applies the writer's rule for the first line (B-27: the +/// The viewer applies the writer's rule for the first line (BS-format-1: the /// two read the same journal the same way): it must be a store.created /// naming a currency. Any other first line, or a store.created without a /// sound base_currency, is corrupt for both; neither guesses a currency. @@ -920,7 +920,7 @@ fn read_journal_and_format_gives_every_line_and_the_format() { ); } -/// P3's journal extensions (rules.md B-27; plan D-39): each is announced +/// P3's journal extensions (BS-format-1; plan D-39): each is announced /// by a feature this version knows, `account_renamed` for an /// `account.renamed`, `require_tax_category` for a `settings.set` naming /// `policy.require_tax_category`. Books an older version made (books(): @@ -1090,7 +1090,7 @@ fn lines(dir: &Path) -> Vec { .collect() } -/// P3 (defect 9; rules.md B-27, D-39): a daily schedule's +/// P3 (defect 9; BS-format-1, D-39): a daily schedule's /// schedule.registered, which carries convention "daily", needs journal /// feature schedule_convention. Books an older version made (books(): /// format 1) refuse one, journaling nothing, until the owner's format @@ -1193,7 +1193,7 @@ fn a_monthly_even_schedule_declares_no_feature() { } /// P3: a schedule convention this version doesn't know (one a newer -/// version adds) is newer, never corrupt (rules.md B-27); one that isn't a +/// version adds) is newer, never corrupt (BS-format-1); one that isn't a /// string is damage. #[test] fn an_unknown_schedule_convention_is_newer_not_corrupt() { @@ -1234,7 +1234,7 @@ fn an_unknown_schedule_convention_is_newer_not_corrupt() { assert_corrupt(Store::open(&dir)); } -/// P4b S4.2 (rules.md B-27): a `party.updated` naming a field this version +/// P4b S4.2 (BS-format-1): a `party.updated` naming a field this version /// doesn't know is newer, never corrupt; a known field with a malformed /// value is still damage. #[test] @@ -1283,7 +1283,7 @@ fn an_unknown_party_field_is_newer_not_corrupt() { assert_corrupt(Store::open(&dir)); } -/// P3 (R3; rules.md B-27): a schedule month reversed within its month is +/// P3 (R3; BS-format-1): a schedule month reversed within its month is /// posted again only in books that declare journal feature month_reposting /// (an older version would refuse the second schedule.posted as posted /// twice): books an older version made wait for the format upgrade, and @@ -1506,7 +1506,7 @@ fn the_replay_fuzzer_writes_every_event_type() { /// Done-when (plan P4b S5): the send event is this version's, it needs /// `documents_v2`, and the books declare that feature before the first /// `invoice.sent` line, so a version without it stops at the declaration -/// and reports the books as newer, never corrupt (rules.md B-27). +/// and reports the books as newer, never corrupt (BS-format-1). #[test] fn an_older_version_stops_at_invoice_sent() { assert!(EVENT_TYPES.contains(&"invoice.sent")); @@ -1585,9 +1585,9 @@ fn an_older_version_stops_at_invoice_sent() { /// The weekly fuzz run of 2026-10-26 (`fuzz_store_replay`, crash /// 0dfab1cc): a journal whose `convention.set` names a kind this version -/// doesn't know. The writer says NewerJournal (B-27: newer content is +/// doesn't know. The writer says NewerJournal (BS-format-1: newer content is /// newer, never corrupt); the viewer must say the same, since the two -/// share one reading of the journal (rules.md B-27, docs/architecture.md +/// share one reading of the journal (BS-format-1, docs/architecture.md /// "The journal format gate"). #[test] fn an_unknown_convention_kind_is_newer_for_the_writer_and_the_viewer_alike() { @@ -1624,7 +1624,7 @@ fn an_unknown_convention_kind_is_newer_for_the_writer_and_the_viewer_alike() { /// `drafts_v2`, and the books declare that feature before the first such /// line, so a version without it stops at the declaration and reports the /// books as newer, never corrupt, never keeping a discarded draft that -/// would block a close (rules.md B-27, B-43). +/// would block a close (BS-format-1, BS-entry-5). #[test] fn an_older_version_stops_at_the_draft_events() { assert!(EVENT_TYPES.contains(&"entry.draft_state_set")); diff --git a/crates/ledger-store/tests/format_upgrade.rs b/crates/ledger-store/tests/format_upgrade.rs index 164731fe..d94bcbbd 100644 --- a/crates/ledger-store/tests/format_upgrade.rs +++ b/crates/ledger-store/tests/format_upgrade.rs @@ -1,4 +1,4 @@ -//! The format upgrade (plan/served.md 3.9, D-39; rules.md B-27): books an +//! The format upgrade (plan/served.md 3.9, D-39; BS-format-1): books an //! older wanderbooks wrote open on their old journal format, refuse only //! what needs the new one, and move to this version's format in one //! journaled step; books this version makes are in its format from their @@ -9,7 +9,7 @@ //! without the owner's go-ahead, and an upgrade changes nothing of the //! books but what may be written from then on. //! SOURCE: plan/served.md 3.9 ("Format changes are the server's gate, not -//! the updater's"); D-39; rules.md B-27. +//! the updater's"); D-39; BS-format-1. //! INVARIANTS: //! 1. New books declare this version's format, every feature it knows, //! as they are created: they wait for no upgrade. diff --git a/crates/ledger-store/tests/golden_drafts.rs b/crates/ledger-store/tests/golden_drafts.rs index 14aff4ac..0099095c 100644 --- a/crates/ledger-store/tests/golden_drafts.rs +++ b/crates/ledger-store/tests/golden_drafts.rs @@ -1,9 +1,9 @@ //! Golden file for draft states, discard and the one evidence gate //! (`docs/parity.md`: "Draft states and discard" and "One evidence gate"). //! -//! Rules: `docs/spec/rules.md` B-43 (a draft waits on its evidence; one that +//! Rules: BS-entry-5 (a draft waits on its evidence; one that //! will never post can be discarded), D-47 (a reversal needs no receipt of -//! its own), B-12 (a period with an open draft cannot close). +//! its own), BS-period-2 (a period with an open draft cannot close). //! //! It is a `Store` fixture, not a bare `Ledger`, because the gate's second //! half (is a receipt on file) lives in the store. Every expected value is diff --git a/crates/ledger-store/tests/member_closes.rs b/crates/ledger-store/tests/member_closes.rs index 32fefbc9..b1affef4 100644 --- a/crates/ledger-store/tests/member_closes.rs +++ b/crates/ledger-store/tests/member_closes.rs @@ -1,4 +1,4 @@ -//! Members closes in the journal (P3 defect 17, rules.md B-13, B-27): +//! Members closes in the journal (P3 defect 17, BS-partner-1, BS-format-1): //! the cumulative rule's feature declaration, its `since_seq`, what a //! newer or damaged rounding tag does on replay, and the first close after //! the upgrade on books an earlier version wrote. Every expected figure is @@ -166,7 +166,7 @@ fn three_cumulative_closes(dir: &Path) -> Books { b } -/// Contract (rules.md B-27; P3 defect 17; D-39): a members close counted +/// Contract (BS-format-1; P3 defect 17; D-39): a members close counted /// from its regime's start needs the `members_cumulative` feature, so an /// older version stops at its declaration (it would replay the close under /// the run rule). New books declare it on their second line, with the rest @@ -262,7 +262,7 @@ fn the_first_cumulative_close_declares_its_feature() { /// A change to a journaled close's target. type Edit = dyn Fn(&mut Value); -/// Contract (rules.md B-27; P3 review R-9): a rounding rule only a newer +/// Contract (BS-format-1; P3 review R-9): a rounding rule only a newer /// version writes is newer, never corrupt: an unknown name, or a value /// that isn't a name. A `since_seq` beside another rule, or a /// "cumulative_since" without a usable one, is damage. @@ -325,7 +325,7 @@ fn an_unknown_rounding_is_newer_not_corrupt() { } } -/// Contract (B-13, B-8): a count that starts after the books' first close +/// Contract (BS-partner-1, BS-ledger-4): a count that starts after the books' first close /// journals the close it starts at, and replays to it. January's cent /// closes at 50/50 (close 1, A's: the tie). February's at 60/40 starts a /// new count at close 2 (0.006 / 0.004: A's), and March's continues it @@ -364,7 +364,7 @@ fn a_count_that_starts_later_journals_its_start() { assert_eq!((bal(b.caps[0]), bal(b.caps[1])), (dec("0.02"), dec("0.01"))); } -/// Contract (B-8, B-13): replay re-derives where each count of members +/// Contract (BS-ledger-4, BS-partner-1): replay re-derives where each count of members /// closes starts and refuses a close journaled with another start, so a /// wrong `since_seq` makes the books refuse to open, never show figures /// split some other way. diff --git a/crates/ledger-store/tests/p2_compat.rs b/crates/ledger-store/tests/p2_compat.rs index 1dbf3dda..69dfcd2a 100644 --- a/crates/ledger-store/tests/p2_compat.rs +++ b/crates/ledger-store/tests/p2_compat.rs @@ -1,5 +1,5 @@ //! Books P2 wrote, served by this version before the owner's go-ahead -//! (plan/served.md 3.9, D-39; rules.md B-27, B-28): nothing is written +//! (plan/served.md 3.9, D-39; BS-format-1, BS-entry-4): nothing is written //! that P2 can't read, or would read with another meaning, and every line //! P2 wrote opens. //! @@ -23,7 +23,7 @@ //! upgrade (a category P2 knew, months run in order, a disposal on or //! after the in-service date). //! 3. A line P2 accepted replays, in the writer and the viewer, however -//! the commands' checks have widened since (B-28). +//! the commands' checks have widened since (BS-entry-4). //! ``` use chrono::NaiveDate; diff --git a/crates/ledger-store/tests/parties.rs b/crates/ledger-store/tests/parties.rs index 60e11398..efa74213 100644 --- a/crates/ledger-store/tests/parties.rs +++ b/crates/ledger-store/tests/parties.rs @@ -318,7 +318,7 @@ fn update_party_journals_party_updated() { assert_eq!(got.notes.as_deref(), Some("net 30")); } -/// Oracle: P4b S4.2 (A-13, rules.md B-39, R-A step 3): a party's email and +/// Oracle: P4b S4.2 (A-13, BS-arap-3, R-A step 3): a party's email and /// default terms are `party.updated` facts the `documents_v2` feature /// guards. In books that haven't declared it they are refused, journaling /// nothing; after the upgrade they journal, replay gives them back, and an diff --git a/crates/ledger-store/tests/party_creditors.rs b/crates/ledger-store/tests/party_creditors.rs index 148dc332..6f5d64d5 100644 --- a/crates/ledger-store/tests/party_creditors.rs +++ b/crates/ledger-store/tests/party_creditors.rs @@ -1,8 +1,8 @@ -//! A party named the creditor of a liability (rules.md B-35, P3 defect +//! A party named the creditor of a liability (BS-partner-3, P3 defect //! 24), in the store: journaled as `party.creditor_set {id, account_id, //! on}`, which needs the journal feature `party_creditors`: books this //! version made declared it when they were created; books an older -//! version wrote refuse it until their format upgrade (rules.md B-27). +//! version wrote refuse it until their format upgrade (BS-format-1). //! //! Oracles: `Store::set_party_creditor`'s doc, `format::KNOWN_FEATURES` //! and `PARTY_CREDITORS`, `Store::ensure_feature`'s doc (refused, diff --git a/crates/ledger-store/tests/projects.rs b/crates/ledger-store/tests/projects.rs index 3c30ef0b..903d26f5 100644 --- a/crates/ledger-store/tests/projects.rs +++ b/crates/ledger-store/tests/projects.rs @@ -1,4 +1,4 @@ -//! Projects in the journal (rules.md B-37): `class.added`, then the whole +//! Projects in the journal (BS-statement-5): `class.added`, then the whole //! record as `project.set` (journal feature `projects`); links to a //! project and decisions naming one wait for the feature too. //! @@ -6,7 +6,7 @@ //! GOAL: a project's record is journaled once, whole, replays exactly, //! and books waiting for their format upgrade can still add //! projects by name but write nothing an older reader would misread. -//! SOURCE: docs/spec/rules.md B-37, B-27; D-39 (the owner's upgrade). +//! SOURCE: BS-statement-5, BS-format-1; D-39 (the owner's upgrade). //! ``` use chrono::NaiveDate; diff --git a/crates/ledger-store/tests/reversal_dates.rs b/crates/ledger-store/tests/reversal_dates.rs index 98012306..54101a51 100644 --- a/crates/ledger-store/tests/reversal_dates.rs +++ b/crates/ledger-store/tests/reversal_dates.rs @@ -1,13 +1,13 @@ //! A reversal is dated on or after the entry it reverses, for every kind of -//! entry (D-73, 2026-11-08; rules.md B-9; bookspec BS-ledger-5): a +//! entry (D-73, 2026-11-08; BS-ledger-5; bookspec BS-ledger-5): a //! correction comes after what it corrects. A journal an earlier version //! wrote may hold one dated before its original, and it opens as it was -//! (B-28: bounds bind new commands, never replay). +//! (BS-entry-4: bounds bind new commands, never replay). //! //! ```text //! GOAL: no new reversal precedes its original; no old one stops a journal //! from opening, or moves a figure. -//! SOURCE: docs/spec/rules.md B-9, B-28; plan/served.md D-73. +//! SOURCE: BS-ledger-5, BS-entry-4; plan/served.md D-73. //! ``` use chrono::NaiveDate; @@ -114,7 +114,7 @@ fn a_plain_entrys_reversal_is_not_dated_before_it() { /// A journal an earlier version wrote, holding a reversal dated before its /// original, opens exactly as it was: same figures, chain verified, in the -/// writer and again after a snapshot-less reopen (B-28). +/// writer and again after a snapshot-less reopen (BS-entry-4). #[test] fn a_journal_with_an_earlier_dated_reversal_opens_as_it_was() { let (dir, s, rent, cash, e) = books("replay"); diff --git a/crates/ledger-store/tests/roles.rs b/crates/ledger-store/tests/roles.rs index c601de66..380ccef5 100644 --- a/crates/ledger-store/tests/roles.rs +++ b/crates/ledger-store/tests/roles.rs @@ -1,6 +1,6 @@ //! Spec-derived tests for control-role assignment in the store. //! -//! Oracles: `docs/spec/rules.md` B-23 ("the assignment is journaled, so +//! Oracles: BS-ledger-8 ("the assignment is journaled, so //! replay never depends on a setting outside the journal"), the doc comment //! on `Store::assign_role` (journaled as `role.assigned`, with the account //! that filled the role before), and the `Ledger::assign_role` spec (a @@ -246,7 +246,7 @@ fn a_refused_assignment_journals_nothing() { assert_eq!(state(s.ledger()), mid); } -/// Oracle: B-23 (replay never depends on a setting outside the journal): +/// Oracle: BS-ledger-8 (replay never depends on a setting outside the journal): /// reopening gives the same assignments, and later commands still post to /// the assigned accounts. #[test] @@ -304,7 +304,7 @@ fn assignments_replay_on_reopen_and_steer_later_invoices() { assert_eq!(state(s.ledger()), after); } -/// Oracle: B-23 + close_period: a close to retained earnings after the +/// Oracle: BS-ledger-8 + close_period: a close to retained earnings after the /// role is assigned goes to the assigned account, and replays identically. #[test] fn a_close_to_assigned_retained_earnings_replays_identically() { diff --git a/crates/ledger-store/tests/schema_files.rs b/crates/ledger-store/tests/schema_files.rs index 00945688..38073b82 100644 --- a/crates/ledger-store/tests/schema_files.rs +++ b/crates/ledger-store/tests/schema_files.rs @@ -1,6 +1,6 @@ //! Each projection schema in a file of its own (ledger_store::db_file_for; //! plan/served.md 3.9: before the owner consents to a format upgrade, the -//! way back to an older version is always there; rules.md B-27). +//! way back to an older version is always there; BS-format-1). //! //! ```text //! GOAL: an older version, gone back to, finds the books it can open, diff --git a/crates/ledger-store/tests/settings.rs b/crates/ledger-store/tests/settings.rs index c21b473c..cb0afef4 100644 --- a/crates/ledger-store/tests/settings.rs +++ b/crates/ledger-store/tests/settings.rs @@ -117,7 +117,7 @@ fn assert_every_reader_agrees(dir: &std::path::Path, s: &Store) { /// until their format upgrade (the owner's go-ahead, D-39); then it is /// made, after the one declaration. /// `invoicing.first_number` is settable only while no numbered invoice -/// exists (A-2, rules.md B-40): once a number has been issued the series +/// exists (A-2, BS-arap-4): once a number has been issued the series /// has begun, so changing or clearing the starting number is refused before /// anything is journaled, and a legacy invoice (no number) never locks it. #[test] @@ -568,7 +568,7 @@ fn a_template_amount_is_at_most_a_lines() { } /// A setting key or convention kind this version doesn't know is a newer -/// version's, never damage (rules.md B-27). +/// version's, never damage (BS-format-1). #[test] fn a_newer_key_or_kind_is_newer() { for (event, payload) in [ @@ -773,7 +773,7 @@ fn figures(s: &Store) -> (Value, Vec) { fn run(s: &mut Store, op: &Op) { // A record (anything but a post or a template's draft) changes no - // figure and no entry (rules.md B-29; Lean Step.record_changes_no_figure). + // figure and no entry (BS-ledger-9; Lean Step.record_changes_no_figure). let records = !matches!(op, Op::Post(_) | Op::Template(_)); let before = records.then(|| figures(s)); run_op(s, op); diff --git a/crates/ledger-store/tests/source_revisions.rs b/crates/ledger-store/tests/source_revisions.rs index 8f9e0480..c17b9453 100644 --- a/crates/ledger-store/tests/source_revisions.rs +++ b/crates/ledger-store/tests/source_revisions.rs @@ -4,7 +4,7 @@ //! event, replays identically, and waits for the owner's format upgrade. //! //! Expected behavior comes from `docs/receipt-store.md` (the three events) -//! and rules.md B-27 (a feature is declared before its first line). +//! and BS-format-1 (a feature is declared before its first line). use chrono::NaiveDate; use ledger_core::Currency; diff --git a/crates/ledger-store/tests/store.rs b/crates/ledger-store/tests/store.rs index 2563ee9d..ed3156c9 100644 --- a/crates/ledger-store/tests/store.rs +++ b/crates/ledger-store/tests/store.rs @@ -723,7 +723,7 @@ fn schedules_and_recurring_entries_replay_exactly() { assert!(store.run_recurring(date(2, 28)).unwrap().is_empty()); } -/// Regression (B-12, found by the refusal property on 2026-10-13): +/// Regression (BS-period-2, found by the refusal property on 2026-10-13): /// `run_recurring` leaves occurrences in a closed period ungenerated /// instead of creating drafts there, and still generates the rest. #[test] @@ -1246,7 +1246,7 @@ mod refusals { }] }; match *op { - // Named for the code: a sibling's name is refused (B-31), and + // Named for the code: a sibling's name is refused (BS-ledger-10), and // a code is the first refusal. Op::AddAccount(c, t, p, h) => store .add_account( @@ -1772,7 +1772,7 @@ mod refusals { /// Regression (CI, 2026-10-13): a payroll run with unrounded employer /// tax posted $65.27794, and sums of it differed in scale between the /// journal replay and the SQLite read-back. Posting now refuses - /// fractions of a cent (B-3; `no_entry_posts_a_fraction_of_the_minor_unit`); + /// fractions of a cent (BS-ledger-1; `no_entry_posts_a_fraction_of_the_minor_unit`); /// this replays the sequence with the tax rounded, as callers must. #[test] fn regression_payroll_with_a_fraction_of_a_cent() { @@ -1793,7 +1793,7 @@ mod refusals { } /// D-75: the ten-place bound on a foreign amount is the command's, never -/// replay's (B-28). A journal an earlier version wrote, holding a line with +/// replay's (BS-entry-4). A journal an earlier version wrote, holding a line with /// a 26-place foreign amount, opens with its figures exactly as journaled. #[test] fn a_journaled_foreign_line_finer_than_ten_places_still_opens() { @@ -2398,7 +2398,7 @@ fn books_written_under_older_rules_still_open() { ); // The write-off replays as written: its line is the invoice's // (WriteOff), so what it owes fell by 30.00 and what was written off - // rose by it (B-41, B-38). + // rose by it (BS-arap-5, BS-arap-2). let st = store .ledger() .invoice_state(2, NaiveDate::from_ymd_opt(2026, 6, 30).unwrap()) @@ -2426,7 +2426,7 @@ fn books_written_under_older_rules_still_open() { /// written through main 188c90ea's Store API (or, for x_older_rules, its /// JournalWriter, as above), and expected.json by main's own code: verify, /// the canonical report snapshot, and every record as replayed. They hold -/// what P0 bounds for new commands only (rules.md B-28): dates before 0001 +/// what P0 bounds for new commands only (BS-entry-4): dates before 0001 /// and after 9999 (to chrono's first and last days), draft, recurring and /// share amounts past the line limit (to Decimal's largest), a contributor /// basis past it, sub-cent document and payroll lines, an asset life of @@ -2500,7 +2500,7 @@ fn old_books_figures(l: &ledger_core::Ledger) -> serde_json::Value { }) } -/// Contract (posted is forever, rules.md B-28; P0 review round 4, +/// Contract (posted is forever, BS-entry-4; P0 review round 4, /// 2026-10-17): every book an earlier version wrote opens, in the writer /// (Store::open, its database rebuilt from the journal) and the viewer /// (Snapshot::load) alike, verifies as it did, and replays to exactly the @@ -2540,7 +2540,7 @@ fn books_an_earlier_version_wrote_open_to_its_figures() { } } -/// Every figure the engine derives from old books (B-28: computed, or +/// Every figure the engine derives from old books (BS-entry-4: computed, or /// refused with TooLargeToCompute or DateOutOfRange, never a panic): every /// report over the books' whole span and the calendar's, every asset's /// schedule and register row, every amortization plan, every recurring @@ -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 (rules.md B-14 rule 9). + // for a reason: never an engine error (BS-statement-3 rule 9). let cf = reports::cash_flow( l, &reports::CashFlowParams { @@ -2738,7 +2738,7 @@ fn every_figure_of(l: &ledger_core::Ledger) -> (usize, usize) { (ok, refused) } -/// B-28 over every old book: each figure is computed or refused, never a +/// BS-entry-4 over every old book: each figure is computed or refused, never a /// panic, in the writer's ledger and the viewer's. #[test] fn every_figure_over_old_books_is_computed_or_refused() { @@ -2909,7 +2909,7 @@ fn store_add(store: &mut Store, code: &str, t: AccountType) -> ledger_core::Acco store.add_account(code, code, t, None, false).unwrap() } -/// Contract (rules.md B-13): each members close journals its rounding rule +/// Contract (BS-partner-1): each members close journals its rounding rule /// and replays under it: "cumulative_since" with the close its count starts /// at for new closes (P3), "cumulative" for the run rule of 2026-10-13 to /// P3, "largest_remainder" for the per-close rule of earlier on 2026-10-13. @@ -3387,7 +3387,7 @@ fn searching_entries_filters_and_pages() { } /// The database's invoice row keeps no figure of its own (schema 15, -/// rules.md B-38): what it has been paid is the ledger's, read from the +/// BS-arap-2): what it has been paid is the ledger's, read from the /// lines tagged with it, so a reversed payment no longer counts; the row /// is the same before and after each payment, and verify agrees. #[test] @@ -3607,7 +3607,7 @@ fn a_database_with_damaged_pages_is_rebuilt() { // --------------------------------------------------------------------------- // P3: renaming an account, and the tax category policy (defects 15 and 8; -// rules.md B-31, B-32). +// BS-ledger-10, BS-ledger-11). // --------------------------------------------------------------------------- /// Every row of every projection table but the journal's own (`events`, @@ -3675,7 +3675,7 @@ fn figures_but_names(l: &ledger_core::Ledger) -> serde_json::Value { }) } -/// rename_account (repro 1.2; rules.md B-31): a rename changes the +/// rename_account (repro 1.2; BS-ledger-10): a rename changes the /// account's name and nothing else: no figure, entry or line, no earlier /// journal line, no projection row but `accounts.name`; the journal gains /// one `account.renamed` line (keyed by id, with the old name and the @@ -3778,7 +3778,7 @@ fn rename_account_changes_only_the_name_defect_15() { assert_eq!(snap.ledger().chart().get(rent).unwrap().name, "Rent"); } -/// rules.md B-28's pair for renames (review R5): the command refuses a +/// BS-entry-4's pair for renames (review R5): the command refuses a /// blank name, a sibling's or nine digits; replay takes a journaled line /// holding any of them (a later version may tighten the rules, never lock /// out books it wrote), and refuses only an account that doesn't exist. @@ -3850,7 +3850,7 @@ fn tax_policy(store: &mut Store, value: Option<&str>) { .unwrap(); } -/// add_account_with_tax and the policy (rules.md B-32): under warn an +/// add_account_with_tax and the policy (BS-ledger-11): under warn an /// account is created without a category; under refuse a revenue or /// expense account that isn't a header is refused without one, journaling /// nothing, and created with one as account.added then account.tax_set; @@ -3996,7 +3996,7 @@ fn the_tax_category_policy_refuses_only_what_it_says() { Store::open(&dir).unwrap().verify().unwrap(); } -/// rules.md B-28's pair for the policy (review R5): the policy is the +/// BS-entry-4's pair for the policy (review R5): the policy is the /// commands', never replay's. A journal that sets refuse and then clears /// a category, or adds an uncategorized expense account, replays. #[test] @@ -4065,7 +4065,7 @@ mod p3_properties { ..ProptestConfig::default() })] - /// rules.md B-31 (the engine-side counterpart to the Lean note, + /// BS-ledger-10 (the engine-side counterpart to the Lean note, /// docs/verification.md law 15): on books with postings, any sequence /// of renames changes no figure (the ledger's statements, without /// names), no entry and no earlier journal line; live equals @@ -4098,7 +4098,7 @@ mod p3_properties { prop_assert!(live.differs_from(reopened.ledger()).is_empty()); } - /// rules.md B-32: add_account_with_tax is refused exactly when the + /// BS-ledger-11: add_account_with_tax is refused exactly when the /// policy is refuse, the account needs a category (revenue or /// expense, not a header) and none is given, or when the category /// doesn't fit; a refusal journals nothing. @@ -4303,7 +4303,7 @@ fn books_written_under_p3_keep_their_names() { assert_eq!(chart_of(snap.ledger()), want); } -/// rules.md B-31: a new account's name is journaled trimmed, as a rename +/// BS-ledger-10: a new account's name is journaled trimmed, as a rename /// journals one, so the live books, a reopen and the projection all read /// the same name; the command's text rules refuse a name a report can't /// print on one line, journaling nothing. diff --git a/docs/architecture.md b/docs/architecture.md index d81de4ff..0085886a 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -59,7 +59,7 @@ closure. The reader now lives in the small library crate `ledger-reader`; re-exports it as `extract`), the store no longer builds the typesetter, and `ledger-import` still never depends on the store. -Audits (P8, rules.md B-45) are split by what each layer can see. The pure +Audits (P8, BS-ledger-13) are split by what each layer can see. The pure checks over a ledger are `ledger_core::audit` (`statements`, with the facts a ledger cannot know handed in by the caller: the receipts filed, the statement of cash flows the role settings give, the settings problems, the @@ -204,7 +204,7 @@ when there is no next line or no `prev` it can read. The writer for the same journal (fuzzed by `fuzz_store_replay`). The writer checks every complete line before it changes anything: a torn tail is set aside only when the gate passes, so an older version never alters newer books. -Rule: `docs/spec/rules.md` B-27. +Rule: BS-format-1. ## How the books are kept, in the books (P1) @@ -222,7 +222,7 @@ books adopt`) moves an older books dir's file in through it, once, and are their settings' only source (D-44): the server (`settings::Live`) takes them whenever their last `settings.set` changes (on every lock of the store), the viewer reads them from the journal it shows, and neither -reads a file; "today" is the company's time zone's, set per request. Rule: `docs/spec/rules.md` B-29. +reads a file; "today" is the company's time zone's, set per request. Rule: BS-ledger-9. ## The MCP server's layout (`ledger-mcp`, P0; U0a) @@ -252,8 +252,7 @@ groups are: - `parties` — parties, vendors, customers, roles, W-9s, the TIN vault, 1099s, entry parties; - `attachments` — receipts, filed documents, and their links; -- `write_offs` — `books.write_off_invoice`, the bad debt (P4b S7; rules.md - B-41), kept apart from `documents` so S4.4's document tools and this one +- `write_offs` — `books.write_off_invoice`, the bad debt (P4b S7; BS-arap-5), kept apart from `documents` so S4.4's document tools and this one land in different files; - `evidence` — finding a file by its hash, number or text, annotating it, recording what a payment settles, and consolidating duplicates (P6); @@ -328,7 +327,7 @@ to move to its own repository (P13 step 6, D-34, Z-17): per rule: pass, fail or not claimed. It compares the engine's answers with the examples' exact expected values; it never asks the engine whether its own answer is right. -- `bookspec/spec/rules-index.md` maps B-1 to B-45 to the bookspec ids; +- `bookspec/spec/rules-index.md` maps BS-entry-1 to BS-ledger-13 to the bookspec ids; `docs/spec/rules.md` carries each stated rule's id under its heading. - `crates/ledger-core/tests/bookspec/` is the wanderbooks adapter: it implements `Engine` over `Store` (a dev-dependency only, so no engine diff --git a/docs/capability-parity.md b/docs/capability-parity.md index 393c8ff5..e16b1b14 100644 --- a/docs/capability-parity.md +++ b/docs/capability-parity.md @@ -35,7 +35,7 @@ Statuses: `covered` (built and tested), `partial` (built, known gaps listed), - Row 10 (`books.digest`) has no sheet equivalent — the sheet can't tell you what changed. This is parity *plus*: the new system is more reviewable than the old one, which is the point of the exercise. -- Projects (rules.md B-37) have no sheet equivalent either: a class with +- Projects (BS-statement-5) have no sheet equivalent either: a class with its facts, created and changed by the agent (`books.add_project`, `books.update_project`), read by the viewer's Projects pages and by `books.projects` / `books.project` (D-28: the agent writes, the viewer diff --git a/docs/glossary.md b/docs/glossary.md index fd230522..8cec0426 100644 --- a/docs/glossary.md +++ b/docs/glossary.md @@ -62,7 +62,7 @@ definitions exactly. reports it: cash plus the adjusted tax basis of property contributed, plus their share of income as figured for tax, less cash and the adjusted tax basis of property distributed (Form 1065 instructions, Item L). -- **Project** — A class with its facts (rules.md B-37): what it is, where it +- **Project** — A class with its facts (BS-statement-5): what it is, where it stands (active, paused, finished, abandoned), what kind of work it is (internal product, client work, on spec, other), who it is for, its dates and links. Its figures are the revenue and expense lines tagged to diff --git a/docs/mcp-interface.md b/docs/mcp-interface.md index 84907be9..50c348e0 100644 --- a/docs/mcp-interface.md +++ b/docs/mcp-interface.md @@ -34,7 +34,7 @@ layer. The books keep their own settings (journal format 2, plan/served.md P1): each change is a `settings.set` line with who decided it and when, replayed into `ledger_core::settings::Settings` by the server and the viewer alike -(rules.md B-29). Every key is in `ledger_core::settings::KEYS`, with what it +(BS-ledger-9). Every key is in `ledger_core::settings::KEYS`, with what it takes and means: the company's facts (`company.name`, `.entity_type`, `.tax_classification`, `.tax_form`, `.fiscal_year_start` ("MM-01"; the year's end is derived, never stored), `.timezone` (what "today" means for @@ -92,7 +92,7 @@ in its folder). changes the books' settings after that. The accounts invoices, bills, payroll, and closes post to are not settings: -they are control roles in the journal (rules.md B-23). +they are control roles in the journal (BS-ledger-8). - `books.roles {}` → `{ roles: [{ role, purpose, account_type, default_code, assigned, account_code?, account_name? }] }`: every control @@ -106,7 +106,7 @@ they are control roles in the journal (rules.md B-23). ## Tools — how the books are kept Conventions, decisions, open items and approvals live in the books too -(`ledger_core::conventions`, rules.md B-29), each with who decided it and +(`ledger_core::conventions`, BS-ledger-9), each with who decided it and when; `books.start` lists them, and the handbook's settings-and-conventions section says how to use them. @@ -177,7 +177,7 @@ settings-and-conventions section says how to use them. item is a problem. `focus` is `daily` (the default), `onboarding`, `close` or `audit`; anything else is refused. Also `books://start`. -**The format upgrade** (plan 3.9, D-39, rules.md B-27). Books an older +**The format upgrade** (plan 3.9, D-39, BS-format-1). Books an older wanderbooks wrote are in an older journal format: they are served on it, and every tool that needs nothing new works as before. A tool whose change needs the newer format (on main: settings, conventions, decisions, @@ -230,7 +230,7 @@ as it is made. `{ id }`; `books.decisions { include_superseded?, project? }`. A decision supersedes at most one live decision; its evidence is a document still in the books. `projects` (ids or names, each once, resolved before - anything is written) names the projects it is about (rules.md B-37); a + anything is written) names the projects it is about (BS-statement-5); a decision without them journals the bytes it always did, and one with them needs the journal feature `projects`. `books.decisions` gives each decision's `projects: [{ id, name }]` (left out when none); `project` @@ -459,7 +459,7 @@ those bounds still open (replay accepts what that version accepted), so every figure the server derives from them (a draft's total, a schedule's plan, aging, a party's totals, the asset register) is computed or refused ("too large to compute exactly", or a date outside the calendar -the books keep), never a panic (rules.md B-28). `tests/hostile_args.rs` +the books keep), never a panic (BS-entry-4). `tests/hostile_args.rs` drives every tool with generated hostile arguments and every resource with generated URIs, checks after each call that the server still serves, restarts it after them to check the books reopen, and drives @@ -545,13 +545,13 @@ every tool over every book in ledger-store's `tests/fixtures/old-books`. Codes are unique; a name another account under the same parent has (top-level accounts are siblings too; ignoring capitals and surrounding space), one holding a run of nine digits, or one that isn't one line of - at most 200 characters, is refused (rules.md B-31); the name is kept + at most 200 characters, is refused (BS-ledger-10); the name is kept trimmed. A revenue or expense account (not a header) without `tax_category` is created with a warning ("6150 Software has no tax category: the tax summary will list it as uncategorized. Propose one from books.tax_categories and set it with books.set_tax_category once the human agrees."), or, under `policy.require_tax_category = refuse`, - refused (rules.md B-32). The category is checked against the account's + refused (BS-ledger-11). The category is checked against the account's type and the return, as `books.set_tax_category` checks it; journaled as `account.added` then `account.tax_set`. - `books.draft_entry { date: "2026-10-10", description: "...", vendor?, @@ -585,7 +585,7 @@ every tool over every book in ledger-store's `tests/fixtures/old-books`. schedule month a second time (naming the entry that posts it now), or re-instate a run a later run caught up (carrying the books past the schedule); and a reversal of any entry dated before that entry's own - date (a correction comes after what it corrects, B-9, D-73; the preview + date (a correction comes after what it corrects, BS-ledger-5, D-73; the preview refuses the same way, and books written before D-73 open as they were). - `books.get_entry { entry_id }` → full entry with lines (each `{ account_id, code, name, side, amount, class_id?, project? }`: a tagged @@ -602,7 +602,7 @@ every tool over every book in ledger-store's `tests/fixtures/old-books`. reversal_of, receipt_count }] }`, posted entries, newest first (no lines: `books.get_entry` has them). `limit` defaults to 50 and caps at 500. -- **Omitted dates (rules.md B-30).** One rule everywhere +- **Omitted dates (BS-period-3).** One rule everywhere (`ledger_core::calendar::PeriodDefaults`), stated in every report tool's description and date parameters in the same words: a period report with no dates covers the fiscal year to date @@ -623,7 +623,7 @@ every tool over every book in ledger-store's `tests/fixtures/old-books`. the fiscal year to date). Closing entries are excluded, so a closed period still shows what it earned. - `books.cash_flow { start?, end?, cash_accounts?, financing_accounts?, investing_accounts? }` (each defaults to the books' settings, `books.cash_accounts` and so on; cash is required one way or the other) - → the statement of cash flows, direct method (rules.md B-14, P3 defect + → the statement of cash flows, direct method (BS-statement-3, P3 defect 1; omitted dates: the fiscal year to date): `{ method: "direct", start, end, operating_by_class, operating, cash_from_operations, investing_by_kind, investing, cash_from_investing, @@ -636,13 +636,13 @@ 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 (rules.md B-14 rule 5; payroll remittances excepted); + on any account (BS-statement-3 rule 5; 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, rules.md B-14 + (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 is a "Proceeds from borrowing — " line and an operating line, each with `on_behalf`, the part of its amount so handled (absent @@ -716,12 +716,12 @@ every tool over every book in ledger-store's `tests/fixtures/old-books`. Needs attention uses the same rule (`ledger_store::reconcilable`). `uncategorized_accounts` lists every revenue and expense account (not a header) with no tax category, active or not, `"CODE Name"`: the list - Needs attention shows (rules.md B-32). + Needs attention shows (BS-ledger-11). ## Tools — fixed assets Straight-line **book** depreciation only; tax depreciation stays with the -CPA. Depreciation accrues by the day (rules.md B-15): a partial first +CPA. Depreciation accrues by the day (BS-asset-1): a partial first month, the life's final month (which takes what the others leave, evenly over its days), and any month a schedule stops in (through a date, or a disposed asset's disposal day, held) are prorated by days, never plugged; @@ -738,7 +738,7 @@ life's last day is 9999-12-31 at the latest. next free `PREFIX-0001` (`[books] asset_tag_prefix`, else the company name's initials without LLC/Inc; "FA" when none). `in_service_date` (the day it is ready and available for its use) starts depreciation (P3, - defect 13; B-15); `purchase_date` is its alias for one release (both + defect 13; BS-asset-1); `purchase_date` is its alias for one release (both given and meaning different days: refused; the alias noted in `notes`). The `acquisition_entry` (posted, debiting the cost account, neither a reversal nor reversed, dated on or before the in-service date) gives @@ -891,7 +891,7 @@ life's last day is 9999-12-31 at the latest. Amortization spreads a prepaid expense (asset → expense) or deferred revenue (liability → revenue) over the time it covers, posting on each -month end, to the minor unit (rules.md B-16). A new schedule's convention +month end, to the minor unit (BS-prepaid-1). A new schedule's convention is `books.schedule_convention` (unset: `daily`, D-11/D-37): `daily` spreads by the day from `start`, the first day covered, as depreciation does, so a mid-month start posts a small first and last month (a 12-month @@ -969,7 +969,7 @@ through the policy. `viewer_open` says whether one does. The note says "The viewer shows …", or "No viewer has these books open: ask the human to open it (opened within a couple of minutes, it shows …)". - - **Dates (rules.md B-30).** For an account or a report, the dates are + - **Dates (BS-period-3).** For an account or a report, the dates are resolved by the one default (omitted: the fiscal year to date; only `end`: its fiscal year to it) and sent to the viewer resolved, so `shown` and the screen can't differ: "the register of 1000 Business @@ -1115,7 +1115,7 @@ on from it. What counts toward a vendor's 1099 is what left the books' cash accounts (`books.cash_accounts`) and financing accounts (`books.financing_accounts`) on entries tagged with the vendor, classified by how each payment was made -(rules.md B-19; plan P3, defects 12, 18 and 23; D-40): +(BS-1099-1; plan P3, defects 12, 18 and 23; D-40): - out of a cash account with no payment method recorded: counts (presumed check, ACH or transfer; tag a debit-card payment with the @@ -1181,7 +1181,7 @@ first entry's). year): tell the human, a filed 1099 may need correcting. Journaled as `vendor.1099_set` (a W-9 flag alone as `vendor.w9_flag_set`), under the journal feature `vendor_1099_decisions` (books an older version wrote - refuse it, `format_upgrade_pending`, until their format upgrade: B-27). + refuse it, `format_upgrade_pending`, until their format upgrade: BS-format-1). - `books.add_instrument { kind, label, last4?, owner_party?, account }` → `{ id, kind, card_or_network, label, last4?, owner_party?, account_id, account, warnings }`. `kind`: `bank` (the company's checks, ACH, wires, @@ -1243,9 +1243,9 @@ first entry's). setting, the CPA package's rule: `ledger_package::Settings::with_accounts`; a code the chart lacks is refused), from January 1 of `year` through `through` when given (`YYYY-MM-DD`, a day of `year`: the worksheet as of - a day, rules.md B-33), else the whole year. On an entry naming several + a day, BS-statement-4), else the whole year. On an entry naming several parties, the buckets count only the vendor's resolved share of the - payment, split across them to the cent (rules.md B-19); an entry whose + payment, split across them to the cent (BS-1099-1); an entry whose shares don't resolve counts in full and `notes` names it. `tin_last4` is the party's TIN facts' last four, else its W-9 facts' (`Party::tin_last4`). With `include_tins: true` (default false) each @@ -1294,7 +1294,7 @@ registries that don't tax: a division of corporations, a licensing board), 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`, rules.md B-14 +payments, never cash paid to suppliers (`books.cash_flow`, BS-statement-3 rule 5). **Rules the engine enforces** (each refusal changes nothing, the journal @@ -1327,7 +1327,7 @@ texts are at most 500 characters, no control characters. phone, contact, billing_address, shipping_address, billing_email, archived, then one `party.creditor_set` per account added or dropped. The email, terms and contact block need the journal feature - `documents_v2` (rules.md B-27): books that haven't declared it refuse + `documents_v2` (BS-format-1): books that haven't declared it refuse them with `format_upgrade_pending`, journaling nothing. Un-archiving is refused while another party has the name. - `books.set_party_roles { party, add?, remove? }` → the party. Adds apply @@ -1405,7 +1405,7 @@ texts are at most 500 characters, no control characters. newest first); its invoices and bills (`{ id, date, due_date, total, paid, balance, status, entry_id }`); and the payroll lines naming it (`{ run_id, date, entry_id, gross_pay, net_pay }`); and the projects for - or with it, by name (`{ id, name }`, rules.md B-37). + or with it, by name (`{ id, name }`, BS-statement-5). - `basis` (both): `"cash"` (the default) or `"all"`; any other word is refused (`basis is "cash" or "all"`). Echoed in the output. Not the books' accounting method (`books.accounting_basis`). @@ -1423,14 +1423,14 @@ replaces the list (`[]` clears it), journaled as `party.creditor_set {id, account_id, on}`, one line per account added or dropped, under the journal feature `party_creditors` (books an older version wrote refuse the whole change, `format_upgrade_pending`, until their format upgrade: -B-27); refused, journaling nothing, for an account that isn't a +BS-format-1); refused, journaling nothing, for an account that isn't a liability, is a placeholder, or is payables or a payroll withholding (owed to many). **Each party's part of an entry** (`books.get_entry`, the `books.post_entry` preview, `books.set_entry_party`: `parties: [{ party_id, party, share, amount?, percent?, resolved, direction, cash, in_kind }]`, -rules.md B-35): +BS-partner-3): - `resolved`: signed as a line on the party's own account would be (debit-positive): positive, the company paid it or gave it value; @@ -1443,7 +1443,7 @@ rules.md B-35): 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 (B-35 item 3): a close, its parties' own-account +- What the shares split (BS-partner-3 item 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 @@ rules.md B-35): 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* (B-35 item 5, P3 defect 24): the `[books] +- *Money accounts* (BS-partner-3 item 5, 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 @@ -1489,7 +1489,7 @@ rules.md B-35): `all` over the entries that name only members and move their capital (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 (B-35 + 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 is in the statement only). The year is the whole calendar year; the viewer's party page and directory show these same @@ -1509,7 +1509,7 @@ rules.md B-35): Full TINs (SSN, EIN, ITIN) and signed W-9 forms, kept so what the CPA gets is complete (every member's TIN for their K-1, every payee's for their 1099), never in the books (`ledger-vault`; design in -`docs/parties-and-attachments.md` "The TIN vault"; B-26). DECISION +`docs/parties-and-attachments.md` "The TIN vault"; BS-partner-2). DECISION (the owner, 2026-10-15): the vault holds everyone's TIN, members included, and the CPA package carries them. @@ -1590,11 +1590,11 @@ and the CPA package carries them. test alone), or a stand-alone number printed as an SSN or EIN is (123-45-6789, 12-3456789; no digit, and no hyphen or dot followed by a digit, beside it). Bank exports pass: routing and account numbers, long - references and dates next to amounts are not TINs (rules.md B-26). No + references and dates next to amounts are not TINs (BS-partner-2). No probing: a text with more than two TIN-shaped numbers ending in the last four of a TIN the books know is refused before the vault is opened, in the same words whether or not one is that TIN, so the vault is compared - against at most two candidates a filing (rules.md B-26). An altered copy + against at most two candidates a filing (BS-partner-2). An altered copy of a binary file (a W-9 PDF re-saved or re-scanned), and a TIN the vault doesn't hold written another way, are not detected: P7 takes full TINs out of the agent's reach. @@ -1867,7 +1867,7 @@ posting. changes in members' equity; members from the settings (`company.members`); earnings not yet closed are split the way the next members close will split them, so a member's capital on a day never changes when its month is - closed: rules.md B-13, D-38), + closed: BS-partner-1, D-38), `general_ledger` (by account: beginning balance, postings with running balance and split, ending balance), `general_journal` (alias `journal`: each entry posted in the period, line by line; `iif`: @@ -1877,19 +1877,19 @@ posting. (as of a day: columns `number,party,date,due_date,terms,total,paid, discounted,outstanding,bucket,days_overdue`, one row per open document, then a tie-out line `TOTAL,,,,,,,,<Σ outstanding>,GL - ,difference 0.00`; B-23, 8.3.10). + ,difference 0.00`; BS-ledger-8, 8.3.10). - Formats: `pdf` and `xlsx` for `profit_and_loss`, `balance_sheet`, `cash_flow`, `trial_balance`, `members_equity`, `tax_summary` and `fixed_asset_register`; `xlsx`, `csv`, `json` for every report (`general_ledger` and `general_journal` have no pdf); `iif` for `general_journal` (alias `journal`), for QuickBooks Desktop. - - Dates (rules.md B-30): the period reports (`profit_and_loss`, + - Dates (BS-period-3): the period reports (`profit_and_loss`, `cash_flow`, `members_equity`, `tax_summary`, `general_ledger`, and `general_journal` as csv, json and xlsx) take `start` and `end` (omitted: the fiscal year to date; a start after the end is refused); `balance_sheet`, `trial_balance`, `fixed_asset_register` and `iif` take `as_of` (omitted: today, the company's time zone). - - IIF (`docs/spec/rules.md` B-34; plan D-36): plain ASCII text, every + - IIF (BS-format-2; plan D-36): plain ASCII text, every line ending CR LF (`text/plain`, handed over like every export): every posted entry from the first through `as_of`, period-closing entries left out (QuickBooks keeps none; imported, a close would zero its period's @@ -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, rules.md B-34 rule 8). No line names a customer or vendor (no + kept, BS-format-2 rule 8). 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 @@ -1972,7 +1972,7 @@ posting. - `books.rename_account { account, name, reason? }` → `{ id, code, previous_name, name, notes }` (scope `books:post`, destructive: a rename changes the label every past report prints): give an account a - new name (rules.md B-31). Only the name changes (entries name accounts + new name (BS-ledger-10). Only the name changes (entries name accounts by id): no entry, balance or statement amount moves, and every report, past periods included, prints the new name. Refuses an unknown account, a blank name, the name it has, a name another account under the same @@ -1981,7 +1981,7 @@ posting. `reason` is one to 2,000 characters with no full TIN. Journaled as `account.renamed { account_id, code, name, previous, reason }`, keyed by id (a code can change; an id can't), under the journal feature - `account_renamed` (rules.md B-27; books an older version wrote refuse + `account_renamed` (BS-format-1; books an older version wrote refuse it, `format_upgrade_pending`, until their format upgrade), so an earlier version stops at the declaration. `notes` always says that QuickBooks matches accounts by name (tell a CPA who imported an earlier IIF), says @@ -2010,12 +2010,12 @@ posting. refuse`, refuses the whole file (a row is never a header account: the file can't say so). - `policy.require_tax_category` (`books.set_setting`): `warn` (unset) or - `refuse` (rules.md B-32). The accounts invoices, bills and payroll + `refuse` (BS-ledger-11). The accounts invoices, bills and payroll create (Revenue 4000, General Expenses 6999, 6100, 6110) are never refused; their results' `warnings` name them. A change naming the key needs the journal feature `require_tax_category`: books an older version wrote refuse it (`format_upgrade_pending`) until the owner's - format upgrade (rules.md B-27). + format upgrade (BS-format-1). ## Tools — import @@ -2115,7 +2115,7 @@ accounting only: the caller supplies every figure), tax filing. missing), or to `books.close_into` (a single owner's capital), zeroing the `books.close_sweep` accounts (draws, dividends) into it too; or, with `company.members` in the settings, to each member's capital - account by share (each member's distribution account zeroed into it), cumulatively (rules.md B-13; D-10): each close gives a member + account by share (each member's distribution account zeroed into it), cumulatively (BS-partner-1; D-10): each close gives a member their share of everything closed to these members and shares so far, to the currency's minor unit (odd units by largest remainder, ties to the member listed first when the count began), less what earlier closes gave @@ -2217,14 +2217,14 @@ snapshots; see plan 8.2 S4. spelling is gone, P5). - The due date: `due_date` as given (and it overrides `terms`); else `terms` ("Net 30", "Net 15 EOM", "2/10 net 30", "Due on receipt", - "Due 2026-11-15", rules.md B-39); else the customer's + "Due 2026-11-15", BS-arap-3); else the customer's `default_terms_as_customer`; else the books' `invoicing.default_terms` ("Net 30" unset); else refused, naming those ways. Terms are kept on the invoice only when given or taken from a default: with only a due date the invoice prints none. - Its number (`INV-0001`) is `invoicing.number_prefix` and `invoicing.first_number` plus the count of numbered invoices before it - (A-2, B-40); it is stored at issue and never recomputed, and a preview + (A-2, BS-arap-4); it is stored at issue and never recomputed, and a preview shows the number the confirm will take (an abandoned preview uses up none). Books that haven't declared `documents_v2` number nothing and show a document as "Invoice {N}". @@ -2244,7 +2244,7 @@ snapshots; see plan 8.2 S4. - Without `confirmed` the DRAFT copy of the PDF is handed over (`pdf`, run its `download`, D-46); confirming renders the issued copy before anything is journaled and files it with the invoice in the same call - (A-7, B-40), returning its `attachment_id` and `sha256` (the same + (A-7, BS-arap-4), returning its `attachment_id` and `sha256` (the same `sha256` `books.get_receipt` reports). - `mailto` is a convenience link for a human to send it from their own mail program: the subject "Invoice INV-0007 from {company}", the body @@ -2252,7 +2252,7 @@ snapshots; see plan 8.2 S4. never send anything (A-4): a mailto link carries no attachment, so say which file to attach. - `warnings` names a revenue account it created with no tax category - (rules.md B-32); `notes` one per finished or abandoned project a line + (BS-ledger-11); `notes` one per finished or abandoned project a line names, and on confirm one per on-spec project (is there now an agreement?). - `books.create_bill { vendor | party_id, date, received_on?, vendor_ref?, @@ -2268,7 +2268,7 @@ snapshots; see plan 8.2 S4. project) part; `vendor` is a vendor id, its party's id or its name (required; the old `party_id` spelling is gone, P5). - `vendor_ref` is the vendor's own invoice number: required in books - that have declared `documents_v2` (B-40). The same vendor and number + that have declared `documents_v2` (BS-arap-4). The same vendor and number twice is refused unless `duplicate_reason` says why, which is journaled with the bill; case, spaces and hyphens are ignored. `received_on` is the day it was received, when it differs from its @@ -2285,7 +2285,7 @@ snapshots; see plan 8.2 S4. - The due date and terms fall back as an invoice's, to the vendor's `default_terms_as_vendor` and no further. `discount_by` is the last day an early-payment discount is open and `max_discount` the largest - it allows (B-39): the caller gives the exact cents when it takes one. + it allows (BS-arap-3): the caller gives the exact cents when it takes one. - `warnings` names an expense account it created with no tax category; `notes` one per finished or abandoned project a line names (none for on-spec: a cost of on-spec work is an expense like any other). @@ -2298,7 +2298,7 @@ snapshots; see plan 8.2 S4. (entry 0, the figures the documents would show, `preview` to pass back) and nothing is written (P4: the S6 tools preview and confirm like the create tools). Settles one or several invoices of one customer in one - entry (B-42): Dr the deposit account the cash less the fee, Dr the + entry (BS-arap-6): Dr the deposit account the cash less the fee, Dr the payment-processing-fees account the fee, Dr sales allowances the discounts, Cr A/R each invoice's cash and discount, every receivable line tagged with its invoice (payment lines in application order, then @@ -2318,7 +2318,7 @@ snapshots; see plan 8.2 S4. - `books.pay_bill { date, paid_from, instrument?, reference?, bill, amount? | applications: [{ bill, amount, discount?, discount_reason? }], confirmed?, preview? }` → as `receive_payment`, per bill and - one vendor (B-42): Dr A/P each bill's cash and discount, Cr the payer + one vendor (BS-arap-6): Dr A/P each bill's cash and discount, Cr the payer account the cash, Cr purchase discounts the discounts. A discount on a bill with an asset or prepaid line is refused with its remedy (record the bill net, or reclassify Dr 6995 / Cr the asset, D-49); a processor's @@ -2328,7 +2328,7 @@ snapshots; see plan 8.2 S4. have existed by reversing its own entry with the reason; it keeps its number and reads `void`. Refused while a payment stands on it (the refusal names the payment entry to reverse first), when void already, - before its date or in a closed period (P4b S1, B-38). + before its date or in a closed period (P4b S1, BS-arap-2). - `books.mark_sent { invoice, on?, by?, via?, recipients?: [string], kind?, reference?, note? }` → `{ invoice, sends: [{ on, by, via, to, kind, reference?, note? }] }`. Records that an invoice went out (P4b S5, @@ -2347,10 +2347,10 @@ snapshots; see plan 8.2 S4. - `books.write_off_invoice { invoice, date, amount?, reason, upload_id | existing_attachment_id, confirmed?, preview? }` → `{ entry_id, document: { ref, status, paid, written_off, outstanding } }`. Writes off an invoice that - will not be collected (a bad debt, P4b S7; rules.md B-41): posts Dr + will not be collected (a bad debt, P4b S7; BS-arap-5): posts Dr `6990` Bad Debt Expense / Cr `1200` Accounts Receivable, the receivable line tagged with the invoice (`WriteOff`), so the invoice reads - `written_off` and its figures stay derived (B-38). `amount` (a decimal + `written_off` and its figures stay derived (BS-arap-2). `amount` (a decimal string, default all it owes) is at most what is owed and may be partial (§1.166-3(a)). Its evidence of worthlessness (collection correspondence, a bankruptcy notice: §1.166-2(a)) is filed in the same @@ -2370,7 +2370,7 @@ snapshots; see plan 8.2 S4. kind, documents: [{ ref, party, date, due_date, total, outstanding, status, overdue_days, last_sent? }], outstanding_total }`. Invoices (`kind` `invoices`) or bills (`bills`), due date first, every figure derived - from the document's lines that stand (B-38). `status` filters: `open` + from the document's lines that stand (BS-arap-2). `status` filters: `open` (default: anything still owed, partly paid and overdue included), `overdue`, `paid`, `void`, `written_off`, `overpaid` or `all`; a row's own `status` is one of `open`, `partial`, `paid`, `written_off`, @@ -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 - (B-23, B-38 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 (B-23, B-38 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: @@ -2464,7 +2464,7 @@ entries. ## Tools — projects (classes) -A project is a class with its facts (`docs/spec/rules.md` B-37): the +A project is a class with its facts (BS-statement-5): the same id, the same name, so `books.add_line`'s `class`, the P&L `class` filter and `books.profit_and_loss_by_class` take projects. A `project` reference is an id or a name (ignoring capitals in any script and @@ -2475,7 +2475,7 @@ ignoring capitals and surrounding space, and never digits only (they would read as an id). A change that keeps a project's own name never checks it again, so old books holding a duplicate name can change either project's facts; a rename onto another project's name is refused. Every project write but a name alone needs the journal feature -`projects` (B-27): books waiting for their format upgrade (D-39) can add +`projects` (BS-format-1): books waiting for their format upgrade (D-39) can add a project by name only, and every other project write (facts, a link to a project, a decision naming one) is refused with `format_upgrade_pending` until the owner upgrades them. @@ -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 (B-37 item 7: revenue less every cost + contribution before overhead (BS-statement-5 item 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 @@ -2515,7 +2515,7 @@ until the owner upgrades them. for an on-spec project (else null): expenses less revenue, never below zero. - `books.project { project, start?, end? }` (books:read; omitted dates: the fiscal - year to date, B-30, as every period report) → `{ project, period: { + year to date, BS-period-3, as every period report) → `{ project, period: { start, end, revenue, expenses, net, margin_pct, by_account: [{ code, name, type ("revenue" | "expense"), amount }], by_month: [{ month ("YYYY-MM"), start, end, revenue, expenses, net, net_to_date }] }, to_date (as above, through @@ -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, rules.md B-37 item 8), in + and `books.create_bill`, `class` on a line, BS-statement-5 item 8), in books that declared the journal feature `document_line_projects`; the handbook's projects section says which these books are. Their payments take none. @@ -2571,12 +2571,12 @@ until the owner upgrades them. dated on or before `as_of` is open (post it or discard it); with `allow_open_drafts: { reason }` the package goes and the reason is journaled as a decision. - **As of one day** (`docs/spec/rules.md` B-33): nothing in it reflects + **As of one day** (BS-statement-4): nothing in it reflects anything dated after `as_of` (default today): no figure, entry, receipt or worksheet row; the chart and `documents/` are as they stand. One list of cash accounts and one of financing accounts serve the whole package: the request's, else the settings'. - **QuickBooks file** (`general-journal.iif`, B-34): as `books.export` + **QuickBooks file** (`general-journal.iif`, BS-format-2): as `books.export` iif makes it, through `as_of`; `warnings` says what it writes differently from the books, in the same lines as `books.export` iif's (account and class names and account numbers one each, the memos @@ -2629,7 +2629,7 @@ until the owner upgrades them. party is the party with the member's name (not a display name) and the member role, as the viewer's capital statement finds it; with none, the member's TIN is a gap. **Tax-basis capital** (`k1-tax-basis-capital.csv`, - P3, D-41, rules.md B-36; Form 1065 instructions, Item L, the tax-basis + P3, D-41, BS-partner-4; Form 1065 instructions, Item L, the tax-basis method): per member, `member, item, book, tax_basis, book_less_tax, status, note` for each Item L line (beginning; capital contributed, cash and property; current year net income (loss); other increase @@ -2667,7 +2667,7 @@ until the owner upgrades them. A draft is an entry being built (`books.draft_entry`, `books.add_line`) that is not in any report until it posts. P4 gives it a state, a way out, and a -read-only preview (rules.md B-43; the journal feature `drafts_v2`: the +read-only preview (BS-entry-5; the journal feature `drafts_v2`: the state and discard tools wait for the books' format upgrade). - `books.list_drafts { state?, as_of? }` → `{ drafts: [{ entry_id, date, @@ -2746,7 +2746,7 @@ An audit is the books read as an auditor reads them, through a day, in one run: the same books give the same findings and the same workpaper. An attestation is a claim by a checker that it looked at something. The audit finds; the attestations stand behind it; the CPA package waits for both -(rules.md B-45; decision D-9; the journal feature `audits`: the audit run +(BS-ledger-13; decision D-9; the journal feature `audits`: the audit run and the attestations wait for the books' format upgrade, refused with `format_upgrade_pending` until then). diff --git a/docs/oracle.md b/docs/oracle.md index d43a88ef..313487b4 100644 --- a/docs/oracle.md +++ b/docs/oracle.md @@ -94,7 +94,7 @@ built through wanderbooks (entries, foreign lines, reversals, closes), every account's balance at month ends and random dates, and each month's P&L, compared exactly (15,800 comparisons). Its first run found one real difference, adjudicated from principles: wanderbooks kept sub-cent -amounts on foreign lines; it now books in cents (rules.md B-3). What the +amounts on foreign lines; it now books in cents (BS-ledger-1). What the original plan still owes (roadmap phase 3): fixture books, not only random ones, diffed as `snapshot()` output automatically, inside the harness as it is (no `ledger-oracle` crate is planned: D-53). This is the direct analog diff --git a/docs/parity.md b/docs/parity.md index 5003ae74..96eed7e6 100644 --- a/docs/parity.md +++ b/docs/parity.md @@ -30,16 +30,16 @@ in CI that the floor never falls between commits. | Reversing entries | Reverse transaction | done | linked via `reversal_of`; dated on or after its original, every kind of entry (D-73) | | Canonical report snapshots (JSON) | — (our oracle format) | done | `reports::snapshot` | | Fixed-asset register + straight-line depreciation | Fixed Asset register | done | `assets.rs`; golden-covered schedule; idempotent runs; disposal with gain/loss; posted (the books') vs scheduled, in-service vs acquired dates, the §723, depreciable and §704(c) figures (P3) | -| Cash flow statement (direct, with the reconciliation schedule and noncash disclosures) | Reports → Cash Flow | done | R-FUTURE-3; rules.md B-14 (P3 defect 1) | +| Cash flow statement (direct, with the reconciliation schedule and noncash disclosures) | Reports → Cash Flow | done | R-FUTURE-3; BS-statement-3 (P3 defect 1) | | Foreign-currency lines (base + foreign stored) | Multi-currency accts | done | R-FUTURE-1 | | Period close (closing entry to Retained Earnings) | Close books | done | R-FUTURE-2 | | Bank reconciliation (cleared flags + report) | Reconcile | done | — | | QuickBooks CSV import (bank txns, chart of accounts) | Banking → Upload | done | R-FUTURE-4 | | QuickBooks IIF + XLSX export | Export / reports | done | R-FUTURE-4 | -| 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 (rules.md B-38); 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/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, rules.md B-37 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 item 8; 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 | @@ -48,7 +48,7 @@ in CI that the floor never falls between commits. | Prepaid expense + deferred revenue amortization | Amortization schedules (Xero/QBO add-ons) | done | hand-verified fixture, to the cent; golden-covered (`golden/amortization_plans.json`, `schedules.rs::golden_amortization_plans`: plan, posted, remaining, P&L and balance sheet; worksheet `plan/golden-worksheets/amortization-plans.md`) | | Automated cross-implementation diff harness (GnuCash first) | — (`just oracle`) | partial | live: `tests/oracle_gnucash.rs` runs 200 random books through GnuCash 5.10 in a pinned container, 15,800 exact comparisons, weekly in CI (docs/oracle.md Layer 5); open: fixture books diffed as `snapshot()` output, and the machine-readable catalog with CI enforcing this floor | | Invoice sent tracking (who, how, to whom, when, original or reminder, the channel's reference) | Business → Invoices (Xero's "Sent"; QBO's email) | done | P4b S5; records, never sends (A-4); a send changes no figure; `invoice.sent` under `documents_v2` (D-52) | -| Multi-document settlements with early-payment discounts (gross method) | Business → Invoices/Bills; Receive payment | done | P4b S6: one entry, one party, one application per document (`kernel::settle`, B-42); a discount beyond the terms needs a reason; a bill with an asset line is refused (D-49); the bill and its payment tested, replay equal to live | +| Multi-document settlements with early-payment discounts (gross method) | Business → Invoices/Bills; Receive payment | done | P4b S6: one entry, one party, one application per document (`kernel::settle`, BS-arap-6); a discount beyond the terms needs a reason; a bill with an asset line is refused (D-49); the bill and its payment tested, replay equal to live | | A processor's fee on a payment received (gross presentation) | Xero/QBO Stripe & Shopify deposits | done | P4b S6: Dr the deposit the net, Dr processing fees the fee, Cr A/R the gross (A-4); `a_fee_posts_gross_to_receivables_and_net_to_the_bank` | | Bills due, aging detail and tie-out, aging exports | Business → Bills; Reports → A/R and A/P Aging | done | P4b S6: `books.bills_due`, `detail`, `control`, `ar_aging.csv`/`ap_aging.csv` in `books.export` and the CPA package, each with its `TOTAL` tie-out (`the_aging_csvs_tie_to_the_control_check`) | @@ -59,13 +59,12 @@ egui phase starts; semantics come first. P0 (`plan/served.md`) changed no feature in the catalog above, so no status moved and the floor stands. It hardened what exists: an older -version refuses books from a newer one as newer, not corrupt (rules.md -B-27); the MCP server fails closed after an internal error, and no input -reaches one (dates are four-digit years, amounts at most a line's, B-28); +version refuses books from a newer one as newer, not corrupt (BS-format-1); the MCP server fails closed after an internal error, and no input +reaches one (dates are four-digit years, amounts at most a line's, BS-entry-4); local files were read only from the import roots, never the books, the vault or its key (P2 slice 5 removed local paths: files now come in only as uploads, -D-46); no file with a full TIN is filed into the books (B-26); the agent is +D-46); no file with a full TIN is filed into the books (BS-partner-2); the agent is told the rules in force in a short connect text and a handbook, and no agent text points at the books' files, git or the repo. @@ -109,7 +108,7 @@ P13 is a specification, not a feature, so no row of the semantic catalog moves and the floor stands. It adds the checker crate (`bookspec/checker`: the example schema, the rule identifiers `BS--` and the `Engine` trait), the runner (`bookspec/runner`: pass, fail or not claimed per rule), -and the rule index from B-1 to B-45 (`bookspec/spec/rules-index.md`). Every +and the rule index from BS-entry-1 to BS-ledger-13 (`bookspec/spec/rules-index.md`). Every existing bookspec example still runs on every `cargo test`, through both the loader's own checks and the `Engine` trait. @@ -122,7 +121,7 @@ number and due date it will take, the DRAFT or the discount, and nothing written) and post with it (A-1), which is what the workflow reference does before a document leaves the company. A bill in books that have declared `documents_v2` names each line's account and keeps the vendor's -invoice (A-10, A-13); an invoice keeps the copy it issued (A-7, B-40) and +invoice (A-10, A-13); an invoice keeps the copy it issued (A-7, BS-arap-4) and a `mailto` link for a human to send it, since the books never send (A-4). `books.update_party` takes the party's email and terms per side (A-13) and the owner's full contact block (D-55: phone, contact person, billing and @@ -144,7 +143,7 @@ saves the issued copy beside the re-created one; the Money in list names an invoice by its number. The handbook's invoices-and-bills procedure is complete (issue, collect, pay on terms, void or write off, the fee, the CPA's list) and says what waits for the owner's upgrade. rules.md gains -B-39 (terms) and B-40 (numbers and the issued copy). No golden moved. +BS-arap-3 (terms) and BS-arap-4 (numbers and the issued copy). No golden moved. ### P9a self-host deployment (2026-10-26) @@ -188,7 +187,7 @@ A/R gained the direct write-off the owner chose (A-5; plan 8.2 S7): an invoice that will not be collected comes off 1200 with Dr 6990 Bad Debt Expense, its receivable line tagged `WriteOff` so the receipt's figures stay derived, and its evidence of worthlessness filed in the same call -(rules.md B-41; IRC §166, §111; Treas. Reg. §1.166-1(e), (f), -2(a), +(BS-arap-5; IRC §166, §111; Treas. Reg. §1.166-1(e), (f), -2(a), -3(a)). A same-year recovery is the reversal D-49 records, not a new movement; bills are never written off. No row above changed status (the A/R and A/P rows already say `done`), so the floor stands (10 done). @@ -207,7 +206,7 @@ hash `books.verify` checks), holds identical bytes as one live attachment annotation field list, engine receipt numbers running from the max) and what a payment settles (`entry.settles`, the only source of "reimbursed"), and gives company records four more homes (`notices`, `correspondence`, -`plans`, `history`, D-20). Rules.md B-44 states it; `docs/testing.md`'s P6 +`plans`, `history`, D-20). Rules.md BS-ledger-12 states it; `docs/testing.md`'s P6 section lists its tests and the P12 mutation targets. ### P4: drafts, the evidence gate, the preview digest (2026-10-29) @@ -216,7 +215,7 @@ Three new rows, none above changed status, and the floor stands. | Area | Counterpart (a cross-check, not the spec) | Status | Notes | |---|---|---|---| -| Draft states and discard (`books.set_draft_state`, `books.discard_draft`, `books.list_drafts`; Lean `Step.discard`) | Draft/pending transactions (QBO "pending"), voiding an unposted entry | done | `entry.draft_state_set` and `entry.draft_discarded` under `drafts_v2`; B-43; tests `discard_unblocks_close`, `draft_states_replay_and_project`, `a_draft_waits_for_its_receipt_and_posts`; the fixture `p4_before` was written by the version before and opens to the same figures; golden-covered (`ledger-store` `golden/draft_states_and_evidence_gate.json`, `golden_drafts.rs::golden_draft_states_and_evidence_gate`; worksheet `plan/golden-worksheets/draft-states-and-evidence-gate.md`) | +| Draft states and discard (`books.set_draft_state`, `books.discard_draft`, `books.list_drafts`; Lean `Step.discard`) | Draft/pending transactions (QBO "pending"), voiding an unposted entry | done | `entry.draft_state_set` and `entry.draft_discarded` under `drafts_v2`; BS-entry-5; tests `discard_unblocks_close`, `draft_states_replay_and_project`, `a_draft_waits_for_its_receipt_and_posts`; the fixture `p4_before` was written by the version before and opens to the same figures; golden-covered (`ledger-store` `golden/draft_states_and_evidence_gate.json`, `golden_drafts.rs::golden_draft_states_and_evidence_gate`; worksheet `plan/golden-worksheets/draft-states-and-evidence-gate.md`) | | One evidence gate (`evidence::requirement`) | Attach-required rules on posting | done | the store, the previews, the digest, the viewer and Needs attention call one function; `gui_and_server_gate_agree`, `a_reversal_needs_no_receipt_of_its_own` (D-47); golden-covered by the same file as the row above (every entry's `evidence::requirement`, the gate's refusals, a reversal exempt by origin) | | Preview digest on every confirm (D-50) | Confirm dialogs | partial | `stale_preview_refused`, `every_confirm_tool_takes_a_preview`; detects drift, not a human's look | @@ -246,7 +245,7 @@ Three new rows, none above changed status, and the floor stands. | Area | Counterpart (a cross-check, not the spec) | Status | Notes | |---|---|---|---| -| Audit run: one programme of checks over the statements, the control accounts, closes, schedules, assets, evidence, drafts, tax categories, 1099 decisions, settings and the store's integrity (`books.audit`, `books.workpaper`) | An auditor's workpaper; QBO "Audit log"/"Review" and Xero's "Reports review" are a cross-check only | done | rules.md B-45; `ledger_core::audit`, `ledger_store::audit`; tests `audit_detects_each_seeded_defect` (every code seeded), `audit_is_deterministic`, `workpaper_pdf_is_deterministic`; the fixture `p8_before` was written by the version before; golden-covered (`golden/audit_workpaper.json`, `golden_audit.rs::golden_audit_workpaper`: five findings in five areas, the 1099 and cash-flow inputs derived from the books; severities are the `CODES` table's CONVENTION; worksheet `plan/golden-worksheets/audit-workpaper.md`) | +| Audit run: one programme of checks over the statements, the control accounts, closes, schedules, assets, evidence, drafts, tax categories, 1099 decisions, settings and the store's integrity (`books.audit`, `books.workpaper`) | An auditor's workpaper; QBO "Audit log"/"Review" and Xero's "Reports review" are a cross-check only | done | BS-ledger-13; `ledger_core::audit`, `ledger_store::audit`; tests `audit_detects_each_seeded_defect` (every code seeded), `audit_is_deterministic`, `workpaper_pdf_is_deterministic`; the fixture `p8_before` was written by the version before; golden-covered (`golden/audit_workpaper.json`, `golden_audit.rs::golden_audit_workpaper`: five findings in five areas, the 1099 and cash-flow inputs derived from the books; severities are the `CODES` table's CONVENTION; worksheet `plan/golden-worksheets/audit-workpaper.md`) | | Attestations of receipts, entries and periods, weighed against `policy.attestation_bar` when asked (`books.attest_receipt`, `books.review_entry`, `books.attest_period`, `books.attestations`) | An accountant's sign-off on a month | partial | `below_bar_not_counted`, `amount_mismatch_never_counts`, `stale_head_period_attestation_refused`; the method is the client's own claim, and the books say so | | The CPA package waits for a counted audit (`policy.cpa_package_requires_audit`) | A close checklist before handoff | partial | `cpa_package_refuses_without_a_counted_audit_unless_a_reason_is_given`; behind the feature `audits` | diff --git a/docs/parties-and-attachments.md b/docs/parties-and-attachments.md index e17e696d..c985b33f 100644 --- a/docs/parties-and-attachments.md +++ b/docs/parties-and-attachments.md @@ -6,7 +6,7 @@ subject. Status: built (2026-10-15 to 2026-10-17: parties with roles, the TIN vault, attachments linked to any subject; the party's contact block, D-55, landed with P4b S4.4 on 2026-10-29; the same bytes filed twice are one attachment since P6, the same day). The design is kept as -written; departures are in `plan/served.md` and `docs/spec/rules.md` B-26. +written; departures are in `plan/served.md` and BS-partner-2. ## Why together @@ -50,7 +50,7 @@ W4Facts { received: NaiveDate, state: String, kept_at: String } The 1099 form stays on the vendor record (`vendor.1099_set`); a party reaches it through `vendor`. -Rules (to vendor as B-26 with sources): +Rules (to vendor as BS-partner-2 with sources): - A full TIN or SSN is never in the journal: `tin_last4` is exactly four digits, and any nine-digit run in any party field is refused (the engine @@ -102,7 +102,7 @@ derived. Spec: `ledger_core::shares`. (`set_entry_party`) is one derived share: all of it. `Ledger::entry_party` means "the sole party"; `entry_parties` lists them all. -- **What a share is of** (rules.md B-35, P3 defect 14): one signed +- **What a share is of** (BS-partner-3, P3 defect 14): one signed target, debit-positive as a line on the parties' own account (positive: the company paid or gave; negative: it received), with its direction (paid, received, neither) and what of it was money and what property in @@ -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 (B-35 item 4): cash (its money: cash, a card, the members' + bases (BS-partner-3 item 4): 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/proofs/k-u1.md b/docs/proofs/k-u1.md index 1a121079..62c2dcdc 100644 --- a/docs/proofs/k-u1.md +++ b/docs/proofs/k-u1.md @@ -174,6 +174,6 @@ rounding) and `Fx.booked_whole` (every booked amount in `Z * u`). The D-75 bound is stated in BS-entry-4 as an engine-neutral MUST (a foreign amount and an exchange rate each take at most ten decimal places, trailing zeros not counted; replay exempt, BS-entry-8), with D-75 as its -provenance. wanderbooks' claim for B-28 (`docs/spec/claims/entry.md`) +provenance. wanderbooks' claim for BS-entry-4 (`docs/spec/claims/entry.md`) lists the enforcement (`add_line_fx`, `ValueOutOfRange`, never on replay) and the checks. diff --git a/docs/proofs/k-u2.md b/docs/proofs/k-u2.md index c05eeede..2065584f 100644 --- a/docs/proofs/k-u2.md +++ b/docs/proofs/k-u2.md @@ -23,7 +23,7 @@ wrapper: when the amount carries no more places than `places` it is returned unchanged, otherwise the result carries exactly `places` places, matching `Decimal::round_dp_with_strategy` to the character (including its scale). `round_minor` picks `10^-currency.minor_units()`; a currency ISO 4217 gives -no minor unit is returned exactly, the FX rule's existing behaviour (B-3). +no minor unit is returned exactly, the FX rule's existing behaviour (BS-ledger-1). The `Amount` trait gained `checked_round_to_step`, implemented for `Decimal`, `i32` and `i64` exactly as `checked_div_round_cent` was: the diff --git a/docs/proofs/k-u4.md b/docs/proofs/k-u4.md index 6f15a41c..69292181 100644 --- a/docs/proofs/k-u4.md +++ b/docs/proofs/k-u4.md @@ -1,8 +1,8 @@ # K-U4: collection totals (`kernel/total.rs`) Kernel sweep unit U4 (`plan/kernel-sweep-audit.md` sections 2 and 3). The -authority is rules.md B-21 (amounts are exact; rounding only on returns) and -B-28 (no input may reach a panic), bookspec `BS-entry-3` and `BS-entry-4`. +authority is BS-entry-3 (amounts are exact; rounding only on returns) and +BS-entry-4 (no input may reach a panic), bookspec `BS-entry-3` and `BS-entry-4`. ## The functions @@ -105,7 +105,7 @@ mirrors): arguments: `audit::check_articulation` (`current_earnings + closed`), `periods::allocate_last_absorbs` / `allocate` (`amount * share`), and the kernel-less helpers with `Decimal` arguments. All now refuse. Documents, - drafts and recurring entries are the figures B-28 lets restore oversized. + drafts and recurring entries are the figures BS-entry-4 lets restore oversized. ## Sites replaced diff --git a/docs/receipt-store.md b/docs/receipt-store.md index 29a7bd1b..fe4c47c6 100644 --- a/docs/receipt-store.md +++ b/docs/receipt-store.md @@ -93,8 +93,7 @@ apply is safe — on startup the applier replays every journal line with through that link (plan 8.3.11). An `invoice.written_off` (plan 8.3.6, P4b S7) carries `{invoice_id, entry_id, date, amount, reason}`; replay tags the entry's receivables line `WriteOff`, and the projection keeps - no written-off figure either: it is the tagged lines' sum (rules.md - B-38, B-41). Its evidence of worthlessness rides beside it, as a + no written-off figure either: it is the tagged lines' sum (BS-arap-2, BS-arap-5). Its evidence of worthlessness rides beside it, as a `receipt.attached` on the write-off's entry and an `attachment.linked` to the invoice, filed in the same call. - `prev`: hex SHA-256 of the previous line's canonical JSON (keys sorted, no @@ -164,7 +163,7 @@ a backup is then proven where it lands, by a drill (docs/mcp-interface.md, only leaves an entry through a recorded unlink. Blobs are untouched: a withdrawn file is still hash-verified and readable, and the journal shows when it was filed, linked, unlinked, and withdrawn, and why. -- **Extraction is derived, and journaled** (P6, rules.md B-44): +- **Extraction is derived, and journaled** (P6, BS-ledger-12): `attachment.text_extracted {attachment_id, text_sha256, extractor, version, pages, status}` records what reading a file found (`ok`, `none`, `failed`); the text itself is a content-addressed blob like any @@ -176,7 +175,7 @@ a backup is then proven where it lands, by a drill (docs/mcp-interface.md, read off a file (the closed field list; a later annotation replaces the earlier record), and `entry.settles {entry_id, settles[]}` says which entries a payment pays back (the only source of "reimbursed"). -- **Audits and attestations are records, not figures** (P8, rules.md B-45, +- **Audits and attestations are records, not figures** (P8, BS-ledger-13, feature `audits`): `audit.run {id, through, through_seq, scope, program_version, tb_hash, findings_sha256, workpaper_attachment?, workpaper_pdf?}` says a programme of checks was run through a day at the @@ -206,7 +205,7 @@ Suspected corruption is fixed by rebuild, never by forensics. schema keeps a file of its own, and a version never migrates, writes or deletes another schema's (`ledger_store::db_file_for`; the legacy `wanderbooks.db` is used only while it holds this version's schema; - rules.md B-27). The journal lives next to it + BS-format-1). The journal lives next to it at `$WANDERBOOKS_DATA/journal.jsonl`; blobs under `$WANDERBOOKS_DATA/blobs/`. WAL mode on, `synchronous=FULL`, `integrity_check` on startup. diff --git a/docs/requirements.md b/docs/requirements.md index 38bbeb3a..a2f2dc19 100644 --- a/docs/requirements.md +++ b/docs/requirements.md @@ -66,7 +66,7 @@ requirement conflict, the requirement wins. to the currency's minor unit by largest remainder (the odd cent goes to the largest remainder, ties to the earlier member; the owner, 2026-10-13), earnings not yet closed the way their close will split them (D-38, - rules.md B-13), so every row's total is exact and a member's capital on a + BS-partner-1), so every row's total is exact and a member's capital on a day never changes when its month is closed. Any equity change the roll-forward doesn't explain is shown as "other", never hidden. - **R-9d — Tax categories.** Revenue and expense accounts map to stable @@ -100,7 +100,7 @@ requirement conflict, the requirement wins. - **R-13 — Receipt enforcement.** The server (not the engine — the engine stays policy-free) enforces the books' evidence policy: postings at or above a threshold (the journaled setting `policy.evidence.threshold`, - with required and exempt accounts; P1, rules.md B-29) must have at least + with required and exempt accounts; P1, BS-ledger-9) must have at least one attached receipt. Evaluated by `ledger-config`'s `ReceiptPolicy` today; P4 moves the evaluation into `ledger_core::evidence` so the store, the server and the viewer call one function (plan I-5, D-47: @@ -118,7 +118,7 @@ requirement conflict, the requirement wins. - **R-? — Cash flow statement** (direct method, with the reconciliation of net income to operating cash and the noncash investing and financing - activities; rules.md B-14, P3 defect 1). Was R-FUTURE-3. + activities; BS-statement-3, P3 defect 1). Was R-FUTURE-3. `ledger-core::reports::cash_flow` + `books.cash_flow`. - **R-? — QuickBooks-compatible import/export.** Was R-FUTURE-4. `ledger-import` crate: CSV bank/chart import, IIF and XLSX export. @@ -137,7 +137,7 @@ requirement conflict, the requirement wins. account by share, to the currency's minor unit, odd units by largest remainder, cumulatively from the first members close with these members and shares, so no member is ever a unit from their exact share: the - partnership convention, rules.md B-13; closes journaled under earlier + partnership convention, BS-partner-1; closes journaled under earlier rules replay with the rule they were made under: `CloseTo::MembersRun`, the run rule of 2026-10-13 to P3, `CloseTo::MembersPerClose`, and before 2026-10-13 the last member absorbing rounding), or `CloseTo::Account` (any equity account, e.g. @@ -166,7 +166,7 @@ requirement conflict, the requirement wins. - **R-? — A/R and A/P workflows.** Was R-FUTURE-5. `ledger-core::arap`: customers, vendors, invoices, bills, payments, AR/AP aging. MCP tools for the full workflow. Since P4b S1 (D-45, - rules.md B-38): a document's figures are the signed sum of its tagged + BS-arap-2): a document's figures are the signed sum of its tagged ledger lines dated on or before the day asked about, so reversals, voids and write-offs are right by construction; a hand line on a control account is refused; `books.control_check` ties the subledger to @@ -185,11 +185,11 @@ requirement conflict, the requirement wins. split explicitly across lines at entry time. - **R-? — CPA handoff package.** `books.export_cpa_package` (and the viewer's Export menu, D-29): a zip, built by `ledger-package` for both, - as of a day (B-33), with the trial balance and general ledger as XLSX, - the statements as Typst PDFs, the journal as IIF (B-34), every receipt + as of a day (BS-statement-4), with the trial balance and general ledger as XLSX, + the statements as Typst PDFs, the journal as IIF (BS-format-2), every receipt behind the period's entries with an index, the company's documents, the 1099 worksheet, the members' equity and K-1 worksheets (book and tax - basis, B-36), and a README; handed over as a download (D-46). + basis, BS-partner-4), and a README; handed over as a download (D-46). ## Non-goals (all phases of the engine) diff --git a/docs/spec/README.md b/docs/spec/README.md index d786b0d7..2b3eaee5 100644 --- a/docs/spec/README.md +++ b/docs/spec/README.md @@ -24,7 +24,7 @@ layers differ in what they cover and in whether we may copy them: ```text SOURCE: Pacioli ch. 36 (sources/pacioli-1494.md); IRS Pub. 583 (sources/irs-records.md) -SOURCE: ASC 830-20-30-1 (cited, rules.md B-3) +SOURCE: ASC 830-20-30-1 (cited, BS-ledger-1) SOURCE: CHOICE (the owner, 2026-10-13) SOURCE: CONVENTION (QuickBooks aging); nearest authority ASC 326-20-55-38 (illustrative) ``` @@ -73,12 +73,12 @@ 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 B-14 rule 11) is in neither list above; ASC -606-10-25-31, 25-32 and 55-20 (B-16's over-time method) are not yet read; -B-15 rule 6 cites ASC 250 with no paragraph; B-17's 606-10-55-39 is in +issue costs, cited by BS-statement-3 rule 11) 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 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): B-38 cites ASC 310-10, 405-20-40-1 and 606-10-45-4, -none yet read in the ASC basic view; B-38 keeps the CONVENTION label +P4b, 2026-10-23): BS-arap-2 cites ASC 310-10, 405-20-40-1 and 606-10-45-4, +none yet read in the ASC basic view; BS-arap-2 keeps the CONVENTION label until they are vendored with a SHA-256, as P4b.16 lists with the sources -B-39 to B-41 will need. +BS-arap-3 to BS-arap-5 will need. diff --git a/docs/spec/sources/fasb-asc.md b/docs/spec/sources/fasb-asc.md index 51b2ebe8..14911fd0 100644 --- a/docs/spec/sources/fasb-asc.md +++ b/docs/spec/sources/fasb-asc.md @@ -14,7 +14,7 @@ allocated "as equitably as possible" to the periods that get its services. Depreciation distributes cost, "less salvage (if any)", over the estimated useful life "in a systematic and rational manner"; it is "a process of allocation, not of valuation." No method is prescribed. -→ B-15: straight line, salvage never depreciated, partial months by +→ BS-asset-1: straight line, salvage never depreciated, partial months by days (each day of service bears the same cost) is one systematic and rational allocation. @@ -25,7 +25,7 @@ normal operating cycle," paid "in advance of their use or consumption" (05-4); examples include insurance, interest, rents, taxes, and advertising not yet received (05-5). The Subtopic covers only their nature (05-2): it prescribes no expensing method. -→ B-16: a prepaid is an asset, expensed over the months it covers +→ BS-prepaid-1: a prepaid is an asset, expensed over the months it covers (a convention; the ASC is silent on the method). ## 210-10-45-1, -45-2, -45-5 (Balance sheet: current assets and liabilities) @@ -47,10 +47,10 @@ operating activities" (45-10). Collections on, and disbursements for, loans the entity makes are investing (45-12(a), 45-13(a)). Proceeds of "other short- or long-term borrowing" are financing inflows (45-14(b)); "repayments of amounts borrowed" are financing outflows (45-15(b)). -→ B-14: money owners advance (Due to Shareholders) is borrowing, so +→ BS-statement-3: money owners advance (Due to Shareholders) is borrowing, so financing, gross; a loan the company makes is investing, gross. -## ASC 230 for the direct method (rules.md B-14, P3 defect 1) +## ASC 230 for the direct method (BS-statement-3, P3 defect 1) Read 2026-10-20, not in the ASC basic view: DART's Codification pages need a login, and its public Roadmap on the statement of cash flows @@ -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." → B-14 rule 1. + of an entity during a period." → BS-statement-3 rule 1. - **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 @@ -92,7 +92,7 @@ Quotes are short; the rest is paraphrase. purchase" for PP&E; generally only those are investing, and incurring debt directly to the seller is a financing transaction whose later principal payments are financing. → rule 12 (the bill split), and the - limit B-14 records. + limit BS-statement-3 records. - **230-10-45-14(a)** (EY p. 42): financing inflows include "Proceeds from issuing equity instruments". **45-15(a)**: financing outflows include "Payments of dividends or other distributions to owners"; **45-15(c)**: @@ -175,7 +175,7 @@ Quotes are short; the rest is paraphrase. referenced to it. → the printed statement's noncash schedule. - **830-230-45-1** (EY p. 81; DART 7.1): the effect of exchange-rate changes on cash held in foreign currencies is reported as a separate - part of the reconciliation of the change in cash. → B-14's scope note + part of the reconciliation of the change in cash. → BS-statement-3's scope note (single-currency books, R-5). - **105-10-05-1, 05-2, 05-3** (read only in their 2009 text, ASU 2009-01 Appendix B, pp. 17-18, https://storage.fasb.org/ASU2009-01.pdf; the @@ -264,24 +264,24 @@ An entity controlling the specified good or service before transfer is the principal (55-37) and recognizes revenue "in the gross amount of consideration" it expects (55-37B); an agent recognizes only its fee or commission (55-38). -→ B-17: an app seller is the principal for its app, so its revenue is +→ BS-revenue-1: an app seller is the principal for its app, so its revenue is the gross price; the platform's commission is an expense. ## 450-30-25-1 (Gain contingencies) -Added 2026-10-21 for B-37 from the paragraph's text as Deloitte's DART +Added 2026-10-21 for BS-statement-5 from the paragraph's text as Deloitte's DART roadmaps quote it (originally FAS 5 ¶17(a)); not re-read in the ASC 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." -→ B-37 item 4: a payment hoped for from work done on spec is recorded +→ BS-statement-5 item 4: 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. ## 340-40-25-5 (Costs to fulfill a contract) -Added 2026-10-21 for B-37 as the DART revenue roadmap sets it out; not +Added 2026-10-21 for BS-statement-5 as the DART revenue roadmap sets it out; not re-read in the ASC basic view: check it there at the next reading. Costs incurred to fulfill a contract (one not in another Topic's scope) are an asset only if all three criteria are met: they relate directly to a @@ -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." -→ B-37 item 4 (with B-22): on-spec work has no contract it is expected +→ BS-statement-5 item 4 (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 B-37 item 8 as the DART revenue roadmap sets it +Added 2026-10-22 for BS-statement-5 item 8 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. -→ B-37 item 8 (with 25-7): a cost traceable to one job (25-7(a), (b), +→ BS-statement-5 item 8 (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/helvering-v-price-1940.md b/docs/spec/sources/helvering-v-price-1940.md index 99901d41..16a8ed11 100644 --- a/docs/spec/sources/helvering-v-price-1940.md +++ b/docs/spec/sources/helvering-v-price-1940.md @@ -1,5 +1,5 @@ # A promise to pay is not payment: Helvering v. Price, 309 U.S. 409 (1940) -Governs why a party's totals never count a promise as a payment (rules.md B-35): a bill, a fee charged on the party's own card, equipment bought on the seller's own note, or a distribution still owed counts when it is paid, not when it is promised. The Supreme Court held that a taxpayer reporting on the cash basis who gave his own note, even a secured one, had not paid. Opinions of the Supreme Court are works of the United States Government (`us-public-domain-status.md`). +Governs why a party's totals never count a promise as a payment (BS-partner-3): a bill, a fee charged on the party's own card, equipment bought on the seller's own note, or a distribution still owed counts when it is paid, not when it is promised. The Supreme Court held that a taxpayer reporting on the cash basis who gave his own note, even a secured one, had not paid. Opinions of the Supreme Court are works of the United States Government (`us-public-domain-status.md`). ## Helvering v. Price, 309 U.S. 409, 412-413 (1940) Source: (United States Reports, Library of Congress) diff --git a/docs/spec/sources/intuit-iif.md b/docs/spec/sources/intuit-iif.md index 92961dbb..ac41461a 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 (rules.md B-34 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 rule 8). 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` @@ -151,7 +151,7 @@ Retrieved: 2026-10-20 Cited (not quoted): "User recognizable name for the Account", with ValidRange "QBW: Max=31" (QuickBooks Desktop; QuickBooks Online: 100). Its `Account.AcctNum` page (`.../95a0835b-80bd-4fe1-2d7f-96ea2c372442.htm`) states no length. -So the limits are Intuit's own: an account name (one level of a subaccount's NAME, as the account's own name is entered) at most 31 characters, an account number at most 7, a memo at most 4,095. The books write each within them: a longer level is cut to 31 (then no two NAMEs may match), a longer number is left out of ACCNUM (it is optional; the NAME identifies the account), a longer memo is cut to 4,095, and every one is listed (rules.md B-34). +So the limits are Intuit's own: an account name (one level of a subaccount's NAME, as the account's own name is entered) at most 31 characters, an account number at most 7, a memo at most 4,095. The books write each within them: a longer level is cut to 31 (then no two NAMEs may match), a longer number is left out of ACCNUM (it is optional; the NAME identifies the account), a longer memo is cut to 4,095, and every one is listed (BS-format-2). ## Add, edit, or delete accounts in QuickBooks Desktop (US, updated 8/4/2026) Source: @@ -162,7 +162,7 @@ Tagged for QuickBooks Desktop (Mac Plus, Premier Plus, Pro Plus, Accountant, Ent > The parent and subaccount must be the same account type. -So the books write a subaccount whose QuickBooks type differs from its parent's (a bank account under a header that is no bank, an asset's cost account under a "Fixed assets" header) at the top level, its own subaccounts with it, and list it (rules.md B-34). Intuit's own journal sample (`journal.zip`, above) declares `Construction:Labor` without ever declaring `Construction`, so QuickBooks makes a missing parent itself; the books declare each parent before its subaccounts all the same, so a parent keeps its own type and number rather than taking ones QuickBooks guesses. +So the books write a subaccount whose QuickBooks type differs from its parent's (a bank account under a header that is no bank, an asset's cost account under a "Fixed assets" header) at the top level, its own subaccounts with it, and list it (BS-format-2). Intuit's own journal sample (`journal.zip`, above) declares `Construction:Labor` without ever declaring `Construction`, so QuickBooks makes a missing parent itself; the books declare each parent before its subaccounts all the same, so a parent keeps its own type and number rather than taking ones QuickBooks guesses. ## Customer and vendor names on accounts receivable and payable @@ -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 (rules.md B-34 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 rule 7). ## 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; rules.md B-34 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 rule 8). ## What QuickBooks does with an over-long name (not Intuit) Source: Thomson Reuters, Accounting CS help, "Export payroll journal entries", @@ -221,7 +221,7 @@ Intuit's own journal sample (above) wraps fields holding a comma in double quote > For imports, you will break the import if you have double quotes within your text -So the books write a double quote as a single one, listed like any other change (rules.md B-34). +So the books write a double quote as a single one, listed like any other change (BS-format-2). ## Not found in any Intuit source @@ -230,7 +230,7 @@ Searched 2026-10-13 and 2026-10-20 (the help articles above and every document i - an escaping mechanism for tabs, line breaks, or double quotes inside a field (no escape syntax is documented; the only safe reading is that fields must not contain tabs or line breaks, and, from the reports above, double quotes); - an explicit sentence that a transaction's TRNS and SPL amounts must sum to zero (every example does; the sign rule implies it); - the allowed number of decimal places, or whether thousands separators or currency symbols are accepted in AMOUNT; -- the character encoding beyond "ASCII text" (so the books write plain ASCII, transliterating anything else and listing what changed: rules.md B-34, DECISION D-36); +- the character encoding beyond "ASCII text" (so the books write plain ASCII, transliterating anything else and listing what changed: BS-format-2, DECISION D-36); - whether a four-digit year is accepted everywhere despite the "MM/DD/YY" wording (Intuit's 2007+ example uses one); - what QuickBooks Desktop does on import with an account name, account number or memo longer than its limits (only the non-Intuit note above, for names), how many levels of subaccounts it allows, or a limit on a whole NAME with its parents; - how long a journal entry's number (DOCNUM) may be (the limits article has no row for it; the books' entry ids are a few digits); diff --git a/docs/spec/sources/irs-capital-accounts.md b/docs/spec/sources/irs-capital-accounts.md index 20362b05..e90aad1e 100644 --- a/docs/spec/sources/irs-capital-accounts.md +++ b/docs/spec/sources/irs-capital-accounts.md @@ -1,5 +1,5 @@ # Partners' capital accounts: what a member's money and property count as -Governs what a member's party totals count (rules.md B-35): a member's capital account rises by the money and the property (net of liabilities on it) the member contributes, and falls by the money and property distributed to them; a partnership liability the member pays for it is money the member contributed. The K-1's capital account analysis (Item L) reports the same contributions and distributions. wanderbooks counts these from the books as they are; the tax-basis figures stay with the CPA. +Governs what a member's party totals count (BS-partner-3): a member's capital account rises by the money and the property (net of liabilities on it) the member contributes, and falls by the money and property distributed to them; a partnership liability the member pays for it is money the member contributed. The K-1's capital account analysis (Item L) reports the same contributions and distributions. wanderbooks counts these from the books as they are; the tax-basis figures stay with the CPA. ## Treas. Reg. §1.704-1(b)(2)(iv)(b): basic rules of capital accounts Source: diff --git a/docs/spec/sources/irs-partnership-basis.md b/docs/spec/sources/irs-partnership-basis.md index 52536105..de61586b 100644 --- a/docs/spec/sources/irs-partnership-basis.md +++ b/docs/spec/sources/irs-partnership-basis.md @@ -1,5 +1,5 @@ # Tax basis of fixed assets: cost, contributed property, and personal-use conversion -Governs the tax figures the fixed asset register carries beside book value (rules.md B-25): the §723 basis, the depreciable basis, and the §704(c) built-in gain or loss at contribution; and the property contributed at its adjusted basis on the K-1 worksheet's tax-basis capital (rules.md B-36). Property the partnership buys has a cost basis (IRC §1012); property a member contributes keeps the member's adjusted basis (IRC §723), and the difference from its fair market value is the built-in gain or loss that §704(c) makes the partnership account for; property a member converts from personal use has a depreciable basis of the lesser of fair market value and adjusted basis (Treas. Reg. §1.168(i)-4(b)(1)). wanderbooks records the basis; tax depreciation (MACRS, conventions, elections) stays with the CPA. +Governs the tax figures the fixed asset register carries beside book value (BS-asset-4): the §723 basis, the depreciable basis, and the §704(c) built-in gain or loss at contribution; and the property contributed at its adjusted basis on the K-1 worksheet's tax-basis capital (BS-partner-4). Property the partnership buys has a cost basis (IRC §1012); property a member contributes keeps the member's adjusted basis (IRC §723), and the difference from its fair market value is the built-in gain or loss that §704(c) makes the partnership account for; property a member converts from personal use has a depreciable basis of the lesser of fair market value and adjusted basis (Treas. Reg. §1.168(i)-4(b)(1)). wanderbooks records the basis; tax depreciation (MACRS, conventions, elections) stays with the CPA. ## 26 U.S.C. §1012(a): basis is cost Source: @@ -99,6 +99,6 @@ SHA-256 of the retrieved file (`p946.html`): `bcc1d04f59bbfc4e74181831c112745e62 > - Increased by the cost of any permanent improvements or additions and other costs that must be added to basis. > - Decreased by any deductions you claimed for casualty and theft losses and other items that reduced your basis. -**Placed in Service** (for tax depreciation, the CPA's; the book in-service date rests on ASC 360-10-35-4, rules.md B-15) +**Placed in Service** (for tax depreciation, the CPA's; the book in-service date rests on ASC 360-10-35-4, BS-asset-1) > You place property in service when it is ready and available for a specific use, whether in a business activity, an income-producing activity, a tax-exempt activity, or a personal activity. Even if you are not using the property, it is in service when it is ready and available for its specific use. diff --git a/docs/spec/sources/irs-partnerships.md b/docs/spec/sources/irs-partnerships.md index ccfa50c6..7745dd11 100644 --- a/docs/spec/sources/irs-partnerships.md +++ b/docs/spec/sources/irs-partnerships.md @@ -1,5 +1,5 @@ # Partnerships: shares of income and capital accounts -Governs `CloseTo::Members`, the members' equity statement, and the K-1 worksheet's capital accounts on the tax basis (rules.md B-13; `ledger_core::tax_capital`, rules.md B-36). Partners' shares come from the partnership agreement (IRC §704(a)); a partner's capital account is one running balance of what they contributed, their allocations of income and loss, and what was distributed to them (Treas. Reg. §1.704-1(b)(2)(iv)(b)); when a partner's interest changes during the year, the distributive shares take the varying interests into account, period by period (IRC §706(d)(1), Treas. Reg. §1.706-4(a)); Form 1065 reports each partner's capital account on the tax basis (Schedule K-1 item L) and the changes in them (Schedule M-2). No authority prescribes how to round a share to the cent: that rule is the owner's decision (largest remainder, 2026-10-13), counted from the company's first close (D-10, 2026-10-16). +Governs `CloseTo::Members`, the members' equity statement, and the K-1 worksheet's capital accounts on the tax basis (BS-partner-1; `ledger_core::tax_capital`, BS-partner-4). Partners' shares come from the partnership agreement (IRC §704(a)); a partner's capital account is one running balance of what they contributed, their allocations of income and loss, and what was distributed to them (Treas. Reg. §1.704-1(b)(2)(iv)(b)); when a partner's interest changes during the year, the distributive shares take the varying interests into account, period by period (IRC §706(d)(1), Treas. Reg. §1.706-4(a)); Form 1065 reports each partner's capital account on the tax basis (Schedule K-1 item L) and the changes in them (Schedule M-2). No authority prescribes how to round a share to the cent: that rule is the owner's decision (largest remainder, 2026-10-13), counted from the company's first close (D-10, 2026-10-16). ## 26 U.S.C. §704(a)-(b) Source: @@ -64,7 +64,7 @@ SHA-256 of the retrieved file (`i1065sk1.html`): `d7d6298286601fd95ab8e445c10fd6 own hash: `irs-capital-accounts.md` quotes another retrieval of the same day. A re-fetch on 2026-10-21 hashed differently again; the quoted text was checked present.) -**Item L, its first paragraph** (the partner's capital account, on the tax basis; the K-1 worksheet carries the book capital account and, beside it, the tax-basis one as far as the books know it, rules.md B-36) +**Item L, its first paragraph** (the partner's capital account, on the tax basis; the K-1 worksheet carries the book capital account and, beside it, the tax-basis one as far as the books know it, BS-partner-4) > The partnership must report your beginning capital account and ending capital account for the year using the tax-basis method, including the amount of capital you contributed to the partnership during the year, your share of the partnership’s current-year net income or loss as computed for tax purposes, any withdrawals and distributions made to you by the partnership, and any other increases or decreases to your capital account determined in a manner generally consistent with figuring the partner’s adjusted tax basis in its partnership interest (without regard to partnership liabilities), taking into account the rules and principles of sections 705, 722, 733, and 742. See the Instructions for Form 1065 for more details. diff --git a/docs/spec/sources/iso-4217.md b/docs/spec/sources/iso-4217.md index c44f54ee..7e59f339 100644 --- a/docs/spec/sources/iso-4217.md +++ b/docs/spec/sources/iso-4217.md @@ -1,7 +1,7 @@ # ISO 4217: currency minor units Governs `Currency::minor_units`, which sets the smallest unit a ledger -books in (rules.md B-3): foreign-currency lines are rounded to it. +books in (BS-ledger-1): foreign-currency lines are rounded to it. Source: ISO 4217 "list one" (current currency & funds), published 2026-09-17 by SIX Financial Information, the ISO 4217 maintenance agency. diff --git a/docs/spec/sources/unicode-tin-text.md b/docs/spec/sources/unicode-tin-text.md index ce554760..6422a681 100644 --- a/docs/spec/sources/unicode-tin-text.md +++ b/docs/spec/sources/unicode-tin-text.md @@ -1,6 +1,6 @@ # Unicode character properties: how a TIN can be written -Governs `ledger_core::parties::has_full_tin` (rules.md B-26): which +Governs `ledger_core::parties::has_full_tin` (BS-partner-2): which characters separate a TIN's digits, and which are invisible between them. The Unicode Character Database is © Unicode, Inc., under the Unicode License v3, which permits copying the data files; the code point lists @@ -53,7 +53,7 @@ form is one of the ASCII separators. - `'/'`: U+FF0F FULLWIDTH SOLIDUS. - `'_'`: U+FE33, U+FE34, U+FE4D..U+FE4F, U+FF3F FULLWIDTH LOW LINE. -## How the books read them (rules.md B-26) +## How the books read them (BS-partner-2) A TIN is nine numerals (any script's: `char::is_numeric`) with at most three separators between neighbors. In ASCII the separators are exactly diff --git a/docs/testing.md b/docs/testing.md index f2c50fde..c7b17213 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -59,21 +59,21 @@ that would fail if it broke: | Law | Test | |---|---| -| Books from a newer wanderbooks are "newer", never "corrupt", from the writer, the viewer and the server; damage stays corruption (rules.md B-27) | `ledger-store` `tests/format.rs` (`old_reader_gets_newer_journal`, `damaged_journals_are_still_corrupt`); `ledger-gui` `tests/newer_journal.rs`; `ledger-cli` `tests/startup.rs` | +| Books from a newer wanderbooks are "newer", never "corrupt", from the writer, the viewer and the server; damage stays corruption (BS-format-1) | `ledger-store` `tests/format.rs` (`old_reader_gets_newer_journal`, `damaged_journals_are_still_corrupt`); `ledger-gui` `tests/newer_journal.rs`; `ledger-cli` `tests/startup.rs` | | A line the gate refuses is called newer only once the next line's `prev` checks its hash; a last line is "newer or damaged" | `a_damaged_line_that_looks_newer_is_corrupt_when_the_next_line_checks_it`, `an_unreadable_last_line_is_reported_as_newer_or_damaged`, `a_newer_line_the_next_line_chains_onto_is_newer_and_intact` (the message vouches for that line only) | | The envelope and its hash are frozen across formats: a next line in a newer format (a float, a string seq, keys of its own) settles by its `prev` alone, never as corrupt; a key beside the envelope is newer, never dropped, and still checked through; a refused line followed by an unreadable one is "newer or damaged" | `format.rs` `a_newer_format_frames_its_lines_its_own_way`, `an_unknown_envelope_key_is_newer_and_checked_through`, `a_refused_line_followed_by_a_garbled_line_is_unverified` | | The writer and the viewer read bytes alike: a line that isn't UTF-8 is corrupt to both; an older version never repairs (truncates) newer books | `a_line_that_is_not_utf8_is_corrupt_for_the_viewer_and_the_writer`, `an_old_reader_never_repairs_newer_books` | | A newer format is newer whatever its features look like; a blank line is damage to the viewer as to the writer | `format.rs` `a_newer_format_is_newer_whatever_its_features_look_like`; `a_blank_line_is_corrupt_for_the_viewer_and_the_writer` | | A request that panics stops the server: every later request, on every session, is refused | `server.rs` `a_request_that_panics_stops_the_server` | -| No input reaches a panic (each would stop the server for every session): every tool with arguments generated from its schema and made hostile (wrong types, u64::MAX, decimals of 30+ digits or absurd exponents, dates like 0000-00-00, 99999-12-31, +262142-12-31, 2026-02-30, periods like 999999-01, control and format characters, long strings), every resource URI generated; the inputs that once panicked, pinned; after each property the server restarts and the books reopen (a call a command accepts but replay refuses would brick them); every tool and resource over every old book (rules.md B-28) | `ledger-cli` `tests/hostile_args.rs` `hostile_tool_arguments_never_stop_the_server` (with a floor: most calls reach a tool, some succeed), `hostile_resource_uris_never_stop_the_server`, `inputs_that_once_panicked_are_refused_or_answered`, `old_books_answer_every_tool`; `MCP_CASES` and `OLD_BOOKS_CASES` (default 3 per tool per book) set the cases | -| Dates are in 0001-01-01 through 9999-12-31 and amounts at most a line's, for every new command; replay accepts every line an earlier version accepted (each bound has its pair: the command refuses past it, the replayed old line is accepted); a figure derived past exact arithmetic or chrono's calendar is refused, never a panic; a recurring run makes at most 1,000 drafts (rules.md B-28) | `ledger-core` `tests/spec_bounds.rs`, `calendar.rs` tests, `plans_at_the_edges_are_computed_or_refused`, `intervals_reach_chronos_last_day`, `a_vendor_part_is_scaled_exactly_or_refused`, the `share_property` cases; `ledger-store` `tests/bounds.rs`, `tests/store.rs` (the old-books tests); `server.rs` `periods_are_a_year_and_a_month`, `dates_are_four_digit_years_and_real_days` | -| Opening the books changes nothing until every complete line passes in memory (chain, gate, first line, replay); the viewer applies the writer's first-line rule (rules.md B-27) | `format.rs` `a_bad_complete_line_before_a_torn_tail_leaves_the_journal_as_it_was`, `the_first_line_is_store_created_for_the_viewer_and_the_writer`; `fuzz_store_replay` (the first line varies) | +| No input reaches a panic (each would stop the server for every session): every tool with arguments generated from its schema and made hostile (wrong types, u64::MAX, decimals of 30+ digits or absurd exponents, dates like 0000-00-00, 99999-12-31, +262142-12-31, 2026-02-30, periods like 999999-01, control and format characters, long strings), every resource URI generated; the inputs that once panicked, pinned; after each property the server restarts and the books reopen (a call a command accepts but replay refuses would brick them); every tool and resource over every old book (BS-entry-4) | `ledger-cli` `tests/hostile_args.rs` `hostile_tool_arguments_never_stop_the_server` (with a floor: most calls reach a tool, some succeed), `hostile_resource_uris_never_stop_the_server`, `inputs_that_once_panicked_are_refused_or_answered`, `old_books_answer_every_tool`; `MCP_CASES` and `OLD_BOOKS_CASES` (default 3 per tool per book) set the cases | +| Dates are in 0001-01-01 through 9999-12-31 and amounts at most a line's, for every new command; replay accepts every line an earlier version accepted (each bound has its pair: the command refuses past it, the replayed old line is accepted); a figure derived past exact arithmetic or chrono's calendar is refused, never a panic; a recurring run makes at most 1,000 drafts (BS-entry-4) | `ledger-core` `tests/spec_bounds.rs`, `calendar.rs` tests, `plans_at_the_edges_are_computed_or_refused`, `intervals_reach_chronos_last_day`, `a_vendor_part_is_scaled_exactly_or_refused`, the `share_property` cases; `ledger-store` `tests/bounds.rs`, `tests/store.rs` (the old-books tests); `server.rs` `periods_are_a_year_and_a_month`, `dates_are_four_digit_years_and_real_days` | +| Opening the books changes nothing until every complete line passes in memory (chain, gate, first line, replay); the viewer applies the writer's first-line rule (BS-format-1) | `format.rs` `a_bad_complete_line_before_a_torn_tail_leaves_the_journal_as_it_was`, `the_first_line_is_store_created_for_the_viewer_and_the_writer`; `fuzz_store_replay` (the first line varies) | | UTF-16 text without a byte-order mark is scanned like any text; a refused `books.set_w9` marks no file; a refused resource read never echoes a TIN | `tin_files.rs` (tests) `utf16_text_without_a_byte_order_mark_is_scanned_either_way_round`, `a_refused_set_w9_never_marks_its_file`, unit test `only_nul_interleaved_bytes_read_as_utf16_without_a_mark`; `spec_vault.rs` `resource_refusals_never_echo_a_tin` | | idempotentHint only where a repeat with the same arguments leaves the journal and the vault as they were; every tool's hints pinned in one table | `spec_vault.rs` `idempotent_tools_change_nothing_when_repeated`; `annotations_complete` | | books.settings lists every receipt-required and exempt account, uncut; a fresh company is "a new company"; the lint catches `just` however it ends and where the books are | `mcp_journeys.rs` `every_receipt_account_left_out_of_the_connect_text_is_in_books_settings`; `handbook.rs` `a_fresh_company_is_a_new_company`; `tool_text_lint_catches_helpers_and_locations` | | A file with full TINs is never written to a path (handed over instead, D-29), and never filed into the books: every file the server read or wrote with TINs (from any session, after a restart, out of a CPA package), by every filing tool | `mcp_journeys.rs` `tin_bearing_files_are_refused_when_given_back_to_be_filed`; `spec_vault.rs` `a_package_is_handed_over_and_never_written`; `tin_files.rs` (tests) `a_tin_bearing_file_is_refused_from_every_session_and_after_a_restart`; unit test `a_recorded_tin_file_is_refused_by_every_reader_of_the_registry` | -| Text filed into the books is refused when it holds a TIN the vault keeps (nine digits, 3-2-4 by hyphen, space or dot, 2-7 by hyphen or space, anywhere) or a stand-alone printed SSN or EIN (123-45-6789, 12-3456789), and only then: a bank export (routing numbers, long references, a date next to an amount) and a longer number holding an SSN shape go in; a locked vault leaves the printed shapes (rules.md B-26) | `tin_files.rs` (tests) `text_with_a_vault_tin_or_a_printed_one_is_refused_and_a_bank_export_is_not`; unit tests `text_holding_a_vault_tin_is_refused_in_every_rendering`, `a_printed_ssn_or_ein_is_refused`, `a_longer_number_holding_a_tin_shape_passes`, `an_ordinary_bank_export_passes`, `binary_bytes_are_not_scanned` | -| Filing is no TIN oracle: text with more than two TIN-shaped numbers ending in a known TIN's last four (the books' TIN and W-9 facts, then the vault's own) is refused before the vault is opened, byte for byte alike whether one is the vault's TIN or none is, the vault open or locked, by every filing tool; one or two such numbers are compared against the vault, one number written many ways counts once, and other last fours never count (rules.md B-26) | `tin_files.rs` (tests) `text_probing_for_a_tin_is_refused_alike_by_every_filing_tool`; unit tests `text_probing_for_a_tin_is_refused_alike_whether_or_not_it_holds_it` (the vault never opened for a probe), `one_or_two_candidates_are_compared_against_the_vault` | +| Text filed into the books is refused when it holds a TIN the vault keeps (nine digits, 3-2-4 by hyphen, space or dot, 2-7 by hyphen or space, anywhere) or a stand-alone printed SSN or EIN (123-45-6789, 12-3456789), and only then: a bank export (routing numbers, long references, a date next to an amount) and a longer number holding an SSN shape go in; a locked vault leaves the printed shapes (BS-partner-2) | `tin_files.rs` (tests) `text_with_a_vault_tin_or_a_printed_one_is_refused_and_a_bank_export_is_not`; unit tests `text_holding_a_vault_tin_is_refused_in_every_rendering`, `a_printed_ssn_or_ein_is_refused`, `a_longer_number_holding_a_tin_shape_passes`, `an_ordinary_bank_export_passes`, `binary_bytes_are_not_scanned` | +| Filing is no TIN oracle: text with more than two TIN-shaped numbers ending in a known TIN's last four (the books' TIN and W-9 facts, then the vault's own) is refused before the vault is opened, byte for byte alike whether one is the vault's TIN or none is, the vault open or locked, by every filing tool; one or two such numbers are compared against the vault, one number written many ways counts once, and other last fours never count (BS-partner-2) | `tin_files.rs` (tests) `text_probing_for_a_tin_is_refused_alike_by_every_filing_tool`; unit tests `text_probing_for_a_tin_is_refused_alike_whether_or_not_it_holds_it` (the vault never opened for a probe), `one_or_two_candidates_are_compared_against_the_vault` | | The connect text fits its budgets, its lead stands alone, it states the receipt rule enforced (exact threshold in the base currency, required and exempt accounts, reversals) and the parties rule in force, and the company name can't break it (control and format characters) | `handbook.rs` `instructions_budget`, `a_typical_company_gets_the_whole_connect_text`, `the_company_name_is_one_plain_line`; `receipt_policy.rs` `the_rule_told_is_the_rule_enforced`, `a_long_or_odd_account_list_stays_short_and_plain`; a new session is told the settings in force: `a_new_session_is_told_the_settings_in_force` | | No text the agent is given (whole tool JSON, resources, connect text, handbook, every error template and refusal) points at files, git, GitHub, repo docs, flags or helper commands; descriptions fit 700 characters (listed exceptions, P5; and what git itself said of a failed backup, which `books.backup` passes on to the human as git said it, its paths hidden) | `tool_text_lint`, `tool_descriptions_fit_700_characters`; `ledger-core` `an_unknown_year_threshold_is_never_guessed` | | Every tool is annotated (openWorldHint false on all but `books.back_up_now`), and the read-only hint is true in behaviour (journal, every file of the books' folder but what every call writes by design: the access log, `ops/` (the viewer's side channel for `books.show`, which is not the books), the books' own backup and the files handed over; the database's rows and the vault unchanged) | `annotations_complete`; `spec_mcp.rs` `read_only_tools_change_nothing` (checked on every call in `Mcp::tool`) | @@ -96,7 +96,7 @@ viewer against its lib tests and `newer_journal`). Final run: | `ledger-core` | 1 | 1 | 0 | 0 | 0 | (`ledger-cli`'s change makes no mutant.) After the filing scan's probe -bound (rules.md B-26), `tin_files.rs` alone was run again against the +bound (BS-partner-2), `tin_files.rs` alone was run again against the whole P0 diff: 74 mutants, 74 caught, among them every mutant of the bound (`probes` made true or false, `>` made `>=`, `==` or `<`, the last four's `%` made `/` or `+`, here and for the vault's own last @@ -628,7 +628,7 @@ are kept with the run's output, outside the repository. ## P3: odd cents (2026-10-20) -Defect 17 (rules.md B-13; D-10, D-38), built without its mutation run +Defect 17 (BS-partner-1; D-10, D-38), built without its mutation run (D-33); what P12 must cover is listed at the end. Every expected figure is worked by hand in the test's comment. @@ -737,7 +737,7 @@ pass. ## P3: the IIF and as-of (2026-10-20) Defects 7 and 21 (plan P3; the owner's decisions D-36). Rules -`docs/spec/rules.md` B-33 (a package as of a day) and B-34 (the IIF). No +BS-statement-4 (a package as of a day) and BS-format-2 (the IIF). No mutation run (D-33): what P12 must cover is at the end. **Named regression tests**, each from its reproduction, on anonymized @@ -877,7 +877,7 @@ each name; with `SHOT_DIR` set, it saves `scripts.png`: looked at, and Hebrew, but doesn't reorder the words of a right-to-left phrase: "مكتب الرياض" shows its two words left to right. -**TINs in any script (B-26).** `ledger_core::parties::has_full_tin` +**TINs in any script (BS-partner-2).** `ledger_core::parties::has_full_tin` missed "123-45-6789": the fullwidth hyphen-minus, the ideographic and thin spaces, the Hebrew maqaf and the other Unicode dashes weren't separators, and a zero-width space or a right-to-left mark between digits @@ -942,8 +942,7 @@ doesn't count them. ## P3: cash flow (defect 1, 2026-10-20) -The statement of cash flows was rebuilt by the direct method (rules.md -B-14, D-35), and what a member or a lender pays for the company shown as +The statement of cash flows was rebuilt by the direct method (BS-statement-3, D-35), and what a member or a lender pays for the company shown as cash borrowed and spent (D-42, rule 11). Built, reviewed twice, `just check` and `just prove`; no mutation run (D-33): what P12 must cover is at the end. @@ -1089,7 +1088,7 @@ in `take` where both bounds coincide, and the kind order's tie-breaks. ## P3: rename, defaults and tax categories (2026-10-20) -Defects 15, 16 and 8 (`plan/served.md` P3; rules.md B-30, B-31, B-32). +Defects 15, 16 and 8 (`plan/served.md` P3; BS-period-3, BS-ledger-10, BS-ledger-11). Every fixture is fictional (Fernhill Labs LLC, its members and vendors); no mutation run (D-33): the targets are listed for P12 below. @@ -1132,7 +1131,7 @@ no mutation run (D-33): the targets are listed for P12 below. (every figure, entry and earlier journal line, every projection row but `accounts.name`; refusals append nothing; reopen, rebuild and viewer), `a_journaled_rename_replays_past_the_command_rules` and - `a_journaled_clear_replays_under_refuse` (B-28's pairs, review R5), + `a_journaled_clear_replays_under_refuse` (BS-entry-4's pairs, review R5), `the_tax_category_policy_refuses_only_what_it_says`, `books_written_under_p3_keep_their_names` (fixture `old-books/p3_rename`, written once by `write_p3_rename_fixture`, `--ignored`; its figures are @@ -1220,7 +1219,7 @@ cash flow statement: fiscal year. - `ledger-core` `tests/bookspec/`: the three examples are in the loader's one shape, and the loader gained what they need (bookspec - `README.md`): `setup.today` and omitted dates resolved by B-30, + `README.md`): `setup.today` and omitted dates resolved by BS-period-3, `header` and `tax_category` on an account, a `bill` event, `[[changes]]` (a rename, the policy) made after an event's expectations, the queries `period`, `day`, `calendar_year`, `account_names` and @@ -1240,7 +1239,7 @@ cash flow statement: `iif_writes_plain_ascii_and_lists_every_change`, `iif_warnings_never_hold_a_tin`) make their siblings of one name, names with a tab and names holding a TIN by replay (`replay_add_account`), as - books written before P3 hold them: B-31 refuses them in a new name, and + books written before P3 hold them: BS-ledger-10 refuses them in a new name, and the file must still keep them apart, write them on one line and mask them. - `books.cash_flow`'s description is the direct method's, shortened to @@ -1281,26 +1280,26 @@ A party's part of an entry is signed as a line on its own account, with a direction and its money and property; party totals take a basis; money is cash, cards and the financing accounts; a credit to a liability a party is owed itself never pays it; the directory's TIN last four comes from TIN or -W-9 facts (rules.md B-35, B-26). Built, reviewed and checked under D-33: +W-9 facts (BS-partner-3, BS-partner-2). Built, reviewed and checked under D-33: no mutation run here; what P12 must cover is at the end. | What | Where | Oracle | |---|---|---| -| 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` | B-35, by hand | +| 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` | B-9 | -| Accruals through another liability count once (defect 24) | `defect24_an_accrual_through_another_liability_counts_once` | B-35 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` | B-35 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) | B-35 items 3, 5; B-26 | +| 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 | | 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 | -| Properties: a reversal's target, parts and flow are the original's negated; parts sum to the target, each with its sign; a sole party's money part is the flow as before P3; tin_last4 is every source present | `a_reversal_is_the_exact_opposite`, `a_sole_partys_money_part_is_the_flow_as_before`, `tin_last4_is_every_source_present` (`PROPTEST_CASES`, default 256; 5,000 run clean) | B-35, B-9 | +| Properties: a reversal's target, parts and flow are the original's negated; parts sum to the target, each with its sign; a sole party's money part is the flow as before P3; tin_last4 is every source present | `a_reversal_is_the_exact_opposite`, `a_sole_partys_money_part_is_the_flow_as_before`, `tin_last4_is_every_source_present` (`PROPTEST_CASES`, default 256; 5,000 run clean) | BS-partner-3, BS-ledger-5 | | Decimal and i64 agree on party_target and reverse_target | `kernel_bridge/` `party_target_agrees` | the bridge | | Kani: the direction is the sign, the target is odd, reverse_target an involution | `proofs/` `party_target_direction_is_its_sign`, `party_target_is_odd`, `reverse_target_is_an_involution` | the kernel spec | | The journal: party.creditor_set one line each, under the feature the books declared when created; in books an older version wrote, refused (FormatUpgradePending, nothing journaled) until the format upgrade; refusals journal nothing; books without creditors never change, in either format; corrupt lines refused | `ledger-store/tests/party_creditors.rs` | the format gate | | Over the MCP: get_entry's direction, cash, in_kind; party totals by basis, echoed, others refused; basis all equals members' equity; creditor_of round trips and a card fee isn't a payment; the post_entry preview's parts are what it posts | `ledger-cli/tests/spec_party_totals.rs` | the tool docs | -| Defect 11 over the MCP: a member's TIN last four in the directory, a W-9's, none, after a purge | `ledger-cli/tests/spec_vault.rs` `defect11_the_directory_shows_a_members_tin_last4` | B-26 | +| Defect 11 over the MCP: a member's TIN last four in the directory, a W-9's, none, after a purge | `ledger-cli/tests/spec_vault.rs` `defect11_the_directory_shows_a_members_tin_last4` | BS-partner-2 | | The viewer shows the tools' numbers, labelled cash basis, with the in-kind line; its what-for reads a reversal as `parties::flow` does | `ledger-gui/tests/parties.rs` `the_party_page_shows_the_basis_and_in_kind`, `a_reversed_member_card_payment_is_nothing_on_the_issuers_page` | `activity_with`, `flow` | | bookspec | `bookspec/examples/p3-party-*.toml` | the same cases, by hand | @@ -1330,10 +1329,10 @@ never disagree, parties INVARIANT 2a, enforced on replay). The 1099 decision kept as a decision (nec, misc, not_reportable with its reason kind and words, undetermined), with who decided and the date it takes effect (D-40); payment methods and the tag on each payment; one -report for the server, the package and the viewer (rules.md B-19). No +report for the server, the package and the viewer (BS-1099-1). No mutation run (D-33); the list P12 must cover is at the end. -| Law (rules.md B-19) | Tests | +| Law (BS-1099-1) | Tests | |---|---| | Undecided is not "not reportable" (defect 18) | `undecided_is_not_not_reportable` | | "No 1099" is a decision with who and when; "none" refused (defect 23) | `a_vendor_marked_no_1099_is_not_undecided`, `the_cutovers_reasons_are_recorded_as_given`, `set_vendor_1099_says_what_a_decision_needs` (`ledger-cli` `spec_1099.rs`) | @@ -1393,11 +1392,11 @@ 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` | B-35 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) | B-35 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` | B-35 item 9; 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` | B-33; 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` | B-27 | +| 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) | +| 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 | **For P12 (mutation targets, none run, D-33):** `parties::card_accounts` @@ -1411,8 +1410,7 @@ method setup. ## P3: depreciation and schedules (defects 22 and 9, 2026-10-20) -Every expected figure below was worked by hand from the rule (rules.md -B-15, B-16) and is written out in the test's doc comment; the fixtures are +Every expected figure below was worked by hand from the rule (BS-asset-1, BS-prepaid-1) and is written out in the test's doc comment; the fixtures are made up (asset X: 12,000.00 over 12 months from 2026-01-01; a 1,200.00 policy from March 15). Each regression that is an accounting rule is also a bookspec example (`bookspec/examples/`, P13, D-34). @@ -1448,7 +1446,7 @@ a bookspec example (`bookspec/examples/`, P13, D-34). | Every order of runs, reversals (any day, before an entry's own included), re-runs, re-instatements, disposals and closes on one asset keeps the books right: refusals journal nothing; at every month end before the disposal the expense is the accumulated depreciation and within the schedule; one run in effect per month; a disposal's month and the end at the schedule through its day, accumulated 0.00, the gain proceeds less book value; an active asset run month by month past its life takes exactly cost less salvage (P3 review round 2) | store `asset_orders.rs` `every_order_of_runs_reversals_disposals_and_closes_keeps_the_books_right` (exhaustive, three commands deep; four and five with `WB_ORDERS_DEPTH`, run clean 2026-10-21), `prop_any_sequence_keeps_the_books_right` (64 cases, up to 9 commands, any day) | | The viewer reads an asset as the store does, whatever the runs, reversals and disposals: what the books carry, each finished month's status against a run of it, what is unposted (P3 review round 2) | GUI `prop_the_viewer_reads_an_asset_as_the_store_does` (48 cases), `the_viewer_counts_a_run_reinstated_after_its_rerun_was_reversed` | | A run re-instated after its month was run again and that run reversed still counts: in the store, the disposal and the viewer (P3 review round 2; before, the projection's row named the reversed re-run) | store `a_run_reinstated_after_its_rerun_was_reversed_still_counts`; GUI `the_viewer_counts_a_run_reinstated_after_its_rerun_was_reversed` | -| Every reversal is dated on or after its original, any kind of entry (D-73); a journal holding an earlier-dated one still opens with the same figures (B-28): store `reversal_dates.rs` `a_plain_entrys_reversal_is_not_dated_before_it`, `a_journal_with_an_earlier_dated_reversal_opens_as_it_was` | +| Every reversal is dated on or after its original, any kind of entry (D-73); a journal holding an earlier-dated one still opens with the same figures (BS-entry-4): store `reversal_dates.rs` `a_plain_entrys_reversal_is_not_dated_before_it`, `a_journal_with_an_earlier_dated_reversal_opens_as_it_was` | | A depreciation run's or schedule month's reversal can't be dated before the entry it reverses (P3 review round 2: a run of March reversed on Jan 31, then a disposal on Feb 15, ended February with a 1,000.00 debit in accumulated depreciation) | store `a_reversal_dated_before_the_entry_it_reverses_is_refused` | | A disposal waits only until what the runs carry at its month's end is what they carry now, so a late change undone after its month closed lets it through (P3 review round 2; round 1 refused it for ever) | store `a_disposal_is_taken_once_a_late_change_is_undone_after_its_month_closed` | | Depreciation still due when the disposal's month has a run is charged in the disposal entry, never as a second run of the month (P3 review round 2; no store test held it) | store `a_disposal_whose_month_has_run_charges_what_is_still_due_in_its_entry` | @@ -1496,7 +1494,7 @@ none (`r >= step - r` against `>` is killed by `half_a_unit_rounds_up`). D-39 and plan/served.md 3.9 (`format_upgrade_pending`): books an older wanderbooks wrote wait for the owner's go-ahead before they move to this -version's journal format (rules.md B-27). Mutation testing waits for P12 +version's journal format (BS-format-1). Mutation testing waits for P12 (D-33); the targets are listed at the end. - `ledger-store` `format.rs` unit tests: this version's format is the @@ -1629,7 +1627,7 @@ basis. Mutation runs wait for P12 (D-33); none was run. note; the gain property's disposal flagged with its built-in gain), property subject to a liability (negative tax property), and three members with unequal shares, one contributing nothing; and, from the - owner's ask of 2026-10-22 (B-36 with D-38), three odd-cent devices + owner's ask of 2026-10-22 (BS-partner-4 with D-38), three odd-cent devices contributed 50/50 whose built-in loss runs cumulatively, a cent apart for the year and from June on a beginning carried from January (`tied_odd_cents_of_property_basis_run_cumulatively`; it fails with @@ -1745,13 +1743,13 @@ rules.md says why not. Mutation runs wait for P12 (D-33). - **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, B-35 items 4 and 8), + advances and distributions, BS-partner-3 items 4 and 8), `a_distribution_declared_then_paid_is_financing_when_paid`, - `the_1099_worksheet_ties_to_party_totals_and_the_ledger` (B-35 item 9, - B-19), `depreciation_is_one_figure_everywhere` (the P&L, the cash flow + `the_1099_worksheet_ties_to_party_totals_and_the_ledger` (BS-partner-3 item 9, + 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`, - `the_cpa_package_as_of_each_date_is_the_tools_figures` (B-33). + `the_cpa_package_as_of_each_date_is_the_tools_figures` (BS-statement-4). - **Viewer** (`ledger-gui/tests/p3_seams.rs`): its capital statements, party money, cash flow, register and 1099 worksheet, read from the books' folder and settings file as it opens them, are the engine's. @@ -1761,14 +1759,14 @@ rules.md says why not. Mutation runs wait for P12 (D-33). `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 - (B-14 rule 2; `a_distribution_declared_then_paid_is_a_distribution_paid` + (BS-statement-3 rule 2; `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 (B-14 rule 8; + loss, not its depreciation (BS-statement-3 rule 8; `a_disposals_depreciation_credit_back_is_depreciation`), and the - tax-basis K-1's book depreciation left it out (B-36); `books.list_assets` - as of a day said "disposed" for a later disposal (B-15 rule 8). + 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). ## P3: the surface review (2026-10-21) @@ -1838,7 +1836,7 @@ The earlier P3 sections' lists stand (one name corrected: The owner's ask: "a Projects page that treats a class as a project ... Projects are entities too", a company rule to link things to projects (the convention `link-to-projects`), and the sidebar's links drawn under -the status box in a short window (rules.md B-37). Mutation runs wait for +the status box in a short window (BS-statement-5). Mutation runs wait for P12 (D-33); none was run. - **ledger-core:** `tests/spec_projects.rs` @@ -1977,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 (rules.md B-37 item 7: contribution before +black or the red, with charts (BS-statement-5 item 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, @@ -2046,7 +2044,7 @@ fail. `the_running_net_is_each_months_net_to_date` (sweeping the pointer over the bars and over the net's own strip shows each month's `months_net_to_date`, in order), - `the_fiscal_year_switch_shows_the_default_period` (B-30's omitted dates, + `the_fiscal_year_switch_shows_the_default_period` (BS-period-3's omitted dates, as `books.project`, with fiscal-year costs unlike to date's; the pill stays to date; switching writes nothing to the journal), `a_fiscal_year_with_nothing_says_so`, @@ -2087,11 +2085,11 @@ rounding strategy; `project_figures`' opening net and running sum; ## Invoices and bills take a project (2026-10-22) -rules.md B-37 item 8: each invoice and bill line takes an optional project +BS-statement-5 item 8: 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 -`class_id` behind the new feature `document_line_projects` (B-27). +`class_id` behind the new feature `document_line_projects` (BS-format-1). - **ledger-core:** `tests/spec_document_projects.rs` (`an_invoices_revenue_is_one_line_per_project_and_the_receivable_none`, @@ -2203,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** (rules.md B-34 rule 8): `ledger-import` +**Point 1, the IIF's classes** (BS-format-2 rule 8): `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 @@ -2236,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** (rules.md B-14 rule 5): `ledger-core` +**Point 2, payments to governments** (BS-statement-3 rule 5): `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 @@ -2525,22 +2523,21 @@ accounting question), CHANGE (a source says otherwise; work pending). | 1 | A P&L whose start is after its end is refused | DESIGN | No standard governs a reversed range; refusing beats silently swapping a typo | | 2 | A balance sheet omits zero-balance accounts | CONFIRMED | Reg. S-X 210.4-03(a): "No caption should be shown ... as to which the items and conditions are not present." A comparative statement must still show a zero beside a non-zero prior column | | 3 | The lifetime `profit_and_loss` counts closing entries | CONFIRMED | Used as earnings not yet closed on the balance sheet; closed income is already in capital (OpenStax Principles of Financial Accounting 5.1). Renamed `unclosed_earnings` (2026-10-14) | -| 4 | Closing a period with nothing to close still locks it | CONVENTION | A close is a lock (B-12); a dormant month must still lock and count for close-in-order | +| 4 | Closing a period with nothing to close still locks it | CONVENTION | A close is a lock (BS-period-2); a dormant month must still lock and count for close-in-order | | 5 | Draws and distributions are closed into capital at period end | CONFIRMED | OpenStax 5.1: dividends "are closed to the permanent account"; drawing accounts close to owner's capital. Monthly closes mean the year's K-1 Item L withdrawals sum across months | | 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`); rules.md B-13 | -| 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` (rules.md B-14) | -| 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). rules.md B-14 rule 11, P3 defect 1 | +| 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 | | 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 | -| 12 | Each close into members' capital rounds on its own (ties to the earlier member) | CHANGED 2026-10-13; CHANGED P3 | Twelve monthly 50/50 closes could leave one member several cents ahead. A run of members closes split cumulatively from 2026-10-13 (Lean `runPart_telescopes`; property `each_member_stays_within_a_cent_of_their_share` fails on the per-close rule), but any other close restarted the run. Since P3 a count of members closes runs from the company's first close (D-10), skipping closes to anything else and ignoring the members' order, so no member is ever a cent from their share (`the_audit_odd_cent_never_piles_up_across_closes` fails on the run rule; Kani `cumulative_close_never_drifts_a_unit_at_*`, Lean `allocW_cumulative_drift`); journaled `"cumulative_since"`, older closes replay as booked (rules.md B-13) | +| 12 | Each close into members' capital rounds on its own (ties to the earlier member) | CHANGED 2026-10-13; CHANGED P3 | Twelve monthly 50/50 closes could leave one member several cents ahead. A run of members closes split cumulatively from 2026-10-13 (Lean `runPart_telescopes`; property `each_member_stays_within_a_cent_of_their_share` fails on the per-close rule), but any other close restarted the run. Since P3 a count of members closes runs from the company's first close (D-10), skipping closes to anything else and ignoring the members' order, so no member is ever a cent from their share (`the_audit_odd_cent_never_piles_up_across_closes` fails on the run rule; Kani `cumulative_close_never_drifts_a_unit_at_*`, Lean `allocW_cumulative_drift`); journaled `"cumulative_since"`, older closes replay as booked (BS-partner-1) | Questions are settled from the sources, not by any one company's CPA (wanderbooks is general software). Where the standards leave a real choice, it is a per-company setting with a sourced default, for that -company's accountant to review: the cash flow account roles (rules.md -B-14) are the first. +company's accountant to review: the cash flow account roles (BS-statement-3) are the first. ## Gap list: what isn't covered, and what would bring it in @@ -2559,7 +2556,7 @@ B-14) are the first. ## P4b S1, part A: documents read their figures from standing lines (2026-10-23) -rules.md B-38 (plan P4b, D-45): every line on receivables or payables +BS-arap-2 (plan P4b, D-45): every line on receivables or payables carries its document (`Ledger.line_docs`); what a document owes, was paid and is (Open, Partly paid, Paid, Void) is read from those lines as of a day; hand lines on the control accounts are refused; a reversal is @@ -2581,7 +2578,7 @@ the wiring into verify, the digest and Needs attention) is part B. line for line; Jan 22 unchanged; Jan 31 Fernhill owes 100.00 and Tobin 80.00 again (their payments' reversals); Mar 31 the voided invoice leaves the aging and the reopened ones age at 31-60. -- **ledger-core:** `tests/spec_documents.rs`, one test per B-38 scenario +- **ledger-core:** `tests/spec_documents.rs`, one test per BS-arap-2 scenario (`reversing_a_payment_reopens_the_invoice`, `a_voided_invoice_never_ages`, `void_refused_while_paid`, `aging_as_of_ignores_a_later_reversal`, @@ -2626,7 +2623,7 @@ the wiring into verify, the digest and Needs attention) is part B. `a_void_is_journaled_as_its_reversal`, `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` (B-38 + `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 method and reference, voids, reversals of any entry, closed months and refused hand lines through `Store`; at half time and at the end the @@ -2671,7 +2668,7 @@ check; `control_check`'s chain netting. ## P4b S1, part B: void, control check, and each payment's details (2026-10-24) -The MCP layer of rules.md B-38 (plan P4b S1, part B). Part A (above) is +The MCP layer of BS-arap-2 (plan P4b S1, part B). Part A (above) is the engine: the tags, the derived figures, the guards. Part B puts it on the wire: `books.void_document` reverses a document's own entry with the reason, `books.control_check` ties each control account to its documents, @@ -2727,7 +2724,7 @@ and per document, both loops); the `digest` that includes it and the `books.documents` and `books.document` (`7d2bf0b7`) and the viewer's Money in and Money out lists and a document's page (`b7b7f171`). No format change and no engine rule: both read the figures part A derives -(B-38), and the viewer reads the same ledger directly (I-8). +(BS-arap-2), and the viewer reads the same ledger directly (I-8). The plan calls the timeline's reversed items "struck through"; as built they are labelled: a payment reversed later reads "Payment (reversed @@ -2787,7 +2784,7 @@ An invoice as a PDF: `ledger_import::invoice_pdf::invoice_pdf` typesets books once, so the server's download and the viewer's Save give the same bytes for the same books. `books.document { pdf: true }` hands the file over; a bill's PDF is the vendor's, so it is refused. No format change -and no engine rule: the figures are part A's (B-38) and the template does +and no engine rule: the figures are part A's (BS-arap-2) and the template does no arithmetic. - **`crates/ledger-import/src/invoice_pdf.rs`:** @@ -2833,7 +2830,7 @@ it but asserts only that it succeeds). ## P7: the TIN scanner's separators (2026-10-26) *(Consolidated, with the other units' targets, in "P12: the checklists" at the end of this file.)* -rules.md B-26; plan 8.2 P7, with vault v2 closed by D-48 (nothing of +BS-partner-2; plan 8.2 P7, with vault v2 closed by D-48 (nothing of HPKE, keyslots or human pages is built here). The scanner (`ledger_core::parties::has_full_tin`, `redact_full_tins`) reads the commas, parentheses and any run of spaces that a TIN's groups can be @@ -2843,9 +2840,9 @@ separates only a 3-2-4 or 2-7 group, so an amount's comma-grouped thousands (`1,234,567.89`, 1-3-3-2) stay an amount. The legacy run reading is unchanged for everything it found (the property asserts it never forgets one), and replay still reads a journaled line as P2 did -(`parties::replaying`, B-28). The access log's masking and digest use +(`parties::replaying`, BS-entry-4). The access log's masking and digest use the same function; the filing scan keeps its narrow printed shapes -(B-26: a bank export's routing numbers must go in) and gains the comma +(BS-partner-2: a bank export's routing numbers must go in) and gains the comma renderings. Tests: `tin_shapes_with_any_separator_are_found` @@ -2893,10 +2890,10 @@ adapter claims the rules the catalogue gives an example; a rule with no example is not claimed, never silently passed. Step 3 adds the rule identifiers: `BS--` for the eleven areas, -`bookspec/spec/rules-index.md` as the table from B-1 to B-45, and each +`bookspec/spec/rules-index.md` as the table from BS-entry-1 to BS-ledger-13, and each stated rule's id under its heading in `docs/spec/rules.md`. `DECISION` there is bookspec's `CHOICE`: the specification names the options, an -engine declares its pick (`Claims::with_choice`). B-39 to B-45 are +engine declares its pick (`Claims::with_choice`). BS-arap-3 to BS-ledger-13 are allocated (`plan/served.md` 8.0.3) and not yet stated; they carry an id and an area and no status. @@ -3277,7 +3274,7 @@ each item's target (`Target::Invoice`) and `books.mark_sent` step args. ## P4b S6: paying on terms (2026-10-27) -rules.md B-42; plan 8.2 P4b S6. One payment settles several documents of +BS-arap-6; plan 8.2 P4b S6. One payment settles several documents of one party, with the early-payment discounts their terms allow, the processor's fee posted gross, a bills-due list, the agings' detail and tie-out, and the aging exports. @@ -3355,15 +3352,15 @@ viewer's `discount_by` and `days_overdue` flags. ## P4b S7: bad debts (write-offs), 2026-10-27 -The write-off (plan 8.2 S7; rules.md B-41): an invoice that will not be +The write-off (plan 8.2 S7; BS-arap-5): an invoice that will not be 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` (B-38 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` (B-41 INVARIANT 3: refused, the + `write_off_refused_on_cash_basis` (BS-arap-5 INVARIANT 3: 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 @@ -3408,14 +3405,14 @@ in the same call. (a write-off of at most what is owed leaves nothing owed below zero over the date-sum). Both theorems are in `Audit.lean`. No kernel function was added, so no Kani harness. -- **bookspec:** `bad-debt-direct-write-off` (B-41, CHOICE: invoice 100, +- **bookspec:** `bad-debt-direct-write-off` (BS-arap-5, CHOICE: invoice 100, two partial write-offs, the balances and the trial balance) and - `arap-hand-control-posting-refused` (B-38: an entry an earlier version + `arap-hand-control-posting-refused` (BS-arap-2: an entry an earlier version wrote on receivables replays, attempts the control guard now refuses, and the books still tie out). The example schema gained the `write_off` event and lets a refused `lines` event say so (an entry posts whole or not at all); the refusal vocabulary gained `untagged_control_line`, - which belongs to B-38. + which belongs to BS-arap-2. **For P12 (mutation targets, none run, D-33):** `Ledger::write_off_steps`' cash-basis comparison (the `eq_ignore_ascii_case`, the early return), its @@ -3434,7 +3431,7 @@ check, and the preview's clone; attention's year comparison and its ## P6: the evidence pipeline (2026-10-27) Extraction, dedup, annotations and company record categories (plan P6; -rules.md B-44). One in-process extractor in `ledger-reader` +BS-ledger-12). One in-process extractor in `ledger-reader` (`crates/ledger-reader/src/lib.rs`): `pdf_text` and `pdf_lines` (promoted from the PDF reader test), `page_count`, `page_png` (promoted from the viewer's private rasterizer), `xlsx_text` (cells as the exact decimal strings the sheet XML diff --git a/docs/verification.md b/docs/verification.md index 1f8bccb7..6050cf87 100644 --- a/docs/verification.md +++ b/docs/verification.md @@ -103,7 +103,7 @@ Each law, and what proves it. Kani harnesses are in `Reachable.accounting_equation_through` (any number of accounts) 9. **Period statements add up**: a year's P&L is the sum of its months'. - Lean `statements_add_up` -10. **The statement of cash flows foots** (rules.md B-14, plan P3 defect +10. **The statement of cash flows foots** (BS-statement-3, plan P3 defect 1): each entry's cash is applied to the sections moving against it, operating, investing, financing, each up to its own movement; what a member or a lender paid or received for the entry, with no cash @@ -196,13 +196,13 @@ sequence of commands, of any length**: model's `record` step touches only the records by definition, so the proof says the model is sound, not the engine; the engine's side is checked by `settings_replay_is_pure`, which snapshots every figure and - entry around each record (rules.md B-29), and for the 1099 records by + entry around each record (BS-ledger-9), and for the 1099 records by `decision_and_method_records_change_no_entry` (ledger-store `tests/form1099.rs`; they change the 1099 worksheet by design, never an entry). Settings that change how the same entries are presented (the fiscal year, cash flow roles, members) are outside this law by design. A rename (`rename_account`, P3, - rules.md B-31) is a record too: the model's chart is `(code, type)` + BS-ledger-10) is a record too: the model's chart is `(code, type)` (`Ledger.lean`), names are not modelled, so a rename is the identity on the model and needs no new `Step` (plan I-13 is met as P1 met it for records). The engine's side is the property @@ -231,7 +231,7 @@ sequence of commands, of any length**: - Lean `net_closings_is_net_income`, `close_credits_net_income` 18. **An allocation's parts sum to the whole, to the unit**, however the other shares were rounded, and only the last share changes; and the - largest-remainder apportionment (`kernel::apportion`, rules.md B-13) + largest-remainder apportionment (`kernel::apportion`, BS-partner-1) succeeds exactly when the rounded-down parts are short of the whole by less than a unit each, then sums to the whole, gives each part nothing or one unit (one part may also take the sub-unit fraction), and never @@ -245,12 +245,12 @@ sequence of commands, of any length**: of cumulative closes is their allocation of everything the run closed (so its rounding is one allocation's, never a sum of them), and each close hands out exactly its net, for any allocation whose parts sum to - the whole (rules.md B-13). Since P3 this is the run rule closes + the whole (BS-partner-1). Since P3 this is the run rule closes journaled `"cumulative"` replay under (`CloseTo::MembersRun`). - Lean `runPart_telescopes`, `closePart_total` · property `each_member_stays_within_a_cent_of_their_share` -The P3 odd cent (defect 17; rules.md B-13; D-10, D-38) adds three laws: +The P3 odd cent (defect 17; BS-partner-1; D-10, D-38) adds three laws: 20. **A cumulative members close hands out exactly its net, and leaves each member's running total one allocation of everything the count closed**, @@ -267,7 +267,7 @@ The P3 odd cent (defect 17; rules.md B-13; D-10, D-38) adds three laws: `allocate_cumulative_agrees_with_the_integer_model` 21. **Bounded drift: no member's running total is ever a minor unit from their exact share.** With shares w_i / W (exact decimals) and every - amount a whole number of minor units (B-3), after every cumulative + amount a whole number of minor units (BS-ledger-1), after every cumulative close |(given_i + part_i)·W − T·w_i| < W, whatever earlier closes gave. The precondition is the code's: `periods::allocate_cumulative` refuses a product Decimal would round, so the remainders it ranks are exact, and @@ -285,7 +285,7 @@ The P3 odd cent (defect 17; rules.md B-13; D-10, D-38) adds three laws: `Apportion.allocW_cumulative_drift` (the two together): any number of members, any amounts - property `members_capital_never_drifts_a_cent_from_their_share` - - the tax-basis K-1's running split (B-36 with D-38, 2026-10-22), + - the tax-basis K-1's running split (BS-partner-4 with D-38, 2026-10-22), whose splits each carry their own weights, so the exact running share is a sum of quotients and Decimal's division can leave it a hair under the cent it is (`tax_capital::RunningSplit` takes it to @@ -319,7 +319,7 @@ The P3 odd cent (defect 17; rules.md B-13; D-10, D-38) adds three laws: the money and property in it each carry the whole's sign and never exceed it; a money target is all cash; a contribution counts all of itself; a distribution counts no more money than it paid and no more - property than it gave, the rest still owed (rules.md B-35). + property than it gave, the rest still owed (BS-partner-3). - Kani `party_target_direction_is_its_sign` · bridge `party_target_agrees` 24. **A reversal is the exact opposite of what it reverses**: the target @@ -330,7 +330,7 @@ The P3 odd cent (defect 17; rules.md B-13; D-10, D-38) adds three laws: engine never reads those off a reversal's lines: its reversal arm takes the original's target), reversing twice gives the original back, and a reversal's movement over any accounts is the original's - negated (B-9). + negated (BS-ledger-5). - Kani `party_target_is_odd`, `reverse_target_is_an_involution` · Lean `partyTarget_odd`, `capitalTarget_odd` (with `cashIsMoney` shown satisfiable), `reverseTarget_involutive`, @@ -340,7 +340,7 @@ The P3 odd cent (defect 17; rules.md B-13; D-10, D-38) adds three laws: ### 1099 payments 25. **A payment to a vendor is split, never lost or counted twice**: - each payment line goes in the bucket rules.md B-19's table names (its + each payment line goes in the bucket BS-1099-1's table names (its 16 cases: with no payment method naming its account, a financing line never counts and a card account's line is always a card's); the buckets are each exactly the credits minus debits of their lines; and @@ -357,8 +357,8 @@ The P3 odd cent (defect 17; rules.md B-13; D-10, D-38) adds three laws: ### Proration by days, catching up, truing up (P3, defects 22 and 9) -Depreciation (rules.md B-15) and daily prepaid and deferred-revenue -schedules (B-16) spread a total over a span of days with one kernel +Depreciation (BS-asset-1) and daily prepaid and deferred-revenue +schedules (BS-prepaid-1) spread a total over a span of days with one kernel function, `kernel::prorate_by_days` (each month's share through `kernel::prorated_through`), in exact integer arithmetic over a common unit, `MONTH_L` = lcm(28, 29, 30, 31) = 377,580 parts of a month, so a day @@ -461,14 +461,14 @@ out, proved equal to `cum` over `W` = months × MONTH_L and over `W` × the last month's days, with the two meeting where the last month starts (`roundUnit_scale`). The one hypothesis is the calendar's: every part but the last ends short of the span (`e < W`), which a walk from any -in-service date keeps (B-15: a first month of at most one, then whole +in-service date keeps (BS-asset-1: a first month of at most one, then whole months); an exhaustive test walks the kernel itself over every 1-to-3-month span of two calendar years, and the bridge and the exact unit tests check the rest. ### An asset's basis figures (P3, defect 13) -The register's tax figures beside book value (rules.md B-25) come from +The register's tax figures beside book value (BS-asset-4) come from one kernel function, `kernel::basis_figures`, for every rule: 31. **Each figure follows from the rule and the facts, and none @@ -484,7 +484,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 (rules.md B-37 item 4) is +The "if repaid" figure of work done on spec (BS-statement-5 item 4) is one kernel function, `kernel::unrecovered_cost`: 32. **Never below zero, the shortfall exactly, and no overflow**: the @@ -506,7 +506,7 @@ tagged with d and dated on or before D, whatever their entries' standing: a reversal's mirror carries the same tag and cancels) plus the legacy untagged lines that still stand. A document never owes less than nothing or more than its total on any day a payment path or a reversal touches -it. Rule: `docs/spec/rules.md` B-38. +it. Rule: BS-arap-2. - Kernel: `kernel::running_bounds(total, deltas)` and `kernel::bounds_kept(total, before, after)` decide, at every date in @@ -537,7 +537,7 @@ it. Rule: `docs/spec/rules.md` B-38. ### Payment terms and document lines (P4b S4.1) -Payment terms (rules.md B-39) give a due date and a discount date by +Payment terms (BS-arap-3) give a due date and a discount date by calendar arithmetic in `arap::Terms`, and the two money figures they touch come from the kernel: @@ -599,13 +599,13 @@ come from the kernel: ### Bad debts (P4b S7) -A write-off (rules.md B-41) is `Ledger::write_off`: a new command, so a new +A write-off (BS-arap-5) is `Ledger::write_off`: a new command, so a new Lean step, and no new kernel function (its two lines are one debit and one credit, and the bounds are the existing date-sum's). 37. **A write-off of at most what is owed leaves nothing owed below zero.** The step posts the document's control line credited (tagged - with it, so it is the same sum B-38 fixed) and the amount of + with it, so it is the same sum BS-arap-2 fixed) and the amount of bad-debt expense debited (untagged, off the control accounts). `through_append` reads the write-off's own two lines through the day separately; `docSum_writeOffLines` gives the control line's −amount; @@ -648,7 +648,7 @@ new command, so a new Lean step, and no kernel function. a period with an open draft can't close, discarded it can, and every balance and id is as it was). -### A tax category's deductible amount (B-32, D-67) +### A tax category's deductible amount (BS-ledger-11, D-67) 39. **A category's deductible amount is its accounts' exact shares added and rounded once**, to the cent, half away from zero: round(Σ bookᵢ × @@ -878,7 +878,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 (rules.md B-14 rule 2). The Lean model's close step lets a + assets (BS-statement-3 rule 2). 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 @@ -893,17 +893,17 @@ balances, so it added no Kani harness and no Lean theorem; nothing here was weakened. What it added is checked by tests and properties (listed in `docs/testing.md`, "P0 guard rails"): the journal format gate (newer is never called corrupt, damage always is; the envelope and its hash are -frozen across formats, rules.md B-27), the server failing closed after a +frozen across formats, BS-format-1), the server failing closed after a panic, the import roots' lockdown (a property over generated paths, and a component walk that refuses a folder swapped for a link; removed with the import roots in P2 slice 5), files with full -TINs kept out of the books (B-26), and the agent text lint. Out of scope +TINs kept out of the books (BS-partner-2), and the agent text lint. Out of scope for proof today: the format gate and the walk are I/O, and bookspec's Lean model stops at the ledger. ### P3: the odd cent (2026-10-20) -The cumulative members close (rules.md B-13) adds a kernel function, +The cumulative members close (BS-partner-1) adds a kernel function, `kernel::apportion_cumulative`, which Kani proves exact and refusal-safe for up to three parts and checks against the integer model of `periods::allocate_cumulative` for bounded drift; Lean proves the drift diff --git a/scripts/rewrite-rule-refs.py b/scripts/rewrite-rule-refs.py new file mode 100644 index 00000000..d0501e65 --- /dev/null +++ b/scripts/rewrite-rule-refs.py @@ -0,0 +1,132 @@ +#!/usr/bin/env python3 +"""Rewrite wanderbooks' retired `B-n` rule references to bookspec ids. + +Unit S-E of plan P14: bookspec (D-68) is now the definitive spec and +every rule's stable identifier is `BS--`. This script rewrites +references in code comments, spec blocks' `SOURCE:` lines, docs and +tests from the old wanderbooks numbering (`docs/spec/rules.md` B-1..B-45) +to that identifier. It is reviewable and repeatable: running it on an +already-rewritten tree changes nothing. + +Map: parsed, not hard-coded, from `docs/spec/rules.md`'s index table +(the `| B-n | BS-- |` rows); that file and `docs/spec/claims/` +are the map and are never rewritten, nor is `plan/` (its history keeps +its wording). + +Patterns treated as rule references (n in 1..45, the mapped range): + 1. `docs/spec/rules.md` B-n, `rules.md` B-n -> `BS--`. The `rules.md` + prefix is dropped: the id names the rule wherever it lives. + Sub-references survive untouched because only the `B-n` token is + replaced: `rules.md` B-14 rule 11 -> `BS-statement-3 rule 11`, + `B-37 item 7` -> `BS-statement-5 item 7`, `B-38 INVARIANT 2` -> + `BS-arap-2 INVARIANT 2`. + 2. Any other bare `B-n` (`(B-19)`, `; B-35.`, `B-14 rule 3:`, + `R-1/B-1`, `B-28's`, `the B-19 table`) -> `BS--`. In this + repo a word-boundary `B-<1..45>` outside the map files is always a + rule citation; that is the judgement this rewrite encodes. + +Patterns skipped (not rule references): + * `WB--`: already a wanderbooks product-rule id. The `B` is + preceded by `W`, so no word boundary matches. + * `B-` glued to a preceding word character, e.g. the asset-tag test + datum `"ÄB-1"`: no word boundary, left alone. + * Numbers outside 1..45 (there is no such rule; e.g. a future + `B-1099`-style string would not be a citation of B-1..B-45 either -- + the full number must be in the map). + * Anything under `plan/`, in `docs/spec/rules.md`, or in + `docs/spec/claims/*.md` (the map itself). + * Program-output string literals are not comments: the few that cited + a rule (evidence-source strings, a tool description, the CPA + package text, a GUI note) were reverted by hand after the run, so + user-visible output and the golden files that record it are + unchanged. The one exception is `DatedRule.catalog` in + `crates/ledger-core/src/rules.rs`, metadata no output prints, + which now holds the bookspec id. + +WB dual-citation (task clause 1): where a sentence clearly concerns a +wanderbooks-only surface (MCP tools, the store, the viewer, the vault) +the product rule is a `WB--` in that B section's claims file. +That judgement is not mechanical, so the script never guesses one; per +the task, the bookspec id alone is correct when unsure. + +Usage: python3 scripts/rewrite-rule-refs.py [--dry-run] [root ...] +Default roots: crates docs AGENTS.md README.md deploy scripts .github +(a file root is rewritten in place; `scripts/rewrite-rule-refs.py` +itself is always skipped so the script's own examples stay literal). +Only text files are touched; binary files are skipped. +""" + +from __future__ import annotations + +import re +import sys +from pathlib import Path + +REPO = Path(__file__).resolve().parent.parent +MAP_FILE = REPO / "docs" / "spec" / "rules.md" +SKIP_FILES = {MAP_FILE, Path(__file__).resolve()} +SKIP_DIRS = {REPO / "plan", REPO / "docs" / "spec" / "claims"} +DEFAULT_ROOTS = ["crates", "docs", "AGENTS.md", "README.md", "deploy", "scripts", ".github"] + + +def load_map() -> dict[int, str]: + """B number -> bookspec id, from docs/spec/rules.md's index table.""" + mapping: dict[int, str] = {} + row = re.compile(r"^\| B-(\d+) \| `(BS-[a-z0-9]+-\d+)` \|", re.M) + for n, bs in row.findall(MAP_FILE.read_text(encoding="utf-8")): + mapping[int(n)] = bs + if sorted(mapping) != list(range(1, 46)): + raise SystemExit(f"map in {MAP_FILE} is not B-1..B-45: {sorted(mapping)}") + return mapping + + +def skipped(path: Path) -> bool: + path = path.resolve() + return path in SKIP_FILES or any(parent in SKIP_DIRS for parent in [path, *path.parents]) + + +def rewrite(text: str, mapping: dict[int, str]) -> str: + """Form 1 (`rules.md` B-n, prefix dropped), then form 2 (bare `B-n`).""" + + def sub(m: re.Match[str]) -> str: + return mapping.get(int(m.group("n"))) or m.group(0) + + text = re.sub(r"`?(?:docs/spec/)?`?rules\.md`?\s+B-(?P\d+)\b", sub, text) + # Wrapped form: the filename ends one comment line, the number opens + # the next (`rules.md\n /// B-14 rule 3`): drop the filename too. + text = re.sub(r"(?:docs/spec/)?`?rules\.md`?[ \t]*\n([ \t]*(?://[/!]?|#)?[ \t]*)\bB-(?P\d+)\b", lambda m: m.group(1) + (mapping.get(int(m.group("n"))) or m.group(0)), text) + return re.sub(r"\bB-(?P\d+)\b", sub, text) + + +def main() -> int: + dry = "--dry-run" in sys.argv + roots = [a for a in sys.argv[1:] if not a.startswith("--")] or DEFAULT_ROOTS + mapping = load_map() + # Count by diffing tokens before/after rather than trusting counters. + token = re.compile(r"\bB-(\d+)\b") + total_refs = total_files = 0 + for root in roots: + base = REPO / root + files = [base] if base.is_file() else sorted(p for p in base.rglob("*") if p.is_file()) + for path in files: + if skipped(path): + continue + try: + before = path.read_text(encoding="utf-8") + except (UnicodeDecodeError, ValueError): + continue # binary + after = rewrite(before, mapping) + if after == before: + continue + refs = sum(1 for n in token.findall(before) if int(n) in mapping) + total_refs += refs + total_files += 1 + print(f"{path.relative_to(REPO)}: {refs}") + if not dry: + path.write_text(after, encoding="utf-8") + print(f"{'would rewrite' if dry else 'rewrote'} {total_refs} references in {total_files} files") + return 0 + + +if __name__ == "__main__": + raise SystemExit(main())