Skip to content

chore(compat): exclude google_purchases _invalid fixture (closes #989) - #1024

Merged
robcohen merged 1 commit into
mainfrom
chore/issue-989-exclusion
May 7, 2026
Merged

robcohen merged 1 commit into
mainfrom
chore/issue-989-exclusion

Conversation

@robcohen

@robcohen robcohen commented May 7, 2026

Copy link
Copy Markdown
Member

Summary

Issue #989 reported six BQL value-diff mismatches between rledger and bean-query. Investigation found:

The upstream bug

bean-query's FIRST(balance) returns different values for the same query and data depending on which other aggregators are in the SELECT list:

SELECT year, month, FIRST(balance)               -> 2018-7 = -31.84  (wrong)
SELECT year, month, FIRST(balance), LAST(balance) -> 2018-7 = -53.68  (correct)

Root cause: balance mutates a shared accumulator on every call (beanquery/sources/beancount.py). FIRST.update short-circuits operand evaluation after the first row of each group, so balance(context) is not called for later rows, leaving the accumulator stale for subsequent groups. This violates the documented contract that balance is "automatically calculated based on the previous selected rows" — the rows ARE selected, but the implementation only updates the accumulator for rows where the operand was actually evaluated.

rledger pre-computes ctx.balance per row in posting collection (crates/rustledger-query/src/executor/evaluation.rs:301-308); the column evaluator is a pure read. FIRST and LAST always agree on single-row groups, and the result is independent of which other aggregators are queried.

Filed upstream as beanquery#279.

Why exclude rather than fix

The fixture is a deliberately-malformed _invalid_journal test file from jbms/beancount-import — its purpose is to test how the project's importers handle bad input, not to be a balanced ledger. Excluding it from compat loses no real coverage. Matching bean-query here would mean reproducing an upstream bug.

Files changed

tests/compatibility/exclusions.toml — one new entry with full investigation context inline.

Closes #989.

🤖 Generated with Claude Code

…rect

Issue #989 reported six BQL value-diff mismatches. Investigation found
that five no longer reproduce (resolved by #986/#987/#988). The single
remaining case is an upstream beanquery bug:

  bean-query's FIRST(balance) returns different values for the same
  query and data depending on which other aggregators are in the
  SELECT list. The `balance` column mutates a shared accumulator and
  FIRST short-circuits operand evaluation after the first row,
  leaving the accumulator stale for later groups.

Filed upstream as beanquery#279. rledger's pre-computed-per-row
balance is correct and SELECT-shape-independent.

Excluding the fixture from compat closes the harness divergence.
The file is a deliberately-malformed `_invalid_journal` test fixture
from jbms/beancount-import; excluding it loses no real coverage.

Closes #989.

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

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 updates the compatibility test exclusion list to skip a specific beancount-import _invalid_journal fixture where rledger’s behavior is correct and the observed mismatch is attributed to an upstream beanquery bug in FIRST(balance) evaluation.

Changes:

  • Added a new exclusion entry for beancount-import/testdata_source_google_purchases_test_invalid_journal.beancount.
  • Documented the upstream beanquery bug and rationale for excluding (rather than matching the buggy behavior).

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

@robcohen
robcohen merged commit 61a3470 into main May 7, 2026
33 checks passed
@robcohen
robcohen deleted the chore/issue-989-exclusion branch May 7, 2026 21:11
@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!

@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 785
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

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: 6 value-diff mismatches from booking-time interpolation precision

2 participants