@jesdi/skills 0.0.97 → 0.0.99

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.
@@ -0,0 +1,151 @@
1
+ """The arbiter: when the driver's own retries are spent on a finding the scoped review leaves open, one read-only
2
+ agent on another provider than the implementer rules `accept` or `follow-up` on it, and the PR opens: draft when a
3
+ critical finding stays open, ready otherwise. `--ask` (IMPLEMENT_SPEC_ASK=1, which conftest pins) asks the operator
4
+ instead.
5
+
6
+ In process, on the rig of test_scoped."""
7
+ import json
8
+
9
+ from test_final import GH, final, fixer, fn, risk_body, writer
10
+ from test_fixloop import inside # noqa: F401 (the autouse fixture puts the rig's CLIs on PATH)
11
+ from test_lenses import ASTRA, MODELS, OPUS, rig_of
12
+ from test_review import RISKY, fix, finding, review
13
+ from test_scoped import ATOMIC
14
+ from test_tidy import Inside
15
+ from test_stops import UNATTENDED, decisions, stage
16
+ from test_tidy import tools # noqa: F401 (tools is an autouse fixture)
17
+ from test_walk import plan
18
+
19
+ Q = "final-finding-open-1"
20
+ LEAK = finding("token logged in clear", severity="critical", file="auth.py", line=7)
21
+ ARBITER = {**MODELS, "arbiter": [OPUS, ASTRA]} # the implementer is on anthropic, so the arbiter runs on ASTRA
22
+
23
+
24
+ def ruled(*rulings):
25
+ """An arbiter step: one (question, ruling) pair per open question."""
26
+ return {"report": {"status": "DONE", "files": [], "concerns": [], "rulings": [
27
+ {"question": question, "ruling": ruling, "reason": f"why {ruling}", "cost": f"cost of {ruling}"}
28
+ for question, ruling in rulings]}}
29
+
30
+
31
+ def open_after_batch(tmp_path, found=ATOMIC, arbiter=(), *extra, **more):
32
+ """The scoped review after the one fix batch leaves `found` open, with no retry left for the driver."""
33
+ rig = rig_of(tmp_path, models=ARBITER)
34
+ steps = plan(**{"final/final-spec": [final(found)], "final/final-reviewer": [final(found)],
35
+ "final/fixer": [fixer(fn("02"), "fix it")], "final/arbiter": list(arbiter), **more})
36
+ return rig.run(steps, "--no-ask", "--retries", "0", *UNATTENDED, *extra), steps
37
+
38
+
39
+ def gh(rig, verb):
40
+ rows = [json.loads(line) for line in rig.gh_log.read_text().splitlines()] if rig.gh_log.exists() else []
41
+ return [row for row in rows if row["argv"][:2] == verb]
42
+
43
+
44
+ def test_the_arbiter_accepts_an_important_finding_and_the_pr_opens_ready_with_its_ruling(tmp_path):
45
+ rig, _ = open_after_batch(tmp_path, ATOMIC, [ruled((Q, "accept"))])
46
+ assert rig.code == 0 and rig.pushes(), rig.out
47
+ (arbiter,) = rig.final_calls("arbiter")
48
+ assert Q in arbiter["prompt"] and "findings-1.json" in arbiter["prompt"]
49
+ assert rig.led(f"End of run: arbiter ran on {ASTRA}")
50
+ (pr,) = rig.prs()
51
+ assert "--draft" not in pr["argv"]
52
+ line = ("Ruling: final ships with the finding open (accept): ledger write not atomic (ledger.py). Ruled by "
53
+ "the arbiter, not the operator: why accept. Cost if wrong: cost of accept.")
54
+ assert f"- {line}" in pr["body"] and line in (rig.repo / ".agent/implement/summary.md").read_text()
55
+ assert stage(rig) == {"stage": "implement", "status": "done", "draft": False, "decisions": 1}
56
+ assert len(rig.final_calls("fixer")) == 1, "an accepted finding gets no fix batch"
57
+
58
+
59
+ def test_an_accepted_critical_finding_opens_the_pr_as_draft(tmp_path):
60
+ rig, _ = open_after_batch(tmp_path, LEAK, [ruled(("final-finding-open-1", "accept"))])
61
+ assert rig.code == 0, rig.out
62
+ (pr,) = rig.prs()
63
+ assert "--draft" in pr["argv"] and stage(rig)["draft"] is True
64
+ assert rig.led("The PR of feat/csv into main is open as a draft: a critical or must-fix finding is open")
65
+
66
+
67
+ def test_a_follow_up_is_filed_as_an_issue_before_the_pr_and_the_pr_body_links_it(tmp_path):
68
+ rig, steps = open_after_batch(tmp_path, ATOMIC, [ruled((Q, "follow-up"))])
69
+ assert rig.code == 0, rig.out
70
+ (issue,) = gh(rig, ["issue", "create"])
71
+ assert issue["argv"][2:4] == ["--title", "ledger write not atomic (ledger.py)"]
72
+ assert "feat/csv" in issue["body"] and "why follow-up" in issue["body"]
73
+ (pr,) = rig.prs()
74
+ assert "(follow-up): ledger write not atomic (ledger.py)." in pr["body"]
75
+ assert "Follow-up issue: https://github.example/issues/1" in pr["body"]
76
+ assert "Follow-up issue: https://github.example/issues/1" in (rig.repo / ".agent/implement/summary.md").read_text()
77
+ rig.run(steps, "--no-ask", *UNATTENDED)
78
+ assert len(gh(rig, ["issue", "create"])) == 1, "a rerun files no second issue"
79
+
80
+
81
+ def test_a_local_run_without_push_files_no_issue(tmp_path):
82
+ rig = rig_of(tmp_path)
83
+ rig.run(plan(**{"final/final-spec": [final(ATOMIC)], "final/final-reviewer": [final(ATOMIC)],
84
+ "final/fixer": [fixer(fn("02"), "fix it")], "final/arbiter": [ruled((Q, "follow-up"))]}),
85
+ "--no-ask")
86
+ assert rig.code == 0 and not gh(rig, ["issue", "create"]) and not rig.prs(), rig.out
87
+ assert "(follow-up)" in (rig.repo / ".agent/implement/summary.md").read_text()
88
+
89
+
90
+ def test_the_arbiter_rules_only_after_the_retries_of_the_driver(tmp_path):
91
+ rig = rig_of(tmp_path)
92
+ steps = plan(**{"final/final-spec": [final(ATOMIC)], "final/final-reviewer": [final(ATOMIC), final(ATOMIC)],
93
+ "final/fixer": [fixer(fn("02"), "fix it"), fixer(fn("02"), "fix it again")],
94
+ "final/arbiter": [ruled(("final-finding-open-2", "accept"))]})
95
+ rig.run(steps, "--no-ask", "--retries", "1", *UNATTENDED)
96
+ assert rig.code == 0, rig.out
97
+ assert len(rig.final_calls("fixer")) == 2 and len(rig.final_calls("arbiter")) == 1
98
+ assert rig.led("Ruling: final runs again (retry)") and rig.led("Ruled by the arbiter")
99
+
100
+
101
+ def test_an_arbiter_that_fails_twice_leaves_the_question_to_the_operator(tmp_path):
102
+ rig, _ = open_after_batch(tmp_path, ATOMIC, [{"report": {"status": "DONE"}}] * 2)
103
+ assert rig.code == 2 and not rig.pushes(), rig.out
104
+ assert len(rig.final_calls("arbiter")) == 2
105
+ (question,) = decisions(rig)["questions"]
106
+ assert question["id"] == Q
107
+ assert rig.led("End of run: the arbiter could not rule, so the operator decides")
108
+
109
+
110
+ def test_an_arbiter_report_that_skips_a_question_is_rejected(tmp_path):
111
+ rig, _ = open_after_batch(tmp_path, ATOMIC, [ruled(), ruled((Q, "accept"))])
112
+ assert rig.code == 0, rig.out
113
+ first, _ = rig.led("End of run: arbiter ran on")
114
+ assert f"no ruling on {Q}" in first
115
+
116
+
117
+ def test_an_issue_filed_before_its_url_was_kept_is_found_again_and_not_filed_twice(tmp_path):
118
+ rig = rig_of(tmp_path, models=ARBITER)
119
+ gh_path = tmp_path / "bin/gh"
120
+ gh_path.write_text(GH.replace('log = Path', 'if sys.argv[1:3] == ["pr", "create"]:\n sys.exit("gh down")\nlog = Path', 1))
121
+ steps = plan(**{"final/final-spec": [final(ATOMIC)], "final/final-reviewer": [final(ATOMIC)],
122
+ "final/fixer": [fixer(fn("02"), "fix it")], "final/arbiter": [ruled((Q, "follow-up"))]})
123
+ rig.run(steps, "--no-ask", "--retries", "0", *UNATTENDED)
124
+ assert rig.code != 0 and len(gh(rig, ["issue", "create"])) == 1 and not rig.prs(), rig.out
125
+ state = rig.state() # as a run that stopped before state.json kept the URL leaves it
126
+ del next(q for q in state["run"]["questions"] if q["id"] == Q)["issue"]
127
+ (rig.repo / ".agent/implement/state.json").write_text(json.dumps(state))
128
+ gh_path.write_text(GH)
129
+ rig.run(steps, "--no-ask", *UNATTENDED)
130
+ assert rig.code == 0 and len(gh(rig, ["issue", "create"])) == 1, rig.out
131
+ (pr,) = rig.prs()
132
+ assert "Follow-up issue: https://github.example/issues/1" in pr["body"]
133
+
134
+
135
+ def test_a_pr_body_that_stays_invalid_files_no_follow_up_issue(tmp_path):
136
+ invalid = writer(risk_body("styles"))
137
+ rig, _ = open_after_batch(tmp_path, ATOMIC, [ruled((Q, "follow-up"))], **{"final/pr-writer": [invalid, invalid]})
138
+ assert rig.code != 0 and not gh(rig, ["issue", "create"]) and not rig.prs(), rig.out
139
+
140
+
141
+ def test_an_accepted_must_fix_finding_opens_the_pr_as_draft(tmp_path):
142
+ rig = Inside(tmp_path, RISKY, {**ARBITER})
143
+ escaping = {**finding("quote escaping", file="csv.py", line=30), "basis": "regression"}
144
+ batch = fixer(fn("02"), "escape quotes", ticket_of="02")
145
+ batch["report"]["addressed_must_fix"] = ["quote escaping (csv.py:30)"]
146
+ rig.run(plan(**{"02/reviewer": [review("02", [escaping])] * 3, "02/fixer": [fix("02", 1), fix("02", 2)],
147
+ "final/final-reviewer": [final()], "final/fixer": [batch],
148
+ "final/arbiter": [ruled((Q, "accept"))]}), "--no-ask", "--retries", "0", *UNATTENDED)
149
+ assert rig.code == 0, rig.out
150
+ (pr,) = rig.prs()
151
+ assert "--draft" in pr["argv"] and rig.led("open as a draft: a critical or must-fix finding is open: quote escaping")
@@ -13,7 +13,7 @@ RUN = SKILL / "run.sh"
13
13
  GIT = ["git", "-c", "user.name=t", "-c", "user.email=t@example.com", "-c", "commit.gpgsign=false"]
