@jesdi/skills 0.0.100 → 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/implement-spec/ARCHITECTURE.md +1 -1
- package/skills/implement-spec/README.md +6 -6
- package/skills/implement-spec/driver_final.py +24 -21
- package/skills/implement-spec/driver_final_gate.py +152 -17
- package/skills/implement-spec/driver_gate.py +12 -0
- package/skills/implement-spec/driver_pr.py +16 -7
- package/skills/implement-spec/driver_slots.py +28 -11
- package/skills/implement-spec/driver_state.py +3 -2
- package/skills/implement-spec/prompts/pr-body.md +1 -0
- package/skills/implement-spec/tests/test_final_gate.py +144 -0
- package/skills/implement-spec/tests/test_overturn.py +2 -2
- package/skills/implement-spec/tests/test_walk.py +1 -0
- 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 +11 -5
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"""Acceptance tests: `pr_exam.py config [<path>]`, run as a subprocess.
|
|
2
|
+
|
|
3
|
+
Spec specs/pr-exam: requirement 9, scenario "an invalid config stops the run".
|
|
4
|
+
"""
|
|
5
|
+
import json
|
|
6
|
+
import subprocess
|
|
7
|
+
import sys
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
SCRIPT = Path(__file__).parent / "pr_exam.py"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def run(*args, cwd=None):
|
|
14
|
+
return subprocess.run([sys.executable, str(SCRIPT), "config", *map(str, args)],
|
|
15
|
+
capture_output=True, text=True, cwd=cwd)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def cfg(tmp_path, content):
|
|
19
|
+
f = tmp_path / ".pr-exam.json"
|
|
20
|
+
f.write_text(content if isinstance(content, str) else json.dumps(content))
|
|
21
|
+
return run(f)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def refused(r):
|
|
25
|
+
assert r.returncode != 0
|
|
26
|
+
assert r.stdout.strip() == ""
|
|
27
|
+
return r.stdout + r.stderr
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def test_no_file_prints_defaults(tmp_path):
|
|
31
|
+
r = run(tmp_path / "missing.json")
|
|
32
|
+
assert r.returncode == 0, r.stderr
|
|
33
|
+
assert json.loads(r.stdout) == {"enabled": True, "bypassLabels": {}}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def test_no_path_prints_defaults(tmp_path):
|
|
37
|
+
r = run(cwd=tmp_path)
|
|
38
|
+
assert r.returncode == 0, r.stderr
|
|
39
|
+
assert json.loads(r.stdout) == {"enabled": True, "bypassLabels": {}}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def test_enabled_false(tmp_path):
|
|
43
|
+
r = cfg(tmp_path, {"enabled": False})
|
|
44
|
+
assert r.returncode == 0, r.stderr
|
|
45
|
+
assert json.loads(r.stdout) == {"enabled": False, "bypassLabels": {}}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def test_bypass_labels(tmp_path):
|
|
49
|
+
labels = {"exam:skip": "skip", "exam:defer": "defer"}
|
|
50
|
+
r = cfg(tmp_path, {"bypassLabels": labels})
|
|
51
|
+
assert r.returncode == 0, r.stderr
|
|
52
|
+
assert json.loads(r.stdout) == {"enabled": True, "bypassLabels": labels}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def test_invalid_bypass_mode(tmp_path):
|
|
56
|
+
out = refused(cfg(tmp_path, {"bypassLabels": {"exam:skip": "maybe"}}))
|
|
57
|
+
for word in ("bypassLabels", "exam:skip", "skip", "defer"):
|
|
58
|
+
assert word in out
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def test_non_boolean_enabled(tmp_path):
|
|
62
|
+
assert "enabled" in refused(cfg(tmp_path, {"enabled": "yes"}))
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def test_unknown_key(tmp_path):
|
|
66
|
+
assert "colour" in refused(cfg(tmp_path, {"colour": 1}))
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def test_invalid_json(tmp_path):
|
|
70
|
+
assert "json" in refused(cfg(tmp_path, "{not json")).lower()
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def test_two_errors_both_named(tmp_path):
|
|
74
|
+
out = refused(cfg(tmp_path, {"enabled": "yes", "colour": 1}))
|
|
75
|
+
assert "enabled" in out and "colour" in out
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def test_config_that_is_not_an_object(tmp_path):
|
|
79
|
+
assert "config: must be a JSON object" in refused(cfg(tmp_path, ["enabled"]))
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def test_bypass_labels_that_are_not_an_object(tmp_path):
|
|
83
|
+
assert "bypassLabels" in refused(cfg(tmp_path, {"bypassLabels": ["exam:skip"]}))
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
"""Acceptance tests: `pr_exam.py validate` and `pr_exam.py public`, run as subprocesses.
|
|
2
|
+
|
|
3
|
+
Interface: `validate --request <request.json> <exam.json>` exits 0 and prints a summary for a valid
|
|
4
|
+
exam; for an invalid one it exits 1 with every broken rule, one per line, on stderr.
|
|
5
|
+
`public <exam.json>` prints the served projection as JSON.
|
|
6
|
+
Spec specs/pr-exam: requirements 2-5; design.md "Data model".
|
|
7
|
+
"""
|
|
8
|
+
import copy
|
|
9
|
+
import json
|
|
10
|
+
import subprocess
|
|
11
|
+
import sys
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
|
|
14
|
+
import pytest
|
|
15
|
+
|
|
16
|
+
SCRIPT = Path(__file__).parent / "pr_exam.py"
|
|
17
|
+
SHA = "a" * 40
|
|
18
|
+
DIFF = "diff --git a/lease.py b/lease.py\n+def take_lease(): ...\n+def recheck_head(): ...\n"
|
|
19
|
+
KINDS = ["why", "concept", "architecture", "risk", "behaviour"]
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def cid(kind, n=0):
|
|
23
|
+
return f"{kind}-{n}"
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def question(qid, concept, kind):
|
|
27
|
+
q = {"id": qid, "concept": concept, "type": "text" if kind == "text" else "choice", "prompt": f"Prompt {qid}?"}
|
|
28
|
+
if kind == "choice":
|
|
29
|
+
q["options"] = ["alpha beta", "gamma delta", "zeta eta"]
|
|
30
|
+
return q
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def key_for(q):
|
|
34
|
+
entry = {"explanation": "Because.", "hunk": "+def take_lease(): ..."}
|
|
35
|
+
if q["type"] == "text":
|
|
36
|
+
entry["rubric"] = {"pass": "Names the lease.", "partial": "Mentions locking."}
|
|
37
|
+
else:
|
|
38
|
+
entry["answer"] = 1
|
|
39
|
+
return entry
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def make_exam(concepts, questions, **over):
|
|
43
|
+
"""concepts: [(slug, kind)]; questions: [(slug, 'text'|'choice')] in order."""
|
|
44
|
+
qs = [question(f"q{i + 1}", slug, t) for i, (slug, t) in enumerate(questions)]
|
|
45
|
+
exam = {
|
|
46
|
+
"version": 1, "mode": "first", "repo": "jesdi/general-skills", "pr": 240, "head_sha": SHA,
|
|
47
|
+
"concepts": [{"id": s, "title": s.title(), "kind": k} for s, k in concepts],
|
|
48
|
+
"questions": qs,
|
|
49
|
+
"key": {q["id"]: key_for(q) for q in qs},
|
|
50
|
+
}
|
|
51
|
+
exam.update(over)
|
|
52
|
+
return exam
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def five():
|
|
56
|
+
concepts = [("c-why", "why"), ("c-con", "concept"), ("c-arch", "architecture"),
|
|
57
|
+
("c-risk", "risk"), ("c-beh", "behaviour")]
|
|
58
|
+
return make_exam(concepts, [("c-why", "text"), ("c-con", "text"), ("c-arch", "choice"),
|
|
59
|
+
("c-risk", "choice"), ("c-beh", "choice")])
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def run(tmp_path, exam, request_over=None, command="validate"):
|
|
63
|
+
(tmp_path / "records").mkdir(exist_ok=True)
|
|
64
|
+
(tmp_path / "diff.patch").write_text(DIFF)
|
|
65
|
+
request = {"mode": "first", "repo": "jesdi/general-skills", "pr": 240, "head_sha": SHA,
|
|
66
|
+
"diff": str(tmp_path / "diff.patch"), "body": str(tmp_path / "body.md"), "glossary": None,
|
|
67
|
+
"records": str(tmp_path / "records"), "today": "2026-11-18",
|
|
68
|
+
"only_concepts": [], "prior_concepts": [], "prior_prompts": [], "out": str(tmp_path / "exam.json")}
|
|
69
|
+
request.update(request_over or {})
|
|
70
|
+
(tmp_path / "body.md").write_text("body")
|
|
71
|
+
(tmp_path / "request.json").write_text(json.dumps(request))
|
|
72
|
+
(tmp_path / "exam.json").write_text(json.dumps(exam))
|
|
73
|
+
args = ["validate", "--request", str(tmp_path / "request.json")] if command == "validate" else ["public"]
|
|
74
|
+
return subprocess.run([sys.executable, str(SCRIPT), *args, str(tmp_path / "exam.json")],
|
|
75
|
+
capture_output=True, text=True)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def refused(result, *words):
|
|
79
|
+
assert result.returncode == 1, (result.returncode, result.stdout, result.stderr)
|
|
80
|
+
for w in words:
|
|
81
|
+
assert w in result.stderr, (w, result.stderr)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def test_well_formed_five_question_exam_is_valid(tmp_path):
|
|
85
|
+
r = run(tmp_path, five())
|
|
86
|
+
assert r.returncode == 0, r.stderr or r.stdout
|
|
87
|
+
assert r.stdout.strip()
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
@pytest.mark.parametrize("concepts", [[("only", "behaviour")], [("no-concept-fallback", "behaviour")]])
|
|
91
|
+
def test_trivial_pr_validates_only_with_exactly_one_question(tmp_path, concepts):
|
|
92
|
+
# the second fixture is the design's fallback for a PR with no concept: one listed behaviour concept
|
|
93
|
+
slug = concepts[0][0]
|
|
94
|
+
assert run(tmp_path, make_exam(concepts, [(slug, "choice")])).returncode == 0
|
|
95
|
+
refused(run(tmp_path, make_exam(concepts, [])))
|
|
96
|
+
refused(run(tmp_path, with_extra_question(make_exam(concepts, [(slug, "choice")]), "ghost")))
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def test_zero_concepts_and_zero_questions_is_refused(tmp_path):
|
|
100
|
+
refused(run(tmp_path, make_exam([], [])))
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def twelve():
|
|
104
|
+
kinds = ["why"] * 2 + ["concept"] * 2 + ["architecture"] * 2 + ["risk"] * 2 + ["behaviour"] * 4
|
|
105
|
+
return [(f"k{i}", k) for i, k in enumerate(kinds)]
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def types_for(concepts, slugs):
|
|
109
|
+
kind = dict(concepts)
|
|
110
|
+
return [(s, "text" if kind[s] == "why" else "choice") for s in slugs]
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def test_twelve_concepts_validate_with_eight_questions_by_priority(tmp_path):
|
|
114
|
+
cs = twelve()
|
|
115
|
+
assert run(tmp_path, make_exam(cs, types_for(cs, [s for s, _ in cs[:8]]))).returncode == 0
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def test_twelve_concepts_with_nine_questions_is_refused(tmp_path):
|
|
119
|
+
cs = twelve()
|
|
120
|
+
refused(run(tmp_path, make_exam(cs, types_for(cs, [s for s, _ in cs[:9]]))))
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def test_behaviour_asked_while_a_why_is_dropped_is_refused(tmp_path):
|
|
124
|
+
cs = twelve()
|
|
125
|
+
asked = ["k0"] + [s for s, _ in cs[2:8]] + ["k8"]
|
|
126
|
+
refused(run(tmp_path, make_exam(cs, types_for(cs, asked))))
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def test_choice_options_with_different_word_counts_name_the_question(tmp_path):
|
|
130
|
+
e = five()
|
|
131
|
+
e["questions"][2]["options"] = ["alpha beta", "gamma", "zeta eta"]
|
|
132
|
+
refused(run(tmp_path, e), "q3")
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def with_extra_question(e, concept):
|
|
136
|
+
q = question("q6", concept, "choice")
|
|
137
|
+
e["questions"].append(q)
|
|
138
|
+
e["key"]["q6"] = key_for(q)
|
|
139
|
+
return e
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def mut_dup_concept(e): return with_extra_question(e, "c-why")
|
|
143
|
+
def mut_unlisted(e): return with_extra_question(e, "ghost")
|
|
144
|
+
def mut_field(e): e["questions"][0]["hint"] = "x"
|
|
145
|
+
def mut_key_missing(e): del e["key"]["q2"]
|
|
146
|
+
def mut_key_extra(e): e["key"]["q9"] = copy.deepcopy(e["key"]["q3"])
|
|
147
|
+
def mut_answer(e): e["key"]["q3"]["answer"] = 7
|
|
148
|
+
def mut_pass(e): e["key"]["q1"]["rubric"]["pass"] = ""
|
|
149
|
+
def mut_partial(e): e["key"]["q1"]["rubric"]["partial"] = ""
|
|
150
|
+
def mut_hunk(e): e["key"]["q3"]["hunk"] = "+not in the diff"
|
|
151
|
+
def mut_repo(e): e["repo"] = "jesdi/other"
|
|
152
|
+
def mut_pr(e): e["pr"] = 241
|
|
153
|
+
def mut_sha(e): e["head_sha"] = "b" * 40
|
|
154
|
+
def mut_version(e): e["version"] = 2
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
@pytest.mark.parametrize("mutate,words", [
|
|
158
|
+
(mut_dup_concept, ["c-why"]), (mut_unlisted, ["ghost"]), (mut_field, ["hint"]),
|
|
159
|
+
(mut_key_missing, ["q2", "key"]), (mut_key_extra, ["q9", "key"]), (mut_answer, ["answer", "q3"]),
|
|
160
|
+
(mut_pass, ["rubric", "pass"]), (mut_partial, ["rubric", "partial"]), (mut_hunk, ["hunk", "q3"]),
|
|
161
|
+
(mut_repo, ["repo"]), (mut_pr, ["pr"]), (mut_sha, ["head_sha"]), (mut_version, ["version"]),
|
|
162
|
+
])
|
|
163
|
+
def test_each_broken_rule_is_refused_with_its_own_message(tmp_path, mutate, words):
|
|
164
|
+
e = five()
|
|
165
|
+
e = mutate(e) or e
|
|
166
|
+
refused(run(tmp_path, e), *words)
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def test_two_questions_with_one_type_is_refused(tmp_path):
|
|
170
|
+
cs = [("c-why", "why"), ("c-beh", "behaviour")]
|
|
171
|
+
refused(run(tmp_path, make_exam(cs, [("c-why", "text"), ("c-beh", "text")])))
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def test_three_questions_without_a_why_text_question_is_refused(tmp_path):
|
|
175
|
+
cs = [("c-why", "why"), ("c-con", "concept"), ("c-beh", "behaviour")]
|
|
176
|
+
refused(run(tmp_path, make_exam(cs, [("c-why", "choice"), ("c-con", "text"), ("c-beh", "choice")])))
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def test_an_exam_breaking_three_rules_prints_all_three_errors(tmp_path):
|
|
180
|
+
e = five()
|
|
181
|
+
e["version"] = 2
|
|
182
|
+
e["repo"] = "jesdi/other"
|
|
183
|
+
e["head_sha"] = "b" * 40
|
|
184
|
+
refused(run(tmp_path, e), "version", "repo", "head_sha")
|
|
185
|
+
assert len([ln for ln in run(tmp_path, e).stderr.splitlines() if ln.strip()]) >= 3
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def test_public_prints_only_what_the_page_may_see(tmp_path):
|
|
189
|
+
e = five()
|
|
190
|
+
r = run(tmp_path, e, command="public")
|
|
191
|
+
assert r.returncode == 0, r.stderr
|
|
192
|
+
out = json.loads(r.stdout)
|
|
193
|
+
assert out == {
|
|
194
|
+
"version": 1, "repo": "jesdi/general-skills", "pr": 240, "head_sha": SHA,
|
|
195
|
+
"questions": [{k: q[k] for k in ("id", "type", "prompt", "options") if k in q} for q in e["questions"]],
|
|
196
|
+
}
|
|
197
|
+
for word in ("key", "concepts", "answer", "rubric", "explanation", "hunk"):
|
|
198
|
+
assert f'"{word}"' not in r.stdout
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def mut_not_object(e): return [e]
|
|
202
|
+
def mut_questions_not_list(e): e["questions"] = {q["id"]: q for q in e["questions"]}
|
|
203
|
+
def mut_one_option(e): e["questions"][2]["options"] = ["alpha beta"]
|
|
204
|
+
def mut_text_options(e): e["questions"][0]["options"] = ["alpha beta", "gamma delta"]
|
|
205
|
+
def mut_mode(e): e["mode"] = "final"
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
@pytest.mark.parametrize("mutate,words", [
|
|
209
|
+
(mut_not_object, ["exam must be a JSON object"]),
|
|
210
|
+
(mut_questions_not_list, ["questions must be a list of objects"]),
|
|
211
|
+
(mut_one_option, ["q3", "choice needs a list of options", "answer is not an index"]),
|
|
212
|
+
(mut_text_options, ["q1", "text question must not have options"]),
|
|
213
|
+
(mut_mode, ["mode must be first, followup or delta", "differs from the request"]),
|
|
214
|
+
])
|
|
215
|
+
def test_each_shape_and_mode_rule_is_refused_with_its_own_message(tmp_path, mutate, words):
|
|
216
|
+
e = five()
|
|
217
|
+
e = mutate(e) or e
|
|
218
|
+
refused(run(tmp_path, e), *words)
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
def mut_empty_id(e): e["questions"][2]["id"] = ""
|
|
222
|
+
def mut_empty_prompt(e): e["questions"][2]["prompt"] = ""
|
|
223
|
+
def mut_empty_option(e): e["questions"][2]["options"] = ["alpha beta", "", "zeta eta"]
|
|
224
|
+
def mut_kind(e): e["concepts"][4]["kind"] = "trivia"
|
|
225
|
+
def mut_listed_twice(e): e["concepts"].append(copy.deepcopy(e["concepts"][4]))
|
|
226
|
+
def mut_duplicate_options(e): e["questions"][2]["options"] = ["alpha beta", "alpha beta", "zeta eta"]
|
|
227
|
+
def mut_choice_rubric(e): e["key"]["q3"]["rubric"] = {"pass": "p", "partial": "q"}
|
|
228
|
+
def mut_text_answer(e): e["key"]["q1"]["answer"] = 0
|
|
229
|
+
def mut_explanation(e): e["key"]["q3"]["explanation"] = ""
|
|
230
|
+
def mut_empty_hunk(e): e["key"]["q3"]["hunk"] = ""
|
|
231
|
+
def mut_entry(e): e["key"]["q3"] = "the second option"
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
@pytest.mark.parametrize("mutate,message", [
|
|
235
|
+
(mut_empty_id, "question '': id must be a non-empty string"),
|
|
236
|
+
(mut_empty_prompt, "question q3: prompt must be a non-empty string"),
|
|
237
|
+
(mut_empty_option, "question q3: options must be non-empty strings"),
|
|
238
|
+
(mut_kind, f"concept c-beh: kind must be one of {KINDS}"),
|
|
239
|
+
(mut_listed_twice, "concept c-beh: listed twice"),
|
|
240
|
+
(mut_duplicate_options, "question q3: options contain duplicates"),
|
|
241
|
+
(mut_choice_rubric, "key q3: choice question must not have a rubric"),
|
|
242
|
+
(mut_text_answer, "key q1: text question must not have an answer"),
|
|
243
|
+
(mut_explanation, "key q3: explanation must be non-empty"),
|
|
244
|
+
(mut_empty_hunk, "key q3: hunk must be non-empty"),
|
|
245
|
+
(mut_entry, "key q3: entry must be an object"),
|
|
246
|
+
])
|
|
247
|
+
def test_each_question_concept_and_key_rule_prints_its_exact_message(tmp_path, mutate, message):
|
|
248
|
+
e = five()
|
|
249
|
+
mutate(e)
|
|
250
|
+
r = run(tmp_path, e)
|
|
251
|
+
refused(r)
|
|
252
|
+
assert message in r.stderr.splitlines(), r.stderr
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"""Acceptance tests: `pr_exam.py validate` for `followup` and `delta` modes, run as subprocesses.
|
|
2
|
+
|
|
3
|
+
Interface: `validate --request <request.json> <exam.json>` with request `mode` "followup" or "delta"
|
|
4
|
+
(`only_concepts`, `prior_concepts`, `prior_prompts` in the request); exit 0 when valid, exit 1 with
|
|
5
|
+
every broken rule on stderr otherwise.
|
|
6
|
+
Spec specs/pr-exam: requirement 7; design.md "exam.json" (`followup`, `delta` rows).
|
|
7
|
+
"""
|
|
8
|
+
from test_exam_format import make_exam, refused, run
|
|
9
|
+
|
|
10
|
+
LEASE, RECHECK = "lease-ownership", "head-sha-recheck"
|
|
11
|
+
MISSED = [(LEASE, "why"), (RECHECK, "concept")]
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def followup(questions, concepts=None, **over):
|
|
15
|
+
return make_exam(concepts or MISSED, questions, mode="followup", **over)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def req(mode, **over):
|
|
19
|
+
return {"mode": mode, **over}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def test_followup_accepts_exactly_one_question_per_missed_concept(tmp_path):
|
|
23
|
+
r = req("followup", only_concepts=[LEASE, RECHECK])
|
|
24
|
+
ok = followup([(LEASE, "text"), (RECHECK, "text")])
|
|
25
|
+
result = run(tmp_path, ok, r)
|
|
26
|
+
assert result.returncode == 0, result.stderr or result.stdout
|
|
27
|
+
refused(run(tmp_path, followup([(LEASE, "text")]), r), RECHECK)
|
|
28
|
+
three = followup([(LEASE, "text"), (RECHECK, "text"), ("extra", "text")], MISSED + [("extra", "behaviour")])
|
|
29
|
+
refused(run(tmp_path, three, r), "extra")
|
|
30
|
+
other = followup([(LEASE, "text"), ("other", "text")], MISSED + [("other", "behaviour")])
|
|
31
|
+
refused(run(tmp_path, other, r), "other")
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_followup_refuses_a_prompt_of_an_earlier_attempt(tmp_path):
|
|
35
|
+
exam = followup([(LEASE, "text"), (RECHECK, "text")])
|
|
36
|
+
only = [LEASE, RECHECK]
|
|
37
|
+
fine = run(tmp_path, exam, req("followup", only_concepts=only, prior_prompts=["Something else?"]))
|
|
38
|
+
assert fine.returncode == 0, fine.stderr or fine.stdout
|
|
39
|
+
refused(run(tmp_path, exam, req("followup", only_concepts=only, prior_prompts=["Prompt q2?"])), "q2")
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def test_type_mix_rule_is_off_but_options_key_and_due_rules_stay_on(tmp_path):
|
|
43
|
+
fr = req("followup", only_concepts=[LEASE, RECHECK])
|
|
44
|
+
ok = run(tmp_path, followup([(LEASE, "text"), (RECHECK, "text")]), fr)
|
|
45
|
+
assert ok.returncode == 0, ok.stderr or ok.stdout
|
|
46
|
+
dr = req("delta", prior_concepts=["old"])
|
|
47
|
+
cs = [("a-one", "concept"), ("a-two", "concept"), ("a-three", "concept")]
|
|
48
|
+
delta = make_exam(cs, [(s, "choice") for s, _ in cs], mode="delta")
|
|
49
|
+
ok = run(tmp_path, delta, dr)
|
|
50
|
+
assert ok.returncode == 0, ok.stderr or ok.stdout
|
|
51
|
+
# the loosened mix does not loosen the prior-concepts rule
|
|
52
|
+
refused(run(tmp_path, delta, req("delta", prior_concepts=["a-two"])), "a-two")
|
|
53
|
+
# options of different word counts are still refused
|
|
54
|
+
bad = followup([(LEASE, "choice"), (RECHECK, "choice")])
|
|
55
|
+
bad["questions"][0]["options"] = ["alpha beta", "gamma", "zeta eta"]
|
|
56
|
+
refused(run(tmp_path, bad, fr), "q1")
|
|
57
|
+
# a key entry still has to exist for every question
|
|
58
|
+
nokey = followup([(LEASE, "text"), (RECHECK, "text")])
|
|
59
|
+
del nokey["key"]["q2"]
|
|
60
|
+
refused(run(tmp_path, nokey, fr), "q2", "key")
|
|
61
|
+
# a concept due for re-testing is still choice only
|
|
62
|
+
records = tmp_path / "records"
|
|
63
|
+
records.mkdir(exist_ok=True)
|
|
64
|
+
(records / "0001-lease-ownership.md").write_text(
|
|
65
|
+
"---\nconcept: lease-ownership\nstate: demonstrated\ndate: 2026-10-19\nsource: jesdi/general-skills#1\n"
|
|
66
|
+
"status: active\n---\n# Lease\n\nText.\n")
|
|
67
|
+
refused(run(tmp_path, followup([(LEASE, "text"), (RECHECK, "text")]), fr), LEASE)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def test_delta_with_no_questions_and_no_concepts_is_valid(tmp_path):
|
|
71
|
+
result = run(tmp_path, make_exam([], [], mode="delta"), req("delta", prior_concepts=["old"]))
|
|
72
|
+
assert result.returncode == 0, result.stderr or result.stdout
|
|
73
|
+
# "nothing new" lists no concept: one that an earlier exam covered is refused, even unasked
|
|
74
|
+
stale = make_exam([("old", "concept")], [("old", "choice")], mode="delta")
|
|
75
|
+
refused(run(tmp_path, stale, req("delta", prior_concepts=["old"])), "old")
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def test_delta_with_a_new_concept_is_valid_and_a_prior_concept_is_refused(tmp_path):
|
|
79
|
+
exam = make_exam([("retry-budget", "concept")], [("retry-budget", "choice")], mode="delta")
|
|
80
|
+
ok = run(tmp_path, exam, req("delta", prior_concepts=["merge-lease"]))
|
|
81
|
+
assert ok.returncode == 0, ok.stderr or ok.stdout
|
|
82
|
+
refused(run(tmp_path, exam, req("delta", prior_concepts=["retry-budget"])), "retry-budget")
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def test_an_exam_whose_mode_differs_from_the_request_is_refused(tmp_path):
|
|
86
|
+
ok = run(tmp_path, followup([(LEASE, "text"), (RECHECK, "text")]), req("followup", only_concepts=[LEASE, RECHECK]))
|
|
87
|
+
assert ok.returncode == 0, ok.stderr or ok.stdout
|
|
88
|
+
refused(run(tmp_path, make_exam([], [], mode="delta"), req("first")), "mode")
|
|
89
|
+
refused(run(tmp_path, make_exam([], [], mode="delta"), req("followup", only_concepts=[])), "mode")
|
|
90
|
+
refused(run(tmp_path, make_exam([("x", "behaviour")], [("x", "choice")], mode="first"), req("delta")), "mode")
|