2026-11-25 19:34:22 -05:00
|
|
|
"""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",
|
|
|
|
|
}
|
2026-11-25 19:37:57 -05:00
|
|
|
CONTRACT = ROOT / "docs/authoritative/instruction-package-contract.md"
|
2026-11-25 19:34:22 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
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:
|
2026-11-25 19:37:57 -05:00
|
|
|
raise AssertionError(f"no '## {heading}' section")
|
2026-11-25 19:34:22 -05:00
|
|
|
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):
|
2026-11-25 19:37:57 -05:00
|
|
|
self.assertIn("(OVERRIDING.md)", (ROOT / "README.md").read_text())
|
2026-11-25 19:34:22 -05:00
|
|
|
|
|
|
|
|
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))
|
|
|
|
|
|
2026-11-25 19:40:21 -05:00
|
|
|
def test_role_matrix_matches_contract_and_packages(self):
|
2026-11-25 19:34:22 -05:00
|
|
|
rows = table_rows(section(self.text, "Role matrix"))
|
2026-11-25 19:37:57 -05:00
|
|
|
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]))
|
2026-11-25 19:58:49 -05:00
|
|
|
elif row[7].startswith("Pinned Designer default"):
|
2026-11-25 19:37:57 -05:00
|
|
|
slots.setdefault("designer", []).append(("1", codes(row[0])[0]))
|
2026-11-25 19:34:22 -05:00
|
|
|
seen = {}
|
|
|
|
|
for row in rows:
|
|
|
|
|
role = ROLE_NAMES[row[0]]
|
|
|
|
|
seen[role] = row
|
|
|
|
|
self.assertEqual(codes(row[1]), [role, ROLE_STEPS[role]])
|
2026-11-25 19:37:57 -05:00
|
|
|
self.assertEqual(row[2], schemas[role])
|
|
|
|
|
self.assertEqual(codes(row[5]), [name for _, name in sorted(slots.get(role, []))])
|
2026-11-25 19:41:44 -05:00
|
|
|
self.assertEqual(row[3].split(" ")[0], "Yes" if "3" in schemas[role].split(", ") else "No")
|
2026-11-25 19:34:22 -05:00
|
|
|
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")
|
2026-11-25 19:40:21 -05:00
|
|
|
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))
|
2026-11-25 19:34:22 -05:00
|
|
|
self.assertEqual(set(seen), set(ROLE_STEPS))
|
|
|
|
|
|
2026-11-25 19:53:15 -05:00
|
|
|
def test_coordinator_customization_names_the_seams_and_the_owner_gates(self):
|
|
|
|
|
text = section(self.text, "Customize the Technical Coordinator").lower()
|
|
|
|
|
for phrase in ("wave aggressiveness", "contention heuristics", "reporting tone",
|
|
|
|
|
"`coordinator-dispatch`", "`wave-selection.md`", "`coordinator-communication`",
|
|
|
|
|
"`portfolio_conflict`", "`unique_resource_needed`", "leases"):
|
|
|
|
|
self.assertIn(phrase.lower(), text)
|
|
|
|
|
|
2026-11-25 19:34:22 -05:00
|
|
|
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()
|