"""Pin the v0.16.0 Planner and Reviewer guidance: proof translation, typed Layer C escalation, and Trust Pyramid Guardrail Proposals.""" import json import re import unittest from pathlib import Path from tools.packages import check_package ROOT = Path(__file__).resolve().parents[1] VERSION = "0.16.0" # name: (role, step, schema, sidecar extra, manual, declared files) PACKAGES = { "planner-scope": ("planner", "planning", 2, {"issueClaim": {"statusLabel": "status/in-progress"}}, False, ["SKILL.md", "scope.md", "escalation.md"]), "planner-communication": ("planner", "planning", 3, {"treatment": "communication_context"}, False, ["SKILL.md"]), "code-review-auto": ("reviewer", "review", 1, {}, False, ["SKILL.md"]), "code-review": ("reviewer", "review", 1, {}, True, ["SKILL.md"]), "reviewer-communication": ("reviewer", "review", 3, {"treatment": "communication_context"}, False, ["SKILL.md"]), } DIRECT_REASONS = ("boundary_crossed", "spec_ambiguity", "verification_incomplete", "behavioral_tradeoff", "convergence_exceeded") IMPLEMENTER_FLAGS = ("needs_operator_decision", "scope_exceeded") REVIEW_PACKAGES = ("code-review-auto", "code-review") # The Trust Pyramid rungs, lowest (most deterministic) first. GUARDRAIL_LADDER = ("architecture or API boundary", "static check or lint rule", "verification harness", "candidate prose skill") def read(name): package = ROOT / "packages" / name manifest = json.loads((package / "relayview-skill.json").read_text()) skill = (package / "SKILL.md").read_text() frontmatter, body = skill.split("---\n", 2)[1:] resources = "".join((package / item["path"]).read_text() for item in manifest["files"] if item["path"] != "SKILL.md") return manifest, frontmatter, body + resources def guardrail_section(text): match = re.search(r"^## Propose a guardrail\n.*?(?=^## |\Z)", text, re.M | re.S) if not match: raise AssertionError("no '## Propose a guardrail' section") return match.group(0) class PlannerReviewerReleaseTests(unittest.TestCase): def test_packages_release_together_and_keep_their_schemas(self): for name, (role, step, schema, extra, manual, files) in PACKAGES.items(): with self.subTest(package=name): check_package(ROOT / "packages" / name) manifest, frontmatter, _ = read(name) self.assertEqual(manifest["source"], {"kind": "first-party", "reference": f"v{VERSION}"}) self.assertEqual((manifest["role"], manifest["step"], manifest["schemaVersion"]), (role, step, schema)) for key, value in extra.items(): self.assertEqual(manifest[key], value) self.assertEqual([item["path"] for item in manifest["files"]], files) self.assertIn(f"relayview-version: {VERSION}", frontmatter) self.assertEqual("disable-model-invocation: true" in frontmatter, manual) def test_packages_use_specification_designer_terminology(self): for name in PACKAGES: with self.subTest(package=name): self.assertNotRegex(read(name)[2], r"(?i)issue designer") class PlannerScopeTests(unittest.TestCase): def setUp(self): self.text = read("planner-scope")[2] def test_translates_specification_proof_into_plan_v1(self): for phrase in ("Specification Designer", "requested proof artifact", "fast-test completeness", "declared test resource", "Plan v1", "Implementer fast check", "Building Inspector", "verification goal", "`requires_runtime_or_human_judgment`", "fast_checks:", "verification_goals:", "test_resources:"): with self.subTest(phrase=phrase): self.assertIn(phrase.lower(), self.text.lower()) def test_triages_implementer_flags(self): for flag in IMPLEMENTER_FLAGS: self.assertIn(f"`{flag}`", self.text) self.assertIn("strictly inside the approved specification", self.text) self.assertIn("promote", self.text) def test_direct_escalation_discipline(self): for reason in DIRECT_REASONS: with self.subTest(reason=reason): self.assertIn(f"`{reason}`", self.text) for phrase in ("risk summary", "just to be safe", "never downgrade `operator_review_required`"): with self.subTest(phrase=phrase): self.assertIn(phrase, self.text) class ReviewerGuardrailTests(unittest.TestCase): def test_review_packages_share_one_guardrail_ladder(self): sections = {name: guardrail_section(read(name)[2]) for name in REVIEW_PACKAGES} self.assertEqual(sections["code-review-auto"], sections["code-review"]) section = sections["code-review"] positions = [section.lower().index(rung.lower()) for rung in GUARDRAIL_LADDER] self.assertEqual(positions, sorted(positions), "rungs run from most to least deterministic") for phrase in ("lowest viable", "repeatable defect class", "root-cause", "fast regression test", "Feature Map", "last resort", "Operator approves"): with self.subTest(phrase=phrase): self.assertIn(phrase, section) def test_review_escalation_uses_typed_reasons(self): for name in REVIEW_PACKAGES: text = read(name)[2] for reason in DIRECT_REASONS: with self.subTest(package=name, reason=reason): self.assertIn(f"`{reason}`", text) self.assertIn("never downgrade `operator_review_required`", text) self.assertIn("just to be safe", text) def test_reviewer_prose_stays_out_of_owner_schemas(self): for name in REVIEW_PACKAGES + ("reviewer-communication", "planner-communication"): with self.subTest(package=name): text = read(name)[2] self.assertNotIn("```", text) self.assertNotIn("{", text) def test_automatic_review_keeps_manual_inspection_out(self): text = read("code-review-auto")[2] self.assertIn("path-aware, and actionable", text) for phrase in ("Report both axes", "subagent"): self.assertNotIn(phrase, text) class CommunicationTests(unittest.TestCase): def test_planner_communication_frames_specification_and_escalation(self): text = read("planner-communication")[2] for phrase in ("Specification Designer", "typed reason", "risk summary", "proportional", "acknowledgement", "Markdown"): with self.subTest(phrase=phrase): self.assertIn(phrase, text) def test_reviewer_communication_frames_review_packet_and_escalation(self): text = read("reviewer-communication")[2] for phrase in ("Review Packet", "typed reason", "risk summary", "Guardrail Proposal", "proportional", "acknowledgement", "Markdown"): with self.subTest(phrase=phrase): self.assertIn(phrase, text) class ReleaseNotesTests(unittest.TestCase): def test_release_notes_give_before_and_after_for_each_package(self): notes = (ROOT / "RELEASE-NOTES.md").read_text() match = re.search(rf"^## v{re.escape(VERSION)}\b.*?(?=^## |\Z)", notes, re.M | re.S) self.assertIsNotNone(match, "no v0.16.0 section") section = match.group(0) for name in PACKAGES: with self.subTest(package=name): entry = re.search(rf"^### `{name}`\n.*?(?=^### |\Z)", section, re.M | re.S) self.assertIsNotNone(entry, f"no entry for {name}") self.assertRegex(entry.group(0), r"\*\*Before \(\d+\.\d+\.\d+\):\*\*") self.assertIn("**After:**", entry.group(0)) self.assertIn("**Fork:**", entry.group(0)) self.assertIn("(RELEASE-NOTES.md)", (ROOT / "OVERRIDING.md").read_text()) self.assertIn("(RELEASE-NOTES.md)", (ROOT / "README.md").read_text()) if __name__ == "__main__": unittest.main()