okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
1fb37cf81
main
1"""#879: a Stop that arrives while the engine reads the prompt (PP lines, no tokens yet) is sent at once, not after the 2first token.""" 3import os 4import queue 5import sys 6import threading 7import unittest 8 9sys .path .insert (0 ,os .path .dirname (os .path .dirname (os .path .abspath (__file__ )))) 10 11from serve import server # noqa: E402 12 13 14class ControlCancelTest (unittest .TestCase ): 15def _engine (self ,lines ): 16eng = object .__new__ (server .StrataEngine ) 17eng .lines = queue .Queue () 18for l in lines : 19eng .lines .put (l ) 20eng .sent = [] 21eng ._send = eng .sent .append 22eng ._ctl_mode = "solo" 23eng ._ctl_result = None 24eng .progress = None 25eng .prefill_tok_s_mean = None 26eng ._last_done = None 27eng ._parse_done = lambda line :None 28return eng 29 30def test_stop_during_prompt_read (self ): 31cancel = threading .Event () 32eng = self ._engine (["PP 256 4096 1 100.0" ,"PP 512 4096 2 100.0" ,"PP 768 4096 3 100.0" ,"DONE 0" ]) 33gen = eng ._control (cancel ,lambda t :None ) 34self .assertIsNone (next (gen ))# first PP line, nothing cancelled yet 35self .assertEqual (eng .sent , []) 36cancel .set () 37self .assertIsNone (next (gen ))# the next PP line: STOP goes out now 38self .assertEqual (eng .sent , ["STOP" ]) 39self .assertIsNone (next (gen )) 40self .assertEqual (eng .sent , ["STOP" ])# once 41 42def test_no_stop_without_cancel (self ): 43eng = self ._engine (["PP 256 4096 1 100.0" ,"DONE 0" ]) 44for _ in eng ._control (threading .Event (),lambda t :None ): 45pass 46self .assertEqual (eng .sent , []) 47 48 49if __name__ == "__main__" : 50unittest .main ()