From b41b4b3ec002b277c30bc628b941b33cbff85470 Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Fri, 17 Jul 2026 05:45:12 -0700 Subject: [PATCH] test(file-safety): unbreak session-snapshot suite; de-flake fixture to env-var resolution (#66293) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two changes to tests/agent/test_file_safety_session_state.py: 1. Drop the stale monkeypatch on tools.file_tools._get_live_tracking_cwd — the helper was deleted in the cwd-tracking refactor (c80b244b5), and monkeypatch.setattr on a missing attribute raises AttributeError, breaking CI slice 4/8 on main for every PR. The patch was redundant: the test writes an absolute path, so cwd resolution never engages. 2. Make the fixture stale-proof: instead of monkeypatching the private _hermes_home_path/_hermes_root_path helpers (same failure class if they're ever renamed), set HERMES_HOME to /profiles/work and let the real resolution chain (get_hermes_home / get_default_hermes_root's profiles-parent rule) derive both paths. The fixture now references zero private symbols and exercises the production resolution path. --- tests/agent/test_file_safety_session_state.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tests/agent/test_file_safety_session_state.py b/tests/agent/test_file_safety_session_state.py index 3f0af7d70da6..21885a35b891 100644 --- a/tests/agent/test_file_safety_session_state.py +++ b/tests/agent/test_file_safety_session_state.py @@ -16,13 +16,20 @@ import pytest @pytest.fixture() def fake_homes(tmp_path, monkeypatch): - import agent.file_safety as fs + """Point HERMES_HOME at a temp profile dir. + Uses the real env-var resolution chain (get_hermes_home / + get_default_hermes_root) instead of monkeypatching private helpers — + a stale monkeypatch on a since-deleted helper broke CI in July 2026 + (monkeypatch.setattr raises AttributeError on missing attributes). + HERMES_HOME=/profiles/ makes get_default_hermes_root() + derive via the `profiles` parent-dir rule, so both the + profile-scoped and root-scoped deny lists resolve into tmp_path. + """ root = tmp_path / ".hermes" profile = root / "profiles" / "work" profile.mkdir(parents=True) - monkeypatch.setattr(fs, "_hermes_home_path", lambda: profile) - monkeypatch.setattr(fs, "_hermes_root_path", lambda: root) + monkeypatch.setenv("HERMES_HOME", str(profile)) return root, profile @@ -58,14 +65,13 @@ def test_project_local_state_db_remains_writable(fake_homes, tmp_path): assert is_write_denied(str(target)) is False -def test_write_file_tool_preserves_existing_session_snapshot(fake_homes, monkeypatch): +def test_write_file_tool_preserves_existing_session_snapshot(fake_homes): import tools.file_tools as ft _root, profile = fake_homes target = profile / "sessions" / "session_abc.json" target.parent.mkdir(parents=True) target.write_text("original transcript", encoding="utf-8") - monkeypatch.setattr(ft, "_get_live_tracking_cwd", lambda task_id="default": None) result = json.loads(ft.write_file_tool(str(target), "tampered"))