test(core): the audit golden derives its 1099 finding from a posted payment

The audit golden used to hand the vendor and amount to the audit; the
ledger held no payment to that vendor. Now the fixture adds the vendor
(Ledger::add_vendor, which makes its party) and posts entry 5, 900.00 of
supplies paid from the bank on 2026-03-10 with a receipt, 1099 decision
left undecided. The audit's 1099 input is built as ledger-mcp's
audit_findings builds it: ledger_package::vendor_1099_report(year 2026,
as of 2026-03-31), keeping the vendors with decision_needed. Because the
books name the bank as their cash account, the cash-flow footing is tried
the same way instead of handed in as None.

Recomputed by hand (worksheet): opening raised to 3,000.00 so the bank
stays positive (860.00 = 3,000 - 40 - 1,200 - 900); trial balance 3,000.00
= 3,000.00; assets 2,060.00 = equity 3,000 - 940; net income -940.00 =
current earnings; cash flow operating -2,140.00 + financing 3,000.00 =
+860.00 = change in cash. The vendor's 900.00 is under the 2026 threshold
of 2,000.00 (B-19, status under_threshold), yet decision_needed is
has_undecided && hi(U) > 0, so the code flags it; the worksheet records
that this is the code's rule, which B-19 does not state separately. The
payment debits Supplies (already categorized) and is entry 5 so the draft
stays entry 4: no other finding changes, and the golden JSON is unchanged.

The worksheet no longer says B-45 gives the severities or the checks'
list: B-45 asks for a deterministic, fixed-order list; the severities are
the CODES table's, the code's own CONVENTION, which this golden pins. It
also lists which checks the golden leaves silent and that tests/audit.rs
seeds each one.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Sonnet 5.5 committed 2026-11-07 11:59:13 -07:00
1 parent 3fa0bddfda
commit 5e526d1cd9
2 files changed
+274 -60

No files matched your search

