tla-connect
TLA+/Apalache integration for model-based testing in Rust.
Overview
tla-connect provides tools for integrating TLA+ and Apalache model checking into Rust test suites. It enables:
- Trace validation: Verify that your implementation matches TLA+ specifications
- Model-based testing: Generate test cases from TLA+ models
- Counterexample replay: Automatically reproduce bugs found by model checkers
Architecture
flowchart TB
subgraph TLA["TLA+ Specification"]
Spec[MySpec.tla]
TraceSpec[TraceSpec.tla]
end
subgraph Apalache["Apalache Model Checker"]
CLI[apalache-mc CLI]
RPC[JSON-RPC Server]
end
subgraph Rust["Rust Implementation"]
Driver[Driver trait]
State[State trait]
Emitter[StateEmitter]
end
subgraph Traces["Trace Formats"]
ITF[ITF Traces]
NDJSON[NDJSON Trace]
end
%% Approach 1: Batch Replay
Spec -->|"generate_traces()"| CLI
CLI -->|produces| ITF
ITF -->|"replay_traces()"| Driver
Driver -->|compared via| State
%% Approach 2: Interactive RPC
Spec -->|"interactive_test()"| RPC
RPC <-->|step-by-step| Driver
%% Approach 3: Post-hoc Validation
Driver -->|records| Emitter
Emitter -->|writes| NDJSON
NDJSON -->|"validate_trace()"| CLI
CLI -->|checks against| TraceSpec
classDef tla fill:#e1f5fe,stroke:#01579b
classDef apalache fill:#fff3e0,stroke:#e65100
classDef rust fill:#e8f5e9,stroke:#2e7d32
classDef trace fill:#fce4ec,stroke:#880e4f
class Spec,TraceSpec tla
class CLI,RPC apalache
class Driver,State,Emitter rust
class ITF,NDJSON trace
| Approach | Direction | Catches |
|---|---|---|
| 1. Batch Replay | Spec → Implementation | Implementation doesn't handle a case the spec allows |
| 2. Interactive RPC | Spec ↔ Implementation | Implementation doesn't handle a case the spec allows |
| 3. Post-hoc Validation | Implementation → Spec | Implementation does something the spec doesn't allow |
Features
- ITF (Informal Trace Format) parsing and validation
- Apalache CLI integration for trace generation
- Apalache JSON-RPC client for interactive symbolic testing
- Trace generation from TLA+ specifications
- State comparison and diff output for debugging mismatches
- Support for both file-based and RPC-based workflows
Feature Flags
replay(default): ITF trace replay against a Drivertrace-gen(default): Apalache CLI trace generationtrace-validation(default): Post-hoc NDJSON trace validationrpc: Interactive symbolic testing via Apalache JSON-RPCparallel: Parallel trace replay using rayonfull: Enable all features
Installation
Add this to your Cargo.toml:
[]
= "0.0.2"
# For interactive RPC testing:
# tla-connect = { version = "0.0.2", features = ["rpc"] }
Quick Start
Approach 1: Batch Trace Replay
Generate traces with Apalache, then replay against your implementation:
use *;
use Deserialize;
Approach 2: Interactive Symbolic Testing (requires rpc feature)
Step-by-step symbolic execution via Apalache's explorer server:
use *;
async
Approach 3: Post-hoc Trace Validation
Record your implementation's execution, then validate against the spec:
use *;
use Serialize;
use Path;
Requirements
- Rust 1.93 or later
- Apalache (if using trace generation or validation features)
Documentation
For detailed documentation, see docs.rs/tla-connect.
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.