From 14a64ea98552b26d9661b2257f66faaeaa4efa4c Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Wed, 2 Sep 2026 09:56:42 -0700 Subject: [PATCH] refactor(tools): repoint tests to moved file_tools guard/path symbols --- tests/tools/test_docker_network_config.py | 12 ++++++++++-- tests/tools/test_file_tools.py | 18 +++++++++--------- tests/tools/test_file_write_safety.py | 8 ++++---- tests/tools/test_read_extract.py | 3 ++- 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/tests/tools/test_docker_network_config.py b/tests/tools/test_docker_network_config.py index c2f6df9da4..ee0eef9ead 100644 --- a/tests/tools/test_docker_network_config.py +++ b/tests/tools/test_docker_network_config.py @@ -34,9 +34,17 @@ def test_sibling_container_config_sites_carry_docker_network(): tree = ast.parse(inspect.getsource(module)) sites = 0 for node in ast.walk(tree): - if not isinstance(node, ast.Dict): + # Accept a dict literal or a (key, default) pair table that a dict + # comprehension is built from. + if isinstance(node, ast.Dict): + keys = {k.value for k in node.keys if isinstance(k, ast.Constant)} + elif isinstance(node, ast.Tuple) and node.elts and all( + isinstance(e, ast.Tuple) and len(e.elts) == 2 and isinstance(e.elts[0], ast.Constant) + for e in node.elts + ): + keys = {e.elts[0].value for e in node.elts} + else: continue - keys = {k.value for k in node.keys if isinstance(k, ast.Constant)} if "docker_run_as_host_user" in keys: sites += 1 assert "docker_network" in keys, ( diff --git a/tests/tools/test_file_tools.py b/tests/tools/test_file_tools.py index 58fb91ac2b..94020b292d 100644 --- a/tests/tools/test_file_tools.py +++ b/tests/tools/test_file_tools.py @@ -436,8 +436,8 @@ class TestSensitivePathCheck: def test_hermes_config_blocked_for_write_file(self, tmp_path, monkeypatch): fake_config = tmp_path / "config.yaml" - monkeypatch.setattr("tools.file_tools._hermes_config_resolved", str(fake_config)) - monkeypatch.setattr("tools.file_tools._hermes_config_resolved_loaded", True) + monkeypatch.setattr("tools.file_tools_write_guards._hermes_config_resolved", str(fake_config)) + monkeypatch.setattr("tools.file_tools_write_guards._hermes_config_resolved_loaded", True) from tools.file_tools import write_file_tool result = json.loads(write_file_tool(str(fake_config), "approvals:\n mode: off\n")) @@ -446,8 +446,8 @@ class TestSensitivePathCheck: def test_hermes_config_blocked_via_tilde_path(self, tmp_path, monkeypatch): fake_config = tmp_path / "config.yaml" - monkeypatch.setattr("tools.file_tools._hermes_config_resolved", str(fake_config)) - monkeypatch.setattr("tools.file_tools._hermes_config_resolved_loaded", True) + monkeypatch.setattr("tools.file_tools_write_guards._hermes_config_resolved", str(fake_config)) + monkeypatch.setattr("tools.file_tools_write_guards._hermes_config_resolved_loaded", True) from tools.file_tools import write_file_tool result = json.loads(write_file_tool(str(fake_config), "approvals:\n mode: off\n")) @@ -456,8 +456,8 @@ class TestSensitivePathCheck: def test_system_path_still_blocked(self, monkeypatch): - monkeypatch.setattr("tools.file_tools._hermes_config_resolved", "/some/other/path") - monkeypatch.setattr("tools.file_tools._hermes_config_resolved_loaded", True) + monkeypatch.setattr("tools.file_tools_write_guards._hermes_config_resolved", "/some/other/path") + monkeypatch.setattr("tools.file_tools_write_guards._hermes_config_resolved_loaded", True) from tools.file_tools import write_file_tool result = json.loads(write_file_tool("/etc/passwd", "evil")) @@ -480,8 +480,8 @@ class TestSensitivePathCheck: @patch("tools.file_tools._get_file_ops") def test_normal_file_not_blocked(self, mock_get, monkeypatch): - monkeypatch.setattr("tools.file_tools._hermes_config_resolved", "/home/user/.hermes/config.yaml") - monkeypatch.setattr("tools.file_tools._hermes_config_resolved_loaded", True) + monkeypatch.setattr("tools.file_tools_write_guards._hermes_config_resolved", "/home/user/.hermes/config.yaml") + monkeypatch.setattr("tools.file_tools_write_guards._hermes_config_resolved_loaded", True) mock_ops = MagicMock() result_obj = MagicMock() result_obj.to_dict.return_value = {"status": "ok", "path": "/tmp/other.txt", "bytes": 5} @@ -1022,7 +1022,7 @@ class TestSSHConfigWriteGateSingleQuery: def test_gate_call_passes_single_query_deny_message(self): import inspect as _inspect import re as _re - import tools.file_tools as ft + import tools.file_tools_write_guards as ft src = _inspect.getsource(ft) idx = src.find("_approval._run_approval_gate(") diff --git a/tests/tools/test_file_write_safety.py b/tests/tools/test_file_write_safety.py index fc92b55b09..5dd358e314 100644 --- a/tests/tools/test_file_write_safety.py +++ b/tests/tools/test_file_write_safety.py @@ -395,7 +395,7 @@ class TestProtectedInstructionFiles: @pytest.fixture(autouse=True) def _gate_on(self, monkeypatch): - import tools.file_tools as ft + import tools.file_tools_write_guards as ft monkeypatch.setattr( ft, "_protected_instruction_config", lambda: (True, []) ) @@ -489,7 +489,7 @@ class TestProtectedInstructionFiles: assert not target.exists() def test_config_disabled_skips_gate(self, tmp_path, approvals, monkeypatch): - import tools.file_tools as ft + import tools.file_tools_write_guards as ft monkeypatch.setattr( ft, "_protected_instruction_config", lambda: (False, []) ) @@ -498,7 +498,7 @@ class TestProtectedInstructionFiles: assert approvals["calls"] == [] def test_extra_patterns_from_config(self, tmp_path, approvals, monkeypatch): - import tools.file_tools as ft + import tools.file_tools_write_guards as ft monkeypatch.setattr( ft, "_protected_instruction_config", lambda: (True, ["*.mdc"]) ) @@ -561,7 +561,7 @@ class TestProtectedInstructionFiles: self, tmp_path, approvals, monkeypatch ): """~/.hermes itself is governed by existing guards, not this gate.""" - import tools.file_tools as ft + import tools.file_tools_write_guards as ft fake_home = tmp_path / ".hermes" (fake_home / "notes").mkdir(parents=True) monkeypatch.setattr( diff --git a/tests/tools/test_read_extract.py b/tests/tools/test_read_extract.py index e44881728e..eec57f81a8 100644 --- a/tests/tools/test_read_extract.py +++ b/tests/tools/test_read_extract.py @@ -16,6 +16,7 @@ import os import tempfile import unittest import zipfile +from pathlib import PurePosixPath from unittest import mock from tools.read_extract import ( @@ -706,7 +707,7 @@ class TestReadFileToolIntegration(unittest.TestCase): mock.patch.object( file_tools, "_resolve_path_for_task", - return_value=file_tools.PurePosixPath("/workspace/remote.rtf"), + return_value=PurePosixPath("/workspace/remote.rtf"), ), mock.patch("os.path.getsize", side_effect=AssertionError("host read")): res = json.loads(read_file_tool("/workspace/remote.rtf", task_id="remote")) finally: