oclaw/tests/test_model_path_audit.py
oliver 420abac9f1 refactor: root-package imports (svc/runtime/interfaces) and fix PYTHONPATH
- Rename platform/ to svc/ to avoid shadowing stdlib platform.
- Replace from oclaw.* with from svc/runtime/interfaces; update -m CLI paths.
- tests/conftest: prepend repo root to sys.path (no parent-folder package name).
- CI: paths and offline_eval script under repo root.
- Ops scripts: PYTHONPATH must be repo root for python -m runtime.* (fixes gateway/WhatsApp sidecar startup).
- Fix default oclaw.json path in tabular/file attachment limits; stabilize attachment test config.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-13 14:51:17 +08:00

46 lines
1.5 KiB
Python

from __future__ import annotations
from 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 "")