@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,287 @@
1
+ """Acceptance tests: `pr_exam.py score --exam --answers --grades`, run as a subprocess.
2
+
3
+ Spec specs/pr-exam: requirement 6; design.md "Served projection, grades.json, result.json".
4
+ Exam: q1 text on a why concept, q2 text, q3-q5 choice (key answer 1).
5
+ """
6
+ import json
7
+ import subprocess
8
+ import sys
9
+ from pathlib import Path
10
+
11
+ import pytest
12
+
13
+ SCRIPT = Path(__file__).parent / "pr_exam.py"
14
+ SHA = "a" * 40
15
+ CONCEPTS = [("c-why", "why"), ("lease-ownership", "concept"),
16
+ ("head-sha-recheck", "architecture"), ("c-risk", "risk"), ("c-beh", "behaviour")]
17
+ TYPES = ["text", "text", "choice", "choice", "choice"]
18
+
19
+
20
+ def exam():
21
+ qs, key = [], {}
22
+ for i, ((slug, _), t) in enumerate(zip(CONCEPTS, TYPES), 1):
23
+ q = {"id": f"q{i}", "concept": slug, "type": t, "prompt": f"Prompt {i}?"}
24
+ k = {"explanation": f"Explain {i}.", "hunk": f"+hunk {i}"}
25
+ if t == "choice":
26
+ q["options"] = ["alpha beta", "gamma delta", "zeta eta"]
27
+ k["answer"] = 1
28
+ else:
29
+ k["rubric"] = {"pass": "Names it.", "partial": "Mentions it."}
30
+ qs.append(q)
31
+ key[q["id"]] = k
32
+ return {"version": 1, "mode": "first", "repo": "jesdi/general-skills", "pr": 240, "head_sha": SHA,
33
+ "concepts": [{"id": s, "title": s, "kind": k} for s, k in CONCEPTS],
34
+ "questions": qs, "key": key}
35
+
36
+
37
+ def score(tmp_path, right=(3, 4, 5), why="pass", other="partial", answers=None, grades=None):
38
+ """`right`: choice questions answered correctly; the others are answered 0 (wrong)."""
39
+ a = {"q1": "because", "q2": "text", **{f"q{i}": 1 if i in right else 0 for i in (3, 4, 5)}}
40
+ g = {"q1": {"grade": why, "feedback": "f1"}, "q2": {"grade": other, "feedback": "f2"}}
41
+ a = a if answers is None else answers
42
+ g = g if grades is None else grades
43
+ for name, data in (("exam", exam()), ("answers", a), ("grades", g)):
44
+ (tmp_path / f"{name}.json").write_text(json.dumps(data))
45
+ return subprocess.run([sys.executable, str(SCRIPT), "score", "--exam", str(tmp_path / "exam.json"),
46
+ "--answers", str(tmp_path / "answers.json"), "--grades", str(tmp_path / "grades.json")],
47
+ capture_output=True, text=True)
48
+
49
+
50
+ def ok(r):
51
+ assert r.returncode == 0, (r.returncode, r.stdout, r.stderr)
52
+ return json.loads(r.stdout)
53
+
54
+
55
+ def refused(r, *words):
56
+ assert r.returncode == 1, (r.returncode, r.stdout, r.stderr)
57
+ for w in words:
58
+ assert w in r.stderr, (w, r.stderr)
59
+
60
+
61
+ def test_pass_at_90_percent(tmp_path):
62
+ res = ok(score(tmp_path))
63
+ assert (res["score"], res["max"], res["passed"]) == (4.5, 5, True)
64
+
65
+
66
+ def test_pass_at_exactly_80_percent(tmp_path):
67
+ res = ok(score(tmp_path, other="fail"))
68
+ assert (res["score"], res["passed"]) == (4, True)
69
+
70
+
71
+ def test_fail_at_70_percent(tmp_path):
72
+ res = ok(score(tmp_path, right=(3, 4), why="pass", other="partial"))
73
+ assert (res["score"], res["passed"]) == (3.5, False)
74
+
75
+
76
+ def test_fail_when_why_is_partial_above_80_percent(tmp_path):
77
+ res = ok(score(tmp_path, why="partial", other="pass"))
78
+ assert (res["score"], res["passed"]) == (4.5, False)
79
+
80
+
81
+ def test_points_per_question(tmp_path):
82
+ res = ok(score(tmp_path, right=(3,), why="partial", other="fail"))
83
+ assert {q["id"]: q["points"] for q in res["questions"]} == {"q1": 0.5, "q2": 0, "q3": 1, "q4": 0, "q5": 0}
84
+
85
+
86
+ def test_full_points_carry_no_explanation(tmp_path):
87
+ res = ok(score(tmp_path, right=(3, 5), why="pass", other="pass"))
88
+ assert res["missed"] == ["c-risk"]
89
+ qs = {q["id"]: q for q in res["questions"]}
90
+ for qid in ("q1", "q2", "q3", "q5"):
91
+ assert "explanation" not in qs[qid] and "hunk" not in qs[qid]
92
+ assert (qs["q4"]["explanation"], qs["q4"]["hunk"]) == ("Explain 4.", "+hunk 4")
93
+
94
+
95
+ def test_two_named_misses(tmp_path):
96
+ # q2 (lease-ownership) failed, q3 (head-sha-recheck) wrong; everything else right.
97
+ res = ok(score(tmp_path, right=(4, 5), why="pass", other="fail"))
98
+ assert sorted(res["missed"]) == ["head-sha-recheck", "lease-ownership"]
99
+ qs = {q["id"]: q for q in res["questions"]}
100
+ for qid, n in (("q2", 2), ("q3", 3)):
101
+ assert (qs[qid]["explanation"], qs[qid]["hunk"]) == (f"Explain {n}.", f"+hunk {n}")
102
+ for qid in ("q1", "q4", "q5"):
103
+ assert "explanation" not in qs[qid] and "hunk" not in qs[qid]
104
+
105
+
106
+ def test_refuse_unanswered_question(tmp_path):
107
+ a = {"q1": "x", "q2": "y", "q3": 1, "q4": 1}
108
+ refused(score(tmp_path, answers=a), "q5")
109
+
110
+
111
+ def test_refuse_grade_for_choice_question(tmp_path):
112
+ g = {"q1": {"grade": "pass", "feedback": "f"}, "q2": {"grade": "pass", "feedback": "f"},
113
+ "q3": {"grade": "pass", "feedback": "f"}}
114
+ refused(score(tmp_path, grades=g), "q3")
115
+
116
+
117
+ def test_refuse_text_question_without_grade(tmp_path):
118
+ refused(score(tmp_path, grades={"q1": {"grade": "pass", "feedback": "f"}}), "q2")
119
+
120
+
121
+ def test_refuse_unknown_grade(tmp_path):
122
+ g = {"q1": {"grade": "excellent", "feedback": "f"}, "q2": {"grade": "pass", "feedback": "f"}}
123
+ refused(score(tmp_path, grades=g), "q1", "excellent")
124
+
125
+
126
+ # --- spec specs/pr-exam-assist: requirements 5-8 (bypassed and assisted questions) ---
127
+ # Optional --flags reads {"bypassed": [qid, ...], "assisted": [qid, ...]}.
128
+ # Omitted keys mean no flags; output questions use help="bypassed" or "assisted".
129
+ # Exam: q1-q3 choice (key answer 1), q4 text on the why concept, q5 and q6 text.
130
+ ASSIST_CONCEPTS = [("merge-lease", "concept"), ("retry-budget", "concept"), ("head-recheck", "architecture"),
131
+ ("lease-owner", "why"), ("fencing-token", "concept"), ("stale-lease", "concept")]
132
+
133
+
134
+ def assist_exam(n=6):
135
+ qs, key = [], {}
136
+ for i, (slug, _) in enumerate(ASSIST_CONCEPTS[:n], 1):
137
+ t = "choice" if i <= 3 else "text"
138
+ q = {"id": f"q{i}", "concept": slug, "type": t, "prompt": f"Prompt {i}?"}
139
+ k = {"explanation": f"Explain {i}.", "hunk": f"+hunk {i}"}
140
+ if t == "choice":
141
+ q["options"] = ["alpha beta", "gamma delta", "zeta eta"]
142
+ k["answer"] = 1
143
+ else:
144
+ k["rubric"] = {"pass": "Names it.", "partial": "Mentions it."}
145
+ qs.append(q)
146
+ key[q["id"]] = k
147
+ concepts = [{"id": s, "title": s, "kind": k} for s, k in ASSIST_CONCEPTS[:n]]
148
+ if n == 1:
149
+ concepts = [{"id": "readme-typo", "title": "README typo", "kind": "behaviour"}]
150
+ qs[0].update(concept="readme-typo", prompt="Which word did the README correct?",
151
+ options=["merge lease", "retry budget", "fencing token"])
152
+ key["q1"].update(explanation="The README now spells retry budget correctly.",
153
+ hunk="-retry buget\n+retry budget")
154
+ return {"version": 1, "mode": "first", "repo": "jesdi/general-skills", "pr": 240, "head_sha": SHA,
155
+ "concepts": concepts, "questions": qs, "key": key}
156
+
157
+
158
+ def flagged(tmp_path, flags, wrong=(), grades=None, skip=(), n=6):
159
+ """Everything full points except `wrong` choice ids (answered 0) and `grades` overrides.
160
+ Questions in `skip` get neither an answer nor a grade."""
161
+ g = {"q4": "pass", "q5": "pass", "q6": "pass", **(grades or {})}
162
+ a = {f"q{i}": (0 if f"q{i}" in wrong else 1) for i in (1, 2, 3)}
163
+ a.update({"q4": "t", "q5": "t", "q6": "t"})
164
+ ans = {k: v for k, v in a.items() if k in {f"q{i}" for i in range(1, n + 1)} and k not in skip}
165
+ grs = {k: {"grade": v, "feedback": "f"} for k, v in g.items()
166
+ if k in {f"q{i}" for i in range(1, n + 1)} and k not in skip}
167
+ files = {"exam": assist_exam(n), "answers": ans, "grades": grs}
168
+ if flags is not None:
169
+ files["flags"] = flags
170
+ for name, data in files.items():
171
+ (tmp_path / f"{name}.json").write_text(json.dumps(data))
172
+ cmd = [sys.executable, str(SCRIPT), "score", "--exam", str(tmp_path / "exam.json"),
173
+ "--answers", str(tmp_path / "answers.json"), "--grades", str(tmp_path / "grades.json")]
174
+ if flags is not None:
175
+ cmd += ["--flags", str(tmp_path / "flags.json")]
176
+ return subprocess.run(cmd, capture_output=True, text=True)
177
+
178
+
179
+ def by_id(res):
180
+ return {q["id"]: q for q in res["questions"]}
181
+
182
+
183
+ def test_bypassed_question_leaves_the_score(tmp_path):
184
+ res = ok(flagged(tmp_path, {"bypassed": ["q6"]}, skip=("q6",)))
185
+ assert (res["score"], res["max"], res["passed"]) == (5, 5, True)
186
+ assert by_id(res)["q6"]["help"] == "bypassed"
187
+ assert "stale-lease" not in res["missed"]
188
+ assert "points" not in by_id(res)["q6"]
189
+
190
+
191
+ def test_exactly_80_percent_of_not_bypassed_passes(tmp_path):
192
+ res = ok(flagged(tmp_path, {"bypassed": ["q6"]}, wrong=("q1",), skip=("q6",)))
193
+ assert (res["score"], res["max"], res["passed"]) == (4, 5, True)
194
+
195
+
196
+ def test_under_80_percent_of_not_bypassed_fails(tmp_path):
197
+ res = ok(flagged(tmp_path, {"bypassed": ["q6"]}, wrong=("q1",), grades={"q5": "partial"}, skip=("q6",)))
198
+ assert (res["score"], res["max"], res["passed"]) == (3.5, 5, False)
199
+ assert sorted(res["missed"]) == ["fencing-token", "merge-lease"]
200
+
201
+
202
+ def test_bypassed_why_question_does_not_fail_the_attempt(tmp_path):
203
+ res = ok(flagged(tmp_path, {"bypassed": ["q4"]}, skip=("q4",)))
204
+ assert (res["score"], res["max"], res["passed"]) == (5, 5, True)
205
+ assert "lease-owner" not in res["missed"]
206
+
207
+
208
+ def test_two_bypasses_are_refused(tmp_path):
209
+ r = flagged(tmp_path, {"bypassed": ["q2", "q6"]})
210
+ refused(r, "q2", "q6")
211
+ assert r.stdout == ""
212
+
213
+
214
+ def test_answer_to_bypassed_question_is_ignored(tmp_path):
215
+ res = ok(flagged(tmp_path, {"bypassed": ["q2"]}, wrong=("q2",)))
216
+ q2 = by_id(res)["q2"]
217
+ assert (res["score"], res["max"]) == (5, 5)
218
+ assert q2["help"] == "bypassed" and "points" not in q2
219
+
220
+
221
+ def test_bypassed_question_carries_explanation_and_hunk(tmp_path):
222
+ q6 = by_id(ok(flagged(tmp_path, {"bypassed": ["q6"]}, skip=("q6",))))["q6"]
223
+ assert (q6["explanation"], q6["hunk"]) == ("Explain 6.", "+hunk 6")
224
+
225
+
226
+ def test_assisted_question_scores_as_usual(tmp_path):
227
+ res = ok(flagged(tmp_path, {"assisted": ["q2"]}))
228
+ q2 = by_id(res)["q2"]
229
+ assert (q2["points"], q2["help"]) == (1, "assisted")
230
+ assert (res["score"], res["max"]) == (6, 6)
231
+
232
+
233
+ def test_bypass_outranks_assisted(tmp_path):
234
+ q6 = by_id(ok(flagged(tmp_path, {"bypassed": ["q6"], "assisted": ["q6"]}, skip=("q6",))))["q6"]
235
+ assert q6["help"] == "bypassed"
236
+
237
+
238
+ def test_bypassing_the_only_question_passes(tmp_path):
239
+ res = ok(flagged(tmp_path, {"bypassed": ["q1"]}, skip=("q1",), n=1))
240
+ assert (res["score"], res["max"], res["passed"]) == (0, 0, True)
241
+
242
+
243
+ @pytest.mark.parametrize("flag", ["assisted", "bypassed"])
244
+ def test_flags_with_unknown_question_are_refused(tmp_path, flag):
245
+ result = flagged(tmp_path, {flag: ["q9"]})
246
+ refused(result, "q9")
247
+ assert result.stdout == ""
248
+
249
+
250
+ def test_flags_with_unknown_key_are_refused(tmp_path):
251
+ result = flagged(tmp_path, {"skipped": ["q1"]})
252
+ refused(result, "skipped")
253
+ assert result.stdout == ""
254
+
255
+
256
+
257
+ @pytest.mark.parametrize("grades,bypassed", [
258
+ ({"q6": "fail"}, "q6"),
259
+ ({"q6": "excellent"}, "q6"),
260
+ ({"q2": "pass"}, "q2"),
261
+ ])
262
+ def test_grade_for_bypassed_question_is_ignored(tmp_path, grades, bypassed):
263
+ res = ok(flagged(tmp_path, {"bypassed": [bypassed]}, grades=grades))
264
+ assert (res["score"], res["max"], res["passed"]) == (5, 5, True)
265
+ assert "stale-lease" not in res["missed"]
266
+ assert by_id(res)[bypassed]["help"] == "bypassed"
267
+ assert "points" not in by_id(res)[bypassed]
268
+ assert res["missed"] == []
269
+
270
+
271
+ def test_flags_are_never_inferred_without_the_flags_file(tmp_path):
272
+ """A follow-up exam reuses ids: stale flag data elsewhere must not mark q6 bypassed."""
273
+ baseline = flagged(tmp_path, None)
274
+ ok(baseline)
275
+ exam_data = json.loads((tmp_path / "exam.json").read_text())
276
+ exam_data["mode"] = "followup"
277
+ exam_data["flags"] = {"bypassed": ["q6"], "assisted": ["q2"]}
278
+ exam_data["questions"][5]["help"] = "bypassed"
279
+ (tmp_path / "exam.json").write_text(json.dumps(exam_data))
280
+ (tmp_path / "flags.json").write_text(json.dumps({"bypassed": ["q6"], "assisted": ["q2"]}))
281
+ r = subprocess.run([sys.executable, str(SCRIPT), "score", "--exam", str(tmp_path / "exam.json"),
282
+ "--answers", str(tmp_path / "answers.json"), "--grades", str(tmp_path / "grades.json")],
283
+ capture_output=True, text=True)
284
+ res = ok(r)
285
+ assert (res["score"], res["max"]) == (6, 6)
286
+ assert all("help" not in q for q in res["questions"])
287
+ assert r.stdout == baseline.stdout
@@ -0,0 +1,38 @@
1
+ """Regression tests: nothing answer-like rides on a served field, and concept ids are slugs.
2
+
3
+ `public` and `validate` refuse an exam whose served fields (`version`, `repo`, `pr`, `head_sha`,
4
+ question `type`) are not their plain shapes, and `validate` refuses a concept id that is not a slug.
5
+ Spec specs/pr-exam: requirement 2; design.md "exam.json" (concept `id`: slug).
6
+ """
7
+ import pytest
8
+
9
+ from test_exam_format import five, refused, run
10
+
11
+ SECRET = {"answer": 1, "rubric": {"pass": "x", "partial": "y"}}
12
+
13
+
14
+ @pytest.mark.parametrize("command", ["validate", "public"])
15
+ def test_question_type_holding_an_object_is_refused(tmp_path, command):
16
+ exam = five()
17
+ exam["questions"][2]["type"] = SECRET
18
+ r = run(tmp_path, exam, command=command)
19
+ refused(r, "q3", "type")
20
+ assert "rubric" not in r.stdout
21
+
22
+
23
+ @pytest.mark.parametrize("field", ["repo", "pr", "head_sha", "version"])
24
+ @pytest.mark.parametrize("command", ["validate", "public"])
25
+ def test_envelope_field_holding_an_object_is_refused_even_when_the_request_mirrors_it(tmp_path, field, command):
26
+ exam = five()
27
+ exam[field] = SECRET
28
+ r = run(tmp_path, exam, {field: SECRET}, command=command)
29
+ refused(r, field)
30
+ assert "rubric" not in r.stdout
31
+
32
+
33
+ @pytest.mark.parametrize("bad", ["../escape", "Merge-Lease", "two\nlines", "", 7])
34
+ def test_concept_id_that_is_not_a_slug_is_refused(tmp_path, bad):
35
+ exam = five()
36
+ exam["concepts"][4]["id"] = bad
37
+ exam["questions"][4]["concept"] = bad
38
+ refused(run(tmp_path, exam), "slug")