Files
hermes-agent/tests/gateway/test_video_context_note.py
T
kshitijk4poor 2f1609a86c refactor: sms AIOHTTP_AVAILABLE flag; ElicitationHandler call_context defaults to a no-op thunk; drop stale TYPE_CHECKING/type-ignore in two tests
Self-review follow-ups on the F821 sweep:

- plugins/platforms/sms/adapter.py: the optional-import block now sets AIOHTTP_AVAILABLE like
  the homeassistant / webhook / whatsapp_cloud adapters, and both call sites test the flag.
  Removes the `if not aiohttp is not None:` double negation left by inlining
  `_aiohttp_available()`.
- tools/mcp_tool_sampling.py: `call_context` defaults to `lambda: None` so the use site is a
  single call instead of an Optional guard; the only None caller was a test. The
  `from __future__ import annotations` was noise (`Context` is a runtime import). Comment
  names the actual cycle (mcp_tool_server_run imports this module).
- gateway/platforms/helpers.py: drop the `from __future__ import annotations` — the only
  MessageEvent annotations are attribute-target locals, which are never evaluated.
- tests/gateway/test_telegram_audio_vs_voice.py, test_video_context_note.py: module-level
  `from gateway.run import GatewayRunner` like the ~100 sibling files; the
  TYPE_CHECKING block + `# type: ignore[name-defined]` were contradicting each other.
  (tests/e2e/conftest.py and test_feishu.py keep TYPE_CHECKING deliberately: they stub
  telegram/discord before importing, and FeishuAdapter is gated on optional lark_oapi.)

Mutation check: neutralising the thunk read (`captured = None`) fails
test_captured_context_is_replayed_in_consent_call; restored → 14/14 green. ty on the three
touched production files vs origin/main: 0 new, 6 resolved.
2026-09-07 22:47:33 +05:30

50 lines
1.5 KiB
Python

"""Tests for video attachment context notes in gateway turns."""
from unittest.mock import patch
import pytest
from gateway.config import GatewayConfig, Platform
from gateway.platforms.event import MessageEvent, MessageType
from gateway.run import GatewayRunner
from gateway.session import SessionSource
def _make_runner() -> GatewayRunner:
runner = GatewayRunner.__new__(GatewayRunner)
runner.config = GatewayConfig()
runner.adapters = {}
runner._has_setup_skill = lambda: False
return runner
@pytest.mark.asyncio
async def test_video_attachment_adds_path_note_without_document_wording():
from gateway.run import _build_media_placeholder
runner = _make_runner()
source = SessionSource(platform=Platform.SLACK, chat_id="D123", chat_type="dm")
event = MessageEvent(
text="what happens here?",
message_type=MessageType.VIDEO,
source=source,
media_urls=["/tmp/video_clip.mp4"],
media_types=["video/mp4"],
)
with patch(
"tools.credential_files.to_agent_visible_cache_path",
side_effect=lambda path: path,
):
result = await runner._prepare_inbound_message_text(
event=event,
source=source,
history=[],
)
assert "video attachment" in result
assert "/tmp/video_clip.mp4" in result
assert "video analysis or media tool" in result
assert "The user sent a document" not in result
assert _build_media_placeholder(event) == "[User sent a video: /tmp/video_clip.mp4]"