@jesdi/skills 0.0.99 → 0.0.101

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 +8 -5
  3. package/skills/implement-spec/README.md +43 -19
  4. package/skills/implement-spec/SKILL.md +2 -0
  5. package/skills/implement-spec/driver.py +136 -30
  6. package/skills/implement-spec/driver_agents.py +13 -0
  7. package/skills/implement-spec/driver_arbiter.py +57 -11
  8. package/skills/implement-spec/driver_decisions.py +186 -49
  9. package/skills/implement-spec/driver_dispute.py +1 -1
  10. package/skills/implement-spec/driver_final.py +232 -242
  11. package/skills/implement-spec/driver_final_gate.py +152 -17
  12. package/skills/implement-spec/driver_gate.py +12 -0
  13. package/skills/implement-spec/driver_legacy.py +15 -2
  14. package/skills/implement-spec/driver_overturn.py +106 -0
  15. package/skills/implement-spec/driver_pr.py +286 -0
  16. package/skills/implement-spec/driver_report.py +9 -4
  17. package/skills/implement-spec/driver_review.py +10 -4
  18. package/skills/implement-spec/driver_run.py +33 -14
  19. package/skills/implement-spec/driver_slots.py +61 -11
  20. package/skills/implement-spec/driver_state.py +30 -16
  21. package/skills/implement-spec/driver_summary.py +10 -3
  22. package/skills/implement-spec/prompts/arbiter.md +8 -4
  23. package/skills/implement-spec/prompts/conflict.md +1 -1
  24. package/skills/implement-spec/prompts/pr-body.md +2 -1
  25. package/skills/implement-spec/recovery.md +4 -4
  26. package/skills/implement-spec/tests/conftest.py +1 -0
  27. package/skills/implement-spec/tests/test_arbiter.py +74 -17
  28. package/skills/implement-spec/tests/test_arbitration.py +1 -1
  29. package/skills/implement-spec/tests/test_decisions.py +30 -6
  30. package/skills/implement-spec/tests/test_driver.py +9 -1
  31. package/skills/implement-spec/tests/test_final.py +20 -3
  32. package/skills/implement-spec/tests/test_final_gate.py +144 -0
  33. package/skills/implement-spec/tests/test_fixloop.py +1 -1
  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_scoped.py +6 -5
  39. package/skills/implement-spec/tests/test_ship_draft.py +203 -0
  40. package/skills/implement-spec/tests/test_slots.py +29 -0
  41. package/skills/implement-spec/tests/test_state.py +4 -2
  42. package/skills/implement-spec/tests/test_stops.py +19 -4
  43. package/skills/implement-spec/tests/test_tidy.py +4 -2
  44. package/skills/implement-spec/tests/test_walk.py +1 -0
  45. package/skills-manifest.json +3 -3
