@jesdi/skills 0.0.77 → 0.0.78

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/README.md +3 -2
  2. package/package.json +1 -1
  3. package/skills/implement-spec/ARCHITECTURE.md +102 -54
  4. package/skills/implement-spec/README.md +53 -51
  5. package/skills/implement-spec/SKILL.md +5 -6
  6. package/skills/implement-spec/driver.py +67 -153
  7. package/skills/implement-spec/driver_agents.py +75 -25
  8. package/skills/implement-spec/driver_decisions.py +92 -199
  9. package/skills/implement-spec/driver_dispute.py +189 -0
  10. package/skills/implement-spec/driver_final.py +196 -97
  11. package/skills/implement-spec/driver_fixloop.py +102 -192
  12. package/skills/implement-spec/driver_legacy.py +73 -5
  13. package/skills/implement-spec/driver_locked.py +186 -0
  14. package/skills/implement-spec/driver_merge.py +3 -48
  15. package/skills/implement-spec/driver_report.py +84 -64
  16. package/skills/implement-spec/driver_review.py +12 -119
  17. package/skills/implement-spec/driver_run.py +167 -130
  18. package/skills/implement-spec/driver_state.py +11 -9
  19. package/skills/implement-spec/models.json +0 -2
  20. package/skills/implement-spec/prompts/arbitration.md +34 -0
  21. package/skills/implement-spec/prompts/conflict.md +1 -0
  22. package/skills/implement-spec/prompts/correction.md +7 -4
  23. package/skills/implement-spec/prompts/elsewhere.md +6 -0
  24. package/skills/implement-spec/prompts/final-fixer.md +1 -1
  25. package/skills/implement-spec/prompts/final-lens.md +40 -0
  26. package/skills/implement-spec/prompts/final-reviewer.md +7 -7
  27. package/skills/implement-spec/prompts/fixer.md +2 -2
  28. package/skills/implement-spec/prompts/implementer.md +1 -1
  29. package/skills/implement-spec/prompts/lens-copy.md +1 -0
  30. package/skills/implement-spec/prompts/lens-correctness.md +8 -0
  31. package/skills/implement-spec/prompts/lens-spec.md +2 -0
  32. package/skills/implement-spec/prompts/lens-structure.md +2 -0
  33. package/skills/implement-spec/prompts/rebase-conflict.md +1 -0
  34. package/skills/implement-spec/prompts/rereview.md +0 -1
  35. package/skills/implement-spec/prompts/rerun.md +1 -1
  36. package/skills/implement-spec/prompts/reviewer.md +3 -6
  37. package/skills/implement-spec/prompts/ruled.md +3 -0
  38. package/skills/implement-spec/prompts/test-writer.md +4 -5
  39. package/skills/implement-spec/tests/test_agents.py +23 -22
  40. package/skills/implement-spec/tests/test_amendments.py +6 -48
  41. package/skills/implement-spec/tests/test_arbitration.py +314 -0
  42. package/skills/implement-spec/tests/test_cli.py +3 -3
  43. package/skills/implement-spec/tests/test_decisions.py +251 -374
  44. package/skills/implement-spec/tests/test_driver.py +22 -50
  45. package/skills/implement-spec/tests/test_final.py +45 -77
  46. package/skills/implement-spec/tests/test_fixloop.py +400 -633
  47. package/skills/implement-spec/tests/test_landing.py +23 -126
  48. package/skills/implement-spec/tests/test_lenses.py +217 -0
  49. package/skills/implement-spec/tests/test_merge.py +0 -43
  50. package/skills/implement-spec/tests/test_models.py +50 -1
  51. package/skills/implement-spec/tests/test_report.py +9 -23
  52. package/skills/implement-spec/tests/test_review.py +15 -153
  53. package/skills/implement-spec/tests/test_review_page.py +7 -3
  54. package/skills/implement-spec/tests/test_scoped.py +125 -0
  55. package/skills/implement-spec/tests/test_state.py +8 -3
  56. package/skills/implement-spec/tests/test_stops.py +43 -61
  57. package/skills/implement-spec/tests/test_tidy.py +77 -98
  58. package/skills/implement-spec/tests/test_walk.py +7 -6
  59. package/skills/review-page/SKILL.md +1 -1
  60. package/skills/to-tickets/SKILL.md +1 -1
  61. package/skills-manifest.json +7 -7
  62. package/skills/implement-spec/prompts/corrected.md +0 -3
  63. package/skills/implement-spec/prompts/correctness.md +0 -42
  64. package/skills/implement-spec/prompts/final-scoped.md +0 -1
  65. package/skills/implement-spec/prompts/full-review.md +0 -2
  66. package/skills/implement-spec/prompts/overruled.md +0 -7
  67. package/skills/implement-spec/prompts/rejected.md +0 -1
  68. package/skills/implement-spec/prompts/restored-red.md +0 -3
  69. package/skills/implement-spec/prompts/restored.md +0 -3
  70. package/skills/implement-spec/prompts/stands.md +0 -2
