mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-06-10 08:32:09 +00:00
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.
This commit is contained in:
parent
311900842e
commit
aea0b7397b
1 changed files with 43 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue