Files
wehub-resource-sync b4fbd6fe9f
Deploy Site / deploy-vercel (push) Has been skipped
Deploy Site / deploy-docs (push) Has been skipped
Build Skills Index / build-index (push) Has been skipped
CI / Deny unrelated histories (push) Has been skipped
CI / Detect affected areas (push) Successful in 27m35s
CI / OSV scan (push) Failing after 4s
CI / Build&Test Docker image (push) Successful in 9s
CI / Supply-chain scan (push) Has been skipped
CI / Lint Docker scripts (push) Failing after 5m13s
CI / Check contributors (push) Failing after 12m8s
CI / Docs Site (push) Failing after 12m8s
CI / TypeScript (push) Failing after 12m8s
CI / Python lints (push) Failing after 12m9s
CI / Python tests (push) Failing after 12m9s
CI / Check uv.lock (push) Failing after 23m22s
CI / CI timing report (push) Has been cancelled
Build Skills Index / trigger-deploy (push) Has been cancelled
CI / All required checks pass (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:56:03 +08:00

98 lines
3.1 KiB
Python

"""Tests for send_message action='react'/'unreact' dispatch.
Kept separate from ``test_send_message_tool.py`` because that module skips
wholesale when optional Telegram dependencies are not installed.
"""
import json
from types import SimpleNamespace
from unittest.mock import patch
import tools.send_message_tool as smt
class _FakePhotonAdapter:
"""Adapter exposing add_reaction/remove_reaction coroutines."""
def __init__(self):
self.calls = []
async def add_reaction(self, chat_id, emoji, message_id=None):
self.calls.append(("add", chat_id, emoji, message_id))
return {"success": True, "emoji": emoji}
async def remove_reaction(self, chat_id, message_id=None):
self.calls.append(("remove", chat_id, message_id))
return {"success": True}
class _NoReactionAdapter:
"""Adapter with no reaction support at all."""
def _runner_with(adapter):
from gateway.config import Platform
return SimpleNamespace(adapters={Platform("photon"): adapter})
def _call(args):
return json.loads(smt.send_message_tool(args))
def test_react_dispatches_to_add_reaction():
adapter = _FakePhotonAdapter()
with patch("gateway.run._gateway_runner_ref", lambda: _runner_with(adapter)):
result = _call(
{"action": "react", "target": "photon:+15551234567", "emoji": "❤️"}
)
assert result["success"] is True
assert adapter.calls == [("add", "+15551234567", "❤️", None)]
def test_unreact_dispatches_to_remove_reaction():
adapter = _FakePhotonAdapter()
with patch("gateway.run._gateway_runner_ref", lambda: _runner_with(adapter)):
result = _call(
{
"action": "unreact",
"target": "photon:+15551234567",
"message_id": "msg-9",
}
)
assert result["success"] is True
assert adapter.calls == [("remove", "+15551234567", "msg-9")]
def test_react_requires_emoji():
result = _call({"action": "react", "target": "photon:+15551234567"})
assert result.get("success") is not True
assert "emoji" in json.dumps(result)
def test_unreact_does_not_require_emoji():
adapter = _FakePhotonAdapter()
with patch("gateway.run._gateway_runner_ref", lambda: _runner_with(adapter)):
result = _call({"action": "unreact", "target": "photon:+15551234567"})
assert result["success"] is True
assert adapter.calls == [("remove", "+15551234567", None)]
def test_react_unsupported_platform_adapter():
adapter = _NoReactionAdapter()
with patch("gateway.run._gateway_runner_ref", lambda: _runner_with(adapter)):
result = _call(
{"action": "react", "target": "photon:+15551234567", "emoji": "👍"}
)
assert result.get("success") is not True
assert "does not support" in json.dumps(result)
def test_react_without_live_gateway():
with patch("gateway.run._gateway_runner_ref", lambda: None):
result = _call(
{"action": "react", "target": "photon:+15551234567", "emoji": "👍"}
)
assert result.get("success") is not True
assert "live" in json.dumps(result)