Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

These exercises practice retrieving what the Module 12 reading explained. They aren’t graded. Work each one on paper first, then check your answer, and only then confirm it with Lab 12 and the starter repository if you like. The answers are in the collapsed blocks; open one only after you have an answer of your own.

Worked example: evidence, decisions, and reports

Here is a short illustrative session, in Lab 12’s format, for a task on the starter’s repair_total:

0 | user  | task         | Make repair_total raise ValueError for a negative part price.
1 | tool  | repository   | Read repair_shop.py: repair_total sums part_cents with no checks.
2 | model | tool_result  | Add a check before the sum, and a test for a part at -200.
3 | tool  | repository   | Test run: Ran 3 tests, OK.
4 | model | conversation | Done: negative part prices now raise ValueError.

Sort each turn by what it gives you:

Exercise P12.1 (LO-12.1, ★, about 10 minutes)

Which events in the example are file or test evidence, and which are decisions?

Hint

Use both the event and the origin of each turn in Lab 12’s session.

Answer

The tool events contain the evidence: what the files said and what the test runs printed. The model events interpret that evidence and decide the next step; the ones whose origin is tool_result rest on the tool event immediately before them. The final model turn, a summary, is a report: a claim about the evidence, which you check against the tool output.

A common mistake is to count the final summary as evidence because it mentions tests. It is the model’s description of a result, not the result.

Worked example: a test-only task

The vague request “the flat-repair estimate seems off when there are two” becomes a task with an acceptance criterion, a value that a test can check:

Check that estimate_minutes in repair_shop.py counts a repeated service once per occurrence:
estimate_minutes(["flat", "flat"]) should return 50. Add that assertion to test_estimate in
test_repair_shop.py. Don't change any rate. If the assertion fails, report the failure and stop
before editing repair_shop.py. Run python -m unittest discover -v and report its output.

The criterion is the expected value, 25 + 25 = 50. The task also names the files, keeps the rates fixed, and says what to do if the check fails.

Exercise P12.2 (LO-12.2, ★★, about 15 minutes)

Turn “repair costs look weird” into a task with a clear acceptance criterion.

Hint 1

Which function computes a repair’s cost, and in what unit?

Hint 2

Give input values and the expected total, so a test can check them.

Answer

One good answer:

In repair_shop.py, repair_total(labor_cents, part_cents) must return the total in integer cents:
repair_total(1200, [200, 500]) returns 1900, and repair_total(1200, []) returns 1200. Add a test
in test_repair_shop.py for a case that isn't a whole number of dollars, such as
repair_total(1250, [5]) returning 1255. Change nothing else. Run python -m unittest discover -v
and report the suite's result and the files you changed.

The acceptance criterion is the expected totals: 1,200 + 200 + 500 = 1,900 cents. Integer cents matter because the function’s own docstring promises them. The most common mistake is to keep the word “weird” and add only “fix it,” which leaves the agent to guess both the symptom and what “fixed” means. Another is to give an expected value without a test, so nothing checks it.

Worked example: a diff that edits a test’s expected value

A diff for a rounding bug changes repair_total and also edits a test:

-        self.assertEqual(repair_total(1200, [200, 500]), 1900)
+        self.assertEqual(repair_total(1200, [200, 500]), 2000)

The suite now passes, but only because the test was changed to agree with the code. The task didn’t ask for a new total, so the edited expectation is the evidence that the change is wrong. Ask what behavior the original test protected, restore it, and rerun the suite.

Exercise P12.3 (LO-12.3, ★★, about 15 minutes)

The proposed diff deletes the existing underscore test. What should you check?

Hint 1

The old behavior is a requirement.

Hint 2

A suite with the test removed can’t fail on underscores. What would it take to show that underscores still work?

Answer

Check whether the code still turns underscores into spaces: keep the underscore case, add a hyphen case, and run both. Deleting the test removes the evidence for a behavior the task said to keep, so a passing suite afterward proves nothing about it. Restore the test before you judge the change.

The common mistake is to accept the diff because the suite passes. When a diff deletes or weakens a test, read that hunk first.

Exercise P12.4 (LO-12.2, LO-12.3, ★★★, about 25 minutes)

Write a scope rule for when the agent sees a necessary change in a third file.

Hint 1

Separate noticing a change from having permission to make it.

Hint 2

What should the agent tell you, and when may it go on?

Answer

Ask it to describe the dependency and wait for a decision before editing outside the two named files. For example:

Edit only repair_shop.py and test_repair_shop.py. If the change needs an edit to any other file,
stop before editing it, name the file and the change it needs, and explain why. Wait for my
answer.

The rule keeps the decision about scope with you, while the agent still reports what it found. A common mistake is to write “don’t touch other files” alone. The agent then either stops without saying why or works around the dependency in a way you can’t see.