Repository navigation
test(booking): stop the rollback property failing at random - #2087
Merged
Merged
Conversation
`a_failed_transaction_restores_the_account_exactly` assumed its doomed
final leg — overselling `STK` by 100,000 — always fails. It does not. A
generated prefix of `{*}` merges can empty the account, and an empty cost
spec against an empty account is an AUGMENTATION rather than a failed
reduction. Beancount's `book_reductions` makes the same call: reduction
only `if balance.is_reduced_by(units)`, else augment. So the transaction
succeeded, the property reported "the doomed leg must reject the
transaction", and whether CI saw it depended on which prefix proptest
happened to generate.
Found by proptest generating `[Merge, Merge, Merge, Merge]` while I was
measuring something unrelated. It reproduces on every commit I tried,
including before #2085 and #2081, so it has been latent since the file
was added in #2067.
The doomed posting now reduces a commodity the generated legs never
mention, seeded once up front. That makes "this leg always fails" a fact
about the fixture rather than a hope about the prefix, and the prefix
still exercises every mutation shape the undo log has to cover.
Verified: the seed that fails on main passes here, eight randomized runs
pass, and the property still catches a rollback bug — neutering
`has_reduction` so the undo log is never armed fails it.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a flaky proptest in rustledger-booking by making the “doomed” posting deterministically fail regardless of the randomly generated prefix of legs, ensuring the rollback invariant is tested reliably.
Changes:
- Adds an “anchor” commodity position that generated legs never touch, so the final doomed posting is always a true reduction attempt (and thus always rejects).
- Switches the doomed posting to oversell the anchor commodity rather than the generated commodity, eliminating random passes/failures.
Suppressed comments (1)
crates/rustledger-booking/tests/apply_rollback_properties.rs:168
- This comment says it used to oversell
STK, but the generated commodity in this test isCURRENCY("X"). Updating the wording avoids confusion when debugging failures.
// Doomed against the ANCHOR commodity, not the generated one.
//
// It used to oversell `STK`, on the assumption that overselling always
// fails. It does not: a prefix of `{*}` merges can empty the account,
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Contributor
📊 Benchmark Results
vs main branch (2026-08-18)
What do these numbers mean?
|
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 |
…ty name Copilot's review. The anchor lot spelled out a `CostSpec` that `per_unit` already builds, which is how a fixture drifts from the shape the rest of the file uses; and two comments called the generated commodity `STK` while the constant has been `X` since the file was written. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
Review of my own change. `holdings` compared units, cost and lot date but not the commodity, which was harmless while the account held one. This change gave it two — the generated legs work on one, the doomed leg reduces the other — so a rollback that restored the right numbers against the wrong commodity would have compared equal. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
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.
A latent CI flake in
apply_rollback_properties, found while measuring something unrelated.What happens
The property builds a randomized prefix of legs, appends a doomed final leg that oversells
STKby 100,000, and asserts the transaction is rejected and the account untouched.The doomed leg does not always fail. A prefix of
{*}merges can empty the account, and an empty cost spec against an empty account is an augmentation, not a failed reduction — so the transaction succeeds and the property reports:Whether CI sees it depends on which prefix proptest generates that run.
The product is right; the test was wrong
Beancount's
book_reductionsmakes the same call — a posting held at cost is a reduction onlyif balance.is_reduced_by(units), otherwise it is booked as an augmentation. rustledger matches. So an all-Mergeprefix draining the account and the doomed leg then augmenting is correct behavior, and the assertion was asserting something that was never true.Fix
The doomed posting now reduces a commodity the generated legs never mention, seeded once up front. "This leg always fails" becomes a fact about the fixture rather than a hope about the prefix, and the prefix still exercises every mutation shape the undo log has to cover (push a slot, write a lot in place, drain one, and
{*}dropping every matched lot at once).Verification
mainpasses here.has_reductionso the undo log is never armed fails it.Age
It reproduces on every commit I tried, including before #2085 and #2081, so it has been latent since the file was added in #2067. Not a regression from recent work — it simply needed proptest to roll four merges in a row.
🤖 Generated with Claude Code
https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr