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).
63 lines
2.3 KiB
Python
63 lines
2.3 KiB
Python
"""Tests for gateway code-skew detection (stale-checkout guard).
|
|
|
|
Companion to ``tests/test_stale_utils_module_import.py``: that test proves the
|
|
crash; these prove the guard that turns it into a clear "restart the gateway"
|
|
message before a model switch can hit it.
|
|
"""
|
|
|
|
import pytest
|
|
|
|
from gateway import code_skew
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _reset_boot_fingerprint(monkeypatch):
|
|
"""Each test starts with no recorded boot fingerprint."""
|
|
monkeypatch.setattr(code_skew, "_boot_fingerprint", None)
|
|
|
|
|
|
class TestDetectCodeSkew:
|
|
def test_no_boot_fingerprint_means_no_skew(self, monkeypatch):
|
|
# Nothing recorded (e.g. non-git install) -> never a false positive.
|
|
monkeypatch.setattr(code_skew, "_fingerprint", lambda: "git:refs/heads/main:def456")
|
|
assert code_skew.detect_code_skew() is None
|
|
|
|
|
|
def test_drift_is_detected_with_short_revs(self, monkeypatch):
|
|
monkeypatch.setattr(code_skew, "_fingerprint", lambda: "git:refs/heads/main:abc1234567890")
|
|
code_skew.record_boot_fingerprint()
|
|
|
|
monkeypatch.setattr(code_skew, "_fingerprint", lambda: "git:refs/heads/main:def4567890123")
|
|
skew = code_skew.detect_code_skew()
|
|
assert skew == ("abc1234567", "def4567890")
|
|
|
|
|
|
|
|
|
|
class TestShort:
|
|
def test_shortens_long_sha(self):
|
|
assert code_skew._short("git:refs/heads/main:abcdef0123456789") == "abcdef0123"
|
|
|
|
def test_keeps_unresolved_marker(self):
|
|
assert code_skew._short("git:refs/heads/main:unresolved") == "unresolved"
|
|
|
|
def test_passes_short_sha_through_untruncated(self):
|
|
assert code_skew._short("git:HEAD:abc1234") == "abc1234"
|
|
|
|
|
|
class TestModelSwitchSkewGuard:
|
|
def test_guard_returns_none_without_skew(self, monkeypatch):
|
|
from gateway import slash_commands
|
|
|
|
monkeypatch.setattr(code_skew, "detect_code_skew", lambda: None)
|
|
assert slash_commands._model_switch_skew_guard() is None
|
|
|
|
def test_guard_message_names_revs_and_restart(self, monkeypatch):
|
|
from gateway import slash_commands
|
|
|
|
monkeypatch.setattr(code_skew, "detect_code_skew", lambda: ("abc1234567", "def4567890"))
|
|
msg = slash_commands._model_switch_skew_guard()
|
|
assert msg is not None
|
|
assert "abc1234567" in msg
|
|
assert "def4567890" in msg
|
|
assert "hermes gateway restart" in msg
|