The review workflow
Lesson 26 Verify, don't trust
write the failing test, lean on linters and types, make the AI explain and check it
What you'll learn
- Write the failing test first and watch it fail for the right reason
- Use type checkers and linters before reading
- Check an AI's explanation by running its claims
AI code reads well and sounds sure of itself. Neither is evidence. The only evidence is something that ran.
The idea
Three habits turn "it looks right" into "it is right". First, write the failing test before the AI writes the code, run it, and watch it fail for the right reason. A green result later then means something. Second, let machines do the boring checks: a type checker and a linter catch a whole class of mistakes without you reading a line. Third, make the AI explain its code, then check the explanation. Each claim in it is something you can run.
That is the whole course in one sentence: read in passes, name the patterns, distrust anything that can't fail, and run what you can't tell.
1// orders.test.js: written first, before asking the AI2import test from "node:test";3import assert from "node:assert/strict";4import { topOrders } from "./orders.js";56test("topOrders gives the 3 biggest, largest first", () => {7 const amounts = [9, 250, 40, 1200, 75];8 assert.deepEqual(topOrders(amounts, 3), [1200, 250, 75]);9});1011// orders.js: the AI's first attempt12export function topOrders(amounts, n) {13 return amounts.sort().reverse().slice(0, n);14}
- Line 1 Because you wrote the test first, the AI's claim "this works" has something to be measured against.
- Line 8 The test states the answer in advance, with numbers chosen so a wrong order shows. Run it before the AI's code exists: it must fail.
- Line 13 Reads fine: sort, reverse, slice. But
sort()with no function compares as text, and it changes the caller's array. The test catches it in a second.
Take away
- Write the failing test first, and watch it fail for the right reason.
- Let the type checker and the linter do the boring checking before you read.
- Ask the AI to explain, then turn each claim into something you can run.
Quiz: test yourself
7 questions: a quick quiz, then a review drill. Pick an answer to see why it's right.