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

27 lines
1.2 KiB
Python

from __future__ import annotations
from svc.llm.transports.anthropic_messages import parse_anthropic_stream_events
def test_anthropic_stream_parses_text_and_tool_use() -> None:
events = [
{"type": "message_start"},
{"type": "content_block_start", "content_block": {"type": "text", "text": ""}},
{"type": "content_block_delta", "delta": {"type": "text_delta", "text": "Hi "}},
{"type": "content_block_delta", "delta": {"type": "text_delta", "text": "there"}},
{"type": "content_block_stop"},
{"type": "content_block_start", "content_block": {"type": "tool_use", "id": "toolu_1", "name": "query_route", "input": {}}},
{"type": "content_block_delta", "delta": {"type": "input_json_delta", "partial_json": "{\"destination\":\"1.1.1.1\"}"}},
{"type": "content_block_stop"},
{"type": "message_stop"},
]
buf: list[str] = []
text, tool_calls = parse_anthropic_stream_events(events, on_token=buf.append)
assert text == "Hi there"
assert "".join(buf) == "Hi there"
assert len(tool_calls) == 1
tc = tool_calls[0]
assert tc.id == "toolu_1"
assert tc.name == "query_route"
assert tc.arguments.get("destination") == "1.1.1.1"