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).
75 lines
2.7 KiB
Python
75 lines
2.7 KiB
Python
"""Tests for hermes_cli.dump._get_git_commit — git SHA resolution for ``hermes dump``.
|
|
|
|
``hermes dump`` prints the running commit so support bug reports identify the
|
|
exact version. Source installs resolve it live via ``git rev-parse``; the
|
|
published Docker image excludes ``.git`` and falls back to the baked SHA
|
|
written by the Dockerfile's ``HERMES_GIT_SHA`` build-arg.
|
|
|
|
These tests cover both paths plus the failure modes (no git, no baked file).
|
|
"""
|
|
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
|
|
def test_get_git_commit_uses_live_git_when_available(tmp_path):
|
|
"""Source install: ``git rev-parse --short=8 HEAD`` wins; no fallback."""
|
|
from hermes_cli import dump
|
|
|
|
repo_dir = tmp_path / "repo"
|
|
repo_dir.mkdir()
|
|
|
|
git_result = MagicMock(returncode=0, stdout="deadbeef\n")
|
|
# build_info should NOT be consulted when live git succeeds.
|
|
with patch("hermes_cli.dump.subprocess.run", return_value=git_result) as mock_run, \
|
|
patch("hermes_cli.build_info.get_build_sha") as mock_build:
|
|
commit = dump._get_git_commit(repo_dir)
|
|
|
|
assert commit == "deadbeef"
|
|
mock_run.assert_called_once()
|
|
mock_build.assert_not_called()
|
|
|
|
|
|
def test_get_git_commit_output_format_identical_between_sources(tmp_path):
|
|
"""Regression guard: live-git and baked-SHA outputs share the same shape.
|
|
|
|
Ben explicitly asked for identical output between Docker and source installs
|
|
so support tooling that parses ``hermes dump`` doesn't have to special-case
|
|
container builds. Both paths must return a bare 8-char SHA — no prefix,
|
|
no suffix, no annotation.
|
|
"""
|
|
from hermes_cli import dump
|
|
|
|
repo_dir = tmp_path / "repo"
|
|
repo_dir.mkdir()
|
|
|
|
# Live-git path.
|
|
git_result = MagicMock(returncode=0, stdout="b2f477a3\n")
|
|
with patch("hermes_cli.dump.subprocess.run", return_value=git_result):
|
|
live = dump._get_git_commit(repo_dir)
|
|
|
|
# Baked-SHA path.
|
|
failed = MagicMock(returncode=128, stdout="")
|
|
with patch("hermes_cli.dump.subprocess.run", return_value=failed), \
|
|
patch("hermes_cli.build_info.get_build_sha", return_value="b2f477a3"):
|
|
baked = dump._get_git_commit(repo_dir)
|
|
|
|
assert live == baked == "b2f477a3"
|
|
# Same length, same charset — no decoration in either branch.
|
|
assert len(live) == 8
|
|
assert all(c in "0123456789abcdef" for c in live)
|
|
|
|
|
|
def test_get_git_commit_date_empty_when_git_fails(tmp_path):
|
|
"""Docker image / pip wheel: no git → '' so the dump line drops the date."""
|
|
from hermes_cli import dump
|
|
|
|
repo_dir = tmp_path / "no-git-here"
|
|
repo_dir.mkdir()
|
|
|
|
failed = MagicMock(returncode=128, stdout="")
|
|
with patch("hermes_cli.dump.subprocess.run", return_value=failed):
|
|
date = dump._get_git_commit_date(repo_dir)
|
|
|
|
assert date == ""
|
|
|
|
|