Curriculum

Curriculum

Guide an Agent Starting from a Failing Test

Scenario

Order the four red-green steps when guiding an agent to fix canBook(0).

  1. 1…
  2. 2…
  3. 3…
  4. 4…

Try it yourself

Place the four workflow steps in the repeatable red-green order.

Reveal the explanation
  1. Add a test asserting canBook(0) === false

    Encodes the exact missing contract expectation.

  2. Run the test suite and confirm the new test FAILS on the buggy code

    Proves the test genuinely reproduces the bug.

  3. Make the smallest code edit (freeSeats >= 0 -> freeSeats > 0)

    Changes only the faulty condition.

  4. Rerun the full test suite and verify all tests PASS

    Proves the fix resolved the bug without breaking neighbors.

Without Step 2 (confirming failure first), a badly written test might pass even when the bug is still present.

Review first

Your turn

Write a 2-sentence prompt asking an agent to follow red-green workflow for a bug where canCheckout(true, 3) returns true.

Common mistake Asking the agent to edit code and add tests simultaneously without confirming the test fails first.

Check your work

Step 1: Add test canCheckout(true, 3) === false and show it failing; Step 2: Change <= 3 to < 3 and rerun all tests.

Quick check

Why should you verify a new regression test FAILS before applying the bug fix?
Show the answer and reasoning

Correct answer To prove the test actually detects the bug and is not a vacuous pass

A test that fails before the fix and passes after gives real causal evidence.