refactor: formaliza contratos de streaming e ciclo de vida dos provedores
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
from voice_assistant.agent.adapter import StreamingAgentAdapter
|
||||
from voice_assistant.tts.adapter import TTSAdapter
|
||||
"""
|
||||
Tests for the Voice Pipeline lifecycle orchestration.
|
||||
|
||||
@@ -832,7 +834,7 @@ async def test_stream_turn_response_produces_audio_before_agent_finishes():
|
||||
is still generating its response.
|
||||
"""
|
||||
|
||||
class StreamingAgent:
|
||||
class StreamingAgent(StreamingAgentAdapter):
|
||||
def __init__(self):
|
||||
self.first_delta_sent = asyncio.Event()
|
||||
self.release_generation = asyncio.Event()
|
||||
@@ -848,7 +850,7 @@ async def test_stream_turn_response_produces_audio_before_agent_finishes():
|
||||
yield " Estou à disposição."
|
||||
self.finished = True
|
||||
|
||||
class StreamingTTS:
|
||||
class StreamingTTS(TTSAdapter):
|
||||
async def synthesize(self, text):
|
||||
yield text.encode("utf-8")
|
||||
|
||||
@@ -931,12 +933,12 @@ async def test_stream_turn_response_produces_audio_before_agent_finishes():
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_stream_turn_response_propagates_agent_failure():
|
||||
class FailingStreamingAgent:
|
||||
class FailingStreamingAgent(StreamingAgentAdapter):
|
||||
async def stream(self, session_id, turn_id, text):
|
||||
yield "Olá, como posso ajudar?"
|
||||
raise RuntimeError("Simulated OCI streaming failure.")
|
||||
|
||||
class StreamingTTS:
|
||||
class StreamingTTS(TTSAdapter):
|
||||
async def synthesize(self, text):
|
||||
yield text.encode("utf-8")
|
||||
|
||||
@@ -971,7 +973,7 @@ async def test_stream_turn_response_propagates_agent_failure():
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_stream_turn_response_cancels_agent_on_tts_failure():
|
||||
class BlockingStreamingAgent:
|
||||
class BlockingStreamingAgent(StreamingAgentAdapter):
|
||||
def __init__(self):
|
||||
self.cancelled = asyncio.Event()
|
||||
|
||||
@@ -982,7 +984,7 @@ async def test_stream_turn_response_cancels_agent_on_tts_failure():
|
||||
finally:
|
||||
self.cancelled.set()
|
||||
|
||||
class FailingTTS:
|
||||
class FailingTTS(TTSAdapter):
|
||||
async def synthesize(self, text):
|
||||
raise RuntimeError("Simulated TTS failure.")
|
||||
yield b"" # Keep this method an async generator.
|
||||
@@ -1023,7 +1025,7 @@ async def test_stream_turn_response_cancels_agent_on_tts_failure():
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_stream_turn_response_external_cancellation():
|
||||
class BlockingAgent:
|
||||
class BlockingAgent(StreamingAgentAdapter):
|
||||
def __init__(self):
|
||||
self.closed = asyncio.Event()
|
||||
|
||||
@@ -1034,7 +1036,7 @@ async def test_stream_turn_response_external_cancellation():
|
||||
finally:
|
||||
self.closed.set()
|
||||
|
||||
class BlockingTTS:
|
||||
class BlockingTTS(TTSAdapter):
|
||||
def __init__(self):
|
||||
self.started = asyncio.Event()
|
||||
self.closed = asyncio.Event()
|
||||
|
||||
Reference in New Issue
Block a user