From b5bd66eac9b18bb0e7c34f141c4631ff4eb1c72b Mon Sep 17 00:00:00 2001 From: teknium1 <127238744+teknium1@users.noreply.github.com> Date: Sun, 21 Jun 2026 20:43:51 -0700 Subject: [PATCH] fix(telegram): observed/replied group docs of any type are cached too MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follow-up to the accept-any-file-type change. The observe-unmentioned and replied-media paths relied on cache_media_bytes() returning None for unsupported document types to emit an 'unsupported, not cached' note. Now that any file type is always cached, those docs are cached and surfaced with a path-pointing note — consistent with the main document path. The remaining cached-is-None branch is image-validation-failure only; its note is reworded accordingly. Updates the group-gating test to the new contract. --- plugins/platforms/telegram/adapter.py | 5 ++++- tests/gateway/test_telegram_group_gating.py | 14 ++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) 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())