14
14
  TOOLS = ("sh", "uname", "dirname", "readlink", "git", "env", "mktemp", "curl", "tar", "gzip", "mv", "rm", "mkdir",
15
15
  "sha256sum", "shasum", "cat", "chmod", "ln", "date", "basename")
16
- ROLES = ("test-writer", "implementer", "reviewer", "fixer", "final-reviewer", "conflict", "pr-writer")
16
+ ROLES = ("test-writer", "implementer", "reviewer", "fixer", "final-reviewer", "conflict", "pr-writer", "arbiter")
17
17
  NONE = "None (can start immediately)"
18
18
 
19
19
 
@@ -182,7 +182,7 @@ def test_unattended_writes_the_stage_file_and_prints_no_question(tmp_path, capsy
182
182
  assert stage(rig) == {"stage": "implement", "status": "awaiting-review", "artifact": PAGE, "open_questions": 1}
183
183
  write_answers(rig, {Q1: "retry"})
184
184
  rig.run(steps(blocked(), blocked(), impl("01")), *UNATTENDED)
185
- assert rig.code == 0 and stage(rig) == {"stage": "implement", "status": "done"}, "no stage file of the earlier run stays"
185
+ assert rig.code == 0 and stage(rig) == {"stage": "implement", "status": "done", "draft": False, "decisions": 0}, "no stage file of the earlier run stays"
186
186
  assert "feat: 01 rows" in rig.pr_subjects()
187
187
 
188
188
 
@@ -454,8 +454,8 @@ def test_the_rerun_of_fix_round_2_wraps_to_the_first_implementer_entry(tmp_path)
454
454
  assert entries(rig, "01", "fixer") == [SONNET, OPUS_5_5, SONNET]
455
455
 
456
456
 
457
- def test_only_two_kinds_exist():
458
- assert list(driver_decisions.KINDS) == ["spec-ambiguous", "ticket-blocked"]
457
+ def test_only_three_kinds_exist():
458
+ assert list(driver_decisions.KINDS) == ["spec-ambiguous", "ticket-blocked", "finding-open"]
459
459
 
460
460
 
461
461
  # ---------------------------------------------------------------- a test-writer report; a question of a merged ticket
@@ -1032,7 +1032,7 @@ def test_the_preflight_asks_each_entry_once_and_drops_each_entry_whose_cli_fails
1032
1032
  models["implementer"][1] = "openai/gpt-6.1-sol@medium"
1033
1033
  models["final-reviewer"] = ["openai/gpt-astra@medium", "claude-opus-5-5@medium"]
1034
1034
  kept, errors, skipped = driver_agents.preflight(models)
1035
- assert errors == [] and len((bin_dir / "asked").read_text().splitlines()) == 5
1035
+ assert errors == [] and len((bin_dir / "asked").read_text().splitlines()) == 7
1036
1036
  assert kept["implementer"] == ["claude-sonnet-5-5@medium"] and kept["final-reviewer"] == ["claude-opus-5-5@medium"]
1037
1037
  assert kept["test-writer"] == ["claude-sonnet-5-5@medium"] and kept["reviewer"] == models["reviewer"]
1038
1038
  assert skipped == [
@@ -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>`, options `retry`, `accept` and
19
+ `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"}`.
@@ -36,7 +37,7 @@ import pytest
36
37
 
37
38
  from test_cli import SKILL, git, ticket
38
39
  from test_review import ASTRA, FABLE, HOOKED, ONE, OPUS, Review, finding, gate_rule, no_full_gate, review
39
- from test_stops import UNATTENDED, stage
40
+ from test_stops import DONE, UNATTENDED, stage
40
41
  from test_walk import fix, impl, plan
41
42
 
42
43
  SCOPED = HOOKED
@@ -81,9 +82,16 @@ for i, a in enumerate(argv[:-1]):
81
82
  body = argv[i + 1]
82
83
  if a in ("--body-file", "-F"):
83
84
  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")
85
+ log = Path(__file__).resolve().parent.parent / "gh.jsonl"
86
+ if argv[:2] == ["issue", "list"]: # an issue whose body has the searched marker, as `gh issue create` logged it
87
+ marker = argv[argv.index("--search") + 1].split('"')[1]
88
+ rows = [json.loads(line) for line in log.read_text().splitlines()] if log.exists() else []
89
+ print(next(("https://github.example/issues/1" for row in rows
90
+ if row["argv"][:2] == ["issue", "create"] and marker in row["body"]), ""))
91
+ sys.exit(0)
92
+ with log.open("a") as out:
93
+ out.write(json.dumps(dict(argv=argv, body=body)) + "\\n")
94
+ print("https://github.example/issues/1" if argv[:2] == ["issue", "create"] else "https://github.example/pull/1")
87
95
  """
88
96
  HOOK = '#!/bin/sh\nwhile read old new ref; do echo "$ref $new" >> "%s"; done\n'
89
97
 
@@ -317,7 +325,7 @@ def test_green_ticket_carries_cap_finding_into_required_final_fix(tmp_path):
317
325
  assert len(rig.final_calls("fixer")) == 1
318
326
 
319
327
 
320
- def test_unresolved_must_fix_cannot_be_accepted_or_published(tmp_path):
328
+ def test_unresolved_must_fix_asks_and_is_not_published_while_the_operator_is_asked(tmp_path):
321
329
  rig = Final(tmp_path, THREE, {"implementer": [OPUS, FABLE]})
322
330
  recurring = review("02", [{**finding("MERGED-QUOTING-REGRESSION"), "basis": "regression"}])
323
331
  batch = fixer(fn("02"), "attempt quoting fix", ticket_of="02")
@@ -330,7 +338,7 @@ def test_unresolved_must_fix_cannot_be_accepted_or_published(tmp_path):
330
338
 
331
339
  assert rig.code == 2, rig.output()
332
340
  (question,) = rig.state()["run"]["questions"]
333
- assert question["id"] == "final-ticket-blocked-1" and "MERGED-QUOTING-REGRESSION" in question["subject"]
341
+ assert question["id"] == "final-finding-open-1" and "MERGED-QUOTING-REGRESSION" in question["subject"]
334
342
  assert [item["title"] for item in rig.state()["run"]["final"]["open"]] == ["MERGED-QUOTING-REGRESSION"]
335
343
  assert not rig.pushes() and not rig.prs()
336
344
  rig.run(steps)
@@ -468,7 +476,7 @@ def test_unattended_with_everything_validated_pushes_once_opens_the_pr_and_write
468
476
  assert rig.pushes() == [f"refs/heads/feat/csv {tip}"] and ref(rig.origin, "refs/heads/feat/csv") == tip
469
477
  (pr,) = rig.prs()
470
478
  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"}
479
+ assert stage(rig) == DONE
472
480
 
473
481
 
474
482
  def test_unattended_with_a_blocked_ticket_pushes_nothing_and_exits_1(tmp_path):
@@ -604,7 +612,7 @@ def test_a_cached_body_that_no_longer_validates_is_rewritten_before_gh_pr_create
604
612
  steps = plan(**{"final/pr-writer": [writer(risk_body()), writer(risk_body())]})
605
613
  rig, _ = pushed_run(tmp_path, monkeypatch, steps, "claude", gh_fails=True)
606
614
  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"
615
+ cached = rig.repo / ".agent/implement/final/pr-writer-body.md"
608
616
  cached.write_text(cached.read_text().replace("touches: [docs]", "touches: [styles]"))
609
617
  (tmp_path / "bin/gh").write_text(GH)
610
618
  rig.rerun()
@@ -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()
@@ -202,7 +202,23 @@ 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"]) == []
209
+
210
+
211
+ def test_a_report_a_claude_agent_gave_as_its_answer_and_did_not_write_is_taken_from_its_log(tmp_path):
212
+ import driver_agents
213
+ report, log = tmp_path / "reviewer-0.json", tmp_path / "reviewer-0.log"
214
+ said = "Here is my report:\n```json\n{\"status\": \"DONE\", \"findings\": []}\n```"
215
+ log.write_text(json.dumps({"type": "assistant"}) + "\n" + json.dumps({"type": "result", "result": said}) + "\n")
216
+ driver_agents.settle_report(report)
217
+ assert json.loads(report.read_text()) == {"status": "DONE", "findings": []}
218
+ report.write_text('{"status": "BLOCKED"}') # a written report that parses stays
219
+ driver_agents.settle_report(report)
220
+ assert json.loads(report.read_text()) == {"status": "BLOCKED"}
221
+ report.unlink()
222
+ log.write_text("no json here\n")
223
+ driver_agents.settle_report(report)
224
+ assert not report.exists()
@@ -1,6 +1,6 @@
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`:
3
+ only a `retry` starts another batch and scoped review; `accept` and `follow-up` ship the PR with it.
4
4
 
5
5
  In process, on the rig of test_tidy and test_lenses."""
6
6
  import json
@@ -28,7 +28,7 @@ def test_the_scoped_review_is_one_agent_on_the_other_provider_over_the_fix_batch
28
28
  assert [(f["title"], f["source"]) for f in findings_file(rig, 1)] == [("Q-ONE", "final-reviewer")]
29
29
 
30
30
 
31
- def test_a_must_fix_the_scoped_review_leaves_out_of_resolved_must_fix_asks_final_ticket_blocked(tmp_path):
31
+ def test_a_must_fix_the_scoped_review_leaves_out_of_resolved_must_fix_asks_final_finding_open(tmp_path):
32
32
  rig = Inside(tmp_path, RISKY, MODELS)
33
33
  escaping = {**finding("quote escaping", file="csv.py", line=30), "basis": "regression"}
34
34
  batch = fixer(fn("02"), "escape quotes", ticket_of="02")
@@ -37,14 +37,14 @@ def test_a_must_fix_the_scoped_review_leaves_out_of_resolved_must_fix_asks_final
37
37
  "final/final-reviewer": [final()], "final/fixer": [batch]}))
