"""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 offset0 assert before==report['component_attempts_after'],'Unexpected inference during connection-only check' print(json.dumps(report)) asyncio.run(main())