From e1b0b135cbb71142e68e9a8b3c27b2b5188634ec Mon Sep 17 00:00:00 2001 From: Kira Date: Thu, 9 Apr 2026 03:15:09 -0400 Subject: [PATCH] fix(discord): accept .log attachments and raise document size limit --- gateway/platforms/base.py | 1 + gateway/platforms/discord.py | 6 +-- .../gateway/test_discord_document_handling.py | 39 ++++++++++++++++++- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/gateway/platforms/base.py b/gateway/platforms/base.py index c72fa513b..bd07459ac 100644 --- a/gateway/platforms/base.py +++ b/gateway/platforms/base.py @@ -298,6 +298,7 @@ SUPPORTED_DOCUMENT_TYPES = { ".pdf": "application/pdf", ".md": "text/markdown", ".txt": "text/plain", + ".log": "text/plain", ".zip": "application/zip", ".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document", ".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", diff --git a/gateway/platforms/discord.py b/gateway/platforms/discord.py index 36984202e..2ace06e77 100644 --- a/gateway/platforms/discord.py +++ b/gateway/platforms/discord.py @@ -2382,7 +2382,7 @@ class DiscordAdapter(BasePlatformAdapter): ext or "unknown", content_type, ) else: - MAX_DOC_BYTES = 20 * 1024 * 1024 + MAX_DOC_BYTES = 32 * 1024 * 1024 if att.size and att.size > MAX_DOC_BYTES: logger.warning( "[Discord] Document too large (%s bytes), skipping: %s", @@ -2406,9 +2406,9 @@ class DiscordAdapter(BasePlatformAdapter): media_urls.append(cached_path) media_types.append(doc_mime) logger.info("[Discord] Cached user document: %s", cached_path) - # Inject text content for .txt/.md files (capped at 100 KB) + # Inject text content for plain-text documents (capped at 100 KB) MAX_TEXT_INJECT_BYTES = 100 * 1024 - if ext in (".md", ".txt") and len(raw_bytes) <= MAX_TEXT_INJECT_BYTES: + if ext in (".md", ".txt", ".log") and len(raw_bytes) <= MAX_TEXT_INJECT_BYTES: try: text_content = raw_bytes.decode("utf-8") display_name = att.filename or f"document{ext}" diff --git a/tests/gateway/test_discord_document_handling.py b/tests/gateway/test_discord_document_handling.py index 7f918d1c7..a22e0f0d6 100644 --- a/tests/gateway/test_discord_document_handling.py +++ b/tests/gateway/test_discord_document_handling.py @@ -209,14 +209,31 @@ class TestIncomingDocumentHandling: assert "[Content of readme.md]:" in event.text assert "# Title" in event.text + @pytest.mark.asyncio + async def test_log_content_injected(self, adapter): + """.log file under 100KB should be treated as text/plain and injected.""" + file_content = b"BLE trace line 1\nBLE trace line 2" + + with _mock_aiohttp_download(file_content): + msg = make_message( + attachments=[make_attachment(filename="btsnoop_hci.log", content_type="text/plain")], + content="please inspect this", + ) + await adapter._handle_message(msg) + + event = adapter.handle_message.call_args[0][0] + assert "[Content of btsnoop_hci.log]:" in event.text + assert "BLE trace line 1" in event.text + assert "please inspect this" in event.text + @pytest.mark.asyncio async def test_oversized_document_skipped(self, adapter): - """A document over 20MB should be skipped — media_urls stays empty.""" + """A document over 32MB should be skipped — media_urls stays empty.""" msg = make_message([ make_attachment( filename="huge.pdf", content_type="application/pdf", - size=25 * 1024 * 1024, + size=33 * 1024 * 1024, ) ]) await adapter._handle_message(msg) @@ -226,6 +243,24 @@ class TestIncomingDocumentHandling: # handler must still be called adapter.handle_message.assert_called_once() + @pytest.mark.asyncio + async def test_mid_sized_zip_under_32mb_is_cached(self, adapter): + """A 25MB .zip should be accepted now that Discord documents allow up to 32MB.""" + msg = make_message([ + make_attachment( + filename="bugreport.zip", + content_type="application/zip", + size=25 * 1024 * 1024, + ) + ]) + + with _mock_aiohttp_download(b"PK\x03\x04test"): + await adapter._handle_message(msg) + + event = adapter.handle_message.call_args[0][0] + assert len(event.media_urls) == 1 + assert event.media_types == ["application/zip"] + @pytest.mark.asyncio async def test_zip_document_cached(self, adapter): """A .zip file should be cached as a supported document."""