mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-09 04:40:45 +08:00
新增 Cloudflare 直连生图公共工具并补充基础测试。
绕过不稳定的 Cloudflare MCP 图片接口,确保所有专家默认可用并验证公共注册可见性与响应解析逻辑。 Made-with: Cursor
This commit is contained in:
parent
6a71892c72
commit
571612ccb5
3 changed files with 189 additions and 0 deletions
43
tests/test_cloudflare_image_generate_tool.py
Normal file
43
tests/test_cloudflare_image_generate_tool.py
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import base64
|
||||
import json
|
||||
|
||||
import pytest
|
||||
|
||||
from oclaw.runtime.tools.public.cloudflare_image_generate_tool import _to_image_bytes
|
||||
|
||||
|
||||
def test_to_image_bytes_accepts_direct_image_content_type() -> None:
|
||||
raw = b"fake-image-bytes"
|
||||
out, mime = _to_image_bytes(raw, "image/png; charset=binary")
|
||||
assert out == raw
|
||||
assert mime == "image/png"
|
||||
|
||||
|
||||
def test_to_image_bytes_accepts_data_url_in_result() -> None:
|
||||
payload = base64.b64encode(b"png-bytes").decode("ascii")
|
||||
resp = {
|
||||
"success": True,
|
||||
"result": {"image": f"data:image/png;base64,{payload}"},
|
||||
}
|
||||
out, mime = _to_image_bytes(json.dumps(resp).encode("utf-8"), "application/json")
|
||||
assert out == b"png-bytes"
|
||||
assert mime == "image/png"
|
||||
|
||||
|
||||
def test_to_image_bytes_accepts_plain_base64_result() -> None:
|
||||
payload = base64.b64encode(b"jpg-bytes").decode("ascii")
|
||||
resp = {
|
||||
"success": True,
|
||||
"result": {"b64_json": payload},
|
||||
}
|
||||
out, mime = _to_image_bytes(json.dumps(resp).encode("utf-8"), "application/json")
|
||||
assert out == b"jpg-bytes"
|
||||
assert mime == "image/png"
|
||||
|
||||
|
||||
def test_to_image_bytes_raises_on_error_response() -> None:
|
||||
resp = {"success": False, "errors": [{"message": "bad request"}]}
|
||||
with pytest.raises(ValueError, match="success"):
|
||||
_to_image_bytes(json.dumps(resp).encode("utf-8"), "application/json")
|
||||
Loading…
Add table
Add a link
Reference in a new issue