@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
@@ -0,0 +1,362 @@
1
+ """Overturn: after a run, `--answer <question id>=<other option>` on a question the driver or the arbiter answered
2
+ overturns its ruling. The new ruling says which ruling it overturns and who took it, and it takes effect from where the
3
+ run is: an accepted finding gets a fix batch, a left-out ticket runs again, a draft's stop runs again. What lands is
4
+ pushed on top of the open PR, with no force. An overturn that would undo work, or that cannot take effect, exits 3
5
+ before any agent and says why.
6
+
7
+ In process, on the rigs of test_arbiter, test_leave_out and test_ship_draft."""
8
+ import subprocess
9
+
10
+ import pytest
11
+
12
+ import driver_decisions
13
+ import driver_overturn
14
+ import driver_pr
15
+ from test_arbiter import Q, gh, open_after_batch, ruled
16
+ from test_arbitration import AMBIGUOUS, SECOND, disputes, ruling
17
+ from test_final import GH, THREE, final, fixer, fn
18
+ from test_fixloop import Inside as Local
19
+ from test_fixloop import inside # noqa: F401 (the autouse fixture puts the rig's CLIs on PATH)
20
+ from test_lenses import rig_of, stopped
21
+ from test_scoped import ATOMIC
22
+ from test_review import ONE, review
23
+ from test_stops import UNATTENDED, blocked
24
+ from test_tidy import Inside
25
+ from test_tidy import tools # noqa: F401 (tools is an autouse fixture)
26
+ from test_walk import impl, plan, tw
27
+
28
+ AUTONOMOUS = ("--no-ask", "--retries", "0", *UNATTENDED)
29
+
30
+
31
+ def on_top(rig, first):
32
+ """The branch tip holds the first pushed tip: the second push needed no force."""
33
+ return subprocess.run(["git", "merge-base", "--is-ancestor", first, rig.branch()], cwd=rig.repo).returncode == 0
34
+
35
+
36
+ def test_an_accept_overturned_to_retry_gets_a_fix_batch_pushed_on_top_of_the_open_draft(tmp_path):
37
+ rig, steps = open_after_batch(tmp_path, ATOMIC, [ruled((Q, "accept"))])
38
+ assert rig.code == 0 and len(rig.final_calls("fixer")) == 1, rig.out
39
+ first = rig.branch()
40
+ steps["final/fixer"].append(fixer(fn("02"), "write the ledger atomically"))
41
+ steps["final/final-reviewer"].append(final())
42
+ rig.run(steps, *AUTONOMOUS, "--answer", f"{Q}=retry")
43
+ assert rig.code == 0, rig.out
44
+ assert len(rig.final_calls("fixer")) == 2 and len(rig.prs()) == 1, "the open PR is not opened again"
45
+ assert rig.pushes() == [f"refs/heads/feat/csv {first}", f"refs/heads/feat/csv {rig.branch()}"]
46
+ assert on_top(rig, first)
47
+ (q,) = rig.state()["run"]["questions"]
48
+ assert q["answer"] == "retry" and "by" not in q
49
+ line = ("Ruling: final runs again (retry): ledger write not atomic (ledger.py). It overturns the ruling accept of "
50
+ "the arbiter.")
51
+ summary = (rig.repo / ".agent/implement/summary.md").read_text()
52
+ assert rig.led(line) and f"Overturned by the operator:\n- {Q}: {line}" in summary
53
+ assert "Driver decisions, taken without the operator:" not in summary
54
+ (edit,) = gh(rig, ["pr", "edit"])
55
+ assert edit["argv"][2] == "https://github.example/pull/1" and "--ready" not in edit["argv"]
56
+ assert line in edit["body"] and f"Branch tip and reviewed tip: {rig.branch()}" in edit["body"]
57
+ assert edit["body"].startswith(rig.prs()[0]["body"].split("\n\n## Tickets")[0]), "the pr-writer's part stays"
58
+ assert rig.led("The body of the PR https://github.example/pull/1 is written again")
59
+ rig.run(steps, *AUTONOMOUS)
60
+ assert rig.code == 0 and len(gh(rig, ["pr", "edit"])) == 1, "a rerun that changes nothing edits no body"
61
+
62
+
63
+ def test_an_accept_overturned_to_follow_up_files_the_issue_for_the_open_pr(tmp_path):
64
+ rig, steps = open_after_batch(tmp_path, ATOMIC, [ruled((Q, "accept"))])
65
+ assert rig.code == 0 and not gh(rig, ["issue", "create"]), rig.out
66
+ rig.run(steps, *AUTONOMOUS, "--answer", f"{Q}=follow-up")
67
+ assert rig.code == 0, rig.out
68
+ (issue,) = gh(rig, ["issue", "create"])
69
+ assert "It overturns the ruling accept of the arbiter." in issue["body"]
70
+ assert len(rig.prs()) == 1 and len(rig.final_calls("fixer")) == 1
71
+ (edit,) = gh(rig, ["pr", "edit"])
72
+ assert "Follow-up issue: https://github.example/issues/1" in edit["body"]
73
+
74
+
75
+ def test_a_left_out_ticket_overturned_to_retry_runs_again_and_lands_on_top_of_the_open_draft(tmp_path):
76
+ rig = Inside(tmp_path, THREE)
77
+ steps = plan(**{"01/implementer": [blocked(), blocked()]})
78
+ rig.run(steps, *AUTONOMOUS)
79
+ assert rig.code == 0 and len(rig.prs()) == 1, rig.output()
80
+ first = rig.branch()
81
+ steps["01/implementer"].append(impl("01"))
82
+ rig.run(steps, *AUTONOMOUS, "--answer", "01-ticket-blocked-1=retry")
83
+ assert rig.code == 0, rig.output()
84
+ assert {entry["phase"] for entry in rig.state()["tickets"].values()} == {"merged"}
85
+ assert rig.calls("02"), "the ticket the left-out one blocked runs too"
86
+ assert rig.pushes()[-1] == f"refs/heads/feat/csv {rig.branch()}" and on_top(rig, first)
87
+ assert len(rig.prs()) == 1
88
+ assert rig.led("Ruling: 01 runs again (retry)", "It overturns the ruling leave-out of the driver.")
89
+ assert len(rig.final_calls("pr-writer")) == 2, "the pr-writer writes its part again for the tickets that landed"
90
+ (edit,) = gh(rig, ["pr", "edit"])
91
+ assert "- 01: " in edit["body"] and "Left out of the run" not in edit["body"]
92
+
93
+
94
+ def test_a_left_out_ticket_lands_only_its_own_commits_on_the_rewritten_branch(tmp_path):
95
+ rig = Inside(tmp_path, THREE)
96
+ steps = plan(**{"02/implementer": [blocked(), blocked()]})
97
+ rig.run(steps, *AUTONOMOUS)
98
+ assert rig.code == 0 and rig.state()["tickets"]["02"]["phase"] == "blocked", rig.output()
99
+ recovery, first = rig.final()["recovery"], rig.branch()
100
+ steps["02/implementer"].append(impl("02"))
101
+ rig.run(steps, *AUTONOMOUS, "--answer", "02-ticket-blocked-1=retry")
102
+ assert rig.code == 0 and rig.state()["tickets"]["02"]["phase"] == "merged", rig.output()
103
+ assert on_top(rig, first) and not on_top(rig, recovery), "no commit of the history before the tidy comes back"
104
+ assert rig.led("Ticket 02: merged into feat/csv as a fast-forward")
105
+ assert rig.led("Ticket 02: its own work is replayed onto")
106
+
107
+
108
+ def test_a_left_out_ticket_that_lands_after_a_ship_draft_gets_its_tip_reviewed_and_pushed(tmp_path):
109
+ rig = Inside(tmp_path, THREE)
110
+ steps = plan(**{"02/implementer": [blocked(), blocked()], "final/final-structure": [stopped(), stopped()]})
111
+ rig.run(steps, *AUTONOMOUS)
112
+ assert rig.code == 0 and rig.final()["ship"] and len(rig.prs()) == 1, rig.output()
113
+ first = rig.branch()
114
+ steps["02/implementer"].append(impl("02"))
115
+ steps["final/final-structure"].append(final())
116
+ rig.run(steps, *AUTONOMOUS, "--answer", "02-ticket-blocked-1=retry")
117
+ assert rig.code == 0 and rig.state()["tickets"]["02"]["phase"] == "merged", rig.output()
118
+ assert not rig.final()["ship"], "the draft ruling shipped the tip before the ticket landed"
119
+ assert rig.final()["reviewed"] == rig.branch() != first
120
+ assert rig.pushes()[-1] == f"refs/heads/feat/csv {rig.branch()}" and on_top(rig, first)
121
+
122
+
123
+ def test_a_ship_draft_overturned_to_retry_runs_the_failed_lens_again(tmp_path):
124
+ rig = rig_of(tmp_path)
125
+ steps = plan(**{"final/final-structure": [stopped(), stopped()]})
126
+ rig.run(steps, *AUTONOMOUS)
127
+ assert rig.code == 0 and len(rig.prs()) == 1, rig.out
128
+ rig.run(steps, *AUTONOMOUS, "--answer", "final-ticket-blocked-1=retry")
129
+ assert rig.code == 0, rig.out
130
+ assert len(rig.final_calls("final-structure")) == 3 and len(rig.prs()) == 1
131
+ assert rig.final()["reviewed"] == rig.branch()
132
+ assert rig.led("(retry)", "It overturns the ruling ship-draft of the driver.")
133
+ (edit,) = gh(rig, ["pr", "edit"])
134
+ assert "It overturns the ruling ship-draft of the driver." in edit["body"] and "--ready" not in edit["argv"]
135
+ assert rig.final()["draft"] and not gh(rig, ["pr", "ready"]), "the PR stays a draft: the operator readies it"
136
+
137
+
138
+ def test_an_overturn_of_an_answer_of_the_operator_exits_3_before_any_agent(tmp_path):
139
+ rig = rig_of(tmp_path)
140
+ steps = plan(**{"final/final-structure": [stopped(), stopped()]})
141
+ rig.run(steps, "--retries", "0", *UNATTENDED)
142
+ assert rig.code == 2, rig.out
143
+ rig.run(steps, "--answer", "final-ticket-blocked-1=ship-draft", *UNATTENDED)
144
+ assert rig.code == 0, rig.out
145
+ calls = len(rig.calls())
146
+ rig.run(steps, "--answer", "final-ticket-blocked-1=retry", *UNATTENDED)
147
+ assert rig.code == 3 and len(rig.calls()) == calls
148
+ assert ("--answer final-ticket-blocked-1=retry: you answered final-ticket-blocked-1: only a ruling of the driver "
149
+ "or the arbiter is overturned") in rig.out
150
+
151
+
152
+ # ---------------------------------------------------------------- the refusals, on a state.json of their own
153
+
154
+ def q(id, answer, ticket="final", kind="finding-open", stop=1, by="driver", subject="s (f.py)", **more):
155
+ options = {"finding-open": ["retry", "accept", "follow-up"], "finding-must-fix": ["retry", "accept", "follow-up"],
156
+ "ticket-blocked": ["retry", "ship-draft", "edit"],
157
+ "spec-ambiguous": ["keep-test", "correct-test", "leave-out", "edit-spec"]}[kind]
158
+ return {"id": id, "ticket": ticket, "kind": kind, "stop": stop, "answer": answer, "subject": subject,
159
+ "options": [{"id": option} for option in options], **({"by": by} if by else {}), **more}
160
+
161
+
162
+ def state(*questions, open=(), pr=None, phases=None):
163
+ return {"run": {"questions": list(questions),
164
+ "final": {"open": [{"title": t, "file": "f.py"} for t in open], "pr": pr}},
165
+ "tickets": {number: {"phase": phase} for number, phase in (phases or {}).items()}}
166
+
167
+
168
+ @pytest.mark.parametrize("asked, pair, why", [
169
+ (state(), ("zz", "retry"), "there is no question zz"),
170
+ (state(q("a", "accept", by=None)), ("a", "retry"),
171
+ "you answered a: only a ruling of the driver or the arbiter is overturned"),
172
+ (state(q("a", "accept", by="arbiter")), ("a", "nope"), "a offers retry, accept, follow-up"),
173
+ (state(q("a", "accept", by="arbiter")), ("a", "accept"), "a is answered accept already"),
174
+ (state(q("a", "retry", open=["s"])), ("a", "accept"),
175
+ "the retry of the driver ran: its work is on the branch, and an overturn undoes no work"),
176
+ (state(q("a", "retry", kind="finding-must-fix"), open=["s"]), ("a", "accept"),
177
+ "the retry of the driver ran: its work is on the branch, and an overturn undoes no work"),
178
+ (state(q("a", "ship-draft", kind="ticket-blocked")), ("a", "edit"),
179
+ "an overturn takes an option that lets the run go on: edit the spec or the ticket, then overturn a to an option "
180
+ "that runs the work again"),
181
+ (state(q("a", "accept", by="arbiter"), q("b", "retry", stop=2), open=["s"]), ("a", "retry"),
182
+ "a later stop of the end of run asked b: only the newest stop of the end of run is overturned"),
183
+ (state(q("a", "keep-test", ticket="01", kind="spec-ambiguous", by="arbiter"), phases={"01": "merged"}),
184
+ ("a", "correct-test"), "ticket 01 merged since: its work is on the PR branch"),
185
+ (state(q("a", "accept", by="arbiter"), open=["other"]), ("a", "retry"),
186
+ "the last review leaves the finding closed: no fix batch is due for it"),
187
+ (state(q("a", "ship-draft", kind="ticket-blocked", subject="the pr-writer: it reported BLOCKED",
188
+ role="pr-writer"), pr="https://pr"),
189
+ ("a", "retry"), "the PR is open, so the pr-writer does not run again: edit its body on GitHub"),
190
+ ])
191
+ def test_an_overturn_that_cannot_take_effect_is_refused_with_why(asked, pair, why):
192
+ assert driver_overturn.refusals([pair], asked) == [f"--answer {pair[0]}={pair[1]}: {why}"]
193
+
194
+
195
+ @pytest.mark.parametrize("asked, pair", [
196
+ (state(q("a", "accept", by="arbiter"), open=["s"]), ("a", "retry")),
197
+ (state(q("a", "accept", by="arbiter")), ("a", "follow-up")),
198
+ (state(q("a", "leave-out", ticket="01", kind="spec-ambiguous"), phases={"01": "blocked"}), ("a", "correct-test")),
199
+ (state(q("a", "ship-draft", kind="ticket-blocked", subject="the final-spec: x"), pr="https://pr"), ("a", "retry")),
200
+ ])
201
+ def test_an_overturn_that_takes_effect_is_not_refused(asked, pair, monkeypatch):
202
+ monkeypatch.setattr(driver_pr, "state", lambda url: "OPEN")
203
+ assert driver_overturn.refusals([pair], asked) == []
204
+
205
+
206
+ @pytest.mark.parametrize("pair, draft", [
207
+ (("a", "follow-up"), ""),
208
+ (("a", "retry"), ""),
209
+ (None, "a finding ships open: s (f.py:1)"),
210
+ ])
211
+ def test_an_agent_s_ship_overturned_is_the_operator_s_ruling_and_drafts_no_pr(pair, draft):
212
+ questions = [q("a", "accept", by="arbiter", resume={"phase": "final"})]
213
+ final = {"open": [{"title": "s", "file": "f.py", "line": 1}], "ship": None}
214
+ if pair:
215
+ driver_decisions.overturn(questions, dict([pair]))
216
+ assert driver_pr._draft(final, questions, []) == draft
217
+
218
+
219
+ def test_a_body_edit_that_fails_is_made_again_by_the_next_run(tmp_path):
220
+ rig, steps = open_after_batch(tmp_path, ATOMIC, [ruled((Q, "accept"))])
221
+ gh_path = tmp_path / "bin/gh"
222
+ down = 'if sys.argv[1:3] == ["pr", "edit"]:\n sys.exit("gh down")\n'
223
+ gh_path.write_text(GH.replace("log = Path", f"{down}log = Path", 1))
224
+ rig.run(steps, *AUTONOMOUS, "--answer", f"{Q}=follow-up")
225
+ assert rig.code != 0 and "gh pr edit failed: gh down" in rig.out, rig.out
226
+ gh_path.write_text(GH)
227
+ rig.run(steps, *AUTONOMOUS)
228
+ assert rig.code == 0, rig.out
229
+ (edit,) = gh(rig, ["pr", "edit"])
230
+ assert "Follow-up issue: https://github.example/issues/1" in edit["body"]
231
+ assert (rig.repo / ".agent/implement/final/pr-body.md").read_text() == edit["body"]
232
+
233
+
234
+ @pytest.mark.parametrize("shown", ["MERGED", "CLOSED"])
235
+ def test_an_overturn_once_the_pr_is_merged_or_closed_exits_3_before_any_agent(tmp_path, shown):
236
+ rig, steps = open_after_batch(tmp_path, ATOMIC, [ruled((Q, "accept"))])
237
+ (tmp_path / "gh-pr-state").write_text(f"{shown}\n")
238
+ calls = len(rig.calls())
239
+ rig.run(steps, *AUTONOMOUS, "--answer", f"{Q}=retry")
240
+ assert rig.code == 3 and len(rig.calls()) == calls and len(rig.pushes()) == 1
241
+ assert (f"--answer {Q}=retry: the PR https://github.example/pull/1 is {shown.lower()}: an overturn adds work to "
242
+ "an open PR only") in rig.out
243
+
244
+
245
+ @pytest.mark.parametrize("shown", ["MERGED", "CLOSED"])
246
+ def test_an_overturn_stopped_before_its_push_pushes_nothing_once_the_pr_is_merged_or_closed(tmp_path, shown,
247
+ monkeypatch):
248
+ rig, steps = open_after_batch(tmp_path, ATOMIC, [ruled((Q, "accept"))])
249
+ steps["final/fixer"].append(fixer(fn("02"), "write the ledger atomically"))
250
+ steps["final/final-reviewer"].append(final())
251
+ import driver_final
252
+
253
+ def killed(*_, **__):
254
+ raise SystemExit(137)
255
+
256
+ with monkeypatch.context() as patch:
257
+ patch.setattr(driver_final, "_push", killed)
258
+ with pytest.raises(SystemExit):
259
+ rig.run(steps, *AUTONOMOUS, "--answer", f"{Q}=retry")
260
+ (tmp_path / "gh-pr-state").write_text(f"{shown}\n")
261
+ rig.run(steps, *AUTONOMOUS)
262
+ assert rig.code == 1 and len(rig.pushes()) == 1 and not gh(rig, ["pr", "edit"]), rig.out
263
+ assert f"the PR https://github.example/pull/1 is {shown.lower()}: nothing goes out to it" in rig.out
264
+
265
+
266
+ def test_a_final_fixer_after_a_ticket_landed_late_keeps_that_ticket_s_locked_test_as_it_landed(tmp_path):
267
+ rig = Inside(tmp_path, THREE)
268
+ steps = plan(**{"02/implementer": [blocked(), blocked()]})
269
+ rig.run(steps, *AUTONOMOUS)
270
+ assert rig.code == 0 and rig.state()["tickets"]["02"]["phase"] == "blocked", rig.output()
271
+ steps["02/implementer"].append(impl("02"))
272
+ steps["final/fixer"] = [fixer(fn("02"), "repair the gate")]
273
+ rig.gate_conf(full={"subjects": ["feat(02): Quote fields"]}) # red on the commit the late ticket lands as
274
+ rig.run(steps, *AUTONOMOUS, "--answer", "02-ticket-blocked-1=retry")
275
+ assert rig.code == 0, rig.output()
276
+ assert len(rig.final_calls("fixer")) == 1 and rig.led("Fix batch of the integration gate: 1 commit"), rig.ledger()
277
+ assert rig.final()["locked"] == rig.state()["run"]["landed"][-1][1]
278
+ assert "def test_x" in subprocess.run(["git", "show", "feat/csv:tests/test_02.py"], cwd=rig.repo,
279
+ capture_output=True, text=True).stdout
280
+
281
+
282
+ QUOTE = "demo/quote.py"
283
+
284
+
285
+ def conflicted(tmp_path, conflict):
286
+ """Ticket 02 is left out, then overturned to `retry`: its work adds QUOTE, which the base the tidy moved onto
287
+ adds too, so its replay onto the rewritten branch conflicts. `conflict` is the conflict agent's steps."""
288
+ rig = Inside(tmp_path, THREE)
289
+ rig.move_base({QUOTE: "base = 1\n"})
290
+ steps = plan(**{"02/implementer": [blocked(), blocked(), impl("02", QUOTE)], "02/conflict": conflict})
291
+ rig.run(steps, *AUTONOMOUS)
292
+ assert rig.code == 0 and rig.state()["tickets"]["02"]["phase"] == "blocked", rig.output()
293
+ return rig, steps
294
+
295
+
296
+ RESOLVED = {"files": {QUOTE: "base = 1\n" + fn("02")}, "commit": "replay 02",
297
+ "report": {"status": "DONE", "commits": ["$SHA"], "files": [QUOTE], "concerns": []}}
298
+
299
+
300
+ def test_a_replay_that_conflicts_goes_to_the_conflict_agent_and_lands(tmp_path):
301
+ rig, steps = conflicted(tmp_path, [RESOLVED])
302
+ rig.run(steps, *AUTONOMOUS, "--answer", "02-ticket-blocked-1=retry")
303
+ assert rig.code == 0 and rig.state()["tickets"]["02"]["phase"] == "merged", rig.output()
304
+ (agent,) = rig.calls("02", "conflict")
305
+ assert "replayed onto the PR branch after the end of run rewrote it, is open in this worktree" in agent["prompt"]
306
+ shown = subprocess.run(["git", "show", f"feat/csv:{QUOTE}"], cwd=rig.repo, capture_output=True, text=True)
307
+ assert shown.stdout == "base = 1\n" + fn("02")
308
+ assert rig.led("Ticket 02: the conflict agent resolved the merge conflict in demo/quote.py")
309
+
310
+
311
+ def test_a_replay_whose_conflict_agent_stops_leaves_the_slot_clean_and_retry_runs_the_agent_again(tmp_path):
312
+ rig, steps = conflicted(tmp_path, [blocked(), blocked(), RESOLVED])
313
+ rig.run(steps, "--retries", "0", "--answer", "02-ticket-blocked-1=retry", *UNATTENDED)
314
+ assert rig.code == 2, rig.output()
315
+ (question,) = [q for q in rig.state()["run"]["questions"] if q["answer"] is None]
316
+ assert (question["id"], question["role"]) == ("02-ticket-blocked-2", "conflict")
317
+ entry = rig.state()["tickets"]["02"]
318
+ slot = rig.repo if entry["slot"] == 1 else rig.repo / f".agent/worktrees/slot-{entry['slot']}"
319
+ run = lambda *a: subprocess.run(["git", *a], cwd=slot, capture_output=True, text=True).stdout.strip()
320
+ assert run("status", "--porcelain") == "" and not run("rev-parse", "-q", "--verify", "CHERRY_PICK_HEAD")
321
+ assert "02" in run("for-each-ref", "--format=%(refname)", "--points-at", entry["tip"], "refs/heads"), \
322
+ "the ticket branch is back on its tip before the replay"
323
+ rig.run(steps, "--retries", "0", "--answer", "02-ticket-blocked-2=retry", *UNATTENDED)
324
+ assert rig.code == 0 and rig.state()["tickets"]["02"]["phase"] == "merged", rig.output()
325
+ assert len(rig.calls("02", "conflict")) == 3
326
+
327
+
328
+ def test_a_run_killed_in_a_replay_replays_again_and_keeps_the_ticket_s_work(tmp_path, monkeypatch):
329
+ rig, steps = conflicted(tmp_path, [RESOLVED])
330
+ import driver
331
+
332
+ def killed(*_, **__): # the driver dies while the conflict agent works: the ticket branch is on the PR tip
333
+ raise SystemExit(137)
334
+
335
+ with monkeypatch.context() as patch:
336
+ patch.setattr(driver, "_resolve_conflict", killed)
337
+ with pytest.raises(SystemExit):
338
+ rig.run(steps, *AUTONOMOUS, "--answer", "02-ticket-blocked-1=retry")
339
+ entry = rig.state()["tickets"]["02"]
340
+ slot = rig.repo if entry["slot"] == 1 else rig.repo / f".agent/worktrees/slot-{entry['slot']}"
341
+ subprocess.run(["git", "cherry-pick", "--abort"], cwd=slot, check=True) # the driver starts on no open change
342
+ rig.run(steps, *AUTONOMOUS)
343
+ assert rig.code == 0 and rig.state()["tickets"]["02"]["phase"] == "merged", rig.output()
344
+ assert len(rig.calls("02", "implementer")) == 3, "the ticket's work is not thrown away"
345
+ shown = subprocess.run(["git", "show", f"feat/csv:{QUOTE}"], cwd=rig.repo, capture_output=True, text=True)
346
+ assert shown.stdout == "base = 1\n" + fn("02")
347
+
348
+
349
+ def test_a_spec_ambiguous_leave_out_overturned_to_keep_test_runs_the_implementer_again_and_lands(tmp_path):
350
+ rig = Local(tmp_path, {**ONE, **SECOND})
351
+ steps = plan(**{"01/implementer": [disputes(), disputes(), impl("01")], "01/test-writer": [tw("01")],
352
+ "02/implementer": [impl("02", "demo/other.py")],
353
+ "01/reviewer": [ruling("code-wrong", "R3 says double quotes"), review("01")]})
354
+ rig.run(steps, "--no-ask", "--retries", "0")
355
+ assert rig.code == 0, rig.ledger()
356
+ (q,) = [q for q in rig.state()["run"]["questions"] if q["id"] == AMBIGUOUS]
357
+ assert q["answer"] == "leave-out" and rig.state()["tickets"]["02"]["phase"] == "merged"
358
+ rig.run(steps, "--no-ask", "--retries", "0", "--answer", f"{AMBIGUOUS}=keep-test")
359
+ assert rig.code == 0 and rig.state()["tickets"]["01"]["phase"] == "merged", rig.ledger()
360
+ assert len(rig.calls("01", "implementer")) == 3
361
+ assert rig.led("(keep-test)", "It overturns the ruling leave-out of the driver.")
362
+ assert rig.led("Ticket 01: its own work is replayed onto")
@@ -202,7 +202,7 @@ def test_reviewer_fields(world):
202
202
  def test_a_read_only_role_lists_no_commits_so_the_commits_it_reviewed_are_not_refused(world, role):
