@jesdi/skills 0.0.77 → 0.0.79

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 (74) hide show
  1. package/README.md +3 -2
  2. package/package.json +1 -1
  3. package/skills/implement-spec/ARCHITECTURE.md +102 -54
  4. package/skills/implement-spec/README.md +53 -51
  5. package/skills/implement-spec/SKILL.md +5 -6
  6. package/skills/implement-spec/driver.py +67 -153
  7. package/skills/implement-spec/driver_agents.py +75 -25
  8. package/skills/implement-spec/driver_decisions.py +92 -199
  9. package/skills/implement-spec/driver_dispute.py +189 -0
  10. package/skills/implement-spec/driver_final.py +196 -97
  11. package/skills/implement-spec/driver_fixloop.py +102 -192
  12. package/skills/implement-spec/driver_legacy.py +73 -5
  13. package/skills/implement-spec/driver_locked.py +186 -0
  14. package/skills/implement-spec/driver_merge.py +3 -48
  15. package/skills/implement-spec/driver_report.py +84 -64
  16. package/skills/implement-spec/driver_review.py +12 -119
  17. package/skills/implement-spec/driver_run.py +167 -130
  18. package/skills/implement-spec/driver_state.py +11 -9
  19. package/skills/implement-spec/models.json +0 -2
  20. package/skills/implement-spec/prompts/arbitration.md +34 -0
  21. package/skills/implement-spec/prompts/conflict.md +1 -0
  22. package/skills/implement-spec/prompts/correction.md +7 -4
  23. package/skills/implement-spec/prompts/elsewhere.md +6 -0
  24. package/skills/implement-spec/prompts/final-fixer.md +1 -1
  25. package/skills/implement-spec/prompts/final-lens.md +40 -0
  26. package/skills/implement-spec/prompts/final-reviewer.md +7 -7
  27. package/skills/implement-spec/prompts/fixer.md +2 -2
  28. package/skills/implement-spec/prompts/implementer.md +1 -1
  29. package/skills/implement-spec/prompts/lens-copy.md +1 -0
  30. package/skills/implement-spec/prompts/lens-correctness.md +8 -0
  31. package/skills/implement-spec/prompts/lens-spec.md +2 -0
  32. package/skills/implement-spec/prompts/lens-structure.md +2 -0
  33. package/skills/implement-spec/prompts/rebase-conflict.md +1 -0
  34. package/skills/implement-spec/prompts/rereview.md +0 -1
  35. package/skills/implement-spec/prompts/rerun.md +1 -1
  36. package/skills/implement-spec/prompts/reviewer.md +3 -6
  37. package/skills/implement-spec/prompts/ruled.md +3 -0
  38. package/skills/implement-spec/prompts/test-writer.md +4 -5
  39. package/skills/implement-spec/tests/test_agents.py +23 -22
  40. package/skills/implement-spec/tests/test_amendments.py +6 -48
  41. package/skills/implement-spec/tests/test_arbitration.py +314 -0
  42. package/skills/implement-spec/tests/test_cli.py +3 -3
  43. package/skills/implement-spec/tests/test_decisions.py +251 -374
  44. package/skills/implement-spec/tests/test_driver.py +22 -50
  45. package/skills/implement-spec/tests/test_final.py +45 -77
  46. package/skills/implement-spec/tests/test_fixloop.py +400 -633
  47. package/skills/implement-spec/tests/test_landing.py +23 -126
  48. package/skills/implement-spec/tests/test_lenses.py +217 -0
  49. package/skills/implement-spec/tests/test_merge.py +0 -43
  50. package/skills/implement-spec/tests/test_models.py +50 -1
  51. package/skills/implement-spec/tests/test_report.py +9 -23
  52. package/skills/implement-spec/tests/test_review.py +15 -153
  53. package/skills/implement-spec/tests/test_review_page.py +7 -3
  54. package/skills/implement-spec/tests/test_scoped.py +125 -0
  55. package/skills/implement-spec/tests/test_state.py +8 -3
  56. package/skills/implement-spec/tests/test_stops.py +43 -61
  57. package/skills/implement-spec/tests/test_tidy.py +77 -98
  58. package/skills/implement-spec/tests/test_walk.py +7 -6
  59. package/skills/review-page/SKILL.md +1 -1
  60. package/skills/test-prune/SKILL.md +7 -3
  61. package/skills/test-prune/prune_source.py +48 -0
  62. package/skills/test-prune/prune_strengthen.py +87 -2
  63. package/skills/test-prune/tests/test_prune_strengthen.py +93 -0
  64. package/skills/to-tickets/SKILL.md +1 -1
  65. package/skills-manifest.json +9 -9
  66. package/skills/implement-spec/prompts/corrected.md +0 -3
  67. package/skills/implement-spec/prompts/correctness.md +0 -42
  68. package/skills/implement-spec/prompts/final-scoped.md +0 -1
  69. package/skills/implement-spec/prompts/full-review.md +0 -2
  70. package/skills/implement-spec/prompts/overruled.md +0 -7
  71. package/skills/implement-spec/prompts/rejected.md +0 -1
  72. package/skills/implement-spec/prompts/restored-red.md +0 -3
  73. package/skills/implement-spec/prompts/restored.md +0 -3
  74. package/skills/implement-spec/prompts/stands.md +0 -2
@@ -1,23 +1,16 @@
1
- """Ticket 09 acceptance tests: locked tests are checked on the merge result; one driver per PR branch.
1
+ """Ticket 09 acceptance tests: the locked files of merged tickets on a ticket branch; one driver per PR branch.
2
2
 
