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).
101 lines
3.1 KiB
Python
101 lines
3.1 KiB
Python
"""Tests for the ``lsp_diagnostics`` field on WriteResult / PatchResult.
|
|
|
|
The field exists so the agent can read syntax errors (``lint``) and
|
|
semantic errors (``lsp_diagnostics``) as separate signals rather than
|
|
having LSP output prepended to the lint string.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from unittest.mock import patch
|
|
|
|
|
|
from tools.environments.local import LocalEnvironment
|
|
from tools.file_operations import (
|
|
PatchResult,
|
|
ShellFileOperations,
|
|
WriteResult,
|
|
)
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Dataclass shape
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_patchresult_to_dict_omits_field_when_none():
|
|
r = PatchResult(success=True)
|
|
assert "lsp_diagnostics" not in r.to_dict()
|
|
|
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Channel separation: lint and lsp_diagnostics stay independent
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
def test_lint_and_lsp_diagnostics_are_separate_channels():
|
|
"""A WriteResult can carry BOTH a syntax-error lint AND an LSP
|
|
diagnostic block. They belong in separate fields."""
|
|
r = WriteResult(
|
|
bytes_written=42,
|
|
lint={"status": "error", "output": "SyntaxError: ..."},
|
|
lsp_diagnostics="<diagnostics>ERROR [1:5] type mismatch</diagnostics>",
|
|
)
|
|
d = r.to_dict()
|
|
assert "lint" in d
|
|
assert "lsp_diagnostics" in d
|
|
assert d["lint"]["output"] == "SyntaxError: ..."
|
|
assert "type mismatch" in d["lsp_diagnostics"]
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# write_file populates the field via _maybe_lsp_diagnostics
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_write_file_skips_lsp_when_syntax_failed(tmp_path):
|
|
"""If the syntax check finds errors, the LSP layer should not be
|
|
consulted (a file that won't parse won't yield meaningful semantic
|
|
diagnostics)."""
|
|
fops = ShellFileOperations(LocalEnvironment(cwd=str(tmp_path)))
|
|
target = tmp_path / "broken.py"
|
|
|
|
with patch.object(fops, "_maybe_lsp_diagnostics") as mock_lsp:
|
|
res = fops.write_file(str(target), "def x(:\n") # syntax error
|
|
assert mock_lsp.call_count == 0
|
|
assert res.lsp_diagnostics is None
|
|
assert res.lint["status"] == "error"
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# patch_replace propagates the field from the inner write_file
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
def test_patch_replace_propagates_lsp_diagnostics(tmp_path):
|
|
"""patch_replace's internal write_file populates lsp_diagnostics —
|
|
the outer PatchResult must carry it forward."""
|
|
fops = ShellFileOperations(LocalEnvironment(cwd=str(tmp_path)))
|
|
target = tmp_path / "x.py"
|
|
target.write_text("x = 1\n")
|
|
|
|
block = "<diagnostics>ERROR [1:5] semantic issue</diagnostics>"
|
|
|
|
with patch.object(fops, "_maybe_lsp_diagnostics", return_value=block):
|
|
res = fops.patch_replace(str(target), "x = 1", "x = 2")
|
|
|
|
assert res.success is True
|
|
assert res.lsp_diagnostics == block
|