okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
aff3a132f
main
1"""Every place a DeepSeek model can still come in (DeepSeek removed in release B; strata_control/retired.py) refuses it in plain words, at 2once, and leaves the person's config and files exactly as they were. No model is needed: fake configs, folders and GGUF headers.""" 3from __future__import annotations 4 5import argparse 6import contextlib 7import hashlib 8import io 9import json 10import struct 11import sys 12import tempfile 13import unittest 14from pathlib import Path 15from unittest import mock 16 17ROOT = Path (__file__ ).resolve ().parents [2 ] 18sys .path .insert (0 ,str (ROOT )) 19 20from strata_control import cfg_paths ,models ,retired ,runtime # noqa: E402 21from strata_control .profiles import ProfileError # noqa: E402 22 23D1_HEAD = "is a DeepSeek model. This version of Strata no longer runs DeepSeek models, so it was not started." 24 25 26def sha (p :Path )-> str : 27return hashlib .sha256 (p .read_bytes ()).hexdigest () 28 29 30def ds_install (d :Path ,* ,model_bytes :int = 3_000_000 )-> tuple [Path ,Path ,Path ]: 31"""(config, model folder, pack) of a fake DeepSeek install as setup 0.2.13 wrote it.""" 32models_dir = d / "data" / "models" / "deepseek-v4.1-flash-ist-das-2.00bpw" 33models_dir .mkdir (parents = True ) 34 (models_dir / "DeepSeek-V4.1-Flash-1017-GSQ-RCO-IQ2_XXS-00001-of-00004.gguf" ).write_bytes (b"\0" * model_bytes ) 35pack = d / "data" / "packs" / "deepseek" 36pack .mkdir (parents = True ) 37 (pack / "ds4.txt" ).write_text (f"format gguf\nmodel_dir { models_dir } \n" ,encoding = "utf-8" ) 38eng = d / "engine-dsv41" / "0.1.59-linux-x86_64-cuda-cuda13" 39eng .mkdir (parents = True ) 40exe = eng / "strata-dsv41" 41exe .write_text ("#!/bin/sh\necho started > \"$0.ran\"\n" ,encoding = "utf-8" ) 42cfg = {"exe" :str (exe ),"args" : ["--pack" ,str (pack ),"--max-context" ,"131072" ,"--eos" ,"1" ],"cwd" :str (d ), 43"tokenizer" :str (pack / "tokenizer" ),"model_name" :"deepseek-v4.1-flash" ,"arch" :"deepseek41" ,"port" :8080 , 44"lib_dirs" : [str (d / "components" / "engine" / "0.1.50-linux-x86_64-cuda" / "lib" )]} 45path = d / "strata-deepseek-v4.1-flash-ist-das-2.00bpw.json" 46path .write_text (json .dumps (cfg ,indent = 2 ),encoding = "utf-8" ) 47return path ,models_dir ,pack 48 49 50class StartRefused (unittest .TestCase ): 51"""The app and `strata start` (and a saved `strata launch` profile) start through runtime.start.""" 52 53def test_runtime_start_refuses_before_anything_is_written (self ): 54with tempfile .TemporaryDirectory ()as d : 55path ,models_dir ,pack = ds_install (Path (d )) 56before = sha (path ) 57profile = {"schema_version" :1 ,"id" :"launch-ds" ,"source_config" :str (path ),"overrides" : {}} 58with mock .patch .object (runtime .profiles ,"load" ,return_value = (profile ,"0" * 16 )), \ 59mock .patch .object (runtime ,"_repair_config_paths" ,side_effect = AssertionError ("wrote configs" )), \ 60mock .patch .object (runtime .subprocess ,"Popen" ,side_effect = AssertionError ("started a process" )): 61with self .assertRaises (ProfileError )as caught : 62runtime .start ("launch-ds" ,wait = 0 ) 63text = str (caught .exception ) 64self .assertTrue (text .startswith ("DeepSeek-V4.1-Flash ISTA-DAS 2.00 bpw " + D1_HEAD ),text ) 65self .assertIn (f"Its files are still on this computer: 0.0 GB in { models_dir } and { pack } . Nothing was changed or deleted." ,text ) 66self .assertTrue (text .endswith ("you can delete that folder to free the space." ),text ) 67self .assertEqual (sha (path ),before ) 68self .assertFalse (Path (json .loads (path .read_text ())["exe" ]+ ".ran" ).exists ()) 69 70def test_a_qwen_profile_is_not_stopped_here (self ): 71with tempfile .TemporaryDirectory ()as d : 72path = Path (d )/ "strata-iq3_s.json" 73path .write_text (json .dumps ({"exe" :"/x/strata" ,"args" : [],"arch" :"qwen3next" ,"model_name" :"q" }),encoding = "utf-8" ) 74profile = {"schema_version" :1 ,"id" :"app-1" ,"source_config" :str (path ),"overrides" : {}} 75with mock .patch .object (runtime .profiles ,"load" ,return_value = (profile ,"0" * 16 )): 76runtime ._refuse_deepseek ("app-1" )# no error 77 78 79class ConfigsNeverWritten (unittest .TestCase ): 80def test_path_repair_leaves_a_deepseek_config_alone (self ): 81with tempfile .TemporaryDirectory ()as d : 82path ,_m ,_p = ds_install (Path (d )) 83before = sha (path ) 84notes ,problems = cfg_paths .repair ([path ]) 85self .assertEqual ((notes ,problems ), ([], [])) 86self .assertEqual (sha (path ),before ) 87 88 89class ModelList (unittest .TestCase ): 90"""The app's model list and `strata models` read strata_control/models.py.""" 91 92def test_listed_as_retired_without_inspection (self ): 93with tempfile .TemporaryDirectory ()as d : 94path ,models_dir ,_p = ds_install (Path (d )) 95before = sha (path ) 96with mock .patch .object (models ,"inspect_components" ,side_effect = AssertionError ("inspected" )): 97out = models .inspect ("deepseek-v4.1-flash-ist-das-2.00bpw" ,override = d )["model" ] 98self .assertEqual (out ["component_status" ],"retired" ) 99self .assertEqual (out ["retired" ],"deepseek" ) 100self .assertEqual (out ["name" ],"DeepSeek-V4.1-Flash ISTA-DAS 2.00 bpw" ) 101self .assertTrue (out ["refusal" ].startswith ("DeepSeek-V4.1-Flash ISTA-DAS 2.00 bpw " + D1_HEAD )) 102self .assertIn (str (models_dir ),out ["retired_line" ]) 103self .assertEqual (sha (path ),before ) 104 105def test_import_of_deepseek_files_is_named (self ): 106with tempfile .TemporaryDirectory ()as d : 107_c ,models_dir ,_p = ds_install (Path (d )) 108with self .assertRaises (ProfileError )as caught : 109models .plan_import (str (models_dir )) 110self .assertIn ("These are DeepSeek model files (0.0 GB in" ,str (caught .exception )) 111self .assertIn ("nothing in the folder was changed" ,str (caught .exception )) 112 113 114class Server (unittest .TestCase ): 115"""serve/server.py started directly (a script, Docker, a gateway) with a DeepSeek config: stops before the engine starts.""" 116 117def run_server (self ,cfg :dict )-> tuple [int ,str ]: 118from serve import server 119with tempfile .TemporaryDirectory ()as d : 120p = Path (d )/ "c.json" 121p .write_text (json .dumps (cfg ),encoding = "utf-8" ) 122out = io .StringIO () 123with contextlib .redirect_stdout (out ): 124code = server .main (["--config" ,str (p ),"--port" ,"0" ]) 125return code ,out .getvalue () 126 127def test_arch (self ): 128code ,out = self .run_server ({"exe" :"/nowhere/strata-dsv41" ,"args" : [],"arch" :"deepseek41" }) 129self .assertEqual (code ,2 ) 130self .assertIn ("this config runs a DeepSeek model (arch deepseek41)" ,out ) 131self .assertIn ("so the server stops here. The model files were not changed." ,out ) 132 133def test_tokenizer_without_arch (self ): 134with tempfile .TemporaryDirectory ()as d : 135tok = Path (d )/ "tok" 136tok .mkdir () 137 (tok / "tokenizer.json" ).write_text (json .dumps ({"pre" :"deepseek3" }),encoding = "utf-8" ) 138code ,out = self .run_server ({"exe" :"/nowhere/strata" ,"args" : [],"tokenizer" :str (tok )}) 139self .assertEqual (code ,2 ) 140self .assertIn ("(DeepSeek tokenizer)" ,out ) 141 142 143class Setup (unittest .TestCase ): 144def run_setup (self ,* argv :str )-> tuple [int ,str ]: 145import setup 146out = io .StringIO () 147with mock .patch .object (sys ,"argv" , ["setup.py" ,* argv ]),contextlib .redirect_stdout (out ): 148code = setup .main () 149return code ,out .getvalue () 150 151def test_family_and_model_names (self ): 152for argv in (("--family" ,"deepseek41" ), ("--family" ,"deepseek41" ,"--model" ,"IST-DAS-2.00bpw" ), ("--model" ,"IST-DAS-2.25bpw" ), 153 ("--model=ISTA-DAS-Coder" ,)): 154code ,out = self .run_setup (* argv ,"--yes" ,"--no-start" ) 155self .assertEqual (code ,2 ,argv ) 156self .assertIn ("Strata no longer offers DeepSeek models. Run `strata launch` to choose one of the Qwen models." ,out ) 157 158def test_config_lists_leave_deepseek_out (self ): 159import setup 160with tempfile .TemporaryDirectory ()as d : 161path ,_m ,_p = ds_install (Path (d )) 162qwen = Path (d )/ "strata-iq3_s.json" 163qwen .write_text (json .dumps ({"exe" :"/x/strata" ,"args" : ["--model" ,"/m/q.gguf" ],"model_name" :"q" }),encoding = "utf-8" ) 164before = sha (path ) 165with mock .patch .object (setup ,"home" ,return_value = Path (d )): 166self .assertEqual (setup .installed_configs (), [qwen ]) 167self .assertEqual (setup .retired_configs (), [path ]) 168qwen .unlink () 169self .assertIsNone (setup .previous_config ([Path (d )], {"installs" : []}))# never set up "like" the DeepSeek model 170self .assertEqual (sha (path ),before ) 171self .assertEqual (retired .left_as_is (retired .title (None ,path )), 172"DeepSeek-V4.1-Flash ISTA-DAS 2.00 bpw: a DeepSeek model, left as it is (this version of Strata no longer " 173"runs DeepSeek models)." ) 174 175 176class Launch (unittest .TestCase ): 177def parse (self ,* argv :str )-> argparse .Namespace : 178from strata_cli .launch import cmd 179ap = argparse .ArgumentParser () 180cmd .add_parsers (ap .add_subparsers (dest = "command" )) 181return ap .parse_args (["launch" ,* argv ]) 182 183def test_typed_names (self ): 184from strata_cli .launch import cmd 185for argv in (("--model" ,"IST-DAS-2.00bpw" ), ("--family" ,"deepseek41" ,"--model" ,"UD-Q8_K_XL" ), ("--model" ,"ISTA-DAS-Coder" )): 186with self .assertRaises (ValueError )as caught : 187cmd .settings_from_args (self .parse (* argv ),catalog = object ()) 188self .assertEqual (str (caught .exception ),retired .NOT_OFFERED ,argv ) 189 190def test_saved_preset (self ): 191from strata_cli .launch import cmd ,store 192from strata_cli .launch .settings import LaunchSettings 193saved = LaunchSettings () 194saved .family ,saved .model = "deepseek41" ,"IST-DAS-2.00bpw" 195with mock .patch .object (store ,"load" ,return_value = saved ): 196with self .assertRaises (ValueError )as caught : 197cmd .settings_from_args (self .parse ("--preset" ,"big" ),catalog = object ()) 198self .assertEqual (str (caught .exception ),retired .NOT_OFFERED ) 199 200def test_each_dropped_deepseek_flag (self ): 201"""--dsv41-package, --speed, --full-quality and --dspark stay accepted (an old script, a saved shortcut) and answer D3.""" 202from strata_cli .launch import cmd 203for argv in (("--model" ,"IQ3_S" ,"--dsv41-package" ,"x.tar.gz" ), ("--model" ,"IQ3_S" ,"--speed" ,"faster" ), 204 ("--model" ,"IQ3_S" ,"--full-quality" ), ("--model" ,"IQ3_S" ,"--dspark" ,"on" )): 205with self .assertRaises (ValueError )as caught : 206cmd .settings_from_args (self .parse (* argv ),catalog = object ()) 207self .assertEqual (str (caught .exception ),retired .NOT_OFFERED ,argv ) 208 209def test_the_dropped_flags_are_not_in_the_help (self ): 210from strata_cli .launch import cmd 211ap = argparse .ArgumentParser () 212sub = ap .add_subparsers (dest = "command" ) 213cmd .add_parsers (sub ) 214text = sub .choices ["launch" ].format_help () 215for flag in ("--dsv41-package" ,"--speed" ,"--full-quality" ,"--dspark" ): 216self .assertNotIn (flag ,text ) 217 218def test_own_files (self ): 219from strata_cli .launch import runner 220with tempfile .TemporaryDirectory ()as d : 221_c ,models_dir ,_p = ds_install (Path (d )) 222fake = mock .Mock () 223fake .s = mock .Mock (model_path = str (models_dir )) 224with self .assertRaises (runner .LaunchError )as caught : 225runner .Runner .resolve_own_files (fake ) 226self .assertIn ("These are DeepSeek model files" ,caught .exception .text ) 227self .assertEqual (caught .exception .code ,2 ) 228 229def test_qwen_names_pass (self ): 230from strata_cli .launch import cmd 231 232class Cat : 233def resolve (self ,model ,family ): 234return ("qwen" ,model ) 235s ,_ = cmd .settings_from_args (self .parse ("--model" ,"IQ3_S" ),catalog = Cat ()) 236self .assertEqual ((s .family ,s .model ), ("qwen" ,"IQ3_S" )) 237 238 239if __name__ == "__main__" : 240unittest .main ()