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).
136 lines
4 KiB
Python
136 lines
4 KiB
Python
"""Tests for the structured logging dedup model.
|
|
|
|
The contract: a 1000-write session in one project should emit exactly
|
|
ONE INFO line ("active for <root>") at the default INFO threshold.
|
|
Steady-state events stay at DEBUG; first-time-seen events surface
|
|
once at INFO/WARNING.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
|
|
import pytest
|
|
|
|
from agent.lsp import eventlog
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _reset():
|
|
eventlog.reset_announce_caches()
|
|
yield
|
|
eventlog.reset_announce_caches()
|
|
|
|
|
|
@pytest.fixture
|
|
def caplog_lsp(caplog):
|
|
caplog.set_level(logging.DEBUG, logger="hermes.lint.lsp")
|
|
return caplog
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Steady-state silence (DEBUG)
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
def test_clean_emits_at_debug(caplog_lsp):
|
|
for _ in range(10):
|
|
eventlog.log_clean("pyright", "/proj/x.py")
|
|
info_records = [r for r in caplog_lsp.records if r.levelno >= logging.INFO]
|
|
debug_records = [r for r in caplog_lsp.records if r.levelno == logging.DEBUG]
|
|
assert info_records == []
|
|
assert len(debug_records) == 10
|
|
|
|
|
|
def test_disabled_emits_at_debug(caplog_lsp):
|
|
eventlog.log_disabled("pyright", "/x.py", "feature off")
|
|
eventlog.log_disabled("pyright", "/x.py", "ext not mapped")
|
|
assert all(r.levelno == logging.DEBUG for r in caplog_lsp.records)
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# State transitions: INFO once, DEBUG thereafter
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Diagnostics events fire INFO every time
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
def test_diagnostics_always_info(caplog_lsp):
|
|
for i in range(5):
|
|
eventlog.log_diagnostics("pyright", f"/x{i}.py", 1)
|
|
info = [r for r in caplog_lsp.records if r.levelno == logging.INFO]
|
|
assert len(info) == 5
|
|
assert all("diags" in r.getMessage() for r in info)
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Action-required: WARNING once, DEBUG thereafter (or per call for novel events)
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_spawn_failed_warns(caplog_lsp):
|
|
eventlog.log_spawn_failed("pyright", "/proj", FileNotFoundError("nope"))
|
|
warns = [r for r in caplog_lsp.records if r.levelno == logging.WARNING]
|
|
assert len(warns) == 1
|
|
assert "spawn/initialize failed" in warns[0].getMessage()
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Format: log lines all carry the lsp[<server_id>] prefix for grep
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Steady-state contract: 1000 clean writes → 1 INFO at most
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
def test_thousand_clean_writes_emit_one_info(caplog_lsp):
|
|
"""A long session writes lots of files cleanly; agent.log should
|
|
show ONE 'active for' INFO and zero other INFO lines."""
|
|
eventlog.log_active("pyright", "/proj")
|
|
for _ in range(1000):
|
|
eventlog.log_clean("pyright", "/proj/x.py")
|
|
info_records = [r for r in caplog_lsp.records if r.levelno == logging.INFO]
|
|
assert len(info_records) == 1
|
|
assert "active for" in info_records[0].getMessage()
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Path shortening
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
def test_short_path_keeps_absolute_when_outside(tmp_path, monkeypatch):
|
|
monkeypatch.chdir(tmp_path / "a") if (tmp_path / "a").exists() else None
|
|
monkeypatch.chdir(tmp_path)
|
|
other = "/var/log/foo.txt"
|
|
out = eventlog._short_path(other)
|
|
# Outside cwd: keeps absolute (no leading "../")
|
|
assert out == "/var/log/foo.txt" or not out.startswith("..")
|
|
|
|
|