@@ -3160,6 +3160,53 @@ def test_deepseek_streaming_keeps_markdown_fences(
31603160 assert parser_cls ().detect_and_parse (text , sample_tools ).normal_text == text
31613161
31623162
3163+ def _dsml_tool_call (tag_prefix : str , block_name : str , name : str ,
3164+ string_arguments : dict [str , str ]) -> str :
3165+ """A tool call as the DSML encoders render it: each string value verbatim."""
3166+ parameters = "\n " .join (
3167+ f'<{ tag_prefix } parameter name="{ key } " string="true">{ value } '
3168+ f"</{ tag_prefix } parameter>" for key , value in string_arguments .items ())
3169+ return (f"<{ tag_prefix } { block_name } >\n "
3170+ f'<{ tag_prefix } invoke name="{ name } ">\n { parameters } \n '
3171+ f"</{ tag_prefix } invoke>\n </{ tag_prefix } { block_name } >" )
3172+
3173+
3174+ @pytest .mark .parametrize ("parser_cls,tag_prefix,block_name" , [
3175+ (DeepSeekV32Parser , "|DSML|" , "function_calls" ),
3176+ (DeepSeekV4Parser , "|DSML|" , "tool_calls" ),
3177+ (DeepSeekV41Parser , "|DSML| " , "calls" ),
3178+ ])
3179+ @pytest .mark .parametrize ("streaming" , [False , True ])
3180+ def test_dsml_string_parameter_values_are_kept_as_written (
3181+ sample_tools : list [ChatCompletionToolsParam ],
3182+ parser_cls : type [BaseToolParser ], tag_prefix : str , block_name : str ,
3183+ streaming : bool ) -> None :
3184+ """A string value's leading and trailing whitespace is part of the value.
3185+
3186+ An edit's ``old_string`` must match the file including its indentation,
3187+ and a written file keeps its last newline.
3188+ """
3189+ arguments = {
3190+ "location" : " indented line\n second line" ,
3191+ "unit" : "file content\n " ,
3192+ }
3193+ text = _dsml_tool_call (tag_prefix , block_name , "get_weather" , arguments )
3194+
3195+ parser = parser_cls ()
3196+ if streaming :
3197+ results = [
3198+ parser .parse_streaming_increment (text [i :i + 7 ], sample_tools )
3199+ for i in range (0 , len (text ), 7 )
3200+ ]
3201+ calls = [call for result in results for call in result .calls ]
3202+ else :
3203+ calls = parser .detect_and_parse (text , sample_tools ).calls
3204+
3205+ assert [call .name for call in calls if call .name ] == ["get_weather" ]
3206+ assert json .loads ("" .join (call .parameters or ""
3207+ for call in calls )) == arguments
3208+
3209+
31633210@pytest .mark .parametrize (
31643211 "parser_cls, tool_call_text" ,
31653212 [
0 commit comments