diff --git a/plugins/platforms/telegram/adapter.py b/plugins/platforms/telegram/adapter.py index 390acb61047..8e062c5c5c0 100644 --- a/plugins/platforms/telegram/adapter.py +++ b/plugins/platforms/telegram/adapter.py @@ -5861,8 +5861,11 @@ class TelegramAdapter(BasePlatformAdapter): return if cached is None: + # Only reachable for images that fail validation now — any other + # file type is always cached (authorization is the gate, not the + # extension). event.text = self._append_observed_note( - event.text, "[Observed Telegram attachment: unsupported type, not cached.]" + event.text, "[Observed Telegram attachment could not be read, not cached.]" ) return diff --git a/tests/gateway/test_telegram_group_gating.py b/tests/gateway/test_telegram_group_gating.py index d9b55fa2ad4..02362db91ec 100644 --- a/tests/gateway/test_telegram_group_gating.py +++ b/tests/gateway/test_telegram_group_gating.py @@ -1180,7 +1180,7 @@ def test_unmentioned_large_document_observed_without_download(monkeypatch): asyncio.run(_run()) -def test_unmentioned_unsupported_document_observed_without_caching(monkeypatch): +def test_unmentioned_unsupported_document_observed_and_cached(monkeypatch): async def _run(): adapter = _make_adapter( require_mention=True, allowed_chats=["-100"], @@ -1188,14 +1188,14 @@ def test_unmentioned_unsupported_document_observed_without_caching(monkeypatch): ) store = _FakeSessionStore() adapter._session_store = store - cache_doc = Mock(return_value="/tmp/malware.exe") + cache_doc = Mock(return_value="/tmp/program.exe") monkeypatch.setattr("gateway.platforms.base.cache_document_from_bytes", cache_doc) file_obj = SimpleNamespace( - file_path="documents/malware.exe", + file_path="documents/program.exe", download_as_bytearray=AsyncMock(return_value=bytearray(b"MZ")), ) document = SimpleNamespace( - file_name="malware.exe", mime_type="application/x-msdownload", + file_name="program.exe", mime_type="application/x-msdownload", file_size=2, get_file=AsyncMock(return_value=file_obj), ) update = SimpleNamespace( @@ -1204,8 +1204,10 @@ def test_unmentioned_unsupported_document_observed_without_caching(monkeypatch): await adapter._handle_media_message(update, SimpleNamespace()) - cache_doc.assert_not_called() + # Any file type is now cached — authorization is the gate, not the + # extension. The observed message records a path-pointing note. + cache_doc.assert_called_once() _, message, _ = store.messages[0] - assert "unsupported" in message["content"].lower() + assert "program.exe" in message["content"] asyncio.run(_run())