mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-30 19:09:28 +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).
87 lines
2.7 KiB
Python
87 lines
2.7 KiB
Python
from pathlib import Path
|
|
from unittest.mock import patch
|
|
|
|
from cli import (
|
|
HermesCLI,
|
|
_collect_query_images,
|
|
_format_image_attachment_badges,
|
|
_termux_example_image_path,
|
|
)
|
|
|
|
|
|
def _make_cli():
|
|
cli_obj = HermesCLI.__new__(HermesCLI)
|
|
cli_obj._attached_images = []
|
|
return cli_obj
|
|
|
|
|
|
def _make_image(path: Path) -> Path:
|
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
path.write_bytes(b"\x89PNG\r\n\x1a\n")
|
|
return path
|
|
|
|
|
|
class TestImageCommand:
|
|
def test_handle_image_command_attaches_local_image(self, tmp_path):
|
|
img = _make_image(tmp_path / "photo.png")
|
|
cli_obj = _make_cli()
|
|
|
|
with patch("cli._cprint"):
|
|
cli_obj._handle_image_command(f"/image {img}")
|
|
|
|
assert cli_obj._attached_images == [img]
|
|
|
|
|
|
def test_handle_image_command_rejects_non_image_file(self, tmp_path):
|
|
file_path = tmp_path / "notes.txt"
|
|
file_path.write_text("hello\n", encoding="utf-8")
|
|
cli_obj = _make_cli()
|
|
|
|
with patch("cli._cprint") as mock_print:
|
|
cli_obj._handle_image_command(f"/image {file_path}")
|
|
|
|
assert cli_obj._attached_images == []
|
|
rendered = " ".join(str(arg) for call in mock_print.call_args_list for arg in call.args)
|
|
assert "Not a supported image file" in rendered
|
|
|
|
|
|
class TestCollectQueryImages:
|
|
def test_collect_query_images_accepts_explicit_image_arg(self, tmp_path):
|
|
img = _make_image(tmp_path / "diagram.png")
|
|
|
|
message, images = _collect_query_images("describe this", str(img))
|
|
|
|
assert message == "describe this"
|
|
assert images == [img]
|
|
|
|
|
|
def test_collect_query_images_supports_tilde_paths(self, tmp_path, monkeypatch):
|
|
home = tmp_path / "home"
|
|
img = _make_image(home / "storage" / "shared" / "Pictures" / "cat.png")
|
|
monkeypatch.setenv("HOME", str(home))
|
|
|
|
message, images = _collect_query_images("describe this", "~/storage/shared/Pictures/cat.png")
|
|
|
|
assert message == "describe this"
|
|
assert images == [img]
|
|
|
|
|
|
class TestTermuxImageHints:
|
|
def test_termux_example_image_path_prefers_real_shared_storage_root(self, monkeypatch):
|
|
existing = {"/sdcard", "/storage/emulated/0"}
|
|
monkeypatch.setattr("cli.os.path.isdir", lambda path: path in existing)
|
|
|
|
hint = _termux_example_image_path()
|
|
|
|
assert hint == "/sdcard/Pictures/cat.png"
|
|
|
|
|
|
class TestImageBadgeFormatting:
|
|
def test_compact_badges_use_filename_on_narrow_terminals(self, tmp_path):
|
|
img = _make_image(tmp_path / "Screenshot 2026-04-09 at 11.22.33 AM.png")
|
|
|
|
badges = _format_image_attachment_badges([img], image_counter=1, width=40)
|
|
|
|
assert badges.startswith("[📎 ")
|
|
assert "Image #1" not in badges
|
|
|