mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-06-23 10:42:00 +00:00
fix(telegram): observed/replied group docs of any type are cached too
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.
This commit is contained in:
parent
4314d451ca
commit
b5bd66eac9
2 changed files with 12 additions and 7 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue