import importlib.util import json from pathlib import Path import tempfile import unittest ROOT = Path(__file__).resolve().parents[1] SPEC = importlib.util.spec_from_file_location("language_system", ROOT / "scripts/language_system.py") MODULE = importlib.util.module_from_spec(SPEC) SPEC.loader.exec_module(MODULE) PUBLIC_SPEC = importlib.util.spec_from_file_location("public_language_system", ROOT / "scripts/public_language_system.py") PUBLIC_MODULE = importlib.util.module_from_spec(PUBLIC_SPEC) PUBLIC_SPEC.loader.exec_module(PUBLIC_MODULE) class LanguageSystemTests(unittest.TestCase): def test_private_and_public_materialize_and_verify(self): with tempfile.TemporaryDirectory() as directory: base = Path(directory) private = base / "private" public = base / "public" MODULE.build(ROOT / "system/fifth-domain-system.json", private, "fifth-domain") MODULE.build(ROOT / "system/public-four-domain-template.json", public, "enterprise-four-domain") self.assertEqual(MODULE.verify(private)["outcome"], "PASS") self.assertEqual(MODULE.verify(public)["outcome"], "PASS") self.assertEqual(len(list(public.glob("*/NODE.json"))), 4) def test_public_private_marker_rejected(self): value = MODULE.load_json(ROOT / "system/public-four-domain-template.json") value["responsible_human_members"] = "ICE-GL∞" with self.assertRaisesRegex(ValueError, "private markers leaked"): MODULE.validate_public(value) def test_standalone_public_materializer(self): with tempfile.TemporaryDirectory() as directory: output = Path(directory) / "public" PUBLIC_MODULE.build(ROOT / "system/public-four-domain-template.json", output) self.assertEqual(PUBLIC_MODULE.verify(output)["outcome"], "PASS") value = MODULE.load_json(ROOT / "system/public-four-domain-template.json") value["responsible_human_members"] = "ICE-PRIVATE" with self.assertRaisesRegex(ValueError, "pending|private"): PUBLIC_MODULE.validate(value) def test_tamper_rejected(self): with tempfile.TemporaryDirectory() as directory: output = Path(directory) / "private" MODULE.build(ROOT / "system/fifth-domain-system.json", output, "fifth-domain") world = json.loads((output / "WORLD.json").read_text()) world["flavor"] = "tampered" (output / "WORLD.json").write_text(json.dumps(world)) with self.assertRaisesRegex(ValueError, "mismatch"): MODULE.verify(output) def test_meta_audit(self): result = MODULE.meta_audit( ROOT / "system/fifth-domain-system.json", ROOT / "system/public-four-domain-template.json", ROOT / "system/legacy-route-map.json", ) self.assertEqual(result["outcome"], "PASS") self.assertEqual(result["yaoming_current_id"], "ICE-BB-0001") self.assertEqual(result["guanghu_team_reality_controller"], True) self.assertEqual(result["hololake_embeds_enterprise_domains"], False) def test_enterprise_portal_and_private_fifth_domain_stay_separate(self): value = MODULE.load_json(ROOT / "system/public-four-domain-template.json") self.assertEqual(value["carrier"], "ENTERPRISE_PORTAL") self.assertFalse(value["embedded_in_hololake"]) self.assertFalse(value["fifth_domain"]["embedded"]) self.assertFalse(next(item for item in value["domains"] if item["id"] == "DOMAIN-ZS")["public_access"]) if __name__ == "__main__": unittest.main()