@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
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"""Human stops as bounded questions: the question kinds, decisions.json and what an answer does.
|
|
2
2
|
|
|
3
3
|
A question in state.json `run.questions`; `answer` is None while it is open:
|
|
4
|
-
{id, title, why, evidence, options: [{id, description}], recommended, ticket, kind, subject, stop, answer
|
|
4
|
+
{id, title, why, evidence, options: [{id, description}], recommended, ticket, kind, subject, stop, answer,
|
|
5
|
+
resume: {phase[, tip][, round]}, the record fields a `retry` or a `keep-test` sets (`Resume`),
|
|
6
|
+
ruling: the ruling sentence, once answered}
|
|
5
7
|
decisions.json: {run: <run.revision>, questions: [the open ones, first six fields], revision: <SHA-256 of the rest>}."""
|
|
6
8
|
from __future__ import annotations
|
|
7
9
|
|
|
@@ -10,186 +12,75 @@ import json
|
|
|
10
12
|
from typing import NamedTuple
|
|
11
13
|
|
|
12
14
|
PUBLIC = ("id", "title", "why", "evidence", "options", "recommended")
|
|
13
|
-
|
|
15
|
+
FINAL = "final" # the end of run asks its questions, and has its record and its files, under this name
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def owner(ticket: str) -> str:
|
|
19
|
+
"""Who stops: `Ticket NN` or the end of run."""
|
|
20
|
+
return "End of run" if ticket == FINAL else f"Ticket {ticket}"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class Resume(NamedTuple):
|
|
24
|
+
"""Where a `retry` or a `keep-test` takes a ticket, or the end of run, back to."""
|
|
25
|
+
phase: str
|
|
26
|
+
tip: str | None = None # the tip it goes on from, for a role that commits
|
|
27
|
+
round: int | None = None # the fix rounds done, for a fixer: its own round runs again
|
|
28
|
+
|
|
29
|
+
def fields(self) -> dict:
|
|
30
|
+
"""The fields of the record; one that is None stays as it is."""
|
|
31
|
+
return {name: value for name, value in self._asdict().items() if value is not None}
|
|
14
32
|
|
|
15
33
|
|
|
16
34
|
class Option(NamedTuple):
|
|
17
35
|
description: str
|
|
18
36
|
ruling: str
|
|
19
|
-
|
|
37
|
+
resumes: bool # the record goes back to the `resume` of the question
|
|
38
|
+
fields: dict = {} # what else the record gets when its stop is settled; no field at all keeps it BLOCKED
|
|
20
39
|
|
|
21
40
|
|
|
22
41
|
class Kind(NamedTuple):
|
|
23
|
-
parks: bool # an open question of this kind ends the run with exit 2
|
|
24
42
|
title: str
|
|
25
43
|
why: str
|
|
26
|
-
recommended: str
|
|
44
|
+
recommended: str # "" for a kind that recommends no option
|
|
27
45
|
options: dict[str, Option]
|
|
28
46
|
|
|
29
47
|
|
|
30
48
|
KINDS = {
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
{"
|
|
38
|
-
"The test is
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"The test
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
{
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
"Keep the ticket BLOCKED. The open part becomes a ticket of its own.",
|
|
56
|
-
"Ruling: {ticket} stays BLOCKED, the open part becomes a new ticket (split): {subject}.", {}),
|
|
57
|
-
"redesign": Option(
|
|
58
|
-
"Keep the ticket BLOCKED. The design changes before more work on it.",
|
|
59
|
-
"Ruling: {ticket} stays BLOCKED, the design changes first (redesign): {subject}.", {})}),
|
|
60
|
-
"locked-test-again": Kind(
|
|
61
|
-
True,
|
|
62
|
-
"Ticket {ticket}: a locked-test finding is open after the test-writer correction: {subject}",
|
|
63
|
-
"The test-writer correction did not close this finding on the locked tests: the review after it found it "
|
|
64
|
-
"again, or the driver rejected the correction (the ledger line says which). Ticket {ticket} is BLOCKED and "
|
|
65
|
-
"each ticket that it blocks waits.",
|
|
66
|
-
"correct-again",
|
|
67
|
-
{"correct-again": Option(
|
|
68
|
-
"The test-writer corrects the locked tests once more, from the next review. Then the fix rounds go on.",
|
|
69
|
-
"Ruling: {ticket} locked-test finding goes back to the test-writer for one more correction "
|
|
70
|
-
"(correct-again): {subject}.", {"phase": "review"}),
|
|
71
|
-
"accept": Option(
|
|
72
|
-
"Close the finding as it is: the locked tests stay as they are, and no more correction runs for the "
|
|
73
|
-
"ticket. The ticket goes on to its fix rounds with its other findings.",
|
|
74
|
-
"Ruling: {ticket} locked-test finding closed as it is (accept): {subject}.", {"phase": "review"}),
|
|
75
|
-
"redesign": Option(
|
|
76
|
-
"Keep the ticket BLOCKED. The design changes before more work on it.",
|
|
77
|
-
"Ruling: {ticket} stays BLOCKED, the design changes first (redesign): {subject}.", {})}),
|
|
78
|
-
"review-stopped": Kind(
|
|
79
|
-
True,
|
|
80
|
-
"Ticket {ticket}: an agent of the review stopped: {subject}",
|
|
81
|
-
"The reviewer or the correctness pass of ticket {ticket} reported BLOCKED or NEEDS_CONTEXT, so the review "
|
|
82
|
-
"did not end. Ticket {ticket} is BLOCKED and each ticket that it blocks waits.",
|
|
83
|
-
"retry",
|
|
84
|
-
{"retry": Option(
|
|
85
|
-
"The review runs again, with each of its agents.",
|
|
86
|
-
"Ruling: {ticket} review runs again (retry): {subject}.", {"phase": "review"}),
|
|
87
|
-
"accept": Option(
|
|
88
|
-
"The review runs again, and from now on a BLOCKED or NEEDS_CONTEXT report of this agent does not stop "
|
|
89
|
-
"the ticket: the review goes on with its findings and those of the other reports.",
|
|
90
|
-
"Ruling: {ticket} review goes on past this stop (accept): {subject}.", {"phase": "review"}),
|
|
91
|
-
"redesign": Option(
|
|
92
|
-
"Keep the ticket BLOCKED. The design changes before more work on it.",
|
|
93
|
-
"Ruling: {ticket} stays BLOCKED, the design changes first (redesign): {subject}.", {})}),
|
|
94
|
-
"review-rejected": Kind(
|
|
95
|
-
True,
|
|
96
|
-
"Ticket {ticket}: the driver rejected an agent of the review two times: {subject}",
|
|
97
|
-
"The driver rejected the report of the reviewer or the correctness pass of ticket {ticket}, and the report of "
|
|
98
|
-
"its rerun too, so the review did not end. Ticket {ticket} is BLOCKED and each ticket that it blocks waits.",
|
|
49
|
+
"spec-ambiguous": Kind(
|
|
50
|
+
"Ticket {ticket}: the spec reads two ways on a locked test: {subject}",
|
|
51
|
+
"This locked test was ruled on or corrected once in ticket {ticket}, and a second dispute or a second "
|
|
52
|
+
"correction needs it again: the spec supports both readings. Ticket {ticket} is BLOCKED and each ticket that "
|
|
53
|
+
"it blocks waits.",
|
|
54
|
+
"",
|
|
55
|
+
{"keep-test": Option(
|
|
56
|
+
"The test stands as it is. The role that disputed it runs again and makes it green; a review finding that "
|
|
57
|
+
"asks to correct it again is closed.",
|
|
58
|
+
"Ruling: {ticket} locked test stands (keep-test): {subject}.", True),
|
|
59
|
+
"correct-test": Option(
|
|
60
|
+
"The test-writer corrects the test once more, to the second reading, then the role that disputed it runs "
|
|
61
|
+
"again (a fixer after the review of its round); after a review finding, the review runs again.",
|
|
62
|
+
"Ruling: {ticket} locked test is corrected to the second reading (correct-test): {subject}.", False,
|
|
63
|
+
{"phase": "test-writer", "note": "correction"}),
|
|
64
|
+
"edit-spec": Option(
|
|
65
|
+
"Keep the ticket BLOCKED, so the spec can be edited to say which reading it means.",
|
|
66
|
+
"Ruling: {ticket} stays BLOCKED for an edit of the spec (edit-spec): {subject}.", False)}),
|
|
67
|
+
# The end of run asks it too, with the ticket `final`: for an agent, or for a finding open after the scoped review.
|
|
68
|
+
"ticket-blocked": Kind(
|
|
69
|
+
"{owner}: an agent stopped or was rejected, and its rerun too, or a final-review finding is open: {subject}",
|
|
70
|
+
"An agent ran two times, the second time on the next entry of its model list, and stopped or was rejected "
|
|
71
|
+
"both times; or the scoped review after the fix batch of the final review left a finding open. {owner} is "
|
|
72
|
+
"BLOCKED, each ticket that it blocks waits, and nothing is pushed.",
|
|
99
73
|
"retry",
|
|
100
74
|
{"retry": Option(
|
|
101
|
-
"The
|
|
102
|
-
"
|
|
103
|
-
"Ruling: {ticket}
|
|
104
|
-
"
|
|
105
|
-
"Keep the ticket
|
|
106
|
-
"Ruling: {ticket} stays BLOCKED
|
|
107
|
-
"implementer-stopped": Kind(
|
|
108
|
-
True,
|
|
109
|
-
"Ticket {ticket}: the implementer stopped: {subject}",
|
|
110
|
-
"The implementer of ticket {ticket} reported BLOCKED or NEEDS_CONTEXT, and no concern says that a locked test "
|
|
111
|
-
"contradicts the spec. Ticket {ticket} is BLOCKED and each ticket that it blocks waits.",
|
|
112
|
-
"retry",
|
|
113
|
-
{"retry": Option(
|
|
114
|
-
"The implementer runs again from the tip it left.",
|
|
115
|
-
"Ruling: {ticket} implementer runs again (retry): {subject}.", {"phase": "implement"}),
|
|
116
|
-
"accept-tip": Option(
|
|
117
|
-
"The implementer does not run again: the driver gates and reviews the tip it left, and the fix rounds "
|
|
118
|
-
"close what the review finds.",
|
|
119
|
-
"Ruling: {ticket} tip goes to the gate and the review as it is (accept-tip): {subject}.",
|
|
120
|
-
{"phase": "gate"}),
|
|
121
|
-
"redesign": Option(
|
|
122
|
-
"Keep the ticket BLOCKED. The design changes before more work on it.",
|
|
123
|
-
"Ruling: {ticket} stays BLOCKED, the design changes first (redesign): {subject}.", {})}),
|
|
124
|
-
"fixer-stopped": Kind(
|
|
125
|
-
True,
|
|
126
|
-
"Ticket {ticket}: the fixer stopped: {subject}",
|
|
127
|
-
"The fixer of ticket {ticket} reported BLOCKED or NEEDS_CONTEXT, and no concern says that a locked test "
|
|
128
|
-
"contradicts the spec. Ticket {ticket} is BLOCKED and each ticket that it blocks waits.",
|
|
129
|
-
"retry",
|
|
130
|
-
{"retry": Option(
|
|
131
|
-
"The round that stopped does not count: the driver gates and reviews the tip the fixer left, and a fixer "
|
|
132
|
-
"runs that round again on what the review finds.",
|
|
133
|
-
"Ruling: {ticket} fix round runs again (retry): {subject}.", {"phase": "review"}),
|
|
134
|
-
"redesign": Option(
|
|
135
|
-
"Keep the ticket BLOCKED. The design changes before more work on it.",
|
|
136
|
-
"Ruling: {ticket} stays BLOCKED, the design changes first (redesign): {subject}.", {})}),
|
|
137
|
-
"merged-locked-file": Kind(
|
|
138
|
-
True,
|
|
139
|
-
"Ticket {ticket}: the landing would change the locked file of a merged ticket: {subject}",
|
|
140
|
-
"The landing check found that ticket {ticket} changes this locked file of a merged ticket, so the PR branch "
|
|
141
|
-
"did not move. Ticket {ticket} is BLOCKED and each ticket that it blocks waits.",
|
|
142
|
-
"restore",
|
|
143
|
-
{"restore": Option(
|
|
144
|
-
"The driver puts the file back to the version of the PR branch in a commit of its own on the ticket "
|
|
145
|
-
"branch, then the landing runs again with its gate. A red gate takes the commit back and asks again.",
|
|
146
|
-
"Ruling: {ticket} lands with {subject} put back to the version of the PR branch (restore).",
|
|
147
|
-
{"phase": "merge"}),
|
|
148
|
-
"adopt": Option(
|
|
149
|
-
"The ticket locks the file, so its change lands: the merged ticket's tests in it become the ticket's own. "
|
|
150
|
-
"The landing runs again with its gate. A red gate asks again.",
|
|
151
|
-
"Ruling: {ticket} locks {subject} and lands its change to it (adopt).", {"phase": "merge"}),
|
|
152
|
-
"redesign": Option(
|
|
153
|
-
"Keep the ticket BLOCKED. The design changes before more work on it.",
|
|
154
|
-
"Ruling: {ticket} stays BLOCKED, the design changes first (redesign): {subject}.", {})}),
|
|
155
|
-
# A final-review question belongs to no ticket: its `ticket` is "".
|
|
156
|
-
"final-finding": Kind(
|
|
157
|
-
True,
|
|
158
|
-
"Final review: a finding is open after the second review round: {subject}",
|
|
159
|
-
"The final review ran its two rounds and this finding is open. Nothing is pushed while it is open.",
|
|
160
|
-
"fix",
|
|
161
|
-
{"fix": Option(
|
|
162
|
-
"Keep the finding open. The run ends with nothing pushed, and the finding is fixed before a push.",
|
|
163
|
-
"Ruling: final-review finding stays open and nothing is pushed (fix): {subject}.", {}),
|
|
164
|
-
"accept": Option(
|
|
165
|
-
"Close the finding as it is. The branch can be pushed when each open finding is accepted.",
|
|
166
|
-
"Ruling: final-review finding closed as it is (accept): {subject}.", {})}),
|
|
75
|
+
"The role runs again on its first entry from the tip the ticket left, with its one rerun on the next "
|
|
76
|
+
"entry; for an open final-review finding, one more fix batch and scoped review run.",
|
|
77
|
+
"Ruling: {ticket} runs again (retry): {subject}.", True),
|
|
78
|
+
"edit": Option(
|
|
79
|
+
"Keep it BLOCKED, so the spec or the ticket can be edited before more work on it.",
|
|
80
|
+
"Ruling: {ticket} stays BLOCKED for an edit of the spec or the ticket (edit): {subject}.", False)}),
|
|
167
81
|
}
|
|
168
82
|
|
|
169
83
|
|
|
170
|
-
AGAIN = 2 # the extra corrections a ticket may get: a test-writer and a reviewer that never agree cannot loop
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
def corrections(questions: list[dict], ticket: str) -> tuple[int, bool]:
|
|
174
|
-
"""(the extra corrections that the `locked-test-again` stops of `ticket` gave, whether one stop accepted its
|
|
175
|
-
findings). A stop with one `correct-again` answer gives one correction; a stop with only `accept` accepts."""
|
|
176
|
-
stops: dict[int, set] = {}
|
|
177
|
-
for q in questions:
|
|
178
|
-
if (q["ticket"], q["kind"]) == (ticket, "locked-test-again") and q["answer"]:
|
|
179
|
-
stops.setdefault(q["stop"], set()).add(q["answer"])
|
|
180
|
-
return sum("correct-again" in answers for answers in stops.values()), {"accept"} in stops.values()
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
def ruled(questions: list[dict], ticket: str, kind: str) -> dict[str, str]:
|
|
184
|
-
"""subject -> the last answer to the questions of `kind` on `ticket`."""
|
|
185
|
-
return {q["subject"]: q["answer"] for q in questions if (q["ticket"], q["kind"]) == (ticket, kind) and q["answer"]}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
def accepted(questions: list[dict], ticket: str, kind: str) -> list[str]:
|
|
189
|
-
"""The subjects of the questions of `kind` on `ticket` that the operator answered `accept`."""
|
|
190
|
-
return [q["subject"] for q in questions if (q["ticket"], q["kind"], q["answer"]) == (ticket, kind, "accept")]
|
|
191
|
-
|
|
192
|
-
|
|
193
84
|
def drop_merged(state: dict) -> list[dict]:
|
|
194
85
|
"""Remove the open questions of each merged ticket from `state`: the stop that asked them is over (issue #136).
|
|
195
86
|
Returns them."""
|
|
@@ -200,38 +91,28 @@ def drop_merged(state: dict) -> list[dict]:
|
|
|
200
91
|
return dropped
|
|
201
92
|
|
|
202
93
|
|
|
203
|
-
def
|
|
204
|
-
"""The
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
""
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
tried = {q["answer"] for q in asked if (q["ticket"], q["kind"], q["subject"]) == (ticket, kind, subject)}
|
|
222
|
-
options = {name: option for name, option in options.items() if name == "redesign" or name not in tried}
|
|
223
|
-
recommended = recommended if recommended in options else next(iter(options))
|
|
224
|
-
return {"id": f"{ticket}-{kind}-{number}".lstrip("-"), "title": made.title.format(**values), "why": made.why.format(**values),
|
|
225
|
-
"evidence": evidence, "recommended": recommended,
|
|
226
|
-
"options": [{"id": name, "description": option.description} for name, option in options.items()],
|
|
227
|
-
"ticket": ticket, "kind": kind, "subject": subject, "stop": stop, "answer": None}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
def stop(run: dict, kind: str, ticket: str, subjects: list[str], evidence: list[str]) -> None:
|
|
94
|
+
def question_id(kind: str, ticket: str, asked: list[dict]) -> str:
|
|
95
|
+
"""The id of the next question of `kind` for `ticket`: `<NN>-<kind>-<n>` (`final-<kind>-<n>` for the end of run);
|
|
96
|
+
n counts in `asked`, the whole run."""
|
|
97
|
+
return f"{ticket}-{kind}-{1 + sum((q['ticket'], q['kind']) == (ticket, kind) for q in asked)}"
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def question(kind: str, ticket: str, subject: str, evidence: list[str], asked: list[dict], stop: int,
|
|
101
|
+
resume: Resume) -> dict:
|
|
102
|
+
"""A new open question."""
|
|
103
|
+
made, values = KINDS[kind], {"ticket": ticket, "subject": subject, "owner": owner(ticket)}
|
|
104
|
+
return {"id": question_id(kind, ticket, asked), "title": made.title.format(**values),
|
|
105
|
+
"why": made.why.format(**values),
|
|
106
|
+
"evidence": evidence, "recommended": made.recommended,
|
|
107
|
+
"options": [{"id": name, "description": option.description} for name, option in made.options.items()],
|
|
108
|
+
"ticket": ticket, "kind": kind, "subject": subject, "stop": stop, "resume": resume.fields(), "answer": None}
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def stop(run: dict, kind: str, ticket: str, subjects: list[str], evidence: list[str], resume: Resume) -> None:
|
|
231
112
|
"""Count one stop in `run` and add one open question of `kind` per subject. No subject is no stop."""
|
|
232
113
|
run["stops"] += bool(subjects)
|
|
233
114
|
for subject in subjects:
|
|
234
|
-
run["questions"].append(question(kind, ticket, subject, evidence, run["questions"], run["stops"]))
|
|
115
|
+
run["questions"].append(question(kind, ticket, subject, evidence, run["questions"], run["stops"], resume))
|
|
235
116
|
|
|
236
117
|
|
|
237
118
|
def decides(kind: str, subjects: int) -> str:
|
|
@@ -248,29 +129,41 @@ def document(run: dict) -> dict:
|
|
|
248
129
|
|
|
249
130
|
def rulings(questions: list[dict]) -> list[str]:
|
|
250
131
|
"""The ruling sentence of each answered question, without the note of the operator."""
|
|
251
|
-
return [
|
|
132
|
+
return [q["ruling"] for q in questions if q["answer"] is not None]
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def ruling(q: dict) -> str:
|
|
136
|
+
"""The ruling sentence of the answer to `q`. An answered question keeps it, so a kind can go away."""
|
|
137
|
+
return KINDS[q["kind"]].options[q["answer"]].ruling.format(**q)
|
|
252
138
|
|
|
253
139
|
|
|
254
140
|
def parked(questions: list[dict]) -> bool:
|
|
255
|
-
|
|
141
|
+
"""An open question ends the run with exit 2."""
|
|
142
|
+
return any(q["answer"] is None for q in questions)
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def _goes_on(q: dict) -> dict:
|
|
146
|
+
"""The record fields of the answer to `q`: its `resume` whole, when the option resumes, and the option's own."""
|
|
147
|
+
option = KINDS[q["kind"]].options[q["answer"]]
|
|
148
|
+
return {**(q["resume"] if option.resumes else {}), **option.fields}
|
|
256
149
|
|
|
257
150
|
|
|
258
151
|
def _settled(questions: list[dict], ticket: str, stop: int) -> dict:
|
|
259
|
-
"""The
|
|
260
|
-
fields = [q["answer"] and
|
|
261
|
-
for q in questions if (q["ticket"], q["stop"]) == (ticket, stop)]
|
|
152
|
+
"""The record fields from the answers of one stop; {} while one is open or one keeps the record BLOCKED."""
|
|
153
|
+
fields = [q["answer"] and _goes_on(q) for q in questions if (q["ticket"], q["stop"]) == (ticket, stop)]
|
|
262
154
|
return {name: value for one in fields for name, value in one.items()} if all(fields) else {}
|
|
263
155
|
|
|
264
156
|
|
|
265
157
|
def apply(questions: list[dict], answers: dict) -> tuple[list[str], dict[str, dict]]:
|
|
266
|
-
"""Answer the open questions in `answers`. Returns (a ruling per answer, ticket -> fields that let
|
|
158
|
+
"""Answer the open questions in `answers`. Returns (a ruling per answer, ticket or FINAL -> the fields that let its
|
|
159
|
+
record go on)."""
|
|
267
160
|
rulings, stops = [], {}
|
|
268
161
|
for q in questions:
|
|
269
162
|
if q["answer"] is None and q["id"] in answers:
|
|
270
163
|
q["answer"] = answers[q["id"]]
|
|
164
|
+
q["ruling"] = ruling(q)
|
|
271
165
|
note = answers.get(f"{q['id']}.note")
|
|
272
|
-
rulings.append(
|
|
273
|
-
+ f" Note of the operator: {note}" * bool(note))
|
|
166
|
+
rulings.append(q["ruling"] + f" Note of the operator: {note}" * bool(note))
|
|
274
167
|
stops[q["ticket"]] = q["stop"]
|
|
275
168
|
moved = {ticket: _settled(questions, ticket, stop) for ticket, stop in stops.items()}
|
|
276
169
|
return rulings, {ticket: fields for ticket, fields in moved.items() if fields}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"""A locked test that an implementer or a fixer disputes: the reviewer's arbitration, the test-writer correction
|
|
2
|
+
(after a ruling, a review finding or a `correct-test` answer), and the `spec-ambiguous` question when a locked file is
|
|
3
|
+
disputed or corrected a second time in its ticket.
|
|
4
|
+
|
|
5
|
+
A dispute is keyed by its locked file, the part of the test id before `::`, so a renamed or parametrized test of a
|
|
6
|
+
ruled file is the same test. The ticket record keeps the ruling in `disputes` and the correction in `corrected`.
|
|
7
|
+
"""
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import json
|
|
11
|
+
import os
|
|
12
|
+
from dataclasses import replace
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
from typing import NamedTuple, NoReturn
|
|
15
|
+
|
|
16
|
+
import driver_decisions
|
|
17
|
+
import driver_locked
|
|
18
|
+
import driver_report
|
|
19
|
+
import driver_slots
|
|
20
|
+
from driver_decisions import Resume
|
|
21
|
+
from driver_report import Dispute
|
|
22
|
+
from driver_run import OUT, Blocked, Call, Run, during, ledger, retry_point
|
|
23
|
+
|
|
24
|
+
class Corrected(NamedTuple):
|
|
25
|
+
"""The reading a locked file is corrected to, which the ticket's `corrected` keeps: its one correction."""
|
|
26
|
+
test: str
|
|
27
|
+
requirement: str
|
|
28
|
+
reason: str
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class Reading(NamedTuple):
|
|
32
|
+
"""The two readings of a locked test that a `spec-ambiguous` question asks about."""
|
|
33
|
+
file: str # the locked file
|
|
34
|
+
test: str
|
|
35
|
+
requirement: str
|
|
36
|
+
first: str # the reading of its ruling or of its one correction
|
|
37
|
+
second: str # the reading of the new dispute or finding
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _rulings(entry: dict) -> str:
|
|
41
|
+
return "".join(f"- {ruling['test']}, {ruling['requirement']}: {ruling['ruling']}: {ruling['reason']}\n"
|
|
42
|
+
for ruling in entry["disputes"].values())
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def agent(run: Run, call: Call) -> dict:
|
|
46
|
+
"""`run.agent` for a role of a ticket. While the implementer or a fixer disputes a locked test, the dispute is
|
|
47
|
+
settled and the role runs again from the tip, with the rulings of the ticket in its prompt."""
|
|
48
|
+
while True:
|
|
49
|
+
entry = run.state.read()["tickets"][call.number]
|
|
50
|
+
values = {**call.values, "locked": " ".join(entry["locked"]), "rulings": _rulings(entry)}
|
|
51
|
+
ruled = call.role in driver_report.DISPUTING and bool(entry["disputes"])
|
|
52
|
+
report = run.agent(replace(call, values=values, notes=[*call.notes, *["ruled"] * ruled], may_dispute=True))
|
|
53
|
+
if not (disputed := driver_report.disputes(call.role, report, entry["locked"])):
|
|
54
|
+
return report
|
|
55
|
+
_settle(run, replace(call, values=values), disputed)
|
|
56
|
+
call = replace(call, values={**call.values, "start_sha": driver_slots.head(call.slot)})
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def ambiguous(run: Run, number: str, readings: list[Reading], resume: Resume) -> NoReturn:
|
|
60
|
+
"""Ask one `spec-ambiguous` question on `readings` and block the ticket. Its evidence is a findings file that a
|
|
61
|
+
`correct-test` correction reads: one finding per locked file, to correct to the second reading. The file is named
|
|
62
|
+
after the question: `spec-ambiguous-<n>.json` for `<NN>-spec-ambiguous-<n>`."""
|
|
63
|
+
question = driver_decisions.question_id("spec-ambiguous", number, run.state.read()["run"]["questions"])
|
|
64
|
+
path = OUT / number / f"{question.removeprefix(f'{number}-')}.json" # the ticket's folder names the ticket
|
|
65
|
+
subjects = [f"{one.test}{f', {one.requirement}' * bool(one.requirement)}: the first reading: {one.first}; the "
|
|
66
|
+
f"second reading: {one.second}" for one in readings]
|
|
67
|
+
_ruling_findings(path, [(one.file, subject, f"correct the test to the second reading: {one.second}")
|
|
68
|
+
for one, subject in zip(readings, subjects)])
|
|
69
|
+
subject = "; ".join(subjects)
|
|
70
|
+
run.ask(number, "spec-ambiguous", [subject], str(path), resume)
|
|
71
|
+
raise Blocked(f"the spec reads two ways on a locked test: {subject}")
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def kept_files(questions: list[dict], number: str) -> set[str]:
|
|
75
|
+
"""The locked files of the `spec-ambiguous` questions of `number` answered `keep-test`."""
|
|
76
|
+
return {finding["file"] for q in questions if (q["ticket"], q["kind"], q["answer"]) ==
|
|
77
|
+
(number, "spec-ambiguous", "keep-test") for finding in json.loads(Path(q["evidence"][0]).read_text())}
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def correction(questions: list[dict], number: str) -> dict:
|
|
81
|
+
"""The last `spec-ambiguous` question of `number` answered `correct-test`, or {}: its evidence is the findings file
|
|
82
|
+
of the correction, the phase of its `resume` the phase after it."""
|
|
83
|
+
answered = [q for q in questions if (q["ticket"], q["kind"], q["answer"]) ==
|
|
84
|
+
(number, "spec-ambiguous", "correct-test")]
|
|
85
|
+
return answered[-1] if answered else {}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def second_readings(found: list[Dispute], record: dict) -> list[Reading]:
|
|
89
|
+
"""The readings of each dispute in `found` whose file `record` (`disputes` or `corrected`) has: the record's is
|
|
90
|
+
the first, the dispute's the second."""
|
|
91
|
+
return [Reading(one.file, one.test, record[one.file]["requirement"], record[one.file]["reason"], one.reason)
|
|
92
|
+
for one in found if one.file in record]
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def _ruling_findings(path: Path, rulings: list[tuple[str, str, str]]) -> list[dict]:
|
|
96
|
+
"""Write the findings file of a correction to rulings: a critical finding of kind `ruling` per (locked file,
|
|
97
|
+
title, evidence). Returns the findings."""
|
|
98
|
+
findings = [{"severity": "critical", "file": file, "line": 0, "title": title, "evidence": evidence,
|
|
99
|
+
"kind": "ruling"} for file, title, evidence in rulings]
|
|
100
|
+
path.write_text(json.dumps(findings, indent=1) + "\n")
|
|
101
|
+
return findings
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def correct(run: Run, call: Call, findings: list[dict], readings: dict[str, Corrected], fate: str) -> dict[str, str]:
|
|
105
|
+
"""One test-writer correction of `findings`, outside the fix rounds. `call` is the test-writer's, its values point
|
|
106
|
+
at the findings file. Its commit becomes the baseline of the ticket's own locked files, and the `corrected` of the
|
|
107
|
+
ticket keeps the reading in `readings` of each file it corrected. A ledger line per finding says what it did,
|
|
108
|
+
with `fate` for one it did not correct. Returns {title: reason} of each finding it did not correct."""
|
|
109
|
+
number = call.number
|
|
110
|
+
report = run.agent(replace(call, notes=["correction"],
|
|
111
|
+
check={"correction": True, "findings": [finding["title"] for finding in findings]}))
|
|
112
|
+
tip = driver_slots.head(call.slot)
|
|
113
|
+
reasons = {item["finding"]: item["reason"] for item in report.get("not_addressed", [])}
|
|
114
|
+
kept = {finding["file"]: readings[finding["file"]]._asdict() for finding in findings
|
|
115
|
+
if finding["file"] in readings and finding["title"] not in reasons}
|
|
116
|
+
|
|
117
|
+
def record(state: dict) -> None:
|
|
118
|
+
entry = state["tickets"][number]
|
|
119
|
+
entry.update(tip=tip, **driver_locked.written(entry, report["locked"], tip))
|
|
120
|
+
entry["corrected"].update(kept)
|
|
121
|
+
|
|
122
|
+
run.state.update(record)
|
|
123
|
+
for finding in findings:
|
|
124
|
+
title = finding["title"]
|
|
125
|
+
result = (f"The test-writer did not correct it: {reasons[title]}.{fate}" if title in reasons else
|
|
126
|
+
f"The test-writer corrected it at {tip[:7]}.")
|
|
127
|
+
ledger(f"Ticket {number}: {finding['kind']} correction in {finding['file']}, outside the fix rounds: {title}: "
|
|
128
|
+
f"{finding['evidence']}. {result}")
|
|
129
|
+
return reasons
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def correct_as_answered(run: Run, call: Call, question: dict) -> None:
|
|
133
|
+
"""The correction of a `spec-ambiguous` question answered `correct-test`, to the findings of its evidence file.
|
|
134
|
+
No answer changes `corrected`."""
|
|
135
|
+
path = question["evidence"][0]
|
|
136
|
+
values = {**call.values, "findings": os.path.relpath(path, call.slot)}
|
|
137
|
+
correct(run, replace(call, values=values), json.loads(Path(path).read_text()), {}, "")
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def _settle(run: Run, call: Call, disputed: list[Dispute]) -> None:
|
|
141
|
+
"""A locked file disputed before asks `spec-ambiguous`. Else the reviewer rules on each disputed test, a test
|
|
142
|
+
ruled `test-wrong` gets its one correction (a file corrected before asks `spec-ambiguous`), and the ticket record
|
|
143
|
+
keeps the rulings."""
|
|
144
|
+
number = call.number
|
|
145
|
+
entry = run.state.read()["tickets"][number]
|
|
146
|
+
resume = retry_point(call.role, driver_slots.head(call.slot), call.fix_round)
|
|
147
|
+
if again := second_readings(disputed, entry["disputes"]):
|
|
148
|
+
ambiguous(run, number, again, resume)
|
|
149
|
+
n = 1 + len(entry["disputes"])
|
|
150
|
+
ruled = _arbitrate(run, call, disputed, n)
|
|
151
|
+
wrong = {file: ruling for file, ruling in ruled.items() if ruling["ruling"] == "test-wrong"}
|
|
152
|
+
if again := second_readings([Dispute(file, ruling["test"], ruling["reason"]) for file, ruling in wrong.items()],
|
|
153
|
+
entry["corrected"]):
|
|
154
|
+
run.state.update(lambda state: state["tickets"][number]["disputes"].update(ruled)) # the file is arbitrated
|
|
155
|
+
ambiguous(run, number, again, resume)
|
|
156
|
+
if wrong:
|
|
157
|
+
_correct(run, call, wrong, n)
|
|
158
|
+
run.state.update(lambda state: state["tickets"][number]["disputes"].update(ruled))
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def _arbitrate(run: Run, call: Call, disputed: list[Dispute], n: int) -> dict[str, dict]:
|
|
162
|
+
"""The reviewer's ruling on each disputed locked file, from `arbitration-<n>.json`."""
|
|
163
|
+
number, slot = call.number, call.slot
|
|
164
|
+
tip, files = driver_slots.head(slot), {one.test: one.file for one in disputed}
|
|
165
|
+
asked = {**call.values, "role": call.role, "start_sha": tip,
|
|
166
|
+
"disputed": "".join(f"- {one.test}: {one.reason}\n" for one in disputed),
|
|
167
|
+
"dispute_report": os.path.relpath(OUT / number / f"{call.role}-{call.fix_round}.json", slot)}
|
|
168
|
+
with during("the arbitration"):
|
|
169
|
+
report = run.read_only(number, slot, call.values["branch"], tip, lambda: run.agent(Call(
|
|
170
|
+
"reviewer", number, slot, asked, template="arbitration", name=f"arbitration-{n}", retry=call.role,
|
|
171
|
+
fix_round=call.fix_round, check={"disputed": list(files)})))
|
|
172
|
+
for ruling in report["rulings"]:
|
|
173
|
+
ledger(f"Ticket {number}: the reviewer ruled {ruling['ruling']} on the locked test {ruling['test']}, "
|
|
174
|
+
f"{ruling['requirement']}: {ruling['reason']}.")
|
|
175
|
+
return {files[ruling["test"]]: ruling for ruling in report["rulings"] if ruling["test"] in files}
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def _correct(run: Run, call: Call, wrong: dict[str, dict], n: int) -> None:
|
|
179
|
+
"""The correction of the tests ruled `test-wrong`, each ruling a finding of kind `ruling` in `ruled-<n>.json`."""
|
|
180
|
+
number, slot = call.number, call.slot
|
|
181
|
+
path = OUT / number / f"ruled-{n}.json"
|
|
182
|
+
findings = _ruling_findings(path, [(file, f"{ruling['test']}, {ruling['requirement']}", ruling["reason"])
|
|
183
|
+
for file, ruling in wrong.items()])
|
|
184
|
+
values = {**call.values, "start_sha": driver_slots.head(slot), "findings": os.path.relpath(path, slot)}
|
|
185
|
+
readings = {file: Corrected(ruling["test"], ruling["requirement"], ruling["reason"])
|
|
186
|
+
for file, ruling in wrong.items()}
|
|
187
|
+
with during("the test-writer correction"):
|
|
188
|
+
correct(run, Call("test-writer", number, slot, values, name=f"correction-{n}", retry=call.role,
|
|
189
|
+
fix_round=call.fix_round), findings, readings, "")
|