Files
hermes-agent/tests/gateway/relay/test_handoff_relay_aliasing.py
T
Teknium 39975613b1 test: prune wave 2 + speed fixes — 28,106 → 19,757 test functions, suite wall 315s → 294s
Second, deeper pass over tools/gateway/hermes_cli plus first pass over
the trees wave 1 missed (acp, acp_adapter, skills, computer_use, docker,
dashboard, conformance, monitoring, secret_sources, hermes_state,
providers). Same rubric as wave 1 (AGENTS.md test policy); security,
alternation/caching invariants, issue-number regressions, and E2E kept.

Real test-quality fixes found and rooted out along the way:
- tests/tools/test_command_guards.py made real auxiliary-LLM HTTPS calls
  (DEFAULT_CONFIG smart-approval leaked in) — pinned approval
  mode=manual via autouse fixture: 17.4s → 0.4s.
- test_model_switch_custom_providers.py / test_user_providers_model_switch.py
  silently probed live provider catalogs (~2s/test) — stubbed
  cached_provider_model_ids/provider_model_ids/fetch_api_models.
- test_telegram_noise_filter.py: 15-platform copy-paste matrix over
  shared gateway.run logic → 3 representative platforms (55s → 3.9s).
- test_gateway_shutdown.py: stop()'s 5s interrupt-deadline loop spun on
  MagicMock agents — interrupt.side_effect now clears _running_agents
  (22s → 1.0s).
- test_gateway_inactivity_timeout.py poll-harness timings shrunk 3-5x
  (24s → 1.1s); test_mcp_stability.py backoff/SIGTERM-grace sleeps
  patched (15.4s → 2.5s); test_async_delegation.py negative-drain wait
  5s → 0.5s.
- test_telegram_init_deadline.py: loop-block margin restored to 1.0s
  with rationale comment — the watchdog-dump assertion needs the loop
  blocked well past deadline+grace under parallel load (flaked once in
  the 40-worker verification run at a 0.2s margin).

Verification: full hermetic suite via scripts/run_tests.sh —
2,438 files, 21,718 tests passed, 0 failed, 293.9s wall.
Suite totals vs original baseline: 46,820 → 19,757 test functions
(−57.8%), wall 583.5s → 293.9s (−50%), subprocess CPU 13,564s → 11,623s.
2026-07-29 13:39:40 -07:00

77 lines
3.0 KiB
Python

"""Unit tests for /handoff platform aliasing over relay (Phase 1 parity).
Symptom fixed: on a relay-fronted gateway, ``/handoff discord`` was rejected
in TWO places even though "discord" is deliverable through the relay adapter:
1. The CLI pre-check (``cli_commands_mixin._handle_handoff_command``) looked
up ``gw_config.platforms.get(DISCORD)`` — only a RELAY entry exists.
2. The gateway watcher (``run.py _process_handoff``) did a literal
``adapters.get(discord)`` — the adapter is registered under RELAY.
Both now resolve fronted platforms through the same alias-aware machinery the
delivery router uses (``resolve_delivery_transport`` — native adapter wins;
relay eligible only when its authenticated transport advertises the logical
platform). These tests cover the resolver semantics the watcher depends on,
plus the CLI pre-check's env-derived fronted set.
"""
from __future__ import annotations
import pytest
from gateway.config import GatewayConfig, Platform, PlatformConfig
from gateway.delivery import resolve_delivery_transport
class _RelayStub:
"""Minimal relay adapter double advertising a fronted-platform set."""
def __init__(self, fronted):
self._fronted = set(fronted)
self.sent = []
def fronts_platform(self, platform):
value = getattr(platform, "value", platform)
return str(value) in self._fronted
async def send_for_platform(self, logical_platform, chat_id, content, reply_to=None, metadata=None):
self.sent.append((getattr(logical_platform, "value", logical_platform), chat_id, content, metadata))
return type("R", (), {"success": True, "message_id": "m-1", "error": None})()
async def send(self, chat_id, content, reply_to=None, metadata=None): # pragma: no cover
raise AssertionError("relay transport must use send_for_platform, not send")
def _config_with(platforms):
cfg = GatewayConfig()
cfg.platforms = platforms
return cfg
class TestHandoffRelayAliasing:
def test_fronted_platform_resolves_to_relay_adapter(self):
"""The watcher's exact miss: adapters holds only RELAY, target is discord."""
relay = _RelayStub({"discord"})
cfg = _config_with({Platform.RELAY: PlatformConfig(enabled=True)})
transport = resolve_delivery_transport(
Platform.DISCORD, cfg, {Platform.RELAY: relay}
)
assert transport is not None
assert transport.adapter is relay
assert transport.is_relay is True
class TestCliHandoffFrontedSet:
"""The CLI pre-check derives the fronted set from deploy env (no live adapter)."""
def test_fronted_set_from_env(self, monkeypatch):
monkeypatch.setenv("GATEWAY_RELAY_PLATFORMS", "discord,telegram")
monkeypatch.delenv("GATEWAY_RELAY_BOT_IDS", raising=False)
from gateway.relay import relay_platform_identities
fronted = {p for p, _ in relay_platform_identities()}
assert "discord" in fronted
assert "telegram" in fronted
assert "slack" not in fronted