72 lines
2.6 KiB
Python
72 lines
2.6 KiB
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
RUNTIME = ROOT / "harness/runtime"
|
|
sys.path.insert(0, str(RUNTIME))
|
|
import active_structure_check # noqa: E402
|
|
|
|
|
|
class ActiveStructureCheckTest(unittest.TestCase):
|
|
def test_repository_active_documents_pass(self) -> None:
|
|
result = active_structure_check.check(ROOT)
|
|
self.assertEqual(result["status"], "PASS")
|
|
expected = len(list((ROOT / "raw/branch-notes").glob("*.md"))) + len(
|
|
list((ROOT / "raw/project-notes").glob("*.md"))
|
|
)
|
|
self.assertEqual(result["checked"], expected)
|
|
|
|
def test_missing_checker_is_environment_error(self) -> None:
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
with self.assertRaises((active_structure_check.ActiveStructureError, FileNotFoundError)):
|
|
active_structure_check.check(Path(directory))
|
|
|
|
def test_canonical_mode_selects_manifest_owner_not_legacy_stub(self) -> None:
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
root = Path(directory)
|
|
canonical = root / "vault/10-projects/demo/branch-notes/feature-x.md"
|
|
canonical.parent.mkdir(parents=True)
|
|
canonical.write_text("canonical", encoding="utf-8")
|
|
stub = root / "raw/branch-notes/feature-x.md"
|
|
stub.parent.mkdir(parents=True)
|
|
stub.write_text("stub", encoding="utf-8")
|
|
checker = root / ".claude/hooks/wiki_structure_lint.py"
|
|
checker.parent.mkdir(parents=True)
|
|
checker.write_text(
|
|
"""
|
|
def authority_mapping(root):
|
|
return {
|
|
'mode': 'canonical',
|
|
'legacy_to_canonical': {
|
|
'raw/branch-notes/feature-x.md':
|
|
'vault/10-projects/demo/branch-notes/feature-x.md'
|
|
},
|
|
}
|
|
|
|
def build_template_index(root): return {}, {}
|
|
def build_vault_index(root): return set(), {}
|
|
def classify(relative, root): return 'full'
|
|
|
|
def lint_file(path, root, *args, **kwargs):
|
|
expected = root / 'vault/10-projects/demo/branch-notes/feature-x.md'
|
|
if path != expected:
|
|
return [('WRONG_AUTHORITY', 0, str(path))], 'branch-note'
|
|
return [], 'branch-note'
|
|
""",
|
|
encoding="utf-8",
|
|
)
|
|
result = active_structure_check.check(root)
|
|
self.assertEqual(result["status"], "PASS")
|
|
self.assertEqual(result["mode"], "canonical")
|
|
self.assertEqual(result["namespace"], "canonical")
|
|
self.assertEqual(result["checked"], 1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|