The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(discord): carry the role verdict into slash command events
Christopherf5ef17a321b0
diff --git a/plugins/platforms/discord/adapter.py b/plugins/platforms/discord/adapter.pyindex afda496c2bf..7be208f3e7b 100644--- a/plugins/platforms/discord/adapter.py+++ b/plugins/platforms/discord/adapter.py@@ -4945,11 +4945,15 @@ class DiscordAdapter(DiscordMediaMixin, DiscordThreadTitlesMixin, DiscordVoiceIn# them — without them a guild- or channel-routed profile never matches a native slash command# (#69178).parent_id = (self._get_parent_channel_id(interaction.channel) if is_thread else None) or ""+ # Callers build the event only after _check_slash_authorization passed, so the+ # adapter's role verdict holds here exactly as on the message path+ # (_discord_message_admission); without it the gateway denies role-only users.source = self.build_source(chat_id=str(interaction.channel_id), chat_name=chat_name, chat_type=chat_type,user_id=str(interaction.user.id), user_name=interaction.user.display_name,thread_id=thread_id, chat_topic=chat_topic,guild_id=self._interaction_guild_id(interaction), parent_chat_id=parent_id or None,+ role_authorized=bool(getattr(self, "_allowed_role_ids", set())),)msg_type = MessageType.COMMAND if text.startswith("/") else MessageType.TEXTchannel_id = str(interaction.channel_id)@@ -4999,11 +5003,13 @@ class DiscordAdapter(DiscordMediaMixin, DiscordThreadTitlesMixin, DiscordVoiceIn# Name, topic and parent come from the thread, as for a message posted in it (same pinned prompt).thread_id = str(thread.id)_parent_id = self._get_parent_channel_id(thread) or ""+ # Only reached from _handle_thread_create_slash after its authorization check.source = self.build_source(chat_id=thread_id, chat_name=self._format_thread_chat_name(thread), chat_type="thread",user_id=str(interaction.user.id), user_name=interaction.user.display_name,thread_id=thread_id, chat_topic=self._get_effective_topic(thread, is_thread=True),guild_id=self._interaction_guild_id(interaction), parent_chat_id=_parent_id or None,+ role_authorized=bool(getattr(self, "_allowed_role_ids", set())),)_skills = self._resolve_channel_skills(thread_id, _parent_id or None)_channel_prompt = self._resolve_channel_prompt(thread_id, _parent_id or None)diff --git a/tests/gateway/test_discord_slash_auth.py b/tests/gateway/test_discord_slash_auth.pyindex afcd12dc74d..232f2766fcb 100644--- a/tests/gateway/test_discord_slash_auth.py+++ b/tests/gateway/test_discord_slash_auth.py@@ -243,6 +243,45 @@ async def test_role_member_passes(adapter):assert await adapter._check_slash_authorization(interaction, "/help") is True+def _gateway_authorizes(source):+ """The real gateway authz verdict for a runner with no allowlist and no pairing store."""+ from gateway.run import GatewayRunner++ return object.__new__(GatewayRunner)._is_user_authorized(source)+++async def test_role_member_slash_command_passes_gateway_authz(adapter):+ """Regression for #118958: the adapter admits a role-only member, and the event it+ dispatches must carry that verdict, or the gateway answers with a pairing code."""+ adapter._allowed_role_ids = {1234}+ interaction = _make_interaction("999999999")+ interaction.user.roles = [SimpleNamespace(id=1234)]+ interaction.user.display_name = "role member"+ dispatched = []+ adapter.handle_message = AsyncMock(side_effect=dispatched.append)++ await adapter._run_simple_slash(interaction, "/reset")++ assert [_gateway_authorizes(event.source) for event in dispatched] == [True]+++async def test_role_member_thread_starter_passes_gateway_authz(adapter):+ """``/thread`` with a starter message dispatches its own event; it must carry the same verdict."""+ adapter._allowed_role_ids = {1234}+ interaction = _make_interaction("999999999")+ interaction.user.roles = [SimpleNamespace(id=1234)]+ interaction.user.display_name = "role member"+ interaction.guild.name = "guild"+ dispatched = []+ adapter.handle_message = AsyncMock(side_effect=dispatched.append)++ await adapter._dispatch_thread_session(interaction, "555", "topic", "hello")++ assert [_gateway_authorizes(event.source) for event in dispatched] == [True]++# ---------------------------------------------------------------------------# Channel allowlist (DISCORD_ALLOWED_CHANNELS) parity — the gate prajer used# ---------------------------------------------------------------------------