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.
122 lines
4.5 KiB
Python
122 lines
4.5 KiB
Python
"""Tests for config.yaml structure validation (validate_config_structure)."""
|
|
|
|
|
|
from hermes_cli.config import (
|
|
DEFAULT_CONFIG,
|
|
_EXTRA_KNOWN_ROOT_KEYS,
|
|
_KNOWN_ROOT_KEYS,
|
|
validate_config_structure,
|
|
ConfigIssue,
|
|
)
|
|
|
|
|
|
class TestCustomProvidersValidation:
|
|
"""custom_providers must be a YAML list, not a dict."""
|
|
|
|
def test_dict_instead_of_list(self):
|
|
"""The exact Discord user scenario — custom_providers as flat dict."""
|
|
issues = validate_config_structure({
|
|
"custom_providers": {
|
|
"name": "Generativelanguage.googleapis.com",
|
|
"base_url": "https://generativelanguage.googleapis.com/v1beta",
|
|
"api_key": "xxx",
|
|
"model": "models/gemini-2.5-flash",
|
|
"rate_limit_delay": 2.0,
|
|
"fallback_model": {
|
|
"provider": "openrouter",
|
|
"model": "qwen/qwen3.6-plus:free",
|
|
},
|
|
},
|
|
"fallback_providers": [],
|
|
})
|
|
errors = [i for i in issues if i.severity == "error"]
|
|
assert any("dict" in i.message and "list" in i.message for i in errors), (
|
|
"Should detect custom_providers as dict instead of list"
|
|
)
|
|
|
|
def test_dict_detects_misplaced_fields(self):
|
|
"""When custom_providers is a dict, detect fields that look misplaced."""
|
|
issues = validate_config_structure({
|
|
"custom_providers": {
|
|
"name": "test",
|
|
"base_url": "https://example.com",
|
|
"api_key": "xxx",
|
|
},
|
|
})
|
|
warnings = [i for i in issues if i.severity == "warning"]
|
|
# Should flag base_url, api_key as looking like custom_providers entry fields
|
|
misplaced = [i for i in warnings if "custom_providers entry fields" in i.message]
|
|
assert len(misplaced) == 1
|
|
|
|
|
|
def test_list_entry_not_dict(self):
|
|
"""Non-dict list entries should warn."""
|
|
issues = validate_config_structure({
|
|
"custom_providers": ["not-a-dict"],
|
|
"model": {"provider": "custom"},
|
|
})
|
|
assert any("not a dict" in i.message for i in issues)
|
|
|
|
|
|
|
|
|
|
class TestMissingModelSection:
|
|
"""Warn when custom_providers exists but model section is missing."""
|
|
|
|
|
|
def test_custom_providers_with_model(self):
|
|
issues = validate_config_structure({
|
|
"custom_providers": [
|
|
{"name": "test", "base_url": "https://example.com/v1"},
|
|
],
|
|
"model": {"provider": "custom", "default": "test-model"},
|
|
})
|
|
# Should not warn about missing model section
|
|
assert not any("no 'model' section" in i.message for i in issues)
|
|
|
|
|
|
class TestConfigIssueDataclass:
|
|
"""ConfigIssue should be a proper dataclass."""
|
|
|
|
def test_fields(self):
|
|
issue = ConfigIssue(severity="error", message="test msg", hint="test hint")
|
|
assert issue.severity == "error"
|
|
assert issue.message == "test msg"
|
|
assert issue.hint == "test hint"
|
|
|
|
def test_equality(self):
|
|
a = ConfigIssue("error", "msg", "hint")
|
|
b = ConfigIssue("error", "msg", "hint")
|
|
assert a == b
|
|
|
|
|
|
class TestUnknownTopLevelKeys:
|
|
"""Arbitrary top-level keys must NOT warn — they are bridged to os.environ.
|
|
|
|
Top-level scalars in config.yaml are forwarded into the environment
|
|
(gateway/run.py, hermes send) so users can feed skills and external apps
|
|
env-style keys like DISCORD_HOME_CHANNEL or MY_APP_TOKEN. A closed-world
|
|
allowlist can never enumerate those, so no "Unknown top-level config key"
|
|
warning may exist.
|
|
"""
|
|
|
|
|
|
def test_known_root_keys_derived_from_default_config(self):
|
|
"""_KNOWN_ROOT_KEYS must be DEFAULT_CONFIG.keys() plus extras — single source of truth."""
|
|
assert set(DEFAULT_CONFIG.keys()).issubset(_KNOWN_ROOT_KEYS)
|
|
assert _EXTRA_KNOWN_ROOT_KEYS.issubset(_KNOWN_ROOT_KEYS)
|
|
assert _KNOWN_ROOT_KEYS == frozenset(DEFAULT_CONFIG.keys()) | _EXTRA_KNOWN_ROOT_KEYS
|
|
|
|
def test_provider_like_unknown_root_keeps_misplaced_message(self):
|
|
"""Preserve existing base_url/api_key root-level guidance."""
|
|
issues = validate_config_structure({
|
|
"base_url": "https://example.com/v1",
|
|
"api_key": "secret",
|
|
})
|
|
misplaced = [
|
|
i for i in issues
|
|
if i.severity == "warning" and "looks misplaced" in i.message
|
|
]
|
|
assert any("base_url" in i.message for i in misplaced)
|
|
assert any("api_key" in i.message for i in misplaced)
|
|
|