@jesdi/skills 0.0.98 → 0.0.100

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 (45) hide show
  1. package/package.json +1 -1
  2. package/skills/implement-spec/ARCHITECTURE.md +10 -5
  3. package/skills/implement-spec/README.md +44 -17
  4. package/skills/implement-spec/SKILL.md +4 -2
  5. package/skills/implement-spec/driver.py +166 -40
  6. package/skills/implement-spec/driver_agents.py +26 -8
  7. package/skills/implement-spec/driver_arbiter.py +89 -0
  8. package/skills/implement-spec/driver_decisions.py +212 -39
  9. package/skills/implement-spec/driver_dispute.py +1 -1
  10. package/skills/implement-spec/driver_final.py +255 -186
  11. package/skills/implement-spec/driver_final_gate.py +1 -1
  12. package/skills/implement-spec/driver_legacy.py +15 -2
  13. package/skills/implement-spec/driver_overturn.py +106 -0
  14. package/skills/implement-spec/driver_pr.py +277 -0
  15. package/skills/implement-spec/driver_report.py +24 -6
  16. package/skills/implement-spec/driver_review.py +10 -4
  17. package/skills/implement-spec/driver_run.py +38 -15
  18. package/skills/implement-spec/driver_slots.py +33 -0
  19. package/skills/implement-spec/driver_state.py +29 -15
  20. package/skills/implement-spec/driver_summary.py +11 -4
  21. package/skills/implement-spec/models.json +2 -1
  22. package/skills/implement-spec/prompts/arbiter.md +38 -0
  23. package/skills/implement-spec/prompts/conflict.md +1 -1
  24. package/skills/implement-spec/prompts/pr-body.md +1 -1
  25. package/skills/implement-spec/recovery.md +4 -4
  26. package/skills/implement-spec/tests/conftest.py +3 -0
  27. package/skills/implement-spec/tests/test_arbiter.py +208 -0
  28. package/skills/implement-spec/tests/test_arbitration.py +1 -1
  29. package/skills/implement-spec/tests/test_cli.py +1 -1
  30. package/skills/implement-spec/tests/test_decisions.py +31 -7
  31. package/skills/implement-spec/tests/test_driver.py +10 -2
  32. package/skills/implement-spec/tests/test_final.py +34 -9
  33. package/skills/implement-spec/tests/test_fixloop.py +2 -2
  34. package/skills/implement-spec/tests/test_leave_out.py +203 -0
  35. package/skills/implement-spec/tests/test_legacy.py +25 -0
  36. package/skills/implement-spec/tests/test_lenses.py +6 -4
  37. package/skills/implement-spec/tests/test_overturn.py +362 -0
  38. package/skills/implement-spec/tests/test_report.py +1 -1
  39. package/skills/implement-spec/tests/test_scoped.py +18 -15
  40. package/skills/implement-spec/tests/test_ship_draft.py +203 -0
  41. package/skills/implement-spec/tests/test_slots.py +29 -0
  42. package/skills/implement-spec/tests/test_state.py +4 -2
  43. package/skills/implement-spec/tests/test_stops.py +21 -5
  44. package/skills/implement-spec/tests/test_tidy.py +7 -5
  45. package/skills-manifest.json +3 -3
@@ -15,7 +15,8 @@ Interface choices (ticket 06):
15
15
  - a tidied commit has the subject `feat(NN): <ticket title>` and a body line `Ticket: <ticket file name>`.
16
16
  - the final fixer's `commits` hold `{"sha", "ticket"}` objects, and the driver renames each fixer commit to
17
17
  `fix(NN): <its subject>` before the gate and the scoped review run (no rewrite after a review).
18
- - a finding open after the scoped review: question `final-ticket-blocked-<n>`, options `retry` and `edit`.
18
+ - a finding open after the scoped review: question `final-finding-open-<n>`, or `final-finding-must-fix-<n>` for a
19
+ critical or must-fix one, options `retry`, `accept` and `follow-up`.
19
20
  - local stop: stdout lines `Branch tip: <sha>`, `Reviewed tip: <sha>` and the rerun command, which has `--push`.
20
21
  - the PR body lists, per ticket, a line with the ticket number and its commit's first 7 hex, and every ruling line.
21
22
  - stage.json at a clean unattended end is `{"stage": "implement", "status": "done"}`.
