From e6b034405239fabc50e1d33315ea4d53d35f6f9d Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Tue, 28 Jul 2026 09:32:03 -0700 Subject: [PATCH] test: adapt salvaged voice tests to current main + lint fix - _FakeProc gains returncode (main's player loop checks proc.returncode) - WSL gate tests clear SSH_* env vars (main hard-warns over SSH without forwarded audio) and accept the merged #37346 forwarded-sound-server notice wording - test_tts_macos_output stubs resolve_streaming_provider so the OutputStream setup path actually runs on main's chunked-streamer code - voice CLI integration tests unwrap the _VoiceInputMessage sentinel - _is_wsl: explicit encoding + drop unreachable return (ruff PLW1514) --- tests/tools/test_tts_macos_output.py | 18 ++++++++++++++++++ tests/tools/test_voice_cli_integration.py | 12 ++++++++++-- tests/tools/test_voice_mode.py | 14 +++++++++++++- tools/voice_mode.py | 3 +-- 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/tests/tools/test_tts_macos_output.py b/tests/tools/test_tts_macos_output.py index b0d74a544b5f..3e6a3ff256d9 100644 --- a/tests/tools/test_tts_macos_output.py +++ b/tests/tools/test_tts_macos_output.py @@ -12,6 +12,16 @@ import threading import pytest +class _FakeStreamer: + """Minimal chunked-streamer stand-in so the OutputStream setup path runs.""" + + sample_rate = 24000 + channels = 1 + + def stream(self, text): + return iter([]) + + def _run_stream(monkeypatch, system_name): """Drive stream_tts_to_speaker once with a mock client on *system_name*. @@ -33,6 +43,10 @@ def _run_stream(monkeypatch, system_name): return iter([]) # no audio chunks needed for setup assertion monkeypatch.setattr("tools.tts_tool._import_elevenlabs", lambda: _FakeTTS) + monkeypatch.setattr( + "tools.tts_streaming.resolve_streaming_provider", + lambda cfg, preferred=None: _FakeStreamer(), + ) sd_called = {"hit": False} @@ -81,6 +95,10 @@ def _run_stream_offmac(monkeypatch): return iter([]) monkeypatch.setattr("tools.tts_tool._import_elevenlabs", lambda: _FakeTTS) + monkeypatch.setattr( + "tools.tts_streaming.resolve_streaming_provider", + lambda cfg, preferred=None: _FakeStreamer(), + ) sd_called = {"hit": False} diff --git a/tests/tools/test_voice_cli_integration.py b/tests/tools/test_voice_cli_integration.py index 5bc6ff462ddf..566d790e84e4 100644 --- a/tests/tools/test_voice_cli_integration.py +++ b/tests/tools/test_voice_cli_integration.py @@ -1208,7 +1208,12 @@ class TestVoiceStopAndTranscribeReal: recorder.stop.return_value = "/tmp/test.wav" cli = _make_voice_cli(_voice_recording=True, _voice_recorder=recorder) cli._voice_stop_and_transcribe() - assert cli._pending_input.get_nowait() == "hello world" + queued = cli._pending_input.get_nowait() + # Voice transcripts are wrapped in the _VoiceInputMessage sentinel so + # only genuine STT output gets the voice prefix (#65827). + from cli import _VoiceInputMessage + assert isinstance(queued, _VoiceInputMessage) + assert str(queued) == "hello world" @patch("cli._cprint") @patch("cli.os.unlink") @@ -1424,7 +1429,10 @@ class TestVoiceBargeCaptureSubmit: cli._voice_submit_barge_utterance(str(wav)) - assert cli._pending_input.get_nowait() == "stop, do it differently" + queued = cli._pending_input.get_nowait() + from cli import _VoiceInputMessage + assert isinstance(queued, _VoiceInputMessage) + assert str(queued) == "stop, do it differently" assert not cli._voice_barge_capture.is_set() assert not wav.exists() diff --git a/tests/tools/test_voice_mode.py b/tests/tools/test_voice_mode.py index f1bb17b567f7..66a9da9bbb4d 100644 --- a/tests/tools/test_voice_mode.py +++ b/tests/tools/test_voice_mode.py @@ -1243,6 +1243,8 @@ class TestMacOSAudioOutputPolicy: popen_cmds = [] class _FakeProc: + returncode = 0 + def wait(self, timeout=None): return 0 @@ -2437,6 +2439,8 @@ class TestWSLAudioEnvironmentGate: monkeypatch.delenv("PULSE_SERVER", raising=False) monkeypatch.delenv("PIPEWIRE_REMOTE", raising=False) + for _ssh_var in ("SSH_CLIENT", "SSH_TTY", "SSH_CONNECTION"): + monkeypatch.delenv(_ssh_var, raising=False) monkeypatch.setattr("tools.voice_mode._import_audio", lambda: (MagicMock(), MagicMock())) with patch("builtins.open", side_effect=self._fake_open_wsl), \ @@ -2462,6 +2466,8 @@ class TestWSLAudioEnvironmentGate: monkeypatch.delenv("PULSE_SERVER", raising=False) monkeypatch.delenv("PIPEWIRE_REMOTE", raising=False) + for _ssh_var in ("SSH_CLIENT", "SSH_TTY", "SSH_CONNECTION"): + monkeypatch.delenv(_ssh_var, raising=False) monkeypatch.setattr("tools.voice_mode._import_audio", lambda: (MagicMock(), MagicMock())) with patch("builtins.open", side_effect=self._fake_open_wsl), \ @@ -2481,6 +2487,8 @@ class TestWSLAudioEnvironmentGate: from tools import voice_mode as vm monkeypatch.setenv("PULSE_SERVER", "unix:/mnt/wslg/PulseServer") + for _ssh_var in ("SSH_CLIENT", "SSH_TTY", "SSH_CONNECTION"): + monkeypatch.delenv(_ssh_var, raising=False) monkeypatch.setattr("tools.voice_mode._import_audio", lambda: (MagicMock(), MagicMock())) with patch("builtins.open", side_effect=self._fake_open_wsl), \ @@ -2488,4 +2496,8 @@ class TestWSLAudioEnvironmentGate: result = vm.detect_audio_environment() assert result["available"] is True - assert any("PulseAudio bridge" in n for n in result["notices"]) + # Merged with #37346: any forwarded sound server (PULSE_SERVER or + # PIPEWIRE_REMOTE) yields the shared reachable-sound-server notice. + assert any( + "PulseAudio" in n and "WSL" in n for n in result["notices"] + ) diff --git a/tools/voice_mode.py b/tools/voice_mode.py index 4eb1c6462edc..9f9636234cf1 100644 --- a/tools/voice_mode.py +++ b/tools/voice_mode.py @@ -1341,11 +1341,10 @@ def stop_playback() -> None: def _is_wsl() -> bool: """True when running inside Windows Subsystem for Linux.""" try: - with open("/proc/version", "r") as f: + with open("/proc/version", "r", encoding="utf-8", errors="replace") as f: return "microsoft" in f.read().lower() except Exception: return False - return False def _is_wsl2_env() -> bool: