muse-agent-example/.claude/skills/read-context/scripts/test_fine_outline_reader.py
zizi 952485a506 框架: 前期创作流程代码——细纲统一合同+字段覆盖门禁+文风/范式注入+取数端统一
修五个硬伤,让"前期准备"从文档纪律变成机械门禁,并补齐写作链上游注入:
- 细纲合同合一:新建 meta/schemas/fine_outline.yaml 作唯一字段权威(必填9+推荐7),
  统一此前 planning 产出形与 writer 装配消费形两套不相交字段;fine-outline 技能对齐。
- 落库字段覆盖门禁:persist_planning 按 schema 校验必填字段,缺必填失败关闭,
  「字段存疑」逃生口;只对声明「字段覆盖门禁:强制」的型生效(fine_outline 已强制)。
- 文风真注入:WriterContext 增可选 styleConstraints(空则省键、上下文逐字节不变),
  装配投影给 writer,不再写死为空。
- 范式规划期绑定:read-context load_confirmed_pattern_bindings 只读已确认 assembly 绑定
  (实验仓承载,确认即绑定,不改主仓表);生产脚本注入已绑定范式。
- 取数端统一:read-context 三个一等取数端(细纲/范式/文风),生产编排 step2 接线,
  已确认细纲不再人肉读库传参。
- harness:AGENTS.md 第9节新增「提交前必须独立子代理形而上四维审查」硬规则。
(writer_contract/retrieve 含上一会话 asOf=0 开篇冻结线改动,同属创作链修复,随本笔提交。)

测试:9 套全绿(合同6/门禁8/装配17/writer_contract21/检索11/统一3/细纲读取4/范式读取5/文风读取6)。
2026-08-02 02:17:14 +08:00

67 lines
2.3 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
"""细纲库读统一消费点回归:load_confirmed_fine_outline 的取数合同(不连真库,用桩连接)。"""
import pathlib
import sys
import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent))
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()