merge: golden files for the members' equity statement and the Form 1065 tax summary (branch t3/golden-equity-tax-reports, 545a502d; reviewed and recomputed independently)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Opus 5.5 committed 2026-11-07 10:04:46 -07:00
commit baf4c8ae0d
6 files changed
+504

No files matched your search

@@ -0,0 +1,70 @@
{
"january": {
"start": "2026-01-01",
"end": "2026-01-31",
"members": [
{
"name": "Alice",
"beginning": "0",
"contributions": "600",
"net_income": "333.34",
"distributions": "0",
"other": "0",
"ending": "933.34"
},
{
"name": "Bob",
"beginning": "0",
"contributions": "400",
"net_income": "333.33",
"distributions": "0",
"other": "0",
"ending": "733.33"
}
],
"total": {
"name": "Total",
"beginning": "0",
"contributions": "1000",
"net_income": "666.67",
"distributions": "0",
"other": "0",
"ending": "1666.67"
},
"balance_sheet_equity": "1666.67"
},
"february": {
"start": "2026-02-01",
"end": "2026-02-28",
"members": [
{
"name": "Alice",
"beginning": "933.34",
"contributions": "0",
"net_income": "50",
"distributions": "0",
"other": "0",
"ending": "983.34"
},
{
"name": "Bob",
"beginning": "733.33",
"contributions": "0",
"net_income": "50.01",
"distributions": "100",
"other": "0",
"ending": "683.34"
}
],
"total": {
"name": "Total",
"beginning": "1666.67",
"contributions": "0",
"net_income": "100.01",
"distributions": "100",
"other": "0",
"ending": "1666.68"
},
"balance_sheet_equity": "1666.68"
}
}
@@ -0,0 +1,70 @@
{
"start": "2026-01-01",
"end": "2026-03-31",
"form": "form1065",
"income": [
{
"category": "gross_receipts",
"label": "Gross receipts or sales",
"accounts": ["4000 Sales"],
"book": "10000",
"tax": "10000"
},
{
"category": "returns_allowances",
"label": "Returns and allowances",
"accounts": ["4100 Refunds"],
"book": "-250",
"tax": "-250"
}
],
"cost_of_goods": [],
"deductions": [
{
"category": "commissions_fees",
"label": "Commissions and fees",
"accounts": ["6000 Platform fees"],
"book": "1500",
"tax": "1500"
},
{
"category": "guaranteed_payments",
"label": "Guaranteed payments to partners",
"accounts": ["6400 Partner pay"],
"book": "2000",
"tax": "2000"
},
{
"category": "meals",
"label": "Meals",
"accounts": ["6100 Meals"],
"book": "333.33",
"tax": "166.67"
},
{
"category": "other_deductions",
"label": "Other deductions",
"accounts": ["6300 Software"],
"book": "600",
"tax": "600"
},
{
"category": "nondeductible",
"label": "Nondeductible expenses",
"accounts": ["6200 Penalties"],
"book": "40",
"tax": "0"
}
],
"separately_stated": [],
"form_4797": [],
"uncategorized": [
{
"account": "6500 Misc",
"account_type": "Expense",
"book": "75"
}
],
"book_net": "5276.67",
"tax_net": "5483.33"
}
+61
View File
@@ -512,6 +512,67 @@ fn members_equity_rolls_capital_forward_and_ties_to_the_balance_sheet() {
}
}
/// Every decimal string in `v`, by value (`"50.00"` and `"50"` are one
/// number), as `snapshot` writes them. Both sides of a golden comparison go
/// through it, so a harmless difference of written scale is no failure and
/// every value must still agree exactly.
fn by_value(v: &mut serde_json::Value) {
match v {
serde_json::Value::String(s) => {
if let Ok(x) = Decimal::from_str(s) {
*s = x.normalize().to_string();
}
}
serde_json::Value::Array(items) => items.iter_mut().for_each(by_value),
serde_json::Value::Object(map) => map.values_mut().for_each(by_value),
_ => {}
}
}
/// The statement as JSON, with the balance sheet's total equity beside it.
fn statement_json(
l: &Ledger,
start: NaiveDate,
end: NaiveDate,
members: &[MemberCapital],
) -> serde_json::Value {
let st = members_equity(l, start, end, members).unwrap();
let mut v = serde_json::to_value(&st).unwrap();
v["balance_sheet_equity"] =
serde_json::to_value(balance_sheet_as_of(l, end).unwrap().total_equity).unwrap();
by_value(&mut v);
v
}
/// The golden: every number in `golden/members_equity_two_member.json` was
/// computed by hand, from the entries, in
/// `plan/golden-worksheets/members_equity_two_member.md`, before the engine's
/// output was looked at. Rules: B-13 (capital account = contributions +
/// allocated income − distributions; cent rounding by largest remainder, the
/// odd cent to the member listed first; unclosed earnings split cumulatively)
/// and B-7 (the Total ties to balance-sheet equity). The same numbers hold
/// whether or not January is closed (B-13: a member's capital on a date never
/// moves when its period closes).
#[test]
fn golden_members_equity_two_member() {
let mut golden: serde_json::Value =
serde_json::from_str(include_str!("golden/members_equity_two_member.json")).unwrap();
by_value(&mut golden);
for close in [false, true] {
let (l, members) = partnership(close);
assert_eq!(
statement_json(&l, d(1, 1), d(1, 31), &members),
golden["january"],
"January, close={close}"
);
assert_eq!(
statement_json(&l, d(2, 1), d(2, 28), &members),
golden["february"],
"February, close={close}"
);
}
}
#[test]
fn members_must_be_configured_correctly() {
let (l, mut members) = partnership(false);
+40
View File
@@ -145,6 +145,46 @@ fn the_summary_groups_by_category_and_applies_deductible_percents() {
assert_eq!(ts.tax_net(), dec("5483.33"));
}
/// Every decimal string in `v`, by value (`"0.00"` and `"0"` are one
/// number), as `snapshot` writes them. Both sides of a golden comparison go
/// through it, so a harmless difference of written scale is no failure and
/// every value must still agree exactly.
fn by_value(v: &mut serde_json::Value) {
match v {
serde_json::Value::String(s) => {
if let Ok(x) = Decimal::from_str(s) {
*s = x.normalize().to_string();
}
}
serde_json::Value::Array(items) => items.iter_mut().for_each(by_value),
serde_json::Value::Object(map) => map.values_mut().for_each(by_value),
_ => {}
}
}
/// The golden: every number in `golden/tax_summary_form_1065.json` was
/// computed by hand, from the fixture's entries, in
/// `plan/golden-worksheets/tax_summary_form_1065.md`, before the engine's
/// output was looked at. Rules: B-32 and `sources/irs-tax-lines.md` (the
/// category-to-line map; a contra-income expense account reduces receipts;
/// meals at 50% from the Schedule C line 24b instructions, so 333.33 is
/// 166.665, the cent half away from zero, 166.67; fines and penalties at 0%
/// from Schedule C Part V; an account with no category is listed, in no
/// total). `book_net` and `tax_net` are methods, so the test adds them.
#[test]
fn golden_tax_summary_form_1065() {
let l = books();
let ts = tax_summary(&l, d(1, 1), d(3, 31), Some(TaxForm::Form1065)).unwrap();
let mut actual = serde_json::to_value(&ts).unwrap();
actual["book_net"] = serde_json::to_value(ts.book_net()).unwrap();
actual["tax_net"] = serde_json::to_value(ts.tax_net()).unwrap();
by_value(&mut actual);
let mut golden: serde_json::Value =
serde_json::from_str(include_str!("golden/tax_summary_form_1065.json")).unwrap();
by_value(&mut golden);
assert_eq!(actual, golden);
}
#[test]
fn an_override_beats_the_category_default() {
let mut l = books();
@@ -0,0 +1,141 @@
# Golden worksheet: statement of changes in members' equity (two members, with rounding and a close)
Golden: `crates/ledger-core/tests/golden/members_equity_two_member.json`
Test: `crates/ledger-core/tests/statements.rs` fn `golden_members_equity_two_member`
Fixture: `partnership(close_january)` in the same file (existing; not changed).
Every number below was computed by hand from the entries before the golden
was written or the report was printed.
## Rules relied on (docs/spec/rules.md)
- **B-13** (26 U.S.C. §704(a); Treas. Reg. §1.704-1(b)(2)(iv)(b); Form 1065
Schedule M-2): a partner's capital account is one running balance
= contributions + allocations of income − distributions. AUTHORITY.
- Share of income: by the agreement (here 1/2 each).
- Rounding a share to the cent: **no authority**; CHOICE (owner, 2026-10-13):
largest remainder, a tied odd cent to the member listed first.
- The statement splits *undistributed earnings cumulatively* (CHOICE, D-38):
a member's earnings share as of a date d is allocate(C + U(d)) − allocate(C),
with C = 0 here (no members close ever happens: the fixture's close goes to
Retained Earnings, which "allocates nothing to the members"), U(d) = the
partnership's undistributed earnings to date.
- Statement INVARIANT 3a: a member's ending equals their beginning on the
next statement, exactly.
- **B-11**: revenue and expenses close into P&L, then capital; the close is not
income or spending (so it is not a contribution).
- **B-7 / B-6**: accounting equation / trial balance: used to tie the Total
column to balance-sheet equity.
## Fixture entries (all USD, shares 1/2 and 1/2, Alice listed first)
Accounts: 1000 Cash (asset), 3000 Capital — Alice, 3001 Capital — Bob
(equity), 4000 Revenue, 6000 Expense.
| # | date | Dr | Cr | amount |
|---|--------|---------------------|----------------------|--------|
| 1 | Jan 2 | 1000 Cash | 3000 Alice capital | 600.00 |
| 2 | Jan 2 | 1000 Cash | 3001 Bob capital | 400.00 |
| 3 | Jan 10 | 1000 Cash | 4000 Revenue | 1000.00 |
| 4 | Jan 20 | 6000 Expense | 1000 Cash | 333.33 |
| – | Jan 31 | (variant only) close of January to Retained Earnings 3999: Dr 4000 1000.00, Cr 6000 333.33, Cr 3999 666.67 |
| 5 | Feb 5 | 3001 Bob capital | 1000 Cash | 100.00 |
| 6 | Feb 9 | 1000 Cash | 4000 Revenue | 100.01 |
The statement must be the same whether or not January is closed (INVARIANT
3c, B-13: "a member's capital on a date never moves when a period ending on
or before it is later closed"), so the golden is one set of numbers asserted
against both variants.
## January 1 – January 31
Beginning: nothing posted before Jan 1: capital 0 and undistributed earnings 0
for both. Beginning = 0.00 / 0.00.
Contributions (credits to the member's own capital account in the span, no
close, no reversal): Alice 600.00 (entry 1), Bob 400.00 (entry 2).
Distributions: none.
Net income for the period = revenue − expense = 1000.00 − 333.33 = **666.67**.
Share, cumulative to the cent. Work in cents: 66667. Exact half = 33333.5.
Floor each: 33333 + 33333 = 66666; 1 cent left over. Both have the same
remainder (0.5): a tie, so the odd cent goes to the member listed first,
Alice. Alice 33334 cents = **333.34**, Bob 33333 cents = **333.33**.
(333.34 + 333.33 = 666.67 ✓.)
Because there are no earlier statements, each member's income for the period
is their cumulative share minus their beginning share (0).
| column | Alice | Bob | Total |
|---------------|--------|--------|---------|
| beginning | 0.00 | 0.00 | 0.00 |
| contributions | 600.00 | 400.00 | 1000.00 |
| net income | 333.34 | 333.33 | 666.67 |
| distributions | 0.00 | 0.00 | 0.00 |
| other | 0.00 | 0.00 | 0.00 |
| ending | 933.34 | 733.33 | 1666.67 |
Roll-forward per row: Alice 0 + 600 + 333.34 − 0 = 933.34 ✓;
Bob 0 + 400 + 333.33 − 0 = 733.33 ✓.
"Other" is the part of the change in equity not explained by contributions,
distributions or income. Change in equity Jan 1→Jan 31 = 1666.67 − 0;
explained = contributions 1000 − distributions 0 + NI 666.67 = 1666.67.
Unexplained 0.00 ✓.
Tie to the balance sheet (B-7): total equity at Jan 31 = capital 600 + 400
+ earnings 666.67 (current earnings in the unclosed variant, retained earnings
3999 in the closed one) = **1666.67** = Total ending ✓. (Assets: cash
600 + 400 + 1000 − 333.33 = 1666.67, no liabilities: the equation holds.)
## February 1 – February 28
Beginning = each member's ending on Jan 31 (INVARIANT 3a):
Alice 933.34, Bob 733.33; total 1666.67.
Contributions: none (entry 5 debits Bob's capital; entry 6 is revenue).
Distributions: Bob 100.00 (entry 5 debits his capital account; the Jan 31
close, in the closed variant, is not a distribution: B-11). Alice 0.
Net income for February = 100.01 (revenue, no expense).
Cumulative undistributed earnings to Feb 28: 666.67 + 100.01 = 766.68
= 76668 cents. Half = 38334 cents exactly, no remainder, no tie. So each
member's cumulative share is **383.34**.
Month income per member = cumulative share to Feb 28 − cumulative share to
Jan 31:
- Alice: 383.34 − 333.34 = **50.00**.
- Bob: 383.34 − 333.33 = **50.01**.
Sum 100.01 = February net income ✓ (INVARIANT 3b).
| column | Alice | Bob | Total |
|---------------|--------|--------|---------|
| beginning | 933.34 | 733.33 | 1666.67 |
| contributions | 0.00 | 0.00 | 0.00 |
| net income | 50.00 | 50.01 | 100.01 |
| distributions | 0.00 | 100.00 | 100.00 |
| other | 0.00 | 0.00 | 0.00 |
| ending | 983.34 | 683.34 | 1666.68 |
Roll-forward: Alice 933.34 + 0 + 50.00 − 0 = 983.34 ✓;
Bob 733.33 + 0 + 50.01 − 100.00 = 683.34 ✓.
Cross-check each ending from first principles, from inception:
Alice 600 contributed + 383.34 earnings − 0 = 983.34 ✓;
Bob 400 + 383.34 − 100 = 683.34 ✓.
"Other": change in equity = 1666.68 − 1666.67 = 0.01; explained = 0 − 100.00 +
100.01 = 0.01. Unexplained 0.00 ✓.
Tie to balance sheet: equity at Feb 28 = 1000 contributed + 766.68 earnings
− 100 distributed = **1666.68** = Total ending ✓. (Cash: 1666.67 − 100 + 100.01
= 1666.68 ✓.)
## Golden file contents
Per statement: `start`, `end`, one column per member in the order given,
`total`, and `balance_sheet_equity` (hand-computed above, compared with the
engine's balance sheet total_equity). Amounts are decimal strings,
normalized (no trailing zeros), as the existing `snapshot` golden does: the
test normalizes both sides so a harmless scale difference ("0" vs "0.00")
is not a failure but every value must still agree exactly.
@@ -0,0 +1,122 @@
# Golden worksheet: tax line mapping + tax summary (Form 1065 first quarter)
Golden: `crates/ledger-core/tests/golden/tax_summary_form_1065.json`
Test: `crates/ledger-core/tests/tax.rs` fn `golden_tax_summary_form_1065`
Fixture: `books()` in the same file (existing; not changed). Summary asked
for 2026-01-01 .. 2026-03-31 as Form 1065.
Every number below was computed by hand from the entries before the golden
was written or the report was printed.
## Rules relied on
- **B-32** (docs/spec/rules.md; IRS Pub. 583, Pub. 538, Rev. Proc. 98-25):
every revenue and expense account maps to a line of the return; an account
with none is listed, not silently dropped.
- **B-11 / B-14**: the summary covers a period, built from the P&L (closing
entries excluded). Book amounts are the accounts' normal-side balances
(revenue credits, expense debits).
- Category-to-line mapping: `docs/spec/sources/irs-tax-lines.md`
(derived from the Schedule C / Form 1065 / 1120-S / 1120 instructions;
vendored). Relevant rows:
- Form 1065 line 1a "Gross receipts or sales", line 1b "Returns and
allowances": returns reduce gross receipts (income).
- Form 1065 line 10 "Guaranteed payments to partners": a deduction on
Form 1065 only.
- `commissions_fees`, `other_deductions`: deductions (Form 1065 line 21).
- `meals`: Schedule C line 24b instructions: "Your deductible business meal
expenses are a percentage of your actual business meal expenses ... In most
cases, the percentage is 50%." AUTHORITY for 50%.
- `nondeductible`: Schedule C Part V: "you can't deduct fines or penalties
paid to a government for violating any law." AUTHORITY for 0% (no line).
- **Cent rounding of a deductible amount** is NOT stated by any authority in
rules.md (see "Observations" below). Applied here: the cent, half away from
zero (the engine's documented rule, `tax_summary` doc; B-3's half-away-
from-zero for currency). Only the meals line needs it.
- Display order of categories is the catalog order in `tax::CATEGORIES`
(a presentation convention, not an accounting number): income
gross_receipts, returns_allowances; deductions commissions_fees,
guaranteed_payments, meals, other_deductions, nondeductible.
## Fixture entries (all USD, all dated Feb 1; each is Dr X / Cr Cash or the reverse)
| # | entry | Dr | Cr | amount |
|----|------------------------------------|----------------|-------------|-----------|
| 1 | sales | 1000 Cash | 4000 Sales | 10,000.00 |
| 2 | refunds | 4100 Refunds | 1000 Cash | 250.00 |
| 3 | platform fees | 6000 Fees | 1000 Cash | 1,500.00 |
| 4 | meals | 6100 Meals | 1000 Cash | 333.33 |
| 5 | penalties | 6200 Penalties | 1000 Cash | 40.00 |
| 6 | software | 6300 Software | 1000 Cash | 600.00 |
| 7 | partner pay | 6400 Partner pay | 1000 Cash | 2,000.00 |
| 8 | misc (no tax category) | 6500 Misc | 1000 Cash | 75.00 |
Chart tags: 4000 Sales (Revenue) gross_receipts; 4100 Refunds (**Expense**
type) returns_allowances; 6000 commissions_fees; 6100 meals (catalog default
50%); 6200 nondeductible (default 0%); 6300 other_deductions; 6400
guaranteed_payments; 6500 none. No account sets its own deductible percent
override, so each uses its category's default.
## Hand computation
Book amount is the account's normal-side balance for the period. One account
per category here, so category = account.
### Income
- gross_receipts (4000 Sales): revenue credit 10,000.00. Book 10,000.00.
Percent 100 → tax 10,000.00.
- returns_allowances (4100 Refunds): the account is an *expense* account
(debit 250.00) in an *income* category, so it counts with its sign flipped: a
contra to income reduces gross receipts (Form 1065 line 1b is subtracted
from 1a). Book −250.00. 100% → tax −250.00.
- Income total: book 10,000 − 250 = 9,750.00; tax 9,750.00.
### Cost of goods sold: none. Separately stated (Schedule K): none. Form 4797: none.
### Deductions
| category | account | book | percent | tax (exact) | tax (cent) |
|---------------------|--------------------|---------|---------|---------------|-------------|
| commissions_fees | 6000 Platform fees | 1500.00 | 100 | 1500.00 | 1500.00 |
| guaranteed_payments | 6400 Partner pay | 2000.00 | 100 | 2000.00 | 2000.00 |
| meals | 6100 Meals | 333.33 | 50 | 333.33×0.5 = 166.665 | **166.67** (half away from zero) |
| other_deductions | 6300 Software | 600.00 | 100 | 600.00 | 600.00 |
| nondeductible | 6200 Penalties | 40.00 | 0 | 0.00 | 0.00 |
Deductions total: book 1500 + 2000 + 333.33 + 600 + 40 = **4,473.33**;
tax 1500 + 2000 + 166.67 + 600 + 0 = **4,266.67**.
### Uncategorized
6500 Misc (Expense), book 75.00: no category, so it is listed (B-32) and is in
no total (the nets are "of the categorized accounts").
### Nets
- Book net = income book − deductions book = 9,750.00 − 4,473.33 = **5,276.67**.
- Tax net = 9,750.00 − 4,266.67 = **5,483.33**.
- Book-to-tax difference = 5,483.33 − 5,276.67 = 206.66
= the disallowed half of meals (333.33 − 166.67 = 166.66)
+ penalties (40.00) = 206.66 ✓ (the Schedule M-1 items).
- Cross-check with the whole P&L: all accounts' net = 9,750 − 4,473.33 − 75
= 5,201.67 (the categorized net 5,276.67 less the uncategorized 75.00 ✓).
## Golden file contents
The serialized `TaxSummary` (start, end, form, income, cost_of_goods,
deductions, separately_stated, form_4797, uncategorized) plus two keys the
test adds from the hand numbers above: `book_net` and `tax_net` (methods on
the report, not serialized fields). `accounts` lists "CODE Name" of the
accounts that roll into a category; `label` is the catalog's label (the
return's own line name). Decimals compare by value (normalized, as the
existing `snapshot` golden writes them).
## Observations (not disagreements; nothing in the golden depends on them)
- No rule in `docs/spec/rules.md` states how a deductible fraction rounds to
the cent (only the code's doc comment does). B-21 says "round off only the
total" on the return. With one account per category the two approaches agree
(166.665 → 166.67 either way); with several accounts in one category the
engine rounds each account and sums, which can differ from rounding the
category's sum by a cent per account. Worth a CONVENTION entry in rules.md.