test(core): golden file for the audit workpaper

The audit's statements programme (rules.md B-45) now has a golden for one
small book, hand-worked from B-45 in plan/golden-worksheets/audit-workpaper.md:
2,000.00 of capital, a 40.00 purchase with no receipt, a year of prepaid
insurance never posted, a 5.00 draft, and one Revenue account with no tax
category. Through 2026-03-31 that gives one failure (evidence_missing,
entry 2, debits 40.00 over the 25.00 threshold) and four warnings: draft 4
on 2026-02-10, schedule 1 with 3 months / 300.00 due from 2026-01-31,
account 4100, and vendor Tobin Harlow Supply at 900.00. Trial balance,
equation, P&L articulation, control accounts, closes, assets, settings and
the receipted entries are all silent.

The golden holds the workpaper's statements data (scope, through, summary,
findings). Hashes, the figure head and the programme version are not
hand-verifiable, and the static check catalogue is not a finding, so they
stay out; the worksheet says so. The first draft mis-marked evidence_missing
a warning: the table and CODES say failure, the prose was wrong, and both
the worksheet and the golden were corrected to the books.

Co-Authored-By: DeepSeek V4.1 Flash <noreply@opencode.ai>
This commit is contained in:
swaitsandDeepSeek V4.1 Flash committed 2026-11-07 10:38:59 -07:00
1 parent 3ac3e8b1b4
commit 3fa0bddfda
3 files changed
+436

No files matched your search

