@jesdi/skills 0.0.77 → 0.0.79
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/test-prune/SKILL.md +7 -3
- package/skills/test-prune/prune_source.py +48 -0
- package/skills/test-prune/prune_strengthen.py +87 -2
- package/skills/test-prune/tests/test_prune_strengthen.py +93 -0
- package/skills/to-tickets/SKILL.md +1 -1
- package/skills-manifest.json +9 -9
- 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,22 +1,23 @@
|
|
|
1
1
|
"""A gated ticket tip in, a reviewed tip out: the review, the test-writer corrections and the fix rounds.
|
|
2
2
|
|
|
3
|
-
Reports of a ticket are `<role>-<K>.json`: K is the fix round the agent follows (reviewer
|
|
3
|
+
Reports of a ticket are `<role>-<K>.json`: K is the fix round the agent follows (reviewer) or is
|
|
4
4
|
(fixer). A test-writer correction after the review of round K is `test-writer-<K+1>.json`.
|
|
5
5
|
"""
|
|
6
6
|
from __future__ import annotations
|
|
7
7
|
|
|
8
8
|
import json
|
|
9
9
|
import os
|
|
10
|
-
from
|
|
11
|
-
from dataclasses import dataclass, field
|
|
10
|
+
from dataclasses import dataclass
|
|
12
11
|
|
|
13
|
-
import
|
|
14
|
-
import driver_decisions
|
|
12
|
+
import driver_dispute
|
|
15
13
|
import driver_gate
|
|
16
|
-
import
|
|
14
|
+
import driver_locked
|
|
17
15
|
import driver_review
|
|
18
16
|
import driver_slots
|
|
19
|
-
from
|
|
17
|
+
from driver_decisions import Resume
|
|
18
|
+
from driver_dispute import Corrected
|
|
19
|
+
from driver_report import Dispute
|
|
20
|
+
from driver_run import OUT, Blocked, Call, Run, during, ledger
|
|
20
21
|
from driver_tickets import Ticket
|
|
21
22
|
|
|
22
23
|
ROUNDS = 2
|
|
@@ -31,26 +32,22 @@ class Job:
|
|
|
31
32
|
values: dict[str, str] # the pointers every prompt of the ticket gets
|
|
32
33
|
round: int # fix rounds started
|
|
33
34
|
tip: str
|
|
35
|
+
writer: str | None # the test-writer commit when the job started or its last fix round ended
|
|
34
36
|
previous: str = "" # the tip before the last fix; "" makes the next review a full one
|
|
35
|
-
proofs: set[tuple[str, int]] = field(default_factory=set) # mutation proofs so far, at `tip`
|
|
36
|
-
again: set[tuple[str, int]] = field(default_factory=set) # each proof at `tip` that a fix made due again
|
|
37
|
-
corrected: bool = False # the last step was a test-writer correction
|
|
38
37
|
red: bool = False # the gate of `tip` is red, so no review saw it
|
|
39
38
|
|
|
39
|
+
def corrected(self) -> bool:
|
|
40
|
+
"""A test-writer correction ran since the job started or its last fix round ended: no review has seen it."""
|
|
41
|
+
return self.run.state.read()["tickets"][self.ticket.number]["test_writer_sha"] != self.writer
|
|
42
|
+
|
|
40
43
|
def pointers(self, review: int) -> dict[str, str]:
|
|
41
44
|
"""The values of a prompt; `review` is the round whose findings the agent reads."""
|
|
42
45
|
entry = self.run.state.read()["tickets"][self.ticket.number]
|
|
43
46
|
findings = os.path.relpath(OUT / self.ticket.number / f"findings-{review}.json", self.slot)
|
|
44
47
|
gate = os.path.relpath(driver_gate.record_path(OUT / self.ticket.number, driver_gate.FAST, self.tip), self.slot)
|
|
45
48
|
return {**self.values, "start_sha": self.tip, "from_sha": self.previous, "round": str(self.round),
|
|
46
|
-
"locked": " ".join(entry["locked"]), "
|
|
47
|
-
"findings": findings, "gate_record": gate
|
|
48
|
-
"proofs": " ".join(f"{file}:{line}" for file, line in sorted(self.again))}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
def tested(entry: dict) -> list[str]:
|
|
52
|
-
"""The locked files of the ticket record that hold tests: each one needs a mutation proof in a full review."""
|
|
53
|
-
return [path for path in entry["locked"] if path not in entry["fixtures"]]
|
|
49
|
+
"locked": " ".join(entry["locked"]), "test_writer_sha": str(entry["test_writer_sha"] or ""),
|
|
50
|
+
"findings": findings, "gate_record": gate}
|
|
54
51
|
|
|
55
52
|
|
|
56
53
|
def entry(models: dict[str, list[str]], round: int) -> str:
|
|
@@ -66,76 +63,37 @@ def _log_findings(number: str, findings: list[dict]) -> list[dict]:
|
|
|
66
63
|
return findings
|
|
67
64
|
|
|
68
65
|
|
|
69
|
-
def
|
|
70
|
-
"""Run the
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
number = job.ticket.number
|
|
75
|
-
values, running = job.pointers(job.round - 1), [role for role, _ in cast]
|
|
66
|
+
def _run_reviewer(job: Job) -> dict:
|
|
67
|
+
"""Run the reviewer in the slot. Returns its report. It gets the diff of each locked file of another ticket that
|
|
68
|
+
the ticket changed: only its test-writer may, and the reviewer judges that change against the spec."""
|
|
69
|
+
run, number = job.run, job.ticket.number
|
|
70
|
+
values = job.pointers(job.round - 1)
|
|
76
71
|
values["fixer_report"] = os.path.relpath(OUT / number / f"fixer-{job.round}.json", job.slot)
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
notes += ["rejected"] * (role in before)
|
|
89
|
-
try:
|
|
90
|
-
return job.run.agent(role, job.ticket.number, job.slot, {**values, "rejection": before.get(role, "")},
|
|
91
|
-
entry=entry, fix_round=job.round,
|
|
92
|
-
notes=notes, check={"full": True, "locked": locked} if full else {},
|
|
93
|
-
alone=lambda: len(running) == 1)
|
|
94
|
-
except Stopped as stopped:
|
|
95
|
-
if any(subject.startswith(f"the {role} ") for subject in accepted):
|
|
96
|
-
ledger(f"Ticket {number}: {stopped}; by the ruling (accept), the review goes on with the other reports.")
|
|
97
|
-
return stopped.report
|
|
98
|
-
stops[role] = str(stopped)
|
|
99
|
-
errors[role] = f"the {role}: {stopped}"
|
|
100
|
-
return {}
|
|
101
|
-
except Blocked as blocked: # the driver rejected its report two times
|
|
102
|
-
rejected[role] = str(blocked)
|
|
103
|
-
errors[role] = f"the {role}: {blocked}"
|
|
104
|
-
return {}
|
|
105
|
-
finally:
|
|
106
|
-
running.remove(role)
|
|
107
|
-
|
|
108
|
-
with ThreadPoolExecutor(len(cast)) as pool:
|
|
109
|
-
reports = list(pool.map(lambda agent: call(*agent), cast))
|
|
110
|
-
if stops:
|
|
111
|
-
first = next(role for role, _ in cast if role in stops)
|
|
112
|
-
job.run.ask(number, "review-stopped", [stops[role] for role, _ in cast if role in stops],
|
|
113
|
-
str(OUT / number / f"{first}-{job.round}.json"))
|
|
114
|
-
elif rejected:
|
|
115
|
-
first = next(role for role, _ in cast if role in rejected)
|
|
116
|
-
job.run.ask(number, "review-rejected", [errors[role] for role, _ in cast if role in rejected],
|
|
117
|
-
str(OUT / number / f"{first}-{job.round}.json"), rejected=rejected)
|
|
118
|
-
if errors:
|
|
119
|
-
raise Blocked("; ".join(errors[role] for role, _ in cast if role in errors))
|
|
120
|
-
return reports
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
def _prior_open(job: Job) -> dict[tuple[str, str, str], str | None]:
|
|
124
|
-
"""The source, file, title and basis of findings that this re-review may revisit."""
|
|
72
|
+
values["elsewhere"] = driver_locked.changed_elsewhere(
|
|
73
|
+
job.slot, run.tip(), driver_locked.others(run.state.read()["tickets"], number))
|
|
74
|
+
notes = ["rereview"] * bool(job.previous)
|
|
75
|
+
notes += ["unchanged"] * (job.previous == job.tip) # a fixer with no commit: its reasons need a check
|
|
76
|
+
notes += ["elsewhere"] * bool(values["elsewhere"])
|
|
77
|
+
with during("the reviewer"):
|
|
78
|
+
return run.agent(Call("reviewer", number, job.slot, values, fix_round=job.round, notes=notes))
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _prior_open(job: Job) -> dict[tuple[str, str], str | None]:
|
|
82
|
+
"""The file, title and basis of the reviewer's findings that this re-review may revisit."""
|
|
125
83
|
if not job.previous:
|
|
126
84
|
return {}
|
|
127
85
|
number = job.ticket.number
|
|
128
|
-
previous = json.loads((OUT / number / f"findings-{job.round - 1}.json").read_text())
|
|
129
|
-
return {(finding["
|
|
130
|
-
|
|
86
|
+
previous = json.loads((OUT / number / f"findings-{job.round - 1}.json").read_text())
|
|
87
|
+
return {(finding["file"], finding["title"]): finding.get("basis") for finding in previous
|
|
88
|
+
if finding["severity"] in driver_review.OPEN and finding["source"] == "reviewer"}
|
|
131
89
|
|
|
132
90
|
|
|
133
|
-
def _partition_findings(
|
|
134
|
-
"""On a re-review, only the
|
|
91
|
+
def _partition_findings(report: dict, prior: dict, scoped: bool) -> tuple[list[dict], list[dict]]:
|
|
92
|
+
"""On a re-review, only the reviewer's previously open findings stay in ticket scope."""
|
|
135
93
|
active, deferred = [], []
|
|
136
94
|
for raw in report["findings"]:
|
|
137
|
-
finding = {**raw, "source":
|
|
138
|
-
key = (
|
|
95
|
+
finding = {**raw, "source": "reviewer"}
|
|
96
|
+
key = (finding["file"], finding["title"])
|
|
139
97
|
if scoped and key not in prior:
|
|
140
98
|
deferred.append(finding)
|
|
141
99
|
continue
|
|
@@ -145,15 +103,12 @@ def _partition_findings(role: str, report: dict, prior: dict, scoped: bool) -> t
|
|
|
145
103
|
return active, deferred
|
|
146
104
|
|
|
147
105
|
|
|
148
|
-
def _reviewer_results(job: Job,
|
|
149
|
-
"""Collect ticket findings
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
for finding in report.get("regressions", [])]
|
|
155
|
-
observations += deferred + [{**finding, "source": role} for finding in report.get("observations", [])]
|
|
156
|
-
job.proofs |= {(proof["file"], proof["line"]) for proof in report.get("mutations", [])}
|
|
106
|
+
def _reviewer_results(job: Job, report: dict) -> tuple[list[dict], list[dict]]:
|
|
107
|
+
"""Collect ticket findings and deferred observations from the reviewer's report."""
|
|
108
|
+
active, deferred = _partition_findings(report, _prior_open(job), bool(job.previous))
|
|
109
|
+
found = active + [{**finding, "source": "reviewer", "basis": finding.get("basis", "regression")}
|
|
110
|
+
for finding in report.get("regressions", [])]
|
|
111
|
+
observations = deferred + [{**finding, "source": "reviewer"} for finding in report.get("observations", [])]
|
|
157
112
|
return found, observations
|
|
158
113
|
|
|
159
114
|
|
|
@@ -167,77 +122,46 @@ def _store_observations(job: Job, observations: list[dict]) -> None:
|
|
|
167
122
|
|
|
168
123
|
|
|
169
124
|
def _review(job: Job) -> list[dict]:
|
|
170
|
-
"""Review `job.tip`. Returns the findings
|
|
125
|
+
"""Review `job.tip`. Returns the reviewer's findings."""
|
|
171
126
|
run, number = job.run, job.ticket.number
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
if job.ticket.risk:
|
|
177
|
-
cast.append(("correctness", driver_agents.correctness_entry(run.models)))
|
|
178
|
-
reports = run.read_only(number, job.slot, job.values["branch"], job.tip,
|
|
179
|
-
lambda: _run_reviewers(job, cast, tested(state)))
|
|
180
|
-
if state["rejected"]:
|
|
181
|
-
run.state.ticket(number, rejected={}) # the rejection is answered: no later review repeats it
|
|
182
|
-
reviewed, observations = _reviewer_results(job, cast, reports)
|
|
183
|
-
found += _log_findings(number, reviewed)
|
|
127
|
+
run.state.ticket(number, phase="review")
|
|
128
|
+
report = run.read_only(number, job.slot, job.values["branch"], job.tip, lambda: _run_reviewer(job))
|
|
129
|
+
reviewed, observations = _reviewer_results(job, report)
|
|
130
|
+
found = _log_findings(number, reviewed)
|
|
184
131
|
_store_observations(job, observations)
|
|
185
132
|
(OUT / number / f"findings-{job.round}.json").write_text(json.dumps(found, indent=1) + "\n")
|
|
186
133
|
return found
|
|
187
134
|
|
|
188
135
|
|
|
189
136
|
def _correct(job: Job, findings: list[dict]) -> list[dict]:
|
|
190
|
-
"""One test-writer correction for the findings on the locked tests. It is outside the fix rounds.
|
|
191
|
-
|
|
137
|
+
"""One test-writer correction for the findings on the locked tests. It is outside the fix rounds. A file that
|
|
138
|
+
was corrected before in the ticket asks `spec-ambiguous` instead. A correction that is rejected twice asks
|
|
139
|
+
`ticket-blocked`, whose `retry` reviews the tip again. Returns the findings that it did not correct, as findings
|
|
140
|
+
of kind code for the fixer (issue #111)."""
|
|
192
141
|
run, number = job.run, job.ticket.number
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
# ticket's code. The driver decides that, not the correction (issue #90).
|
|
201
|
-
with during("the gate of the restore"):
|
|
202
|
-
record = run.red_gate(number, job.slot, job.tip, driver_gate.FAST, restored) if restored else ""
|
|
203
|
-
if not record and all(finding["source"] == "driver" for finding in findings):
|
|
204
|
-
job.previous = "" # no review has seen the restore commit
|
|
205
|
-
ledger(f"Ticket {number}: the code does not need the change to {', '.join(restored)}: the restore closes it, "
|
|
206
|
-
"with no correction.")
|
|
207
|
-
return []
|
|
208
|
-
values = {**job.pointers(job.round), "restored": " ".join(restored),
|
|
209
|
-
"record": record and os.path.relpath(record, job.slot)}
|
|
210
|
-
notes = ["correction"] + ["restored"] * bool(restored) + ["restored-red"] * bool(record)
|
|
142
|
+
corrected = run.state.read()["tickets"][number]["corrected"]
|
|
143
|
+
found = [Dispute(finding["file"], corrected.get(finding["file"], {}).get("test", finding["file"]),
|
|
144
|
+
f"{finding['title']}: {finding['evidence']}") for finding in findings]
|
|
145
|
+
if again := driver_dispute.second_readings(found, corrected):
|
|
146
|
+
with during("the review"):
|
|
147
|
+
driver_dispute.ambiguous(run, number, again, Resume("review"))
|
|
148
|
+
call = Call("test-writer", number, job.slot, job.pointers(job.round), fix_round=job.round + 1, retry="reviewer")
|
|
211
149
|
with during("the test-writer correction"):
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
run.ask(number, "locked-test-again", titles, evidence) # a rejected correction is one that did not close
|
|
218
|
-
raise
|
|
219
|
-
job.tip, job.previous, job.corrected = driver_slots.head(job.slot), "", True
|
|
220
|
-
entry = run.state.read()["tickets"][number]
|
|
221
|
-
run.state.ticket(number, tip=job.tip, **driver_review.written(job.slot, entry, report["locked"],
|
|
222
|
-
report.get("fixtures", []), job.tip))
|
|
223
|
-
return _uncorrected(job, findings, report.get("not_addressed", []))
|
|
150
|
+
reasons = driver_dispute.correct(run, call, findings, {one.file: Corrected(one.test, "", one.reason)
|
|
151
|
+
for one in found},
|
|
152
|
+
" It goes to the fixer as a finding of kind code.")
|
|
153
|
+
job.tip, job.previous = driver_slots.head(job.slot), ""
|
|
154
|
+
return _uncorrected(job, findings, reasons)
|
|
224
155
|
|
|
225
156
|
|
|
226
|
-
def _uncorrected(job: Job, findings: list[dict],
|
|
227
|
-
"""
|
|
228
|
-
|
|
229
|
-
number = job.ticket.number
|
|
230
|
-
reasons = {item["finding"]: item["reason"] for item in not_addressed}
|
|
231
|
-
for finding in findings:
|
|
232
|
-
result = (f"The test-writer did not correct it: {reasons[finding['title']]}. It goes to the fixer as a finding "
|
|
233
|
-
"of kind code." if finding["title"] in reasons else f"The test-writer corrected it at {job.tip[:7]}.")
|
|
234
|
-
ledger(f"Ticket {number}: {finding['kind']} correction in {finding['file']}, outside the fix rounds: "
|
|
235
|
-
f"{finding['title']}: {finding['evidence']}. {result}")
|
|
157
|
+
def _uncorrected(job: Job, findings: list[dict], reasons: dict[str, str]) -> list[dict]:
|
|
158
|
+
"""Each finding the correction did not correct, with its reason, as a finding of kind code, with the reason as
|
|
159
|
+
its evidence: the test needs a production change first, so a fixer closes it."""
|
|
236
160
|
code = {finding["title"]: {**finding, "kind": "code", "evidence": f"the test-writer did not correct it: {reason}"}
|
|
237
161
|
for finding in findings if (reason := reasons.get(finding["title"]))}
|
|
238
162
|
if code:
|
|
239
163
|
# The fixer reads the findings file of this review, so the finding is of kind code there too.
|
|
240
|
-
path = OUT / number / f"findings-{job.round}.json"
|
|
164
|
+
path = OUT / job.ticket.number / f"findings-{job.round}.json"
|
|
241
165
|
written = [code.get(finding["title"], finding) if finding in findings else finding
|
|
242
166
|
for finding in json.loads(path.read_text())]
|
|
243
167
|
path.write_text(json.dumps(written, indent=1) + "\n")
|
|
@@ -266,37 +190,28 @@ def _fix(job: Job, findings: list[dict], landing: str = "") -> None:
|
|
|
266
190
|
values.update(landing_sha=landing[:7], landing_record=os.path.relpath(record, job.slot))
|
|
267
191
|
notes = ["landing-red"] + ["landing-merge"] * (landing != job.tip)
|
|
268
192
|
with during(f"fix round {job.round}"):
|
|
269
|
-
|
|
270
|
-
|
|
193
|
+
driver_dispute.agent(run, Call("fixer", number, job.slot, values, entry=on, entries=run.models["implementer"],
|
|
194
|
+
fix_round=job.round, notes=notes,
|
|
195
|
+
check={"fix": [finding["title"] for finding in findings],
|
|
196
|
+
"red": _red(job, landing)}))
|
|
271
197
|
before, job.tip = job.tip, driver_slots.head(job.slot)
|
|
272
198
|
run.state.ticket(number, tip=job.tip, landing=None)
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
followed = driver_review.follow(job.slot, before, job.tip, job.proofs)
|
|
279
|
-
due = {proof for proof, changed in followed.items() if changed}
|
|
280
|
-
if job.red:
|
|
281
|
-
# No review saw `before`: the next review covers the fix before it too, and its due proofs stay due.
|
|
282
|
-
due |= set(driver_review.follow(job.slot, before, job.tip, job.again))
|
|
283
|
-
else:
|
|
284
|
-
# No review has seen a test-writer correction, so the review after a fix on a corrected tip is a full one.
|
|
285
|
-
job.previous = "" if job.corrected else before
|
|
286
|
-
job.corrected, job.proofs, job.again = False, set(followed), due
|
|
199
|
+
# No review saw a red `before`, so the next review covers the fix before it too. No review has seen a test-writer
|
|
200
|
+
# correction either (before the fix, or after a dispute of the fixer), so the review after it is a full one.
|
|
201
|
+
if not job.red:
|
|
202
|
+
job.previous = "" if job.corrected() else before
|
|
203
|
+
job.writer = run.state.read()["tickets"][number]["test_writer_sha"]
|
|
287
204
|
|
|
288
205
|
|
|
289
|
-
def
|
|
290
|
-
"""The findings for a correction
|
|
291
|
-
driver's, since a changed locked file is still restored. With no such ruling, `to_correct`."""
|
|
206
|
+
def _still_to_correct(job: Job, state: dict, to_correct: list[dict]) -> list[dict]:
|
|
207
|
+
"""The findings for a correction, but those on a file whose `spec-ambiguous` question was answered `keep-test`."""
|
|
292
208
|
number = job.ticket.number
|
|
293
|
-
|
|
294
|
-
return to_correct
|
|
209
|
+
kept = driver_dispute.kept_files(state["run"]["questions"], number)
|
|
295
210
|
for finding in to_correct:
|
|
296
|
-
if finding["
|
|
211
|
+
if finding["file"] in kept:
|
|
297
212
|
ledger(f"Ticket {number}: {finding['kind']} finding in {finding['file']} closed as it is by the ruling "
|
|
298
|
-
f"(
|
|
299
|
-
return [finding for finding in to_correct if finding["
|
|
213
|
+
f"(keep-test), with no correction: {finding['title']}.")
|
|
214
|
+
return [finding for finding in to_correct if finding["file"] not in kept]
|
|
300
215
|
|
|
301
216
|
|
|
302
217
|
def _save_must_fix(state: dict, number: str, findings: list[dict]) -> None:
|
|
@@ -310,40 +225,35 @@ def _save_must_fix(state: dict, number: str, findings: list[dict]) -> None:
|
|
|
310
225
|
existing.add(key)
|
|
311
226
|
|
|
312
227
|
|
|
313
|
-
def _settled_at_landing(finding: dict) -> bool:
|
|
314
|
-
"""The landing has its own restore/adopt question for a merged ticket's locked file."""
|
|
315
|
-
return (finding["source"] == "driver" and
|
|
316
|
-
finding["title"].startswith("the ticket changed the locked file of a merged ticket:"))
|
|
317
|
-
|
|
318
|
-
|
|
319
228
|
def _at_cap(job: Job, findings: list[dict]) -> bool:
|
|
320
229
|
"""Block unmet criteria; carry other open findings to the required final fix batch."""
|
|
321
230
|
blocking = [finding for finding in findings if finding.get("basis") != "regression"]
|
|
322
231
|
if blocking:
|
|
323
232
|
titles = [f"{finding['title']} ({finding['file']}:{finding['line']})" for finding in blocking]
|
|
324
233
|
raise Blocked(f"the review: after round {ROUNDS} these findings are open: {'; '.join(titles)}")
|
|
325
|
-
|
|
326
|
-
# The final fixer cannot edit that file while it remains protected.
|
|
327
|
-
carry = [finding for finding in findings if not _settled_at_landing(finding)]
|
|
328
|
-
if carry:
|
|
329
|
-
job.run.state.update(lambda state: _save_must_fix(state, job.ticket.number, carry))
|
|
234
|
+
job.run.state.update(lambda state: _save_must_fix(state, job.ticket.number, findings))
|
|
330
235
|
ledger(f"Ticket {job.ticket.number}: the green gate and met criteria allow merge after round {ROUNDS}; "
|
|
331
|
-
f"{len(
|
|
236
|
+
f"{len(findings)} finding{'s' if len(findings) != 1 else ''} go to the final must-fix list.")
|
|
332
237
|
return True
|
|
333
238
|
|
|
334
239
|
|
|
335
|
-
def
|
|
336
|
-
"""
|
|
240
|
+
def _routed(job: Job, found: list[dict]) -> tuple[list[dict], list[dict]]:
|
|
241
|
+
"""(the findings for a correction, those for a fix round). A locked file of another ticket is protected."""
|
|
337
242
|
state = job.run.state.read()
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
to_correct =
|
|
243
|
+
locked = state["tickets"][job.ticket.number]["locked"]
|
|
244
|
+
protected = [path for path in driver_locked.others(state["tickets"], job.ticket.number) if path not in locked]
|
|
245
|
+
to_correct, to_fix = driver_review.route(found, locked, protected)
|
|
246
|
+
to_correct = _still_to_correct(job, state, to_correct)
|
|
341
247
|
if job.round == ROUNDS:
|
|
342
248
|
# No correction at the cap: no fix round could make its new locked tests green.
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
249
|
+
return [], [finding for finding in found if finding in to_correct + to_fix]
|
|
250
|
+
return to_correct, to_fix
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
def _act_on(job: Job, found: list[dict]) -> bool:
|
|
254
|
+
"""Do what the findings of a review ask for: a correction, a fix round, or a stop. True: none is open."""
|
|
255
|
+
to_correct, to_fix = _routed(job, found)
|
|
256
|
+
if to_correct:
|
|
347
257
|
to_fix += [finding for finding in _correct(job, to_correct) if finding["severity"] in driver_review.OPEN]
|
|
348
258
|
if not to_fix:
|
|
349
259
|
return False
|
|
@@ -389,7 +299,7 @@ def _gate(job: Job) -> list[dict]:
|
|
|
389
299
|
run, number = job.run, job.ticket.number
|
|
390
300
|
job.red = False
|
|
391
301
|
with during("the gate"):
|
|
392
|
-
if job.round == ROUNDS or job.corrected:
|
|
302
|
+
if job.round == ROUNDS or job.corrected():
|
|
393
303
|
run.gate(number, job.slot, job.tip, driver_gate.FAST)
|
|
394
304
|
return []
|
|
395
305
|
record = run.red_gate(number, job.slot, job.tip, driver_gate.FAST)
|
|
@@ -405,7 +315,7 @@ def _gate(job: Job) -> list[dict]:
|
|
|
405
315
|
def run(ticket: Ticket, slot: str, run: Run, values: dict[str, str]) -> None:
|
|
406
316
|
"""Gate, review and fix the ticket tip until a review leaves no finding open."""
|
|
407
317
|
state = run.state.read()["tickets"][ticket.number]
|
|
408
|
-
job = Job(ticket, slot, run, values, state["round"], state["tip"])
|
|
318
|
+
job = Job(ticket, slot, run, values, state["round"], state["tip"], state["test_writer_sha"])
|
|
409
319
|
if state["phase"] == "fix" and state["landing"]:
|
|
410
320
|
# A red full gate at the landing started this round, and its fixer has not reported yet.
|
|
411
321
|
job.round -= 1
|
|
@@ -3,15 +3,18 @@
|
|
|
3
3
|
|
|
4
4
|
Every run of a newer driver holds `lock` (driver._hold), so a newer and an older driver never run in one repository
|
|
5
5
|
at the same time. The driver calls `resume` once, after the locks and before any check reads a ref: a run with no
|
|
6
|
-
`schema` in state.json gets the new names of its refs; a run before schema 3 gets its gates as the full tier
|
|
6
|
+
`schema` in state.json gets the new names of its refs; a run before schema 3 gets its gates as the full tier; a run
|
|
7
|
+
before schema 4 keeps the ruling of each answered question, and one with an open question of a removed kind stops.
|
|
7
8
|
ponytail: delete this module, tests/test_legacy.py and its one line in driver._hold and in driver._start_errors
|
|
8
9
|
once no older driver is left.
|
|
9
10
|
"""
|
|
10
11
|
from __future__ import annotations
|
|
11
12
|
|
|
12
13
|
from pathlib import Path
|
|
14
|
+
from types import MappingProxyType
|
|
13
15
|
from typing import IO
|
|
14
16
|
|
|
17
|
+
import driver_decisions
|
|
15
18
|
import driver_slots
|
|
16
19
|
import driver_state
|
|
17
20
|
from driver_names import Names
|
|
@@ -80,9 +83,71 @@ def lock(common_dir: Path) -> tuple[IO | None, str]:
|
|
|
80
83
|
"Wait until it ends, then run the driver again.")
|
|
81
84
|
|
|
82
85
|
|
|
83
|
-
def
|
|
84
|
-
"""Schema
|
|
86
|
+
def _removed(run: dict) -> list[str]:
|
|
87
|
+
"""Schema 4: the open questions of a kind that this driver no longer has, each as an error."""
|
|
88
|
+
return [f"the open question {q['id']} is of the kind {q['kind']}, which this driver no longer has: answer it with "
|
|
89
|
+
"the driver version that asked it, or start the run again"
|
|
90
|
+
for q in run.get("questions", []) if q["answer"] is None and q["kind"] not in driver_decisions.KINDS]
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
_REDESIGN = "Ruling: {ticket} stays BLOCKED, the design changes first (redesign): {subject}."
|
|
94
|
+
# The ruling sentences of the removed kinds, as the older driver wrote them: kind -> option -> sentence.
|
|
95
|
+
_RULINGS = MappingProxyType({
|
|
96
|
+
"locked-test": {
|
|
97
|
+
"overrule-test": "Ruling: {ticket} locked test overruled: the test-writer corrects {subject}, then the "
|
|
98
|
+
"implementer runs again.",
|
|
99
|
+
"overrule-implementer": "Ruling: {ticket} locked test stands: the implementer is overruled on {subject} and "
|
|
100
|
+
"runs again."},
|
|
101
|
+
"finding": {
|
|
102
|
+
"accept": "Ruling: {ticket} finding closed as it is (accept): {subject}.",
|
|
103
|
+
"split": "Ruling: {ticket} stays BLOCKED, the open part becomes a new ticket (split): {subject}.",
|
|
104
|
+
"redesign": _REDESIGN},
|
|
105
|
+
"locked-test-again": {
|
|
106
|
+
"correct-again": "Ruling: {ticket} locked-test finding goes back to the test-writer for one more correction "
|
|
107
|
+
"(correct-again): {subject}.",
|
|
108
|
+
"accept": "Ruling: {ticket} locked-test finding closed as it is (accept): {subject}.",
|
|
109
|
+
"redesign": _REDESIGN},
|
|
110
|
+
"review-stopped": {
|
|
111
|
+
"retry": "Ruling: {ticket} review runs again (retry): {subject}.",
|
|
112
|
+
"accept": "Ruling: {ticket} review goes on past this stop (accept): {subject}.",
|
|
113
|
+
"redesign": _REDESIGN},
|
|
114
|
+
"review-rejected": {
|
|
115
|
+
"retry": "Ruling: {ticket} review runs again (retry): {subject}.",
|
|
116
|
+
"redesign": _REDESIGN},
|
|
117
|
+
"implementer-stopped": {
|
|
118
|
+
"retry": "Ruling: {ticket} implementer runs again (retry): {subject}.",
|
|
119
|
+
"accept-tip": "Ruling: {ticket} tip goes to the gate and the review as it is (accept-tip): {subject}.",
|
|
120
|
+
"redesign": _REDESIGN},
|
|
121
|
+
"fixer-stopped": {
|
|
122
|
+
"retry": "Ruling: {ticket} fix round runs again (retry): {subject}.",
|
|
123
|
+
"redesign": _REDESIGN},
|
|
124
|
+
"merged-locked-file": {
|
|
125
|
+
"restore": "Ruling: {ticket} lands with {subject} put back to the version of the PR branch (restore).",
|
|
126
|
+
"adopt": "Ruling: {ticket} locks {subject} and lands its change to it (adopt).",
|
|
127
|
+
"redesign": _REDESIGN},
|
|
128
|
+
"final-finding": {
|
|
129
|
+
"fix": "Ruling: final-review finding stays open and nothing is pushed (fix): {subject}.",
|
|
130
|
+
"accept": "Ruling: final-review finding closed as it is (accept): {subject}."},
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def _ruled(q: dict) -> str:
|
|
135
|
+
"""Schema 4: the ruling sentence of an answered question of an older driver; for a removed kind, the older
|
|
136
|
+
driver's sentence, or a generic one for a kind or an answer it did not have."""
|
|
137
|
+
if q["kind"] in driver_decisions.KINDS:
|
|
138
|
+
return driver_decisions.ruling(q)
|
|
139
|
+
if template := _RULINGS.get(q["kind"], {}).get(q["answer"]):
|
|
140
|
+
return template.format(**q)
|
|
141
|
+
return f"Ruling: {q['ticket'] or 'end of run'} {q['kind']} ({q['answer']}): {q['subject']}."
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def _upgraded(state: dict) -> None:
|
|
145
|
+
"""Schema 3: every gate of an older driver was the full gate, so its greens and its count are of the full tier.
|
|
146
|
+
Schema 4: an answered question keeps its ruling sentence."""
|
|
85
147
|
run = state["run"]
|
|
148
|
+
for q in run.get("questions", []):
|
|
149
|
+
if q["answer"] is not None:
|
|
150
|
+
q.setdefault("ruling", _ruled(q))
|
|
86
151
|
for record in [run.get("final", {}), *state["tickets"].values()]:
|
|
87
152
|
if isinstance(record.get("green_gates"), list):
|
|
88
153
|
record["green_gates"] = {**driver_state.tiers(), "full": record["green_gates"]}
|
|
@@ -95,10 +160,13 @@ def resume(state: driver_state.State) -> list[str]:
|
|
|
95
160
|
"""Give each ref of a run that an older driver started its new name, then mark the run: the errors, or []."""
|
|
96
161
|
if not state.path.exists() or (schema := state.read()["run"].get("schema", 1)) >= driver_state.SCHEMA:
|
|
97
162
|
return []
|
|
163
|
+
run = state.read()["run"]
|
|
164
|
+
if errors := _removed(run):
|
|
165
|
+
return errors
|
|
98
166
|
if schema < 2: # the names of driver_names
|
|
99
|
-
|
|
167
|
+
names = Names(run["pr_branch"])
|
|
100
168
|
moves = [_branch(entry, number, names, run["start"]) for number, entry in state.read()["tickets"].items()]
|
|
101
169
|
if errors := [error for error in [*moves, _recovery(run, names)] if error]:
|
|
102
170
|
return errors
|
|
103
|
-
state.update(
|
|
171
|
+
state.update(_upgraded)
|
|
104
172
|
return []
|