okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
fcb0c2d0e
main
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 5python -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 ): 18f = tempfile .NamedTemporaryFile ("w+" ,suffix = ".log" ,delete = False ) 19f .write (text ) 20f .flush () 21return f 22 23 24class StartError (unittest .TestCase ): 25def test_an_empty_line_is_never_a_blank_sentence (self ): 26m = server .vision_start_error ("" ) 27self .assertNotEqual (m .strip (),"the vision encoder did not start:" ) 28self .assertIn ("without saying anything" ,m ) 29 30def test_exit_code_and_stderr_tail_come_with_it (self ): 31f = log_with ("loading mmproj\nggml_cuda_init: failed\nsome last words\n" ) 32self .addCleanup (lambda : (f .close (),Path (f .name ).unlink ())) 33m = server .vision_start_error ("" ,f ,3 ) 34self .assertIn ("exit code 3" ,m ) 35self .assertIn ("some last words" ,m ) 36self .assertIn ("ggml_cuda_init: failed" ,m ) 37 38def test_a_windows_crash_status_is_named (self ): 39m = server .vision_start_error ("" ,None ,0xC0000135 ) 40self .assertIn ("0xC0000135" ,m ) 41 42def test_kernel_image_error_names_the_card_and_the_way_out (self ): 43for sign in ("CUDA error: device kernel image is invalid" ,"IM2COL failed" ,"no kernel image is available for execution" ): 44with self .subTest (sign = sign ): 45f = log_with ("warm-up\n" + sign + "\n" ) 46try : 47m = server .vision_start_error ("" ,f ,1 ) 48finally : 49f .close () 50Path (f .name ).unlink () 51self .assertIn ("no code for this graphics card" ,m ) 52self .assertIn ("CPU" ,m ) 53self .assertIn (sign .split (":" )[- 1 ].strip ()[:12 ],m ) 54 55def test_a_timeout_names_the_seconds_and_the_last_log_line (self ): 56f = log_with ("loading weights\nstill loading the projector\n" ) 57self .addCleanup (lambda : (f .close (),Path (f .name ).unlink ())) 58m = server .vision_start_error ("" ,f ,waited = 300 ) 59self .assertIn ("said nothing for 300 s" ,m ) 60self .assertIn ("still loading the projector" ,m ) 61 62def test_the_reader_that_ends_before_READY_raises_with_its_exit_code (self ): 63proc = SimpleNamespace (stdin = io .StringIO (),stdout = io .StringIO ("" ),kill = lambda :None ,wait = lambda timeout = None :0 , 64poll = lambda :7 ,returncode = 7 ) 65v = server .Vision .__new__ (server .Vision ) 66v .spawn = (["strata-vision" ],None ,None ) 67v .dir = Path (tempfile .gettempdir ()) 68with mock .patch .object (server ,"popen" ,lambda * a ,** k :proc ): 69with self .assertRaises (RuntimeError )as cm : 70v ._start () 71self .assertIn ("exit code 7" ,str (cm .exception )) 72 73def test_a_normal_message_is_unchanged (self ): 74self .assertEqual (server .vision_start_error ("ERR no mmproj\n" ),"the vision encoder did not start: ERR no mmproj" ) 75 76 77if __name__ == "__main__" : 78unittest .main ()