- 从 story 路由 prompt/校验中移除 new_story_title,改由叙事管线在正文足够长时生成 - 新增 story_title_min_body_chars;短正文使用章节类别占位标题 - CATEGORY_TO_CHAT_STAGE 对齐访谈 state.slots 的 stage 键 - 删除相对口述长度的叙事回退,仅保留 merge JSON 极端缩水类 fallback - evidence_format:解析 object_json 并优化事实条目标点符号 - 更新 narrative / experience 相关单测
61 lines
2.2 KiB
Python
61 lines
2.2 KiB
Python
"""叙事分区、merge_shrink 回退、配图字数门闸(纯函数/无 DB)。"""
|
||
|
||
from app.agents.memoir.prompts import format_narrative_user_content
|
||
from app.features.memoir import story_pipeline_sync as sps
|
||
|
||
|
||
def test_format_narrative_user_content_oral_only() -> None:
|
||
assert format_narrative_user_content("hello", "") == "【本段用户口述】\nhello"
|
||
|
||
|
||
def test_format_narrative_user_content_with_evidence() -> None:
|
||
out = format_narrative_user_content("口述A", "摘录B")
|
||
assert "【本段用户口述】" in out
|
||
assert "口述A" in out
|
||
assert "摘录B" in out
|
||
assert "非本段口述" in out
|
||
|
||
|
||
def test_apply_narrative_fallbacks_merge_shrink_appends_oral() -> None:
|
||
"""整篇合并 JSON 输出过短:保留旧文并拼本段口述。"""
|
||
long_existing = "x" * 500
|
||
raw = '{"paragraphs": [{"content": "短"}]}'
|
||
out, _ft = sps._apply_narrative_fallbacks(
|
||
raw,
|
||
"新口述补充",
|
||
long_existing,
|
||
chapter_category="childhood",
|
||
)
|
||
assert long_existing in out
|
||
assert "新口述补充" in out
|
||
|
||
|
||
def test_apply_narrative_fallbacks_short_output_no_longer_falls_back() -> None:
|
||
"""短口述的正常改写不应被回退到口述原文。"""
|
||
oral = "我1999年出生在上海,小学时爷爷常带我去河边散步。"
|
||
raw = '{"paragraphs": [{"content": "1999年,我出生在上海。"}]}'
|
||
out, ft = sps._apply_narrative_fallbacks(
|
||
raw, oral, "", chapter_category="childhood"
|
||
)
|
||
assert ft == "none"
|
||
assert "1999" in out
|
||
|
||
|
||
def test_coalesce_story_markdown_empty_md_falls_back_to_oral() -> None:
|
||
"""模型返回空 paragraphs 时仍回退到口述原文。"""
|
||
md = sps._coalesce_story_markdown("", "口述原文", "")
|
||
assert md == "口述原文"
|
||
|
||
|
||
def test_coalesce_story_markdown_nonempty_md_kept() -> None:
|
||
"""非空改写不再按字数比例回退。"""
|
||
md = sps._coalesce_story_markdown("改写后的短文本", "原始口述比较长的一段话", "")
|
||
assert md == "改写后的短文本"
|
||
|
||
|
||
def test_memoir_image_settings_min_body_field() -> None:
|
||
from app.features.memoir.memoir_images.settings import MemoirImageSettings
|
||
|
||
cfg = MemoirImageSettings(story_image_min_body_chars=799)
|
||
assert cfg.story_image_min_body_chars == 799
|