A TypeScript-native formal specification testing framework. Define state machines in TypeScript → compile to TLA+ → run exhaustive model checking → generate Vitest tests.
packages/
core/ ← The main package (@stateproof/core)
src/
types.ts All TypeScript types/interfaces
machine.ts Machine builder DSL (fluent API)
concurrent.ts Concurrent composition builder
compiler.ts JS function → TLA+ expression compiler
tla-generator.ts AST → TLA+ spec generation
tlc.ts TLC integration (verify function)
test-generator.ts Trace-driven test generation
runtime.ts Runtime state machine + code generation
mermaid.ts Mermaid diagram generation
diff.ts Spec diffing
vitest-plugin.ts Vitest plugin
cli.ts CLI entry point
index.ts Public API (re-exports everything)
index.test.ts Comprehensive test suite (74 tests)
client/ ← Template client (ignore)
server/ ← Template server (ignore)
pnpm --filter @stateproof/core test # Run tests
pnpm --filter @stateproof/core check # TypeScript type check
pnpm --filter @stateproof/core build # Build with rollup-
DSL Layer (
machine.ts,concurrent.ts): Fluent builders that collect state machine definitions into an AST (MachineAST / ConcurrentAST). -
Compiler Layer (
compiler.ts): Parses constrained JavaScript function sources (guards, actions, invariants) into a simple expression AST, then translates to TLA+ expressions. Supports: comparisons, logic, arithmetic, array ops, Math.floor. -
Generator Layer (
tla-generator.ts): Takes a MachineAST and produces a complete TLA+ module (.tla) and configuration (.cfg). Handles single machines and concurrent compositions. -
Verification Layer (
tlc.ts): Writes TLA+ files to temp dir, shells out to TLC (Java), parses output into structured VerifyResult with violations and traces. -
Test Generation (
test-generator.ts): BFS simulation to generate traces covering all transitions. Also extracts violation traces from TLC counterexamples. -
Runtime (
runtime.ts): Creates executable state machines from specs. Also generates standalone TypeScript source code.
The compiler handles a strict subset of JavaScript:
- Property access:
ctx.x,ctx.arr.length - Comparisons:
===,!==,<,<=,>,>= - Logic:
&&,||,! - Arithmetic:
+,-,*,%,Math.floor(x/y) - Array:
.push(),.shift(),.length,.includes() - Assignments:
ctx.x = expr,ctx.x += n - Literals, ternary, null
No closures, no async, no arbitrary function calls.
- Add types to
types.ts - Implement in the appropriate module
- Export from
index.ts - Add tests to
index.test.ts - Run
pnpm --filter @stateproof/core test && pnpm --filter @stateproof/core check