mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-09 01:50:44 +08:00
完善 MCP/会话上下文治理并补齐搜索与诊断能力。
补充历史压缩与会话诊断链路,强化 tool pairing 与空响应兜底观测;完善 Admin MCP 导入/绑定与相关前端展示;新增 web_search_fast/web_fetch_clean 及多项测试与文档更新,并同步技能安装与角色绑定策略改进。 Made-with: Cursor
This commit is contained in:
parent
df91434936
commit
ae44cbcad5
43 changed files with 3549 additions and 57 deletions
43
tests/test_web_fetch_clean_tool.py
Normal file
43
tests/test_web_fetch_clean_tool.py
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from oclaw.runtime.tools.public.web_fetch_clean_tool import web_fetch_clean_tool
|
||||
|
||||
|
||||
class _Resp:
|
||||
def __init__(self, body: bytes, *, status: int = 200, headers: dict[str, str] | None = None):
|
||||
self._body = body
|
||||
self.status = status
|
||||
self.headers = headers or {"content-type": "text/html; charset=utf-8"}
|
||||
|
||||
def read(self) -> bytes:
|
||||
return self._body
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc, tb):
|
||||
return False
|
||||
|
||||
|
||||
def test_web_fetch_clean_html_strip(monkeypatch) -> None:
|
||||
html = b"""
|
||||
<html><head><title> Hello </title><style>.x{}</style></head>
|
||||
<body><h1>Title</h1><p>Para <b>one</b>.</p><script>alert(1)</script></body></html>
|
||||
"""
|
||||
|
||||
monkeypatch.setattr("urllib.request.urlopen", lambda req, timeout=0: _Resp(html)) # noqa: ARG005
|
||||
out = web_fetch_clean_tool().handler({"url": "https://example.com"})
|
||||
assert out.get("ok") is True, out
|
||||
assert out.get("title") == "Hello"
|
||||
text = str(out.get("text") or "")
|
||||
assert "Para" in text
|
||||
assert "one" in text
|
||||
assert "alert" not in str(out.get("text") or "")
|
||||
|
||||
|
||||
def test_web_fetch_clean_http_error(monkeypatch) -> None:
|
||||
monkeypatch.setattr("urllib.request.urlopen", lambda req, timeout=0: _Resp(b"no", status=403)) # noqa: ARG005
|
||||
out = web_fetch_clean_tool().handler({"url": "https://example.com"})
|
||||
# Our stub doesn't raise HTTPError; status is checked and returns http_error.
|
||||
assert out.get("ok") is False
|
||||
assert out.get("error_code") == "http_error"
|
||||
Loading…
Add table
Add a link
Reference in a new issue