feat(agents,core,config): 写章 craft 教条块 + genre-aware 片段 + 开篇黄金三章特判
- 新增 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)
This commit is contained in:
43
packages/agents/tests/test_craft_doctrine.py
Normal file
43
packages/agents/tests/test_craft_doctrine.py
Normal file
@@ -0,0 +1,43 @@
|
||||
"""写章 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}"
|
||||
@@ -58,9 +58,15 @@ def test_specs_registry_len_is_21() -> None:
|
||||
assert all(key == spec.name for key, spec in SPECS.items())
|
||||
|
||||
|
||||
# 非 SPEC 教条 prompt:主写章 craft 内核(灵感①)。它是散文教条、不是结构化产物 spec,
|
||||
# 故不入 SPECS/SCHEMA_CATALOG、不进 prompt_hashes 金标准——但仍是 prompts/*.md,需在
|
||||
# md↔spec↔catalog 一一对应校验里显式排除,否则集合等式误报。
|
||||
_DOCTRINE_STEMS = {"write_craft"}
|
||||
|
||||
|
||||
# ---- #2 md ↔ spec ↔ catalog 一一对应(覆盖 style.md / character-gen.md 连字符)----
|
||||
def test_md_spec_catalog_one_to_one() -> None:
|
||||
md_stems = {p.stem for p in PROMPTS_DIR.glob("*.md")}
|
||||
md_stems = {p.stem for p in PROMPTS_DIR.glob("*.md")} - _DOCTRINE_STEMS
|
||||
assert set(SPECS) == md_stems == set(SCHEMA_CATALOG)
|
||||
# 易错连字符 / 非变量名命名显式覆盖
|
||||
assert "style" in md_stems and "style_drift" not in md_stems
|
||||
|
||||
Reference in New Issue
Block a user