summaryrefslogtreecommitdiff
path: root/internal/llm/openai_http_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-06-11 00:21:50 +0300
committerPaul Buetow <paul@buetow.org>2026-06-11 00:21:50 +0300
commit2b2f4110da53a03742faff89cdec17c55e091a90 (patch)
treeb0c355f2470dbf984f373e0dcc45f12d00960a98 /internal/llm/openai_http_test.go
parent1f3ae20a9830fd776f6ef3c11b4c198154b8205f (diff)
llm: return concrete client types from provider constructors
Follow the Go idiom "return concrete types, accept interfaces": the provider constructors newOpenAI, newAnthropic, newOpenRouter, newOllama and their *WithTimeout variants now return their concrete *Client value types instead of the Client interface. The provider factories registered in the registry still return Client, so NewFromConfig and the registry keep working unchanged. Updated comments to explain the reasoning, dropped the now-redundant type assertions in tests, and switched the anthropic Streamer-capability tests to assert via an explicit Client interface value. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'internal/llm/openai_http_test.go')
-rw-r--r--internal/llm/openai_http_test.go18
1 files changed, 9 insertions, 9 deletions
diff --git a/internal/llm/openai_http_test.go b/internal/llm/openai_http_test.go
index d0fc828..400ac18 100644
--- a/internal/llm/openai_http_test.go
+++ b/internal/llm/openai_http_test.go
@@ -23,7 +23,7 @@ func TestOpenAI_Chat_Success(t *testing.T) {
_ = json.NewEncoder(w).Encode(map[string]any{"choices": []map[string]any{{"index": 0, "message": map[string]string{"role": "assistant", "content": "OK"}}}})
}))
defer srv.Close()
- c := newOpenAI(srv.URL, "g", "KEY", f64p(0.2)).(openAIClient)
+ c := newOpenAI(srv.URL, "g", "KEY", f64p(0.2))
c.httpClient = srv.Client()
out, err := c.Chat(context.Background(), []Message{{Role: "user", Content: "hi"}})
if err != nil || out != "OK" {
@@ -32,7 +32,7 @@ func TestOpenAI_Chat_Success(t *testing.T) {
}
func TestOpenAI_Chat_MissingKey(t *testing.T) {
- c := newOpenAI("http://x", "g", "", f64p(0.2)).(openAIClient)
+ c := newOpenAI("http://x", "g", "", f64p(0.2))
if _, err := c.Chat(context.Background(), []Message{{Role: "user", Content: "hi"}}); err == nil {
t.Fatalf("expected error for missing key")
}
@@ -49,7 +49,7 @@ func TestOpenAI_ChatStream_SSE(t *testing.T) {
_, _ = io.WriteString(w, "data: [DONE]\n")
}))
defer srv.Close()
- c := newOpenAI(srv.URL, "g", "KEY", f64p(0.2)).(openAIClient)
+ c := newOpenAI(srv.URL, "g", "KEY", f64p(0.2))
c.httpClient = srv.Client()
var got string
err := c.ChatStream(context.Background(), []Message{{Role: "user", Content: "hi"}}, func(s string) { got += s })
@@ -75,7 +75,7 @@ func TestOpenAI_ChatStream_SSE_ErrorChunk(t *testing.T) {
_, _ = io.WriteString(w, "data: [DONE]\n")
}))
defer srv.Close()
- c := newOpenAI(srv.URL, "g", "KEY", f64p(0.2)).(openAIClient)
+ c := newOpenAI(srv.URL, "g", "KEY", f64p(0.2))
c.httpClient = srv.Client()
var got string
if err := c.ChatStream(context.Background(), []Message{{Role: "user", Content: "hi"}}, func(s string) { got += s }); err == nil {
@@ -91,7 +91,7 @@ func TestOpenAI_Chat_NoChoices_Error(t *testing.T) {
_ = json.NewEncoder(w).Encode(map[string]any{"choices": []any{}})
}))
defer srv.Close()
- c := newOpenAI(srv.URL, "g", "KEY", f64p(0.2)).(openAIClient)
+ c := newOpenAI(srv.URL, "g", "KEY", f64p(0.2))
c.httpClient = srv.Client()
if _, err := c.Chat(context.Background(), []Message{{Role: "user", Content: "hi"}}); err == nil {
t.Fatalf("expected error when choices empty")
@@ -108,7 +108,7 @@ func TestOpenAI_ChatStream_SSE_EmptyDelta_NoError(t *testing.T) {
_, _ = io.WriteString(w, "data: [DONE]\\n")
}))
defer srv.Close()
- c := newOpenAI(srv.URL, "g", "KEY", f64p(0.2)).(openAIClient)
+ c := newOpenAI(srv.URL, "g", "KEY", f64p(0.2))
c.httpClient = srv.Client()
var got string
if err := c.ChatStream(context.Background(), []Message{{Role: "user", Content: "hi"}}, func(s string) { got += s }); err != nil {
@@ -129,7 +129,7 @@ func TestOpenAI_Chat_DecodeError_StatusOK(t *testing.T) {
_, _ = io.WriteString(w, "{invalid")
}))
defer srv.Close()
- c := newOpenAI(srv.URL, "g", "KEY", f64p(0.2)).(openAIClient)
+ c := newOpenAI(srv.URL, "g", "KEY", f64p(0.2))
c.httpClient = srv.Client()
if _, err := c.Chat(context.Background(), []Message{{Role: "user", Content: "hi"}}); err == nil {
t.Fatalf("expected decode error for invalid JSON body")
@@ -150,7 +150,7 @@ func TestOpenAI_Chat_MultiChoiceAndErrorBody(t *testing.T) {
})
}))
defer srv.Close()
- c := newOpenAI(srv.URL, "g", "KEY", f64p(0.2)).(openAIClient)
+ c := newOpenAI(srv.URL, "g", "KEY", f64p(0.2))
c.httpClient = srv.Client()
out, err := c.Chat(context.Background(), []Message{{Role: "user", Content: "hi"}})
if err != nil || out != "FIRST" {
@@ -163,7 +163,7 @@ func TestOpenAI_Chat_MultiChoiceAndErrorBody(t *testing.T) {
_ = json.NewEncoder(w).Encode(map[string]any{"error": map[string]any{"message": "bad", "type": "invalid"}})
}))
defer srv2.Close()
- c2 := newOpenAI(srv2.URL, "g", "KEY", f64p(0.2)).(openAIClient)
+ c2 := newOpenAI(srv2.URL, "g", "KEY", f64p(0.2))
c2.httpClient = srv2.Client()
if _, err := c2.Chat(context.Background(), []Message{{Role: "user", Content: "hi"}}); err == nil {
t.Fatalf("expected error from non-2xx with error body")