okami.mom/strata

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

Niko1221Merge f-ds-out ac306afb2 into f-own-intaff3a132f

main
4.1 KiB76 linesraw
1"""Changing the model must not carry a Drafting choice to a model that has none (owner, 2026-11-02): the Coder, Swift and NVFP4 builds have only the MTP.
2The Terminal's wizard goes back to Auto when the model changes to one of them, and the Q4_0-selector pack is made only where the installed engine reads it.
3"""
4
5from __future__ import annotations
6
7import tempfile
8import unittest
9from pathlib import Path
10from types import SimpleNamespace
11from unittest import mock
12
13from strata_cli.launch import modelstate
14from strata_cli.launch import settings as S
15from strata_cli.launch.runner import derive_config
16from strata_control import drafting
17
18
19class TheChoiceStaysWithItsFamily(unittest.TestCase):
20    def test_qwen_gyro_and_unsloth_keep_it(self):
21        for family in ("qwen", "gyro", "unsloth"):
22            for choice in (None, "auto", "mtp", "dflash2", "off"):
23                self.assertEqual(modelstate.drafting_for_family(choice, family), choice, (family, choice))
24
25    def test_every_other_family_goes_back_to_auto(self):
26        for family in ("coder", "swift", "nvfp4"):
27            for choice in ("auto", "mtp", "dflash2", "off"):
28                self.assertIsNone(modelstate.drafting_for_family(choice, family), (family, choice))
29        self.assertEqual(modelstate.drafting_for_family("mtp", None), "mtp", "no family yet: nothing to decide")
30
31    def test_the_model_list_does_it_when_the_person_changes_model(self):
32        from strata_cli.launch.screens import ModelScreen
33        rows = [SimpleNamespace(family=f, model="m", verdict="fits", title=f) for f in ("qwen", "coder", "gyro")]
34        for target, choice, want in (("coder", "off", None), ("gyro", "dflash2", "dflash2"), ("qwen", "mtp", "mtp")):
35            s = S.LaunchSettings(family="qwen", model="m", drafting=choice)
36            fake = SimpleNamespace(ctx=SimpleNamespace(settings=s, notes=[]), rows=rows, input_open=lambda: False,
37                                   menu=lambda target=target: SimpleNamespace(current=SimpleNamespace(key=(target, "m"))))
38            ModelScreen.commit(fake)
39            self.assertEqual((s.family, s.drafting), (target, want), (target, choice))
40        # and back to Qwen after the Coder: Auto (the choice that was made for the other model is gone), which the person can change again
41        s = S.LaunchSettings(family="qwen", model="m", drafting="mtp")
42        for target in ("coder", "qwen"):
43            fake = SimpleNamespace(ctx=SimpleNamespace(settings=s, notes=[]), rows=rows, input_open=lambda: False,
44                                   menu=lambda target=target: SimpleNamespace(current=SimpleNamespace(key=(target, "m"))))
45            ModelScreen.commit(fake)
46        self.assertIsNone(s.drafting)
47
48
49class AQwenLaunchWritesItsDraftingChoice(unittest.TestCase):
50    def test_qwen_still_writes_it(self):
51        base = {"exe": "component:strata-engine", "args": ["--pack", "/d/packs/x", "--mtp", "/d/mtp/rt"], "port": 8080, "model_name": "qwen3.8-flash-next-iq3_s"}
52        for family in ("qwen", "gyro", "unsloth"):
53            cfg = derive_config(base, S.LaunchSettings(family=family, drafting="dflash2"), bool_flags=frozenset())
54            self.assertEqual(cfg["drafting"], "dflash2", family)
55
56
57class TheSelectorPackIsMadeWhereTheEngineReadsIt(unittest.TestCase):
58    def test_the_engine_decides(self):
59        with tempfile.TemporaryDirectory() as tmp:
60            reads = Path(tmp) / "reads.exe"
61            reads.write_bytes(b"x" * 100 + drafting._MARK_SELQ4 + b"y" * 100)
62            sycl = Path(tmp) / "sycl.exe"
63            sycl.write_bytes(b"x" * 300)
64            for exe, want in ((reads, True), (sycl, False), (None, False), (Path(tmp) / "missing.exe", False)):
65                with mock.patch.object(drafting, "installed_engine_exe", return_value=exe):
66                    self.assertEqual(drafting.engine_has_selector_q4(), want, exe)
67
68    def test_a_launch_converts_only_for_such_an_engine(self):
69        import inspect
70        from strata_cli.launch import runner
71        source = inspect.getsource(runner)
72        self.assertIn("drafting.needs_conversion(**want) and drafting.engine_has_selector_q4()", source)
73
74
75if __name__ == "__main__":
76    unittest.main()