Files
Mikei386 c0bc5d3a1b Integrate Basalt telemetry and shared GPU speech runtimes
Publish the reviewed accumulated runtime, scheduler, profile, UI, native recipes and historical maintenance evidence. Includes Qwen GPU ASR correction and shared Anna/atelier ownership. Validated with 784 local tests, Python/JSON parsing and eight JavaScript syntax checks. Live GPU acceptance and full fresh-host restore limits remain documented.
2026-11-03 21:16:41 +01:00

37 lines
2.5 KiB
Python

#!/usr/bin/env python3
"""CPU-only upstream mock; run in the worker's actual Python environment."""
import argparse,json,os,signal,socket,subprocess,time,urllib.request,urllib.error
from pathlib import Path
p=argparse.ArgumentParser();p.add_argument('--python',required=True);p.add_argument('--source',required=True);p.add_argument('--launcher',required=True);a=p.parse_args()
with socket.socket() as s:s.bind(('127.0.0.1',0));port=s.getsockname()[1]
base='http://127.0.0.1:'+str(port);key='synthetic-telemetry-test-key'
log=Path(a.launcher).parent/'mock-check.log'
def request(path,data=None,auth=True):
h={'Content-Type':'application/json'}
if auth:h['Authorization']='Bearer '+key
req=urllib.request.Request(base+path,data=json.dumps(data).encode() if data is not None else None,headers=h)
with urllib.request.urlopen(req,timeout=5) as r:return json.load(r)
with log.open('w') as out:
process=subprocess.Popen([a.python,a.launcher,'--deck-source',a.source,'--mock-engine','--host','127.0.0.1','--port',str(port),'--api-key',key],stdout=out,stderr=subprocess.STDOUT,env=dict(os.environ,CUDA_VISIBLE_DEVICES='',NVIDIA_VISIBLE_DEVICES='void',PYTHONUNBUFFERED='1'),start_new_session=True)
try:
deadline=time.monotonic()+25
while True:
try:before=request('/telemetry');break
except (OSError,ValueError):
if process.poll() is not None or time.monotonic()>deadline:raise RuntimeError('Upstream mock did not start; inspect own mock-check.log') from None
time.sleep(.1)
assert before['schema_version']==1 and before['backend']=='basalt' and before['available']
try:request('/telemetry',auth=False);raise AssertionError('Missing auth accepted')
except urllib.error.HTTPError as e:assert e.code==401
model=request('/v1/models')['data'][0]['id']
response=request('/v1/chat/completions',dict(model=model,messages=[dict(role='user',content='SYNTHETIC_PRIVATE_MARKER')],max_tokens=16,stream=False))
after=request('/telemetry');assert after['metrics']['requests_completed_total']==1
assert after['metrics']['tokens_predicted_total']>0
text=json.dumps(after);assert 'SYNTHETIC_PRIVATE_MARKER' not in text and key not in text and 'requests' not in after and 'history' not in after
print(json.dumps(dict(real_upstream_mock=True,auth_401=True,existing_chat_route=True,numeric_counters=True,content_free=True,slots=len(after['slots']))),flush=True)
finally:
if process.poll() is None:
os.killpg(process.pid,signal.SIGTERM)
try:process.wait(timeout=5)
except subprocess.TimeoutExpired:os.killpg(process.pid,signal.SIGKILL);process.wait()