d10bb2ab6f
`scripts/run_tests.sh tests/<dir>/` is how a change gets its regression
coverage run, so a test filed under the wrong directory is a test nobody
runs when that code changes. Two kinds of drift had accumulated.
Parallel directories for one source package, folded into the mirror:
tests/acp -> tests/acp_adapter (its __init__/conftest move with it)
tests/cli -> tests/hermes_cli (prompt_toolkit fixture merged into
hermes_cli/conftest.py)
tests/run_agent -> tests/agent (backoff fixture becomes
agent/conftest.py)
tests/relay -> tests/gateway/relay
tests/state -> tests/hermes_state
246 loose files at tests/ root, routed by the package they import/patch:
hermes_cli, hermes_state, agent, gateway, tools, plugins, tui_gateway, cron.
Installer and desktop-update script tests go to tests/scripts/{install,
desktop_update}/. 43 tests of root-level modules (batch_runner, utils,
hermes_constants, packaging) stay at the root.
Filenames drop their issue numbers (95 files: test_89315_x.py -> test_x.py);
the number stays in the module docstring where it has context.
Collisions: test_cli_skin_integration.py existed in both tests/ and tests/cli
with different subsets — merged into one (10 tests, all kept);
run_agent/test_pre_compress_memory_context.py -> agent/..._handoff.py;
tests/test_account_usage.py -> agent/test_account_usage_fetch.py;
tests/test_web_server.py -> hermes_cli/test_web_server_ws_ping.py.
Deleted: test_minisweagent_path.py (empty since PR #2804),
test_model_picker_scroll.py (tested a private copy of the logic, imported
nothing), test_process_loop_event_loop_warning.py (asserted asyncio behaviour,
imported nothing from Hermes).
Repo-root path arithmetic (Path(__file__).parents[N], dirname chains) is
bumped for the 202 files that changed depth and verified by evaluating every
such expression against the new location. classify_changes' desktop-updater
lane prefix, tests-os.yml's ignore glob and every in-tree path comment follow
the moves. tests/test_tests_tree_layout.py keeps the tree from drifting back.
123 lines
4.1 KiB
Python
123 lines
4.1 KiB
Python
from pathlib import Path
|
|
from unittest.mock import MagicMock
|
|
|
|
|
|
def test_default_config_exposes_vacuum_interval():
|
|
from hermes_cli.config import DEFAULT_CONFIG
|
|
|
|
assert DEFAULT_CONFIG["sessions"]["min_vacuum_interval_days"] == 30
|
|
|
|
|
|
def test_default_config_auto_prune_on_with_90_day_retention():
|
|
"""#54189: state.db retention is ON by default (ended sessions, 90 days)."""
|
|
from hermes_cli.config import DEFAULT_CONFIG
|
|
|
|
sessions = DEFAULT_CONFIG["sessions"]
|
|
assert sessions["auto_prune"] is True
|
|
assert sessions["retention_days"] == 90
|
|
assert sessions["vacuum_after_prune"] is True
|
|
|
|
|
|
def test_fresh_config_runs_auto_prune_at_startup(monkeypatch, tmp_path: Path):
|
|
"""A config.yaml with NO ``sessions:`` keys must reach the prune call with the
|
|
new defaults (the loader deep-merges DEFAULT_CONFIG)."""
|
|
import cli
|
|
import hermes_cli.config
|
|
import hermes_constants
|
|
from hermes_cli.config import DEFAULT_CONFIG
|
|
|
|
session_db = MagicMock()
|
|
session_db.get_meta.return_value = "already-done"
|
|
# Simulate load_config() on a fresh home: only defaults for the section.
|
|
monkeypatch.setattr(
|
|
hermes_cli.config,
|
|
"load_config",
|
|
lambda: {"sessions": dict(DEFAULT_CONFIG["sessions"])},
|
|
)
|
|
monkeypatch.setattr(hermes_constants, "get_hermes_home", lambda: tmp_path)
|
|
|
|
cli._run_state_db_auto_maintenance(session_db)
|
|
|
|
session_db.maybe_auto_prune_and_vacuum.assert_called_once_with(
|
|
retention_days=90,
|
|
min_interval_hours=24,
|
|
min_vacuum_interval_days=30,
|
|
vacuum=True,
|
|
sessions_dir=tmp_path / "sessions",
|
|
)
|
|
|
|
|
|
def test_explicit_auto_prune_false_is_respected(monkeypatch, tmp_path: Path):
|
|
"""Migration guard: an install that explicitly opted out keeps its choice."""
|
|
import cli
|
|
import hermes_cli.config
|
|
import hermes_constants
|
|
|
|
session_db = MagicMock()
|
|
session_db.get_meta.return_value = "already-done"
|
|
monkeypatch.setattr(
|
|
hermes_cli.config,
|
|
"load_config",
|
|
lambda: {"sessions": {"auto_prune": False, "retention_days": 90}},
|
|
)
|
|
monkeypatch.setattr(hermes_constants, "get_hermes_home", lambda: tmp_path)
|
|
|
|
cli._run_state_db_auto_maintenance(session_db)
|
|
|
|
session_db.maybe_auto_prune_and_vacuum.assert_not_called()
|
|
|
|
|
|
def test_shipped_template_does_not_pin_sessions_keys():
|
|
"""Installers copy cli-config.yaml.example verbatim into config.yaml, so any
|
|
uncommented ``sessions:`` value there becomes an EXPLICIT user setting that
|
|
would freeze the retention defaults. The template must leave them commented
|
|
so code defaults (and future flips) apply."""
|
|
import yaml
|
|
|
|
template = Path(__file__).resolve().parents[2] / "cli-config.yaml.example"
|
|
data = yaml.safe_load(template.read_text(encoding="utf-8")) or {}
|
|
assert "sessions" not in data
|
|
|
|
|
|
def test_loader_yields_new_defaults_for_fresh_home(monkeypatch, tmp_path: Path):
|
|
"""Real load_config() against an empty HERMES_HOME → auto_prune on, 90 days."""
|
|
monkeypatch.setenv("HERMES_HOME", str(tmp_path))
|
|
from hermes_cli.config import load_config
|
|
|
|
sessions = load_config().get("sessions") or {}
|
|
assert sessions.get("auto_prune") is True
|
|
assert sessions.get("retention_days") == 90
|
|
|
|
|
|
def test_cli_auto_maintenance_forwards_vacuum_interval(monkeypatch, tmp_path: Path):
|
|
import cli
|
|
import hermes_cli.config
|
|
import hermes_constants
|
|
|
|
session_db = MagicMock()
|
|
session_db.get_meta.return_value = "already-done"
|
|
monkeypatch.setattr(
|
|
hermes_cli.config,
|
|
"load_config",
|
|
lambda: {
|
|
"sessions": {
|
|
"auto_prune": True,
|
|
"retention_days": 90,
|
|
"vacuum_after_prune": True,
|
|
"min_interval_hours": 24,
|
|
"min_vacuum_interval_days": 17,
|
|
}
|
|
},
|
|
)
|
|
monkeypatch.setattr(hermes_constants, "get_hermes_home", lambda: tmp_path)
|
|
|
|
cli._run_state_db_auto_maintenance(session_db)
|
|
|
|
session_db.maybe_auto_prune_and_vacuum.assert_called_once_with(
|
|
retention_days=90,
|
|
min_interval_hours=24,
|
|
min_vacuum_interval_days=17,
|
|
vacuum=True,
|
|
sessions_dir=tmp_path / "sessions",
|
|
)
|