Skip to content

fix(query): drop leading space inside cost-spec braces in BQL output - #1020

Merged
robcohen merged 1 commit into
mainfrom
fix/issue-987-cost-spec-brace-spacing
May 7, 2026
Merged

robcohen merged 1 commit into
mainfrom
fix/issue-987-cost-spec-brace-spacing

Conversation

@robcohen

@robcohen robcohen commented May 7, 2026

Copy link
Copy Markdown
Member

Summary

rledger query rendered positions with a leading space inside the cost-spec braces — { 128.99 USD} — while bean-query doesn't:

# rledger (pre-fix)
Assets:US:Vanguard:RGAGX  8.373 RGAGX { 128.99 USD}  8.199 RGAGX { 131.73 USD}

# bean-query
Assets:US:Vanguard:RGAGX  8.373 RGAGX {128.99 USD}  8.199 RGAGX {131.73 USD}

Of the 99 remaining BQL compat mismatches identified alongside #986, 83 were this single rendering bug. Fixing it pushes BQL parity from 78% → ~96% on the local 30-file corpus.

Root cause

Two format!(" {{ {}}}", ...) calls in crates/rustledger/src/cmd/query/output.rs (the Value::Position and Value::Inventory arms) — the format string expanded to " { COST}". The core format_cost_spec helper in rustledger-core/src/format/amount.rs was already correct; the divergence was local to the BQL output formatter.

Changes

  • crates/rustledger/src/cmd/query/output.rs:279,346 — drop the leading space inside the braces.
  • Add unit tests for the Value::Position and Value::Inventory rendering paths. No snapshot tests pinned the buggy output (which is how it shipped); the new tests assert the rendered string contains {COST} and does NOT contain { so a future format-string change can't silently regress.

Test plan

Out of scope

Per the issue: cost label rendering ({COST, "label"}) and rledger format's round-trip beancount formatter are explicitly out of scope; this PR only touches the query output path.

Closes #987.

🤖 Generated with Claude Code

`rledger query` rendered positions with a leading space inside the
cost-spec braces (`{ 128.99 USD}`), diverging from `bean-query`
(`{128.99 USD}`). Of the 99 BQL compat mismatches discovered
alongside #986, 83 were this single rendering bug.

Root cause: two `format!(" {{ {}}}", ...)` calls in the query output
path expanded to `" { COST}"`. The core `format_cost_spec` helper in
`rustledger-core` was already correct (`format!("{{{}}}", ...)`); the
divergence was local to the BQL output formatter.

Changes:
- `crates/rustledger/src/cmd/query/output.rs:279,346` — drop the
  leading space inside the braces so output matches `bean-query`.
- Add unit tests for both the `Value::Position` and `Value::Inventory`
  rendering paths so a future format-string change can't silently
  regress this — no snapshot tests pinned the buggy output, which is
  how it shipped in the first place.

Closes #987.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings May 7, 2026 15:06
@robcohen
robcohen requested a review from a team as a code owner May 7, 2026 15:06

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

This PR fixes a BQL output formatting mismatch where rledger query rendered cost-specs with an extra leading space inside braces (e.g., { 128.99 USD}), bringing output in line with bean-query and improving BQL compatibility.

Changes:

  • Remove the leading space inside cost-spec braces for Value::Position and Value::Inventory rendering.
  • Add unit tests to pin the no-leading-space behavior for both Position and Inventory output paths.

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

@github-actions

github-actions Bot commented May 7, 2026

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Tool Time Memory
rustledger 29.3ms ± 0.2ms 22 MB
beancount 868.7ms ± 19.6ms 50.5 MB
Comparison 29.6x faster 2.3x less

vs main branch (2026-05-07)

Metric main this PR Change
Time 34.2ms 29.3ms -14.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

@github-actions

github-actions Bot commented May 7, 2026

Copy link
Copy Markdown
Contributor

⚠️ Compatibility Test Results

Metric Result
Check Compatibility 99%
BQL Compatibility 74%
Full AST Match 99%
Total Files 786
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 May 7, 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 b5df052 into main May 7, 2026
35 checks passed
@robcohen
robcohen deleted the fix/issue-987-cost-spec-brace-spacing branch May 7, 2026 15:19
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.

BQL: cost-spec brace rendering has leading space () — diverges from bean-query

2 participants