38
38
  assert rig.code == 2, rig.out
39
39
  (question,) = decisions(rig)["questions"]
40
- assert question["id"] == Q and "quote escaping (csv.py:30)" in question["title"]
40
+ assert question["id"] == Q and "quote escaping (csv.py)" in question["title"]
41
41
  assert len(rig.final_calls("final-reviewer")) == 1
42
42
 
43
43
 
44
44
  # ---------------------------------------------------------------- a finding open after the scoped review
45
45
 
46
46
  ATOMIC = finding("ledger write not atomic", file="ledger.py", line=12)
47
- Q = "final-ticket-blocked-1"
47
+ Q = "final-finding-open-1"
48
48
 
49
49
 
50
50
  def open_after_batch(tmp_path):
@@ -55,13 +55,14 @@ def open_after_batch(tmp_path):
55
55
  return rig.run(steps, *UNATTENDED), steps
56
56
 
57
57
 
58
- def test_a_finding_open_after_the_scoped_review_asks_one_final_ticket_blocked_and_pushes_nothing(tmp_path):
58
+ def test_a_finding_open_after_the_scoped_review_asks_one_finding_open_and_pushes_nothing(tmp_path):
59
59
  rig, _ = open_after_batch(tmp_path)
60
60
  assert rig.code == 2 and not rig.pushes() and not rig.prs(), rig.out