3
- All through `sh run.sh --runner <script> --parallel 2` on the three-ticket fixture repository (the rigs of test_review
4
- and test_final), and through two worktrees of one fixture repository, on two PR branches, for the run lock. Tickets are ordered with signal
5
- files and with `wait_pr_moves`, never with a sleep.
3
+ All through `sh run.sh --runner <script> --parallel 2` on the three-ticket fixture repository (the rig of test_review),
4
+ and through two worktrees of one fixture repository, on two PR branches, for the run lock. Tickets are ordered with
5
+ signal files and with `wait_pr_moves`, never with a sleep.
6
6
 
7
- Interface choices (ticket 09):
8
- - a ticket that "does not land" ends the run with phase `blocked`; one ledger sentence names the ticket and
9
- `locked file changed: <path>`, and a `merged-locked-file` question (exit 2) names the path (issue #116); no commit of
10
- the ticket is on the PR branch. Whether a fix round ran before is free:
11
- each plan gives that ticket fixers that write no report.
7
+ Interface choices:
8
+ - a ticket agent whose commits change a locked file of a merged ticket is rejected naming the file; its rerun does the
9
+ same, so the ticket ends `blocked` with a `ticket-blocked` question (exit 2) and no commit of it on the PR branch.
12
10
  - an implementer "merges the PR branch" with the `git` hook of the fake runner: `git merge --no-edit feat/csv` in its
13
11
  slot, after `wait_pr_moves`, before it writes its files and commits.
14
12
  - a rejected test-writer report gets the usual one rerun: the second prompt is the first plus a note that names the
15
13
  file the report did not list.
16
- - check and ref move as one step: no black-box test can stop the driver between the two. The one window a test can
17
- hold open is the merge gate, which runs between the merge commit and the ref move. The gate of the first merge
18
- commit stays open until the reviewer of the other ticket ended, plus a bounded time for that ticket to reach its
19
- landing. Either order of the two landings is correct, and so is a driver that gives the stale merge commit up;
20
- a landing after the lock with the weakened file is not, and a landing that is lost is not.
21
14
  - a driver on another PR branch in another worktree runs its one ticket to exit 0 while the first driver runs, and
22
15
  changes no file and no ref of the first run. The lock of the same PR branch is in test_driver.
23
16
  - "never reported as an uncommitted change": no line of `git status --short` in either worktree has `lock` in it.
@@ -33,19 +26,13 @@ import pytest
33
26
  from driver_names import Names
34
27
 
35
28
  from test_cli import RUN, git, models_file, snapshot, three, ticket
36
- from test_final import Final
37
29
  from test_review import HOOKED, Review, cli
38
- from test_stops import UNATTENDED, blocked as contradicted
39
- from test_walk import GATE, Rig, impl, make_env, plan, tw
30
+ from test_stops import blocked
31
+ from test_walk import GATE, Rig, fix, impl, make_env, plan, tw
40
32
 
41
- T01, T03, SHARED = "tests/test_01.py", "tests/test_03.py", "tests/test_shared.py"
33
+ T01, T03 = "tests/test_01.py", "tests/test_03.py"
42
34
  LOCKED_01, LOCKED_03 = tw("01")["files"][T01], tw("03")["files"][T03]
43
35
  WEAK = "def test_x():\n assert True\n"
44
- # A test file of the repository's start. A weaker first test and a new last test merge with no conflict.
45
- SEED = ("def test_first():\n assert 1 + 1 == 2\n\n\n# one\n# two\n# three\n# four\n# five\n# six\n\n\n"
46
- "def test_last():\n assert 2 + 2 == 4\n")
47
- WEAK_SEED = SEED.replace("assert 1 + 1 == 2", "assert True")
48
- MORE_SEED = SEED + "\n\ndef test_more():\n assert 3 + 3 == 'x'\n"
49
36
  NO_REPORT = [{}, {}] # a fixer that writes no report: a fix round, when one starts, ends BLOCKED
50
37
 
51
38
 
@@ -70,21 +57,6 @@ def kept_out(rig, nn, codes=(1,)):
70
57
  assert not any(holds(rig, c["sha"]) for c in rig.calls(nn) if c["sha"])
71
58
 
72
59
 
73
- def refused(rig, nn, path):
74
- """The landing of ticket `nn` was refused for the locked file `path` of a merged ticket, with a question."""
75
- kept_out(rig, nn, codes=(2,))
76
- assert rig.led(nn, f"locked file changed: {path}"), rig.ledger()
77
- (question,) = [q for q in rig.state()["run"]["questions"] if q["answer"] is None]
78
- assert (question["id"], question["subject"]) == (f"{nn}-merged-locked-file-1", path)
79
-
80
-
81
- def restored(rig, nn, path):
82
- """The review of ticket `nn` found its change to the locked file `path` of a merged ticket, and the restore
83
- closed it."""
84
- return (rig.led(f"Ticket {nn}: critical finding of kind fixture from the driver at {path}:1")
85
- and rig.led(f"Ticket {nn}:", "the restore closes it"))
86
-
87
-
88
60
  def writer(nn, path, text, listed=True):
89
61
  """The test-writer of `nn` that also writes `path`, and lists it as locked or not."""
90
62
  step = tw(nn)
@@ -93,25 +65,6 @@ def writer(nn, path, text, listed=True):
93
65
  return step
94
66
 
95
67
 
96
- def seeded(rig):
97
- (rig.repo / SHARED).parent.mkdir()
98
- (rig.repo / SHARED).write_text(SEED)
99
- git(rig.repo, "add", "-A")
100
- git(rig.repo, "commit", "-q", "-m", "seed")
101
- return rig
102
-
103
-
104
- # ---------------------------------------------------------------- the implementer of a later ticket
105
-
106
- def test_an_implementer_that_weakens_the_locked_test_of_a_merged_ticket_lands_only_with_the_test_put_back(tmp_path):
107
- """The review finds the change and the driver restores the file; the gate stays green, so no correction runs."""
108
- rig = Final(tmp_path, three())
109
- weak = impl("02", files={"demo/export.py": "def fn_02():\n return '02'\n", T01: WEAK})
110
- rig.run(plan(**{"02/implementer": [weak], "02/fixer": NO_REPORT}), *UNATTENDED)
111
- assert rig.code == 0 and restored(rig, "02", T01), rig.output()
112
- assert len(rig.calls("02", "test-writer")) == 1 and on_pr(rig, T01) == LOCKED_01
113
-
114
-
115
68
  # ---------------------------------------------------------------- a ticket branch that takes the PR branch in
116
69
 
117
70
  def takes_in(*more):
@@ -128,28 +81,13 @@ def test_a_ticket_that_merged_the_pr_branch_into_itself_lands_with_the_tests_of_
128
81
  assert phase(rig, "03") == "merged" and on_pr(rig, T01) == LOCKED_01 and on_pr(rig, T03) == LOCKED_03
129
82
 
130
83
 
131
- def test_a_ticket_that_merged_the_pr_branch_and_deleted_a_locked_test_of_the_merged_ticket_lands_with_it_put_back(tmp_path):
84
+ def test_a_ticket_that_merged_the_pr_branch_and_deleted_a_locked_test_of_the_merged_ticket_is_rejected(tmp_path):
132
85
  rig = Review(tmp_path, three())
133
- rig.run(plan(**{"03/implementer": [takes_in(["rm", "-q", T01])], "03/fixer": NO_REPORT}))
134
- (call,) = rig.calls("03", "implementer")
86
+ rig.run(plan(**{"03/implementer": [takes_in(["rm", "-q", T01]), {}]}))
87
+ call = rig.calls("03", "implementer")[0]
135
88
  assert holds(rig, rig.sha("01", "implementer"), call["sha"]), "01 is in ticket/feat%2Fcsv/03"
136
- assert rig.code == 0 and restored(rig, "03", T01), rig.output()
137
- assert phase(rig, "01") == "merged" and on_pr(rig, T01) == LOCKED_01
138
-
139
-
140
- # ---------------------------------------------------------------- a file that no ticket had locked yet
141
-
142
- def test_a_ticket_that_weakened_a_test_file_before_a_ticket_locked_it_does_not_land_after_that_ticket(tmp_path):
143
- """03 passes its gate and starts its review while 01 runs; 01 then locks the file and merges first."""
144
- rig = seeded(Review(tmp_path, three()))
145
- weak = impl("03", files={"demo/cli.py": cli("three"), SHARED: WEAK_SEED})
146
- rig.run(plan(**{"01/test-writer": [writer("01", SHARED, MORE_SEED)],
147
- "01/implementer": [{**impl("01"), "wait": ["r3"]}],
148
- "03/implementer": [weak], "03/reviewer": [{"touch": ["r3"], "wait_pr_moves": True}],
149
- "03/fixer": NO_REPORT}))
150
- assert phase(rig, "01") == "merged" and SHARED in rig.state()["tickets"]["01"]["locked"], rig.output()
151
- refused(rig, "03", SHARED)
152
- assert on_pr(rig, SHARED) == MORE_SEED
89
+ assert rig.code == 2 and rig.led("Ticket 03: implementer ran on", f"locked file changed: {T01}"), rig.output()
90
+ assert phase(rig, "01") == "merged" and phase(rig, "03") == "blocked" and on_pr(rig, T01) == LOCKED_01
153
91
 
154
92
 
155
93
  # ---------------------------------------------------------------- the test-writer of a later ticket
@@ -176,7 +114,7 @@ def test_a_test_writer_that_changes_a_locked_file_of_a_merged_ticket_and_does_no
176
114
  assert rig.code == 0, rig.output()
177
115
  assert phase(rig, "02") == "merged" and on_pr(rig, T01) == two and not rig.led("locked file changed")
178
116
  else:
179
- assert rig.code == 1, rig.output()
117
+ assert rig.code == 2, rig.output()
180
118
  assert rig.led("02", "BLOCKED", T01) and phase(rig, "02") == "blocked"
181
119
  assert not rig.calls("02", "implementer") and on_pr(rig, T01) == LOCKED_01
182
120
 
@@ -192,60 +130,19 @@ def test_a_conflict_resolution_lands_only_when_it_leaves_the_locked_files_of_the
192
130
  rig = Review(tmp_path, three()).run(plan(**{
193
131
  "01/test-writer": [{**tw("01"), "touch": ["s1"]}],
194
132
  "03/implementer": [{**impl("03", "demo/cli.py", cli("three")), "wait": ["s1"]}],
195
- "01/implementer": [{**one, "wait_pr_moves": True}], "01/conflict": [resolve]}))
196
- assert len(rig.calls("01", "conflict")) == 1 and phase(rig, "03") == "merged", rig.output()
133
+ "01/implementer": [{**one, "wait_pr_moves": True}], "01/conflict": [resolve, resolve]}))
134
+ assert len(rig.calls("01", "conflict")) == 1 + changes and phase(rig, "03") == "merged", rig.output()
197
135
  assert on_pr(rig, T03) == LOCKED_03
