state-machine-testing
Skill1 starsChanged 2 months agoMITView on GitHub
Test stateful flows exhaustively by modeling states and transitions — checkout, onboarding, subscription lifecycle, order status — covering every valid transition and rejecting every invalid one. Use for multi-step flows, wizards, status fields, or anywhere "it got stuck in a weird state" happens.
In this repository34 other files it gives its agents.
- a11y-auditSkill
- api-contract-testingSkill
- autonomous-explorationSkill
- bug-reproSkill
- chaos-resilienceSkill
- ci-wiringSkill
- contract-testing-pactSkill
- coverage-ratchetSkill
- database-testingSkill
- e2e-authoringSkill
- environment-paritySkill
- exploratory-chartersSkill
- false-positive-hunterSkill
- flake-forensicsSkill
- i18n-l10n-testingSkill
- load-and-stressSkill
- mutation-proofSkill
- never-break-prodSkill
- payment-testingSkill
- perf-budgetSkill
- qa-triageSkill
- regression-curationSkill
- release-gateSkill
- responsive-mobile-testingSkill
- risk-mapSkill
- root-cause-protocolSkill
- security-regressionSkill
- smoke-and-sanitySkill
- test-data-managementSkill
- test-strategySkill
- tracking-testingSkill
- transactional-email-testingSkill
- unit-test-authoringSkill
- visual-regressionSkill
The file
Files
State Machine Testing
Any entity with a status column is a state machine, whether or not anyone drew it. The bugs
live in the transitions nobody drew.
Model first
draft --submit--> pending --approve--> active --cancel--> cancelled
| |
reject expire
v v
rejected expiredList every state and every event. Then build the transition table, including the cells that must be refused:
| From \ Event | submit | approve | cancel | expire |
| draft | pending | reject | reject | reject |
| pending | reject | active | cancelled | reject |
| active | reject | reject | cancelled | expired |
| cancelled | reject | reject | reject | reject |
The bold cells are the tests nobody writes and the bugs everybody ships. Approving a cancelled order, cancelling twice, submitting a draft twice from two tabs — each is one cell.
Coverage targets, in order
- Every valid transition — one test each, asserting the new state and its side effects.
- Every invalid transition — asserted to be refused, with the state unchanged afterwards.
- Every terminal state — no event escapes it.
- Idempotency — the same event twice produces one effect (see
chaos-resilience). - Concurrency — the same event from two clients simultaneously; exactly one wins, and the loser gets a coherent error rather than a corrupted row.
Generate rather than hand-write
for (const [from, events] of Object.entries(TRANSITIONS)) {
for (const [event, expected] of Object.entries(events)) {
test(`${from} + ${event} -> ${expected ?? 'rejected'}`, async () => {
const order = await seedOrderInState(from)
const res = await api.post(`/orders/${order.id}/${event}`)
if (expected) { expect(res.status).toBe(200); expect(await stateOf(order.id)).toBe(expected) }
else { expect(res.status).toBe(409); expect(await stateOf(order.id)).toBe(from) }
})
}
}The table is the specification, the tests are generated from it, and a new state is one row — not twelve copy-pasted tests.
Property-based extension
For deep flows, random walks find sequences no human enumerates: apply random valid events and assert the invariants hold at every step (fast-check, Hypothesis). Invariants beat expected values here — "a cancelled order never has a charge created afterwards" holds for every path.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

