okami.mom/strata

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

Niko1221Merge f-clean-2 (c94ef2375): drafting and plan test fixtures no longer read the box's real Intel GPU (9 failures on the Arc box)6a7187997

main
5.0 KiB102 linesraw
1"""0.2.3 RC stress test: #6 (A07/B03) the download size counts the draft layer and the picture reader, B03 `--plan` does not call an installed
2engine missing, B10/E04 `--drafting off` leaves `--mtp <path>` out of the written config."""
3
4import unittest
5from unittest import mock
6
7from strata_cli.launch import modelstate, settings as S
8from strata_cli.launch.runner import Runner, derive_config
9from strata_control import engine_component
10from tests.terminal.launch_support import HW_12, Home, catalog
11
12
13class DownloadSize(unittest.TestCase):
14    def setUp(self):
15        self.home = Home().__enter__()
16        self.addCleanup(self.home.__exit__, None, None, None)
17        from tests.terminal.launch_support import not_intel
18        not_intel(self)
19
20    def runner(self, **kw):
21        values = dict(family="gyro", model="Gyro-S", context=32768, vision="cpu")
22        values.update(kw)
23        return Runner(S.LaunchSettings(**values), catalog=catalog(HW_12))
24
25    def test_gyro_s_counts_the_model_the_draft_layer_and_the_picture_reader(self):
26        runner = self.runner()
27        state = runner.model_state()
28        self.assertEqual([p.kind for p in state.parts], ["weights", "mtp", "mmproj"])
29        self.assertAlmostEqual(state.remaining_gb, 58.5 + 5.2 + 0.9, places=1)
30        title, text = runner.download_question()
31        self.assertEqual(title, "Download about 65 GB?")
32        plan = runner.download_plan()
33        self.assertEqual([p["kind"] for p in plan["parts"]], ["weights", "mtp", "mmproj"])
34        self.assertAlmostEqual(plan["gb"], 64.6, places=1)
35        self.assertIn("the draft layer (5.2 GB)", plan["text"])
36
37    def test_what_the_person_turns_off_is_not_counted(self):
38        self.assertEqual([p.kind for p in self.runner(vision="off").model_state().parts], ["weights", "mtp"])
39        self.assertEqual([p.kind for p in self.runner(mtp="off").model_state().parts], ["weights", "mmproj"])
40        self.assertEqual([p.kind for p in self.runner(drafting="off").model_state().parts], ["weights", "mmproj"])
41        self.assertAlmostEqual(self.runner(vision="off", mtp="off").model_state().remaining_gb, 58.5, places=1)
42
43    def test_the_other_families_that_get_helpers_count_the_same(self):
44        for family, model in (("qwen", "Q2_0"), ("swift", "IQ2_XS"), ("coder", "IQ3_XXS")):
45            kinds = [p.kind for p in self.runner(family=family, model=model).model_state().parts]
46            self.assertEqual(kinds, ["weights", "mtp", "mmproj"], family)
47
48    def test_setup_is_told_the_draft_layer_is_off_for_drafting_off(self):
49        args = self.runner(drafting="off").setup_args()
50        self.assertEqual(args[args.index("--mtp") + 1], "off")
51        self.assertTrue(modelstate.HELPER_FAMILIES.count("gyro"))
52
53
54class PlanEngine(unittest.TestCase):
55    def setUp(self):
56        self.home = Home().__enter__()
57        self.addCleanup(self.home.__exit__, None, None, None)
58
59    def plan(self, report):
60        runner = Runner(S.LaunchSettings(family="gyro", model="Gyro-S", context=32768, vision="off"), catalog=catalog(HW_12))
61        with mock.patch.object(engine_component, "status", return_value=report):
62            return runner.download_plan()
63
64    def test_an_engine_that_is_installed_but_unusable_is_not_called_missing(self):
65        out = self.plan({"usable": False, "installed": [{"version": "0.1.48"}], "notice": "x"})
66        self.assertIs(out["engine_missing"], False)
67        self.assertIs(out["engine_usable"], False)
68        self.assertIn("An engine (0.1.48) is installed", out["text"])
69        self.assertNotIn("downloaded first", out["text"])
70
71    def test_no_engine_at_all_is_missing_and_a_usable_one_is_neither(self):
72        out = self.plan({"usable": False, "installed": []})
73        self.assertIs(out["engine_missing"], True)
74        self.assertIn("downloaded first", out["text"])
75        ok = self.plan({"usable": True, "installed": [{"version": "0.1.48"}]})
76        self.assertEqual((ok["engine_missing"], ok["engine_usable"]), (False, True))
77
78
79class DraftingOffConfig(unittest.TestCase):
80    BASE = {"exe": "component:strata-engine", "port": 8080, "model_name": "m", "env": {},
81            "args": ["--native", "x.gguf", "--spec", "4", "--spec-min-p", "0.5", "--mtp", "/m/rt"]}
82
83    def test_drafting_off_writes_no_mtp_path(self):
84        cfg = derive_config(self.BASE, S.LaunchSettings(drafting="off"), bool_flags=frozenset())
85        self.assertIs(cfg["mtp"], False)
86        self.assertEqual(cfg["drafting"], "off")
87        for flag in ("--mtp", "--spec-min-p"):
88            self.assertNotIn(flag, cfg["args"])
89        self.assertIn("--mtp", self.BASE["args"])
90
91    def test_auto_and_mtp_keep_the_draft_layer(self):
92        for mode in ("auto", "mtp", None):
93            cfg = derive_config(self.BASE, S.LaunchSettings(drafting=mode), bool_flags=frozenset())
94            self.assertIn("--mtp", cfg["args"], mode)
95
96    def test_an_installed_config_that_already_says_off_stays_off(self):
97        cfg = derive_config({**self.BASE, "drafting": "off"}, S.LaunchSettings(), bool_flags=frozenset())
98        self.assertNotIn("--mtp", cfg["args"])
99
100
101if __name__ == "__main__":
102    unittest.main()