feat: M3 — 伏笔账本 + 节奏引擎 + 大纲(含并发记账 bugfix)
- 伏笔账本:纯函数状态机(OPEN/PARTIAL/CLOSED/OVERDUE) + ForeshadowLedger repo;验收后到期扫描(BackgroundTask 自建 session 置 OVERDUE);登记/状态变更端点 - 节奏 + 三审齐:foreshadow-analyst + pace-checker 并入 LangGraph 并行审(REVIEW_SPECS),collect 分列落 chapter_reviews(conflicts/foreshadow_sug/pace),review SSE 加 foreshadow/pace 事件 - 大纲:outliner Agent 产 OutlineResult(含 foreshadow_windows),POST /outline 逐章 upsert outline 表;GET /foreshadow?status= 看板 - 前端:伏笔四泳道看板(OVERDUE 琥珀) + 大纲编辑器(窗口徽标) + 节奏节拍图(▁▃▅) + 审稿页消费 foreshadow/pace SSE - bugfix(T3.8):并行三审共用请求 session 记账触发 'Session is already flushing' → foreshadow/pace 静默丢失;SqlAlchemyLedgerSink.record 改 add-only(靠端点/事务 commit),加并发回归测试 - M3 E2E:真实 DB + mock 网关零 token 走通 埋设→进展→验收后扫描 OVERDUE→看板 + 大纲含窗口 + 三审齐 SSE/留痕;E2E 暴露并钉住上述 bug - 门禁绿:mypy 111 / pytest 228(0 xfailed) / alembic 无漂移;前端 gen:api/lint/tsc/vitest 69/build
This commit is contained in:
63
apps/api/tests/test_outline_context.py
Normal file
63
apps/api/tests/test_outline_context.py
Normal file
@@ -0,0 +1,63 @@
|
||||
"""T3.5 大纲注入上下文组装单测(确定性纯函数;ARCH §5.4)。
|
||||
|
||||
断言:四源(设定/伏笔/人物/世界观)都进文本、排序确定(同输入同输出)、空源不炸。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from ww_api.services.outline_context import build_outline_context
|
||||
from ww_core.domain import ForeshadowLedgerView
|
||||
from ww_core.domain.project_repo import ProjectView
|
||||
from ww_core.domain.repositories import CharacterView, WorldEntityView
|
||||
|
||||
|
||||
def _project() -> ProjectView:
|
||||
import uuid
|
||||
|
||||
return ProjectView(
|
||||
id=uuid.UUID(int=1),
|
||||
title="逆天剑帝",
|
||||
genre="玄幻",
|
||||
logline="少年逆袭",
|
||||
selling_points=["爽点密集", "升级流"],
|
||||
)
|
||||
|
||||
|
||||
def test_build_context_includes_all_four_sources() -> None:
|
||||
text = build_outline_context(
|
||||
project=_project(),
|
||||
foreshadow=[
|
||||
ForeshadowLedgerView(
|
||||
code="F1", title="神秘信物", status="OPEN", planted_at=3, expected_close_to=10
|
||||
)
|
||||
],
|
||||
characters=[CharacterView(name="主角", role="protagonist", motive="复仇")],
|
||||
world_entities=[WorldEntityView(type="location", name="剑冢")],
|
||||
)
|
||||
assert "逆天剑帝" in text
|
||||
assert "F1" in text and "神秘信物" in text
|
||||
assert "回收窗口 ?-10" in text
|
||||
assert "主角" in text
|
||||
assert "剑冢" in text
|
||||
|
||||
|
||||
def test_build_context_is_deterministic_and_sorted() -> None:
|
||||
project = _project()
|
||||
fs = [
|
||||
ForeshadowLedgerView(code="F2", title="b", status="OPEN"),
|
||||
ForeshadowLedgerView(code="F1", title="a", status="OPEN"),
|
||||
]
|
||||
a = build_outline_context(project=project, foreshadow=fs, characters=[], world_entities=[])
|
||||
b = build_outline_context(
|
||||
project=project, foreshadow=list(reversed(fs)), characters=[], world_entities=[]
|
||||
)
|
||||
assert a == b
|
||||
# F1 排在 F2 前(按 code 升序)。
|
||||
assert a.index("[F1]") < a.index("[F2]")
|
||||
|
||||
|
||||
def test_build_context_handles_empty_sources() -> None:
|
||||
text = build_outline_context(
|
||||
project=_project(), foreshadow=[], characters=[], world_entities=[]
|
||||
)
|
||||
assert "(无)" in text
|
||||
Reference in New Issue
Block a user