61
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")
62
+ assert question["id"] == Q and "ledger write not atomic (ledger.py)" in question["title"]
63
+ assert [o["id"] for o in question["options"]] == ["retry", "accept", "follow-up"]
64
+ assert question["recommended"] == "retry"
65
+ assert rig.led("End of run: the operator decides on 1 question of kind finding-open")
65
66
 
66
67
 
67
68
  def test_retry_on_an_open_final_finding_runs_one_more_fix_batch_and_one_scoped_review(tmp_path):
@@ -75,12 +76,24 @@ def test_retry_on_an_open_final_finding_runs_one_more_fix_batch_and_one_scoped_r
75
76
  assert [len(rig.final_calls(role)) for role in LENSES] == [1, 1, 1]
76
77
 
77
78
 
78
- def test_edit_on_an_open_final_finding_keeps_the_end_of_run_blocked_and_runs_no_agent(tmp_path):
79
+ def test_with_retries_the_driver_runs_the_one_more_fix_batch_itself_and_pushes_with_its_ruling(tmp_path):
80
+ rig = rig_of(tmp_path)
81
+ steps = plan(**{"final/final-spec": [final(ATOMIC)], "final/final-reviewer": [final(ATOMIC), final()],
82
+ "final/fixer": [fixer(fn("02"), "fix the ledger"), fixer(fn("02"), "write the ledger atomically")]})
83
+ rig.run(steps, "--retries", "1", *UNATTENDED)
84
+ assert rig.code == 0 and rig.pushes() == [f"refs/heads/feat/csv {rig.branch()}"], rig.out
85
+ assert len(rig.final_calls("fixer")) == 2 and len(rig.final_calls("final-reviewer")) == 2
86
+ assert rig.led("Ruling: final runs again (retry)") and rig.led("Ruled by the driver, not the operator.")
87
+ assert [len(rig.final_calls(role)) for role in LENSES] == [1, 1, 1]
88
+
89
+
90
+ def test_accept_on_an_open_final_finding_ships_it_with_no_fix_batch_and_lists_the_operator_ruling(tmp_path):
79
91
  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)")
