Workshop index · Download all examples and lessons
Time: 40 minutes. Prerequisite: lesson 4. Outcome: a test that fails on a defect and passes on its correction, for a reason you can explain.
Open the cancellation exercise. The contract says cancellation restores seats exactly once. Read the store and predict the result of two cancellation calls before running tests.
Choose an expectation independently
The store starts with seven available seats and a three-seat booking. After cancelling that booking once, ten seats are available. Cancelling it again must not create more capacity.
This expectation comes from the contract. Do not ask an AI to infer the expected value from the current implementation; that can produce a test that merely preserves the bug.
Python task
Add a test that cancels twice. Assert both return values and final availability. Run it against the candidate, record the failure, then move the state mutation after the already-cancelled check and run it again.
TypeScript task
Run the smoke test and the misleading test separately. The misleading test creates a promise that never resolves, attaches assertions to it, and returns immediately. No assertion about cancellation is executed. Its green result is not evidence about the contract.
Replace it with an async test that awaits two actual cancellation calls and checks the return values and availability. Observe the failure before changing the store. Simply adding await to the never-resolving fake gate will not produce a meaningful test; remove the unused gate and await the operation you intend to exercise.
Challenge a generated test
Constructed AI suggestion:
“After two cancellations the implementation reports 13 available seats, so the regression test should assert 13.”
Explain why this assertion is wrong even though it matches the observed code. Then ask a live assistant, if available, to propose a counterexample to your corrected test rather than to rewrite the service.
Hint: place the mutation behind the guard
The early return must happen before increasing availability. Otherwise the return value can be correct while state is already corrupted.
Checkpoint
Save the failing output, the corrected test, and the passing output after the fix. Explain what your test covers and what it does not: it does not establish thread safety or persistence correctness.
Compare with the reference solution. Continue with cross-component behaviour.
← 4. Ask AI questions you can verify · 6. Follow the failure beyond the diff →