mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-06-16 01:35:36 -04:00
refactor(tools): migrate execution logic to src/agent_tools/ package with handler registry (#3435)
* refactor(tools): implement strict cohesive class coordinator pattern per #2917 * test: update edit_file tests to use EditFileTool class * fix(tools): restore tool_policy param and security backstop in coordinator * refactor(tools): migrate domain tools to agent_tools package per #2917 * test: update test imports for new agent_tools package * fix: resolve circular import between tool_execution and agent_tools * fix: remove leftover git conflict markers * fix(tools): resolve pytest failure and document _apply method * fix(tools): clean up whitespace and remove dead _tool_python helper --------- Co-authored-by: Alexandre Teixeira <111787685+alteixeira20@users.noreply.github.com>
This commit is contained in:
@@ -11,7 +11,7 @@ from src.tool_security import (
|
||||
is_public_blocked_tool,
|
||||
blocked_tools_for_owner,
|
||||
)
|
||||
from src.tool_execution import _do_edit_file
|
||||
from src.agent_tools.filesystem_tools import EditFileTool
|
||||
from src.agent_tools import ToolBlock
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ async def test_edit_file_blocked_at_execution_for_non_admin(monkeypatch):
|
||||
async def test_edit_file_success():
|
||||
p = os.path.join("/tmp", "ef_ok.py")
|
||||
open(p, "w").write("def f():\n return 1\n")
|
||||
res = await _do_edit_file(json.dumps({"path": p, "old_string": "return 1", "new_string": "return 2"}))
|
||||
res = await EditFileTool().execute(json.dumps({"path": p, "old_string": "return 1", "new_string": "return 2"}), {})
|
||||
assert res["exit_code"] == 0
|
||||
assert open(p).read() == "def f():\n return 2\n"
|
||||
assert res["diff"]["added"] == 1 and res["diff"]["removed"] == 1 and res["diff"]["file"] == "ef_ok.py"
|
||||
@@ -71,7 +71,7 @@ async def test_edit_file_success():
|
||||
async def test_edit_file_not_found():
|
||||
p = os.path.join("/tmp", "ef_nf.txt")
|
||||
open(p, "w").write("hello\n")
|
||||
res = await _do_edit_file(json.dumps({"path": p, "old_string": "nope", "new_string": "x"}))
|
||||
res = await EditFileTool().execute(json.dumps({"path": p, "old_string": "nope", "new_string": "x"}), {})
|
||||
assert res["exit_code"] == 1 and "not found" in res["error"]
|
||||
os.unlink(p)
|
||||
|
||||
@@ -80,15 +80,15 @@ async def test_edit_file_not_found():
|
||||
async def test_edit_file_non_unique():
|
||||
p = os.path.join("/tmp", "ef_dup.txt")
|
||||
open(p, "w").write("x\nx\n")
|
||||
res = await _do_edit_file(json.dumps({"path": p, "old_string": "x", "new_string": "y"}))
|
||||
res = await EditFileTool().execute(json.dumps({"path": p, "old_string": "x", "new_string": "y"}), {})
|
||||
assert res["exit_code"] == 1 and "not unique" in res["error"]
|
||||
# replace_all resolves it
|
||||
res = await _do_edit_file(json.dumps({"path": p, "old_string": "x", "new_string": "y", "replace_all": True}))
|
||||
res = await EditFileTool().execute(json.dumps({"path": p, "old_string": "x", "new_string": "y", "replace_all": True}), {})
|
||||
assert res["exit_code"] == 0 and open(p).read() == "y\ny\n"
|
||||
os.unlink(p)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_edit_file_outside_allowed_roots():
|
||||
res = await _do_edit_file(json.dumps({"path": "/etc/hosts", "old_string": "x", "new_string": "y"}))
|
||||
res = await EditFileTool().execute(json.dumps({"path": "/etc/hosts", "old_string": "x", "new_string": "y"}), {})
|
||||
assert res["exit_code"] == 1 and ("outside the allowed roots" in res["error"] or "sensitive" in res["error"])
|
||||
|
||||
Reference in New Issue
Block a user