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>
192 lines
7.2 KiB
Rust
192 lines
7.2 KiB
Rust
use crate::engine::unpicked_option;
|
|
use crate::*;
|
|
|
|
/// The `Engine` adapter over `Store` runs every example through the
|
|
/// runner, and every rule the adapter claims passes (`plan/served.md` P13
|
|
/// step 2). The loader above proves the same figures with its own checks;
|
|
/// this proves the trait path, which is what another engine supplies.
|
|
#[test]
|
|
pub(crate) fn the_runner_reports_every_claimed_rule_green() {
|
|
let mut examples = Vec::new();
|
|
for (name, text) in bookspec_checker::examples() {
|
|
examples.push(Example::from_toml(text).unwrap_or_else(|e| panic!("{name}: {e}")));
|
|
}
|
|
assert!(examples.len() >= 56, "the seed has at least 56 examples");
|
|
let report = bookspec_runner::run(&examples, bookspec_checker::rules(), Books::blank);
|
|
assert!(
|
|
report.passed(),
|
|
"the runner is not green:\n{}",
|
|
report.failures().join("\n")
|
|
);
|
|
// An example for an option wanderbooks did not pick is not run; every
|
|
// other one is, and passes.
|
|
let skipped = report.skipped();
|
|
let unpicked: Vec<&str> = examples
|
|
.iter()
|
|
.filter(|ex| unpicked_option(ex).is_some())
|
|
.map(|ex| ex.id.as_str())
|
|
.collect();
|
|
assert_eq!(
|
|
skipped.len(),
|
|
unpicked.len(),
|
|
"the runner skips exactly the examples for unpicked options: {skipped:?}"
|
|
);
|
|
for id in &unpicked {
|
|
assert!(
|
|
skipped.iter().any(|s| s.starts_with(&format!("{id}:"))),
|
|
"{id} is skipped"
|
|
);
|
|
}
|
|
let ran = report.examples.len() - skipped.len();
|
|
let passed = report
|
|
.examples
|
|
.iter()
|
|
.filter(|e| e.skipped.is_none() && e.failure.is_none())
|
|
.count();
|
|
eprintln!(
|
|
"bookspec runner: {} examples, {ran} run, {passed} passed, {} skipped (an option wanderbooks did not pick)",
|
|
report.examples.len(),
|
|
skipped.len()
|
|
);
|
|
for s in &skipped {
|
|
eprintln!(" skipped {s}");
|
|
}
|
|
assert_eq!(ran, passed, "every example run passed");
|
|
for rule in bookspec_checker::covered_rules() {
|
|
assert_eq!(
|
|
report.rules.get(&rule.id),
|
|
Some(&bookspec_runner::Outcome::Pass),
|
|
"{}",
|
|
rule.id
|
|
);
|
|
}
|
|
assert!(
|
|
report
|
|
.rules
|
|
.values()
|
|
.any(|o| *o == bookspec_runner::Outcome::NotClaimed),
|
|
"a rule with no example is not claimed"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
pub(crate) fn every_bookspec_example_holds() {
|
|
let files = bookspec_checker::examples();
|
|
let mut ids = BTreeSet::new();
|
|
let mut checked: BTreeMap<String, usize> = BTreeMap::new();
|
|
let mut skipped = Vec::new();
|
|
for (name, text) in &files {
|
|
let ex = Example::from_toml(text).unwrap_or_else(|e| panic!("{name}: {e}"));
|
|
let stem = name.strip_suffix(".toml").unwrap();
|
|
assert_eq!(ex.id, stem, "{name}: the file is named for its id");
|
|
assert!(ids.insert(ex.id.clone()), "{}: id used twice", ex.id);
|
|
assert!(
|
|
!ex.title.is_empty() && !ex.rule.is_empty() && !ex.tags.is_empty(),
|
|
"{}: title, rule and tags",
|
|
ex.id
|
|
);
|
|
assert!(
|
|
matches!(ex.status.as_str(), "AUTHORITY" | "CONVENTION" | "CHOICE"),
|
|
"{}: status {:?}",
|
|
ex.id,
|
|
ex.status
|
|
);
|
|
assert!(!ex.sources.is_empty(), "{}: every rule is sourced", ex.id);
|
|
assert!(!ex.expect.is_empty(), "{}: something to expect", ex.id);
|
|
// The examples for an option wanderbooks did not pick are for
|
|
// another engine; they are read (above) and not run.
|
|
if let Some(why) = unpicked_option(&ex) {
|
|
skipped.push(format!("{} {why}", ex.id));
|
|
continue;
|
|
}
|
|
for (q, by) in run(&ex) {
|
|
if let Some(by) = by {
|
|
eprintln!("{}: {q} is checked by {by}", ex.id);
|
|
}
|
|
*checked.entry(q).or_insert(0) += 1;
|
|
}
|
|
}
|
|
// Each query the examples use ran: the cash flow's seven examples at
|
|
// least, the as-of and 1099 examples', the members closes', the
|
|
// formats appendix's, and P3's default period, rename, tax category,
|
|
// parties, 1099, depreciation, schedules, asset basis and K-1 tax-basis
|
|
// examples'.
|
|
for (q, at_least) in [
|
|
("cash_flow", 7),
|
|
("trial_balance", 2),
|
|
("profit_and_loss", 2),
|
|
("vendor_1099_paid", 5),
|
|
("vendor_1099", 10),
|
|
("entry", 8),
|
|
("balances", 4),
|
|
("members_equity", 10),
|
|
("k1", 5),
|
|
("party_part", 28),
|
|
("party_totals", 23),
|
|
("party_tin_last4", 5),
|
|
("iif_lines", 1),
|
|
("iif_changes", 1),
|
|
("iif_line_ending", 1),
|
|
("setting", 1),
|
|
("role_account", 1),
|
|
("tax_summary", 1),
|
|
("period", 6),
|
|
("day", 1),
|
|
("calendar_year", 1),
|
|
("account_names", 2),
|
|
("uncategorized_accounts", 2),
|
|
("rename_account", 5),
|
|
("add_account", 4),
|
|
("set_tax_category", 2),
|
|
("run", 4),
|
|
("disposal", 5),
|
|
("depreciation_schedule", 5),
|
|
("schedule_plan", 3),
|
|
("register_row", 5),
|
|
("register_totals", 1),
|
|
("asset_basis", 6),
|
|
("asset_tag", 4),
|
|
("k1_tax_basis", 5),
|
|
("k1_reconciliation", 2),
|
|
("project", 6),
|
|
("aging", 4),
|
|
("document_dates", 8),
|
|
("document", 8),
|
|
("invoice_numbers", 1),
|
|
] {
|
|
let n = checked.get(q).copied().unwrap_or(0);
|
|
assert!(n >= at_least, "{q} ran {n} times, fewer than {at_least}");
|
|
}
|
|
eprintln!(
|
|
"bookspec examples: {} files, {} run, {} skipped (an option wanderbooks did not pick): {skipped:?}",
|
|
files.len(),
|
|
files.len() - skipped.len(),
|
|
skipped.len()
|
|
);
|
|
// The examples for an option wanderbooks did not pick: the other option
|
|
// of BS-arap-2 (documents-kept-apart), -7, -8, -9, -10 (compare-exactly),
|
|
// -11 (recovery-movement), -12 (net-of-expected-discount), -13
|
|
// (net-against-the-deposit) and -14 (apportion-across-the-lines),
|
|
// BS-prepaid-2's equal-months, BS-prepaid-4's cent rule and BS-ledger-20's
|
|
// refuse (each option's example, so no allow-list grows), BS-entry-6's
|
|
// check-only-when-posting and BS-ledger-17's reversal-needs-its-own
|
|
// (wanderbooks refuses a line on a header as it is added, and a reversal
|
|
// needs no evidence of its own), BS-format-5's file place, -6's one
|
|
// fiscal year, -8's closes-written and -4's platform line ending,
|
|
// BS-ledger-21's round-per-account, BS-period-4's allow-partial-overlap,
|
|
// BS-1099-2's carry-the-last-amount and BS-partner-8's nowhere
|
|
// (wanderbooks nests periods, refuses a year whose threshold it does not
|
|
// know, and keeps the full TIN outside the books), and X-H1e2's:
|
|
// BS-asset-3's no-tags, BS-partner-15's every-prepaid-is-cash and
|
|
// every-prepaid-is-property, BS-partner-17's left-open and BS-1099-5's
|
|
// whole-payment-to-each (wanderbooks keeps asset tags, counts a contract
|
|
// handed over as property and a vendor-paid service as cash, takes a
|
|
// prepaid contract into the tax capital at its book amount with a note,
|
|
// and counts only the payee's share of a shared entry).
|
|
assert_eq!(
|
|
skipped.len(),
|
|
27,
|
|
"the twenty-seven unpicked-option examples: {skipped:?}"
|
|
);
|
|
}
|