92
+ rig.run(steps, "--answer", f"{Q}=accept", *UNATTENDED)
93
+ assert rig.code == 0 and rig.pushes() and len(rig.final_calls("fixer")) == 1, rig.out
94
+ (pr,) = rig.prs()
95
+ assert "- Ruling: final ships with the finding open (accept): ledger write not atomic (ledger.py).\n" in pr["body"]
96
+ assert "--draft" not in pr["argv"] and not rig.final_calls("arbiter")
84
97
 
85
98
 
86
99
  # ---------------------------------------------------------------- the locked files
@@ -117,7 +130,7 @@ def test_a_run_of_an_older_driver_after_its_first_round_resumes_into_the_fix_bat
117
130
  (folder / "findings-0.json").write_text(json.dumps(old))
118
131
  before = len(rig.ledger())
119
132
 
120
- rig.run(steps, "--answer", f"{Q}=retry")
133
+ rig.run(steps, "--answer", "final-ticket-blocked-1=retry")
121
134
  assert rig.code == 0, rig.out
122
135
  assert [len(rig.final_calls(role)) for role in LENSES] == [1, 1, 1]
123
136
  assert len(rig.final_calls("fixer")) == 3 and len(rig.final_calls("final-reviewer")) == 1
@@ -40,6 +40,7 @@ from test_walk import impl, plan
40
40
 
