okami.mom/strata

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

Niko1221Merge f-140 into the Aurora port; verify: halo's STRATA_VERIFY_RESIDENT is 0.1.39's all-resident graph1fb37cf81

main
1.7 KiB50 linesraw
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):
15    def _engine(self, lines):
16        eng = object.__new__(server.StrataEngine)
17        eng.lines = queue.Queue()
18        for l in lines:
19            eng.lines.put(l)
20        eng.sent = []
21        eng._send = eng.sent.append
22        eng._ctl_mode = "solo"
23        eng._ctl_result = None
24        eng.progress = None
25        eng.prefill_tok_s_mean = None
26        eng._last_done = None
27        eng._parse_done = lambda line: None
28        return eng
29
30    def test_stop_during_prompt_read(self):
31        cancel = threading.Event()
32        eng = self._engine(["PP 256 4096 1 100.0", "PP 512 4096 2 100.0", "PP 768 4096 3 100.0", "DONE 0"])
33        gen = eng._control(cancel, lambda t: None)
34        self.assertIsNone(next(gen))               # first PP line, nothing cancelled yet
35        self.assertEqual(eng.sent, [])
36        cancel.set()
37        self.assertIsNone(next(gen))               # the next PP line: STOP goes out now
38        self.assertEqual(eng.sent, ["STOP"])
39        self.assertIsNone(next(gen))
40        self.assertEqual(eng.sent, ["STOP"])       # once
41
42    def test_no_stop_without_cancel(self):
43        eng = self._engine(["PP 256 4096 1 100.0", "DONE 0"])
44        for _ in eng._control(threading.Event(), lambda t: None):
45            pass
46        self.assertEqual(eng.sent, [])
47
48
49if __name__ == "__main__":
50    unittest.main()