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).
88 lines
2.5 KiB
Python
88 lines
2.5 KiB
Python
"""Tests for tui_gateway.loop_noise — the WS peer-hangup teardown filter (#50005)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import asyncio
|
|
|
|
import pytest
|
|
|
|
from tui_gateway.loop_noise import (
|
|
_is_benign_teardown,
|
|
install_loop_noise_filter,
|
|
)
|
|
|
|
|
|
class _FakeConnectionLostCallback:
|
|
"""Stand-in whose repr matches asyncio's ``_call_connection_lost`` flood."""
|
|
|
|
def __repr__(self) -> str:
|
|
return "<Handle _ProactorBasePipeTransport._call_connection_lost(None)>"
|
|
|
|
|
|
def test_benign_teardown_matches_reset_in_connection_lost():
|
|
ctx = {
|
|
"exception": ConnectionResetError(10054, "forcibly closed"),
|
|
"handle": _FakeConnectionLostCallback(),
|
|
}
|
|
assert _is_benign_teardown(ctx) is True
|
|
|
|
|
|
def test_benign_teardown_matches_aborted_and_broken_pipe():
|
|
for exc in (
|
|
ConnectionAbortedError(10053, "aborted"),
|
|
BrokenPipeError("epipe"),
|
|
):
|
|
ctx = {"exception": exc, "callback": _FakeConnectionLostCallback()}
|
|
assert _is_benign_teardown(ctx) is True
|
|
|
|
|
|
def test_reset_outside_connection_lost_is_not_suppressed():
|
|
# Same error type, but NOT from the connection-lost teardown path — must
|
|
# fall through to the default handler.
|
|
ctx = {
|
|
"exception": ConnectionResetError("reset in a real handler"),
|
|
"handle": "<Handle some_other_handler()>",
|
|
}
|
|
assert _is_benign_teardown(ctx) is False
|
|
|
|
|
|
def test_unrelated_exception_is_not_suppressed():
|
|
ctx = {
|
|
"exception": ValueError("boom"),
|
|
"handle": _FakeConnectionLostCallback(),
|
|
}
|
|
assert _is_benign_teardown(ctx) is False
|
|
|
|
|
|
def test_no_exception_is_not_suppressed():
|
|
assert _is_benign_teardown({"message": "loop warning, no exc"}) is False
|
|
|
|
|
|
def test_install_suppresses_flood_and_forwards_real_errors():
|
|
loop = asyncio.new_event_loop()
|
|
try:
|
|
forwarded: list[dict] = []
|
|
loop.set_exception_handler(lambda _loop, ctx: forwarded.append(ctx))
|
|
|
|
install_loop_noise_filter(loop)
|
|
|
|
# Benign teardown flood → swallowed, not forwarded.
|
|
loop.call_exception_handler(
|
|
{
|
|
"exception": ConnectionResetError(10054, "forcibly closed"),
|
|
"handle": _FakeConnectionLostCallback(),
|
|
}
|
|
)
|
|
assert forwarded == []
|
|
|
|
# Genuine loop error → forwarded to the previous handler unchanged.
|
|
real_ctx = {"exception": RuntimeError("genuine loop bug")}
|
|
loop.call_exception_handler(real_ctx)
|
|
assert len(forwarded) == 1
|
|
assert forwarded[0] is real_ctx
|
|
finally:
|
|
loop.close()
|
|
|
|
|
|
|
|
|