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.
131 lines
4.8 KiB
Python
131 lines
4.8 KiB
Python
"""Regression tests for dashboard profile-scoped skills/toolsets management.
|
|
|
|
"Set as active" on the Profiles page only flips the sticky ``active_profile``
|
|
file (future CLI/gateway runs) — it never retargets the running dashboard
|
|
process. Before the ``profile`` parameter existed, toggling a skill after
|
|
"activating" a profile silently wrote into the dashboard's own config.
|
|
These tests pin the new behavior: reads and writes land in the REQUESTED
|
|
profile's HERMES_HOME, and the dashboard's own profile stays untouched.
|
|
"""
|
|
import pytest
|
|
import yaml
|
|
|
|
|
|
def _write_skill(skills_dir, name, description="test skill"):
|
|
d = skills_dir / name
|
|
d.mkdir(parents=True, exist_ok=True)
|
|
(d / "SKILL.md").write_text(
|
|
f"---\nname: {name}\ndescription: {description}\n---\n\n# {name}\n",
|
|
encoding="utf-8",
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def isolated_profiles(tmp_path, monkeypatch, _isolate_hermes_home):
|
|
"""Isolated default home + one named profile, each with its own skills."""
|
|
from hermes_constants import get_hermes_home
|
|
from hermes_cli import profiles
|
|
|
|
default_home = get_hermes_home()
|
|
profiles_root = default_home / "profiles"
|
|
worker_home = profiles_root / "worker_alpha"
|
|
for home in (default_home, worker_home):
|
|
(home / "skills").mkdir(parents=True, exist_ok=True)
|
|
(home / "config.yaml").write_text("{}\n", encoding="utf-8")
|
|
|
|
_write_skill(default_home / "skills", "dashboard-skill")
|
|
_write_skill(worker_home / "skills", "worker-skill")
|
|
|
|
monkeypatch.setattr(profiles, "_get_default_hermes_home", lambda: default_home)
|
|
monkeypatch.setattr(profiles, "_get_profiles_root", lambda: profiles_root)
|
|
return {"default": default_home, "worker_alpha": worker_home}
|
|
|
|
|
|
@pytest.fixture
|
|
def client(monkeypatch, isolated_profiles):
|
|
try:
|
|
from starlette.testclient import TestClient
|
|
except ImportError:
|
|
pytest.skip("fastapi/starlette not installed")
|
|
|
|
import hermes_state
|
|
from hermes_constants import get_hermes_home
|
|
from hermes_cli.web_server import app, _SESSION_HEADER_NAME, _SESSION_TOKEN
|
|
|
|
monkeypatch.setattr(hermes_state, "DEFAULT_DB_PATH", get_hermes_home() / "state.db")
|
|
c = TestClient(app)
|
|
c.headers[_SESSION_HEADER_NAME] = _SESSION_TOKEN
|
|
return c
|
|
|
|
|
|
def _load_cfg(home):
|
|
return yaml.safe_load((home / "config.yaml").read_text()) or {}
|
|
|
|
|
|
class TestProfileScopedSkills:
|
|
|
|
|
|
def test_toggle_writes_into_target_profile_only(self, client, isolated_profiles):
|
|
resp = client.put(
|
|
"/api/skills/toggle",
|
|
json={"name": "worker-skill", "enabled": False, "profile": "worker_alpha"},
|
|
)
|
|
assert resp.status_code == 200
|
|
assert resp.json() == {"ok": True, "name": "worker-skill", "enabled": False}
|
|
|
|
worker_cfg = _load_cfg(isolated_profiles["worker_alpha"])
|
|
assert "worker-skill" in worker_cfg.get("skills", {}).get("disabled", [])
|
|
# The dashboard's own config must stay untouched — this was the bug.
|
|
default_cfg = _load_cfg(isolated_profiles["default"])
|
|
assert "worker-skill" not in default_cfg.get("skills", {}).get("disabled", [])
|
|
|
|
|
|
|
|
def test_scope_restores_module_globals(self, client, isolated_profiles):
|
|
"""The SKILLS_DIR swap is per-request; the module global must be
|
|
restored even after a scoped call (cron-style locked swap)."""
|
|
import tools.skills_tool as skills_tool
|
|
|
|
before = skills_tool.SKILLS_DIR
|
|
client.get("/api/skills", params={"profile": "worker_alpha"})
|
|
assert skills_tool.SKILLS_DIR == before
|
|
|
|
|
|
class TestProfileScopedHubActions:
|
|
def test_hub_install_spawns_with_profile_flag(
|
|
self, client, isolated_profiles, monkeypatch
|
|
):
|
|
"""Hub installs must go through a fresh ``hermes -p <profile>``
|
|
subprocess — the in-process scope can't reach skills_hub's
|
|
import-time SKILLS_DIR binding."""
|
|
import hermes_cli.web_server as web_server
|
|
|
|
calls = []
|
|
|
|
class _FakeProc:
|
|
pid = 4242
|
|
|
|
def _fake_spawn(subcommand, name):
|
|
calls.append((list(subcommand), name))
|
|
return _FakeProc()
|
|
|
|
monkeypatch.setattr(web_server, "_spawn_hermes_action", _fake_spawn)
|
|
resp = client.post(
|
|
"/api/skills/hub/install",
|
|
json={"identifier": "official/demo", "profile": "worker_alpha"},
|
|
)
|
|
assert resp.status_code == 200
|
|
assert calls == [
|
|
(
|
|
["-p", "worker_alpha", "skills", "install", "official/demo", "--yes"],
|
|
web_server._hub_action_name("install", "official/demo"),
|
|
)
|
|
]
|
|
|
|
|
|
def test_hub_install_unknown_profile_404(self, client, isolated_profiles):
|
|
resp = client.post(
|
|
"/api/skills/hub/install",
|
|
json={"identifier": "official/demo", "profile": "ghost"},
|
|
)
|
|
assert resp.status_code == 404
|