Repository navigation
Conversation
Booking decides WHICH lot a reduction consumes. Get it wrong and the postings still balance, the count is still right and the error list is still empty — the ledger is simply wrong about what you own and what you gained. Example-based tests are worst at exactly that, and the fix log shows it: five booking fixes in twenty commits (#2058, #2069, #2081, #2093, #2099), each an ordering or lot-selection case nobody had written a test for. So this generates ledgers and compares BOOKED LOTS against Python beancount — an independent implementation, not a restatement of our own logic. For every account it compares full lot identity, (currency, per-unit cost, cost currency, lot date) -> units, so consuming the wrong lot at the same total value is still a failure. It also compares ACCEPTANCE: a ledger one engine books and the other rejects is a divergence even when no numbers differ, which is the shape of #2099. It found a real divergence on its first campaign — 58/60 agreed, both failures LIFO with same-date lots. Filed separately with a 12-line reproduction. Two things learned building it, both encoded in the script: `cost(position)` is the wrong column to read. For a costless posting it returns the units themselves, so a cash leg looks like it holds a cost of 1. `cost_number` is per-unit and null when there is no cost, which is what makes it the right discriminator. The first draft compared cash legs against nothing and reported four false divergences per run. AVERAGE and NONE booking are deliberately not generated: beancount rejects both outright, so every such run would be a known-unsupported skip rather than a test. `--self-test` plants six known outcomes (wrong lot, wrong units, either side rejecting, and two agreements) and requires each be classified correctly, then requires the real engines to agree on a hand-checked ledger. A harness that has only ever printed "no divergences" cannot be distinguished from one that is incapable of printing anything else; this one is checked in both directions before it is believed.
Comment on lines
+131
to
+132
| "SELECT account, units(position) AS u, cost_number AS cn, " | ||
| "cost_currency AS cc, cost_date AS cd", |
Member
Author
|
Superseded by the same commit on an allowed branch prefix — |
Comment on lines
+131
to
+132
| "SELECT account, units(position) AS u, cost_number AS cn, " | ||
| "cost_currency AS cc, cost_date AS cd", |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new differential “booking fuzzer” script that generates small Beancount ledgers and compares booked lot identities (and accept/reject behavior) between rledger and Python beancount, aiming to catch lot-selection/order divergences that example-based tests routinely miss.
Changes:
- Introduces
scripts/compat-booking-fuzz.pyto generate randomized ledgers across supported booking methods (STRICT/FIFO/LIFO/HIFO) and compare booked lots per account. - Implements a
--self-testmode that verifies the harness can detect planted divergences before running real engine comparisons.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| failures += 1 | ||
| print("\n".join(report)) | ||
| print("-" * 60) | ||
| total = len(list(seeds)) |
Comment on lines
+141
to
+143
| lots: Booked = {} | ||
| for row in json.loads(out.stdout).get("rows", []): | ||
| units = row.get("u") or {} |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
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.
Booking decides which lot a reduction consumes. Get it wrong and the postings still balance, the count is still right, and the error list is still empty — the ledger is simply wrong about what you own and what you gained.
Example-based tests are worst at exactly that, and the fix log agrees: five booking fixes in twenty commits (#2058, #2069, #2081, #2093, #2099), each an ordering or lot-selection case nobody had written a test for.
What it does
Generates ledgers and compares booked lots against Python beancount — an independent implementation rather than a restatement of our own logic. For every account it compares full lot identity,
(currency, per-unit cost, cost currency, lot date) -> units, so consuming the wrong lot at the same total value is still a failure.It also compares acceptance: a ledger one engine books and the other rejects is a divergence even when no numbers differ. That's the shape of #2099 — the bug there was answering at all.
It found a real divergence immediately
First campaign: 58/60 agreed. Both failures were LIFO with same-date lots. Filed separately with a 12-line reproduction — beancount and rustledger disagree about which same-date lot LIFO treats as "last in", giving different cost bases and different realised gains.
Two things learned building it
cost(position)is the wrong column. For a costless posting it returns the units themselves, so a cash leg looks like it holds a cost of 1.cost_numberis per-unit and null when there is no cost, which makes it the right discriminator. The first draft compared cash legs against nothing and reported four false divergences per run — caught by the self-test, not by reading.AVERAGE and NONE are deliberately not generated. beancount rejects both outright, so every such run would be a known-unsupported skip rather than a test.
Why you can believe a green run
--self-testplants six known outcomes — wrong lot, wrong units, either side rejecting, and two agreements — and requires each to be classified correctly. Then it requires the real engines to agree on a hand-checked ledger.A harness that has only ever printed "no divergences" cannot be distinguished from one incapable of printing anything else. This one is checked in both directions before it's believed, which is also how the
cost(position)mistake surfaced within minutes rather than living as a permanent source of false alarms.