What this looks like

Give the agent a task and permission to run the tests, and the loop from Lesson 3.2 closes
without you in it:

Act    →  changes the code
Check  →  runs npm test
          → 2 failed
Read   →  reads the failure messages
Plan   →  "the date is being compared as text, not as a date"
Act    →  fixes it
Check  →  runs npm test
          → all passed

You watched. You did not intervene. That is the point.

How to set this up

Say it plainly in your request:

Run npm test after each change. Keep going until it passes.
Do not change any test to make it pass. If you think a test is wrong,
stop and tell me instead.

That last sentence matters more than the rest. Read on.

The move you must block

When an agent cannot make a test pass, changing the test is very tempting. It produces
green immediately.

It is also the single most damaging thing it can do, because you now have a passing project
that checks nothing, and you will not notice for a long time.

So put it in your instructions every time:

Never change a test to make it pass. If a test looks wrong, stop and ask.

And when reviewing, run this before anything else:

git diff -- '*test*'

If tests changed in a session that was supposed to fix code, read every line of that.

What makes this loop work well

Fast tests. If your tests take two minutes, the agent runs them rarely, and the loop
barely closes. Under ten seconds is a different experience entirely.

Clear failure messages. “Expected 2 but received 3” tells it where to look. “Assertion
failed” does not.

No manual setup. If a test needs a database started by hand, the agent cannot run it.

What breaks it

Flaky tests — ones that sometimes pass and sometimes fail — are worse than no tests. The
agent will chase a failure that was never real, change working code to fix it, and you will
have a genuine bug introduced in pursuit of an imaginary one.

If a test is flaky, fix it or delete it. Do not leave it.

Try this before the next lesson

  1. Break nextGap on purpose. Ask the agent to make the tests pass. Watch the loop.
  2. Now try it without saying “do not change the tests”. Does it change one?
  3. Time your test suite. If it is over ten seconds, what is slow?