Guide an Agent Starting from a Failing Test
Scenario
Order the four red-green steps when guiding an agent to fix canBook(0).
- 1…
- 2…
- 3…
- 4…
Try it yourself
Place the four workflow steps in the repeatable red-green order.
Reveal the explanation
- Add a test asserting canBook(0) === false
Encodes the exact missing contract expectation.
- Run the test suite and confirm the new test FAILS on the buggy code
Proves the test genuinely reproduces the bug.
- Make the smallest code edit (freeSeats >= 0 -> freeSeats > 0)
Changes only the faulty condition.
- 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
This browser could not save your progress. Changes last until you leave the page.