Files
Cesc 254081462c fix(memory): apply Docker localhost rewrite in embedding provider constructor
Model listing and chat provider construction rewrite localhost to
host.docker.internal via config.DockerLocalhost() when running inside
Docker, but all three memory.NewOpenAIEmbeddingProvider call sites
(verify-embedding handler, runtime memory embedding) passed the raw
api_base through. In Docker the container resolved localhost to itself,
so Ollama Verify Embedding and runtime embedding failed with connection
refused while the model dropdown loaded fine.

Centralize the rewrite inside the constructor so no call site can miss
it, add a SetInDockerForTest hook for environment-independent regression
tests, and pin Docker detection off in httptest-based suites.

Fixes #1519
2026-08-21 10:57:36 +07:00

37 lines
998 B
Go

package config
import "testing"
func TestDockerLocalhostRewritesLoopbackInDocker(t *testing.T) {
restore := SetInDockerForTest(true)
defer restore()
cases := []struct {
name string
in string
want string
}{
{"localhost", "http://localhost:11434/v1", "http://host.docker.internal:11434/v1"},
{"loopback ip", "http://127.0.0.1:11434/v1", "http://host.docker.internal:11434/v1"},
{"non-loopback unchanged", "https://api.openai.com/v1", "https://api.openai.com/v1"},
{"empty", "", ""},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
if got := DockerLocalhost(tc.in); got != tc.want {
t.Fatalf("DockerLocalhost(%q) = %q, want %q", tc.in, got, tc.want)
}
})
}
}
func TestDockerLocalhostPassthroughOutsideDocker(t *testing.T) {
restore := SetInDockerForTest(false)
defer restore()
in := "http://localhost:11434/v1"
if got := DockerLocalhost(in); got != in {
t.Fatalf("DockerLocalhost(%q) = %q, want unchanged outside Docker", in, got)
}
}