diff --git a/tests/gateway/test_voice_command.py b/tests/gateway/test_voice_command.py index 5066f4952f6..d285e31fe3a 100644 --- a/tests/gateway/test_voice_command.py +++ b/tests/gateway/test_voice_command.py @@ -1929,6 +1929,49 @@ class TestVoiceTimeoutCleansRunnerState: assert 111 not in adapter._voice_clients + @pytest.mark.asyncio + async def test_timeout_skips_disconnect_when_voice_mode_off(self, adapter): + """Voice-off is deliberate text-only mode, not idle neglect — the + inactivity timer must NOT disconnect or spam the channel (#PanBartosz).""" + disconnect_calls = [] + adapter._on_voice_disconnect = lambda chat_id: disconnect_calls.append(chat_id) + adapter._voice_mode_getter = lambda chat_id: "off" + + mock_vc = MagicMock() + mock_vc.is_connected.return_value = True + mock_vc.disconnect = AsyncMock() + adapter._voice_clients[111] = mock_vc + adapter._voice_text_channels[111] = 999 + adapter._voice_timeout_tasks[111] = MagicMock() + + with patch("asyncio.sleep", new_callable=AsyncMock): + await adapter._voice_timeout_handler(111) + + # Still connected, no disconnect callback, no "inactivity timeout" spam. + assert 111 in adapter._voice_clients + assert disconnect_calls == [] + mock_vc.disconnect.assert_not_called() + + @pytest.mark.asyncio + async def test_timeout_still_disconnects_when_voice_mode_active(self, adapter): + """A non-off mode still auto-disconnects on genuine inactivity.""" + disconnect_calls = [] + adapter._on_voice_disconnect = lambda chat_id: disconnect_calls.append(chat_id) + adapter._voice_mode_getter = lambda chat_id: "all" + + mock_vc = MagicMock() + mock_vc.is_connected.return_value = True + mock_vc.disconnect = AsyncMock() + adapter._voice_clients[111] = mock_vc + adapter._voice_text_channels[111] = 999 + adapter._voice_timeout_tasks[111] = MagicMock() + + with patch("asyncio.sleep", new_callable=AsyncMock): + await adapter._voice_timeout_handler(111) + + assert 111 not in adapter._voice_clients + assert disconnect_calls == ["999"] + # ===================================================================== # Bug 6: play_in_voice_channel has playback timeout