将角色与 Skill 从 .claude 迁入 .agent,移除 Claude CLI 运行时并接入固定 Opus 角色 profile、完整 schema、预算 deadline、raw 与回执证据链。 同步拆分 Skill 职责、复利 lesson、Gate 回放、Dashboard 人审入口、数据库登记和机械门禁;候选设计正文不包含在本提交中。
69 lines
2.5 KiB
Python
69 lines
2.5 KiB
Python
#!/usr/bin/env python3
|
||
"""细纲库读统一消费点回归:load_confirmed_fine_outline 的取数合同(不连真库,用桩连接)。"""
|
||
|
||
import pathlib
|
||
import sys
|
||
import unittest
|
||
|
||
PROJECT_ROOT = pathlib.Path(__file__).resolve().parents[3]
|
||
SCRIPT_DIR = PROJECT_ROOT / ".agent" / "skills" / "assemble-context" / "scripts"
|
||
sys.path.insert(0, str(SCRIPT_DIR))
|
||
|
||
from retrieve_writer_sources import RetrievalError, load_confirmed_fine_outline # noqa: E402
|
||
|
||
|
||
class FakeCursor:
|
||
def __init__(self, row):
|
||
self._row = row
|
||
|
||
def fetchone(self):
|
||
return self._row
|
||
|
||
|
||
class FakeConn:
|
||
"""记录 SQL 与参数,按预设行返回,模拟 db skill 连接的 execute/fetchone 接口。"""
|
||
|
||
def __init__(self, row):
|
||
self._row = row
|
||
self.sql = None
|
||
self.params = None
|
||
|
||
def execute(self, sql, params=None):
|
||
self.sql = sql
|
||
self.params = params
|
||
return FakeCursor(self._row)
|
||
|
||
|
||
class FineOutlineReaderTest(unittest.TestCase):
|
||
def test_returns_dict_payload_and_uses_confirmed_latest_contract(self):
|
||
conn = FakeConn(({"targetChapter": 3, "chapterGoal": "x"},))
|
||
result = load_confirmed_fine_outline(conn, work_id=12, target_chapter=3)
|
||
self.assertEqual(result["targetChapter"], 3)
|
||
# 取数合同:fine_outline + confirmed + 未删 + version 倒序取最新。
|
||
self.assertIn("section_type='fine_outline'", conn.sql)
|
||
self.assertIn("state='confirmed'", conn.sql)
|
||
self.assertIn("deleted=false", conn.sql)
|
||
self.assertIn("ORDER BY version DESC LIMIT 1", conn.sql)
|
||
self.assertEqual(conn.params, (12, 3))
|
||
|
||
def test_parses_jsonb_returned_as_string(self):
|
||
conn = FakeConn(('{"targetChapter": 5, "chapterGoal": "y"}',))
|
||
result = load_confirmed_fine_outline(conn, work_id=12, target_chapter=5)
|
||
self.assertEqual(result, {"targetChapter": 5, "chapterGoal": "y"})
|
||
|
||
def test_missing_confirmed_outline_fails_closed(self):
|
||
conn = FakeConn(None)
|
||
with self.assertRaises(RetrievalError) as ctx:
|
||
load_confirmed_fine_outline(conn, work_id=12, target_chapter=9)
|
||
self.assertIn("已确认细纲", str(ctx.exception))
|
||
|
||
def test_illegal_payload_fails_closed(self):
|
||
for bad in (None, "{}", "[]", '"str"'):
|
||
conn = FakeConn((bad,))
|
||
with self.assertRaises(RetrievalError):
|
||
load_confirmed_fine_outline(conn, work_id=12, target_chapter=3)
|
||
|
||
|
||
if __name__ == "__main__":
|
||
unittest.main()
|