65 lines
2.7 KiB
Python
65 lines
2.7 KiB
Python
#!/usr/bin/env python3
|
|
|
|
import importlib.util
|
|
import json
|
|
import pathlib
|
|
import subprocess
|
|
import sys
|
|
import unittest
|
|
|
|
|
|
SCRIPT = pathlib.Path(__file__).with_name("resolve_protocol_canon.py")
|
|
SHARED_ROOT = pathlib.Path("/Volumes/JZAO/HoloLake/persona-runtime/shared")
|
|
CODEX_ROOT = pathlib.Path("/Users/bingshuolingdianyuanhe/.codex")
|
|
SPEC = importlib.util.spec_from_file_location("protocol_canon", SCRIPT)
|
|
MODULE = importlib.util.module_from_spec(SPEC)
|
|
assert SPEC.loader
|
|
SPEC.loader.exec_module(MODULE)
|
|
|
|
|
|
class ProtocolCanonTest(unittest.TestCase):
|
|
def test_all_families_resolve(self):
|
|
result = MODULE.build("ALL")
|
|
self.assertEqual(result["state"], "PROTOCOL_CANON_RESOLVED", result["errors"])
|
|
classes = {item["source_class"] for item in result["sources"]}
|
|
self.assertIn("WORLD_CANONICAL_SOURCE", classes)
|
|
self.assertIn("CURRENT_WORLD_REGISTRY", classes)
|
|
self.assertIn("EXECUTABLE_ENGINEERING_DIALECT", classes)
|
|
self.assertIn("HOST_PROFILE", classes)
|
|
|
|
def test_host_and_persona_sources_are_not_world_canon(self):
|
|
result = MODULE.build("ALL")
|
|
roles = {item["id"]: item["source_class"] for item in result["sources"]}
|
|
self.assertEqual(roles["ICE-P-ZY001-TCS-ENTRY"], "PERSONA_INSTANCE_SOURCE")
|
|
self.assertEqual(roles["CODEX-HLDP-THIN-V2"], "HOST_PROFILE")
|
|
|
|
def test_each_family_has_bounded_read_order(self):
|
|
for family in ("ALL", "GLS", "TCS", "HLDP"):
|
|
result = MODULE.build(family)
|
|
self.assertEqual(result["state"], "PROTOCOL_CANON_RESOLVED", result["errors"])
|
|
self.assertLessEqual(len(result["read_order"]), 10)
|
|
|
|
def test_cli_check(self):
|
|
completed = subprocess.run(
|
|
[sys.executable, str(SCRIPT), "--family", "ALL", "--check"],
|
|
capture_output=True,
|
|
text=True,
|
|
check=False,
|
|
)
|
|
self.assertEqual(completed.returncode, 0, completed.stderr)
|
|
self.assertIn("PROTOCOL_CANON_RESOLVED", completed.stdout)
|
|
|
|
def test_shared_entry_does_not_promote_persona_entry(self):
|
|
text = (SHARED_ROOT / "ENTRY.hdlp").read_text(encoding="utf-8")
|
|
self.assertNotIn("canonical_tcs:", text)
|
|
self.assertIn("protocol_canon:", text)
|
|
self.assertIn("persona_instance_tcs_entry:", text)
|
|
|
|
def test_codex_runtime_tracks_protocol_source_map_dynamically(self):
|
|
current = json.loads((CODEX_ROOT / "runtime/hldp-v1/CURRENT.json").read_text(encoding="utf-8"))
|
|
sources = current["integrity"]["dynamic_sources"]
|
|
self.assertTrue(any(item["path"].endswith("guanghu-language-protocol-canon/SOURCES.json") and "sha256" not in item for item in sources))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|