okami.mom/strata

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

Niko1221Merge f-023-int into f-023-guifcb0c2d0e

main
3.2 KiB78 linesraw
1"""I3 (tools and images review, 2026-10-22): a picture reader that dies before it prints used to say only "the vision
2encoder did not start: " (#3645, #3444, #3697, #3669).  The message now carries the tail of its stderr, its exit status
3and, for a kernel-image error, the card/architecture hint.
4
5    python -m serve.test_vision_start_error
6"""
7import io
8import tempfile
9import unittest
10from pathlib import Path
11from types import SimpleNamespace
12from unittest import mock
13
14import serve.server as server
15
16
17def log_with(text):
18    f = tempfile.NamedTemporaryFile("w+", suffix=".log", delete=False)
19    f.write(text)
20    f.flush()
21    return f
22
23
24class StartError(unittest.TestCase):
25    def test_an_empty_line_is_never_a_blank_sentence(self):
26        m = server.vision_start_error("")
27        self.assertNotEqual(m.strip(), "the vision encoder did not start:")
28        self.assertIn("without saying anything", m)
29
30    def test_exit_code_and_stderr_tail_come_with_it(self):
31        f = log_with("loading mmproj\nggml_cuda_init: failed\nsome last words\n")
32        self.addCleanup(lambda: (f.close(), Path(f.name).unlink()))
33        m = server.vision_start_error("", f, 3)
34        self.assertIn("exit code 3", m)
35        self.assertIn("some last words", m)
36        self.assertIn("ggml_cuda_init: failed", m)
37
38    def test_a_windows_crash_status_is_named(self):
39        m = server.vision_start_error("", None, 0xC0000135)
40        self.assertIn("0xC0000135", m)
41
42    def test_kernel_image_error_names_the_card_and_the_way_out(self):
43        for sign in ("CUDA error: device kernel image is invalid", "IM2COL failed", "no kernel image is available for execution"):
44            with self.subTest(sign=sign):
45                f = log_with("warm-up\n" + sign + "\n")
46                try:
47                    m = server.vision_start_error("", f, 1)
48                finally:
49                    f.close()
50                    Path(f.name).unlink()
51                self.assertIn("no code for this graphics card", m)
52                self.assertIn("CPU", m)
53                self.assertIn(sign.split(":")[-1].strip()[:12], m)
54
55    def test_a_timeout_names_the_seconds_and_the_last_log_line(self):
56        f = log_with("loading weights\nstill loading the projector\n")
57        self.addCleanup(lambda: (f.close(), Path(f.name).unlink()))
58        m = server.vision_start_error("", f, waited=300)
59        self.assertIn("said nothing for 300 s", m)
60        self.assertIn("still loading the projector", m)
61
62    def test_the_reader_that_ends_before_READY_raises_with_its_exit_code(self):
63        proc = SimpleNamespace(stdin=io.StringIO(), stdout=io.StringIO(""), kill=lambda: None, wait=lambda timeout=None: 0,
64                               poll=lambda: 7, returncode=7)
65        v = server.Vision.__new__(server.Vision)
66        v.spawn = (["strata-vision"], None, None)
67        v.dir = Path(tempfile.gettempdir())
68        with mock.patch.object(server, "popen", lambda *a, **k: proc):
69            with self.assertRaises(RuntimeError) as cm:
70                v._start()
71        self.assertIn("exit code 7", str(cm.exception))
72
73    def test_a_normal_message_is_unchanged(self):
74        self.assertEqual(server.vision_start_error("ERR no mmproj\n"), "the vision encoder did not start: ERR no mmproj")
75
76
77if __name__ == "__main__":
78    unittest.main()