198
136
  if changes:
199
- refused(rig, "01", T03)
137
+ kept_out(rig, "01", codes=(2,))
138
+ (question,) = rig.state()["run"]["questions"]
139
+ assert question["kind"] == "ticket-blocked" and f"locked file changed: {T03}" in question["subject"]
200
140
  assert on_pr(rig, "demo/cli.py") == cli("three") and not rig.calls("02")
201
141
  else:
202
142
  assert rig.code == 0, rig.output()
203
143
  assert on_pr(rig, "demo/cli.py") == cli("resolved") and not rig.led("locked file changed")
204
144
 
205
145
 
206
- # ---------------------------------------------------------------- the check and the ref move are one step
207
-
208
- # The gate of test_walk. The gate of the first merge commit stays open until the call `hold` ended, and 1 s more.
209
- HELD = GATE.replace('print("GATE-OUTPUT-MARK"', '''def ended():
210
- calls = [json.loads(p.read_text()) for p in (rig / "calls").glob("*.json")]
211
- return any(c["key"] == conf["hold"] and "t1" in c for c in calls)
212
- merge = len(git("rev-list", "--parents", "-n1", "HEAD").split()) == 3
213
- if conf.get("hold") and merge and not (rig / "sig/held").exists():
214
- (rig / "sig/held").touch()
215
- end = time.time() + 30
216
- while not ended() and time.time() < end:
217
- time.sleep(0.02)
218
- time.sleep(1) # not an order: the time the other ticket gets to try its landing in the open window
219
- rec["held"] = ended()
220
- print("GATE-OUTPUT-MARK"''', 1)
221
- assert HELD.count("sig/held") == 2
222
-
223
-
224
- def landed(rig, sha):
225
- """The place, in the first-parent history the walk made, of the first PR commit that holds `sha`."""
226
- line = git(rig.repo, "rev-list", "--first-parent", "--reverse", rig.walked()).split()
227
- return next(i for i, commit in enumerate(line) if holds(rig, sha, commit))
228
-
229
-
230
- def test_a_ticket_that_lands_while_the_merge_gate_of_another_is_open_does_not_let_that_one_land_unchecked(tmp_path):
231
- """03 weakens a file that 02 locks. 03 is at its merge gate (after any check on its merge commit, before the ref
232
- move) when 02 passes its review and wants to land."""
233
- rig = seeded(Review(tmp_path, three()))
234
- (rig.rig / "gate").write_text(HELD)
235
- rig.gate_conf(hold="02/reviewer")
236
- weak = impl("03", files={"demo/cli.py": cli("three"), SHARED: WEAK_SEED})
237
- rig.run(plan(**{"02/test-writer": [writer("02", SHARED, MORE_SEED)],
238
- "03/implementer": [{**weak, "wait_pr_moves": True}], "03/fixer": NO_REPORT}))
239
- assert [g for g in rig.gates() if g.get("held")], "the merge gate of 03 was open while 02 ended its review"
240
- assert phase(rig, "02") == "merged" and "test_more" in on_pr(rig, SHARED), rig.output()
241
- if phase(rig, "03") == "merged": # 03 landed first, when no merged ticket had locked the file
242
- assert rig.code == 0, rig.output()
243
- assert landed(rig, rig.sha("03", "implementer")) < landed(rig, rig.sha("02", "test-writer")), rig.ledger()
244
- else: # 02 landed in the window: the driver looked again (a question), or it gave the stale merge commit up
245
- kept_out(rig, "03", codes=(1, 2))
246
- assert on_pr(rig, SHARED) == MORE_SEED
247
-
248
-
249
146
  # ---------------------------------------------------------------- one driver for each repository
