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).
71 lines
2.4 KiB
Python
71 lines
2.4 KiB
Python
"""Tests for cgroup-aware TUI V8 heap sizing.
|
|
|
|
V8 is not cgroup-aware: a flat ``--max-old-space-size=8192`` lets the heap grow
|
|
toward 8GB in a memory-limited container, so the cgroup OOM-killer SIGKILLs Node
|
|
before V8's own monitor fires — leaving the user with only a bare gateway
|
|
``stdin EOF`` and no breadcrumb. ``_resolve_tui_heap_mb`` reads the real cgroup
|
|
limit and sizes the cap below it so V8 exits gracefully instead.
|
|
"""
|
|
|
|
import builtins
|
|
import io
|
|
from unittest import mock
|
|
|
|
import hermes_cli.main as m
|
|
|
|
V2 = "/sys/fs/cgroup/memory.max"
|
|
V1 = "/sys/fs/cgroup/memory/memory.limit_in_bytes"
|
|
GB = 1024 ** 3
|
|
|
|
|
|
def _fake_open(files: dict):
|
|
"""Return an open() shim serving cgroup paths from ``files`` (path->str)."""
|
|
real_open = builtins.open
|
|
|
|
def opener(path, *args, **kwargs):
|
|
if path in (V2, V1):
|
|
content = files.get(path)
|
|
if content is None:
|
|
raise FileNotFoundError(path)
|
|
return io.StringIO(content)
|
|
return real_open(path, *args, **kwargs)
|
|
|
|
return opener
|
|
|
|
|
|
def _read(files: dict):
|
|
with mock.patch.object(builtins, "open", _fake_open(files)):
|
|
return m._read_cgroup_memory_limit()
|
|
|
|
|
|
class TestReadCgroupMemoryLimit:
|
|
def test_v2_max_is_unlimited(self):
|
|
assert _read({V2: "max"}) is None
|
|
|
|
|
|
class TestResolveTuiHeapMb:
|
|
def _resolve(self, limit_bytes):
|
|
with mock.patch.object(m, "_read_cgroup_memory_limit", return_value=limit_bytes):
|
|
return m._resolve_tui_heap_mb()
|
|
|
|
def test_unconstrained_uses_default(self):
|
|
assert self._resolve(None) == 8192
|
|
|
|
|
|
class TestNodeOptionsTokenMerge:
|
|
"""The _launch_tui token-merge block must add the sized cap unless the user
|
|
already supplied one, and must preserve unrelated NODE_OPTIONS flags."""
|
|
|
|
def _merge(self, node_options, limit_bytes):
|
|
with mock.patch.object(m, "_read_cgroup_memory_limit", return_value=limit_bytes):
|
|
tokens = node_options.split()
|
|
if not any(t.startswith("--max-old-space-size=") for t in tokens):
|
|
tokens.append(f"--max-old-space-size={m._resolve_tui_heap_mb()}")
|
|
return " ".join(tokens)
|
|
|
|
def test_unconstrained_empty(self):
|
|
assert self._merge("", None) == "--max-old-space-size=8192"
|
|
|
|
|
|
def test_preserves_other_flags(self):
|
|
assert self._merge("--enable-source-maps", 4 * GB) == "--enable-source-maps --max-old-space-size=3072"
|