okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
fefaa985c
main
1"""Tester report T05, T09, T11 and the smaller wizard items, with Textual's pilot at 120x40, 80x24, 60x20 and 40x15: the Folder step knows an installed 2model, the Advanced command follows the choices, the final choices stay on screen, the key hints wrap instead of being cut off.""" 3 4from __future__import annotations 5 6import asyncio 7import json 8import os 9import unittest 10from pathlib import Path 11from unittest import mock 12 13from strata_cli .launch import settings as S 14from strata_cli .launch .app import Ctx ,LaunchApp 15from strata_cli .launch import params as P 16from tests .terminal .launch_support import HW_12 ,Home ,text_of 17from tests .terminal .test_launch_tui import FakeRunner ,make_ctx ,press ,flat ,typed 18 19SIZES = ((120 ,40 ), (80 ,24 ), (60 ,20 ), (40 ,15 )) 20 21 22async def settled (pilot ,check ,timeout = 30.0 ): 23"""Wait until `check()` stops raising AssertionError (or the query fails because the screen is not there yet); give up after `timeout`.""" 24loop = asyncio .get_running_loop () 25deadline = loop .time ()+ timeout 26while loop .time ()< deadline : 27try : 28check () 29return 30except Exception : 31await pilot .pause (0.05 ) 32 33 34class Base (unittest .TestCase ): 35def setUp (self ): 36self .home = Home ().__enter__ () 37self .addCleanup (self .home .__exit__ ,None ,None ,None ) 38FakeRunner .instances .clear () 39FakeRunner .behaviour = "ok" 40FakeRunner .download = 0.0 41p = mock .patch ("strata_cli.launch.app.Runner" ,FakeRunner ) 42p .start () 43self .addCleanup (p .stop ) 44 45def run_app (self ,coro ,ctx = None ,size = (120 ,40 )): 46ctx = ctx or make_ctx () 47app = LaunchApp (ctx ) 48 49async def go (): 50async with app .run_test (size = size )as pilot : 51await pilot .pause (0.2 ) 52return await coro (app ,pilot ,ctx ) 53return asyncio .run (go ()) 54 55 56class SaveChoices (Base ): 57def test_the_three_choices_and_the_name_are_on_screen_at_every_size (self ): 58choices = ("Save as a preset and launch" ,"Launch without saving" ,"Save the preset and stop here" ) 59 60def check (app ,size ): 61shown = text_of (app ) 62for choice in choices : 63self .assertIn (choice ,shown , (size ,shown )) 64body = app .screen .query_one ("#body" ) 65menu = app .screen .menu () 66self .assertLessEqual (menu .region .bottom ,body .region .bottom ,size )# the choices are inside the body, not below it 67self .assertGreaterEqual (menu .region .y ,body .region .y ,size ) 68name = app .screen .query_one ("#name" ) 69self .assertLessEqual (name .region .bottom ,body .region .bottom ,size ) 70self .assertIn ("Enter:" ,flat (app ),size )# the footer says which action Enter does 71 72async def case (app ,pilot ,ctx ): 73await press (pilot ,* ("enter" ,)* 7 ,"n" ,"enter" ) 74for size in SIZES : 75await pilot .resize_terminal (* size ) 76# wait for the layout to settle (a loaded machine redraws late), not for a fixed time; the checks themselves are unchanged 77await settled (pilot ,lambda :check (app ,size )) 78check (app ,size ) 79self .run_app (case ) 80 81def test_the_footer_names_the_action_enter_will_do (self ): 82async def case (app ,pilot ,ctx ): 83await press (pilot ,* ("enter" ,)* 7 ,"n" ,"enter" ) 84self .assertIn ("Enter: Save as a preset and launch" ,flat (app )) 85await press (pilot ,"down" ) 86self .assertIn ("Enter: Launch without saving" ,flat (app )) 87await press (pilot ,"down" ) 88self .assertIn ("Enter: Save the preset and stop here" ,flat (app )) 89self .run_app (case ) 90 91def test_the_full_layout_is_kept_when_it_fits (self ): 92async def case (app ,pilot ,ctx ): 93await press (pilot ,* ("enter" ,)* 7 ,"n" ,"enter" ) 94shown = text_of (app ) 95for part in ("Save as preset, then launch" ,"Context" ,"Pictures" ,"Parallel" ,"Tuning" ,"Access" ,"Storage" ): 96self .assertIn (part ,shown ) 97self .run_app (case ) 98 99 100def path_of (n :int )-> str : 101"""A storage path of exactly `n` characters, starting with /home/ana/ and ending with /Strata-data.""" 102head ,tail = "/home/ana/" ,"/Strata-data" 103p = head + ("models-and-more-" * 20 )[:n - len (head )- len (tail )]+ tail 104assert len (p )== n 105return p 106 107 108class StoragePath (Base ): 109"""A storage folder longer than the row used to wrap and push "Save the preset and stop here" off an 80x24 screen (RULES.md, --keep scratch 110path length); it is now shortened in the middle to one row, and every choice stays on screen for any length.""" 111 112def test_every_choice_stays_on_an_80x24_screen_for_any_path_length (self ): 113choices = ("Save as a preset and launch" ,"Launch without saving" ,"Save the preset and stop here" ) 114for n in (36 ,80 ,200 ): 115ctx = make_ctx () 116path = path_of (n ) 117 118async def case (app ,pilot ,ctx ,path = path ,n = n ): 119await press (pilot ,* ("enter" ,)* 7 ,"n" ,"enter" ) 120ctx .settings .data_dir = path 121app .screen .paint () 122 123def check (): 124shown = text_of (app ) 125for choice in choices : 126self .assertIn (choice ,shown , (n ,shown )) 127body ,menu = app .screen .query_one ("#body" ),app .screen .menu () 128self .assertLessEqual (menu .region .bottom ,body .region .bottom ,n ) 129rows = [r for r in shown .split ("\n" )if "Storage" in r ] 130self .assertEqual (len (rows ),1 , (n ,shown )) 131row = rows [0 ].strip () 132self .assertTrue (row .startswith ("Storage /home/ana/" ), (n ,row )) 133self .assertTrue (row .endswith ("/Strata-data" ), (n ,row )) 134self .assertLessEqual (len (rows [0 ]),80 , (n ,row )) 135if n <= 60 : 136self .assertIn (path ,row ,"a path that fits is shown whole" ) 137else : 138self .assertIn ("\u2026" ,row ,"a long path is shortened in the middle" ) 139await settled (pilot ,check ) 140check () 141self .run_app (case ,ctx = ctx ,size = (80 ,24 )) 142 143def test_middle_shorten (self ): 144from strata_cli .launch .screens import middle_shorten 145self .assertEqual (middle_shorten ("C:/a/b" ,10 ),"C:/a/b" ) 146p = "C:\\Users\\Ana\\Documents\\Strata\\a-very-long-folder-name-for-models\\Strata-data" 147s = middle_shorten (p ,40 ) 148self .assertEqual (len (s ),40 ) 149self .assertEqual (s ,"C:\\Users\\Ana\\Do\u2026e-for-models\\Strata-data" )# 2/5 of the room for the start, the rest for the end 150self .assertEqual (middle_shorten (p ,40 ,"..." ),"C:\\Users\\Ana\\D...-for-models\\Strata-data" ) 151self .assertEqual (middle_shorten (p ,3 ),p [0 ]+ "\u2026" + p [- 1 ])# the smallest: one character on each side 152self .assertEqual (middle_shorten ("/home/\u6a21\u578b\u6a21\u578b\u6a21\u578b/data" ,12 ),"/hom\u2026\u578b/data" )# wide characters count as two cells 153 154 155class AdvancedLayout (Base ): 156HELP = " --prefill N prompt chunk size (default 2048)\n --kv fp16|int8 KV storage\n" 157 158def ctx_with_engine (self ,** choices ): 159ctx = make_ctx () 160ctx .settings .family ,ctx .settings .model = "qwen" ,"IQ3_XXS" 161for k ,v in choices .items (): 162setattr (ctx .settings ,k ,v ) 163base = {"exe" :"component:strata-engine" ,"vision" : {"mmproj" :"/x/mmproj.gguf" ,"gpu" :False }, 164"args" : ["--native" ,"/very/long/path/to/the/models/folder/Qwen3.8-Flash-Next-Something-IQ3_XXS-00001-of-00002.gguf" , 165"--pack" ,"/very/long/path/to/the/data/packs/iq3_xxs" ,"--max-context" ,"131072" ,"--kv" ,"int8" ,"--prefill" ,"auto" , 166"--vision" ]} 167for p in (mock .patch .object (Ctx ,"base_config" ,lambda self :base ),mock .patch .object (Ctx ,"engine_exe" ,lambda self :"/engine/strata" ), 168mock .patch ("strata_cli.launch.params.engine_help_text" ,return_value = self .HELP )): 169p .start () 170self .addCleanup (p .stop ) 171return ctx 172 173def test_the_command_follows_the_wizard_choices (self ): 174ctx = self .ctx_with_engine (context = 102400 ,kv = "q4_0" ,vision = "off" ) 175cmd = ctx .command_text () 176self .assertIn ("--max-context 102400" ,cmd ) 177self .assertIn ("--kv q4_0" ,cmd ) 178self .assertNotIn ("--vision" ,cmd ) 179self .assertNotIn ("131072" ,cmd ) 180ctx2 = self .ctx_with_engine (context = 65536 ,kv = "int8" ,vision = "cpu" ) 181cmd2 = ctx2 .command_text () 182self .assertIn ("--max-context 65536" ,cmd2 ) 183self .assertIn ("--vision" ,cmd2 ) 184# and the "Same as" line agrees with it 185self .assertIn ("--context 100k" ,S .flags_text (ctx .settings )) 186self .assertIn ("--kv q4_0" ,S .flags_text (ctx .settings )) 187self .assertIn ("--vision off" ,S .flags_text (ctx .settings )) 188 189def test_the_preview_is_inside_its_own_scroll_area_at_every_size_and_the_next_key_is_visible (self ): 190ctx = self .ctx_with_engine (context = 102400 ,kv = "q4_0" ,vision = "off" ) 191 192async def case (app ,pilot ,ctx ): 193await press (pilot ,* ("enter" ,)* 7 ) 194self .assertEqual (app .current ,"advanced" ) 195for size in SIZES : 196await pilot .resize_terminal (* size ) 197await pilot .pause (0.3 ) 198body = app .screen .query_one ("#body" ) 199box = app .screen .query_one ("#cmdbox" ) 200self .assertGreaterEqual (box .region .y ,body .region .y ,size ) 201self .assertLessEqual (box .region .bottom ,body .region .bottom ,size )# the preview never leaves the body 202self .assertGreaterEqual (box .region .height ,3 ,size ) 203self .assertIn ("n next" ,flat (app ),size )# the key hints wrap instead of being cut off 204self .assertIn ("Command that will run" ,text_of (app ),size ) 205self .run_app (case ,ctx ) 206 207def test_tab_scrolls_the_preview_and_esc_comes_back (self ): 208ctx = self .ctx_with_engine (context = 102400 ,kv = "q4_0" ,vision = "off" ) 209 210async def case (app ,pilot ,ctx ): 211await press (pilot ,* ("enter" ,)* 7 ) 212await pilot .resize_terminal (60 ,20 ) 213await pilot .pause (0.3 ) 214await press (pilot ,"tab" ) 215self .assertTrue (app .screen .query_one ("#cmdbox" ).has_focus ) 216await press (pilot ,"down" ,"down" ) 217await press (pilot ,"escape" ) 218self .assertFalse (app .screen .query_one ("#cmdbox" ).has_focus ) 219self .assertEqual (app .current ,"advanced" )# Esc only gave the focus back; it did not leave the step 220await press (pilot ,"n" ) 221self .assertEqual (app .current ,"access" ) 222self .run_app (case ,ctx ) 223 224def test_descriptions_use_plain_words (self ): 225text = " --expert-cache N R4: experts held in VRAM (default auto)\n --mystery N R7 internal thing T2\n" 226rows = {p .name :p for p in P .parse_help (text )} 227self .assertNotIn ("R4" ,rows ["--expert-cache" ].short ) 228self .assertIn ("graphics memory" ,rows ["--expert-cache" ].short ) 229self .assertNotRegex (rows ["--mystery" ].short ,r"\bR\d|\bT\d" ) 230 231 232class HintsWrap (Base ): 233def test_long_key_hints_wrap_instead_of_being_cut (self ): 234async def case (app ,pilot ,ctx ): 235await press (pilot ,* ("enter" ,)* 7 ) 236for width in (120 ,80 ,60 ,40 ): 237await pilot .resize_terminal (width ,24 ) 238await pilot .pause (0.25 ) 239hints = app .screen .query_one ("#hints" ) 240self .assertGreaterEqual (hints .region .height ,1 ) 241self .assertIn ("n next" ,flat (app ),width ) 242ctx = make_ctx () 243ctx .settings .family ,ctx .settings .model = "qwen" ,"IQ3_XXS" 244self .run_app (case ,ctx ) 245 246 247class InstalledModelFolder (Base ): 248"""The GUI's installation: weights, pack, picture reader there; the draft layer gone.""" 249 250def build (self ): 251base = Path (os .environ ["LOCALAPPDATA" ]).parent / "gui" 252docs = base / "Documents" / "Strata" 253gguf = docs / "Models" / "qwen-IQ3_XXS" / "Qwen3.8-Flash-Next-GSQ-RCO-IQ3_XXS-00001-of-00002.gguf" 254gguf .parent .mkdir (parents = True ) 255gguf .write_bytes (b"x" ) 256pack = docs / "packs" / "iq3_xxs" 257pack .mkdir (parents = True ) 258mm = docs / "Models" / "mmproj-Qwen3.8-Flash-Next-BF16.gguf" 259mm .write_bytes (b"x" ) 260install = Path (os .environ ["STRATA_INSTALL_DIR" ]) 261install .mkdir (parents = True ,exist_ok = True ) 262cfg = {"exe" :"component:strata-engine" ,"tokenizer" :str (pack ),"args" : ["--pack" ,str (pack ),"--native" ,str (gguf ),"--mtp" ,str (docs / "mtp" / "rt" ), 263"--max-context" ,"32768" ,"--kv" ,"int8" ], 264"vision" : {"mmproj" :str (mm ),"gpu" :False }} 265 (install / "strata-iq3_xxs.json" ).write_text (json .dumps (cfg )) 266return docs 267 268def test_the_folder_starts_where_the_model_is_and_says_what_is_missing (self ): 269docs = self .build () 270ctx = make_ctx () 271ctx .settings .family ,ctx .settings .model ,ctx .settings .vision = "qwen" ,"IQ3_XXS" ,"cpu" 272 273async def case (app ,pilot ,ctx ): 274await press (pilot ,"enter" ,"up" ,"enter" )# Start -> Model (up: IQ3_XXS, the 64 GB tier pre-selects IQ3_S) -> Folder 275self .assertEqual (app .current ,"folder" ) 276field = app .screen .query_one ("#folderpath" ) 277self .assertEqual (Path (field .value ).resolve (),docs .resolve ()) 278shown = flat (app ) 279self .assertIn ("The model is already downloaded" ,shown ) 280self .assertIn ("Only the draft layer is missing (5.2 GB)" ,shown ) 281self .assertNotIn ("Needs about" ,shown ) 282self .assertNotIn ("download the model" ,shown .lower ()) 283self .run_app (case ,ctx ) 284 285def test_everything_there_says_already_downloaded (self ): 286docs = self .build () 287 (docs / "mtp" / "rt" ).mkdir (parents = True ) 288 (docs / "mtp" / "rt" / "experts.bin" ).write_bytes (b"x" ) 289ctx = make_ctx () 290ctx .settings .family ,ctx .settings .model ,ctx .settings .vision = "qwen" ,"IQ3_XXS" ,"cpu" 291 292async def case (app ,pilot ,ctx ): 293await press (pilot ,"enter" ,"up" ,"enter" )# up: IQ3_XXS (IQ3_S is pre-selected) 294shown = flat (app ) 295self .assertIn ("Already downloaded" ,shown ) 296self .assertIn ("Nothing more to download" ,shown ) 297# and the final screen does not warn about a download 298await press (pilot ,* ("enter" ,)* 5 ,"n" ,"enter" ) 299self .assertIn ("Nothing needs to be downloaded" ,flat (app )) 300self .run_app (case ,ctx ) 301 302 303if __name__ == "__main__" : 304unittest .main ()