@jesdi/skills 0.0.86 → 0.0.88
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/skills/implement-spec/ARCHITECTURE.md +33 -14
- package/skills/implement-spec/README.md +30 -15
- package/skills/implement-spec/SKILL.md +1 -1
- package/skills/implement-spec/driver.py +3 -2
- package/skills/implement-spec/driver_agents.py +93 -32
- package/skills/implement-spec/driver_decisions.py +3 -2
- package/skills/implement-spec/driver_dispute.py +82 -57
- package/skills/implement-spec/driver_fixloop.py +18 -21
- package/skills/implement-spec/driver_legacy.py +31 -2
- package/skills/implement-spec/driver_report.py +13 -3
- package/skills/implement-spec/driver_run.py +23 -13
- package/skills/implement-spec/driver_state.py +9 -8
- package/skills/implement-spec/driver_summary.py +8 -1
- package/skills/implement-spec/prompts/correction.md +1 -0
- package/skills/implement-spec/prompts/reviewer.md +3 -3
- package/skills/implement-spec/prompts/ruled.md +1 -1
- package/skills/implement-spec/tests/conftest.py +2 -0
- package/skills/implement-spec/tests/test_agents.py +56 -5
- package/skills/implement-spec/tests/test_arbitration.py +104 -11
- package/skills/implement-spec/tests/test_decisions.py +7 -5
- package/skills/implement-spec/tests/test_driver.py +2 -1
- package/skills/implement-spec/tests/test_fixloop.py +3 -3
- package/skills/implement-spec/tests/test_legacy.py +27 -0
- package/skills/implement-spec/tests/test_lenses.py +10 -5
- package/skills/implement-spec/tests/test_models.py +74 -0
- package/skills/implement-spec/tests/test_state.py +1 -1
- package/skills/implement-spec/tests/test_summary.py +8 -0
- package/skills/test-weigh-in/dashboard.html +70 -17
- package/skills/test-weigh-in/tests/browser_driver.py +46 -5
- package/skills/test-weigh-in/tests/layout_page.py +7 -3
- package/skills/test-weigh-in/tests/overlap_page.py +3 -0
- package/skills/test-weigh-in/tests/rules_fixture.py +1 -1
- package/skills/test-weigh-in/tests/test_coverage_run.py +5 -1
- package/skills/test-weigh-in/tests/test_dashboard_layout.py +50 -9
- package/skills/test-weigh-in/tests/test_score.py +53 -2
- package/skills/test-weigh-in/weigh.py +2 -2
- package/skills/test-weigh-in/weigh_coverage.py +22 -2
- package/skills/test-weigh-in/weigh_dashboard.py +51 -10
- package/skills/test-weigh-in/weigh_score.py +6 -3
- package/skills/test-weigh-in/weigh_smells.py +3 -2
- package/skills-manifest.json +3 -3
|
@@ -1,9 +1,10 @@
|
|
|
1
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
|
|
3
|
-
disputed or corrected a second time in its ticket.
|
|
2
|
+
(after a ruling, a review finding or a `correct-test` answer), and the `spec-ambiguous` question when a locked test is
|
|
3
|
+
disputed or corrected a second time in its ticket, or when its locked tests were settled `SETTLEMENTS` times.
|
|
4
4
|
|
|
5
|
-
A dispute is keyed by its locked
|
|
6
|
-
ruled file is
|
|
5
|
+
A dispute is keyed by its locked test, `<locked file>::<test>` (driver_report.test_key), so a parametrized case is its
|
|
6
|
+
test and another test of a ruled file is a first dispute. A review finding is keyed by `requested`. The ticket record
|
|
7
|
+
keeps the ruling in `disputes` and the correction in `corrected`, and counts both in `settled`.
|
|
7
8
|
"""
|
|
8
9
|
from __future__ import annotations
|
|
9
10
|
|
|
@@ -21,20 +22,21 @@ from driver_decisions import Resume
|
|
|
21
22
|
from driver_report import Dispute
|
|
22
23
|
from driver_run import OUT, Blocked, Call, Run, during, ledger, retry_point
|
|
23
24
|
|
|
25
|
+
SETTLEMENTS = 3 # arbitrations and review corrections per ticket before one more asks: no new test dodges the bound
|
|
26
|
+
|
|
24
27
|
class Corrected(NamedTuple):
|
|
25
|
-
"""The reading a locked
|
|
28
|
+
"""The reading a locked test is corrected to, which the ticket's `corrected` keeps: its one correction."""
|
|
26
29
|
test: str
|
|
27
30
|
requirement: str
|
|
28
31
|
reason: str
|
|
29
32
|
|
|
30
33
|
|
|
31
34
|
class Reading(NamedTuple):
|
|
32
|
-
"""The two readings of a locked test that a `spec-ambiguous` question asks about.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
"""The two readings of a locked test that a `spec-ambiguous` question asks about. The second is the reason of the
|
|
36
|
+
new dispute or finding."""
|
|
37
|
+
found: Dispute
|
|
35
38
|
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
|
|
39
|
+
first: str # the reading of its ruling or of its one correction, or the count at the cap
|
|
38
40
|
|
|
39
41
|
|
|
40
42
|
def _rulings(entry: dict) -> str:
|
|
@@ -58,22 +60,31 @@ def agent(run: Run, call: Call) -> dict:
|
|
|
58
60
|
|
|
59
61
|
def ambiguous(run: Run, number: str, readings: list[Reading], resume: Resume) -> NoReturn:
|
|
60
62
|
"""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
|
|
62
|
-
after the question: `spec-ambiguous-<n>.json` for
|
|
63
|
+
`correct-test` correction reads: one finding per locked test, to correct to the second reading, with the `key` that
|
|
64
|
+
`keep-test` closes. The file is named after the question: `spec-ambiguous-<n>.json` for
|
|
65
|
+
`<NN>-spec-ambiguous-<n>`."""
|
|
63
66
|
question = driver_decisions.question_id("spec-ambiguous", number, run.state.read()["run"]["questions"])
|
|
64
67
|
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
|
|
66
|
-
f"second reading: {one.
|
|
67
|
-
_ruling_findings(path, [(one.
|
|
68
|
+
subjects = [f"{one.found.test or one.found.file}{f', {one.requirement}' * bool(one.requirement)}: the first "
|
|
69
|
+
f"reading: {one.first}; the second reading: {one.found.reason}" for one in readings]
|
|
70
|
+
_ruling_findings(path, [(one.found, subject, f"correct the test to the second reading: {one.found.reason}")
|
|
68
71
|
for one, subject in zip(readings, subjects)])
|
|
69
72
|
subject = "; ".join(subjects)
|
|
70
73
|
run.ask(number, "spec-ambiguous", [subject], str(path), resume)
|
|
71
74
|
raise Blocked(f"the spec reads two ways on a locked test: {subject}")
|
|
72
75
|
|
|
73
76
|
|
|
74
|
-
def
|
|
75
|
-
"""
|
|
76
|
-
|
|
77
|
+
def requested(finding: dict) -> Dispute:
|
|
78
|
+
"""What a review finding on a locked file asks to correct, keyed: the test it names, the whole file for a
|
|
79
|
+
`fixture` finding that names none, else a test to add, keyed by its title."""
|
|
80
|
+
file, test, title = finding["file"], finding.get("test", ""), finding["title"]
|
|
81
|
+
key = driver_report.test_key(file, test) if test or finding["kind"] == "fixture" else f"{file}::+{title}"
|
|
82
|
+
return Dispute(file, test, f"{title}: {finding['evidence']}", key)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def kept(questions: list[dict], number: str) -> set[str]:
|
|
86
|
+
"""The keys of the `spec-ambiguous` questions of `number` answered `keep-test`."""
|
|
87
|
+
return {finding["key"] for q in questions if (q["ticket"], q["kind"], q["answer"]) ==
|
|
77
88
|
(number, "spec-ambiguous", "keep-test") for finding in json.loads(Path(q["evidence"][0]).read_text())}
|
|
78
89
|
|
|
79
90
|
|
|
@@ -85,38 +96,46 @@ def correction(questions: list[dict], number: str) -> dict:
|
|
|
85
96
|
return answered[-1] if answered else {}
|
|
86
97
|
|
|
87
98
|
|
|
88
|
-
def
|
|
89
|
-
"""
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
99
|
+
def admit(run: Run, number: str, found: list[Dispute], record: str, resume: Resume) -> None:
|
|
100
|
+
"""Ask `spec-ambiguous` instead of settling `found` when the ticket's `record` (`disputes` or `corrected`) has one
|
|
101
|
+
of its keys, or when the ticket's locked tests were settled `SETTLEMENTS` times: a renamed or added test has a new
|
|
102
|
+
key, so only the count bounds them."""
|
|
103
|
+
entry = run.state.read()["tickets"][number]
|
|
104
|
+
again = [Reading(one, entry[record][one.key]["requirement"], entry[record][one.key]["reason"])
|
|
105
|
+
for one in found if one.key in entry[record]]
|
|
106
|
+
if not again and entry["settled"] >= SETTLEMENTS:
|
|
107
|
+
first = f"the locked tests of this ticket were settled {entry['settled']} times, the most without a question"
|
|
108
|
+
again = [Reading(one, "", first) for one in found]
|
|
109
|
+
if again:
|
|
110
|
+
ambiguous(run, number, again, resume)
|
|
93
111
|
|
|
94
112
|
|
|
95
|
-
def _ruling_findings(path: Path, rulings: list[tuple[
|
|
96
|
-
"""Write the findings file of a correction to rulings: a critical finding of kind `ruling` per (
|
|
97
|
-
|
|
98
|
-
findings = [{"severity": "critical", "file": file, "
|
|
99
|
-
"kind": "ruling"} for
|
|
113
|
+
def _ruling_findings(path: Path, rulings: list[tuple[Dispute, str, str]]) -> list[dict]:
|
|
114
|
+
"""Write the findings file of a correction to rulings: a critical finding of kind `ruling` per (dispute, title,
|
|
115
|
+
evidence). Returns the findings."""
|
|
116
|
+
findings = [{"severity": "critical", "file": one.file, "test": one.test, "key": one.key, "line": 0, "title": title,
|
|
117
|
+
"evidence": evidence, "kind": "ruling"} for one, title, evidence in rulings]
|
|
100
118
|
path.write_text(json.dumps(findings, indent=1) + "\n")
|
|
101
119
|
return findings
|
|
102
120
|
|
|
103
121
|
|
|
104
|
-
def correct(run: Run, call: Call, findings: list[dict], readings: dict[str, Corrected], fate: str
|
|
122
|
+
def correct(run: Run, call: Call, findings: list[dict], readings: dict[str, tuple[str, Corrected]], fate: str,
|
|
123
|
+
settles: bool = False) -> dict[str, str]:
|
|
105
124
|
"""One test-writer correction of `findings`, outside the fix rounds. `call` is the test-writer's, its values point
|
|
106
125
|
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
|
|
108
|
-
|
|
126
|
+
ticket keeps, under its key, the reading in `readings` ({title: (key, reading)}) of each finding it corrected; a
|
|
127
|
+
review correction `settles`, in the same write. A ledger line per finding says what it did, with `fate` for one it
|
|
128
|
+
did not correct. Returns {title: reason} of each finding it did not correct."""
|
|
109
129
|
number = call.number
|
|
110
130
|
report = run.agent(replace(call, notes=["correction"],
|
|
111
131
|
check={"correction": True, "findings": [finding["title"] for finding in findings]}))
|
|
112
132
|
tip = driver_slots.head(call.slot)
|
|
113
133
|
reasons = {item["finding"]: item["reason"] for item in report.get("not_addressed", [])}
|
|
114
|
-
kept = {
|
|
115
|
-
if finding["file"] in readings and finding["title"] not in reasons}
|
|
134
|
+
kept = {key: reading._asdict() for title, (key, reading) in readings.items() if title not in reasons}
|
|
116
135
|
|
|
117
136
|
def record(state: dict) -> None:
|
|
118
137
|
entry = state["tickets"][number]
|
|
119
|
-
entry.update(tip=tip, **driver_locked.written(entry, report["locked"], tip))
|
|
138
|
+
entry.update(tip=tip, settled=entry["settled"] + settles, **driver_locked.written(entry, report["locked"], tip))
|
|
120
139
|
entry["corrected"].update(kept)
|
|
121
140
|
|
|
122
141
|
run.state.update(record)
|
|
@@ -138,52 +157,58 @@ def correct_as_answered(run: Run, call: Call, question: dict) -> None:
|
|
|
138
157
|
|
|
139
158
|
|
|
140
159
|
def _settle(run: Run, call: Call, disputed: list[Dispute]) -> None:
|
|
141
|
-
"""A locked
|
|
142
|
-
ruled `test-wrong` gets its one correction (a
|
|
143
|
-
keeps the rulings."""
|
|
160
|
+
"""A locked test disputed before, or a ticket settled `SETTLEMENTS` times, asks `spec-ambiguous`. Else the
|
|
161
|
+
reviewer rules on each disputed test, a test ruled `test-wrong` gets its one correction (a test corrected before
|
|
162
|
+
asks `spec-ambiguous`), and the ticket record keeps the rulings and counts the arbitration in one write."""
|
|
144
163
|
number = call.number
|
|
145
|
-
entry = run.state.read()["tickets"][number]
|
|
146
164
|
resume = retry_point(call.role, driver_slots.head(call.slot), call.fix_round)
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
n = 1 + len(entry["disputes"])
|
|
165
|
+
admit(run, number, disputed, "disputes", resume)
|
|
166
|
+
n = 1 + len(run.state.read()["tickets"][number]["disputes"])
|
|
150
167
|
ruled = _arbitrate(run, call, disputed, n)
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
168
|
+
|
|
169
|
+
def settle(state: dict) -> None:
|
|
170
|
+
entry = state["tickets"][number]
|
|
171
|
+
entry["disputes"].update({one.key: ruling for one, ruling in ruled})
|
|
172
|
+
entry["settled"] += 1
|
|
173
|
+
|
|
174
|
+
wrong = [(one._replace(reason=ruling["reason"]), ruling) for one, ruling in ruled
|
|
175
|
+
if ruling["ruling"] == "test-wrong"]
|
|
176
|
+
try: # the count did not move since the first admit, so only a test corrected before asks here
|
|
177
|
+
admit(run, number, [one for one, _ in wrong], "corrected", resume)
|
|
178
|
+
except Blocked:
|
|
179
|
+
run.state.update(settle) # the test is arbitrated
|
|
180
|
+
raise
|
|
156
181
|
if wrong:
|
|
157
182
|
_correct(run, call, wrong, n)
|
|
158
|
-
run.state.update(
|
|
183
|
+
run.state.update(settle)
|
|
159
184
|
|
|
160
185
|
|
|
161
|
-
def _arbitrate(run: Run, call: Call, disputed: list[Dispute], n: int) ->
|
|
162
|
-
"""The reviewer's ruling on each disputed locked
|
|
186
|
+
def _arbitrate(run: Run, call: Call, disputed: list[Dispute], n: int) -> list[tuple[Dispute, dict]]:
|
|
187
|
+
"""The reviewer's ruling on each disputed locked test, from `arbitration-<n>.json`, with its dispute."""
|
|
163
188
|
number, slot = call.number, call.slot
|
|
164
|
-
tip,
|
|
189
|
+
tip, by_test = driver_slots.head(slot), {one.test: one for one in disputed}
|
|
165
190
|
asked = {**call.values, "role": call.role, "start_sha": tip,
|
|
166
191
|
"disputed": "".join(f"- {one.test}: {one.reason}\n" for one in disputed),
|
|
167
192
|
"dispute_report": os.path.relpath(OUT / number / f"{call.role}-{call.fix_round}.json", slot)}
|
|
168
193
|
with during("the arbitration"):
|
|
169
194
|
report = run.read_only(number, slot, call.values["branch"], tip, lambda: run.agent(Call(
|
|
170
195
|
"reviewer", number, slot, asked, template="arbitration", name=f"arbitration-{n}", retry=call.role,
|
|
171
|
-
fix_round=call.fix_round, check={"disputed": list(
|
|
196
|
+
fix_round=call.fix_round, check={"disputed": list(by_test)})))
|
|
172
197
|
for ruling in report["rulings"]:
|
|
173
198
|
ledger(f"Ticket {number}: the reviewer ruled {ruling['ruling']} on the locked test {ruling['test']}, "
|
|
174
199
|
f"{ruling['requirement']}: {ruling['reason']}.")
|
|
175
|
-
return
|
|
200
|
+
return [(by_test[ruling["test"]], ruling) for ruling in report["rulings"] if ruling["test"] in by_test]
|
|
176
201
|
|
|
177
202
|
|
|
178
|
-
def _correct(run: Run, call: Call, wrong:
|
|
203
|
+
def _correct(run: Run, call: Call, wrong: list[tuple[Dispute, dict]], n: int) -> None:
|
|
179
204
|
"""The correction of the tests ruled `test-wrong`, each ruling a finding of kind `ruling` in `ruled-<n>.json`."""
|
|
180
205
|
number, slot = call.number, call.slot
|
|
181
206
|
path = OUT / number / f"ruled-{n}.json"
|
|
182
|
-
|
|
183
|
-
|
|
207
|
+
titled = [(one, f"{one.test}, {ruling['requirement']}", ruling) for one, ruling in wrong]
|
|
208
|
+
findings = _ruling_findings(path, [(one, title, ruling["reason"]) for one, title, ruling in titled])
|
|
184
209
|
values = {**call.values, "start_sha": driver_slots.head(slot), "findings": os.path.relpath(path, slot)}
|
|
185
|
-
readings = {
|
|
186
|
-
for
|
|
210
|
+
readings = {title: (one.key, Corrected(one.test, ruling["requirement"], ruling["reason"]))
|
|
211
|
+
for one, title, ruling in titled}
|
|
187
212
|
with during("the test-writer correction"):
|
|
188
213
|
correct(run, Call("test-writer", number, slot, values, name=f"correction-{n}", retry=call.role,
|
|
189
214
|
fix_round=call.fix_round), findings, readings, "")
|
|
@@ -16,7 +16,6 @@ import driver_review
|
|
|
16
16
|
import driver_slots
|
|
17
17
|
from driver_decisions import Resume
|
|
18
18
|
from driver_dispute import Corrected
|
|
19
|
-
from driver_report import Dispute
|
|
20
19
|
from driver_run import OUT, Blocked, Call, Run, during, ledger
|
|
21
20
|
from driver_tickets import Ticket
|
|
22
21
|
|
|
@@ -134,22 +133,19 @@ def _review(job: Job) -> list[dict]:
|
|
|
134
133
|
|
|
135
134
|
|
|
136
135
|
def _correct(job: Job, findings: list[dict]) -> list[dict]:
|
|
137
|
-
"""One test-writer correction for the findings on the locked tests. It is outside the fix rounds. A
|
|
138
|
-
was corrected before in the ticket
|
|
139
|
-
`ticket-blocked`, whose `retry` reviews the tip
|
|
140
|
-
of kind code for the fixer (issue #111)."""
|
|
136
|
+
"""One test-writer correction for the findings on the locked tests. It is outside the fix rounds. A finding whose
|
|
137
|
+
key (driver_dispute.requested) was corrected before in the ticket, or a ticket settled `SETTLEMENTS` times, asks
|
|
138
|
+
`spec-ambiguous` instead. A correction that is rejected twice asks `ticket-blocked`, whose `retry` reviews the tip
|
|
139
|
+
again. Returns the findings that it did not correct, as findings of kind code for the fixer (issue #111)."""
|
|
141
140
|
run, number = job.run, job.ticket.number
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
if again := driver_dispute.second_readings(found, corrected):
|
|
146
|
-
with during("the review"):
|
|
147
|
-
driver_dispute.ambiguous(run, number, again, Resume("review"))
|
|
141
|
+
found = {finding["title"]: driver_dispute.requested(finding) for finding in findings}
|
|
142
|
+
with during("the review"):
|
|
143
|
+
driver_dispute.admit(run, number, list(found.values()), "corrected", Resume("review"))
|
|
148
144
|
call = Call("test-writer", number, job.slot, job.pointers(job.round), fix_round=job.round + 1, retry="reviewer")
|
|
145
|
+
readings = {title: (one.key, Corrected(one.test, "", one.reason)) for title, one in found.items()}
|
|
149
146
|
with during("the test-writer correction"):
|
|
150
|
-
reasons = driver_dispute.correct(run, call, findings,
|
|
151
|
-
|
|
152
|
-
" It goes to the fixer as a finding of kind code.")
|
|
147
|
+
reasons = driver_dispute.correct(run, call, findings, readings,
|
|
148
|
+
" It goes to the fixer as a finding of kind code.", settles=True)
|
|
153
149
|
job.tip, job.previous = driver_slots.head(job.slot), ""
|
|
154
150
|
return _uncorrected(job, findings, reasons)
|
|
155
151
|
|
|
@@ -205,14 +201,15 @@ def _fix(job: Job, findings: list[dict], landing: str = "") -> None:
|
|
|
205
201
|
|
|
206
202
|
|
|
207
203
|
def _still_to_correct(job: Job, state: dict, to_correct: list[dict]) -> list[dict]:
|
|
208
|
-
"""The findings for a correction, but those on a
|
|
204
|
+
"""The findings for a correction, but those on a locked test whose `spec-ambiguous` question was answered
|
|
205
|
+
`keep-test`."""
|
|
209
206
|
number = job.ticket.number
|
|
210
|
-
kept = driver_dispute.
|
|
211
|
-
for finding in to_correct
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
return [finding for finding in to_correct if finding
|
|
207
|
+
kept = driver_dispute.kept(state["run"]["questions"], number)
|
|
208
|
+
closed = [finding for finding in to_correct if driver_dispute.requested(finding).key in kept]
|
|
209
|
+
for finding in closed:
|
|
210
|
+
ledger(f"Ticket {number}: {finding['kind']} finding in {finding['file']} closed as it is by the ruling "
|
|
211
|
+
f"(keep-test), with no correction: {finding['title']}.")
|
|
212
|
+
return [finding for finding in to_correct if finding not in closed]
|
|
216
213
|
|
|
217
214
|
|
|
218
215
|
def _save_must_fix(state: dict, number: str, findings: list[dict]) -> None:
|
|
@@ -4,17 +4,20 @@
|
|
|
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
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
|
+
before schema 4 keeps the ruling of each answered question, and one with an open question of a removed kind stops;
|
|
8
|
+
a run before schema 5 gets its rulings and corrections keyed by their test.
|
|
8
9
|
ponytail: delete this module, tests/test_legacy.py and its one line in driver._hold and in driver._start_errors
|
|
9
10
|
once no older driver is left.
|
|
10
11
|
"""
|
|
11
12
|
from __future__ import annotations
|
|
12
13
|
|
|
14
|
+
import json
|
|
13
15
|
from pathlib import Path
|
|
14
16
|
from types import MappingProxyType
|
|
15
17
|
from typing import IO
|
|
16
18
|
|
|
17
19
|
import driver_decisions
|
|
20
|
+
import driver_report
|
|
18
21
|
import driver_slots
|
|
19
22
|
import driver_state
|
|
20
23
|
from driver_names import Names
|
|
@@ -141,9 +144,34 @@ def _ruled(q: dict) -> str:
|
|
|
141
144
|
return f"Ruling: {q['ticket'] or 'end of run'} {q['kind']} ({q['answer']}): {q['subject']}."
|
|
142
145
|
|
|
143
146
|
|
|
147
|
+
def _per_test(entry: dict, evidence: list[Path]) -> None:
|
|
148
|
+
"""Schema 5: `disputes` and `corrected` move from their locked file to the test each record names, a review
|
|
149
|
+
correction that named only its file to the file itself, and each finding of `evidence`, the files of the ticket's
|
|
150
|
+
`spec-ambiguous` questions, gets the key of its file's record. `settled` counts one per record that is not the
|
|
151
|
+
correction of a ruling, so an arbitration of two files counts two: the cap comes no later than it would."""
|
|
152
|
+
disputes, corrected = entry.get("disputes", {}), entry.get("corrected", {})
|
|
153
|
+
keys = {file: driver_report.test_key(file, record["test"]) for file, record in {**corrected, **disputes}.items()}
|
|
154
|
+
entry["disputes"] = {keys[file]: record for file, record in disputes.items()}
|
|
155
|
+
entry["corrected"] = {keys[file]: record for file, record in corrected.items()}
|
|
156
|
+
entry["settled"] = len(disputes) + len(corrected.keys() - disputes.keys())
|
|
157
|
+
for path in evidence:
|
|
158
|
+
findings = json.loads(path.read_text())
|
|
159
|
+
path.write_text(json.dumps([{"key": keys.get(one["file"], one["file"]), **one} for one in findings],
|
|
160
|
+
indent=1) + "\n")
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def _all_per_test(state: dict) -> None:
|
|
164
|
+
"""Schema 5 for each ticket not keyed per test yet, with the evidence of its `spec-ambiguous` questions."""
|
|
165
|
+
for number, entry in state["tickets"].items():
|
|
166
|
+
if "settled" not in entry: # schema 5 added it, so its presence marks a ticket already keyed per test
|
|
167
|
+
asked = [Path(q["evidence"][0]) for q in state["run"].get("questions", [])
|
|
168
|
+
if (q["ticket"], q["kind"]) == (number, "spec-ambiguous")]
|
|
169
|
+
_per_test(entry, [path for path in asked if path.exists()])
|
|
170
|
+
|
|
171
|
+
|
|
144
172
|
def _upgraded(state: dict) -> None:
|
|
145
173
|
"""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."""
|
|
174
|
+
Schema 4: an answered question keeps its ruling sentence. Schema 5: see `_per_test`."""
|
|
147
175
|
run = state["run"]
|
|
148
176
|
for q in run.get("questions", []):
|
|
149
177
|
if q["answer"] is not None:
|
|
@@ -151,6 +179,7 @@ def _upgraded(state: dict) -> None:
|
|
|
151
179
|
for record in [run.get("final", {}), *state["tickets"].values()]:
|
|
152
180
|
if isinstance(record.get("green_gates"), list):
|
|
153
181
|
record["green_gates"] = {**driver_state.tiers(), "full": record["green_gates"]}
|
|
182
|
+
_all_per_test(state)
|
|
154
183
|
if isinstance(run.get("gates"), int):
|
|
155
184
|
run["gates"] = {"fast": 0, "full": run["gates"]}
|
|
156
185
|
run["schema"] = driver_state.SCHEMA
|
|
@@ -160,11 +160,20 @@ def _locked_file(name: str, locked: list[str]) -> str:
|
|
|
160
160
|
return found[0] if len(found) == 1 else ""
|
|
161
161
|
|
|
162
162
|
|
|
163
|
+
def test_key(file: str, test: str) -> str:
|
|
164
|
+
"""`<locked file>::<test>`, the key of a locked test in `disputes` and `corrected`: `test` is an id `<path>::<test>`
|
|
165
|
+
or a bare name, and a parametrized case is its test. The file itself when `test` names no test."""
|
|
166
|
+
name = re.sub(r"\[.*\]$", "", test.partition("::")[2] if "::" in test else test)
|
|
167
|
+
return f"{file}::{name}" if name and name != file else file
|
|
168
|
+
|
|
169
|
+
|
|
163
170
|
class Dispute(NamedTuple):
|
|
164
|
-
"""One concern `locked test contradicts spec: <file>::<test>: <reason>` of a BLOCKED implementer or fixer
|
|
171
|
+
"""One concern `locked test contradicts spec: <file>::<test>: <reason>` of a BLOCKED implementer or fixer, or a
|
|
172
|
+
review finding on a locked file (driver_dispute.requested)."""
|
|
165
173
|
file: str # the locked file it names; "" when it names no file of the ticket's `locked`
|
|
166
|
-
test: str
|
|
174
|
+
test: str # as the report gives it; "" for a review finding that names no test
|
|
167
175
|
reason: str
|
|
176
|
+
key: str # what `disputes` and `corrected` key it by: one dispute or correction each
|
|
168
177
|
|
|
169
178
|
|
|
170
179
|
def disputes(role: str, report: dict, locked: list[str]) -> list[Dispute]:
|
|
@@ -175,7 +184,8 @@ def disputes(role: str, report: dict, locked: list[str]) -> list[Dispute]:
|
|
|
175
184
|
for concern in report["concerns"]:
|
|
176
185
|
if concern.startswith(CONTRADICTS):
|
|
177
186
|
test, _, reason = concern[len(CONTRADICTS):].strip().partition(": ")
|
|
178
|
-
|
|
187
|
+
file = _locked_file(test.partition("::")[0], locked)
|
|
188
|
+
found.append(Dispute(file, test, reason, test_key(file, test)))
|
|
179
189
|
return found
|
|
180
190
|
|
|
181
191
|
|
|
@@ -44,8 +44,8 @@ class Blocked(Exception):
|
|
|
44
44
|
|
|
45
45
|
|
|
46
46
|
class Halted(Exception):
|
|
47
|
-
"""The CLI of an agent failed with no report
|
|
48
|
-
signed in. The run starts no other agent and ends with exit 4; the ticket keeps its phase for the next run."""
|
|
47
|
+
"""The CLI of an agent failed with no report: a model the account cannot use or has no usage left for, a CLI
|
|
48
|
+
that is not signed in. The run starts no other agent and ends with exit 4; the ticket keeps its phase for the next run."""
|
|
49
49
|
|
|
50
50
|
|
|
51
51
|
@contextmanager
|
|
@@ -319,11 +319,9 @@ def _ask_blocked(run: Run, call: Call, report: Path, error: str) -> None:
|
|
|
319
319
|
run.ask(call.number, "ticket-blocked", [f"the {call.role}: {error}"], str(report), resume)
|
|
320
320
|
|
|
321
321
|
|
|
322
|
-
def _give_up(run: Run, call: Call, report: Path, error: str,
|
|
323
|
-
"""After the rerun failed too:
|
|
324
|
-
|
|
325
|
-
if failed:
|
|
326
|
-
raise Halted(failed)
|
|
322
|
+
def _give_up(run: Run, call: Call, report: Path, error: str, same: bool) -> NoReturn:
|
|
323
|
+
"""After the rerun failed too: Blocked, with a `ticket-blocked` question when the agent stopped or was
|
|
324
|
+
rejected."""
|
|
327
325
|
if not same:
|
|
328
326
|
_ask_blocked(run, call, report, error)
|
|
329
327
|
raise Blocked(error)
|
|
@@ -344,13 +342,24 @@ def _first_prompt(template: str, values: dict[str, str], notes: tuple | list, re
|
|
|
344
342
|
|
|
345
343
|
|
|
346
344
|
def _record_attempt(run: Run, role: str, number: str, entry: str, seconds: float, log: Path, error: str) -> None:
|
|
347
|
-
|
|
348
|
-
|
|
345
|
+
tokens = driver_agents.tokens(log)
|
|
346
|
+
cost = driver_agents.cost(log, entry, tokens)
|
|
347
|
+
# cost None: not priced, a codex model with no list price or a CLI that reported none.
|
|
348
|
+
used = {"ticket": number, "role": role, "entry": entry, "seconds": round(seconds, 1), "cost": cost,
|
|
349
|
+
"tokens": tokens}
|
|
349
350
|
run.state.update(lambda state: state["run"]["agents"].append(used))
|
|
350
|
-
spent = f", cost {cost} USD" if cost else
|
|
351
|
+
spent = f", cost {cost:g} USD" if cost is not None else _unpriced(tokens)
|
|
351
352
|
ledger(f"{_owner(number)}: {role} ran on {entry} for {seconds:.1f}s{spent}: {error or 'report accepted'}.")
|
|
352
353
|
|
|
353
354
|
|
|
355
|
+
def _unpriced(tokens: dict[str, int]) -> str:
|
|
356
|
+
"""The ledger words of a codex agent whose model has no list price: its tokens; "" when it has none."""
|
|
357
|
+
if not tokens:
|
|
358
|
+
return ""
|
|
359
|
+
return (f", {tokens['input']} input tokens ({tokens['cached_input']} cached) and {tokens['output']} output tokens, "
|
|
360
|
+
"not priced")
|
|
361
|
+
|
|
362
|
+
|
|
354
363
|
def _command(run: Run, role: str, entry: str, prompt: str, report: str) -> list[str]:
|
|
355
364
|
if run.args.runner: # `--runner` is for tests
|
|
356
365
|
return [run.args.runner, role, prompt, report]
|
|
@@ -370,7 +379,7 @@ def _attempts(run: Run, call: Call) -> dict:
|
|
|
370
379
|
"template": call.template or role, **call.check}
|
|
371
380
|
text = _first_prompt(context["template"], values, call.notes, report_in_slot)
|
|
372
381
|
rerun_on = _rerun_entry(run, role, entry, call.entries)
|
|
373
|
-
minutes, error,
|
|
382
|
+
minutes, error, same = run.args.timeout[role], "", True
|
|
374
383
|
for _ in range(2):
|
|
375
384
|
argv = _command(run, role, entry, os.path.relpath(prompt, slot), report_in_slot)
|
|
376
385
|
prompt.write_text(text)
|
|
@@ -386,10 +395,11 @@ def _attempts(run: Run, call: Call) -> dict:
|
|
|
386
395
|
_record_attempt(run, role, number, entry, seconds, log, error)
|
|
387
396
|
if not error:
|
|
388
397
|
return json.loads(report.read_text())
|
|
389
|
-
failed
|
|
398
|
+
if failed := _cli_failure(role, entry, code, report, log):
|
|
399
|
+
raise Halted(failed) # the operator changes the config: the run moves to no other entry on its own
|
|
390
400
|
# The rerun prompt is the first prompt, the rejection, then the same ending again.
|
|
391
401
|
text += rerun_lines + driver_agents.tail(text, report_in_slot)
|
|
392
402
|
if code is None:
|
|
393
403
|
minutes *= 2
|
|
394
404
|
entry = entry if same else rerun_on
|
|
395
|
-
_give_up(run, call, report, error,
|
|
405
|
+
_give_up(run, call, report, error, same)
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
"""state.json, the resume contract: one lock, every write a read-modify-write, published by rename.
|
|
2
2
|
|
|
3
|
-
{"run": {revision, pr_branch, schema, gates: {fast, full}, stops, agents: [{ticket, role, entry, seconds, cost}], questions, start,
|
|
3
|
+
{"run": {revision, pr_branch, schema, gates: {fast, full}, stops, agents: [{ticket, role, entry, seconds, cost, tokens}], questions, start,
|
|
4
4
|
landed: [[ticket, the PR tip its merge made]], final},
|
|
5
5
|
"tickets": {"NN": {phase, round, tip, test_writer_sha, locked, green_gates, slot, note,
|
|
6
|
-
landing, disputes, corrected}}}
|
|
6
|
+
landing, disputes, corrected, settled}}}
|
|
7
7
|
|
|
8
8
|
green_gates is {"fast": [commit], "full": [commit]}, in a ticket and in run.final: a fast green never stands in for a
|
|
9
9
|
full one. landing is the commit whose full gate was red at the landing while the fixer of the round it started has
|
|
10
|
-
not reported, else None. disputes is {locked file
|
|
11
|
-
the
|
|
12
|
-
at most one of each per ticket
|
|
10
|
+
not reported, else None. disputes is {<locked file>::<test>: {test, requirement, ruling, reason}}, the reviewer's
|
|
11
|
+
ruling on the test; corrected is {<locked file>::<test>: {test, requirement, reason}}, the reading of its one
|
|
12
|
+
correction. A locked test has at most one of each per ticket. settled counts the arbitrations and review corrections
|
|
13
|
+
of the ticket's locked tests. No answer writes the three."""
|
|
13
14
|
from __future__ import annotations
|
|
14
15
|
|
|
15
16
|
import fcntl
|
|
@@ -23,8 +24,8 @@ from typing import IO
|
|
|
23
24
|
from driver_names import Names
|
|
24
25
|
from driver_slots import ancestor, git, on_branch, path
|
|
25
26
|
|
|
26
|
-
SCHEMA =
|
|
27
|
-
# the ruling kept on an answered question. A run of an older driver has none.
|
|
27
|
+
SCHEMA = 5 # the version of this contract; 2: the names of driver_names, 3: gate tiers, 4: the two question kinds and
|
|
28
|
+
# the ruling kept on an answered question, 5: disputes and corrected per locked test. A run of an older driver has none.
|
|
28
29
|
PHASES = ("pending", "test-writer", "implement", "gate", "review", "fix", "merge", "merged", "blocked")
|
|
29
30
|
|
|
30
31
|
|
|
@@ -35,7 +36,7 @@ def tiers() -> dict:
|
|
|
35
36
|
|
|
36
37
|
def _ticket() -> dict:
|
|
37
38
|
return {"phase": "pending", "round": 0, "tip": None, "test_writer_sha": None, "locked": [], "green_gates": tiers(),
|
|
38
|
-
"slot": None, "note": "", "landing": None, "disputes": {}, "corrected": {}}
|
|
39
|
+
"slot": None, "note": "", "landing": None, "disputes": {}, "corrected": {}, "settled": 0}
|
|
39
40
|
|
|
40
41
|
|
|
41
42
|
def _final() -> dict:
|
|
@@ -15,7 +15,14 @@ def _rows(run: dict, tickets: dict) -> list[tuple[str, object]]:
|
|
|
15
15
|
*((f"wall time, {role}", f"{total:.1f} s") for role, total in seconds.items()),
|
|
16
16
|
("fix rounds per ticket", rounds),
|
|
17
17
|
("human stops", run["stops"]),
|
|
18
|
-
(
|
|
18
|
+
*_cost(run["agents"])]
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _cost(agents: list[dict]) -> list[tuple[str, object]]:
|
|
22
|
+
"""The cost row, and a row that counts the agents with no price (cost None), which the cost leaves out."""
|
|
23
|
+
unpriced = sum(agent["cost"] is None for agent in agents)
|
|
24
|
+
return [("cost", f"{sum(agent['cost'] or 0 for agent in agents):.2f} USD"),
|
|
25
|
+
*([("agents not priced", unpriced)] if unpriced else [])]
|
|
19
26
|
|
|
20
27
|
|
|
21
28
|
def _end(run: dict) -> list[str]:
|
|
@@ -3,6 +3,7 @@ This call is a correction of the locked tests, not a new test set. Read in {find
|
|
|
3
3
|
A `ruling` finding: a ruling says that a locked test contradicts the spec, and its `evidence` gives the reading of the spec that the test must assert. Change what the test asserts to that reading.
|
|
4
4
|
A `fixture` finding: a locked test encodes a stale path, format, fixture layout or setup detail. Correct only that detail and keep what each test asserts.
|
|
5
5
|
A `test` finding: a locked test is too weak, for example it stays green when the production line it protects is broken. Make the test assert the behavior of its criterion so that it fails on that break. Do not remove an assertion.
|
|
6
|
+
A `test` finding with no `test` field: a test that the ticket asks for is missing. Add it to the finding's file.
|
|
6
7
|
A finding on a locked file of another ticket, of any kind: only this correction may change that file. When the ticket must change it, as one that its Touches line names, make the change, keep what each test of the other ticket asserts, and list the file in `locked`.
|
|
7
8
|
For this you may read the implementation. Keep each test that no finding names as it is, and commit only the test files you correct.
|
|
8
9
|
When a finding needs a production change first, so that no correct test can be green, leave the test as it is and add the finding to `not_addressed`: `finding` is its `title` as the findings file gives it, `reason` is the production change it needs. The driver sends it to the fixer as a finding of kind `code`. A correction whose findings are all in `not_addressed` may report DONE with no commit.
|
|
@@ -9,7 +9,7 @@ Test-writer report, when the ticket has a test-writer: {writer_report}
|
|
|
9
9
|
|
|
10
10
|
Check the diff against the ticket and the spec. Put only an unmet ticket criterion or a regression of a merged ticket's behavior in `findings`; set `basis` to `criterion` or `regression` accordingly; put every other observation in `observations` for final review. A red gate is a finding made by the driver. Check that each criterion has a locked test. Test each suspicion that the ticket names in its Suspicions line.
|
|
11
11
|
{risk}
|
|
12
|
-
Give each finding and observation a severity (critical, important or minor), the file and line, a title, the evidence, and a kind: `fixture` when a locked test encodes a stale path, format or setup detail; `test` when a test is weak or missing; `code` for anything else. The test-writer corrects each `fixture` finding and each critical or important `test` finding on a locked file, and the fixer gets the rest.
|
|
12
|
+
Give each finding and observation a severity (critical, important or minor), the file and line, a title, the evidence, and a kind: `fixture` when a locked test encodes a stale path, format or setup detail; `test` when a test is weak or missing; `code` for anything else. When a `fixture` or `test` finding is on a locked test that exists, give its id `<locked file>::<test>` in `test`; leave `test` out when the finding asks for a test that is missing. The test-writer corrects each `fixture` finding and each critical or important `test` finding on a locked file, and the fixer gets the rest.
|
|
13
13
|
Do not commit and do not dispatch subagents. Leave the tree as you found it.
|
|
14
14
|
|
|
15
15
|
Write one JSON report at {report}. When your sandbox is read-only, give the JSON as your whole final message and the driver saves it there. The report matches this schema:
|
|
@@ -22,9 +22,9 @@ Write one JSON report at {report}. When your sandbox is read-only, give the JSON
|
|
|
22
22
|
"status": {"enum": ["DONE", "DONE_WITH_CONCERNS", "NEEDS_CONTEXT", "BLOCKED"]},
|
|
23
23
|
"files": {"type": "array", "items": {"type": "string"}},
|
|
24
24
|
"concerns": {"type": "array", "items": {"type": "string"}},
|
|
25
|
-
"findings": {"type": "array", "items": {"type": "object", "required": ["severity", "file", "line", "title", "evidence", "kind"], "properties": {"severity": {"enum": ["critical", "important", "minor"]}, "file": {"type": "string"}, "line": {"type": "integer"}, "title": {"type": "string", "minLength": 1}, "evidence": {"type": "string", "minLength": 1}, "kind": {"enum": ["code", "fixture", "test"]}, "basis": {"enum": ["criterion", "regression"]}}}},
|
|
25
|
+
"findings": {"type": "array", "items": {"type": "object", "required": ["severity", "file", "line", "title", "evidence", "kind"], "properties": {"severity": {"enum": ["critical", "important", "minor"]}, "file": {"type": "string"}, "line": {"type": "integer"}, "title": {"type": "string", "minLength": 1}, "evidence": {"type": "string", "minLength": 1}, "kind": {"enum": ["code", "fixture", "test"]}, "test": {"type": "string", "minLength": 1}, "basis": {"enum": ["criterion", "regression"]}}}},
|
|
26
26
|
"observations": {"type": "array", "items": {"type": "object", "required": ["severity", "file", "line", "title", "evidence", "kind"], "properties": {"severity": {"enum": ["critical", "important", "minor"]}, "file": {"type": "string"}, "line": {"type": "integer"}, "title": {"type": "string", "minLength": 1}, "evidence": {"type": "string", "minLength": 1}, "kind": {"enum": ["code", "fixture", "test"]}}}},
|
|
27
|
-
"regressions": {"description": "After a fix: new regressions introduced by that fix. Set basis to criterion when a ticket criterion fails, or regression when merged-ticket behavior fails.", "type": "array", "items": {"type": "object", "required": ["severity", "file", "line", "title", "evidence", "kind"], "properties": {"severity": {"enum": ["critical", "important", "minor"]}, "file": {"type": "string"}, "line": {"type": "integer"}, "title": {"type": "string", "minLength": 1}, "evidence": {"type": "string", "minLength": 1}, "kind": {"enum": ["code", "fixture", "test"]}, "basis": {"enum": ["criterion", "regression"]}}}}
|
|
27
|
+
"regressions": {"description": "After a fix: new regressions introduced by that fix. Set basis to criterion when a ticket criterion fails, or regression when merged-ticket behavior fails.", "type": "array", "items": {"type": "object", "required": ["severity", "file", "line", "title", "evidence", "kind"], "properties": {"severity": {"enum": ["critical", "important", "minor"]}, "file": {"type": "string"}, "line": {"type": "integer"}, "title": {"type": "string", "minLength": 1}, "evidence": {"type": "string", "minLength": 1}, "kind": {"enum": ["code", "fixture", "test"]}, "test": {"type": "string", "minLength": 1}, "basis": {"enum": ["criterion", "regression"]}}}}
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
```
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
|
|
2
2
|
The reviewer ruled on locked tests of this ticket that an earlier attempt disputed:
|
|
3
|
-
{rulings}A test ruled `test-wrong` was corrected by the test-writer, and a test ruled `code-wrong` stands. Each locked test stands as the branch has it now: make it green. A second dispute on one of these
|
|
3
|
+
{rulings}A test ruled `test-wrong` was corrected by the test-writer, and a test ruled `code-wrong` stands. Each locked test stands as the branch has it now: make it green. A second dispute on one of these tests goes to the operator as a question of the spec.
|
|
@@ -25,6 +25,8 @@ def pr_skill(tmp_path_factory):
|
|
|
25
25
|
(home / "skills/pr/SKILL.md").write_text("---\nname: pr\n---\n")
|
|
26
26
|
with pytest.MonkeyPatch.context() as patch:
|
|
27
27
|
patch.setenv("CLAUDE_CONFIG_DIR", str(home))
|
|
28
|
+
# No test reads the operator's own provider config (driver_agents.load_models).
|
|
29
|
+
patch.setenv("XDG_CONFIG_HOME", str(tmp_path_factory.mktemp("config-home")))
|
|
28
30
|
yield home / "skills/pr/SKILL.md"
|
|
29
31
|
|
|
30
32
|
|