41
41
  STOP = "no write access to fixtures/"
42
42
  UNATTENDED = ("--unattended", "--stage-json", ".agent/stage.json")
43
+ DONE = {"stage": "implement", "status": "done", "draft": False, "decisions": 0} # a ready PR, no ruling
43
44
  Q1 = "01-ticket-blocked-1"
44
45
  RULED = "Ruling: 01 runs again (retry)"
45
46
 
@@ -214,7 +215,7 @@ def test_unattended_rerun_with_a_submitted_answers_file_at_the_current_revision_
214
215
  assert rig.code == 0, rig.output()
215
216
  assert Q1 not in rig.out + rig.err and rig.led(RULED)
216
217
  assert len(rig.calls("01", "implementer")) == 3 and "feat: 01 rows" in rig.pr_subjects()
217
- assert stage(rig) == {"stage": "implement", "status": "done"}
218
+ assert stage(rig) == DONE
218
219
 
219
220
 
220
221
  def test_unattended_blocked_ticket_ends_with_stage_json_blocked_naming_it_and_exit_1(tmp_path):
@@ -223,3 +224,31 @@ def test_unattended_blocked_ticket_ends_with_stage_json_blocked_naming_it_and_ex
223
224
  rig.run(plan(**{"01/fixer": [fix("01", n) for n in (1, 2)]}), *UNATTENDED)
