zizi 091b66a9bb 重构: 收敛 Agent/Skill 运行时与创作质量闭环
将角色与 Skill 从 .claude 迁入 .agent,移除 Claude CLI 运行时并接入固定 Opus 角色 profile、完整 schema、预算 deadline、raw 与回执证据链。

同步拆分 Skill 职责、复利 lesson、Gate 回放、Dashboard 人审入口、数据库登记和机械门禁;候选设计正文不包含在本提交中。
2026-08-22 02:12:32 +08:00

75 lines
2.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
"""文风取数端回归:load_confirmed_style / derive_style_constraints(桩连接,不连真库)。
read-context 的文风取数端,与细纲/范式取数端并排成一等公民。优先独立 style 规划行,
回退设定行的 style 字段(书12 现状为一句话 blob)。结构化画像抽取仍待建。
"""
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 derive_style_constraints, load_confirmed_style # noqa: E402
class FakeCursor:
def __init__(self, row):
self._row = row
def fetchone(self):
return self._row
class FakeConn:
"""按 SQL 区分两次查询:schema_type='style' 的独立文风行 / section_type='setting' 的设定行。"""
def __init__(self, style_row=None, setting_row=None):
self.style_row = style_row
self.setting_row = setting_row
def execute(self, sql, params=None):
if "schema_type='style'" in sql:
return FakeCursor(self.style_row)
if "section_type='setting'" in sql:
return FakeCursor(self.setting_row)
return FakeCursor(None)
class DeriveStyleTest(unittest.TestCase):
def test_blob_becomes_single_constraint(self):
self.assertEqual(derive_style_constraints("冷峻、克制、微恐。"), ["冷峻、克制、微恐。"])
def test_structured_dict_projects_per_aspect(self):
self.assertEqual(
derive_style_constraints({"叙事人称": "第三人称限制视角", "AI味黑名单": "禁 仿佛/似乎", "达标样张": ""}),
["叙事人称:第三人称限制视角", "AI味黑名单:禁 仿佛/似乎"],
)
def test_blank_and_illegal_return_empty(self):
self.assertEqual(derive_style_constraints(" "), [])
self.assertEqual(derive_style_constraints(None), [])
self.assertEqual(derive_style_constraints(42), [])
class LoadConfirmedStyleTest(unittest.TestCase):
def test_prefers_dedicated_style_section(self):
conn = FakeConn(style_row=('{"叙事人称": "第三人称"}',),
setting_row=('{"style": "不该用到我"}',))
self.assertEqual(load_confirmed_style(conn, work_id=12), ["叙事人称:第三人称"])
def test_falls_back_to_setting_style_field(self):
conn = FakeConn(style_row=None, setting_row=('{"title": "深渊机神", "style": "冷峻克制"}',))
self.assertEqual(load_confirmed_style(conn, work_id=12), ["冷峻克制"])
def test_no_confirmed_style_returns_empty(self):
conn = FakeConn(style_row=None, setting_row=None)
self.assertEqual(load_confirmed_style(conn, work_id=12), [])
if __name__ == "__main__":
unittest.main()