mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-17 22:00:50 +08:00
初始化:独立 oclaw 仓库首提交
- 在 oclaw/ 下重新初始化 Git 仓库 - 补齐子仓库 .gitignore,避免提交本地运行态数据(_local、node_modules、logs 等) - 提交当前工程代码与配置 Made-with: Cursor
This commit is contained in:
commit
ba3836f00f
579 changed files with 83112 additions and 0 deletions
50
tests/test_replay_tool_call_id.py
Normal file
50
tests/test_replay_tool_call_id.py
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
"""Regression tests for OpenClaw-style tool_call_id replay (see src/platform/llm/tool_call_id.py)."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from oclaw.platform.llm.replay_policy import apply_replay_policy_to_messages, resolve_replay_policy
|
||||
from oclaw.platform.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"]
|
||||
Loading…
Add table
Add a link
Reference in a new issue