Files
hermes-agent/tests/scripts/test_tree_guard_missing_roots.py
alt-glitch e8d908b1c9 fix(ci): guards fail instead of passing when they cannot see a change
Three guards could report success while they checked nothing:

- The public-surface check listed only modified files, so a moved
  file (git reports a rename) was never compared. It now pairs each
  renamed file with its old path, and treats src/hermes_agent/ as
  source.
- The change classifier read file names from the compare API, which
  stops at 300 files without saying so and drops the old path of a
  rename. A list at the cap now runs every lane, and a rename counts
  under both of its paths.
- Tree guards skipped a scan root that did not exist. The config
  reader and writer checks, the subprocess stdin check and two guard
  tests now fail when a root they scan is missing.
2026-11-06 23:02:54 -05:00

50 lines
1.8 KiB
Python

"""A tree guard fails when one of its scan roots is gone, instead of passing with nothing checked.
Each guard below walks a fixed list of top-level directories. When a directory moves (into
``src/hermes_agent/`` or a sibling package) a guard that skips missing roots keeps reporting
success while it checks none of the moved files.
"""
from __future__ import annotations
import importlib.util
import shutil
import sys
from pathlib import Path
import pytest
REPO_ROOT = Path(__file__).resolve().parents[2]
def _load(name: str):
spec = importlib.util.spec_from_file_location(name, REPO_ROOT / "scripts" / f"{name}.py")
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
@pytest.mark.parametrize("name", ["check_config_yaml_writers", "check_config_yaml_readers"])
def test_config_guard_fails_when_a_default_tree_is_missing(name, tmp_path, monkeypatch, capsys):
guard = _load(name)
for tree in guard.DEFAULT_TREES[1:]:
source = REPO_ROOT / tree
(tmp_path / tree).parent.mkdir(parents=True, exist_ok=True)
(tmp_path / tree).mkdir() if source.is_dir() else shutil.copy(source, tmp_path / tree)
monkeypatch.setattr(guard, "ROOT", tmp_path)
assert guard.main([]) == 2
assert guard.DEFAULT_TREES[0] in capsys.readouterr().err
def test_subprocess_stdin_guard_fails_when_a_context_dir_is_missing(tmp_path, monkeypatch, capsys):
guard = _load("check_subprocess_stdin")
for d in guard.TUI_CONTEXT_DIRS[1:]:
(tmp_path / d).mkdir()
monkeypatch.setattr(guard, "__file__", str(tmp_path / "scripts" / "check_subprocess_stdin.py"))
monkeypatch.setattr(sys, "argv", ["check_subprocess_stdin.py"])
monkeypatch.setattr(sys, "path", list(sys.path))
monkeypatch.chdir(tmp_path)
assert guard.main() == 2
assert guard.TUI_CONTEXT_DIRS[0] in capsys.readouterr().err