224
225
  assert rig.code == 1, rig.output()
225
226
  assert stage(rig) == {"stage": "implement", "status": "blocked", "blocked": ["01"]}
227
+
228
+
229
+ # ---------------------------------------------------------------- the driver rules (--retries)
230
+
231
+ def test_with_retries_the_driver_answers_retry_itself_and_lists_its_decision_at_the_end(tmp_path):
232
+ rig = Review(tmp_path, ONE).run(steps(blocked(), blocked(), impl("01")), "--retries", "2")
233
+ assert rig.code == 0, rig.output()
234
+ assert rig.led(RULED) and rig.led("Ruled by the driver, not the operator.")
235
+ assert len(rig.calls("01", "implementer")) == 3 and "feat: 01 rows" in rig.pr_subjects()
236
+ summary = (rig.repo / ".agent/implement/summary.md").read_text()
237
+ assert "| human stops | 0 |" in summary and "| stops the driver ruled on | 1 |" in summary
238
+ assert "Driver decisions, taken without the operator:\n- " + RULED in summary
239
+ assert not answers_file(rig).exists()
240
+
241
+
242
+ def test_after_the_retries_are_spent_the_next_stop_of_the_ticket_asks_the_operator(tmp_path):
243
+ rig = Review(tmp_path, ONE).run(steps(*[blocked()] * 6, impl("01")), "--retries", "2")
244
+ assert rig.code == 2, rig.output()
245
+ assert [q["id"] for q in decisions(rig)["questions"]] == ["01-ticket-blocked-3"]
246
+ assert len(rig.calls("01", "implementer")) == 6
247
+ assert "| human stops | 1 |" in (rig.repo / ".agent/implement/summary.md").read_text()
248
+
249
+
250
+ def test_the_driver_answers_only_a_recommended_retry():
251
+ import driver_decisions
252
+ ask = lambda id, recommended: {"id": id, "ticket": "01", "stop": 1, "answer": None, "recommended": recommended}
253
+ questions = [ask("a", "retry"), ask("b", "accept"), ask("c", "")]
254
+ assert driver_decisions.automatic(questions, 2) == {"a": "retry"}
@@ -21,7 +21,7 @@ from test_cli import git
21
21
  from test_final import FILES, FINAL_MODELS, RESOLVE, THREE, TITLES, final, fixer, fn, ref, stop_lines
