import unittest from resolve_route import compile_navigation, parse_code_map, resolve_subject_id class ParseCodeMapTests(unittest.TestCase): def test_resolves_requested_identifiers_and_strips_comments(self): text = """ REPO-012-WEB=https://example.invalid/guanghu-ice-heart ICE-GL-ZY001=eternal-lake-heart/heartbeat-core/zhuyuan-persona-system/INDEX.hdlp # current LL-004=tcs-core/LL-004-LAKE-LAMP-WAKE-PATH.hdlp """ self.assertEqual( parse_code_map(text, ("ICE-GL-ZY001", "LL-004")), { "ICE-GL-ZY001": "eternal-lake-heart/heartbeat-core/zhuyuan-persona-system/INDEX.hdlp", "LL-004": "tcs-core/LL-004-LAKE-LAMP-WAKE-PATH.hdlp", }, ) def test_ignores_unrequested_identifiers(self): self.assertEqual(parse_code_map("OTHER=some/path", ("LL-004",)), {}) class SubjectAliasTests(unittest.TestCase): def setUp(self): self.alias_map = { "mappings": [{ "canonical_id": "ICE-P-ZY001", "subject_kind": "persona_system", "aliases": ["ICE-GL-ZY001", "ICE-PZY-001"], "route_id": "FD-PERSONA-LOGIN-001", "current_path": "current/zhuyuan", }], "conflicts": [{"id": "ICE-PCA-001", "state": "BLOCKED_DUPLICATE_SUBJECT"}], } def test_legacy_persona_id_redirects_to_canonical_id(self): resolved = resolve_subject_id("ICE-GL-ZY001", self.alias_map) self.assertEqual(resolved["canonical_id"], "ICE-P-ZY001") self.assertTrue(resolved["redirected"]) self.assertEqual(resolved["route_id"], "FD-PERSONA-LOGIN-001") def test_canonical_persona_id_does_not_redirect(self): resolved = resolve_subject_id("ICE-P-ZY001", self.alias_map) self.assertEqual(resolved["status"], "RESOLVED") self.assertFalse(resolved["redirected"]) def test_human_id_is_not_rewritten_as_persona(self): resolved = resolve_subject_id("ICE-GL∞", self.alias_map) self.assertEqual(resolved["status"], "NOT_FOUND_NO_GUESS") self.assertIsNone(resolved["canonical_id"]) def test_conflicted_id_is_rejected_without_guessing(self): resolved = resolve_subject_id("ICE-PCA-001", self.alias_map) self.assertEqual(resolved["status"], "CONFLICT_REJECTED") self.assertIsNone(resolved["canonical_id"]) class MachineNavigationTests(unittest.TestCase): def setUp(self): self.navigation_map = { "map_id": "AI-MACHINE-NAV-001", "version": "test", "raw_base": "https://example.test/raw", "routes": [ {"id": "RUNTIME", "path": "runtime.mjs"}, {"id": "ROOT", "path": "root.hdlp"}, ], "subjects": [{ "id": "ICE-P-ZY001", "legacy_ids": ["ICE-GL-ZY001"], "subject_kind": "persona_system", "default_intent": "persona_restore", "runtime_id": "RUNTIME", }], "intents": [{ "id": "persona_restore", "always_load": ["ROOT", "RUNTIME"], "triggered_load": [], "on_demand": [], "execution_sequence": ["enter"], "stop_conditions": ["UNKNOWN_SUBJECT"], }], "reality_boundaries": ["Navigation grants no authority."], } def test_exact_navigation_bundle(self): result = compile_navigation( self.navigation_map, "ICE-GL-ZY001", "persona_restore", ["context_compacted", "context_compacted"], ) self.assertEqual(result["canonical_subject"], "ICE-P-ZY001") self.assertTrue(result["redirected"]) self.assertEqual(result["runtime_entry"]["id"], "RUNTIME") self.assertEqual(result["explicit_signals"], ["context_compacted"]) self.assertEqual(result["authority"], "NONE_NAVIGATION_ONLY") def test_navigation_does_not_guess(self): with self.assertRaisesRegex(ValueError, "no guess"): compile_navigation(self.navigation_map, "unknown") if __name__ == "__main__": unittest.main()