Done means the tests are green
By the end of this lesson you will have a test you wrote before the code and watched fail, and an agent's change that turned it green without touching it, so a symbol the API does not know stays on your list as a row marked unavailable.
Until now, verify has meant you: load the page, break it on purpose, look. That works, and it does not last. By the tenth change you check the thing you just touched and nothing else. This lesson moves the check into the repository, where your agent runs it on every change and your job shrinks to the part only you can do — deciding what it checks.
The order is the whole idea
- Write the acceptance criterion: one sentence you can be wrong about.
- Turn it into a test before any code exists, and watch it fail.
- Let the agent write the code, with one instruction: make this test pass without changing the test.
- The agent runs the tests itself and shows you the output. Done is green, not "I think it works".
Each step prevents something. A criterion written after the code describes what the code happens to do. A test written after the code tends to assert whatever the code printed. And an agent told to "make it work" decides for itself what working means — the one decision this track keeps handing back to you.
A criterion from the last lesson
The bad ticker. Today the starter's quotes() drops a row whose fields arrive as "NA", so a symbol the API does not know silently vanishes from your list. The criterion:
A symbol the API does not know stays on the list as its own row, marked unavailable, and the other rows are unaffected.
As a test, written against a literal response so it needs no network, no key and no open market:
// tests/rows.test.ts
import { expect, test } from "vitest";
import { toRows } from "@/lib/rows";
test("an unknown symbol keeps its own row and the others stay", () => {
const body = [
{ code: "AAPL.US", timestamp: 1793390400, close: 251.32, change: 2.42, change_p: 0.9723 },
{ code: "NOTREAL.US", close: "NA", change: "NA", change_p: "NA", volume: "NA" },
];
const rows = toRows(body);
expect(rows).toHaveLength(2);
expect(rows[0]).toMatchObject({ code: "AAPL.US", close: 251.32 });
expect(rows[1]).toEqual({ code: "NOTREAL.US", status: "unavailable" });
});
toRows does not exist yet. That is the point. The starter keeps its tests in tests/, beside the ones already there, and npm test runs them all in a few seconds. The @/ in the import is the starter's name for the src/ folder; if the failure says Cannot find package '@/lib/rows', it is complaining that the file is missing, not that you need to install anything.
See red first
npm test
It fails: there is no src/lib/rows.ts. That failure is your first evidence that the test runs at all. A test you have never seen fail proves nothing, because a test can pass by not running.
Now hand it over
Make tests/rows.test.ts pass. Write toRows in src/lib/rows.ts and use it in quotes(), so the watchlist shows an unavailable row instead of dropping it. Do not edit the test. Mock mode is on; to see the unavailable row on the page, add a ticker that does not exist (NOTREAL with the US suffix) to the watchlist for now (mock mode answers "NA" for any symbol it has no row for). Run npm test and npm run check:leak and show me both outputs.
The agent writes the function, runs the suite, reads its own failures and tries again. That loop is where a terminal agent earns its keep: you are no longer the clipboard between the code and the error.
What its green does not tell you
Did it change the test? "Make the test pass" has a cheap solution: weaken the test. Read the test file's diff first. If it changed, the green means nothing until you know why.
Does the test check the criterion? An agent writing its own tests tends to mirror the code — computing the expected value the way the implementation does, so both are wrong together and the suite stays green. Assert values you worked out yourself, like 251.32 above, copied from a response you read.
Does the page survive the row the test lets through? Look at the test's own AAPL row: it has no volume. isQuote never checked for one, so that row passes as a Quote, reaches the table, and the table's volume.toLocaleString() crashes the page. A green test proves what it asserts and nothing beside it. So volume becomes number | null, and the table prints a dash for null.
Done, in the house rules
Rule 6 of AGENTS.md says done means npm test && npm run check:leak pass, plus lint and the type check. Now you know why both halves: the tests check that the code does what you decided, the leak check that it does so without publishing the key. The starter's pre-push hook runs them again before anything leaves your machine, so a red suite cannot reach GitHub by accident.
From here on, every feature in this course starts as a sentence and a failing test. Build a Screener adds the second source of tests — the bugs a review finds.
Try it now
The prompt
Create tests/rows.test.ts with the test above and run npm test. Watch it fail. Stage it with git add tests/rows.test.ts, so git holds the version you wrote. Put EODHD_MOCK=1 in .env.local and restart, then give your agent the prompt above in Manual mode, with the plan asked for first:
Read tests/rows.test.ts and plan the change before writing code: which
files, and how quotes() will use toRows. Then make the test pass: write
toRows in src/lib/rows.ts and use it in quotes(), so the watchlist shows
an unavailable row instead of dropping it. A row with prices but no
volume, like the test's AAPL row, keeps volume as null and the table
shows a dash. Do not edit tests/rows.test.ts. Other source files and
tests may change where the new row type requires it; list them for me.
Mock mode is on; to see the unavailable row on the page, add a ticker that does not exist (NOTREAL with the US suffix)
to the watchlist for now (mock mode answers "NA" for any symbol it has
no row for). Run npm test and npm run check:leak and show me both
outputs, then the diff.
Read each step before you approve it. A good answer adds src/lib/rows.ts, changes src/lib/quotes.ts and the table component (and whatever else the new row type reaches, such as the page's sorting or age line) so an unavailable row renders and a missing volume prints a dash, leaves the test alone, and ends with both outputs green.
Check it yourself
- Your own first
npm testfailed becausesrc/lib/rows.tsdid not exist: proof that the test runs. - When it reports green,
git diff -- tests/rows.test.tsprints nothing. Unchanged is the only acceptable answer. - Run
npm testandnpm run check:leakyourself: both green, as the agent showed you. - With an unknown symbol on the list in mock mode, the page shows its row marked unavailable, and every other row as before.
- Take one more failure from the last lesson, the missing key, write its criterion as one sentence, and run the whole loop again without this page open. Expect a second test file, red first and then green.
Break it on purpose
Break the code on purpose — make toRows mark every row unavailable — and run npm test. Red means the test has an opinion. Put it back and run it once more: green.
Compare with ours
Our toRows
// src/lib/rows.ts
export type Row = Quote | { code: string; status: "unavailable" };
export function toRows(body: unknown): Row[] {
const raw: unknown[] = Array.isArray(body) ? body : [body];
return raw.flatMap((r) => {
const code = (r as { code?: unknown } | null)?.code;
if (typeof code !== "string") return [];
if (!isQuote(r)) return [{ code, status: "unavailable" as const }];
const volume = (r as { volume?: unknown }).volume;
return [{ ...r, volume: typeof volume === "number" ? volume : null }];
});
}
isQuote moved here from src/lib/quotes.ts unchanged, Quote.volume is now number | null, and quotes() now returns toRows(body). The starter's branch ref/build-your-first-tool/u2 carries this unit's changes.

Checkpoint
First take the made-up ticker (NOTREAL with the US suffix) back out of src/lib/watchlist.ts: it was there to show the row on the page, the test covers it from now on, and live it would cost a call on every load.
npm test
git status # only the files you expect, and no .env*
git add -A
git commit -m "Keep an unknown symbol on the list as unavailable, test first"
git status lists whatever the agent touched to carry the new row type through; read each file before git add -A, and make sure no .env* file is among them. Commit the missing-key test from check 5 on its own, with a message that says why. Then answer this lesson's questions.