fix(voice): stabilize v2 streaming topic handling

This commit is contained in:
Yera All
2026-04-12 21:59:32 +05:00
parent 7f4c80add1
commit 989bf9a0c1
6 changed files with 254 additions and 8 deletions
+39
View File
@@ -1497,6 +1497,45 @@ def test_voice_postprocess_reply_rewrites_false_lookup_promise():
assert "филиал" in reply_text.lower() or "адрес" in reply_text.lower()
def test_voice_postprocess_reply_rewrites_midcall_greeting_with_followup_question():
reply_text = voice_module._voice_postprocess_reply_text(
language="ru",
transcript_text="Здравствуйте, мне надо узнать...",
transcript_window=[
SimpleNamespace(speaker="assistant", text=voice_module._voice_greeting("ru"), sequence_no=1, source_type="voice_policy", barge_in_interrupted=False, created_at=utc_now_iso()),
SimpleNamespace(speaker="caller", text="Здравствуйте, мне надо узнать...", sequence_no=2, source_type="voice_asr", barge_in_interrupted=False, created_at=utc_now_iso()),
],
reply_text="Здравствуйте, Ернур! О чем именно вы хотите узнать?",
kb_results=[],
needs_handoff=False,
)
normalized = reply_text.lower()
assert "здравствуйте" not in normalized
assert "о чем именно" not in normalized
def test_voice_postprocess_reply_reuses_active_topic_after_frustration_turn():
reply_text = voice_module._voice_postprocess_reply_text(
language="ru",
transcript_text="Сколько раз повторять тебе?",
transcript_window=[
SimpleNamespace(speaker="caller", text="Мне надо узнать график работы.", sequence_no=1, source_type="voice_asr", barge_in_interrupted=False, created_at=utc_now_iso()),
SimpleNamespace(speaker="caller", text="В городе Алма-Ата.", sequence_no=2, source_type="voice_asr", barge_in_interrupted=False, created_at=utc_now_iso()),
SimpleNamespace(speaker="caller", text="Меня интересует филиал в Ауэзовском районе.", sequence_no=3, source_type="voice_asr", barge_in_interrupted=False, created_at=utc_now_iso()),
SimpleNamespace(speaker="caller", text="Сколько раз повторять тебе?", sequence_no=4, source_type="voice_asr", barge_in_interrupted=False, created_at=utc_now_iso()),
],
reply_text="Пожалуйста, уточните, какая услуга вас интересует, чтобы я мог подсказать тариф.",
kb_results=[],
needs_handoff=False,
)
normalized = reply_text.lower()
assert "тариф" not in normalized
assert "услуг" not in normalized
assert "филиал" in normalized or "адрес" in normalized
def test_turn_voice_session_early_plan_does_not_persist_partial_turns(monkeypatch):
monkeypatch.setenv("AI_VOICE_POLICY_MODE", "v2_streaming_duplex")