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).
80 lines
2.2 KiB
Python
80 lines
2.2 KiB
Python
"""End-to-end client tests against the in-process mock LSP server.
|
|
|
|
Spins up :file:`_mock_lsp_server.py` as an actual subprocess, drives
|
|
it through real LSP traffic, and asserts diagnostic flow. This is
|
|
the closest thing we have to integration coverage without requiring
|
|
pyright/gopls/etc. to be installed in CI.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import asyncio
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from agent.lsp.client import LSPClient
|
|
|
|
|
|
MOCK_SERVER = str(Path(__file__).parent / "_mock_lsp_server.py")
|
|
|
|
|
|
def _client(workspace: Path, script: str = "clean") -> LSPClient:
|
|
env = {"MOCK_LSP_SCRIPT": script, "PYTHONPATH": os.environ.get("PYTHONPATH", "")}
|
|
return LSPClient(
|
|
server_id=f"mock-{script}",
|
|
workspace_root=str(workspace),
|
|
command=[sys.executable, MOCK_SERVER],
|
|
env=env,
|
|
cwd=str(workspace),
|
|
)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_client_lifecycle_clean(tmp_path: Path):
|
|
"""Full lifecycle: spawn, initialize, open, get clean diagnostics, shutdown."""
|
|
f = tmp_path / "x.py"
|
|
f.write_text("print('hi')\n")
|
|
|
|
client = _client(tmp_path, "clean")
|
|
await client.start()
|
|
try:
|
|
assert client.is_running
|
|
version = await client.open_file(str(f), language_id="python")
|
|
assert version == 0
|
|
await client.wait_for_diagnostics(str(f), version, mode="document")
|
|
diags = client.diagnostics_for(str(f))
|
|
assert diags == []
|
|
finally:
|
|
await client.shutdown()
|
|
assert not client.is_running
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_client_receives_published_errors(tmp_path: Path):
|
|
f = tmp_path / "x.py"
|
|
f.write_text("print('hi')\n")
|
|
|
|
client = _client(tmp_path, "errors")
|
|
await client.start()
|
|
try:
|
|
version = await client.open_file(str(f), language_id="python")
|
|
await client.wait_for_diagnostics(str(f), version, mode="document")
|
|
diags = client.diagnostics_for(str(f))
|
|
assert len(diags) == 1
|
|
d = diags[0]
|
|
assert d["severity"] == 1
|
|
assert d["code"] == "MOCK001"
|
|
assert d["source"] == "mock-lsp"
|
|
assert "synthetic error" in d["message"]
|
|
finally:
|
|
await client.shutdown()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|