82 lines
5.7 KiB
Python
82 lines
5.7 KiB
Python
#!/usr/bin/env python3
|
|
"""Finite model-free WS route replay of canonical deployed source in isolated localhost.
|
|
No live phone/session/history, no inference, no fake pack approvals or live configuration.
|
|
"""
|
|
import argparse,json,subprocess
|
|
from pathlib import Path
|
|
ROOT=Path(__file__).resolve().parents[1]
|
|
REMOTE=r'''
|
|
import asyncio,contextlib,inspect,json,secrets,socket,tempfile,hashlib,sys
|
|
from pathlib import Path
|
|
root=Path('/home/gorios-spark-2/lan-voice')
|
|
for name,digest in expected.items():assert hashlib.sha256((root/name).read_bytes()).hexdigest()==digest
|
|
import shutil
|
|
stage_dir=tempfile.TemporaryDirectory(prefix='startup-canonical-source-')
|
|
stage=Path(stage_dir.name)
|
|
for path in root.glob('*.py'):shutil.copy2(path,stage/path.name)
|
|
shutil.copy2(root/'reviewed_action_packs.json',stage/'reviewed_action_packs.json')
|
|
(stage/'web').mkdir();sys.path.insert(0,str(stage))
|
|
import gateway as g
|
|
import uvicorn,websockets,httpx
|
|
from history import History
|
|
from guest_sessions import GuestSessions
|
|
from tests_fake import FakeModel
|
|
from action_protocol import configured_packs
|
|
assert configured_packs()[pin]==durations
|
|
async def main():
|
|
with tempfile.TemporaryDirectory(prefix='startup-capabilities-probe-') as directory:
|
|
history=History(Path(directory)/'public-empty.sqlite3');await history.initialize()
|
|
token=secrets.token_urlsafe(32)
|
|
async with httpx.AsyncClient(transport=httpx.MockTransport(lambda req: (_ for _ in ()).throw(AssertionError('no_inference_allowed')))) as client:
|
|
state=g.app.state
|
|
state.busy=False;state.model=FakeModel();state.client=client;state.history=history
|
|
state.token=token;state.guest_enabled=False;state.lan_open=False;state.guests=GuestSessions();state.debug=None
|
|
state.voices=[{'id':g.DEFAULT_VOICE_ID,'source':'registered_reference','default':True}]
|
|
server=uvicorn.Server(uvicorn.Config(g.app,host='127.0.0.1',port=0,lifespan='off',log_level='critical',access_log=False))
|
|
sock=socket.socket();sock.bind(('127.0.0.1',0));sock.listen();sock.setblocking(False);port=sock.getsockname()[1]
|
|
task=asyncio.create_task(server.serve(sockets=[sock]));rows=[]
|
|
try:
|
|
async with asyncio.timeout(5):
|
|
while not server.started:await asyncio.sleep(.01)
|
|
kwargs={'origin':'https://192.168.31.61:5011','open_timeout':3,'close_timeout':1}
|
|
if 'proxy' in inspect.signature(websockets.connect).parameters:kwargs['proxy']=None
|
|
for kind,offer in [('pending',{'action_protocol':1,'action_kinds':[],'action_pending_pack_sha256':pin}),('legacy',{}),('unknown',{'action_protocol':1,'action_kinds':[],'action_pending_pack_sha256':'b'*64})]:
|
|
async with websockets.connect(f'ws://127.0.0.1:{port}/ws/dialogue',**kwargs) as ws:
|
|
await ws.send(json.dumps({'type':'auth','token':token}));assert json.loads(await ws.recv())['type']=='auth'
|
|
await ws.send(json.dumps({'type':'hello','codec':'pcm16','sample_rate':16000,'frame_duration':20,'persona':'default','tts_debug':False,**offer}))
|
|
hello=json.loads(await ws.recv());assert hello['type']=='hello' and not hello['action_available']
|
|
assert hello['action_pending']==(kind=='pending')
|
|
async def update(value):
|
|
await ws.send(json.dumps({'type':'client.capabilities.ready','action_protocol':1,'action_kinds':['dance'],'action_pack_sha256':value}))
|
|
async with asyncio.timeout(3):
|
|
while True:
|
|
event=json.loads(await ws.recv())
|
|
if event['type']=='client.capabilities':return event['action_available'],event['turn_id']
|
|
assert event['type']=='history' # Isolated empty history; never saved or printed.
|
|
denied=await update('b'*64);accepted=await update(pin);duplicate=await update(pin)
|
|
assert not denied[0] and accepted[0]==(kind=='pending') and duplicate==accepted
|
|
rows.append({'offer':kind,'hello_available':False,'pending':hello['action_pending'],'ready_available':accepted[0],'duplicate_turn_unchanged':duplicate[1]==hello['turn_id']})
|
|
async with asyncio.timeout(3):
|
|
while state.busy:await asyncio.sleep(.01)
|
|
finally:
|
|
server.should_exit=True;await task
|
|
return {'status':'passed','scope':'canonical source isolated actual WS routes; no live session','rows':rows,'connections':3,'model_calls':0,'asr_calls':0,'tts_calls':0,'device':'not_run'}
|
|
print(json.dumps(asyncio.run(main())))
|
|
stage_dir.cleanup()
|
|
'''
|
|
def main():
|
|
parser=argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument('--pin',choices=['987e125a7d7a2cde99121b5f5246c82f4dbe36c4899d3d49eaffd1a68bafb887','208f703ed92bf795bfeb78a1cef89b67bed2e45da80038a56157fd1ecd4cfa93'],default='987e125a7d7a2cde99121b5f5246c82f4dbe36c4899d3d49eaffd1a68bafb887')
|
|
parser.add_argument('--output',type=Path,default=ROOT/'logs/action-emotion/startup-074/capability-ws.json')
|
|
args=parser.parse_args()
|
|
if args.output.exists():raise SystemExit('Fresh output required')
|
|
durations=json.loads((ROOT/'gateway/reviewed_action_packs.json').read_text())[args.pin]
|
|
expected=json.loads((ROOT/'gateway/SOURCE_MANIFEST.json').read_text())['deployment_baseline']['files']
|
|
payload='expected='+repr(expected)+'\npin='+repr(args.pin)+'\ndurations='+repr(durations)+'\n'+REMOTE
|
|
result=subprocess.run(['ssh','-o','BatchMode=yes','-o','ConnectTimeout=5','gorios-spark-2@192.168.31.61','cd /home/gorios-spark-2/lan-voice && exec .venv/bin/python -'],input=payload.encode(),capture_output=True,timeout=25)
|
|
if result.returncode:
|
|
print('FAIL: isolated capability probe; remote exception suppressed, no live changes');raise SystemExit(1)
|
|
report=json.loads(result.stdout);report['manifest_sha256']=args.pin;report['action_durations_ms']=durations;output=args.output
|
|
output.parent.mkdir(parents=True,exist_ok=True);output.write_text(json.dumps(report,indent=2)+'\n');print(json.dumps(report,indent=2))
|
|
if __name__=='__main__':main()
|