Files
leleka/scripts/smoke-runtime-image.py
T
Pavlo Ratushnyi 4013e0c9bd
Desktop foundation / core (ubuntu-latest) (push) Failing after 28s
Desktop foundation / core (macos-latest) (push) Canceled after 0s
Desktop foundation / core (windows-latest) (push) Canceled after 0s
Linux / verify (push) Canceled after 0s
Linux / keyless-cuda (push) Canceled after 0s
Linux / static-cuda-package (push) Canceled after 0s
Linux / hosted-cuda-package (push) Canceled after 0s
Linux / linux-static-cli (push) Canceled after 0s
Linux / linux-cli-container (push) Canceled after 0s
Linux / release-cli (push) Canceled after 0s
Import tracked Strata Next source snapshot
2026-10-05 18:15:08 +02:00

78 lines
4.1 KiB
Python

#!/usr/bin/env python3
"""Actual combined CPU image proof. Never use with a model/CUDA image."""
import importlib.util
import json
from pathlib import Path
import subprocess
import sys
import tempfile
import time
import urllib.request
import uuid
def docker(*args, check=True):
return subprocess.run(['docker', *map(str, args)], check=check, capture_output=True, text=True, timeout=30)
def main(receipt):
proof = json.loads(Path(receipt).read_text())
assert proof['kind'] == 'cpu-fixture' and proof['gpu_tested'] is False
image = proof['image']
label = docker('inspect', '--format', '{{index .Config.Labels "io.strata.package-kind"}}', image).stdout.strip()
assert label == 'cpu-fixture'
spec = importlib.util.spec_from_file_location('helper', Path(__file__).with_name('smoke-worker-cancel.py'))
helper = importlib.util.module_from_spec(spec); spec.loader.exec_module(helper)
name = 'strata-runtime-smoke-' + uuid.uuid4().hex
opener = urllib.request.build_opener(urllib.request.ProxyHandler({}))
with tempfile.TemporaryDirectory(prefix='strata-container-fixture-') as tmp:
root = Path(tmp); root.chmod(0o755)
helper.tokenizer(root)
(root/'config.json').write_text(json.dumps({'bind': '0.0.0.0:8081', 'model': 'embedded-fixture',
'engine_probe': True, 'engine': {'executable': '@embedded', 'args': ['/tmp/worker.pid'],
'tokenizer_dir': '/fixture', 'startup_timeout_s': 5, 'max_restarts': 1}}))
for path in root.iterdir(): path.chmod(0o644)
try:
docker('run', '-d', '--name', name, '--platform', 'linux/amd64', '--read-only',
'--cap-drop', 'ALL', '--security-opt', 'no-new-privileges', '--user', '65532:65532',
'--tmpfs', '/tmp:rw,nosuid,nodev,size=64m', '-e', 'CUDA_VISIBLE_DEVICES=',
'-e', 'NVIDIA_VISIBLE_DEVICES=void', '-p', '127.0.0.1::8081',
'--mount', f'type=bind,src={root},dst=/fixture,readonly', image,
'serve', '--config', '/fixture/config.json')
port = int(docker('port', name, '8081/tcp').stdout.strip().rsplit(':', 1)[1])
def request(route, body=None):
req = urllib.request.Request(f'http://127.0.0.1:{port}{route}',
data=json.dumps(body).encode() if body else None, headers={'Content-Type': 'application/json'})
with opener.open(req, timeout=5) as response: return json.load(response)
def ready():
deadline = time.monotonic()+15
while time.monotonic()<deadline:
try:
if request('/status')['ready']: return
except OSError: pass
time.sleep(.1)
raise AssertionError('container worker did not become ready')
def generate():
result = request('/v1/responses', {'model':'embedded-fixture','input':'Reply A',
'max_output_tokens':1,'reasoning':{'effort':'none'}})
assert result['status']=='completed'
assert result['output'][0]['content'][0]['text']=='A'
ready(); generate()
before = docker('exec', name, 'cat', '/tmp/worker.pid').stdout.strip()
assert before.isascii() and before.isdigit()
docker('exec', name, '/bin/sh', '-c', 'kill -KILL "$1"', 'strata-smoke', before)
deadline = time.monotonic()+15
while docker('exec', name, 'cat', '/tmp/worker.pid').stdout.strip()==before:
assert time.monotonic()<deadline
time.sleep(.1)
ready(); generate()
docker('stop', '--time', '10', name)
state = json.loads(docker('inspect','--format','{{json .State}}',name).stdout)
assert state['ExitCode']==0 and not state['OOMKilled']
print('Combined CPU OCI: Responses A exact, worker crash/restart A exact, nonroot/read-only, graceful stop. No GPU/model qualification.')
finally:
docker('rm','-f',name,check=False)
if __name__=='__main__': main(sys.argv[1])