From 909330a61c028b815d9fa5ddda63101fb187d2a7 Mon Sep 17 00:00:00 2001 From: teknium1 <127238744+teknium1@users.noreply.github.com> Date: Tue, 30 Jun 2026 23:47:57 -0700 Subject: [PATCH] test(discord): fix double-dispatch dedup test for fail-closed auto-thread MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit test_no_dedup_seed_when_thread_creation_fails asserted the agent still ran inline when auto-thread creation failed — the pre-#20243 silent-fallback behavior. Flip that to assert_not_awaited() to match the new fail-closed contract; the test's actual contract (phantom thread id must not leak into the dedup cache on failure) is unchanged. Give the fake channel a send mock so the failure-notice path runs cleanly. --- tests/gateway/test_discord_double_dispatch.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/gateway/test_discord_double_dispatch.py b/tests/gateway/test_discord_double_dispatch.py index fcf45bfd4..ee42895f4 100644 --- a/tests/gateway/test_discord_double_dispatch.py +++ b/tests/gateway/test_discord_double_dispatch.py @@ -226,11 +226,19 @@ class TestThreadStarterDedup: @pytest.mark.asyncio async def test_no_dedup_seed_when_thread_creation_fails(self, adapter, monkeypatch): - """When _auto_create_thread returns None, no pre-seeding occurs.""" + """When _auto_create_thread returns None, no pre-seeding occurs. + + Auto-thread failure is now fail-closed (#20243): the agent is NOT + invoked and the user gets a visible notice instead of a silent inline + reply. This test's contract is specifically about dedup pre-seeding — + the phantom thread id must not leak into the dedup cache when creation + fails. + """ monkeypatch.setenv("DISCORD_REQUIRE_MENTION", "false") monkeypatch.setenv("DISCORD_AUTO_THREAD", "true") channel = _TextChannel(channel_id=100) + channel.send = AsyncMock() phantom_thread_id = 55555 async def fake_auto_create_thread_fail(message): @@ -243,8 +251,9 @@ class TestThreadStarterDedup: user_msg = _make_message(msg_id=42, channel=channel, content="hello") await adapter._handle_message(user_msg) - # The message was still dispatched (no thread, but message goes through) - adapter.handle_message.assert_awaited_once() + # Fail-closed: the agent must NOT run when the required thread route + # could not be created (#20243). + adapter.handle_message.assert_not_awaited() # The phantom thread id should NOT be in the dedup cache assert str(phantom_thread_id) not in adapter._dedup._seen, (