The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(discord): annotate the auto-thread topic parity test and keep it to the topic
unsupportedpastels455e229ef9f3
diff --git a/plugins/platforms/discord/adapter.py b/plugins/platforms/discord/adapter.pyindex 87c0c10a021..837567a6d4e 100644--- a/plugins/platforms/discord/adapter.py+++ b/plugins/platforms/discord/adapter.py@@ -6134,9 +6134,7 @@ class DiscordAdapter(DiscordMediaMixin, DiscordThreadTitlesMixin, BasePlatformAdchat_name = getattr(message.channel, "name", str(message.channel.id))if hasattr(message.channel, "guild") and message.channel.guild:chat_name = f"{message.channel.guild.name} / #{chat_name}"- # Channel topic (TextChannels only); forum-parented threads inherit the parent topic.- # Read from the auto-created thread, not the channel the mention was posted in: this turn pins- # the thread session's context prompt, and the thread's next message reads its own topic.+ # The session channel's topic, as the auto-thread's next message reads it; forum threads inherit it.chat_topic = self._get_effective_topic(effective_channel, is_thread=is_thread)guild = getattr(message, "guild", None)source = self.build_source(diff --git a/tests/gateway/test_discord_auto_thread_prompt_parity.py b/tests/gateway/test_discord_auto_thread_prompt_parity.pyindex 12fd5b33ef4..72a6fe39d0a 100644--- a/tests/gateway/test_discord_auto_thread_prompt_parity.py+++ b/tests/gateway/test_discord_auto_thread_prompt_parity.py@@ -1,12 +1,10 @@-"""An auto-threaded @mention opens the thread's session with the prompt inputs its later messages use.+"""An auto-threaded @mention reads the new thread's topic, as the thread's next message does.-The first turn's source points at the new thread, but its topic was read from the parent text channel-the mention was posted in. The next message in the thread read the thread's own topic (none outside-forums), so the pinned session-context prompt (``Channel Topic``) was re-rendered on the second turn of-every auto-threaded conversation in a channel with a topic: a prompt-cache miss. Channel prompt and-skill lookups already resolve the same on both turns (exact id, then parent) and are asserted as parity-guards only.+The first turn's source pointed at the new thread but took its topic from the parent text channel,+while the thread's next message read the thread's own topic (none outside forums). ``Channel Topic``+is part of the pinned session-context prompt, so turn 2 re-rendered it."""+from __future__ import annotationsfrom datetime import datetime, timezonefrom types import SimpleNamespace@@ -20,66 +18,45 @@ from gateway.config import GatewayConfig, Platform, PlatformConfigfrom gateway.session import build_session_contextfrom plugins.platforms.discord.adapter import DiscordAdapter--class _Text:- def __init__(self, channel_id, name="ops", topic="Incident triage"):- self.id, self.name, self.topic = channel_id, name, topic- self.guild = SimpleNamespace(id=1, name="Hermes Server")+_BOT = SimpleNamespace(id=999)class _Thread:- def __init__(self, channel_id, parent, name="what-broke"):- self.id, self.name, self.parent, self.parent_id = channel_id, name, parent, parent.id+ def __init__(self, parent: SimpleNamespace) -> None:+ self.id, self.name, self.parent, self.parent_id = 800, "what-broke", parent, parent.idself.guild = parent.guild-_USER = SimpleNamespace(id=42, display_name="Alice", name="alice")-_BOT = SimpleNamespace(id=999)---def _message(channel, message_id, mention=False):+def _message(channel: object, message_id: int, *, mention: bool) -> SimpleNamespace:return SimpleNamespace(id=message_id, content=("<@999> " if mention else "") + "what broke?",mentions=[_BOT] if mention else [], attachments=[], reference=None,- created_at=datetime.now(timezone.utc), channel=channel, author=_USER)+ created_at=datetime.now(timezone.utc), channel=channel,+ author=SimpleNamespace(id=42, display_name="Alice", name="alice"))@pytest.mark.asyncio-async def test_auto_thread_first_turn_matches_the_threads_next_message(monkeypatch):+async def test_auto_thread_first_turn_pins_the_threads_topic(monkeypatch: pytest.MonkeyPatch) -> None:monkeypatch.setattr(discord_platform.discord, "Thread", _Thread, raising=False)monkeypatch.delenv("DISCORD_REQUIRE_MENTION", raising=False)monkeypatch.setenv("DISCORD_AUTO_THREAD", "true")- parent = _Text(700)- thread = _Thread(800, parent)- adapter = DiscordAdapter(PlatformConfig(enabled=True, token="fake", extra={- "channel_prompts": {"700": "Answer in haiku."},- "channel_skill_bindings": [{"id": "700", "skill": "triage"}]}))+ guild = SimpleNamespace(id=1, name="Hermes Server")+ parent = SimpleNamespace(id=700, name="ops", topic="Incident triage", guild=guild)+ thread = _Thread(parent)+ adapter = DiscordAdapter(PlatformConfig(enabled=True, token="fake"))adapter._client = SimpleNamespace(user=_BOT)adapter._text_batch_delay_seconds = 0adapter._discord_history_backfill = lambda: Falseadapter._auto_create_thread = AsyncMock(return_value=thread)adapter.handle_message = AsyncMock()+ runner = object.__new__(gateway_run.GatewayRunner)+ config = GatewayConfig(platforms={Platform.DISCORD: PlatformConfig(enabled=True, token="x")})- # Default mention gate: an untagged parent message neither threads nor dispatches.- assert await adapter._handle_message(_message(parent, 99)) is False- adapter._auto_create_thread.assert_not_awaited()- adapter.handle_message.assert_not_awaited()-- events = []+ prompts = []for channel, message_id, mention in ((parent, 100, True), (thread, 101, False)):- assert await adapter._handle_message(_message(channel, message_id, mention)) is True- events.append(adapter.handle_message.await_args.args[0])+ assert await adapter._handle_message(_message(channel, message_id, mention=mention))+ source = adapter.handle_message.await_args.args[0].source+ assert source.chat_id == "800"+ prompts.append(runner._pinned_session_context_prompt(build_session_context(source, config), False, "k"))adapter._auto_create_thread.assert_awaited_once()- first, follow_up = events- assert first.source.chat_id == follow_up.source.chat_id == "800"-- runner = object.__new__(gateway_run.GatewayRunner)- config = GatewayConfig(platforms={Platform.DISCORD: PlatformConfig(enabled=True, token="x")})- pinned = []- for event in (first, follow_up):- context = build_session_context(event.source, config)- channel_prompt, _ = runner._pinned_channel_inputs("k", event.channel_prompt, event.source, internal=False)- pinned.append((runner._pinned_session_context_prompt(context, False, "k"), channel_prompt))- assert pinned[0][1] == "Answer in haiku."- assert pinned[0] == pinned[1], (pinned[0][0], pinned[1][0])- assert first.auto_skill == follow_up.auto_skill == ["triage"]+ assert prompts[0] == prompts[1]