@@ -59,7 +59,7 @@ def test_a_stop_prints_the_question_and_an_answer_is_applied_once(tmp_path, caps
59
59
 
60
60
  # The question is closed: its answer cannot be given again, and the old answers file is history.
61
61
  rig.run({}, "--answer", f"{Q1}=edit")
62
- assert rig.code == 3 and f"--answer {Q1}=edit: no open question {Q1}" in capsys.readouterr().out
62
+ assert rig.code == 3 and f"--answer {Q1}=edit: you answered {Q1}: only a ruling of the driver" in capsys.readouterr().out
63
63
  rig.run({})
64
64
  assert rig.code == 0 and not rig.led("ignored") and len(rig.led("Ruling")) == 1
65
65
 
@@ -67,7 +67,7 @@ def test_a_stop_prints_the_question_and_an_answer_is_applied_once(tmp_path, caps
67
67
  def test_an_answer_with_an_option_the_question_does_not_offer_exits_3(tmp_path, capsys):
68
68
  rig = stopped(tmp_path)
69
69
  rig.run(steps(blocked(), blocked(), impl("01")), "--answer", f"{Q1}=nope")
70
- assert rig.code == 3 and f"--answer {Q1}=nope: {Q1} offers retry, edit" in capsys.readouterr().out
70
+ assert rig.code == 3 and f"--answer {Q1}=nope: {Q1} offers retry, leave-out, edit" in capsys.readouterr().out
71
71
  assert not (rig.repo / driver_answers.FILE).exists()
72
72
 
73
73
 
@@ -305,7 +305,7 @@ def test_each_answer_is_checked_on_its_own_and_a_note_goes_with_its_question(one
305
305
  "The answer for 02-spec-ambiguous-1.note in .agent/implement-answers.json is ignored: there is "
306
306
  "no open question 02-spec-ambiguous-1."]
307
307
  found, (ignored,) = answers(one, answers={Q1: ["retry"], f"{Q1}.note": 5})
308
- assert found == {} and ignored.endswith("the question offers retry, edit.")
308
+ assert found == {} and ignored.endswith("the question offers retry, leave-out, edit.")
309
309
 
310
310
 
311
311
  def test_no_open_question_or_no_file_reads_nothing_and_given_writes_only_valid_answers(one):
@@ -383,7 +383,7 @@ def test_a_second_stop_blocks_the_ticket_with_one_ticket_blocked_question(tmp_pa
383
383
  assert rig.code == 2 and rig.state()["tickets"]["01"]["phase"] == "blocked", rig.ledger()
384
384
  (question,) = rig.state()["run"]["questions"]
385
385
  assert (question["id"], question["kind"], question["recommended"]) == (TB1, "ticket-blocked", "retry")
386
- assert [o["id"] for o in question["options"]] == ["retry", "edit"]
386
+ assert [o["id"] for o in question["options"]] == ["retry", "leave-out", "edit"]
387
387
  assert "implementer" in question["subject"] and NO_ACCESS in question["subject"]
388
388
  assert question["evidence"][0] == ".agent/implement/01/implementer-0.json"
389
389
  assert entries(rig, "01", "implementer") == [SONNET, OPUS_5_5]
@@ -454,8 +454,32 @@ 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_three_kinds_exist():
458
- assert list(driver_decisions.KINDS) == ["spec-ambiguous", "ticket-blocked", "finding-open"]
457
+ def test_only_four_kinds_exist():
458
+ assert list(driver_decisions.KINDS) == ["spec-ambiguous", "ticket-blocked", "finding-open", "finding-must-fix"]
459
+
460
+
461
+ def test_a_must_fix_finding_asks_its_own_kind_whose_ships_are_the_operators_only():
462
+ """No agent ships a critical or must-fix finding: it asks `finding-must-fix`, not the arbiter's `finding-open`."""
463
+ must_fix = driver_decisions.KINDS["finding-must-fix"]
464
+ assert list(must_fix.options) == ["retry", "accept", "follow-up"] and must_fix.recommended == "retry"
465
+ assert must_fix.options is driver_decisions.KINDS["finding-open"].options and "only you may" in must_fix.why
466
+ assert [q["kind"] for q in driver_decisions.arbitrated([
467
+ {"answer": None, "kind": kind, "ticket": "final", "stop": 1} for kind in driver_decisions.KINDS], 2)] == [
468
+ "spec-ambiguous", "finding-open"]
469
+ assert "critical" not in driver_decisions.KINDS["finding-open"].why
470
+ kind = driver_decisions.finding_kind
471
+ assert [kind({"severity": "critical"}), kind({"severity": "important", "must_fix": True}),
472
+ kind({"severity": "important"})] == ["finding-must-fix", "finding-must-fix", "finding-open"]
473
+
474
+
475
+ def test_one_stop_asks_questions_of_two_kinds_and_the_ledger_names_both():
476
+ run = {"stops": 0, "questions": []}
477
+ asked = [("finding-must-fix", "leak (auth.py)", None), ("finding-open", "slow (db.py)", None)]
478
+ driver_decisions.stop(run, "final", asked, ["findings-1.json"], driver_decisions.Resume("final"))
479
+ assert [(q["id"], q["stop"]) for q in run["questions"]] == [("final-finding-must-fix-1", 1),
480
+ ("final-finding-open-1", 1)]
481
+ assert driver_decisions.decides(asked) == ("the operator decides on 1 question of kind finding-must-fix and "
482
+ "1 question of kind finding-open")
459
483
 
460
484
 
461
485
  # ---------------------------------------------------------------- a test-writer report; a question of a merged ticket
@@ -962,12 +962,20 @@ def test_a_gate_that_changes_the_tree_or_moves_head_is_red(repo, tmp_path, capsy
962
962
  assert "by-the-gate" not in out_of("git", "log", "--format=%s", "feat/x")
963
963
 
964
964
 
965
- def test_a_merged_ticket_whose_commits_left_the_pr_branch_is_not_merged_on_a_rerun(repo, tmp_path, capsys):
965
+ @pytest.mark.parametrize("rerun_date", ["2026-01-01T00:00:00Z", "2026-01-01T00:00:09Z"])
966
+ def test_a_merged_ticket_whose_commits_left_the_pr_branch_is_not_merged_on_a_rerun(repo, tmp_path, capsys, monkeypatch,
967
+ rerun_date):
968
+ """With the first `rerun_date`, the rerun's implementer makes the very commit of the first run (same work, same
969
+ second, as on a fast machine): the recovery point of the tidy is then the ticket tip, and it still lands."""
966
970
  repo(t01=ticket("01", **REFACTOR))
967
971
  base = out_of("git", "rev-parse", "HEAD")
972
+ for name in ("GIT_AUTHOR_DATE", "GIT_COMMITTER_DATE"):
973
+ monkeypatch.setenv(name, "2026-01-01T00:00:00Z")
968
974
  assert walk(tmp_path, capsys, WORK + REPORT)[0] == 0
969
975
  tip = out_of("git", "rev-parse", "--short=7", "HEAD")
970
976
  subprocess.run(["git", "reset", "-q", "--hard", base], check=True) # the operator dropped the ticket's commits
977
+ for name in ("GIT_AUTHOR_DATE", "GIT_COMMITTER_DATE"):
978
+ monkeypatch.setenv(name, rerun_date)
971
979
  code, ledger, out = walk(tmp_path, capsys, WORK + REPORT)
972
980
  assert f"Ticket 01: returned to implement from the PR tip: the recorded tip {tip} is not in feat/x." in ledger
973
981
  assert ledger[-1].startswith("Ticket 01: merged into feat/x as a fast-forward at ")
@@ -15,8 +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-finding-open-<n>`, options `retry`, `accept` and
19
- `follow-up`.
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`.
20
20
  - local stop: stdout lines `Branch tip: <sha>`, `Reviewed tip: <sha>` and the rerun command, which has `--push`.
21
21
  - the PR body lists, per ticket, a line with the ticket number and its commit's first 7 hex, and every ruling line.
22
22
  - stage.json at a clean unattended end is `{"stage": "implement", "status": "done"}`.
@@ -35,6 +35,7 @@ from types import SimpleNamespace
35
35
 
36
36
  import pytest
37
37
 
38
+ import driver_final
38
39
  from test_cli import SKILL, git, ticket
39
40
  from test_review import ASTRA, FABLE, HOOKED, ONE, OPUS, Review, finding, gate_rule, no_full_gate, review
40
41
  from test_stops import DONE, UNATTENDED, stage
@@ -89,6 +90,10 @@ if argv[:2] == ["issue", "list"]: # an issue whose body has the searched marker
89
90
  print(next(("https://github.example/issues/1" for row in rows
90
91
  if row["argv"][:2] == ["issue", "create"] and marker in row["body"]), ""))
91
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)
92
97
  with log.open("a") as out:
93
98
  out.write(json.dumps(dict(argv=argv, body=body)) + "\\n")
94
99
  print("https://github.example/issues/1" if argv[:2] == ["issue", "create"] else "https://github.example/pull/1")
@@ -338,7 +343,7 @@ def test_unresolved_must_fix_asks_and_is_not_published_while_the_operator_is_ask
338
343
 
339
344
  assert rig.code == 2, rig.output()
340
345
  (question,) = rig.state()["run"]["questions"]
341
- assert question["id"] == "final-finding-open-1" and "MERGED-QUOTING-REGRESSION" in question["subject"]
346
+ assert question["id"] == "final-finding-must-fix-1" and "MERGED-QUOTING-REGRESSION" in question["subject"]
342
347
  assert [item["title"] for item in rig.state()["run"]["final"]["open"]] == ["MERGED-QUOTING-REGRESSION"]
343
348
  assert not rig.pushes() and not rig.prs()
344
349
  rig.run(steps)
@@ -675,3 +680,15 @@ def test_final_gate_repair_can_prove_no_code_change_but_still_spends_its_attempt
675
680
  assert [g['exit'] for g in rig.gates('full')] == [1, 0 if transient else 1]
676
681
  assert bool(rig.pushes()) == transient
677
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)")
@@ -153,3 +153,147 @@ def test_gate_repair_preserves_locked_tests_and_escalates_a_needed_correction(tm
153
153
  assert rig.final()["gate_repairs"] == 0 and not rig.pushes()
154
154
  assert rig.branch() == rig.final()["tidied"]
155
155
  assert rig.state()["tickets"]["01"]["phase"] == "merged"
156
+
157
+
158
+ # ---------------------------------------------------------------- the base gate: only new failures count
159
+
160
+ OLD, NEW = 'FAILED tests/test_old.py::test_y - AssertionError', 'FAILED tests/test_01.py::test_z - KeyError'
161
+
162
+
163
+ def test_a_red_gate_with_only_the_failures_of_the_base_goes_on_to_review_and_a_draft_pr(tmp_path, monkeypatch):
164
+ import driver_final_gate
165
+ import driver_slots
166
+ from test_final import final
167
+ from test_review import finding
168
+
169
+ rig = Inside(tmp_path)
170
+ tips = ['feat(01): Export rows', 'fix(01): review fix']
171
+ rig.gate_conf(full={'subjects': ['spec', *tips]}, print={subject: [OLD] for subject in ['spec', *tips]})
172
+ steps = plan(**{'final/final-spec': [final(finding('A REVIEW FINDING'))],
173
+ 'final/fixer': [fixer('review\n', 'review fix', ticket_of='01')]})
174
+ slot_1 = []
175
+ base_gate = driver_final_gate._run_base_gate
176
+ seen = lambda: (driver_slots.head('.'), driver_slots.on_branch('.'), driver_slots.git('.', 'status', '-s').stdout)
177
+
178
+ def watched(*args):
179
+ before = seen()
180
+ kept = base_gate(*args)
181
+ slot_1.append(before == seen())
182
+ return kept
183
+
184
+ monkeypatch.setattr(driver_final_gate, '_run_base_gate', watched)
185
+ rig.run(steps, '--push')
186
+ assert rig.code == 0, rig.output()
187
+ assert slot_1 == [True], 'the base gate leaves slot 1 on its branch, at its tip, with its status'
188
+ onto = rig.final()['onto']
189
+ base = [gate for gate in rig.gates('full') if gate['commit'] == onto]
190
+ assert len(base) == 1, 'the base gate runs once for both red tips'
191
+ assert base[0]['cwd'].endswith('.agent/worktrees/slot-base')
192
+ assert len(rig.final_calls('fixer')) == 1, 'only the review fix: no gate repair'
193
+ assert "not this change's to fix" in rig.final_calls('final-spec')[0]['prompt']
194
+ assert rig.final()['reviewed'] == rig.branch()
195
+ assert rig.pushes() == [f'refs/heads/feat/csv {rig.branch()}']
196
+ (pr,) = rig.prs()
197
+ assert '--draft' in pr['argv'], 'a match of failure lines is no proof: the operator readies the PR'
198
+ old = f"final/base/gate-full-{onto[:7]}.log"
199
+ assert f'only with failures that its base {onto[:7]} is red with too' in pr['body'] and old in pr['body']
200
+ assert rig.led(f'red on {rig.branch()[:7]} only with failures that its base {onto[:7]} is red with too', old,
201
+ 'the PR opens as a draft')
202
+ assert rig.led('is open as a draft: the full gate is red on')
203
+
204
+
205
+ def test_a_failure_the_base_lacks_goes_to_the_repair_with_the_base_record(tmp_path):
206
+ rig = Inside(tmp_path)
207
+ rig.gate_conf(full={'subjects': ['spec', 'feat(01): Export rows']},
208
+ print={'spec': [OLD], 'feat(01): Export rows': [OLD, NEW]})
209
+ rig.run(plan(**{'final/fixer': [fixer('fixed\n', 'repair integration', ticket_of='01')]}), '--push')
210
+ assert rig.code == 0, rig.output()
211
+ (repair,) = rig.final_calls('fixer')
212
+ assert f"final/base/gate-full-{rig.final()['onto'][:7]}.log" in repair['prompt']
213
+ assert '--draft' not in rig.prs()[0]['argv']
214
+
215
+
216
+ def test_a_red_tip_on_a_green_base_goes_to_the_repair(tmp_path):
217
+ rig = Inside(tmp_path)
218
+ rig.gate_conf(full={'subjects': ['feat(01): Export rows']}, print={'feat(01): Export rows': [OLD]})
219
+ rig.run(plan(**{'final/fixer': [fixer('fixed\n', 'repair integration', ticket_of='01')]}), '--push')
220
+ assert rig.code == 0, rig.output()
221
+ (repair,) = rig.final_calls('fixer')
222
+ assert 'is red too' not in repair['prompt']
223
+ assert rig.led(f"the full gate is green on the base {rig.final()['onto'][:7]}")
224
+ assert not rig.final()['gate_preexisting'] and '--draft' not in rig.prs()[0]['argv']
225
+
226
+
227
+ def test_a_base_gate_that_cannot_run_counts_each_failure_as_new(tmp_path):
228
+ rig = Inside(tmp_path)
229
+ (rig.repo / '.agent/worktrees').mkdir(parents=True, exist_ok=True)
230
+ (rig.repo / '.agent/worktrees/slot-base').write_text('not a worktree\n')
231
+ rig.gate_conf(full={'subjects': ['spec', 'feat(01): Export rows']},
232
+ print={'spec': [OLD], 'feat(01): Export rows': [OLD]})
233
+ rig.run(plan(**{'final/fixer': [fixer('fixed\n', 'repair integration', ticket_of='01')]}), '--push')
234
+ assert rig.code == 0, rig.output()
235
+ assert len(rig.final_calls('fixer')) == 1 and not rig.final()['gate_preexisting']
236
+ assert rig.led('the full gate cannot run on the base', 'so each failure counts as new')
237
+
238
+
239
+ def test_a_red_gate_with_no_failure_line_counts_as_new_and_runs_no_base_gate(tmp_path):
240
+ rig = Inside(tmp_path)
241
+ rig.gate_conf(full={'subjects': ['spec', 'feat(01): Export rows']})
242
+ rig.run(plan(**{'final/fixer': [fixer('fixed\n', 'repair integration', ticket_of='01')]}), '--push')
243
+ assert rig.code == 0, rig.output()
244
+ assert len(rig.final_calls('fixer')) == 1
245
+ assert not [gate for gate in rig.gates('full') if gate['commit'] == rig.final()['onto']]
246
+
247
+
248
+ def test_failures_are_the_failure_lines_of_the_output_with_times_line_numbers_and_counts_masked(tmp_path):
249
+ import driver_final_gate
250
+
251
+ def record(name, output, after='clean', end='exit: 1\nafter: {after}\nend: y\n'):
252
+ path = tmp_path / name
253
+ path.write_text(f'start: x\ntier: full\ncommit: abc\nstatus: clean\ncommand: make check\n\n{output}\n'
254
+ + end.format(after=after))
255
+ return str(path)
256
+
257
+ base = record('base', 'FAILED tests/a.py::test_1 - x\n== 1 failed, 40 passed in 2.31s ==\n'
258
+ 'src/a.ts:12:5 error no-x\nmake: *** [check] Error 1')
259
+ same = record('same', 'ok\nFAILED tests/a.py::test_1 - x\n== 1 failed, 52 passed in 3.1s ==\n'
260
+ 'src/a.ts:14:5 error no-x')
261
+ assert driver_final_gate.only_old(same, base), 'a wrapper line names no failure'
262
+ assert not driver_final_gate.only_old(record('new', 'FAILED tests/a.py::test_2 - x'), base)
263
+ assert not driver_final_gate.only_old(record('twice', 'src/a.ts:1:1 error no-x\nsrc/a.ts:2:1 error no-x'), base)
264
+ assert not driver_final_gate.only_old(record('none', 'Segmentation fault'), base)
265
+ assert not driver_final_gate.only_old(record('dirty', 'FAILED tests/a.py::test_1 - x', 'not clean'), base)
266
+ one = record('one', 'FAILED tests/a.py::test_limit[1] - x')
267
+ assert not driver_final_gate.only_old(record('two', 'FAILED tests/a.py::test_limit[2] - x'), one), \
268
+ 'a number in a test identifier is part of its name'
269
+ assert not driver_final_gate.only_old(record('fewer', 'FAILED tests/a.py::test_1 - x'), base), \
270
+ 'a new failure that no line names can hide behind the same lines: only the same failures are old'
271
+ wrapped = record('wrapped', 'make: *** [check] Error 1')
272
+ assert not driver_final_gate.only_old(wrapped, wrapped), 'a wrapper line alone proves nothing'
273
+ mocha = record('mocha', ' 2 failing\n 1) Suite does x:\n AssertionError: expected 1 to equal 2 (12ms)')
274
+ assert driver_final_gate.only_old(
275
+ record('mocha-2', ' 2 failing\n 1) Suite does x:\n AssertionError: expected 1 to equal 2 (40ms)'), mocha)
276
+ assert not driver_final_gate.only_old(
277
+ record('mocha-3', ' 2 failing\n 1) Suite does x:\n AssertionError: expected 1 to equal 3 (40ms)'), mocha)
278
+ assert not driver_final_gate.only_old(record('3-failing', ' 3 failing'), record('2-failing', ' 2 failing')), \
279
+ 'a count of failures stays'
280
+ titled = record('titled', ' 1 failing\n 1) Suite does x:\n AssertionError: expected 1 to equal 2')
281
+ assert not driver_final_gate.only_old(
282
+ record('retitled', ' 1 failing\n 1) Suite does y:\n AssertionError: expected 1 to equal 2'), titled), \
283
+ 'the title of a failed test names it'
284
+ for name, end in (('killed', 'exit: 137\nafter: clean\nend: y\n'), ('signal', 'exit: -9\nafter: clean\nend: y\n'),
285
+ ('segfault', 'exit: 139\nafter: clean\nend: y\n'), ('abort', 'exit: 134\nafter: clean\nend: y\n'),
286
+ ('cut', '')):
287
+ stopped = record(name, 'FAILED tests/a.py::test_1 - x', end=end)
288
+ assert not driver_final_gate.only_old(stopped, stopped), f'a {name} run judged nothing'
289
+ assert not driver_final_gate.only_old(same, stopped), f'a {name} base run judged nothing'
290
+
291
+
292
+ def test_read_gives_the_output_exit_and_after_of_a_gate_record(tmp_path):
293
+ import driver_gate
294
+
295
+ record = tmp_path / 'r.log'
296
+ record.write_text('start: x\ncommand: make\n\nline 1\n\nline 2\nexit: 2\nafter: not clean\n M a.py\nend: y\n')
297
+ assert driver_gate.read(record) == ('line 1\n\nline 2', 2, 'not clean\n M a.py')
298
+ record.write_text('start: x\ncommand: make\n\nline 1\n')
299
+ assert driver_gate.read(record) == ('line 1\n', '', '')
@@ -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")
@@ -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 "