250
147
 
251
148
  OTHER = {"04/test-writer": [tw("04")], "04/implementer": [impl("04", "demo/other.py")]}
@@ -340,8 +237,8 @@ def test_a_driver_on_another_pr_branch_in_another_worktree_runs_while_the_first_
340
237
 
341
238
  ENDS = {
342
239
  0: (plan(), {}, ()),
343
- 1: (plan(), {"red": ["ticket/feat%2Fcsv/01"]}, ()),
344
- 2: (plan(**{"01/implementer": [contradicted()]}), {}, ()),
240
+ 1: (plan(**{"01/fixer": [fix("01", n) for n in (1, 2)]}), {"red": ["ticket/feat%2Fcsv/01"]}, ()),
241
+ 2: (plan(**{"01/implementer": [blocked(), blocked()]}), {}, ()),
345
242
  3: (plan(), {}, ("--prepare", "false")), # slot 2 cannot be made: the run has started and holds the lock
346
243
  130: (plan(**{"01/test-writer": [{**tw("01"), "wait": ["never"]}]}), {}, ()),
347
244
  }
@@ -0,0 +1,217 @@
1
+ """Fewer roles, ticket 03: the final review runs three lenses, `final-spec`, `final-correctness` and
2
+ `final-structure`, at the same time in slot 1, and merges their findings into one `findings-0.json`.
3
+
4
+ In process, on the rig of test_tidy. A lens the plan does not script reports no findings."""
5
+ import json
6
+
7
+ import pytest
8
+
9
+ import driver_final
10
+ from test_final import Final, final, fixer, fn
11
+ from test_fixloop import inside # noqa: F401 (the autouse fixture puts the rig's CLIs on PATH)
12
+ from test_review import RISKY, finding, fix, review
13
+ from test_tidy import Inside, tools # noqa: F401 (tools is an autouse fixture)
14
+ from test_cli import ticket
15
+ from test_walk import plan
16
+
17
+ SONNET, OPUS, ASTRA = "claude-sonnet-5-5@medium", "claude-opus-5-5@medium", "openai/gpt-6-astra@medium"
18
+ MODELS = {"implementer": [SONNET], "final-reviewer": [OPUS, ASTRA]}
19
+ TWO = {"01-export-rows.md": ticket("01", "Export rows"), "02-cli-flag.md": ticket("02", "CLI flag")}
20
+ LENSES = ("final-spec", "final-correctness", "final-structure")
21
+
22
+
23
+ def rig_of(tmp_path, files=TWO, models=MODELS):
24
+ return Inside(tmp_path, files, models)
25
+
26
+
27
+ def findings_file(rig, k=0):
28
+ return json.loads((rig.repo / f".agent/implement/final/findings-{k}.json").read_text())
29
+
30
+
31
+ def stopped(status="BLOCKED"):
32
+ return {"report": dict(status=status, commits=[], files=[], concerns=["cannot read the spec"], findings=[])}
33
+
34
+
35
+ # ---------------------------------------------------------------- the cast and its input
36
+
37
+ @pytest.fixture(scope="module")
38
+ def clean(tmp_path_factory):
39
+ """Two merged tickets and a clean final review: no lens reports a critical or important finding. A module
40
+ fixture runs before the autouse fixtures put the rig's CLIs on PATH, so this rig runs the driver as a subprocess."""
41
+ rig = Final(tmp_path_factory.mktemp("clean"), TWO, MODELS)
42
+ return rig.run(plan(**{"final/final-structure": [final(finding("NAMING", "minor"))]}))
43
+
44
+
45
+ def test_spec_and_structure_run_on_the_first_final_reviewer_entry_and_correctness_on_the_other_provider(clean):
46
+ assert clean.code == 0, clean.out
47
+ assert clean.led("End of run: final-spec ran on", OPUS) and clean.led("End of run: final-structure ran on", OPUS)
48
+ assert clean.led("End of run: final-correctness ran on", ASTRA)
49
+ assert not clean.led("final-correctness ran on", OPUS) and not clean.final_calls("final-reviewer")
50
+
51
+
52
+ def test_each_lens_gets_the_gate_record_of_the_tip_writes_its_own_report_and_names_no_other_report(clean):
53
+ tip, folder = clean.state()["run"]["final"]["tidied"], clean.repo / ".agent/implement/final"
54
+ for role in LENSES:
55
+ (call,) = clean.final_calls(role)
56
+ assert call["head"] == tip and f"final/gate-full-{tip[:7]}.log" in call["prompt"]
57
+ assert (folder / f"{role}-0.json").is_file()
58
+ assert [other for other in LENSES if other != role and f"{other}-0" in call["prompt"]] == []
59
+ assert "<checks>\n# Correctness reviewer" in clean.final_calls("final-correctness")[0]["prompt"]
60
+ assert "review-diff/spec.md" in clean.final_calls("final-spec")[0]["prompt"]
61
+ assert "deep-quality-review/SKILL.md" in clean.final_calls("final-structure")[0]["prompt"]
62
+
63
+
64
+ def test_a_clean_final_review_runs_no_fix_batch_and_no_scoped_review(clean):
65
+ final_ = clean.state()["run"]["final"]
66
+ assert not clean.final_calls("fixer") and not clean.final_calls("final-reviewer")
67
+ assert final_["reviewed"] == final_["tidied"] == clean.branch() and final_["open"] == []
68
+ assert [(f["title"], f["source"]) for f in findings_file(clean)] == [("NAMING", "structure")]
69
+
70
+
71
+ def test_the_summary_counts_each_lens_under_its_role_and_has_no_correctness_row(clean):
72
+ summary = (clean.repo / ".agent/implement/summary.md").read_text()
73
+ assert f"| agents, final-spec on {OPUS} | 1 |" in summary
74
+ assert f"| agents, final-correctness on {ASTRA} | 1 |" in summary
75
+ assert f"| agents, final-structure on {OPUS} | 1 |" in summary
76
+ assert "agents, correctness" not in summary
77
+
78
+
79
+ # ---------------------------------------------------------------- input validation
80
+
81
+ def test_a_final_reviewer_list_with_no_entry_on_another_provider_exits_3_before_any_agent(tmp_path):
82
+ rig = rig_of(tmp_path, models={"implementer": [SONNET], "final-reviewer": [OPUS]}).run(plan())
83
+ assert rig.code == 3 and not rig.calls(), rig.out
84
+ assert rig.out == (f"final-reviewer: no entry of its list ({OPUS}) is on another provider than the implementer's "
85
+ f"first entry {SONNET}; its other-provider entry serves the correctness lens of the final "
86
+ "review and the scoped review, which never run on the implementer's provider\n")
87
+
88
+
89
+ def test_without_the_deep_quality_review_skill_the_run_exits_3_before_any_agent(tmp_path, monkeypatch):
90
+ installed = driver_final._installed
91
+ monkeypatch.setattr(driver_final, "_installed", lambda name: None if name == "deep-quality-review" else installed(name))
92
+ rig = rig_of(tmp_path).run(plan())
93
+ assert rig.code == 3 and not rig.calls(), rig.out
94
+ assert rig.out == ("the deep-quality-review skill is missing its SKILL.md: the structure lens of the final review "
95
+ "follows it; install it next to implement-spec with `npx skills add jesdi/general-skills --skill "
96
+ "deep-quality-review`\n")
97
+
98
+
99
+ # ---------------------------------------------------------------- the merge
100
+
101
+ def test_the_lens_findings_merge_into_one_file_and_the_critical_and_important_ones_go_to_the_fix_batch(tmp_path):
102
+ rig = rig_of(tmp_path)
103
+ flag = finding("missing --dry-run flag", file="cli.py", line=40)
104
+ atomic = finding("ledger write not atomic", "critical", file="ledger.py", line=12)
105
+ rig.run(plan(**{"final/final-spec": [final(flag)], "final/final-correctness": [final(atomic)],
106
+ "final/final-structure": [final({**atomic, "severity": "important"}, finding("LONG", "minor"))],
107
+ "final/fixer": [fixer(fn("02"), "fix the flag and the ledger")]}))
108
+ assert rig.code == 0, rig.out
109
+ found = findings_file(rig)
110
+ assert [(f["title"], f["severity"], f["source"]) for f in found] == [
111
+ ("missing --dry-run flag", "important", "spec"), ("ledger write not atomic", "critical", "correctness"),
112
+ ("LONG", "minor", "structure")]
113
+ batch = rig.final_calls("fixer")[0]["prompt"]
114
+ assert "important: missing --dry-run flag (cli.py:40)" in batch and "critical: ledger write not atomic" in batch
115
+ assert not [line for line in batch.splitlines() if "LONG" in line]
116
+ assert rig.led("important finding of kind code from spec at cli.py:40: missing --dry-run flag")
117
+ assert rig.led("critical finding of kind code from correctness at ledger.py:12: ledger write not atomic")
118
+ assert rig.led("minor finding of kind code from structure at demo/export.py:99: LONG")
119
+ assert len(rig.final_calls("final-reviewer")) == 1, "one scoped review"
120
+
121
+
122
+ def test_a_tie_keeps_the_earlier_lens():
123
+ one = finding("same", file="a.py", line=1)
124
+ merged = driver_final._merged([{**one, "source": "spec"}, {**one, "source": "structure"},
125
+ {**one, "line": 2, "source": "structure"}])
126
+ assert [(f["line"], f["source"]) for f in merged] == [(1, "spec"), (2, "structure")]
127
+
128
+
129
+ def test_a_must_fix_finding_reaches_every_lens_and_the_fix_batch(tmp_path):
130
+ rig = Inside(tmp_path, RISKY, MODELS)
131
+ escaping = {**finding("quote escaping", file="csv.py", line=30), "basis": "regression"}
132
+ title = "quote escaping (csv.py:30)"
133
+ scoped = final()
134
+ scoped["report"]["resolved_must_fix"] = [title]
135
+ batch = fixer(fn("02"), "escape quotes", ticket_of="02")
136
+ batch["report"]["addressed_must_fix"] = [title]
137
+ rig.run(plan(**{"02/reviewer": [review("02", [escaping])] * 3, "02/fixer": [fix("02", 1), fix("02", 2)],
138
+ "final/final-correctness": [final({**escaping, "severity": "critical"})],
139
+ "final/final-reviewer": [scoped], "final/fixer": [batch]}))
140
+ assert rig.code == 0, rig.out
141
+ assert all(title in rig.final_calls(role)[0]["prompt"] for role in LENSES)
142
+ assert title in rig.final_calls("fixer")[0]["prompt"]
143
+ (found,) = findings_file(rig)
144
+ assert (found["must_fix"], found["ticket"], found["source"]) == (True, "02", "correctness")
145
+
146
+
147
+ # ---------------------------------------------------------------- a lens that stops
148
+
149
+ @pytest.mark.parametrize("bad", ["BLOCKED", "rejected"])
150
+ def test_a_lens_that_stops_twice_halts_the_round_with_final_ticket_blocked_and_a_retry_runs_only_that_lens(tmp_path, bad):
151
+ rig = rig_of(tmp_path)
152
+ flag, atomic = finding("missing --dry-run flag", file="cli.py", line=40), finding("not atomic", file="ledger.py")
153
+ broken = stopped() if bad == "BLOCKED" else {"report": {"status": "DONE"}}
154
+ steps = plan(**{"final/final-spec": [final(flag)], "final/final-correctness": [final(atomic)],
155
+ "final/final-structure": [broken, broken, final(finding("LONG"))],
156
+ "final/fixer": [fixer(fn("02"), "fix all three")]})
157
+ rig.run(steps)
158
+ assert rig.code == 2 and not rig.final_calls("fixer"), rig.out
159
+ first, second = rig.led("End of run: final-structure ran on")
160
+ assert OPUS in first and ASTRA in second, "the rerun is on the second final-reviewer entry"
161
+ (line,) = rig.led("End of run: BLOCKED at the final review")
162
+ assert ("the final-structure: it reported BLOCKED: cannot read the spec" if bad == "BLOCKED" else
163
+ "the final-structure: report: ") in line
164
+ (question,) = rig.state()["run"]["questions"]
165
+ assert question["id"] == "final-ticket-blocked-1" and "the final-structure: " in question["subject"]
166
+ tip = rig.final()["tidied"]
167
+ assert rig.final()["reviewed"] is None and set(rig.final()["lenses"]) == {"final-spec", "final-correctness"}
168
+ assert all(rig.final()["lenses"][role]["tip"] == tip for role in ("final-spec", "final-correctness"))
169
+
170
+ rig.run(steps, "--answer", "final-ticket-blocked-1=retry")
171
+ assert rig.code == 0, rig.out
172
+ assert [len(rig.final_calls(role)) for role in LENSES] == [1, 1, 3]
173
+ assert [(f["title"], f["source"]) for f in findings_file(rig)] == [
174
+ ("missing --dry-run flag", "spec"), ("not atomic", "correctness"), ("LONG", "structure")]
175
+ assert len(rig.final_calls("fixer")) == 1
176
+
177
+
178
+ def test_a_correctness_lens_that_stops_once_runs_again_on_another_provider_and_the_round_goes_on(tmp_path):
179
+ """The final-reviewer list has one entry on another provider than the implementer's: the rerun stays on it."""
180
+ rig = rig_of(tmp_path)
181
+ rig.run(plan(**{"final/final-correctness": [stopped("NEEDS_CONTEXT"), final(finding("LONG", "minor"))]}))
182
+ assert rig.code == 0 and not rig.state()["run"]["questions"], rig.out
183
+ first, second = rig.led("End of run: final-correctness ran on")
184
+ assert "it reported NEEDS_CONTEXT: cannot read the spec" in first and second.endswith("report accepted.")
185
+ assert ASTRA in first and ASTRA in second and not rig.led("final-correctness ran on", OPUS)
186
+ assert "cannot read the spec" in rig.final_calls("final-correctness")[1]["prompt"]
187
+
188
+
189
+ def test_a_kept_lens_report_is_not_reused_for_another_tip(tmp_path):
190
+ rig = rig_of(tmp_path)
191
+ rig.run(plan(**{"final/final-structure": [stopped(), stopped()]}))
192
+ assert rig.code == 2 and rig.final()["lenses"]
193
+ tip = rig.final()["tidied"]
194
+ state = rig.state()
195
+ for kept in state["run"]["final"]["lenses"].values():
196
+ kept["tip"] = "0" * 40 # as if the lens had reviewed another tip
197
+ (rig.repo / ".agent/implement/state.json").write_text(json.dumps(state))
198
+ rig.run(plan(), "--answer", "final-ticket-blocked-1=retry")
199
+ assert rig.code == 0 and [len(rig.final_calls(role)) for role in LENSES] == [2, 2, 3], rig.out
200
+ assert rig.final()["reviewed"] == tip
201
+
202
+
203
+ def test_a_lens_that_changes_the_slot_on_both_attempts_leaves_no_kept_lens_report(tmp_path):
204
+ rig = rig_of(tmp_path)
205
+ rig.run(plan(**{"final/final-spec": [final(files={"left.txt": "x"}), final(files={"more.txt": "x"}, commit="by it")]}))
206
+ assert rig.code == 1 and rig.final()["reviewed"] is None, rig.out
207
+ assert [len(rig.final_calls(role)) for role in LENSES] == [2, 2, 2] and rig.final()["lenses"] == {}
208
+
209
+
210
+ def test_a_lens_that_changes_the_slot_makes_the_kept_lenses_run_again_too(tmp_path):
211
+ rig = rig_of(tmp_path)
212
+ steps = plan(**{"final/final-structure": [stopped(), stopped(), final(files={"left.txt": "x"})]})
213
+ rig.run(steps)
214
+ assert rig.code == 2 and set(rig.final()["lenses"]) == {"final-spec", "final-correctness"}, rig.out
215
+ rig.run(steps, "--answer", "final-ticket-blocked-1=retry")
216
+ # The structure lens alone first, then all three after it changed the slot.
217
+ assert rig.code == 0 and [len(rig.final_calls(role)) for role in LENSES] == [2, 2, 4], rig.out
@@ -1,5 +1,4 @@
1
1
  """Plumbing merges: fast-forward, merge commit, conflict, the guarded ref move and the guarded branch delete."""
