Skip to content

Your lightweight open-source personal agent.

test(discord): cover allow_channels filtering in _should_accept_inbound

Xubin Ren459a4d7311d6
diff --git a/tests/channels/test_discord_channel.py b/tests/channels/test_discord_channel.py
index 7a39bff2b..82ef6c51b 100644
--- a/tests/channels/test_discord_channel.py
+++ b/tests/channels/test_discord_channel.py
@@ -313,6 +313,45 @@ async def test_on_message_accepts_allowlisted_dm() -> None:
assert handled[0]["metadata"] == {"message_id": "789", "guild_id": None, "reply_to": None}
+async def test_on_message_accepts_when_channel_in_allow_channels() -> None:
+ # When allow_channels is set, messages from listed channels should be forwarded.
+ channel = DiscordChannel(
+ DiscordConfig(enabled=True, allow_from=["*"], allow_channels=["456"]),
+ MessageBus(),
+ )
+ handled: list[dict] = []
+
+ async def capture_handle(**kwargs) -> None:
+ handled.append(kwargs)
+
+ channel._handle_message = capture_handle # type: ignore[method-assign]
+
+ await channel._on_message(_make_message(author_id=123, channel_id=456))
+
+ assert len(handled) == 1
+ assert handled[0]["chat_id"] == "456"
+
+
+async def test_on_message_drops_when_channel_not_in_allow_channels() -> None:
+ # When allow_channels is set and incoming channel is not listed, drop silently.
+ channel = DiscordChannel(
+ DiscordConfig(enabled=True, allow_from=["*"], allow_channels=["999"]),
+ MessageBus(),
+ )
+ handled: list[dict] = []
+
+ async def capture_handle(**kwargs) -> None:
+ handled.append(kwargs)
+
+ channel._handle_message = capture_handle # type: ignore[method-assign]
+
+ await channel._on_message(_make_message(author_id=123, channel_id=456))
+
+ assert handled == []
+
+
@pytest.mark.asyncio
async def test_on_message_ignores_unmentioned_guild_message() -> None:
# With mention-only group policy, guild messages without a bot mention are dropped.