@jesdi/skills 0.0.87 → 0.0.89
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/babysit-pr/SKILL.md +1 -1
- package/skills/babysit-pr/babysit.py +21 -10
- package/skills/babysit-pr/fixtures/gh +2 -1
- package/skills/babysit-pr/judge-prompt.md +7 -3
- package/skills/babysit-pr/test_babysit_judge.py +16 -10
- package/skills/babysit-pr/test_babysit_judge_isolation.py +1 -1
- package/skills/babysit-pr/test_handoff_takeover.py +1 -1
- package/skills/babysit-pr/test_merge_and_handoff.py +17 -16
- package/skills/babysit-pr/test_merge_base_pin.py +1 -1
- package/skills/babysit-pr/test_merge_gate.py +49 -14
- package/skills/babysit-pr/test_merge_session_safety.py +3 -3
- package/skills/babysit-pr/test_merged_pr_labels.py +1 -1
- package/skills/babysit-pr/test_terminal_label_regressions.py +1 -1
- package/skills/babysit-pr/test_trusted_merge_risk.py +1 -1
- package/skills/implement-spec/ARCHITECTURE.md +20 -8
- package/skills/implement-spec/README.md +7 -4
- 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_state.py +8 -7
- 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/test_arbitration.py +101 -10
- package/skills/implement-spec/tests/test_decisions.py +7 -5
- package/skills/implement-spec/tests/test_final.py +1 -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_state.py +1 -1
- package/skills/implement-spec/tests/test_walk.py +1 -1
- package/skills/pr-risk/SKILL.md +18 -3
- package/skills/pr-risk/merge_policy.py +29 -9
- package/skills/pr-risk/merge_risk.py +57 -14
- package/skills/pr-risk/test_hooks.py +2 -2
- package/skills/pr-risk/test_merge_risk.py +2 -2
- package/skills/pr-risk/test_merge_risk_gate.py +128 -43
- package/skills/pr-risk/test_merge_risk_regressions.py +5 -5
- package/skills/pr-risk/test_merge_risk_structure.py +5 -4
- 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 +9 -9
|
@@ -73,9 +73,9 @@ def test_a_test_ruled_wrong_gets_one_correction_with_the_ruling_then_the_impleme
|
|
|
73
73
|
assert ".agent/implement/01/ruled-1.json" in fixed["prompt"] and again["head"] == fixed["sha"]
|
|
74
74
|
assert "R3 says single quotes" in again["prompt"]
|
|
75
75
|
entry = rig.state()["tickets"]["01"]
|
|
76
|
-
assert entry["disputes"][
|
|
77
|
-
assert entry["corrected"] == {
|
|
78
|
-
|
|
76
|
+
assert entry["disputes"][TEST]["ruling"] == "test-wrong" and entry["test_writer_sha"] == fixed["sha"]
|
|
77
|
+
assert entry["corrected"] == {TEST: {"test": TEST, "requirement": "R3", "reason": "R3 says single quotes"}}
|
|
78
|
+
assert entry["settled"] == 1
|
|
79
79
|
assert rig.led("the reviewer ruled test-wrong on the locked test tests/test_01.py::test_x, R3")
|
|
80
80
|
|
|
81
81
|
|
|
@@ -116,7 +116,7 @@ def test_a_dispute_on_another_locked_file_is_arbitrated_too(tmp_path):
|
|
|
116
116
|
ruling("code-wrong", "R4 says y is a column", f"{OTHER}::test_y", "R4"),
|
|
117
117
|
review("01")]})
|
|
118
118
|
assert rig.code == 0 and not rig.state()["run"]["questions"], rig.ledger()
|
|
119
|
-
assert len(arbitrations(rig)) == 2 and set(rig.state()["tickets"]["01"]["disputes"]) == {
|
|
119
|
+
assert len(arbitrations(rig)) == 2 and set(rig.state()["tickets"]["01"]["disputes"]) == {TEST, f"{OTHER}::test_y"}
|
|
120
120
|
assert (rig.folder() / "arbitration-2.json").exists()
|
|
121
121
|
|
|
122
122
|
|
|
@@ -182,7 +182,7 @@ def test_a_second_dispute_on_the_same_test_asks_spec_ambiguous_with_both_reading
|
|
|
182
182
|
|
|
183
183
|
|
|
184
184
|
def test_after_a_correction_a_review_finding_on_the_test_asks_spec_ambiguous(tmp_path):
|
|
185
|
-
stale = finding("STALE", kind="fixture", file="tests/test_01.py")
|
|
185
|
+
stale = {**finding("STALE", kind="fixture", file="tests/test_01.py"), "test": TEST}
|
|
186
186
|
rig = run(tmp_path, {"01/implementer": [disputes(), impl("01")], "01/test-writer": [tw("01"), correction()],
|
|
187
187
|
"01/reviewer": [ruling("test-wrong", "R3 says single quotes"), review("01", [stale])]})
|
|
188
188
|
assert rig.code == 2 and len(rig.calls("01", "test-writer")) == 2, rig.ledger()
|
|
@@ -192,7 +192,7 @@ def test_after_a_correction_a_review_finding_on_the_test_asks_spec_ambiguous(tmp
|
|
|
192
192
|
|
|
193
193
|
|
|
194
194
|
def test_a_test_ruled_wrong_that_a_review_corrected_before_asks_spec_ambiguous(tmp_path):
|
|
195
|
-
stale = finding("STALE", kind="fixture", file="tests/test_01.py")
|
|
195
|
+
stale = {**finding("STALE", kind="fixture", file="tests/test_01.py"), "test": TEST}
|
|
196
196
|
rig = run(tmp_path, {"01/test-writer": [tw("01"), correction()],
|
|
197
197
|
"01/reviewer": [review("01", [stale, STUCK]), ruling("test-wrong", "R3 says single quotes")],
|
|
198
198
|
"01/fixer": [disputes(role="fixer")]})
|
|
@@ -203,18 +203,109 @@ def test_a_test_ruled_wrong_that_a_review_corrected_before_asks_spec_ambiguous(t
|
|
|
203
203
|
|
|
204
204
|
|
|
205
205
|
def test_a_ruling_that_asks_spec_ambiguous_is_kept_so_a_dispute_after_keep_test_is_not_arbitrated_again(tmp_path):
|
|
206
|
-
stale = finding("STALE", kind="fixture", file="tests/test_01.py")
|
|
206
|
+
stale = {**finding("STALE", kind="fixture", file="tests/test_01.py"), "test": TEST}
|
|
207
207
|
steps = plan(**{"01/test-writer": [tw("01"), correction()],
|
|
208
208
|
"01/reviewer": [review("01", [stale, STUCK]), ruling("test-wrong", "R3 says single quotes"),
|
|
209
209
|
review("01", [STUCK]), ruling("test-wrong", "R3 says single quotes")],
|
|
210
210
|
"01/fixer": [disputes(role="fixer"), disputes(role="fixer")]})
|
|
211
211
|
rig = Inside(tmp_path, ONE).run(steps)
|
|
212
|
-
assert rig.state()["tickets"]["01"]["disputes"][
|
|
212
|
+
assert rig.state()["tickets"]["01"]["disputes"][TEST]["ruling"] == "test-wrong", rig.ledger()
|
|
213
213
|
rig.run(steps, "--answer", f"{AMBIGUOUS}=keep-test")
|
|
214
214
|
assert rig.code == 2 and len(arbitrations(rig)) == 1, rig.ledger()
|
|
215
215
|
assert [q["id"] for q in asked(rig)] == ["01-spec-ambiguous-2"]
|
|
216
216
|
|
|
217
217
|
|
|
218
|
+
# ---------------------------------------------------------------- per test, not per file
|
|
219
|
+
|
|
220
|
+
TEST_Y = "tests/test_01.py::test_y"
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def test_a_dispute_of_another_test_in_a_corrected_file_is_arbitrated_and_corrected_with_no_question(tmp_path):
|
|
224
|
+
"""The cv-tailoring run asked 02-spec-ambiguous-1 here: test_x was corrected, then test_y of its file disputed."""
|
|
225
|
+
rig = run(tmp_path, {"01/implementer": [disputes(), disputes((TEST_Y, "a dict has no .body")), impl("01")],
|
|
226
|
+
"01/test-writer": [tw("01"), correction(), correction(CORRECTED + "def test_y():\n pass\n")],
|
|
227
|
+
"01/reviewer": [ruling("test-wrong", "R3 says single quotes"),
|
|
228
|
+
ruling("test-wrong", "a dict has no .body", TEST_Y, "R5"), review("01")]})
|
|
229
|
+
assert rig.code == 0 and not rig.state()["run"]["questions"], rig.ledger()
|
|
230
|
+
assert roles(rig) == ["test-writer", "implementer", "arbitration", "test-writer", "implementer", "arbitration",
|
|
231
|
+
"test-writer", "implementer", "reviewer"]
|
|
232
|
+
entry = rig.state()["tickets"]["01"]
|
|
233
|
+
assert set(entry["disputes"]) == set(entry["corrected"]) == {TEST, TEST_Y}
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
WEAK_Y = {**finding("WEAK", "critical", kind="test", file="tests/test_01.py"), "test": TEST_Y}
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
@pytest.mark.parametrize("found", [finding("MISSING", "critical", kind="test", file="tests/test_01.py"), WEAK_Y],
|
|
240
|
+
ids=["missing-test", "another-test"])
|
|
241
|
+
def test_a_review_finding_after_a_correction_of_another_test_gets_a_correction_with_no_question(tmp_path, found):
|
|
242
|
+
"""The cv-tailoring run asked 01-spec-ambiguous-2 here: a review asked for missing tests in a corrected file."""
|
|
243
|
+
rig = run(tmp_path, {"01/implementer": [disputes(), impl("01")],
|
|
244
|
+
"01/test-writer": [tw("01"), correction(), correction(CORRECTED + "def test_z():\n pass\n")],
|
|
245
|
+
"01/reviewer": [ruling("test-wrong", "R3 says single quotes"), review("01", [found]),
|
|
246
|
+
review("01")]})
|
|
247
|
+
assert rig.code == 0 and not rig.state()["run"]["questions"], rig.ledger()
|
|
248
|
+
assert roles(rig) == ["test-writer", "implementer", "arbitration", "test-writer", "implementer", "reviewer",
|
|
249
|
+
"test-writer", "reviewer"]
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
def missing(n):
|
|
253
|
+
"""A review finding that asks for the missing test `n` of tests/test_01.py."""
|
|
254
|
+
return finding(f"MISSING-{n}", "critical", kind="test", file="tests/test_01.py")
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def test_the_ticket_asks_spec_ambiguous_once_its_locked_tests_were_settled_three_times(tmp_path):
|
|
258
|
+
"""A test added is never corrected twice, so a cap bounds the review that keeps asking for one more."""
|
|
259
|
+
steps = {"01/test-writer": [tw("01"), *[correction(f"# added {n}\n") for n in range(1, 4)]],
|
|
260
|
+
"01/reviewer": [review("01", [missing(n)]) for n in range(1, 5)] + [review("01")]}
|
|
261
|
+
rig = run(tmp_path, steps)
|
|
262
|
+
assert rig.code == 2 and len(rig.calls("01", "test-writer")) == 4, rig.ledger()
|
|
263
|
+
(question,) = asked(rig)
|
|
264
|
+
assert question["id"] == AMBIGUOUS and "3 times" in question["subject"] and "MISSING-4" in question["subject"]
|
|
265
|
+
assert rig.state()["tickets"]["01"]["settled"] == 3
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
def test_disputes_of_new_tests_reach_the_cap_too_and_the_next_one_asks_with_no_arbitration(tmp_path):
|
|
269
|
+
names = ["test_x", "test_y", "test_z", "test_w"]
|
|
270
|
+
rig = run(tmp_path, {"01/implementer": [disputes((f"tests/test_01.py::{name}", "no")) for name in names],
|
|
271
|
+
"01/reviewer": [ruling("code-wrong", "R3 holds", f"tests/test_01.py::{name}")
|
|
272
|
+
for name in names[:3]]})
|
|
273
|
+
assert rig.code == 2 and len(arbitrations(rig)) == 3, rig.ledger()
|
|
274
|
+
(question,) = asked(rig)
|
|
275
|
+
assert "tests/test_01.py::test_w" in question["subject"] and "3 times" in question["subject"]
|
|
276
|
+
assert rig.state()["tickets"]["01"]["settled"] == 3
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
def test_a_missing_test_asked_for_again_after_its_correction_asks_spec_ambiguous(tmp_path):
|
|
280
|
+
rig = run(tmp_path, {"01/test-writer": [tw("01"), correction("# added\n")],
|
|
281
|
+
"01/reviewer": [review("01", [missing(1)])] * 2})
|
|
282
|
+
assert rig.code == 2 and len(rig.calls("01", "test-writer")) == 2, rig.ledger()
|
|
283
|
+
(question,) = asked(rig)
|
|
284
|
+
subject = question["subject"]
|
|
285
|
+
assert "the first reading: MISSING-1" in subject and "the second reading: MISSING-1" in subject
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
def test_a_fixture_finding_that_names_no_test_is_corrected_once_per_file(tmp_path):
|
|
289
|
+
stale = finding("STALE", kind="fixture", file="tests/test_01.py")
|
|
290
|
+
rig = run(tmp_path, {"01/test-writer": [tw("01"), correction("# fixed\n")],
|
|
291
|
+
"01/reviewer": [review("01", [stale])] * 2})
|
|
292
|
+
assert rig.code == 2 and len(rig.calls("01", "test-writer")) == 2, rig.ledger()
|
|
293
|
+
assert [q["id"] for q in asked(rig)] == [AMBIGUOUS]
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
def test_keep_test_on_a_missing_test_closes_that_request_only(tmp_path):
|
|
297
|
+
steps = plan(**{"01/test-writer": [tw("01"), *[correction(f"# added {n}\n") for n in range(1, 4)]],
|
|
298
|
+
"01/reviewer": [review("01", [missing(n)]) for n in range(1, 5)] +
|
|
299
|
+
[review("01", [missing(4), WEAK_Y])]})
|
|
300
|
+
rig = Inside(tmp_path, ONE).run(steps)
|
|
301
|
+
assert [q["id"] for q in asked(rig)] == [AMBIGUOUS], rig.ledger()
|
|
302
|
+
rig.run(steps, "--answer", f"{AMBIGUOUS}=keep-test")
|
|
303
|
+
assert rig.code == 2 and rig.led("MISSING-4", "closed as it is by the ruling (keep-test)"), rig.ledger()
|
|
304
|
+
(question,) = asked(rig)
|
|
305
|
+
assert question["id"] == "01-spec-ambiguous-2" and "WEAK" in question["subject"]
|
|
306
|
+
assert "MISSING-4" not in question["subject"]
|
|
307
|
+
|
|
308
|
+
|
|
218
309
|
# ---------------------------------------------------------------- the answers
|
|
219
310
|
|
|
220
311
|
def test_keep_test_runs_the_implementer_again_and_keeps_the_record(tmp_path):
|
|
@@ -243,7 +334,7 @@ def test_correct_test_corrects_to_the_second_reading_then_the_implementer_runs_a
|
|
|
243
334
|
assert wanted["evidence"] == "correct the test to the second reading: the example in R3 uses '"
|
|
244
335
|
assert rig.calls("01", "implementer")[2]["head"] == fixed["sha"]
|
|
245
336
|
assert [q["id"] for q in asked(rig)] == ["01-spec-ambiguous-2"]
|
|
246
|
-
assert set(rig.state()["tickets"]["01"]["disputes"]) == {
|
|
337
|
+
assert set(rig.state()["tickets"]["01"]["disputes"]) == {TEST}
|
|
247
338
|
|
|
248
339
|
|
|
249
340
|
def test_correct_test_after_a_fixer_s_dispute_runs_the_fixer_of_that_round_again_after_the_correction(tmp_path):
|
|
@@ -271,7 +362,7 @@ def test_edit_spec_keeps_the_ticket_blocked_with_the_ruling_and_runs_no_agent(tm
|
|
|
271
362
|
|
|
272
363
|
|
|
273
364
|
def test_keep_test_on_a_review_finding_closes_it_and_the_ticket_goes_on(tmp_path):
|
|
274
|
-
stale = finding("STALE", kind="fixture", file="tests/test_01.py")
|
|
365
|
+
stale = {**finding("STALE", kind="fixture", file="tests/test_01.py"), "test": TEST}
|
|
275
366
|
steps = plan(**{"01/test-writer": [tw("01"), correction()], "01/fixer": [fix("01", 1)],
|
|
276
367
|
"01/reviewer": [review("01", [stale]), review("01", [stale]), review("01", [stale, STUCK]),
|
|
277
368
|
review("01")]})
|
|
@@ -10,6 +10,7 @@ import driver_answers
|
|
|
10
10
|
import driver_decisions
|
|
11
11
|
import driver_report
|
|
12
12
|
import driver_review_page
|
|
13
|
+
import driver_state
|
|
13
14
|
from test_cli import git, ticket
|
|
14
15
|
from test_fixloop import Inside, inside # noqa: F401 (the autouse fixture puts the rig's CLIs on PATH)
|
|
15
16
|
from test_tidy import Inside as Pushing, tools # noqa: F401 (an unattended run pushes: the rig with an origin and a fake gh)
|
|
@@ -141,7 +142,7 @@ def as_schema_3(rig, **question):
|
|
|
141
142
|
"""Make the run of `rig` one that a schema 3 driver left, its one question changed by `question`."""
|
|
142
143
|
path = rig.repo / ".agent/implement/state.json"
|
|
143
144
|
state = json.loads(path.read_text())
|
|
144
|
-
assert state["run"]["schema"] ==
|
|
145
|
+
assert state["run"]["schema"] == driver_state.SCHEMA, "a new run writes the current schema"
|
|
145
146
|
state["run"]["schema"] = 3
|
|
146
147
|
state["run"]["questions"][0].update(question)
|
|
147
148
|
path.write_text(json.dumps(state))
|
|
@@ -167,7 +168,7 @@ def test_an_older_run_keeps_the_ruling_of_an_answered_question_of_a_removed_kind
|
|
|
167
168
|
state["tickets"]["01"]["phase"] = "implement" # what the older driver's `retry` did
|
|
168
169
|
(rig.repo / ".agent/implement/state.json").write_text(json.dumps(state))
|
|
169
170
|
rig.run(run, *UNATTENDED)
|
|
170
|
-
assert rig.code == 0 and rig.state()["run"]["schema"] ==
|
|
171
|
+
assert rig.code == 0 and rig.state()["run"]["schema"] == driver_state.SCHEMA, rig.ledger()
|
|
171
172
|
sentence = f"Ruling: 01 review runs again (retry): the implementer: it reported BLOCKED: {STOP}." # the older driver's
|
|
172
173
|
assert f"## Rulings\n\n- {sentence}\n" in rig.prs()[0]["body"]
|
|
173
174
|
assert rig.state()["run"]["questions"][0]["ruling"] == sentence
|
|
@@ -230,9 +231,10 @@ def test_only_an_implementer_or_a_fixer_blocked_on_the_contradiction_concern_dis
|
|
|
230
231
|
f"{contra} test_01.py::test_x[a]: R3", f"{contra} b::c", contra]}
|
|
231
232
|
locked = ["tests/test_01.py", "src/test_01.py", "tests/b"]
|
|
232
233
|
assert driver_report.disputes("fixer", report, locked) == [
|
|
233
|
-
("tests/test_01.py", "tests/test_01.py::test_x", "why"
|
|
234
|
-
("tests/b", "b::c", ""), ("", "", "")]
|
|
235
|
-
assert driver_report.disputes("fixer", report, locked[:1])[1] == (
|
|
234
|
+
("tests/test_01.py", "tests/test_01.py::test_x", "why", "tests/test_01.py::test_x"),
|
|
235
|
+
("", "test_01.py::test_x[a]", "R3", "::test_x"), ("tests/b", "b::c", "", "tests/b::c"), ("", "", "", "")]
|
|
236
|
+
assert driver_report.disputes("fixer", report, locked[:1])[1] == (
|
|
237
|
+
"tests/test_01.py", "test_01.py::test_x[a]", "R3", "tests/test_01.py::test_x")
|
|
236
238
|
assert driver_report.disputes("reviewer", report, locked) == []
|
|
237
239
|
assert driver_report.disputes("implementer", {**report, "status": "DONE"}, locked) == []
|
|
238
240
|
assert driver_report.disputes("implementer", {}, locked) == [], "a rejected report is no report"
|
|
@@ -505,7 +505,7 @@ def test_with_commit_gpgsign_on_every_pushed_commit_is_signed_with_the_configure
|
|
|
505
505
|
# ---------------------------------------------------------------- the merge-risk block of the PR body (ticket 15)
|
|
506
506
|
|
|
507
507
|
PR_RISK = SKILL.parent / "pr-risk"
|
|
508
|
-
BLOCK = ("door: two-way\nblast_radius: isolated\ntouches: [%s]\nrollback: revert\
|
|
508
|
+
BLOCK = ("door: two-way\nblast_radius: isolated\ntouches: [%s]\nrollback: revert\nrisk: 1\n"
|
|
509
509
|
"reasons:\n - \"Only prose changes\"\n")
|
|
510
510
|
|
|
511
511
|
|
|
@@ -132,7 +132,7 @@ def test_capped_regression_is_carried_through_the_final_fix_batch(tmp_path):
|
|
|
132
132
|
|
|
133
133
|
# ---------------------------------------------------------------- the locked files
|
|
134
134
|
|
|
135
|
-
STALE = finding("STALE", kind="fixture", file="tests/test_01.py")
|
|
135
|
+
STALE = {**finding("STALE", kind="fixture", file="tests/test_01.py"), "test": "tests/test_01.py::test_x"}
|
|
136
136
|
AMBIGUOUS_1 = "01-spec-ambiguous-1"
|
|
137
137
|
|
|
138
138
|
|
|
@@ -154,8 +154,8 @@ def test_a_locked_test_finding_that_comes_back_after_its_correction_asks_spec_am
|
|
|
154
154
|
"01/reviewer": [review("01", [STALE])] * 2 + [review("01")]})
|
|
155
155
|
rig = Inside(tmp_path).run(steps)
|
|
156
156
|
assert rig.code == 2 and rig.state()["tickets"]["01"]["phase"] == "blocked", rig.ledger()
|
|
157
|
-
assert rig.led("BLOCKED at the review: the spec reads two ways on a locked test: tests/test_01.py: the
|
|
158
|
-
"reading: STALE: STALE; the second reading: STALE: STALE.")
|
|
157
|
+
assert rig.led("BLOCKED at the review: the spec reads two ways on a locked test: tests/test_01.py::test_x: the "
|
|
158
|
+
"first reading: STALE: STALE; the second reading: STALE: STALE.")
|
|
159
159
|
assert asked(rig) == {AMBIGUOUS_1: ["keep-test", "correct-test", "edit-spec"]}
|
|
160
160
|
(question,) = rig.state()["run"]["questions"]
|
|
161
161
|
assert question["recommended"] == "" and question["evidence"][0] == ".agent/implement/01/spec-ambiguous-1.json"
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"""The names of a run, and the take-over of a run that an older driver started (driver_names, driver_legacy)."""
|
|
2
|
+
import json
|
|
2
3
|
import subprocess
|
|
3
4
|
|
|
5
|
+
import driver_dispute
|
|
4
6
|
import driver_legacy
|
|
5
7
|
import driver_state
|
|
6
8
|
from conftest import GIT
|
|
@@ -137,3 +139,28 @@ def test_the_lock_of_an_older_driver_is_shared_by_newer_drivers_and_excludes_an_
|
|
|
137
139
|
f"a driver of an older version runs in this repository: it holds the lock {tmp_path / 'implement-spec.lock'}. "
|
|
138
140
|
"Wait until it ends, then run the driver again."))
|
|
139
141
|
older.close()
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def test_resume_keys_the_rulings_and_corrections_of_a_schema_4_run_by_their_test(repo, tmp_path):
|
|
145
|
+
"""Schema 4 keyed them by the locked file; each record names its test, so the key moves to that test. A review
|
|
146
|
+
correction recorded only its file and is keyed by it, as a fixture finding that names no test is. The evidence
|
|
147
|
+
of each `spec-ambiguous` question of the ticket gets the key of its file's record, which `keep-test` closes."""
|
|
148
|
+
state, _, _ = older_run(repo, tmp_path)
|
|
149
|
+
ruled = {"test": "test_01.py::test_x[a]", "requirement": "R3", "ruling": "test-wrong", "reason": "r"}
|
|
150
|
+
by_file = {"test": "tests/test_02.py", "requirement": "", "reason": "STALE"}
|
|
151
|
+
evidence = tmp_path / ".agent/implement/01/spec-ambiguous-1.json"
|
|
152
|
+
evidence.parent.mkdir(parents=True, exist_ok=True)
|
|
153
|
+
evidence.write_text(json.dumps([{"file": "tests/test_01.py", "title": "t"}, {"file": "tests/test_02.py"}]))
|
|
154
|
+
question = {"ticket": "01", "kind": "spec-ambiguous", "answer": "keep-test", "evidence": [str(evidence)],
|
|
155
|
+
"subject": "s"}
|
|
156
|
+
gone = {**question, "evidence": [str(tmp_path / "gone.json")]}
|
|
157
|
+
edit(state, {"disputes": {"tests/test_01.py": ruled},
|
|
158
|
+
"corrected": {"tests/test_01.py": ruled, "tests/test_02.py": by_file}}, questions=[question, gone])
|
|
159
|
+
assert resume(state, tmp_path)[0] == []
|
|
160
|
+
entry = state.read()["tickets"]["01"]
|
|
161
|
+
assert entry["disputes"] == {"tests/test_01.py::test_x": ruled}
|
|
162
|
+
assert entry["corrected"] == {"tests/test_01.py::test_x": ruled, "tests/test_02.py": by_file}
|
|
163
|
+
assert entry["settled"] == 2 # one per record of schema 4: each was an arbitration or a correction
|
|
164
|
+
assert [one["key"] for one in json.loads(evidence.read_text())] == ["tests/test_01.py::test_x", "tests/test_02.py"]
|
|
165
|
+
assert driver_dispute.kept(state.read()["run"]["questions"][:1], "01") == {"tests/test_01.py::test_x",
|
|
166
|
+
"tests/test_02.py"}
|
|
@@ -42,7 +42,7 @@ def test_start_keeps_a_recorded_run_and_adds_only_the_new_tickets(tmp_path):
|
|
|
42
42
|
assert again["tickets"]["01"]["phase"] == "merged" and again["tickets"]["01"]["landing"] is None
|
|
43
43
|
assert again["tickets"]["02"] == {
|
|
44
44
|
"phase": "pending", "round": 0, "tip": None, "test_writer_sha": None, "locked": [], "green_gates": {"fast": [], "full": []}, "slot": None,
|
|
45
|
-
"note": "", "landing": None, "disputes": {}, "corrected": {}}
|
|
45
|
+
"note": "", "landing": None, "disputes": {}, "corrected": {}, "settled": 0}
|
|
46
46
|
|
|
47
47
|
|
|
48
48
|
def test_verified_trusts_a_tip_only_while_it_is_on_the_ticket_branch(repo, tmp_path):
|
|
@@ -66,7 +66,7 @@ step = step[n] if n < len(step) else {{}}
|
|
|
66
66
|
if role in ("reviewer", "final-reviewer", "final-spec", "final-correctness", "final-structure") and "report" not in step:
|
|
67
67
|
step = dict(step, report=dict(status="DONE", commits=[], files=[], concerns=[], findings=[]))
|
|
68
68
|
if role == "pr-writer" and "report" not in step: # an unscripted pr-writer writes a summary and a valid merge-risk block
|
|
69
|
-
step = dict(step, report=dict(status="DONE", commits=[], files=[], concerns=[], body="## Summary\\n\\nCSV export.\\n\\n## Merge Danger\\n\\n```merge-risk v1\\ndoor: two-way\\nblast_radius: isolated\\ntouches: [docs]\\nrollback: revert\\
|
|
69
|
+
step = dict(step, report=dict(status="DONE", commits=[], files=[], concerns=[], body="## Summary\\n\\nCSV export.\\n\\n## Merge Danger\\n\\n```merge-risk v1\\ndoor: two-way\\nblast_radius: isolated\\ntouches: [docs]\\nrollback: revert\\nrisk: 1\\nreasons:\\n - \\"Only prose changes\\"\\n```\\n"))
|
|
70
70
|
for name in step.get("touch", []):
|
|
71
71
|
(rig / "sig" / name).touch()
|
|
72
72
|
for name in step.get("wait", []):
|
package/skills/pr-risk/SKILL.md
CHANGED
|
@@ -11,10 +11,24 @@ description: >-
|
|
|
11
11
|
`python3 merge_risk.py validate <body-file>` prints the errors and exits non-zero when the block is invalid.
|
|
12
12
|
|
|
13
13
|
The block is the one fenced ```` ```merge-risk v1 ```` block in the body. Keys: `door`, `blast_radius`,
|
|
14
|
-
`touches`, `rollback`, `
|
|
14
|
+
`touches`, `rollback`, `risk`, `reasons`.
|
|
15
15
|
|
|
16
16
|
`python3 merge_risk.py gate --body <file> --base <ref> --head <sha>` prints JSON with `verdict` (`auto | human`),
|
|
17
|
-
`reasons`, `categories` and `countedLines`. The policy is read from `origin/<base
|
|
17
|
+
`reasons`, `risk`, `maxAutoRisk`, `categories` and `countedLines`. The policy is read from `origin/<base>`.
|
|
18
|
+
|
|
19
|
+
## Risk
|
|
20
|
+
|
|
21
|
+
The gate scores the risk from 1 to 10 and gives `auto` only when `risk <= maxAutoRisk` and nothing else makes it human:
|
|
22
|
+
|
|
23
|
+
- **Floor**: the riskiest category of the diff and `touches` (`CATEGORY_RISK` in `merge_policy.py`, overridden per
|
|
24
|
+
category by the policy's `categoryRisk`), plus 1 for `module`, 2 for `service`, 3 for `consumers`, plus 1 for
|
|
25
|
+
`rollback: revert+redeploy`, capped at 10. The block's `risk` raises the score above the floor, never lowers it.
|
|
26
|
+
- **Limit**: the policy's `maxAutoRisk` (0 to 10, default 3). A public repo, or one whose visibility `gh` cannot tell,
|
|
27
|
+
is capped at 3.
|
|
28
|
+
- **One-way is always human**: `door: one-way` or `rollback: data-fix | impossible`, at any risk and any limit. Only
|
|
29
|
+
the owner's `@babysitter merge <sha>` merges it.
|
|
30
|
+
|
|
31
|
+
`babysit-pr`'s judge scores the risk too; the merge needs the higher of the two within the limit.
|
|
18
32
|
|
|
19
33
|
## Writing the block
|
|
20
34
|
|
|
@@ -27,7 +41,8 @@ Read `.merge-risk.json` for the policy, then fill the block from the diff:
|
|
|
27
41
|
- `blast_radius`: how far a bad change reaches: `isolated`, `module`, `service` or `consumers`.
|
|
28
42
|
- `touches`: inline list of categories the diff touches, e.g. `[docs, tests]`.
|
|
29
43
|
- `rollback`: `revert`, `revert+redeploy`, `data-fix` or `impossible`.
|
|
30
|
-
- `
|
|
44
|
+
- `risk`: a whole number from 1 to 10, your honest score of what a bad merge would cost (see Risk). Write it
|
|
45
|
+
higher than the floor when the diff is riskier than its categories say.
|
|
31
46
|
- `reasons`: one quoted line per reason for the verdict.
|
|
32
47
|
|
|
33
48
|
Check it with `python3 merge_risk.py validate <body-file>` before opening the PR.
|
|
@@ -17,23 +17,35 @@ DEFAULT_PATHS = {
|
|
|
17
17
|
"infra": ["**/Dockerfile*"],
|
|
18
18
|
"logic": ["**/SKILL.md", "**/AGENTS.md", "**/CLAUDE.md", "**/prompts/**"],
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
# Risk of each category, 1 (harmless) to 10 (never merged by an agent). A repo overrides
|
|
21
|
+
# single entries with `categoryRisk`.
|
|
22
|
+
CATEGORY_RISK = {"docs": 1, "tests": 2, "ui": 3, "logic": 4, "deps": 5, "config": 6, "ci": 7,
|
|
23
|
+
"public-api": 7, "infra": 8, "schema/migration": 9, "auth/security": 10,
|
|
24
|
+
"money": 10, "data-delete": 10}
|
|
25
|
+
# A public repo never merges above this risk without a human; a repo that sets no
|
|
26
|
+
# `maxAutoRisk` gets it too.
|
|
27
|
+
PUBLIC_MAX_RISK = 3
|
|
28
|
+
DEFAULT_POLICY = {"maxAutoRisk": PUBLIC_MAX_RISK, "categoryRisk": {}, "paths": {},
|
|
29
|
+
"mergeMethod": None, "judgeMaxLines": 1500, "waitMinutes": 60}
|
|
30
|
+
REPLACED_KEYS = {"agentMerge": "maxAutoRisk", "alwaysHuman": "categoryRisk"}
|
|
24
31
|
|
|
25
32
|
|
|
26
33
|
def is_int(v):
|
|
27
34
|
return isinstance(v, int) and not isinstance(v, bool)
|
|
28
35
|
|
|
29
36
|
|
|
37
|
+
def is_risk(v, low=1):
|
|
38
|
+
return is_int(v) and low <= v <= 10
|
|
39
|
+
|
|
40
|
+
|
|
30
41
|
def is_str_list(v):
|
|
31
42
|
return isinstance(v, list) and all(isinstance(x, str) for x in v)
|
|
32
43
|
|
|
33
44
|
|
|
34
45
|
POLICY_TYPES = {
|
|
35
|
-
"
|
|
36
|
-
"
|
|
46
|
+
"maxAutoRisk": lambda v: is_risk(v, low=0),
|
|
47
|
+
"categoryRisk": lambda v: isinstance(v, dict) and all(
|
|
48
|
+
c in CATEGORIES and is_risk(r) for c, r in v.items()),
|
|
37
49
|
"paths": lambda v: isinstance(v, dict) and all(
|
|
38
50
|
c in CATEGORIES and is_str_list(g) for c, g in v.items()),
|
|
39
51
|
"mergeMethod": lambda v: v in ("rebase", "merge", "squash"),
|
|
@@ -49,22 +61,30 @@ def git(*args, check=True):
|
|
|
49
61
|
return p
|
|
50
62
|
|
|
51
63
|
|
|
64
|
+
def has_bracket_glob(paths):
|
|
65
|
+
return any("[" in g or "]" in g for globs in paths.values() for g in globs)
|
|
66
|
+
|
|
67
|
+
|
|
52
68
|
def policy_error(key, value):
|
|
53
69
|
"""Why one policy entry is rejected, else None."""
|
|
70
|
+
if key in REPLACED_KEYS:
|
|
71
|
+
return f"policy: {key} was replaced by {REPLACED_KEYS[key]}"
|
|
54
72
|
if key not in POLICY_TYPES:
|
|
55
73
|
return f"policy: unknown key {key}"
|
|
56
74
|
if not POLICY_TYPES[key](value):
|
|
57
75
|
return f"policy: wrong type for {key}"
|
|
58
|
-
if key == "paths" and
|
|
76
|
+
if key == "paths" and has_bracket_glob(value):
|
|
59
77
|
return "policy: unsupported glob syntax in paths"
|
|
60
78
|
return None
|
|
61
79
|
|
|
62
80
|
|
|
63
81
|
def load_policy(base):
|
|
64
|
-
"""Policy from the base commit, never the PR head. Returns (policy, errors).
|
|
82
|
+
"""Policy from the base commit, never the PR head. Returns (policy, errors).
|
|
83
|
+
|
|
84
|
+
No policy file on the base is an error: a PR must not merge itself under a policy it adds."""
|
|
65
85
|
p = git("show", f"{base}:{POLICY_FILE}", check=False)
|
|
66
86
|
if p.returncode:
|
|
67
|
-
return dict(DEFAULT_POLICY), []
|
|
87
|
+
return dict(DEFAULT_POLICY), [f"policy: no {POLICY_FILE} on the base"]
|
|
68
88
|
try:
|
|
69
89
|
raw = json.loads(p.stdout)
|
|
70
90
|
except ValueError:
|
|
@@ -9,15 +9,17 @@ import re
|
|
|
9
9
|
import subprocess
|
|
10
10
|
import sys
|
|
11
11
|
|
|
12
|
-
from merge_policy import CATEGORIES, DEFAULT_PATHS, POLICY_FILE,
|
|
12
|
+
from merge_policy import (CATEGORIES, CATEGORY_RISK, DEFAULT_PATHS, POLICY_FILE, # noqa: F401
|
|
13
|
+
PUBLIC_MAX_RISK, git, load_policy)
|
|
13
14
|
|
|
14
15
|
ENUMS = {
|
|
15
16
|
"door": ["one-way", "two-way"],
|
|
16
17
|
"blast_radius": ["isolated", "module", "service", "consumers"],
|
|
17
18
|
"rollback": ["revert", "revert+redeploy", "data-fix", "impossible"],
|
|
18
|
-
"verdict": ["auto", "human"],
|
|
19
19
|
}
|
|
20
|
-
KEYS = [*ENUMS, "touches", "reasons"]
|
|
20
|
+
KEYS = [*ENUMS, "risk", "touches", "reasons"]
|
|
21
|
+
BLAST_RISK = {"isolated": 0, "module": 1, "service": 2, "consumers": 3}
|
|
22
|
+
ONE_WAY_ROLLBACKS = ("data-fix", "impossible")
|
|
21
23
|
FENCE = re.compile(r"^```merge-risk v1[ \t]*\n(.*?)^```[ \t]*$", re.S | re.M)
|
|
22
24
|
|
|
23
25
|
|
|
@@ -149,6 +151,17 @@ class Block:
|
|
|
149
151
|
if c and c not in CATEGORIES]
|
|
150
152
|
if "reasons" in fields and not fields["reasons"]:
|
|
151
153
|
self.errors.append("reasons must have at least one item")
|
|
154
|
+
self.read_risk()
|
|
155
|
+
|
|
156
|
+
def read_risk(self):
|
|
157
|
+
"""Turn `risk` into an int from 1 to 10, or record why it is not one."""
|
|
158
|
+
risk = self.fields.get("risk")
|
|
159
|
+
if risk is None:
|
|
160
|
+
return
|
|
161
|
+
if re.fullmatch(r"[1-9]|10", risk):
|
|
162
|
+
self.fields["risk"] = int(risk)
|
|
163
|
+
else:
|
|
164
|
+
self.errors.append(f"risk: {risk!r} is not a whole number from 1 to 10")
|
|
152
165
|
|
|
153
166
|
|
|
154
167
|
def parse_block(text):
|
|
@@ -254,21 +267,20 @@ def block_reasons(block, cats):
|
|
|
254
267
|
return ["no merge-risk block"]
|
|
255
268
|
if block["errors"]:
|
|
256
269
|
return [f"invalid block: {e}" for e in block["errors"]]
|
|
270
|
+
# A one-way change is never merged by an agent, whatever the risk and the policy say.
|
|
257
271
|
reasons = []
|
|
258
272
|
if block["door"] == "one-way":
|
|
259
273
|
reasons.append("door one-way")
|
|
260
|
-
if block["rollback"]
|
|
261
|
-
reasons.append(f"rollback {block['rollback']}")
|
|
274
|
+
if block["rollback"] in ONE_WAY_ROLLBACKS:
|
|
275
|
+
reasons.append(f"rollback {block['rollback']} is one-way")
|
|
262
276
|
return reasons + [f"diff touches {c}, not in touches"
|
|
263
277
|
for c in sorted(cats - set(block["touches"]))]
|
|
264
278
|
|
|
265
279
|
|
|
266
|
-
def diff_reasons(policy,
|
|
280
|
+
def diff_reasons(policy, stats):
|
|
267
281
|
"""Reasons from the policy and the diff stats."""
|
|
268
282
|
cats, counted, unknown, policy_changed = stats
|
|
269
|
-
reasons = []
|
|
270
|
-
reasons += [f"{c} is always human" for c in sorted(touches | cats)
|
|
271
|
-
if c in policy["alwaysHuman"]]
|
|
283
|
+
reasons = []
|
|
272
284
|
if policy_changed:
|
|
273
285
|
reasons.append(f"config: {POLICY_FILE} changed")
|
|
274
286
|
reasons += [f"unknown line count: {p}" for p in unknown]
|
|
@@ -277,16 +289,47 @@ def diff_reasons(policy, touches, stats):
|
|
|
277
289
|
return reasons
|
|
278
290
|
|
|
279
291
|
|
|
280
|
-
def
|
|
292
|
+
def risk_floor(policy, cats, block):
|
|
293
|
+
"""The lowest risk the diff can have: its riskiest category, raised by blast radius and rollback.
|
|
294
|
+
|
|
295
|
+
The block's own `risk` can raise the score above this floor, never lower it."""
|
|
296
|
+
risks = {**CATEGORY_RISK, **policy["categoryRisk"]}
|
|
297
|
+
floor = max((risks[c] for c in cats), default=1) + BLAST_RISK[block["blast_radius"]]
|
|
298
|
+
floor += block["rollback"] == "revert+redeploy"
|
|
299
|
+
return min(floor, 10)
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
def risk_limit(policy, public):
|
|
303
|
+
"""The highest risk an agent may merge: the repo's maxAutoRisk, never above 3 when public."""
|
|
304
|
+
return min(policy["maxAutoRisk"], PUBLIC_MAX_RISK) if public else policy["maxAutoRisk"]
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
def is_public_repo():
|
|
308
|
+
"""Whether the checkout's GitHub repo is public. Unknown counts as public."""
|
|
309
|
+
try:
|
|
310
|
+
p = subprocess.run(["gh", "repo", "view", "--json", "isPrivate", "--jq", ".isPrivate"],
|
|
311
|
+
text=True, capture_output=True)
|
|
312
|
+
except OSError: # no gh
|
|
313
|
+
return True
|
|
314
|
+
return not (p.returncode == 0 and p.stdout.strip() == "true")
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
def gate(body, base, head, public=True):
|
|
318
|
+
"""The merge verdict. `public` defaults to True so a caller that predates it gets the strict cap."""
|
|
281
319
|
block = parse(body)
|
|
282
320
|
base, policy, reasons = base_policy(base)
|
|
283
321
|
stats = diff_stats(classify_diff(base, head, policy)[1])
|
|
284
322
|
cats, counted = stats[0], stats[1]
|
|
285
323
|
reasons += block_reasons(block, cats)
|
|
286
324
|
touches = set(block["touches"]) if not block["errors"] else set()
|
|
287
|
-
reasons += diff_reasons(policy,
|
|
288
|
-
|
|
289
|
-
|
|
325
|
+
reasons += diff_reasons(policy, stats)
|
|
326
|
+
risk = 10 if block["errors"] else max(risk_floor(policy, cats | touches, block), block["risk"])
|
|
327
|
+
limit = risk_limit(policy, public)
|
|
328
|
+
if risk > limit:
|
|
329
|
+
capped = limit < policy["maxAutoRisk"]
|
|
330
|
+
reasons.append(f"risk {risk} > max auto risk {limit}" + (" (public repo)" if capped else ""))
|
|
331
|
+
return {"verdict": "human" if reasons else "auto", "reasons": reasons, "risk": risk,
|
|
332
|
+
"maxAutoRisk": limit, "categories": sorted(cats), "countedLines": counted}
|
|
290
333
|
|
|
291
334
|
|
|
292
335
|
def is_gate_call(argv):
|
|
@@ -296,7 +339,7 @@ def is_gate_call(argv):
|
|
|
296
339
|
def main(argv):
|
|
297
340
|
if is_gate_call(argv):
|
|
298
341
|
with open(argv[3]) as f:
|
|
299
|
-
print(json.dumps(gate(f.read(), argv[5], argv[7])))
|
|
342
|
+
print(json.dumps(gate(f.read(), argv[5], argv[7], is_public_repo())))
|
|
300
343
|
return 0
|
|
301
344
|
if len(argv) != 3 or argv[1] not in ("parse", "validate"):
|
|
302
345
|
print(__doc__, file=sys.stderr)
|
|
@@ -20,7 +20,7 @@ door: two-way
|
|
|
20
20
|
blast_radius: isolated
|
|
21
21
|
touches: [docs, tests]
|
|
22
22
|
rollback: revert
|
|
23
|
-
|
|
23
|
+
risk: 1
|
|
24
24
|
reasons:
|
|
25
25
|
- "Only skill prose and its tests change"
|
|
26
26
|
```
|
|
@@ -47,7 +47,7 @@ def make_repo(tmp_path, policy=True):
|
|
|
47
47
|
git(seed, "push", str(origin), "main")
|
|
48
48
|
git(tmp_path, "clone", str(origin), str(repo))
|
|
49
49
|
if policy:
|
|
50
|
-
(repo / ".merge-risk.json").write_text('{"
|
|
50
|
+
(repo / ".merge-risk.json").write_text('{"maxAutoRisk": 3}\n')
|
|
51
51
|
return repo
|
|
52
52
|
|
|
53
53
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"""Acceptance tests for `merge_risk.py parse|validate`, through the command line only.
|
|
2
2
|
|
|
3
|
-
`parse` prints one JSON object: door, blast_radius, touches, rollback,
|
|
3
|
+
`parse` prints one JSON object: door, blast_radius, touches, rollback, risk,
|
|
4
4
|
reasons and errors (a list of messages, empty when the block is valid).
|
|
5
5
|
"""
|
|
6
6
|
import json
|
|
@@ -14,7 +14,7 @@ VALID = '''door: two-way # one-way | two-way
|
|
|
14
14
|
blast_radius: isolated
|
|
15
15
|
touches: [docs, tests]
|
|
16
16
|
rollback: revert
|
|
17
|
-
|
|
17
|
+
risk: 1
|
|
18
18
|
reasons:
|
|
19
19
|
- "Only skill prose and its tests change"
|
|
20
20
|
'''
|