okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
aff3a132f
main
1"""Changing the model must not carry a Drafting choice to a model that has none (owner, 2026-11-02): the Coder, Swift and NVFP4 builds have only the MTP. 2The Terminal's wizard goes back to Auto when the model changes to one of them, and the Q4_0-selector pack is made only where the installed engine reads it. 3""" 4 5from __future__import annotations 6 7import tempfile 8import unittest 9from pathlib import Path 10from types import SimpleNamespace 11from unittest import mock 12 13from strata_cli .launch import modelstate 14from strata_cli .launch import settings as S 15from strata_cli .launch .runner import derive_config 16from strata_control import drafting 17 18 19class TheChoiceStaysWithItsFamily (unittest .TestCase ): 20def test_qwen_gyro_and_unsloth_keep_it (self ): 21for family in ("qwen" ,"gyro" ,"unsloth" ): 22for choice in (None ,"auto" ,"mtp" ,"dflash2" ,"off" ): 23self .assertEqual (modelstate .drafting_for_family (choice ,family ),choice , (family ,choice )) 24 25def test_every_other_family_goes_back_to_auto (self ): 26for family in ("coder" ,"swift" ,"nvfp4" ): 27for choice in ("auto" ,"mtp" ,"dflash2" ,"off" ): 28self .assertIsNone (modelstate .drafting_for_family (choice ,family ), (family ,choice )) 29self .assertEqual (modelstate .drafting_for_family ("mtp" ,None ),"mtp" ,"no family yet: nothing to decide" ) 30 31def test_the_model_list_does_it_when_the_person_changes_model (self ): 32from strata_cli .launch .screens import ModelScreen 33rows = [SimpleNamespace (family = f ,model = "m" ,verdict = "fits" ,title = f )for f in ("qwen" ,"coder" ,"gyro" )] 34for target ,choice ,want in (("coder" ,"off" ,None ), ("gyro" ,"dflash2" ,"dflash2" ), ("qwen" ,"mtp" ,"mtp" )): 35s = S .LaunchSettings (family = "qwen" ,model = "m" ,drafting = choice ) 36fake = SimpleNamespace (ctx = SimpleNamespace (settings = s ,notes = []),rows = rows ,input_open = lambda :False , 37menu = lambda target = target :SimpleNamespace (current = SimpleNamespace (key = (target ,"m" )))) 38ModelScreen .commit (fake ) 39self .assertEqual ((s .family ,s .drafting ), (target ,want ), (target ,choice )) 40# and back to Qwen after the Coder: Auto (the choice that was made for the other model is gone), which the person can change again 41s = S .LaunchSettings (family = "qwen" ,model = "m" ,drafting = "mtp" ) 42for target in ("coder" ,"qwen" ): 43fake = SimpleNamespace (ctx = SimpleNamespace (settings = s ,notes = []),rows = rows ,input_open = lambda :False , 44menu = lambda target = target :SimpleNamespace (current = SimpleNamespace (key = (target ,"m" )))) 45ModelScreen .commit (fake ) 46self .assertIsNone (s .drafting ) 47 48 49class AQwenLaunchWritesItsDraftingChoice (unittest .TestCase ): 50def test_qwen_still_writes_it (self ): 51base = {"exe" :"component:strata-engine" ,"args" : ["--pack" ,"/d/packs/x" ,"--mtp" ,"/d/mtp/rt" ],"port" :8080 ,"model_name" :"qwen3.8-flash-next-iq3_s" } 52for family in ("qwen" ,"gyro" ,"unsloth" ): 53cfg = derive_config (base ,S .LaunchSettings (family = family ,drafting = "dflash2" ),bool_flags = frozenset ()) 54self .assertEqual (cfg ["drafting" ],"dflash2" ,family ) 55 56 57class TheSelectorPackIsMadeWhereTheEngineReadsIt (unittest .TestCase ): 58def test_the_engine_decides (self ): 59with tempfile .TemporaryDirectory ()as tmp : 60reads = Path (tmp )/ "reads.exe" 61reads .write_bytes (b"x" * 100 + drafting ._MARK_SELQ4 + b"y" * 100 ) 62sycl = Path (tmp )/ "sycl.exe" 63sycl .write_bytes (b"x" * 300 ) 64for exe ,want in ((reads ,True ), (sycl ,False ), (None ,False ), (Path (tmp )/ "missing.exe" ,False )): 65with mock .patch .object (drafting ,"installed_engine_exe" ,return_value = exe ): 66self .assertEqual (drafting .engine_has_selector_q4 (),want ,exe ) 67 68def test_a_launch_converts_only_for_such_an_engine (self ): 69import inspect 70from strata_cli .launch import runner 71source = inspect .getsource (runner ) 72self .assertIn ("drafting.needs_conversion(**want) and drafting.engine_has_selector_q4()" ,source ) 73 74 75if __name__ == "__main__" : 76unittest .main ()