Ten tests of the export admission contract
The supplied SQLite teaching lab records requests, jobs, outbox rows and remaining credits after each failure. Explore the four pre-commit cuts, post-commit recovery and identity cases.
Ten-credit fixture
Each crash case starts in a temporary database with ten credits. Reconnect after the child process terminates and count committed rows before retrying.
Outgoing
- Stop after the first write→ After request insert
- Stop with an uncommitted debit→ After quota debit
- Stop with an uncommitted job→ After job insert
- Stop after staging the outbox→ Immediately before commit
- Stop after durable acceptance→ After commit, before reply
- Submit matching intents together→ Eight equal callers
- Resubmit a changed snapshot→ Same key, new snapshot
- Change the tenant namespace→ Same key, different tenant
- Express another intent→ Same input, new key
- Set initial credit to zero→ Exhausted balance
After request insert
The request identity was tentatively inserted. On reconnect no claimed request, job or outbox survives and the balance remains ten.
After quota debit
The transaction had reduced the balance. The uncommitted debit rolls back with the identity, restoring all ten credits.
After job insert
The job row may have existed within the transaction. Reopening the database must reveal no durable job awaiting a missing dispatch.
Immediately before commit
All four writes were staged, including outbox intent. The four observed values after restart are zero requests, zero jobs, zero outbox rows and ten credits.
After commit, before reply
Restart now finds one request, one job, one outbox row and nine credits. Replaying the same key must yield the saved receipt without changing any count.
Eight equal callers
Eight callers submit one key and payload. SQLite serializes writers in this fixture. All eight must converge on one receipt, one job and one debit.
Same key, new snapshot
After a prior acceptance, changing the normalized input with the original key must produce a mismatch and leave that acceptance untouched.
Same key, different tenant
Each namespace gets an independent job and balance. This teaching case exercises key scoping. Production authorization requires its own checks.
Same input, new key
A fresh key represents deliberate new work. An identical payload can produce another accepted job and another debit when there is credit.
Exhausted balance
The zero-credit fixture rejects admission. No partial request, job or outbox may survive. Retrying alone cannot fund an export.
Perform one admission
Retry after a pre-commit crash. The expected durable tuple is now one request, one job, one outbox and nine credits, all representing the same intent.
Compare durable state
Compare the receipt and the four state values with the prediction for this case. A successful HTTP status alone cannot establish the debit and dispatch invariant.
Incoming
- Replay the existing receipt← After commit, before reply
- Assert one accepted job← Perform one admission
- Compare all eight receipts← Eight equal callers
- Assert unchanged state← Same key, new snapshot
- Check both independent balances← Same key, different tenant
- Assert a second accepted job← Same input, new key
- Assert zero partial records← Exhausted balance
Move the test to the real adapter
Single-writer SQLite results apply to this fixture. Lock timeouts, lost commit acknowledgements and failover must be examined against the production engine and its isolation rules.