mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-06-12 08:51:53 +00:00
Pin spectrum-ts to exactly 3.0.0 (was ^1.18.0 plus an `npm install spectrum-ts@latest` on every setup) so breaking SDK majors can't take down fresh installs silently; `hermes photon setup` now runs `npm ci`. Upgrade procedure documented in the README. Migrate resolveSpace to the v3 namespace API: `im.space.create(phone)` for DMs and `im.space.get(id)` for everything else — group spaces are now rehydratable from their persisted id after a sidecar restart, which v1 could not do. Markdown: replies go out via the v3 `markdown()` builder (iMessage renders natively; other Spectrum platforms degrade to plain text). `PHOTON_MARKDOWN=false` reverts to the stripped plain-text path. Reactions, behind PHOTON_REACTIONS (default off): lifecycle tapbacks (👀 while processing, 👍/👎 on completion) via new sidecar /react and /unreact endpoints with per-target reaction-handle tracking, and user tapbacks on bot-sent messages routed to the agent as synthetic `reaction:added:<emoji>` events. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
129 lines
4 KiB
Python
129 lines
4 KiB
Python
"""Markdown handling tests for PhotonAdapter.
|
|
|
|
Markdown is on by default (the sidecar sends it via spectrum-ts'
|
|
``markdown()`` builder and iMessage renders it); ``PHOTON_MARKDOWN=false``
|
|
reverts to the stripped-plain-text path.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from typing import Any, Dict, List, Tuple
|
|
|
|
import pytest
|
|
|
|
from gateway.config import PlatformConfig
|
|
from plugins.platforms.photon import adapter as photon_adapter
|
|
from plugins.platforms.photon.adapter import PhotonAdapter
|
|
|
|
_MD = "**bold** and `code`"
|
|
|
|
|
|
def _make_adapter(monkeypatch: pytest.MonkeyPatch) -> PhotonAdapter:
|
|
monkeypatch.setenv("PHOTON_PROJECT_ID", "test-project-id")
|
|
monkeypatch.setenv("PHOTON_PROJECT_SECRET", "test-project-secret")
|
|
cfg = PlatformConfig(enabled=True, token="", extra={})
|
|
return PhotonAdapter(cfg)
|
|
|
|
|
|
def _capture_sidecar(adapter: PhotonAdapter) -> List[Tuple[str, Dict[str, Any]]]:
|
|
calls: List[Tuple[str, Dict[str, Any]]] = []
|
|
|
|
async def _fake_call(path: str, body: Dict[str, Any]) -> Dict[str, Any]:
|
|
calls.append((path, body))
|
|
return {"ok": True, "messageId": "msg-123"}
|
|
|
|
adapter._sidecar_call = _fake_call # type: ignore[assignment]
|
|
return calls
|
|
|
|
|
|
def test_format_message_passthrough_by_default(
|
|
monkeypatch: pytest.MonkeyPatch,
|
|
) -> None:
|
|
monkeypatch.delenv("PHOTON_MARKDOWN", raising=False)
|
|
adapter = _make_adapter(monkeypatch)
|
|
assert adapter.format_message(_MD) == _MD
|
|
|
|
|
|
def test_format_message_strips_when_disabled(
|
|
monkeypatch: pytest.MonkeyPatch,
|
|
) -> None:
|
|
monkeypatch.setenv("PHOTON_MARKDOWN", "false")
|
|
adapter = _make_adapter(monkeypatch)
|
|
assert adapter.format_message(_MD) == "bold and code"
|
|
|
|
|
|
def test_supports_code_blocks_mirrors_env(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
monkeypatch.delenv("PHOTON_MARKDOWN", raising=False)
|
|
assert _make_adapter(monkeypatch).supports_code_blocks is True
|
|
monkeypatch.setenv("PHOTON_MARKDOWN", "false")
|
|
assert _make_adapter(monkeypatch).supports_code_blocks is False
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_sidecar_send_includes_markdown_format(
|
|
monkeypatch: pytest.MonkeyPatch,
|
|
) -> None:
|
|
monkeypatch.delenv("PHOTON_MARKDOWN", raising=False)
|
|
adapter = _make_adapter(monkeypatch)
|
|
calls = _capture_sidecar(adapter)
|
|
|
|
await adapter.send("+15551234567", _MD)
|
|
|
|
path, body = calls[0]
|
|
assert path == "/send"
|
|
assert body["format"] == "markdown"
|
|
assert body["text"] == _MD # passed through unstripped
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_sidecar_send_omits_format_when_disabled(
|
|
monkeypatch: pytest.MonkeyPatch,
|
|
) -> None:
|
|
"""Old-sidecar compat: the key is absent, not "text", when disabled."""
|
|
monkeypatch.setenv("PHOTON_MARKDOWN", "false")
|
|
adapter = _make_adapter(monkeypatch)
|
|
calls = _capture_sidecar(adapter)
|
|
|
|
await adapter.send("+15551234567", _MD)
|
|
|
|
_, body = calls[0]
|
|
assert "format" not in body
|
|
assert body["text"] == "bold and code"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_standalone_send_includes_markdown_format(
|
|
monkeypatch: pytest.MonkeyPatch,
|
|
) -> None:
|
|
monkeypatch.delenv("PHOTON_MARKDOWN", raising=False)
|
|
monkeypatch.setenv("PHOTON_SIDECAR_TOKEN", "tok")
|
|
|
|
posted: List[Tuple[str, Dict[str, Any]]] = []
|
|
|
|
class _Resp:
|
|
status_code = 200
|
|
|
|
@staticmethod
|
|
def json() -> Dict[str, Any]:
|
|
return {"ok": True, "messageId": "m-9"}
|
|
|
|
class _FakeClient:
|
|
def __init__(self, *a, **k):
|
|
pass
|
|
|
|
async def __aenter__(self):
|
|
return self
|
|
|
|
async def __aexit__(self, *a):
|
|
return False
|
|
|
|
async def post(self, url: str, json: Dict[str, Any], headers=None):
|
|
posted.append((url, json))
|
|
return _Resp()
|
|
|
|
monkeypatch.setattr(photon_adapter.httpx, "AsyncClient", _FakeClient)
|
|
|
|
cfg = PlatformConfig(enabled=True, token="", extra={})
|
|
result = await photon_adapter._standalone_send(cfg, "+15551234567", _MD)
|
|
|
|
assert result.get("success") is True
|
|
assert posted[0][1]["format"] == "markdown"
|