okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge main (87dfca0e7) into f-own-int: the 0.2.14 app branch, fixtures and CI fixes, the Qwen4-readiness tools, the shape-engine build scriptsffb3d9b31

main
2.6 KiB54 linesraw
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:
12    here = root / name / "usr" / "lib" / "Strata" / "control"
13    (here / "data").mkdir(parents=True)
14    (here / "data" / "expert-profile.bin").write_bytes(b"x")
15    return here
16
17
18class ControlPaths(unittest.TestCase):
19    def setUp(self):
20        tmp = tempfile.TemporaryDirectory()
21        self.addCleanup(tmp.cleanup)
22        self.root = Path(tmp.name)
23
24    def test_a_gone_mount_path_is_pointed_at_this_control(self):
25        here = _control(self.root, ".mount_StrataNEW")
26        gone = "/tmp/.mount_StratappjGco/usr/lib/Strata/control"
27        cfg = {"cwd": gone, "args": ["--native", "/data/m/a.gguf", "--expert-profile", gone + "/data/expert-profile.bin", "--max-context", "32768"],
28               "model_name": "Qwen"}
29        out = control_paths.repoint(cfg, here)
30        self.assertEqual(out["cwd"], str(here))
31        self.assertEqual(out["args"][3], str(here / "data" / "expert-profile.bin"))
32        self.assertEqual(out["args"][:3], cfg["args"][:3])
33        self.assertEqual(out["args"][4:], cfg["args"][4:])
34        self.assertEqual(cfg["cwd"], gone, "the input is not changed")
35
36    def test_paths_that_exist_or_have_no_counterpart_stay(self):
37        here = _control(self.root, "new")
38        other = _control(self.root, "old")
39        kept = str(other / "data" / "expert-profile.bin")
40        self.assertEqual(control_paths.repoint_value(kept, here), kept, "an existing file is left alone")
41        missing = "/tmp/.mount_X/usr/lib/Strata/control/data/not-in-this-control.bin"
42        self.assertEqual(control_paths.repoint_value(missing, here), missing, "no counterpart: unchanged (the start reports it)")
43        self.assertEqual(control_paths.repoint_value("/home/u/controller/x", here), "/home/u/controller/x")
44        self.assertEqual(control_paths.repoint_value(32768, here), 32768)
45
46    def test_the_update_test_start_uses_the_repointed_config(self):
47        src = (Path(control_paths.__file__).parent / "updater.py").read_text(encoding="utf-8")
48        at = src.index('cfg = json.loads(source.read_text(encoding="utf-8-sig"))')
49        self.assertIn("control_paths.repoint(cfg)", src[at:at + 400])
50        json.dumps(control_paths.repoint({"cwd": "x"}))
51
52
53if __name__ == "__main__":
54    unittest.main()