@@ -1,19 +1,18 @@
1
1
  """Report validation acceptance tests, through driver_report.validate only.
2
2
 
3
3
  context is a dict: repo (slot path), branch, start (HEAD sha when the role started),
4
- log (the agent's log file), full (a full review of the reviewer).
4
+ log (the agent's log file).
5
5
  """
6
6
  import json
7
7
  import subprocess
8
8
 
9
9
  import pytest
10
10
 
11
- from driver_agents import READ_ONLY
11
+ from driver_agents import LENSES, READ_ONLY
12
12
  from driver_report import validate
13
13
 
14
14
  GIT = ["git", "-c", "user.name=t", "-c", "user.email=t@example.com", "-c", "commit.gpgsign=false"]
15
15
  RED = "FAILED tests/test_export.py::test_rows - AttributeError"
16
- MUTATION = "FAILED tests/test_export.py::test_rows after breaking demo/export.py:2"
17
16
 
18
17
 
19
18
  def git(root, *args):
@@ -40,7 +39,7 @@ def world(tmp_path):
40
39
  git(root, "checkout", "-q", "-b", "ticket/01", "main")
41
40
  tests = commit(root, "tests/test_export.py", "def test_rows():\n assert False\n")
42
41
  impl = commit(root, "demo/export.py", "def export_csv():\n return 'rows'\n")
43
- (tmp_path / "agent.log").write_text(f"collected 1 item\n{RED}\n{MUTATION}\n")
42
+ (tmp_path / "agent.log").write_text(f"collected 1 item\n{RED}\n")
44
43
  shas = dict(base=base, stray=stray, tests=tests, impl=impl)
45
44
 
46
45
  def check(role, report, **context):
@@ -70,8 +69,7 @@ def finding(**changes):
70
69
 
71
70
 
72
71
  def reviewer(**changes):
73
- return common(**{"findings": [finding()], "mutations": [
74
- {"test": "tests/test_export.py::test_rows", "file": "demo/export.py", "line": 2, "red": MUTATION}], **changes})
72
+ return common(**{"findings": [finding()], **changes})
75
73
 
76
74
 
77
75
  def test_valid_reports_pass_and_unknown_status_is_named(world):
@@ -184,14 +182,6 @@ def test_a_locked_path_that_the_commits_delete_is_a_violation(world):
184
182
  "locked path tests/test_export.py is not a file at the tip of ticket/01: list in `locked` only files you keep"]
185
183
 
186
184
 
187
- def test_a_full_review_needs_no_proof_for_a_locked_file_that_is_not_at_the_tip(world):
188
- shas, check, _ = world
189
- locked = ["tests/test_export.py", "tests/test_gone.py"]
190
- assert check("reviewer", reviewer(), start=shas["impl"], full=True, locked=locked) == []
191
- assert check("reviewer", reviewer(mutations=[]), start=shas["impl"], full=True, locked=locked) == [
192
- "mutations: no mutation proof for the locked test file tests/test_export.py"]
193
-
194
-
195
185
  def test_red_line_absent_from_the_log_is_a_violation(world):
196
186
  shas, check, _ = world
197
187
  assert check("test-writer", writer(shas), start=shas["base"]) == []
@@ -200,17 +190,12 @@ def test_red_line_absent_from_the_log_is_a_violation(world):
200
190
  "red line not found in log: t: FAILED tests/test_export.py::test_rows - KeyError"]
201
191
 
202
192
 
203
- def test_reviewer_fields_and_mutation_proofs(world):
193
+ def test_reviewer_fields(world):
204
194
  shas, check, _ = world
205
- assert check("reviewer", reviewer(), start=shas["impl"], full=True) == []
195
+ assert check("reviewer", reviewer(), start=shas["impl"]) == []
206
196
  assert any("severity" in e for e in check("reviewer", reviewer(findings=[finding(severity="huge")]),
207
197
  start=shas["impl"]))
208
198
  assert any("kind" in e for e in check("reviewer", reviewer(findings=[finding(kind="style")]), start=shas["impl"]))
209
- no_proof = reviewer()
210
- del no_proof["mutations"]
211
- assert any("mutations" in e for e in check("reviewer", no_proof, start=shas["impl"], full=True))
212
- fake = reviewer(mutations=[{"test": "t", "file": "demo/export.py", "line": 2, "red": "never ran"}])
213
- assert any("not found in log" in e for e in check("reviewer", fake, start=shas["impl"], full=True))
214
199
 
215
200
 
216
201
  @pytest.mark.parametrize("role", READ_ONLY)
@@ -218,5 +203,6 @@ def test_a_read_only_role_lists_no_commits_so_the_commits_it_reviewed_are_not_re
218
203
  # Issue #129: the final reviewer read `commits` as the commits under review, and each was refused as not new.
219
204
  shas, check, _ = world
