Skip to content

The agent that grows with you

test(discord): trim the admission thread-exemption suite to two invariants

teknium1d54902a822d1
diff --git a/tests/gateway/test_discord_admission_thread_exemption.py b/tests/gateway/test_discord_admission_thread_exemption.py
index 0666db92c27..1de9fe0901d 100644
--- a/tests/gateway/test_discord_admission_thread_exemption.py
+++ b/tests/gateway/test_discord_admission_thread_exemption.py
@@ -10,7 +10,6 @@ from types import SimpleNamespace
from unittest.mock import Mock
import discord
-import pytest
from gateway.platforms.helpers import MessageDeduplicator
from plugins.platforms.discord.adapter import DiscordAdapter
@@ -45,75 +44,38 @@ def _thread_channel():
return channel
-def _message(channel, *, content: str, mentions: list):
+def _mentions_third_party(channel):
return SimpleNamespace(
id=123,
author=SimpleNamespace(id=42, bot=False),
channel=channel,
- content=content,
- mentions=mentions,
- type=discord.MessageType.default,
- guild=SimpleNamespace(id=1),
- )
-
-
-def _mentions_third_party(channel):
- return _message(
- channel,
content=f"<@{OTHER_USER_ID}> test",
mentions=[SimpleNamespace(id=OTHER_USER_ID, bot=False)],
+ type=discord.MessageType.default,
+ guild=SimpleNamespace(id=1),
)
def test_third_party_mention_in_bot_thread_is_admitted(monkeypatch):
monkeypatch.delenv("DISCORD_IGNORE_NO_MENTION", raising=False)
- adapter = _adapter()
- admitted, _ = adapter._discord_message_admission(
+ admitted, _ = _adapter()._discord_message_admission(
_mentions_third_party(_thread_channel()), claim=False)
assert admitted is True
-
-
-def test_no_mention_in_bot_thread_stays_admitted(monkeypatch):
- # The asymmetry the fix removes: this case was already admitted, because an empty
- # ``mentions`` skips the enclosing block entirely.
- monkeypatch.delenv("DISCORD_IGNORE_NO_MENTION", raising=False)
- adapter = _adapter()
-
- admitted, _ = adapter._discord_message_admission(
- _message(_thread_channel(), content="test", mentions=[]), claim=False)
- assert admitted is True
-
-
-def test_third_party_mention_in_a_plain_channel_is_still_dropped(monkeypatch):
- # Outside a bot thread the gate keeps its original meaning: don't barge into a
- # conversation addressed to someone else.
- monkeypatch.delenv("DISCORD_IGNORE_NO_MENTION", raising=False)
- adapter = _adapter()
-
- admitted, _ = adapter._discord_message_admission(
- _mentions_third_party(SimpleNamespace(id=THREAD_ID, parent_id=None)), claim=False)
- assert admitted is False
-
-
-def test_thread_require_mention_keeps_multi_bot_threads_strict(monkeypatch):
# ``thread_require_mention`` gates threads like channels for multi-bot servers;
- # _in_bot_thread() already encodes that, so the exemption must not override it.
- monkeypatch.delenv("DISCORD_IGNORE_NO_MENTION", raising=False)
- adapter = _adapter(thread_require_mention=True)
-
- admitted, _ = adapter._discord_message_admission(
+ # _in_bot_thread() encodes that, so the exemption must not override it.
+ admitted, _ = _adapter(thread_require_mention=True)._discord_message_admission(
_mentions_third_party(_thread_channel()), claim=False)
assert admitted is False
[email protected]("value", ["false", "0", "no"])
-def test_explicit_opt_out_still_admits_everything(monkeypatch, value):
- # The documented workaround keeps working: with the gate off, a third-party mention is
- # admitted in a plain channel too.
- monkeypatch.setenv("DISCORD_IGNORE_NO_MENTION", value)
- adapter = _adapter()
+def test_third_party_mention_in_a_plain_channel_is_still_dropped_and_logged(monkeypatch, caplog):
+ # Outside a bot thread the gate keeps its meaning (don't barge into a conversation
+ # addressed to someone else) and now says so, instead of dropping silently.
+ monkeypatch.delenv("DISCORD_IGNORE_NO_MENTION", raising=False)
+ caplog.set_level("DEBUG", logger="plugins.platforms.discord.adapter")
- admitted, _ = adapter._discord_message_admission(
+ admitted, _ = _adapter()._discord_message_admission(
_mentions_third_party(SimpleNamespace(id=THREAD_ID, parent_id=None)), claim=False)
- assert admitted is True
+ assert admitted is False
+ assert any("admission: dropping message 123" in r.getMessage() for r in caplog.records)