Repository navigation
chore(test): pin BQL BALANCES == report balances on netted reductions - #1733
Merged
Merged
Conversation
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]>
Contributor
📊 Benchmark Results
vs main branch (2026-07-10)
What do these numbers mean?
|
Contributor
There was a problem hiding this comment.
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
BALANCESvsreport balanceson 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.
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-matchingapply(#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:
5 AAPL {150.00}{}reduction across two lots → both surfaces: single netted5 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