220
205
  report = {"status": "DONE", "files": [], "concerns": [], "findings": [], "body": "b"}
221
- assert check(role, report, start=shas["impl"]) == []
222
- assert check(role, {**report, "commits": [shas["tests"], shas["impl"]]}, start=shas["impl"]) == []
206
+ template = "final-lens" if role in LENSES else role # the lenses share one prompt
207
+ assert check(template, report, start=shas["impl"]) == []
208
+ assert check(template, {**report, "commits": [shas["tests"], shas["impl"]]}, start=shas["impl"]) == []
@@ -1,27 +1,19 @@
1
- """Ticket 04 acceptance tests: review, correctness pass, fix loop, fixture corrections, conflict agent.
1
+ """Ticket 04 acceptance tests: review, fix loop, fixture corrections, conflict agent.
2
2
 
3
3
  All through `sh run.sh --runner <script>` on the fixture repository (the rig of test_walk). The fake runner also plays
4
- reviewer, correctness, fixer, conflict and a second test-writer call; a role it has no script for reports nothing wrong.
4
+ reviewer, fixer, conflict and a second test-writer call; a role it has no script for reports nothing wrong.
5
5
 
6
6
  Interface choices (ticket 04):
7
7
  - the runner replaces the CLI, so a model entry is observed in the ledger: the line of a call names its role and entry.
8
8
  - a fix round runs the role `fixer` (report `fixer-<round>.json`) on the implementer's model list: entry 0 in round
9
9
  1, entry 1 in round 2. `state.json` `round` counts fix rounds only. The review that follows round K writes
10
- `reviewer-K.json` (the first review `reviewer-0.json`); a correctness pass writes `correctness-K.json`.
11
- - `mutations[].test` is `<locked file>::test_x`; a re-review prompt names each mutation proof to repeat as
12
- `<file>:<line>`, with the line number it has at the new tip.
13
- - an installed skill without a sibling `review-diff/correctness.md` makes the driver exit 3 before any agent, and the
14
- message names `review-diff/correctness.md`.
10
+ `reviewer-K.json` (the first review `reviewer-0.json`).
15
11
  - a second conflict on one merge: the PR branch moved again while the conflict agent worked.
