oclaw/tests/test_tool_batch_partition.py
oliver 4a23b715a2 重构仓库目录为统一的 runtime 分层并清理历史 openclaw 残留。
本次迁移将网关/通道/工具/技能/脚本与协议资源集中到新结构,统一路径常量与脚本转发机制,减少顶层噪音并保证运行与测试行为一致。

Made-with: Cursor
2026-04-25 01:24:23 +08:00

39 lines
1.4 KiB
Python

from __future__ import annotations
from oclaw.runtime.chat.tool_runtime import partition_tool_use_batches
from oclaw.platform.llm.chat_models import LLMToolCall
from oclaw.runtime.tools.base import ToolRegistry, ToolSpec
def _spec(name: str, *, read_only: bool) -> ToolSpec:
return ToolSpec(
name=name,
description="t",
parameters={"type": "object", "properties": {}},
handler=lambda _a: {"ok": True},
read_only=read_only,
)
def test_partition_merges_consecutive_read_only() -> None:
reg = ToolRegistry([_spec("a", read_only=True), _spec("b", read_only=True), _spec("c", read_only=False)])
calls = [
LLMToolCall(id="1", name="a", arguments={}),
LLMToolCall(id="2", name="b", arguments={}),
LLMToolCall(id="3", name="c", arguments={}),
LLMToolCall(id="4", name="a", arguments={}),
]
batches = partition_tool_use_batches(calls, reg)
assert [len(b) for b in batches] == [2, 1, 1]
assert [tc.id for b in batches for tc in b] == ["1", "2", "3", "4"]
def test_partition_unknown_tool_is_sequential_only() -> None:
reg = ToolRegistry([_spec("a", read_only=True)])
calls = [
LLMToolCall(id="1", name="a", arguments={}),
LLMToolCall(id="2", name="missing", arguments={}),
LLMToolCall(id="3", name="a", arguments={}),
]
batches = partition_tool_use_batches(calls, reg)
assert [len(b) for b in batches] == [1, 1, 1]