Fix Cookbook container-local model endpoints (#1223)

Co-authored-by: ghreprimand <203024559+ghreprimand@users.noreply.github.com>
This commit is contained in:
ghreprimand
2026-06-02 10:09:48 -05:00
committed by GitHub
parent 37f5635f8f
commit 1fda906407
4 changed files with 130 additions and 30 deletions
+33
View File
@@ -49,6 +49,7 @@ from routes.model_routes import (
_ping_endpoint,
_probe_single_model,
_classify_endpoint,
_rewrite_loopback_for_docker,
_PROVIDER_CURATED,
)
@@ -192,6 +193,38 @@ class TestPingEndpoint:
}
# ── Docker loopback rewrite ──
class TestDockerLoopbackRewrite:
def test_manual_loopback_rewrites_to_docker_host_when_available(self, monkeypatch):
monkeypatch.setattr(model_routes, "_docker_host_gateway_reachable", lambda: True)
assert (
_rewrite_loopback_for_docker("http://localhost:8000/v1")
== "http://host.docker.internal:8000/v1"
)
def test_cookbook_container_local_loopback_stays_inside_container(self, monkeypatch):
monkeypatch.setattr(model_routes, "_docker_host_gateway_reachable", lambda: True)
assert (
_rewrite_loopback_for_docker("http://localhost:8000/v1", container_local=True)
== "http://localhost:8000/v1"
)
def test_bind_address_becomes_connectable_loopback_for_container_local(self, monkeypatch):
monkeypatch.setattr(model_routes, "_docker_host_gateway_reachable", lambda: True)
assert (
_rewrite_loopback_for_docker("http://0.0.0.0:8000/v1", container_local=True)
== "http://127.0.0.1:8000/v1"
)
def test_bind_address_becomes_connectable_loopback_on_native_install(self, monkeypatch):
monkeypatch.setattr(model_routes, "_docker_host_gateway_reachable", lambda: False)
assert (
_rewrite_loopback_for_docker("http://0.0.0.0:8000/v1")
== "http://127.0.0.1:8000/v1"
)
# ── _probe_single_model: completion probe ──
class TestProbeSingleModel: