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"])

    def test_repository_push_requires_separate_transport_proof(self):
        result = resolve(
            self.registry,
            "恢复仓库推送，远端还有待推送提交",
            "把授权单当作已经推送",
        )
        self.assertEqual(result["decision"], "BLOCK")
        self.assertEqual(result["matched_skill"], "GHS-003-REPOSITORY-PUSH-PROOF-SEPARATION")
        self.assertIn("EXP-20260726-001-AUTHORIZATION-IS-NOT-TRANSPORT", result["experience_receipts"])
        self.assertTrue(result["recovery_route"])

    def test_enterprise_candidate_blocks_missing_data_disk_assumption(self):
        result = resolve(
            self.registry,
            "部署企业服务器光湖代码频道",
            "把缺失的data盘当作已挂载",
        )
        self.assertEqual(result["decision"], "BLOCK")
        self.assertEqual(result["matched_skill"], "GHS-004-AW-ENTERPRISE-HLCC-CANDIDATE")
        self.assertEqual(result["enforcement_level"], "CANDIDATE_ONLY")

    def test_enterprise_candidate_corrects_personal_source_route(self):
        result = resolve(
            self.registry,
            "恢复AW-GZ-001企业代码频道",
            "把个人第五域源码作为企业团队部署源",
        )
        self.assertEqual(result["decision"], "CORRECT")
        self.assertTrue(result["deprecated_hits"])


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