#!/usr/bin/env python3 """prevent-ai-flavor:预防合同 lesson 离线钉死。""" from __future__ import annotations import pathlib import sys import unittest from unittest.mock import patch ROOT = pathlib.Path(__file__).resolve().parents[3] SCRIPT = ROOT / "muse" / "lifecycle" / "quality" / "humanization" / "skills" / "prevent-ai-flavor" / "scripts" EVIDENCE = ROOT / "muse" / "authority" / "evidence" / "skills" / "record-run-evidence" / "scripts" for path in (SCRIPT, EVIDENCE): if str(path) not in sys.path: sys.path.insert(0, str(path)) from prevent_ai_flavor import _propose_prevention_lesson # noqa: E402 class PreventLessonOfflineTest(unittest.TestCase): def test_registers_win(self): calls: list[dict] = [] def fake(**kwargs): calls.append(kwargs) return {"status": "proposed", "lesson_id": 1, "deduped": False} contract = { "work_ref": "work:1", "built_from": { "active_rule_count": 3, "rule_library_version": "v1", "voice_ledger_sha256": "a" * 64, }, } with patch("lesson_registry.propose_lesson_dedup", side_effect=fake): out = _propose_prevention_lesson(run_id="prev-1", contract=contract) self.assertEqual(out["lesson_id"], 1) self.assertEqual(calls[0]["kind"], "win") self.assertEqual(calls[0]["title"], "生成前 AI 味预防合同已装配") self.assertEqual(calls[0]["creator"], "prevent-ai-flavor") if __name__ == "__main__": unittest.main()