fix: relay confirmation interrupts past muted input

This commit is contained in:
Xin Wang
2026-08-04 11:12:34 +08:00
parent da828aca41
commit 775e4058bc
8 changed files with 153 additions and 70 deletions

View File

@@ -1,6 +1,5 @@
from __future__ import annotations
import asyncio
import unittest
from types import SimpleNamespace
from unittest.mock import AsyncMock, patch
@@ -11,7 +10,6 @@ from pipecat.frames.frames import (
OutputTransportMessageUrgentFrame,
)
from services.pipecat.pipeline_events import bind_cascade_pipeline_events
from services.pipecat.pipeline import _wait_for_output_stop
class _EventSource:
@@ -82,25 +80,37 @@ class _Brain:
class PipelineEventTest(unittest.IsolatedAsyncioTestCase):
async def test_interrupted_output_waits_for_transport_stop(self):
events = []
async def test_interruption_acknowledges_deferred_client_tool_result(self):
transport = _EventSource()
text_input = _EventSource()
user_aggregator = _EventSource()
assistant_aggregator = _EventSource()
worker = _Worker()
brain = _Brain(worker)
acknowledgements = []
client_tools = SimpleNamespace(
on_interruption_processed=lambda: acknowledgements.append(True)
)
async def wait_until_stopped():
events.append("stopped")
bind_cascade_pipeline_events(
transport=transport,
worker=worker,
brain=brain,
context=SimpleNamespace(),
text_input=text_input,
user_aggregator=user_aggregator,
assistant_aggregator=assistant_aggregator,
greeting="",
vision_enabled=False,
vision_state={"client_id": None},
client_tools=client_tools,
)
await _wait_for_output_stop(wait_until_stopped)
await assistant_aggregator.handlers["on_interruption_processed"](
assistant_aggregator
)
self.assertEqual(events, ["stopped"])
async def test_interrupted_output_rejects_stop_timeout(self):
async def wait_forever():
await asyncio.Event().wait()
with self.assertRaisesRegex(RuntimeError, "语音停止超时"):
await _wait_for_output_stop(
wait_forever,
timeout_seconds=0.001,
)
self.assertEqual(acknowledgements, [True])
async def test_greeting_keeps_playback_timestamp_until_client_ready(self):
transport = _EventSource()