| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | """Unit tests for the ``vllm serve`` CLI subcommand.""" |
| 4 | |
| 5 | import argparse |
| 6 | from unittest.mock import MagicMock, patch |
| 7 | |
| 8 | import pytest |
| 9 | |
| 10 | from vllm.entrypoints.cli.serve import run_headless |
| 11 | |
| 12 | |
| 13 | class _StopAfterEngineConfig(Exception): |
| 14 | pass |
| 15 | |
| 16 | |
| 17 | def test_headless_imports_reasoning_parser_plugin_before_engine_config(): |
| 18 | plugin_path = "/tmp/custom_reasoning_parser.py" |
| 19 | args = argparse.Namespace( |
| 20 | api_server_count=0, |
| 21 | reasoning_parser_plugin=plugin_path, |
| 22 | ) |
| 23 | engine_args = MagicMock() |
| 24 | |
| 25 | with ( |
| 26 | patch( |
| 27 | "vllm.entrypoints.cli.serve.vllm.AsyncEngineArgs.from_cli_args", |
| 28 | return_value=engine_args, |
| 29 | ), |
| 30 | patch( |
| 31 | "vllm.reasoning.ReasoningParserManager.import_reasoning_parser" |
| 32 | ) as import_plugin, |
| 33 | ): |
| 34 | |
| 35 | def create_engine_config(**kwargs): |
| 36 | import_plugin.assert_called_once_with(plugin_path) |
| 37 | raise _StopAfterEngineConfig |
| 38 | |
| 39 | engine_args.create_engine_config.side_effect = create_engine_config |
| 40 | |
| 41 | with pytest.raises(_StopAfterEngineConfig): |
| 42 | run_headless(args) |