203
203
  # Issue #129: the final reviewer read `commits` as the commits under review, and each was refused as not new.
204
204
  shas, check, _ = world
205
- report = {"status": "DONE", "files": [], "concerns": [], "findings": [], "body": "b"}
205
+ report = {"status": "DONE", "files": [], "concerns": [], "findings": [], "body": "b", "rulings": []}
206
206
  template = "final-lens" if role in LENSES else role # the lenses share one prompt
207
207
  assert check(template, report, start=shas["impl"]) == []
208
208
  assert check(template, {**report, "commits": [shas["tests"], shas["impl"]]}, start=shas["impl"]) == []
@@ -1,6 +1,7 @@
1
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.
2
+ role on the other-provider entry of the `final-reviewer` list. A finding it leaves open asks `final-finding-open`, or
3
+ `final-finding-must-fix` for a critical or must-fix one: only a `retry` starts another batch and scoped review;
4
+ `accept` and `follow-up` ship the PR with it.
4
5
 
5
6
  In process, on the rig of test_tidy and test_lenses."""
6
7
  import json
@@ -28,7 +29,7 @@ def test_the_scoped_review_is_one_agent_on_the_other_provider_over_the_fix_batch
28
29
  assert [(f["title"], f["source"]) for f in findings_file(rig, 1)] == [("Q-ONE", "final-reviewer")]
29
30
 
30
31
 
31
- def test_a_must_fix_the_scoped_review_leaves_out_of_resolved_must_fix_asks_final_ticket_blocked(tmp_path):
32
+ def test_a_must_fix_the_scoped_review_leaves_out_of_resolved_must_fix_asks_final_finding_must_fix(tmp_path):
32
33
  rig = Inside(tmp_path, RISKY, MODELS)
33
34
  escaping = {**finding("quote escaping", file="csv.py", line=30), "basis": "regression"}
34
35
  batch = fixer(fn("02"), "escape quotes", ticket_of="02")
@@ -37,14 +38,14 @@ def test_a_must_fix_the_scoped_review_leaves_out_of_resolved_must_fix_asks_final
37
38
  "final/final-reviewer": [final()], "final/fixer": [batch]}))
38
39
  assert rig.code == 2, rig.out
39
40
  (question,) = decisions(rig)["questions"]
40
- assert question["id"] == Q and "quote escaping (csv.py:30)" in question["title"]
41
+ assert question["id"] == "final-finding-must-fix-1" and "quote escaping (csv.py)" in question["title"]
41
42
  assert len(rig.final_calls("final-reviewer")) == 1
42
43
 
43
44
 
44
45
  # ---------------------------------------------------------------- a finding open after the scoped review
45
46
 
46
47
  ATOMIC = finding("ledger write not atomic", file="ledger.py", line=12)
47
- Q = "final-ticket-blocked-1"
48
+ Q = "final-finding-open-1"
48
49
 
49
50
 
50
51
  def open_after_batch(tmp_path):
@@ -55,13 +56,14 @@ def open_after_batch(tmp_path):
55
56
  return rig.run(steps, *UNATTENDED), steps
56
57
 
57
58
 
58
- def test_a_finding_open_after_the_scoped_review_asks_one_final_ticket_blocked_and_pushes_nothing(tmp_path):
59
+ def test_a_finding_open_after_the_scoped_review_asks_one_finding_open_and_pushes_nothing(tmp_path):
59
60
  rig, _ = open_after_batch(tmp_path)
60
61
  assert rig.code == 2 and not rig.pushes() and not rig.prs(), rig.out
61
62
  (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")
63
+ assert question["id"] == Q and "ledger write not atomic (ledger.py)" in question["title"]
64
+ assert [o["id"] for o in question["options"]] == ["retry", "accept", "follow-up"]
65
+ assert question["recommended"] == "retry"
66
+ assert rig.led("End of run: the operator decides on 1 question of kind finding-open")
65
67
 
66
68
 
67
69
  def test_retry_on_an_open_final_finding_runs_one_more_fix_batch_and_one_scoped_review(tmp_path):
@@ -86,12 +88,13 @@ def test_with_retries_the_driver_runs_the_one_more_fix_batch_itself_and_pushes_w
86
88
  assert [len(rig.final_calls(role)) for role in LENSES] == [1, 1, 1]
87
89
 
88
90
 
89
- def test_edit_on_an_open_final_finding_keeps_the_end_of_run_blocked_and_runs_no_agent(tmp_path):
91
+ def test_the_operators_accept_on_an_open_final_finding_ships_it_ready_with_no_fix_batch_and_lists_the_ruling(tmp_path):
90
92
  rig, steps = open_after_batch(tmp_path)
91
- calls = len(rig.calls())
92
- rig.run(steps, "--answer", f"{Q}=edit", *UNATTENDED)
93
- assert rig.code == 1 and len(rig.calls()) == calls and not rig.pushes() and not rig.prs(), rig.out
94
- assert rig.led("End of run: BLOCKED at the operator keeps the end of run BLOCKED for an edit (edit)")
93
+ rig.run(steps, "--answer", f"{Q}=accept", *UNATTENDED)
94
+ assert rig.code == 0 and rig.pushes() and len(rig.final_calls("fixer")) == 1, rig.out
95
+ (pr,) = rig.prs()
96
+ assert "- Ruling: final ships with the finding open (accept): ledger write not atomic (ledger.py).\n" in pr["body"]
97
+ assert "--draft" not in pr["argv"] and not rig.final_calls("arbiter")
95
98
 
96
99
 
97
100
  # ---------------------------------------------------------------- the locked files
@@ -128,7 +131,7 @@ def test_a_run_of_an_older_driver_after_its_first_round_resumes_into_the_fix_bat
128
131
  (folder / "findings-0.json").write_text(json.dumps(old))
129
132
  before = len(rig.ledger())
130
133
 
131
- rig.run(steps, "--answer", f"{Q}=retry")
134
+ rig.run(steps, "--answer", "final-ticket-blocked-1=retry")
132
135
  assert rig.code == 0, rig.out
133
136
  assert [len(rig.final_calls(role)) for role in LENSES] == [1, 1, 1]
134
137
  assert len(rig.final_calls("fixer")) == 3 and len(rig.final_calls("final-reviewer")) == 1