mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-31 19:16:29 +00:00
Systematic prune per AGENTS.md test policy, one pass over every major test tree (gateway, hermes_cli, tools, agent, run_agent, plugins, cli, cron, tui_gateway, honcho/openviking, root-level): - DELETE: source-reading tests (read_text/getsource on prod files), change-detector tests (exact catalog counts, model-name snapshots, config version literals), mock-echo tests (assert a mock returns what it was told), assertion-free/trivial tests, near-duplicate parametrizations (boundaries + one representative kept), async/sync twin duplicates, cosmetic within-file variations. - KEEP (mandatory): security/redaction/approval guards, message-role alternation invariants, prompt-caching/deterministic-call-id invariants, issue-number regression tests (deduped), E2E tests. - 6 test files deleted outright (script-style/no-assert or fully redundant); conftest.py, fakes/, fixtures/ untouched. - tests/acp/conftest.py added: autouse fixture stubs the live models.dev/GitHub/Copilot/Anthropic inventory fetches that ACP server tests performed on every session create — test_server.py 147s → 3.4s, and the tests are now genuinely hermetic. - Sleep-based slowness shrunk where safe (codex_ttfb_watchdog, compression_concurrent_fork, etc.); no wall-clock assertion tightened. Verification: full hermetic suite via scripts/run_tests.sh — 2439 files, 31,130 tests passed, 0 failed, 0 flaky retries, 315s wall (baseline: 583s wall, 13,564s subprocess CPU).
105 lines
3.2 KiB
Python
105 lines
3.2 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_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_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"
|