mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-11 03:00:45 +08:00
Refactor media payload handling to persist base64 blobs as attachment refs and keep non-turn model paths safe by degrading risky payloads.
This preserves multimodal fidelity for the latest user turn while preventing historical/tool replay bloat, and adds admin UI support for referenced attachment preview/download flows. Made-with: Cursor
This commit is contained in:
parent
3d27a01879
commit
6cfaff06f6
20 changed files with 1626 additions and 101 deletions
46
tests/test_model_path_audit.py
Normal file
46
tests/test_model_path_audit.py
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from oclaw.runtime.chat.model_path_audit import ensure_no_tool_or_embedded_image_payload
|
||||
|
||||
|
||||
def test_audit_accepts_plain_system_user_messages() -> None:
|
||||
ensure_no_tool_or_embedded_image_payload(
|
||||
path="unit.ok",
|
||||
messages=[
|
||||
{"role": "system", "content": "sys"},
|
||||
{"role": "user", "content": "hello"},
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
def test_audit_degrades_tool_role() -> None:
|
||||
msgs = [
|
||||
{"role": "assistant", "content": "a"},
|
||||
{"role": "tool", "content": '{"ok":true}'},
|
||||
]
|
||||
ensure_no_tool_or_embedded_image_payload(path="unit.tool", messages=msgs)
|
||||
assert msgs[1]["role"] == "assistant"
|
||||
assert "omitted" in str(msgs[1]["content"] or "")
|
||||
|
||||
|
||||
def test_audit_degrades_embedded_image_payload() -> None:
|
||||
msgs = [
|
||||
{
|
||||
"role": "user",
|
||||
"content": [
|
||||
{"type": "text", "text": "x"},
|
||||
{"type": "input_image", "image_base64": "a" * 600, "mime": "image/png"},
|
||||
],
|
||||
}
|
||||
]
|
||||
ensure_no_tool_or_embedded_image_payload(path="unit.image", messages=msgs)
|
||||
c = msgs[0]["content"]
|
||||
assert isinstance(c, list)
|
||||
assert any(isinstance(x, dict) and str(x.get("type") or "") == "text" and "omitted" in str(x.get("text") or "") for x in c)
|
||||
|
||||
|
||||
def test_audit_degrades_large_base64_like_plain_text() -> None:
|
||||
payload = "A" * 700
|
||||
msgs = [{"role": "user", "content": payload}]
|
||||
ensure_no_tool_or_embedded_image_payload(path="unit.b64_text", messages=msgs)
|
||||
assert "omitted" in str(msgs[0]["content"] or "")
|
||||
Loading…
Add table
Add a link
Reference in a new issue