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).
72 lines
2.3 KiB
Python
72 lines
2.3 KiB
Python
"""Tests for OpenViking memory-provider shutdown teardown.
|
|
|
|
The runtime-autostart waiter is a tracked ``daemon=True`` thread that blocks
|
|
on network health probes. If ``shutdown()`` doesn't join it (and the waiter
|
|
doesn't bail on the shutdown flag), it can be left alive at interpreter exit,
|
|
which crashes CPython with SIGABRT at ``Py_FinalizeEx``. These tests assert
|
|
the waiter short-circuits on shutdown and that ``shutdown()`` waits for the
|
|
runtime-start thread.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import threading
|
|
import time
|
|
from unittest.mock import patch
|
|
|
|
import plugins.memory.openviking as openviking_module
|
|
from plugins.memory.openviking import OpenVikingMemoryProvider
|
|
|
|
|
|
def test_wait_for_health_short_circuits_on_should_stop():
|
|
"""The health waiter returns False without probing when should_stop is set,
|
|
so the daemon thread running it can be join()ed promptly at shutdown."""
|
|
probes: list[str] = []
|
|
|
|
def _reach(endpoint):
|
|
probes.append(endpoint)
|
|
return (False, "down")
|
|
|
|
with patch.object(
|
|
openviking_module, "_validate_openviking_reachability", _reach
|
|
):
|
|
result = openviking_module._wait_for_openviking_health(
|
|
"http://example.invalid",
|
|
timeout_seconds=60.0,
|
|
should_stop=lambda: True,
|
|
)
|
|
|
|
assert result is False
|
|
assert probes == [] # bailed before the first network probe
|
|
|
|
|
|
def test_shutdown_waits_for_runtime_start_thread():
|
|
"""shutdown() must join the runtime-autostart waiter thread.
|
|
|
|
The fake waiter does post-stop work (a short sleep) once it observes the
|
|
shutdown flag. If shutdown() joins it, that work has completed by the time
|
|
shutdown() returns; without the join, shutdown() returns early and the
|
|
thread is still running (the SIGABRT-at-exit failure mode).
|
|
"""
|
|
provider = OpenVikingMemoryProvider()
|
|
started = threading.Event()
|
|
finished = threading.Event()
|
|
|
|
def _runtime():
|
|
started.set()
|
|
while not provider._shutting_down:
|
|
time.sleep(0.01)
|
|
time.sleep(0.2) # work that must finish during shutdown's join
|
|
finished.set()
|
|
|
|
t = threading.Thread(target=_runtime, daemon=True, name="openviking-runtime-start")
|
|
provider._runtime_start_thread = t
|
|
t.start()
|
|
assert started.wait(2.0)
|
|
|
|
provider.shutdown()
|
|
|
|
assert finished.is_set()
|
|
assert not t.is_alive()
|
|
|
|
|