From 73db9bd24fc6fa24c15375fc50688bc6973fb961 Mon Sep 17 00:00:00 2001 From: matheusPavaneli Date: Sun, 27 Sep 2026 00:16:06 -0300 Subject: [PATCH] docs: show what workbench caught, from the benchmark's own records docs/caught.md walks through every case the first clean run (9abd3c9) separated, each with the ticket, what plain did, what the workbench session did, and links to the run records: - BN-6: plain fixed the deprecated in_stock copy both times and left the live check broken; workbench fixed stock.available. No guardrail refused anything: the light path's demand for a covering test sent the session to tests/test_stock.py, which names the live function. An earlier, non-citable run where that did not work is cited too. - BN-3, BN-4, BN-7: plain wrote no test in 6 of 6 runs; workbench wrote one in 6 of 6, with wb finish ready to refuse and never needing to. - BN-4: the one guardrail that fired, sending a user-data change to the standard route at 6.7x the tokens. - What has not been caught: BN-5's spill and any invented reference. bench/demo.py records a 33-second asciicast of wb start, wb next, the fix, wb finish --commit and wb approve on BN-6, from real output on a fresh fixture; only the pace is set. The README links both. --- .workflow/tasks/WB-57.json | 4 +- README.md | 8 +- bench/demo.py | 120 ++++++++++++++++++++++ docs/caught.md | 100 +++++++++++++++++++ docs/demo.cast | 199 +++++++++++++++++++++++++++++++++++++ tests/test_bench.py | 29 ++++++ 6 files changed, 456 insertions(+), 4 deletions(-) create mode 100644 bench/demo.py create mode 100644 docs/caught.md create mode 100644 docs/demo.cast diff --git a/.workflow/tasks/WB-57.json b/.workflow/tasks/WB-57.json index af5b233..11315a3 100644 --- a/.workflow/tasks/WB-57.json +++ b/.workflow/tasks/WB-57.json @@ -2,10 +2,10 @@ "key": "WB-57", "title": "Show real errors workbench caught, and a 30-60 s demo", "type": "chore", - "status": "open", + "status": "done", "desc": "Build later: only once the WB-52 bench records at least one catch plain missed. Examples must come from bench records or real tickets, never staged.\n\nACCEPTANCE:\n- docs page with each example: the ticket, what plain did, what workbench flagged, link to the run record\n- a 30-60 s recording of wb start, wb next, wb approve on one fixture ticket, linked from the README", "created": "2026-09-26T17:51:51Z", - "updated": "2026-09-26T17:51:51Z", + "updated": "2026-09-27T03:12:57Z", "comments": [], "linked": [ { diff --git a/README.md b/README.md index 0b46199..f7cd5d3 100644 --- a/README.md +++ b/README.md @@ -264,7 +264,10 @@ arm, so a direction rather than a verdict): | bug in user data | fixed, no test (2/2) | fixed, with a test, planned (critical zone) | 6.7x tokens, 5.8x wall | Small work now costs about twice a plain session; work in a critical zone still -costs the full plan. +costs the full plan. [What workbench caught](docs/caught.md) walks through each +case, and a 33-second recording of `wb start`, `wb next`, `wb finish` and +`wb approve` on one of these tickets is in [docs/demo.cast](docs/demo.cast) +(`asciinema play docs/demo.cast`; recorded by `bench/demo.py` from real output). ### The light path @@ -475,7 +478,8 @@ Exit codes: 2 usage, 3 config, 4 auth, 5 provider, 6 not found, 7 audit failed, - [CHANGELOG.md](CHANGELOG.md) — what changed, and the deprecation policy - [status.md](docs/status.md) — the pipeline, the command history, rigour tiers, settled gates - [flow.md](docs/flow.md) — source and validation branches, cherry-pick carrying, branch naming -- [bench.md](docs/bench.md) — the benchmark: metrics, the two arms, running it, reading the report +- [bench.md](docs/bench.md) — the benchmark: metrics, the arms, running it, reading the report +- [caught.md](docs/caught.md) — what workbench caught in the benchmark, case by case, with the run records These are for maintainers. Agents do not read them: the behaviour they describe is enforced in code, and loading them into a session would pay twice for the diff --git a/bench/demo.py b/bench/demo.py new file mode 100644 index 0000000..72e5ffd --- /dev/null +++ b/bench/demo.py @@ -0,0 +1,120 @@ +"""Record the README's demo: wb start, wb next, wb finish and wb approve on BN-6. + + python bench/demo.py [--out docs/demo.cast] + +Every line of output in the recording is what the command printed, run for real +against a fresh copy of the benchmark fixture; nothing is typed into the file by +hand. The one edit is the fix itself, made by a command shown on screen, since a +recording of an editor would show nothing wb does. The pace -- typing speed and +the pause after each output -- is set here, so the clip lasts 30-60 s whatever +the machine; the real duration of each command is not what the clip is about. + +Writes an asciicast v2 file: `asciinema play docs/demo.cast`, or any asciicast +player. +""" + +from __future__ import annotations + +import argparse +import json +import os +import subprocess +import sys +from pathlib import Path + +import run as bench_run + +ROOT = bench_run.ROOT +TICKET = "BN-6" +MESSAGE = "fix: allow ordering exactly the units on hand" +FIX = "shop/stock.py" +TEST = "tests/test_stock.py" +TEST_ADDED = ( + "\n\nclass LastUnitTest(unittest.TestCase):\n" + " def test_the_last_units_on_hand_can_be_ordered(self):\n" + " self.assertTrue(available({\"tea\": 2}, \"tea\", 2))\n" +) +TYPE_S = 0.06 +# Time to read an output: a base, plus a little per line. +PAUSE_S = 3.5 +PAUSE_PER_LINE_S = 0.45 +WIDTH, HEIGHT = 100, 30 + + +def steps(wb: str) -> list[tuple[str, list[str] | None]]: + """(what is shown at the prompt, the argv that runs it; None for a shell step done in Python).""" + return [ + (f"wb start {TICKET}", [sys.executable, wb, "start", TICKET]), + ("wb next", [sys.executable, wb, "next"]), + (f"sed -i 's/> quantity/>= quantity/' {FIX} # the fix, and a test for it", None), + (f'wb finish {TICKET} -m "{MESSAGE}" --commit', [sys.executable, wb, "finish", TICKET, "-m", MESSAGE, "--commit"]), + ("wb approve", [sys.executable, wb, "approve"]), + ] + + +def record(out: Path) -> Path: + ticket = next(t for t in bench_run.load_tickets([TICKET])) + with bench_run.workdir("wb-demo-") as work: + env = bench_run.session_env(work) + env["WB_NO_HOOKS"] = "1" + plugin = bench_run.copy_plugin(work / "plugin") + repo = work / "repo" + bench_run.prepare(repo, ticket, "workbench", env, plugin) + wb = str(plugin / "lib" / "wb.py") + + events: list[list] = [] + clock = 0.5 + for shown, argv in steps(wb): + clock = _type(events, clock, f"$ {shown}") + if argv is None: + _fix(repo) + output = "" + else: + done = subprocess.run(argv, cwd=repo, env=env, stdin=subprocess.DEVNULL, capture_output=True, + text=True, encoding="utf-8", errors="replace", timeout=300) + output = (done.stdout + done.stderr).replace(str(work), "~").replace(str(work).replace("\\", "/"), "~") + events.append([round(clock, 3), "o", "\r\n" + output.replace("\n", "\r\n")]) + clock += (PAUSE_S + PAUSE_PER_LINE_S * output.count("\n")) if output else 1.2 + + out.parent.mkdir(parents=True, exist_ok=True) + header = {"version": 2, "width": WIDTH, "height": HEIGHT, "title": f"workbench: {TICKET} on the light path", + "env": {"SHELL": "/bin/sh", "TERM": "xterm-256color"}} + lines = [json.dumps(header)] + [json.dumps(event, ensure_ascii=False) for event in events] + out.write_text("\n".join(lines) + "\n", encoding="utf-8") + return out + + +def _type(events: list[list], clock: float, text: str) -> float: + for character in text: + events.append([round(clock, 3), "o", character]) + clock += TYPE_S + return clock + 0.4 + + +def _fix(repo: Path) -> None: + path = repo / FIX + # newline="\n": the fixture's line endings, as an editor keeps them. A CRLF + # rewrite on Windows would read as every line changed. + fixed = path.read_text(encoding="utf-8").replace("> quantity", ">= quantity") + path.write_text(fixed, encoding="utf-8", newline="\n") + test = repo / TEST + test.write_text(test.read_text(encoding="utf-8").rstrip("\n") + TEST_ADDED, encoding="utf-8", newline="\n") + + +def duration(cast: Path) -> float: + last = cast.read_text(encoding="utf-8").strip().splitlines()[-1] + return float(json.loads(last)[0]) + + +def main(argv: list[str] | None = None) -> int: + parser = argparse.ArgumentParser(description="Record the README demo (asciicast v2).") + parser.add_argument("--out", default=str(ROOT / "docs" / "demo.cast")) + args = parser.parse_args(argv) + os.environ.setdefault("PYTHONIOENCODING", "utf-8") + path = record(Path(args.out)) + print(f"wrote {path} ({duration(path):.0f} s)") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/docs/caught.md b/docs/caught.md new file mode 100644 index 0000000..c017a24 --- /dev/null +++ b/docs/caught.md @@ -0,0 +1,100 @@ +# What workbench caught + +Every example here comes from a benchmark record, never from a staged session: +the ticket, what a plain session did with it, what the workbench session did, +and the run records that show both. The numbers come from the first clean run, +[2026-09-27, commit 9abd3c9](../bench/results/2026-09-27-9abd3c9/report.md): the +same model (Sonnet), the same prompt, two runs per arm. Two runs is a direction, +not a verdict. How the benchmark works is in [bench.md](bench.md). + +A catch is said the way it happened. Where a guardrail refused something, it +says so. Where the flow only asked for something and the session did the rest, +it says that instead. + +## BN-6: the ticket names a function that was renamed + +**The ticket.** "`in_stock` refuses the last unit on hand: with 2 on hand, an +order for 2 is refused." The live check is `shop/stock.available`. A deprecated +`in_stock` with the same bug still sits in `shop/legacy.py`, kept for an old +export script that checkout never calls. + +**Plain, 2 of 2 runs.** It searched for `in_stock`, found the one in +`shop/legacy.py`, fixed it and committed. It wrote no test. The live check is +still broken, and the hidden tests fail. It took 5-6 turns and about 16 s. +Records: [BN-6-plain-1](../bench/results/2026-09-27-9abd3c9/BN-6-plain-1.json), +[BN-6-plain-2](../bench/results/2026-09-27-9abd3c9/BN-6-plain-2.json). + +**Workbench, 2 of 2 runs.** `wb start` put the ticket on the light path, which +asks for the change *and a test that covers it*. The session opened +`shop/legacy.py` too, then went looking for the test to extend. `tests/test_stock.py` +tests `stock.available`, not `in_stock`, so the session concluded that the copy +in `legacy.py` is dead and the live code is `stock.py`. In its own words: "The +ticket's `in_stock` name matches `shop/legacy.py`, but that module is explicitly +deprecated and unused by checkout. The live code path is `shop/stock.py`'s +`available()`." It fixed that function and added a test for the last unit. +`wb finish` proved the test fails on the base and passes with the fix. The hidden +tests pass. It took 16 turns and about 47 s. +Records: [BN-6-workbench-1](../bench/results/2026-09-27-9abd3c9/BN-6-workbench-1.json), +[BN-6-workbench-2](../bench/results/2026-09-27-9abd3c9/BN-6-workbench-2.json). + +**What caught it.** No guardrail refused anything. What steered the session was +the light path's requirement to cover the change with a test. The requirement +does not always work: in an earlier run whose numbers are not citable +([31a7699](../bench/results/2026-09-27-31a7699/report.md)), one of two workbench +sessions fixed `legacy.py` and wrote a test for it, and `wb finish` passed +that. A test proves the code does what the test says, not that it is the right +code. + +## BN-3, BN-4, BN-7: a fix with no test + +**The tickets.** A one-file chore (`format_money` prints refunds wrong), a bug +in user data (`display_name` keeps stray whitespace), and a one-character bug +(loyalty points are a tenth of what they should be). There is no test file for +the loyalty module at all. + +**Plain, 6 of 6 runs.** It fixed each bug correctly (the hidden tests pass) and +wrote no test for any of them. The next change to any of these functions has +nothing to stop it undoing the fix. + +**Workbench, 6 of 6 runs.** Every run added or extended a test. On BN-3 and BN-7 +(the light path), `wb finish` refuses a logic change with no test change, and +on a bug it runs each changed test on the base the branch left, where the test +must fail. In these runs the session wrote the test before it was asked, so +the refusal never had to fire. What held the line was the instruction, backed +by a check that would have refused. + +Records: `BN-3-*`, `BN-4-*` and `BN-7-*` in +[9abd3c9](../bench/results/2026-09-27-9abd3c9/). The report's caught-errors +section counts `tests_missing` for each arm. + +## BN-4: a fix that lands in user data + +**The ticket.** `display_name` keeps stray whitespace. The function is in +`shop/users.py`, which the repo profile puts in the **user-data** critical zone. + +**Plain, 2 of 2 runs.** Fixed, no test, committed. 7-8 turns. + +**Workbench, 2 of 2 runs.** This is the one guardrail that fired. The session +fixed the bug on the light path, then `wb finish` refused: +`BN-4 outgrew the light path: touches user-data. It now takes the standard route`. +The session then planned the change, audited the plan, verified it and +committed, with a test. The result matched plain's plus a test, and it cost +6.7x the tokens. Both runs also discarded the working fix before planning, +which WB-58 records as waste. +Records: [BN-4-workbench-1](../bench/results/2026-09-27-9abd3c9/BN-4-workbench-1.json), +[BN-4-workbench-2](../bench/results/2026-09-27-9abd3c9/BN-4-workbench-2.json). + +**What caught it.** The zone check did what it is for: a change to user data is +held to the highest bar in the repo. Whether that bar paid for itself on a +whitespace fix is a fair question, and this record is the evidence either way. + +## What has not been caught + +- **A spill into a shared neighbour (BN-5).** Every plain session so far fixed + it in place and left the shared `regions.zone_for` alone. This ticket has + never separated the arms. +- **An invented reference.** `invalid_refs` has been 0 in every run of both + arms. + +Both stay in the fixture. A ticket that does not separate the arms is a result +too. diff --git a/docs/demo.cast b/docs/demo.cast new file mode 100644 index 0000000..884a59c --- /dev/null +++ b/docs/demo.cast @@ -0,0 +1,199 @@ +{"version": 2, "width": 100, "height": 30, "title": "workbench: BN-6 on the light path", "env": {"SHELL": "/bin/sh", "TERM": "xterm-256color"}} +[0.5, "o", "$"] +[0.56, "o", " "] +[0.62, "o", "w"] +[0.68, "o", "b"] +[0.74, "o", " "] +[0.8, "o", "s"] +[0.86, "o", "t"] +[0.92, "o", "a"] +[0.98, "o", "r"] +[1.04, "o", "t"] +[1.1, "o", " "] +[1.16, "o", "B"] +[1.22, "o", "N"] +[1.28, "o", "-"] +[1.34, "o", "6"] +[1.8, "o", "\r\nBN-6 bug in_stock refuses the last unit on hand\r\n\r\n in_stock says no when a customer orders exactly the units left: with 2 on hand, an order for 2 is refused. Ordering up to the units on hand must be allowed; more than that is still refused.\r\n\r\ntriage wrote .workflow/BN-6/triage.json\r\nbranch BN-6-in-stock-refuses-the-last-unit (created from master, no origin remote)\r\nroute light path: triage, change, commit, pr (no plan up front; wb finish holds the change to the floor)\r\n no plan, no other skill: make the change and a test that covers it, then\r\n wb finish BN-6 -m \": \" --commit -- it runs the suite and every check,\r\n commits exactly the checked files, and speaks only if something blocks\r\nBN-6 change todo light path: make the change and a test that covers it\r\n next: wb finish BN-6 -m \": \" --commit\r\n"] +[10.7, "o", "$"] +[10.76, "o", " "] +[10.82, "o", "w"] +[10.88, "o", "b"] +[10.94, "o", " "] +[11.0, "o", "n"] +[11.06, "o", "e"] +[11.12, "o", "x"] +[11.18, "o", "t"] +[11.64, "o", "\r\nBN-6 (branch) change todo light path: make the change and a test that covers it\r\n next: wb finish BN-6 -m \": \" --commit\r\n"] +[16.04, "o", "$"] +[16.1, "o", " "] +[16.16, "o", "s"] +[16.22, "o", "e"] +[16.28, "o", "d"] +[16.34, "o", " "] +[16.4, "o", "-"] +[16.46, "o", "i"] +[16.52, "o", " "] +[16.58, "o", "'"] +[16.64, "o", "s"] +[16.7, "o", "/"] +[16.76, "o", ">"] +[16.82, "o", " "] +[16.88, "o", "q"] +[16.94, "o", "u"] +[17.0, "o", "a"] +[17.06, "o", "n"] +[17.12, "o", "t"] +[17.18, "o", "i"] +[17.24, "o", "t"] +[17.3, "o", "y"] +[17.36, "o", "/"] +[17.42, "o", ">"] +[17.48, "o", "="] +[17.54, "o", " "] +[17.6, "o", "q"] +[17.66, "o", "u"] +[17.72, "o", "a"] +[17.78, "o", "n"] +[17.84, "o", "t"] +[17.9, "o", "i"] +[17.96, "o", "t"] +[18.02, "o", "y"] +[18.08, "o", "/"] +[18.14, "o", "'"] +[18.2, "o", " "] +[18.26, "o", "s"] +[18.32, "o", "h"] +[18.38, "o", "o"] +[18.44, "o", "p"] +[18.5, "o", "/"] +[18.56, "o", "s"] +[18.62, "o", "t"] +[18.68, "o", "o"] +[18.74, "o", "c"] +[18.8, "o", "k"] +[18.86, "o", "."] +[18.92, "o", "p"] +[18.98, "o", "y"] +[19.04, "o", " "] +[19.1, "o", " "] +[19.16, "o", " "] +[19.22, "o", "#"] +[19.28, "o", " "] +[19.34, "o", "t"] +[19.4, "o", "h"] +[19.46, "o", "e"] +[19.52, "o", " "] +[19.58, "o", "f"] +[19.64, "o", "i"] +[19.7, "o", "x"] +[19.76, "o", ","] +[19.82, "o", " "] +[19.88, "o", "a"] +[19.94, "o", "n"] +[20.0, "o", "d"] +[20.06, "o", " "] +[20.12, "o", "a"] +[20.18, "o", " "] +[20.24, "o", "t"] +[20.3, "o", "e"] +[20.36, "o", "s"] +[20.42, "o", "t"] +[20.48, "o", " "] +[20.54, "o", "f"] +[20.6, "o", "o"] +[20.66, "o", "r"] +[20.72, "o", " "] +[20.78, "o", "i"] +[20.84, "o", "t"] +[21.3, "o", "\r\n"] +[22.5, "o", "$"] +[22.56, "o", " "] +[22.62, "o", "w"] +[22.68, "o", "b"] +[22.74, "o", " "] +[22.8, "o", "f"] +[22.86, "o", "i"] +[22.92, "o", "n"] +[22.98, "o", "i"] +[23.04, "o", "s"] +[23.1, "o", "h"] +[23.16, "o", " "] +[23.22, "o", "B"] +[23.28, "o", "N"] +[23.34, "o", "-"] +[23.4, "o", "6"] +[23.46, "o", " "] +[23.52, "o", "-"] +[23.58, "o", "m"] +[23.64, "o", " "] +[23.7, "o", "\""] +[23.76, "o", "f"] +[23.82, "o", "i"] +[23.88, "o", "x"] +[23.94, "o", ":"] +[24.0, "o", " "] +[24.06, "o", "a"] +[24.12, "o", "l"] +[24.18, "o", "l"] +[24.24, "o", "o"] +[24.3, "o", "w"] +[24.36, "o", " "] +[24.42, "o", "o"] +[24.48, "o", "r"] +[24.54, "o", "d"] +[24.6, "o", "e"] +[24.66, "o", "r"] +[24.72, "o", "i"] +[24.78, "o", "n"] +[24.84, "o", "g"] +[24.9, "o", " "] +[24.96, "o", "e"] +[25.02, "o", "x"] +[25.08, "o", "a"] +[25.14, "o", "c"] +[25.2, "o", "t"] +[25.26, "o", "l"] +[25.32, "o", "y"] +[25.38, "o", " "] +[25.44, "o", "t"] +[25.5, "o", "h"] +[25.56, "o", "e"] +[25.62, "o", " "] +[25.68, "o", "u"] +[25.74, "o", "n"] +[25.8, "o", "i"] +[25.86, "o", "t"] +[25.92, "o", "s"] +[25.98, "o", " "] +[26.04, "o", "o"] +[26.1, "o", "n"] +[26.16, "o", " "] +[26.22, "o", "h"] +[26.28, "o", "a"] +[26.34, "o", "n"] +[26.4, "o", "d"] +[26.46, "o", "\""] +[26.52, "o", " "] +[26.58, "o", "-"] +[26.64, "o", "-"] +[26.7, "o", "c"] +[26.76, "o", "o"] +[26.82, "o", "m"] +[26.88, "o", "m"] +[26.94, "o", "i"] +[27.0, "o", "t"] +[27.46, "o", "\r\nBN-6 clear: 2 file(s), 6 line(s), 1 suite run(s) passed, 1 regression test(s) proven\r\n committed eaa9a2c5: fix: allow ordering exactly the units on hand\r\n"] +[31.86, "o", "$"] +[31.92, "o", " "] +[31.98, "o", "w"] +[32.04, "o", "b"] +[32.1, "o", " "] +[32.16, "o", "a"] +[32.22, "o", "p"] +[32.28, "o", "p"] +[32.34, "o", "r"] +[32.4, "o", "o"] +[32.46, "o", "v"] +[32.52, "o", "e"] +[32.98, "o", "\r\nBN-6 nothing waiting on you\r\nBN-6 (branch) pr todo\r\n next: wb pr context BN-6 (draft-pr)\r\n"] diff --git a/tests/test_bench.py b/tests/test_bench.py index f0c32d8..0fe9dc0 100644 --- a/tests/test_bench.py +++ b/tests/test_bench.py @@ -670,6 +670,35 @@ def test_wb_bench_tmp_overrides(self) -> None: self.assertTrue((Path(tmp) / "x").is_dir()) +class DemoTest(unittest.TestCase): + """WB-57: the README's recording is real output, 30-60 s, of the four verbs.""" + + CAST = BENCH.parent / "docs" / "demo.cast" + + def test_the_recording_is_an_asciicast_of_the_four_verbs_in_30_to_60_seconds(self) -> None: + lines = self.CAST.read_text(encoding="utf-8").splitlines() + header = json.loads(lines[0]) + self.assertEqual(2, header["version"]) + events = [json.loads(line) for line in lines[1:]] + self.assertTrue(all(kind == "o" for _, kind, _ in events)) + self.assertTrue(30 <= events[-1][0] <= 60, events[-1][0]) + shown = "".join(text for _, _, text in events) + for verb in ("wb start BN-6", "wb next", "wb finish BN-6", "wb approve"): + with self.subTest(verb=verb): + self.assertIn(verb, shown) + self.assertIn("regression test(s) proven", shown, "the finish output is the real one") + + def test_every_record_caught_md_links_exists(self) -> None: + import re + + text = (BENCH.parent / "docs" / "caught.md").read_text(encoding="utf-8") + linked = re.findall(r"\]\((\.\./bench/results/[^)]+)\)", text) + self.assertGreater(len(linked), 4) + for target in linked: + with self.subTest(target=target): + self.assertTrue((BENCH.parent / "docs" / target).resolve().exists(), target) + + class WorkdirTest(unittest.TestCase): def test_a_dir_with_read_only_files_is_removed(self) -> None: with bench_run.workdir("wb-bench-test-") as work: