diff --git a/tests/tool_parsers/test_qwen3coder_tool_parser.py b/tests/tool_parsers/test_qwen3coder_tool_parser.py index ac770ff8e5b..1f5e51412b9 100644 --- a/tests/tool_parsers/test_qwen3coder_tool_parser.py +++ b/tests/tool_parsers/test_qwen3coder_tool_parser.py @@ -1300,6 +1300,73 @@ def test_streaming_multi_param_single_chunk(qwen3_tool_parser, qwen3_tokenizer): assert args["unit"] == "fahrenheit" +def test_streaming_complete_tool_call_single_delta(qwen3_tool_parser): + """Regression: one delta may contain a complete tool call.""" + request = ChatCompletionRequest(model=MODEL, messages=[]) + + from tests.tool_parsers.utils import ( + run_tool_extraction_streaming, + ) + + reconstructor = run_tool_extraction_streaming( + qwen3_tool_parser, + [ + ( + "\n" + "\n" + "\nDallas\n\n" + "\nTX\n\n" + "\n" + "" + ) + ], + request, + assert_one_tool_per_delta=False, + ) + + assert len(reconstructor.tool_calls) == 1 + assert reconstructor.tool_calls[0].function.name == "get_current_weather" + args = json.loads(reconstructor.tool_calls[0].function.arguments) + assert args == {"city": "Dallas", "state": "TX"} + + +def test_streaming_next_tool_call_starts_in_close_delta(qwen3_tool_parser): + """Regression: a close delta may also contain the next tool call.""" + request = ChatCompletionRequest(model=MODEL, messages=[]) + + from tests.tool_parsers.utils import ( + run_tool_extraction_streaming, + ) + + reconstructor = run_tool_extraction_streaming( + qwen3_tool_parser, + [ + "\n", + "\n", + "\nDallas\n\n", + "\nTX\n\n", + "", + ( + "\n\n" + "\n" + "\n" + "\nOrlando\n\n" + "\nFL\n\n" + "\n" + "" + ), + ], + request, + assert_one_tool_per_delta=False, + ) + + assert len(reconstructor.tool_calls) == 2 + first_args = json.loads(reconstructor.tool_calls[0].function.arguments) + second_args = json.loads(reconstructor.tool_calls[1].function.arguments) + assert first_args == {"city": "Dallas", "state": "TX"} + assert second_args == {"city": "Orlando", "state": "FL"} + + def test_no_double_serialization_string_args(qwen3_tool_parser): """Regression: string arguments must not be double-serialized (PR #35615).""" tools = [