v3.11.8: fix _XML_TC_RE regex bug, fix test paths, 177/177 tests pass

This commit is contained in:
Roman | RyzenAdvanced
2026-05-26 20:21:31 +04:00
Unverified
parent 66fe3c07a3
commit 142a0a5859
3 changed files with 12 additions and 14 deletions

Binary file not shown.

View File

@@ -2350,7 +2350,7 @@ def _normalize_tool_args(raw_args):
except json.JSONDecodeError:
return raw_args
_XML_TC_RE = re.compile(r'exec_command(.*?)</invoke>', re.DOTALL)
_XML_TC_RE = re.compile(r'<invoke><(\w+)(?:_command)?>(.*?)</\1(?:_command)?></invoke>', re.DOTALL)
_XML_ARG_VALUE_RE = re.compile(r'</?arg_value>\s*')
_PAREN_TC_RE = re.compile(

View File

@@ -6,6 +6,7 @@ Uses only stdlib unittest + unittest.mock (zero pip dependencies).
"""
import json
import os
import sys
import time
import unittest
@@ -19,7 +20,7 @@ import importlib
_spec = importlib.util.spec_from_file_location(
"translate_proxy",
r"C:\dev\Codex-Launcher---Any-AI-Porovider\src\translate-proxy.py",
os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "src", "translate-proxy.py"),
)
tp = importlib.util.module_from_spec(_spec)
_spec.loader.exec_module(tp)
@@ -121,36 +122,33 @@ class TestExtractXmlToolCalls(unittest.TestCase):
self.assertEqual(tp._extract_xml_tool_calls("just plain text"), [])
def test_single_tool_call(self):
# Regex: <tool_call>(\w+)(.*?)</tool_call>
# Format: <tool_call>NAME>CONTENT</tool_call>
text = '<tool_call>bash>echo hi</tool_call>'
text = '<invoke><exec_command>echo hi</exec_command></invoke>'
results = tp._extract_xml_tool_calls(text)
self.assertEqual(len(results), 1)
self.assertEqual(results[0]["name"], "bash")
self.assertEqual(results[0]["name"], "exec_command")
self.assertIn("call_id", results[0])
self.assertTrue(results[0]["call_id"].startswith("xml_"))
def test_multiple_tool_calls(self):
text = (
'<tool_call>bash>echo hi</tool_call>'
'<tool_call>edit>test.py</tool_call>'
'<invoke><exec_command>echo hi</exec_command></invoke>'
'<invoke><exec_command>test.py</exec_command></invoke>'
)
results = tp._extract_xml_tool_calls(text)
self.assertEqual(len(results), 2)
self.assertEqual(results[0]["name"], "bash")
self.assertEqual(results[1]["name"], "edit")
self.assertEqual(results[0]["name"], "exec_command")
self.assertEqual(results[1]["name"], "exec_command")
def test_json_args(self):
text = '<tool_call>tool>{"key": "value"}</tool_call>'
text = '<invoke><exec_command>{"key": "value"}</exec_command></invoke>'
results = tp._extract_xml_tool_calls(text)
self.assertEqual(len(results), 1)
self.assertEqual(results[0]["name"], "tool")
self.assertEqual(results[0]["name"], "exec_command")
args = json.loads(results[0]["args"])
# JSON parsing of XML content may vary - just check result exists
self.assertIn("args", results[0])
def test_code_fenced_args(self):
text = '<tool_call>tool>{"a": 1}</tool_call>'
text = '<invoke><exec_command>{"a": 1}</exec_command></invoke>'
results = tp._extract_xml_tool_calls(text)
self.assertEqual(len(results), 1)