[Bugfix][Gemma4] Fix infinite loop and array boundary issues in tool parser (#41991)
Signed-off-by: David Oy <david.oy@baseten.co> Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -135,6 +135,11 @@ class TestParseGemma4Args:
|
||||
result = _parse_gemma4_args('name:<|"|>test<|"|>,flag:', partial=True)
|
||||
assert result == {"name": "test"}
|
||||
|
||||
@pytest.mark.timeout(5)
|
||||
def test_malformed_partial_array(self):
|
||||
result = _parse_gemma4_args(":[t:[]")
|
||||
assert isinstance(result, dict)
|
||||
|
||||
|
||||
class TestParseGemma4Array:
|
||||
def test_string_array(self):
|
||||
@@ -149,6 +154,16 @@ class TestParseGemma4Array:
|
||||
result = _parse_gemma4_array("42,true,3.14")
|
||||
assert result == [42, True, 3.14]
|
||||
|
||||
@pytest.mark.timeout(5)
|
||||
def test_string_element_with_closing_bracket(self):
|
||||
result = _parse_gemma4_array('[<|"|>a]b<|"|>,<|"|>c<|"|>],<|"|>tail<|"|>')
|
||||
assert result == [["a]b", "c"], "tail"]
|
||||
|
||||
@pytest.mark.timeout(5)
|
||||
def test_stray_closing_bracket(self):
|
||||
result = _parse_gemma4_array("42,]trailing")
|
||||
assert result == [42]
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Non-streaming extraction tests
|
||||
|
||||
Reference in New Issue
Block a user