16
12
  """
17
- import json
18
- import shutil
19
- import subprocess
20
- from pathlib import Path
21
13
 
22
14
  import pytest
23
15
 
24
- from test_cli import SKILL, ticket, three, git, models_file
16
+ from test_cli import ticket, three, git, models_file
25
17
  from test_walk import RUNNER, Rig, fix, impl, plan, tw
26
18
 
27
19
  # The fake runner of test_walk plus three hooks: `git` runs before the step's files, `git_after` right after them,
@@ -37,8 +29,7 @@ assert HOOKED.count("git_after") == 1 and HOOKED.count('step.get("git", [])') ==
37
29
 
38
30
  ONE = {"01-export-rows.md": ticket("01", "Export rows")}
39
31
  RISKY = {"02-quote-fields.md": ticket("02", "Quote fields", risk="persistence")}
40
- OPUS, FABLE, SOL = "claude-opus-5@medium", "claude-fable-5-1@high", "openai/gpt-sol@medium"
41
- LONG = "".join(f"v{i} = {i}\n" for i in range(1, 41))
32
+ OPUS, FABLE, ASTRA = "claude-opus-5@medium", "claude-fable-5-1@high", "openai/gpt-6-astra@medium"
42
33
 
43
34
 
44
35
  class Review(Rig):
@@ -63,99 +54,26 @@ def finding(title, severity="important", kind="code", file="demo/export.py", lin
63
54
  return dict(severity=severity, file=file, line=line, title=title, evidence=title, kind=kind)
64
55
 
65
56
 
66
- def red(nn, line):
67
- return f"FAILED tests/test_{nn}.py::test_x - AssertionError at demo/export.py:{line}"
68
-
69
-
70
- def review(nn="01", findings=(), lines=(1,), **extra):
71
- """A reviewer step: findings plus a mutation proof per production line, its red line printed to the log."""
72
- proofs = [dict(test=f"tests/test_{nn}.py::test_x", file="demo/export.py", line=n, red=red(nn, n)) for n in lines]
73
- report = dict(status="DONE", commits=[], files=[], concerns=[], findings=list(findings), mutations=proofs)
74
- return {"stdout": "".join(p["red"] + "\n" for p in proofs), "report": report, **extra}
75
-
76
-
77
- def correct(findings=(), **extra):
57
+ def review(nn="01", findings=(), **extra):
58
+ """A reviewer step with `findings`."""
78
59
  report = dict(status="DONE", commits=[], files=[], concerns=[], findings=list(findings))
79
60
  return {"report": report, **extra}
80
61
 
81
62
 
82
- def edit(text, **new):
83
- """`text` with line N replaced (keyword `l<N>`)."""
84
- lines = text.splitlines(keepends=True)
85
- for key, value in new.items():
86
- lines[int(key[1:]) - 1] = value + "\n"
87
- return "".join(lines)
88
-
89
-
90
- # ---------------------------------------------------------------- locked-file check
91
-
92
- def test_a_changed_locked_file_is_a_critical_finding_that_starts_a_fix_round(tmp_path):
93
- rig = Review(tmp_path)
94
- locked = tw("01")["files"]
95
- cheat = impl("01", files={"demo/export.py": "def fn_01():\n return '01'\n", "tests/test_01.py": "# edited\n"})
96
- steps = plan(**{"01/implementer": [cheat], "01/fixer": [fix("01", 1, files={**locked, "demo/export.py": "x = 1\n"})]})
97
- rig.run(steps)
98
- assert rig.code == 0, rig.output()
99
- (line,) = rig.led("locked file changed: tests/test_01.py")
100
- assert "critical" in line.lower()
101
- assert len(rig.calls("01", "fixer")) == 1 and rig.state()["tickets"]["01"]["round"] == 1
102
- assert git(rig.repo, "show", "feat/csv:tests/test_01.py") == locked["tests/test_01.py"]
103
-
104
-
105
- # ---------------------------------------------------------------- correctness pass
106
-
107
- @pytest.fixture(scope="module")
108
- def pair(tmp_path_factory):
109
- """Ticket 02 (Risk: persistence), codex on PATH: reviewer and correctness each wait for the other to start."""
110
- rig = Review(tmp_path_factory.mktemp("pair"), RISKY, {"correctness": [SOL, OPUS], "implementer": [OPUS]})
111
- steps = plan(**{
112
- "02/reviewer": [review("02", [finding("R-MINOR", "minor")], touch=["r"], wait=["c"])],
113
- "02/correctness": [correct([finding("C-IMPORTANT")], touch=["c"], wait=["r"])],
114
- "02/fixer": [fix("02", 1)]})
115
- return rig.run(steps)
116
-
117
-
118
- def test_reviewer_and_correctness_run_at_the_same_time_on_their_models(pair):
119
- assert pair.code == 0, pair.output()
120
- (r,), (c,) = pair.calls("02", "reviewer")[:1], pair.calls("02", "correctness")[:1]
121
- assert r["t0"] < c["t1"] and c["t0"] < r["t1"], "each started before the other ended"
122
- assert pair.led("reviewer", OPUS) and pair.led("correctness", "gpt-sol@medium")
123
-
124
-
125
- def test_findings_of_both_reports_are_merged_with_their_severities(pair):
126
- assert len(pair.calls("02", "fixer")) == 1, "the important finding of the correctness pass starts a round"
127
- assert pair.led("R-MINOR", "minor") and pair.led("C-IMPORTANT", "important")
128
- assert pair.state()["tickets"]["02"]["phase"] == "merged"
129
-
130
-
131
- # Ticket 08: the pass is never folded into the reviewer. A correctness entry with no CLI on PATH stops the run at the
132
- # start: test_amendments.py test_a_correctness_entry_whose_cli_is_not_on_path_stops_the_run_before_any_agent.
133
-
134
- def test_an_installed_skill_without_review_diff_fails_clearly_before_any_agent(tmp_path):
135
- rig = Review(tmp_path, RISKY)
136
- copy = tmp_path / "installed/skills/implement-spec"
137
- shutil.copytree(SKILL, copy, ignore=shutil.ignore_patterns("__pycache__", ".pytest_cache", "test_*"))
138
- (rig.rig / "plan.json").write_text(json.dumps(plan()))
139
- args = ["--tickets", ".agent/tickets", "--gate", f"TIER=full {rig.rig / 'gate'}", "--fast-gate", f"TIER=fast {rig.rig / 'gate'}", "--spec", "specs/csv/spec.md",
140
- "--models", str(rig.models), "--runner", str(rig.rig / "run-agent")]
141
- proc = subprocess.run(["sh", str(copy / "run.sh"), *args], cwd=rig.repo, env=rig.env, text=True,
142
- capture_output=True, timeout=120)
143
- assert proc.returncode == 3, proc.stdout + proc.stderr
144
- assert "review-diff/correctness.md" in proc.stdout + proc.stderr
145
- assert not rig.calls() and not (rig.repo / ".agent/implement/summary.md").exists()
146
-
63
+ # ---------------------------------------------------------------- the reviewer alone
147
64
 
148
65
  @pytest.fixture(scope="module")
149
66
  def plain(tmp_path_factory):
150
67
  """A ticket without a Risk line whose reviewer reports two minor findings."""
151
- rig = Review(tmp_path_factory.mktemp("plain"), ONE, {"correctness": [SOL, OPUS]})
68
+ rig = Review(tmp_path_factory.mktemp("plain"), ONE)
152
69
  return rig.run(plan(**{"01/reviewer": [review("01", [finding("M-ONE", "minor"), finding("M-TWO", "minor")])]}))
153
70
 
154
71
 
155
- def test_a_ticket_without_a_risk_line_runs_no_correctness_pass(plain):
72
+ def test_a_ticket_without_a_risk_line_is_reviewed_by_one_agent_told_it_names_no_risk(plain):
156
73
  assert plain.code == 0, plain.output()
157
- assert len(plain.calls("01", "reviewer")) == 1 and not plain.calls("01", "correctness")
158
- assert not plain.led("folded")
74
+ (call,) = plain.calls("01", "reviewer")
75
+ assert "The ticket names no risk." in call["prompt"]
76
+ assert [c["role"] for c in plain.calls("01")] == ["test-writer", "implementer", "reviewer"]
159
77
 
160
78
 
161
79
  def test_a_review_with_only_minor_findings_passes_and_writes_them_to_the_ledger(plain):
@@ -174,7 +92,7 @@ def test_unrelated_important_observation_waits_for_final_review(tmp_path):
174
92
  assert rig.code == 0, rig.output()
175
93
  assert not rig.calls("01", "fixer")
176
94
  assert rig.state()["tickets"]["01"]["phase"] == "merged"
177
- assert "DUPLICATED-HELPER" in rig.calls("final", "final-reviewer")[0]["prompt"]
95
+ assert "DUPLICATED-HELPER" in rig.calls("final", "final-spec")[0]["prompt"]
178
96
 
179
97
 
180
98
  def test_rereview_defers_newly_noticed_issue_outside_its_open_findings(tmp_path):
@@ -187,7 +105,7 @@ def test_rereview_defers_newly_noticed_issue_outside_its_open_findings(tmp_path)
187
105
 
188
106
  assert rig.code == 0, rig.output()
189
107
  assert len(rig.calls("01", "fixer")) == 1
190
- assert "PREEXISTING-NAME" in rig.calls("final", "final-reviewer")[0]["prompt"]
108
+ assert "PREEXISTING-NAME" in rig.calls("final", "final-spec")[0]["prompt"]
191
109
 
192
110
 
193
111
  def test_rereview_can_open_a_regression_introduced_by_the_fix(tmp_path):
@@ -341,62 +259,6 @@ def test_a_fixture_finding_runs_one_test_writer_correction_outside_the_rounds(tm
341
259
  assert git(rig.repo, "show", "feat/csv:tests/test_01.py") == new
342
260
 
343
261
 
344
- # ---------------------------------------------------------------- mutation proofs
345
-
346
- def scoped(tmp, lines, fixes, last_lines):
347
- """01's implementer writes 40 lines; the reviewer proves `lines`; each fix replaces the file."""
348
- rig = Review(tmp)
349
- bad = review("01", [STUCK], lines=lines)
350
- reviews = [bad] * len(fixes) + [review("01", lines=last_lines)]
351
- rig.run(plan(**{"01/implementer": [impl("01", text=LONG)], "01/reviewer": reviews,
352
- "01/fixer": [fix("01", n, text=t) for n, t in enumerate(fixes, 1)]}))
353
- return rig
354
-
355
-
356
- def test_a_re_review_asks_the_mutation_proof_only_for_the_lines_the_fix_changed(tmp_path):
357
- first = edit(LONG, l12="v12 = 'a'", l30="v30 = 'a'")
358
- rig = scoped(tmp_path, (12, 30), [first, edit(first, l30="v30 = 'b'")], (30,))
359
- assert rig.code == 0, rig.output()
360
- after1, after2 = (c["prompt"] for c in rig.calls("01", "reviewer")[1:])
361
- assert "demo/export.py:12" in after1 and "demo/export.py:30" in after1
362
- assert "demo/export.py:30" in after2 and "demo/export.py:12" not in after2
363
-
364
-
365
- def test_a_mutation_proof_follows_its_production_line_when_a_fix_moves_it(tmp_path):
366
- lines = LONG.splitlines(keepends=True)
367
- moved = "".join(lines[:19] + ["i1 = 1\n", "i2 = 2\n"] + lines[19:29] + ["v30 = 'changed'\n"] + lines[30:])
368
- rig = scoped(tmp_path, (12, 30, 35), [moved], (32,))
369
- assert rig.code == 0, rig.output()
370
- prompt = rig.calls("01", "reviewer")[1]["prompt"]
371
- assert "demo/export.py:32" in prompt, "line 30 is line 32 after two inserted lines"
372
- for gone in (":30", ":12", ":35", ":37"): # the old number, and the lines that did not change
373
- assert f"demo/export.py{gone}" not in prompt, gone
374
-
375
-
376
- def test_a_first_review_without_a_mutation_for_a_locked_test_is_a_violation(tmp_path):
377
- rig = Review(tmp_path)
378
- rig.run(plan(**{"01/reviewer": [review("01", lines=()), review("01")]}))
379
- assert rig.code == 0, rig.output()
380
- first, second = rig.calls("01", "reviewer")
381
- appended = second["prompt"].replace(first["prompt"].strip(), "")
382
- assert first["prompt"].strip() in second["prompt"] and "tests/test_01.py" in appended
383
- assert "mutation" in appended.lower()
384
-
385
-
386
- @pytest.mark.parametrize("second_matches", [True, False])
387
- def test_a_red_line_missing_from_the_reviewer_log_reruns_once_then_blocks(tmp_path, second_matches):
388
- rig = Review(tmp_path)
389
- bad = review("01")
390
- bad["report"]["mutations"][0]["red"] = "NEVER PRINTED"
391
- rig.run(plan(**{"01/reviewer": [bad, review("01") if second_matches else bad]}))
392
- first, second = rig.calls("01", "reviewer")
393
- assert "red line not found in log" in second["prompt"] and "red line not found" not in first["prompt"]
394
- assert rig.code == (0 if second_matches else 2), rig.output() # 2: the `review-rejected` question
395
- assert len(rig.calls("01", "reviewer")) == 2
396
- if not second_matches:
397
- assert rig.led("01", "BLOCKED") and "feat: 01 rows" not in rig.pr_subjects()
398
-
399
-
400
262
  # ---------------------------------------------------------------- conflict agent
