fix(platform): Improve WSL SSH remote compatibility (#3316)

* fix(platform): add WSL compatibility functions and path translation
fix(cookbook): enhance model scan script to support additional HuggingFace cache paths
fix(hardware): improve cache key generation for remote SSH context
test(tests): add tests for WSL detection and path translation functionality

* fix(cookbook): prefer prebuilt wheels for llama-cpp-python and normalize package aliases

* fix: enable StrictHostKeyChecking in nvidia probe
refactor: consolidate ssh & powershell command execution to utility functions in core module
refactor: consolidate nvidia path candidates in to single variables in core module
tests: add tests for new utility functions

* fix: correct wrong variable name
This commit is contained in:
horribleCodes
2026-06-08 00:33:50 +02:00
committed by GitHub
parent 73315e6ddc
commit 9c90f62657
8 changed files with 763 additions and 33 deletions
+97
View File
@@ -25,6 +25,7 @@ from routes.cookbook_helpers import (
_validate_serve_cmd,
_validate_serve_model_id,
_validate_ssh_port,
run_ssh_command_async,
)
@@ -35,6 +36,56 @@ def test_safe_env_prefix_accepts_quoted_venv_path():
)
@pytest.mark.asyncio
async def test_run_ssh_command_executes_with_stdin_and_returns_output(monkeypatch):
captured = {}
class _Proc:
returncode = 0
async def communicate(self, input=None):
captured["input"] = input
return b"stdout", b"stderr"
async def _fake_exec(*args, **kwargs):
captured["args"] = list(args)
captured["stdin"] = kwargs.get("stdin")
captured["stdout"] = kwargs.get("stdout")
captured["stderr"] = kwargs.get("stderr")
return _Proc()
monkeypatch.setattr("asyncio.create_subprocess_exec", _fake_exec)
rc, out, err = await run_ssh_command_async(
"alice@gpu-box",
"2222",
"python -",
timeout=5,
connect_timeout=4,
strict_host_key_checking=False,
stdin_data=b"python -m pip install vllm",
)
assert rc == 0
assert out == b"stdout"
assert err == b"stderr"
assert captured["args"] == [
"ssh",
"-o",
"ConnectTimeout=4",
"-o",
"StrictHostKeyChecking=no",
"-p",
"2222",
"alice@gpu-box",
"python -",
]
assert captured["stdin"] is not None
assert captured["stdout"] is not None
assert captured["stderr"] is not None
assert captured["input"] == b"python -m pip install vllm"
def test_safe_env_prefix_leaves_compound_conda_prefix_unchanged():
prefix = 'eval "$(conda shell.bash hook)" && conda activate qwen35'
assert _safe_env_prefix(prefix) == prefix
@@ -170,6 +221,8 @@ def test_pip_install_fallback_chain_quotes_extras_spec():
chain = _pip_install_fallback_chain("llama-cpp-python[server]", python_cmd="pip")
# Quoted in both the plain and the --user attempt.
assert chain.count("'llama-cpp-python[server]'") == 2
# llama-cpp installs must prefer prebuilt wheels to avoid fragile source builds.
assert "--extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cpu" in chain
# Never the unquoted form (bracket-glob risk).
assert "install -q llama-cpp-python[server]" not in chain
# A plain package name is still passed through unquoted (no regression).
@@ -194,6 +247,17 @@ def test_serve_runner_installs_llama_cpp_server_extra():
assert "_pip_install_fallback_chain('llama-cpp-python[server]'" in src
def test_serve_pip_install_normalizes_llama_cpp_alias_and_adds_wheel_index():
import pathlib
src = (pathlib.Path(__file__).resolve().parent.parent
/ "routes" / "cookbook_routes.py").read_text(encoding="utf-8")
assert "re.sub(r\"(?<![A-Za-z0-9_.-])llama_cpp(?![A-Za-z0-9_.-])\", \"llama-cpp-python[server]\", req.cmd)" in src
assert "if \"llama-cpp-python\" in req.cmd and \"--extra-index-url\" not in req.cmd:" in src
assert "https://abetlen.github.io/llama-cpp-python/whl/cpu" in src
def test_vllm_preflight_reports_cli_and_version():
lines = []
@@ -289,6 +353,7 @@ def test_local_tooling_path_export_converts_windows_paths_for_bash():
def test_user_shell_path_bootstrap_falls_back_to_python_on_windows_bash():
script = "\n".join(_user_shell_path_bootstrap())
assert 'command -v python3 >/dev/null 2>&1 || python3() { python "$@"; }' in script
assert 'command -v python >/dev/null 2>&1 || python() { python3 "$@"; }' in script
def test_serve_preflight_failure_keeps_tmux_pane_visible():
@@ -606,3 +671,35 @@ def test_pip_install_no_cache_is_idempotent_and_scoped():
# not a pip install -> unchanged
assert _pip_install_no_cache("vllm serve --model x") == "vllm serve --model x"
assert _pip_install_no_cache("") == ""
def test_cached_model_scan_runs_additional_hf_cache(tmp_path):
extra_cache = tmp_path / "extra_hf_cache"
model_dir = extra_cache / "models--acme--sample-7b"
snap = model_dir / "snapshots" / "rev-1"
snap.mkdir(parents=True)
weights = snap / "model.safetensors"
weights.write_bytes(b"abc123")
scan_py = tmp_path / "scan_cache.py"
scan_py.write_text(
_cached_model_scan_script(add_hf_cache=str(extra_cache)),
encoding="utf-8",
)
proc = subprocess.run(
[sys.executable, str(scan_py)],
check=True,
capture_output=True,
text=True,
)
models = json.loads(proc.stdout)
by_repo = {m["repo_id"]: m for m in models}
assert "acme/sample-7b" in by_repo
rec = by_repo["acme/sample-7b"]
assert rec["path"] == str(extra_cache)
assert rec["nb_files"] == 1
assert rec["size_bytes"] == len(b"abc123")
assert rec["has_incomplete"] is False
assert rec["is_diffusion"] is False