"""职业文本推断 background_voice(干部/军队)。""" from app.agents.chat.background_voice import ( get_background_voice_narrative_block, get_background_voice_tone_hint, 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_tone_hints_and_narrative_retirement_context() -> None: chat_c = get_background_voice_tone_hint("cadre") chat_m = get_background_voice_tone_hint("military") assert chat_c and chat_m assert "稳重" in chat_c or "分寸" in chat_c assert "简洁" in chat_m or "利落" in chat_m narr_c = get_background_voice_narrative_block("cadre") narr_m = get_background_voice_narrative_block("military") assert "退休" in narr_c assert "退役" in narr_m