Add pinned CPU engine dependencies, retained interrupted-response history, provider admission, offline evaluation and isolated browser tooling. Record Phase 2 acceptance and Phase 3/4 preparation, bounded paid-test accounting and interruption incident findings. Human interruption acceptance, paired OpenAI evaluation and rollback remain pending.
87 lines
4.9 KiB
Python
87 lines
4.9 KiB
Python
"""HTTP-fixture-only browser duplex reproduction; synthesized input and sink."""
|
|
import asyncio
|
|
import json
|
|
from pathlib import Path
|
|
from uuid import uuid4
|
|
import httpx
|
|
import subprocess
|
|
from websockets.asyncio.client import connect
|
|
|
|
root=Path('.local-s2s-build')
|
|
account=json.loads((root/'browser-login.json').read_text())
|
|
origin='http://127.0.0.2:4201'
|
|
|
|
async def main():
|
|
engine=json.loads(subprocess.check_output(['docker','inspect','rag-local-s2s-test-local-s2s-engine-1'],text=True))[0]
|
|
if engine['Config']['Entrypoint']!=['python','/checks/browser-fixture-engine.py']:
|
|
raise RuntimeError('Refusing audio: native engine is not fixture-only')
|
|
if any(m['Destination'].startswith('/secret') for m in engine['Mounts']):
|
|
raise RuntimeError('Fixture engine must not mount a provider key')
|
|
report={}
|
|
with httpx.Client(base_url=origin,headers={'Origin':origin},timeout=20,trust_env=False) as client:
|
|
async with asyncio.timeout(30):
|
|
while True:
|
|
try:
|
|
ready=client.get('/api/v1/me')
|
|
if ready.status_code in (200,401):break
|
|
except httpx.HTTPError:pass
|
|
await asyncio.sleep(.5)
|
|
login=client.post('/api/v1/auth/login',json={k:account[k] for k in ('username','password')})
|
|
login.raise_for_status();csrf=login.json()['csrf_token']
|
|
client.headers['x-csrf-token']=csrf
|
|
created=client.post('/api/v1/conversations',json={'client_request_id':str(uuid4()),'title':'Phase2 browser connection check','mode':'voice'})
|
|
created.raise_for_status();conversation=created.json()['id']
|
|
session=client.post('/api/v1/voice/sessions',json={'conversation_id':conversation,'client_request_id':str(uuid4())})
|
|
session.raise_for_status();session=session.json()
|
|
report.update(conversation_id=conversation,session_id=session['session_id'],events=[],binary_bytes=0)
|
|
cookie='; '.join(k+'='+v for k,v in client.cookies.items())
|
|
ledger=root/'browser-paid/browser-paid-ledger.json'
|
|
before=len(json.loads(ledger.read_text())['attempts'])
|
|
microphone=None
|
|
try:
|
|
async with connect('ws://127.0.0.2:4201'+session['stream_path'],origin=origin,
|
|
additional_headers={'Cookie':cookie},proxy=None,close_timeout=3) as ws:
|
|
async with asyncio.timeout(20):
|
|
while True:
|
|
event=json.loads(await ws.recv());report['events'].append(event['type'])
|
|
if event['type']=='error':raise RuntimeError('Browser preflight received '+event['error']['code'])
|
|
if event['type']=='session_ready':break
|
|
report['session_ready']=True
|
|
raw=(root/'native-paid/input.pcm').read_bytes()
|
|
async def capture():
|
|
offset=0
|
|
while True:
|
|
await asyncio.wait_for(ws.send(raw[offset:offset+960] if offset<len(raw) else bytes(960)),5)
|
|
offset+=960
|
|
await asyncio.sleep(.02)
|
|
microphone=asyncio.create_task(capture())
|
|
async with asyncio.timeout(40):
|
|
while True:
|
|
event=await ws.recv()
|
|
if isinstance(event,bytes):
|
|
report['binary_bytes']+=len(event)
|
|
await ws.send(json.dumps({'type':'playback_progress','audio_ref':audio_ref,'played_ms':report['binary_bytes']//48}))
|
|
continue
|
|
event=json.loads(event);report['events'].append(event['type'])
|
|
if event['type']=='error':raise RuntimeError('Duplex fixture failed '+event['error']['code'])
|
|
if event['type']=='audio_started':audio_ref=event['audio_ref']
|
|
if event['type']=='audio_ended':break
|
|
microphone.cancel()
|
|
await asyncio.gather(microphone,return_exceptions=True)
|
|
closed=client.post('/api/v1/voice/sessions/'+session['session_id']+'/close')
|
|
closed.raise_for_status();report['close']=closed.json()
|
|
finally:
|
|
if microphone is not None:
|
|
microphone.cancel()
|
|
await asyncio.gather(microphone,return_exceptions=True)
|
|
client.post('/api/v1/voice/sessions/'+session['session_id']+'/close')
|
|
client.post('/api/v1/auth/logout')
|
|
report['component_attempts_before']=before
|
|
report['component_attempts_after']=len(json.loads(ledger.read_text())['attempts'])
|
|
(root/'browser-duplex-result.json').write_text(json.dumps(report,indent=2)+'\n')
|
|
assert report.get('session_ready') and report['binary_bytes']>0
|
|
assert before==report['component_attempts_after'],'Unexpected inference during connection-only check'
|
|
print(json.dumps(report))
|
|
|
|
asyncio.run(main())
|