feat: harden webtool

This commit is contained in:
Alex committed 2026-07-20 19:57:44 +01:00
1 parent 3cbd284948
commit 64b3bd3356
20 files changed
+939 -80

No files matched your search

@@ -11,7 +11,7 @@ class TestReadWebpageErrors:
tool = ReadWebpageTool(config={})
with patch(
"application.agents.tools.read_webpage.pinned_request",
"application.agents.tools.read_webpage.pinned_fetch_bytes",
side_effect=requests.exceptions.RequestException("bad url"),
):
got = tool.execute_action(
@@ -20,17 +20,21 @@ class TestReadWebpageErrors:
assert "Error fetching URL" in got
def test_generic_exception_returns_error_string(self):
from unittest.mock import MagicMock
from application.agents.tools.read_webpage import ReadWebpageTool
tool = ReadWebpageTool(config={})
response = MagicMock()
response.headers = {"Content-Type": "text/html"}
response.raise_for_status.return_value = None
with patch(
"application.agents.tools.read_webpage.markdownify",
side_effect=RuntimeError("boom"),
), patch(
"application.agents.tools.read_webpage.pinned_request",
) as mock_pinned_request:
mock_pinned_request.return_value.text = "<h1>hi</h1>"
mock_pinned_request.return_value.raise_for_status.return_value = None
"application.agents.tools.read_webpage.pinned_fetch_bytes",
return_value=(b"<h1>hi</h1>", response),
):
got = tool.execute_action(
"read_webpage", url="https://example.com/",
)