From bdb52bdef5ae199811642345b264dec808d284e2 Mon Sep 17 00:00:00 2001 From: worldmozara Date: Tue, 14 Jul 2026 22:22:22 +0800 Subject: [PATCH] test/agent: cover merge_stream_tool_calls accumulation --- tests/test_agent/test_stream_merge.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/test_agent/test_stream_merge.py diff --git a/tests/test_agent/test_stream_merge.py b/tests/test_agent/test_stream_merge.py new file mode 100644 index 0000000..f902324 --- /dev/null +++ b/tests/test_agent/test_stream_merge.py @@ -0,0 +1,25 @@ +from __future__ import annotations + +from plyngent.lmproto.openai_compatible.client import merge_stream_tool_calls + + +def test_merge_stream_tool_calls_accumulates_arguments() -> None: + lines = [ + b'{"choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"id":"c1","type":"function","function":{"name":"add","arguments":""}}]}}]}', + b'{"choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"function":{"arguments":"{\\"a\\":"}}]}}]}', + b'{"choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"function":{"arguments":"1}"}}]},"finish_reason":"tool_calls"}]}', + ] + calls = merge_stream_tool_calls(lines) + assert len(calls) == 1 + assert calls[0].id == "c1" + assert calls[0].function.name == "add" + assert calls[0].function.arguments == '{"a":1}' + + +def test_merge_stream_tool_calls_multiple_indices() -> None: + lines = [ + b'{"choices":[{"delta":{"tool_calls":[{"index":0,"id":"a","type":"function","function":{"name":"f1","arguments":"{}"}}]}}]}', + b'{"choices":[{"delta":{"tool_calls":[{"index":1,"id":"b","type":"function","function":{"name":"f2","arguments":"[]"}}]}}]}', + ] + calls = merge_stream_tool_calls(lines) + assert {c.function.name for c in calls} == {"f1", "f2"}