feat(deploy-control): 添加命令执行异常处理 当subprocess.run执行失败时捕获OSError异常,并抛出带有详细错误信息的ApiError, 提供更好的错误提示和调试支持。 ```
30 lines
839 B
Python
30 lines
839 B
Python
from __future__ import annotations
|
|
|
|
import importlib.util
|
|
from http import HTTPStatus
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
|
|
SERVER_PATH = Path(__file__).resolve().parents[1] / "server.py"
|
|
|
|
|
|
def _load_server_module():
|
|
spec = importlib.util.spec_from_file_location("deploy_control_server_command_tests", SERVER_PATH)
|
|
assert spec and spec.loader
|
|
module = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(module)
|
|
return module
|
|
|
|
|
|
def test_run_command_reports_missing_executable_as_bad_gateway(tmp_path: Path) -> None:
|
|
server = _load_server_module()
|
|
missing = tmp_path / "missing-command"
|
|
|
|
with pytest.raises(server.ApiError) as exc_info:
|
|
server.run_command([str(missing)])
|
|
|
|
assert exc_info.value.status_code == HTTPStatus.BAD_GATEWAY
|
|
assert str(missing) in exc_info.value.detail
|