+105 -16
View File
@@ -2,13 +2,15 @@
//! (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
//! expense accounts, a 12-month prepaid plan, and a vendor paid from the
//! bank. 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, the cash
//! flow foots, no control account or document exists, no close has run, no
//! asset is registered, and the entries the receipt policy reaches have
//! their receipts.
//! their receipts. The `vendor_1099_undecided` input is derived from the
//! books the way `ledger-mcp`'s `audit_findings` does it, not handed in.
//!
//! The golden holds the workpaper's statements data — scope, through,
//! summary and findings — not the store's hashes, the figure head or the
@@ -16,11 +18,12 @@
use std::collections::BTreeSet;
use chrono::NaiveDate;
use chrono::{Datelike, NaiveDate};
use ledger_core::audit::{self, AuditInput, Severity};
use ledger_core::settings::Settings;
use ledger_core::settings::{Company, Settings};
use ledger_core::{
AccountType, Currency, Ledger, Money, NewSchedule, ScheduleConvention, ScheduleKind, Side,
Status1099,
};
use rust_decimal::Decimal;
@@ -48,7 +51,8 @@ fn post(
}
/// The worksheet's fixture: accounts in creation order (ids 1–7), then the
/// opening, the unreceipted purchase, the prepaid payment, and a draft.
/// opening, the unreceipted purchase, the prepaid payment, a draft, and the
/// vendor's payment (entry 5, after the draft so the draft stays entry 4).
fn audit_company() -> Ledger {
let mut ledger = Ledger::new(Currency::USD);
let bank = ledger
@@ -84,14 +88,14 @@ fn audit_company() -> Ledger {
.unwrap();
}
// 1. Opening: 2,000.00 of capital into the bank.
// 1. Opening: 3,000.00 of capital into the bank.
post(
&mut ledger,
d(1, 1),
"Opening",
&[
(bank, Side::Debit, "2000.00"),
(capital, Side::Credit, "2000.00"),
(bank, Side::Debit, "3000.00"),
(capital, Side::Credit, "3000.00"),
],
);
// 2. Printer paper, 40.00, no receipt: the evidence defect.
@@ -124,6 +128,22 @@ fn audit_company() -> Ledger {
.add_line(draft, bank, Side::Credit, usd("5.00"))
.unwrap();
// 5. 900.00 of supplies paid from the bank to a vendor (a party of its
// own), with its receipt; the vendor's 1099 decision is left
// undecided: the 1099 defect.
let vendor = ledger.add_vendor("Tobin Harlow Supply").unwrap();
assert!(ledger.party_of_vendor(vendor).is_some());
let paid = post(
&mut ledger,
d(3, 10),
"Supplies from Tobin Harlow",
&[
(supplies, Side::Debit, "900.00"),
(bank, Side::Credit, "900.00"),
],
);
ledger.set_entry_vendor(paid, Some(vendor)).unwrap();
ledger
.register_schedule(NewSchedule {
description: "Prepaid insurance".into(),
@@ -146,17 +166,86 @@ fn audit_company() -> Ledger {
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)];
// Entries 1, 3 and 5 carry receipts; entry 2 is the evidence defect.
let receipts: BTreeSet<u64> = [1, 3, 5].into_iter().collect();
let through = d(3, 31);
// The books name the bank (1000) as their one cash account
// (`books.cash_accounts`); the package reads the roles from there.
let company = Company::default();
let cash_accounts = vec!["1000".to_string()];
let package = ledger_package::Settings {
company: &company,
cash_accounts: &cash_accounts,
financing_accounts: &[],
investing_accounts: &[],
};
// The statement of cash flows, from the first entry through `through`,
// with the roles: as `ledger-mcp`'s `audit_findings` tries it.
let first = ledger
.posted_entries()
.filter(|e| e.date() <= through)
.map(|e| e.date())
.min()
.expect("the fixture posts entries");
let statement = ledger_package::cash_flow_for(
&ledger,
&package,
Some(&first.to_string()),
Some(&through.to_string()),
&[],
&[],
&[],
through,
);
let cash = Some(statement.clone().map(|s| s.reconciles));
// Vendors paid in a way that could need a 1099 and undecided: the same
// derivation as `ledger-mcp`'s `audit_findings`, from the ledger.
let report =
ledger_package::vendor_1099_report(&ledger, &package, through.year(), None, Some(through));
let undecided_1099: Vec<(String, Decimal)> = report
.as_ref()
.map(|r| {
r.vendors
.iter()
.filter(|v| v.decision_needed)
.map(|v| (v.name.clone(), v.paid))
.collect()
})
.unwrap_or_default();
// The worksheet's hand values for the two derived inputs (see "The
// vendor's 1099 and the cash flow, by hand"): the statement foots at
// +860.00 (operating -2,140.00, financing +3,000.00); the vendor's
// report is 900.00 of undecided payments against the 2026 threshold
// of 2,000.00, so under threshold, yet a decision is asked for.
let statement = statement.unwrap();
assert_eq!(statement.cash_from_operations, usd("-2140.00").amount);
assert_eq!(statement.cash_from_investing, Decimal::ZERO);
assert_eq!(statement.cash_from_financing, usd("3000.00").amount);
assert_eq!(statement.cash_beginning, Decimal::ZERO);
assert_eq!(statement.cash_ending, usd("860.00").amount);
let footing = cash.as_ref().unwrap().as_ref().unwrap();
assert_eq!(footing.sections_sum, usd("860.00").amount);
assert_eq!(footing.net_change, usd("860.00").amount);
assert_eq!(footing.difference, Decimal::ZERO);
let report = report.unwrap();
assert_eq!(report.threshold, usd("2000.00").amount);
assert_eq!(report.vendors.len(), 1);
assert_eq!(report.vendors[0].status, Status1099::UnderThreshold);
assert_eq!(
undecided_1099,
[("Tobin Harlow Supply".to_string(), usd("900.00").amount)]
);
let findings = audit::statements(
&ledger,
&AuditInput {
settings: &settings,
receipts: &receipts,
cash_flow: None,
cash_flow: cash.as_ref(),
settings_problems: &[],
undecided_1099: &undecided_1099,
},