Repository navigation
fix: honor name_* account-root renames in reports and BQL (beanquery parity) - #1731
Merged
Merged
Conversation
…parity)
beancount lets a ledger rename its five root accounts (`option
"name_income" "Revenue"`); both engines accept such ledgers at
check-time, but every rledger consumer that classified accounts by
root did so against hardcoded prefixes. Two user-visible bugs:
- `report income` rendered an EMPTY income statement under a renamed
Income root (`starts_with("Income:")` misses "Revenue:Sales"); same
class in balsheet/holdings/networth routing.
- BQL `POSSIGN` diverged from beanquery: -100.00 vs beanquery's
+100.00 on a renamed credit-normal root (hardcoded
Liabilities|Equity|Income set). `ACCOUNT_SORTKEY` sorted renamed
roots as custom/5 where beanquery classifies them (index 3).
Fix: a single config-aware classifier, threaded everywhere:
- core: new `AccountTypes` (+ `AccountTypeKind`) — kind()/
is_balance_sheet()/is_income_statement()/is_credit_normal()/
sort_index() against the CONFIGURED names; Default = standard five.
- loader: `Options::to_account_types()`.
- reports: `LoadedReport` carries it; balsheet/income/holdings/
networth route by kind() — no hardcoded prefixes remain in report
routing.
- query: `Executor` holds `AccountTypes` (default standard) with
`set_account_types`; POSSIGN + ACCOUNT_SORTKEY classify through it.
CLI query threads it via ShellSettings (batch + interactive); the
ffi-component threads it in `query`, `batch`, and session `query`
from loaded options. `query-entries` keeps defaults — its WIT
contract carries no options (documented at the call site).
Verified vs beanquery 3.2.3 on the renamed fixture: POSSIGN +100.00
and ACCOUNT_SORTKEY "3-Revenue:Sales" now match exactly; income
statement shows Revenue:Sales / Total Income -100.00 / Net Income
100.00. New report_account_rename_test.rs pins all four surfaces.
Default-name behavior unchanged (report/CLI/query suites green).
Found by the Phase-0 duplication sweep (account-type classification
family: ~13 raw-prefix sites; this fixes the correctness-bearing ones
— the remaining cosmetic sites are follow-up).
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
This PR fixes root-account renames (option "name_*" ...) being ignored by report routing and BQL classification by introducing a config-aware AccountTypes classifier and threading it through reports, the query executor, CLI shells, and the FFI component surface to match beancount/beanquery behavior.
Changes:
- Added
rustledger_core::AccountTypes/AccountTypeKindfor rename-aware account classification (routing, credit-normal checks, sort index). - Updated reports (balsheet/income/holdings/networth) to route by
AccountTypes::kind()instead of hardcoded"Assets:"/"Income:"prefixes. - Updated BQL executor and hosts (CLI + FFI component) so
POSSIGNandACCOUNT_SORTKEYuse configured roots; added regression tests covering the renamed-root surfaces.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| crates/rustledger/tests/report_account_rename_test.rs | Adds regression tests validating report routing and BQL behavior under renamed roots. |
| crates/rustledger/src/cmd/report_cmd/networth.rs | Uses AccountTypes to classify assets/liabilities for net worth instead of prefix checks. |
| crates/rustledger/src/cmd/report_cmd/mod.rs | Threads AccountTypes through report loading and dispatch to all relevant reports. |
| crates/rustledger/src/cmd/report_cmd/income.rs | Routes income/expense sections via AccountTypes::kind(). |
| crates/rustledger/src/cmd/report_cmd/holdings.rs | Filters holdings to configured Assets root via AccountTypes. |
| crates/rustledger/src/cmd/report_cmd/balsheet.rs | Routes balance sheet sections via AccountTypes::kind(). |
| crates/rustledger/src/cmd/query/output.rs | Configures the query Executor with ledger-specific AccountTypes. |
| crates/rustledger/src/cmd/query/mod.rs | Stores AccountTypes in ShellSettings and passes it into interactive/batch execution. |
| crates/rustledger/src/cmd/query/interactive.rs | Wires AccountTypes into interactive shell settings. |
| crates/rustledger-query/src/executor/mod.rs | Adds account_types to Executor, defaults it, and applies it to POSSIGN/ACCOUNT_SORTKEY. |
| crates/rustledger-query/src/executor/functions/account.rs | Makes account_type_index use AccountTypes::sort_index() (rename-aware). |
| crates/rustledger-loader/src/options.rs | Adds Options::to_account_types() constructor for the classifier. |
| crates/rustledger-ffi-component/src/convert.rs | Threads configured AccountTypes into query execution for FFI batch/query/session paths. |
| crates/rustledger-core/src/lib.rs | Re-exports new account type symbols from identifiers. |
| crates/rustledger-core/src/identifiers.rs | Introduces AccountTypeKind and AccountTypes with kind/sign/sort helpers. |
💡 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 |
split(':').next() can never return None, so the unwrap_or fallback
was unreachable; split_once makes the root-vs-whole-name cases
explicit.
Co-Authored-By: Claude Fable 5 <[email protected]>
The deep review found the PR's own bug class still alive on the wasm embedding surface: api::query, api::query_multi_file, and the shared execute_query behind ParsedLedger::query / Ledger::query / balances() constructed executors without set_account_types, so POSSIGN and ACCOUNT_SORTKEY silently misclassified renamed ledgers there. - helpers::account_types_from_raw derives core AccountTypes from raw parsed option tuples (the wasm wire LedgerOptions deliberately carries no name_*); single-file paths use it (ParsedLedger has parse_result in both new() and from_cache(), which re-parses). - Multi-file paths use loader Options::to_account_types; the Ledger struct carries the value, and the cache payload persists it as five root names (CACHE_VERSION 2 -> 3 — version mismatch falls back to re-parse, the established mechanism) so fromCache ledgers classify identically. Co-Authored-By: Claude Fable 5 <[email protected]>
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
robcohen
added a commit
that referenced
this pull request
Jul 10, 2026
…ecks, quarter math) (#1741) * chore: consolidate utility copies (CSV/JSON escaping, account-type checks, quarter math) Utility-census batch from the Phase-1 sweep (U1/U2/U5). All changes behavior-identical; no user-visible output changes. - CSV escaping: report_cmd csv_escape and BQL output escape_csv were byte-identical private copies. Hoist to rustledger_core::format::escape_csv (with unit tests); both CLI sites now delegate (report_cmd via a pub(super) use alias so the 26 call sites are untouched). - JSON escaping: report_cmd json_escape hand-chained replace() over exactly the escape set core's format::escape_string handles (backslash, quote, \n, \r, \t) — aliased to the core fn, hand chain deleted. - Account-type checks: four production sites re-derived the account type from raw string prefixes; they now use the core helpers (ACCOUNT_TYPES / account_type), so a future sixth type or rule change has one home: - LSP on_type_formatting + utils is_account_like: the deliberately colon-less mid-typing heuristics now iterate core ACCOUNT_TYPES. - check_drained plugin: six hand-written clauses (three prefixes + three bare-root equalities) collapse to a three-arm match on core account_type, which classifies by root component. - split_expenses plugin: is_expense via account_type (identical for any parsable account, which always has >= 2 components). - Quarter math: the (month - 1) / 3 formula appeared twice within query functions/date.rs, diverging only in off-by-one framing (DATE_TRUNC zero-based vs QUARTER() one-based). Single const quarter_index0 helper now feeds both. Deliberately NOT in this batch: - report-section routing sites (balsheet/income/networth/holdings) are already rewritten config-aware by open PR #1731 — touching them here would conflict. - networth's period bucketing was NOT ported onto query IntervalUnit: its buckets are label-string equality (ISO %V weeks) and switching machinery risks silent boundary changes for purely cosmetic dedup. Reports adopting DisplayContext (U4) is user-visible and belongs in its own PR, like #1728. Note: test_account_lifecycle_consistency (integration_test.rs) fails on main BEFORE this change — rledger check passes an account-used-before-open ledger that Python rejects. Pre-existing; tracked separately. Co-Authored-By: Claude Fable 5 <[email protected]> * fix: reattach add_days docs; tighten escape_csv wording; hoist import (review) - quarter_index0 had been inserted between add_days's doc block and its fn, so rustdoc attached the wrong docs; moved above the block, plus a debug_assert and a note on the 1-based month contract. - escape_csv doc said "newline"; only \n triggers quoting (\r does not), matching the prior copies byte-for-byte — say so. - escape_csv import moved to the top import group in query output. Co-Authored-By: Claude Fable 5 <[email protected]> * docs: DATE_BIN quarter arm is not a quarter_index0 user (deep review) Its bucketing is origin- and width-relative months arithmetic, not calendar-quarter indexing — the doc claimed a third call site that does not (and could not) exist. Co-Authored-By: Claude Fable 5 <[email protected]> * docs: split escape_csv doc paragraph (clippy 1.97 length lint) Co-Authored-By: Claude Fable 5 <[email protected]> --------- Co-authored-by: Claude Fable 5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Jul 10, 2026
* docs: canonical-function discipline and toolchain-bump runbook Distills the 2026-07 duplication review (PRs #1731-#1743) into standing guidance: the one anti-pattern every found bug traced to, the ranked remedies (call the canonical / document divergence at both sites / drift-guard test), the current canonical inventory, the two supporting test-hygiene rules (#1729, #1742), and the lockstep toolchain-bump procedure learned from #1745/#1751. Co-Authored-By: Claude Fable 5 <[email protected]> * docs: scope the pin claim to stable-channel sites (review) Co-Authored-By: Claude Fable 5 <[email protected]> --------- Co-authored-by: Claude Fable 5 <[email protected]>
Merged
18 tasks done
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.
Found by the Phase-0 duplication sweep (L5). beancount ledgers can rename their five root accounts (
option "name_income" "Revenue") — both engines accept them at check-time, but every rledger consumer classified accounts against hardcoded prefixes. Two user-visible bugs, verified against beanquery 3.2.3:report incomerendered an EMPTY income statement under a renamed Income root; same class in balsheet/holdings/networth routing.POSSIGNdiverged from beanquery (-100.00 vs +100.00 on a renamed credit-normal root);ACCOUNT_SORTKEYsorted renamed roots as custom where beanquery classifies them.Fix: one config-aware classifier, threaded everywhere
AccountTypes+AccountTypeKind—kind()/is_balance_sheet()/is_income_statement()/is_credit_normal()/sort_index()against the configured names.Options::to_account_types().LoadedReportcarries it; balsheet/income/holdings/networth route bykind()— no hardcoded prefixes remain in report routing.Executorholds it (set_account_types); POSSIGN + ACCOUNT_SORTKEY classify through it. Threaded via ShellSettings (CLI batch + interactive) and the ffi-component (query/batch/session).query-entrieskeeps defaults — its WIT contract carries no options (documented inline).Verified
3-Revenue:Salesmatch exactly; income statement shows Revenue:Sales → Net Income 100.00.report_account_rename_test.rspins all four surfaces (4 tests).Follow-ups (registry, not this PR): remaining cosmetic raw-prefix sites (~9), wasm executor default (wasm LedgerOptions lacks name_* fields today), possible WIT option-passing for
query-entries.🤖 Generated with Claude Code