fix(cookbook): default Ollama serve to loopback (#872)

This commit is contained in:
lolwuttav
2026-06-01 21:27:04 -06:00
committed by GitHub
parent ffb77d7ff2
commit c99193041a
6 changed files with 95 additions and 9 deletions

View File

@@ -11,6 +11,7 @@ from routes.cookbook_helpers import (
_append_serve_preflight_exit_lines,
_local_tooling_path_export,
_pip_install_fallback_chain,
_ollama_bind_from_cmd,
_safe_env_prefix,
_validate_gpus,
_validate_repo_id,
@@ -130,6 +131,40 @@ def test_serve_runner_preserves_command_exit_code():
assert 'echo "=== Process exited with code $? ==="' not in script
def test_ollama_serve_defaults_to_loopback_bind():
assert _ollama_bind_from_cmd("ollama serve") == ("127.0.0.1", "11434")
assert _ollama_bind_from_cmd("ollama run qwen2.5:0.5b") == ("127.0.0.1", "11434")
def test_ollama_serve_accepts_remote_reachable_default_bind():
assert (
_ollama_bind_from_cmd("ollama serve", default_host="0.0.0.0")
== ("0.0.0.0", "11434")
)
def test_ollama_serve_preserves_explicit_bind_opt_in():
assert (
_ollama_bind_from_cmd("OLLAMA_HOST=0.0.0.0:12345 ollama serve")
== ("0.0.0.0", "12345")
)
assert (
_ollama_bind_from_cmd("OLLAMA_HOST=[::1]:11435 ollama serve")
== ("[::1]", "11435")
)
def test_ollama_serve_rejects_unsafe_bind_values():
assert (
_ollama_bind_from_cmd("OLLAMA_HOST='$HOST:11434' ollama serve")
== ("127.0.0.1", "11434")
)
assert (
_ollama_bind_from_cmd("OLLAMA_HOST=127.0.0.1:99999 ollama serve")
== ("127.0.0.1", "11434")
)
def test_cached_model_scan_reports_plain_dir_gguf(tmp_path):
"""Custom download dirs may sit inside the HF hub cache and contain plain
per-model folders. They must show up in Serve and keep the GGUF signal."""

View File

@@ -125,6 +125,18 @@ def test_readme_native_quickstart_uses_loopback():
assert "Use `--host 0.0.0.0` only when you intentionally want" in readme
def test_ollama_cookbook_runner_does_not_force_public_bind():
route = Path("routes/cookbook_routes.py").read_text(encoding="utf-8")
cookbook_js = Path("static/js/cookbook.js").read_text(encoding="utf-8")
assert 'OLLAMA_HOST="0.0.0.0:${ODYSSEUS_OLLAMA_PORT}" ollama serve' not in route
assert 'OLLAMA_HOST="${ODYSSEUS_OLLAMA_HOST}:${ODYSSEUS_OLLAMA_PORT}" ollama serve' in route
assert '_ollama_default_host = "0.0.0.0" if remote else "127.0.0.1"' in route
assert "WARNING: remote Ollama will bind" in route
assert "OLLAMA_HOST=0.0.0.0:${ollamaPort}" not in cookbook_js
assert "const bindHost = _envState.remoteHost ? '0.0.0.0' : '127.0.0.1';" in cookbook_js
assert "OLLAMA_HOST=${bindHost}:${ollamaPort}" in cookbook_js
def _import_integrations(tmp_path, monkeypatch):
"""Import src.integrations with data + encryption key redirected to tmp."""
_import_secret_storage(tmp_path, monkeypatch)