v3.11.8: fix _XML_TC_RE regex bug, fix test paths, 177/177 tests pass
This commit is contained in:
Binary file not shown.
@@ -2350,7 +2350,7 @@ def _normalize_tool_args(raw_args):
|
|||||||
except json.JSONDecodeError:
|
except json.JSONDecodeError:
|
||||||
return raw_args
|
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*')
|
_XML_ARG_VALUE_RE = re.compile(r'</?arg_value>\s*')
|
||||||
|
|
||||||
_PAREN_TC_RE = re.compile(
|
_PAREN_TC_RE = re.compile(
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ Uses only stdlib unittest + unittest.mock (zero pip dependencies).
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import unittest
|
import unittest
|
||||||
@@ -19,7 +20,7 @@ import importlib
|
|||||||
|
|
||||||
_spec = importlib.util.spec_from_file_location(
|
_spec = importlib.util.spec_from_file_location(
|
||||||
"translate_proxy",
|
"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)
|
tp = importlib.util.module_from_spec(_spec)
|
||||||
_spec.loader.exec_module(tp)
|
_spec.loader.exec_module(tp)
|
||||||
@@ -121,36 +122,33 @@ class TestExtractXmlToolCalls(unittest.TestCase):
|
|||||||
self.assertEqual(tp._extract_xml_tool_calls("just plain text"), [])
|
self.assertEqual(tp._extract_xml_tool_calls("just plain text"), [])
|
||||||
|
|
||||||
def test_single_tool_call(self):
|
def test_single_tool_call(self):
|
||||||
# Regex: <tool_call>(\w+)(.*?)</tool_call>
|
text = '<invoke><exec_command>echo hi</exec_command></invoke>'
|
||||||
# Format: <tool_call>NAME>CONTENT</tool_call>
|
|
||||||
text = '<tool_call>bash>echo hi</tool_call>'
|
|
||||||
results = tp._extract_xml_tool_calls(text)
|
results = tp._extract_xml_tool_calls(text)
|
||||||
self.assertEqual(len(results), 1)
|
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.assertIn("call_id", results[0])
|
||||||
self.assertTrue(results[0]["call_id"].startswith("xml_"))
|
self.assertTrue(results[0]["call_id"].startswith("xml_"))
|
||||||
|
|
||||||
def test_multiple_tool_calls(self):
|
def test_multiple_tool_calls(self):
|
||||||
text = (
|
text = (
|
||||||
'<tool_call>bash>echo hi</tool_call>'
|
'<invoke><exec_command>echo hi</exec_command></invoke>'
|
||||||
'<tool_call>edit>test.py</tool_call>'
|
'<invoke><exec_command>test.py</exec_command></invoke>'
|
||||||
)
|
)
|
||||||
results = tp._extract_xml_tool_calls(text)
|
results = tp._extract_xml_tool_calls(text)
|
||||||
self.assertEqual(len(results), 2)
|
self.assertEqual(len(results), 2)
|
||||||
self.assertEqual(results[0]["name"], "bash")
|
self.assertEqual(results[0]["name"], "exec_command")
|
||||||
self.assertEqual(results[1]["name"], "edit")
|
self.assertEqual(results[1]["name"], "exec_command")
|
||||||
|
|
||||||
def test_json_args(self):
|
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)
|
results = tp._extract_xml_tool_calls(text)
|
||||||
self.assertEqual(len(results), 1)
|
self.assertEqual(len(results), 1)
|
||||||
self.assertEqual(results[0]["name"], "tool")
|
self.assertEqual(results[0]["name"], "exec_command")
|
||||||
args = json.loads(results[0]["args"])
|
args = json.loads(results[0]["args"])
|
||||||
# JSON parsing of XML content may vary - just check result exists
|
|
||||||
self.assertIn("args", results[0])
|
self.assertIn("args", results[0])
|
||||||
|
|
||||||
def test_code_fenced_args(self):
|
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)
|
results = tp._extract_xml_tool_calls(text)
|
||||||
self.assertEqual(len(results), 1)
|
self.assertEqual(len(results), 1)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user