Files
sausheong 50b791d3b6 Rename providers/ollama to providers/local
Ollama is one local-model server among several (LM Studio, llama.cpp's
server, vLLM, ...) that all speak the same OpenAI-compatible shape —
naming the package (and provider name downstream) after one of them
was misleading. Same constructor, same default endpoint (Ollama's,
being the most common), just generically named: NewLocalProvider.

This renames a package published minutes ago in v0.3.8 with no other
known consumers yet, so no compatibility shim is kept.
2026-09-07 13:27:58 +08:00

47 lines
1.4 KiB
Go

package local
import (
"context"
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/require"
"github.com/sausheong/harness/llm"
)
func TestDefaultBaseURL(t *testing.T) {
require.Equal(t, "http://localhost:11434/v1", DefaultBaseURL)
}
// TestNewLocalProvider_HitsGivenBaseURL confirms a custom baseURL
// overrides the default and is actually what the provider talks to.
func TestNewLocalProvider_HitsGivenBaseURL(t *testing.T) {
var hit bool
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
hit = true
w.Header().Set("Content-Type", "text/event-stream")
_, _ = w.Write([]byte("data: [DONE]\n\n"))
}))
t.Cleanup(srv.Close)
p := NewLocalProvider(srv.URL + "/v1")
stream, err := p.ChatStream(context.Background(), llm.ChatRequest{SystemPrompt: "hi"})
require.NoError(t, err)
for range stream {
}
require.True(t, hit, "provider did not hit the configured baseURL")
}
// TestNewLocalProvider_EmptyBaseURLDoesNotPanic confirms the empty ->
// DefaultBaseURL fallback path constructs a usable provider (the actual
// outbound host isn't inspectable from outside the openai package —
// OpenAIProvider's client config is unexported — so this checks the
// fallback doesn't panic or return nil, and DefaultBaseURL's own value
// is asserted separately above).
func TestNewLocalProvider_EmptyBaseURLDoesNotPanic(t *testing.T) {
p := NewLocalProvider("")
require.NotNil(t, p)
}