from unittest.mock import AsyncMock, MagicMock import pytest import discord from chorus_bot.cogs.thread_ingest import ThreadIngestCog from chorus_bot.ping import build_ping_embed class _FakeConfig: inbox_channel_id = 111 @pytest.mark.asyncio async def test_thread_create_passes_direction_to_backend_client(): bot = MagicMock() backend_client = AsyncMock() cog = ThreadIngestCog(bot, _FakeConfig(), backend_client) embed = build_ping_embed( modality="lead_found", sender_id=None, snippet="found post", raw_content="Someone posting about book donation", captured_at=__import__("datetime").datetime(2026, 7, 13, 7, 0, 0, tzinfo=__import__("datetime").timezone.utc), direction="outbound", ) parent_message = MagicMock() parent_message.embeds = [embed] thread = MagicMock(spec=discord.Thread) thread.id = 555 thread.parent_id = 111 thread.parent.fetch_message = AsyncMock(return_value=parent_message) thread.send = AsyncMock() await cog.on_thread_create(thread) backend_client.create_item.assert_awaited_once() assert backend_client.create_item.call_args.kwargs["direction"] == "outbound"