okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
3cabb9e3f
main
1"""Tester report 2026-10-18, T03 / T04 / T05: existing models are found the same way by the launch screens, `strata models list`, the 2own-files import and `strata launch` (strata_control/discovery.py), with a mock of the desktop app's folders and a Gyro-S file header 3(TQK6 / TQK7 experts, the one-file layout).""" 4 5from __future__import annotations 6 7import io 8import json 9import os 10import shutil 11import struct 12import tempfile 13import unittest 14from contextlib import redirect_stdout 15from pathlib import Path 16from unittest import mock 17 18from strata_cli .launch import modelstate ,settings as S 19from strata_cli .launch .catalog import Catalog 20from strata_cli .launch .runner import Runner 21from strata_control import discovery ,models 22from tests .terminal .launch_support import HW_12 23 24GYRO_S = "Qwen3.8-Flash-Next-Gyro-S-TQ1_0.gguf" 25GYRO_M = "Qwen3.8-Flash-Next-Gyro-M-TQ2_0.gguf" 26TQ2_T ,TQK6 ,TQK7 = 144 ,145 ,146 27 28 29def string (value :str )-> bytes : 30raw = value .encode () 31return struct .pack ("<Q" ,len (raw ))+ raw 32 33 34def gguf_with (tensors :list [tuple [str ,int ,int ,int ]])-> bytes : 35"""A tiny qwen4exp GGUF: (name, ggml type id, elements, payload bytes) per tensor, laid out one after another.""" 36pairs = [("general.architecture" ,8 ,string ("qwen4exp" )), ("tokenizer.ggml.model" ,8 ,string ("gpt2" )), 37 ("tokenizer.ggml.tokens" ,9 ,struct .pack ("<IQ" ,8 ,1 )+ string ("a" )), 38 ("tokenizer.ggml.merges" ,9 ,struct .pack ("<IQ" ,8 ,1 )+ string ("a b" ))] 39header = (b"GGUF" + struct .pack ("<IQQ" ,3 ,len (tensors ),len (pairs ))+ 40b"" .join (string (k )+ struct .pack ("<I" ,kind )+ value for k ,kind ,value in pairs )) 41offset = 0 42for name ,type_id ,elements ,nbytes in tensors : 43header += string (name )+ struct .pack ("<IQIQ" ,1 ,elements ,type_id ,offset ) 44offset += - (- nbytes // 32 )* 32 45header += b"\x00" * (- len (header )% 32 ) 46return header + b"\x00" * offset 47 48 49def gyro_s_bytes ()-> bytes : 50return gguf_with ([("blk.0.ffn_gate_exps.weight" ,TQK6 ,256 ,52 ), ("blk.0.ffn_down_exps.weight" ,TQK7 ,256 ,60 )]) 51 52 53def gyro_m_bytes ()-> bytes : 54return gguf_with ([("blk.0.ffn_gate_exps.weight" ,TQ2_T ,256 ,68 )]) 55 56 57class GuiLayout (unittest .TestCase ): 58"""The desktop app's folders, as the Windows (and Linux) app lays them out, plus an empty Terminal folder.""" 59 60def setUp (self ): 61self .tmp = tempfile .TemporaryDirectory (prefix = "strata-discovery-" ) 62self .addCleanup (self .tmp .cleanup ) 63base = Path (self .tmp .name ) 64self .base = base 65self .env = {"LOCALAPPDATA" :str (base / "local" ),"XDG_DATA_HOME" :str (base / "local" ),"APPDATA" :str (base / "roaming" ), 66"XDG_CONFIG_HOME" :str (base / "config" ),"USERPROFILE" :str (base / "home" ),"HOME" :str (base / "home" ), 67"XDG_STATE_HOME" :str (base / "state" ),"XDG_DOCUMENTS_DIR" :"" } 68settings = Path (self .env ["APPDATA" ])/ "Strata" if os .name == "nt" else Path (self .env ["XDG_CONFIG_HOME" ])/ "strata" 69self .settings_path = settings / "settings.json" 70patch = mock .patch .dict (os .environ ,self .env ) 71patch .start () 72self .addCleanup (patch .stop ) 73for key in ("STRATA_INSTALL_DIR" ,"STRATA_SETTINGS_FILE" ,"STRATA_COMPONENTS_DIR" ,"STRATA_DOCUMENTS_DIR" ): 74patch = mock .patch .dict (os .environ ) 75patch .start () 76self .addCleanup (patch .stop ) 77os .environ .pop (key ,None ) 78self .terminal = base / "terminal" 79 (self .terminal / "data" ).mkdir (parents = True ) 80shutil .copy (Path (models .__file__ ).resolve ().parents [1 ]/ "data" / "gguf_fingerprints.json" ,self .terminal / "data" ) 81p = mock .patch .object (models ,"ROOT" ,self .terminal ) 82p .start () 83self .addCleanup (p .stop ) 84self .install = discovery .app_install_dir () 85self .docs = base / "home" / "Documents" / "Strata" 86gyro = self .docs / "Models" / "gyro-Gyro-S" 87gyro .mkdir (parents = True ) 88self .gguf = gyro / GYRO_S 89self .gguf .write_bytes (gyro_s_bytes ()) 90 (gyro / (GYRO_S + ".done" )).write_text ("done" ) 91 (self .docs / "packs" / "gyro-gyro-s" / "tokenizer" ).mkdir (parents = True ) 92 (self .docs / "packs" / "gyro-gyro-s" / "dense.bin" ).write_bytes (b"x" ) 93 (self .docs / "mtp" / "rt" ).mkdir (parents = True ) 94 (self .docs / "mtp" / "rt" / "experts.bin" ).write_bytes (b"x" ) 95self .mmproj = self .docs / "Models" / "mmproj-Qwen3.8-Flash-Next-BF16.gguf" 96self .mmproj .write_bytes (b"x" ) 97self .install .mkdir (parents = True ) 98engine = base / "engine.exe" 99engine .write_bytes (b"e" ) 100tok = self .docs / "packs" / "gyro-gyro-s" / "tokenizer" 101 (tok / "vocab.json" ).write_text ("{}" ) 102self .cfg = {"exe" :"component:strata-engine" ,"tokenizer" :str (tok ),"model_name" :"qwen3.8-flash-next-gyro-gyro-s" , 103"args" : ["--pack" ,str (self .docs / "packs" / "gyro-gyro-s" ),"--native" ,str (self .gguf ),"--ple-gguf" ,str (self .gguf ), 104"--mtp" ,str (self .docs / "mtp" / "rt" ),"--max-context" ,"131072" ,"--kv" ,"int8" ,"--vision" ], 105"vision" : {"exe" :str (engine ),"mmproj" :str (self .mmproj ),"model" :str (self .gguf ),"gpu" :False }} 106self .config_path = self .install / "strata-gyro-gyro-s.json" 107self .config_path .write_text (json .dumps (self .cfg )) 108 (self .install .parent / "app-settings.json" ).write_text (json .dumps ({"data_dir" :str (self .docs ),"installs" : [str (self .install )]})) 109 110def catalog (self )-> Catalog : 111return Catalog (hardware = HW_12 ) 112 113# ---- T04: one answer for list and the wizard 114def test_models_list_finds_the_app_install_by_default (self ): 115result = models .list_installed () 116self .assertEqual ([m ["id" ]for m in result ["models" ]], ["gyro-gyro-s" ]) 117self .assertEqual (Path (result ["install_dir" ]).resolve (),self .install .resolve ()) 118self .assertEqual (result ["install_dir_source" ],"app" ) 119 120def test_list_and_the_wizard_agree_on_the_install (self ): 121cat = self .catalog () 122self .assertEqual (cat .root .resolve (),models .resolve_install ()[0 ].resolve ()) 123self .assertIsNotNone (cat .installed_config ("gyro-gyro-s" )) 124row = next (r for r in cat .rows ()if (r .family ,r .model )== ("gyro" ,"Gyro-S" )) 125self .assertTrue (row .installed ) 126 127def test_cli_list_names_where_it_looked_when_nothing_is_found (self ): 128self .config_path .unlink () 129out = io .StringIO () 130from strata_cli .cli import main 131with redirect_stdout (out ): 132code = main (["models" ,"list" ]) 133self .assertEqual (code ,0 ) 134self .assertIn ("No installed models found. Looked in:" ,out .getvalue ()) 135self .assertIn ("--install-dir" ,out .getvalue ()) 136 137def test_an_explicit_install_dir_is_the_only_place (self ): 138other = self .base / "other" 139other .mkdir () 140self .assertEqual (models .list_installed (str (other ))["models" ], []) 141self .assertEqual ([p .source for p in discovery .places (explicit = str (other ))], ["explicit" ]) 142 143def test_a_remembered_older_install_and_the_app_install_are_both_listed (self ): 144old = self .base / "T-Strata" 145old .mkdir () 146 (old / "strata-qwen-iq3_xxs.json" ).write_text (json .dumps ({"exe" :"e" ,"tokenizer" :"t" ,"args" : []})) 147settings = self .settings_path 148settings .parent .mkdir (parents = True ) 149settings .write_text (json .dumps ({"installs" : [str (old )]})) 150got = models .list_installed () 151self .assertEqual (sorted (m ["id" ]for m in got ["models" ]), ["gyro-gyro-s" ,"qwen-iq3_xxs" ]) 152self .assertEqual (got ["install_dir_source" ],"remembered" ) 153 154def test_inside_the_app_an_older_install_is_still_not_adopted (self ): 155old = self .base / "T-Strata" 156old .mkdir () 157 (old / "strata-x.json" ).write_text (json .dumps ({"exe" :"e" ,"tokenizer" :"t" ,"args" : []})) 158app_settings = self .install .parent / "app-settings.json" 159with mock .patch .dict (os .environ , {"STRATA_SETTINGS_FILE" :str (app_settings )}): 160settings = self .settings_path 161settings .parent .mkdir (parents = True ) 162settings .write_text (json .dumps ({"installs" : [str (old )]})) 163self .assertEqual ([m ["id" ]for m in models .list_installed ()["models" ]], ["gyro-gyro-s" ]) 164 165# ---- T03: the own-files import knows Gyro 166def test_import_recognises_a_gyro_s_folder_and_its_prepared_files (self ): 167plan = models .plan_import (str (self .gguf .parent )) 168self .assertEqual (plan ["issues" ], []) 169self .assertEqual ((plan ["candidate_selection" ]["family" ],plan ["candidate_selection" ]["model" ]), ("gyro" ,"Gyro-S" )) 170self .assertEqual (sorted (plan ["observed_expert_types" ]), ["TQK6" ,"TQK7" ]) 171done = plan ["already_set_up" ] 172self .assertEqual (Path (done ["config" ]).resolve (),self .config_path .resolve ()) 173self .assertEqual (Path (done ["pack" ]).resolve (), (self .docs / "packs" / "gyro-gyro-s" ).resolve ()) 174self .assertEqual (Path (done ["mtp" ]).resolve (), (self .docs / "mtp" / "rt" ).resolve ()) 175self .assertEqual (Path (done ["data_dir" ]).resolve (),self .docs .resolve ()) 176 177def test_import_recognises_the_file_itself (self ): 178plan = models .plan_import (str (self .gguf )) 179self .assertEqual (plan ["issues" ], []) 180self .assertEqual (plan ["candidate_selection" ]["model" ],"Gyro-S" ) 181 182def test_import_recognises_gyro_m (self ): 183folder = self .base / "gyro-m" 184folder .mkdir () 185 (folder / GYRO_M ).write_bytes (gyro_m_bytes ()) 186plan = models .plan_import (str (folder )) 187self .assertEqual (plan ["issues" ], []) 188self .assertEqual (plan ["candidate_selection" ]["model" ],"Gyro-M" ) 189 190def test_a_folder_with_two_models_says_which_and_asks_for_one_file (self ): 191folder = self .base / "both" 192folder .mkdir () 193 (folder / GYRO_S ).write_bytes (gyro_s_bytes ()) 194 (folder / GYRO_M ).write_bytes (gyro_m_bytes ()) 195plan = models .plan_import (str (folder )) 196self .assertIn ("multiple_model_groups" ,plan ["issues" ]) 197self .assertEqual (sorted ((h ["family" ],h ["model" ])for h in plan ["folder_holds" ]), [("gyro" ,"Gyro-M" ), ("gyro" ,"Gyro-S" )]) 198from strata_cli .cli import _import_problem 199text = _import_problem (plan ) 200self .assertIn ("more than one model" ,text ) 201self .assertIn ("holds 2 models" ,text ) 202self .assertIn ("gyro Gyro-S" ,text ) 203self .assertIn ("type the path of its .gguf file" ,text ) 204self .assertNotIn ("multiple_model_groups" ,text ) 205self .assertNotIn ("not a model size" ,text ) 206 207def test_import_still_refuses_gyro_s_with_the_wrong_expert_format (self ): 208folder = self .base / "wrong" 209folder .mkdir () 210 (folder / GYRO_S ).write_bytes (gyro_m_bytes ())# TQ2_T experts under the Gyro-S name 211plan = models .plan_import (str (folder )) 212self .assertIn ("missing_or_unexpected_expert_quantization" ,plan ["issues" ]) 213 214def test_a_renamed_file_is_known_by_its_header (self ): 215data = gyro_s_bytes () 216folder = self .base / "renamed" 217folder .mkdir () 218 (folder / "my-copy.gguf" ).write_bytes (data ) 219fake_root = self .base / "fake-root" 220 (fake_root / "data" ).mkdir (parents = True ) 221payload = 52 + 60 + 12 # 32-byte aligned offsets: 64 + 64 -> see below 222table = {"gyro/Gyro-S" : {"arch" :"qwen4exp" ,"tensors" :2 ,"bytes" :None ,"expert_bytes" : {"TQK6" :52 ,"TQK7" :60 }, 223"files" : [GYRO_S ],"repo" :"x" }} 224first = models .plan_import (str (folder / "my-copy.gguf" )) 225self .assertIsNone (first ["candidate_selection" ])# not in the real table under another name 226table ["gyro/Gyro-S" ]["bytes" ]= first ["metadata" ]["payload_bytes_required" ] 227 (fake_root / "data" / "gguf_fingerprints.json" ).write_text (json .dumps (table )) 228with mock .patch .object (models ,"ROOT" ,fake_root ): 229plan = models .plan_import (str (folder / "my-copy.gguf" )) 230self .assertEqual (plan ["candidate_selection" ]["basis" ],"header_size_and_tensors" ) 231self .assertEqual (plan ["candidate_selection" ]["model" ],"Gyro-S" ) 232self .assertEqual (payload ,124 ) 233 234def test_a_fine_tune_with_the_layout_of_a_known_build_is_used_not_refused (self ):# #3651 #3777 235folder = self .base / "finetune" 236folder .mkdir () 237 (folder / "Qwen3.8-Flash-Next-Gyro-S-abliterated-TQ1_0.gguf" ).write_bytes (gyro_s_bytes ()) 238fake_root = self .base / "fake-root2" 239 (fake_root / "data" ).mkdir (parents = True ) 240table = {"gyro/Gyro-S" : {"arch" :"qwen4exp" ,"tensors" :2 ,"bytes" :999_999 ,"expert_bytes" : {"TQK6" :52 ,"TQK7" :60 }, 241"files" : [GYRO_S ],"repo" :"x" }, 242"gyro/Gyro-M" : {"arch" :"qwen4exp" ,"tensors" :2 ,"bytes" :888_888 ,"expert_bytes" : {"TQ2_T" :40 }, 243"files" : [GYRO_S ],"repo" :"x" }} 244 (fake_root / "data" / "gguf_fingerprints.json" ).write_text (json .dumps (table )) 245with mock .patch .object (models ,"ROOT" ,fake_root ): 246plan = models .plan_import (str (folder )) 247self .assertEqual (plan ["issues" ], []) 248self .assertEqual (plan ["candidate_selection" ]["basis" ],"same_layout_other_build" ) 249self .assertEqual (plan ["candidate_selection" ]["model" ],"Gyro-S" )# the closest by expert formats 250self .assertTrue (any ("not exactly a build Strata has tested" in m for m in plan ["messages" ])) 251self .assertIn ("unrecognized_or_unsupported_model_variant" ,models .plan_import (str (folder ))["issues" ])# the real table has 1224 tensors 252 253# ---- T05: where it is, what is missing 254def test_the_folder_defaults_to_where_the_model_is (self ): 255cat = self .catalog () 256self .assertEqual (cat .data_dir ().resolve (),self .docs .resolve ()) 257self .assertEqual (cat .data_dir_for ("gyro" ,"Gyro-S" ).resolve (),self .docs .resolve ()) 258self .assertEqual (cat .data_dir_choice ()[1 ],"app" ) 259 260def test_an_own_setting_beats_the_apps_folder (self ): 261mine = self .base / "mine" 262mine .mkdir () 263settings = self .settings_path 264settings .parent .mkdir (parents = True ,exist_ok = True ) 265settings .write_text (json .dumps ({"data_dir" :str (mine )})) 266self .assertEqual (self .catalog ().data_dir ().resolve (),mine .resolve ()) 267 268def test_installed_with_everything_there_is_already_downloaded (self ): 269st = modelstate .assess (self .catalog (),"gyro" ,"Gyro-S" ,vision = "cpu" ) 270self .assertTrue (st .installed ) 271self .assertEqual (st .remaining_gb ,0.0 ) 272self .assertIn ("Already downloaded" ,st .headline ()) 273self .assertIn ("Nothing more to download" ,st .headline ()) 274 275def test_only_the_draft_layer_missing_says_so_with_its_size (self ): 276 (self .docs / "mtp" / "rt" / "experts.bin" ).unlink () 277cat = self .catalog () 278st = modelstate .assess (cat ,"gyro" ,"Gyro-S" ,vision = "cpu" ) 279self .assertEqual ([p .kind for p in st .parts ], ["mtp" ]) 280self .assertAlmostEqual (st .remaining_gb ,discovery .MTP_FETCH_GB ) 281text = st .headline () 282self .assertIn ("Only the draft layer is missing (5.2 GB)" ,text ) 283self .assertNotIn ("download the model" ,text .lower ()) 284title ,body = st .question () 285self .assertIn ("draft layer" ,title ) 286self .assertIn ("not downloaded again" ,body ) 287 288def test_draft_layer_and_picture_reader_are_itemised (self ): 289 (self .docs / "mtp" / "rt" / "experts.bin" ).unlink () 290self .mmproj .unlink () 291st = modelstate .assess (self .catalog (),"gyro" ,"Gyro-S" ,vision = "cpu" ) 292self .assertEqual (sorted (p .kind for p in st .parts ), ["mmproj" ,"mtp" ]) 293self .assertIn ("the draft layer (5.2 GB) and the picture reader (0.9 GB)" ,st .headline ()) 294self .assertAlmostEqual (st .remaining_gb ,5.2 + 0.9 ) 295 296def test_pictures_off_never_asks_for_the_reader (self ): 297self .mmproj .unlink () 298st = modelstate .assess (self .catalog (),"gyro" ,"Gyro-S" ,vision = "off" ) 299self .assertEqual (st .parts , []) 300 301def test_weights_gone_downloads_the_model_again_and_says_so (self ): 302self .gguf .unlink () 303st = modelstate .assess (self .catalog (),"gyro" ,"Gyro-S" ,vision = "off" ) 304self .assertFalse (st .installed ) 305self .assertGreater (st .remaining_gb ,50 ) 306 307def test_runner_counts_only_the_missing_helper_and_gives_setup_the_apps_folder (self ): 308 (self .docs / "mtp" / "rt" / "experts.bin" ).unlink () 309cat = self .catalog () 310r = Runner (S .LaunchSettings (family = "gyro" ,model = "Gyro-S" ,context = 131072 ,kv = "int8" ,vision = "cpu" ),catalog = cat ) 311self .assertAlmostEqual (r .download_gb (),5.2 ) 312argv = r .setup_args () 313self .assertEqual (Path (argv [argv .index ("--data-dir" )+ 1 ]).resolve (),self .docs .resolve ()) 314 315def test_own_files_use_the_prepared_pack_and_folder (self ): 316r = Runner (S .LaunchSettings (model_path = str (self .gguf .parent ),family = "gyro" ,model = "Gyro-S" ,vision = "off" ),catalog = self .catalog ()) 317self .assertEqual (r .download_gb (),0.0 ) 318self .assertEqual (Path (r .existing_data_dir ()).resolve (),self .docs .resolve ()) 319 320 321if __name__ == "__main__" : 322unittest .main ()