Run a Tests-First Task

In the last video, task 3 went tests first: the criteria became a test, read against them, seen failing because the behavior was missing, and committed before the behavior existed. Now it’s your turn, on your own project and with your own agent.

In this lesson, you’ll write task 3’s criteria, ask your agent for tests only, read them, and commit them once they fail for the right reason. Then you’ll protect the test folder and ask for the code. Start where the video started, with the answers in your own words.

Write the Criteria, Then Ask for Tests Only

Tests can only check what you’ve decided, so decide first. Run git status and check that it shows nothing to commit apart from your agent’s settings folder. Then open docs/tasks.md and give task 3 its criteria and a done-when that ends in commands, as you did for task 2. Here’s the reference version’s task 3:

Language: Markdown Text Filename: docs/tasks.md
- [ ] 3. Each unreachable puzzle says which of its needs
  nothing reachable provides.
  Criteria:
  - The Smuggler's Cellar: the strongbox misses the iron
    key. The trapdoor misses only the trapdoor code,
    because the map gives the cellar code.
  - The Lighthouse Keeper's Study misses nothing.
  Done when all three pass after the last change:
  - npm test passes.
  - npm start --silent -- rooms/the-smugglers-cellar.json
    prints the verdict line, then these two lines:
    the iron strongbox: needs the iron key, which
    nothing reachable unlocks
    the trapdoor: needs the trapdoor code, which
    nothing reachable unlocks
  - npm start --silent -- rooms/lighthouse-keepers-study.json
    prints its verdict line and nothing else.

Your puzzle names and wording may differ. The printed lines are wrapped here to fit. Each is one line in the terminal.

Why “nothing reachable unlocks” when the old check line said “which nothing unlocks”? That wording is true of the iron key, but the strongbox does unlock the trapdoor code. No team can open the strongbox, though. Writing the exact line forced the distinction the video’s wrong version missed.

Now ask your agent for tests only. If you’d rather write the test yourself, do, and ask your agent only for the empty function. Here’s the reference version’s request, as an example of what each part does:

Language: Text
Task 3 from docs/tasks.md, tests only. Add a test to
test/check-room.test.js for a new function,
missingNeeds(room), exported from src/check-room.js.
It returns one entry per unreachable puzzle, in the
room's order, with its id and the needs that no
reachable puzzle unlocks:
- rooms/lighthouse-keepers-study.json gives [].
- rooms/the-smugglers-cellar.json gives
  [{ id: "strongbox", missing: ["iron key"] },
   { id: "trapdoor", missing: ["trapdoor code"] }].

Don't implement missingNeeds(). Add it only as an
empty function that returns [], so the test file
loads. Change nothing else. Then run npm test, stop,
and show me the output.

The criteria go in as examples, so the test has expected values that come from you. “Don’t implement” and “an empty function” keep the code out, and “show me the output” brings back the run you’re about to judge.

Start a new session, send your request, and when your agent stops, open the test file. Read the new test against each of your criteria:

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.