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