generated from john/python-template
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
"""Regression guards for canonical documentation and instruction contracts."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
PROJECT_ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
ACTIVE_CONTRACT_FILES = (
|
||||
".github/instructions/services.instructions.md",
|
||||
".github/instructions/ui.instructions.md",
|
||||
".github/instructions/error-handling.instructions.md",
|
||||
".github/skills/python-code-reviewer/skill.md",
|
||||
".github/skills/evidence-provenance-auditor/skill.md",
|
||||
"docs/ver4/index_v4.md",
|
||||
"docs/ver4/architecture_v4.md",
|
||||
"docs/ver4/requirements_v4.md",
|
||||
"docs/ver4/schema_v4.md",
|
||||
"docs/ver4/error_handling_v4.md",
|
||||
"docs/ui/README.md",
|
||||
)
|
||||
|
||||
|
||||
LEGACY_REFERENCE_MARKERS = (
|
||||
"docs-v4x-archive",
|
||||
"docs/ver4/history.md",
|
||||
"docs/ver4.0",
|
||||
"docs/ver4.1",
|
||||
"docs/ver4.2",
|
||||
"docs/ver4.3",
|
||||
"docs/ver4.4",
|
||||
"docs/ver4.5",
|
||||
"docs/ver4.6",
|
||||
"docs/ver4.7",
|
||||
)
|
||||
|
||||
|
||||
def _read(relative_path: str) -> str:
|
||||
return (PROJECT_ROOT / relative_path).read_text(encoding="utf-8")
|
||||
|
||||
|
||||
def test_active_contract_files_are_present():
|
||||
"""Guard the guard: ensure all expected authority files are scanned."""
|
||||
missing = [path for path in ACTIVE_CONTRACT_FILES if not (PROJECT_ROOT / path).exists()]
|
||||
assert missing == []
|
||||
|
||||
|
||||
def test_no_legacy_authority_references_in_active_contract_files():
|
||||
"""Active contracts must not route authority through removed V4 revision trees."""
|
||||
violations: dict[str, list[str]] = {}
|
||||
for relative_path in ACTIVE_CONTRACT_FILES:
|
||||
text = _read(relative_path)
|
||||
found = [marker for marker in LEGACY_REFERENCE_MARKERS if marker in text]
|
||||
if found:
|
||||
violations[relative_path] = found
|
||||
assert violations == {}
|
||||
|
||||
|
||||
def test_canonical_authority_references_are_present():
|
||||
"""Critical instruction and skill files must keep canonical references explicit."""
|
||||
required_fragments = {
|
||||
".github/instructions/services.instructions.md": (
|
||||
"docs/ver4/",
|
||||
"./error-handling.instructions.md",
|
||||
"src/transcription/db/models.py",
|
||||
"docs/ver4/schema_v4.md",
|
||||
"append-only",
|
||||
),
|
||||
".github/instructions/ui.instructions.md": (
|
||||
"docs/ver4/",
|
||||
"./error-handling.instructions.md",
|
||||
"src/transcription/db/models.py",
|
||||
"docs/ver4/schema_v4.md",
|
||||
),
|
||||
".github/instructions/error-handling.instructions.md": (
|
||||
"docs/ver4/error_handling_v4.md",
|
||||
"docs/ver4/requirements_v4.md",
|
||||
),
|
||||
".github/skills/python-code-reviewer/skill.md": (
|
||||
"docs/ver4/*",
|
||||
"docs/ver4/schema_v4.md",
|
||||
".github/instructions/error-handling.instructions.md",
|
||||
),
|
||||
".github/skills/evidence-provenance-auditor/skill.md": (
|
||||
"docs/ver4/schema_v4.md",
|
||||
"docs/ver4/requirements_v4.md",
|
||||
"docs/ver4/error_handling_v4.md",
|
||||
),
|
||||
}
|
||||
|
||||
missing: dict[str, list[str]] = {}
|
||||
for relative_path, fragments in required_fragments.items():
|
||||
text = _read(relative_path)
|
||||
absent = [fragment for fragment in fragments if fragment not in text]
|
||||
if absent:
|
||||
missing[relative_path] = absent
|
||||
assert missing == {}
|
||||
Reference in New Issue
Block a user