Point Operators at rolePolicies and reviewerSkills for their own defaults, add the Designer card and designerSkills paths for the pinned methods, correct the README's default summary, and check the role matrix lists every package of its role. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
151 lines
6.0 KiB
Python
151 lines
6.0 KiB
Python
"""Keep the Operator override guide consistent with the packages it describes."""
|
|
|
|
import hashlib
|
|
import json
|
|
import re
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
from tools.packages import ROLE_STEPS, check_package
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
GUIDE = ROOT / "OVERRIDING.md"
|
|
|
|
ROLE_NAMES = {
|
|
"Specification Designer": "designer",
|
|
"Technical Coordinator": "coordinator",
|
|
"Planner": "planner",
|
|
"Implementer": "implementer",
|
|
"Reviewer": "reviewer",
|
|
"Tester": "tester",
|
|
}
|
|
CONTRACT = ROOT / "docs/authoritative/instruction-package-contract.md"
|
|
|
|
|
|
def section(text, heading):
|
|
"""Return a level-2 section's body; headings inside code fences do not end it."""
|
|
lines, body, fenced = text.splitlines(keepends=True), None, False
|
|
for line in lines:
|
|
if line.startswith("```"):
|
|
fenced = not fenced
|
|
if not fenced and line.startswith("## "):
|
|
if body is not None:
|
|
break
|
|
if line.rstrip("\n") == f"## {heading}":
|
|
body = []
|
|
continue
|
|
if body is not None:
|
|
body.append(line)
|
|
if body is None:
|
|
raise AssertionError(f"no '## {heading}' section")
|
|
return "".join(body)
|
|
|
|
|
|
def table_rows(text):
|
|
rows = []
|
|
for line in text.splitlines():
|
|
if line.startswith("| ") and not set(line) <= set("|- "):
|
|
rows.append([cell.strip() for cell in line.strip("|").split("|")])
|
|
return rows[1:]
|
|
|
|
|
|
def codes(cell):
|
|
return re.findall(r"`([^`]+)`", cell)
|
|
|
|
|
|
def package_facts(path):
|
|
manifest = json.loads((path / "relayview-skill.json").read_text())
|
|
frontmatter = (path / "SKILL.md").read_text().split("---\n")[1]
|
|
manual = re.search(r"^disable-model-invocation: true$", frontmatter, re.M)
|
|
if manifest["schemaVersion"] == 2:
|
|
extra = f"issueClaim: {manifest['issueClaim']['statusLabel']}"
|
|
elif manifest["schemaVersion"] == 3:
|
|
extra = manifest["treatment"]
|
|
else:
|
|
extra = None
|
|
return {
|
|
"role_step": [manifest["role"], manifest["step"]],
|
|
"mode": "manual" if manual else "automatic",
|
|
"schema": str(manifest["schemaVersion"]),
|
|
"extra": extra,
|
|
"version": re.search(r"relayview-version: (\S+)", frontmatter).group(1),
|
|
"release": manifest["source"]["reference"],
|
|
}
|
|
|
|
|
|
class OverrideGuideTests(unittest.TestCase):
|
|
def setUp(self):
|
|
self.text = GUIDE.read_text()
|
|
|
|
def test_readme_points_operators_to_the_guide(self):
|
|
self.assertIn("(OVERRIDING.md)", (ROOT / "README.md").read_text())
|
|
|
|
def test_package_matrix_matches_every_package_sidecar(self):
|
|
rows = table_rows(section(self.text, "Package matrix"))
|
|
listed = {}
|
|
for row in rows:
|
|
name = codes(row[0])[0]
|
|
self.assertNotIn(name, listed, f"{name} is listed twice")
|
|
extra = codes(row[4])
|
|
listed[name] = {
|
|
"role_step": codes(row[1]),
|
|
"mode": row[2],
|
|
"schema": row[3],
|
|
"extra": extra[0] if extra else None,
|
|
"version": row[5],
|
|
"release": codes(row[6])[0],
|
|
}
|
|
packages = sorted(path.name for path in (ROOT / "packages").iterdir())
|
|
self.assertEqual(sorted(listed), packages)
|
|
for name in packages:
|
|
with self.subTest(package=name):
|
|
self.assertEqual(listed[name], package_facts(ROOT / "packages" / name))
|
|
|
|
def test_role_matrix_matches_contract_and_packages(self):
|
|
rows = table_rows(section(self.text, "Role matrix"))
|
|
schemas = {codes(row[0])[0]: row[2] for row in table_rows(section(CONTRACT.read_text(), "Role and step"))}
|
|
slots = {}
|
|
for row in table_rows(section(self.text, "Package matrix")):
|
|
slot = re.fullmatch(r"(\w+) automatic, (\d)\w\w", row[7])
|
|
if slot:
|
|
slots.setdefault(slot.group(1).lower(), []).append((slot.group(2), codes(row[0])[0]))
|
|
elif row[7] == "Pinned Designer default":
|
|
slots.setdefault("designer", []).append(("1", codes(row[0])[0]))
|
|
seen = {}
|
|
for row in rows:
|
|
role = ROLE_NAMES[row[0]]
|
|
seen[role] = row
|
|
self.assertEqual(codes(row[1]), [role, ROLE_STEPS[role]])
|
|
self.assertEqual(row[2], schemas[role])
|
|
self.assertEqual(codes(row[5]), [name for _, name in sorted(slots.get(role, []))])
|
|
self.assertEqual(row[3].split(" ")[0], "Yes" if "3" in schemas[role] else "No")
|
|
for name in codes(row[5]):
|
|
with self.subTest(role=role, default=name):
|
|
facts = package_facts(ROOT / "packages" / name)
|
|
self.assertEqual(facts["role_step"], [role, ROLE_STEPS[role]])
|
|
self.assertEqual(facts["mode"], "automatic")
|
|
listed = codes(row[5]) + codes(row[6])
|
|
packages = [path.name for path in (ROOT / "packages").iterdir() if package_facts(path)["role_step"][0] == role]
|
|
self.assertEqual(sorted(listed), sorted(packages))
|
|
self.assertEqual(set(seen), set(ROLE_STEPS))
|
|
|
|
def test_layer_four_template_is_a_valid_user_package(self):
|
|
template = section(self.text, "Layer-4 authoring template")
|
|
skill = re.search(r"```markdown\n(.*?)```", template, re.S).group(1)
|
|
sidecar = re.search(r"```json\n(.*?)```", template, re.S).group(1)
|
|
name = re.search(r"^name: (\S+)$", skill, re.M).group(1)
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
package = Path(directory) / name
|
|
package.mkdir()
|
|
(package / "SKILL.md").write_text(skill)
|
|
digest = hashlib.sha256(skill.encode()).hexdigest()
|
|
(package / "relayview-skill.json").write_text(sidecar.replace("<sha256 of SKILL.md>", digest))
|
|
check_package(package)
|
|
manifest = json.loads((package / "relayview-skill.json").read_text())
|
|
self.assertEqual(manifest["source"]["kind"], "user")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|