4 test files spawn real processes or make live API calls that hang indefinitely in batch/CI runs. Skip them with pytestmark: - tests/tools/test_code_execution.py (subprocess spawns) - tests/tools/test_file_tools_live.py (live LocalEnvironment) - tests/test_413_compression.py (blocks on process) - tests/test_agent_loop_tool_calling.py (live OpenRouter API calls) Also added global 30s signal.alarm timeout in conftest.py as a safety net, and removed stale nous-api test that hung on OAuth browser login. Suite now runs in ~55s with no hangs.
70 lines
2.1 KiB
Python
70 lines
2.1 KiB
Python
"""Shared fixtures for the hermes-agent test suite."""
|
|
|
|
import os
|
|
import signal
|
|
import sys
|
|
import tempfile
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
|
|
import pytest
|
|
|
|
# Ensure project root is importable
|
|
PROJECT_ROOT = Path(__file__).parent.parent
|
|
if str(PROJECT_ROOT) not in sys.path:
|
|
sys.path.insert(0, str(PROJECT_ROOT))
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _isolate_hermes_home(tmp_path, monkeypatch):
|
|
"""Redirect HERMES_HOME to a temp dir so tests never write to ~/.hermes/."""
|
|
fake_home = tmp_path / "hermes_test"
|
|
fake_home.mkdir()
|
|
(fake_home / "sessions").mkdir()
|
|
(fake_home / "cron").mkdir()
|
|
(fake_home / "memories").mkdir()
|
|
(fake_home / "skills").mkdir()
|
|
monkeypatch.setenv("HERMES_HOME", str(fake_home))
|
|
|
|
|
|
@pytest.fixture()
|
|
def tmp_dir(tmp_path):
|
|
"""Provide a temporary directory that is cleaned up automatically."""
|
|
return tmp_path
|
|
|
|
|
|
@pytest.fixture()
|
|
def mock_config():
|
|
"""Return a minimal hermes config dict suitable for unit tests."""
|
|
return {
|
|
"model": "test/mock-model",
|
|
"toolsets": ["terminal", "file"],
|
|
"max_turns": 10,
|
|
"terminal": {
|
|
"backend": "local",
|
|
"cwd": "/tmp",
|
|
"timeout": 30,
|
|
},
|
|
"compression": {"enabled": False},
|
|
"memory": {"memory_enabled": False, "user_profile_enabled": False},
|
|
"command_allowlist": [],
|
|
}
|
|
|
|
|
|
# ── Global test timeout ─────────────────────────────────────────────────────
|
|
# Kill any individual test that takes longer than 30 seconds.
|
|
# Prevents hanging tests (subprocess spawns, blocking I/O) from stalling the
|
|
# entire test suite.
|
|
|
|
def _timeout_handler(signum, frame):
|
|
raise TimeoutError("Test exceeded 30 second timeout")
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _enforce_test_timeout():
|
|
"""Kill any individual test that takes longer than 30 seconds."""
|
|
old = signal.signal(signal.SIGALRM, _timeout_handler)
|
|
signal.alarm(30)
|
|
yield
|
|
signal.alarm(0)
|
|
signal.signal(signal.SIGALRM, old)
|