mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-31 19:16:29 +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.
114 lines
4.8 KiB
Python
114 lines
4.8 KiB
Python
"""Tests for Blank Slate setup mode (hermes_cli/setup.py).
|
|
|
|
Blank Slate is the third first-time setup option: everything off except the
|
|
bare minimum needed to run an agent (provider/model + file + terminal). These
|
|
tests pin the config the writers produce and the invariant that the toolset
|
|
resolver + tool-schema builder yield exactly the file/terminal tools.
|
|
"""
|
|
|
|
import pytest
|
|
|
|
from hermes_cli.setup import (
|
|
_blank_slate_minimal_toolsets,
|
|
_blank_slate_minimize_config,
|
|
)
|
|
|
|
|
|
class TestBlankSlateMinimalToolsets:
|
|
|
|
|
|
|
|
def test_no_disabled_bundle_overlaps_kept_tools(self):
|
|
"""Invariant: ``disabled_toolsets`` is applied at *tool* granularity and
|
|
a single tool can belong to several toolsets, so no disabled entry may
|
|
share a tool with a kept toolset — it would silently strip that tool
|
|
from the blank-slate agent (#57315, #58281).
|
|
"""
|
|
from toolsets import resolve_toolset
|
|
cfg = {}
|
|
_blank_slate_minimal_toolsets(cfg)
|
|
kept_tools = set()
|
|
for ts in cfg["platform_toolsets"]["cli"]:
|
|
kept_tools.update(resolve_toolset(ts))
|
|
for ts in cfg["agent"]["disabled_toolsets"]:
|
|
overlap = set(resolve_toolset(ts)) & kept_tools
|
|
assert not overlap, (
|
|
f"disabled toolset '{ts}' overlaps kept tools {sorted(overlap)}; "
|
|
"it would silently strip them from the blank-slate agent"
|
|
)
|
|
|
|
|
|
|
|
def test_tool_schema_survives_disabled_toolsets_from_config(self):
|
|
"""Regression: disabled_toolsets must not erase the minimal Blank Slate
|
|
surface when passed to model_tools. Before the fix, posture toolsets
|
|
like ``coding`` in disabled_toolsets caused model_tools to subtract
|
|
terminal, read_file, write_file, etc. (#57315).
|
|
"""
|
|
import model_tools
|
|
from hermes_cli.tools_config import _get_platform_tools
|
|
cfg = {}
|
|
_blank_slate_minimal_toolsets(cfg)
|
|
_blank_slate_minimize_config(cfg)
|
|
enabled = sorted(_get_platform_tools(cfg, "cli"))
|
|
disabled = cfg.get("agent", {}).get("disabled_toolsets") or []
|
|
defs = model_tools.get_tool_definitions(
|
|
enabled_toolsets=enabled,
|
|
disabled_toolsets=disabled,
|
|
quiet_mode=True,
|
|
)
|
|
names = sorted(
|
|
{(d.get("function") or {}).get("name") or d.get("name") for d in defs}
|
|
)
|
|
assert names == ["patch", "process", "read_file", "search_files",
|
|
"terminal", "write_file"]
|
|
|
|
|
|
class TestBlankSlateMinimizeConfig:
|
|
def test_optional_features_turned_off(self):
|
|
cfg = {}
|
|
_blank_slate_minimize_config(cfg)
|
|
assert cfg["compression"]["enabled"] is False
|
|
assert cfg["memory"]["memory_enabled"] is False
|
|
assert cfg["memory"]["user_profile_enabled"] is False
|
|
assert cfg["checkpoints"]["enabled"] is False
|
|
assert cfg["smart_model_routing"]["enabled"] is False
|
|
assert cfg["session_reset"]["mode"] == "none"
|
|
|
|
|
|
class TestBlankSlateFork:
|
|
"""The post-baseline fork: finish now vs walk through configurations."""
|
|
|
|
def _patch_common(self, monkeypatch):
|
|
import hermes_cli.setup as s
|
|
# Neutralize side-effecting setup steps and I/O.
|
|
monkeypatch.setattr(s, "setup_model_provider", lambda cfg, **k: None)
|
|
monkeypatch.setattr(s, "setup_terminal_backend", lambda cfg, **k: None)
|
|
monkeypatch.setattr(s, "save_config", lambda cfg: None)
|
|
monkeypatch.setattr(s, "_print_setup_summary", lambda cfg, home: None)
|
|
monkeypatch.setattr(s, "print_header", lambda *a, **k: None)
|
|
monkeypatch.setattr(s, "print_info", lambda *a, **k: None)
|
|
monkeypatch.setattr(s, "print_success", lambda *a, **k: None)
|
|
monkeypatch.setattr(s, "print_warning", lambda *a, **k: None)
|
|
|
|
def test_finish_now_skips_walkthrough(self, monkeypatch, tmp_path):
|
|
import hermes_cli.setup as s
|
|
self._patch_common(monkeypatch)
|
|
# Fork prompt returns 0 = finish now.
|
|
monkeypatch.setattr(s, "prompt_choice", lambda *a, **k: 0)
|
|
walked = {"called": False}
|
|
monkeypatch.setattr(s, "_blank_slate_walkthrough",
|
|
lambda cfg, home: walked.__setitem__("called", True))
|
|
opted_out = {"value": None}
|
|
monkeypatch.setattr("tools.skills_sync.set_bundled_skills_opt_out",
|
|
lambda enabled: opted_out.__setitem__("value", enabled))
|
|
|
|
cfg = {}
|
|
s._run_blank_slate_setup(cfg, tmp_path, is_existing=False)
|
|
|
|
# Minimal baseline was applied, walkthrough was NOT run.
|
|
assert cfg["platform_toolsets"]["cli"] == ["file", "terminal"]
|
|
assert walked["called"] is False
|
|
# Finish-now path records the skill opt-out (no bundled skills).
|
|
assert opted_out["value"] is True
|
|
|