[CI] Ignore ruff D209, rejoin the docstrings it split, and silence incompatible-rule warnings (#57212)
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
1085b64425
commit
651a88c09a
@@ -241,8 +241,7 @@ class TestToolResultContent:
|
||||
self, tool_result_content
|
||||
) -> AnthropicMessagesRequest:
|
||||
"""Build a request with assistant tool_use followed by user
|
||||
tool_result.
|
||||
"""
|
||||
tool_result."""
|
||||
return _make_request(
|
||||
[
|
||||
{
|
||||
@@ -327,8 +326,7 @@ class TestToolResultContent:
|
||||
|
||||
def test_tool_result_with_text_and_image(self):
|
||||
"""Mixed text+image tool_result: text in tool msg, image in user
|
||||
msg.
|
||||
"""
|
||||
msg."""
|
||||
request = self._make_tool_result_request(
|
||||
[
|
||||
{"type": "text", "text": "Here is the screenshot"},
|
||||
@@ -425,8 +423,7 @@ class TestToolResultContent:
|
||||
class TestAttributionHeaderStripping:
|
||||
def test_billing_header_stripped_from_system(self):
|
||||
"""Claude Code's x-anthropic-billing-header block should be
|
||||
stripped to preserve prefix caching.
|
||||
"""
|
||||
stripped to preserve prefix caching."""
|
||||
request = _make_request(
|
||||
[{"role": "user", "content": "Hello"}],
|
||||
system=[
|
||||
@@ -1150,8 +1147,7 @@ class TestMessageStreamConverterToolUseContentBuffering:
|
||||
async def test_buffered_content_flushed_on_done_without_usage_chunk(self):
|
||||
"""Content buffered during tool_use must be emitted even if the
|
||||
stream jumps straight from finish_reason to [DONE], skipping the
|
||||
empty-choices usage chunk.
|
||||
"""
|
||||
empty-choices usage chunk."""
|
||||
|
||||
async def sse_input():
|
||||
yield _make_stream_chunk(
|
||||
@@ -1255,8 +1251,7 @@ class TestStreamingCacheUsageSemantics:
|
||||
async def test_streaming_cache_fields_absent_then_populated(self):
|
||||
"""First chunk lacks prompt_tokens_details (vLLM contract);
|
||||
message_start omits cache fields. The final chunk carries
|
||||
prompt_tokens_details, so message_delta carries resolved values.
|
||||
"""
|
||||
prompt_tokens_details, so message_delta carries resolved values."""
|
||||
|
||||
async def sse_input():
|
||||
yield _make_stream_chunk(
|
||||
@@ -1301,8 +1296,7 @@ class TestStreamingCacheUsageSemantics:
|
||||
@pytest.mark.asyncio
|
||||
async def test_streaming_no_cache_hit(self):
|
||||
"""When the final chunk reports cached_tokens=0, message_delta carries
|
||||
cache fields = 0 (cache miss); message_start still omits them.
|
||||
"""
|
||||
cache fields = 0 (cache miss); message_start still omits them."""
|
||||
|
||||
async def sse_input():
|
||||
yield _make_stream_chunk(
|
||||
@@ -1343,8 +1337,7 @@ class TestStreamingCacheUsageSemantics:
|
||||
@pytest.mark.asyncio
|
||||
async def test_streaming_no_prompt_tokens_details_at_all(self):
|
||||
"""If --enable-prompt-tokens-details is off, no chunk carries cache
|
||||
info; both message_start and message_delta omit cache fields.
|
||||
"""
|
||||
info; both message_start and message_delta omit cache fields."""
|
||||
|
||||
async def sse_input():
|
||||
yield _make_stream_chunk(
|
||||
@@ -1465,8 +1458,7 @@ class TestMessagesFullConverter:
|
||||
class TestCacheSalt:
|
||||
def test_cache_salt_passed_through(self):
|
||||
"""cache_salt on the Anthropic request reaches the converted
|
||||
ChatCompletionRequest so prefix-cache isolation works via /v1/messages.
|
||||
"""
|
||||
ChatCompletionRequest so prefix-cache isolation works via /v1/messages."""
|
||||
request = _make_request(
|
||||
[{"role": "user", "content": "Hello"}],
|
||||
cache_salt="tenant-abc-secret-salt",
|
||||
@@ -1671,8 +1663,7 @@ class TestClientErrorResponses:
|
||||
@staticmethod
|
||||
def _conversion_error() -> ValidationError:
|
||||
"""A real pydantic ValidationError like the one ChatCompletionRequest
|
||||
construction raises when Anthropic input violates the OpenAI schema.
|
||||
"""
|
||||
construction raises when Anthropic input violates the OpenAI schema."""
|
||||
|
||||
class _StubRequest(BaseModel):
|
||||
stop: Annotated[list[str], Field(max_length=4)] | None = None
|
||||
@@ -1683,8 +1674,7 @@ class TestClientErrorResponses:
|
||||
|
||||
def test_validation_error_returns_bad_request(self):
|
||||
"""A pydantic ValidationError during Anthropic->OpenAI conversion is
|
||||
surfaced as a 400 BadRequestError, not a 500.
|
||||
"""
|
||||
surfaced as a 400 BadRequestError, not a 500."""
|
||||
handler = MagicMock(spec=AnthropicServingMessages)
|
||||
handler.create_messages.side_effect = self._conversion_error()
|
||||
|
||||
|
||||
@@ -87,8 +87,7 @@ def _make_chunk(
|
||||
citations: list[Any] | None = None,
|
||||
) -> str:
|
||||
"""Build the ``data: {...}\\n\\n`` SSE frame the production code
|
||||
consumes.
|
||||
"""
|
||||
consumes."""
|
||||
delta: dict[str, Any] = {}
|
||||
if role is not None:
|
||||
delta["role"] = role
|
||||
@@ -136,8 +135,7 @@ async def _stream_from(items: list[str]) -> AsyncGenerator[str, None]:
|
||||
|
||||
async def _drain(serving: CohereServingChatV2, items: list[str]) -> list[str]:
|
||||
"""Drive ``_chat_completion_stream_to_v2`` over ``items`` and collect
|
||||
the emitted SSE frames.
|
||||
"""
|
||||
the emitted SSE frames."""
|
||||
request = CohereChatV2Request(
|
||||
model="m", messages=[{"role": "user", "content": "hi"}], stream=True
|
||||
)
|
||||
|
||||
@@ -50,8 +50,7 @@ def update_admission_stats_worker(listen_address, sock, args, client_config):
|
||||
# importable by `multiprocessing.spawn` (no closures, no nesting).
|
||||
def defer_addresses_stub_worker(listen_address, sock, args, client_config):
|
||||
"""Bind ROUTER/PULL with a kernel-assigned port, report the actual
|
||||
endpoints back via the pipe, then exit.
|
||||
"""
|
||||
endpoints back via the pipe, then exit."""
|
||||
ctx = zmq.Context()
|
||||
try:
|
||||
in_sock = make_zmq_socket(
|
||||
@@ -358,8 +357,7 @@ def test_external_process_monitoring(api_server_args):
|
||||
def test_gather_actual_addresses_end_to_end():
|
||||
"""Each child binds ROUTER/PULL with a kernel-picked port and reports
|
||||
the bound endpoints back via its per-child pipe; the manager surfaces
|
||||
them via :py:meth:`gather_actual_addresses`.
|
||||
"""
|
||||
them via :py:meth:`gather_actual_addresses`."""
|
||||
host = "127.0.0.1"
|
||||
num_servers = 4
|
||||
|
||||
@@ -409,8 +407,7 @@ def test_gather_actual_addresses_end_to_end():
|
||||
@pytest.mark.timeout(30)
|
||||
def test_gather_actual_addresses_child_crash_before_report():
|
||||
"""A child that exits before sending its endpoints must surface a
|
||||
clear ``RuntimeError`` rather than hang or return ``None`` slots.
|
||||
"""
|
||||
clear ``RuntimeError`` rather than hang or return ``None`` slots."""
|
||||
host = "127.0.0.1"
|
||||
num_servers = 2
|
||||
placeholder_inputs = [
|
||||
@@ -447,8 +444,7 @@ def test_gather_actual_addresses_child_crash_before_report():
|
||||
|
||||
def test_rust_frontend_launch_log_redacts_credentials(monkeypatch, caplog):
|
||||
"""The Rust frontend command carries every non-default arg as JSON.
|
||||
Credentials must not reach the log line.
|
||||
"""
|
||||
Credentials must not reach the log line."""
|
||||
import subprocess as subprocess_mod
|
||||
|
||||
from vllm.entrypoints.launchers.cli_args import make_arg_parser
|
||||
|
||||
@@ -186,8 +186,7 @@ def test_enable_auto_choice_fails_with_enable_reasoning(serve_parser):
|
||||
|
||||
def test_passes_with_reasoning_parser(serve_parser):
|
||||
"""Ensure validation passes if reasoning is enabled
|
||||
with a reasoning parser
|
||||
"""
|
||||
with a reasoning parser"""
|
||||
args = serve_parser.parse_args(
|
||||
args=[
|
||||
"--reasoning-parser",
|
||||
@@ -382,8 +381,7 @@ def test_default_chat_template_kwargs_invalid_json(serve_parser):
|
||||
)
|
||||
def test_served_model_name_parsing(tmp_path, vllm_parser, args, raises):
|
||||
"""Ensure that users don't misuse --served-model-name and end up with the default
|
||||
model tag instead of the one they intended to serve.
|
||||
"""
|
||||
model tag instead of the one they intended to serve."""
|
||||
# Call the serve subparser
|
||||
args.insert(0, "serve")
|
||||
# Create a dummy config file if the test case includes it
|
||||
|
||||
+1
-2
@@ -2,8 +2,7 @@
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
"""E2E test for mixing `prompt_embeds` with `audio_embeds` in a single
|
||||
Chat Completions request.
|
||||
"""
|
||||
Chat Completions request."""
|
||||
|
||||
import json
|
||||
|
||||
|
||||
+1
-2
@@ -68,8 +68,7 @@ async def client(server):
|
||||
def image_url() -> str:
|
||||
"""Stable real image as a data URL, kept identical across both the
|
||||
text and prompt_embeds requests so any output difference must come from
|
||||
how the text content is delivered.
|
||||
"""
|
||||
how the text content is delivered."""
|
||||
return encode_image_url(ImageAsset("stop_sign").pil_image)
|
||||
|
||||
|
||||
|
||||
@@ -145,8 +145,7 @@ def describe_image_messages(
|
||||
) -> list[dict]:
|
||||
"""Build the system + user messages used by the completions-with-image
|
||||
family of tests. *extra_image_fields* is merged into the top-level
|
||||
image content block (for uuid / bad-key tests).
|
||||
"""
|
||||
image content block (for uuid / bad-key tests)."""
|
||||
image_block: dict = {
|
||||
"type": "image_url",
|
||||
"image_url": {"url": image_url},
|
||||
@@ -176,8 +175,7 @@ async def complete_and_check(
|
||||
temperature: float = 0.0,
|
||||
) -> str:
|
||||
"""Run a chat completion and assert the output is non-empty.
|
||||
Returns the content string.
|
||||
"""
|
||||
Returns the content string."""
|
||||
chat_completion = await client.chat.completions.create(
|
||||
model=model_name,
|
||||
messages=messages,
|
||||
|
||||
@@ -465,8 +465,7 @@ def test_system_message_warns_on_video(video_content):
|
||||
def test_json_schema_response_format_missing_schema():
|
||||
"""When response_format type is 'json_schema' but the json_schema field
|
||||
is not provided, request construction should raise a validation error
|
||||
so the API returns 400 instead of 500.
|
||||
"""
|
||||
so the API returns 400 instead of 500."""
|
||||
with pytest.raises(Exception, match="json_schema.*must be provided"):
|
||||
ChatCompletionRequest(
|
||||
model=MODEL_NAME,
|
||||
@@ -520,8 +519,7 @@ def test_structured_outputs_structural_tag_invalid(structural_tag):
|
||||
@pytest.mark.parametrize("field_name", ["prompt_logprobs", "top_logprobs"])
|
||||
def test_non_numeric_logprobs_rejected(field_name):
|
||||
"""A non-numeric logprobs value must be a clean 400 validation error, not a
|
||||
TypeError from the mode='before' comparison (which surfaces as HTTP 500).
|
||||
"""
|
||||
TypeError from the mode='before' comparison (which surfaces as HTTP 500)."""
|
||||
with pytest.raises(VLLMValidationError, match=f"`{field_name}` must be an integer"):
|
||||
ChatCompletionRequest(
|
||||
model=MODEL_NAME,
|
||||
|
||||
@@ -81,8 +81,7 @@ async def test_chat_logit_bias_invalid(client):
|
||||
@pytest.mark.asyncio
|
||||
async def test_chat_logit_bias_non_integer_key(client):
|
||||
"""Test that a non-integer logit_bias key is rejected with a clean,
|
||||
informative error instead of a raw 'invalid literal for int()' message.
|
||||
"""
|
||||
informative error instead of a raw 'invalid literal for int()' message."""
|
||||
with pytest.raises(openai.BadRequestError) as excinfo:
|
||||
await client.chat.completions.create(
|
||||
model=MODEL_NAME,
|
||||
@@ -102,8 +101,7 @@ async def test_chat_logit_bias_non_integer_key(client):
|
||||
@pytest.mark.asyncio
|
||||
async def test_chat_logit_bias_non_numeric_value(client):
|
||||
"""Test that a non-numeric logit_bias value is rejected with a message
|
||||
that names the specific offending token, not just a generic TypeError.
|
||||
"""
|
||||
that names the specific offending token, not just a generic TypeError."""
|
||||
with pytest.raises(openai.BadRequestError) as excinfo:
|
||||
await client.chat.completions.create(
|
||||
model=MODEL_NAME,
|
||||
@@ -122,8 +120,7 @@ async def test_chat_logit_bias_non_numeric_value(client):
|
||||
@pytest.mark.asyncio
|
||||
async def test_chat_logit_bias_multiple_non_integer_keys(client):
|
||||
"""Test that ALL invalid logit_bias keys are reported together,
|
||||
not just the first one encountered.
|
||||
"""
|
||||
not just the first one encountered."""
|
||||
with pytest.raises(openai.BadRequestError) as excinfo:
|
||||
await client.chat.completions.create(
|
||||
model=MODEL_NAME,
|
||||
|
||||
@@ -54,8 +54,7 @@ def stop_sign_image_url():
|
||||
async def test_translategemma_extra_lang_code_fields(client: openai.AsyncOpenAI):
|
||||
"""En -> es translation through TranslateGemma's bundled chat template's
|
||||
``text`` content branch, which depends on ``source_lang_code`` /
|
||||
``target_lang_code`` extra fields being preserved on the content part.
|
||||
"""
|
||||
``target_lang_code`` extra fields being preserved on the content part."""
|
||||
completion = await client.chat.completions.create(
|
||||
model=MODEL_NAME,
|
||||
messages=[
|
||||
@@ -99,8 +98,7 @@ async def test_translategemma_image_extra_lang_code_fields(
|
||||
``source_lang_code`` / ``target_lang_code`` extras must survive parsing
|
||||
and end up alongside the ``{"type": "image"}`` placeholder so the
|
||||
template's image branch (``content["type"] == 'image'``) renders the
|
||||
right OCR-translation prompt.
|
||||
"""
|
||||
right OCR-translation prompt."""
|
||||
completion = await client.chat.completions.create(
|
||||
model=MODEL_NAME,
|
||||
messages=[
|
||||
|
||||
@@ -191,8 +191,7 @@ async def test_logprob_token_ids_stream_with_no_top_k(server):
|
||||
async def test_logprob_token_ids_default_behavior_unchanged(server):
|
||||
"""Without `logprob_token_ids`, the response carries the natural top-k
|
||||
most-likely tokens. This guards against the new field accidentally
|
||||
changing the default-path output.
|
||||
"""
|
||||
changing the default-path output."""
|
||||
async with server.get_async_client() as client:
|
||||
resp = await client.chat.completions.create(
|
||||
model=MODEL_NAME,
|
||||
|
||||
@@ -1406,8 +1406,7 @@ async def test_serving_chat_did_set_correct_cache_salt(model_type):
|
||||
@pytest.mark.asyncio
|
||||
async def test_serving_chat_data_parallel_rank_extraction():
|
||||
"""Test that data_parallel_rank is properly extracted from header and
|
||||
passed to engine.
|
||||
"""
|
||||
passed to engine."""
|
||||
mock_engine = MagicMock(spec=AsyncLLM)
|
||||
mock_engine.errored = False
|
||||
mock_engine.model_config = MockModelConfig()
|
||||
@@ -1729,8 +1728,7 @@ class TestServingChatWithHarmony:
|
||||
@pytest.mark.asyncio
|
||||
async def test_system_message_without_tools(self, serving_chat, stream):
|
||||
"""Leading system message produces a developer message with
|
||||
DeveloperContent (# Instructions header).
|
||||
"""
|
||||
DeveloperContent (# Instructions header)."""
|
||||
messages = [
|
||||
{"role": "system", "content": "You are a helpful assistant."},
|
||||
{"role": "user", "content": "Hello"},
|
||||
@@ -1752,8 +1750,7 @@ class TestServingChatWithHarmony:
|
||||
@pytest.mark.asyncio
|
||||
async def test_system_message_with_tools(self, serving_chat, stream, weather_tools):
|
||||
"""Leading system message is folded into the developer message
|
||||
alongside tool definitions.
|
||||
"""
|
||||
alongside tool definitions."""
|
||||
messages = [
|
||||
{"role": "system", "content": "You are a helpful assistant."},
|
||||
{"role": "user", "content": "What's the weather?"},
|
||||
@@ -2168,8 +2165,7 @@ class TestServingChatWithHarmony:
|
||||
@pytest.mark.asyncio
|
||||
async def test_tool_choice_validation_without_parser():
|
||||
"""Test that tool_choice='required' or named tool without tool_parser
|
||||
returns an appropriate error message.
|
||||
"""
|
||||
returns an appropriate error message."""
|
||||
mock_engine = MagicMock(spec=AsyncLLM)
|
||||
mock_engine.errored = False
|
||||
mock_engine.model_config = MockModelConfig()
|
||||
|
||||
@@ -151,8 +151,7 @@ async def client(request, server, server_with_auto_reasoning_config):
|
||||
@pytest.mark.parametrize("client", ["default", "auto_config"], indirect=True)
|
||||
async def test_thinking_token_budget_mixed_requests(client: openai.AsyncOpenAI):
|
||||
"""Test that mixed requests (some with thinking_token_budget, some without)
|
||||
complete successfully without errors.
|
||||
"""
|
||||
complete successfully without errors."""
|
||||
response_with_budget = await client.chat.completions.create(
|
||||
model=MODEL_NAME,
|
||||
messages=MESSAGES,
|
||||
|
||||
@@ -521,8 +521,7 @@ async def test_completion_error_stream():
|
||||
def test_json_schema_response_format_missing_schema():
|
||||
"""When response_format type is 'json_schema' but the json_schema field
|
||||
is not provided, request construction should raise a validation error
|
||||
so the API returns 400 instead of 500.
|
||||
"""
|
||||
so the API returns 400 instead of 500."""
|
||||
with pytest.raises(Exception, match="json_schema.*must be provided"):
|
||||
CompletionRequest(
|
||||
model=MODEL_NAME,
|
||||
@@ -585,8 +584,7 @@ def test_negative_prompt_token_ids_flat():
|
||||
def test_logprobs_minus_one_allowed():
|
||||
"""logprobs=-1 means "return all logprobs". The sampling layer and the chat
|
||||
top_logprobs / prompt_logprobs validators all accept -1, so the completion
|
||||
logprobs validator must accept it too instead of rejecting it as negative.
|
||||
"""
|
||||
logprobs validator must accept it too instead of rejecting it as negative."""
|
||||
request = CompletionRequest(
|
||||
model=MODEL_NAME,
|
||||
prompt="Test prompt",
|
||||
@@ -746,8 +744,7 @@ class TestCompletionPromptListLimit:
|
||||
@pytest.mark.parametrize("field_name", ["prompt_logprobs", "logprobs"])
|
||||
def test_non_numeric_logprobs_rejected(field_name):
|
||||
"""A non-numeric logprobs value must be a clean 400 validation error, not a
|
||||
TypeError from the mode='before' comparison (which surfaces as HTTP 500).
|
||||
"""
|
||||
TypeError from the mode='before' comparison (which surfaces as HTTP 500)."""
|
||||
with pytest.raises(VLLMValidationError, match=f"`{field_name}` must be an integer"):
|
||||
CompletionRequest(
|
||||
model=MODEL_NAME,
|
||||
|
||||
@@ -43,8 +43,7 @@ def _system():
|
||||
|
||||
class TestResponseInputToHarmonyRenderParity:
|
||||
"""Each test drives the same conversation through both APIs and asserts
|
||||
identical Harmony messages and rendered token sequences.
|
||||
"""
|
||||
identical Harmony messages and rendered token sequences."""
|
||||
|
||||
# -----------------------------------------------------------------------
|
||||
# Single-message cases
|
||||
@@ -52,8 +51,7 @@ class TestResponseInputToHarmonyRenderParity:
|
||||
|
||||
def test_developer_message(self):
|
||||
"""Both APIs must render developer messages identically using
|
||||
DeveloperContent (with the '# Instructions' header).
|
||||
"""
|
||||
DeveloperContent (with the '# Instructions' header)."""
|
||||
chat_msgs = parse_chat_input_to_harmony_message(
|
||||
{"role": "developer", "content": "Be concise."}
|
||||
)
|
||||
@@ -248,8 +246,7 @@ class TestResponseInputToHarmonyRenderParity:
|
||||
def test_reasoning_combined_with_function_call(self):
|
||||
"""Chat API packs reasoning + tool_calls into one dict; responses API
|
||||
represents them as two separate items. Both must produce the same two
|
||||
Harmony messages in the same order: analysis then commentary.
|
||||
"""
|
||||
Harmony messages in the same order: analysis then commentary."""
|
||||
chat_msgs = parse_chat_input_to_harmony_message(
|
||||
{
|
||||
"role": "assistant",
|
||||
@@ -532,8 +529,7 @@ class TestResponseInputToHarmonyRenderParity:
|
||||
def test_completed_turns_drop_reasoning(self):
|
||||
"""Validates that reasoning from completed turns is dropped, while
|
||||
reasoning from the current in-progress tool-call turn is preserved
|
||||
in both chat completions and responses previous_input_messages.
|
||||
"""
|
||||
in both chat completions and responses previous_input_messages."""
|
||||
first_turn_reasoning = "FIRST_TURN_REASONING"
|
||||
second_turn_reasoning = "SECOND_TURN_REASONING"
|
||||
|
||||
|
||||
@@ -323,8 +323,7 @@ class TestCommonParseInputToHarmonyMessage:
|
||||
|
||||
def test_system_message(self, parse_function):
|
||||
"""Test parsing system messages, which are parsed into developer messages
|
||||
with DeveloperContent.
|
||||
"""
|
||||
with DeveloperContent."""
|
||||
chat_msg = {
|
||||
"role": "system",
|
||||
"content": "You are a helpful assistant",
|
||||
|
||||
@@ -12,8 +12,7 @@ from vllm.entrypoints.openai.responses.protocol import ResponsesRequest
|
||||
|
||||
def test_function_call_dict_converted_to_object():
|
||||
"""Test that function_call dictionaries are correctly parsed into
|
||||
ResponseFunctionToolCall objects.
|
||||
"""
|
||||
ResponseFunctionToolCall objects."""
|
||||
# Create a request with function_call as dict
|
||||
request_data = {
|
||||
"model": "gpt-oss",
|
||||
@@ -330,8 +329,7 @@ def test_validator_handles_empty_iterator():
|
||||
|
||||
def test_assistant_string_content_stays_easyinput():
|
||||
"""EasyInput assistant message with plain string content is not
|
||||
coerced into a ResponseOutputMessage.
|
||||
"""
|
||||
coerced into a ResponseOutputMessage."""
|
||||
request_data = {
|
||||
"model": "test-model",
|
||||
"input": [
|
||||
@@ -353,8 +351,7 @@ def test_assistant_string_content_stays_easyinput():
|
||||
|
||||
def test_assistant_output_style_content_coerced():
|
||||
"""Assistant message whose content is output-message-shaped (list of
|
||||
output_text items) should be coerced to ResponseOutputMessage.
|
||||
"""
|
||||
output_text items) should be coerced to ResponseOutputMessage."""
|
||||
request_data = {
|
||||
"model": "test-model",
|
||||
"input": [
|
||||
|
||||
@@ -67,8 +67,7 @@ class TestResponseInputToHarmonyMessage:
|
||||
|
||||
def test_system_message(self):
|
||||
"""System messages carry developer instructions and must be rendered
|
||||
as developer messages with DeveloperContent.
|
||||
"""
|
||||
as developer messages with DeveloperContent."""
|
||||
msg = response_input_to_harmony(
|
||||
{"type": "message", "role": "system", "content": "Be helpful."},
|
||||
prev_responses=[],
|
||||
@@ -90,8 +89,7 @@ class TestResponseInputToHarmonyMessage:
|
||||
|
||||
def test_developer_message_gets_instructions_prefix(self):
|
||||
"""Developer messages must use DeveloperContent which adds the
|
||||
'# Instructions' header the model was trained on.
|
||||
"""
|
||||
'# Instructions' header the model was trained on."""
|
||||
msg = response_input_to_harmony(
|
||||
{"type": "message", "role": "developer", "content": "Be concise."},
|
||||
prev_responses=[],
|
||||
@@ -121,8 +119,7 @@ class TestResponseInputToHarmonyMessage:
|
||||
|
||||
def test_developer_message_array_content_concatenated(self):
|
||||
"""Array content in developer messages is flattened and rendered
|
||||
via DeveloperContent with the '# Instructions' header.
|
||||
"""
|
||||
via DeveloperContent with the '# Instructions' header."""
|
||||
msg = response_input_to_harmony(
|
||||
{
|
||||
"type": "message",
|
||||
@@ -213,8 +210,7 @@ class TestResponseInputToHarmonyMessage:
|
||||
|
||||
def test_function_call_output_uses_most_recent_matching_call(self):
|
||||
"""When multiple prev_responses share a call_id, the last one wins
|
||||
because the search is reversed.
|
||||
"""
|
||||
because the search is reversed."""
|
||||
earlier = ResponseFunctionToolCall(
|
||||
id="fc_old",
|
||||
call_id="call_test",
|
||||
|
||||
@@ -839,13 +839,11 @@ class TestConstructChatMessagesCombinePolicy:
|
||||
|
||||
class TestConstructInputMessagesInstructionsLeak:
|
||||
"""Regression tests for #37697: instructions from a prior response
|
||||
should NOT leak through previous_response_id.
|
||||
"""
|
||||
should NOT leak through previous_response_id."""
|
||||
|
||||
def test_old_instructions_stripped_from_prev_msg(self):
|
||||
"""System message in prev_msg must be dropped so the new request's
|
||||
instructions are the only system message in the conversation.
|
||||
"""
|
||||
instructions are the only system message in the conversation."""
|
||||
prev = [
|
||||
{"role": "system", "content": "old instructions"},
|
||||
{"role": "user", "content": "What is 2+2?"},
|
||||
@@ -862,8 +860,7 @@ class TestConstructInputMessagesInstructionsLeak:
|
||||
|
||||
def test_no_instructions_in_new_request(self):
|
||||
"""If the new request has no instructions, old ones should still
|
||||
be stripped -- they must not carry over.
|
||||
"""
|
||||
be stripped -- they must not carry over."""
|
||||
prev = [
|
||||
{"role": "system", "content": "old instructions"},
|
||||
{"role": "user", "content": "Hi"},
|
||||
|
||||
@@ -1163,8 +1163,7 @@ class TestHarmonyPreambleStreaming:
|
||||
|
||||
def test_preamble_done_emits_text_done_events(self) -> None:
|
||||
"""Completed preamble should emit text done + content_part done +
|
||||
output_item done, same shape as final channel.
|
||||
"""
|
||||
output_item done, same shape as final channel."""
|
||||
from vllm.entrypoints.openai.responses.streaming_events import (
|
||||
emit_previous_item_done_events,
|
||||
)
|
||||
@@ -1185,8 +1184,7 @@ class TestHarmonyPreambleStreaming:
|
||||
|
||||
def test_commentary_with_recipient_no_preamble_done(self) -> None:
|
||||
"""Commentary + recipient='functions.X' should route to function call
|
||||
done, not preamble done.
|
||||
"""
|
||||
done, not preamble done."""
|
||||
from vllm.entrypoints.openai.responses.streaming_events import (
|
||||
emit_previous_item_done_events,
|
||||
)
|
||||
@@ -1332,8 +1330,7 @@ def _mock_parser_with_reasoning(serving, delta_sequence: list[DeltaMessage]):
|
||||
class TestStreamingReasoningToContentTransition:
|
||||
"""Tests for _process_simple_streaming_events reasoning-to-content
|
||||
transition, specifically the fix for mixed deltas that carry both
|
||||
reasoning and content simultaneously.
|
||||
"""
|
||||
reasoning and content simultaneously."""
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_mixed_delta_reasoning_and_content_emits_reasoning_delta(
|
||||
@@ -1343,8 +1340,7 @@ class TestStreamingReasoningToContentTransition:
|
||||
and content set (e.g. reasoning end and content start in the same
|
||||
chunk), the trailing reasoning text must be emitted as a
|
||||
ResponseReasoningTextDeltaEvent and included in the
|
||||
ResponseReasoningTextDoneEvent text.
|
||||
"""
|
||||
ResponseReasoningTextDoneEvent text."""
|
||||
monkeypatch.setattr(envs, "VLLM_USE_EXPERIMENTAL_PARSER_CONTEXT", False)
|
||||
serving = _make_serving_instance_with_reasoning()
|
||||
|
||||
@@ -1413,8 +1409,7 @@ class TestStreamingReasoningToContentTransition:
|
||||
self, monkeypatch
|
||||
):
|
||||
"""When the transition from reasoning to content is clean (no mixed
|
||||
delta), no extra reasoning delta event should be emitted.
|
||||
"""
|
||||
delta), no extra reasoning delta event should be emitted."""
|
||||
monkeypatch.setattr(envs, "VLLM_USE_EXPERIMENTAL_PARSER_CONTEXT", False)
|
||||
serving = _make_serving_instance_with_reasoning()
|
||||
|
||||
@@ -1475,8 +1470,7 @@ class TestStreamingReasoningToContentTransition:
|
||||
async def test_reasoning_only_stream_no_content(self, monkeypatch):
|
||||
"""When the stream has only reasoning deltas and no content, the
|
||||
reasoning done event should be emitted at finalization with the
|
||||
full accumulated text, and no text delta events should appear.
|
||||
"""
|
||||
full accumulated text, and no text delta events should appear."""
|
||||
monkeypatch.setattr(envs, "VLLM_USE_EXPERIMENTAL_PARSER_CONTEXT", False)
|
||||
serving = _make_serving_instance_with_reasoning()
|
||||
|
||||
|
||||
@@ -143,8 +143,7 @@ async def test_streaming_output_consistency(client: OpenAI, model_name: str):
|
||||
@pytest.mark.parametrize("model_name", [MODEL_NAME])
|
||||
async def test_streaming_logprobs(client: OpenAI, model_name: str):
|
||||
"""Test that streaming with logprobs returns valid logprob data on
|
||||
output_text.delta events and that top_logprobs has the requested count.
|
||||
"""
|
||||
output_text.delta events and that top_logprobs has the requested count."""
|
||||
response = await client.responses.create(
|
||||
model=model_name,
|
||||
input="Say hello.",
|
||||
|
||||
@@ -124,8 +124,7 @@ class TestProcessorCompoundDeltas:
|
||||
|
||||
def test_split_name_and_args_same_index(self):
|
||||
"""Regression: parsers like KimiK2 emit name and args as separate
|
||||
DeltaToolCalls at the same index within one DeltaMessage.
|
||||
"""
|
||||
DeltaToolCalls at the same index within one DeltaMessage."""
|
||||
tc_name = _make_tool_call(0, name="get_weather")
|
||||
tc_args = _make_tool_call(0, arguments='{"city":"SF"}')
|
||||
delta = DeltaMessage(tool_calls=[tc_name, tc_args])
|
||||
@@ -141,8 +140,7 @@ class TestProcessorCompoundDeltas:
|
||||
|
||||
def test_reasoning_to_content_transition(self):
|
||||
"""Regression: the old special case in emit_delta handled this;
|
||||
now split_delta handles it generically.
|
||||
"""
|
||||
now split_delta handles it generically."""
|
||||
processor = SimpleStreamingEventProcessor()
|
||||
_run_through_processor(processor, DeltaMessage(reasoning="think"))
|
||||
assert processor.state.current_state == _StateType.REASONING
|
||||
|
||||
@@ -25,8 +25,7 @@ def _model_config() -> Mock:
|
||||
def test_completion_flag_forwarded_to_tok_params():
|
||||
"""build_tok_params must forward return_token_offsets, defaulting to
|
||||
False (zero behavioral change for existing callers) and coercing JSON
|
||||
null to False via the bool() guard.
|
||||
"""
|
||||
null to False via the bool() guard."""
|
||||
cfg = _model_config()
|
||||
|
||||
default = CompletionRequest(model="m", prompt="hi")
|
||||
@@ -41,8 +40,7 @@ def test_completion_flag_forwarded_to_tok_params():
|
||||
|
||||
def test_chat_flag_forwarded_to_tok_params():
|
||||
"""Chat build_tok_params has its own (max_completion_tokens) branch, so
|
||||
its return_token_offsets forwarding is verified independently.
|
||||
"""
|
||||
its return_token_offsets forwarding is verified independently."""
|
||||
cfg = _model_config()
|
||||
messages = [{"role": "user", "content": "hi"}]
|
||||
|
||||
@@ -66,8 +64,7 @@ def test_generate_request_token_offsets_default_none():
|
||||
|
||||
def test_generate_request_token_offsets_survive_json_round_trip():
|
||||
"""GenerateRequest crosses the disagg serialization boundary; the
|
||||
tuple[int, int] offsets must survive model_dump and re-validate.
|
||||
"""
|
||||
tuple[int, int] offsets must survive model_dump and re-validate."""
|
||||
req = GenerateRequest(
|
||||
token_ids=[10, 20],
|
||||
sampling_params=SamplingParams(),
|
||||
|
||||
@@ -111,8 +111,7 @@ def test_basic_embed(server: RemoteOpenAIServer, model_name: str):
|
||||
|
||||
def test_unsupported_input_type_rejected(server: RemoteOpenAIServer, model_name: str):
|
||||
"""An input_type not defined in the model's prompt config should be
|
||||
rejected with a 400 error.
|
||||
"""
|
||||
rejected with a 400 error."""
|
||||
body = {
|
||||
"model": model_name,
|
||||
"input_type": "nonexistent_type",
|
||||
@@ -139,8 +138,7 @@ def test_omitted_input_type_accepted(server: RemoteOpenAIServer, model_name: str
|
||||
|
||||
def test_v1_v2_parity(server: RemoteOpenAIServer, model_name: str):
|
||||
"""v1 (OpenAI) and v2 (Cohere) endpoints should produce the same
|
||||
float embeddings for a generic model.
|
||||
"""
|
||||
float embeddings for a generic model."""
|
||||
texts = ["hello world"]
|
||||
v2 = _cohere_embed(server, model_name, texts=texts, embedding_types=["float"])
|
||||
v1 = _openai_embed(server, model_name, texts)
|
||||
|
||||
@@ -76,8 +76,7 @@ def test_single_text_parity(server: RemoteOpenAIServer):
|
||||
|
||||
def test_batch_parity(server: RemoteOpenAIServer):
|
||||
"""A batch of texts should produce equivalent embeddings via both APIs,
|
||||
in the same order.
|
||||
"""
|
||||
in the same order."""
|
||||
texts = [
|
||||
"machine learning",
|
||||
"deep learning",
|
||||
|
||||
@@ -241,8 +241,7 @@ class TestResolveTruncation:
|
||||
|
||||
def test_truncate_none_with_max_tokens(self):
|
||||
"""truncate=NONE should NOT set truncate_prompt_tokens; the
|
||||
max_tokens limit is enforced separately via _check_max_tokens.
|
||||
"""
|
||||
max_tokens limit is enforced separately via _check_max_tokens."""
|
||||
req = self._make_request(truncate="NONE", max_tokens=10)
|
||||
tokens, side = EmbedIOProcessor._resolve_cohere_truncation(req)
|
||||
assert tokens is None
|
||||
|
||||
@@ -240,8 +240,7 @@ async def test_long_text_embedding_1500_chars(
|
||||
client_with_chunked_processing: openai.AsyncOpenAI, model_name: str
|
||||
):
|
||||
"""Test embedding processing for ~1500 character long text
|
||||
(~1028 tokens, exceeding 512 token limit).
|
||||
"""
|
||||
(~1028 tokens, exceeding 512 token limit)."""
|
||||
# Verify text length
|
||||
# Verify text has sufficient word count (approximately 1500 words)
|
||||
word_count = len(LONG_TEXT_1500_WORDS.split())
|
||||
@@ -289,8 +288,7 @@ async def test_long_text_embedding_2500_chars(
|
||||
client_with_chunked_processing: openai.AsyncOpenAI, model_name: str
|
||||
):
|
||||
"""Test embedding processing for ~2500 character long text
|
||||
(~2048 tokens, requiring multiple chunks).
|
||||
"""
|
||||
(~2048 tokens, requiring multiple chunks)."""
|
||||
# Verify text length
|
||||
# Verify text has sufficient word count (approximately 2500 words)
|
||||
word_count = len(LONG_TEXT_2500_WORDS.split())
|
||||
@@ -382,8 +380,7 @@ async def test_chunked_vs_normal_consistency(
|
||||
client_with_chunked_processing: openai.AsyncOpenAI, model_name: str
|
||||
):
|
||||
"""Test consistency between chunked and
|
||||
normal processing (using short text).
|
||||
"""
|
||||
normal processing (using short text)."""
|
||||
# Use a short text within the 512 token limit
|
||||
short_text = (
|
||||
"Artificial intelligence technology is changing our world, "
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
"""Unit tests for Cohere embed protocol: build_typed_embeddings and its
|
||||
underlying packing helpers, plus Cohere-specific serving helpers.
|
||||
"""
|
||||
underlying packing helpers, plus Cohere-specific serving helpers."""
|
||||
|
||||
import struct
|
||||
|
||||
|
||||
@@ -454,8 +454,7 @@ async def test_derender_completion_empty_generate_responses(client):
|
||||
@pytest.mark.asyncio
|
||||
async def test_derender_completion_logprobs(client):
|
||||
"""token_id:N placeholders in logprobs are resolved; CompletionLogProbs
|
||||
flat-list structure is returned with non-empty tokens and text_offsets.
|
||||
"""
|
||||
flat-list structure is returned with non-empty tokens and text_offsets."""
|
||||
gr1 = await _render_completion(client, "Hello world")
|
||||
ids1 = gr1["token_ids"][:3]
|
||||
token_id = ids1[0]
|
||||
|
||||
@@ -121,8 +121,7 @@ async def _disagg(
|
||||
|
||||
def _tool_sig(response_choice: dict) -> list[tuple[str, dict]]:
|
||||
"""[(name, json normalized args)] so key ordering / whitespace don't
|
||||
cause false negatives.
|
||||
"""
|
||||
cause false negatives."""
|
||||
return [
|
||||
(tc["function"]["name"], json.loads(tc["function"]["arguments"]))
|
||||
for tc in (response_choice["message"].get("tool_calls") or [])
|
||||
@@ -144,8 +143,7 @@ async def _run_parity_case(
|
||||
client: httpx.AsyncClient, messages: list[dict], **extra
|
||||
) -> tuple[dict, dict]:
|
||||
"""Run the coupled request then feed its generated tokens into the
|
||||
disaggregated derender endpoint. Returns (coupled, disagg).
|
||||
"""
|
||||
disaggregated derender endpoint. Returns (coupled, disagg)."""
|
||||
coupled = await _coupled(client, messages, **extra)
|
||||
ch = coupled["choices"][0]
|
||||
chat_request = {"model": MODEL, "messages": messages, **extra}
|
||||
@@ -205,8 +203,7 @@ async def test_parity_tool_call(client):
|
||||
@pytest.mark.asyncio
|
||||
async def test_parity_reasoning_and_tool_call(client):
|
||||
"""Combined reasoning + tool call parity means the highest drift risk
|
||||
since it exercises both parser branches on the same output.
|
||||
"""
|
||||
since it exercises both parser branches on the same output."""
|
||||
messages = [{"role": "user", "content": "What's the weather in Paris?"}]
|
||||
coupled, disagg = await _run_parity_case(
|
||||
client,
|
||||
|
||||
@@ -455,8 +455,7 @@ async def test_chat_completion_render_with_sampling_params(client):
|
||||
@pytest.mark.asyncio
|
||||
async def test_completion_render_emits_token_offsets(client):
|
||||
"""With return_token_offsets, /v1/completions/render returns per-token
|
||||
(start, end) char offsets aligned with token_ids.
|
||||
"""
|
||||
(start, end) char offsets aligned with token_ids."""
|
||||
prompt = "Hello, world."
|
||||
response = await client.post(
|
||||
"/v1/completions/render",
|
||||
@@ -481,8 +480,7 @@ async def test_completion_render_emits_token_offsets(client):
|
||||
@pytest.mark.asyncio
|
||||
async def test_completion_render_default_no_token_offsets(client):
|
||||
"""Without the flag, token_offsets must be null (existing responses
|
||||
unchanged).
|
||||
"""
|
||||
unchanged)."""
|
||||
response = await client.post(
|
||||
"/v1/completions/render",
|
||||
json={
|
||||
@@ -499,8 +497,7 @@ async def test_completion_render_default_no_token_offsets(client):
|
||||
@pytest.mark.asyncio
|
||||
async def test_chat_render_emits_token_offsets(client):
|
||||
"""With return_token_offsets, /v1/chat/completions/render returns
|
||||
per-token offsets relative to the templated prompt string.
|
||||
"""
|
||||
per-token offsets relative to the templated prompt string."""
|
||||
response = await client.post(
|
||||
"/v1/chat/completions/render",
|
||||
json={
|
||||
@@ -674,8 +671,7 @@ async def test_chat_completion_render_assistant_tokens_mask_with_generation_tags
|
||||
client,
|
||||
):
|
||||
"""With a ``{% generation %}``-enabled template, the mask marks assistant
|
||||
tokens and the masked tokens decode to the assistant content.
|
||||
"""
|
||||
tokens and the masked tokens decode to the assistant content."""
|
||||
response = await client.post(
|
||||
"/v1/chat/completions/render",
|
||||
json={
|
||||
|
||||
@@ -25,8 +25,7 @@ def _base_payload() -> dict:
|
||||
|
||||
def test_omitted_max_tokens_is_not_provided():
|
||||
"""Body without ``max_tokens`` must surface as 'not provided' so the
|
||||
server can apply its own default instead of the dataclass 16.
|
||||
"""
|
||||
server can apply its own default instead of the dataclass 16."""
|
||||
req = GenerateRequest.model_validate(_base_payload())
|
||||
# SamplingParams' dataclass default leaks through the parsed instance —
|
||||
# this is exactly the bug the server-side defaulting works around.
|
||||
@@ -36,8 +35,7 @@ def test_omitted_max_tokens_is_not_provided():
|
||||
|
||||
def test_explicit_max_tokens_is_provided():
|
||||
"""Even when the client picks the same value as the dataclass default,
|
||||
it must register as explicitly set so the server won't override it.
|
||||
"""
|
||||
it must register as explicitly set so the server won't override it."""
|
||||
payload = _base_payload()
|
||||
payload["sampling_params"] = {"max_tokens": 16}
|
||||
req = GenerateRequest.model_validate(payload)
|
||||
@@ -69,8 +67,7 @@ def test_json_roundtrip_preserves_provided_keys():
|
||||
def test_internal_instance_construction_treats_all_as_provided():
|
||||
"""When internal callers build ``GenerateRequest`` from a pre-resolved
|
||||
``SamplingParams`` instance, every field is considered explicitly set
|
||||
so server-side defaulting can't clobber values resolved upstream.
|
||||
"""
|
||||
so server-side defaulting can't clobber values resolved upstream."""
|
||||
sp = SamplingParams(max_tokens=500, temperature=0.0)
|
||||
req = GenerateRequest(token_ids=[1, 2, 3], sampling_params=sp)
|
||||
assert req.is_sampling_param_provided("max_tokens")
|
||||
|
||||
@@ -22,8 +22,7 @@ def test_sanitize_message():
|
||||
|
||||
class TestSanitizeMessageFilePaths:
|
||||
"""sanitize_message should also strip file paths and traceback
|
||||
frames, not just memory addresses - see #31683.
|
||||
"""
|
||||
frames, not just memory addresses - see #31683."""
|
||||
|
||||
def test_strips_traceback_style_frame(self):
|
||||
msg = (
|
||||
@@ -45,8 +44,7 @@ class TestSanitizeMessageFilePaths:
|
||||
|
||||
def test_strips_single_parent_container_path(self):
|
||||
"""Regression: /app/server.py and /workspace/server.py (common in
|
||||
container deployments) were missed by the original {2,} quantifier.
|
||||
"""
|
||||
container deployments) were missed by the original {2,} quantifier."""
|
||||
assert "/app/" not in sanitize_message("Error in /app/server.py")
|
||||
assert "/workspace/" not in sanitize_message("Error in /workspace/server.py")
|
||||
|
||||
|
||||
@@ -24,8 +24,7 @@ from vllm.entrypoints.serve.exception_handling.handlers.validation import (
|
||||
|
||||
def _fake_request(log_error_stack: bool = False) -> SimpleNamespace:
|
||||
"""Minimal stand-in for a FastAPI Request - just enough for the
|
||||
handler to read req.app.state.args.log_error_stack.
|
||||
"""
|
||||
handler to read req.app.state.args.log_error_stack."""
|
||||
return SimpleNamespace(
|
||||
app=SimpleNamespace(
|
||||
state=SimpleNamespace(args=SimpleNamespace(log_error_stack=log_error_stack))
|
||||
@@ -36,8 +35,7 @@ def _fake_request(log_error_stack: bool = False) -> SimpleNamespace:
|
||||
|
||||
class TestValidationErrorParamFallback:
|
||||
"""Ensure `param` falls back to the Pydantic error's `loc` when no
|
||||
custom VLLMValidationError context is present.
|
||||
"""
|
||||
custom VLLMValidationError context is present."""
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("error_type", "msg"),
|
||||
@@ -61,8 +59,7 @@ class TestValidationErrorParamFallback:
|
||||
async def test_param_fallback_does_not_crash_on_non_dict_error(self):
|
||||
"""Schemathesis fuzzing found that errors[0] isn't always a dict.
|
||||
The fallback must not crash in that case - it should just leave
|
||||
param as None instead of raising.
|
||||
"""
|
||||
param as None instead of raising."""
|
||||
exc = RequestValidationError(["some unexpected non-dict error"])
|
||||
|
||||
response = await validation_exception_handler(_fake_request(), exc)
|
||||
@@ -100,8 +97,7 @@ class TestCleanLocForParam:
|
||||
|
||||
def test_all_internal_falls_back_to_raw_join(self):
|
||||
"""If every loc segment looks internal, fall back to the raw
|
||||
dot-join rather than returning an empty string.
|
||||
"""
|
||||
dot-join rather than returning an empty string."""
|
||||
loc = ("function-wrap[__log_extra_fields__()]",)
|
||||
assert clean_loc_for_param(loc) == "function-wrap[__log_extra_fields__()]"
|
||||
|
||||
@@ -109,8 +105,7 @@ class TestCleanLocForParam:
|
||||
class TestValidationErrorDoesNotLeakServerPaths:
|
||||
"""FastAPI sets endpoint_file/line/function/path on the exception
|
||||
during routing, not in the constructor - so we set them manually
|
||||
here to reproduce the real leak. See #31683.
|
||||
"""
|
||||
here to reproduce the real leak. See #31683."""
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_handler_strips_endpoint_file_context(self):
|
||||
|
||||
@@ -245,8 +245,7 @@ async def test_multiple_lora_adapters(
|
||||
client: openai.AsyncOpenAI, tmp_path, qwen3_lora_files
|
||||
):
|
||||
"""Validate that many loras can be dynamically registered and inferenced
|
||||
with concurrently
|
||||
"""
|
||||
with concurrently"""
|
||||
|
||||
# This test file configures the server with --max-cpu-loras=2 and this test
|
||||
# will concurrently load 10 adapters, so it should flex the LRU cache
|
||||
|
||||
@@ -72,8 +72,7 @@ class MockModelConfig:
|
||||
@pytest.fixture(params=get_args(SupportedTask))
|
||||
def task_routes(request, monkeypatch) -> tuple[str, list[tuple[str, list[str]]]]:
|
||||
"""For each supported task, build an app with only that task's routers,
|
||||
extract all routes, and return the task name and routes.
|
||||
"""
|
||||
extract all routes, and return the task name and routes."""
|
||||
task = request.param
|
||||
# Enable development mode to register all routes (including dev-only routes).
|
||||
monkeypatch.setenv("VLLM_SERVER_DEV_MODE", "1")
|
||||
@@ -99,8 +98,7 @@ def task_routes(request, monkeypatch) -> tuple[str, list[tuple[str, list[str]]]]
|
||||
|
||||
def test_auto_discovered_protected_routes_require_auth(task_routes):
|
||||
"""For every auto-discovered route that starts with a guarded prefix,
|
||||
verify that authentication is enforced.
|
||||
"""
|
||||
verify that authentication is enforced."""
|
||||
task, routes = task_routes
|
||||
app = _create_app_with_mock_routes(routes)
|
||||
client = TestClient(app)
|
||||
@@ -134,8 +132,7 @@ def test_auto_discovered_protected_routes_require_auth(task_routes):
|
||||
|
||||
def test_auto_discovered_unprotected_routes_no_auth(task_routes):
|
||||
"""For every auto-discovered route that does NOT start with a guarded
|
||||
prefix, verify that no authentication is required.
|
||||
"""
|
||||
prefix, verify that no authentication is required."""
|
||||
task, routes = task_routes
|
||||
app = _create_app_with_mock_routes(routes)
|
||||
client = TestClient(app)
|
||||
|
||||
@@ -114,8 +114,7 @@ class TestHandlerOverrideIntegration:
|
||||
|
||||
def test_customer_script_functions_auto_loaded(self, monkeypatch, tmp_path):
|
||||
"""Test customer scenario: script functions automatically override
|
||||
framework defaults.
|
||||
"""
|
||||
framework defaults."""
|
||||
try:
|
||||
from model_hosting_container_standards.sagemaker.config import (
|
||||
SageMakerEnvVars,
|
||||
@@ -176,8 +175,7 @@ async def custom_sagemaker_invocation_handler(request: Request):
|
||||
|
||||
def test_customer_decorator_usage(self, monkeypatch, tmp_path):
|
||||
"""Test customer scenario: using @custom_ping_handler and
|
||||
@custom_invocation_handler decorators.
|
||||
"""
|
||||
@custom_invocation_handler decorators."""
|
||||
try:
|
||||
from model_hosting_container_standards.sagemaker.config import (
|
||||
SageMakerEnvVars,
|
||||
@@ -233,8 +231,7 @@ async def my_invoke(request: Request):
|
||||
|
||||
def test_handler_priority_order(self, monkeypatch, tmp_path):
|
||||
"""Test priority: @custom_ping_handler/@custom_invocation_handler
|
||||
decorators vs script functions.
|
||||
"""
|
||||
decorators vs script functions."""
|
||||
try:
|
||||
from model_hosting_container_standards.sagemaker.config import (
|
||||
SageMakerEnvVars,
|
||||
@@ -307,8 +304,7 @@ async def custom_sagemaker_invocation_handler(request: Request):
|
||||
|
||||
def test_environment_variable_script_loading(self, monkeypatch, tmp_path):
|
||||
"""Test that environment variables correctly specify script location
|
||||
and loading.
|
||||
"""
|
||||
and loading."""
|
||||
try:
|
||||
from model_hosting_container_standards.sagemaker.config import (
|
||||
SageMakerEnvVars,
|
||||
@@ -420,8 +416,7 @@ async def custom_sagemaker_invocation_handler(request: Request):
|
||||
|
||||
def test_handler_env_var_override(self, monkeypatch, tmp_path):
|
||||
"""Test CUSTOM_FASTAPI_PING_HANDLER and CUSTOM_FASTAPI_INVOCATION_HANDLER
|
||||
environment variable overrides.
|
||||
"""
|
||||
environment variable overrides."""
|
||||
try:
|
||||
from model_hosting_container_standards.common.fastapi.config import (
|
||||
FastAPIEnvVars,
|
||||
@@ -515,8 +510,7 @@ async def custom_sagemaker_invocation_handler(request: Request):
|
||||
|
||||
def test_env_var_priority_over_decorator_and_script(self, monkeypatch, tmp_path):
|
||||
"""Test that environment variables have highest priority over decorators
|
||||
and script functions for both ping and invocation handlers.
|
||||
"""
|
||||
and script functions for both ping and invocation handlers."""
|
||||
try:
|
||||
from model_hosting_container_standards.common.fastapi.config import (
|
||||
FastAPIEnvVars,
|
||||
|
||||
@@ -51,8 +51,7 @@ async def test_tokenize_then_chat_completion_with_image(
|
||||
local_asset_server,
|
||||
):
|
||||
"""Tokenize a multimodal message, then send the same message to chat
|
||||
completions. The chat completion must succeed (not 500).
|
||||
"""
|
||||
completions. The chat completion must succeed (not 500)."""
|
||||
image_url = local_asset_server.url_for("stop_sign.jpg")
|
||||
messages = [
|
||||
{
|
||||
|
||||
@@ -36,13 +36,11 @@ def test_should_include_usage_force_enables_continuous_usage(stream_options, exp
|
||||
class TestGetMaxTokens:
|
||||
"""Tests for get_max_tokens() to ensure generation_config's max_tokens
|
||||
acts as a default when from model author, and as a ceiling when
|
||||
explicitly set by the user.
|
||||
"""
|
||||
explicitly set by the user."""
|
||||
|
||||
def test_default_sampling_params_used_when_no_request_max_tokens(self):
|
||||
"""When user doesn't specify max_tokens, generation_config default
|
||||
should apply.
|
||||
"""
|
||||
should apply."""
|
||||
result = get_max_tokens(
|
||||
max_model_len=24000,
|
||||
max_tokens=None,
|
||||
@@ -53,8 +51,7 @@ class TestGetMaxTokens:
|
||||
|
||||
def test_request_max_tokens_not_capped_by_default_sampling_params(self):
|
||||
"""When user specifies max_tokens in request, model author's
|
||||
generation_config max_tokens must NOT cap it (fixes #34005).
|
||||
"""
|
||||
generation_config max_tokens must NOT cap it (fixes #34005)."""
|
||||
result = get_max_tokens(
|
||||
max_model_len=24000,
|
||||
max_tokens=5000,
|
||||
@@ -97,8 +94,7 @@ class TestGetMaxTokens:
|
||||
|
||||
def test_request_max_tokens_smaller_than_default(self):
|
||||
"""When user explicitly requests fewer tokens than gen_config default,
|
||||
that should be respected.
|
||||
"""
|
||||
that should be respected."""
|
||||
result = get_max_tokens(
|
||||
max_model_len=24000,
|
||||
max_tokens=512,
|
||||
|
||||
@@ -239,8 +239,7 @@ def test_request_logger_log_outputs_integration():
|
||||
|
||||
def test_streaming_complete_logs_full_text_content():
|
||||
"""Test that streaming complete logging includes
|
||||
full accumulated text, not just token count.
|
||||
"""
|
||||
full accumulated text, not just token count."""
|
||||
mock_logger = MagicMock()
|
||||
|
||||
with patch("vllm.entrypoints.serve.utils.request_logger.logger", mock_logger):
|
||||
|
||||
@@ -17,8 +17,7 @@ from vllm.entrypoints.serve.utils.sse_keep_alive import (
|
||||
def test_disabled_returns_same_generator():
|
||||
"""For 0, negative, and NaN intervals the exact same generator object must
|
||||
be returned (identity), proving no wrapper or per-chunk overhead when
|
||||
disabled.
|
||||
"""
|
||||
disabled."""
|
||||
|
||||
async def gen():
|
||||
yield "x"
|
||||
@@ -34,8 +33,7 @@ def test_disabled_returns_same_generator():
|
||||
@pytest.mark.asyncio
|
||||
async def test_keep_alive_during_silent_start():
|
||||
"""A silent start (queue wait / prefill) emits keep-alive comments before
|
||||
the first real chunk.
|
||||
"""
|
||||
the first real chunk."""
|
||||
release = asyncio.Event()
|
||||
|
||||
async def gen():
|
||||
@@ -57,8 +55,7 @@ async def test_keep_alive_during_silent_start():
|
||||
@pytest.mark.asyncio
|
||||
async def test_no_keep_alive_when_streaming_is_fast():
|
||||
"""If chunks arrive faster than the interval, no comment is emitted and all
|
||||
data is forwarded.
|
||||
"""
|
||||
data is forwarded."""
|
||||
|
||||
async def gen():
|
||||
for chunk in ["a", "b", "c"]:
|
||||
@@ -72,8 +69,7 @@ async def test_no_keep_alive_when_streaming_is_fast():
|
||||
@pytest.mark.asyncio
|
||||
async def test_keep_alive_between_chunks_does_not_drop_data():
|
||||
"""Keep-alives interleaved with real chunks must never drop or reorder
|
||||
data.
|
||||
"""
|
||||
data."""
|
||||
release_b = asyncio.Event()
|
||||
release_c = asyncio.Event()
|
||||
|
||||
@@ -139,8 +135,7 @@ async def test_upstream_cancelled_error_propagates():
|
||||
@pytest.mark.asyncio
|
||||
async def test_aclose_closes_upstream():
|
||||
"""Closing a wrapper that is mid-stream must complete promptly and close
|
||||
the upstream generator (regression for the earlier leaked-task hang).
|
||||
"""
|
||||
the upstream generator (regression for the earlier leaked-task hang)."""
|
||||
finalized = asyncio.Event()
|
||||
|
||||
async def gen():
|
||||
@@ -159,8 +154,7 @@ async def test_aclose_closes_upstream():
|
||||
@pytest.mark.asyncio
|
||||
async def test_client_disconnect_cancels_upstream():
|
||||
"""Cancelling the consumer mid-stream must cancel the pending anext and
|
||||
close the upstream generator so its cleanup runs.
|
||||
"""
|
||||
close the upstream generator so its cleanup runs."""
|
||||
finalized = asyncio.Event()
|
||||
|
||||
async def gen():
|
||||
@@ -187,8 +181,7 @@ async def test_client_disconnect_cancels_upstream():
|
||||
@pytest.mark.asyncio
|
||||
async def test_streaming_response_emits_comment():
|
||||
"""A keep-alive comment must reach the client through the real
|
||||
StreamingResponse used by the routers.
|
||||
"""
|
||||
StreamingResponse used by the routers."""
|
||||
release = asyncio.Event()
|
||||
|
||||
async def gen():
|
||||
@@ -227,8 +220,7 @@ async def test_streaming_response_emits_comment():
|
||||
async def test_streaming_response_disconnect_closes_upstream():
|
||||
"""On the ASGI 2.3 disconnect path used by the pinned Uvicorn, Starlette
|
||||
cancels streaming and the wrapper's finally must close the upstream
|
||||
generator.
|
||||
"""
|
||||
generator."""
|
||||
finalized = asyncio.Event()
|
||||
|
||||
async def gen():
|
||||
|
||||
@@ -295,8 +295,7 @@ async def test_session_update_invalid_model_returns_error(model_name):
|
||||
@pytest.mark.parametrize("model_name", [MODEL_NAME])
|
||||
async def test_commit_without_session_update_returns_error(model_name):
|
||||
"""Test that committing before validating the model returns an error
|
||||
and does not fall through to processing.
|
||||
"""
|
||||
and does not fall through to processing."""
|
||||
server_args = ["--enforce-eager", "--max-model-len", "2048"]
|
||||
|
||||
if model_name.startswith("mistralai"):
|
||||
|
||||
@@ -51,8 +51,7 @@ async def generate_mock_outputs(
|
||||
num_turns, prompt_token_counts, output_token_counts, cached_token_counts=None
|
||||
):
|
||||
"""Generate a sequence of mock RequestOutput objects to simulate multiple
|
||||
turns.
|
||||
"""
|
||||
turns."""
|
||||
if cached_token_counts is None:
|
||||
cached_token_counts = [0] * num_turns
|
||||
|
||||
@@ -271,8 +270,7 @@ def test_reasoning_tokens_counting():
|
||||
|
||||
def test_preamble_tokens_not_counted_as_reasoning():
|
||||
"""Preambles (commentary with no recipient) are visible user text,
|
||||
not hidden reasoning. They must NOT inflate num_reasoning_tokens.
|
||||
"""
|
||||
not hidden reasoning. They must NOT inflate num_reasoning_tokens."""
|
||||
context, parser = make_harmony_context()
|
||||
parser.enqueue_chunk_result(reasoning_token_count=0)
|
||||
|
||||
@@ -289,8 +287,7 @@ def test_preamble_tokens_not_counted_as_reasoning():
|
||||
|
||||
def test_commentary_with_recipient_counted_as_reasoning():
|
||||
"""Commentary directed at a tool (recipient != None) is hidden from
|
||||
the user, so it should still count as reasoning tokens.
|
||||
"""
|
||||
the user, so it should still count as reasoning tokens."""
|
||||
context, parser = make_harmony_context()
|
||||
parser.enqueue_chunk_result(reasoning_token_count=3)
|
||||
|
||||
@@ -349,8 +346,7 @@ async def test_single_turn_no_tool_output():
|
||||
@pytest.mark.asyncio
|
||||
async def test_negative_tool_tokens_edge_case():
|
||||
"""Test edge case where calculation could result in negative tool
|
||||
tokens. We should log an error and clamp the value to 0.
|
||||
"""
|
||||
tokens. We should log an error and clamp the value to 0."""
|
||||
# Use patch to check if logger.error was called
|
||||
with patch("vllm.entrypoints.openai.responses.context.logger.error") as mock_log:
|
||||
context, _ = make_harmony_context(available_tools=["browser"])
|
||||
@@ -690,8 +686,7 @@ def create_simple_context_output(
|
||||
finished=True,
|
||||
):
|
||||
"""Helper to create a RequestOutput with customizable text for
|
||||
SimpleContext tests.
|
||||
"""
|
||||
SimpleContext tests."""
|
||||
if token_ids is None:
|
||||
token_ids = []
|
||||
return RequestOutput(
|
||||
@@ -875,8 +870,7 @@ def test_simple_context_final_output():
|
||||
|
||||
def test_simple_context_output_messages_empty_text_with_tokens():
|
||||
"""output_messages should be returned when tokens exist even if text is
|
||||
empty (e.g. special tokens).
|
||||
"""
|
||||
empty (e.g. special tokens)."""
|
||||
context = SimpleContext()
|
||||
context.append_output(
|
||||
create_simple_context_output(
|
||||
@@ -894,8 +888,7 @@ def test_simple_context_output_messages_empty_text_with_tokens():
|
||||
|
||||
def test_simple_context_output_messages_no_mutation():
|
||||
"""Each call to output_messages returns a fresh list; callers can't
|
||||
corrupt internal state.
|
||||
"""
|
||||
corrupt internal state."""
|
||||
context = SimpleContext()
|
||||
context.append_output(
|
||||
create_simple_context_output(
|
||||
|
||||
@@ -121,8 +121,7 @@ def test_get_world_size_tp1(vllm_runner):
|
||||
@create_new_process_for_each_test()
|
||||
def test_init_weight_transfer_engine_calls_engine(vllm_runner):
|
||||
"""Test that init_weight_transfer_engine calls the engine's
|
||||
init_transfer_engine method.
|
||||
"""
|
||||
init_transfer_engine method."""
|
||||
if torch.accelerator.device_count() < 1:
|
||||
pytest.skip("Need at least 1 GPU for this test")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user