okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
d8278a0c0
main
1"""A restart with no Drafting word keeps the saved word (boxia d3d and l620 C2, 0.2.14.1: after `--drafting auto` and a restart with no word the launch's 2records said null where they said "auto"; the start still ran DFlash2, because null is Auto). Nothing real is used (tests/snapshot/README.md). 3 4Proves on every machine and model set of the matrix: "auto" stays "auto" over two restarts with no word and the engine line does not change; a saved Off 5still holds (keep_saved_off); a choice the model's installed config holds (the app's Models screen) still decides a start with no word, so no "auto" is 6written over it; a first launch with no word still writes nothing (null = Auto, as before). 7 8python -m pytest tests/snapshot/test_drafting_word_restart.py -q -p no:cacheprovider 9""" 10 11from __future__import annotations 12 13import json 14import sys 15import unittest 16from pathlib import Path 17 18ROOT = Path (__file__ ).resolve ().parents [2 ] 19if str (ROOT )not in sys .path : 20sys .path .insert (0 ,str (ROOT )) 21 22from tests .snapshot .matrix import MACHINES ,MODEL_SETS ,machine as get_machine ,model_set as get_set # noqa: E402 23from tests .snapshot .test_drafting_round_trip import argv ,drafter ,launches # noqa: E402 24 25 26class AutoStaysAuto (unittest .TestCase ): 27maxDiff = None 28 29def test_a_restart_without_a_word_keeps_auto (self ): 30for m in MACHINES : 31for s in MODEL_SETS : 32with self .subTest (machine = m .key ,set = s .key ): 33recs = launches (m ,s , [("auto" ,False ), (None ,False ), (None ,False )]) 34for later in recs [1 :]: 35self .assertEqual (later ["config_file" ].get ("drafting" ),"auto" ,"the saved word stays as it was" ) 36self .assertEqual (drafter (later ),drafter (recs [0 ]),"the same drafter as with the word" ) 37# (the first Auto start can fetch the drafter's pack; the restarts after it start alike) 38self .assertEqual (argv (recs [2 ]),argv (recs [1 ]),"the restarts start alike" ) 39same = launches (m ,s , [("auto" ,False ), ("auto" ,False )]) 40self .assertEqual (argv (recs [1 ]),argv (same [1 ]),"a restart with no word starts as one with --drafting auto" ) 41 42def test_a_saved_off_still_holds (self ): 43for mkey ,skey in (("nv_12gb_streaming" ,"iq3_s" ), ("nv_resident" ,"iq3_s" ), ("strix_halo_win" ,"ud_q4_k_xl" )): 44with self .subTest (machine = mkey ,set = skey ): 45recs = launches (get_machine (mkey ),get_set (skey ), [("auto" ,False ), ("off" ,False ), (None ,False )]) 46self .assertEqual (recs [2 ]["config_file" ].get ("drafting" ),"off" ) 47self .assertEqual (argv (recs [2 ]),argv (recs [1 ])) 48 49def test_null_is_auto_where_the_word_is_read (self ): 50from strata_control import drafting 51self .assertEqual (drafting .normalize (None ),"auto" ) 52self .assertEqual (drafting .DEFAULT_MODE ,"auto" ) 53for backend ,archs in (("cuda" , ["sm_120" ]), ("hip" , ["gfx1201" ]), ("metal" , []), ("sycl" , ["arc_a" ])): 54self .assertEqual (drafting .choice_of (None ,family = "qwen" ,backend = backend ,archs = archs ), 55drafting .choice_of ("auto" ,family = "qwen" ,backend = backend ,archs = archs ),backend ) 56host = (ROOT / "apps" / "host" / "server" / "native-control.mjs" ).read_text (encoding = "utf-8" ) 57self .assertIn ("drafting:cfg.drafting??'auto'" ,host ,"the app reads a missing word as Auto" ) 58 59def test_a_first_launch_without_a_word_writes_nothing (self ): 60recs = launches (get_machine ("nv_resident" ),get_set ("iq3_s" ), [(None ,False ), (None ,False )]) 61for rec in recs : 62self .assertIsNone (rec ["config_file" ].get ("drafting" ),"no word, nothing chosen: null is Auto" ) 63self .assertEqual (argv (recs [1 ]),argv (recs [0 ])) 64 65def test_the_models_screen_choice_still_decides_a_start_without_a_word (self ): 66# the app saves its Drafting choice in the model's installed config; a later `strata launch` with no word runs that choice, as before 67def models_screen_says_mtp (world ): 68cfg = json .loads (world .config_path .read_text (encoding = "utf-8" )) 69cfg ["drafting" ]= "mtp" 70world .config_path .write_text (json .dumps (cfg ,indent = 1 ),encoding = "utf-8" ) 71recs = launches (get_machine ("nv_resident" ),get_set ("iq3_s" ), [("auto" ,False ), (None ,False )],prepare = models_screen_says_mtp ) 72self .assertEqual (recs [0 ]["config_file" ].get ("drafting" ),"auto" ,"the word given wins over the installed choice" ) 73self .assertEqual (recs [1 ]["config_file" ].get ("drafting" ),"mtp" ,"no word: the installed config's own choice, not an auto written over it" ) 74 75 76if __name__ == "__main__" : 77unittest .main ()