Files
relayview-skills/tests/test_overriding.py
T
adminandClaude Opus 5.5 3cef92a36d
Check instruction packages / check (push) Successful in 7s
Check instruction packages / check (pull_request) Successful in 5s
Add Technical Coordinator recovery package (v0.17.0)
Add coordinator-recovery, an automatic coordinator/coordination
package (schema 1) that triages a stalled task's blockers before any
nudge, sends one bounded "please keep going" nudge within the owner's
budget and cooldown, parks repeated stalls for the Operator with a
diagnostic summary, rebuilds the Coordinator's posture from the
Portfolio Read Model and Working Ledger after a context refresh, and
records implicit contention edges in the ledger when discovered.

The override guide, contract, and README list the package, show the
recovery seams, and give a named set that swaps recovery without
touching coordinator-dispatch.

Refs #27

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 20:39:21 -05:00

172 lines
7.3 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].startswith("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].split(", ") 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_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)
def test_coordinator_recovery_is_overridable_without_dispatch(self):
text = section(self.text, "Customize the Technical Coordinator")
for phrase in ("`coordinator-recovery`", "nudge", "reorientation", "Working Ledger",
"named set", "Settings → Skills", "nudge budgets and cooldowns"):
self.assertIn(phrase.lower(), text.lower())
members = re.search(r"members: \[(.*?)\]", text).group(1).split(", ")
self.assertIn("coordinator-dispatch", members)
self.assertIn("coordinator-communication", members)
self.assertNotIn("coordinator-recovery", members)
fork = [name for name in members if name.endswith("-coordinator-recovery")]
self.assertEqual(len(fork), 1, members)
self.assertIn("role: coordinator", text)
self.assertIn("step: coordination", text)
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()