From 2b2f4110da53a03742faff89cdec17c55e091a90 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Thu, 11 Jun 2026 00:21:50 +0300 Subject: 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 --- internal/llm/openrouter_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'internal/llm/openrouter_test.go') diff --git a/internal/llm/openrouter_test.go b/internal/llm/openrouter_test.go index 07d6e0f..f42459e 100644 --- a/internal/llm/openrouter_test.go +++ b/internal/llm/openrouter_test.go @@ -35,7 +35,7 @@ func TestOpenRouter_Chat_SendsHeadersAndBody(t *testing.T) { })) defer srv.Close() - c := newOpenRouter(srv.URL, "anthropic/claude-test", "KEY", f64p(0.2)).(openRouterClient) + c := newOpenRouter(srv.URL, "anthropic/claude-test", "KEY", f64p(0.2)) c.httpClient = srv.Client() out, err := c.Chat(context.Background(), []Message{{Role: "user", Content: "ping"}}) if err != nil { @@ -81,7 +81,7 @@ func TestOpenRouter_ChatStream_SendsHeaders(t *testing.T) { })) defer srv.Close() - c := newOpenRouter(srv.URL, "anthropic/claude-test", "KEY", f64p(0.2)).(openRouterClient) + c := newOpenRouter(srv.URL, "anthropic/claude-test", "KEY", f64p(0.2)) c.httpClient = srv.Client() var got string err := c.ChatStream(context.Background(), []Message{{Role: "user", Content: "ping"}}, func(s string) { got += s }) @@ -100,7 +100,7 @@ func TestOpenRouter_ChatStream_SendsHeaders(t *testing.T) { } func TestOpenRouter_Chat_MissingKey(t *testing.T) { - c := newOpenRouter("http://example", "anthropic/claude-test", "", f64p(0.2)).(openRouterClient) + c := newOpenRouter("http://example", "anthropic/claude-test", "", f64p(0.2)) if _, err := c.Chat(context.Background(), []Message{{Role: "user", Content: "ping"}}); err == nil { t.Fatalf("expected error for missing api key") } else if !strings.Contains(err.Error(), "OPENROUTER_API_KEY") || !strings.Contains(err.Error(), "HEXAI_OPENROUTER_API_KEY") { @@ -111,7 +111,7 @@ func TestOpenRouter_Chat_MissingKey(t *testing.T) { func TestOpenRouter_DefaultsAndMetadata(t *testing.T) { logger := log.New(io.Discard, "", 0) logging.Bind(logger) - c := newOpenRouter("", "", "KEY", nil).(openRouterClient) + c := newOpenRouter("", "", "KEY", nil) if c.baseURL != "https://openrouter.ai/api/v1" { t.Fatalf("default baseURL mismatch: %s", c.baseURL) } -- cgit v1.2.3