2
- import os
3
2
  import subprocess
4
3
 
5
4
  import driver_merge
@@ -88,48 +87,6 @@ def test_delete_keeps_a_branch_a_slot_has_checked_out_and_a_branch_that_is_not_m
88
87
  assert sh("git", "branch", "--format=%(refname:short)").split() == ["feat/x", "ticket/02"]
89
88
 
90
89
 
91
- def test_the_landing_check_refuses_what_it_cannot_read(repo, monkeypatch):
92
- """Ticket 09: the check fails closed. Only a path that a commit which exists does not have is "absent"."""
93
- repo()
94
- base = sh("git", "rev-parse", "HEAD")
95
- sh("git", "branch", "pr")
96
- sh("git", "branch", "ticket/02")
97
- same = commit_on("ticket/02", "a.txt", "a\n")
98
- tickets = {"01": {"phase": "merged", "locked": ["t.py", "gone.py"]}, "02": {"phase": "merge", "locked": []}}
99
- assert driver_merge.refused(tickets, "02", base, same) == ([], "") # absent on both sides of two commits that exist
100
- there = commit_on("ticket/02", "t.py", "t\n")
101
- assert driver_merge.refused(tickets, "02", base, there) == (["t.py"], "")
102
- assert driver_merge.refused(tickets, "02", there, base) == (["t.py"], "")
103
- # A candidate that is no commit: an id that does not resolve, and a tree.
104
- for bad in ("1" * 40, sh("git", "rev-parse", f"{base}^{{tree}}")):
105
- assert driver_merge.refused(tickets, "02", base, bad)[1].startswith(f"cannot read the locked files at {bad}: ")
106
- assert driver_merge.refused(tickets, "02", bad, base)[1].startswith(f"cannot read the locked files at {bad}: ")
107
- # A record with no `locked` key is a ticket that locked nothing: no error in the middle of a landing.
108
- assert driver_merge.protected({"01": {"phase": "merged"}, "02": {"phase": "merge"}}, "02") == []
109
- assert driver_merge.protected({"01": {"phase": "merged", "locked": ["a"]}}, "02") == ["a"]
110
- # git fails on both sides: the two answers are equal, and the landing is refused all the same.
111
- monkeypatch.setenv("GIT_DIR", "/nowhere")
112
- assert driver_merge.refused(tickets, "02", base, there)[1].startswith(f"cannot read the locked files at {base}: ")
113
- monkeypatch.delenv("GIT_DIR")
114
- assert driver_merge.land("pr", there, "1" * 40) != "" and sh("git", "rev-parse", "pr") == base
115
-
116
-
117
- def test_the_landing_check_compares_the_mode_and_the_type_of_a_locked_file_too(repo):
118
- """Review round 1, Codex 4: a symlink whose target is the old text has the blob id of the file it replaced."""
119
- repo()
120
- sh("git", "branch", "ticket/01")
121
- file = commit_on("ticket/01", "t.py", "t\n")
122
- tickets = {"01": {"phase": "merged", "locked": ["t.py"]}, "02": {"phase": "merge", "locked": []}}
123
- sh("git", "branch", "ticket/02", file)
124
- runs = commit_on("ticket/02", "t.py", "", lambda path: os.chmod(path, 0o755))
125
- link = commit_on("ticket/02", "t.py", "", lambda path: (os.remove(path), os.symlink("t\n", path)))
126
- blob = lambda commit: sh("git", "rev-parse", f"{commit}:t.py")
127
- assert blob(file) == blob(runs) == blob(link) and sh("git", "ls-tree", link, "t.py").startswith("120000 ")
128
- assert driver_merge.refused(tickets, "02", file, file) == ([], "")
129
- assert driver_merge.refused(tickets, "02", file, runs) == (["t.py"], "")
130
- assert driver_merge.refused(tickets, "02", file, link) == (["t.py"], "")
131
-
132
-
133
90
  def test_begin_opens_the_conflicting_merge_on_a_machine_with_no_git_identity(repo, monkeypatch, tmp_path):
