tests: Add more side cases for exec command

This commit is contained in:
2026-05-04 11:19:28 +02:00
parent 9dc5b9ba50
commit eac1643d48
2 changed files with 90 additions and 7 deletions
+15 -7
View File
@@ -7,7 +7,6 @@ exactly as they would be when called by an LLM agent.
from __future__ import annotations
import pytest
from langchain_core.tools import BaseTool
from docker_agent_sandbox import (
@@ -26,7 +25,6 @@ from docker_agent_sandbox import (
make_write_file_tool,
)
# ---------------------------------------------------------------------------
# bash
# ---------------------------------------------------------------------------
@@ -113,7 +111,9 @@ def test_read_file_pagination(sandbox: DockerSandbox, workdir: str):
content = "\n".join(f"line{i}" for i in range(1, 11)) + "\n"
sandbox.write_file(f"{workdir}/paged.txt", content)
tool = make_read_file_tool(sandbox)
result = tool.invoke({"path": f"{workdir}/paged.txt", "start_line": 3, "end_line": 5})
result = tool.invoke(
{"path": f"{workdir}/paged.txt", "start_line": 3, "end_line": 5}
)
assert "line3" in result
assert "line5" in result
assert "line1" not in result
@@ -124,7 +124,9 @@ def test_read_file_shows_total_line_count(sandbox: DockerSandbox, workdir: str):
content = "\n".join(f"line{i}" for i in range(1, 21)) + "\n"
sandbox.write_file(f"{workdir}/info.txt", content)
tool = make_read_file_tool(sandbox)
result = tool.invoke({"path": f"{workdir}/info.txt", "start_line": 1, "end_line": 5})
result = tool.invoke(
{"path": f"{workdir}/info.txt", "start_line": 1, "end_line": 5}
)
# There are 20 lines but we only requested 1-5, suffix should mention totals.
assert "20" in result
@@ -187,7 +189,9 @@ def test_edit_file_delete_block(sandbox: DockerSandbox, workdir: str):
def test_edit_file_missing_file_returns_error(sandbox: DockerSandbox, workdir: str):
tool = make_edit_file_tool(sandbox)
result = tool.invoke({"path": f"{workdir}/ghost.txt", "old_str": "x", "new_str": "y"})
result = tool.invoke(
{"path": f"{workdir}/ghost.txt", "old_str": "x", "new_str": "y"}
)
assert result.startswith("[ERROR")
@@ -195,7 +199,9 @@ def test_edit_file_multiline_replace(sandbox: DockerSandbox, workdir: str):
path = f"{workdir}/multi.txt"
sandbox.write_file(path, "line1\nline2\nline3\n")
tool = make_edit_file_tool(sandbox)
result = tool.invoke({"path": path, "old_str": "line1\nline2\n", "new_str": "replaced\n"})
result = tool.invoke(
{"path": path, "old_str": "line1\nline2\n", "new_str": "replaced\n"}
)
assert result.startswith("[OK]")
assert sandbox.read_file(path) == b"replaced\nline3\n"
@@ -438,7 +444,9 @@ def test_grep_recursive(sandbox: DockerSandbox, workdir: str):
sandbox.write_file(f"{workdir}/d/a.txt", "find_me\n")
sandbox.write_file(f"{workdir}/d/b.txt", "not here\n")
tool = make_grep_tool(sandbox)
result = tool.invoke({"pattern": "find_me", "path": f"{workdir}/d", "recursive": True})
result = tool.invoke(
{"pattern": "find_me", "path": f"{workdir}/d", "recursive": True}
)
assert "find_me" in result
assert "a.txt" in result