@@ -34,9 +35,10 @@ from types import SimpleNamespace
34
35
 
35
36
  import pytest
36
37
 
38
+ import driver_final
37
39
  from test_cli import SKILL, git, ticket
38
40
  from test_review import ASTRA, FABLE, HOOKED, ONE, OPUS, Review, finding, gate_rule, no_full_gate, review
39
- from test_stops import UNATTENDED, stage
41
+ from test_stops import DONE, UNATTENDED, stage
40
42
  from test_walk import fix, impl, plan
41
43
 
42
44
  SCOPED = HOOKED
@@ -81,9 +83,20 @@ for i, a in enumerate(argv[:-1]):
81
83
  body = argv[i + 1]
82
84
  if a in ("--body-file", "-F"):
83
85
  body = sys.stdin.read() if argv[i + 1] == "-" else Path(argv[i + 1]).read_text()
84
- with (Path(__file__).resolve().parent.parent / "gh.jsonl").open("a") as log:
85
- log.write(json.dumps(dict(argv=argv, body=body)) + "\\n")
86
- print("https://github.example/pull/1")
86
+ log = Path(__file__).resolve().parent.parent / "gh.jsonl"
87
+ if argv[:2] == ["issue", "list"]: # an issue whose body has the searched marker, as `gh issue create` logged it
88
+ marker = argv[argv.index("--search") + 1].split('"')[1]
89
+ rows = [json.loads(line) for line in log.read_text().splitlines()] if log.exists() else []
90
+ print(next(("https://github.example/issues/1" for row in rows
91
+ if row["argv"][:2] == ["issue", "create"] and marker in row["body"]), ""))
92
+ sys.exit(0)
93
+ if argv[:2] == ["pr", "view"]: # the state of the PR: OPEN, unless a test wrote another into gh-pr-state
94
+ state = log.with_name("gh-pr-state")
95
+ print(state.read_text().strip() if state.exists() else "OPEN")
96
+ sys.exit(0)
97
+ with log.open("a") as out:
98
+ out.write(json.dumps(dict(argv=argv, body=body)) + "\\n")
99
+ print("https://github.example/issues/1" if argv[:2] == ["issue", "create"] else "https://github.example/pull/1")
87
100
  """
88
101
  HOOK = '#!/bin/sh\nwhile read old new ref; do echo "$ref $new" >> "%s"; done\n'
89
102
 
@@ -317,7 +330,7 @@ def test_green_ticket_carries_cap_finding_into_required_final_fix(tmp_path):
317
330
  assert len(rig.final_calls("fixer")) == 1
318
331
 
319
332
 
320
- def test_unresolved_must_fix_cannot_be_accepted_or_published(tmp_path):
333
+ def test_unresolved_must_fix_asks_and_is_not_published_while_the_operator_is_asked(tmp_path):
321
334
  rig = Final(tmp_path, THREE, {"implementer": [OPUS, FABLE]})
322
335
  recurring = review("02", [{**finding("MERGED-QUOTING-REGRESSION"), "basis": "regression"}])
323
336
  batch = fixer(fn("02"), "attempt quoting fix", ticket_of="02")
@@ -330,7 +343,7 @@ def test_unresolved_must_fix_cannot_be_accepted_or_published(tmp_path):
330
343
 
331
344
  assert rig.code == 2, rig.output()
332
345
  (question,) = rig.state()["run"]["questions"]
333
- assert question["id"] == "final-ticket-blocked-1" and "MERGED-QUOTING-REGRESSION" in question["subject"]
346
+ assert question["id"] == "final-finding-must-fix-1" and "MERGED-QUOTING-REGRESSION" in question["subject"]
334
347
  assert [item["title"] for item in rig.state()["run"]["final"]["open"]] == ["MERGED-QUOTING-REGRESSION"]
335
348
  assert not rig.pushes() and not rig.prs()
336
349
  rig.run(steps)
@@ -468,7 +481,7 @@ def test_unattended_with_everything_validated_pushes_once_opens_the_pr_and_write
468
481
  assert rig.pushes() == [f"refs/heads/feat/csv {tip}"] and ref(rig.origin, "refs/heads/feat/csv") == tip
469
482
  (pr,) = rig.prs()
470
483
  assert [l for l in pr["body"].splitlines() if "01" in l and tip[:7] in l], pr["body"]
471
- assert stage(rig) == {"stage": "implement", "status": "done"}
484
+ assert stage(rig) == DONE
472
485
 
473
486
 
474
487
  def test_unattended_with_a_blocked_ticket_pushes_nothing_and_exits_1(tmp_path):
@@ -604,7 +617,7 @@ def test_a_cached_body_that_no_longer_validates_is_rewritten_before_gh_pr_create
604
617
  steps = plan(**{"final/pr-writer": [writer(risk_body()), writer(risk_body())]})
605
618
  rig, _ = pushed_run(tmp_path, monkeypatch, steps, "claude", gh_fails=True)
606
619
  assert rig.code != 0 and "gh pr create failed" in rig.out and len(rig.final_calls("pr-writer")) == 1, rig.out
607
- cached = rig.repo / ".agent/implement/final/pr-body.md"
620
+ cached = rig.repo / ".agent/implement/final/pr-writer-body.md"
608
621
  cached.write_text(cached.read_text().replace("touches: [docs]", "touches: [styles]"))
609
622
  (tmp_path / "bin/gh").write_text(GH)
610
623
  rig.rerun()
@@ -667,3 +680,15 @@ def test_final_gate_repair_can_prove_no_code_change_but_still_spends_its_attempt
667
680
  assert [g['exit'] for g in rig.gates('full')] == [1, 0 if transient else 1]
668
681
  assert bool(rig.pushes()) == transient
669
682
  assert len(rig.final_calls('final-spec')) == int(transient)
683
+
684
+
685
+ def test_the_final_review_carries_each_minor_finding_and_observation_of_the_tickets_once(tmp_path, monkeypatch):
686
+ monkeypatch.chdir(tmp_path)
687
+ folder = tmp_path / ".agent/implement/01"
688
+ folder.mkdir(parents=True)
689
+ one = {"title": "t", "file": "a.py", "line": 1}
690
+ (folder / "findings-0.json").write_text(json.dumps([{**one, "severity": "minor"}, {**one, "severity": "important",
691
+ "title": "big"}]))
692
+ (folder / "observations-0.json").write_text(json.dumps([{**one, "title": "seen"}, {**one, "title": "seen"}]))
693
+ assert driver_final._carried_findings() == (f"- .agent/implement/01/findings-0.json: t (a.py:1)\n"
694
+ f"- .agent/implement/01/observations-0.json: seen (a.py:1)")
@@ -156,7 +156,7 @@ def test_a_locked_test_finding_that_comes_back_after_its_correction_asks_spec_am
156
156
  assert rig.code == 2 and rig.state()["tickets"]["01"]["phase"] == "blocked", rig.ledger()
157
157
  assert rig.led("BLOCKED at the review: the spec reads two ways on a locked test: tests/test_01.py::test_x: the "
158
158
  "first reading: STALE: STALE; the second reading: STALE: STALE.")
159
- assert asked(rig) == {AMBIGUOUS_1: ["keep-test", "correct-test", "edit-spec"]}
159
+ assert asked(rig) == {AMBIGUOUS_1: ["keep-test", "correct-test", "leave-out", "edit-spec"]}
160
160
  (question,) = rig.state()["run"]["questions"]
161
161
  assert question["recommended"] == "" and question["evidence"][0] == ".agent/implement/01/spec-ambiguous-1.json"
162
162
  rig.run(steps, "--answer", f"{AMBIGUOUS_1}=correct-test")
@@ -1139,7 +1139,7 @@ def test_the_templates_of_the_new_roles_hold_a_valid_schema_and_end_with_the_rul
1139
1139
 
1140
1140
  def test_no_template_names_the_ledger_and_the_method_of_step_6_is_in_the_reviewer_prompt():
1141
1141
  # The final review gets the ledger as a pointer (requirement 19); no other prompt names it.
1142
- final = ("final-reviewer.md", "final-lens.md", "lens-correctness.md")
1142
+ final = ("final-reviewer.md", "final-lens.md", "lens-correctness.md", "arbiter.md")
1143
1143
  for path in driver_report.PROMPTS.glob("*.md"):
1144
1144
  assert ("ledger" in path.read_text().lower()) == (path.name in final), path.name
1145
1145
  reviewer = (driver_report.PROMPTS / "reviewer.md").read_text()
@@ -0,0 +1,203 @@
1
+ """`leave-out`: once the driver's retries are spent on a ticket's stop, the driver leaves the ticket out of the run,
2
+ with each ticket it blocks; the merged tickets get the end of run and a draft PR that names them. The arbiter rules
3
+ `keep-test` or `correct-test` on a `spec-ambiguous` question, at most `--retries` stops of one ticket; the next one
4
+ leaves the ticket out. `--ask` (IMPLEMENT_SPEC_ASK=1, which conftest pins) asks the operator instead.
5
+
6
+ In process, on the rigs of test_tidy and test_arbitration."""
7
+ from test_arbiter import ARBITER, ruled
8
+ from test_arbitration import AMBIGUOUS, SECOND, SINGLE, correction, disputes, ruling
9
+ from test_cli import git, ticket
10
+ from test_final import RESOLVE, THREE, final, fixer, fn
11
+ from test_fixloop import Inside as Local
12
+ from test_fixloop import inside # noqa: F401 (the autouse fixture puts the rig's CLIs on PATH)
13
+ from test_review import ONE, review
14
+ from test_scoped import ATOMIC
15
+ from test_stops import UNATTENDED, blocked, decisions, stage
16
+ from test_tidy import Inside
17
+ from test_tidy import tools # noqa: F401 (tools is an autouse fixture)
18
+ from test_walk import impl, plan, tw
19
+
20
+ AUTONOMOUS = ("--no-ask", "--retries", "0", *UNATTENDED)
21
+ FOUR = {**THREE, "04-export-docs.md": ticket("04", "Export docs", "02", touches="`demo/docs.py: h`")}
22
+
23
+
24
+ def dirty(path, text="half = 1\n"):
25
+ """A BLOCKED implementer that leaves uncommitted work in its slot."""
26
+ return {**blocked(), "files": {path: text}}
27
+
28
+
29
+ def test_a_blocked_ticket_is_left_out_with_the_tickets_it_blocks_and_the_rest_ships_as_draft(tmp_path):
30
+ rig = Inside(tmp_path, THREE)
31
+ rig.run(plan(**{"01/implementer": [blocked(), blocked()]}), *AUTONOMOUS)
32
+ assert rig.code == 0, rig.output()
33
+ tickets = rig.state()["tickets"]
34
+ assert (tickets["01"]["phase"], tickets["02"]["phase"], tickets["03"]["phase"]) == ("blocked", "pending", "merged")
35
+ assert not rig.calls("02"), "a ticket that a left-out ticket blocks never starts"
36
+ assert rig.led("(leave-out)") and rig.led("Ruled by the driver, not the operator.")
37
+ (pr,) = rig.prs()
38
+ assert "--draft" in pr["argv"]
39
+ assert "Left out of the run, so not in this PR: 01 Export rows; 02 Quote fields." in pr["body"]
40
+ assert rig.led("open as a draft: tickets are left out of the run: 01, 02")
41
+ assert stage(rig) == {"stage": "implement", "status": "done", "draft": True, "decisions": 1}
42
+
43
+
44
+ def test_a_left_out_ticket_s_work_in_slot_2_is_saved_and_the_tickets_it_blocks_through_another_are_left_out(
45
+ tmp_path):
46
+ rig = Inside(tmp_path, FOUR)
47
+ rig.run(plan(**{"03/implementer": [dirty("demo/cli.py"), dirty("demo/cli.py")]}), *AUTONOMOUS)
48
+ assert rig.code == 0, rig.output()
49
+ phases = {number: entry["phase"] for number, entry in rig.state()["tickets"].items()}
50
+ assert phases == {"01": "merged", "02": "pending", "03": "blocked", "04": "pending"}
51
+ (pr,) = rig.prs()
52
+ assert "Left out of the run, so not in this PR: 02 Quote fields; 03 CLI flag; 04 Export docs." in pr["body"]
53
+ patch = ".agent/implement/03/left-out.patch"
54
+ assert rig.led(f"Ticket 03: left out; its uncommitted work in slot 2 is saved as {patch}, and the slot is free.")
55
+ assert "+half = 1" in (rig.repo / patch).read_text()
56
+ slot = rig.repo / ".agent/worktrees/slot-2"
57
+ assert git(slot, "status", "--porcelain") == "" and git(slot, "rev-parse", "--abbrev-ref", "HEAD").strip() == "HEAD"
58
+
59
+
60
+ def test_a_left_out_ticket_s_work_in_slot_1_is_saved_and_the_next_ticket_starts_there_clean(tmp_path):
61
+ rig = Inside(tmp_path, THREE)
62
+ rig.run(plan(**{"01/implementer": [dirty("demo/export.py"), dirty("demo/export.py")]}), *AUTONOMOUS, parallel="1")
63
+ assert rig.code == 0, rig.output()
64
+ assert rig.state()["tickets"]["03"]["phase"] == "merged"
65
+ assert rig.led("Ticket 01: left out; its uncommitted work in slot 1 is saved as .agent/implement/01/left-out.patch")
66
+ (writer,) = rig.calls("03", "test-writer")
67
+ assert writer["status"] == "" and writer["cwd"] == str(rig.repo.resolve())
68
+ assert "half = 1" not in git(rig.repo, "show", "feat/csv:demo/export.py")
69
+
70
+
71
+ def test_an_operator_s_leave_out_saves_the_work_of_slot_1_before_the_next_ticket_starts_there(tmp_path):
72
+ rig = Inside(tmp_path, THREE)
73
+ steps = plan(**{"01/implementer": [dirty("demo/export.py"), dirty("demo/export.py")]})
74
+ rig.run(steps, "--retries", "0", *UNATTENDED, parallel="1")
75
+ assert rig.code == 2, rig.output()
76
+ rig.run(steps, "--retries", "0", "--answer", "01-ticket-blocked-1=leave-out", *UNATTENDED, parallel="1")
77
+ assert rig.code == 0 and rig.state()["tickets"]["03"]["phase"] == "merged", rig.output()
78
+ assert rig.led("Ticket 01: left out; its uncommitted work in slot 1 is saved as .agent/implement/01/left-out.patch")
79
+ (writer,) = rig.calls("03", "test-writer")
80
+ assert writer["status"] == ""
81
+
82
+
83
+ def test_the_rebase_conflict_agent_locks_only_the_merged_tickets(tmp_path):
84
+ rig = Inside(tmp_path, THREE)
85
+ rig.move_base({"demo/cli.py": "def main():\n return 'base'\n"})
86
+ # The resolution writes the locked test of 01, which is left out: no merged ticket locks it.
87
+ resolve = {**RESOLVE, "files": {"demo/cli.py": "x = 1\n", "tests/test_01.py": "def test_x():\n assert True\n"}}
88
+ rig.run(plan(**{"01/implementer": [blocked(), blocked()], "final/conflict": [resolve]}), *AUTONOMOUS)
89
+ assert rig.code == 0, rig.output()
90
+ (line,) = rig.led("End of run: conflict ran on")
91
+ assert line.endswith("report accepted."), line
92
+
93
+
94
+ def test_the_final_fixer_owns_and_locks_only_the_merged_tickets(tmp_path):
95
+ rig = Inside(tmp_path, THREE)
96
+ rig.run(plan(**{"01/implementer": [blocked(), blocked()], "final/final-spec": [final(ATOMIC)],
97
+ "final/final-reviewer": [final()],
98
+ "final/fixer": [fixer(fn("03"), "fix it", ticket_of="01"),
99
+ fixer(fn("03"), "fix it", ticket_of="03")]}),
100
+ *AUTONOMOUS)
101
+ assert rig.code == 0, rig.output()
102
+ first, second = rig.final_calls("fixer")
103
+ assert "IMPLEMENT_SPEC_LOCKED='tests/test_03.py'" in first["prompt"]
104
+ rejected, _ = rig.led("End of run: fixer ran on")
105
+ assert "01" in rejected and "accepted" not in rejected
106
+ assert [c["subject"] for c in rig.commits(rig.start) if c["subject"].startswith("fix(")] == ["fix(03): fix it"]
107
+
108
+
109
+ def test_ask_keeps_the_park_and_a_ticket_question_offers_leave_out(tmp_path):
110
+ rig = Inside(tmp_path, THREE)
111
+ rig.run(plan(**{"01/implementer": [blocked(), blocked()]}), "--retries", "0", *UNATTENDED)
112
+ assert rig.code == 2 and not rig.pushes(), rig.out
113
+ (question,) = decisions(rig)["questions"]
114
+ assert [o["id"] for o in question["options"]] == ["retry", "leave-out", "edit"]
115
+
116
+
117
+ def test_ask_on_spec_ambiguous_asks_the_operator_with_leave_out_and_no_arbiter(tmp_path):
118
+ rig = ambiguous(tmp_path, "--retries", "0", "--ask", then=())
119
+ assert rig.code == 2 and not rig.calls("final", "arbiter"), rig.ledger()
120
+ (question,) = decisions(rig)["questions"]
121
+ assert question["id"] == AMBIGUOUS and "leave-out" in [o["id"] for o in question["options"]]
122
+
123
+
124
+ def test_no_ticket_is_left_out_when_it_would_leave_out_every_ticket(tmp_path):
125
+ rig = Inside(tmp_path, ONE)
126
+ rig.run(plan(**{"01/implementer": [blocked(), blocked()]}), *AUTONOMOUS)
127
+ assert rig.code == 2 and not rig.pushes(), rig.out
128
+ assert [q["id"] for q in decisions(rig)["questions"]] == ["01-ticket-blocked-1"]
129
+
130
+
131
+ def ambiguous(tmp_path, *extra, files=ONE, arbiter=(), then=(impl("01"),), writer=(tw("01"),)):
132
+ """Ticket 01 after a `code-wrong` ruling and a second dispute on the same test, run with `extra`."""
133
+ rig = Local(tmp_path, files, models=ARBITER)
134
+ return rig.run(plan(**{"01/implementer": [disputes(), disputes(), *then], "01/test-writer": list(writer),
135
+ "01/reviewer": [ruling("code-wrong", "R3 says double quotes"), review("01")],
136
+ "final/arbiter": list(arbiter)}), "--no-ask", *extra)
137
+
138
+
139
+ def test_the_arbiter_rules_keep_test_on_spec_ambiguous_and_the_ticket_goes_on(tmp_path):
140
+ rig = ambiguous(tmp_path, "--retries", "1", arbiter=[ruled((AMBIGUOUS, "keep-test"))])
141
+ assert rig.code == 0 and rig.state()["tickets"]["01"]["phase"] == "merged", rig.ledger()
142
+ (arbiter,) = rig.calls("final", "arbiter")
143
+ assert f"- {AMBIGUOUS}: " in arbiter["prompt"] and "Options: keep-test, correct-test." in arbiter["prompt"]
144
+ assert rig.led("(keep-test)", "Ruled by the arbiter, not the operator: why keep-test. Cost if wrong: cost of")
145
+
146
+
147
+ def test_the_arbiter_rules_correct_test_and_the_test_writer_corrects_the_test_then_the_ticket_merges(tmp_path):
148
+ rig = ambiguous(tmp_path, "--retries", "1", arbiter=[ruled((AMBIGUOUS, "correct-test"))],
149
+ writer=[tw("01"), correction()])
150
+ assert rig.code == 0 and rig.state()["tickets"]["01"]["phase"] == "merged", rig.ledger()
151
+ assert rig.led("(correct-test)", "Ruled by the arbiter, not the operator: why correct-test.")
152
+ assert len(rig.calls("01", "test-writer")) == 2
153
+
154
+
155
+ def test_a_second_spec_ambiguous_stop_past_the_arbiter_s_budget_leaves_the_ticket_out(tmp_path):
156
+ rig = ambiguous(tmp_path, "--retries", "1", files={**ONE, **SECOND}, arbiter=[ruled((AMBIGUOUS, "keep-test"))],
157
+ then=(disputes(),))
158
+ assert rig.code == 0, rig.ledger()
159
+ assert len(rig.calls("final", "arbiter")) == 1 and rig.state()["tickets"]["02"]["phase"] == "merged"
160
+ assert rig.led("Ruling: 01 is left out of the run, with each ticket it blocks (leave-out)")
161
+ assert [q["id"] for q in rig.state()["run"]["questions"] if q["answer"] == "leave-out"] == ["01-spec-ambiguous-2"]
162
+
163
+
164
+ def test_the_arbiter_rules_in_its_own_checkout_while_slot_1_holds_a_stopped_ticket_s_work(tmp_path):
165
+ test, question = "tests/test_02.py::test_x", "02-spec-ambiguous-1"
166
+ rig = Local(tmp_path, {**ONE, **SECOND}, models=ARBITER)
167
+ rig.run(plan(**{"01/implementer": [dirty("demo/export.py")] * 4,
168
+ "02/implementer": [disputes((test, SINGLE)), disputes((test, "the example in R3 uses '")),
169
+ impl("02")],
170
+ "02/reviewer": [ruling("code-wrong", "R3 says double quotes", test=test), review("02")],
171
+ "final/arbiter": [ruled((question, "keep-test"))]}), "--no-ask", "--retries", "1")
172
+ assert rig.code == 0 and rig.state()["tickets"]["02"]["phase"] == "merged", rig.ledger()
173
+ (arbiter,) = rig.calls("final", "arbiter")
174
+ assert arbiter["cwd"].endswith(".agent/worktrees/arbiter") and arbiter["status"] == ""
175
+ assert "../../../specs/csv/spec.md" in arbiter["prompt"]
176
+ assert rig.led("Ticket 01: left out; its uncommitted work in slot 1 is saved")
177
+ assert not (rig.repo / ".agent/worktrees/arbiter").exists()
178
+
179
+
180
+ def test_an_arbiter_ruling_that_the_question_does_not_offer_is_rejected(tmp_path):
181
+ rig = ambiguous(tmp_path, "--retries", "1",
182
+ arbiter=[ruled((AMBIGUOUS, "accept")), ruled((AMBIGUOUS, "keep-test"))])
183
+ assert rig.code == 0, rig.ledger()
184
+ first, _ = rig.led("End of run: arbiter ran on")
185
+ assert f"rulings: {AMBIGUOUS} takes keep-test or correct-test, not accept" in first
186
+
187
+
188
+ def test_a_spec_ambiguous_stop_past_the_budget_of_the_arbiter_leaves_the_ticket_out(tmp_path):
189
+ rig = ambiguous(tmp_path, "--retries", "0", files={**ONE, **SECOND}, then=())
190
+ assert rig.code == 0, rig.ledger()
191
+ assert not rig.calls("final", "arbiter")
192
+ assert rig.state()["tickets"]["02"]["phase"] == "merged"
193
+ assert rig.led("Ruling: 01 is left out of the run, with each ticket it blocks (leave-out)")
194
+
195
+
196
+ def test_the_left_out_tickets_are_the_ones_answered_leave_out_and_every_ticket_they_block():
197
+ import driver_decisions
198
+ from driver_tickets import Ticket
199
+ make = lambda number, *blockers: Ticket(number, "", "", "", "", "", "", "", [], {}, list(blockers))
200
+ tickets = [make("01"), make("02", "01", "03"), make("03"), make("04", "02")]
201
+ answered = lambda *answers: [{"ticket": number, "answer": answer} for number, answer in answers]
202
+ assert driver_decisions.left_out(answered(("03", "leave-out"), ("01", "retry")), tickets) == {"02", "03", "04"}
203
+ assert driver_decisions.left_out(answered(("01", None)), tickets) == set()
@@ -2,6 +2,7 @@
2
2
  import json
3
3
  import subprocess
4
4
 
5
+ import driver_decisions
5
6
  import driver_dispute
6
7
  import driver_legacy
7
8
  import driver_state
@@ -164,3 +165,27 @@ def test_resume_keys_the_rulings_and_corrections_of_a_schema_4_run_by_their_test
164
165
  assert [one["key"] for one in json.loads(evidence.read_text())] == ["tests/test_01.py::test_x", "tests/test_02.py"]
165
166
  assert driver_dispute.kept(state.read()["run"]["questions"][:1], "01") == {"tests/test_01.py::test_x",
166
167
  "tests/test_02.py"}
168
+
169
+
170
+ def test_resume_makes_the_open_finding_questions_of_a_schema_5_run_on_a_must_fix_finding_must_fix(repo, tmp_path):
171
+ """Schema 5 had no `finding-must-fix`: an open `finding-open` question on a critical or must-fix finding of the
172
+ last review becomes one, with its id and its decisions.json revision; one on an important finding, or an answered
173
+ one, does not. A later `finding-open` question gets the next id, not the one the changed question keeps."""
174
+ state, _, _ = older_run(repo, tmp_path)
175
+ found = [{"title": "leak", "file": "auth.py", "severity": "critical"},
176
+ {"title": "quoting", "file": "csv.py", "severity": "important", "must_fix": True},
177
+ {"title": "slow", "file": "db.py", "severity": "important"}]
178
+ asked = []
179
+ for one in found:
180
+ asked.append(driver_decisions.question("finding-open", "final", f"{one['title']} ({one['file']})", [], asked,
181
+ 1, driver_decisions.Resume("final")))
182
+ answered = {**asked[0], "id": "final-finding-open-4", "answer": "retry", "ruling": "r"}
183
+ edit(state, final={"recovery": None, "open": found}, questions=[*asked, answered], revision="run-1", stops=1)
184
+ before = driver_decisions.document(state.read()["run"])
185
+ assert resume(state, tmp_path)[0] == []
186
+ run = state.read()["run"]
187
+ assert [(q["id"], q["kind"]) for q in run["questions"]] == [
188
+ ("final-finding-open-1", "finding-must-fix"), ("final-finding-open-2", "finding-must-fix"),
189
+ ("final-finding-open-3", "finding-open"), ("final-finding-open-4", "finding-open")]
190
+ assert driver_decisions.document(run) == before and run["schema"] == driver_state.SCHEMA
191
+ assert driver_decisions.question_id("finding-open", "final", run["questions"]) == "final-finding-open-5"
@@ -9,6 +9,7 @@ import pytest
9
9
  import driver
10
10
  import driver_agents
11
11
  import driver_final
12
+ import driver_pr
12
13
  from test_final import Final, final, fixer, fn
13
14
  from test_fixloop import inside # noqa: F401 (the autouse fixture puts the rig's CLIs on PATH)
14
15
  from test_review import RISKY, finding, fix, review
@@ -93,7 +94,7 @@ def test_with_the_other_provider_out_of_credits_every_review_runs_on_the_entry_l
93
94
  assert rig.out.splitlines()[:2] == skipped and rig.ledger()[:2] == skipped
94
95
  ran = {(agent["role"], agent["entry"]) for agent in rig.state()["run"]["agents"]}
95
96
  assert {entry for role, entry in ran if role in ("reviewer", "final-correctness")} == {OPUS}, ran
96
- assert driver_final._review_providers(rig.state()["run"]["agents"]).splitlines() == [
97
+ assert driver_pr._review_providers(rig.state()["run"]["agents"]).splitlines() == [
97
98
  f"- Ticket reviews ran on: {OPUS}, on a provider that also wrote code",
98
99
  f"- Correctness lens ran on: {OPUS}, on a provider that also wrote code"]
99
100
 
@@ -102,7 +103,7 @@ def test_the_review_coverage_names_only_what_ran_so_an_undone_fallback_is_not_cl
102
103
  agents = [{"role": "implementer", "entry": SONNET}, {"role": "reviewer", "entry": OPUS},
103
104
  {"role": "reviewer", "entry": ASTRA}, {"role": "final-correctness", "entry": ASTRA},
104
105
  {"role": "final-reviewer", "entry": ASTRA}]
105
- assert driver_final._review_providers(agents).splitlines() == [
106
+ assert driver_pr._review_providers(agents).splitlines() == [
106
107
  f"- Ticket reviews ran on: {OPUS}, {ASTRA}, on a provider that also wrote code",
107
108
  f"- Correctness lens ran on: {ASTRA}", f"- Scoped review ran on: {ASTRA}"]
108
109
 
@@ -123,8 +124,9 @@ def test_a_final_reviewer_list_with_no_entry_on_another_provider_runs_every_revi
123
124
 
124
125
 
125
126
  def test_without_the_deep_quality_review_skill_the_run_exits_3_before_any_agent(tmp_path, monkeypatch):
126
- installed = driver_final._installed
127
- monkeypatch.setattr(driver_final, "_installed", lambda name: None if name == "deep-quality-review" else installed(name))
127
+ installed = driver_agents.installed
128
+ monkeypatch.setattr(driver_agents, "installed",
129
+ lambda name: None if name == "deep-quality-review" else installed(name))
128
130
  rig = rig_of(tmp_path).run(plan())
129
131
  assert rig.code == 3 and not rig.calls(), rig.out
130
132
  assert rig.out == ("the deep-quality-review skill is missing its SKILL.md: the structure lens of the final review "