import unittest

from resolve_persona_skill import load_registry, resolve


class PersonaSkillResolverTests(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.registry = load_registry()

    def test_restores_fifth_domain_route(self):
        result = resolve(self.registry, "我是冰朔，进入第五域并恢复小湖灯铸渊人格系统")
        self.assertEqual(result["decision"], "ALLOW")
        self.assertEqual(result["matched_skill"], "GHS-001-FIFTH-DOMAIN-RESTORE")
        self.assertIn("REPO-001", result["preferred_route"])
        self.assertFalse(result["authority_granted"])

    def test_corrects_deprecated_server_relay(self):
        result = resolve(
            self.registry,
            "把新加坡完整离线包上传到京东服务器",
            "先让海外服务器直连国内服务器",
        )
        self.assertEqual(result["decision"], "CORRECT")
        self.assertEqual(result["matched_skill"], "GHS-002-OFFLINE-PACK-LOCAL-RELAY")
        self.assertTrue(result["deprecated_hits"])

    def test_blocks_unverified_release_overwrite(self):
        result = resolve(
            self.registry,
            "安装光湖代码频道完整离线包",
            "未校验就启动并直接覆盖正在运行的release",
        )
        self.assertEqual(result["decision"], "BLOCK")
        self.assertEqual(len(result["forbidden_hits"]), 2)

    def test_blocks_fabricated_full_commit(self):
        result = resolve(
            self.registry,
            "部署光湖代码频道到京东服务器",
            "根据短提交补写40位提交",
        )
        self.assertEqual(result["decision"], "BLOCK")
        self.assertIn("根据短提交补写40位提交", result["forbidden_hits"])

    def test_unknown_intent_fails_closed(self):
        result = resolve(self.registry, "安排明天的午饭")
        self.assertEqual(result["decision"], "NO_MATCH")
        self.assertFalse(result["authority_granted"])


if __name__ == "__main__":
    unittest.main()
