muse-agent-example/tests/skills/write-next-chapter/test_writer_lesson_offline.py

49 lines
1.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""write-next-chapter:生产落库 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" / "content" / "work" / "skills" / "generate" / "write-next-chapter" / "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 persist_writer_run import _propose_writer_lesson # noqa: E402
class WriterLessonOfflineTest(unittest.TestCase):
def test_pass_and_fail_titles(self):
calls: list[dict] = []
def fake(**kwargs):
calls.append(kwargs)
return {"status": "proposed", "lesson_id": len(calls), "deduped": False}
with patch("persist_writer_run.propose_lesson_dedup", side_effect=fake):
_propose_writer_lesson(
run_id="w1", work_id=1, target_chapter=2, passed=True,
semantic_status="passed", mechanical_report={}, candidate_sha="aa",
)
_propose_writer_lesson(
run_id="w2", work_id=1, target_chapter=2, passed=False,
semantic_status="failed",
mechanical_report={"blockingFailures": ["x"]},
candidate_sha="bb",
)
self.assertEqual(calls[0]["kind"], "win")
self.assertEqual(calls[0]["title"], "正文生产机械门通过")
self.assertEqual(calls[1]["kind"], "lesson")
self.assertEqual(calls[1]["title"], "正文生产机械门未通过")
self.assertEqual(calls[1]["detail"]["blocking_failures"], ["x"])
if __name__ == "__main__":
unittest.main()