Files
wanderbooks/crates/ledger-core/tests/bookspec/check.rs
T
swaitsandClaude Sonnet 5.5 a87e2d0a7a test(core): the adapter runs a platform's payout, an asset's tag and the K-1's tax-basis note through the engine
The bookspec schema gained a `payout` event, a `tag_asset` event, an
`asset_tag` query and a note on the tax-basis property line (BS-revenue-1,
BS-asset-3, BS-partner-17). The adapter runs each through the engine and
rebuilds none of it: a payout goes through `payouts::payout_plan`, which
refuses unless gross less fee is the deposit to the cent, and its plan's lines
post as one entry; a tag goes through `Store::set_asset_tag`, which refuses a
tag of a wrong form and one another asset holds or ever held; the tax-basis
line's note is `Note::PrepaidAtBook` read off the worksheet. The engine's
InvalidPayout, InvalidAssetTag and AssetTagTaken are worded as the examples
word them.

Thirteen examples were added and every one the engine's picks reach passes:
five are for options wanderbooks did not pick (no-tags, every-prepaid-is-cash,
every-prepaid-is-property, left-open, whole-payment-to-each) and are skipped,
so the skipped count is 22 + 5 = 27 and 112 of 139 run. A prepaid contract
credited straight to capital is property (1,500.00 each) and a service paid
through Due to Members is cash (1,000.00 each); the contract enters the tax
capital at its book amount with the note; a 1,000.00 check naming Dana Studio
at 600.00 counts 600.00 toward Dana's 1099.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 12:05:15 -07:00

165 lines
5.8 KiB
Rust

use crate::*;
use crate::queries::commands::COMMANDS;
use crate::queries::formats::FORMAT_QUERIES;
/// Check one expectation against the books as they stand: a query the
/// core answers, value by value; a format query's shape, its values left
/// to the test [`FORMAT_QUERIES`] names (returned); a query no crate
/// answers is refused.
pub(crate) fn check(b: &Books<'_>, x: &Expect) -> Option<&'static str> {
let (ex, l) = (b.ex, b.l());
let q = x.query.as_str();
let only = |given: bool, key: &str, queries: &[&str]| {
assert!(
!given || queries.contains(&q),
"{}: {q}: {key} is for {} only",
ex.id,
queries.join(" and ")
);
};
only(
x.entry.is_some(),
"entry",
&["entry", "party_part", "draft_state", "evidence"],
);
only(x.event.is_some(), "event", &["run"]);
only(
x.asset.is_some(),
"asset",
&[
"disposal",
"depreciation_schedule",
"register_row",
"asset_basis",
"asset_tag",
],
);
only(x.schedule.is_some(), "schedule", &["schedule_plan"]);
only(
x.party.is_some(),
"party",
&[
"party_part",
"party_totals",
"party_tin_last4",
"return_tin",
],
);
only(x.basis.is_some(), "basis", &["party_totals"]);
only(x.payee.is_some(), "payee", &["vendor_1099"]);
only(
x.document.is_some(),
"document",
&["document_dates", "document"],
);
only(x.of.is_some(), "of", &["aging"]);
only(
x.code.is_some(),
"code",
&["rename_account", "set_tax_category"],
);
only(x.key.is_some(), "key", &["setting"]);
only(x.role.is_some(), "role", &["role_account"]);
only(x.name.is_some(), "name", &["rename_account"]);
only(x.category.is_some(), "category", &["set_tax_category"]);
only(x.account.is_some(), "account", &["add_account"]);
only(x.accepted.is_some(), "accepted", &COMMANDS);
only(
x.refused.is_some(),
"refused",
&[
"rename_account",
"add_account",
"set_tax_category",
"period",
"vendor_1099",
"iif_lines",
"iif_changes",
"return_tin",
],
);
if COMMANDS.contains(&q) {
// A command is accepted or refused, and shows no values.
assert!(
x.values.is_none() && (x.accepted == Some(true)) != x.refused.is_some(),
"{}: {q} is a command: accepted = true, or refused, and no values",
ex.id
);
check_command(ex, l, x);
return None;
}
// Anything else shows its values; a period may be refused instead, and
// so may a 1099 worksheet, an export and a return (BS-1099-2,
// BS-format-10, BS-partner-8). The refusal is the engine's own.
assert!(
x.refused.is_some() != x.values.as_ref().is_some_and(|v| !v.is_empty()),
"{}: {q} expects values (a period: values or refused)",
ex.id
);
if let Some(want) = &x.refused
&& matches!(
q,
"vendor_1099" | "iif_lines" | "iif_changes" | "return_tin"
)
{
match b.answer(&x.query()) {
Err(r) => assert_eq!(&r.reason, want, "{}: {q} refused ({})", ex.id, r.reason),
Ok(v) => panic!("{}: {q} answered {v}, expected refused: {want}", ex.id),
}
if matches!(q, "iif_lines" | "iif_changes") {
check_format_refused(ex, x);
}
return None;
}
match q {
"period" => check_period(ex, x),
"day" => check_day(ex, x),
"calendar_year" => check_calendar_year(ex, x),
"account_names" => check_account_names(ex, l, x),
"uncategorized_accounts" => check_uncategorized_accounts(ex, l, x),
"cash_flow" => check_cash_flow(b, x),
"trial_balance" => check_trial_balance(ex, l, x),
"profit_and_loss" => check_profit_and_loss(ex, l, x),
"vendor_1099_paid" => check_vendor_1099_paid(b, x),
"vendor_1099" => check_vendor_1099(b, x),
"entry" => check_entry(b, x),
"run" => check_run(b, x),
"disposal" => check_disposal(b, x),
"depreciation_schedule" => check_depreciation_schedule(b, x),
"schedule_plan" => check_schedule_plan(b, x),
"register_row" => check_register_row(b, x),
"register_totals" => check_register_totals(b, x),
"asset_basis" => check_asset_basis(b, x),
"asset_tag" => check_asset_tag(b, x),
"k1_tax_basis" => check_k1_tax_basis(b, x),
"k1_reconciliation" => check_k1_reconciliation(b, x),
"balances" => check_balances(ex, l, x),
"members_equity" => check_members_equity(ex, l, &b.members, x),
"k1" => check_k1(ex, l, &b.members, x),
"party_part" => check_party_part(b, x),
"party_totals" => check_party_totals(b, x),
"party_tin_last4" => check_party_tin_last4(b, x),
"return_tin" => check_return_tin(b, x),
"project" => check_project(b, x),
"aging" => check_aging(b, x),
"document_dates" => check_document_dates(b, x),
"document" => check_document(b, x),
"invoice_numbers" => check_invoice_numbers(b, x),
"draft_state" => check_draft_state(b, x),
"evidence" => check_evidence(b, x),
"setting" => check_setting(b, x),
"role_account" => check_role_account(b, x),
"tax_summary" => check_tax_summary(b, x),
q => {
let &(_, by) = FORMAT_QUERIES
.iter()
.find(|(f, _)| *f == q)
.unwrap_or_else(|| panic!("{}: no crate answers query {q:?}", ex.id));
check_format_shape(ex, x);
return Some(by);
}
}
None
}