The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test: the home I/O guard allows metadata reads of the guarded root itself
ethernetb897d79ba29d
diff --git a/tests/hermes_cli/test_kanban_write_guard.py b/tests/hermes_cli/test_kanban_write_guard.pyindex d6c1e950d84..254d77d015c 100644--- a/tests/hermes_cli/test_kanban_write_guard.py+++ b/tests/hermes_cli/test_kanban_write_guard.py@@ -7,6 +7,9 @@ import pytestfrom hermes_cli import kanban_dbfrom hermes_cli import kanban_db_connect as kbc+# These probe the kanban guard against the real root on purpose.+pytestmark = pytest.mark.allow_real_home_io+def test_connect_succeeds_under_test_home(tmp_path, monkeypatch):"""When HERMES_HOME is a temp dir, kanban connect succeeds normally."""diff --git a/tests/hermes_state/test_live_db_isolation_guard.py b/tests/hermes_state/test_live_db_isolation_guard.pyindex de7d11aec7b..383edac3322 100644--- a/tests/hermes_state/test_live_db_isolation_guard.py+++ b/tests/hermes_state/test_live_db_isolation_guard.py@@ -24,6 +24,9 @@ from gateway.config import GatewayConfigfrom gateway.session import SessionStorefrom hermes_state import SessionDB+# These probe the live-DB guard against the real root on purpose.+pytestmark = pytest.mark.allow_real_home_io+# Must match the root the guard itself computes. Hardcoding ``~/.hermes``# silently disarmed every assertion below on Windows, where the real root is# ``%LOCALAPPDATA%\hermes``: the paths under test were then *correctly*diff --git a/tests/home_io_guard.py b/tests/home_io_guard.pyindex d5f5c7adaa7..9a82b0b5003 100644--- a/tests/home_io_guard.py+++ b/tests/home_io_guard.py@@ -17,7 +17,7 @@ class HomeIOGuard:self.checking = threading.local()self.directories: dict[int, Path] = {}- def check(self, value, *, dir_fd=None):+ def check(self, value, *, dir_fd=None, metadata=False):if value is None or isinstance(value, int) or getattr(self.checking, "active", False):returnself.checking.active = True@@ -30,11 +30,17 @@ class HomeIOGuard:candidate = parent / candidateabsolute = Path(os.path.abspath(candidate))roots = self.roots()+ # Resolving the root itself (get_default_hermes_root's relative_to+ # probe) reads no state; only its contents are guarded.+ if metadata and absolute in roots:+ return# Check the lexical path first: resolving must not probe a protected# tree merely to decide that the original path was forbidden.if any(absolute.is_relative_to(root) for root in roots):self.refuse(value)resolved = absolute.resolve()+ if metadata and resolved in roots:+ returnif any(resolved.is_relative_to(root) for root in roots):self.refuse(value)finally:@@ -48,22 +54,24 @@ class HomeIOGuard:)def install(self, monkeypatch):- def wrap(module, name, parameters):+ def wrap(module, name, parameters, *, metadata=False):original = getattr(module, name)@wraps(original)def guarded(*args, **kwargs):for index, (parameter, descriptor) in enumerate(parameters):value = args[index] if index < len(args) else kwargs.get(parameter)- self.check(value, dir_fd=kwargs.get(descriptor) if descriptor else None)+ self.check(value, dir_fd=kwargs.get(descriptor) if descriptor else None, metadata=metadata)return original(*args, **kwargs)monkeypatch.setattr(module, name, guarded)for module in (builtins, io):wrap(module, "open", (("file", None),))- for name in ("mkdir", "stat", "lstat", "unlink", "remove", "rmdir", "chmod", "utime", "readlink", "access"):+ for name in ("mkdir", "unlink", "remove", "rmdir", "chmod", "utime"):wrap(os, name, (("path", "dir_fd"),))+ for name in ("stat", "lstat", "readlink", "access"):+ wrap(os, name, (("path", "dir_fd"),), metadata=True)for name in ("makedirs", "listdir", "scandir"):wrap(os, name, (("name" if name == "makedirs" else "path", None),))for name in ("rename", "replace"):diff --git a/tests/tools/test_hook_output_spill.py b/tests/tools/test_hook_output_spill.pyindex c2be87a60de..37794a6ff35 100644--- a/tests/tools/test_hook_output_spill.py+++ b/tests/tools/test_hook_output_spill.py@@ -69,12 +69,7 @@ class SpillIfOversizedTests(unittest.TestCase):# Also patch get_hermes_home to the env var to mirror production.cfg = self._cfg(directory=None, max_chars=5)hos.spill_if_oversized("x" * 200, session_id="sess", config=cfg)- # Spill directory exists somewhere under test_home OR default- # ~/.hermes/hook_outputs depending on get_hermes_home behaviour.- candidates = [- Path(test_home) / "hook_outputs" / "sess",- Path(os.path.expanduser("~/.hermes/hook_outputs/sess")),- ]+ candidates = [Path(test_home) / "hook_outputs" / "sess"]# At least one of the candidate dirs now exists and has a file.existing = [c for c in candidates if c.is_dir() and list(c.iterdir())]self.assertTrue(existing, f"No spill dir found in {candidates}")