@jesdi/skills 0.0.62 → 0.0.64
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 +15 -0
- package/package.json +2 -2
- package/skills/babysit-pr/SKILL.md +54 -0
- package/skills/babysit-pr/babysit.py +998 -0
- package/skills/babysit-pr/fixtures/gh +310 -0
- package/skills/babysit-pr/hooks/post-pr-create.sh +56 -0
- package/skills/babysit-pr/hooks.json +10 -0
- package/skills/babysit-pr/judge-prompt.md +10 -0
- package/skills/babysit-pr/test_babysit.py +242 -0
- package/skills/babysit-pr/test_babysit_judge.py +286 -0
- package/skills/babysit-pr/test_babysit_judge_diff.py +25 -0
- package/skills/babysit-pr/test_babysit_judge_isolation.py +61 -0
- package/skills/babysit-pr/test_checks_regressions.py +210 -0
- package/skills/babysit-pr/test_comment_fidelity.py +88 -0
- package/skills/babysit-pr/test_comment_identity.py +70 -0
- package/skills/babysit-pr/test_e2e_setup.py +74 -0
- package/skills/babysit-pr/test_handoff_takeover.py +141 -0
- package/skills/babysit-pr/test_handoff_terminal.py +29 -0
- package/skills/babysit-pr/test_hook_quoting.py +25 -0
- package/skills/babysit-pr/test_hooks.py +62 -0
- package/skills/babysit-pr/test_lease_regressions.py +198 -0
- package/skills/babysit-pr/test_merge_and_handoff.py +260 -0
- package/skills/babysit-pr/test_merge_base_pin.py +10 -0
- package/skills/babysit-pr/test_merge_gate.py +124 -0
- package/skills/babysit-pr/test_merge_session_safety.py +117 -0
- package/skills/babysit-pr/test_merged_pr_labels.py +144 -0
- package/skills/babysit-pr/test_owner_comment_edits.py +26 -0
- package/skills/babysit-pr/test_owner_comments.py +316 -0
- package/skills/babysit-pr/test_retry_and_stall_hardening.py +143 -0
- package/skills/babysit-pr/test_rounds_and_checks.py +305 -0
- package/skills/babysit-pr/test_terminal_label_regressions.py +117 -0
- package/skills/babysit-pr/test_trusted_merge_risk.py +184 -0
- package/skills/babysit-pr/test_update_plan.py +157 -0
- package/skills/implement-spec/ARCHITECTURE.md +5 -0
- package/skills/implement-spec/README.md +7 -6
- package/skills/implement-spec/SKILL.md +1 -1
- package/skills/implement-spec/driver.py +11 -1
- package/skills/implement-spec/driver_decisions.py +23 -0
- package/skills/implement-spec/driver_final.py +49 -10
- package/skills/implement-spec/driver_fixloop.py +17 -5
- package/skills/implement-spec/driver_report.py +16 -5
- package/skills/implement-spec/driver_state.py +2 -2
- package/skills/implement-spec/prompts/pr-writer.md +3 -2
- package/skills/implement-spec/prompts/rejected.md +1 -0
- package/skills/implement-spec/tests/test_decisions.py +57 -0
- package/skills/implement-spec/tests/test_final.py +112 -1
- package/skills/implement-spec/tests/test_fixloop.py +14 -2
- package/skills/implement-spec/tests/test_report.py +18 -0
- package/skills/implement-spec/tests/test_review.py +1 -1
- package/skills/implement-spec/tests/test_state.py +1 -1
- package/skills/implement-spec/tests/test_tidy.py +2 -2
- package/skills/implement-spec/tests/test_walk.py +2 -2
- package/skills/pr-risk/SKILL.md +33 -0
- package/skills/pr-risk/hooks/pre-pr-create.sh +274 -0
- package/skills/pr-risk/hooks.json +10 -0
- package/skills/pr-risk/merge_policy.py +81 -0
- package/skills/pr-risk/merge_risk.py +314 -0
- package/skills/pr-risk/test_hook_commands.py +47 -0
- package/skills/pr-risk/test_hook_heredoc.py +16 -0
- package/skills/pr-risk/test_hook_substitution.py +40 -0
- package/skills/pr-risk/test_hooks.py +175 -0
- package/skills/pr-risk/test_merge_risk.py +97 -0
- package/skills/pr-risk/test_merge_risk_gate.py +217 -0
- package/skills/pr-risk/test_merge_risk_regressions.py +37 -0
- package/skills/pr-risk/test_merge_risk_structure.py +101 -0
- package/skills-manifest.json +15 -3
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"""Acceptance tests for `merge_risk.py parse|validate`, through the command line only.
|
|
2
|
+
|
|
3
|
+
`parse` prints one JSON object: door, blast_radius, touches, rollback, verdict,
|
|
4
|
+
reasons and errors (a list of messages, empty when the block is valid).
|
|
5
|
+
"""
|
|
6
|
+
import json
|
|
7
|
+
import subprocess
|
|
8
|
+
import sys
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
SCRIPT = Path(__file__).with_name("merge_risk.py").resolve()
|
|
12
|
+
|
|
13
|
+
VALID = '''door: two-way # one-way | two-way
|
|
14
|
+
blast_radius: isolated
|
|
15
|
+
touches: [docs, tests]
|
|
16
|
+
rollback: revert
|
|
17
|
+
verdict: auto
|
|
18
|
+
reasons:
|
|
19
|
+
- "Only skill prose and its tests change"
|
|
20
|
+
'''
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def body(block=VALID):
|
|
24
|
+
return f"## Summary\n\nText.\n\n## Merge Danger\n\n```merge-risk v1\n{block}```\n"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def run(cmd, tmp_path, text):
|
|
28
|
+
f = tmp_path / "body.md"
|
|
29
|
+
f.write_text(text)
|
|
30
|
+
return subprocess.run([sys.executable, str(SCRIPT), cmd, str(f)],
|
|
31
|
+
text=True, capture_output=True, timeout=30)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def parsed(tmp_path, text):
|
|
35
|
+
proc = run("parse", tmp_path, text)
|
|
36
|
+
assert proc.returncode == 0, proc.stderr
|
|
37
|
+
return json.loads(proc.stdout)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def errors_of(tmp_path, text):
|
|
41
|
+
return parsed(tmp_path, text)["errors"]
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def test_valid_block_parses(tmp_path):
|
|
45
|
+
out = parsed(tmp_path, body())
|
|
46
|
+
assert out["door"] == "two-way"
|
|
47
|
+
assert out["touches"] == ["docs", "tests"]
|
|
48
|
+
assert out["reasons"] == ["Only skill prose and its tests change"]
|
|
49
|
+
assert out["errors"] == []
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def test_unknown_category_is_invalid(tmp_path):
|
|
53
|
+
errs = errors_of(tmp_path, body(VALID.replace("[docs, tests]", "[docs, styles]")))
|
|
54
|
+
assert "unknown category: styles" in errs
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def test_touches_as_item_list_is_invalid(tmp_path):
|
|
58
|
+
block = VALID.replace("touches: [docs, tests]", "touches:\n - docs\n - tests")
|
|
59
|
+
assert errors_of(tmp_path, body(block))
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def test_two_blocks_are_invalid(tmp_path):
|
|
63
|
+
assert "more than one block" in errors_of(tmp_path, body() + "\n" + body())
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def test_no_block_is_invalid(tmp_path):
|
|
67
|
+
assert "no merge-risk block" in errors_of(tmp_path, "## Summary\n\nNothing here.\n")
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def test_missing_key_is_named(tmp_path):
|
|
71
|
+
errs = errors_of(tmp_path, body(VALID.replace("rollback: revert\n", "")))
|
|
72
|
+
assert any("rollback" in e for e in errs)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test_unknown_key_is_named(tmp_path):
|
|
76
|
+
errs = errors_of(tmp_path, body(VALID + "colour: red\n"))
|
|
77
|
+
assert any("colour" in e for e in errs)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def test_enum_outside_list_is_named(tmp_path):
|
|
81
|
+
errs = errors_of(tmp_path, body(VALID.replace("door: two-way", "door: sideways")))
|
|
82
|
+
assert any("door" in e and "sideways" in e for e in errs)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def test_empty_reasons_is_invalid(tmp_path):
|
|
86
|
+
block = VALID.split("reasons:")[0] + "reasons:\n"
|
|
87
|
+
assert any("reasons" in e for e in errors_of(tmp_path, body(block)))
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def test_validate_exits_zero_for_valid(tmp_path):
|
|
91
|
+
assert run("validate", tmp_path, body()).returncode == 0
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def test_validate_exits_nonzero_and_prints_errors(tmp_path):
|
|
95
|
+
proc = run("validate", tmp_path, body(VALID.replace("[docs, tests]", "[docs, styles]")))
|
|
96
|
+
assert proc.returncode != 0
|
|
97
|
+
assert "unknown category: styles" in proc.stdout + proc.stderr
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
"""Acceptance tests for `merge_risk.py gate --body <file> --base <ref> --head <sha>`.
|
|
2
|
+
|
|
3
|
+
Each test builds a temp git repo: `origin/<base>` is a remote-tracking ref that holds the
|
|
4
|
+
policy, the head commit is the PR. The gate prints one JSON object on stdout:
|
|
5
|
+
`verdict` ("auto" | "human"), `reasons` (every reason that made it human),
|
|
6
|
+
`categories` (categories of the diff) and `countedLines`.
|
|
7
|
+
"""
|
|
8
|
+
import json
|
|
9
|
+
import os
|
|
10
|
+
import subprocess
|
|
11
|
+
import sys
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
|
|
14
|
+
SCRIPT = Path(__file__).with_name("merge_risk.py").resolve()
|
|
15
|
+
ENV = {**os.environ, "GIT_AUTHOR_NAME": "t", "GIT_AUTHOR_EMAIL": "t@t",
|
|
16
|
+
"GIT_COMMITTER_NAME": "t", "GIT_COMMITTER_EMAIL": "t@t",
|
|
17
|
+
"GIT_CONFIG_GLOBAL": os.devnull, "GIT_CONFIG_SYSTEM": os.devnull}
|
|
18
|
+
|
|
19
|
+
POLICY = ".merge-risk.json"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def git(repo, *args):
|
|
23
|
+
p = subprocess.run(["git", *args], cwd=repo, env=ENV, text=True,
|
|
24
|
+
capture_output=True, check=True)
|
|
25
|
+
return p.stdout.strip()
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def write(repo, files):
|
|
29
|
+
for name, content in files.items():
|
|
30
|
+
f = Path(repo) / name
|
|
31
|
+
f.parent.mkdir(parents=True, exist_ok=True)
|
|
32
|
+
f.write_text(content)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def commit(repo, files, msg="c"):
|
|
36
|
+
write(repo, files)
|
|
37
|
+
git(repo, "add", "-A")
|
|
38
|
+
git(repo, "commit", "-m", msg)
|
|
39
|
+
return git(repo, "rev-parse", "HEAD")
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def make_repo(tmp_path, base_files, head_files, base="main"):
|
|
43
|
+
"""Base commit published as origin/<base>; head commit on top of it. Returns (repo, sha)."""
|
|
44
|
+
repo = tmp_path / "repo"
|
|
45
|
+
repo.mkdir()
|
|
46
|
+
git(repo, "init", "-q", "-b", "work")
|
|
47
|
+
base_sha = commit(repo, base_files or {"README.md": "hi\n"}, "base")
|
|
48
|
+
git(repo, "update-ref", f"refs/remotes/origin/{base}", base_sha)
|
|
49
|
+
return repo, commit(repo, head_files, "head")
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def policy(**kw):
|
|
53
|
+
return {POLICY: json.dumps(kw)}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def block(door="two-way", touches="docs", rollback="revert", verdict="auto"):
|
|
57
|
+
return (
|
|
58
|
+
"## Summary\n\nText.\n\n## Merge Danger\n\n```merge-risk v1\n"
|
|
59
|
+
f"door: {door}\nblast_radius: isolated\ntouches: [{touches}]\n"
|
|
60
|
+
f"rollback: {rollback}\nverdict: {verdict}\n"
|
|
61
|
+
'reasons:\n - "Small and reversible"\n```\n'
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def gate(tmp_path, repo, sha, body, base="main"):
|
|
66
|
+
f = tmp_path / "body.md"
|
|
67
|
+
f.write_text(body)
|
|
68
|
+
proc = subprocess.run(
|
|
69
|
+
[sys.executable, str(SCRIPT), "gate", "--body", str(f), "--base", base, "--head", sha],
|
|
70
|
+
cwd=repo, env=ENV, text=True, capture_output=True, timeout=60)
|
|
71
|
+
assert proc.returncode == 0, f"gate exited {proc.returncode}: {proc.stderr or proc.stdout}"
|
|
72
|
+
return json.loads(proc.stdout)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test_no_block_is_human(tmp_path):
|
|
76
|
+
repo, sha = make_repo(tmp_path, policy(agentMerge=True), {"docs/a.md": "x\n"})
|
|
77
|
+
out = gate(tmp_path, repo, sha, "## Summary\n\nNo block here.\n")
|
|
78
|
+
assert out["verdict"] == "human"
|
|
79
|
+
assert "no merge-risk block" in out["reasons"]
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def test_repo_paths_add_to_defaults(tmp_path):
|
|
83
|
+
repo, sha = make_repo(
|
|
84
|
+
tmp_path, policy(agentMerge=True, paths={"money": ["src/billing/**"]}),
|
|
85
|
+
{"src/billing/invoice.py": "x\n", "db/migrations/0042_add.sql": "x\n"})
|
|
86
|
+
out = gate(tmp_path, repo, sha, block(touches="money, schema/migration"))
|
|
87
|
+
assert sorted(out["categories"]) == ["money", "schema/migration"]
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def test_repo_paths_extend_default_globs_of_existing_category(tmp_path):
|
|
91
|
+
repo, sha = make_repo(
|
|
92
|
+
tmp_path, policy(agentMerge=True, paths={"docs": ["notes/**"]}),
|
|
93
|
+
{"docs/a.md": "x\n", "notes/b.txt": "x\n"})
|
|
94
|
+
out = gate(tmp_path, repo, sha, block(touches="docs"))
|
|
95
|
+
assert out["categories"] == ["docs"]
|
|
96
|
+
assert out["verdict"] == "auto"
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def test_repo_always_human_replaces_defaults(tmp_path):
|
|
100
|
+
repo, sha = make_repo(tmp_path, policy(agentMerge=True, alwaysHuman=["money"]),
|
|
101
|
+
{"Dockerfile": "FROM x\n"})
|
|
102
|
+
out = gate(tmp_path, repo, sha, block(touches="infra"))
|
|
103
|
+
assert out["verdict"] == "auto"
|
|
104
|
+
assert out["reasons"] == []
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def test_pr_cannot_loosen_its_own_policy(tmp_path):
|
|
108
|
+
repo, sha = make_repo(
|
|
109
|
+
tmp_path, policy(agentMerge=True),
|
|
110
|
+
{"db/migrations/0042_add.sql": "x\n", **policy(agentMerge=True, alwaysHuman=[])})
|
|
111
|
+
out = gate(tmp_path, repo, sha, block(touches="schema/migration, config"))
|
|
112
|
+
assert out["verdict"] == "human"
|
|
113
|
+
assert "schema/migration is always human" in out["reasons"]
|
|
114
|
+
assert "config: .merge-risk.json changed" in out["reasons"]
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def test_first_policy_file_is_not_used_by_its_own_pr(tmp_path):
|
|
118
|
+
repo, sha = make_repo(tmp_path, {"README.md": "hi\n"}, policy(agentMerge=True))
|
|
119
|
+
out = gate(tmp_path, repo, sha, block(touches="config"))
|
|
120
|
+
assert out["verdict"] == "human"
|
|
121
|
+
assert "agentMerge is off" in out["reasons"]
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def test_unknown_policy_key_is_human(tmp_path):
|
|
125
|
+
repo, sha = make_repo(tmp_path, policy(agentMerge=True, autoMerge=True),
|
|
126
|
+
{"docs/a.md": "x\n"})
|
|
127
|
+
out = gate(tmp_path, repo, sha, block())
|
|
128
|
+
assert out["verdict"] == "human"
|
|
129
|
+
assert "policy: unknown key autoMerge" in out["reasons"]
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def test_skill_md_is_logic_not_docs(tmp_path):
|
|
133
|
+
repo, sha = make_repo(tmp_path, policy(agentMerge=True),
|
|
134
|
+
{"skills/pr-risk/SKILL.md": "x\n"})
|
|
135
|
+
out = gate(tmp_path, repo, sha, block(touches="docs"))
|
|
136
|
+
assert out["verdict"] == "human"
|
|
137
|
+
assert "diff touches logic, not in touches" in out["reasons"]
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def test_instruction_file_under_docs_counts_as_logic_with_its_lines(tmp_path):
|
|
141
|
+
repo, sha = make_repo(tmp_path, policy(agentMerge=True, judgeMaxLines=3),
|
|
142
|
+
{"docs/SKILL.md": "a\nb\nc\nd\ne\n"})
|
|
143
|
+
out = gate(tmp_path, repo, sha, block(touches="docs, logic"))
|
|
144
|
+
assert out["categories"] == ["logic"]
|
|
145
|
+
assert out["countedLines"] == 5
|
|
146
|
+
assert out["verdict"] == "human"
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def test_one_way_door_is_human_whatever_verdict_says(tmp_path):
|
|
150
|
+
repo, sha = make_repo(tmp_path, policy(agentMerge=True), {"docs/a.md": "x\n"})
|
|
151
|
+
out = gate(tmp_path, repo, sha, block(door="one-way", verdict="auto"))
|
|
152
|
+
assert out["verdict"] == "human"
|
|
153
|
+
assert "door one-way" in out["reasons"]
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def test_rollback_other_than_revert_is_human(tmp_path):
|
|
157
|
+
repo, sha = make_repo(tmp_path, policy(agentMerge=True), {"docs/a.md": "x\n"})
|
|
158
|
+
out = gate(tmp_path, repo, sha, block(rollback="revert+redeploy"))
|
|
159
|
+
assert out["verdict"] == "human"
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def test_undeclared_migration_is_human(tmp_path):
|
|
163
|
+
repo, sha = make_repo(tmp_path, policy(agentMerge=True),
|
|
164
|
+
{"src/app.py": "x\n", "tests/test_app.py": "x\n",
|
|
165
|
+
"db/migrations/0042_add.sql": "x\n"})
|
|
166
|
+
out = gate(tmp_path, repo, sha, block(touches="logic, tests"))
|
|
167
|
+
assert out["verdict"] == "human"
|
|
168
|
+
assert "diff touches schema/migration, not in touches" in out["reasons"]
|
|
169
|
+
assert "schema/migration is always human" in out["reasons"]
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def test_always_human_category_declared_only_in_body_is_human(tmp_path):
|
|
173
|
+
repo, sha = make_repo(tmp_path, policy(agentMerge=True), {"src/app.py": "x\n"})
|
|
174
|
+
out = gate(tmp_path, repo, sha, block(touches="logic, auth/security"))
|
|
175
|
+
assert out["verdict"] == "human"
|
|
176
|
+
assert "auth/security is always human" in out["reasons"]
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def test_agent_merge_false_is_human(tmp_path):
|
|
180
|
+
repo, sha = make_repo(tmp_path, policy(agentMerge=False), {"docs/a.md": "x\n"})
|
|
181
|
+
out = gate(tmp_path, repo, sha, block())
|
|
182
|
+
assert out["verdict"] == "human"
|
|
183
|
+
assert "agentMerge is off" in out["reasons"]
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def counted_diff(n):
|
|
187
|
+
return {"src/app.py": "x\n" * n, "pnpm-lock.yaml": "l\n" * 4000,
|
|
188
|
+
"docs/guide.md": "d\n" * 900}
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def test_counted_lines_at_the_limit_is_auto(tmp_path):
|
|
192
|
+
repo, sha = make_repo(tmp_path, policy(agentMerge=True), counted_diff(1500))
|
|
193
|
+
out = gate(tmp_path, repo, sha, block(touches="deps, docs, logic"))
|
|
194
|
+
assert out["countedLines"] == 1500
|
|
195
|
+
assert out["verdict"] == "auto"
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def test_counted_lines_over_the_limit_is_human(tmp_path):
|
|
199
|
+
repo, sha = make_repo(tmp_path, policy(agentMerge=True), counted_diff(1501))
|
|
200
|
+
out = gate(tmp_path, repo, sha, block(touches="deps, docs, logic"))
|
|
201
|
+
assert out["verdict"] == "human"
|
|
202
|
+
assert "1501 counted lines > 1500" in out["reasons"]
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def test_stacked_base_uses_origin_parent_never_main(tmp_path):
|
|
206
|
+
repo = tmp_path / "repo"
|
|
207
|
+
repo.mkdir()
|
|
208
|
+
git(repo, "init", "-q", "-b", "work")
|
|
209
|
+
main_sha = commit(repo, {"README.md": "hi\n"}, "main") # main: no policy
|
|
210
|
+
git(repo, "update-ref", "refs/remotes/origin/main", main_sha)
|
|
211
|
+
parent_sha = commit(repo, {**policy(agentMerge=True), "db/migrations/0001.sql": "x\n"},
|
|
212
|
+
"parent")
|
|
213
|
+
git(repo, "update-ref", "refs/remotes/origin/feat/parent", parent_sha)
|
|
214
|
+
sha = commit(repo, {"docs/a.md": "x\n"}, "head")
|
|
215
|
+
out = gate(tmp_path, repo, sha, block(), base="feat/parent")
|
|
216
|
+
assert out["categories"] == ["docs"]
|
|
217
|
+
assert out["verdict"] == "auto"
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""Gate regressions exercised through its CLI in temporary repositories."""
|
|
2
|
+
import pytest
|
|
3
|
+
|
|
4
|
+
from test_merge_risk_gate import block, commit, gate, git, make_repo, policy, write
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@pytest.mark.parametrize("pattern", ["src/billing[12]/**", "src/billing[!3]/**"])
|
|
8
|
+
def test_unsupported_policy_glob_requires_human(tmp_path, pattern):
|
|
9
|
+
repo, sha = make_repo(
|
|
10
|
+
tmp_path, policy(agentMerge=True, paths={"money": [pattern]}),
|
|
11
|
+
{"src/billing1/invoice.py": "amount = 1\n"})
|
|
12
|
+
out = gate(tmp_path, repo, sha, block(touches="logic"))
|
|
13
|
+
assert out["verdict"] == "human"
|
|
14
|
+
assert "policy: unsupported glob syntax in paths" in out["reasons"]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@pytest.mark.parametrize("was_generated", [False, True])
|
|
18
|
+
def test_deleted_file_uses_merge_base_marker_and_base_tip_policy(tmp_path, was_generated):
|
|
19
|
+
repo, _ = make_repo(
|
|
20
|
+
tmp_path,
|
|
21
|
+
{**policy(agentMerge=False),
|
|
22
|
+
"src/app.py": ("# @generated\n" if was_generated else "") + "x\n" * 1501},
|
|
23
|
+
{"README.md": "hi\n"})
|
|
24
|
+
ancestor = git(repo, "rev-parse", "HEAD")
|
|
25
|
+
(repo / "src/app.py").unlink()
|
|
26
|
+
sha = commit(repo, {}, "PR deletes app")
|
|
27
|
+
# Build an independent base commit without moving the PR's checked-out branch.
|
|
28
|
+
write(repo, {**policy(agentMerge=True),
|
|
29
|
+
"src/app.py": ("" if was_generated else "# @generated\n") + "x\n" * 1501})
|
|
30
|
+
git(repo, "add", "-A")
|
|
31
|
+
tree = git(repo, "write-tree")
|
|
32
|
+
base_tip = git(repo, "commit-tree", tree, "-p", ancestor, "-m", "base changes marker")
|
|
33
|
+
git(repo, "update-ref", "refs/remotes/origin/main", base_tip)
|
|
34
|
+
out = gate(tmp_path, repo, sha, block(touches="logic"))
|
|
35
|
+
assert "agentMerge is off" not in out["reasons"]
|
|
36
|
+
assert out["countedLines"] == (0 if was_generated else 1501)
|
|
37
|
+
assert out["verdict"] == ("auto" if was_generated else "human")
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"""Structure and behavior-preservation tests for the merge_risk refactor (ticket 17).
|
|
2
|
+
|
|
3
|
+
Golden outputs were recorded from merge_risk.py before the refactor (commit 74ccb2c).
|
|
4
|
+
"""
|
|
5
|
+
import ast
|
|
6
|
+
import os
|
|
7
|
+
import subprocess
|
|
8
|
+
import sys
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
HERE = Path(__file__).resolve().parent
|
|
12
|
+
SCRIPT = HERE / "merge_risk.py"
|
|
13
|
+
BRANCHES = (ast.If, ast.For, ast.While, ast.ExceptHandler, ast.IfExp,
|
|
14
|
+
ast.comprehension)
|
|
15
|
+
|
|
16
|
+
CASES = {'valid': 'door: two-way\nblast_radius: isolated\ntouches: [docs, tests]\nrollback: revert\nverdict: auto\nreasons:\n - "Only prose"\n', 'inline': 'door: two-way\nblast_radius: isolated\ntouches: [docs, tests]\nrollback: revert\nverdict: auto\nreasons: [a, "b, c"]\n', 'bad': 'door: sideways\ntouches: [docs, styles, ]\nrollback: revert\nrollback: x\nfoo: 1\nreasons: nope\n junk\n', 'emptyreasons': 'door: two-way\nblast_radius: isolated\ntouches: [docs, tests]\nrollback: revert\nverdict: auto\nreasons:\n', 'badreasons': 'door: two-way\nblast_radius: isolated\ntouches: [docs, tests]\nrollback: revert\nverdict: auto\nreasons:\n - a: b\n - ""\n - [x]\n - \'q\'x\'\n'}
|
|
17
|
+
GOLDEN = {'valid:parse': [0, '{"door": "two-way", "blast_radius": "isolated", "rollback": "revert", "verdict": "auto", "touches": ["docs", "tests"], "reasons": ["Only prose"], "errors": []}\n'], 'valid:validate': [0, ''], 'inline:parse': [0, '{"door": "two-way", "blast_radius": "isolated", "rollback": "revert", "verdict": "auto", "touches": ["docs", "tests"], "reasons": ["a", "b, c"], "errors": []}\n'], 'inline:validate': [0, ''], 'bad:parse': [0, '{"door": "sideways", "blast_radius": null, "rollback": "revert", "verdict": null, "touches": ["docs", "styles", ""], "reasons": [], "errors": ["touches has an empty element", "duplicate key: rollback", "unknown key: foo", "reasons must be a `- item` list or an inline list", "unsupported line: junk", "missing key: blast_radius", "missing key: verdict", "door: \'sideways\' is not one of one-way | two-way", "unknown category: styles", "reasons must have at least one item"]}\n'], 'bad:validate': [1, "touches has an empty element\nduplicate key: rollback\nunknown key: foo\nreasons must be a `- item` list or an inline list\nunsupported line: junk\nmissing key: blast_radius\nmissing key: verdict\ndoor: 'sideways' is not one of one-way | two-way\nunknown category: styles\nreasons must have at least one item\n"], 'emptyreasons:parse': [0, '{"door": "two-way", "blast_radius": "isolated", "rollback": "revert", "verdict": "auto", "touches": ["docs", "tests"], "reasons": [], "errors": ["reasons must have at least one item"]}\n'], 'emptyreasons:validate': [1, 'reasons must have at least one item\n'], 'badreasons:parse': [0, '{"door": "two-way", "blast_radius": "isolated", "rollback": "revert", "verdict": "auto", "touches": ["docs", "tests"], "reasons": [], "errors": ["unsupported reason form: a: b", "empty reason", "unsupported reason form: [x]", "malformed quoted reason: \'q\'x\'", "reasons must have at least one item"]}\n'], 'badreasons:validate': [1, "unsupported reason form: a: b\nempty reason\nunsupported reason form: [x]\nmalformed quoted reason: 'q'x'\nreasons must have at least one item\n"]}
|
|
18
|
+
|
|
19
|
+
GATE_GOLDEN = '{"verdict": "human", "reasons": ["diff touches logic, not in touches", "agentMerge is off"], "categories": ["docs", "logic"], "countedLines": 1}\n'
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def complexity(fn):
|
|
23
|
+
"""McCabe complexity of one function, nested functions counted separately."""
|
|
24
|
+
n, stack = 1, list(ast.iter_child_nodes(fn))
|
|
25
|
+
while stack:
|
|
26
|
+
node = stack.pop()
|
|
27
|
+
if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef, ast.Lambda)):
|
|
28
|
+
continue
|
|
29
|
+
n += isinstance(node, BRANCHES)
|
|
30
|
+
n += len(node.ifs) if isinstance(node, ast.comprehension) else 0
|
|
31
|
+
n += len(node.values) - 1 if isinstance(node, ast.BoolOp) else 0
|
|
32
|
+
stack.extend(ast.iter_child_nodes(node))
|
|
33
|
+
return n
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def functions(path):
|
|
37
|
+
tree = ast.parse(path.read_text())
|
|
38
|
+
return [n for n in ast.walk(tree) if isinstance(n, (ast.FunctionDef, ast.AsyncFunctionDef))]
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def test_no_function_is_more_complex_than_8():
|
|
42
|
+
too_complex = {f"{p.name}:{f.name}": complexity(f)
|
|
43
|
+
for p in (SCRIPT, HERE / "merge_policy.py") for f in functions(p)
|
|
44
|
+
if complexity(f) > 8}
|
|
45
|
+
assert too_complex == {}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def test_parse_block_is_gone_or_under_15_lines():
|
|
49
|
+
for f in functions(SCRIPT):
|
|
50
|
+
if f.name == "parse_block":
|
|
51
|
+
assert f.end_lineno - f.lineno + 1 < 15
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def test_policy_lives_in_merge_policy_and_merge_risk_still_exposes_it():
|
|
55
|
+
code = ("import merge_risk, merge_policy;"
|
|
56
|
+
"[getattr(merge_risk, n) for n in "
|
|
57
|
+
"('git','load_policy','DEFAULT_PATHS','POLICY_FILE','file_categories')];"
|
|
58
|
+
"assert merge_risk.load_policy is merge_policy.load_policy;"
|
|
59
|
+
"assert merge_policy.POLICY_FILE and merge_policy.LOCKFILES and merge_policy.DEFAULT_POLICY")
|
|
60
|
+
proc = subprocess.run([sys.executable, "-c", code], cwd=HERE, capture_output=True, text=True)
|
|
61
|
+
assert proc.returncode == 0, proc.stderr
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def test_parse_and_validate_output_is_byte_identical_to_before_the_refactor(tmp_path):
|
|
65
|
+
for key, (code, out) in GOLDEN.items():
|
|
66
|
+
name, cmd = key.split(":")
|
|
67
|
+
f = tmp_path / "body.md"
|
|
68
|
+
f.write_text("x\n```merge-risk v1\n" + CASES[name] + "```\n")
|
|
69
|
+
proc = subprocess.run([sys.executable, str(SCRIPT), cmd, str(f)],
|
|
70
|
+
capture_output=True, text=True, cwd=tmp_path)
|
|
71
|
+
assert (proc.returncode, proc.stdout) == (code, out), key
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def test_gate_output_is_byte_identical_to_before_the_refactor(tmp_path):
|
|
75
|
+
env = {**os.environ, "GIT_AUTHOR_NAME": "t", "GIT_AUTHOR_EMAIL": "t@t",
|
|
76
|
+
"GIT_COMMITTER_NAME": "t", "GIT_COMMITTER_EMAIL": "t@t",
|
|
77
|
+
"GIT_CONFIG_GLOBAL": os.devnull, "GIT_CONFIG_SYSTEM": os.devnull}
|
|
78
|
+
repo = tmp_path / "repo"
|
|
79
|
+
repo.mkdir()
|
|
80
|
+
|
|
81
|
+
def git(*args):
|
|
82
|
+
return subprocess.run(["git", *args], cwd=repo, env=env, text=True,
|
|
83
|
+
capture_output=True, check=True).stdout.strip()
|
|
84
|
+
|
|
85
|
+
git("init", "-q", "-b", "work")
|
|
86
|
+
(repo / "README.md").write_text("hi\n")
|
|
87
|
+
git("add", "-A")
|
|
88
|
+
git("commit", "-qm", "base")
|
|
89
|
+
git("update-ref", "refs/remotes/origin/main", git("rev-parse", "HEAD"))
|
|
90
|
+
(repo / "src").mkdir()
|
|
91
|
+
(repo / "src" / "a.py").write_text("x = 1\n")
|
|
92
|
+
(repo / "docs.md").write_text("doc\n")
|
|
93
|
+
git("add", "-A")
|
|
94
|
+
git("commit", "-qm", "head")
|
|
95
|
+
body = tmp_path / "body.md"
|
|
96
|
+
body.write_text("x\n```merge-risk v1\n" + CASES["valid"] + "```\n")
|
|
97
|
+
proc = subprocess.run([sys.executable, str(SCRIPT), "gate", "--body", str(body),
|
|
98
|
+
"--base", "main", "--head", git("rev-parse", "HEAD")],
|
|
99
|
+
capture_output=True, text=True, cwd=repo, env=env)
|
|
100
|
+
assert proc.returncode == 0, proc.stderr
|
|
101
|
+
assert proc.stdout == GATE_GOLDEN
|
package/skills-manifest.json
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
|
-
"generatedAt": "2026-10-
|
|
3
|
+
"generatedAt": "2026-10-22T11:14:54.556Z",
|
|
4
4
|
"skills": [
|
|
5
|
+
{
|
|
6
|
+
"name": "babysit-pr",
|
|
7
|
+
"version": "0.1.0",
|
|
8
|
+
"hash": "sha256-6da121d1648ed363c265dcf9b3faa6ca79f1a3e639050b52643a6867f71e8370",
|
|
9
|
+
"description": "Babysit an open pull request until it is merged or handed to a human. Started by the PostToolUse hook after `gh pr create`, or by hand with `/babysit-pr <pr-url>`."
|
|
10
|
+
},
|
|
5
11
|
{
|
|
6
12
|
"name": "backlog",
|
|
7
13
|
"version": "0.1.8",
|
|
@@ -46,10 +52,16 @@
|
|
|
46
52
|
},
|
|
47
53
|
{
|
|
48
54
|
"name": "implement-spec",
|
|
49
|
-
"version": "0.1.
|
|
50
|
-
"hash": "sha256-
|
|
55
|
+
"version": "0.1.39",
|
|
56
|
+
"hash": "sha256-303cb5ea3c05a8f5e3b127780d772e8aa808de618801f468093a6d7f40781259",
|
|
51
57
|
"description": "Implement a specification in code."
|
|
52
58
|
},
|
|
59
|
+
{
|
|
60
|
+
"name": "pr-risk",
|
|
61
|
+
"version": "0.1.0",
|
|
62
|
+
"hash": "sha256-54b54a42738571c346a040326cde2d314d0239dca3ce42323d2b8434dbe9d5f9",
|
|
63
|
+
"description": "Merge-risk block of a PR body. Use when a PR body needs its ```merge-risk v1 block parsed or validated, with every error named."
|
|
64
|
+
},
|
|
53
65
|
{
|
|
54
66
|
"name": "pr-visual-diff",
|
|
55
67
|
"version": "0.1.2",
|