When the LLM sends heredoc commands (cat << 'EOF'), the semicolon sentinel (EOF; echo '<<exit>>') prevents bash from recognizing the terminator, causing the session to hang until the 120s timeout. Confirmed in production logs: the exact command that caused the hang. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
57 lines
1.5 KiB
Python
57 lines
1.5 KiB
Python
"""Tests for BashTool20250124."""
|
|
|
|
import pytest
|
|
from nanobot.agent.tools.anthropic.bash import BashTool20250124
|
|
from nanobot.agent.tools.anthropic.base import ToolResult
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_bash_tool_simple_command():
|
|
"""Test bash tool executes simple command."""
|
|
tool = BashTool20250124()
|
|
result = await tool(command="echo hello")
|
|
|
|
assert isinstance(result, ToolResult)
|
|
assert "hello" in result.output
|
|
assert result.error is None
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_bash_tool_persistent_session():
|
|
"""Test bash tool maintains session across calls."""
|
|
tool = BashTool20250124()
|
|
|
|
# Set variable
|
|
result1 = await tool(command="export TEST_VAR=42")
|
|
assert result1.error is None
|
|
|
|
# Read variable (should persist)
|
|
result2 = await tool(command="echo $TEST_VAR")
|
|
assert "42" in result2.output
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_bash_tool_restart():
|
|
"""Test bash tool can restart session."""
|
|
tool = BashTool20250124()
|
|
|
|
# Set variable
|
|
await tool(command="export TEST_VAR=42")
|
|
|
|
# Restart
|
|
result = await tool(restart=True)
|
|
assert "restarted" in (result.system or result.output or "").lower()
|
|
|
|
# Variable should be gone
|
|
result2 = await tool(command="echo $TEST_VAR")
|
|
assert "42" not in result2.output
|
|
|
|
|
|
def test_bash_tool_to_params():
|
|
"""Test bash tool returns correct params."""
|
|
tool = BashTool20250124()
|
|
params = tool.to_params()
|
|
|
|
assert params["type"] == "bash_20250124"
|
|
assert params["name"] == "bash"
|