22
22
  from test_fixloop import inside # noqa: F401 (the autouse fixture puts the rig's CLIs on PATH)
23
23
  from test_review import FABLE, ONE, finding
24
- from test_stops import UNATTENDED, decisions, stage
24
+ from test_stops import DONE, UNATTENDED, decisions, stage
25
25
  from test_walk import fix, plan, tw
26
26
 
27
27
 
@@ -344,7 +344,7 @@ def test_a_base_that_moved_with_no_conflict_is_rebased_onto_with_no_agent_and_on
344
344
  assert [p.name for p in (rig.repo / ".agent/implement/final").glob("gate-*.log")] == [f"gate-full-{rig.branch()[:7]}.log"]
345
345
  assert rig.final()["commits"] == {nn: row["sha"] for nn, row in zip(order, rows)}
346
346
  assert rig.final()["onto"] == base and f"Range: {base}..{rig.branch()}\n" in rig.final_calls("final-spec")[0]["prompt"]
347
- assert rig.pushes() == [f"refs/heads/feat/csv {rig.branch()}"] and stage(rig) == {"stage": "implement", "status": "done"}
347
+ assert rig.pushes() == [f"refs/heads/feat/csv {rig.branch()}"] and stage(rig) == DONE
348
348
 
349
349
 
350
350
  def test_a_resolved_rebase_keeps_ticket_messages_and_gates_only_the_final_tidied_tip(tmp_path):
@@ -470,7 +470,7 @@ def test_a_push_or_a_pr_that_fails_is_tried_again_and_nothing_is_sent_twice(tmp_
470
470
  calls = len(rig.calls())
471
471
  rig.run(plan(), *UNATTENDED)
472
472
  assert rig.code == 0 and len(rig.pushes()) == 1 and len(rig.prs()) == 1 and len(rig.calls()) == calls, rig.out
473
- assert stage(rig) == {"stage": "implement", "status": "done"} and rig.final()["pr"] == "https://github.example/pull/1"
473
+ assert stage(rig) == DONE and rig.final()["pr"] == "https://github.example/pull/1"
474
474
 
475
475
 
476
476
  def test_a_reviewed_tip_with_no_green_gate_record_is_not_pushed(tmp_path):
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
- "generatedAt": "2026-11-10T09:31:49.250Z",
3
+ "generatedAt": "2026-11-16T00:15:36.754Z",
4
4
  "skills": [
5
5
  {
6
6
  "name": "agents-wayfinder",
@@ -58,8 +58,8 @@
58
58
  },
59
59
  {
60
60
  "name": "implement-spec",
61
- "version": "0.1.59",
62
- "hash": "sha256-4537ddbf8e4b4139a79f12a8248b60e9c3a28760ed0e3a90b8480216fa6ada8a",
61
+ "version": "0.1.61",
62
+ "hash": "sha256-94886542aabc6729b225228693c4049ae7fc3241eedb37778fde9da6b2ed621d",
63
63
  "description": "Implement a specification in code."
64
64
  },
65
65
  {