Module L3-M03 exercises: a multi-step scenario suite for ThuVien Mini v2, from the end-state oracle and workflow coverage to partial credit and environment verification

Study time
≈ 4 h (estimate)
Updated
2026-11-04
Draft · reviewed by AI, not yet by a person. Content may change. English translation: AI-assisted, not human-reviewed.
On this page

Estimated time: ~4 hours for someone who has finished the four independent exercises of L01-L04 (an estimate, not measured with real learners). Main tools: lab.scenario, lab.workflow, lab.grading, lab.endstate, lab.agents in code-labs/l3-m03. Every agent, scenario, tool, cost (cu, a pseudo cost unit), score and result in the lab is simulated (deterministic functions written by the lab author): no model call, no real server, no API key needed; tools run only in memory and in a temporary folder.

Main hands-on exercise

Business context

The ThuVien Mini team (fictional) is moving the library assistant to ThuVien Mini v2 for a new school: student S0101, other books, and the same workflow "lend the first-choice book, if it is out lend the second, keep a note of the loan, queue a notice if it is approved". A colleague's ticket says: "the agent answers Done and the per-tool tests are all green so it is fine". That line does not say whether the agent really changes the right things, whether the scenario suite passes through every branch, whether a run that got half the work done is seen, and whether the message matches the environment. You need to build a multi-step scenario suite for v2 together with its reports, and then answer: what does this suite catch, and what does it not yet prove?

The problem

A happy-path scenario touches only one branch; an oracle that reads the message passes even an agent that does nothing; a scale can be gamed with a message; a comparison of message and state can report "clean" for a note with the wrong content; coverage of 1 does not say which defects the suite notices. Your job is to measure each part separately under the fixed configuration below, say what each part does not prove, and let a person record the final decision. The oracle, coverage, score and gate only flag and rank; the gate fails closed when data is missing and has no word for "approved"; every real effect needs a person's approval.

Input data

The lab's data is in code-labs/l3-m03/data/ (scenarios.json, workflow.json, tools.json, books.json, documents.json) and is fictional; do not edit lab/, data/, tests/ or exercises/. You write yourself every data file in the scenario_suite/ package.

Fixed configuration (so that every submission is reproducible and comparable):

Item Value
Scenarios (Task 1) 11 scenarios v01 to v11 taken from the lab's s01 to s11, with identifiers changed by the mapping table below (id sNN becomes vNN); keep the structure, checks, weights, scope and setup; edit goal, params and every book, student, name and approval key by the table
Workflow (Task 2) the lab's data/workflow.json (19 named edges, 17 reachable); the diligent agent
Agents (all tasks) the 12 agents of lab.agents.DEFECTS, each run on the 11 scenarios: 132 cells
Score (Task 3) lab.grading.grade and gate with the default min_full_rate of 1 and the default max_harmful of 0
Environment (Task 4) lab.endstate.compare on the same 132 runs
Reproduction (Task 6) Five Markdown reports, table.json, expected_v2.json, review.json and notes/decisions.md; no timestamps, no Python version

The mapping table (apply it everywhere it occurs, including goal, approval keys and note names):

In the lab In v2
B001 B005
B002 B006
B003 B002
B099 B098
B004 B004 (unchanged)
S0042 S0101
S0007 S0099
loan_s0042 loan_s0101
notice-s0042-b001 notice-s0101-b005