@@ -0,0 +1,52 @@
{
"scope": "month",
"through": "2026-03-31",
"summary": "1 failure(s), 4 warning(s), 0 note(s)",
"findings": [
{
"code": "evidence_missing",
"severity": "failure",
"subject": {
"kind": "entry",
"id": 2
},
"message": "entry 2 (2026-01-05) has no receipt: its debits 40.00 are strictly greater than the 25.00 threshold"
},
{
"code": "draft_open",
"severity": "warning",
"subject": {
"kind": "entry",
"id": 4
},
"message": "draft 4 (2026-02-10) \"Stamps\" is not posted"
},
{
"code": "schedule_behind",
"severity": "warning",
"subject": {
"kind": "schedule",
"id": 1
},
"message": "\"Prepaid insurance\" has 3 month(s) due and not posted, from 2026-01-31, 300.00 in all"
},
{
"code": "tax_category_missing",
"severity": "warning",
"subject": {
"kind": "account",
"id": 5
},
"message": "account 4100 Other income has no tax category"
},
{
"code": "vendor_1099_undecided",
"severity": "warning",
"subject": {
"kind": "vendor",
"id": "Tobin Harlow Supply"
},
"message": "Tobin Harlow Supply was paid 900.00 in a way that could need a 1099 and has no decision"
}
]
}
+186
View File
@@ -0,0 +1,186 @@
//! The audit workpaper's findings for one small book, hand-verified
//! (rules.md B-45; plan/golden-worksheets/audit-workpaper.md).
//!
//! The fixture is a bank, prepaid insurance, capital, two revenue and two
//! expense accounts, and a 12-month prepaid plan. It seeds five defects in
//! five check areas (`draft_open`, `evidence_missing`, `schedule_behind`,
//! `tax_category_missing`, `vendor_1099_undecided`) and leaves every other
//! check silent: the trial balance balances, the equation holds, the P&L
//! articulates, no control account or document exists, no close has run, no
//! asset is registered, and the entries the receipt policy reaches have
//! their receipts.
//!
//! The golden holds the workpaper's statements data — scope, through,
//! summary and findings — not the store's hashes, the figure head or the
//! programme's version (see the worksheet's "Scope of this golden").
use std::collections::BTreeSet;
use chrono::NaiveDate;
use ledger_core::audit::{self, AuditInput, Severity};
use ledger_core::settings::Settings;
use ledger_core::{
AccountType, Currency, Ledger, Money, NewSchedule, ScheduleConvention, ScheduleKind, Side,
};
use rust_decimal::Decimal;
fn d(month: u32, day: u32) -> NaiveDate {
NaiveDate::from_ymd_opt(2026, month, day).unwrap()
}
fn usd(amount: &str) -> Money {
Money::new(amount.parse::<Decimal>().unwrap(), Currency::USD)
}
/// Post a balanced entry in one call and return its id.
fn post(
ledger: &mut Ledger,
date: NaiveDate,
description: &str,
lines: &[(u64, Side, &str)],
) -> u64 {
let id = ledger.create_entry(date, description);
for (account, side, amount) in lines {
ledger.add_line(id, *account, *side, usd(amount)).unwrap();
}
ledger.post_entry(id).unwrap();
id
}
/// The worksheet's fixture: accounts in creation order (ids 1–7), then the
/// opening, the unreceipted purchase, the prepaid payment, and a draft.
fn audit_company() -> Ledger {
let mut ledger = Ledger::new(Currency::USD);
let bank = ledger
.add_account("1000", "Bank", AccountType::Asset, None, false)
.unwrap();
let prepaid = ledger
.add_account("1300", "Prepaid Insurance", AccountType::Asset, None, false)
.unwrap();
let capital = ledger
.add_account("3000", "Capital", AccountType::Equity, None, false)
.unwrap();
let sales = ledger
.add_account("4000", "Sales", AccountType::Revenue, None, false)
.unwrap();
let other_income = ledger
.add_account("4100", "Other income", AccountType::Revenue, None, false)
.unwrap();
let supplies = ledger
.add_account("6000", "Supplies", AccountType::Expense, None, false)
.unwrap();
let insurance = ledger
.add_account("6100", "Insurance", AccountType::Expense, None, false)
.unwrap();
// Every Revenue/Expense account but 4100 gets a category: 4100 is the
// seeded tax-category defect and nothing else is uncategorized.
for (account, category) in [
(sales, "gross_receipts"),
(supplies, "supplies"),
(insurance, "insurance"),
] {
ledger
.set_account_tax(account, Some(category), None)
.unwrap();
}
// 1. Opening: 2,000.00 of capital into the bank.
post(
&mut ledger,
d(1, 1),
"Opening",
&[
(bank, Side::Debit, "2000.00"),
(capital, Side::Credit, "2000.00"),
],
);
// 2. Printer paper, 40.00, no receipt: the evidence defect.
post(
&mut ledger,
d(1, 5),
"Printer paper",
&[
(supplies, Side::Debit, "40.00"),
(bank, Side::Credit, "40.00"),
],
);
// 3. A year of insurance paid up front, with its receipt. The plan is
// never posted, so its months are the schedule defect.
post(
&mut ledger,
d(1, 1),
"Prepaid insurance",
&[
(prepaid, Side::Debit, "1200.00"),
(bank, Side::Credit, "1200.00"),
],
);
// 4. A draft dated before the audit, never posted: the draft defect.
let draft = ledger.create_entry(d(2, 10), "Stamps");
ledger
.add_line(draft, supplies, Side::Debit, usd("5.00"))
.unwrap();
ledger
.add_line(draft, bank, Side::Credit, usd("5.00"))
.unwrap();
ledger
.register_schedule(NewSchedule {
description: "Prepaid insurance".into(),
kind: ScheduleKind::PrepaidExpense,
total: usd("1200.00"),
start: d(1, 1),
months: 12,
balance_account: prepaid,
pl_account: insurance,
convention: ScheduleConvention::MonthlyEven,
})
.unwrap();
let _ = other_income;
ledger
}
/// By-hand worksheet: `plan/golden-worksheets/audit-workpaper.md`.
#[test]
fn golden_audit_workpaper() {
let ledger = audit_company();
let settings = Settings::default();
// Entries 1 and 3 carry receipts; entry 2 is the evidence defect.
let receipts: BTreeSet<u64> = [1, 3].into_iter().collect();
let undecided_1099 = [("Tobin Harlow Supply".to_string(), usd("900.00").amount)];
let through = d(3, 31);
let findings = audit::statements(
&ledger,
&AuditInput {
settings: &settings,
receipts: &receipts,
cash_flow: None,
settings_problems: &[],
undecided_1099: &undecided_1099,
},
through,
);
let count = |severity: Severity| findings.iter().filter(|f| f.severity == severity).count();
let summary = format!(
"{} failure(s), {} warning(s), {} note(s)",
count(Severity::Failure),
count(Severity::Warning),
count(Severity::Info)
);
// The workpaper's statements data: what `books.audit` files, minus the
// fields that are not hand-verifiable (hashes, figure head, build
// version) or not findings (company name, the static check catalogue).
let got = serde_json::json!({
"scope": "month",
"through": through.to_string(),
"summary": summary,
"findings": serde_json::to_value(&findings).unwrap(),
});
let want: serde_json::Value =
serde_json::from_str(include_str!("golden/audit_workpaper.json")).unwrap();
assert_eq!(got, want);
}