Skip to content
mentoor

Topic 4 of 5 · 6 min read

A plan-build-review task end to end

Goal: Follow a full task through plan, build and review and name the point where the loop should have stopped.

The loop is: explore, plan, then repeat build, check, review, commit for each step. Seeing it on one real task shows where it earns its keep.

Check yourself · 1 of 3

In the coupon example, the agent changed an existing test's expected total from 19.99 to 20.0. What is the right reaction?

Choose one answer

The task

"Let customers enter a coupon code at checkout." The codebase is a Node shop with calculateTotal, an orders table and tests with Vitest.

Explore and plan

You start in a read-only mode: "Read src/checkout and src/db. Explain how totals are computed. Do not edit." The agent answers and mentions that discounts exist for staff, in applyStaffDiscount. You ask for a plan. It returns three steps:

  1. Add a coupons table and model.
  2. Apply a coupon inside calculateTotal.
  3. Add the coupon field to the checkout API and test it.

You add one correction: reuse applyStaffDiscount's rounding helper. Then you approve.

Step 1: model and migration

The diff is two files plus a test. The migration runs. You commit.

Step 2: apply in calculateTotal

Here it nearly goes wrong. git diff --stat shows four files, not two. The agent also edited formatPrice.ts, and one existing test now expects different rounding.

- expect(calculateTotal(cart)).toBe(19.99)
+ expect(calculateTotal(cart)).toBe(20.0)

This is the stop point. A passing test was changed to fit new behaviour, and nobody asked for new rounding. You do not approve. You tell the agent to revert formatPrice.ts and the test, and to use the rounding helper from applyStaffDiscount. The diff shrinks to two files and the old test passes unchanged. You commit.

Step 3: API field

The agent adds couponCode to the endpoint. The review finds that an unknown code returns HTTP 500. You ask for a 422 with a clear message and a test. Fixed inside the same step, then committed.

What the example shows

  • The read-only start found a rule (staff discount rounding) the agent would have missed.
  • The review at step 2 caught a changed test, which a pass-or-fail check alone would not catch.
  • Each commit made a rollback possible, but none was needed.

What goes wrong

  • Skipping the explore step. The agent invents rounding that conflicts with the existing helper.
  • Treating green tests as proof. The test went green because it was edited.
  • Not stopping. If you approve at step 2 to keep momentum, step 3 builds on wrong rounding.

Examples

The stat that gave it away

$ git diff --stat
 src/checkout/calculateTotal.ts      | 18 ++++---
 src/checkout/calculateTotal.test.ts |  6 +--
 src/lib/formatPrice.ts              |  9 ++-
 src/lib/formatPrice.test.ts         |  4 +-

Step 2 should touch only the first two files. The last two are the drift.

The error that was a 500

An unknown coupon code made the API crash with a 500. The review caught it because the step's plan said "test the failure path" and the diff had no such test.

Key points

  • The loop is explore, plan, then build, check, review and commit for each step.
  • Reading the existing code first finds rules the agent would otherwise invent over, such as a rounding helper.
  • A test changed to match new behaviour is a stop point, even when the whole suite is green.
  • Fix problems inside the step where they appear, then commit the clean result.
  • Each commit is a rollback point, even when you never use it.

Common mistakes

  • Approving step 2 because the full test suite passed.
  • Starting step 3 before the problem from step 2 was fixed.
  • Skipping exploration, so the plan ignores existing helpers.
  • Not committing between steps.

Check yourself · 2 of 3

Why was exploring the code before planning useful in the coupon task?

Choose one answer

Check yourself · 3 of 3

What does git diff --stat tell you at the start of a step review?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic