okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
aff3a132f
main
1"""The gate of CLEAN-1A: in every machine class x model set, the app's plain Load and the app's Models-screen Load start the engine as `strata launch` does, 2apart from the allow-list (tests/snapshot/allowlist.py). Reads the golden files, so it needs no Node and no machine; test_config_snapshot.py keeps the golden files true.""" 3 4from __future__import annotations 5 6import json 7import sys 8import unittest 9from pathlib import Path 10 11ROOT = Path (__file__ ).resolve ().parents [2 ] 12if str (ROOT )not in sys .path : 13sys .path .insert (0 ,str (ROOT )) 14 15from tests .snapshot import allowlist # noqa: E402 16from tests .snapshot .generate import GOLDEN # noqa: E402 17 18 19def flat (value ,prefix = "" ): 20if isinstance (value ,dict ): 21out = {} 22for k ,v in value .items (): 23out .update (flat (v ,f" { prefix } / { k } " )) 24return out 25return {prefix :value } 26 27 28def comparable (rec :dict ,allowed_cfg :set [str ])-> dict : 29cfg = {k :v for k ,v in rec ["config_file" ].items ()if k not in allowed_cfg } 30env = {k :v for k ,v in rec ["engine" ]["env_set" ].items ()if k not in allowed_cfg and k not in allowlist .ENV_BY_DESIGN } 31return {"config" :flat (cfg ),"argv" :rec ["engine" ]["argv" ],"env" :env ,"fetches" :rec .get ("fetches" )} 32 33 34class EntryPointsAgree (unittest .TestCase ): 35maxDiff = None 36 37def cells (self ): 38for path in sorted (GOLDEN .glob ("*/*.json" )): 39yield path .parent .name + "/" + path .stem ,json .loads (path .read_text (encoding = "utf-8" ))["entries" ] 40 41def check (self ,other :str ,allowed :set [str ]): 42seen = 0 43for cell ,entries in self .cells (): 44with self .subTest (cell = cell ,entry = other ): 45want ,got = comparable (entries ["launch" ],allowed ),comparable (entries [other ],allowed ) 46self .assertEqual (want ["argv" ],got ["argv" ],f" { cell } : engine arguments" ) 47self .assertEqual (want ["env" ],got ["env" ],f" { cell } : engine environment" ) 48self .assertEqual (want ["config" ],got ["config" ],f" { cell } : run config" ) 49self .assertEqual (want ["fetches" ],got ["fetches" ],f" { cell } : the drafter downloads asked for" ) 50seen += 1 51self .assertGreaterEqual (seen ,24 ) 52 53def test_the_plain_load_starts_the_engine_as_launch_does (self ): 54self .check ("app_plain" ,set (allowlist .BY_DESIGN )) 55 56def test_the_models_screen_load_differs_only_by_the_choice_it_saves (self ): 57self .check ("app_models" ,set (allowlist .BY_DESIGN )| set (allowlist .MODELS_SCREEN )) 58 59def test_no_app_entry_writes_request_slots (self ): 60for cell ,entries in self .cells (): 61for entry in ("app_plain" ,"app_models" ): 62self .assertNotIn ("parallel" ,entries [entry ]["config_file" ],f" { cell } / { entry } " ) 63self .assertNotIn ("--batch-mtp" ,entries [entry ]["engine" ]["argv" ],f" { cell } / { entry } " ) 64 65 66if __name__ == "__main__" : 67unittest .main ()