Estimated time: ~14 hours for someone new to Python (an estimate, not yet measured with real learners). The starter file:
code-labs/l1-m05/exercises/test_order_service.py.
Main practical exercise
Business context
The ShopEasy team (fictional) has rewritten the order agent and the ticket classifier "to be faster and cheaper" (v2). Before v2 answers real customers and is allowed to create return orders, you are asked to write schema and function-call validation tests: verify that v2 follows the contract, point out the violations, and assess their severity.
The problem to solve
Does v2 follow the contract A1-A10 and K1? If not, which violations can cause wrong side effects, 400 errors for customers, or leaks of internal information?
Input data
- Contract: the docstring of
lab/order_service.py(A1-A10, K1). - Tools:
lab/fake_api.py(message,text,tool_use,Reply),lab/tools.py(MockOrderSystem,INPUT_SCHEMAS,ORDERS),lab/schemas.py,lab/conversation.py; the fixturesapi,clientintests/conftest.py. - Black-box rule: call v2 through
service.make_agent(...)andservice.classify(...); observe what it sends (api.requests), what the backend runs (backend.calls) and what it returns. Do not readlab/_v2_impl.py.
Tasks
- Contract analysis.
contract-analysis.md: for each clause A1-A10 and K1, record the fake replies to queue, the quantity to measure (requests, backend calls, turns), and the oracle. - Test pack. Copy
exercises/test_order_service.pyintotests/. Write at least one test for each clause, namedtest_a<number>_...ortest_k1_.... The pack must have:- at least one test with two parallel tool calls;
- at least 4 wrong-argument cases for
create_return, including at least one business-rule case; - both branches of the approval, with every value of
reason; - a
max_tokensturn with atool_use, arefusalturn, a tool error, and a backend that raises an unexpected exception; - at least one three-turn conversation script run with
conversation.run_script(...)against v2. The golden file must be recorded from the reference agent (python -m lab.conversation record <script file> --save), and then the transcript of v2 is compared with it. Never save a transcript of v2 as the golden file: that golden file would protect v2's own bugs. - at least one API-error test (A9):
api.queue(Reply(status=500, body=error_body("api_error", "boom"))).
- Run and analyse. For each failing test: is it a bug in v2 or a bug in the test? Based on what?
- Defect report.
reports/v2-defects.md: one entry per bug, with the clause, the fake replies and input that reproduce it, expected, actual (with the relevant request,backend.callsorside_effects), severity, and the impact in production. - Reflection. 5-10 sentences: which of your tests say nothing about the behaviour of the real model? Which kind of test would you add once you have the real model (L1-M06)?
Deliverables
contract-analysis.md
tests/test_order_service.py
reports/v2-defects.md
reports/reflection.md
Paste the output of python -m pytest tests/test_order_service.py -v at the end of the defect report.
Acceptance criteria (mandatory)
| # | Criterion |
|---|---|
| AC1 | Every clause A1-A10 and K1 has at least one test; runs offline, needs no real API key |
| AC2 | Side-effect tests assert backend.side_effects(), not just the answer |
| AC3 | Protocol tests assert the actual requests (api.requests), not just the returned result |
| AC4 | Each failing test has a matching defect report, or is explained as a bug in the test |
| AC5 | At least 6 different bugs are found |
| AC6 | No real API key, real data or real API output in the submission |
Scoring rubric (100 points)
| Dimension | 0 | 1 | 2 | 3 | Weight |
|---|---|---|---|---|---|
| Test design | AC1 not met | AC1 met, each clause has only easy cases | AC1-AC3 met; has parallel calls, wrong arguments, both approval branches, abnormal turns | As level 2, plus a three-turn script with a golden file and at least one case not in the lessons | 25 |
| Implementation | Does not run | Runs, but only asserts turn.text |
Asserts requests, backend calls and turns | As level 2, with independent tests, clear failure messages, sensible parametrize | 25 |
| Contract analysis | Missing | Lists the clauses | Has fake replies, measured quantities and an oracle for each clause | As level 2, plus points out where the contract is ambiguous and questions for the product owner | 10 |
| Defect analysis | AC5 not met | 6 bugs, severity or impact missing | ≥ 6 bugs, each with its clause and severity | As level 2, plus a reasoned impact (side effects, 400 errors for customers, information leaks) and at least one bug outside the patterns learned | 15 |
| Reporting | Missing | Vague | All fields, reproducible | Concise, with requests and side_effects, clear fix priorities |
15 |
| Reflection | Missing | Generic | Distinguishes integration tests from model evaluation | As level 2, plus a test plan for the real model with a number of runs and property-style oracles | 10 |
Score per dimension = (level reached / 3) × weight. Mapping to the module: practical = Test design + Implementation (50); applied QA analysis = Contract analysis + Defect analysis (25); review/reflection = Reporting + Reflection (25).
Hints
Hint 1
Some bugs only appear when the model does two things at once, or when the conversation is longer than two turns.Hint 2
If many tests fail with the same kind of `api_error`, read the 400 message in `api.requests` and the response before drawing a conclusion. One bug can hide others (masking, L1-M02-L05).Hint 3
Count the requests, do not just read the answers. An agent can answer correctly and still send wrong requests, or send too many requests.Independent challenge (practical challenge)
There is no code to run. This assesses design skills.
Context: TravelMate (fictional) is a hotel-booking agent with three tools: search_hotels(city, check_in, nights), book_room(hotel_id, check_in, nights, guests) (charges the card), cancel_booking(booking_id).
The product owner requires: "Never book or cancel without the customer's confirmation; at most 14 nights; the
check-in date is never in the past."
Tasks:
- Write the
input_schemaforbook_room(includingadditionalProperties: false), and point out which constraints must be checked in code if strict tool use is used. - Design 10 cases for wrong arguments and business rules, each with its expectation.
- Write 3 multi-turn conversation scripts (described in words), each protecting against a different risk, and state which field of the transcript is the oracle.
Separate rubric (100 points, pass at ≥ 70):
| Dimension | 0 | 1 | 2 | 3 | Weight |
|---|---|---|---|---|---|
| Schema and constraints | Missing | The schema has errors | A correct schema, points out the constraints that must be checked in code | As level 2, plus the time-dependent rule (check-in) and how to test it deterministically | 30 |
| Argument cases | Missing | Only data-type cases | 10 valid cases, including business rules | As level 2, covering every group of L04 and both approval branches | 35 |
| Scripts | Missing | One turn | 3 multi-turn scripts, with oracles | As level 2, each script protecting against a different risk (side effects, context, tool errors) | 35 |
Rules
- No real API key, real data or real API output in the submission.
- Do not add tests that call the real API to the submission. If you try the real model yourself, use your own account and a spending limit (L1-M03-L01).