deerflow / backend /tests /test_agent_browser_tool.py
pjpjq's picture
Fix web search fallback and integrate vercel agent-browser tool
9c0e837
import subprocess
from src.community.agent_browser import tools as agent_browser_tools
def test_agent_browser_tool_rejects_unsupported_command():
result = agent_browser_tools.agent_browser_tool.invoke({"command": "rm -rf /"})
assert "unsupported agent-browser command" in result
def test_agent_browser_tool_runs_and_returns_stdout(monkeypatch):
monkeypatch.setattr(agent_browser_tools, "_resolve_agent_browser_command", lambda: ["agent-browser"])
def _fake_run(cmd, capture_output, text, check, timeout):
assert cmd[0] == "agent-browser"
assert "--session" in cmd
assert "--json" in cmd
return subprocess.CompletedProcess(cmd, 0, stdout='{"ok":true}\n', stderr="")
monkeypatch.setattr(agent_browser_tools.subprocess, "run", _fake_run)
result = agent_browser_tools.agent_browser_tool.invoke(
{
"command": "open https://example.com",
"session": "s1",
"json_output": True,
"timeout_seconds": 30,
}
)
assert result == '{"ok":true}'
def test_agent_browser_tool_reports_cli_errors(monkeypatch):
monkeypatch.setattr(agent_browser_tools, "_resolve_agent_browser_command", lambda: ["agent-browser"])
def _fake_run(cmd, capture_output, text, check, timeout):
return subprocess.CompletedProcess(cmd, 1, stdout="", stderr="browser failed")
monkeypatch.setattr(agent_browser_tools.subprocess, "run", _fake_run)
result = agent_browser_tools.agent_browser_tool.invoke({"command": "snapshot -i"})
assert "exited with code 1" in result
assert "browser failed" in result