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).
120 lines
4 KiB
Python
120 lines
4 KiB
Python
"""Tests for cronjob no_agent mode — script-driven jobs that skip the LLM.
|
|
|
|
Covers:
|
|
|
|
* ``create_job(no_agent=True)`` shape, validation, and serialization.
|
|
* ``cronjob(action='create', no_agent=True)`` tool-level validation.
|
|
* ``cronjob(action='update')`` flipping no_agent on/off.
|
|
* ``scheduler.run_job`` short-circuit path: success/silent/failure.
|
|
* Shell script support in ``_run_job_script`` (.sh runs via bash).
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
from unittest.mock import patch
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.fixture
|
|
def hermes_env(tmp_path, monkeypatch):
|
|
"""Isolate HERMES_HOME for each test so jobs/scripts don't leak."""
|
|
home = tmp_path / ".hermes"
|
|
home.mkdir()
|
|
(home / "scripts").mkdir()
|
|
(home / "cron").mkdir()
|
|
|
|
monkeypatch.setenv("HERMES_HOME", str(home))
|
|
|
|
# Reload modules that cache get_hermes_home() at import time.
|
|
import importlib
|
|
import hermes_constants
|
|
importlib.reload(hermes_constants)
|
|
import cron.jobs
|
|
importlib.reload(cron.jobs)
|
|
import cron.scheduler
|
|
importlib.reload(cron.scheduler)
|
|
|
|
return home
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# create_job / update_job: data-layer semantics
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
def test_create_job_no_agent_requires_script(hermes_env):
|
|
from cron.jobs import create_job
|
|
|
|
with pytest.raises(ValueError, match="no_agent=True requires a script"):
|
|
create_job(prompt=None, schedule="every 5m", no_agent=True)
|
|
|
|
|
|
def test_update_job_roundtrips_no_agent_flag(hermes_env):
|
|
from cron.jobs import create_job, update_job, get_job
|
|
|
|
script_path = hermes_env / "scripts" / "w.sh"
|
|
script_path.write_text("echo hi\n")
|
|
job = create_job(prompt=None, schedule="every 5m", script="w.sh", no_agent=True, deliver="local")
|
|
|
|
update_job(job["id"], {"no_agent": False})
|
|
reloaded = get_job(job["id"])
|
|
assert reloaded["no_agent"] is False
|
|
|
|
update_job(job["id"], {"no_agent": True})
|
|
reloaded = get_job(job["id"])
|
|
assert reloaded["no_agent"] is True
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# cronjob tool: API-layer validation
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
def test_cronjob_tool_create_no_agent_without_script_errors(hermes_env):
|
|
from tools.cronjob_tools import cronjob
|
|
|
|
result = json.loads(
|
|
cronjob(action="create", schedule="every 5m", no_agent=True, deliver="local")
|
|
)
|
|
assert result.get("success") is False
|
|
assert "no_agent=True requires a script" in result.get("error", "")
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# scheduler.run_job: short-circuit behavior
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
def test_run_job_no_agent_success_returns_script_stdout(hermes_env):
|
|
"""Happy path: script exits 0 with output, delivered verbatim."""
|
|
from cron.jobs import create_job
|
|
from cron.scheduler import run_job
|
|
|
|
script_path = hermes_env / "scripts" / "alert.sh"
|
|
script_path.write_text("#!/bin/bash\necho 'RAM 92% on host'\n")
|
|
|
|
job = create_job(
|
|
prompt=None, schedule="every 5m", script="alert.sh", no_agent=True, deliver="local"
|
|
)
|
|
success, doc, final_response, error = run_job(job)
|
|
assert success is True
|
|
assert error is None
|
|
assert "RAM 92% on host" in final_response
|
|
assert "RAM 92% on host" in doc
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# _run_job_script: shell-script support
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
def test_run_job_script_path_traversal_still_blocked(hermes_env):
|
|
"""Security regression: shell-script support must NOT loosen containment."""
|
|
from cron.scheduler import _run_job_script
|
|
|
|
# Absolute path outside the scripts dir should be rejected.
|
|
ok, output = _run_job_script("/etc/passwd")
|
|
assert ok is False
|
|
assert "Blocked" in output or "outside" in output
|