okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
76e51103c
main
1#!/usr/bin/env python3 2"""Exercise fake-engine serving from a clean runtime-only Python environment. 3 4Create a fresh venv, install requirements.txt, then run this script with that 5venv's Python. The runtime integration module exercises foreground and POSIX 6owned serving; no GPU, model weights or optional terminal framework is needed. 7""" 8 9from __future__import annotations 10 11import argparse 12import hashlib 13import importlib .util 14import json 15import os 16import platform 17import re 18import subprocess 19import sys 20import time 21from pathlib import Path 22 23 24ROOT = Path (__file__ ).resolve ().parents [1 ] 25TEST_MODULE = "tests.terminal.test_runtime" 26MIN_TESTS = 32 27 28 29def smoke ()-> dict : 30if sys .prefix == sys .base_prefix : 31raise RuntimeError ("run with a dedicated virtual environment" ) 32if os .name != "posix" : 33raise RuntimeError ("this owned-runtime check currently requires POSIX" ) 34visible = {name :importlib .util .find_spec (name )is not None 35for name in ("rich" ,"textual" ,"numpy" ,"jinja2" ,"requests" )} 36if visible != {"rich" :False ,"textual" :False ,"numpy" :True , 37"jinja2" :True ,"requests" :True }: 38raise RuntimeError (f"runtime-only dependency set was not isolated: { visible } " ) 39started = time .monotonic () 40result = subprocess .run ([sys .executable ,"-m" ,"unittest" ,TEST_MODULE ],cwd = ROOT , 41capture_output = True ,text = True ,timeout = 240 ,check = False ) 42summary = result .stdout + result .stderr 43# Windows-only tests skip on POSIX, so unittest ends "OK (skipped=N)", not a bare "OK". 44count = re .search (r"Ran (\d+) tests in [0-9.]+s\s+OK(?: \(skipped=(\d+)\))?\s*$" ,summary ) 45executed = int (count [1 ])- int (count [2 ]or 0 )if count else 0 46passed = result .returncode == 0 and count is not None and executed >= MIN_TESTS 47return {"schema_version" :1 ,"scope" :"source_checkout_fake_engine_runtime_only" , 48"platform" :platform .platform (),"python" :platform .python_version (), 49"requirements_sha256" :hashlib .sha256 ((ROOT / "requirements.txt" ).read_bytes ()).hexdigest (), 50"optional_packages_visible" : {name :visible [name ]for name in ("rich" ,"textual" )}, 51"server_packages_visible" : {name :visible [name ]for name in ("numpy" ,"jinja2" ,"requests" )}, 52"test_module" :TEST_MODULE ,"tests_run" :executed if count else None , 53"duration_s" :round (time .monotonic ()- started ,2 ), 54"test_exit_code" :result .returncode ,"actual_gpu_engine" :False , 55"passed" :bool (passed ),"test_summary" :summary [- 1000 :]} 56 57 58def main ()-> int : 59parser = argparse .ArgumentParser (description = __doc__ ) 60parser .add_argument ("--report" ,type = Path ,required = True ,help = "new absolute JSON report path" ) 61args = parser .parse_args () 62report = args .report .expanduser () 63if not report .is_absolute ()or report .exists (): 64parser .error ("--report must be an absolute new file" ) 65result = smoke () 66report .parent .mkdir (parents = True ,exist_ok = True ) 67descriptor = os .open (report ,os .O_WRONLY | os .O_CREAT | os .O_EXCL ,0o600 ) 68with os .fdopen (descriptor ,"w" ,encoding = "utf-8" )as stream : 69json .dump (result ,stream ,indent = 2 ) 70stream .write ("\n" ) 71json .dumps ({"report" :str (report ),"passed" :result ["passed" ]}),flush = True ) 72return 0 if result ["passed" ]else 6 73 74 75if __name__ == "__main__" : 76raise SystemExit (main ())