fix(memory): guard against malformed image_url in parse_vision_messages (#5631)
This commit is contained in:
@@ -96,6 +96,24 @@ class TestParseVisionMessages:
|
||||
result = parse_vision_messages(messages, llm=None)
|
||||
assert result == messages
|
||||
|
||||
def test_malformed_image_dict_raises_value_error(self):
|
||||
# A malformed image part (missing the nested url) used to raise an
|
||||
# uncaught KeyError that aborted add(); it should raise a clear ValueError.
|
||||
mock_llm = Mock()
|
||||
messages = [{"role": "user", "content": {"type": "image_url", "image_url": {}}}]
|
||||
with pytest.raises(ValueError, match=r"missing image_url\.url"):
|
||||
parse_vision_messages(messages, llm=mock_llm)
|
||||
mock_llm.generate_response.assert_not_called()
|
||||
|
||||
def test_none_image_url_raises_value_error(self):
|
||||
# image_url present but None (or any non-dict) must also raise the clear
|
||||
# ValueError, not an AttributeError from calling .get() on None.
|
||||
mock_llm = Mock()
|
||||
messages = [{"role": "user", "content": {"type": "image_url", "image_url": None}}]
|
||||
with pytest.raises(ValueError, match=r"missing image_url\.url"):
|
||||
parse_vision_messages(messages, llm=mock_llm)
|
||||
mock_llm.generate_response.assert_not_called()
|
||||
|
||||
|
||||
class TestRemoveSpacesFromEntities:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user