Workshop index · Download all examples and lessons
Time: 30 minutes. Prerequisite: lesson 2. Outcome: a behaviour map and a list of invariants grounded in callers and contracts.
Open the request adapter exercise. Start with the baseline, not the candidate diff. This adapter bridges untrusted decoded JSON and the booking function you already reviewed.
Follow one request
Trace { "seats": 2 } with capacity 10 and booked 7. Find the value after defaulting, the validation decision, the arguments sent to reserve, the service result, and the HTTP-shaped response. Do this in code, using Emacs file navigation or project search.
Your map should resemble:
decoded JSON → default missing field → validate quantity
→ reserve(capacity, booked, seats) → translate result to response This is a map of function calls, not a claim that the exercise runs an HTTP server.
Locate the trust boundary
Lesson 1 gave the service a valid-integer precondition. Here you can inspect the adapter that enforces it. In Python, bool is a subclass of int, so the exact type check excludes booleans. In TypeScript, number alone would permit fractional values; Number.isInteger enforces the integer requirement at runtime.
Write down three invariants: an invalid request never reaches the service; omission has a specific default; successful responses preserve the service’s booked total. Identify the line that enforces each.
Independent exercise
Trace these inputs before running code: {}, { "seats": 0 }, { "seats": null }, and { "seats": 4 }. Use capacity 10, booked 7. Record the expected status and whether the service should run.
Only now inspect the candidate diff. State the author’s intended change in one sentence. Identify which invariant is at risk without yet asking a model for a general review.
Optional AI question:
Trace the supplied request through the adapter and service. Cite the relevant expressions. Separate values established by code from assumptions supplied by the contract. Do not edit files or list speculative bugs.
Hint: find the caller's promise
The service does not distinguish a defaulted one from an explicitly requested one. If invalid input is converted into one before validation, the service cannot repair that mistake.
Checkpoint
You have a request map, four predicted outcomes, and the location of the input-validation boundary. Compare with the shared solution after lesson 4, so its defect explanation does not spoil your investigation.
Save your map and continue with verifiable AI questions. Both lessons use the same independent snapshots.
← 2. Your Emacs review workspace · 4. Ask AI questions you can verify →