[Frontend] Migrate Responses harmony input validation to VLLMValidationError (#55701)

Signed-off-by: shaolila <shaolila@buaa.edu.cn>
Co-authored-by: shaolila <shaolila@buaa.edu.cn>
This commit is contained in:
Adababy
2026-09-07 13:30:11 +00:00
committed by GitHub
co-authored by shaolila
parent b339d75a41
commit 167858ea17
3 changed files with 36 additions and 7 deletions
@@ -16,6 +16,7 @@ from vllm.entrypoints.openai.responses.harmony import (
harmony_to_response_output,
response_previous_input_to_harmony,
)
from vllm.exceptions import VLLMValidationError
class TestResponsePreviousInputToHarmony:
@@ -92,6 +93,16 @@ class TestResponsePreviousInputToHarmony:
assert messages[0].author.name == "functions.empty_tool"
assert messages[0].content[0].text == ""
def test_chat_message_without_role_raises_validation_error(self):
"""A chat-format message missing the 'role' key is invalid input."""
chat_msg = {"content": "hello, no role here"}
with pytest.raises(
VLLMValidationError, match="Message has no 'role' key"
) as exc_info:
response_previous_input_to_harmony(chat_msg)
assert exc_info.value.parameter == "input"
class TestHarmonyToResponseOutput:
"""Tests for harmony_to_response_output function."""
@@ -15,6 +15,7 @@ from openai.types.responses.response_reasoning_item import (
from openai_harmony import DeveloperContent, Role
from vllm.entrypoints.openai.responses.harmony import response_input_to_harmony
from vllm.exceptions import VLLMValidationError
# ---------------------------------------------------------------------------
# Shared fixtures
@@ -252,7 +253,9 @@ class TestResponseInputToHarmonyMessage:
assert msg.author.name == "functions.get_weather"
def test_function_call_output_raises_if_no_matching_call(self):
with pytest.raises(ValueError, match="No call message found for"):
with pytest.raises(
VLLMValidationError, match="No call message found for"
) as exc_info:
response_input_to_harmony(
{
"type": "function_call_output",
@@ -261,21 +264,26 @@ class TestResponseInputToHarmonyMessage:
},
prev_responses=[_PREV_CALL],
)
assert exc_info.value.parameter == "input"
def test_function_call_output_raises_on_empty_prev_responses(self):
with pytest.raises(ValueError, match="No call message found for"):
with pytest.raises(
VLLMValidationError, match="No call message found for"
) as exc_info:
response_input_to_harmony(
{"type": "function_call_output", "call_id": "call_test", "output": "x"},
prev_responses=[],
)
assert exc_info.value.parameter == "input"
# -----------------------------------------------------------------------
# Error cases
# -----------------------------------------------------------------------
def test_unknown_type_raises_value_error(self):
with pytest.raises(ValueError, match="Unknown input type"):
def test_unknown_type_raises_validation_error(self):
with pytest.raises(VLLMValidationError, match="Unknown input type") as exc_info:
response_input_to_harmony(
{"type": "image_url", "url": "https://example.com/img.png"},
prev_responses=[],
)
assert exc_info.value.parameter == "input"