fix(discord): fall back when auto-thread creation fails

This commit is contained in:
sgaofen
2026-04-12 17:31:57 -07:00
committed by Teknium
parent f5dc4e905d
commit 32a694ad5f
2 changed files with 47 additions and 4 deletions

View File

@@ -401,6 +401,8 @@ async def test_auto_create_thread_uses_message_content_as_name(adapter):
message = SimpleNamespace(
content="Hello world, how are you?",
create_thread=AsyncMock(return_value=thread),
channel=SimpleNamespace(send=AsyncMock()),
author=SimpleNamespace(display_name="Jezza"),
)
result = await adapter._auto_create_thread(message)
@@ -419,6 +421,8 @@ async def test_auto_create_thread_truncates_long_names(adapter):
message = SimpleNamespace(
content=long_text,
create_thread=AsyncMock(return_value=thread),
channel=SimpleNamespace(send=AsyncMock()),
author=SimpleNamespace(display_name="Jezza"),
)
result = await adapter._auto_create_thread(message)
@@ -430,10 +434,33 @@ async def test_auto_create_thread_truncates_long_names(adapter):
@pytest.mark.asyncio
async def test_auto_create_thread_returns_none_on_failure(adapter):
async def test_auto_create_thread_falls_back_to_seed_message(adapter):
thread = SimpleNamespace(id=555, name="Hello")
seed_message = SimpleNamespace(create_thread=AsyncMock(return_value=thread))
message = SimpleNamespace(
content="Hello",
create_thread=AsyncMock(side_effect=RuntimeError("no perms")),
channel=SimpleNamespace(send=AsyncMock(return_value=seed_message)),
author=SimpleNamespace(display_name="Jezza"),
)
result = await adapter._auto_create_thread(message)
assert result is thread
message.channel.send.assert_awaited_once_with("🧵 Thread created by Hermes: **Hello**")
seed_message.create_thread.assert_awaited_once_with(
name="Hello",
auto_archive_duration=1440,
reason="Auto-threaded from mention by Jezza",
)
@pytest.mark.asyncio
async def test_auto_create_thread_returns_none_when_direct_and_fallback_fail(adapter):
message = SimpleNamespace(
content="Hello",
create_thread=AsyncMock(side_effect=RuntimeError("no perms")),
channel=SimpleNamespace(send=AsyncMock(side_effect=RuntimeError("send failed"))),
author=SimpleNamespace(display_name="Jezza"),
)
result = await adapter._auto_create_thread(message)