Files
Athena-Deck/docs/experiments/deepseek-context-2026-10-24/verify_restore.py
T

32 lines
2.9 KiB
Python

#!/usr/bin/env python3
"""Verify restored production worker without printing credentials or user content."""
import hashlib,json,os,subprocess,sys,urllib.request
from pathlib import Path
BASE=Path(os.environ.get('DECK_TEST_BASE','/data/athena-deck-strata/experiments/deepseek-iq2-20261024'))
STATE=Path(os.environ.get('DECK_TEST_STATE','/opt/athena-deck-dev/runtime/state'))
r=Path((BASE/'active-context-run.txt').read_text().strip());d=json.loads((r/'result.json').read_text())
if d['phase'] not in ('complete','finished_with_error'):raise SystemExit('Test still running; do not verify prematurely')
key=json.load(sys.stdin)['key']
req=urllib.request.Request('http://127.0.0.1:8108/api/v1/status',headers={'Authorization':'Bearer '+key})
endpoint=json.load(urllib.request.urlopen(req,timeout=10))['endpoint']
worker=json.loads((STATE/'strata-worker/worker.json').read_text());before=json.loads((r/'qwen-template.json').read_text())
fields=('exe','args','cwd','tokenizer','model_name','host','gpu','gpu_order','layer_split','vram_elastic','open_browser','log','parallel','reasoning_loop_recovery','vision','env')
comparison={k:before.get(k)==worker.get(k) for k in fields}
pids=[];leftovers=[]
for p in Path('/proc').iterdir():
if not p.name.isdigit():continue
try:args=(p/'cmdline').read_bytes().split(b'\0')
except OSError:continue
if any(a.endswith(b'/serve/server.py') for a in args):
if any(a in (b'/var/lib/deck/strata-worker/worker.json',str(STATE/'strata-worker/worker.json').encode()) for a in args):pids.append(int(p.name))
if any(str(r).encode() in a for a in args):leftovers.append(int(p.name))
if any(a.endswith(b'/strata-dsv41') for a in args):leftovers.append(int(p.name))
assert len(pids)==1,'Restored worker identity not unique'
probe="import json,sys,urllib.request;x=json.load(sys.stdin);r=urllib.request.Request('http://127.0.0.1:'+str(x['port'])+'/health',headers={'Authorization':'Bearer '+x['api_key']});print(json.dumps(json.load(urllib.request.urlopen(r,timeout=5))))"
health=json.loads(subprocess.check_output(['nsenter','-t',str(pids[0]),'-n','python3','-c',probe],input=json.dumps(worker),text=True))
settings={n:hashlib.sha256((STATE/n).read_bytes()).hexdigest() for n in d['settings_before']}
out=dict(previous_profile=d['previous_profile'],restored_profile=worker['model_name'],controller_restored=d.get('restored'),settings_unchanged=settings==d['settings_before'],worker_fields_unchanged=comparison,health=health,endpoint=endpoint,test_worker_pids=leftovers)
out['verified']=bool(out['controller_restored'] and out['settings_unchanged'] and all(comparison.values()) and health.get('status')=='ok' and health.get('loaded') and endpoint['counts']['llm']['loaded'] and endpoint['counts']['tts']['loaded'] and endpoint['counts']['stt']['loaded'] and not leftovers)
(r/'verification.json').write_text(json.dumps(out,indent=2)+'\n');print(json.dumps(out,indent=2))
if not out['verified']:raise SystemExit(1)