merge: the adapter runs payouts, asset tags, prepaid contributions and several payees (X-H1e2's wanderbooks half; reviewed)

Wanderbooks passes every bookspec example for its picks: 112 run, 112
passed, 27 for options it did not pick. A payout goes through the same
payout_plan the MCP tool uses, a tag through Store::set_asset_tag, the
K-1 contribution columns and the 1099 payments through the worksheet and
the report. No engine change. The claims say what the engine does not do
for BS-asset-9 (no 704(c) method unless a command gives one) and
BS-partner-16 (members are a setting handed to each close).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Opus 5.5 committed 2026-11-09 12:36:03 -07:00
commit 26a9ddf6cf
13 files changed
+177 -19

No files matched your search

@@ -32,6 +32,7 @@ pub(crate) fn check(b: &Books<'_>, x: &Expect) -> Option<&'static str> {
"depreciation_schedule",
"register_row",
"asset_basis",
"asset_tag",
],
);
only(x.schedule.is_some(), "schedule", &["schedule_plan"]);
@@ -130,6 +131,7 @@ pub(crate) fn check(b: &Books<'_>, x: &Expect) -> Option<&'static str> {
"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),
@@ -187,6 +187,16 @@ pub(crate) fn refusal(e: &LedgerError) -> String {
LedgerError::ControlAccountMismatch { .. } => "role_account_mismatch",
// A 1099 threshold for a year the books do not know (BS-1099-2).
LedgerError::RuleNotKnown { .. } => "unknown_1099_year",
// A platform's payout whose deposit is not gross less fee
// (BS-revenue-1): `payout_plan` refuses it for no other reason that
// the examples name.
LedgerError::InvalidPayout(why) if why.starts_with("payout doesn't reconcile") => {
"payout_does_not_reconcile"
}
// A tag of a wrong form, and one another asset holds or ever held
// (BS-asset-3).
LedgerError::InvalidAssetTag { .. } => "asset_tag_invalid",
LedgerError::AssetTagTaken { .. } => "asset_tag_taken",
other => return format!("another refusal: {other}"),
}
.to_string()
+52 -3
View File
@@ -26,11 +26,13 @@ impl Books<'_> {
("discard_draft", e.discard_draft.is_some()),
("assign_role", e.assign_role.is_some()),
("set_setting", e.set_setting.is_some()),
("payout", e.payout.is_some()),
("tag_asset", e.tag_asset.is_some()),
];
match kinds.iter().filter(|(_, given)| *given).collect::<Vec<_>>()[..] {
[(kind, _)] => kind,
_ => panic!(
"{} event {n}: an event is one of lines, reverses, close, bill, invoice, write_off, payment, settlement, recovery, run_depreciation, dispose_asset, run_schedules, register_schedule, post_draft, set_draft_state, attach_receipt, discard_draft, assign_role or set_setting",
"{} event {n}: an event is one of lines, reverses, close, bill, invoice, write_off, payment, settlement, recovery, run_depreciation, dispose_asset, run_schedules, register_schedule, post_draft, set_draft_state, attach_receipt, discard_draft, assign_role, set_setting, payout or tag_asset",
self.ex.id
),
}
@@ -43,7 +45,10 @@ impl Books<'_> {
// An entry of the example's own words: dated and described. A
// disposal is dated; the other commands date their own entries,
// and every command describes its own.
let own = matches!(kind, "lines" | "reverses" | "close" | "bill" | "invoice");
let own = matches!(
kind,
"lines" | "reverses" | "close" | "bill" | "invoice" | "payout"
);
let dated = own
|| matches!(
kind,
@@ -198,7 +203,10 @@ impl Books<'_> {
let ex = self.ex.id.as_str();
let kind = self.event_kind(n, e);
let what = format!("{ex} event {n}");
let own = matches!(kind, "lines" | "reverses" | "close" | "bill" | "invoice");
let own = matches!(
kind,
"lines" | "reverses" | "close" | "bill" | "invoice" | "payout"
);
let head = self.store.head();
let first = self.l().next_entry_id();
let result = self.apply_event(n, e);
@@ -412,6 +420,47 @@ impl Books<'_> {
"{what}: wanderbooks has no draft reversal: it picks reversal-evidence-is-originals (BS-ledger-17), under which a reversal posts at once"
),
))),
// A platform's payout (BS-revenue-1): the engine's own plan of its
// lines (`payout_plan`, which refuses unless gross - fee equals the
// deposit to the cent), posted as one entry. The plan is made
// before anything is journaled, so a refused payout leaves nothing.
"payout" => {
let p = e.payout.as_ref().expect("checked: a payout");
let line = |account: &str, amount: &str| ledger_core::PayoutLine {
account: self.id(account),
amount: exact(amount, what),
class: None,
};
let payout = ledger_core::Payout {
deposit_account: self.id(&p.deposit_account),
deposit: exact(&p.deposit, what),
revenue: vec![line(&p.revenue_account, &p.gross)],
fees: match (&p.fee, &p.fee_account) {
(Some(fee), Some(account)) => vec![line(account, fee)],
_ => Vec::new(),
},
adjustments: Vec::new(),
};
let (plan, _) = ledger_core::payout_plan(&payout, self.store.ledger().chart())?;
let entry = self.store.create_entry(day(), description)?;
for (account, side, amount, _class) in plan {
self.store
.add_line(entry, account, side, Money::new(amount, self.currency))?;
}
if self.has_policy() {
self.store.post_entry_checked(entry)
} else {
self.store.post_entry(entry)
}
}
// A tag put on an asset (BS-asset-3): the engine's own command,
// which refuses a tag of a wrong form and one another asset holds
// or ever held.
"tag_asset" => {
let t = e.tag_asset.as_ref().expect("checked: a tag");
let asset = self.asset(&t.asset, what);
self.store.set_asset_tag(asset, &t.tag)
}
"post_draft" => {
let p = e.post_draft.as_ref().expect("checked: a post");
let entry = self.entry_of(p.entry, what);
+13 -6
View File
@@ -115,12 +115,12 @@ pub(crate) fn every_bookspec_example_holds() {
("cash_flow", 7),
("trial_balance", 2),
("profit_and_loss", 2),
("vendor_1099_paid", 4),
("vendor_1099_paid", 5),
("vendor_1099", 10),
("entry", 8),
("balances", 4),
("members_equity", 10),
("k1", 3),
("k1", 5),
("party_part", 28),
("party_totals", 23),
("party_tin_last4", 5),
@@ -145,7 +145,8 @@ pub(crate) fn every_bookspec_example_holds() {
("register_row", 5),
("register_totals", 1),
("asset_basis", 6),
("k1_tax_basis", 4),
("asset_tag", 4),
("k1_tax_basis", 5),
("k1_reconciliation", 2),
("project", 6),
("aging", 4),
@@ -175,10 +176,16 @@ pub(crate) fn every_bookspec_example_holds() {
// 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).
// 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(),
22,
"the twenty-two unpicked-option examples: {skipped:?}"
27,
"the twenty-seven unpicked-option examples: {skipped:?}"
);
}
+3 -2
View File
@@ -8,7 +8,8 @@
//! its accounts, fixed assets, schedules, parties, members, payees,
//! payees' dated 1099 decisions and payment methods, every event (an
//! entry, a reversal, a close, a bill, or a command that posts what is
//! due: a depreciation run, a disposal, a schedule run or registration),
//! due: a depreciation run, a disposal, a schedule run or registration, a
//! platform's payout or an asset's tag),
//! each accepted or refused as it says, with the parties, payee and
//! payment method it is tagged with, and every change that posts no entry
//! (a rename, a policy, an asset's correction). The books are the
@@ -22,7 +23,7 @@
//! `party_part`, `party_totals`, `party_tin_last4`, `period`, `day`,
//! `calendar_year`, `account_names`, `uncategorized_accounts`, `run`,
//! `disposal`, `depreciation_schedule`, `schedule_plan`, `register_row`,
//! `register_totals`, `asset_basis`) are then checked value by value, and
//! `register_totals`, `asset_basis`, `asset_tag`) are then checked value by value, and
//! the commands it tries (`rename_account`, `add_account`,
//! `set_tax_category`) accepted or refused on a copy of the books, each
//! after the event it names (`after`) or the last; the formats appendix's
@@ -196,6 +196,19 @@ impl Books<'_> {
]))
}
/// The tag the asset carries, or `"none"` (BS-asset-3).
pub(crate) fn answer_asset_tag(&self, q: &Query) -> Result<Value, Refusal> {
let name = q.asset.as_deref().ok_or_else(|| self.missing("asset"))?;
let a = self
.l()
.get_asset(self.asset(name, name))
.expect("a registered asset");
Ok(json_figures([(
"tag".to_string(),
a.tag.clone().unwrap_or_else(|| "none".to_string()),
)]))
}
pub(crate) fn answer_asset_basis(&self, q: &Query) -> Result<Value, Refusal> {
let name = q.asset.as_deref().ok_or_else(|| self.missing("asset"))?;
let a = self
@@ -443,6 +456,25 @@ pub(crate) fn check_register_totals(b: &Books<'_>, x: &Expect) {
named(ex, x, &what, &figures);
}
/// Check one `asset_tag` expectation: the tag the asset carries now, or
/// `"none"` (BS-asset-3); every value listed.
pub(crate) fn check_asset_tag(b: &Books<'_>, x: &Expect) {
let ex = b.ex;
undated(ex, x);
let name = x
.asset
.as_deref()
.unwrap_or_else(|| panic!("{}: asset_tag names its asset", ex.id));
let what = format!("{} asset_tag of {name}", ex.id);
let a = b
.l()
.get_asset(b.asset(name, &what))
.expect("a registered asset");
exactly(ex, x, &BTreeSet::from(["tag".to_string()]));
let got = a.tag.clone().unwrap_or_else(|| "none".to_string());
assert_eq!(got, x.figures(&ex.id)["tag"], "{what}: tag");
}
/// Check one `asset_basis` expectation: the asset's basis facts and the
/// tax figures they give (BS-asset-4): `rule`,
/// `contributor_adjusted_basis`, `fmv_at_contribution`, `tax_basis_723`,
@@ -104,6 +104,7 @@ impl Books<'_> {
"register_row" => self.answer_register_row(q),
"register_totals" => self.answer_register_totals(q),
"asset_basis" => self.answer_asset_basis(q),
"asset_tag" => self.answer_asset_tag(q),
"period" => {
let (from, to) = self.q_period(q)?;
Ok(json_figures([
@@ -43,6 +43,10 @@ impl Books<'_> {
format!("{name}.contributions_cash"),
Value::String(figure(row.contributions_cash)),
);
m.insert(
format!("{name}.contributions_property_note"),
Value::String(property_note(&row.contributions_property).to_string()),
);
for (line, tax) in [
("beginning", &row.beginning),
("contributions_property", &row.contributions_property),
@@ -173,6 +177,10 @@ pub(crate) fn check_k1_tax_basis(b: &Books<'_>, x: &Expect) {
format!("{m}.contributions_cash"),
figure(row.contributions_cash),
);
figures.insert(
format!("{m}.contributions_property_note"),
property_note(&row.contributions_property).to_string(),
);
for (line, tax) in [
("beginning", &row.beginning),
("contributions_property", &row.contributions_property),
@@ -191,6 +199,23 @@ pub(crate) fn check_k1_tax_basis(b: &Books<'_>, x: &Expect) {
named(ex, x, &what, &figures);
}
/// The note a property line carries (BS-partner-17): `prepaid_at_book` when
/// property contributed to a prepaid account with no fixed asset behind it
/// was taken at its book amount for the preparer to confirm, `none` when the
/// line carries no note.
fn property_note(line: &ledger_core::tax_capital::TaxLine) -> &'static str {
use ledger_core::tax_capital::Note;
if line
.notes
.iter()
.any(|n| matches!(n, Note::PrepaidAtBook { .. }))
{
"prepaid_at_book"
} else {
"none"
}
}
/// The causes `k1_reconciliation` reports, each member's every one.
pub(crate) const RECONCILING_CAUSES: [&str; 5] = [
"beginning",
+6 -1
View File
@@ -69,7 +69,12 @@ option picked: a 2027 worksheet is refused through
`every_bookspec_example_holds` and
`the_runner_reports_every_claimed_rule_green`; the example for the option
not picked, `1099-a-worksheet-for-an-unpublished-year-carries-the-last-amount`,
is skipped.
is skipped; for BS-1099-5, `1099-an-entry-naming-two-parties-counts-the-payees-share`
(one check of 1,000.00 naming Dana Studio at 600.00 and a member at 400.00
counts 600.00 toward Dana, through `shares::resolve`), run likewise, and the
example for the option not picked,
`1099-an-entry-naming-two-parties-counts-the-whole-payment-to-each`, is
skipped.
### Product rules
+7 -2
View File
@@ -130,7 +130,12 @@ None.
**Checked:** `ledger-core` `tests/spec_asset_tags.rs`; `ledger-store`
`tests/asset_tags.rs` (`a_journaled_tag_taken_by_another_asset_is_refused_on_open`,
`a_retagged_assets_old_tag_is_never_reused`);
`ledger-cli` `tests/spec_assets.rs`.
`ledger-cli` `tests/spec_assets.rs`; the bookspec examples
`asset-a-tag-is-unique-ignoring-case-and-one-of-a-form` and
`asset-a-retagged-assets-old-tag-is-never-reused`, run through
`Store::set_asset_tag` by `every_bookspec_example_holds` and
`the_runner_reports_every_claimed_rule_green`; the example for the option not
picked, `asset-an-engine-that-keeps-no-tags-refuses-to-tag`, is skipped.
### Product rules
@@ -156,7 +161,7 @@ printer makes an Avery 5160 label sheet from the register's tags.
**Pick (BS-asset-7):** `books-recorded-amounts`, the owner, D-41, 2026-10-20.
**Pick (BS-asset-8):** `register-carries-tax-figures`, the owner, 2026-10-15; D-41, 2026-10-20.
**Pick (BS-asset-9):** `traditional`, the owner, D-41, 2026-10-20; recorded as a choice the CPA confirms.
**Pick (BS-asset-9):** `traditional`, the owner, D-41, 2026-10-20; recorded as a choice the CPA confirms. This is the books' convention, not an engine default: `Asset::sec704c_method` is left unset unless a command gives one, so no bookspec example shows the pick apart (the record's note says why).
**Enforced:** `kernel::basis_figures` (Kani `basis_figures_laws`),
`AssetBasis::check` (a purchase takes no contribution facts; a
+15 -3
View File
@@ -21,7 +21,7 @@ Rules: B-13, B-26, B-35, B-36.
**Pick (BS-partner-7):** `running-split`, the owner, D-38, 2026-10-20.
**Pick (BS-partner-15):** `contract-is-property-vendor-paid-is-cash`, the owner, 2026-10-15.
**Pick (BS-partner-16):** `close-at-the-change`, the owner, 2026-10-16.
**Pick (BS-partner-16):** `close-at-the-change`, the owner, 2026-10-16. The books close at the members a close is handed and a change of members or shares starts a new count of closes (`Ledger::members_regime`); no command closes a period at a change, so the pick states what the books do by convention at the close, and no bookspec example shows it (the record's note says why).
**Enforced:** `CloseTo::Members`, `CloseTo::MembersCumulative`,
`Ledger::members_regime`, `Regime::allocate`,
@@ -55,7 +55,13 @@ Rules: B-13, B-26, B-35, B-36.
`old_books_name_each_closes_rule_and_true_up_at_the_next_close`;
`ledger-gui` `a_members_page_shows_the_same_capital_before_and_after_a_close`,
`a_yen_members_page_splits_in_whole_yen`; the bookspec examples
`members-close.*`.
`members-close.*`, and for BS-partner-15 the example
`partner-a-prepaid-contract-is-property-and-a-vendor-paid-service-is-cash`
(a prepaid contract credited straight to capital is property, a prepaid
service paid through Due to Members is cash, by `k1_worksheet`), run by
`every_bookspec_example_holds`; the examples for the options not picked,
`partner-every-prepaid-service-is-cash` and
`partner-every-prepaid-service-is-property`, are skipped.
### Product rules
@@ -421,7 +427,13 @@ package); the odd cents, `ledger_core::tax_capital::RunningSplit` on
`ledger-package` `tests/package.rs`
(`the_k1_worksheet_reports_tax_basis_capital`), `tests/p3_seams.rs`
(`depreciation_is_one_figure_everywhere`,
`the_cpa_package_as_of_each_date_is_the_tools_figures`).
`the_cpa_package_as_of_each_date_is_the_tools_figures`); for BS-partner-17
the bookspec example
`partner-a-prepaid-contract-enters-the-tax-capital-at-its-book-amount-with-a-note`
(the contract's 1,500.00 each at its book amount, with the note
`Note::PrepaidAtBook`), run by `every_bookspec_example_holds`; the example for
the option not picked, `partner-a-prepaid-contract-is-left-open-in-the-tax-capital`,
is skipped.
### Product rules
+8 -1
View File
@@ -13,7 +13,14 @@ Rules: B-17.
**Claims:** yes
**Enforced:** `payouts::payout_plan`. **Checked:**
`a_payout_is_grossed_up_to_revenue_and_fees`.
`a_payout_is_grossed_up_to_revenue_and_fees`; the bookspec examples
`revenue-a-principals-payout-is-recorded-gross`,
`revenue-an-agents-payout-is-its-commission-only` and
`revenue-a-payout-that-does-not-reconcile-is-refused`, run through
`payouts::payout_plan` (a payout whose deposit is not gross less fee is
refused `InvalidPayout`, which the examples word payout_does_not_reconcile),
by `every_bookspec_example_holds` and
`the_runner_reports_every_claimed_rule_green`.
### Product rules
+3 -1
View File
@@ -246,7 +246,9 @@ an invoice's or bill's page (each line's project).
and `tests/format_upgrade.rs` (`books_p2_served_cut_over_whole`); bookspec
`projects-net-is-its-tagged-lines`,
`projects-on-spec-costs-are-expenses` and
`projects-invoice-and-bill-lines-count-by-project`; proptest
`projects-invoice-and-bill-lines-count-by-project` (also BS-statement-9's
rule-level example: one line per project, whose figures come out the same
under both of its options); proptest
`prop_document_parts_partition_the_total`; Kani `unrecovered_cost_laws`;
proptests `prop_project_nets_partition_the_pnl`,
`prop_project_set_round_trips`, `prop_project_contribution_is_the_net_to_date`