From 562c8b418fdda15ad560334fc2c8c4b0f2ff57cd Mon Sep 17 00:00:00 2001 From: Solitud1nem <76743883+Solitud1nem@users.noreply.github.com> Date: Sun, 19 Jul 2026 11:18:28 +0300 Subject: [PATCH] test(voice): drive the micro-pause test from the explicit clock too Review follow-up: test_micro_pause_tolerance_during_speech was left on real sleeps, so it kept the wall-clock dependency the rest of this PR removes. Its three sleeps (50 ms, 50 ms, 60 ms) feed the same monotonic gate at tools/voice_mode.py:561 that the other two tests were converted for. It was measured rather than assumed before being left out: 0 failures in 40 runs, because on Windows sleep() rounds up to the timer tick, so sleep(0.05) really costs ~62.5 ms and the three sleeps clear the 150 ms gate by ~37.5 ms -- wider than the 15.625 ms GetTickCount64() quantum that made the other two flake. That margin is an accident of sleep granularity rather than anything the test guarantees, so it is not worth keeping the bet. Driving it from fake_clock makes the timeline exact (0.05 + 0.05 + 0.06 = 0.16 against the 0.15 gate, dip 0.05 under the 0.1 tolerance) and drops the real sleeping from the suite. Mutation-checked: widening the gate at :561 fails the test. --- tests/tools/test_voice_mode.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/tools/test_voice_mode.py b/tests/tools/test_voice_mode.py index 636e809024bd..c8e245f1c079 100644 --- a/tests/tools/test_voice_mode.py +++ b/tests/tools/test_voice_mode.py @@ -1551,7 +1551,7 @@ class TestSilenceDetection: recorder.cancel() - def test_micro_pause_tolerance_during_speech(self, mock_sd): + def test_micro_pause_tolerance_during_speech(self, mock_sd, fake_clock): """Brief dips below threshold during speech should NOT reset speech tracking.""" np = pytest.importorskip("numpy") import threading @@ -1578,14 +1578,14 @@ class TestSilenceDetection: # Speech chunk 1 callback(loud_frame, 1600, None, None) - time.sleep(0.05) + fake_clock.advance(0.05) # Brief micro-pause (dip < max_dip_tolerance) callback(quiet_frame, 1600, None, None) - time.sleep(0.05) + fake_clock.advance(0.05) # Speech resumes -- speech_start should NOT have been reset callback(loud_frame, 1600, None, None) assert recorder._speech_start > 0, "Speech start should be preserved across brief dips" - time.sleep(0.06) + fake_clock.advance(0.06) # Another speech chunk to exceed min_speech_duration callback(loud_frame, 1600, None, None) assert recorder._has_spoken is True, "Speech should be confirmed after tolerating micro-pause"