From aea0b7397b2290ba9be848191eba43e7bcdcbce1 Mon Sep 17 00:00:00 2001 From: xxxigm Date: Wed, 10 Jun 2026 07:04:28 +0700 Subject: [PATCH] test(discord): cover voice timeout under voice-off mode Assert the inactivity handler skips disconnect (and the channel spam) when the voice-mode getter reports "off", and still disconnects on genuine inactivity when the mode is active. --- tests/gateway/test_voice_command.py | 43 +++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) 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