Files
life-echo/api/tests/test_background_voice.py
Kevin 53d9e003af feat(api): 叙事 prompt、职业上下文、读路径章节、WS 解耦与错误脱敏
- 回忆录:事实边界补充允许清单;传记文体示例与 JSON 叙事要求对齐
- default 职业提示 occupation_context;cadre/military 退休语境
- GET 章节读路径零写入,prepare_chapter_read_view + markdown_for_response
- 文本归一抽到 core/text_normalize;移除弃用 reply 策略与 recompose_chapters_for_story
- ConversationService:WS 连接/用户段落/结束对话;对外错误固定文案
- 测试:HTTP 脱敏契约、章节读视图、occupation 与 background_voice
2026-04-01 11:55:52 +08:00

52 lines
1.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.
"""职业文本推断 background_voice干部/军队)。"""
from app.agents.chat.background_voice import (
get_background_voice_chat_block,
get_background_voice_narrative_block,
infer_background_voice,
normalize_background_voice,
)
def test_infer_military_before_cadre() -> None:
assert infer_background_voice("机关文职干部") == "military"
def test_infer_military_keywords() -> None:
assert infer_background_voice("退伍军人") == "military"
assert infer_background_voice("陆军某部") == "military"
def test_infer_cadre_keywords() -> None:
assert infer_background_voice("公务员") == "cadre"
assert infer_background_voice("某局科长") == "cadre"
def test_infer_default() -> None:
assert infer_background_voice(None) == "default"
assert infer_background_voice("") == "default"
assert infer_background_voice("中学教师") == "default"
def test_normalize_accepts_enum_strings() -> None:
assert normalize_background_voice("military") == "military"
assert normalize_background_voice("cadre") == "cadre"
def test_narrative_editor_system_prompt_appends_voice() -> None:
from app.agents.memoir.prompts import get_narrative_editor_system_prompt
base = get_narrative_editor_system_prompt("default")
mil = get_narrative_editor_system_prompt("military")
assert len(mil) > len(base)
assert "背景文体(军队" in mil
def test_cadre_military_blocks_include_retirement_context() -> None:
chat_c = get_background_voice_chat_block("cadre")
chat_m = get_background_voice_chat_block("military")
narr_c = get_background_voice_narrative_block("cadre")
narr_m = get_background_voice_narrative_block("military")
assert "退休" in chat_c and "退休" in narr_c
assert "退役" in chat_m and "退役" in narr_m