mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-30 19:09:28 +00:00
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.
115 lines
4.9 KiB
Python
115 lines
4.9 KiB
Python
"""Tests for config.get() null-coalescing in tool configuration.
|
|
|
|
YAML ``null`` values (or ``~``) for a present key make ``dict.get(key, default)``
|
|
return ``None`` instead of the default — calling ``.lower()`` on that raises
|
|
``AttributeError``. These tests verify the ``or`` coalescing guards.
|
|
"""
|
|
|
|
from unittest.mock import patch
|
|
|
|
|
|
# ── TTS tool ──────────────────────────────────────────────────────────────
|
|
|
|
class TestTTSProviderNullGuard:
|
|
"""tools/tts_tool.py — _get_provider()"""
|
|
|
|
def test_explicit_null_provider_returns_default(self):
|
|
"""YAML ``tts: {provider: null}`` should fall back to default."""
|
|
from tools.tts_tool import _get_provider, DEFAULT_PROVIDER
|
|
|
|
result = _get_provider({"provider": None})
|
|
assert result == DEFAULT_PROVIDER.lower().strip()
|
|
|
|
|
|
def test_missing_provider_keeps_free_default_with_cloud_credentials(self):
|
|
"""A chat-provider key must not silently opt the user into paid TTS."""
|
|
from tools.tts_tool import _get_provider, DEFAULT_PROVIDER
|
|
|
|
assert _get_provider({}) == DEFAULT_PROVIDER
|
|
assert _get_provider({"provider": None}) == DEFAULT_PROVIDER
|
|
|
|
def test_active_provider_without_credentials_keeps_edge(self):
|
|
"""A TTS-capable active provider that can't authenticate must NOT
|
|
silently displace the free Edge default (no surprise billing / hard
|
|
errors for a credential-less deployment)."""
|
|
from tools.tts_tool import _get_provider, DEFAULT_PROVIDER
|
|
|
|
assert _get_provider({}) == DEFAULT_PROVIDER.lower().strip()
|
|
|
|
def test_explicit_provider_wins_over_active(self):
|
|
"""An explicit tts.provider always overrides the active-provider fallback."""
|
|
from tools.tts_tool import _get_provider
|
|
|
|
assert _get_provider({"provider": "edge"}) == "edge"
|
|
|
|
|
|
# ── Web tools ─────────────────────────────────────────────────────────────
|
|
|
|
class TestWebBackendNullGuard:
|
|
"""tools/web_tools.py — _get_backend()"""
|
|
|
|
@patch("tools.web_tools._load_web_config", return_value={"backend": None})
|
|
def test_explicit_null_backend_does_not_crash(self, _cfg):
|
|
"""YAML ``web: {backend: null}`` should not raise AttributeError."""
|
|
from tools.web_tools import _get_backend
|
|
|
|
# Should not raise — the exact return depends on env key fallback
|
|
result = _get_backend()
|
|
assert isinstance(result, str)
|
|
|
|
@patch("tools.web_tools._load_web_config", return_value={})
|
|
def test_missing_backend_does_not_crash(self, _cfg):
|
|
from tools.web_tools import _get_backend
|
|
|
|
result = _get_backend()
|
|
assert isinstance(result, str)
|
|
|
|
|
|
# ── MCP tool ──────────────────────────────────────────────────────────────
|
|
|
|
class TestMCPAuthNullGuard:
|
|
"""tools/mcp_tool.py — MCPServerTask.__init__() auth config line"""
|
|
|
|
def test_explicit_null_auth_does_not_crash(self):
|
|
"""YAML ``auth: null`` in MCP server config should not raise."""
|
|
# Test the expression directly — MCPServerTask.__init__ has many deps
|
|
config = {"auth": None, "timeout": 30}
|
|
auth_type = (config.get("auth") or "").lower().strip()
|
|
assert auth_type == ""
|
|
|
|
|
|
def test_valid_auth_passed_through(self):
|
|
config = {"auth": "OAUTH", "timeout": 30}
|
|
auth_type = (config.get("auth") or "").lower().strip()
|
|
assert auth_type == "oauth"
|
|
|
|
|
|
# ── Trajectory compressor ─────────────────────────────────────────────────
|
|
|
|
class TestTrajectoryCompressorNullGuard:
|
|
"""trajectory_compressor.py — _detect_provider() and config loading"""
|
|
|
|
def test_null_base_url_does_not_crash(self):
|
|
"""base_url=None should not crash _detect_provider()."""
|
|
from trajectory_compressor import CompressionConfig, TrajectoryCompressor
|
|
|
|
config = CompressionConfig()
|
|
config.base_url = None
|
|
|
|
compressor = TrajectoryCompressor.__new__(TrajectoryCompressor)
|
|
compressor.config = config
|
|
|
|
# Should not raise AttributeError; returns empty string (no match)
|
|
result = compressor._detect_provider()
|
|
assert result == ""
|
|
|
|
def test_config_loading_null_base_url_keeps_default(self):
|
|
"""YAML ``summarization: {base_url: null}`` should keep default."""
|
|
from trajectory_compressor import CompressionConfig
|
|
from hermes_constants import OPENROUTER_BASE_URL
|
|
|
|
config = CompressionConfig()
|
|
data = {"summarization": {"base_url": None}}
|
|
|
|
config.base_url = data["summarization"].get("base_url") or config.base_url
|
|
assert config.base_url == OPENROUTER_BASE_URL
|