oclaw/tests/test_tool_batch_partition.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

39 lines
1.4 KiB
Python

from __future__ import annotations
from runtime.chat.tool_runtime import partition_tool_use_batches
from svc.llm.chat_models import LLMToolCall
from 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]