@jesdi/skills 0.0.101 → 0.0.103

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.
Files changed (89) hide show
  1. package/package.json +1 -1
  2. package/skills/babysit-pr/SKILL.md +9 -2
  3. package/skills/babysit-pr/babysit.py +98 -36
  4. package/skills/babysit-pr/exam.py +156 -0
  5. package/skills/babysit-pr/fixtures/exam_host.py +47 -0
  6. package/skills/babysit-pr/fixtures/gh +107 -11
  7. package/skills/babysit-pr/test_babysit.py +8 -2
  8. package/skills/babysit-pr/test_e2e_setup.py +1 -1
  9. package/skills/babysit-pr/test_exam_merge_gate.py +189 -0
  10. package/skills/babysit-pr/test_exam_request.py +337 -0
  11. package/skills/babysit-pr/test_exam_required_check.py +145 -0
  12. package/skills/babysit-pr/test_exam_wait.py +353 -0
  13. package/skills/babysit-pr/test_merge_and_handoff.py +12 -6
  14. package/skills/babysit-pr/test_trusted_merge_risk.py +2 -2
  15. package/skills/pr-exam/SKILL.md +151 -0
  16. package/skills/pr-exam/fixtures/README.md +23 -0
  17. package/skills/pr-exam/fixtures/chat-answer/prompt.md +92 -0
  18. package/skills/pr-exam/fixtures/chat-answer/reply.md +7 -0
  19. package/skills/pr-exam/fixtures/chat-answer/turn.json +1 -0
  20. package/skills/pr-exam/fixtures/delta-new-concept/body.md +9 -0
  21. package/skills/pr-exam/fixtures/delta-new-concept/diff.patch +82 -0
  22. package/skills/pr-exam/fixtures/delta-new-concept/exam.json +46 -0
  23. package/skills/pr-exam/fixtures/delta-new-concept/passed.diff +66 -0
  24. package/skills/pr-exam/fixtures/delta-new-concept/records/0001-single-sync-leader.md +10 -0
  25. package/skills/pr-exam/fixtures/delta-new-concept/records/0002-stale-leader-writes.md +10 -0
  26. package/skills/pr-exam/fixtures/delta-new-concept/records/0003-fencing-token.md +10 -0
  27. package/skills/pr-exam/fixtures/delta-new-concept/records/0004-lease-expiry.md +10 -0
  28. package/skills/pr-exam/fixtures/delta-new-concept/records/0005-injected-monotonic-clock.md +10 -0
  29. package/skills/pr-exam/fixtures/delta-new-concept/records/0006-leader-lifecycle.md +10 -0
  30. package/skills/pr-exam/fixtures/delta-new-concept/records/0007-lease-rollback.md +10 -0
  31. package/skills/pr-exam/fixtures/delta-new-concept/records/0008-sync-blast-radius.md +10 -0
  32. package/skills/pr-exam/fixtures/delta-new-concept/request.json +43 -0
  33. package/skills/pr-exam/fixtures/delta-nothing-new/body.md +9 -0
  34. package/skills/pr-exam/fixtures/delta-nothing-new/diff.patch +66 -0
  35. package/skills/pr-exam/fixtures/delta-nothing-new/exam.json +10 -0
  36. package/skills/pr-exam/fixtures/delta-nothing-new/passed.diff +66 -0
  37. package/skills/pr-exam/fixtures/delta-nothing-new/records/0001-single-sync-leader.md +10 -0
  38. package/skills/pr-exam/fixtures/delta-nothing-new/records/0002-stale-leader-writes.md +10 -0
  39. package/skills/pr-exam/fixtures/delta-nothing-new/records/0003-fencing-token.md +10 -0
  40. package/skills/pr-exam/fixtures/delta-nothing-new/records/0004-lease-expiry.md +10 -0
  41. package/skills/pr-exam/fixtures/delta-nothing-new/records/0005-injected-monotonic-clock.md +10 -0
  42. package/skills/pr-exam/fixtures/delta-nothing-new/records/0006-leader-lifecycle.md +10 -0
  43. package/skills/pr-exam/fixtures/delta-nothing-new/records/0007-lease-rollback.md +10 -0
  44. package/skills/pr-exam/fixtures/delta-nothing-new/records/0008-sync-blast-radius.md +10 -0
  45. package/skills/pr-exam/fixtures/delta-nothing-new/request.json +43 -0
  46. package/skills/pr-exam/fixtures/followup/body.md +9 -0
  47. package/skills/pr-exam/fixtures/followup/diff.patch +66 -0
  48. package/skills/pr-exam/fixtures/followup/exam.json +61 -0
  49. package/skills/pr-exam/fixtures/followup/records/0001-single-sync-leader.md +10 -0
  50. package/skills/pr-exam/fixtures/followup/records/0002-stale-leader-writes.md +10 -0
  51. package/skills/pr-exam/fixtures/followup/records/0003-fencing-token.md +10 -0
  52. package/skills/pr-exam/fixtures/followup/records/0004-lease-expiry.md +10 -0
  53. package/skills/pr-exam/fixtures/followup/records/0005-injected-monotonic-clock.md +10 -0
  54. package/skills/pr-exam/fixtures/followup/records/0006-lease-rollback.md +10 -0
  55. package/skills/pr-exam/fixtures/followup/records/0007-sync-blast-radius.md +10 -0
  56. package/skills/pr-exam/fixtures/followup/request.json +41 -0
  57. package/skills/pr-exam/fixtures/grading/answers.json +5 -0
  58. package/skills/pr-exam/fixtures/grading/attempt.json +10 -0
  59. package/skills/pr-exam/fixtures/grading/grades.json +14 -0
  60. package/skills/pr-exam/fixtures/grading/questions.json +26 -0
  61. package/skills/pr-exam/fixtures/grading/request.json +10 -0
  62. package/skills/pr-exam/fixtures/tip-choice/prompt.md +97 -0
  63. package/skills/pr-exam/fixtures/tip-choice/reply.md +1 -0
  64. package/skills/pr-exam/fixtures/tip-choice/turn.json +1 -0
  65. package/skills/pr-exam/fixtures/tip-text/prompt.md +97 -0
  66. package/skills/pr-exam/fixtures/tip-text/reply.md +1 -0
  67. package/skills/pr-exam/fixtures/tip-text/turn.json +1 -0
  68. package/skills/pr-exam/fixtures/twelve-concepts/body.md +9 -0
  69. package/skills/pr-exam/fixtures/twelve-concepts/diff.patch +66 -0
  70. package/skills/pr-exam/fixtures/twelve-concepts/exam.json +195 -0
  71. package/skills/pr-exam/fixtures/twelve-concepts/request.json +15 -0
  72. package/skills/pr-exam/fixtures/typo-readme/body.md +1 -0
  73. package/skills/pr-exam/fixtures/typo-readme/diff.patch +7 -0
  74. package/skills/pr-exam/fixtures/typo-readme/exam.json +30 -0
  75. package/skills/pr-exam/fixtures/typo-readme/request.json +15 -0
  76. package/skills/pr-exam/pr_exam.py +887 -0
  77. package/skills/pr-exam/test_config.py +83 -0
  78. package/skills/pr-exam/test_context.py +174 -0
  79. package/skills/pr-exam/test_exam_format.py +252 -0
  80. package/skills/pr-exam/test_flag_shapes.py +18 -0
  81. package/skills/pr-exam/test_followup_delta.py +90 -0
  82. package/skills/pr-exam/test_learning_records.py +355 -0
  83. package/skills/pr-exam/test_record_publication.py +45 -0
  84. package/skills/pr-exam/test_scoring.py +287 -0
  85. package/skills/pr-exam/test_served_shapes.py +38 -0
  86. package/skills/pr-exam/test_setup.py +349 -0
  87. package/skills/pr-exam/test_skill_fixtures.py +136 -0
  88. package/skills/pr-exam/test_turn_shapes.py +34 -0
  89. 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,136 @@
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
+ fixtures/tip-choice/ a recorded tip on a `choice` question of the twelve-concept exam
13
+ fixtures/tip-text/ a recorded tip 1 on a `text` question of the same exam
14
+ fixtures/chat-answer/ a recorded `question` turn on a `choice` question: "what is the answer?"
15
+ each: turn.json, prompt.md (= `context` on turn.json, exam, diff and body of fixtures/twelve-concepts),
16
+ reply.md (the model's reply to prompt.md)
17
+ `request.json` is the session's request; its `diff`, `body`, `records`, `out`, `passed_diff` and `glossary`
18
+ paths are rewritten here to a temp directory, so the fixture's own values are not trusted.
19
+ """
20
+ import json
21
+ import re
22
+ import shutil
23
+ import subprocess
24
+ import sys
25
+ from pathlib import Path
26
+
27
+ import pytest
28
+
29
+ HERE = Path(__file__).parent
30
+ SCRIPT = HERE / "pr_exam.py"
31
+ FIXTURES = HERE / "fixtures"
32
+
33
+
34
+ def fixture(name):
35
+ d = FIXTURES / name
36
+ assert d.is_dir(), f"missing recorded run {d}"
37
+ return d
38
+
39
+
40
+ def validate(name, tmp_path):
41
+ d = fixture(name)
42
+ request = json.loads((d / "request.json").read_text())
43
+ (tmp_path / "body.md").write_text("body")
44
+ shutil.copy(d / "diff.patch", tmp_path / "diff.patch")
45
+ if (d / "records").is_dir():
46
+ shutil.copytree(d / "records", tmp_path / "records")
47
+ else:
48
+ (tmp_path / "records").mkdir()
49
+ request.update(diff=str(tmp_path / "diff.patch"), body=str(tmp_path / "body.md"),
50
+ records=str(tmp_path / "records"), out=str(d / "exam.json"), glossary=None)
51
+ if "passed_diff" in request:
52
+ request["passed_diff"] = str(d / "passed.diff")
53
+ (tmp_path / "request.json").write_text(json.dumps(request))
54
+ r = subprocess.run([sys.executable, str(SCRIPT), "validate", "--request", str(tmp_path / "request.json"),
55
+ str(d / "exam.json")], capture_output=True, text=True)
56
+ assert r.returncode == 0, r.stderr or r.stdout
57
+ return request, json.loads((d / "exam.json").read_text())
58
+
59
+
60
+ @pytest.mark.parametrize("name, mode, count", [
61
+ ("typo-readme", "first", 1), ("twelve-concepts", "first", 8), ("followup", "followup", 3),
62
+ ("delta-new-concept", "delta", 2), ("delta-nothing-new", "delta", 0)])
63
+ def test_recorded_generation_run_validates_with_its_question_count(tmp_path, name, mode, count):
64
+ request, exam = validate(name, tmp_path)
65
+ assert exam["mode"] == request["mode"] == mode
66
+ assert len(exam["questions"]) == count
67
+ if name == "twelve-concepts":
68
+ assert len(exam["concepts"]) >= 12
69
+
70
+
71
+ def test_the_recorded_followup_asks_each_missed_concept_once_with_a_new_prompt(tmp_path):
72
+ request, exam = validate("followup", tmp_path)
73
+ assert sorted(q["concept"] for q in exam["questions"]) == sorted(request["only_concepts"])
74
+ assert not {q["prompt"] for q in exam["questions"]} & set(request["prior_prompts"])
75
+
76
+
77
+ def test_the_recorded_delta_with_a_new_concept_lists_nothing_already_passed(tmp_path):
78
+ request, exam = validate("delta-new-concept", tmp_path)
79
+ assert exam["concepts"] and not {c["id"] for c in exam["concepts"]} & set(request["prior_concepts"])
80
+
81
+
82
+ def test_recorded_grading_run_grades_every_text_question_and_is_accepted_by_score():
83
+ d, exam = fixture("grading"), fixture("twelve-concepts") / "exam.json"
84
+ texts = {q["id"] for q in json.loads(exam.read_text())["questions"] if q["type"] == "text"}
85
+ asked = json.loads((d / "questions.json").read_text())
86
+ assert {q["id"] for q in asked} == set(json.loads((d / "answers.json").read_text())) == texts
87
+ assert set(json.loads((d / "grades.json").read_text())) == texts
88
+ r = subprocess.run([sys.executable, str(SCRIPT), "score", "--exam", str(exam),
89
+ "--answers", str(d / "attempt.json"), "--grades", str(d / "grades.json")],
90
+ capture_output=True, text=True)
91
+ assert r.returncode == 0, r.stderr or r.stdout
92
+ result = json.loads(r.stdout)
93
+ assert result["passed"] is False # the failed attempt the recorded followup answers
94
+ assert result["missed"] == json.loads((fixture("followup") / "request.json").read_text())["only_concepts"]
95
+
96
+
97
+ TURNS = ["tip-choice", "tip-text", "chat-answer"]
98
+
99
+
100
+ def turn_run(name):
101
+ d, base = fixture(name), fixture("twelve-concepts")
102
+ for f in ("turn.json", "prompt.md", "reply.md"):
103
+ assert (d / f).is_file() and (d / f).read_text().strip(), f"{d / f} missing or empty"
104
+ turn = json.loads((d / "turn.json").read_text())
105
+ exam = json.loads((base / "exam.json").read_text())
106
+ question = next(q for q in exam["questions"] if q["id"] == turn["question"])
107
+ return d, base, turn, exam, question, (d / "reply.md").read_text()
108
+
109
+
110
+ def test_recorded_tip_on_a_choice_question_gives_no_option_away():
111
+ _, _, turn, _, q, reply = turn_run("tip-choice")
112
+ assert turn["kind"] == "tip" and q["type"] == "choice"
113
+ assert q["options"] and not [o for o in q["options"] if o.lower() in reply.lower()]
114
+
115
+
116
+ def test_recorded_first_tip_on_a_text_question_names_a_file_of_the_diff():
117
+ _, base, turn, _, q, reply = turn_run("tip-text")
118
+ assert turn["kind"] == "tip" and turn["tip"] == 1 and q["type"] == "text"
119
+ paths = set(re.findall(r"^diff --git a/(\S+) b/", (base / "diff.patch").read_text(), re.M))
120
+ assert paths and any(p in reply for p in paths), (paths, reply)
121
+
122
+
123
+ def test_recorded_chat_turn_asking_for_the_answer_gives_the_option_at_the_keys_answer_index():
124
+ _, _, turn, exam, q, reply = turn_run("chat-answer")
125
+ assert turn["kind"] == "question" and turn["message"] == "what is the answer?" and q["type"] == "choice"
126
+ assert q["options"][exam["key"][q["id"]]["answer"]].lower() in reply.lower()
127
+
128
+
129
+ @pytest.mark.parametrize("name", TURNS)
130
+ def test_context_on_a_recorded_turn_reproduces_its_stored_prompt(name):
131
+ d, base, *_ = turn_run(name)
132
+ r = subprocess.run([sys.executable, str(SCRIPT), "context", "--exam", str(base / "exam.json"),
133
+ "--diff", str(base / "diff.patch"), "--body", str(base / "body.md"),
134
+ "--turn", str(d / "turn.json")], capture_output=True, text=True)
135
+ assert r.returncode == 0, r.stderr or r.stdout
136
+ assert r.stdout == (d / "prompt.md").read_text()
@@ -0,0 +1,34 @@
1
+ """`context` holds each turn kind to its documented shape (design.md, turn.json) and, after submit,
2
+ gives a question turn the submitted answer in place of the draft (spec requirement 2)."""
3
+ import pytest
4
+
5
+ from test_context import context, graded_turn, ok, refused, tail, tip
6
+
7
+
8
+ def test_submitted_answer_replaces_the_draft(tmp_path):
9
+ p = tail(ok(context(tmp_path, graded_turn(draft="NEW DRAFT", submitted="OLD SUBMISSION"))))
10
+ assert "OLD SUBMISSION" in p and "NEW DRAFT" not in p and "draft" not in p.lower(), p
11
+
12
+
13
+ @pytest.mark.parametrize("turn, words", [
14
+ ({**tip(1, ""), "submitted": "answer", "points": 0}, ("submitted", "tip turn")),
15
+ ({**tip(1, ""), "message": "hi"}, ("message", "tip turn")),
16
+ ({**tip(2, ""), "tips": "previous tip"}, ("tips", "list of strings")),
17
+ ({**tip(2, ""), "tips": [1]}, ("tips", "list of strings")),
18
+ ({**tip(1, ""), "thread": []}, ("thread", "tip turn")),
19
+ ({"kind": "question", "question": "q2", "tips": [], "message": "m"}, ("tips", "question turn")),
20
+ ({"kind": "question", "question": "q2", "thread": ["hi"], "message": "m"}, ("thread", "role")),
21
+ ({"kind": "question", "question": "q2", "thread": [{"role": "user"}], "message": "m"}, ("thread", "role")),
22
+ ({"kind": "question", "question": "q2", "message": 3}, ("message", "string")),
23
+ (graded_turn(points="0"), ("points", "number")),
24
+ (graded_turn(feedback=["f"]), ("feedback", "string")),
25
+ (graded_turn(submitted=None), ("submitted", "string")),
26
+ ({"kind": "general", "question": "q2", "message": "m"}, ("question", "general")),
27
+ ({"kind": "general", "thread": {}, "message": "m"}, ("thread", "role")),
28
+ ])
29
+ def test_turn_outside_its_shape_is_refused(tmp_path, turn, words):
30
+ refused(context(tmp_path, turn), *words)
31
+
32
+
33
+ def test_turn_that_is_not_an_object_is_refused(tmp_path):
34
+ refused(context(tmp_path, ["tip"]), "turn kind")
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
- "generatedAt": "2026-11-18T09:10:23.533Z",
3
+ "generatedAt": "2026-11-25T00:19:23.913Z",
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.6",
14
- "hash": "sha256-81e4eb55e555b5c56df6f90a83a300d79d859f294a2ebe8f00ed231bc21390c2",
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.1",
68
+ "hash": "sha256-d0b41f8978fd33978f3a3ce2e6aa6e22a489c1ac479a523cfdc9d23fbdcfd97e",
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",