mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-31 19:16:29 +00:00
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).
141 lines
5 KiB
Python
141 lines
5 KiB
Python
"""Setup surfaces ask only for what a platform can't start without.
|
|
|
|
The knobs in SETUP_HIDDEN_ENV_SUFFIXES are self-configuring (/sethome) or
|
|
already correct by default, so they don't belong on a setup form. They must
|
|
still be reachable everywhere else — this is a presentation change, not a
|
|
feature removal.
|
|
"""
|
|
|
|
import pytest
|
|
|
|
from hermes_cli.setup_hidden_env import is_setup_hidden_env
|
|
|
|
|
|
class TestIsSetupHiddenEnv:
|
|
@pytest.mark.parametrize(
|
|
"key",
|
|
[
|
|
"DISCORD_HOME_CHANNEL",
|
|
"DISCORD_HOME_CHANNEL_NAME",
|
|
"DISCORD_ALLOW_ALL_USERS",
|
|
"DISCORD_REPLY_TO_MODE",
|
|
"MATTERMOST_REPLY_MODE",
|
|
"TELEGRAM_PROXY",
|
|
],
|
|
)
|
|
def test_self_configuring_knobs_are_hidden(self, key):
|
|
assert is_setup_hidden_env(key)
|
|
|
|
|
|
def test_applies_to_plugin_platforms_nobody_enumerated(self):
|
|
"""Suffix matching is the point — IRC/SimpleX/ntfy get this for free."""
|
|
for key in (
|
|
"IRC_ALLOW_ALL_USERS",
|
|
"SIMPLEX_HOME_CHANNEL",
|
|
"NTFY_HOME_CHANNEL_NAME",
|
|
"LINE_ALLOW_ALL_USERS",
|
|
):
|
|
assert is_setup_hidden_env(key), key
|
|
|
|
|
|
class TestChannelCards:
|
|
def test_discord_card_asks_for_token_and_allowlist_only(self):
|
|
"""The reported bug: the Discord card asked five questions for a
|
|
one-credential platform."""
|
|
from hermes_cli.web_server import _build_catalog_entry
|
|
|
|
assert set(_build_catalog_entry("discord")["env_vars"]) == {
|
|
"DISCORD_BOT_TOKEN",
|
|
"DISCORD_ALLOWED_USERS",
|
|
}
|
|
|
|
def test_no_card_shows_a_hidden_knob(self):
|
|
from hermes_cli.web_server import _messaging_platform_catalog
|
|
|
|
for entry in _messaging_platform_catalog():
|
|
for key in entry["env_vars"]:
|
|
assert not is_setup_hidden_env(key), f"{entry['id']}: {key}"
|
|
|
|
|
|
def test_hidden_knobs_move_to_the_keys_page_not_into_a_void(self):
|
|
"""Keys hides what a Channels card owns. Dropping these from the card
|
|
must hand them back to Keys, not orphan them from every surface."""
|
|
from hermes_cli.web_server import _channel_managed_env_keys
|
|
|
|
managed = _channel_managed_env_keys()
|
|
for key in (
|
|
"DISCORD_HOME_CHANNEL",
|
|
"DISCORD_ALLOW_ALL_USERS",
|
|
"DISCORD_REPLY_TO_MODE",
|
|
):
|
|
assert key not in managed, f"{key} is hidden from both surfaces"
|
|
|
|
|
|
class TestCliWizard:
|
|
"""`hermes setup gateway` drops the same knobs. Real wizard, scripted
|
|
stdin, real .env writes under a temp HERMES_HOME."""
|
|
|
|
@pytest.fixture
|
|
def home(self, tmp_path, monkeypatch):
|
|
monkeypatch.setenv("HERMES_HOME", str(tmp_path))
|
|
return tmp_path
|
|
|
|
def _run(self, answers, monkeypatch):
|
|
import io
|
|
|
|
from hermes_cli import gateway as gw
|
|
|
|
platform = next(p for p in gw._PLATFORMS if p["key"] == "mattermost")
|
|
monkeypatch.setattr("sys.stdin", io.StringIO("\n".join(answers) + "\n"))
|
|
gw._setup_standard_platform(dict(platform))
|
|
|
|
def _env(self, home):
|
|
path = home / ".env"
|
|
if not path.exists():
|
|
return {}
|
|
out = {}
|
|
for line in path.read_text().splitlines():
|
|
line = line.strip()
|
|
if line and not line.startswith("#") and "=" in line:
|
|
k, v = line.split("=", 1)
|
|
out[k] = v
|
|
return out
|
|
|
|
def test_wizard_stops_asking_about_hidden_knobs(self, home, monkeypatch, capsys):
|
|
# Only the three real answers. If the wizard still prompted for the
|
|
# home channel it would read past them.
|
|
self._run(
|
|
["https://mm.example.com", "tok-abc", "user26charid"], monkeypatch
|
|
)
|
|
|
|
written = self._env(home)
|
|
assert written.get("MATTERMOST_URL") == "https://mm.example.com"
|
|
assert written.get("MATTERMOST_TOKEN") == "tok-abc"
|
|
assert "MATTERMOST_HOME_CHANNEL" not in written
|
|
assert "MATTERMOST_REPLY_MODE" not in written
|
|
|
|
out = capsys.readouterr().out
|
|
assert "Home channel" not in out
|
|
assert "Reply mode" not in out
|
|
|
|
def test_required_token_still_gates_setup(self, home, monkeypatch):
|
|
"""Proves the token wasn't swept out along with the knobs."""
|
|
self._run(["https://mm.example.com", ""], monkeypatch)
|
|
|
|
assert "MATTERMOST_TOKEN" not in self._env(home)
|
|
|
|
|
|
class TestStillConfigurable:
|
|
def test_gateway_still_honors_the_env_vars(self, tmp_path, monkeypatch):
|
|
"""Nothing was removed from the product — only from the setup form."""
|
|
monkeypatch.setenv("HERMES_HOME", str(tmp_path))
|
|
monkeypatch.setenv("DISCORD_BOT_TOKEN", "t")
|
|
monkeypatch.setenv("DISCORD_HOME_CHANNEL", "999")
|
|
monkeypatch.setenv("DISCORD_REPLY_TO_MODE", "off")
|
|
|
|
from gateway.config import Platform, load_gateway_config
|
|
|
|
discord = load_gateway_config().platforms[Platform.DISCORD]
|
|
assert discord.home_channel is not None
|
|
assert discord.home_channel.chat_id == "999"
|
|
assert discord.reply_to_mode == "off"
|