Skip to content

The agent that grows with you

fix: keep virtual cron soak within the CI file budget

ethernet054f5f94ded5
diff --git a/tests/e2e/core/delivery/test_cron_virtual_clock_soak.py b/tests/e2e/core/delivery/test_cron_virtual_clock_soak.py
index ef82b6e78a9..e2b6b6e3098 100644
--- a/tests/e2e/core/delivery/test_cron_virtual_clock_soak.py
+++ b/tests/e2e/core/delivery/test_cron_virtual_clock_soak.py
@@ -385,6 +385,13 @@ class Soak:
def ev_long_run(self, name):
"""A run that outlives the fire-claim TTL while the ticker keeps ticking."""
+ pending = self.model.jobs[name].pending
+ if pending is not None and pending > self.now():
+ # A known schedule gap may shift the stored slot. Keep driving all intervening
+ # ticks, then hold the actual due run rather than waiting at the wrong instant.
+ self.at(pending, "long_run", name)
+ self.events.sort()
+ return
job_id = self.ids[name]
hold = self.control.hold_file(name)
hold.write_text("1", encoding="utf-8")
diff --git a/tests/hermes_cli/test_real_home_tripwire.py b/tests/hermes_cli/test_real_home_tripwire.py
index e5d96bc1464..de1ae67d97d 100644
--- a/tests/hermes_cli/test_real_home_tripwire.py
+++ b/tests/hermes_cli/test_real_home_tripwire.py
@@ -132,6 +132,34 @@ def test_close_keeps_a_reused_descriptors_new_owner(tmp_path, monkeypatch):
original_close(fd)
+def test_path_metadata_exemption_tracks_path_changes(protected_home, monkeypatch):
+ from tests.home_io_guard import HomeIOGuard
+
+ target = protected_home / "file.txt"
+ guard = HomeIOGuard(lambda: [protected_home])
+ monkeypatch.setenv("PATH", str(protected_home))
+ guard.check(target, metadata=True) # executable lookup, not a state read
+ monkeypatch.setenv("PATH", str(protected_home.parent))
+ with pytest.raises(AssertionError, match="REAL hermes home"):
+ guard.check(target, metadata=True)
+
+
+def test_relative_path_metadata_exemption_tracks_working_directory(protected_home, tmp_path, monkeypatch):
+ from tests.home_io_guard import HomeIOGuard
+
+ target = protected_home / "file.txt"
+ guard = HomeIOGuard(lambda: [protected_home])
+ other = tmp_path / "other"
+ other.mkdir()
+ (other / "nested").mkdir()
+ monkeypatch.setenv("PATH", "../protected")
+ monkeypatch.chdir(other)
+ guard.check(target, metadata=True)
+ monkeypatch.chdir(other / "nested")
+ with pytest.raises(AssertionError, match="REAL hermes home"):
+ guard.check(target, metadata=True)
+
+
def test_checkout_inside_a_guarded_root_is_not_hermes_state():
"""The default install checks the repo out INSIDE the home (install.sh:
INSTALL_DIR=$HERMES_HOME/hermes-agent): the checkout, its .venv and test
diff --git a/tests/home_io_guard.py b/tests/home_io_guard.py
index 45a89ca929b..ce4c1e1b715 100644
--- a/tests/home_io_guard.py
+++ b/tests/home_io_guard.py
@@ -2,7 +2,7 @@
from __future__ import annotations
import builtins
-from functools import wraps
+from functools import lru_cache, wraps
import io
import os
from pathlib import Path
@@ -65,8 +65,11 @@ class HomeIOGuard:
# ``shutil.which`` stats/accesses ``<PATH entry>/<name>``. A developer shell puts
# PM's tool store (~/.hermes/tools/...) on PATH; probing an executable there is
# command lookup, not reading Hermes state. CI has no such entries.
- if metadata and any(absolute.parent == entry for entry in self._path_entries()):
- return
+ if metadata:
+ path = os.environ.get("PATH", "")
+ cwd = os.getcwd() if self._relative_path_entries(path) else None
+ if absolute.parent in self._path_entries(path, cwd):
+ return
# The interpreter's own installation (a PM-managed python under ~/.hermes/tools):
# stdlib source reads (linecache, traceback) are not Hermes state either, nor is
# realpath() walking up through its ancestors.
@@ -96,8 +99,18 @@ class HomeIOGuard:
)
@staticmethod
- def _path_entries():
- return [Path(os.path.abspath(entry)) for entry in os.environ.get("PATH", "").split(os.pathsep) if entry]
+ @lru_cache(maxsize=8)
+ def _relative_path_entries(path: str) -> bool:
+ return any(entry and not os.path.isabs(entry) for entry in path.split(os.pathsep))
+
+ @staticmethod
+ @lru_cache(maxsize=8)
+ def _path_entries(path: str, cwd: str | None):
+ # Relative PATH entries change meaning after chdir; absolute ones need no cwd.
+ return frozenset(
+ Path(os.path.normpath(os.path.join(cwd or "", entry)))
+ for entry in path.split(os.pathsep) if entry
+ )
def install(self, monkeypatch):
def wrap(module, name, parameters, *, metadata=False):