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
4.3 KiB98 linesraw
1"""QAGUI-STRIX 11-09 (APP-WIN item 3): on Windows Strix Halo the app's Models-screen Load rewrote the reserve setup wrote (700) to 1024, 2048 with pictures,
2while `strata launch` started the same model with 700.  The app's Load ("Leave room for my work" and "Full performance", what the Models screen passes)
3now starts the engine as `strata launch` does, from the run config setup writes; the only difference allowed is the work profile's --pool-workers (the
4profile's meaning) and the variables it sets (allowlist.ENV_BY_DESIGN, STRATA_RAM_KEEP_GIB).
5
6  python -m pytest tests/snapshot/test_strix_app_reserve.py -q        (needs Node, as the app entries of the snapshot do)
7"""
8
9from __future__ import annotations
10
11import json
12import os
13import shutil
14import sys
15import unittest
16from pathlib import Path
17from unittest import mock
18
19ROOT = Path(__file__).resolve().parents[2]
20if str(ROOT) not in sys.path:
21    sys.path.insert(0, str(ROOT))
22
23from tests.snapshot.driver import drive, drive_app, drive_launch  # noqa: E402
24from tests.snapshot.matrix import machine, model_set  # noqa: E402
25from tests.snapshot.world import World  # noqa: E402
26
27NODE = os.environ.get("STRATA_SNAPSHOT_NODE") or shutil.which("node")
28
29
30def flag(argv: list[str], name: str):
31    return argv[argv.index(name) + 1] if name in argv else None
32
33
34def without(argv: list[str], name: str) -> list[str]:
35    out, skip = [], False
36    for a in argv:
37        if skip:
38            skip = False
39            continue
40        if a == name:
41            skip = True
42            continue
43        out.append(a)
44    return out
45
46
47def setup_reserve(model: str) -> str:
48    """The reserve setup itself writes on this class (strata_control/setup_config.py, driven by the snapshot's setup entry)."""
49    args = drive("strix_halo_win", model, "setup")["config_file"]["args"]
50    return flag(args, "--vram-reserve-mib")
51
52
53def world_with_setup_reserve(model: str, reserve: str) -> World:
54    world = World(machine("strix_halo_win"), model_set(model)).build()
55    cfg = json.loads(world.config_path.read_text(encoding="utf-8"))
56    if "--vram-reserve-mib" not in cfg["args"]:
57        cfg["args"] += ["--vram-reserve-mib", reserve]
58    world.config_path.write_text(json.dumps(cfg, indent=1), encoding="utf-8")
59    return world
60
61
62@unittest.skipIf(not NODE, "no Node: the app's Load runs in Node")
63class StrixAppReserve(unittest.TestCase):
64    maxDiff = None
65
66    def engine(self, model: str, reserve: str, entry: str, app_args: dict | None = None) -> dict:
67        world = world_with_setup_reserve(model, reserve)
68        try:
69            if entry == "launch":
70                with world.patched():
71                    rec = drive_launch(world)
72            else:
73                with mock.patch.dict(os.environ, {"STRATA_SNAPSHOT_APP_ARGS": json.dumps(app_args or {})}):
74                    rec = drive_app(world, "models")
75            self.assertNotIn("failed", rec, json.dumps(rec.get("failed")))
76            # each entry runs in its own scratch world: its folder is written as <ROOT> so two engine lines can be compared
77            root = str(world.root)
78            return {**rec["engine"], "argv": [a.replace(root, "<ROOT>") for a in rec["engine"]["argv"]]}
79        finally:
80            world.close()
81
82    def test_the_models_screen_load_keeps_setups_reserve_and_starts_as_launch_does(self):
83        for model in ("ud_q4_k_xl", "iq3_s"):
84            reserve = setup_reserve(model)
85            self.assertEqual(reserve, "700", "setup's own reserve on Windows Strix Halo")
86            launch = self.engine(model, reserve, "launch")
87            self.assertEqual(flag(launch["argv"], "--vram-reserve-mib"), "700")
88            for profile in ("work", "performance"):
89                with self.subTest(model=model, profile=profile):
90                    app = self.engine(model, reserve, "app", {"resourceProfile": profile, "vision": "no", "values": {"drafting": "auto"}})
91                    self.assertEqual(flag(app["argv"], "--vram-reserve-mib"), "700", "the app keeps what setup wrote (it wrote 1024)")
92                    self.assertEqual(without(app["argv"], "--pool-workers"), without(launch["argv"], "--pool-workers"), "the same engine line")
93                    if profile == "performance":
94                        self.assertIsNone(flag(app["argv"], "--pool-workers"))
95
96
97if __name__ == "__main__":
98    unittest.main()