okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
ffb3d9b31
main
1"""A run config that names files in a Control folder that is gone (the AppImage's /tmp/.mount_<random>) is pointed at this Control (QAGUI-LIN 0213). 2Plain unittest with tempfile (pytest's tmp_path base folder cannot be read on the owner PC: WinError 5, 11-10).""" 3import json 4import tempfile 5import unittest 6from pathlib import Path 7 8from strata_control import control_paths 9 10 11def _control (root :Path ,name :str )-> Path : 12here = root / name / "usr" / "lib" / "Strata" / "control" 13 (here / "data" ).mkdir (parents = True ) 14 (here / "data" / "expert-profile.bin" ).write_bytes (b"x" ) 15return here 16 17 18class ControlPaths (unittest .TestCase ): 19def setUp (self ): 20tmp = tempfile .TemporaryDirectory () 21self .addCleanup (tmp .cleanup ) 22self .root = Path (tmp .name ) 23 24def test_a_gone_mount_path_is_pointed_at_this_control (self ): 25here = _control (self .root ,".mount_StrataNEW" ) 26gone = "/tmp/.mount_StratappjGco/usr/lib/Strata/control" 27cfg = {"cwd" :gone ,"args" : ["--native" ,"/data/m/a.gguf" ,"--expert-profile" ,gone + "/data/expert-profile.bin" ,"--max-context" ,"32768" ], 28"model_name" :"Qwen" } 29out = control_paths .repoint (cfg ,here ) 30self .assertEqual (out ["cwd" ],str (here )) 31self .assertEqual (out ["args" ][3 ],str (here / "data" / "expert-profile.bin" )) 32self .assertEqual (out ["args" ][:3 ],cfg ["args" ][:3 ]) 33self .assertEqual (out ["args" ][4 :],cfg ["args" ][4 :]) 34self .assertEqual (cfg ["cwd" ],gone ,"the input is not changed" ) 35 36def test_paths_that_exist_or_have_no_counterpart_stay (self ): 37here = _control (self .root ,"new" ) 38other = _control (self .root ,"old" ) 39kept = str (other / "data" / "expert-profile.bin" ) 40self .assertEqual (control_paths .repoint_value (kept ,here ),kept ,"an existing file is left alone" ) 41missing = "/tmp/.mount_X/usr/lib/Strata/control/data/not-in-this-control.bin" 42self .assertEqual (control_paths .repoint_value (missing ,here ),missing ,"no counterpart: unchanged (the start reports it)" ) 43self .assertEqual (control_paths .repoint_value ("/home/u/controller/x" ,here ),"/home/u/controller/x" ) 44self .assertEqual (control_paths .repoint_value (32768 ,here ),32768 ) 45 46def test_the_update_test_start_uses_the_repointed_config (self ): 47src = (Path (control_paths .__file__ ).parent / "updater.py" ).read_text (encoding = "utf-8" ) 48at = src .index ('cfg = json.loads(source.read_text(encoding="utf-8-sig"))' ) 49self .assertIn ("control_paths.repoint(cfg)" ,src [at :at + 400 ]) 50json .dumps (control_paths .repoint ({"cwd" :"x" })) 51 52 53if __name__ == "__main__" : 54unittest .main ()