Repository navigation
fix(query): drop leading space inside cost-spec braces in BQL output - #1020
Merged
Merged
Conversation
`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]>
Contributor
There was a problem hiding this comment.
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::PositionandValue::Inventoryrendering. - 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.
Contributor
📊 Benchmark Results
vs main branch (2026-05-07)
What do these numbers mean?
|
Contributor
|
| 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 Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
Summary
rledger queryrendered positions with a leading space inside the cost-spec braces —{ 128.99 USD}— whilebean-querydoesn't: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 incrates/rustledger/src/cmd/query/output.rs(theValue::PositionandValue::Inventoryarms) — the format string expanded to" { COST}". The coreformat_cost_spechelper inrustledger-core/src/format/amount.rswas 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.Value::PositionandValue::Inventoryrendering 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
cargo test -p rustledger --lib cmd::query::output— both new tests pass.cargo clippy -p rustledger --all-features --all-targets -- -D warningsclean.cargo fmt --all -- --checkclean.Out of scope
Per the issue: cost label rendering (
{COST, "label"}) andrledger 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