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