Skip to content

chore(test): pin BQL BALANCES == report balances on netted reductions - #1733

Merged
robcohen merged 2 commits into
mainfrom
chore/query-report-realization-parity
Jul 10, 2026
Merged

robcohen merged 2 commits into
mainfrom
chore/query-report-realization-parity

Conversation

@robcohen

@robcohen robcohen commented Jul 9, 2026

Copy link
Copy Markdown
Member

Drift guard from the Phase-0 duplication sweep (realization family). Test-only.

Why

The two surfaces realize balances differently by construction: the query executor re-aggregates already-booked postings with naive Inventory::add (lot-key netting), while reports realize through the booking engine's lot-matching apply (#1728). They agree today ONLY because both consume post-booking directives — the loader's book phase has already matched every reduction against its lot, so naive re-aggregation lands on the same keys.

That invariant holds by pipeline design, not by any check. Probed empirically before writing this: BQL BALANCES == beanquery == booked report on both reduction shapes — so this is a pin, not a fix. Feeding the executor unbooked directives (a new embedding path, a harness shortcut) would silently reactivate the #1726 netting class in BQL while reports stayed correct — and nothing would catch it.

What

Two tests on the #1726 reduction shapes:

  • explicit-cost reduction + price annotation → both surfaces: single netted 5 AAPL {150.00}
  • FIFO empty-{} reduction across two lots → both surfaces: single netted 5 AAPL {200.00}

Asserts exactly one AAPL row per surface (the pre-#1726 failure shape was split augment/reduce rows), identical (units, lot-cost) across surfaces, at the beancount-3.2.3-verified values. The failure message points to the duplication registry's realization family so nobody "fixes" one side alone.

clippy 0, fmt clean.

🤖 Generated with Claude Code

Drift guard from the Phase-0 duplication sweep (realization family, Z2).
The two surfaces realize balances differently by construction — query
re-aggregates booked postings with naive Inventory::add; reports realize
through the booking engine — and agree today ONLY because both consume
post-booking directives. That invariant holds by pipeline design, not by
any check: feeding the executor unbooked directives would silently
reactivate the #1726 netting class in BQL while reports stayed correct.

Pins agreement on the two #1726 reduction shapes (explicit-cost + price;
FIFO empty-{} across two lots), asserting a single netted AAPL row with
identical units and lot cost on both surfaces, at the beancount-verified
values (5 @ 150.00 / 5 @ 200.00).

Co-Authored-By: Claude Fable 5 <[email protected]>
Copilot AI review requested due to automatic review settings July 9, 2026 16:34
@robcohen
robcohen requested a review from a team as a code owner July 9, 2026 16:34
@github-actions

github-actions Bot commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Tool Time Memory
rustledger 33.8ms ± 0.7ms 23.8 MB
beancount 759.2ms ± 4.9ms 50.5 MB
Comparison 22.5x faster 2.1x less

vs main branch (2026-07-10)

Metric main this PR Change
Time 33.7ms 33.8ms +0.3% ✅
10K transactions · 5 runs, 2 warmup · hyperfine
What do these numbers mean?
  • Time: Wall-clock time to parse and validate the ledger (± std dev)
  • Memory: Peak resident set size (RSS)
  • vs main: Compared to latest nightly benchmark on main branch

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an integration-test drift guard to ensure BQL BALANCES and rledger report balances continue to agree on realized (netted) holdings for reduction shapes that previously produced split augment/reduce results (#1726). This helps catch future pipeline/embedding changes that accidentally feed unbooked directives into the BQL executor while reports still realize via the booking engine.

Changes:

  • Introduces a new parity test that compares BQL BALANCES vs report balances on the same fixture and asserts they produce exactly one netted AAPL holding line each.
  • Adds two fixtures covering: (1) explicit-cost reduction with price annotation, (2) FIFO empty-{} reduction spanning two lots, pinned to beancount 3.2.3-verified values.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions

github-actions Bot commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100%
Full AST Match 100%
Total Files 811
What's tested
  • Check: Exit codes and error counts match bean-check
  • BQL: Query results match bean-query
  • Files: ~800 test files downloaded from 10+ beancount repositories

Full results available in workflow artifacts

@codecov

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@robcohen
robcohen merged commit 3263fa2 into main Jul 10, 2026
41 checks passed
@robcohen
robcohen deleted the chore/query-report-realization-parity branch July 10, 2026 09:11
robcohen added a commit that referenced this pull request Jul 10, 2026
…1750)

* feat(report): render numbers through the ledger DisplayContext (U4)

Balance-style reports (balances, balsheet, income, holdings, networth)
printed raw Decimal Display, whose precision is an artifact of booking
arithmetic rather than ledger convention: an integer-written posting
in a 2dp ledger showed "100 USD" where bean-query (and our own BQL
output, context-aware since #961/#985) shows "100.00 USD".

LoadedReport now carries the loader's DisplayContext (per-currency
inferred precision under the MostCommon policy, display_precision
overrides, render_commas) and the five reports format every units
number and total through format_amount_number — one rendering shared
by text, CSV, and JSON arms. Lot-cost annotations keep their existing
Display form (pinned to bean-query's Position string in #1728/#1733).

Verified byte-identical against beancount 3.2.3 bean-query BALANCES on
a mixed-precision fixture, including both directions of the MostCommon
policy: 2dp-dominant ledgers pad integers to 100.00, integer-dominant
ledgers render 2400 — matching bean-query in each case. New
integration test pins the padded rendering and CSV consistency; full
CLI suite (incl. the #1733 query==report parity guard) green.

Co-Authored-By: Claude Fable 5 <[email protected]>

* fix: csv-escape context-formatted amounts; square balsheet CSV row (review)

render_commas puts thousands separators inside formatted numbers, so
every CSV arm writing them raw produced rows with extra columns — all
five reports now csv_escape the numeric fields (RFC-4180 quoting).
Also the balsheet Net Worth CSV row gains its empty trailing cost
field to match the five-column header. New test drives
option "render_commas" "TRUE" end-to-end and asserts quoted amounts
plus quote-aware column counts on every row.

Co-Authored-By: Claude Fable 5 <[email protected]>

---------

Co-authored-by: Claude Fable 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants