diff --git a/crates/ledger-store/tests/calls.rs b/crates/ledger-store/tests/calls.rs index ee10bc5a..2a8a0701 100644 --- a/crates/ledger-store/tests/calls.rs +++ b/crates/ledger-store/tests/calls.rs @@ -702,3 +702,94 @@ fn a_call_whose_begin_line_the_projection_refuses_still_closes_its_frame() { drop(s); Store::open(tmp.path()).unwrap().verify().unwrap(); } + +/// 8.0.6: books the version before this feature wrote (the fixture +/// `old-books/p15_t1_before`, written by main 7058fbd2 through its Store +/// API, with its expected.json) open as ever and report the same figures: +/// every line of theirs is outside a frame, so every line counts; they +/// take no call until the owner's upgrade (D-89); an upgrade then gives +/// them a books id and leaves every figure where it was. +#[test] +fn books_the_version_before_call_transactions_wrote_open_and_report_the_same_figures() { + let fixture = + Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/old-books/p15_t1_before"); + let tmp = tempfile::tempdir().unwrap(); + for e in std::fs::read_dir(&fixture).unwrap() { + let e = e.unwrap(); + if e.file_name() == "expected.json" { + continue; + } + let to = tmp.path().join(e.file_name()); + if e.file_type().unwrap().is_dir() { + copy_dir(&e.path(), &to); + } else { + std::fs::copy(e.path(), to).unwrap(); + } + } + let expected: Value = + serde_json::from_str(&std::fs::read_to_string(fixture.join("expected.json")).unwrap()) + .unwrap(); + let lines = lines_of(tmp.path()); + assert!(lines.iter().all(|l| !l.line_type.starts_with("call."))); + let mut s = Store::open(tmp.path()).unwrap(); + s.verify().unwrap(); + // Every line counts, and the figures are the old version's. + let standing = ledger_store::calls::standings(&lines).unwrap(); + assert!(standing.iter().all(|s| s.counts())); + assert_eq!( + ledger_store::calls::committed(&lines).unwrap().len(), + lines.len() + ); + let snapshot = + serde_json::to_value(ledger_core::reports::snapshot(s.ledger()).unwrap()).unwrap(); + assert_eq!(snapshot, expected["snapshot"]["Ok"]); + assert_eq!( + serde_json::to_value(s.ledger().invoices()).unwrap(), + expected["invoices"] + ); + assert_eq!( + serde_json::to_value(s.ledger().bills()).unwrap(), + expected["bills"] + ); + // They take no call yet, and say what the owner does. + assert!(!s.takes_calls()); + let refused = s.begin_call(id("key-old-books-1")).unwrap_err(); + assert!( + matches!(refused, StoreError::FormatUpgradePending { .. }), + "{refused:?}" + ); + assert_eq!( + lines_of(tmp.path()).len(), + lines.len(), + "refusing wrote nothing" + ); + // The owner's upgrade: books keep every figure and are given an id. + drop(s); + let mut s = Store::open(tmp.path()).unwrap(); + s.upgrade_format().unwrap().expect("waited for an upgrade"); + assert!(s.takes_calls()); + assert!(s.books_id().is_some()); + let after = serde_json::to_value(ledger_core::reports::snapshot(s.ledger()).unwrap()).unwrap(); + assert_eq!(after, expected["snapshot"]["Ok"]); + s.begin_call(id("key-old-books-2")).unwrap(); + // January is closed in these books: the first framed call is a March one. + let e = s.create_entry(d(2026, 3, 1), "A first framed call").unwrap(); + let bank = s.ledger().chart().find_by_code("1000").unwrap().id; + let capital = s.ledger().chart().find_by_code("3000").unwrap().id; + s.add_line(e, bank, Side::Debit, money(10)).unwrap(); + s.add_line(e, capital, Side::Credit, money(10)).unwrap(); + s.close_call(CallEnd::Done("{}")).unwrap(); + s.verify().unwrap(); +} + +fn copy_dir(from: &Path, to: &Path) { + std::fs::create_dir_all(to).unwrap(); + for e in std::fs::read_dir(from).unwrap() { + let e = e.unwrap(); + if e.file_type().unwrap().is_dir() { + copy_dir(&e.path(), &to.join(e.file_name())); + } else { + std::fs::copy(e.path(), to.join(e.file_name())).unwrap(); + } + } +} diff --git a/crates/ledger-store/tests/fixtures/old-books-writer/Cargo.toml b/crates/ledger-store/tests/fixtures/old-books-writer/Cargo.toml index 9dac2a31..3ef67d38 100644 --- a/crates/ledger-store/tests/fixtures/old-books-writer/Cargo.toml +++ b/crates/ledger-store/tests/fixtures/old-books-writer/Cargo.toml @@ -17,6 +17,12 @@ # cargo run --bin p5_before -- OUT (p5_before: run against b97234ac, the # revision before P5: a revised # convention, two decisions, two open items) +# cargo run --bin p15_t1_before -- OUT (p15_t1_before: run against 7058fbd2, +# the revision before P15 T1: a +# receipted opening, a reversal, an +# invoice with a part payment, a bill, +# an open draft, a closed January; no +# call frames, no request keys) # cargo run --bin expect -- OUT (expected.json beside each journal) # and copy each journal.jsonl, blobs/ and expected.json into old-books/. # x_member_closes was written later, the same way, by main 00226a4c diff --git a/crates/ledger-store/tests/fixtures/old-books-writer/src/bin/p15_t1_before.rs b/crates/ledger-store/tests/fixtures/old-books-writer/src/bin/p15_t1_before.rs new file mode 100644 index 00000000..490cdacd --- /dev/null +++ b/crates/ledger-store/tests/fixtures/old-books-writer/src/bin/p15_t1_before.rs @@ -0,0 +1,115 @@ +//! Writes `p15_t1_before`: books the version before P15 T1 (main +//! 7058fbd2, which has no call transactions: no request keys, no +//! `call.begun` or `call.closed`, no books id) wrote through its Store API: +//! a receipted opening and purchase, a purchase with no receipt, a +//! reversal, an invoice with a part payment, a vendor bill, an open draft, +//! and a closed January. This version opens the same journal, reads it as +//! ever, takes no write until the owner's format upgrade (D-89), and +//! reports the same figures. +use chrono::NaiveDate; +use ledger_core::{AccountType, Currency, DocumentLine, Money, Side}; +use ledger_store::Store; +use rust_decimal::Decimal; +use std::path::PathBuf; + +fn d(y: i32, m: u32, day: u32) -> NaiveDate { + NaiveDate::from_ymd_opt(y, m, day).unwrap() +} +fn cents(c: i64) -> Decimal { + Decimal::new(c, 2) +} +fn usd(c: i64) -> Money { + Money::new(cents(c), Currency::USD) +} + +fn main() { + let root = PathBuf::from(std::env::args().nth(1).unwrap()); + let dir = root.join("p15_t1_before"); + let _ = std::fs::remove_dir_all(&dir); + std::fs::create_dir_all(&dir).unwrap(); + let mut s = Store::create(&dir, Currency::USD).unwrap(); + let bank = s.add_account("1000", "Bank", AccountType::Asset, None, false).unwrap(); + let capital = s.add_account("3000", "Capital", AccountType::Equity, None, false).unwrap(); + let sales = s.add_account("4000", "Sales", AccountType::Revenue, None, false).unwrap(); + let rent = s.add_account("6000", "Rent", AccountType::Expense, None, false).unwrap(); + let software = s.add_account("6100", "Software", AccountType::Expense, None, false).unwrap(); + let post = |s: &mut Store, date: NaiveDate, what: &str, dr: u64, cr: u64, c: i64| { + let e = s.create_entry(date, what).unwrap(); + s.add_line(e, dr, Side::Debit, usd(c)).unwrap(); + s.add_line(e, cr, Side::Credit, usd(c)).unwrap(); + e + }; + let seed = post(&mut s, d(2026, 1, 1), "Opening capital", bank, capital, 100_000); + s.post_entry(seed).unwrap(); + s.attach_receipt(Some(seed), "opening.txt", "text/plain", b"Opening deposit 1000.00 2026-01-01", None) + .unwrap(); + let rent_jan = post(&mut s, d(2026, 1, 5), "January rent", rent, bank, 50_000); + s.post_entry(rent_jan).unwrap(); + s.attach_receipt(Some(rent_jan), "rent.txt", "text/plain", b"Rent January 500.00 2026-01-05", None) + .unwrap(); + // 40.00 is over the 25.00 threshold: no receipt, so an audit finds it. + let paper = post(&mut s, d(2026, 1, 7), "Printer paper", software, bank, 4_000); + s.post_entry(paper).unwrap(); + // Under the threshold: needs none. + let stamps = post(&mut s, d(2026, 1, 8), "Stamps", software, bank, 1_200); + s.post_entry(stamps).unwrap(); + let wrong = post(&mut s, d(2026, 1, 12), "Rent paid twice", rent, bank, 50_000); + s.post_entry(wrong).unwrap(); + s.attach_receipt(Some(wrong), "rent2.txt", "text/plain", b"Rent again 500.00 2026-01-12", None) + .unwrap(); + s.reverse_entry(wrong, d(2026, 1, 14), "Entered twice").unwrap(); + let customer = s.add_customer("Fernhill Labs").unwrap(); + let inv = s + .create_invoice( + customer, + d(2026, 1, 10), + d(2026, 2, 9), + vec![DocumentLine { + description: "Design".into(), + amount: cents(120_000), + class_id: None, + account: None, + quantity: None, + unit_price: None, + }], + ) + .unwrap(); + s.receive_payment(inv, d(2026, 1, 20), cents(40_000), bank).unwrap(); + // An open draft in February; January closes around it. + let vendor = s.add_vendor("Paper Co").unwrap(); + s.create_bill( + vendor, + d(2026, 1, 15), + d(2026, 2, 14), + vec![DocumentLine { + description: "Toner".into(), + amount: cents(8_000), + class_id: None, + account: None, + quantity: None, + unit_price: None, + }], + ) + .unwrap(); + let vendor = s.add_vendor("Paper Co").unwrap(); + s.create_bill( + vendor, + d(2026, 1, 15), + d(2026, 2, 14), + vec![DocumentLine { + description: "Toner".into(), + amount: cents(8_000), + class_id: None, + account: None, + quantity: None, + unit_price: None, + }], + ) + .unwrap(); + let _open = post(&mut s, d(2026, 2, 12), "Coworking day pass", rent, bank, 3_500); + let jan = s.create_period("2026-01", d(2026, 1, 1), d(2026, 1, 31)).unwrap(); + s.close_period(jan).unwrap(); + let _ = sales; + s.verify().unwrap(); + println!("WROTE {:?}", dir); +} diff --git a/crates/ledger-store/tests/fixtures/old-books/p15_t1_before/blobs/0d/46/0d462b0d3e7b13628aa5b6279a6ced262a8670bd5d7063a0668469398ac6523e b/crates/ledger-store/tests/fixtures/old-books/p15_t1_before/blobs/0d/46/0d462b0d3e7b13628aa5b6279a6ced262a8670bd5d7063a0668469398ac6523e new file mode 100644 index 00000000..c0a41246 --- /dev/null +++ b/crates/ledger-store/tests/fixtures/old-books/p15_t1_before/blobs/0d/46/0d462b0d3e7b13628aa5b6279a6ced262a8670bd5d7063a0668469398ac6523e @@ -0,0 +1 @@ +Opening deposit 1000.00 2026-01-01 \ No newline at end of file diff --git a/crates/ledger-store/tests/fixtures/old-books/p15_t1_before/blobs/65/c7/65c730c09a9b8c3ecf4cc2ae55fafe083dc33e2111abe6cafaf6fcb02a7d8ad8 b/crates/ledger-store/tests/fixtures/old-books/p15_t1_before/blobs/65/c7/65c730c09a9b8c3ecf4cc2ae55fafe083dc33e2111abe6cafaf6fcb02a7d8ad8 new file mode 100644 index 00000000..22c35d34 --- /dev/null +++ b/crates/ledger-store/tests/fixtures/old-books/p15_t1_before/blobs/65/c7/65c730c09a9b8c3ecf4cc2ae55fafe083dc33e2111abe6cafaf6fcb02a7d8ad8 @@ -0,0 +1 @@ +Rent again 500.00 2026-01-12 \ No newline at end of file diff --git a/crates/ledger-store/tests/fixtures/old-books/p15_t1_before/blobs/dd/30/dd3075d12716028c7ae1b8f9a10c590f8f4cc26ff4d854e30c9551ef7ad5898f b/crates/ledger-store/tests/fixtures/old-books/p15_t1_before/blobs/dd/30/dd3075d12716028c7ae1b8f9a10c590f8f4cc26ff4d854e30c9551ef7ad5898f new file mode 100644 index 00000000..e77bc398 --- /dev/null +++ b/crates/ledger-store/tests/fixtures/old-books/p15_t1_before/blobs/dd/30/dd3075d12716028c7ae1b8f9a10c590f8f4cc26ff4d854e30c9551ef7ad5898f @@ -0,0 +1 @@ +Rent January 500.00 2026-01-05 \ No newline at end of file diff --git a/crates/ledger-store/tests/fixtures/old-books/p15_t1_before/expected.json b/crates/ledger-store/tests/fixtures/old-books/p15_t1_before/expected.json new file mode 100644 index 00000000..38698c36 --- /dev/null +++ b/crates/ledger-store/tests/fixtures/old-books/p15_t1_before/expected.json @@ -0,0 +1,594 @@ +{ + "assets": [], + "bills": [ + { + "amount_paid": "0", + "date": "2026-01-15", + "due_date": "2026-02-14", + "entry_id": 9, + "id": 1, + "lines": [ + { + "amount": "80.00", + "description": "Toner" + } + ], + "status": "Open", + "vendor_id": 1 + }, + { + "amount_paid": "0", + "date": "2026-01-15", + "due_date": "2026-02-14", + "entry_id": 10, + "id": 2, + "lines": [ + { + "amount": "80.00", + "description": "Toner" + } + ], + "status": "Open", + "vendor_id": 2 + } + ], + "entries": [ + { + "date": "2026-01-01", + "description": "Opening capital", + "id": 1, + "lines": [ + { + "account": 1, + "amount": { + "amount": "1000.00", + "currency": [ + 85, + 83, + 68 + ] + }, + "side": "Debit" + }, + { + "account": 2, + "amount": { + "amount": "1000.00", + "currency": [ + 85, + 83, + 68 + ] + }, + "side": "Credit" + } + ], + "reversal_of": null, + "status": "Posted" + }, + { + "date": "2026-01-05", + "description": "January rent", + "id": 2, + "lines": [ + { + "account": 4, + "amount": { + "amount": "500.00", + "currency": [ + 85, + 83, + 68 + ] + }, + "side": "Debit" + }, + { + "account": 1, + "amount": { + "amount": "500.00", + "currency": [ + 85, + 83, + 68 + ] + }, + "side": "Credit" + } + ], + "reversal_of": null, + "status": "Posted" + }, + { + "date": "2026-01-07", + "description": "Printer paper", + "id": 3, + "lines": [ + { + "account": 5, + "amount": { + "amount": "40.00", + "currency": [ + 85, + 83, + 68 + ] + }, + "side": "Debit" + }, + { + "account": 1, + "amount": { + "amount": "40.00", + "currency": [ + 85, + 83, + 68 + ] + }, + "side": "Credit" + } + ], + "reversal_of": null, + "status": "Posted" + }, + { + "date": "2026-01-08", + "description": "Stamps", + "id": 4, + "lines": [ + { + "account": 5, + "amount": { + "amount": "12.00", + "currency": [ + 85, + 83, + 68 + ] + }, + "side": "Debit" + }, + { + "account": 1, + "amount": { + "amount": "12.00", + "currency": [ + 85, + 83, + 68 + ] + }, + "side": "Credit" + } + ], + "reversal_of": null, + "status": "Posted" + }, + { + "date": "2026-01-12", + "description": "Rent paid twice", + "id": 5, + "lines": [ + { + "account": 4, + "amount": { + "amount": "500.00", + "currency": [ + 85, + 83, + 68 + ] + }, + "side": "Debit" + }, + { + "account": 1, + "amount": { + "amount": "500.00", + "currency": [ + 85, + 83, + 68 + ] + }, + "side": "Credit" + } + ], + "reversal_of": null, + "status": "Posted" + }, + { + "date": "2026-01-14", + "description": "Entered twice", + "id": 6, + "lines": [ + { + "account": 4, + "amount": { + "amount": "500.00", + "currency": [ + 85, + 83, + 68 + ] + }, + "side": "Credit" + }, + { + "account": 1, + "amount": { + "amount": "500.00", + "currency": [ + 85, + 83, + 68 + ] + }, + "side": "Debit" + } + ], + "reversal_of": 5, + "status": "Posted" + }, + { + "date": "2026-01-10", + "description": "Invoice 1", + "id": 7, + "lines": [ + { + "account": 6, + "amount": { + "amount": "1200.00", + "currency": [ + 85, + 83, + 68 + ] + }, + "side": "Debit" + }, + { + "account": 3, + "amount": { + "amount": "1200.00", + "currency": [ + 85, + 83, + 68 + ] + }, + "side": "Credit" + } + ], + "reversal_of": null, + "status": "Posted" + }, + { + "date": "2026-01-20", + "description": "Payment on invoice 1", + "id": 8, + "lines": [ + { + "account": 6, + "amount": { + "amount": "400.00", + "currency": [ + 85, + 83, + 68 + ] + }, + "side": "Credit" + }, + { + "account": 1, + "amount": { + "amount": "400.00", + "currency": [ + 85, + 83, + 68 + ] + }, + "side": "Debit" + } + ], + "reversal_of": null, + "status": "Posted" + }, + { + "date": "2026-01-15", + "description": "Bill 1", + "id": 9, + "lines": [ + { + "account": 7, + "amount": { + "amount": "80.00", + "currency": [ + 85, + 83, + 68 + ] + }, + "side": "Debit" + }, + { + "account": 8, + "amount": { + "amount": "80.00", + "currency": [ + 85, + 83, + 68 + ] + }, + "side": "Credit" + } + ], + "reversal_of": null, + "status": "Posted" + }, + { + "date": "2026-01-15", + "description": "Bill 2", + "id": 10, + "lines": [ + { + "account": 7, + "amount": { + "amount": "80.00", + "currency": [ + 85, + 83, + 68 + ] + }, + "side": "Debit" + }, + { + "account": 8, + "amount": { + "amount": "80.00", + "currency": [ + 85, + 83, + 68 + ] + }, + "side": "Credit" + } + ], + "reversal_of": null, + "status": "Posted" + }, + { + "date": "2026-02-12", + "description": "Coworking day pass", + "id": 11, + "lines": [ + { + "account": 4, + "amount": { + "amount": "35.00", + "currency": [ + 85, + 83, + 68 + ] + }, + "side": "Debit" + }, + { + "account": 1, + "amount": { + "amount": "35.00", + "currency": [ + 85, + 83, + 68 + ] + }, + "side": "Credit" + } + ], + "reversal_of": null, + "status": "Draft" + }, + { + "date": "2026-01-31", + "description": "Close period 2026-01", + "id": 12, + "lines": [ + { + "account": 3, + "amount": { + "amount": "1200.00", + "currency": [ + 85, + 83, + 68 + ] + }, + "side": "Debit" + }, + { + "account": 4, + "amount": { + "amount": "500.00", + "currency": [ + 85, + 83, + 68 + ] + }, + "side": "Credit" + }, + { + "account": 5, + "amount": { + "amount": "52.00", + "currency": [ + 85, + 83, + 68 + ] + }, + "side": "Credit" + }, + { + "account": 7, + "amount": { + "amount": "160.00", + "currency": [ + 85, + 83, + 68 + ] + }, + "side": "Credit" + }, + { + "account": 9, + "amount": { + "amount": "488.00", + "currency": [ + 85, + 83, + 68 + ] + }, + "side": "Credit" + } + ], + "reversal_of": null, + "status": "Posted" + } + ], + "entry_parties": [ + [ + 7, + [ + { + "party_id": 1, + "share": "derived" + } + ] + ], + [ + 8, + [ + { + "party_id": 1, + "share": "derived" + } + ] + ], + [ + 9, + [ + { + "party_id": 2, + "share": "derived" + } + ] + ], + [ + 10, + [ + { + "party_id": 3, + "share": "derived" + } + ] + ] + ], + "invoices": [ + { + "amount_paid": "400.00", + "customer_id": 1, + "date": "2026-01-10", + "due_date": "2026-02-09", + "entry_id": 7, + "id": 1, + "lines": [ + { + "amount": "1200.00", + "description": "Design" + } + ], + "status": "Partial" + } + ], + "payroll_runs": [], + "periods": [ + { + "close_seq": 1, + "closing_entry": 12, + "end": "2026-01-31", + "id": 1, + "member_close": null, + "name": "2026-01", + "start": "2026-01-01", + "status": "Closed" + } + ], + "recurring": [], + "schedules": [], + "snapshot": { + "Ok": { + "balance_sheet": { + "assets": "1648", + "balanced": true, + "current_earnings": "0", + "equity": "1488", + "liabilities": "160" + }, + "profit_and_loss": { + "expenses": "0", + "net_income": "0", + "revenue": "0" + }, + "trial_balance": { + "lines": [ + { + "code": "1000", + "credit": "0", + "debit": "848", + "name": "Bank" + }, + { + "code": "1200", + "credit": "0", + "debit": "800", + "name": "Accounts Receivable" + }, + { + "code": "2000", + "credit": "160", + "debit": "0", + "name": "Accounts Payable" + }, + { + "code": "3000", + "credit": "1000", + "debit": "0", + "name": "Capital" + }, + { + "code": "3999", + "credit": "488", + "debit": "0", + "name": "Retained Earnings" + } + ], + "total_credits": "1648", + "total_debits": "1648" + } + } + }, + "verify": { + "Ok": null + } +} diff --git a/crates/ledger-store/tests/fixtures/old-books/p15_t1_before/journal.jsonl b/crates/ledger-store/tests/fixtures/old-books/p15_t1_before/journal.jsonl new file mode 100644 index 00000000..5f98d1e2 --- /dev/null +++ b/crates/ledger-store/tests/fixtures/old-books/p15_t1_before/journal.jsonl @@ -0,0 +1,66 @@ +{"payload":{"base_currency":"USD"},"prev":"0000000000000000000000000000000000000000000000000000000000000000","seq":1,"ts":"2026-11-21T17:21:17Z","type":"store.created"} +{"payload":{"features":["account_renamed","asset_basis","attachment_text","audits","depreciation_catch_up","disposal_before_service","document_line_projects","document_standing","documents_v2","drafts_v2","members_cumulative","month_reposting","party_creditors","payment_instruments","projects","require_tax_category","schedule_convention","schedule_minor_unit","source_revisions","tax_categories_gain_exempt","vendor_1099_decisions"],"format":2},"prev":"2b84eff6c3870874bd3b147f92a9f4afae201804c4bbe6fcbd898754905aa657","seq":2,"ts":"2026-11-21T17:21:17Z","type":"journal.format_set"} +{"payload":{"account_type":"Asset","code":"1000","currency":"USD","id":1,"name":"Bank","parent":null,"placeholder":false},"prev":"e1ab1c72030a2a0710158fca913aca1f42a3ddf06a864d0e14e6a290d3a2feab","seq":3,"ts":"2026-11-21T17:21:17Z","type":"account.added"} +{"payload":{"account_type":"Equity","code":"3000","currency":"USD","id":2,"name":"Capital","parent":null,"placeholder":false},"prev":"6717f495b84133c3f02280db421be6da564d7a742415f60067b3fc102780cd3c","seq":4,"ts":"2026-11-21T17:21:17Z","type":"account.added"} +{"payload":{"account_type":"Revenue","code":"4000","currency":"USD","id":3,"name":"Sales","parent":null,"placeholder":false},"prev":"ed7d9fe2e9501fb6519aa6bbe42eb7c7682254f4b35b0c3db22e9fd47b4dc638","seq":5,"ts":"2026-11-21T17:21:17Z","type":"account.added"} +{"payload":{"account_type":"Expense","code":"6000","currency":"USD","id":4,"name":"Rent","parent":null,"placeholder":false},"prev":"7642d09215f0a106829fea696429f192970f41bd89f22c820fd7aa8e7078ea31","seq":6,"ts":"2026-11-21T17:21:17Z","type":"account.added"} +{"payload":{"account_type":"Expense","code":"6100","currency":"USD","id":5,"name":"Software","parent":null,"placeholder":false},"prev":"6f5e42a32c90e5fe9aa194404910e0f4352d04e37c8d3fd280940aa623eb1563","seq":7,"ts":"2026-11-21T17:21:17Z","type":"account.added"} +{"payload":{"date":"2026-01-01","description":"Opening capital","id":1},"prev":"1e7f06bdf05c2d3818507adfff1df00b970112b231ea6a8f76b10a85c9e42c8f","seq":8,"ts":"2026-11-21T17:21:17Z","type":"entry.created"} +{"payload":{"account":1,"amount":"1000.00","currency":"USD","id":1,"side":"debit"},"prev":"ba05e967a853e32cb712bf62e3df6791880d9c575b849296da96bc8ce6450811","seq":9,"ts":"2026-11-21T17:21:17Z","type":"entry.line_added"} +{"payload":{"account":2,"amount":"1000.00","currency":"USD","id":1,"side":"credit"},"prev":"5232348c2c19a5b7ec0969cef65cb5ac2c8e3d8d65ecaec0d295ec60c7d3611f","seq":10,"ts":"2026-11-21T17:21:17Z","type":"entry.line_added"} +{"payload":{"date":"2026-01-01","description":"Opening capital","id":1,"lines":[{"account":1,"amount":"1000.00","currency":"USD","side":"debit"},{"account":2,"amount":"1000.00","currency":"USD","side":"credit"}],"reversal_of":null},"prev":"e0b96ba7f5827397e2c89e878ca89a17c480e76e220ac123318ad2c1723f9bdc","seq":11,"ts":"2026-11-21T17:21:17Z","type":"entry.posted"} +{"payload":{"attachment_id":1,"blob_sha":"0d462b0d3e7b13628aa5b6279a6ced262a8670bd5d7063a0668469398ac6523e","category":"receipts","description":null,"entry_id":1,"file_name":"opening.txt","mime_type":"text/plain","size_bytes":34},"prev":"6edd977de13ff0aabca5c2f858ecc98de51f776c54106fa91a25440b634ac06d","seq":12,"ts":"2026-11-21T17:21:17Z","type":"receipt.attached"} +{"payload":{"attachment_id":1,"extractor":"wanderbooks","pages":1,"status":"ok","text_sha256":"0d462b0d3e7b13628aa5b6279a6ced262a8670bd5d7063a0668469398ac6523e","version":"0.1.0"},"prev":"41ca2d42a98d8b5eab5749c2bf71ee674f6135621a1507e26c378b06300c0257","seq":13,"ts":"2026-11-21T17:21:17Z","type":"attachment.text_extracted"} +{"payload":{"date":"2026-01-05","description":"January rent","id":2},"prev":"9708c879fa1b9bf0ec0a428dbc90729538b5955ebd04ef00b5fb40548463584f","seq":14,"ts":"2026-11-21T17:21:17Z","type":"entry.created"} +{"payload":{"account":4,"amount":"500.00","currency":"USD","id":2,"side":"debit"},"prev":"cf9c43907f31ca54887f2de7daac8c6ff9ebe7458ef27b440eb0cf492adf3d4e","seq":15,"ts":"2026-11-21T17:21:17Z","type":"entry.line_added"} +{"payload":{"account":1,"amount":"500.00","currency":"USD","id":2,"side":"credit"},"prev":"1cb79ebc08696ad70a990b08fa54025d48db4ad1e8eee9f4110ef92ec905c68e","seq":16,"ts":"2026-11-21T17:21:17Z","type":"entry.line_added"} +{"payload":{"date":"2026-01-05","description":"January rent","id":2,"lines":[{"account":4,"amount":"500.00","currency":"USD","side":"debit"},{"account":1,"amount":"500.00","currency":"USD","side":"credit"}],"reversal_of":null},"prev":"841b939d3ef9524aeaef5eb37ef045cafb19ae66647906e573b370f8c2df31a5","seq":17,"ts":"2026-11-21T17:21:17Z","type":"entry.posted"} +{"payload":{"attachment_id":2,"blob_sha":"dd3075d12716028c7ae1b8f9a10c590f8f4cc26ff4d854e30c9551ef7ad5898f","category":"receipts","description":null,"entry_id":2,"file_name":"rent.txt","mime_type":"text/plain","size_bytes":30},"prev":"3f149bb954e0c132a0673de90a6028cb3378e3bba70aa8d2ac6da74f8aec0f0c","seq":18,"ts":"2026-11-21T17:21:17Z","type":"receipt.attached"} +{"payload":{"attachment_id":2,"extractor":"wanderbooks","pages":1,"status":"ok","text_sha256":"dd3075d12716028c7ae1b8f9a10c590f8f4cc26ff4d854e30c9551ef7ad5898f","version":"0.1.0"},"prev":"e963e11c535bd64fea1a052f164c23c6a69e0e30119bb31dc03ce3f2bbc1e009","seq":19,"ts":"2026-11-21T17:21:17Z","type":"attachment.text_extracted"} +{"payload":{"date":"2026-01-07","description":"Printer paper","id":3},"prev":"a5e0cd4357ca13480837afcf430bd7d7d1fe71f19e7e0b94b5f83127449b484c","seq":20,"ts":"2026-11-21T17:21:17Z","type":"entry.created"} +{"payload":{"account":5,"amount":"40.00","currency":"USD","id":3,"side":"debit"},"prev":"60a961e8d2a377a5060ac7b9855ecd9fa980acda3df626f843465bd699f20683","seq":21,"ts":"2026-11-21T17:21:17Z","type":"entry.line_added"} +{"payload":{"account":1,"amount":"40.00","currency":"USD","id":3,"side":"credit"},"prev":"79ec9eb7e2964e39c3495a494e6207a5fcaa888c90be3784da24274e900e47d2","seq":22,"ts":"2026-11-21T17:21:17Z","type":"entry.line_added"} +{"payload":{"date":"2026-01-07","description":"Printer paper","id":3,"lines":[{"account":5,"amount":"40.00","currency":"USD","side":"debit"},{"account":1,"amount":"40.00","currency":"USD","side":"credit"}],"reversal_of":null},"prev":"1b032147bac04d88d186dd898015ecf1760540f87309fb34726d6581c25e25e5","seq":23,"ts":"2026-11-21T17:21:17Z","type":"entry.posted"} +{"payload":{"date":"2026-01-08","description":"Stamps","id":4},"prev":"7c6576c6e37574f37aa19367bcb6eb903bced46ae9af4743cb013e5108394379","seq":24,"ts":"2026-11-21T17:21:17Z","type":"entry.created"} +{"payload":{"account":5,"amount":"12.00","currency":"USD","id":4,"side":"debit"},"prev":"5ba613907078b656dc44b89902bdcfd3f2d852bd46476ed572a3aceb1bda5fd3","seq":25,"ts":"2026-11-21T17:21:17Z","type":"entry.line_added"} +{"payload":{"account":1,"amount":"12.00","currency":"USD","id":4,"side":"credit"},"prev":"7974e98292837366d966fdae04a9b1da20343b9716402b00446e91961e91b5be","seq":26,"ts":"2026-11-21T17:21:18Z","type":"entry.line_added"} +{"payload":{"date":"2026-01-08","description":"Stamps","id":4,"lines":[{"account":5,"amount":"12.00","currency":"USD","side":"debit"},{"account":1,"amount":"12.00","currency":"USD","side":"credit"}],"reversal_of":null},"prev":"103ffeb3ea65bcb6fb9d1d98e053b820854bb365a5ecd6e79ca9566ddfc2d1a3","seq":27,"ts":"2026-11-21T17:21:18Z","type":"entry.posted"} +{"payload":{"date":"2026-01-12","description":"Rent paid twice","id":5},"prev":"fb2fd5dac822d531039a36dc21acdf01fa52e7fd7742503b1dc0f57d169bde2f","seq":28,"ts":"2026-11-21T17:21:18Z","type":"entry.created"} +{"payload":{"account":4,"amount":"500.00","currency":"USD","id":5,"side":"debit"},"prev":"4173cac71861ded819608087a7d1f8b95eacf66def4d771f52352659551eefde","seq":29,"ts":"2026-11-21T17:21:18Z","type":"entry.line_added"} +{"payload":{"account":1,"amount":"500.00","currency":"USD","id":5,"side":"credit"},"prev":"8bec73a440c2775a7c2db2ea4646224ee3fa750099afa51f0c98d23fe9c670c9","seq":30,"ts":"2026-11-21T17:21:18Z","type":"entry.line_added"} +{"payload":{"date":"2026-01-12","description":"Rent paid twice","id":5,"lines":[{"account":4,"amount":"500.00","currency":"USD","side":"debit"},{"account":1,"amount":"500.00","currency":"USD","side":"credit"}],"reversal_of":null},"prev":"b3f437e100a5f779b482e5beedde09803d3824a7e6ef2b20ad8153d6d08fd385","seq":31,"ts":"2026-11-21T17:21:18Z","type":"entry.posted"} +{"payload":{"attachment_id":3,"blob_sha":"65c730c09a9b8c3ecf4cc2ae55fafe083dc33e2111abe6cafaf6fcb02a7d8ad8","category":"receipts","description":null,"entry_id":5,"file_name":"rent2.txt","mime_type":"text/plain","size_bytes":28},"prev":"e5605c49331605dcfa94abed01ea4eb3bc709c8a8cc135e152567fb9b4f4bbf5","seq":32,"ts":"2026-11-21T17:21:18Z","type":"receipt.attached"} +{"payload":{"attachment_id":3,"extractor":"wanderbooks","pages":1,"status":"ok","text_sha256":"65c730c09a9b8c3ecf4cc2ae55fafe083dc33e2111abe6cafaf6fcb02a7d8ad8","version":"0.1.0"},"prev":"3c50461894af5053a8fb32bb0c3c194b2f206c368e59e1730da85bef70469c64","seq":33,"ts":"2026-11-21T17:21:18Z","type":"attachment.text_extracted"} +{"payload":{"date":"2026-01-14","description":"Entered twice","id":6,"lines":[{"account":4,"amount":"500.00","currency":"USD","side":"credit"},{"account":1,"amount":"500.00","currency":"USD","side":"debit"}],"reverses":5},"prev":"ec86f4668bfafe0a6b2c17ca4e7bff2fdc5a053f3b8793f1d7684b15b75afe91","seq":34,"ts":"2026-11-21T17:21:18Z","type":"entry.reversed"} +{"payload":{"id":1,"name":"Fernhill Labs"},"prev":"fbbf3ba9de71b08916b141169d3a6afc02012dacd75c65a6e1ea1ca2c5870226","seq":35,"ts":"2026-11-21T17:21:18Z","type":"customer.added"} +{"payload":{"account_type":"Asset","code":"1200","currency":"USD","id":6,"name":"Accounts Receivable","parent":null,"placeholder":false},"prev":"9bb260c5fc23b8979a86dfb82434f27fbec5f08f05e14fabe263a7ebf5ac06f2","seq":36,"ts":"2026-11-21T17:21:18Z","type":"account.added"} +{"payload":{"date":"2026-01-10","description":"Invoice 1","id":7},"prev":"c7bb545bbd78dbd9c0e484ca0b30daf365428c184a2d0a1c7026a6c9f1534f28","seq":37,"ts":"2026-11-21T17:21:18Z","type":"entry.created"} +{"payload":{"account":6,"amount":"1200.00","currency":"USD","id":7,"side":"debit"},"prev":"b2eed9cb65adb9b62d6d8f1edb612f5c457dc10860669431cd38ff3e1063875d","seq":38,"ts":"2026-11-21T17:21:18Z","type":"entry.line_added"} +{"payload":{"account":3,"amount":"1200.00","currency":"USD","id":7,"side":"credit"},"prev":"3b562385f5122e382edef85cebf101572a7f942b8bdc661d974ff04b790c6a4a","seq":39,"ts":"2026-11-21T17:21:18Z","type":"entry.line_added"} +{"payload":{"date":"2026-01-10","description":"Invoice 1","id":7,"lines":[{"account":6,"amount":"1200.00","currency":"USD","side":"debit"},{"account":3,"amount":"1200.00","currency":"USD","side":"credit"}],"reversal_of":null},"prev":"d12b8ed32eb20092a70772e0d5c41d1e3282fae11c2fe2e41464932d12338c2d","seq":40,"ts":"2026-11-21T17:21:18Z","type":"entry.posted"} +{"payload":{"customer_id":1,"date":"2026-01-10","due_date":"2026-02-09","entry_id":7,"id":1,"lines":[{"amount":"1200.00","description":"Design"}]},"prev":"db2f943a9fc4f63ce1bdb693c337b677ade9b2c8304644e2eaa305430f4ea460","seq":41,"ts":"2026-11-21T17:21:18Z","type":"invoice.created"} +{"payload":{"date":"2026-01-20","description":"Payment on invoice 1","id":8},"prev":"6fdfb950b0348503b3f15d7e30bc7df82bd8e7fa89d5536c3a278c0e62848b50","seq":42,"ts":"2026-11-21T17:21:18Z","type":"entry.created"} +{"payload":{"account":6,"amount":"400.00","currency":"USD","id":8,"side":"credit"},"prev":"9c7e1b9401452196792a66965b83976e1a729841ade564e0ce4040b5508065bc","seq":43,"ts":"2026-11-21T17:21:18Z","type":"entry.line_added"} +{"payload":{"account":1,"amount":"400.00","currency":"USD","id":8,"side":"debit"},"prev":"3efb25e4c64f06bde9906e2613050eed434e194c4375e89c77a01a9268651edd","seq":44,"ts":"2026-11-21T17:21:18Z","type":"entry.line_added"} +{"payload":{"date":"2026-01-20","description":"Payment on invoice 1","id":8,"lines":[{"account":6,"amount":"400.00","currency":"USD","side":"credit"},{"account":1,"amount":"400.00","currency":"USD","side":"debit"}],"reversal_of":null},"prev":"2cbd6a77427a46a5768516971a08848971b369a2d98d5151366776d1bfd212e4","seq":45,"ts":"2026-11-21T17:21:18Z","type":"entry.posted"} +{"payload":{"amount":"400.00","cash_account":1,"date":"2026-01-20","entry_id":8,"invoice_id":1},"prev":"9d6f20f7dceed2bfc4ad665add8646619c504c4368c1edf71df47835150b5c49","seq":46,"ts":"2026-11-21T17:21:18Z","type":"invoice.payment_received"} +{"payload":{"id":1,"name":"Paper Co"},"prev":"4c50d9955f03b91e2c3fce29fd887deb5ab9096584e47c5a85efc34f49ed72a2","seq":47,"ts":"2026-11-21T17:21:18Z","type":"vendor.added"} +{"payload":{"account_type":"Expense","code":"6999","currency":"USD","id":7,"name":"General Expenses","parent":null,"placeholder":false},"prev":"5553de03d5aac9b56f60a9bbde5aa42e44ff344586c418b9856227f22f1f46e2","seq":48,"ts":"2026-11-21T17:21:18Z","type":"account.added"} +{"payload":{"account_type":"Liability","code":"2000","currency":"USD","id":8,"name":"Accounts Payable","parent":null,"placeholder":false},"prev":"30f702f2b37017c5c874db07dcd6c67613b9109a12d56f8239ed6f4eff1eae19","seq":49,"ts":"2026-11-21T17:21:18Z","type":"account.added"} +{"payload":{"date":"2026-01-15","description":"Bill 1","id":9},"prev":"61e35219d6faa4b6340533b8a2cacfd43debe53782c8d4e63eac22ca5d2e5805","seq":50,"ts":"2026-11-21T17:21:18Z","type":"entry.created"} +{"payload":{"account":7,"amount":"80.00","currency":"USD","id":9,"side":"debit"},"prev":"a4ebfaa95046b0a5d59a7cd32871ffbe18b3250a6134b164089267e7bec63ba0","seq":51,"ts":"2026-11-21T17:21:18Z","type":"entry.line_added"} +{"payload":{"account":8,"amount":"80.00","currency":"USD","id":9,"side":"credit"},"prev":"28858765913dfef4c936f4fdf7d875a5851fa63b09f5a0adbc4cee4e2fc4ff58","seq":52,"ts":"2026-11-21T17:21:18Z","type":"entry.line_added"} +{"payload":{"date":"2026-01-15","description":"Bill 1","id":9,"lines":[{"account":7,"amount":"80.00","currency":"USD","side":"debit"},{"account":8,"amount":"80.00","currency":"USD","side":"credit"}],"reversal_of":null},"prev":"218c776b0c1154a98411a33181dd6d3cafd8043efac16f6af95b9795d39ebb22","seq":53,"ts":"2026-11-21T17:21:18Z","type":"entry.posted"} +{"payload":{"date":"2026-01-15","due_date":"2026-02-14","entry_id":9,"id":1,"lines":[{"amount":"80.00","description":"Toner"}],"vendor_id":1},"prev":"e1229f4d739cc44e2c78d931779122ca55a5d4606c828e59258e7dd0741bed6f","seq":54,"ts":"2026-11-21T17:21:18Z","type":"bill.created"} +{"payload":{"id":2,"name":"Paper Co"},"prev":"18235b3318fecf59ffbf80dd90fec3040aa71e5ac35fcf6a7343839ef0f3e51e","seq":55,"ts":"2026-11-21T17:21:18Z","type":"vendor.added"} +{"payload":{"date":"2026-01-15","description":"Bill 2","id":10},"prev":"3948822602f054c0c5f175bf772267a1a504663d71b51cc2b6e4d2873c2aa585","seq":56,"ts":"2026-11-21T17:21:18Z","type":"entry.created"} +{"payload":{"account":7,"amount":"80.00","currency":"USD","id":10,"side":"debit"},"prev":"6c8573a7d6478bfc33a3400179e0144e84f8fa335f3ed4f522ffb802258ac57d","seq":57,"ts":"2026-11-21T17:21:18Z","type":"entry.line_added"} +{"payload":{"account":8,"amount":"80.00","currency":"USD","id":10,"side":"credit"},"prev":"972930a53a0eaf33104f6ef30564bc700b4f0555e6fc30c51e8530adfd7377b5","seq":58,"ts":"2026-11-21T17:21:18Z","type":"entry.line_added"} +{"payload":{"date":"2026-01-15","description":"Bill 2","id":10,"lines":[{"account":7,"amount":"80.00","currency":"USD","side":"debit"},{"account":8,"amount":"80.00","currency":"USD","side":"credit"}],"reversal_of":null},"prev":"2209efd9c19b9294c129ae160212b8c9b43af67795d6b27428f51131305eb5bf","seq":59,"ts":"2026-11-21T17:21:18Z","type":"entry.posted"} +{"payload":{"date":"2026-01-15","due_date":"2026-02-14","entry_id":10,"id":2,"lines":[{"amount":"80.00","description":"Toner"}],"vendor_id":2},"prev":"42303256a0b0a6b78348fdaaec5d40005e6fd3f423822d0059ac88116115a42a","seq":60,"ts":"2026-11-21T17:21:18Z","type":"bill.created"} +{"payload":{"date":"2026-02-12","description":"Coworking day pass","id":11},"prev":"298490d98419cf6c6160cc13985e1d8ed7b89c0a22ff562bea61adc48644b638","seq":61,"ts":"2026-11-21T17:21:18Z","type":"entry.created"} +{"payload":{"account":4,"amount":"35.00","currency":"USD","id":11,"side":"debit"},"prev":"85eb41426eaa06c547b0de87a9a2d316c52c99857370685abfdebcebcdba4a95","seq":62,"ts":"2026-11-21T17:21:18Z","type":"entry.line_added"} +{"payload":{"account":1,"amount":"35.00","currency":"USD","id":11,"side":"credit"},"prev":"a2471ce2220b5149a57111bc24b8e2099272a7ba70df2ed0c0d0cc4f07a85894","seq":63,"ts":"2026-11-21T17:21:18Z","type":"entry.line_added"} +{"payload":{"end":"2026-01-31","id":1,"name":"2026-01","start":"2026-01-01"},"prev":"2404ced35786e0fc18b89e6abc40ae38b71744d11e873c268861eb161d44955c","seq":64,"ts":"2026-11-21T17:21:18Z","type":"period.created"} +{"payload":{"account_type":"Equity","code":"3999","currency":"USD","id":9,"name":"Retained Earnings","parent":null,"placeholder":false},"prev":"eba0c17e576a4cda32ec8dc1d0e5009d43aa75bf4bb15f62dc8486a23f49e259","seq":65,"ts":"2026-11-21T17:21:18Z","type":"account.added"} +{"payload":{"close_to":"retained_earnings","closing_entry":12,"entry":{"date":"2026-01-31","description":"Close period 2026-01","id":12,"lines":[{"account":3,"amount":"1200.00","currency":"USD","side":"debit"},{"account":4,"amount":"500.00","currency":"USD","side":"credit"},{"account":5,"amount":"52.00","currency":"USD","side":"credit"},{"account":7,"amount":"160.00","currency":"USD","side":"credit"},{"account":9,"amount":"488.00","currency":"USD","side":"credit"}]},"id":1},"prev":"2ee4640029200f64e0e12dee7b23b8d320617f17843eb43c45ce1a29bd8fd04f","seq":66,"ts":"2026-11-21T17:21:18Z","type":"period.closed"} diff --git a/crates/ledger-store/tests/store.rs b/crates/ledger-store/tests/store.rs index b2fa05e8..a8a62319 100644 --- a/crates/ledger-store/tests/store.rs +++ b/crates/ledger-store/tests/store.rs @@ -2316,11 +2316,70 @@ fn books_written_under_older_rules_still_open() { "method": method, "audit_run_id": 1}), ) .unwrap(); + // P15 T1's new shape (`call_transactions`), hand-written as this + // version writes it: a call's lines between `call.begun` and + // `call.closed`. They count only when the closing line says `ok`. An + // ok call (a note on the party), a call that failed (whose party id + // is handed out again by the standalone line after it), a call that + // never finished, and an ok call whose answer was too long to keep. + let frame = |w: &mut JournalWriter, outcome: &str, lines: &[(&str, serde_json::Value)]| { + let id = json!({"tool": "books.update_party", "token": "t-1", + "key": format!("key-frame-{outcome}"), "args": "ab".repeat(32)}); + let begun = w.append("call.begun", id.clone()).unwrap().seq; + let mut last = begun; + for (ty, payload) in lines { + last = w.append(ty, payload.clone()).unwrap().seq; + } + let mut closed = id; + closed["outcome"] = json!(outcome); + closed["first_seq"] = json!(begun); + closed["last_seq"] = json!(last); + match outcome { + "ok" => closed["answer"] = json!(r#"{"party_id":1}"#), + "long" => { + closed["outcome"] = json!("ok"); + closed["answer_sha256"] = json!("cd".repeat(32)); + closed["answer_bytes"] = json!(9000); + } + "failed" => closed["error"] = json!("the call failed after its lines"), + _ => closed["error"] = json!("the call never finished"), + } + w.append("call.closed", closed).unwrap(); + }; + let note = |text: &str| { + ( + "party.updated", + json!({"id": 1, "change": {"field": "notes", "value": text}}), + ) + }; + frame(&mut w, "ok", &[note("counted")]); + frame( + &mut w, + "failed", + &[ + ("party.added", json!({"id": 4, "name": "Dead", "roles": []})), + note("not counted: failed"), + ], + ); + // The id the failed call had is handed out again. + w.append("party.added", json!({"id": 4, "name": "Real", "roles": []})) + .unwrap(); + frame(&mut w, "unfinished", &[note("not counted: unfinished")]); + frame(&mut w, "long", &[note("counted, long answer")]); drop(w); // Opening rebuilds from the journal; it must accept all of it. let _ = std::fs::remove_file(dir.join(ledger_store::db_file())); let store = Store::open(&dir).expect("older books still open"); store.verify().unwrap(); + // Only the lines of calls that closed ok are the books': the last note + // is the long-answer call's, the failed call's party never was, and + // the id it had is the standalone party's. + assert_eq!( + store.ledger().get_party(1).unwrap().notes.as_deref(), + Some("counted, long answer") + ); + assert_eq!(store.ledger().get_party(4).unwrap().name, "Real"); + assert!(store.ledger().get_party(5).is_none()); assert_eq!(store.journal_format().format, 1); assert_eq!(store.ledger().chart().len(), 9); assert_eq!(store.ledger().list_periods().len(), 2);