134
91
  repo()
135
92
  sh("git", "branch", "ticket/01")
@@ -1,4 +1,7 @@
1
- """Ticket 07: models.json through the driver and in content; README against the help text of run.sh."""
1
+ """Ticket 07: models.json through the driver and in content; README against the help text of run.sh.
2
+
3
+ Fewer roles, ticket 01: the driver has no `correctness` or `explorer` role, and a --models file that names a role the
4
+ skill's models.json does not define stops the run before the preflight and before any agent."""
2
5
  import json
3
6
  import re
4
7
  import subprocess
@@ -7,6 +10,8 @@ import pytest
7
10
 
8
11
  from test_cli import RUN, SKILL, drive, env, make_repo, three # noqa: F401 (env is a fixture)
9
12
 
13
+ RUNS = ("--tickets", ".agent/tickets", "--gate", "true", "--fast-gate", "true", "--spec", "spec.md")
14
+
10
15
  STANDARD = {
11
16
  "implementer": ["claude-sonnet-5-5@medium", "claude-opus-5-5@medium"],
12
17
  "test-writer": ["claude-sonnet-5-5@medium", "openai/gpt-6.1-sol@medium"],
@@ -45,3 +50,47 @@ def test_readme_documents_every_flag_of_the_help():
45
50
  assert len(flags) >= 11, flags
46
51
  readme = (SKILL / "README.md").read_text()
47
52
  assert [flag for flag in flags if flag not in readme] == []
53
+
54
+
55
+ def _started(env, tmp_path, models, *extra):
56
+ """A run that is not a dry run: without an input error, the preflight launches the fake claude and codex."""
57
+ repo = make_repo(tmp_path / "demo", three())
58
+ path = tmp_path / "models.json"
59
+ path.write_text(json.dumps(models))
60
+ return drive(env, repo, *RUNS, "--models", str(path), *extra)
61
+
62
+
63
+ @pytest.mark.parametrize("role", ["correctness", "explorer"])
64
+ def test_a_models_file_with_a_removed_role_exits_3_before_the_preflight(env, tmp_path, role):
65
+ proc = _started(env, tmp_path, {role: ["openai/gpt-6-astra@medium"]})
66
+ assert proc.returncode == 3, proc.stdout + proc.stderr
67
+ assert f"{role}: the role was removed; delete its key from the --models file" in proc.stdout.splitlines()
68
+ assert not (tmp_path / "launched").exists(), "no preflight and no agent"
69
+
70
+
71
+ def test_a_models_file_with_an_unknown_role_exits_3_naming_it(env, tmp_path):
72
+ proc = _started(env, tmp_path, {"planner": ["claude-opus-5-5@medium"]})
73
+ assert proc.returncode == 3, proc.stdout + proc.stderr
74
+ assert [line for line in proc.stdout.splitlines() if line.startswith("planner: unknown role (known: ")]
75
+ assert not (tmp_path / "launched").exists()
76
+
77
+
78
+ def test_a_models_file_that_overrides_only_the_implementer_is_accepted(env, tmp_path):
79
+ repo = make_repo(tmp_path / "demo", three())
80
+ path = tmp_path / "models.json"
81
+ path.write_text(json.dumps({"implementer": ["claude-opus-5-5@medium", "openai/gpt-6.1-sol@medium"]}))
82
+ proc = drive(env, repo, *RUNS, "--models", str(path), "--dry-run")
83
+ assert proc.returncode == 0, proc.stdout + proc.stderr
84
+ assert "max frontier width" in proc.stdout
85
+
86
+
87
+ def test_only_correctness_exits_3_as_an_unknown_role(env, tmp_path):
88
+ proc = _started(env, tmp_path, {}, "--only", "correctness")
89
+ assert proc.returncode == 3, proc.stdout + proc.stderr
90
+ assert "argument --only: invalid choice: 'correctness'" in proc.stdout
91
+ assert not (tmp_path / "launched").exists()
92
+
93
+
94
+ def test_the_skill_has_no_correctness_or_explorer_role():
95
+ assert not {"correctness", "explorer"} & models().keys()
96
+ assert not (SKILL / "prompts/correctness.md").exists()