Repository navigation
test(core): booking-family behavior replay + fix NONE shorting (#1686) - #1688
Merged
Merged
Conversation
…specs Generalizes the MBT layer to the full booking family — FIFO/LIFO/HIFO/STRICT/ AVERAGE/NONE — bringing the enumerated conformance corpus to ~3,976 behaviors (replayed in <0.1s of plain cargo test): - tla-behaviors.py: structured TLA value parsing (records/sequences/sets, escaped strings, TLC's pretty-printed multi-segment values), a SPECS registry with per-spec delta-derived actions, canonicalization for the richer states. Conservation output stays byte-identical. - Per-spec replay interpreters: FIFO/LIFO assert the matched lot's DATE and per-date totals; HIFO the matched COST; STRICT maps the model's success/no_match/ambiguous onto Ok/NoMatchingLot/AmbiguousMatch; AVERAGE asserts the units abstraction (the model's average uses integer \div, the implementation divides exactly — documented); NONE asserts balance incl. shorts. - tla.yml lockstep guard now loops over ALL committed corpora. First-run findings, both adjudicated: - STRICT 'ambiguous' vs impl Ok — a mapping-fidelity issue, not a bug: reduce_strict deliberately treats same-cost lots as financially interchangeable (documented FIFO fallback), so the replay now gives each model lot a distinct cost number to reproduce lot-identity ambiguity. - NONE: reduce_none refuses to short from a POSITIVE balance while allowing it from zero — inconsistent with itself, the model, and beancount NONE. Filed as #1686; the replay pins the divergent outcome by issue number and asserts the pin FIRES, so a fix flips it loudly. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Closes #1686 — found by the behavior-replay suite's first run over the NONECorrect corpus. reduce_none returned InsufficientUnits when reducing more than a POSITIVE balance while allowing the same short from zero/same-sign, so the outcome depended on whether zero was crossed in one step (0 -> -2 allowed; +1 -> -1 rejected). NONE performs no booking: per NONECorrect.tla and beancount NONE semantics the reduction always applies. The over-reduction arm now consumes everything available and carries the remainder as a negative simple position. - The two unit tests that pinned the old behavior are flipped with balance assertions (reduce_none_exact_succeeds_over_reduction_shorts, test_none_booking_shorts_past_zero). - prop_none_allows_any_reduction widened past the holdings range with balance arithmetic asserted through the short. - The #1686 pin in the NONE replay is removed: the full 396-behavior corpus now replays clean. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
📊 Benchmark Results
vs main branch (2026-07-02)
What do these numbers mean?
|
Contributor
There was a problem hiding this comment.
Pull request overview
Extends the TLA+ model-based “behavior replay” harness to cover the full booking-method family (FIFO/LIFO/HIFO/STRICT/AVERAGE/NONE) and fixes NONE booking semantics so over-reductions short past zero rather than erroring, aligning with the model and beancount behavior.
Changes:
- Generalize
scripts/tla-behaviors.pyto parse richer TLC dot dumps and derive canonical, delta-based action steps for multiple specs/corpora. - Expand
tla_behavior_replay.rsto replay all booking-method corpora with spec-specific assertions (lot selection, STRICT outcomes, AVERAGE units-only caveat, NONE shorts). - Fix
Inventory::reduce_noneto allow shorting from a positive balance, and update unit/property tests and CI corpus lockstep verification accordingly.
Reviewed changes
Copilot reviewed 7 out of 14 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| spec/tla/RUST_MAPPING.md | Documents the expanded set of replayed specs/corpora and the abstraction used for comparison. |
| scripts/tla-behaviors.py | Adds structured TLA value parsing + spec registry and derives canonical behavior corpora across booking specs. |
| crates/rustledger-core/tests/tla_proptest.rs | Widens NONE reduction property range and asserts resulting balance arithmetic through shorts. |
| crates/rustledger-core/tests/tla_behavior_replay.rs | Reworks replay harness to load/replay multiple corpora with method-specific checks. |
| crates/rustledger-core/src/inventory/mod.rs | Updates NONE booking unit test to assert shorting behavior instead of InsufficientUnits. |
| crates/rustledger-core/src/inventory/booking.rs | Fixes reduce_none to short on over-reduction; updates corresponding reduction test. |
| .github/workflows/tla.yml | Verifies lockstep regeneration for all behavior corpora rather than only Conservation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
This was referenced Jul 2, 2026
Merged
robcohen
added a commit
that referenced
this pull request
Jul 2, 2026
Patch release. User-facing fixes since v0.19.0: - NONE booking: over-reduction now shorts past zero from ANY balance (consumes available units, appends the remainder as a negative position), fixing the inconsistency where shorting from a positive balance was rejected while shorting from zero was allowed (#1686, via #1688). - try_reduce: the read-only preview is now reduce-on-a-clone — equivalent to the mutating path by construction. Previously it diverged under STRICT (FIFO fallback instead of AmbiguousMatch), NONE (error instead of short), and {*} merge (wrong dispatch) (#1690). No WIT change (rustledger:ledger stays 3.2.0); embedders are unaffected. Also carries the formal-verification hardening arc (#1683-#1697): behavior replay across 11 corpora, dual-direction trace validation, exact-rational AVERAGE model, coverage lint, weekly escalated replay, pad-directive spec, and Kani proofs for the new NONE semantics. Workspace 0.19.0 -> 0.19.1; packages/mcp-server bumped to match. Co-authored-by: Claude Opus 4.8 <[email protected]>
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.
Replaces #1687 (GitHub closed the stacked PR when #1685's base branch was deleted — branch + commits intact, rebased onto main). Two commits:
1. Extend behavior-replay conformance to the booking-method specs
~3,976 enumerated behaviors across 7 corpora, replayed in <0.1s of plain
cargo test:success/no_match/ambiguous↔Ok/NoMatchingLot/AmbiguousMatch\div; documented)Generator: structured TLA value parsing (records/sequences/sets, escaped strings, TLC's pretty-printed multi-segment values — two real dump-dialect quirks found and fixed), SPECS registry with delta-derived actions. Conservation's corpus stays byte-identical. tla.yml lockstep guard loops over all corpora.
First-run adjudications: STRICT's apparent divergence traced to the documented same-cost-interchangeable FIFO fallback in
reduce_strict→ mapping made faithful (distinct cost per model lot). NONE's divergence was real → …2. Fix NONE shorting — Closes #1686
reduce_nonerefused to short from a positive balance while allowing it from zero — the outcome depended on whether zero was crossed in one step (0 → -2allowed;+1 → -1rejected). PerNONECorrect.tlaand beancount NONE (no booking at all), the reduction always applies: the over-reduction arm now consumes what's available and carries the remainder as a negative simple position.Instructive detail: two hand-written unit tests faithfully pinned the bug (
assert!(matches!(.., InsufficientUnits))) — only the model-derived corpus contradicted the shared assumption. Both flipped with balance assertions; the property test is widened past the holdings range; the full 396-behavior NONE corpus now replays clean.Verification
7/7 replay suites, core lib 422/422, booking + validate suites green; generator self-tests (incl. reorder + label-stripping invariance); clippy
-D warnings+ fmt clean.🤖 Generated with Claude Code