Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Debugging with an Assistant  ›  Lesson

Reproduce Before You Fix

Debugging 12 minBefore asking for a fix, pin down the steps, expected result, actual result and smallest case, then capture the bug in a failing test.

Reproduce Before You Fix

Meera sends a message: "Kitty says I've paid way more than I have." The fastest-looking move is to paste that into the assistant with "fix the balances". It will change something plausible, and you will have no way to tell whether it fixed Meera's problem, a different problem, or nothing. Debugging starts before any fix.

The rule

No fix until you can make the bug happen on purpose.

A bug you can trigger whenever you like is half solved. To get there, pin down four things:

  • Steps. Exactly what was done, in order.
  • Expected. What should have happened, according to the spec.
  • Actual. What happened instead, with real numbers.
  • Smallest case. The shortest set of steps that still shows the bug. Strip away every expense, flatmate and click that does not matter.

Then catch the bug in a test. A failing test is the bug held still: the assistant can run it, you can see when it turns green, and it stays in the suite to stop the bug returning.

def test_editing_an_expense_replaces_it():
    flat = make_flat(["Asha", "Ravi", "Meera"])
    expense = add_expense(flat, paid_by="Meera", paise=30000, note="groceries")
    edit_expense(flat, expense, paise=33000)
    assert total_paid(flat, "Meera") == 33000

Now your prompt can be precise: "This test fails: Meera's total is 63000 instead of 33000. Make it pass without editing the test."

The shortcut

Before any fix prompt, write four lines: steps, expected, actual, smallest. If you cannot fill one of them, you are not ready to ask for a fix. Ask questions or experiment instead.

From "my balance is wrong" to a failing testStep 1 of 4
  1. Steps

    You ask Meera what she did. She logged ₹300 of groceries, then noticed the receipt said ₹330 and edited the expense.

The trap is fixing the story instead of the bug. "Balance is wrong" could mean a dozen different faults. Reproducing it turns a story into one specific, checkable fact.

Drills

Answer fast — trust the rule.

quick drill

Meera says "my balance is wrong". What is your first move?

quick drill

Why shrink a bug down to its smallest case?

quick drill

What does turning the bug into a failing test give you?

quick drill

After one edit from ₹300 to ₹330, Meera's total shows ₹630. What is the most likely cause to check first?

Remember

  • Rule: no fix until you can make the bug happen on purpose.
  • Shortcut: steps, expected, actual, smallest, then a failing test.
  • Trap: sending the story ("it's wrong") instead of the reproduced fact.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainCatch the bug

Ravi reports that 'settle up doesn't work'. Explain how you would turn this into steps, expected, actual and a smallest case, and what exactly you would hand the assistant once you have them.