401
263
 
402
264
  def cli(text):
@@ -1,7 +1,8 @@
1
1
  """Ticket 05 acceptance tests for `driver_review_page.render(decisions) -> html`.
2
2
 
3
3
  Interface choice: `decisions` is the dict of decisions.json (`revision`, `questions[]` with `id`, `title`, `why`,
4
- `evidence` (list of strings), `options` (list of `{id, description}`), `recommended` (an option id)); the result is the
4
+ `evidence` (list of strings), `options` (list of `{id, description}`), `recommended` (an option id, or "" for none));
5
+ the result is the
5
6
  whole page as a string. The checks are only those that skills/review-page/SKILL.md and schema.md state.
6
7
  """
7
8
  import re
@@ -22,7 +23,7 @@ def question(qid, options, recommended, title=None):
22
23
 
23
24
 
24
25
  DECISIONS = {"revision": "ab" * 32, "questions": [
25
- question("01-locked-test-1", ["overrule-test", "overrule-implementer"], "overrule-implementer"),
26
+ question("01-spec-ambiguous-1", ["keep-test", "correct-test", "edit-spec"], ""),
26
27
  question("02-finding-1", ["accept", "split", "redesign", "other"], "split", title=WHAT)]}
27
28
 
28
29
 
@@ -50,6 +51,9 @@ def check_page(html, decisions):
50
51
  assert radios == [(qid, o["id"]) for o in want["options"]], "name is the question id, value is the option id"
