okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
6a7187997
main
1"""0.2.3 RC stress test: #6 (A07/B03) the download size counts the draft layer and the picture reader, B03 `--plan` does not call an installed 2engine missing, B10/E04 `--drafting off` leaves `--mtp <path>` out of the written config.""" 3 4import unittest 5from unittest import mock 6 7from strata_cli .launch import modelstate ,settings as S 8from strata_cli .launch .runner import Runner ,derive_config 9from strata_control import engine_component 10from tests .terminal .launch_support import HW_12 ,Home ,catalog 11 12 13class DownloadSize (unittest .TestCase ): 14def setUp (self ): 15self .home = Home ().__enter__ () 16self .addCleanup (self .home .__exit__ ,None ,None ,None ) 17from tests .terminal .launch_support import not_intel 18not_intel (self ) 19 20def runner (self ,** kw ): 21values = dict (family = "gyro" ,model = "Gyro-S" ,context = 32768 ,vision = "cpu" ) 22values .update (kw ) 23return Runner (S .LaunchSettings (** values ),catalog = catalog (HW_12 )) 24 25def test_gyro_s_counts_the_model_the_draft_layer_and_the_picture_reader (self ): 26runner = self .runner () 27state = runner .model_state () 28self .assertEqual ([p .kind for p in state .parts ], ["weights" ,"mtp" ,"mmproj" ]) 29self .assertAlmostEqual (state .remaining_gb ,58.5 + 5.2 + 0.9 ,places = 1 ) 30title ,text = runner .download_question () 31self .assertEqual (title ,"Download about 65 GB?" ) 32plan = runner .download_plan () 33self .assertEqual ([p ["kind" ]for p in plan ["parts" ]], ["weights" ,"mtp" ,"mmproj" ]) 34self .assertAlmostEqual (plan ["gb" ],64.6 ,places = 1 ) 35self .assertIn ("the draft layer (5.2 GB)" ,plan ["text" ]) 36 37def test_what_the_person_turns_off_is_not_counted (self ): 38self .assertEqual ([p .kind for p in self .runner (vision = "off" ).model_state ().parts ], ["weights" ,"mtp" ]) 39self .assertEqual ([p .kind for p in self .runner (mtp = "off" ).model_state ().parts ], ["weights" ,"mmproj" ]) 40self .assertEqual ([p .kind for p in self .runner (drafting = "off" ).model_state ().parts ], ["weights" ,"mmproj" ]) 41self .assertAlmostEqual (self .runner (vision = "off" ,mtp = "off" ).model_state ().remaining_gb ,58.5 ,places = 1 ) 42 43def test_the_other_families_that_get_helpers_count_the_same (self ): 44for family ,model in (("qwen" ,"Q2_0" ), ("swift" ,"IQ2_XS" ), ("coder" ,"IQ3_XXS" )): 45kinds = [p .kind for p in self .runner (family = family ,model = model ).model_state ().parts ] 46self .assertEqual (kinds , ["weights" ,"mtp" ,"mmproj" ],family ) 47 48def test_setup_is_told_the_draft_layer_is_off_for_drafting_off (self ): 49args = self .runner (drafting = "off" ).setup_args () 50self .assertEqual (args [args .index ("--mtp" )+ 1 ],"off" ) 51self .assertTrue (modelstate .HELPER_FAMILIES .count ("gyro" )) 52 53 54class PlanEngine (unittest .TestCase ): 55def setUp (self ): 56self .home = Home ().__enter__ () 57self .addCleanup (self .home .__exit__ ,None ,None ,None ) 58 59def plan (self ,report ): 60runner = Runner (S .LaunchSettings (family = "gyro" ,model = "Gyro-S" ,context = 32768 ,vision = "off" ),catalog = catalog (HW_12 )) 61with mock .patch .object (engine_component ,"status" ,return_value = report ): 62return runner .download_plan () 63 64def test_an_engine_that_is_installed_but_unusable_is_not_called_missing (self ): 65out = self .plan ({"usable" :False ,"installed" : [{"version" :"0.1.48" }],"notice" :"x" }) 66self .assertIs (out ["engine_missing" ],False ) 67self .assertIs (out ["engine_usable" ],False ) 68self .assertIn ("An engine (0.1.48) is installed" ,out ["text" ]) 69self .assertNotIn ("downloaded first" ,out ["text" ]) 70 71def test_no_engine_at_all_is_missing_and_a_usable_one_is_neither (self ): 72out = self .plan ({"usable" :False ,"installed" : []}) 73self .assertIs (out ["engine_missing" ],True ) 74self .assertIn ("downloaded first" ,out ["text" ]) 75ok = self .plan ({"usable" :True ,"installed" : [{"version" :"0.1.48" }]}) 76self .assertEqual ((ok ["engine_missing" ],ok ["engine_usable" ]), (False ,True )) 77 78 79class DraftingOffConfig (unittest .TestCase ): 80BASE = {"exe" :"component:strata-engine" ,"port" :8080 ,"model_name" :"m" ,"env" : {}, 81"args" : ["--native" ,"x.gguf" ,"--spec" ,"4" ,"--spec-min-p" ,"0.5" ,"--mtp" ,"/m/rt" ]} 82 83def test_drafting_off_writes_no_mtp_path (self ): 84cfg = derive_config (self .BASE ,S .LaunchSettings (drafting = "off" ),bool_flags = frozenset ()) 85self .assertIs (cfg ["mtp" ],False ) 86self .assertEqual (cfg ["drafting" ],"off" ) 87for flag in ("--mtp" ,"--spec-min-p" ): 88self .assertNotIn (flag ,cfg ["args" ]) 89self .assertIn ("--mtp" ,self .BASE ["args" ]) 90 91def test_auto_and_mtp_keep_the_draft_layer (self ): 92for mode in ("auto" ,"mtp" ,None ): 93cfg = derive_config (self .BASE ,S .LaunchSettings (drafting = mode ),bool_flags = frozenset ()) 94self .assertIn ("--mtp" ,cfg ["args" ],mode ) 95 96def test_an_installed_config_that_already_says_off_stays_off (self ): 97cfg = derive_config ({** self .BASE ,"drafting" :"off" },S .LaunchSettings (),bool_flags = frozenset ()) 98self .assertNotIn ("--mtp" ,cfg ["args" ]) 99 100 101if __name__ == "__main__" : 102unittest .main ()