okami.mom/strata

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

Niko1221Version 0.2.10 / engine 0.1.56 follow-through: test_tui2_023_versions and AGENTS.md follow the bump; the '0.2.9.1' tags that meant this release now read 0.2.10; the test comment names 0.2.9.1 as the unpublished DeepSeek hotfix labelf31abf7bd

main
4.7 KiB95 linesraw
1"""0.2.10: a PC with cards of more than one make chooses the engine with `strata launch --backend` (kept in the settings file), is told that the
2other cards exist, and a person who chose is never refused."""
3
4from __future__ import annotations
5
6import json
7import os
8import tempfile
9import unittest
10from pathlib import Path
11from unittest import mock
12
13from strata_control import engine_component as ec, gpu_fit
14
15NV = {"vendor": "nvidia", "name": "NVIDIA GeForce RTX 5060", "vram_gb": 8.0, "usable": True, "index": 0}
16ARC = [{"vendor": "intel", "name": "Intel Arc Pro B65", "vram_gb": 32.0, "usable": True, "index": i} for i in (0, 1)]
17
18
19class SavedChoice(unittest.TestCase):
20    def env(self, d):
21        return {"STRATA_SETTINGS_FILE": str(Path(d) / "settings.json")}
22
23    def test_names_people_type(self):
24        self.assertEqual([ec.clean_backend_name(x) for x in ("Intel", "nvidia", "AMD", "sycl", "arc", "toaster", "")],
25                         ["sycl", "cuda", "hip", "sycl", "sycl", "", ""])
26
27    def test_a_saved_choice_decides_and_keeps_the_other_settings(self):
28        with tempfile.TemporaryDirectory() as d:
29            env = self.env(d)
30            Path(env["STRATA_SETTINGS_FILE"]).write_text(json.dumps({"data_dir": "/x"}))
31            with mock.patch.object(ec, "gpu_makes_present", lambda: {"cuda", "sycl"}):
32                ec.save_backend("intel", env)
33                self.assertEqual(json.loads(Path(env["STRATA_SETTINGS_FILE"]).read_text()), {"data_dir": "/x", "engine_backend": "sycl"})
34                self.assertEqual(ec.detect_backend(env), ("sycl", "saved choice"))
35                self.assertEqual(ec.detect_backend({**env, ec.ENV_BACKEND: "cuda"}), ("cuda", "environment"), "the environment still wins")
36                ec.save_backend(None, env)
37                self.assertEqual(json.loads(Path(env["STRATA_SETTINGS_FILE"]).read_text()), {"data_dir": "/x"})
38
39    def test_a_choice_for_a_make_this_pc_does_not_have_is_ignored(self):
40        with tempfile.TemporaryDirectory() as d:
41            env = self.env(d)
42            with mock.patch.object(ec, "gpu_makes_present", lambda: {"cuda"}):
43                ec.save_backend("sycl", env)
44                self.assertIsNone(ec.saved_backend(env))
45
46    def test_the_update_make_guard_lets_a_saved_choice_through(self):
47        from strata_control import updater
48        ctx = mock.Mock()
49        ctx.hardware = {"backend": "sycl", "backend_source": "saved choice"}
50        self.assertIsNone(updater.make_guard(ctx))
51
52
53class Notes(unittest.TestCase):
54    def test_intel_cards_beside_nvidia_are_always_mentioned(self):
55        note = gpu_fit.other_vendor_note([NV, *ARC], "nvidia")
56        self.assertIn("2 Intel Arc cards (64 GB together)", note)
57        self.assertIn("--backend intel", note)
58
59    def test_one_intel_card_and_the_reverse_note(self):
60        self.assertIn("an Intel Arc Pro B65 (32 GB)", gpu_fit.other_vendor_note([NV, ARC[0]], "nvidia"))
61        back = gpu_fit.other_vendor_note([NV, *ARC], "intel")
62        self.assertIn("NVIDIA", back)
63        self.assertIn("--backend auto", back)
64
65    def test_no_note_without_other_makes(self):
66        self.assertIsNone(gpu_fit.other_vendor_note(ARC, "intel"))
67
68
69class BrokenNvidia(unittest.TestCase):
70    def test_says_what_is_wrong_and_the_next_step_only_when_it_is(self):
71        from strata_cli.launch import cmd
72        comp = mock.Mock(gpus=list(ARC))
73        with mock.patch.object(ec, "detect_backend", lambda *a, **k: ("cuda", "sysfs pci vendor")),                 mock.patch.object(ec, "gpu_makes_present", lambda: {"cuda", "sycl"}):
74            note = cmd._broken_nvidia_note(comp)
75            self.assertIn("driver does not answer", note)
76            self.assertIn("--backend intel", note)
77            self.assertIsNone(cmd._broken_nvidia_note(mock.Mock(gpus=[NV, *ARC])), "a working NVIDIA card: nothing to say")
78        with mock.patch.object(ec, "detect_backend", lambda *a, **k: ("sycl", "saved choice")),                 mock.patch.object(ec, "gpu_makes_present", lambda: {"cuda", "sycl"}):
79            self.assertIsNone(cmd._broken_nvidia_note(comp), "the person already chose")
80
81
82class SavedChoiceLine(unittest.TestCase):
83    def test_a_launch_after_a_saved_choice_says_so(self):
84        from strata_cli.launch import cmd, settings as S
85        from tests.terminal.launch_support import HW_12, Home, catalog
86        with Home(), mock.patch.object(ec, "detect_backend", lambda *a, **k: ("sycl", "saved choice")):
87            _s, notes = cmd.apply_defaults(S.LaunchSettings(family="qwen", model="IQ3_XXS"), catalog(HW_12))
88            hit = [n for n in notes if "your saved choice" in n.text]
89            self.assertTrue(hit, [n.text for n in notes])
90            self.assertIn("Intel cards", hit[0].text)
91            self.assertIn("--backend auto", hit[0].text)
92
93
94if __name__ == "__main__":
95    unittest.main()