okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
3b8dc8fa3
main
1"""#3714: the launch hint named an engine log that was never written (the start stopped before the engine existed). Nothing here starts 2an engine or reads the real profile.""" 3from __future__import annotations 4 5import json 6import unittest 7from pathlib import Path 8from unittest import mock 9 10from strata_cli .launch import runner as R ,settings as LS 11from strata_control .profiles import ProfileError 12from tests .terminal .launch_support import HW_12 ,Home ,catalog 13 14 15class LogHint (unittest .TestCase ): 16"""#3714: 'The engine's log has the reason: <path>' for a log that was never written (the start stopped before the engine existed).""" 17 18def config (self ,home :Home ,log :Path )-> Path : 19path = home .base / "run.json" 20path .write_text ('{"exe": "e", "args": [], "log": %s}' % json .dumps (str (log )),encoding = "utf-8" ) 21return path 22 23def test_a_busy_profile_gets_its_own_sentence_and_no_log_path (self ): 24with Home ()as h : 25log = h .base / "missing.log" 26text = R ._log_hint (self .config (h ,log ),ProfileError ("this profile already has a live managed runtime" ,6 )) 27self .assertNotIn (str (log ),text ) 28self .assertIn ("still running or starting" ,text ) 29self .assertIn ("strata launch --stop" ,text ) 30 31def test_a_log_that_does_not_exist_is_not_pointed_at (self ): 32with Home ()as h : 33log = h .base / "missing.log" 34text = R ._log_hint (self .config (h ,log ),RuntimeError ("something else" )) 35self .assertNotIn (str (log ),text ) 36self .assertIn ("did not get as far as writing its log" ,text ) 37 38def test_a_log_that_exists_is_still_pointed_at (self ): 39with Home ()as h : 40log = h .base / "engine.log" 41log .write_text ("line\n" ,encoding = "utf-8" ) 42self .assertEqual (R ._log_hint (self .config (h ,log ),RuntimeError ("x" )),f"The engine's log has the reason: { log } " ) 43 44def test_without_a_config_the_general_sentence_stays (self ): 45self .assertIn ("strata logs" ,R ._log_hint (None )) 46 47def test_explain_engine_exit_does_not_name_a_missing_log_either (self ): 48with Home ()as h : 49log = h .base / "missing.log" 50text ,nxt = R .explain_engine_exit ({"state" :"failed" ,"error" :"server_exited" },self .config (h ,log )) 51self .assertNotIn (str (log ),nxt ) 52self .assertIn ("did not get as far as writing its log" ,nxt ) 53log .write_text ("[strata] out of memory\n" ,encoding = "utf-8" ) 54text ,nxt = R .explain_engine_exit ({"state" :"failed" ,"error" :"server_exited" },self .config (h ,log )) 55self .assertIn (f"The engine's log: { log } " ,nxt ) 56 57def test_start_reports_a_busy_profile_without_a_log_path (self ): 58with Home ()as h : 59log = h .base / "never-written.log" 60runner = R .Runner (LS .LaunchSettings (family = "qwen" ,model = "IQ3_XXS" ,context = 32768 ,vision = "off" ),catalog = catalog (HW_12 )) 61runner .config_path = self .config (h ,log ) 62busy = ProfileError ("this profile already has a live managed runtime" ,6 ) 63with mock .patch .object (R .Runner ,"stop_others" ),mock .patch .object (R .Runner ,"check_port_free" ), \ 64mock .patch .object (R .Runner ,"log_marks" ,return_value = {}),mock .patch .object (R .Runner ,"end_failed_start" ), \ 65mock .patch .object (R .Runner ,"start_wait" ,return_value = 5 ),mock .patch .object (R .Runner ,"emit" ), \ 66mock .patch ("strata_control.runtime.status" ,return_value = {"state" :"stopped" }), \ 67mock .patch ("strata_control.runtime.start" ,side_effect = busy ): 68with self .assertRaises (R .LaunchError )as raised : 69runner .start () 70self .assertIn ("already has a live managed runtime" ,raised .exception .text ) 71self .assertNotIn (str (log ),raised .exception .next ) 72self .assertIn ("strata launch --stop" ,raised .exception .next ) 73 74 75if __name__ == "__main__" : 76unittest .main ()