67 lines
2.5 KiB
Python
67 lines
2.5 KiB
Python
#!/usr/bin/env python3
|
||
"""decide-candidate:accept 授权下游草稿自动;转正式仍须人。"""
|
||
|
||
from __future__ import annotations
|
||
|
||
import ast
|
||
import pathlib
|
||
import sys
|
||
import unittest
|
||
|
||
ROOT = pathlib.Path(__file__).resolve().parents[3]
|
||
SCRIPT = ROOT / "muse" / "content" / "work" / "skills" / "sovereignty" / "decide-candidate" / "scripts"
|
||
if str(SCRIPT) not in sys.path:
|
||
sys.path.insert(0, str(SCRIPT))
|
||
|
||
from write_canonical import next_steps_after_decision # noqa: E402
|
||
|
||
|
||
class NextStepsOfflineTest(unittest.TestCase):
|
||
def test_accept_authorizes_draft_auto(self):
|
||
steps = next_steps_after_decision(
|
||
decision="accept", work_id=12, target_chapter=3, candidate_id=37,
|
||
)
|
||
self.assertTrue(steps)
|
||
by_id = {s["id"]: s for s in steps}
|
||
self.assertIn("read_canonical", by_id)
|
||
self.assertFalse(by_id["read_canonical"]["auto"])
|
||
extract = by_id["extract_chapter_knowledge"]
|
||
self.assertTrue(extract["auto"])
|
||
self.assertEqual(extract.get("requires"), "confirm_to_promote")
|
||
flavor = by_id["ai_flavor_followup"]
|
||
self.assertTrue(flavor["auto"])
|
||
self.assertEqual(flavor.get("requires"), "confirm_to_promote")
|
||
# 下一章规划仍须人授权
|
||
self.assertFalse(by_id["next_chapter_planning"]["auto"])
|
||
self.assertEqual(by_id["next_chapter_planning"].get("requires"), "human_authorize")
|
||
|
||
def test_discard_steps(self):
|
||
steps = next_steps_after_decision(
|
||
decision="discard", work_id=12, target_chapter=3, candidate_id=37,
|
||
)
|
||
self.assertTrue(any(s["id"] == "read_discard" for s in steps))
|
||
self.assertTrue(all(s.get("auto") is False for s in steps))
|
||
|
||
def test_generation_entry_cannot_call_accept(self):
|
||
source = (ROOT / "muse" / "content" / "work" / "skills" / "generate" / "write-next-chapter" / "scripts" / "produce_next_chapter.py").read_text(
|
||
encoding="utf-8"
|
||
)
|
||
tree = ast.parse(source)
|
||
imported_accept = any(
|
||
isinstance(node, ast.ImportFrom)
|
||
and any(alias.name == "accept" for alias in node.names)
|
||
for node in ast.walk(tree)
|
||
)
|
||
accept_calls = [
|
||
node for node in ast.walk(tree)
|
||
if isinstance(node, ast.Call)
|
||
and isinstance(node.func, ast.Name)
|
||
and node.func.id == "accept"
|
||
]
|
||
self.assertFalse(imported_accept)
|
||
self.assertEqual(accept_calls, [])
|
||
|
||
|
||
if __name__ == "__main__":
|
||
unittest.main()
|