fix(cookbook): treat local Windows as Windows for serve commands (#3975)

* fix(cookbook): prefer native llama-server on local Windows

* fix(cookbook): harden local llama-server launch commands

* fix(cookbook): build serve commands for selected target
This commit is contained in:
Dividesbyzer0
2026-06-26 08:13:01 -04:00
committed by GitHub
parent de12d4734a
commit f5200ec45b
7 changed files with 190 additions and 36 deletions
+101 -3
View File
@@ -1,4 +1,4 @@
"""Regression guard for issue #1291 CPU-only serve still emitted GPU-only flags.
"""Regression guard for issue #1291 - CPU-only serve still emitted GPU-only flags.
The llama.cpp serve command builder (static/js/cookbook.js) added
`--flash-attn on` and exported `GGML_CUDA_ENABLE_UNIFIED_MEMORY=1` from
@@ -16,8 +16,8 @@ from pathlib import Path
SRC = Path(__file__).resolve().parent.parent / "static/js/cookbook.js"
SERVE_SRC = Path(__file__).resolve().parent.parent / "static/js/cookbookServe.js"
ROUTES_SRC = Path(__file__).resolve().parent.parent / "routes/cookbook_routes.py"
ROOT = SRC.parent.parent.parent
ROUTES_SRC = ROOT / "routes/cookbook_routes.py"
def test_cpu_only_drops_gpu_only_flags():
text = SRC.read_text(encoding="utf-8")
@@ -84,3 +84,101 @@ def test_vllm_route_strips_swap_space_when_runtime_rejects_it():
assert "print(shlex.join(parts[:serve_i + 1] + [\"--help\"]))" in text
assert "eval \"$ODYSSEUS_VLLM_HELP_CMD\" 2>&1 | grep -q -- \"--swap-space\"" in text
assert "eval \"$ODYSSEUS_SERVE_CMD\"" in text
def test_local_windows_platform_comes_from_backend_host_state():
text = SRC.read_text(encoding="utf-8")
routes = ROUTES_SRC.read_text(encoding="utf-8")
running = (SRC.parent / "cookbookRunning.js").read_text(encoding="utf-8")
assert "hostPlatform" in text
assert "navigator.platform" not in text
assert "hostOrTask === 'local'" in text
assert "if (hostOrTask === 'local') return _envState.hostPlatform || '';" in text
assert "return _envState.hostPlatform || _envState.platform || ''" not in text
assert "s.platform = _envState.hostPlatform || '';" in text
assert "platform: _envState.hostPlatform || ''" in text
assert "s.platform = _envState.hostPlatform || _envState.platform || '';" not in text
assert "platform: _envState.hostPlatform || _envState.platform || ''" not in text
assert 'return "windows" if IS_WINDOWS else ""' in routes
assert 'env["hostPlatform"] = _client_host_platform()' in routes
assert "return _state_for_client({})" in routes
assert 'env.pop("hostPlatform", None)' in routes
assert "delete env.hostPlatform;" in running
def test_local_serve_payload_ignores_stale_env_platform():
serve = SERVE_SRC.read_text(encoding="utf-8")
running = (SRC.parent / "cookbookRunning.js").read_text(encoding="utf-8")
assert "platform: host ? (server?.platform || '') : (_envState.hostPlatform || '')," in serve
assert "platform: server?.platform || _envState.platform || ''" not in serve
assert "const _hplatform = _host ? (_hsrv.platform || '') : (_envState.hostPlatform || '');" in running
assert "const _hplatform = _host ? (_hsrv.platform || '') : (_envState.platform || '');" not in running
def test_local_windows_llamacpp_prefers_native_llama_server():
text = SRC.read_text(encoding="utf-8")
helpers = (ROOT / "routes/cookbook_helpers.py").read_text(encoding="utf-8")
assert "Object.prototype.hasOwnProperty.call(f, 'host')" in text
assert "const _isWin = _targetHost ? _isWindows(_targetHost) : _isWindows('local');" in text
assert "const _localWindows = _isWin && !_targetHost;" in text
assert "const _curHost = _targetHost;" in text
assert "const _localWindows = _isWin && !_envState.remoteHost;" not in text
assert "const gpuId = (f.gpus || f.gpu_id || '').toString().trim();" in text
assert "const _lcServer = `${lcPrefix}llama-server --model" in text
assert "if (_localWindows) {" in text
assert "cmd += _lcServer;" in text
assert '"llama-server.exe"' in helpers
def test_serve_command_preview_uses_selected_target_host():
text = SERVE_SRC.read_text(encoding="utf-8")
assert "const buildTarget = _selectedServeTarget(panel);" in text
assert "f.host = buildTarget.host || '';" in text
assert "f.platform = buildTarget.platform || '';" in text
assert "const hostField = panel.querySelector('[data-field=\"host\"]');" in text
assert "if (hostField) hostField.value = f.host;" in text
def test_local_windows_llama_server_skips_source_bootstrap():
routes = ROUTES_SRC.read_text(encoding="utf-8")
assert 'local_windows_llama_cmd = local_windows and ("llama_cpp" in req.cmd or "llama-server" in req.cmd)' in routes
assert 'if ("llama_cpp" in req.cmd or "llama-server" in req.cmd) and not local_windows_llama_cmd:' in routes
def test_local_windows_llama_server_path_includes_user_wrapper_and_cuda_builds():
routes = (ROOT / "routes/cookbook_routes.py").read_text(encoding="utf-8")
assert 'if local_windows:' in routes
assert (
'export PATH="$HOME/bin:$HOME/llama.cpp/build-cuda/bin/Release:'
'$HOME/llama.cpp/build/bin/Release:$HOME/llama.cpp/build/bin/Debug:'
'$HOME/llama.cpp/build/bin:$PATH"'
) in routes
def test_serve_panel_keeps_row_markup_and_launch_cmd_assignment_executable():
text = SERVE_SRC.read_text(encoding="utf-8").replace("\r\n", "\n")
assert '// Row 1: Engine + Server + Env panelHtml +=' not in text
assert "px'; panel._cmd = cmd;" not in text
assert '// Row 1: Engine + Server + Env\n panelHtml += `<div class="hwfit-serve-row">`;' in text
assert "px';\n panel._cmd = cmd;" in text
def test_llamacpp_vision_uses_scanned_projector_instead_of_runtime_find():
text = SERVE_SRC.read_text(encoding="utf-8")
assert "function _projectorGgufFiles(model)" in text
assert "const selectedProjector = _projectorGgufFiles(m)[0];" in text
assert "f._mmproj_path = selectedProjector ? _selectedGgufExpr(m, repo, selectedProjector.rel_path) : '';" in text
assert "const missingVisionProjector = backend === 'llamacpp' && !!f.vision && !f._mmproj_path;" in text
assert "hwfit-serve-vision-warn" in text
assert "!/(?:^|\\s)(?:--mmproj|--clip_model_path)\\b/.test(launchCmd)" in text
assert "no mmproj projector is in the launch command" in text
assert "find ${_vsearchdir} -iname 'mmproj*.gguf'" not in text
+13 -6
View File
@@ -419,8 +419,6 @@ def test_pip_install_attempt_failure_propagates_real_exit_code():
"""Run the generated snippet against a deliberately broken pip install
to confirm the subshell exits with pip's non-zero status."""
snippet = _pip_install_attempt("python3 -m pip install __nonexistent_package_12345__")
if sys.platform == "win32":
snippet = snippet.replace("$", "\\$")
result = subprocess.run(
["bash", "-c", snippet],
capture_output=True,
@@ -433,8 +431,6 @@ def test_pip_install_attempt_failure_propagates_real_exit_code():
def test_pip_install_attempt_success_exits_zero():
"""When pip succeeds, the subshell should exit 0."""
snippet = _pip_install_attempt("python3 -c 'pass'")
if sys.platform == "win32":
snippet = snippet.replace("$", "\\$")
result = subprocess.run(
["bash", "-c", snippet],
capture_output=True,
@@ -447,8 +443,6 @@ def test_pip_install_attempt_success_exits_zero():
def test_pip_install_attempt_surfaces_stderr_on_failure():
"""On failure, the last 5 lines of pip output should appear in stdout."""
snippet = _pip_install_attempt("python3 -m pip install __nonexistent_package_12345__")
if sys.platform == "win32":
snippet = snippet.replace("$", "\\$")
result = subprocess.run(
["bash", "-c", snippet],
capture_output=True,
@@ -557,6 +551,19 @@ def test_validate_serve_cmd_accepts_windows_printf_format():
assert _validate_serve_cmd(cmd) == cmd
def test_validate_serve_cmd_accepts_llama_mmproj_printf_format():
cmd = (
"CUDA_VISIBLE_DEVICES=0 llama-server --model "
"\"$(printf %s ${HOME}'/.cache/huggingface/hub/models--unsloth--Qwen3.6-35B-A3B-GGUF/snapshots/abc/Qwen3.6-35B-A3B-UD-Q4_K_M.gguf')\" "
"--host 0.0.0.0 --port 8000 -ngl 99 -c 20000 "
"--cache-type-k q4_0 --cache-type-v q4_0 --mmproj "
"\"$(printf %s ${HOME}'/.cache/huggingface/hub/models--unsloth--Qwen3.6-35B-A3B-GGUF/snapshots/abc/mmproj-BF16.gguf')\" "
"--image-max-tokens 1024"
)
assert _validate_serve_cmd(cmd) == cmd
def test_normalize_llama_cpp_python_cache_types_for_stale_client_cmd():
cmd = (
"python -m llama_cpp.server --model model.gguf --host 0.0.0.0 --port 8000 "