Files
relayview-skills/tests/test_planner_reviewer.py
T

178 lines
8.8 KiB
Python
Raw Normal View History

"""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 section(text, heading):
match = re.search(rf"^## {re.escape(heading)}\n.*?(?=^## |\Z)", text, re.M | re.S)
if not match:
raise AssertionError(f"no '## {heading}' 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)
# Implementer flags arrive only once the Implementer emits them, so the
# triage is conditional rather than a claim about current behavior.
self.assertIn("When the Implementer reports", self.text)
def test_verification_goals_have_a_fallback_without_a_tester(self):
self.assertIn("When the owner reports that no Tester step will run for the task", self.text)
self.assertIn("When the owner reports nothing about a Tester step", 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):
for heading in ("Propose a guardrail", "Escalate"):
with self.subTest(heading=heading):
self.assertEqual(section(read("code-review-auto")[2], heading), section(read("code-review")[2], heading))
ladder = section(read("code-review")[2], "Propose a guardrail")
positions = [ladder.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", "candidate skill diff",
"could a lower-numbered rung"):
with self.subTest(phrase=phrase):
self.assertIn(phrase, ladder)
# The trigger must not presuppose a deterministic check, or rung 4 is unreachable.
self.assertNotIn("a deterministic check could have caught it", ladder)
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",
"Specification Designer", "requested proof",
"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()