okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
ffb3d9b31
main
1"""QAGUI-STRIX 11-09 (APP-WIN item 3): on Windows Strix Halo the app's Models-screen Load rewrote the reserve setup wrote (700) to 1024, 2048 with pictures, 2while `strata launch` started the same model with 700. The app's Load ("Leave room for my work" and "Full performance", what the Models screen passes) 3now starts the engine as `strata launch` does, from the run config setup writes; the only difference allowed is the work profile's --pool-workers (the 4profile's meaning) and the variables it sets (allowlist.ENV_BY_DESIGN, STRATA_RAM_KEEP_GIB). 5 6python -m pytest tests/snapshot/test_strix_app_reserve.py -q (needs Node, as the app entries of the snapshot do) 7""" 8 9from __future__import annotations 10 11import json 12import os 13import shutil 14import sys 15import unittest 16from pathlib import Path 17from unittest import mock 18 19ROOT = Path (__file__ ).resolve ().parents [2 ] 20if str (ROOT )not in sys .path : 21sys .path .insert (0 ,str (ROOT )) 22 23from tests .snapshot .driver import drive ,drive_app ,drive_launch # noqa: E402 24from tests .snapshot .matrix import machine ,model_set # noqa: E402 25from tests .snapshot .world import World # noqa: E402 26 27NODE = os .environ .get ("STRATA_SNAPSHOT_NODE" )or shutil .which ("node" ) 28 29 30def flag (argv :list [str ],name :str ): 31return argv [argv .index (name )+ 1 ]if name in argv else None 32 33 34def without (argv :list [str ],name :str )-> list [str ]: 35out ,skip = [],False 36for a in argv : 37if skip : 38skip = False 39continue 40if a == name : 41skip = True 42continue 43out .append (a ) 44return out 45 46 47def setup_reserve (model :str )-> str : 48"""The reserve setup itself writes on this class (strata_control/setup_config.py, driven by the snapshot's setup entry).""" 49args = drive ("strix_halo_win" ,model ,"setup" )["config_file" ]["args" ] 50return flag (args ,"--vram-reserve-mib" ) 51 52 53def world_with_setup_reserve (model :str ,reserve :str )-> World : 54world = World (machine ("strix_halo_win" ),model_set (model )).build () 55cfg = json .loads (world .config_path .read_text (encoding = "utf-8" )) 56if "--vram-reserve-mib" not in cfg ["args" ]: 57cfg ["args" ]+= ["--vram-reserve-mib" ,reserve ] 58world .config_path .write_text (json .dumps (cfg ,indent = 1 ),encoding = "utf-8" ) 59return world 60 61 62@ unittest . skipIf ( not NODE , "no Node: the app's Load runs in Node" ) 63class StrixAppReserve (unittest .TestCase ): 64maxDiff = None 65 66def engine (self ,model :str ,reserve :str ,entry :str ,app_args :dict | None = None )-> dict : 67world = world_with_setup_reserve (model ,reserve ) 68try : 69if entry == "launch" : 70with world .patched (): 71rec = drive_launch (world ) 72else : 73with mock .patch .dict (os .environ , {"STRATA_SNAPSHOT_APP_ARGS" :json .dumps (app_args or {})}): 74rec = drive_app (world ,"models" ) 75self .assertNotIn ("failed" ,rec ,json .dumps (rec .get ("failed" ))) 76# each entry runs in its own scratch world: its folder is written as <ROOT> so two engine lines can be compared 77root = str (world .root ) 78return {** rec ["engine" ],"argv" : [a .replace (root ,"<ROOT>" )for a in rec ["engine" ]["argv" ]]} 79finally : 80world .close () 81 82def test_the_models_screen_load_keeps_setups_reserve_and_starts_as_launch_does (self ): 83for model in ("ud_q4_k_xl" ,"iq3_s" ): 84reserve = setup_reserve (model ) 85self .assertEqual (reserve ,"700" ,"setup's own reserve on Windows Strix Halo" ) 86launch = self .engine (model ,reserve ,"launch" ) 87self .assertEqual (flag (launch ["argv" ],"--vram-reserve-mib" ),"700" ) 88for profile in ("work" ,"performance" ): 89with self .subTest (model = model ,profile = profile ): 90app = self .engine (model ,reserve ,"app" , {"resourceProfile" :profile ,"vision" :"no" ,"values" : {"drafting" :"auto" }}) 91self .assertEqual (flag (app ["argv" ],"--vram-reserve-mib" ),"700" ,"the app keeps what setup wrote (it wrote 1024)" ) 92self .assertEqual (without (app ["argv" ],"--pool-workers" ),without (launch ["argv" ],"--pool-workers" ),"the same engine line" ) 93if profile == "performance" : 94self .assertIsNone (flag (app ["argv" ],"--pool-workers" )) 95 96 97if __name__ == "__main__" : 98unittest .main ()