feat(voice): add authenticated Phase 2 live lifecycle

Add cookie authentication, owned conversations, durable Live reservations,
tool completion/replay fencing, revocation, and startup reconciliation.
Introduce forward lifecycle/owner-chain migrations and the temporary Gemini
adapter while preserving the existing OpenAI Realtime adapter.

Include the executable audio client, regression coverage, configuration,
API/database documentation, and recorded acceptance evidence.

Validation: focused review suite 82 passed; Python/TOML parsing, JavaScript
syntax, and whitespace checks passed. Full PostgreSQL/provider-free results
are recorded in the repair report; real-provider/browser acceptance is unrun.

Follow-up work remains for configurable OpenAI/Gemini selection, transport
admission, authority diagnostics, playback message bounds, and client replay
identity after ambiguous creation responses.
This commit is contained in:
11linear11
2026-10-09 07:59:02 -04:00
parent 07245cd5ca
commit 996435d2ae
42 changed files with 4551 additions and 88 deletions
+53
View File
@@ -0,0 +1,53 @@
"""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':'openai'},{'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'})