Metakit / Write a rule once

4. Prove that every transition preserves the schema invariants

Prove.machine checks that no state a transition's guard allows can break a rule of the Schema. It runs the built-in interval and zone checkers first and starts Z3 only for a goal they cannot decide. pin names the transitions that must stay proved.

ts
import { Effect } from 'effect'
import * as Prove from '@doeixd/metakit/prove'

const report = await Effect.runPromise(
  Prove.machine(AccountMachine, {
    pin: [AccountMachine.transitions.Withdraw, AccountMachine.transitions.Freeze],
  }),
)
// report.ok -> true
// report.format():
//   PROVED (zone) Withdraw [pinned]
//   PROVED (zone) Freeze [pinned]

If someone removes Num.lte(input.amount, Num.sub(state.balance, state.reserved)) from Withdraw, report.ok becomes false and report.format() prints a state and input that break the rule: the exact before, input, after, the violated rule, and a Transition.run(...) call that repeats it. Try it: delete that guard line, run the file again, and compare with the report in Verify a state machine in CI.