51
52
  labels = block.split('<label class="opt">')[1:]
52
53
  recommended = [i for i, label in enumerate(labels) if "chip rec" in label]
54
+ if not want["recommended"]:
55
+ assert not recommended, "a question that recommends no option marks none"
56
+ continue
53
57
  assert block.count("chip rec") == 1 and len(recommended) == 1, "exactly one recommended option"
54
58
  assert f'value="{want["recommended"]}"' in labels[recommended[0]]
55
59
 
@@ -63,5 +67,5 @@ def test_titles_whys_and_descriptions_show_up_and_markup_in_them_is_escaped():
63
67
  for want in DECISIONS["questions"]:
64
68
  assert f"Why {want['id']} matters" in html
65
69
  assert all(f"Trade-off of {o['id']}" in html for o in want["options"])
66
- assert "Title of 01-locked-test-1" in html
70
+ assert "Title of 01-spec-ambiguous-1" in html
67
71
  assert WHAT not in html and "&lt;b&gt;" in html, "a title is text, never markup"
@@ -0,0 +1,125 @@
1
+ """Fewer roles, ticket 04: after the fix batch of the final review, one scoped re-review runs, the `final-reviewer`
2
+ role on the other-provider entry of the `final-reviewer` list. A finding it leaves open asks `final-ticket-blocked`:
3
+ only a `retry` starts another batch and scoped review.
4
+
5
+ In process, on the rig of test_tidy and test_lenses."""
6
+ import json
7
+
8
+ from test_final import final, fixer, fn
9
+ from test_fixloop import inside # noqa: F401 (the autouse fixture puts the rig's CLIs on PATH)
10
+ from test_cli import git
11
+ from test_lenses import ASTRA, LENSES, MODELS, OPUS, findings_file, rig_of
12
+ from test_review import RISKY, finding, fix, review
13
+ from test_stops import UNATTENDED, decisions
14
+ from test_tidy import Inside, tools # noqa: F401 (tools is an autouse fixture)
15
+ from test_walk import plan, tw
16
+
17
+
18
+ def test_the_scoped_review_is_one_agent_on_the_other_provider_over_the_fix_batch_and_no_third_round_starts(tmp_path):
19
+ rig = rig_of(tmp_path)
20
+ rig.run(plan(**{"final/final-spec": [final(finding("Q-ONE"))], "final/final-reviewer": [final(finding("Q-ONE"))],
21
+ "final/fixer": [fixer(fn("02"), "fix q-one")]}))
22
+ assert rig.code == 2, rig.out
23
+ final_, batch = rig.final(), rig.branch()
24
+ (scoped,) = rig.final_calls("final-reviewer")
25
+ assert rig.led("End of run: final-reviewer ran on", ASTRA) and f"Range: {final_['tidied']}..{batch}\n" in scoped["prompt"]
26
+ assert scoped["head"] == batch and final_["reviewed"] == batch and final_["round"] == 2
27
+ assert [len(rig.final_calls(role)) for role in LENSES] == [1, 1, 1] and len(rig.final_calls("fixer")) == 1
28
+ assert [(f["title"], f["source"]) for f in findings_file(rig, 1)] == [("Q-ONE", "final-reviewer")]
29
+
30
+
31
+ def test_a_must_fix_the_scoped_review_leaves_out_of_resolved_must_fix_asks_final_ticket_blocked(tmp_path):
32
+ rig = Inside(tmp_path, RISKY, MODELS)
33
+ escaping = {**finding("quote escaping", file="csv.py", line=30), "basis": "regression"}
34
+ batch = fixer(fn("02"), "escape quotes", ticket_of="02")
35
+ batch["report"]["addressed_must_fix"] = ["quote escaping (csv.py:30)"]
36
+ rig.run(plan(**{"02/reviewer": [review("02", [escaping])] * 3, "02/fixer": [fix("02", 1), fix("02", 2)],
37
+ "final/final-reviewer": [final()], "final/fixer": [batch]}))
38
+ assert rig.code == 2, rig.out
39
+ (question,) = decisions(rig)["questions"]
40
+ assert question["id"] == Q and "quote escaping (csv.py:30)" in question["title"]
41
+ assert len(rig.final_calls("final-reviewer")) == 1
42
+
43
+
44
+ # ---------------------------------------------------------------- a finding open after the scoped review
45
+
46
+ ATOMIC = finding("ledger write not atomic", file="ledger.py", line=12)
47
+ Q = "final-ticket-blocked-1"
48
+
49
+
50
+ def open_after_batch(tmp_path):
51
+ """The scoped review after the batch reports the important finding ATOMIC, not a must-fix one."""
52
+ rig = rig_of(tmp_path)
53
+ steps = plan(**{"final/final-spec": [final(ATOMIC)], "final/final-reviewer": [final(ATOMIC), final()],
54
+ "final/fixer": [fixer(fn("02"), "fix the ledger"), fixer(fn("02"), "write the ledger atomically")]})
55
+ return rig.run(steps, *UNATTENDED), steps
56
+
57
+
58
+ def test_a_finding_open_after_the_scoped_review_asks_one_final_ticket_blocked_and_pushes_nothing(tmp_path):
59
+ rig, _ = open_after_batch(tmp_path)
60
+ assert rig.code == 2 and not rig.pushes() and not rig.prs(), rig.out
61
+ (question,) = decisions(rig)["questions"]
62
+ assert question["id"] == Q and "ledger write not atomic (ledger.py:12)" in question["title"]
63
+ assert [o["id"] for o in question["options"]] == ["retry", "edit"] and question["recommended"] == "retry"
64
+ assert rig.led("End of run: the operator decides on 1 question of kind ticket-blocked")
65
+
66
+
67
+ def test_retry_on_an_open_final_finding_runs_one_more_fix_batch_and_one_scoped_review(tmp_path):
68
+ rig, steps = open_after_batch(tmp_path)
69
+ rig.run(steps, "--answer", f"{Q}=retry", *UNATTENDED)
70
+ assert rig.code == 0 and rig.pushes() == [f"refs/heads/feat/csv {rig.branch()}"], rig.out
71
+ first, second = rig.final_calls("fixer")
72
+ assert "- important: ledger write not atomic (ledger.py:12)" in second["prompt"]
73
+ (_, scoped) = rig.final_calls("final-reviewer")
74
+ assert scoped["t0"] >= second["t1"] and scoped["head"] == rig.branch() == rig.final()["reviewed"]
75
+ assert [len(rig.final_calls(role)) for role in LENSES] == [1, 1, 1]
76
+
77
+
78
+ def test_edit_on_an_open_final_finding_keeps_the_end_of_run_blocked_and_runs_no_agent(tmp_path):
79
+ rig, steps = open_after_batch(tmp_path)
80
+ calls = len(rig.calls())
81
+ rig.run(steps, "--answer", f"{Q}=edit", *UNATTENDED)
82
+ assert rig.code == 1 and len(rig.calls()) == calls and not rig.pushes() and not rig.prs(), rig.out
83
+ assert rig.led("End of run: BLOCKED at the operator keeps the end of run BLOCKED for an edit (edit)")
84
+
85
+
86
+ # ---------------------------------------------------------------- the locked files
87
+
88
+ def test_a_final_fixer_that_changes_a_locked_file_is_rejected_and_runs_again_on_its_second_entry(tmp_path):
89
+ rig = rig_of(tmp_path, models={**MODELS, "fixer": [OPUS, ASTRA]})
90
+ weakens = fixer(fn("02"), "fix q-one")
91
+ weakens["commits"][0]["files"]["tests/test_01.py"] = "def test_x():\n assert True\n"
92
+ puts_back = fixer(fn("02"), "put the test back")
93
+ puts_back["commits"][0]["files"]["tests/test_01.py"] = tw("01")["files"]["tests/test_01.py"]
94
+ puts_back["report"]["commits"].insert(0, {"sha": "$HEAD", "ticket": "02"})
95
+ rig.run(plan(**{"final/final-spec": [final(finding("Q-ONE"))], "final/fixer": [weakens, puts_back]}))
96
+ assert rig.code == 0, rig.out
97
+ first, second = rig.led("End of run: fixer ran on")
98
+ assert "locked file changed: tests/test_01.py" in first and second.endswith("report accepted.")
99
+ assert OPUS in first and ASTRA in second
100
+ assert git(rig.repo, "show", "feat/csv:tests/test_01.py") == tw("01")["files"]["tests/test_01.py"]
101
+ assert {f["source"] for f in findings_file(rig)} == {"spec"} and not rig.led("from driver")
102
+
103
+
104
+ def test_a_run_of_an_older_driver_after_its_first_round_resumes_into_the_fix_batch_and_one_scoped_review(tmp_path):
105
+ rig = rig_of(tmp_path)
106
+ steps = plan(**{"final/final-spec": [final(finding("Q-ONE"))],
107
+ "final/final-reviewer": [final(finding("SCOPED-NOTE", "minor"))],
108
+ "final/fixer": [{"report": {"status": "DONE"}}] * 2 + [fixer(fn("02"), "fix q-one")]})
109
+ rig.run(steps)
110
+ assert rig.code == 2 and rig.final()["round"] == 1, rig.out
111
+ # As an older driver left it: no lenses record, and findings with no source.
112
+ folder, state = rig.repo / ".agent/implement/final", rig.state()
113
+ del state["run"]["final"]["lenses"]
114
+ state["run"]["final"]["open"] = [{k: v for k, v in f.items() if k != "source"} for f in state["run"]["final"]["open"]]
115
+ (rig.repo / ".agent/implement/state.json").write_text(json.dumps(state))
116
+ old = [{k: v for k, v in f.items() if k != "source"} for f in findings_file(rig)]
117
+ (folder / "findings-0.json").write_text(json.dumps(old))
118
+ before = len(rig.ledger())
119
+
120
+ rig.run(steps, "--answer", f"{Q}=retry")
121
+ assert rig.code == 0, rig.out
122
+ assert [len(rig.final_calls(role)) for role in LENSES] == [1, 1, 1]
123
+ assert len(rig.final_calls("fixer")) == 3 and len(rig.final_calls("final-reviewer")) == 1
124
+ found = [line for line in rig.ledger()[before:] if "finding of kind" in line]
125
+ assert found and all(" from final-reviewer at " in line for line in found)
@@ -30,14 +30,19 @@ def test_updates_from_many_threads_are_all_kept_and_no_scratch_file_stays(tmp_pa
30
30
  def test_start_keeps_a_recorded_run_and_adds_only_the_new_tickets(tmp_path):
31
31
  state = driver_state.State(tmp_path / "state.json")
32
32
  revision = state.start("feat/x", ["01"])["run"]["revision"]
33
- state.update(lambda record: record["tickets"]["01"].pop("fixtures")) # a run of an older driver
33
+
34
+ def older(record): # a run of an older driver: no `landing` key, and a `fixtures` key that no reader reads
35
+ record["tickets"]["01"].pop("landing")
36
+ record["tickets"]["01"]["fixtures"] = ["gh"]
37
+
38
+ state.update(older)
34
39
  state.ticket("01", phase="merged")
35
40
  again = state.start("other", ["01", "02"])
36
41
  assert (again["run"]["revision"], again["run"]["pr_branch"]) == (revision, "feat/x")
37
- assert again["tickets"]["01"]["phase"] == "merged" and again["tickets"]["01"]["fixtures"] == []
42
+ assert again["tickets"]["01"]["phase"] == "merged" and again["tickets"]["01"]["landing"] is None
38
43
  assert again["tickets"]["02"] == {
39
44
  "phase": "pending", "round": 0, "tip": None, "test_writer_sha": None, "locked": [], "green_gates": {"fast": [], "full": []}, "slot": None,
40
- "note": "", "held": {}, "rejected": {}, "fixtures": [], "landing": None}
45
+ "note": "", "landing": None, "disputes": {}, "corrected": {}}
41
46
 
42
47
 
43
48
  def test_verified_trusts_a_tip_only_while_it_is_on_the_ticket_branch(repo, tmp_path):