Repository navigation
chore(compat): fuzz currency-less units numbers against beancount - #2564
Merged
Merged
Conversation
The booking fuzzer never generated a posting written as a number with no currency, so the categorize_by_currency rule #2490 ported had no differential coverage. Every seed now also books a second ledger, drawn from its own RNG so the lot-selection ledgers are unchanged, with number-only postings in seven shapes against accounts holding one currency, several, none, or one since emptied. The report tallies agreement per shape and per holding, with both-booked and both-refused counts, and the self-test fails if a shape or holding stops appearing. Seeds 0-1999 agree against main. Three deliberately broken builds of the rule each produce divergences. Closes #2513 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
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 |
Member
Author
Review rounds (#2513)
The loop converged after round 1 found nothing, and round 2 confirmed it. Campaign numbers are in the PR body: seeds 0–1999 give 2000/2000 on both ledger kinds. Three broken builds give 33, 77 and 7 divergences. Two booking divergences turned up while building the generator. Neither comes from the currency-less rule, and both reproduce with the commodity written. They are listed in the PR body as follow-ups to decide:
|
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.
What
scripts/compat-booking-fuzz.pynow generates postings written as a number with no currency (Assets:CashA -100,Assets:StockA -5 {},-3 @ 1.10 USD) and compares how rledger and Python beancount book them.Every seed books its existing lot-selection ledger as before, plus a second "number-only" ledger. The second ledger comes from its own RNG (
random.Random(f"number-only-{seed}")), so every seed's lot-selection ledger is byte-for-byte unchanged. Each number-only ledger:categorize_by_currency, as ported in fix(booking): infer a currency-less units number from the account balance #2490:plain-one-group: the other postings form one currency group (step 1). That currency wins even when the account holds a different one. Sometimes there is an auto-posting beside it.plain-several-groups: the other postings span two groups, so the balance decides (step 2). Sometimes there is no auto-posting, so a wrong currency makes the transaction unbalanced.plain-no-group: the posting sits beside an auto-posting only.several-number-only: 2–3 currency-less postings in one transaction. The balancing leg is an auto-posting, number-only, or written with a currency.cost-reduce:-N {},-N {C CUR}or-N {C}, optionally priced. The cash leg is sometimes number-only too.cost-augment:N {C CUR}.price:-N @ R CUR,@@, or@ Rwith the price currency elided.infer_tolerance_from_cost20% of the time, and shuffles posting order 30% of the time.The report keeps the existing lines and adds a per-shape and a per-holding tally. Each line shows agreed/total and how many ledgers both engines booked versus both refused, so it shows that the accepting and the refusing sides of the rule were both reached. Zeros are printed too. Any number-only divergence fails the run, like any other unexplained divergence.
--self-testnow also fails if any shape or holding goes ungenerated over 300 seeds, or if a ledger has no currency-less posting. The detector for currency-less postings is itself tested on cases where it must answer no.Why
#2490 checked the rule with a 37-case matrix and a corpus sweep, but nothing compared it against beancount after the PR merged.
How tested
All runs used beancount 3.2.3. Each run pointed
--rledgerat a copied, named binary, never attarget/.Against main (
rledger-main, built from 001cca9):--self-testpasses.By holding: one 1339/1339, several 581/581, empty 282/282, emptied 285/285.
Self-check: the new shapes do report a broken rule. I made three temporary edits to
resolve_elided_units_currencies, built each one and copied the binary, then ran seeds 0–199:Assets:CashA/EUR: rledger=None beancount=-328.9Lot-selection ledgers stayed at 200/200 in all three runs. After restoring the code and rebuilding, the binary's sha256 matched the main build (
14afbb34…).Out of scope: two divergences unrelated to the currency-less rule
An earlier version of the generator priced reductions and paid them in USD whatever the lots' cost currency was. It found two divergences that reproduce identically with the commodity written. They come from cost booking, not from inferring a currency:
-2 HOOL {11.00 EUR} @ 14.50 USD: beancount refuses it ("Cost and price currencies must match: EUR != USD"), and rledger books it.-1 HOOL {}besideAssets:Cash 13.00 USD, when the lot is held at EUR cost: beancount takes the cost currency from the other postings' group (USD) and finds no position. rledger books the EUR lot.The generator now keeps a reduction's price and cash leg in the lots' cost currency. The comment and the docstring say why. Neither divergence is waived; they are left for a separate decision.
CHANGELOG: entry under "Testing & Engineering Quality".
Closes #2513
🤖 Generated with Claude Code
https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr