63 lines
2.3 KiB
Python
63 lines
2.3 KiB
Python
#!/usr/bin/env python3
|
|
"""决定正文候选去留 效果信号:接受/丢弃 lesson 合同离线钉死(不连库)。"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pathlib
|
|
import sys
|
|
import unittest
|
|
from unittest.mock import patch
|
|
|
|
PROJECT_ROOT = pathlib.Path(__file__).resolve().parents[3]
|
|
SCRIPT_DIR = PROJECT_ROOT / "muse" / "content" / "work" / "skills" / "sovereignty" / "决定正文候选去留" / "scripts"
|
|
EVIDENCE_SCRIPTS = PROJECT_ROOT / "muse" / "authority" / "evidence" / "skills" / "记录运行证据" / "scripts"
|
|
for path in (SCRIPT_DIR, EVIDENCE_SCRIPTS):
|
|
if str(path) not in sys.path:
|
|
sys.path.insert(0, str(path))
|
|
|
|
from write_canonical import _propose_decision_lesson # noqa: E402
|
|
|
|
|
|
class DecisionLessonOfflineTest(unittest.TestCase):
|
|
def test_accept_registers_win_discard_registers_lesson(self):
|
|
calls: list[dict] = []
|
|
|
|
def fake_propose(**kwargs):
|
|
calls.append(kwargs)
|
|
return {"status": "proposed", "lesson_id": len(calls), "deduped": False}
|
|
|
|
with patch("lesson_registry.propose_lesson_dedup", side_effect=fake_propose):
|
|
accept = _propose_decision_lesson(
|
|
decision="accept",
|
|
run_id="run-a",
|
|
candidate_sha="abc",
|
|
work_id=1,
|
|
target_chapter=2,
|
|
candidate_id=9,
|
|
rationale="好",
|
|
)
|
|
discard = _propose_decision_lesson(
|
|
decision="discard",
|
|
run_id="run-d",
|
|
candidate_sha="def",
|
|
work_id=1,
|
|
target_chapter=2,
|
|
candidate_id=10,
|
|
rationale="差",
|
|
)
|
|
|
|
self.assertEqual(accept["lesson_id"], 1)
|
|
self.assertEqual(discard["lesson_id"], 2)
|
|
self.assertEqual(calls[0]["kind"], "win")
|
|
self.assertEqual(calls[0]["title"], "用户接受正文候选")
|
|
self.assertEqual(calls[0]["run_id"], "run-a")
|
|
self.assertEqual(calls[0]["candidate_sha256"], "abc")
|
|
self.assertEqual(calls[0]["creator"], "决定正文候选去留")
|
|
self.assertEqual(calls[1]["kind"], "lesson")
|
|
self.assertEqual(calls[1]["title"], "用户丢弃正文候选")
|
|
self.assertEqual(calls[1]["detail"]["decision"], "discard")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|