Files
rag-technical-docs-assistant/tests/unit/test_voice_event_capacity.py
T
amirhosein mazaheri 18e595ac93 fix(voice): preserve interrupted searches and report used sources
Retain and revalidate interrupted searches, resolve abandoned provider calls, recover invalid source reports privately, and expose only declared sources. Improve Persian delivery and provider event replay capacity. Include regression coverage and contract updates.
2026-10-13 14:09:20 +03:30

45 lines
1.9 KiB
Python

"""Session replay capacity supports ordinary multi-turn provider traffic."""
import asyncio
from types import SimpleNamespace
import pytest
from pydantic import ValidationError
from app.modules.voice.settings import RuntimeSettings
from tests.unit.test_realtime_phase1 import runner, persisted, make
def test_session_accepts_more_than_old_event_cap_and_still_detects_replay_conflict(runner, persisted):
async def scenario():
runtime, wire, out = await make(SimpleNamespace(engine=None), runner, persisted)
try:
original = dict(type='rate_limits.updated', event_id='event-0', rate_limits=[])
for index in range(4200):
await runtime.handle(dict(original, event_id=f'event-{index}'))
assert runtime.usable
count = len(runtime.events)
await runtime.handle(original)
assert runtime.usable and len(runtime.events) == count
await runtime.handle(dict(original, rate_limits=[dict(name='changed')]))
assert runtime.failure == 'LIVE_PROVIDER_PROTOCOL_ERROR'
finally:
await runtime.close()
asyncio.run(scenario())
def test_configured_event_cap_remains_finite_and_fails_safely(runner, persisted):
async def scenario():
runtime, wire, out = await make(SimpleNamespace(engine=None), runner, persisted)
runtime.settings = RuntimeSettings(_env_file=None, max_events=8)
try:
for index in range(9):
await runtime.handle(dict(type='rate_limits.updated', event_id=f'event-{index}', rate_limits=[]))
assert runtime.failure == 'LIVE_BUFFER_OVERFLOW'
assert len(runtime.events) == 8
finally:
await runtime.close()
asyncio.run(scenario())
def test_event_capacity_rejects_unbounded_configuration():
with pytest.raises(ValidationError):
RuntimeSettings(_env_file=None, max_events=32769)