Repository navigation
test(core): behavior-replay conformance against the TLA+ model (MBT) - #1685
Merged
Merged
Conversation
The specs bounds are tiny (Conservation: 207 states / 678 transitions), so TLC can enumerate the COMPLETE state graph. New model-based-testing layer: - scripts/tla-behaviors.py: TLC -dump dot,actionlabels state graph -> edge-coverage behavior corpus (one behavior per transition = shortest canonical path to the source state + the transition). Output is canonical (content-derived ordering, no node ids), so regeneration is byte-stable regardless of TLC dump order. --self-test included. - spec/tla/behaviors/Conservation.json: the committed corpus (678 behaviors covering all 678 transitions). - tests/tla_behavior_replay.rs: replays EVERY behavior against the real Inventory, asserting after each step (a) the abstraction — units == spec inventory, harness accumulators == totalAdded/totalReduced — and (b) enabledness: a model-enabled Reduce may not Err. Hermetic (no Java/TLC in cargo test); graceful skip when spec/ is not packaged (published-crate / crane builds, the #1659 lesson). - tla.yml: lockstep guard — regenerates the corpus from the spec and fails on drift, so the replay test can never silently certify against a stale model. - RUST_MAPPING.md: documents the layer and how to extend it to more specs. Exhaustive conformance up to the model bound: strictly stronger than the sampled tla_proptest properties, one notch below a refinement proof. 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
Adds a model-based testing layer that exhaustively replays every TLC transition (within the spec’s configured bounds) against the real rustledger-core::Inventory, keeping the committed behavior corpus in CI lockstep with the TLA+ model.
Changes:
- Introduces a TLC state-graph → canonical JSON “behavior corpus” generator (
scripts/tla-behaviors.py) with a self-test. - Adds a Rust integration test that replays the committed corpus (
tla_behavior_replay.rs) and checks per-step abstraction + enabledness. - Extends the TLA CI workflow to regenerate and byte-compare the corpus to prevent silent drift; documents the approach in
RUST_MAPPING.md.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| spec/tla/RUST_MAPPING.md | Documents the new behavior-replay (MBT) conformance layer and how it fits with existing verification. |
| scripts/tla-behaviors.py | Generates a canonical edge-coverage behavior corpus from TLC -dump dot,actionlabels output (includes --self-test). |
| spec/tla/behaviors/Conservation.json | Committed corpus for Conservation.tla used by cargo test without requiring Java/TLC. |
| crates/rustledger-core/tests/tla_behavior_replay.rs | Replays every behavior against Inventory and asserts abstraction + enabledness at each step (with graceful skip when spec/ isn’t packaged). |
| .github/workflows/tla.yml | Adds a CI lockstep guard that regenerates the corpus and fails on drift. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…nostic edge parsing The PR's own lockstep guard caught the exact failure mode it exists for: CI's tla2tools (1.8.0) emits dot edges the 1.7.4-tuned label regex didn't match, so CI regenerated a corpus with 207 states but ZERO transitions and the byte-diff failed. Fixes: - Edge regex matches any 'id -> id' line; the action label is optional decoration. Semantics are DERIVED from the state delta (totalAdded grew -> Add, totalReduced grew -> Reduce), so committed corpus and CI regeneration agree regardless of TLC's dot dialect. - The generator now REFUSES to emit a vacuous corpus (states without transitions = parse failure, hard error instead of a garbage diff). - Stutter self-loops (emitted by some TLC versions) are skipped, and coverage.transitions counts only semantic edges, keeping the byte-diff stable across versions. - Self-test extended: stripping all action labels must produce the identical corpus. Committed corpus regenerated with the new derivation: byte-identical (678 behaviors / 678 transitions), confirming the change is purely parsing. Co-Authored-By: Claude Opus 4.8 <[email protected]>
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.
Third formal-verification PR (after #1683/#1684) — the behavior-replay prototype from the model↔implementation gap analysis.
Idea
The specs' bounds are deliberately tiny —
Conservation.cfgyields 207 states / 678 transitions — so TLC can enumerate the complete state graph. Instead of sampling properties, replay every model behavior against the realInventoryand check the correspondence at every step. Exhaustive conformance up to the model bound: strictly stronger thantla_proptest.rs, one notch below a refinement proof.Pieces
scripts/tla-behaviors.py— TLC-dump dot,actionlabels→ edge-coverage corpus (one behavior per transition: shortest canonical path + the transition). Output is canonical (content-derived ordering, no node ids) so regeneration is byte-stable under TLC's nondeterministic dump order. Self-tested, incl. a reorder-invariance check.spec/tla/behaviors/Conservation.json— committed corpus: 678 behaviors covering all 678 transitions.tests/tla_behavior_replay.rs— replays everything in plaincargo test(hermetic, no Java), asserting per step: abstraction (units ==inventory, accumulators ==totalAdded/totalReduced) and enabledness (a model-enabledReducemay notErr— catches over-strict implementations, the dual of test(core): error-path conformance for TLA+ refinement — Err must be a stutter #1683's stutter obligation). Graceful skip whenspec/isn't packaged (fix(validate): read the spec doc at runtime in the error-code test (fixes Nix channel) #1659 lesson). Runs in 0.01s.tla.ymllockstep guard — regenerates the corpus from the spec in CI and fails on drift, so the replay can never silently certify against a stale model. (This PR triggers the TLA workflow itself, so the guard is verified on this very PR.)RUST_MAPPING.md— documents the layer + how to extend to the booking-method specs next.Verified
Generator self-test OK; corpus generated from a real TLC run; all 678 behaviors replay identically; clippy
-D warnings+ fmt clean.🤖 Generated with Claude Code