mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-09 07:20:44 +08:00
- 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>
50 lines
2.1 KiB
Python
50 lines
2.1 KiB
Python
"""Regression tests for Oclaw-style tool_call_id replay (see svc/llm/tool_call_id.py)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from svc.llm.replay_policy import apply_replay_policy_to_messages, resolve_replay_policy
|
|
from svc.llm.tool_call_id import repair_orphan_tool_messages, rewrite_openai_chat_messages_tool_ids
|
|
|
|
|
|
def test_rewrite_pairs_assistant_and_tool_ids() -> None:
|
|
msgs = [
|
|
{"role": "user", "content": "list files"},
|
|
{
|
|
"role": "assistant",
|
|
"content": "",
|
|
"tool_calls": [
|
|
{
|
|
"id": "call_function_2aij35g1tffl_1",
|
|
"type": "function",
|
|
"function": {"name": "get_system_time", "arguments": "{}"},
|
|
}
|
|
],
|
|
},
|
|
{"role": "tool", "tool_call_id": "call_function_2aij35g1tffl_1", "content": '{"ok":true}'},
|
|
]
|
|
out = rewrite_openai_chat_messages_tool_ids(msgs, max_len=40)
|
|
assert out[1]["tool_calls"][0]["id"]
|
|
tid = out[1]["tool_calls"][0]["id"]
|
|
assert out[2]["tool_call_id"] == tid
|
|
assert tid.isalnum() or all(c.isalnum() for c in tid if c)
|
|
|
|
|
|
def test_repair_strips_dangling_tool_call_id() -> None:
|
|
msgs = [
|
|
{"role": "assistant", "content": "x", "tool_calls": [{"id": "onlyhere", "type": "function", "function": {"name": "a", "arguments": "{}"}}]},
|
|
{"role": "tool", "tool_call_id": "unknown", "content": "{}"},
|
|
]
|
|
out = repair_orphan_tool_messages(msgs)
|
|
assert "tool_call_id" not in out[1] or out[1].get("tool_call_id") in ("",)
|
|
|
|
|
|
def test_apply_replay_policy_full_pipeline() -> None:
|
|
policy = resolve_replay_policy("https://example.com/v1", "mimo-v2-omni")
|
|
assert policy.enabled
|
|
assert policy.sanitize_tool_call_ids
|
|
msgs = [
|
|
{"role": "assistant", "content": "", "tool_calls": [{"id": "weird|id:here", "type": "function", "function": {"name": "t", "arguments": "{}"}}]},
|
|
{"role": "tool", "tool_call_id": "weird|id:here", "content": "{}"},
|
|
]
|
|
out = apply_replay_policy_to_messages(msgs, policy)
|
|
assert out[0]["tool_calls"][0]["id"] == out[1]["tool_call_id"]
|