Tasks

  1. Scenarios and the oracle (L01). Write scenarios_v2.json by the table. Report oracle.md: an 11-row table (id, number of lint_scenario findings with the lab's six books, whether diligent passes the oracle, the failed checks, whether claim_only passes the oracle) and one sentence saying in how many scenarios message_oracle accepts claim_only.
  2. Workflow and coverage (L02). Write in mine.py the function min_cover(required, offers): the smallest number of scenarios and one concrete set (exhaustive search by increasing size, the first set in id order for the same size) that covers all of required; (0, []) when required is empty and (None, None) when it cannot be done. Write the function kill_matrix(rows, baseline_agent): rows is {(agent, scenario id): signature}, where the signature of a run is the three fields [level, score, violated rules] (the definition of "notices" in L02 §5.1, not the six fields of a table.json cell); return {agent: [scenario ids whose signature differs from the baseline]}; ValueError for a missing row or a missing baseline. Report workflow.md: the coverage line (Coverage ...), the line on unreachable edges with their reasons, the smallest-set line, and the table "which scenario notices which defect".
  3. Partial credit and the gate (L03). Report grading.md: a table of 12 agents × 11 scenarios with the level letter (F, P, N, H) and the fractional score; the line with the gate's decision for the diligent agent at the default threshold and its reasons; the line recording the person's decision from review.json (or "none" if decision is empty). In review.json you record a decision by a person, not by a test or CI.
  4. Environment verification (L04). Report endstate.md: for each agent, the list of scenarios where compare reports a mismatch (an unsupported claim or an unreported change).
  5. Mutations and the golden table. Generate table.json (each cell agent/id: level, score, oracle, rules violated, kinds of unsupported claims, unreported changes). Read each cell once and then write it into expected_v2.json (the golden table). Write check_suite() returning the list of cells that differ from the golden table. Report mutation.md: the number of differing cells (0) and the gate's fixed cases (missing, repeated, malformed, harmful, no approval). In notes/decisions.md, section Mutations, list at least ten broken versions of the oracle, the grader, diff_state, collateral, verify_claims, unreported or the process rules that you tried installing, which the golden table killed and which survived with the reason.
  6. Reproduction. Write build_scenario_suite.py, which generates six files in the output folder (five reports and table.json; every figure comes from lab and mine, none typed by hand) and test_build_scenario_suite.py, which checks the AC1-AC6 constraints on the text of the reports you generated. Write notes/decisions.md with exactly five sections: Scenarios and the oracle, Workflow and coverage, Score and gate, Mutations, What the suite does not prove. The last section answers: how far can this suite, the oracle, the score and the gate be trusted, and what are they not yet usable for.

Deliverables

scenario_suite/
  __init__.py                    (file rỗng)
  mine.py                        (Nhiệm vụ 2: min_cover, kill_matrix)
  scenarios_v2.json              (Nhiệm vụ 1)
  expected_v2.json               (Nhiệm vụ 5: bảng vàng 132 ô)
  review.json                    (Nhiệm vụ 3: quyết định của một người)
  build_scenario_suite.py        (Nhiệm vụ 6; chạy: python -m scenario_suite.build_scenario_suite <thư mục ra>)
  test_build_scenario_suite.py   (Nhiệm vụ 6; chạy: python -m pytest scenario_suite)
  notes/
    decisions.md                 (năm mục)

Put the scenario_suite/ folder inside code-labs/l3-m03 so that import lab works. Run from the lab folder. Use relative imports inside the package (from . import mine). Do not create or edit any file under .github/; every tool runs in a temporary folder (tempfile), and every temporary file you create must be deleted.

Acceptance criteria (mandatory)

# Criterion How it is checked
AC1 scenarios_v2.json has 11 scenarios v01 to v11, every params.student is S0101, it lints clean with the lab's six books, and every scenario has at least one check that reads the state; oracle.md has an 11-row table, diligent passes the oracle in 9 scenarios (failing v08 and v09 on check c2) and the sentence "Message-only oracle accepts claim_only on 11 of 11 scenarios." your test reads the text of the report; the grader runs it again
AC2 min_cover and kill_matrix are right at the edges (one set suffices; id order for the same size; empty required; impossible cover; a matrix with a missing row or a missing baseline is a ValueError); workflow.md has the line "Coverage 1 (17 of 17 reachable edges). Missing: none.", the two edges B:NOT_AVAILABLE and D:NOT_AVAILABLE with their reasons, the smallest-set sentence with 9 scenarios (v03 to v11) and a table in which no defect row is "none"; the retry_blocked row has only v11, the retry_limit row is v06, v07 the test reads the text of the report
AC3 grading.md has the 12 × 11 grid with cells computed by hand: diligent/v08 = P3/4, diligent/v01 = F1, claim_only/v01 = N0, wrong_book/v01 = H0 (lends B006 instead of B005: a change outside the scope), wrong_student/v06 = H0, skip_note/v10 = P4/5; the gate line for diligent is HOLD; the person's decision line is "none" when review.json has an empty decision, and no approval word appears in the report the test compares cells with hand-computed figures (not with the function under test)
AC4 endstate.md has a 12-row agent table: diligent is none; claim_only lists all 11 scenarios; wrong_book is none although the oracle grades it harmful in five scenarios (the agent says truthfully what it did, so comparing message and state sees no defect); retry_limit differs only at v08 (it lends B005, then keeps retrying the note until max_steps, so there is no final message and the change loan+:B005 is unreported); in table.json the cell wrong_student/v01 has an unsupported loan claim and the cell overreach/v01 has the unreported change note+:audit the test reads table.json and the text of the report
AC5 table.json has exactly 132 cells and equals expected_v2.json; check_suite() returns []; mutation.md has "No mismatch with the pinned table (132 cells)." and "Gate cases failing: none"; decisions.md section Mutations has at least ten broken versions, each marked killed or survived with a reason run the tests; the grader reads the section
AC6 Running again gives exactly six files (compared byte by byte), with no timestamps, Python version or CR characters; every report says this is simulated (or is the golden table) and has no vendor or model name; python -m pytest scenario_suite passes; notes/decisions.md has all five sections in order, every fraction in it appears in the reports, no ranking words ("best", "should use", "recommended") run twice and compare; the grader reads decisions.md against the rubric

Grading rubric (100 points)

Dimension 0 1 2 3 Weight
Scenarios and the oracle (AC1) Does not meet AC1 Scenarios exist but the lint is not clean or the oracle reads only the message Meets AC1; checks name both the book and the student As level 2, and states that the oracle does not know whether the goal matches what the user meant, a correct but different solution is flagged as a fail, called and final_has are weak evidence 15
Workflow and coverage (AC2) Does not meet AC2 Has coverage 1 but no table of which defect is noticed Meets AC2; both mine functions are right at the edges As level 2, and states that coverage says only that the branch ran, an "unreachable" edge is a person's decision, the table speaks only about known defects 20
Score and gate (AC3) Does not meet AC3 Has a score grid but explains no cell Meets AC3; hand-computed cells are right, the gate fails closed, no approval word As level 2, and states that the weights are judgements, a fraction is not a measurement, harmful merges several kinds of damage, and a person rather than the gate decides the threshold 20
Environment verification (AC4) Does not meet AC4 Has a mismatch table but mixes unsupported claims with unreported changes Meets AC4; tells the two kinds of mismatch apart correctly As level 2, and states that clean does not mean the run is right (wrong_note), the extractor reads only fixed phrases, a log that matches the state does not prove a good effect 15
Mutations and the golden table (AC5) Does not meet AC5 Has a golden table but copied it from run results without reading Meets AC5; at least ten broken versions, each with a conclusion As level 2, and explains why the survivors survive (no agent changes the number of loan days, every message phrase uses the same capitals, no agent breaks a pre-existing loan, the approval gate blocks every notice outside the scope) and says how to add an agent or a scenario to kill them 15
Reproduction and notes (AC6) Does not meet AC6 Reports typed by hand or not saying simulated A script generates every report, running again gives the same files, there are tests on the text of the reports As level 2, the tests catch deliberate faults (changing one golden cell, changing a weight, swapping two scenarios, setting the decision maker to ci), decisions.md is honest that every figure is simulated 15

The score of each dimension = (level reached / 3) × weight. Mapping to the module: practical = Scenarios and the oracle + Score and gate + Reproduction and notes (50); applied QA analysis = Workflow and coverage + Environment verification + Mutations and the golden table (50).

Hints

Hint 1: scenariosApply the mapping table to every word in the file, including `goal`, approval keys and note names. Then run `lint_scenario` and `W.execute(sc, "diligent")` on each scenario: the result must have the same shape as the original scenario (level, score, edges).
Hint 2: workflowA scenario's edges are in the `execute` result (`edges`). The set of edges to cover is `agents.edges(workflow, reachable_only=True)`. For `min_cover`, try every combination by increasing size; the number of scenarios is small, so exhaustive search is fast enough.
Hint 3: scoreRead each cell from `grade` rather than copying: the level is abbreviated to its capital first letter, the score is a reduced fraction. For a hard cell, compute by hand from the weights and then compare with the function.
Hint 4: mutationsInstall a broken version with `monkeypatch` on the lab's module and then run `check_suite()`; remember to remove it after each one. Do not install an equivalent broken version (no change in behaviour) and call it a "survivor" of the suite; ask whether it can change any cell of the golden table.
Hint 5: testing your own testsAfter the tests are green, try changing one golden cell, changing one weight in `scenarios_v2.json`, swapping two scenarios, setting the person's decision to `ci`, or letting the script write a timestamp: if the tests stay green they are only comparing a report with itself. A good test compares with a figure **derived independently** (a hand calculation), not with the output of the function under test.

Independent challenge (practical challenge)

Less guidance. No need for the scenario_suite package; use the lab's functions directly on the 11 original scenarios s01 to s11. Submit one file challenge.md with four answers and how you computed each.

Question Requirement
(a) Of the eleven defective agents, which one is noticed by exactly one scenario (its result differs from diligent's: level, score or the set of rules violated)? Name that scenario
(b) The smallest number of scenarios, among the 11, whose union of reachable edges covers all 17 edges; give one concrete set (the first set in id order for the same size)
(c) The scenarios where the result (level, score, rules violated) of skip_note is the same as diligent's
(d) With the result set of wrong_book and min_full_rate equal to 2/5, the smallest max_harmful that makes the gate return READY_FOR_REVIEW
Question 0 1 2 3 Weight
(a) Missing Names the agent but not the scenario Right agent and scenario As level 2, and states the consequence: dropping that scenario loses the ability to see this defect 25
(b) Missing Right number, wrong set Right number and set As level 2, and states why the edge B:NOT_AVAILABLE is not counted 25
(c) Missing One scenario missing or extra The whole set right As level 2, and explains why those scenarios have no note work to skip 25
(d) Missing Right value but no explanation Right value and states the number of harmful runs As level 2, and states that the threshold is a decision of one person who records a reason, not of a test 25

Rules

  • Do not use real data or a real API in your submission. Agents, scenarios, tools, costs, scores and every figure in the lab are simulated; do not infer the behaviour of a real model, vendor, framework or agent.
  • Do not edit lab/, data/, tests/ or exercises/. Put proposed changes in notes/decisions.md.
  • Every tool runs only in the lab's temporary sandbox folder; do not run shell commands, network access or files outside that folder. Every real effect needs a person's approval.
  • Do not change scenarios, weights, thresholds or the golden table after seeing results in order to reach a wanted conclusion; if you change them, record the reason and the result before the change.
  • Every figure in a report comes from a script; state the configuration. Do not let the oracle, the score or the gate stand in for reading the report.
  • The oracle, coverage, score and gate only flag and rank; the gate fails closed when data is missing; a person reviews, decides the threshold and every real effect. Do not create or edit any automated workflow.