Return a few days after finishing. Close the earlier lessons and use your own notes only after a first attempt from memory.
Four boundary bugs
This copy of the project has four deliberately broken rules. The case table
runs repository operations on fresh fixtures and reports four findings.
Fix the implementation in lib/domain.js and lib/repository.js, not the
checks in lib/review-checks.js.
npm install and npm run dev. Hint 1: the idea
The failures concern tenant isolation, deletion authorization, output projection and version checks. For each, write a counterexample and the state that should remain unchanged before editing anything.
Hint 2: a first step
Each finding names the rule it guards. Start from the check in
lib/review-checks.js, note the call it makes, and follow that call into
lib/repository.js and the helper it uses in lib/domain.js. Two of the bugs
are in domain.js helpers that several operations share, so one fix there
repairs more than one operation. Compare each line with what Day 1 or Day 2
said it must check.
The four bugs
| Finding | The broken line | The fix | Taught on |
|---|---|---|---|
| Tenant isolation | canWrite compares only actor.id === row.ownerId | also require actor.tenantId === row.tenantId | Day 1, deny by default |
| Deletion permission | remove checks only if (!row) | if (!canWrite(actor, row)), the same guard as edit | Day 1, trusted actor |
| Public projection | publicItem returns { ...row } | an allowlist: { id: row.id, title: row.title, version: row.version } | Day 1, minimal output |
| Stale edit rejected | edit has no version comparison | if (row.version !== version) return { ok: false, code: "conflict" }; before the write | Day 2, concurrent edits |
The tenant bug lives in a shared helper, so it also let get and list read
across tenants; fixing canWrite repairs all of them. The spread in
publicItem sends ownerId and tenantId to every page and route that shows
an item. The exercise is complete when all four findings pass without any
change to lib/review-checks.js.
Retrieval questions
- Which values come from a caller, and where is identity established? (Day 1)
- Which fields may leave the server, even for an authorized reader? (Day 1)
- What must remain unchanged after a rejected mutation, and how would a test prove it? (Days 2 and 6)
- What makes a version check atomic with the write? (Day 2)
- Why can offset pages skip a row, and how does a cursor with
limit + 1know there's no next page? (Day 3) - Which changes to an error vocabulary are safe for existing clients, and what must a client do with a code it doesn't know? (Day 3)
- When should a request be retried, and how long may each call wait inside one deadline? (Day 4)
- Which cache scope could return another caller's data, and why can't a
"use cache"function readcookies()? (Day 5) - Why does
toLocaleTimeString()in a client component's first render cause a hydration error, and what's the fix? (Day 5) - What's the difference between a readiness probe and a release gate? (Day 6)
- Which evidence must come from a real Next.js build or database? (Day 7)
If any answer is vague, redo that day's checkpoint without the solution. Completion is a useful record of practice, not evidence of mastery by itself.
Completion is saved in this browser only. It does not measure mastery.