okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
477fd36bc
main
1"""Tester report 2026-10-18, T06 / T08 / T10 and the smaller monitor items: one seven-view model in every view and at every width, 2Connect that says what is vendor history and what is this server's live result, and a light theme the Connect view and its pop-ups follow.""" 3 4from __future__import annotations 5 6import asyncio 7import re 8import unittest 9from unittest import mock 10 11from strata_cli import nav 12from strata_cli .launch import check ,harness 13from strata_cli .launch .monitor_ext import LaunchMonitor 14from strata_cli .launch .widgets import DARK ,LIGHT 15from strata_cli .monitor import MonitorApp 16from tests .terminal .launch_support import Home ,text_of 17from tests .terminal .test_launch_monitor import INFO 18from tests .terminal .test_overview import Source ,metrics 19 20SIZES = ((120 ,40 ), (80 ,24 ), (60 ,20 ), (40 ,15 )) 21NAMES = ["Overview" ,"Serving" ,"Requests" ,"Engine" ,"Hardware" ,"Logs" ,"Connect" ] 22SHORT = {"Overview" :"Over" ,"Serving" :"Serve" ,"Requests" :"Reqs" ,"Engine" :"Engine" ,"Hardware" :"GPU" ,"Logs" :"Logs" ,"Connect" :"Conn" } 23 24 25def tab_line (shown :str )-> str : 26"""The row with the tab names: the one that has the marked tab.""" 27for line in shown .splitlines (): 28if re .search (r"\[\d [A-Za-z]+\]" ,line )and re .search (r"\b\d [A-Za-z]+" ,line .replace ("[" ," " )): 29return line 30return "" 31 32 33def marked (line :str )-> str | None : 34m = re .search (r"\[(\d) ([A-Za-z]+)\]" ,line ) 35return None if m is None else m .group (2 ) 36 37 38class TabModel (unittest .TestCase ): 39def test_all_names_when_there_is_room (self ): 40self .assertEqual (nav .plain (1 ,120 ,True ),"1 Overview [2 Serving] 3 Requests 4 Engine 5 Hardware 6 Logs 7 Connect" ) 41self .assertEqual (nav .plain (1 ,120 ,False ),"1 Overview [2 Serving] 3 Requests 4 Engine 5 Hardware 6 Logs" ) 42 43def test_short_names_then_a_window_around_the_selected_tab_and_it_is_always_marked (self ): 44for connect in (False ,True ): 45for current in range (nav .count (connect )): 46for width in (120 ,90 ,80 ,60 ,50 ,40 ,30 ,24 ): 47line = nav .plain (current ,width ,connect ) 48self .assertLessEqual (len (line ),width , (current ,width ,connect )) 49name = NAMES [current ] 50self .assertTrue (f"[ { current + 1 } { name } ]" in line or f"[ { current + 1 } { SHORT [ name ] } ]" in line , (line ,current ,width )) 51if width >= 60 + (10 if connect else 0 ): 52self .assertNotIn ("<" ,line )# nothing hidden when the short names fit 53self .assertEqual (nav .plain (3 ,40 ,True ),"< 3 Reqs [4 Engine] 5 GPU 6 Logs 7 Conn" ) 54self .assertEqual (nav .plain (3 ,34 ,True ),"< 3 Reqs [4 Engine] 5 GPU 6 Logs >" ) 55 56def test_the_hint_matches_the_number_of_views (self ): 57self .assertEqual ((nav .keys (False ),nav .keys (True )), ("1-6" ,"1-7" )) 58 59def test_styled_marks_the_selected_tab_bold (self ): 60t = nav .styled (2 ,120 ,True ,accent = "#34d399" ) 61spans = [(t .plain [s .start :s .end ],s .style )for s in t .spans if "bold" in str (s .style )] 62self .assertEqual ([x for x ,_ in spans ], ["[3 Requests]" ]) 63 64 65class MonitorViews (unittest .TestCase ): 66def run_app (self ,cls ,size ,coro ,** kw ): 67async def go (): 68if cls is LaunchMonitor : 69app = LaunchMonitor (Source (metrics ("idle" )),None ,info = dict (INFO ),interval = 30 ,** kw ) 70else : 71app = MonitorApp (Source (metrics ("idle" )),None ,interval = 30 ,** kw ) 72async with app .run_test (size = size )as pilot : 73await pilot .pause (0.4 ) 74return await coro (app ,pilot ) 75with Home (): 76return asyncio .run (go ()) 77 78def test_arrows_visit_all_seven_views_and_wrap_both_ways (self ): 79async def case (app ,pilot ): 80seen = [app .view ] 81for _ in range (7 ): 82await pilot .press ("right" ) 83await pilot .pause (0.05 ) 84seen .append (app .view ) 85self .assertEqual (seen , [0 ,1 ,2 ,3 ,4 ,5 ,6 ,0 ])# Logs -> Connect -> Overview 86await pilot .press ("left" ) 87await pilot .pause (0.05 ) 88self .assertEqual (app .view ,6 )# Overview <- Connect 89await pilot .press ("left" ) 90await pilot .pause (0.05 ) 91self .assertEqual (app .view ,5 )# Connect <- Logs: the previous tab, not a relative of the last ordinary view 92self .run_app (LaunchMonitor , (120 ,40 ),case ) 93 94def test_number_keys_and_arrows_agree (self ): 95async def case (app ,pilot ): 96for n in range (1 ,8 ): 97await pilot .press (str (n )) 98await pilot .pause (0.05 ) 99self .assertEqual (app .view ,n - 1 ) 100self .run_app (LaunchMonitor , (120 ,40 ),case ) 101 102def test_every_view_at_every_size_shows_the_tabs_the_hint_and_the_selection (self ): 103async def case (app ,pilot ): 104for size in SIZES : 105await pilot .resize_terminal (* size ) 106await pilot .pause (0.15 ) 107for index in range (7 ): 108await pilot .press (str (index + 1 )) 109await pilot .pause (0.08 ) 110shown = text_of (app ) 111line = tab_line (shown ) 112name = marked (line ) 113self .assertIsNotNone (name , (size ,index ,shown [:400 ])) 114self .assertIn (name , (NAMES [index ],SHORT [NAMES [index ]]), (size ,index ,line )) 115self .assertNotIn ("1-6 views" ,shown , (size ,index ))# the hint never disagrees with the tab line 116self .assertIn ("Overview" if index == 0 and size [0 ]>= 78 else NAMES [index ][:3 ],shown .replace ("[" ," " ), (size ,index )) 117self .run_app (LaunchMonitor , (120 ,40 ),case ) 118 119def test_the_plain_monitor_has_six_views_and_says_1_6 (self ): 120async def case (app ,pilot ): 121for size in SIZES : 122await pilot .resize_terminal (* size ) 123await pilot .pause (0.15 ) 124shown = text_of (app ) 125self .assertNotIn ("Connect" ,shown ) 126self .assertNotIn ("1-7" ,shown ) 127await pilot .press ("7" ) 128await pilot .pause (0.05 ) 129self .assertEqual (app .view ,0 )# no seventh view here 130await pilot .press ("left" ) 131await pilot .pause (0.05 ) 132self .assertEqual (app .view ,5 ) 133self .run_app (MonitorApp , (120 ,40 ),case ) 134 135def test_strata_monitor_is_the_same_seven_view_monitor_as_launchs (self ): 136"""`strata monitor --url ...` builds the launch monitor without the quit question: seven views, key 7, Connect points at that server.""" 137from strata_cli import monitor_commands 138seen = {} 139 140class Fake : 141def __init__ (self ,endpoint ,snapshot ,** kw ): 142seen .update (kw ,endpoint = endpoint ) 143 144def run (self ): 145seen ["ran" ]= True 146 147args = monitor_commands .parser ().parse_args (["monitor" ,"--url" ,"http://127.0.0.1:18765" ]) 148with mock .patch ("strata_cli.launch.monitor_ext.LaunchMonitor" ,Fake ),mock .patch ("sys.stdout.isatty" ,return_value = True ),Home (): 149self .assertEqual (monitor_commands .run (args ),0 ) 150self .assertTrue (seen .get ("ran" )) 151self .assertFalse (seen ["ask_quit" ])# q detaches: this command started nothing 152self .assertEqual (seen ["info" ]["url" ],"http://127.0.0.1:18765" )# the Connect view's address is the --url server 153self .assertIn ("seven views" ," " .join (monitor_commands .parser ().format_help ().split ())) 154 155def test_the_monitor_strata_monitor_opens_has_seven_views_and_connect_shows_the_server (self ): 156async def case (app ,pilot ): 157shown = text_of (app ) 158self .assertIn ("7 Connect" ,shown ) 159self .assertNotIn ("1-6" ,shown ) 160await pilot .press ("7" ) 161await pilot .pause (0.2 ) 162self .assertEqual (app .view ,6 ) 163self .assertIn (INFO ["url" ],text_of (app )) 164await pilot .press ("escape" ) 165await pilot .pause (0.1 ) 166self .assertEqual (app .view ,0 ) 167async def go (): 168app = LaunchMonitor (Source (metrics ("idle" )),None ,info = dict (INFO ),interval = 30 ,ask_quit = False ) 169async with app .run_test (size = (120 ,40 ))as pilot : 170await pilot .pause (0.4 ) 171return await case (app ,pilot ) 172with Home (): 173asyncio .run (go ()) 174 175def test_the_overview_is_titled_overview (self ): 176async def case (app ,pilot ): 177self .assertIn ("STRATA Overview" ,text_of (app )) 178self .assertNotIn ("STRATA Serving" ,text_of (app )) 179await pilot .press ("2" ) 180await pilot .pause (0.1 ) 181self .assertIn ("Serving" ,text_of (app )) 182self .run_app (LaunchMonitor , (120 ,40 ),case ) 183 184 185class ConnectStatus (unittest .TestCase ): 186def run_app (self ,coro ,size = (120 ,40 ),** kw ): 187async def go (): 188app = LaunchMonitor (Source (metrics ("idle" )),None ,info = dict (INFO ),interval = 30 ,** kw ) 189async with app .run_test (size = size )as pilot : 190await pilot .pause (0.4 ) 191return await coro (app ,pilot ) 192with Home (): 193return asyncio .run (go ()) 194 195def test_vendor_history_and_this_servers_result_are_separate_columns (self ): 196async def case (app ,pilot ): 197await pilot .press ("7" ) 198await pilot .pause (0.2 ) 199shown = text_of (app ) 200header = next (ln for ln in shown .splitlines ()if "Vendor tested" in ln ) 201self .assertIn ("This server" ,header ) 202for h in harness .HARNESSES : 203said = "built into Strata" if h .built_in else h .tested 204row = next (ln for ln in shown .splitlines ()if h .title [:16 ]in ln and said [:23 ]in ln ) 205self .assertIn ("Not checked" ,row )# nothing has been tried against THIS server yet 206self .assertNotIn ("tested ok" ,row ) 207self .assertIn (said [:23 ],row ) 208self .assertNotIn ("Passed" ,shown ) 209self .run_app (case ) 210 211def test_a_check_turns_not_checked_into_passed_or_failed_for_that_app_only (self ): 212good = [check .Check ("prompt" ,True ,"ok" ,1.0 ),check .Check ("tool call" ,True ,"ok" ,1.0 )] 213bad = [check .Check ("prompt" ,True ,"ok" ,1.0 ),check .Check ("tool call" ,False ,"no tool call" ,1.0 )] 214 215async def case (app ,pilot ): 216await pilot .press ("7" ) 217for results ,want in ((good ,"Passed (2/2)" ), (bad ,"Failed (1/2)" )): 218with mock .patch .object (check ,"run_checks" ,return_value = results ): 219await pilot .press ("h" ) 220for _ in range (30 ): 221await pilot .pause (0.1 ) 222if want in text_of (app ): 223break 224self .assertIn (want ,text_of (app )) 225await pilot .press ("down" ) 226await pilot .pause (0.1 ) 227shown = text_of (app ) 228self .assertEqual (shown .count ("Not checked" ),6 )# 8 apps, 2 checked 229self .run_app (case ) 230 231def test_narrow_widths_keep_the_this_server_column (self ): 232async def case (app ,pilot ): 233for width in (80 ,60 ,40 ): 234await pilot .resize_terminal (width ,24 ) 235await pilot .pause (0.15 ) 236await pilot .press ("7" ) 237await pilot .pause (0.1 ) 238shown = text_of (app ) 239self .assertIn ("This server" ,shown ,width ) 240self .assertIn ("Not checked" ,shown ,width ) 241self .run_app (case ) 242 243 244def luminance (hex_color :str )-> float : 245r ,g ,b = (int (hex_color [i :i + 2 ],16 )/ 255 for i in (1 ,3 ,5 )) 246f = lambda c :c / 12.92 if c <= 0.03928 else ((c + 0.055 )/ 1.055 )** 2.4 # noqa: E731 247return 0.2126 * f (r )+ 0.7152 * f (g )+ 0.0722 * f (b ) 248 249 250def contrast (a :str ,b :str )-> float : 251la ,lb = sorted ((luminance (a ),luminance (b )),reverse = True ) 252return (la + 0.05 )/ (lb + 0.05 ) 253 254 255class LightTheme (unittest .TestCase ): 256def test_the_light_palette_is_readable_on_white_and_on_its_selection (self ): 257for name in ("fg" ,"mute" ,"accent" ,"warn" ,"bad" ): 258self .assertGreaterEqual (contrast (getattr (LIGHT ,name ),LIGHT .panel ),4.5 ,name ) 259self .assertGreaterEqual (contrast (LIGHT .accent ,LIGHT .sel ),4.5 ) 260self .assertLess (contrast (DARK .accent ,"#ffffff" ),3.0 )# the old dark colours are what the report measured (1.92:1) 261 262def run_app (self ,coro ,size = (120 ,40 )): 263async def go (): 264app = LaunchMonitor (Source (metrics ("idle" )),None ,info = dict (INFO ),interval = 30 ,theme = "light" ,color = "always" ) 265async with app .run_test (size = size )as pilot : 266await pilot .pause (0.4 ) 267return await coro (app ,pilot ) 268with Home (): 269return asyncio .run (go ()) 270 271def test_connect_uses_the_light_colours_only (self ): 272async def case (app ,pilot ): 273await pilot .press ("7" ) 274await pilot .pause (0.2 ) 275t = app .connect_text (118 ) 276used = {str (s .style )for s in t .spans } 277joined = " " .join (used ) 278for dark_only in ("#34d399" ,"#8e979f" ,"#f28b82" ,"#f5c56b" ,"#1f2a27" ): 279self .assertNotIn (dark_only ,joined ) 280self .assertIn (LIGHT .accent ,joined ) 281self .assertIn (LIGHT .mute ,joined ) 282self .run_app (case ) 283 284def test_the_dialog_opened_from_light_mode_is_light (self ): 285async def case (app ,pilot ): 286self .assertTrue (app .has_class ("theme-light" )) 287await pilot .press ("7" ) 288await pilot .pause (0.1 ) 289await pilot .press ("w" ) 290await pilot .pause (0.3 ) 291dialog = app .screen .query_one ("#dialog" ) 292self .assertEqual (str (dialog .styles .background .hex ).lower ()[:7 ],"#ffffff" ) 293await pilot .press ("escape" ) 294await pilot .pause (0.1 ) 295self .run_app (case ) 296 297def test_theme_cycling_moves_the_class_and_the_dialog_back_to_dark (self ): 298async def case (app ,pilot ): 299self .assertTrue (app .has_class ("theme-light" )) 300await pilot .press ("t" )# light -> terminal 301await pilot .pause (0.05 ) 302self .assertFalse (app .has_class ("theme-light" )) 303await pilot .press ("t" )# terminal -> dark 304await pilot .press ("7" ,"w" ) 305await pilot .pause (0.3 ) 306self .assertEqual (str (app .screen .query_one ("#dialog" ).styles .background .hex ).lower ()[:7 ],"#161a1d" ) 307self .run_app (case ) 308 309 310if __name__ == "__main__" : 311unittest .main ()