6b81590c55
Systematic prune per AGENTS.md test policy, one pass over every major test tree (gateway, hermes_cli, tools, agent, run_agent, plugins, cli, cron, tui_gateway, honcho/openviking, root-level): - DELETE: source-reading tests (read_text/getsource on prod files), change-detector tests (exact catalog counts, model-name snapshots, config version literals), mock-echo tests (assert a mock returns what it was told), assertion-free/trivial tests, near-duplicate parametrizations (boundaries + one representative kept), async/sync twin duplicates, cosmetic within-file variations. - KEEP (mandatory): security/redaction/approval guards, message-role alternation invariants, prompt-caching/deterministic-call-id invariants, issue-number regression tests (deduped), E2E tests. - 6 test files deleted outright (script-style/no-assert or fully redundant); conftest.py, fakes/, fixtures/ untouched. - tests/acp/conftest.py added: autouse fixture stubs the live models.dev/GitHub/Copilot/Anthropic inventory fetches that ACP server tests performed on every session create — test_server.py 147s → 3.4s, and the tests are now genuinely hermetic. - Sleep-based slowness shrunk where safe (codex_ttfb_watchdog, compression_concurrent_fork, etc.); no wall-clock assertion tightened. Verification: full hermetic suite via scripts/run_tests.sh — 2439 files, 31,130 tests passed, 0 failed, 0 flaky retries, 315s wall (baseline: 583s wall, 13,564s subprocess CPU).
89 lines
3.8 KiB
Python
89 lines
3.8 KiB
Python
"""Tests for `hermes memory setup [provider]` routing.
|
|
|
|
The `memory setup` subcommand accepts an optional positional ``provider`` so a
|
|
fresh install can configure a specific provider directly (e.g.
|
|
``hermes memory setup honcho``) without the interactive picker — which matters
|
|
because the per-provider ``hermes <provider>`` subcommand is only registered
|
|
once that provider is active.
|
|
"""
|
|
|
|
from types import SimpleNamespace
|
|
from unittest.mock import patch
|
|
|
|
from hermes_cli import memory_setup
|
|
|
|
|
|
class TestMemorySetupProviderRouting:
|
|
def test_setup_with_provider_arg_skips_picker(self):
|
|
"""`memory setup honcho` routes straight to cmd_setup_provider."""
|
|
args = SimpleNamespace(memory_command="setup", provider="honcho")
|
|
with patch.object(memory_setup, "cmd_setup_provider") as direct, \
|
|
patch.object(memory_setup, "cmd_setup") as picker:
|
|
memory_setup.memory_command(args)
|
|
direct.assert_called_once_with("honcho")
|
|
picker.assert_not_called()
|
|
|
|
|
|
def test_unknown_provider_reports_and_returns_early(self, capsys):
|
|
"""An unknown provider name surfaces a helpful message and returns
|
|
before any config load/save (the not-found guard precedes those imports)."""
|
|
memory_setup.cmd_setup_provider("notaprovider")
|
|
out = capsys.readouterr().out
|
|
assert "not found" in out
|
|
assert "hermes memory setup" in out
|
|
|
|
|
|
class TestInstallDependenciesRunner:
|
|
"""`_install_dependencies` must route through the canonical
|
|
``_pip_install`` ladder (uv → pip → ensurepip): uv when present, standard
|
|
pip when uv is unavailable, and an ensurepip bootstrap for pip-less venvs
|
|
instead of dead-ending with "cannot install"."""
|
|
|
|
def _run_with_missing_dep(self, tmp_path, which_side_effect, run_behavior=None):
|
|
"""Drive _install_dependencies for a plugin that declares one missing
|
|
pip dep, capturing every subprocess.run argv issued by the ladder."""
|
|
import sys
|
|
|
|
(tmp_path / "plugin.yaml").write_text(
|
|
"pip_dependencies:\n - definitely-not-installed-xyz\n", encoding="utf-8"
|
|
)
|
|
calls = []
|
|
|
|
def fake_run(cmd, **kw):
|
|
calls.append(cmd)
|
|
if run_behavior:
|
|
return run_behavior(cmd)
|
|
return SimpleNamespace(returncode=0, stdout="", stderr="")
|
|
|
|
with patch("plugins.memory.find_provider_dir", return_value=tmp_path), \
|
|
patch("hermes_cli.tools_config.shutil.which", side_effect=which_side_effect), \
|
|
patch("hermes_cli.tools_config.subprocess.run", fake_run):
|
|
memory_setup._install_dependencies("x")
|
|
return calls, sys.executable
|
|
|
|
def test_uses_uv_when_available(self, tmp_path):
|
|
calls, _ = self._run_with_missing_dep(
|
|
tmp_path, lambda b: "/usr/bin/uv" if b == "uv" else None
|
|
)
|
|
assert calls
|
|
assert calls[0][:3] == ["/usr/bin/uv", "pip", "install"]
|
|
|
|
def test_falls_back_to_pip_when_uv_missing(self, tmp_path):
|
|
"""No uv but pip importable -> python -m pip install."""
|
|
calls, py = self._run_with_missing_dep(tmp_path, lambda b: None)
|
|
assert calls
|
|
# Ladder probes pip first, then installs with it.
|
|
assert calls[0][:3] == [py, "-m", "pip"]
|
|
assert calls[-1][:4] == [py, "-m", "pip", "install"]
|
|
|
|
def test_bootstraps_pip_via_ensurepip_when_missing(self, tmp_path):
|
|
"""Neither uv nor pip -> ensurepip bootstrap, then pip install."""
|
|
def behavior(cmd):
|
|
if cmd[-1] == "--version":
|
|
return SimpleNamespace(returncode=1, stdout="", stderr="")
|
|
return SimpleNamespace(returncode=0, stdout="", stderr="")
|
|
|
|
calls, py = self._run_with_missing_dep(tmp_path, lambda b: None, behavior)
|
|
assert any("ensurepip" in c for c in calls)
|
|
assert calls[-1][:4] == [py, "-m", "pip", "install"]
|