refactor(tools): repoint tests to moved file_tools guard/path symbols
This commit is contained in:
@@ -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, (
|
||||
|
||||
@@ -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(")
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user