"""Canonical impl contracts stay reachable without duplicated skill bodies.""" import re import unittest from pathlib import Path from harness.tests.common.impl_contract_docs import read_contract, REQUIRED ROOT = Path(__file__).resolve().parents[3] class ImplArchitectureDocsTests(unittest.TestCase): def test_skills_require_single_detailed_workflow_source(self): for name in ("gitea-issue-implementation", "gitea-issue-rework"): path = ROOT / "harness/agents/impl/skills" / name / "SKILL.md" text = path.read_text() reference = path.parent / "references/workflow.md" with self.subTest(skill=name): self.assertIn(REQUIRED, text) self.assertLess(len(text.splitlines()), 100) self.assertEqual(text.count("name: " + name), 1) self.assertNotIn("## Managed-lock broker gate", text) self.assertFalse(reference.read_text().startswith("---")) contract = read_contract(path) self.assertEqual(contract.count("## Managed-lock broker gate"), 1) for gate in ("## Delegation evidence acceptance gate", "## Test inventory source-binding gate", "## Canonical external verification evidence"): self.assertEqual(contract.count(gate), 1) def test_all_canonical_impl_markdown_links_resolve(self): for name in ("gitea-issue-implementation", "gitea-issue-rework"): directory = ROOT / "harness/agents/impl/skills" / name for path in [directory / "SKILL.md", directory / "references/workflow.md"]: for link in re.findall(r"\[[^\]]+\]\(([^)]+)\)", path.read_text()): if link.startswith(("https://", "http://", "#")): continue target = link.split("#", 1)[0] with self.subTest(path=path.name, link=link): self.assertTrue((path.parent / target).resolve().exists()) def test_correction_default_and_exception_remain_distinct(self): text = (ROOT / "harness/agents/impl/skills/gitea-issue-rework/references/readback.md").read_text() for token in ("strict", "separately", "atomic_client_precondition=false", "residual", "neutered"): self.assertIn(token.lower(), text.lower()) if __name__ == "__main__": unittest.main()