- 新增 write_craft.md 品类无关写章 craft 内核(网文语域/show-don't-tell/对话 voice/ 反注水/结构性文字质感,灵活原则非穷举清单)+ load_craft_doctrine()(import 期读盘, 不入 SPECS/金标准) - build_write_request 把 craft 教条作为最前的 cache=True system 块注入(craft→stable_core, 守缓存前缀 #9,tier=writer 不写 model) - 新增 packages/config GENRE_CRAFT 题材片段表,assemble 按 project.genre 注入 stable_core; ProjectSpecView + SqlProjectSpecRepo 透传 genre - 开篇前 3 章在 volatile 注入黄金三章提示(含章号→每章易变,不进缓存前缀) - 修正 toolbox_registry 注释:11 条 → 15 条(legacy 3 + 新 8 + Scope B 4)
44 lines
1.5 KiB
Python
44 lines
1.5 KiB
Python
"""写章 craft 教条加载器单测(灵感①)。
|
||
|
||
`load_craft_doctrine()` import 期读盘 `prompts/write_craft.md`(仿 load_prompt),
|
||
主写章不在 SPECS、不进 prompt_hashes 金标准。文件缺失应 fail-fast(崩 import)。
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
import hashlib
|
||
|
||
from ww_agents import load_craft_doctrine
|
||
|
||
|
||
def _sha256(text: str) -> str:
|
||
return hashlib.sha256(text.encode("utf-8")).hexdigest()
|
||
|
||
|
||
def test_load_craft_doctrine_returns_nonempty_text() -> None:
|
||
# Act
|
||
doctrine = load_craft_doctrine()
|
||
# Assert
|
||
assert isinstance(doctrine, str)
|
||
assert doctrine.strip()
|
||
|
||
|
||
def test_load_craft_doctrine_is_byte_stable() -> None:
|
||
# 稳定缓存前缀(不变量 #9):两次读盘字节完全一致。
|
||
assert _sha256(load_craft_doctrine()) == _sha256(load_craft_doctrine())
|
||
|
||
|
||
def test_craft_doctrine_covers_core_principles() -> None:
|
||
# 品类无关内核应覆盖:show-don't-tell / 对话个性化 / 反注水(按情节功能分配字数)。
|
||
doctrine = load_craft_doctrine()
|
||
assert "反注水" in doctrine or "注水" in doctrine
|
||
assert "对话" in doctrine
|
||
assert "情节功能" in doctrine
|
||
|
||
|
||
def test_craft_doctrine_is_genre_agnostic() -> None:
|
||
# 品类无关内核不应写死具体题材名(题材片段归 GENRE_CRAFT)。
|
||
doctrine = load_craft_doctrine()
|
||
for genre in ("玄幻", "仙侠", "都市"):
|
||
assert genre not in doctrine, f"品类无关内核不应含题材名 {genre!r}"
|