Add authenticated upload, review, retry and knowledge-selection HTTP flows with bounded JSON processing and frozen OCR policy. Preserve Gemini/OpenAI provider selection and fenced lifecycle semantics; retain FAQ preambles and uncertain vision candidates, and expose opt-in uncalibrated voice transport diagnostics. Include frontend integration examples, aligned contracts and deterministic regressions. Validation: 1767 provider-free tests passed; all 404 PostgreSQL scenarios have passing evidence across the documented runs.
54 lines
2.7 KiB
Python
54 lines
2.7 KiB
Python
"""Provider-free configuration, notification threading, and strict transport DTOs."""
|
|
import asyncio
|
|
from threading import Thread
|
|
from uuid import uuid4
|
|
import pytest
|
|
from pydantic import ValidationError
|
|
from app.modules.voice.configuration import VoiceSettings
|
|
from app.modules.voice import registry
|
|
from app.modules.voice.lifecycle import canonical_hash
|
|
from app.api.v1.live import CreateLiveSessionRequest
|
|
from app.api.v1.auth import LoginRequest
|
|
from app.api.v1.conversations import CreateConversationRequest
|
|
|
|
|
|
def test_gemini_configuration_requires_no_openai_voice_key(monkeypatch):
|
|
monkeypatch.delenv('OPENAI_API_KEY',raising=False)
|
|
config=VoiceSettings(_env_file=None,gemini_api_key='fixture',gemini_model='intended-profile',gemini_voice='Aoede')
|
|
config.require_voice()
|
|
assert config.provider=='gemini' and config.profile()['model']=='intended-profile'
|
|
assert 'fixture' not in repr(config)
|
|
|
|
@pytest.mark.parametrize('changes', [{'provider':'unknown'},{'trusted_origins':['http://evil/path']},
|
|
{'trusted_hosts':['*']},{'gemini_proxy':'https://user:secret@proxy'},
|
|
{'trusted_origins':['https://prod.example'],'cookie_secure':False},{'live_session_seconds':0}])
|
|
def test_invalid_configuration_fails_before_remote_setup(changes):
|
|
with pytest.raises(ValidationError): VoiceSettings(_env_file=None,**changes)
|
|
|
|
@pytest.mark.parametrize('model,payload',[(CreateLiveSessionRequest,{'conversation_id':str(uuid4()),'client_request_id':str(uuid4())}),
|
|
(CreateConversationRequest,{'client_request_id':str(uuid4()),'mode':'voice'}),
|
|
(LoginRequest,{'username':'a','password':'p'})])
|
|
def test_strict_dto_rejects_extra_scope(model,payload):
|
|
with pytest.raises(ValidationError): model.model_validate(dict(payload,organization_id=str(uuid4())))
|
|
|
|
|
|
def test_epoch_notification_runs_on_owner_loop_and_skips_new_sessions():
|
|
async def scenario():
|
|
org=uuid4();called=[]
|
|
class Runtime:
|
|
def __init__(self):self.lock=asyncio.Lock()
|
|
def fail(self,code):called.append((self,asyncio.get_running_loop(),code))
|
|
old,new=Runtime(),Runtime();sid1,sid2=uuid4(),uuid4()
|
|
registry.register(sid1,org,1,uuid4(),old);registry.register(sid2,org,2,uuid4(),new)
|
|
try:
|
|
thread=Thread(target=lambda:registry.notify(organization_id=org,new_epoch=2));thread.start();thread.join()
|
|
await asyncio.sleep(.01)
|
|
assert called==[(old,asyncio.get_running_loop(),'CONTEXT_REVOKED')]
|
|
finally:
|
|
registry.unregister(sid1);registry.unregister(sid2)
|
|
asyncio.run(scenario())
|
|
|
|
|
|
def test_canonical_argument_hash_is_order_independent():
|
|
assert canonical_hash({'query':'q','context':None})==canonical_hash({'context':None,'query':'q'})
|