@jesdi/skills 0.0.77 → 0.0.78
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/README.md +3 -2
- package/package.json +1 -1
- package/skills/implement-spec/ARCHITECTURE.md +102 -54
- package/skills/implement-spec/README.md +53 -51
- package/skills/implement-spec/SKILL.md +5 -6
- package/skills/implement-spec/driver.py +67 -153
- package/skills/implement-spec/driver_agents.py +75 -25
- package/skills/implement-spec/driver_decisions.py +92 -199
- package/skills/implement-spec/driver_dispute.py +189 -0
- package/skills/implement-spec/driver_final.py +196 -97
- package/skills/implement-spec/driver_fixloop.py +102 -192
- package/skills/implement-spec/driver_legacy.py +73 -5
- package/skills/implement-spec/driver_locked.py +186 -0
- package/skills/implement-spec/driver_merge.py +3 -48
- package/skills/implement-spec/driver_report.py +84 -64
- package/skills/implement-spec/driver_review.py +12 -119
- package/skills/implement-spec/driver_run.py +167 -130
- package/skills/implement-spec/driver_state.py +11 -9
- package/skills/implement-spec/models.json +0 -2
- package/skills/implement-spec/prompts/arbitration.md +34 -0
- package/skills/implement-spec/prompts/conflict.md +1 -0
- package/skills/implement-spec/prompts/correction.md +7 -4
- package/skills/implement-spec/prompts/elsewhere.md +6 -0
- package/skills/implement-spec/prompts/final-fixer.md +1 -1
- package/skills/implement-spec/prompts/final-lens.md +40 -0
- package/skills/implement-spec/prompts/final-reviewer.md +7 -7
- package/skills/implement-spec/prompts/fixer.md +2 -2
- package/skills/implement-spec/prompts/implementer.md +1 -1
- package/skills/implement-spec/prompts/lens-copy.md +1 -0
- package/skills/implement-spec/prompts/lens-correctness.md +8 -0
- package/skills/implement-spec/prompts/lens-spec.md +2 -0
- package/skills/implement-spec/prompts/lens-structure.md +2 -0
- package/skills/implement-spec/prompts/rebase-conflict.md +1 -0
- package/skills/implement-spec/prompts/rereview.md +0 -1
- package/skills/implement-spec/prompts/rerun.md +1 -1
- package/skills/implement-spec/prompts/reviewer.md +3 -6
- package/skills/implement-spec/prompts/ruled.md +3 -0
- package/skills/implement-spec/prompts/test-writer.md +4 -5
- package/skills/implement-spec/tests/test_agents.py +23 -22
- package/skills/implement-spec/tests/test_amendments.py +6 -48
- package/skills/implement-spec/tests/test_arbitration.py +314 -0
- package/skills/implement-spec/tests/test_cli.py +3 -3
- package/skills/implement-spec/tests/test_decisions.py +251 -374
- package/skills/implement-spec/tests/test_driver.py +22 -50
- package/skills/implement-spec/tests/test_final.py +45 -77
- package/skills/implement-spec/tests/test_fixloop.py +400 -633
- package/skills/implement-spec/tests/test_landing.py +23 -126
- package/skills/implement-spec/tests/test_lenses.py +217 -0
- package/skills/implement-spec/tests/test_merge.py +0 -43
- package/skills/implement-spec/tests/test_models.py +50 -1
- package/skills/implement-spec/tests/test_report.py +9 -23
- package/skills/implement-spec/tests/test_review.py +15 -153
- package/skills/implement-spec/tests/test_review_page.py +7 -3
- package/skills/implement-spec/tests/test_scoped.py +125 -0
- package/skills/implement-spec/tests/test_state.py +8 -3
- package/skills/implement-spec/tests/test_stops.py +43 -61
- package/skills/implement-spec/tests/test_tidy.py +77 -98
- package/skills/implement-spec/tests/test_walk.py +7 -6
- package/skills/review-page/SKILL.md +1 -1
- package/skills/to-tickets/SKILL.md +1 -1
- package/skills-manifest.json +7 -7
- package/skills/implement-spec/prompts/corrected.md +0 -3
- package/skills/implement-spec/prompts/correctness.md +0 -42
- package/skills/implement-spec/prompts/final-scoped.md +0 -1
- package/skills/implement-spec/prompts/full-review.md +0 -2
- package/skills/implement-spec/prompts/overruled.md +0 -7
- package/skills/implement-spec/prompts/rejected.md +0 -1
- package/skills/implement-spec/prompts/restored-red.md +0 -3
- package/skills/implement-spec/prompts/restored.md +0 -3
- package/skills/implement-spec/prompts/stands.md +0 -2
|
@@ -8,20 +8,20 @@ import pytest
|
|
|
8
8
|
|
|
9
9
|
import driver_answers
|
|
10
10
|
import driver_decisions
|
|
11
|
-
import
|
|
11
|
+
import driver_report
|
|
12
12
|
import driver_review_page
|
|
13
|
-
from test_cli import git
|
|
13
|
+
from test_cli import git, ticket
|
|
14
14
|
from test_fixloop import Inside, inside # noqa: F401 (the autouse fixture puts the rig's CLIs on PATH)
|
|
15
15
|
from test_tidy import Inside as Pushing, tools # noqa: F401 (an unattended run pushes: the rig with an origin and a fake gh)
|
|
16
|
-
from test_review import ONE, STUCK,
|
|
17
|
-
from test_stops import
|
|
18
|
-
from test_walk import
|
|
16
|
+
from test_review import ONE, STUCK, fix, review
|
|
17
|
+
from test_stops import Q1, RULED, STOP, UNATTENDED, blocked, decisions, stage, steps, write_answers
|
|
18
|
+
from test_walk import impl, plan, tw
|
|
19
19
|
|
|
20
20
|
PAGE = ".agent/implement-review.html"
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
def stopped(tmp_path, *extra, then=(impl("01"),)):
|
|
24
|
-
return Inside(tmp_path, ONE).run(steps(blocked(), *then), *extra)
|
|
24
|
+
return Inside(tmp_path, ONE).run(steps(blocked(), blocked(), *then), *extra)
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
def doc(*questions, run="run-1"):
|
|
@@ -29,8 +29,9 @@ def doc(*questions, run="run-1"):
|
|
|
29
29
|
return driver_decisions.document({"revision": run, "questions": list(questions)})
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
def asked(kind="
|
|
33
|
-
return driver_decisions.question(kind, ticket, subject, ["report.json", "ledger.md:3"], list(before), stop
|
|
32
|
+
def asked(kind="ticket-blocked", ticket="01", subject="the implementer: it reported BLOCKED", before=(), stop=1):
|
|
33
|
+
return driver_decisions.question(kind, ticket, subject, ["report.json", "ledger.md:3"], list(before), stop,
|
|
34
|
+
driver_decisions.Resume(""))
|
|
34
35
|
|
|
35
36
|
|
|
36
37
|
# ---------------------------------------------------------------- the stop and its answer
|
|
@@ -38,43 +39,35 @@ def asked(kind="locked-test", ticket="01", subject="tests/test_a.py::test_x", be
|
|
|
38
39
|
def test_a_stop_prints_the_question_and_an_answer_is_applied_once(tmp_path, capsys):
|
|
39
40
|
rig = stopped(tmp_path)
|
|
40
41
|
out = capsys.readouterr().out
|
|
41
|
-
assert rig.code == 2 and f"Question {Q1}: Ticket 01:
|
|
42
|
-
assert "
|
|
42
|
+
assert rig.code == 2 and f"Question {Q1}: Ticket 01: an agent stopped or was rejected" in out
|
|
43
|
+
assert " retry (recommended): " in out and "--answer <question id>=<option id>" in out
|
|
43
44
|
(q,) = rig.state()["run"]["questions"]
|
|
44
|
-
assert (q["ticket"], q["kind"], q["
|
|
45
|
-
|
|
45
|
+
assert (q["ticket"], q["kind"], q["stop"], q["answer"]) == ("01", "ticket-blocked", 1, None)
|
|
46
|
+
assert q["subject"] == f"the implementer: it reported BLOCKED: {STOP}"
|
|
46
47
|
assert q["evidence"][0] == ".agent/implement/01/implementer-0.json" and rig.state()["run"]["stops"] == 1
|
|
47
|
-
assert rig.led("Ticket 01: the operator decides on 1 question of kind
|
|
48
|
+
assert rig.led("Ticket 01: the operator decides on 1 question of kind ticket-blocked in .agent/implement/decisions.json.")
|
|
48
49
|
|
|
49
|
-
rig.run(steps(blocked(), impl("01")), "--answer", f"{Q1}=
|
|
50
|
+
rig.run(steps(blocked(), blocked(), impl("01")), "--answer", f"{Q1}=retry")
|
|
50
51
|
assert rig.code == 0, rig.ledger()
|
|
51
|
-
assert len(rig.led(
|
|
52
|
-
prompt = rig.prompt("test-writer-0")
|
|
53
|
-
assert "This call is a correction after a ruling" in prompt and "read `concerns` in .agent/implement/01/implementer-0.json" in prompt
|
|
54
|
-
assert "ruling" not in rig.prompt("implementer-0") and prompt.rstrip().endswith("one ref store.")
|
|
52
|
+
assert len(rig.led(RULED)) == 1
|
|
55
53
|
entry = rig.state()["tickets"]["01"]
|
|
56
54
|
assert (entry["phase"], entry["note"], entry["locked"]) == ("merged", "", ["tests/test_01.py"])
|
|
57
|
-
assert rig.state()["run"]["questions"][0]["answer"] == "
|
|
55
|
+
assert rig.state()["run"]["questions"][0]["answer"] == "retry"
|
|
58
56
|
assert decisions(rig)["questions"] == [] and not (rig.repo / PAGE).exists()
|
|
59
57
|
assert "Question" not in capsys.readouterr().out
|
|
60
58
|
|
|
61
59
|
# The question is closed: its answer cannot be given again, and the old answers file is history.
|
|
62
|
-
rig.run({}, "--answer", f"{Q1}=
|
|
63
|
-
assert rig.code == 3 and f"--answer {Q1}=
|
|
60
|
+
rig.run({}, "--answer", f"{Q1}=edit")
|
|
61
|
+
assert rig.code == 3 and f"--answer {Q1}=edit: no open question {Q1}" in capsys.readouterr().out
|
|
64
62
|
rig.run({})
|
|
65
63
|
assert rig.code == 0 and not rig.led("ignored") and len(rig.led("Ruling")) == 1
|
|
66
64
|
|
|
67
65
|
|
|
68
|
-
def
|
|
66
|
+
def test_an_answer_with_an_option_the_question_does_not_offer_exits_3(tmp_path, capsys):
|
|
69
67
|
rig = stopped(tmp_path)
|
|
70
|
-
rig.run(steps(blocked(), impl("01")), "--answer", f"{Q1}=nope")
|
|
71
|
-
assert rig.code == 3 and f"--answer {Q1}=nope: {Q1} offers
|
|
68
|
+
rig.run(steps(blocked(), blocked(), impl("01")), "--answer", f"{Q1}=nope")
|
|
69
|
+
assert rig.code == 3 and f"--answer {Q1}=nope: {Q1} offers retry, edit" in capsys.readouterr().out
|
|
72
70
|
assert not (rig.repo / driver_answers.FILE).exists()
|
|
73
|
-
rig.run(steps(blocked(), impl("01")), "--answer", f"{Q1}=overrule-implementer")
|
|
74
|
-
assert rig.code == 0, rig.ledger()
|
|
75
|
-
assert rig.led("Ruling: 01 locked test stands: the implementer is overruled on tests/test_01.py::test_x")
|
|
76
|
-
assert len(rig.calls("01", "test-writer")) == 1 and len(rig.calls("01", "implementer")) == 2
|
|
77
|
-
assert "the operator ruled that the locked tests stand as they are" in rig.prompt("implementer-0")
|
|
78
71
|
|
|
79
72
|
|
|
80
73
|
def test_an_answer_needs_a_question_and_an_option(tmp_path, capsys):
|
|
@@ -84,11 +77,11 @@ def test_an_answer_needs_a_question_and_an_option(tmp_path, capsys):
|
|
|
84
77
|
|
|
85
78
|
|
|
86
79
|
def test_a_second_stop_counts_on_and_its_page_holds_only_the_open_question(tmp_path, capsys):
|
|
87
|
-
rig = stopped(tmp_path
|
|
88
|
-
rig.run(steps(blocked(), blocked()), "--answer", f"{Q1}=
|
|
89
|
-
assert rig.code == 2 and [q["id"] for q in decisions(rig)["questions"]] == ["01-
|
|
80
|
+
rig = stopped(tmp_path)
|
|
81
|
+
rig.run(steps(blocked(), blocked(), blocked(), blocked()), "--answer", f"{Q1}=retry")
|
|
82
|
+
assert rig.code == 2 and [q["id"] for q in decisions(rig)["questions"]] == ["01-ticket-blocked-2"]
|
|
90
83
|
html = (rig.repo / PAGE).read_text()
|
|
91
|
-
assert 'data-q="01-
|
|
84
|
+
assert 'data-q="01-ticket-blocked-2"' in html and Q1 not in html and rig.state()["run"]["stops"] == 2
|
|
92
85
|
|
|
93
86
|
|
|
94
87
|
# ---------------------------------------------------------------- what a stop keeps for the rerun
|
|
@@ -96,281 +89,107 @@ def test_a_second_stop_counts_on_and_its_page_holds_only_the_open_question(tmp_p
|
|
|
96
89
|
def test_an_answers_file_of_an_earlier_run_is_not_applied_to_the_same_question_of_a_new_run(tmp_path, capsys):
|
|
97
90
|
rig = stopped(tmp_path)
|
|
98
91
|
old = decisions(rig)
|
|
99
|
-
write_answers(rig, {Q1: "
|
|
92
|
+
write_answers(rig, {Q1: "retry"})
|
|
100
93
|
# The operator starts again: the run directory goes, the answers file is outside it and stays.
|
|
101
94
|
shutil.rmtree(rig.repo / ".agent/implement")
|
|
102
95
|
git(rig.repo, "branch", "-D", "ticket/feat%2Fcsv/01")
|
|
103
|
-
again = steps(blocked(),
|
|
96
|
+
again = steps(*[blocked()] * 4, impl("01"), **{"01/test-writer": [tw("01")] * 2})
|
|
104
97
|
rig.run(again)
|
|
105
98
|
new = decisions(rig)
|
|
106
99
|
assert rig.code == 2 and new["questions"] == old["questions"], "the same question, word for word"
|
|
107
100
|
assert new["run"] == rig.state()["run"]["revision"] != old["run"] and new["revision"] != old["revision"]
|
|
108
101
|
rig.run(again)
|
|
109
102
|
assert rig.code == 2 and rig.led("is ignored: its revision") and not rig.led("Ruling")
|
|
110
|
-
assert len(rig.calls("01", "implementer")) ==
|
|
103
|
+
assert len(rig.calls("01", "implementer")) == 4, "no agent ran on the old answer"
|
|
111
104
|
assert doc(asked(), run="a")["revision"] != doc(asked(), run="b")["revision"]
|
|
112
105
|
|
|
113
106
|
|
|
114
|
-
def partial():
|
|
115
|
-
"""An implementer that commits a part of its work, then reports the contradicted locked test."""
|
|
116
|
-
step = {**blocked(), "files": {"demo/export.py": "def partial():\n return 1\n"}, "commit": "feat: 01 partial work"}
|
|
117
|
-
step["report"] = {**step["report"], "commits": ["$SHA"], "files": ["demo/export.py"]}
|
|
118
|
-
return step
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
@pytest.mark.parametrize("option, role", [("overrule-implementer", "implementer"), ("overrule-test", "test-writer")])
|
|
122
|
-
def test_after_a_ruling_the_ticket_goes_on_from_the_commits_of_the_blocked_implementer(tmp_path, capsys, option, role):
|
|
123
|
-
rig = Inside(tmp_path, ONE).run(steps(partial(), impl("01")))
|
|
124
|
-
stop = rig.calls("01", "implementer")[0]["sha"]
|
|
125
|
-
assert rig.code == 2 and rig.state()["tickets"]["01"]["tip"] == stop
|
|
126
|
-
rig.run(steps(partial(), impl("01")), "--answer", f"{Q1}={option}")
|
|
127
|
-
assert rig.code == 0, rig.ledger()
|
|
128
|
-
after = rig.calls("01", role)[1]
|
|
129
|
-
assert after["head"] == stop and "feat: 01 partial work" in after["log"].splitlines()
|
|
130
|
-
# After overrule-test the implementer starts from the correction, which is on top of its own commit.
|
|
131
|
-
assert "feat: 01 partial work" in rig.calls("01", "implementer")[1]["log"].splitlines()
|
|
132
|
-
assert rig.state()["tickets"]["01"]["locked"] == ["tests/test_01.py"]
|
|
133
|
-
assert "feat: 01 partial work" in rig.pr_subjects() and "feat: 01 rows" in rig.pr_subjects()
|
|
134
|
-
|
|
135
|
-
|
|
136
107
|
def test_a_stop_with_uncommitted_work_keeps_its_slot_and_takes_the_answer(tmp_path, capsys):
|
|
137
108
|
dirty = {**blocked(), "files": {"demo/export.py": "half = 1\n"}}
|
|
138
|
-
|
|
109
|
+
run = steps(dirty, dirty, impl("01"))
|
|
110
|
+
rig = Pushing(tmp_path, ONE).run(run, *UNATTENDED)
|
|
139
111
|
assert rig.code == 2 and git(rig.repo, "status", "--porcelain") == " M demo/export.py\n"
|
|
140
|
-
rig.run(
|
|
141
|
-
assert rig.code == 2 and len(rig.calls()) ==
|
|
112
|
+
rig.run(run, *UNATTENDED)
|
|
113
|
+
assert rig.code == 2 and len(rig.calls()) == 3, "the stop repeats: the work in the slot is no error"
|
|
142
114
|
assert (rig.repo / "demo/export.py").read_text() == "half = 1\n"
|
|
143
|
-
write_answers(rig, {Q1: "
|
|
144
|
-
rig.run(
|
|
115
|
+
write_answers(rig, {Q1: "retry"})
|
|
116
|
+
rig.run(run, *UNATTENDED)
|
|
145
117
|
assert rig.code == 0, rig.ledger()
|
|
146
|
-
|
|
147
|
-
assert
|
|
148
|
-
|
|
149
|
-
assert "the locked tests stand as they are" in prompt and "uncommitted work" in prompt
|
|
118
|
+
third = rig.calls("01", "implementer")[2]
|
|
119
|
+
assert third["status"] == "M demo/export.py" and third["branch"] == "ticket/feat%2Fcsv/01", "the work is in the tree of the rerun"
|
|
120
|
+
assert "uncommitted work is in the tree" in (rig.folder() / "implementer-0.prompt.md").read_text()
|
|
150
121
|
assert "feat: 01 rows" in rig.pr_subjects() and not git(rig.repo, "status", "--porcelain")
|
|
151
122
|
|
|
152
123
|
|
|
153
|
-
# ---------------------------------------------------------------- the
|
|
124
|
+
# ---------------------------------------------------------------- the answers of one stop
|
|
154
125
|
|
|
155
|
-
|
|
156
|
-
|
|
126
|
+
def test_one_answer_that_keeps_the_ticket_blocked_wins_over_a_retry():
|
|
127
|
+
one = asked(subject="A")
|
|
128
|
+
two = asked(subject="B", before=[one])
|
|
129
|
+
other = asked(ticket="02", subject="C", before=[one, two], stop=2)
|
|
130
|
+
rulings, moved = driver_decisions.apply([one, two, other], {one["id"]: "retry", two["id"]: "edit",
|
|
131
|
+
other["id"]: "retry", "09-ticket-blocked-1": "retry"})
|
|
132
|
+
assert moved == {"02": {"phase": ""}} and len(rulings) == 3
|
|
133
|
+
assert rulings[1] == "Ruling: 01 stays BLOCKED for an edit of the spec or the ticket (edit): B."
|
|
134
|
+
assert driver_decisions.rulings([one, two, other]) == rulings
|
|
135
|
+
assert driver_decisions.apply([one, two, other], {one["id"]: "edit"}) == ([], {}), "an answer is applied once"
|
|
157
136
|
|
|
158
137
|
|
|
159
|
-
|
|
160
|
-
"""A test-writer that locks two files; the contradiction is about the first one."""
|
|
161
|
-
step = tw("01")
|
|
162
|
-
step["files"][OTHER] = OTHER_TEST
|
|
163
|
-
step["report"] = {**step["report"], "locked": ["tests/test_01.py", OTHER], "files": ["tests/test_01.py", OTHER]}
|
|
164
|
-
return step
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
def restored(path):
|
|
168
|
-
return f"Ticket 01: {path} was not the locked version at the correction: the driver restored it in a commit"
|
|
138
|
+
# ---------------------------------------------------------------- a run of an older driver (schema 3)
|
|
169
139
|
|
|
140
|
+
def as_schema_3(rig, **question):
|
|
141
|
+
"""Make the run of `rig` one that a schema 3 driver left, its one question changed by `question`."""
|
|
142
|
+
path = rig.repo / ".agent/implement/state.json"
|
|
143
|
+
state = json.loads(path.read_text())
|
|
144
|
+
assert state["run"]["schema"] == 4, "a new run writes schema 4"
|
|
145
|
+
state["run"]["schema"] = 3
|
|
146
|
+
state["run"]["questions"][0].update(question)
|
|
147
|
+
path.write_text(json.dumps(state))
|
|
148
|
+
return state
|
|
170
149
|
|
|
171
|
-
TWO_TESTS = "def test_x():\n assert 01 == 'x'\n\n\ndef test_y():\n assert 1 == 'y'\n"
|
|
172
|
-
ONLY_X = TWO_TESTS.split("\n\n\n")[0] + "\n"
|
|
173
|
-
# The edit of an agent: the one line of test_x, in place, in the file as the tree has it.
|
|
174
|
-
EDIT = "--- a/tests/test_01.py\n+++ b/tests/test_01.py\n@@ -2 +2 @@\n- assert 01 == 'x'\n+ assert '01' == '01'\n"
|
|
175
150
|
|
|
151
|
+
def test_an_older_run_with_an_open_question_of_a_removed_kind_exits_3_before_any_agent(tmp_path, capsys):
|
|
152
|
+
rig = stopped(tmp_path)
|
|
153
|
+
as_schema_3(rig, id="01-locked-test-1", kind="locked-test")
|
|
154
|
+
capsys.readouterr()
|
|
155
|
+
rig.run(steps(blocked(), blocked(), impl("01")))
|
|
156
|
+
out = capsys.readouterr().out
|
|
157
|
+
assert rig.code == 3 and len(rig.calls()) == 3, out
|
|
158
|
+
assert ("implement-spec: the open question 01-locked-test-1 is of the kind locked-test, which this driver no "
|
|
159
|
+
"longer has: answer it with the driver version that asked it, or start the run again") in out
|
|
160
|
+
assert rig.state()["run"]["schema"] == 3, "the run stays the older driver's"
|
|
176
161
|
|
|
177
|
-
@pytest.mark.parametrize("committed", [True, False])
|
|
178
|
-
def test_the_correction_starts_from_the_locked_version_of_a_file_the_implementer_changed(tmp_path, capsys, committed):
|
|
179
|
-
writer = {**tw("01"), "files": {"tests/test_01.py": TWO_TESTS}}
|
|
180
|
-
deletes = {**(partial() if committed else blocked()), "files": {"tests/test_01.py": ONLY_X}}
|
|
181
|
-
rig = Inside(tmp_path, ONE)
|
|
182
|
-
(rig.rig / "edit.patch").write_text(EDIT)
|
|
183
|
-
edits = {**correction(), "files": {}, "git": [["apply", "--unidiff-zero", str(rig.rig / "edit.patch")]]}
|
|
184
|
-
scenario = plan(**{"01/test-writer": [writer, edits], "01/implementer": [deletes, impl("01")]})
|
|
185
|
-
rig.run(scenario)
|
|
186
|
-
assert rig.code == 2, rig.ledger()
|
|
187
|
-
rig.run(scenario, "--answer", f"{Q1}=overrule-test")
|
|
188
|
-
assert rig.code == 0, rig.ledger()
|
|
189
|
-
assert git(rig.repo, "show", "feat/csv:tests/test_01.py") == TWO_TESTS.replace("01 == 'x'", "'01' == '01'")
|
|
190
|
-
assert len(rig.led(restored("tests/test_01.py"))) == 1 and not rig.led("locked file changed")
|
|
191
|
-
assert rig.state()["tickets"]["01"]["held"] == {}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
def test_a_locked_file_the_correction_changes_without_listing_it_is_still_a_finding(tmp_path, capsys):
|
|
195
|
-
gutted = partial()
|
|
196
|
-
gutted["files"] = {**gutted["files"], OTHER: "# gutted\n"}
|
|
197
|
-
# The driver restored the other file before the correction; the correction guts it again and commits it unlisted.
|
|
198
|
-
guts = {**correction(), "files": {"tests/test_01.py": NEW_TEST, OTHER: "# gutted again\n"}}
|
|
199
|
-
restore = fix("01", 1, files={"demo/export.py": "x = 1\n", OTHER: OTHER_TEST})
|
|
200
|
-
scenario = plan(**{"01/test-writer": [two_locked(), guts], "01/implementer": [gutted, impl("01")],
|
|
201
|
-
"01/fixer": [restore]})
|
|
202
|
-
rig = Inside(tmp_path, ONE).run(scenario)
|
|
203
|
-
first = rig.calls("01", "test-writer")[0]["sha"]
|
|
204
|
-
rig.run(scenario, "--answer", f"{Q1}=overrule-test")
|
|
205
|
-
assert rig.code == 0, rig.ledger()
|
|
206
|
-
assert rig.led(restored(OTHER)) and not rig.led(restored("tests/test_01.py"))
|
|
207
|
-
(line,) = rig.led(f"locked file changed: {OTHER}")
|
|
208
|
-
assert "critical" in line and len(rig.calls("01", "fixer")) == 1
|
|
209
|
-
entry = rig.state()["tickets"]["01"]
|
|
210
|
-
assert entry["held"] == {OTHER: first} and entry["test_writer_sha"] == rig.calls("01", "test-writer")[1]["sha"]
|
|
211
|
-
assert git(rig.repo, "show", f"feat/csv:{OTHER}") == OTHER_TEST and git(rig.repo, "show", "feat/csv:tests/test_01.py") == NEW_TEST
|
|
212
162
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
rig
|
|
220
|
-
rig.
|
|
221
|
-
|
|
222
|
-
assert
|
|
223
|
-
|
|
224
|
-
# Issue #134: the refused correction asks the locked-test question again, from the same blocked report.
|
|
225
|
-
(again,) = decisions(rig)["questions"]
|
|
226
|
-
asked_again = rig.state()["run"]["questions"][-1]
|
|
227
|
-
assert again["id"] == "01-locked-test-2" and asked_again["subject"] == "tests/test_01.py::test_x"
|
|
228
|
-
assert asked_again["evidence"][0] == ".agent/implement/01/implementer-0.json"
|
|
229
|
-
assert rig.led(restored(OTHER)) and git(rig.repo, "show", f"ticket/feat%2Fcsv/01:{OTHER}") == OTHER_TEST
|
|
230
|
-
assert len(rig.calls("01", "test-writer")) == 3 and len(rig.calls("01", "implementer")) == 1, "one rerun, no implementer"
|
|
231
|
-
assert "its commits also change demo/export.py" in rig.prompt("test-writer-0")
|
|
232
|
-
assert "feat: 01 rows" not in rig.pr_subjects() and rig.state()["tickets"]["01"]["held"] == {}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
MUTATION = "FAILED tests/test_01.py::test_x - AssertionError: fn_01 deleted"
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
def test_an_overrule_correction_whose_test_is_green_against_the_tip_reaches_the_review(tmp_path, capsys):
|
|
239
|
-
# Issue #134: the corrected test is green on the implementer's code, so its red line comes from a reverted mutation.
|
|
240
|
-
green = {**correction(), "stdout": MUTATION + "\n" + COST}
|
|
241
|
-
green["report"] = {**green["report"], "red": [{"test": "tests/test_01.py::test_x", "line": MUTATION}]}
|
|
242
|
-
scenario = plan(**{"01/test-writer": [tw("01"), green, green], "01/implementer": [partial(), impl("01")]})
|
|
243
|
-
rig = Inside(tmp_path, ONE).run(scenario)
|
|
244
|
-
rig.run(scenario, "--answer", f"{Q1}=overrule-test")
|
|
245
|
-
assert rig.code == 0, rig.ledger()
|
|
246
|
-
assert len(rig.calls("01", "test-writer")) == 2, "the green correction is accepted with no rerun"
|
|
247
|
-
assert "break the production line that the test protects" in rig.prompt("test-writer-0")
|
|
248
|
-
assert rig.state()["tickets"]["01"]["phase"] == "merged"
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
def test_an_overrule_correction_may_leave_the_overruled_concern_not_addressed(tmp_path, capsys):
|
|
252
|
-
keeps = {**correction(), "files": {}, "commit": None, "stdout": COST}
|
|
253
|
-
del keeps["files"], keeps["commit"]
|
|
254
|
-
keeps["report"] = {**keeps["report"], "commits": [], "files": [], "locked": [], "red": [],
|
|
255
|
-
"not_addressed": [{"finding": CONTRA, "reason": "the test is right"}]}
|
|
256
|
-
scenario = plan(**{"01/test-writer": [tw("01"), keeps, keeps], "01/implementer": [blocked(), impl("01")]})
|
|
257
|
-
rig = Inside(tmp_path, ONE).run(scenario)
|
|
258
|
-
rig.run(scenario, "--answer", f"{Q1}=overrule-test")
|
|
259
|
-
assert rig.code == 0, rig.ledger()
|
|
260
|
-
assert len(rig.calls("01", "test-writer")) == 2, "the concern is a target the correction can name"
|
|
261
|
-
assert f"- {CONTRA}" in rig.prompt("test-writer-0")
|
|
262
|
-
assert rig.led(f"Ticket 01: the test-writer correction did not correct {CONTRA}: the test is right.")
|
|
263
|
-
|
|
264
|
-
def test_a_correction_of_its_own_file_leaves_the_work_in_the_tree_to_the_implementer(tmp_path, capsys):
|
|
265
|
-
dirty = {**blocked(), "files": {"demo/export.py": "half = 1\n"}}
|
|
266
|
-
# This correction commits only its test file: the implementer's file is out of the reach of `git add -A`.
|
|
267
|
-
only = {**correction(), "git_after": [["update-index", "--assume-unchanged", "demo/export.py"]]}
|
|
268
|
-
goes_on = {**impl("01"), "files": {}, "git": [["update-index", "--no-assume-unchanged", "demo/export.py"]]}
|
|
269
|
-
scenario = plan(**{"01/test-writer": [two_locked(), only], "01/implementer": [dirty, goes_on]})
|
|
270
|
-
rig = Inside(tmp_path, ONE).run(scenario)
|
|
271
|
-
rig.run(scenario, "--answer", f"{Q1}=overrule-test")
|
|
272
|
-
assert rig.code == 0, rig.ledger()
|
|
273
|
-
fixed = rig.calls("01", "test-writer")[1]["sha"]
|
|
274
|
-
assert git(rig.repo, "show", "--name-only", "--format=", fixed).split() == ["tests/test_01.py"]
|
|
275
|
-
assert git(rig.repo, "show", "feat/csv:demo/export.py") == "half = 1\n", "the implementer committed its own work"
|
|
276
|
-
entry = rig.state()["tickets"]["01"]
|
|
277
|
-
assert entry["held"] == {} and entry["locked"] == ["tests/test_01.py", OTHER] and not rig.led("locked file changed")
|
|
278
|
-
assert git(rig.repo, "show", f"feat/csv:{OTHER}") == OTHER_TEST
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
def proved(findings=()):
|
|
282
|
-
"""A reviewer step with a mutation proof for each of the two locked files."""
|
|
283
|
-
step = review("01", findings)
|
|
284
|
-
red = "FAILED tests/test_01b.py::test_y - AssertionError at demo/export.py:1"
|
|
285
|
-
step["report"]["mutations"].append(dict(test=f"{OTHER}::test_y", file="demo/export.py", line=1, red=red))
|
|
286
|
-
return {**step, "stdout": step["stdout"] + red + "\n"}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
STRONGER = "def test_x():\n assert '01' == '01' # stronger\n"
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
@pytest.mark.parametrize("cheat", [False, True])
|
|
293
|
-
def test_a_second_correction_of_a_locked_file_is_its_new_reference(tmp_path, capsys, cheat):
|
|
294
|
-
# Issue #75: the review correction (#70) changes tests/test_01.py and first lists only the other file. Before
|
|
295
|
-
# the fix it was accepted, `held` kept the overrule commit as the reference, and each review after a fix that
|
|
296
|
-
# did not touch the file found "locked file changed". A correction now lists each file it changes.
|
|
297
|
-
vacuous = finding("VACUOUS", "critical", kind="test", file="tests/test_01.py")
|
|
298
|
-
files = {"tests/test_01.py": STRONGER.replace("stronger", "draft"), OTHER: OTHER_TEST + "# stronger\n"}
|
|
299
|
-
unlisted = {**correction(), "files": files, "commit": "test: 01 stronger"}
|
|
300
|
-
unlisted["report"] = {**unlisted["report"], "locked": [OTHER], "files": [OTHER]}
|
|
301
|
-
# The rerun lists both files: the commit of the rejected attempt is in its commits too.
|
|
302
|
-
listed = {**unlisted, "files": {"tests/test_01.py": STRONGER}}
|
|
303
|
-
listed["report"] = {**unlisted["report"], "locked": ["tests/test_01.py", OTHER]}
|
|
304
|
-
gutted = fix("01", 1, files={"demo/export.py": "x = 1\n", "tests/test_01.py": "# gutted\n"})
|
|
305
|
-
fixes = [gutted, fix("01", 2, files={"demo/export.py": "x = 2\n", "tests/test_01.py": STRONGER})] if cheat else [
|
|
306
|
-
fix("01", 1)]
|
|
307
|
-
scenario = plan(**{"01/test-writer": [two_locked(), correction(), unlisted, listed],
|
|
308
|
-
"01/implementer": [blocked(), impl("01")], "01/fixer": fixes,
|
|
309
|
-
"01/reviewer": [proved([vacuous]), proved([finding("STUCK")])] + [proved()] * 3})
|
|
310
|
-
rig = Inside(tmp_path, ONE).run(scenario)
|
|
311
|
-
rig.run(scenario, "--answer", f"{Q1}=overrule-test")
|
|
312
|
-
assert rig.code == 0, rig.ledger()
|
|
313
|
-
assert rig.led("BLOCKED", "correction") == [] and rig.led("its commits also change tests/test_01.py")
|
|
314
|
-
entry = rig.state()["tickets"]["01"]
|
|
315
|
-
assert entry["held"] == {} and entry["test_writer_sha"] == rig.calls("01", "test-writer")[3]["sha"]
|
|
316
|
-
assert len(rig.led("locked file changed: tests/test_01.py")) == cheat, "only a fixer's change is a finding"
|
|
317
|
-
assert git(rig.repo, "show", "feat/csv:tests/test_01.py") == STRONGER
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
def test_a_locked_file_keeps_its_old_reference_until_a_test_writer_lists_it(repo, tmp_path):
|
|
321
|
-
def commit(name, text):
|
|
322
|
-
(tmp_path / name).write_text(text)
|
|
323
|
-
return git(tmp_path, "add", "-A") + git(tmp_path, "commit", "-q", "-m", name) + git(tmp_path, "rev-parse", "HEAD").strip()
|
|
324
|
-
|
|
325
|
-
repo()
|
|
326
|
-
commit("a.py", "1\n"), commit("c.py", "1\n")
|
|
327
|
-
old = commit("b.py", "1\n")
|
|
328
|
-
commit("b.py", "the implementer changed it\n")
|
|
329
|
-
tip = commit("a.py", "the correction\n")
|
|
330
|
-
first = driver_review.written(".", {"test_writer_sha": None, "locked": [], "held": {}, "fixtures": []},
|
|
331
|
-
["a.py", "b.py", "c.py"], [], old)
|
|
332
|
-
assert first == {"test_writer_sha": old, "locked": ["a.py", "b.py", "c.py"], "held": {}, "fixtures": []}
|
|
333
|
-
after = driver_review.written(".", first, ["a.py"], [], tip)
|
|
334
|
-
assert after == {"test_writer_sha": tip, "locked": ["a.py", "b.py", "c.py"], "held": {"b.py": old}, "fixtures": []}
|
|
335
|
-
(finding,) = driver_review.locked_findings(".", after)
|
|
336
|
-
assert (finding["title"], finding["evidence"]) == ("locked file changed: b.py", f"git diff {old}..HEAD -- b.py")
|
|
337
|
-
assert driver_review.written(".", after, ["b.py"], [], tip)["held"] == {}, "the test-writer corrected it: a new reference"
|
|
338
|
-
# A diff that git cannot make holds each other file, and then the check of the review fails in the open.
|
|
339
|
-
lost = driver_review.written(".", {**first, "test_writer_sha": "0" * 40}, ["a.py"], [], tip)
|
|
340
|
-
assert lost["held"] == {"b.py": "0" * 40, "c.py": "0" * 40}
|
|
341
|
-
assert [f["title"].split(":")[0] for f in driver_review.locked_findings(".", lost)] == ["locked file check failed"]
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
# ---------------------------------------------------------------- legacy finding-question decisions
|
|
345
|
-
|
|
346
|
-
def test_one_answer_that_keeps_the_ticket_blocked_wins_over_an_accept():
|
|
347
|
-
one = asked("finding", subject="A")
|
|
348
|
-
two = asked("finding", subject="B", before=[one])
|
|
349
|
-
other = asked("finding", ticket="02", subject="C", before=[one, two], stop=2)
|
|
350
|
-
rulings, moved = driver_decisions.apply([one, two, other], {one["id"]: "accept", two["id"]: "redesign",
|
|
351
|
-
other["id"]: "accept", "09-finding-1": "accept"})
|
|
352
|
-
assert moved == {"02": {"phase": "merge"}} and len(rulings) == 3
|
|
353
|
-
assert rulings[1] == "Ruling: 01 stays BLOCKED, the design changes first (redesign): B."
|
|
354
|
-
assert driver_decisions.apply([one, two, other], {one["id"]: "split"}) == ([], {}), "an answer is applied once"
|
|
163
|
+
def test_an_older_run_keeps_the_ruling_of_an_answered_question_of_a_removed_kind_in_the_pr_body(tmp_path):
|
|
164
|
+
run = steps(blocked(), blocked(), impl("01"))
|
|
165
|
+
rig = Pushing(tmp_path, ONE).run(run, *UNATTENDED)
|
|
166
|
+
state = as_schema_3(rig, id="01-review-stopped-1", kind="review-stopped", answer="retry")
|
|
167
|
+
state["tickets"]["01"]["phase"] = "implement" # what the older driver's `retry` did
|
|
168
|
+
(rig.repo / ".agent/implement/state.json").write_text(json.dumps(state))
|
|
169
|
+
rig.run(run, *UNATTENDED)
|
|
170
|
+
assert rig.code == 0 and rig.state()["run"]["schema"] == 4, rig.ledger()
|
|
171
|
+
sentence = f"Ruling: 01 review runs again (retry): the implementer: it reported BLOCKED: {STOP}." # the older driver's
|
|
172
|
+
assert f"## Rulings\n\n- {sentence}\n" in rig.prs()[0]["body"]
|
|
173
|
+
assert rig.state()["run"]["questions"][0]["ruling"] == sentence
|
|
355
174
|
|
|
356
175
|
|
|
357
176
|
# ---------------------------------------------------------------- unattended
|
|
358
177
|
|
|
359
178
|
def test_unattended_writes_the_stage_file_and_prints_no_question(tmp_path, capsys):
|
|
360
|
-
rig = Pushing(tmp_path, ONE).run(steps(blocked(), impl("01")), *UNATTENDED)
|
|
179
|
+
rig = Pushing(tmp_path, ONE).run(steps(blocked(), blocked(), impl("01")), *UNATTENDED)
|
|
361
180
|
assert rig.code == 2 and "Question" not in rig.out
|
|
362
181
|
assert stage(rig) == {"stage": "implement", "status": "awaiting-review", "artifact": PAGE, "open_questions": 1}
|
|
363
|
-
write_answers(rig, {Q1: "
|
|
364
|
-
rig.run(steps(blocked(), impl("01")), *UNATTENDED)
|
|
182
|
+
write_answers(rig, {Q1: "retry"})
|
|
183
|
+
rig.run(steps(blocked(), blocked(), impl("01")), *UNATTENDED)
|
|
365
184
|
assert rig.code == 0 and stage(rig) == {"stage": "implement", "status": "done"}, "no stage file of the earlier run stays"
|
|
366
|
-
assert
|
|
185
|
+
assert "feat: 01 rows" in rig.pr_subjects()
|
|
367
186
|
|
|
368
187
|
|
|
369
188
|
def test_unattended_names_the_blocked_tickets_and_needs_a_stage_path_to_write(tmp_path):
|
|
370
189
|
rig = Pushing(tmp_path, ONE, gate={"red": ["ticket/feat%2Fcsv/01"]})
|
|
371
|
-
rig.run(plan(), "--unattended")
|
|
190
|
+
rig.run(plan(**{"01/fixer": [fix("01", n) for n in (1, 2)]}), "--unattended")
|
|
372
191
|
assert rig.code == 1 and not (rig.repo / ".agent/stage.json").exists()
|
|
373
|
-
rig.run(plan(), "--unattended", "--stage-json", ".agent/out/stage.json")
|
|
192
|
+
rig.run(plan(**{"01/fixer": [fix("01", n) for n in (1, 2)]}), "--unattended", "--stage-json", ".agent/out/stage.json")
|
|
374
193
|
assert json.loads((rig.repo / ".agent/out/stage.json").read_text()) == {
|
|
375
194
|
"stage": "implement", "status": "blocked", "blocked": ["01"]}
|
|
376
195
|
|
|
@@ -405,29 +224,39 @@ def test_a_template_of_another_shape_is_an_error_and_every_text_of_a_question_is
|
|
|
405
224
|
|
|
406
225
|
# ---------------------------------------------------------------- questions
|
|
407
226
|
|
|
408
|
-
def
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
assert
|
|
414
|
-
|
|
415
|
-
|
|
227
|
+
def test_only_an_implementer_or_a_fixer_blocked_on_the_contradiction_concern_disputes_and_names_its_locked_file():
|
|
228
|
+
contra = driver_report.CONTRADICTS
|
|
229
|
+
report = {"status": "BLOCKED", "concerns": [f"{contra} tests/test_01.py::test_x: why", "other",
|
|
230
|
+
f"{contra} test_01.py::test_x[a]: R3", f"{contra} b::c", contra]}
|
|
231
|
+
locked = ["tests/test_01.py", "src/test_01.py", "tests/b"]
|
|
232
|
+
assert driver_report.disputes("fixer", report, locked) == [
|
|
233
|
+
("tests/test_01.py", "tests/test_01.py::test_x", "why"), ("", "test_01.py::test_x[a]", "R3"),
|
|
234
|
+
("tests/b", "b::c", ""), ("", "", "")]
|
|
235
|
+
assert driver_report.disputes("fixer", report, locked[:1])[1] == ("tests/test_01.py", "test_01.py::test_x[a]", "R3")
|
|
236
|
+
assert driver_report.disputes("reviewer", report, locked) == []
|
|
237
|
+
assert driver_report.disputes("implementer", {**report, "status": "DONE"}, locked) == []
|
|
238
|
+
assert driver_report.disputes("implementer", {}, locked) == [], "a rejected report is no report"
|
|
416
239
|
|
|
417
240
|
|
|
418
241
|
def test_question_ids_count_per_ticket_and_kind_over_the_run_and_only_open_questions_are_published():
|
|
419
242
|
one = asked()
|
|
420
|
-
two, other, found = asked(before=[one]), asked(ticket="02", before=[one]), asked("
|
|
421
|
-
assert [q["id"] for q in (one, two, other, found)] == ["01-
|
|
243
|
+
two, other, found = asked(before=[one]), asked(ticket="02", before=[one]), asked("spec-ambiguous", before=[one])
|
|
244
|
+
assert [q["id"] for q in (one, two, other, found)] == ["01-ticket-blocked-1", "01-ticket-blocked-2",
|
|
245
|
+
"02-ticket-blocked-1", "01-spec-ambiguous-1"]
|
|
422
246
|
both = doc(one, two)
|
|
423
247
|
assert set(both["questions"][0]) == set(driver_decisions.PUBLIC) and len(both["questions"]) == 2
|
|
424
|
-
one["answer"] = "
|
|
248
|
+
one["answer"] = "retry"
|
|
425
249
|
left = doc(one, two)
|
|
426
|
-
assert [q["id"] for q in left["questions"]] == ["01-
|
|
427
|
-
assert driver_decisions.parked([one, two]) and
|
|
250
|
+
assert [q["id"] for q in left["questions"]] == ["01-ticket-blocked-2"] and left["revision"] != both["revision"]
|
|
251
|
+
assert driver_decisions.parked([one, two]) and driver_decisions.parked([one, found])
|
|
252
|
+
found["answer"] = "keep-test"
|
|
253
|
+
assert not driver_decisions.parked([one, found])
|
|
428
254
|
assert driver_decisions.text([], "answers.json", "page.html") == ""
|
|
429
|
-
for kind in driver_decisions.KINDS.
|
|
430
|
-
assert 2 <= len(kind.options) <= 4 and kind.recommended in kind.options
|
|
255
|
+
for name, kind in driver_decisions.KINDS.items():
|
|
256
|
+
assert 2 <= len(kind.options) <= 4 and (kind.recommended in kind.options or name == "spec-ambiguous")
|
|
257
|
+
unrecommended = asked("spec-ambiguous", subject="tests/a.py::t, R3: the first reading: x; the second reading: y")
|
|
258
|
+
out = driver_decisions.text([unrecommended], "answers.json", "page.html")
|
|
259
|
+
assert "(recommended)" not in out and " keep-test: " in out and unrecommended["recommended"] == ""
|
|
431
260
|
|
|
432
261
|
|
|
433
262
|
# ---------------------------------------------------------------- the answers file
|
|
@@ -442,7 +271,7 @@ def one(tmp_path, monkeypatch):
|
|
|
442
271
|
|
|
443
272
|
def answers(document, **fields):
|
|
444
273
|
body = {"v": 1, "stage": "implement", "submitted": "approve", "revision": document["revision"],
|
|
445
|
-
"answers": {Q1: "
|
|
274
|
+
"answers": {Q1: "retry"}, **fields}
|
|
446
275
|
driver_answers.FILE.write_text(json.dumps(body))
|
|
447
276
|
return driver_answers.read(document)
|
|
448
277
|
|
|
@@ -453,7 +282,7 @@ def answers(document, **fields):
|
|
|
453
282
|
({"submitted": None}, "it is a draft: `submitted` is not set"),
|
|
454
283
|
({"stage": "plan"}, "it is not a version 1 file of the implement stage"),
|
|
455
284
|
({"v": 2}, "it is not a version 1 file of the implement stage"),
|
|
456
|
-
({"answers": ["
|
|
285
|
+
({"answers": ["retry"]}, "it is not an object with an `answers` object")])
|
|
457
286
|
def test_a_file_that_is_not_a_submission_for_this_revision_gives_no_answer(one, fields, why):
|
|
458
287
|
found, (ignored,) = answers(one, **fields)
|
|
459
288
|
assert found == {} and ignored.startswith(f"The answers file .agent/implement-answers.json is ignored: {why}")
|
|
@@ -467,128 +296,176 @@ def test_a_file_that_is_not_a_json_object_gives_no_answer(one, content):
|
|
|
467
296
|
|
|
468
297
|
|
|
469
298
|
def test_each_answer_is_checked_on_its_own_and_a_note_goes_with_its_question(one):
|
|
470
|
-
found, ignored = answers(one, answers={Q1: "
|
|
471
|
-
"02-
|
|
472
|
-
assert found == {Q1: "
|
|
299
|
+
found, ignored = answers(one, answers={Q1: "retry", f"{Q1}.note": "see ADR 3", "track": "standard",
|
|
300
|
+
"02-spec-ambiguous-1.note": "x"})
|
|
301
|
+
assert found == {Q1: "retry", f"{Q1}.note": "see ADR 3"}
|
|
473
302
|
assert ignored == ["The answer for track in .agent/implement-answers.json is ignored: there is no open question track.",
|
|
474
|
-
"The answer for 02-
|
|
475
|
-
"question 02-
|
|
476
|
-
found, (ignored,) = answers(one, answers={Q1: ["
|
|
477
|
-
assert found == {} and ignored.endswith("the question offers
|
|
303
|
+
"The answer for 02-spec-ambiguous-1.note in .agent/implement-answers.json is ignored: there is "
|
|
304
|
+
"no open question 02-spec-ambiguous-1."]
|
|
305
|
+
found, (ignored,) = answers(one, answers={Q1: ["retry"], f"{Q1}.note": 5})
|
|
306
|
+
assert found == {} and ignored.endswith("the question offers retry, edit.")
|
|
478
307
|
|
|
479
308
|
|
|
480
309
|
def test_no_open_question_or_no_file_reads_nothing_and_given_writes_only_valid_answers(one):
|
|
481
310
|
assert driver_answers.read(one) == ({}, [])
|
|
482
311
|
assert driver_answers.given([], one) == [] and not driver_answers.FILE.exists()
|
|
483
|
-
assert driver_answers.given([(Q1, "
|
|
312
|
+
assert driver_answers.given([(Q1, "retry"), ("zz", "accept")], one) == ["--answer zz=accept: no open question zz"]
|
|
484
313
|
assert not driver_answers.FILE.exists()
|
|
485
|
-
assert driver_answers.given([(Q1, "
|
|
486
|
-
assert driver_answers.read(one) == ({Q1: "
|
|
314
|
+
assert driver_answers.given([(Q1, "retry")], one) == []
|
|
315
|
+
assert driver_answers.read(one) == ({Q1: "retry"}, [])
|
|
487
316
|
assert driver_answers.read(doc()) == ({}, []), "with no open question the file is history"
|
|
488
317
|
|
|
489
318
|
|
|
490
|
-
# ----------------------------------------------------------------
|
|
319
|
+
# ---------------------------------------------------------------- a stop or a rejection: the rerun, then ticket-blocked
|
|
491
320
|
|
|
492
|
-
|
|
493
|
-
|
|
321
|
+
SONNET, OPUS_5_5, ASTRA = "claude-sonnet-5-5@medium", "claude-opus-5-5@medium", "openai/gpt-6-astra@medium"
|
|
322
|
+
TWO = {"implementer": [SONNET, OPUS_5_5], "reviewer": [ASTRA, OPUS_5_5]}
|
|
323
|
+
TB1 = "01-ticket-blocked-1"
|
|
324
|
+
NO_ACCESS = "no write access to fixtures/"
|
|
325
|
+
NO_FINDINGS = "report: 'findings' is a required property"
|
|
326
|
+
# 01 and 02 are independent, 03 waits on 01.
|
|
327
|
+
TRIO = {"01-export-rows.md": ticket("01", "Export rows"),
|
|
328
|
+
"02-quote-fields.md": ticket("02", "Quote fields", touches="`demo/other.py: g`"),
|
|
329
|
+
"03-cli-flag.md": ticket("03", "CLI flag", "01", touches="`demo/cli.py: main`")}
|
|
494
330
|
|
|
495
331
|
|
|
496
|
-
def
|
|
497
|
-
""
|
|
498
|
-
|
|
499
|
-
|
|
332
|
+
def stops(status="NEEDS_CONTEXT", concern="the ticket names no column order", role="implementer", **step):
|
|
333
|
+
report = {"status": status, "commits": [], "files": [], "concerns": [concern], "green": [],
|
|
334
|
+
**{"fixer": {"ticket": "01"}, "test-writer": {"locked": [], "red": []}}.get(role, {})}
|
|
335
|
+
return {"report": report, **step}
|
|
500
336
|
|
|
501
337
|
|
|
502
|
-
def
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
338
|
+
def left_wip():
|
|
339
|
+
"""The rerun's stop, with a commit: the tip the ticket leaves."""
|
|
340
|
+
step = stops("BLOCKED", NO_ACCESS, files={"demo/export.py": "wip = 1\n"}, commit="wip: 01")
|
|
341
|
+
step["report"].update(commits=["$SHA"], files=["demo/export.py"])
|
|
342
|
+
return step
|
|
506
343
|
|
|
507
344
|
|
|
508
|
-
def
|
|
509
|
-
""
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
345
|
+
def entries(rig, nn, role):
|
|
346
|
+
return [agent["entry"] for agent in rig.state()["run"]["agents"] if (agent["ticket"], agent["role"]) == (nn, role)]
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
def trio(tmp_path, *implementers):
|
|
350
|
+
"""Run 1 of TRIO with 01's implementer steps; 02 writes its own file, so 01 merges after it with no conflict."""
|
|
351
|
+
rig = Inside(tmp_path, TRIO, models=TWO)
|
|
352
|
+
return rig, plan(**{"01/implementer": list(implementers), "02/implementer": [impl("02", "demo/other.py")]})
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
def test_a_stopped_implementer_runs_again_on_its_second_entry_with_its_concern_and_asks_nothing(tmp_path):
|
|
356
|
+
rig = Inside(tmp_path, ONE, models=TWO).run(steps(stops(concern="which CSV dialect?"), impl("01")))
|
|
513
357
|
assert rig.code == 0 and rig.state()["tickets"]["01"]["phase"] == "merged", rig.ledger()
|
|
514
|
-
assert
|
|
515
|
-
|
|
516
|
-
assert
|
|
517
|
-
assert rig.calls("01", "reviewer")[0]["head"] == corrected
|
|
518
|
-
assert "list no commit" in rig.prompt("implementer-0")
|
|
358
|
+
assert entries(rig, "01", "implementer") == [SONNET, OPUS_5_5]
|
|
359
|
+
assert "which CSV dialect?" in rig.calls("01", "implementer")[1]["prompt"]
|
|
360
|
+
assert not rig.state()["run"]["questions"] and rig.state()["run"]["stops"] == 0
|
|
519
361
|
|
|
520
362
|
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
"""
|
|
524
|
-
rig = Inside(tmp_path, ONE).run(
|
|
363
|
+
def test_a_rejected_review_report_runs_again_on_the_second_reviewer_entry_with_the_error(tmp_path):
|
|
364
|
+
bad = review("01")
|
|
365
|
+
del bad["report"]["findings"]
|
|
366
|
+
rig = Inside(tmp_path, ONE, models=TWO).run(plan(**{"01/reviewer": [bad]}))
|
|
367
|
+
assert rig.code == 0 and rig.state()["tickets"]["01"]["phase"] == "merged", rig.ledger()
|
|
368
|
+
assert entries(rig, "01", "reviewer") == [ASTRA, OPUS_5_5]
|
|
369
|
+
assert NO_FINDINGS in rig.calls("01", "reviewer")[1]["prompt"]
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
def test_a_role_with_one_entry_that_stops_runs_again_on_that_entry(tmp_path):
|
|
373
|
+
rig = Inside(tmp_path, ONE).run(plan(**{"01/test-writer": [stops(role="test-writer"), tw("01")]}))
|
|
374
|
+
assert rig.code == 0 and rig.state()["tickets"]["01"]["phase"] == "merged", rig.ledger()
|
|
375
|
+
(one,) = set(entries(rig, "01", "test-writer"))
|
|
376
|
+
assert len(entries(rig, "01", "test-writer")) == 2 and one == "anthropic/claude-opus-5@medium"
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
def test_a_second_stop_blocks_the_ticket_with_one_ticket_blocked_question(tmp_path):
|
|
380
|
+
rig = Inside(tmp_path, ONE, models=TWO).run(steps(stops(), stops("BLOCKED", NO_ACCESS)))
|
|
525
381
|
assert rig.code == 2 and rig.state()["tickets"]["01"]["phase"] == "blocked", rig.ledger()
|
|
526
382
|
(question,) = rig.state()["run"]["questions"]
|
|
527
|
-
assert (question["id"], question["recommended"]) == (
|
|
528
|
-
assert [o["id"] for o in question["options"]] == ["retry", "
|
|
383
|
+
assert (question["id"], question["kind"], question["recommended"]) == (TB1, "ticket-blocked", "retry")
|
|
384
|
+
assert [o["id"] for o in question["options"]] == ["retry", "edit"]
|
|
385
|
+
assert "implementer" in question["subject"] and NO_ACCESS in question["subject"]
|
|
529
386
|
assert question["evidence"][0] == ".agent/implement/01/implementer-0.json"
|
|
530
|
-
assert
|
|
531
|
-
rig.run(steps(stops(status=status), impl("01")), "--answer", f"{IMPLEMENTER_STOPPED}=retry")
|
|
532
|
-
assert rig.code == 0 and rig.state()["tickets"]["01"]["phase"] == "merged", rig.ledger()
|
|
533
|
-
assert len(rig.calls("01", "implementer")) == 2 and len(rig.calls("01", "test-writer")) == 1
|
|
534
|
-
assert rig.led(f"Ruling: 01 implementer runs again (retry): the implementer reported {status}")
|
|
387
|
+
assert entries(rig, "01", "implementer") == [SONNET, OPUS_5_5]
|
|
535
388
|
|
|
536
389
|
|
|
537
|
-
def
|
|
538
|
-
rig =
|
|
390
|
+
def test_a_ticket_blocked_question_holds_only_its_ticket_and_those_that_wait_on_it(tmp_path):
|
|
391
|
+
rig, run = trio(tmp_path, stops(), stops("BLOCKED", NO_ACCESS))
|
|
392
|
+
rig.run(run)
|
|
539
393
|
assert rig.code == 2, rig.ledger()
|
|
540
|
-
rig.
|
|
541
|
-
assert
|
|
542
|
-
|
|
543
|
-
assert
|
|
544
|
-
assert rig.calls("
|
|
394
|
+
tickets = rig.state()["tickets"]
|
|
395
|
+
assert [q["id"] for q in rig.state()["run"]["questions"]] == [TB1]
|
|
396
|
+
assert (tickets["01"]["phase"], tickets["02"]["phase"], tickets["03"]["phase"]) == ("blocked", "merged", "pending")
|
|
397
|
+
assert "feat: 02 rows" in rig.pr_subjects() and not rig.calls("03")
|
|
398
|
+
assert rig.led("End-of-run work skipped") and not rig.calls("final", "final-reviewer")
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
def test_retry_runs_the_role_on_its_first_entry_from_the_tip_it_left_and_resumes_only_its_ticket(tmp_path):
|
|
402
|
+
rig, run = trio(tmp_path, stops(), left_wip(), impl("01"))
|
|
403
|
+
rig.run(run)
|
|
404
|
+
wip, done_02 = rig.calls("01", "implementer")[1]["sha"], len(rig.calls("02"))
|
|
405
|
+
assert rig.code == 2 and rig.state()["tickets"]["01"]["tip"] == wip, rig.ledger()
|
|
406
|
+
rig.run(run, "--answer", f"{TB1}=retry")
|
|
407
|
+
assert rig.code == 0 and {e["phase"] for e in rig.state()["tickets"].values()} == {"merged"}, rig.ledger()
|
|
408
|
+
assert rig.led("Ruling: 01 runs again (retry): the implementer")
|
|
409
|
+
resumed = rig.calls("01", "implementer")[2]
|
|
410
|
+
assert entries(rig, "01", "implementer") == [SONNET, OPUS_5_5, SONNET] and resumed["head"] == wip
|
|
411
|
+
assert len(rig.calls("02")) == done_02
|
|
412
|
+
assert rig.calls("03")[0]["t0"] > resumed["t1"] and "feat: 01 rows" in rig.calls("03")[0]["pr_log"]
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
def test_edit_keeps_the_ticket_blocked_with_the_ruling_and_runs_no_agent_of_it(tmp_path):
|
|
416
|
+
rig = Inside(tmp_path, ONE, models=TWO).run(steps(stops(), stops("BLOCKED", NO_ACCESS)))
|
|
417
|
+
seen = len(rig.calls("01"))
|
|
418
|
+
rig.run(steps(stops(), stops("BLOCKED", NO_ACCESS), impl("01")), "--answer", f"{TB1}=edit")
|
|
419
|
+
assert rig.code == 1 and rig.state()["tickets"]["01"]["phase"] == "blocked", rig.ledger()
|
|
420
|
+
assert rig.led("Ruling: 01 stays BLOCKED", "(edit)") and len(rig.calls("01")) == seen
|
|
545
421
|
|
|
546
422
|
|
|
547
|
-
def
|
|
548
|
-
rig =
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
assert
|
|
423
|
+
def test_two_blocked_tickets_put_both_questions_in_decisions_and_on_the_one_page(tmp_path):
|
|
424
|
+
rig, run = trio(tmp_path, stops(), stops())
|
|
425
|
+
run["02/implementer"] = [stops(), stops()]
|
|
426
|
+
rig.run(run)
|
|
427
|
+
assert rig.code == 2, rig.ledger()
|
|
428
|
+
ids = ["01-ticket-blocked-1", "02-ticket-blocked-1"]
|
|
429
|
+
assert sorted(q["id"] for q in decisions(rig)["questions"]) == ids
|
|
430
|
+
html = (rig.repo / PAGE).read_text()
|
|
431
|
+
assert all(f'data-q="{qid}"' in html for qid in ids)
|
|
552
432
|
|
|
553
433
|
|
|
554
|
-
def
|
|
555
|
-
"""
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
rig = Inside(tmp_path, ONE).run(
|
|
434
|
+
def test_a_fixer_that_stops_twice_blocks_and_retry_runs_its_round_again_after_a_review(tmp_path):
|
|
435
|
+
"""The round that stopped does not count: `retry` reviews the tip the fixer left, then a fixer runs that round."""
|
|
436
|
+
run = plan(**{"01/reviewer": [review("01", [STUCK]), review("01", [STUCK]), review("01")],
|
|
437
|
+
"01/fixer": [stops(role="fixer"), stops(role="fixer"), fix("01", 1)]})
|
|
438
|
+
rig = Inside(tmp_path, ONE).run(run)
|
|
559
439
|
assert rig.code == 2 and rig.state()["tickets"]["01"]["round"] == 0, rig.ledger()
|
|
560
440
|
(question,) = rig.state()["run"]["questions"]
|
|
561
|
-
assert (question["id"], question["
|
|
562
|
-
|
|
563
|
-
assert question["evidence"][0] == ".agent/implement/01/fixer-1.json"
|
|
564
|
-
rig.run(steps, "--answer", f"{FIXER_STOPPED}=retry")
|
|
441
|
+
assert (question["id"], question["evidence"][0]) == (TB1, ".agent/implement/01/fixer-1.json")
|
|
442
|
+
rig.run(run, "--answer", f"{TB1}=retry")
|
|
565
443
|
assert rig.code == 0 and rig.state()["tickets"]["01"]["phase"] == "merged", rig.ledger()
|
|
566
|
-
assert rig.state()["tickets"]["01"]["round"] == 1 and len(rig.calls("01", "fixer")) ==
|
|
567
|
-
assert rig.led("Ruling: 01 fix round runs again (retry): the fixer reported NEEDS_CONTEXT")
|
|
444
|
+
assert rig.state()["tickets"]["01"]["round"] == 1 and len(rig.calls("01", "fixer")) == 3
|
|
568
445
|
|
|
569
446
|
|
|
570
|
-
|
|
447
|
+
def test_the_rerun_of_fix_round_2_wraps_to_the_first_implementer_entry(tmp_path):
|
|
448
|
+
run = plan(**{"01/reviewer": [review("01", [STUCK])] * 2 + [review("01")],
|
|
449
|
+
"01/fixer": [fix("01", 1), stops(role="fixer"), fix("01", 2)]})
|
|
450
|
+
rig = Inside(tmp_path, ONE, models=TWO).run(run)
|
|
451
|
+
assert rig.code == 0, rig.ledger()
|
|
452
|
+
assert entries(rig, "01", "fixer") == [SONNET, OPUS_5_5, SONNET]
|
|
571
453
|
|
|
572
|
-
REJECTED = "01-review-rejected-1"
|
|
573
|
-
NO_PROOF = "mutations: no mutation proof for the locked test file tests/test_01b.py"
|
|
574
454
|
|
|
455
|
+
def test_only_two_kinds_exist():
|
|
456
|
+
assert list(driver_decisions.KINDS) == ["spec-ambiguous", "ticket-blocked"]
|
|
575
457
|
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
rig.run(steps, "--answer", f"{REJECTED}=retry")
|
|
588
|
-
assert rig.code == 0 and rig.state()["tickets"]["01"]["phase"] == "merged", rig.ledger()
|
|
589
|
-
assert len(rig.calls("01", "reviewer")) == 3
|
|
590
|
-
assert rig.led(f"Ruling: 01 review runs again (retry): the reviewer: {NO_PROOF}")
|
|
591
|
-
assert NO_PROOF in rig.calls("01", "reviewer")[2]["prompt"]
|
|
458
|
+
|
|
459
|
+
# ---------------------------------------------------------------- a test-writer report; a question of a merged ticket
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
def two_locked():
|
|
463
|
+
"""A test-writer that locks two files."""
|
|
464
|
+
step = tw("01")
|
|
465
|
+
step["files"]["tests/test_01b.py"] = "def test_y():\n assert 1 == 'y'\n"
|
|
466
|
+
step["report"] = {**step["report"], "locked": ["tests/test_01.py", "tests/test_01b.py"],
|
|
467
|
+
"files": ["tests/test_01.py", "tests/test_01b.py"]}
|
|
468
|
+
return step
|
|
592
469
|
|
|
593
470
|
|
|
594
471
|
def test_a_test_writer_report_that_locks_a_file_it_deleted_is_rejected(tmp_path):
|
|
@@ -604,21 +481,21 @@ def test_a_test_writer_report_that_locks_a_file_it_deleted_is_rejected(tmp_path)
|
|
|
604
481
|
|
|
605
482
|
def test_a_question_of_a_ticket_that_merged_is_dropped_and_does_not_park_the_run(tmp_path, capsys):
|
|
606
483
|
"""Issue #136: the operator set a stopped ticket to `merge` by hand; its question stayed open, with exit 2."""
|
|
607
|
-
rig = Inside(tmp_path, ONE).run(steps(stops()))
|
|
484
|
+
rig = Inside(tmp_path, ONE).run(steps(stops(), stops()))
|
|
608
485
|
assert rig.code == 2, rig.ledger()
|
|
609
486
|
capsys.readouterr()
|
|
610
487
|
path = rig.repo / ".agent/implement/state.json"
|
|
611
488
|
state = json.loads(path.read_text())
|
|
612
489
|
state["tickets"]["01"]["phase"] = "merge"
|
|
613
490
|
path.write_text(json.dumps(state))
|
|
614
|
-
rig.run(steps(stops()))
|
|
491
|
+
rig.run(steps(stops(), stops()))
|
|
615
492
|
assert rig.code == 0 and rig.state()["tickets"]["01"]["phase"] == "merged", rig.ledger()
|
|
616
|
-
assert decisions(rig)["questions"] == [] and
|
|
617
|
-
assert rig.led(f"Ticket 01: the question {
|
|
493
|
+
assert decisions(rig)["questions"] == [] and TB1 not in capsys.readouterr().out
|
|
494
|
+
assert rig.led(f"Ticket 01: the question {TB1} is dropped: the ticket merged.")
|
|
618
495
|
|
|
619
496
|
|
|
620
497
|
def test_dropping_the_questions_of_merged_tickets_keeps_the_answered_ones_and_those_of_other_tickets():
|
|
621
498
|
state = {"tickets": {"01": {"phase": "merged"}, "02": {"phase": "blocked"}},
|
|
622
499
|
"run": {"questions": [asked(), {**asked(stop=2), "id": "01-x", "answer": "accept"}, asked(ticket="02")]}}
|
|
623
|
-
assert [q["id"] for q in driver_decisions.drop_merged(state)] == ["01-
|
|
624
|
-
assert [q["id"] for q in state["run"]["questions"]] == ["01-x", "02-
|
|
500
|
+
assert [q["id"] for q in driver_decisions.drop_merged(state)] == ["01-ticket-blocked-1"]
|
|
501
|
+
assert [q["id"] for q in state["run"]["questions"]] == ["01-x", "02-ticket-blocked-1"]
|