okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
aff3a132f
main
1"""packaging/make_model_release.py: the model-release plan is a dry run, case A leaves the engines alone, case B ships the engine of the new shape as its own 2component (the Strata engine, the Controls and the app are not rebuilt), and the steps that need the release key only print a placeholder. 3 4python -m unittest tests.terminal.test_make_model_release 5""" 6from __future__import annotations 7 8import contextlib 9import io 10import json 11import sys 12import tempfile 13import unittest 14from unittest import mock 15from pathlib import Path 16 17ROOT = Path (__file__ ).resolve ().parents [2 ] 18sys .path [:0 ]= [str (ROOT / "packaging" ),str (ROOT / "tools" ),str (ROOT )] 19import make_model_release as M # noqa: E402 20import test_qwen4_intake as T # noqa: E402 21import qwen4_intake as Q # noqa: E402 22 23PREV = {"strata-engine-0.1.57-linux-x86_64-cuda-cuda13.tar.gz" :720_000_000 ,"strata-engine-0.1.57-linux-x86_64-sycl.tar.gz" :187_000_000 , 24"strata-engine-0.1.57-windows-x86_64-cuda-cuda13.zip" :900_000_000 ,"strata-engine-0.1.57-macos-arm64-metal.tar.gz" :150_000_000 , 25"strata-control-0.1.57-linux-x86_64.tar.gz" :99_000_000 , 26"Strata-0.2.11-windows-x64-setup.exe" :80_000_000 ,"Strata-0.2.11-windows-x64-setup.exe.sig" :400 , 27"Strata-0.2.11-linux-x86_64.AppImage" :90_000_000 ,"Strata-0.2.11-macos-arm64.dmg" :160_000_000 ,"Strata.app.tar.gz" :70_000_000 , 28"strata-feed.json" :9000 ,"strata-feed.json.sig" :200 ,"SHA256SUMS.txt" :5000 ,"latest.json" :1500 ,"install.sh" :9000 } 29 30 31def make_prev (d :Path )-> Path : 32d .mkdir () 33for n ,size in PREV .items (): 34with (d / n ).open ("wb" )as f : 35f .truncate (size ) 36return d 37 38 39def report (name :str )-> dict : 40return Q .run ([Q .read_local (p )for p in T .files_for (name )],build_tokenizer = False ) 41 42 43def run (argv )-> tuple [int ,str ,str ]: 44out ,err = io .StringIO (),io .StringIO () 45with contextlib .redirect_stdout (out ),contextlib .redirect_stderr (err ): 46try : 47code = M .main (argv ) 48except SystemExit as e : 49code = e .code if isinstance (e .code ,int )else 1 50if isinstance (e .code ,str ): 51err .write (e .code ) 52return code ,out .getvalue (),err .getvalue () 53 54 55class Plan (unittest .TestCase ): 56@classmethod 57def setUpClass (cls ): 58cls .tmp = tempfile .TemporaryDirectory () 59cls .prev = make_prev (Path (cls .tmp .name )/ "prev" ) 60cls .a = Path (cls .tmp .name )/ "a.json" 61cls .a .write_text (json .dumps (report ("q36_ud_q4_k_xl" ))) 62 63@classmethod 64def tearDownClass (cls ): 65cls .tmp .cleanup () 66 67def base (self ,rep ,* extra ): 68return ["--intake" ,str (rep ),"--id" ,"m1" ,"--app-version" ,"0.2.12" ,"--sequence" ,"122" ,"--prev-upload" ,str (self .prev ),* extra ] 69 70def test_case_a_is_feed_and_app_only (self ): 71code ,out ,err = run (self .base (self .a ,"--json" ,"--revision" ,"abc" ,"--hf-repo" ,"x/y" )) 72self .assertEqual (code ,0 ,err ) 73p = json .loads (out ) 74self .assertEqual (p ["case" ],"A" ) 75names = {c ["name" ]for c in p ["changed" ]} 76self .assertFalse (any (n .startswith (("strata-engine-" ,"strata-dsv41-" ,"strata-control-" ))for n in names )) 77self .assertTrue ({"strata-feed.json" ,"strata-feed.json.sig" ,"SHA256SUMS.txt" }<= names ) 78# G12 of the Q4-P8 rehearsal: a feed model needs no app rebuild (the app lists it from the feed), so case A plans no app and no Mac step 79self .assertFalse (names & {"latest.json" ,"Strata-0.2.12-windows-x64-setup.exe" }) 80self .assertFalse (any ("App text" in s ["what" ]or "Mac" in s ["what" ]for s in p ["steps" ])) 81kept = {k ["name" ]for k in p ["kept" ]} 82self .assertTrue ({n for n in PREV if n .startswith (("strata-engine-" ,"strata-control-" ,"Strata-" ))}<= kept ) 83self .assertFalse (any ("Build the Qwen engine" in s ["what" ]for s in p ["steps" ])) 84self .assertEqual (p ["entry" ]["family" ],"qwen35moe" ) 85self .assertEqual (p ["entry" ]["hf" ], {"repo" :"x/y" ,"revision" :"abc" }) 86self .assertIs (p ["entry" ]["pictures" ],False )# no picture reader next to this set 87 88def test_case_a_with_app_plans_the_app_steps_when_asked (self ): 89code ,out ,err = run (self .base (self .a ,"--json" ,"--with-app" )) 90self .assertEqual (code ,0 ,err ) 91p = json .loads (out ) 92self .assertTrue ({"latest.json" ,"Strata-0.2.12-windows-x64-setup.exe" }<= {c ["name" ]for c in p ["changed" ]}) 93self .assertTrue (any ("App text" in s ["what" ]for s in p ["steps" ])) 94 95def test_the_plan_names_the_boxes_of_the_rehearsal (self ): 96code ,out ,err = run (self .base (self .a ,"--case" ,"B" ,"--engine-version" ,"0.1.58" ,"--shape" ,"q4_lite" )) 97self .assertEqual (code ,0 ,err ) 98for good in ("l620" ,"p1006" ,"owner PC" ,"m1002" ): 99self .assertIn (good ,out ) 100for stale in ("z440" ,"p1004" ,"m1001" ): 101self .assertNotIn (stale ,out ) 102self .assertIn ("STRATA_GEOMETRY_FILE" ,out ) 103self .assertIn ("--from-gguf" ,out ) 104 105def test_case_b_ships_the_shape_engine_as_its_own_component_and_rebuilds_nothing_else (self ): 106code ,out ,err = run (self .base (self .a ,"--json" ,"--case" ,"B" ,"--engine-version" ,"0.1.58" ,"--shape" ,"q4_lite" )) 107self .assertEqual (code ,0 ,err ) 108p = json .loads (out ) 109names = {c ["name" ]for c in p ["changed" ]} 110self .assertIn ("strata-q4-lite-0.1.58-linux-x86_64-sycl.tar.gz" ,names ) 111self .assertIn ("strata-q4-lite-0.1.58-windows-x86_64-cuda-cuda13.zip" ,names ) 112self .assertFalse (any (n .startswith (("strata-engine-" ,"strata-control-" ,"strata-dsv41-" ))for n in names ),"the Strata engine and the Controls are not rebuilt" ) 113self .assertFalse (any ("0.1.57" in n for n in names )) 114kept = {k ["name" ]for k in p ["kept" ]} 115self .assertTrue ({n for n in PREV if n .startswith (("strata-engine-" ,"strata-control-" ,"Strata-" ))}<= kept ) 116self .assertFalse (any ("Controls: pack" in s ["what" ]or "App text" in s ["what" ]for s in p ["steps" ])) 117self .assertIn ("strata-q4-lite-0.1.58-macos-arm64-metal.tar.gz" ,names ) 118self .assertTrue (any ("Mac" in s ["what" ]and s ["owner_only" ]for s in p ["steps" ]),"the owner signs the Mac shape engine" ) 119self .assertTrue (any ("--shape q4_lite" in c for s in p ["steps" ]for c in s ["commands" ])) 120self .assertTrue (any ("--shapes <shape-entries>" in c for s in p ["steps" ]for c in s ["commands" ])) 121self .assertEqual (p ["entry" ]["family" ],"qwen35moe" ,"the family changes only for a qwen4exp model" ) 122for missing in ({"--shape" :None }, {"--engine-version" :None }): 123args = ["--case" ,"B" ,"--engine-version" ,"0.1.58" ,"--shape" ,"q4_lite" ] 124for k in missing : 125i = args .index (k ) 126del args [i :i + 2 ] 127code ,_ ,err = run (self .base (self .a ,* args )) 128self .assertNotEqual (code ,0 ,missing )# case B needs an engine version and a shape 129code ,_ ,err = run (self .base (self .a ,"--case" ,"B" ,"--engine-version" ,"0.1.58" ,"--shape" ,"Not A Shape" )) 130self .assertNotEqual (code ,0 ) 131code ,_ ,err = run (self .base (self .a ,"--shape" ,"q4_lite" )) 132self .assertNotEqual (code ,0 )# --shape is for case B 133 134def test_a_case_b_entry_names_the_family_of_its_shape (self ): 135from strata_control import feed as feedmod 136rep = json .loads (self .a .read_text ()) 137rep ["sets" ][0 ]["architecture" ]= "qwen4exp" 138b = Path (self .tmp .name )/ "b.json" 139b .write_text (json .dumps (rep )) 140out = Path (self .tmp .name )/ "outb" 141code ,_ ,err = run (self .base (b ,"--case" ,"B" ,"--engine-version" ,"0.1.59" ,"--shape" ,"q4_lite" ,"--write" ,str (out ),"--revision" ,"a" * 40 ,"--hf-repo" ,"x/y" )) 142self .assertEqual (code ,0 ,err ) 143self .assertEqual (json .loads ((out / "models" / "m1.entry.json" ).read_text ())["family" ],"qwen4exp_q4_lite" ) 144self .assertEqual (json .loads ((out / "models" / "m1.model.json" ).read_text ())["family" ],"qwen4exp_q4_lite" ) 145self .assertEqual (feedmod .shape_engine .shape_of_family ("qwen4exp_q4_lite" ),"q4_lite" ) 146 147def test_case_c_is_refused (self ): 148p = Path (self .tmp .name )/ "c.json" 149p .write_text (json .dumps (report ("ds41_ud_q8_k_xl" ))) 150code ,out ,err = run (self .base (p )) 151self .assertNotEqual (code ,0 ) 152self .assertIn ("case C" ,err ) 153self .assertEqual (out ,"" ) 154 155def test_it_is_a_dry_run_and_never_touches_a_key (self ): 156code ,out ,err = run (self .base (self .a ,"--execute" )) 157self .assertEqual (code ,2 ) 158self .assertIn ("REFUSED" ,out ) 159with contextlib .redirect_stderr (io .StringIO ()),self .assertRaises (SystemExit ): 160M .main (self .base (self .a ,"--key" ,"k.json" ))# there is no such option 161code ,out ,err = run (self .base (self .a )) 162self .assertEqual (code ,0 ,err ) 163key_lines = [l for l in out .splitlines ()if "--key" in l or "sign-package" in l ] 164self .assertTrue (key_lines ) 165for l in key_lines : 166self .assertIn ("<FEED-KEY>" ,l ) 167src = Path (M .__file__ ).read_text (encoding = "utf-8" ) 168for bad in ("subprocess" ,"os.system" ,"urllib" ,"requests" ,"socket" ,"shutil.copy" ): 169self .assertNotIn (bad ,src ) 170 171def test_write_makes_the_entry_and_fills_the_templates (self ): 172t = Path (self .tmp .name )/ "tpl" 173t .mkdir () 174 (t / "RELEASE-NOTES.md" ).write_text ("# {{model_title}} {{app_version}}\n{{file_rows}}\n[FILL: a number] {{unknown}}\n" ,encoding = "utf-8" ) 175out = Path (self .tmp .name )/ "out" 176code ,_ ,err = run (self .base (self .a ,"--write" ,str (out ),"--templates" ,str (t ),"--revision" ,"abc" )) 177self .assertNotEqual (code ,0 ,"case A with --write needs --min-engine (Q4-READY: it left a [FILL] in the entry)" ) 178self .assertIn ("--min-engine" ,err ) 179self .assertFalse (out .exists ()) 180code ,_ ,err = run (self .base (self .a ,"--write" ,str (out ),"--templates" ,str (t ),"--revision" ,"abc" ,"--min-engine" ,"0.1.58" )) 181self .assertEqual (code ,0 ,err ) 182entry = json .loads ((out / "models" / "m1.model.json" ).read_text ()) 183self .assertIn ("DRAFT" ,entry ["_status" ]) 184self .assertEqual (entry ["files" ][0 ]["name" ],"Qwen3.6-35B-A3B-UD-Q4_K_XL.gguf" ) 185self .assertEqual (entry ["drafter" ],"mtp" ) 186self .assertEqual (entry ["min_engine" ],"0.1.58" ) 187notes = (out / "RELEASE-NOTES.md" ).read_text () 188self .assertIn ("# Qwen3.6-35B-A3B 0.2.12" ,notes ) 189self .assertIn ("[FILL: a number]" ,notes ) 190self .assertIn ("{{unknown}}" ,notes )# a key it does not know stays visible 191self .assertTrue ((out / "PLAN.md" ).is_file ()and (out / "plan.json" ).is_file ()) 192code ,_ ,err = run (self .base (self .a ,"--write" ,str (out )))# not an empty folder 193self .assertNotEqual (code ,0 ) 194 195def test_write_makes_an_entry_in_the_feeds_schema_and_build_feed_refuses_what_is_unfilled (self ): 196import feed_tool 197from strata_control import feed as feedmod 198out = Path (self .tmp .name )/ "outfeed" 199rev = "a" * 40 200code ,_ ,err = run (self .base (self .a ,"--write" ,str (out ),"--revision" ,rev ,"--hf-repo" ,"x/y" ,"--default-context" ,"131072" ,"--min-engine" ,"0.1.58" )) 201self .assertEqual (code ,0 ,err ) 202path = out / "models" / "m1.entry.json" 203entry = json .loads (path .read_text ()) 204self .assertIn ("[FILL" ,json .dumps (entry ))# the values the report cannot know are left to a person 205with self .assertRaises (SystemExit )as cm : 206feed_tool .build_feed (Path (self .tmp .name )/ "rel0" ,key = {},sequence = 1 ,models_dir = out / "models" ) 207self .assertIn ("FILL" ,str (cm .exception )) 208out2 = Path (self .tmp .name )/ "outfeed2" 209code ,_ ,err = run (self .base (self .a ,"--write" ,str (out2 ),"--revision" ,rev ,"--hf-repo" ,"x/y" ,"--default-context" ,"131072" ,"--about" ,"one sentence" , 210"--licence" ,"Apache 2.0" ,"--licence-url" ,"https://example.org/licence" ,"--quant" ,"Q4" ,"--quant-about" ,"4-bit" ,"--ram-gb" ,"24" ,"--min-engine" ,"0.1.58" , 211"--title" ,"Qwen4 Test" )) 212self .assertEqual (code ,0 ,err ) 213filled = json .loads ((out2 / "models" / "m1.entry.json" ).read_text ()) 214self .assertEqual (filled ["title" ],"Qwen4 Test" )# --title (Q4-READY); without it the file's general.name, as before 215self .assertEqual (json .loads ((out / "models" / "m1.entry.json" ).read_text ())["title" ],"Qwen3.6-35B-A3B" ) 216self .assertNotIn ("[FILL" ,json .dumps (filled ).replace ("[FILL: sha256]" ,"" )) 217for f in filled ["quants" ][0 ]["files" ]: 218f ["sha256" ]= f ["sha256" ]if len (f ["sha256" ])== 64 else "0" * 64 219feedmod ._model_entry (filled )# strata_control/feed.py keeps it 220 221def test_the_plan_prints_the_launch_line_with_the_size_name_a_person_types (self ): 222"""Q4-READY: a feed size whose quant name is a built-in size is <quant>-<id> (strata_control/feed_models.py); the rehearsal typed the plain name twice.""" 223code ,out ,err = run (self .base (self .a ,"--json" ,"--quant" ,"UD-Q4_K_XL" )) 224self .assertEqual (code ,0 ,err ) 225launch = json .loads (out )["launch" ] 226self .assertIn ("strata launch --family m1 --model ud-q4_k_xl-m1" ,launch ) 227self .assertTrue (any (l .startswith ("strata launch --family m1 --model ud-q4_k_xl-m1 --model-path " )for l in launch )) 228code ,out ,err = run (self .base (self .a ,"--json" ,"--quant" ,"Q4REH" )) 229self .assertEqual (code ,0 ,err ) 230self .assertIn ("strata launch --family m1 --model q4reh" ,json .loads (out )["launch" ]) 231code ,out ,err = run (self .base (self .a ,"--quant" ,"Q4REH" )) 232self .assertIn ("## How a person starts it" ,out ) 233self .assertIn (" strata launch --family m1 --model q4reh" ,out ) 234with mock .patch .object (M ,"builtin_sizes" ,return_value = None ): 235code ,out ,err = run (self .base (self .a ,"--json" ,"--quant" ,"Q4REH" )) 236launch = json .loads (out )["launch" ] 237self .assertIn ("strata launch --family m1 --model q4reh" ,launch ) 238self .assertIn ("strata launch --family m1 --model q4reh-m1" ,launch ) 239 240def test_the_repo_templates_have_what_the_script_fills (self ): 241"""The templates live in the repo (packaging/templates/model-release, the default of --templates), so this runs on every box.""" 242d = M .TEMPLATES 243self .assertEqual (d ,Path (M .__file__ ).resolve ().parents [1 ]/ "packaging" / "templates" / "model-release" ) 244self .assertTrue ((d / "RELEASE-NOTES.md" ).is_file ()and (d / "MODEL-CARD.md" ).is_file ()) 245self .assertFalse ((d / "CHECKLIST.md" ).exists (),"the release checklist is an internal work list and is not in the repo" ) 246out = Path (self .tmp .name )/ "out2" 247code ,_ ,err = run (self .base (self .a ,"--write" ,str (out ),"--revision" ,"abc" ,"--hf-repo" ,"x/y" )) 248self .assertNotEqual (code ,0 ,"case A with --write needs --min-engine (078b52563)" ) 249self .assertIn ("case A: give --min-engine" ,err ) 250self .assertFalse (out .exists ()) 251code ,_ ,err = run (self .base (self .a ,"--write" ,str (out ),"--revision" ,"abc" ,"--hf-repo" ,"x/y" ,"--min-engine" ,"0.1.58" )) 252self .assertEqual (code ,0 ,err ) 253self .assertIn ("no template CHECKLIST.md" ,err ) 254for name in ("RELEASE-NOTES.md" ,"MODEL-CARD.md" ): 255text = (out / name ).read_text (encoding = "utf-8" ) 256self .assertRegex (text .splitlines ()[0 ],"DRAFT" )# drafts for the owner's approval 257self .assertNotIn ("{{" ,text ,name )# every key the templates use is one the script fills 258notes = (out / "RELEASE-NOTES.md" ).read_text (encoding = "utf-8" ) 259self .assertTrue (notes .rstrip ().endswith ('height="50"></a>' ))# the coffee button is last 260self .assertIn ("[FILL" ,notes ) 261self .assertFalse ((out / "CHECKLIST.md" ).exists ()) 262 263def test_the_private_checklist_by_path_beside_the_repo_templates (self ): 264"""--checklist names the internal checklist (outside the repo) and the notes and the model card still come from the repo's default folder.""" 265priv = Path (self .tmp .name )/ "private" 266priv .mkdir () 267 (priv / "my-list.md" ).write_text ("<!-- WORKING DOCUMENT -->\n# Runbook {{model_title}} case {{case}}\n" ,encoding = "utf-8" ) 268out = Path (self .tmp .name )/ "out-checklist" 269code ,_ ,err = run (self .base (self .a ,"--write" ,str (out ),"--checklist" ,str (priv / "my-list.md" ),"--revision" ,"abc" ,"--min-engine" ,"0.1.58" )) 270self .assertEqual (code ,0 ,err ) 271self .assertEqual ((out / "CHECKLIST.md" ).read_text (encoding = "utf-8" ),"<!-- WORKING DOCUMENT -->\n# Runbook Qwen3.6-35B-A3B case A\n" ) 272self .assertEqual ((out / "RELEASE-NOTES.md" ).read_text (encoding = "utf-8" ).splitlines ()[0 ], 273 (M .TEMPLATES / "RELEASE-NOTES.md" ).read_text (encoding = "utf-8" ).splitlines ()[0 ])# the repo's notes 274self .assertTrue ((out / "MODEL-CARD.md" ).is_file ()) 275self .assertNotIn ("no template CHECKLIST.md" ,err ) 276code ,_ ,err = run (self .base (self .a ,"--write" ,str (Path (self .tmp .name )/ "out-missing" ),"--checklist" ,str (priv / "nope.md" ),"--min-engine" ,"0.1.58" )) 277self .assertNotEqual (code ,0 ) 278self .assertIn ("--checklist: no file" ,err ) 279 280def test_another_templates_folder_is_still_read (self ): 281t = Path (self .tmp .name )/ "tpl-other" 282t .mkdir () 283for name in M .TEMPLATE_NAMES : 284 (t / name ).write_text ("# %s {{model_title}}\n" % name ,encoding = "utf-8" ) 285out = Path (self .tmp .name )/ "out-other" 286code ,_ ,err = run (self .base (self .a ,"--write" ,str (out ),"--templates" ,str (t ),"--revision" ,"abc" ,"--min-engine" ,"0.1.58" )) 287self .assertEqual (code ,0 ,err ) 288for name in M .TEMPLATE_NAMES : 289self .assertEqual ((out / name ).read_text (encoding = "utf-8" ),"# %s Qwen3.6-35B-A3B\n" % name ) 290 291 292if __name__ == "__main__" : 293unittest .main ()