test(core): golden file for the tax summary

Golden for the Form 1065 first-quarter fixture (tax.rs books()), Jan 1 to
Mar 31. Every number was recomputed by hand from the entries
(plan/golden-worksheets/tax_summary_form_1065.md) before the engine's output
was compared:

Income: sales 10,000.00; refunds 250.00 are an expense-type account in an
income category, so a contra: -250.00 (Form 1065 line 1b). Income 9,750.00.
Deductions, book / deductible: fees 1,500 / 1,500; guaranteed payments
2,000 / 2,000; meals 333.33 at 50% = 166.665 = 166.67 (cent, half away from
zero; Schedule C line 24b: "in most cases, the percentage is 50%"); software
600 / 600; penalties 40 at 0% = 0 (Schedule C Part V: no deduction for
fines). Totals 4,473.33 book, 4,266.67 deductible. Misc 75.00 has no
category and is listed apart, in no total (B-32).
Book net 9,750.00 - 4,473.33 = 5,276.67; tax net 9,750.00 - 4,266.67 =
5,483.33; the 206.66 difference is the disallowed meals half (166.66) plus
penalties (40.00).

Decimals compare by value (normalized), as the existing snapshot golden
writes them; no existing golden or assertion changed.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Sonnet 5.5 committed 2026-11-07 09:54:39 -07:00
1 parent 5c7055123d
commit 545a502d3d
3 files changed
+232

No files matched your search

@@ -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"
}
+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,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.