Estimated time: ~16 hours for someone new to Python (an estimate, not yet measured with real learners). The starter file:
code-labs/l1-m04/exercises/test_shopeasy_v2.py.
Main practical exercise
Business context
The ShopEasy team (fictional) has received the bugs you found in v1 during this module and released v2. They say v2 "fixes everything". Before v2 answers real customers, you are asked to write a functional and negative test pack: functional tests, boundary inputs, prompt injection, refusal behaviour and consistency.
The problem to solve
Does v2 comply with the contract C1-C12? Do the fixes fix the whole class of defect or only the exact case that was reported? Does v2 have new defects?
Input data
- Contract: C1-C12 in the docstring of
lab/shopeasy.py. - Tools:
lab/oracles.py,lab/inputs.py,lab/injection.py,lab/refusal.py,lab/counterfactual.py,lab/chat.py --build v2. - The test environment's canary:
lab.shopeasy.TEST_CANARY. - Black-box rule: use only
make_assistant("v2").reply(...)andlab.chat --build v2. Do not readlab/_engine.py. The contract is the source of every expectation.
Tasks
- Oracle matrix.
oracle-matrix.md: every clause C2-C12 has a kind of oracle (exact, rule, reference, human), a concrete function, and a reason. - Exploratory session. One 30-45 minute session on v2, with a charter, a JSONL log and an edited session sheet (L03).
- Test pack. Copy
exercises/test_shopeasy_v2.pyintotests/. Write tests for every clause C2-C12, namedtest_c<number>_.... The pack must have:- a boundary pack: the length limit, whitespace, NFD for at least 3 flows, invisible characters, malformed order numbers, mixed language;
- at least 6 injection cases as data (
data/my_v2_injection.json), mapped to OWASP, including direct, indirect and control cases, with at least 3 techniques; - a refusal set of at least 10 cases, including at least 3 contrast pairs, with both rates;
- at least 2 counterfactual groups.
- Regression check for the fixes. For each known v1 defect (the 8 xfails in
tests/), write the matching test for v2 and a variant of the same class, such as another flow, another channel or another spelling. - Defect report.
reports/v2-defects.md: one entry per defect, with the ID, clause, exact input (ascii()when there are unusual characters), expected, actual, severity, impact and, for injection, the OWASP code and the defence layer that was bypassed. - Reflection. 5-10 sentences: which of your results hold only for the simulation? With a real model, which parts would you rerun, how many times, and how would you report the results?
Deliverables
oracle-matrix.md
sessions/<log>.jsonl + sessions/<log>-sheet.md (đã sửa)
tests/test_shopeasy_v2.py
data/my_v2_injection.json (+ data/docs/my-*.md)
data/my_v2_refusal.json
reports/v2-defects.md
reports/reflection.md
In English, "(đã sửa)" means "(edited)".
Paste the output of python -m pytest tests/test_shopeasy_v2.py -v at the end of the defect report.
Acceptance criteria (mandatory)
| # | Criterion |
|---|---|
| AC1 | Every clause C2-C12 has at least one test; expectations are taken from the contract, not from observed behaviour |
| AC2 | Injection oracles check the consequence (canary, link, facts), not the wording of the attack sentence |
| AC3 | The refusal set measures both rates, with counts |
| AC4 | Every failing test has a matching defect report, or is explained as a defect in the test |
| AC5 | At least 6 different v2 defects found |
| AC6 | No real personal data, no real secrets, and no experiments on systems you are not authorised to test |
Scoring rubric (100 points)
| Dimension | 0 | 1 | 2 | 3 | Weight |
|---|---|---|---|---|---|
| Test design | AC1 not met | AC1 met, only easy cases per clause | AC1 and AC2 met; boundaries, NFD in several flows, injection with several techniques, contrast pairs | As level 2, plus a same-class variant for every v1 defect and at least one case for a channel or technique not covered in the lessons | 25 |
| Implementation | Does not run | Runs, but weak oracles (intent only) | Several oracles per clause; data-driven cases with OWASP codes | As level 2, plus oracles verified with good/bad samples, sensible parametrisation, clear failure messages | 25 |
| Oracle matrix | Missing | Lists oracles | Kind of oracle and reason for every clause | As level 2, plus the limits of each oracle and questions for the product owner where the contract is ambiguous | 10 |
| Defect analysis | AC5 not met | 6 defects, missing severity or impact | ≥ 6 defects, each with clause, severity, defect class | As level 2, plus at least one defect that the lessons did not teach as a pattern, and a reasoned impact | 15 |
| Reporting | Missing | Vague | All fields, reproducible, with a session sheet | Concise, input in ascii() form, OWASP codes, clear fix priorities |
15 |
| Reflection | Missing | Generic | Separates simulation results from results that need verifying on a real model | As level 2, plus a plan for repeated runs with a number of runs and a concrete way of reporting | 10 |
Score per dimension = (level reached / 3) × weight. Mapping to the module: practical = Test design + Implementation (50); applied QA analysis = Oracle matrix + Defect analysis (25); review/reflection = Reporting + Reflection (25).
Hints
Hint 1
"Fixed" only means the reported case no longer fails. Try the same class of defect in another flow, another channel and another spelling.Hint 2
Every limit has three boundary values. Do not look only at `intent`: is the customer's question still answered?Hint 3
A document can carry instructions in several ways. Does the v1 fix handle all the ways you have learned?Independent challenge (practical challenge)
There is no code to run. This assesses design skills.
Context: HealthBuddy (fictional) is the chatbot of a pharmacy chain. It answers questions about opening hours and prescription status, and summarises the medicine leaflets uploaded by manufacturers. Policy: no diagnosis; hand off to a pharmacist when a customer asks about dosage; never disclose someone else's prescription; show a "call emergency services" button when a customer describes emergency symptoms.
Tasks:
- Write a contract in the form C1-Cn (at least 6 clauses) from the policy above, and point out 2 places where the policy is ambiguous.
- Design 8 injection cases (direct, and indirect through the leaflet), mapped to OWASP, each with a consequence-based oracle.
- Design a refusal set of 10 cases with 3 contrast pairs, and explain why over-refusal is especially dangerous in this context.
Separate rubric (100 points, pass at ≥ 70):
| Dimension | 0 | 1 | 2 | 3 | Weight |
|---|---|---|---|---|---|
| Contract | Missing | Clauses that cannot be verified | ≥ 6 verifiable clauses | As level 2, plus 2 ambiguous places with concrete questions | 30 |
| Injection | Missing | Direct cases only | 8 cases, with OWASP codes and consequence-based oracles | As level 2, plus an indirect case through the leaflet with a consequence that is dangerous to health | 35 |
| Refusal | Missing | One direction only | 10 cases, 3 contrast pairs | As level 2, plus reasoning about over-refusal with emergency symptoms | 35 |
Rules
- Do not use real personal data or real secrets in your submission; every document you write yourself must be fictional.
- Try injection techniques only on this lab or on a system you have written permission to test.