fix(cli): avoid voice TTS restart race

This commit is contained in:
tmdgusya
2026-05-03 14:12:28 +09:00
committed by Teknium
parent 314fe9f827
commit a1cb811cb8
2 changed files with 31 additions and 5 deletions

View File

@@ -1040,6 +1040,25 @@ class TestDisableVoiceModeReal:
class TestVoiceSpeakResponseReal:
"""Tests _voice_speak_response with real CLI instance."""
def test_async_scheduling_clears_done_before_thread_start(self):
cli = _make_voice_cli(_voice_tts=True)
starts = []
class FakeThread:
def __init__(self, target=None, args=(), daemon=None):
self.target = target
self.args = args
self.daemon = daemon
def start(self):
starts.append(cli._voice_tts_done.is_set())
with patch("cli.threading.Thread", FakeThread):
cli._voice_speak_response_async("Hello")
assert starts == [False]
assert not cli._voice_tts_done.is_set()
@patch("cli._cprint")
def test_early_return_when_tts_off(self, _cp):
cli = _make_voice_cli(_voice_tts=False)