@jesdi/skills 0.0.101 → 0.0.102
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 +9 -2
- package/skills/babysit-pr/babysit.py +98 -36
- package/skills/babysit-pr/exam.py +156 -0
- package/skills/babysit-pr/fixtures/exam_host.py +47 -0
- package/skills/babysit-pr/fixtures/gh +107 -11
- package/skills/babysit-pr/test_babysit.py +8 -2
- package/skills/babysit-pr/test_e2e_setup.py +1 -1
- package/skills/babysit-pr/test_exam_merge_gate.py +189 -0
- package/skills/babysit-pr/test_exam_request.py +337 -0
- package/skills/babysit-pr/test_exam_required_check.py +145 -0
- package/skills/babysit-pr/test_exam_wait.py +353 -0
- package/skills/babysit-pr/test_merge_and_handoff.py +12 -6
- package/skills/babysit-pr/test_trusted_merge_risk.py +2 -2
- package/skills/pr-exam/SKILL.md +131 -0
- package/skills/pr-exam/fixtures/README.md +20 -0
- package/skills/pr-exam/fixtures/delta-new-concept/body.md +9 -0
- package/skills/pr-exam/fixtures/delta-new-concept/diff.patch +82 -0
- package/skills/pr-exam/fixtures/delta-new-concept/exam.json +46 -0
- package/skills/pr-exam/fixtures/delta-new-concept/passed.diff +66 -0
- package/skills/pr-exam/fixtures/delta-new-concept/records/0001-single-sync-leader.md +10 -0
- package/skills/pr-exam/fixtures/delta-new-concept/records/0002-stale-leader-writes.md +10 -0
- package/skills/pr-exam/fixtures/delta-new-concept/records/0003-fencing-token.md +10 -0
- package/skills/pr-exam/fixtures/delta-new-concept/records/0004-lease-expiry.md +10 -0
- package/skills/pr-exam/fixtures/delta-new-concept/records/0005-injected-monotonic-clock.md +10 -0
- package/skills/pr-exam/fixtures/delta-new-concept/records/0006-leader-lifecycle.md +10 -0
- package/skills/pr-exam/fixtures/delta-new-concept/records/0007-lease-rollback.md +10 -0
- package/skills/pr-exam/fixtures/delta-new-concept/records/0008-sync-blast-radius.md +10 -0
- package/skills/pr-exam/fixtures/delta-new-concept/request.json +43 -0
- package/skills/pr-exam/fixtures/delta-nothing-new/body.md +9 -0
- package/skills/pr-exam/fixtures/delta-nothing-new/diff.patch +66 -0
- package/skills/pr-exam/fixtures/delta-nothing-new/exam.json +10 -0
- package/skills/pr-exam/fixtures/delta-nothing-new/passed.diff +66 -0
- package/skills/pr-exam/fixtures/delta-nothing-new/records/0001-single-sync-leader.md +10 -0
- package/skills/pr-exam/fixtures/delta-nothing-new/records/0002-stale-leader-writes.md +10 -0
- package/skills/pr-exam/fixtures/delta-nothing-new/records/0003-fencing-token.md +10 -0
- package/skills/pr-exam/fixtures/delta-nothing-new/records/0004-lease-expiry.md +10 -0
- package/skills/pr-exam/fixtures/delta-nothing-new/records/0005-injected-monotonic-clock.md +10 -0
- package/skills/pr-exam/fixtures/delta-nothing-new/records/0006-leader-lifecycle.md +10 -0
- package/skills/pr-exam/fixtures/delta-nothing-new/records/0007-lease-rollback.md +10 -0
- package/skills/pr-exam/fixtures/delta-nothing-new/records/0008-sync-blast-radius.md +10 -0
- package/skills/pr-exam/fixtures/delta-nothing-new/request.json +43 -0
- package/skills/pr-exam/fixtures/followup/body.md +9 -0
- package/skills/pr-exam/fixtures/followup/diff.patch +66 -0
- package/skills/pr-exam/fixtures/followup/exam.json +61 -0
- package/skills/pr-exam/fixtures/followup/records/0001-single-sync-leader.md +10 -0
- package/skills/pr-exam/fixtures/followup/records/0002-stale-leader-writes.md +10 -0
- package/skills/pr-exam/fixtures/followup/records/0003-fencing-token.md +10 -0
- package/skills/pr-exam/fixtures/followup/records/0004-lease-expiry.md +10 -0
- package/skills/pr-exam/fixtures/followup/records/0005-injected-monotonic-clock.md +10 -0
- package/skills/pr-exam/fixtures/followup/records/0006-lease-rollback.md +10 -0
- package/skills/pr-exam/fixtures/followup/records/0007-sync-blast-radius.md +10 -0
- package/skills/pr-exam/fixtures/followup/request.json +41 -0
- package/skills/pr-exam/fixtures/grading/answers.json +5 -0
- package/skills/pr-exam/fixtures/grading/attempt.json +10 -0
- package/skills/pr-exam/fixtures/grading/grades.json +14 -0
- package/skills/pr-exam/fixtures/grading/questions.json +26 -0
- package/skills/pr-exam/fixtures/grading/request.json +10 -0
- package/skills/pr-exam/fixtures/twelve-concepts/body.md +9 -0
- package/skills/pr-exam/fixtures/twelve-concepts/diff.patch +66 -0
- package/skills/pr-exam/fixtures/twelve-concepts/exam.json +195 -0
- package/skills/pr-exam/fixtures/twelve-concepts/request.json +15 -0
- package/skills/pr-exam/fixtures/typo-readme/body.md +1 -0
- package/skills/pr-exam/fixtures/typo-readme/diff.patch +7 -0
- package/skills/pr-exam/fixtures/typo-readme/exam.json +30 -0
- package/skills/pr-exam/fixtures/typo-readme/request.json +15 -0
- package/skills/pr-exam/pr_exam.py +705 -0
- package/skills/pr-exam/test_config.py +83 -0
- package/skills/pr-exam/test_exam_format.py +252 -0
- package/skills/pr-exam/test_followup_delta.py +90 -0
- package/skills/pr-exam/test_learning_records.py +267 -0
- package/skills/pr-exam/test_record_publication.py +45 -0
- package/skills/pr-exam/test_scoring.py +121 -0
- package/skills/pr-exam/test_served_shapes.py +38 -0
- package/skills/pr-exam/test_setup.py +349 -0
- package/skills/pr-exam/test_skill_fixtures.py +88 -0
- package/skills-manifest.json +9 -3
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
"""Acceptance tests for `pr_exam.py setup <owner/repo>` (spec specs/pr-exam, requirement 14;
|
|
2
|
+
scenarios "setup on a public repo", "setup on a private repo of a free account").
|
|
3
|
+
|
|
4
|
+
Interface under test:
|
|
5
|
+
pr_exam.py setup OWNER/REPO
|
|
6
|
+
Asks the host for its GitHub App: `GET $PR_EXAM_HOST/api/exam/host` answers 200 with
|
|
7
|
+
{"app_id": <int>}. Then makes `exam` a required status check of the repo's default branch
|
|
8
|
+
through `gh api`, changing as little as it can:
|
|
9
|
+
- a protected branch: one PATCH of the required-status-checks sub-resource, holding the
|
|
10
|
+
existing checks (each with its app) plus `exam` bound to that App id; no other setting is sent;
|
|
11
|
+
- a protected branch with status checks off: the same PATCH turns them on; where GitHub
|
|
12
|
+
answers 404 to it, the context is added first (POST .../contexts) and then bound;
|
|
13
|
+
- an unprotected default branch: one PUT of a protection holding only `exam`, enforced for admins;
|
|
14
|
+
- GitHub answering "Upgrade to GitHub Pro or make this repository public": no write, exit 0,
|
|
15
|
+
the output says the gate is agent-enforced only;
|
|
16
|
+
- any other GitHub error, or a host that cannot report the App id: non-zero, no write.
|
|
17
|
+
pr_exam.py setup --check OWNER/REPO
|
|
18
|
+
Reads only, and needs no host: prints {"required": <bool>, "branch": <default branch>}, true when
|
|
19
|
+
`exam` is among the default branch's required checks. Non-zero when GitHub would not say.
|
|
20
|
+
`gh` is the fake in ../babysit-pr/fixtures/gh (branch protection state, see its docstring).
|
|
21
|
+
"""
|
|
22
|
+
import copy
|
|
23
|
+
import json
|
|
24
|
+
import os
|
|
25
|
+
import shutil
|
|
26
|
+
import subprocess
|
|
27
|
+
import sys
|
|
28
|
+
import threading
|
|
29
|
+
from http.server import BaseHTTPRequestHandler, HTTPServer
|
|
30
|
+
from pathlib import Path
|
|
31
|
+
|
|
32
|
+
import pytest
|
|
33
|
+
|
|
34
|
+
SCRIPT = Path(__file__).parent / "pr_exam.py"
|
|
35
|
+
FAKE_GH = Path(__file__).parent.parent / "babysit-pr" / "fixtures" / "gh"
|
|
36
|
+
APP_ID = 424242
|
|
37
|
+
UPGRADE = {"status": 403, "message": "Upgrade to GitHub Pro or make this repository public."}
|
|
38
|
+
|
|
39
|
+
PROTECTION = {
|
|
40
|
+
"required_status_checks": {"strict": True, "contexts": ["test", "lint"],
|
|
41
|
+
"checks": [{"context": "test", "app_id": 15368},
|
|
42
|
+
{"context": "lint", "app_id": 15368}]},
|
|
43
|
+
"enforce_admins": {"enabled": False},
|
|
44
|
+
"required_pull_request_reviews": {"required_approving_review_count": 2,
|
|
45
|
+
"dismiss_stale_reviews": True},
|
|
46
|
+
"restrictions": None,
|
|
47
|
+
"required_linear_history": {"enabled": True},
|
|
48
|
+
"allow_force_pushes": {"enabled": False},
|
|
49
|
+
"allow_deletions": {"enabled": False},
|
|
50
|
+
"block_creations": {"enabled": True},
|
|
51
|
+
"required_conversation_resolution": {"enabled": True},
|
|
52
|
+
"lock_branch": {"enabled": False},
|
|
53
|
+
"allow_fork_syncing": {"enabled": True},
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class Host:
|
|
58
|
+
"""GET /api/exam/host -> `status`, `answer`; records the request paths."""
|
|
59
|
+
|
|
60
|
+
def __init__(self, answer=None, status=200):
|
|
61
|
+
self.answer = {"app_id": APP_ID} if answer is None else answer
|
|
62
|
+
self.status = status
|
|
63
|
+
self.paths = []
|
|
64
|
+
host = self
|
|
65
|
+
|
|
66
|
+
class Handler(BaseHTTPRequestHandler):
|
|
67
|
+
def do_GET(self):
|
|
68
|
+
host.paths.append(self.path)
|
|
69
|
+
data = json.dumps(host.answer).encode()
|
|
70
|
+
self.send_response(host.status)
|
|
71
|
+
self.send_header("Content-Type", "application/json")
|
|
72
|
+
self.send_header("Content-Length", str(len(data)))
|
|
73
|
+
self.end_headers()
|
|
74
|
+
self.wfile.write(data)
|
|
75
|
+
|
|
76
|
+
def log_message(self, *args):
|
|
77
|
+
pass
|
|
78
|
+
|
|
79
|
+
self.server = HTTPServer(("127.0.0.1", 0), Handler)
|
|
80
|
+
self.url = f"http://127.0.0.1:{self.server.server_port}"
|
|
81
|
+
threading.Thread(target=self.server.serve_forever, daemon=True).start()
|
|
82
|
+
|
|
83
|
+
def close(self):
|
|
84
|
+
self.server.shutdown()
|
|
85
|
+
self.server.server_close()
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
@pytest.fixture
|
|
89
|
+
def host():
|
|
90
|
+
h = Host()
|
|
91
|
+
yield h
|
|
92
|
+
h.close()
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
class Repo:
|
|
96
|
+
def __init__(self, tmp_path, **state):
|
|
97
|
+
bindir = tmp_path / "bin"
|
|
98
|
+
bindir.mkdir()
|
|
99
|
+
shutil.copy(FAKE_GH, bindir / "gh")
|
|
100
|
+
(bindir / "gh").chmod(0o755)
|
|
101
|
+
self.state, self.log = tmp_path / "state.json", tmp_path / "log.jsonl"
|
|
102
|
+
self.log.write_text("")
|
|
103
|
+
self.state.write_text(json.dumps({"now": "2026-01-01T00:00:00Z", "user": "jesdi",
|
|
104
|
+
"comments": [], "labels": [], "next_id": 1, **state}))
|
|
105
|
+
self.env = {**os.environ, "PATH": f"{bindir}{os.pathsep}{os.environ['PATH']}",
|
|
106
|
+
"GH_FAKE_STATE": str(self.state), "GH_FAKE_LOG": str(self.log)}
|
|
107
|
+
self.env.pop("PR_EXAM_HOST", None)
|
|
108
|
+
|
|
109
|
+
def setup(self, repo, host_url, *flags):
|
|
110
|
+
env = {**self.env, **({"PR_EXAM_HOST": host_url} if host_url else {})}
|
|
111
|
+
p = subprocess.run([sys.executable, str(SCRIPT), "setup", *flags, repo], env=env, text=True,
|
|
112
|
+
capture_output=True, cwd=self.state.parent)
|
|
113
|
+
p.output = p.stdout + p.stderr
|
|
114
|
+
return p
|
|
115
|
+
|
|
116
|
+
def github(self):
|
|
117
|
+
return json.loads(self.state.read_text())
|
|
118
|
+
|
|
119
|
+
def set(self, **kw):
|
|
120
|
+
st = self.github()
|
|
121
|
+
st.update(kw)
|
|
122
|
+
self.state.write_text(json.dumps(st))
|
|
123
|
+
|
|
124
|
+
def writes(self):
|
|
125
|
+
return [e["argv"] for e in map(json.loads, self.log.read_text().splitlines()) if e["write"]]
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def exam_check(app_id=APP_ID):
|
|
129
|
+
return {"context": "exam", "app_id": app_id}
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def test_setup_on_a_public_repo_adds_exam_bound_to_the_app_and_keeps_the_rest(tmp_path, host):
|
|
133
|
+
r = Repo(tmp_path, private=False, default_branch="trunk", protection=copy.deepcopy(PROTECTION))
|
|
134
|
+
p = r.setup("jesdi/agent-ops", host.url)
|
|
135
|
+
assert p.returncode == 0, p.output
|
|
136
|
+
assert "/api/exam/host" in host.paths
|
|
137
|
+
after = r.github()["protection"]
|
|
138
|
+
rsc = after["required_status_checks"]
|
|
139
|
+
assert rsc["contexts"] == ["test", "lint", "exam"]
|
|
140
|
+
assert rsc["checks"] == PROTECTION["required_status_checks"]["checks"] + [exam_check()]
|
|
141
|
+
assert rsc["strict"] is True
|
|
142
|
+
assert {k: v for k, v in after.items() if k != "required_status_checks"} == \
|
|
143
|
+
{k: v for k, v in PROTECTION.items() if k != "required_status_checks"}
|
|
144
|
+
[write] = r.writes() # one narrow write: the other settings are never sent, so never rewritten
|
|
145
|
+
assert write[:3] == ["api", "-X", "PATCH"]
|
|
146
|
+
assert write[3] == "repos/jesdi/agent-ops/branches/trunk/protection/required_status_checks"
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def test_running_setup_a_second_time_changes_nothing(tmp_path, host):
|
|
150
|
+
r = Repo(tmp_path, private=False, protection=copy.deepcopy(PROTECTION))
|
|
151
|
+
assert r.setup("jesdi/agent-ops", host.url).returncode == 0
|
|
152
|
+
first = r.github()
|
|
153
|
+
assert first["protection"]["required_status_checks"]["contexts"] == ["test", "lint", "exam"]
|
|
154
|
+
p = r.setup("jesdi/agent-ops", host.url)
|
|
155
|
+
assert p.returncode == 0, p.output
|
|
156
|
+
assert r.github()["protection"] == first["protection"]
|
|
157
|
+
assert r.github()["protection"]["required_status_checks"]["checks"].count(exam_check()) == 1
|
|
158
|
+
assert len(r.writes()) == 1 # the first run's; the second wrote nothing
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def test_an_unprotected_default_branch_gets_exam_only_enforced_for_admins(tmp_path, host):
|
|
162
|
+
r = Repo(tmp_path, private=False, default_branch="main")
|
|
163
|
+
p = r.setup("jesdi/agent-ops", host.url)
|
|
164
|
+
assert p.returncode == 0, p.output
|
|
165
|
+
after = r.github()["protection"]
|
|
166
|
+
assert after["required_status_checks"]["checks"] == [exam_check()]
|
|
167
|
+
assert after["required_status_checks"]["contexts"] == ["exam"]
|
|
168
|
+
assert after["enforce_admins"] == {"enabled": True}
|
|
169
|
+
assert after["required_pull_request_reviews"] is None
|
|
170
|
+
assert after["restrictions"] is None
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def test_a_private_repo_on_a_free_account_is_left_alone_and_said_agent_enforced(tmp_path, host):
|
|
174
|
+
r = Repo(tmp_path, private=True, protection_error=UPGRADE)
|
|
175
|
+
p = r.setup("jesdi/claude-config", host.url)
|
|
176
|
+
assert p.returncode == 0, p.output
|
|
177
|
+
assert "agent-enforced" in p.output.lower(), p.output
|
|
178
|
+
assert r.writes() == []
|
|
179
|
+
assert "protection" not in r.github()
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
@pytest.mark.parametrize("error", [
|
|
183
|
+
{"status": 500, "message": "Server Error"},
|
|
184
|
+
{"status": 403, "message": "Resource not accessible by integration"},
|
|
185
|
+
], ids=["server-error", "forbidden"])
|
|
186
|
+
def test_any_other_github_error_fails_and_changes_nothing(tmp_path, host, error):
|
|
187
|
+
r = Repo(tmp_path, private=False, protection=copy.deepcopy(PROTECTION), protection_error=error)
|
|
188
|
+
p = r.setup("jesdi/agent-ops", host.url)
|
|
189
|
+
assert p.returncode != 0, p.output
|
|
190
|
+
assert "agent-enforced" not in p.output.lower()
|
|
191
|
+
assert r.writes() == []
|
|
192
|
+
# control: the failure was the refusal, not a missing command
|
|
193
|
+
r.set(protection_error=None)
|
|
194
|
+
ok = r.setup("jesdi/agent-ops", host.url)
|
|
195
|
+
assert ok.returncode == 0, ok.output
|
|
196
|
+
assert "exam" in r.github()["protection"]["required_status_checks"]["contexts"]
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def test_a_failed_protection_write_fails_and_leaves_the_protection_as_it_was(tmp_path, host):
|
|
200
|
+
r = Repo(tmp_path, private=False, protection=copy.deepcopy(PROTECTION),
|
|
201
|
+
put_error={"status": 422, "message": "Validation Failed"})
|
|
202
|
+
p = r.setup("jesdi/agent-ops", host.url)
|
|
203
|
+
assert p.returncode != 0, p.output
|
|
204
|
+
assert r.github()["protection"] == PROTECTION
|
|
205
|
+
r.set(put_error=None)
|
|
206
|
+
assert r.setup("jesdi/agent-ops", host.url).returncode == 0
|
|
207
|
+
assert "exam" in r.github()["protection"]["required_status_checks"]["contexts"]
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
@pytest.mark.parametrize("answer, status", [({}, 200), ({"app_id": "abc"}, 200), ({"app_id": None}, 200),
|
|
211
|
+
({"error": "boom"}, 500), (None, "unreachable")],
|
|
212
|
+
ids=["no-app-id", "bad-app-id", "null-app-id", "host-error", "unreachable"])
|
|
213
|
+
def test_a_host_that_cannot_report_the_app_id_fails_and_changes_nothing(tmp_path, answer, status):
|
|
214
|
+
r = Repo(tmp_path, private=False, protection=copy.deepcopy(PROTECTION))
|
|
215
|
+
bad = Host(answer, status if status != "unreachable" else 200)
|
|
216
|
+
url = bad.url
|
|
217
|
+
if status == "unreachable":
|
|
218
|
+
bad.close()
|
|
219
|
+
try:
|
|
220
|
+
p = r.setup("jesdi/agent-ops", url)
|
|
221
|
+
finally:
|
|
222
|
+
if status != "unreachable":
|
|
223
|
+
bad.close()
|
|
224
|
+
assert p.returncode != 0, p.output
|
|
225
|
+
assert r.writes() == []
|
|
226
|
+
assert r.github()["protection"] == PROTECTION
|
|
227
|
+
# control: with a healthy host the same repo is protected
|
|
228
|
+
good = Host()
|
|
229
|
+
try:
|
|
230
|
+
ok = r.setup("jesdi/agent-ops", good.url)
|
|
231
|
+
finally:
|
|
232
|
+
good.close()
|
|
233
|
+
assert ok.returncode == 0, ok.output
|
|
234
|
+
assert exam_check() in r.github()["protection"]["required_status_checks"]["checks"]
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
def test_setup_without_a_host_configured_fails_and_changes_nothing(tmp_path, host):
|
|
238
|
+
r = Repo(tmp_path, private=False, protection=copy.deepcopy(PROTECTION))
|
|
239
|
+
p = r.setup("jesdi/agent-ops", None)
|
|
240
|
+
assert p.returncode != 0, p.output
|
|
241
|
+
assert r.writes() == []
|
|
242
|
+
assert r.setup("jesdi/agent-ops", host.url).returncode == 0
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
def test_review_allowances_and_push_restrictions_are_left_exactly_as_they_were(tmp_path, host):
|
|
246
|
+
people = {"url": "https://api.github.com/x", "users": [{"login": "ana", "url": "u"}],
|
|
247
|
+
"teams": [{"slug": "core", "url": "u"}], "apps": [{"slug": "bot", "url": "u"}]}
|
|
248
|
+
protection = copy.deepcopy(PROTECTION)
|
|
249
|
+
protection["restrictions"] = copy.deepcopy(people)
|
|
250
|
+
protection["required_pull_request_reviews"] = {
|
|
251
|
+
"url": "https://api.github.com/r", "required_approving_review_count": 1,
|
|
252
|
+
"dismissal_restrictions": copy.deepcopy(people), "bypass_pull_request_allowances": {"users": [], "teams": []}}
|
|
253
|
+
r = Repo(tmp_path, private=False, protection=copy.deepcopy(protection))
|
|
254
|
+
p = r.setup("jesdi/agent-ops", host.url)
|
|
255
|
+
assert p.returncode == 0, p.output
|
|
256
|
+
after = r.github()["protection"]
|
|
257
|
+
assert exam_check() in after["required_status_checks"]["checks"]
|
|
258
|
+
assert {k: v for k, v in after.items() if k != "required_status_checks"} == \
|
|
259
|
+
{k: v for k, v in protection.items() if k != "required_status_checks"}
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
def test_checks_named_only_by_context_stay_required_from_any_app(tmp_path, host):
|
|
263
|
+
r = Repo(tmp_path, private=False, required_checks=["test", "lint"]) # contexts with no app
|
|
264
|
+
p = r.setup("jesdi/agent-ops", host.url)
|
|
265
|
+
assert p.returncode == 0, p.output
|
|
266
|
+
assert r.github()["protection"]["required_status_checks"]["checks"] == [
|
|
267
|
+
{"context": "test", "app_id": None}, {"context": "lint", "app_id": None}, exam_check()]
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
def test_an_exam_required_from_another_sender_is_rebound_to_the_app(tmp_path, host):
|
|
271
|
+
r = Repo(tmp_path, private=False, required_checks=["test", "exam"])
|
|
272
|
+
p = r.setup("jesdi/agent-ops", host.url)
|
|
273
|
+
assert p.returncode == 0, p.output
|
|
274
|
+
assert r.github()["protection"]["required_status_checks"]["checks"] == [
|
|
275
|
+
{"context": "test", "app_id": None}, exam_check()]
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
@pytest.mark.parametrize("patch_needs_checks", [False, True], ids=["patch-turns-them-on", "patch-404s"])
|
|
279
|
+
def test_a_protected_branch_with_status_checks_off_gets_exam_and_keeps_the_rest(tmp_path, host, patch_needs_checks):
|
|
280
|
+
protection = {**copy.deepcopy(PROTECTION), "required_status_checks": None}
|
|
281
|
+
r = Repo(tmp_path, private=False, protection=copy.deepcopy(protection), patch_needs_checks=patch_needs_checks)
|
|
282
|
+
p = r.setup("jesdi/agent-ops", host.url)
|
|
283
|
+
assert p.returncode == 0, p.output
|
|
284
|
+
after = r.github()["protection"]
|
|
285
|
+
assert after["required_status_checks"]["checks"] == [exam_check()]
|
|
286
|
+
assert {k: v for k, v in after.items() if k != "required_status_checks"} == \
|
|
287
|
+
{k: v for k, v in protection.items() if k != "required_status_checks"}
|
|
288
|
+
assert all("required_status_checks" in a[3] for a in r.writes()), r.writes() # only the sub-resource
|
|
289
|
+
assert not r.github().get("puts")
|
|
290
|
+
again = r.setup("jesdi/agent-ops", host.url)
|
|
291
|
+
assert again.returncode == 0 and r.github()["protection"] == after
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
def test_status_checks_off_and_a_refused_write_fail_and_change_nothing(tmp_path, host):
|
|
295
|
+
protection = {**copy.deepcopy(PROTECTION), "required_status_checks": None}
|
|
296
|
+
r = Repo(tmp_path, private=False, protection=copy.deepcopy(protection),
|
|
297
|
+
put_error={"status": 403, "message": "Resource not accessible by integration"})
|
|
298
|
+
p = r.setup("jesdi/agent-ops", host.url)
|
|
299
|
+
assert p.returncode != 0, p.output
|
|
300
|
+
assert "Resource not accessible" in p.stderr
|
|
301
|
+
assert r.github()["protection"] == protection
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
def test_a_protected_branch_without_required_reviews_keeps_none(tmp_path, host):
|
|
305
|
+
r = Repo(tmp_path, private=False, protection={**copy.deepcopy(PROTECTION), "required_pull_request_reviews": None})
|
|
306
|
+
p = r.setup("jesdi/agent-ops", host.url)
|
|
307
|
+
assert p.returncode == 0, p.output
|
|
308
|
+
assert r.github()["protection"]["required_pull_request_reviews"] is None
|
|
309
|
+
assert exam_check() in r.github()["protection"]["required_status_checks"]["checks"]
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
def test_a_repo_github_cannot_read_fails_and_changes_nothing(tmp_path, host):
|
|
313
|
+
r = Repo(tmp_path, private=False, protection=copy.deepcopy(PROTECTION))
|
|
314
|
+
p = r.setup("agent-ops", host.url) # no owner: `gh api repos/agent-ops` fails
|
|
315
|
+
assert p.returncode != 0, p.output
|
|
316
|
+
assert "fake gh: unsupported api GET repos/agent-ops" in p.stderr, p.stderr
|
|
317
|
+
assert r.writes() == []
|
|
318
|
+
assert r.github()["protection"] == PROTECTION
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
CHECK_CASES = {
|
|
322
|
+
"bound-to-the-app": (dict(protection=PROTECTION | {"required_status_checks": {
|
|
323
|
+
"strict": False, "contexts": ["exam"], "checks": [{"context": "exam", "app_id": APP_ID}]}}), True),
|
|
324
|
+
"required-from-anyone": (dict(required_checks=["test", "exam"]), True),
|
|
325
|
+
"other-checks-only": (dict(protection=PROTECTION), False),
|
|
326
|
+
"unprotected": ({}, False),
|
|
327
|
+
"status-checks-off": (dict(protection=PROTECTION | {"required_status_checks": None}), False),
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
@pytest.mark.parametrize("state, required", CHECK_CASES.values(), ids=CHECK_CASES)
|
|
332
|
+
def test_check_reports_whether_exam_is_required_without_a_host_or_a_write(tmp_path, state, required):
|
|
333
|
+
r = Repo(tmp_path, private=False, default_branch="trunk", **copy.deepcopy(state))
|
|
334
|
+
before = r.github()
|
|
335
|
+
p = r.setup("jesdi/agent-ops", None, "--check")
|
|
336
|
+
assert p.returncode == 0, p.output
|
|
337
|
+
assert json.loads(p.stdout) == {"required": required, "branch": "trunk"}
|
|
338
|
+
assert r.writes() == [] and r.github() == before
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
@pytest.mark.parametrize("error", [UPGRADE, {"status": 500, "message": "Server Error"}], ids=["upgrade", "server-error"])
|
|
342
|
+
def test_check_fails_when_github_will_not_say(tmp_path, error):
|
|
343
|
+
r = Repo(tmp_path, private=False, protection=copy.deepcopy(PROTECTION), protection_error=error)
|
|
344
|
+
p = r.setup("jesdi/agent-ops", None, "--check")
|
|
345
|
+
assert p.returncode != 0, p.output
|
|
346
|
+
assert error["message"] in p.stderr and p.stdout == ""
|
|
347
|
+
assert r.writes() == []
|
|
348
|
+
unknown_repo = r.setup("agent-ops", None, "--check") # `gh api repos/agent-ops` fails
|
|
349
|
+
assert unknown_repo.returncode != 0 and unknown_repo.stdout == ""
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"""Acceptance tests: the recorded live runs of the `pr-exam` skill, checked by `pr_exam.py`.
|
|
2
|
+
|
|
3
|
+
Fixture layout the skill ships (ticket 06, Touches `skills/pr-exam/fixtures/`), one live run per mode:
|
|
4
|
+
fixtures/typo-readme/ first: a typo-only README diff
|
|
5
|
+
fixtures/twelve-concepts/ first: a diff with 12 concepts
|
|
6
|
+
fixtures/followup/ followup: the three concepts the attempt of fixtures/grading missed
|
|
7
|
+
fixtures/delta-new-concept/ delta: a push after the pass that adds a retry budget
|
|
8
|
+
fixtures/delta-nothing-new/ delta: a push after the pass that only rewords and renames
|
|
9
|
+
each: request.json, diff.patch, exam.json; the later modes also records/, a delta passed.diff
|
|
10
|
+
fixtures/grading/ request.json, questions.json, answers.json -> grades.json (one grading session),
|
|
11
|
+
and attempt.json: every answer of the attempt, which the host scores
|
|
12
|
+
`request.json` is the session's request; its `diff`, `body`, `records`, `out`, `passed_diff` and `glossary`
|
|
13
|
+
paths are rewritten here to a temp directory, so the fixture's own values are not trusted.
|
|
14
|
+
"""
|
|
15
|
+
import json
|
|
16
|
+
import shutil
|
|
17
|
+
import subprocess
|
|
18
|
+
import sys
|
|
19
|
+
from pathlib import Path
|
|
20
|
+
|
|
21
|
+
import pytest
|
|
22
|
+
|
|
23
|
+
HERE = Path(__file__).parent
|
|
24
|
+
SCRIPT = HERE / "pr_exam.py"
|
|
25
|
+
FIXTURES = HERE / "fixtures"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def fixture(name):
|
|
29
|
+
d = FIXTURES / name
|
|
30
|
+
assert d.is_dir(), f"missing recorded run {d}"
|
|
31
|
+
return d
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def validate(name, tmp_path):
|
|
35
|
+
d = fixture(name)
|
|
36
|
+
request = json.loads((d / "request.json").read_text())
|
|
37
|
+
(tmp_path / "body.md").write_text("body")
|
|
38
|
+
shutil.copy(d / "diff.patch", tmp_path / "diff.patch")
|
|
39
|
+
if (d / "records").is_dir():
|
|
40
|
+
shutil.copytree(d / "records", tmp_path / "records")
|
|
41
|
+
else:
|
|
42
|
+
(tmp_path / "records").mkdir()
|
|
43
|
+
request.update(diff=str(tmp_path / "diff.patch"), body=str(tmp_path / "body.md"),
|
|
44
|
+
records=str(tmp_path / "records"), out=str(d / "exam.json"), glossary=None)
|
|
45
|
+
if "passed_diff" in request:
|
|
46
|
+
request["passed_diff"] = str(d / "passed.diff")
|
|
47
|
+
(tmp_path / "request.json").write_text(json.dumps(request))
|
|
48
|
+
r = subprocess.run([sys.executable, str(SCRIPT), "validate", "--request", str(tmp_path / "request.json"),
|
|
49
|
+
str(d / "exam.json")], capture_output=True, text=True)
|
|
50
|
+
assert r.returncode == 0, r.stderr or r.stdout
|
|
51
|
+
return request, json.loads((d / "exam.json").read_text())
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@pytest.mark.parametrize("name, mode, count", [
|
|
55
|
+
("typo-readme", "first", 1), ("twelve-concepts", "first", 8), ("followup", "followup", 3),
|
|
56
|
+
("delta-new-concept", "delta", 2), ("delta-nothing-new", "delta", 0)])
|
|
57
|
+
def test_recorded_generation_run_validates_with_its_question_count(tmp_path, name, mode, count):
|
|
58
|
+
request, exam = validate(name, tmp_path)
|
|
59
|
+
assert exam["mode"] == request["mode"] == mode
|
|
60
|
+
assert len(exam["questions"]) == count
|
|
61
|
+
if name == "twelve-concepts":
|
|
62
|
+
assert len(exam["concepts"]) >= 12
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def test_the_recorded_followup_asks_each_missed_concept_once_with_a_new_prompt(tmp_path):
|
|
66
|
+
request, exam = validate("followup", tmp_path)
|
|
67
|
+
assert sorted(q["concept"] for q in exam["questions"]) == sorted(request["only_concepts"])
|
|
68
|
+
assert not {q["prompt"] for q in exam["questions"]} & set(request["prior_prompts"])
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def test_the_recorded_delta_with_a_new_concept_lists_nothing_already_passed(tmp_path):
|
|
72
|
+
request, exam = validate("delta-new-concept", tmp_path)
|
|
73
|
+
assert exam["concepts"] and not {c["id"] for c in exam["concepts"]} & set(request["prior_concepts"])
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def test_recorded_grading_run_grades_every_text_question_and_is_accepted_by_score():
|
|
77
|
+
d, exam = fixture("grading"), fixture("twelve-concepts") / "exam.json"
|
|
78
|
+
texts = {q["id"] for q in json.loads(exam.read_text())["questions"] if q["type"] == "text"}
|
|
79
|
+
asked = json.loads((d / "questions.json").read_text())
|
|
80
|
+
assert {q["id"] for q in asked} == set(json.loads((d / "answers.json").read_text())) == texts
|
|
81
|
+
assert set(json.loads((d / "grades.json").read_text())) == texts
|
|
82
|
+
r = subprocess.run([sys.executable, str(SCRIPT), "score", "--exam", str(exam),
|
|
83
|
+
"--answers", str(d / "attempt.json"), "--grades", str(d / "grades.json")],
|
|
84
|
+
capture_output=True, text=True)
|
|
85
|
+
assert r.returncode == 0, r.stderr or r.stdout
|
|
86
|
+
result = json.loads(r.stdout)
|
|
87
|
+
assert result["passed"] is False # the failed attempt the recorded followup answers
|
|
88
|
+
assert result["missed"] == json.loads((fixture("followup") / "request.json").read_text())["only_concepts"]
|
package/skills-manifest.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
|
-
"generatedAt": "2026-11-
|
|
3
|
+
"generatedAt": "2026-11-21T14:15:51.769Z",
|
|
4
4
|
"skills": [
|
|
5
5
|
{
|
|
6
6
|
"name": "agents-wayfinder",
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
},
|
|
11
11
|
{
|
|
12
12
|
"name": "babysit-pr",
|
|
13
|
-
"version": "0.1.
|
|
14
|
-
"hash": "sha256-
|
|
13
|
+
"version": "0.1.7",
|
|
14
|
+
"hash": "sha256-06b245097cbeeab219daa6574a066fe78f5b5d3e82c2b1a8ce34d19f10c80591",
|
|
15
15
|
"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` and a PR URL."
|
|
16
16
|
},
|
|
17
17
|
{
|
|
@@ -62,6 +62,12 @@
|
|
|
62
62
|
"hash": "sha256-6876e448ed0a7697aed064b2e31a6ef683c9966d45e584afcd333b562a7a4e49",
|
|
63
63
|
"description": "Implement a specification in code."
|
|
64
64
|
},
|
|
65
|
+
{
|
|
66
|
+
"name": "pr-exam",
|
|
67
|
+
"version": "0.1.0",
|
|
68
|
+
"hash": "sha256-af12d523a609c4eb220e38af8688600fdb61b69acbb5670f93d121ffeba99ef6",
|
|
69
|
+
"description": "Deterministic rules for a PR exam: validate a generated exam.json against its generation request, project the served (answer-free) exam, score an attempt, read and write learning records, and validate a repo's .pr-exam.json. Use when generating, serving or grading a PR exam, or when the user says \"pr-exam\"."
|
|
70
|
+
},
|
|
65
71
|
{
|
|
66
72
|
"name": "pr-risk",
|
|
67
73
|
"version": "0.1.1",
|