summaryrefslogtreecommitdiff
path: root/internal/lsp/llm_client_registry_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-10 19:34:02 +0200
committerPaul Buetow <paul@buetow.org>2026-03-10 19:34:02 +0200
commitde5029e6d4a7efffcccfb08d98770b1c1c4f54fe (patch)
tree7429b9a72c96393ca74d323faf4f989224e83db0 /internal/lsp/llm_client_registry_test.go
parentba4b4b340b17450fa86122f227a75ef054e0ad53 (diff)
task bf088a70: extract LSP client and completion state
Diffstat (limited to 'internal/lsp/llm_client_registry_test.go')
-rw-r--r--internal/lsp/llm_client_registry_test.go65
1 files changed, 65 insertions, 0 deletions
diff --git a/internal/lsp/llm_client_registry_test.go b/internal/lsp/llm_client_registry_test.go
new file mode 100644
index 0000000..5700a53
--- /dev/null
+++ b/internal/lsp/llm_client_registry_test.go
@@ -0,0 +1,65 @@
+package lsp
+
+import (
+ "errors"
+ "testing"
+
+ "codeberg.org/snonux/hexai/internal/appconfig"
+ "codeberg.org/snonux/hexai/internal/llm"
+)
+
+func TestLLMClientRegistryClientFor_CachesAlternateProviders(t *testing.T) {
+ registry := newLLMClientRegistry()
+ registry.applyOptions(fakeClient{name: "openai", model: "gpt-5.0"}, "openai")
+
+ cfg := appconfig.App{}
+ spec := requestSpec{
+ provider: "anthropic",
+ entry: appconfig.SurfaceConfig{Model: "claude-3-7-sonnet"},
+ fallbackModel: "claude-3-7-sonnet",
+ }
+
+ buildCalls := 0
+ builder := func(_ appconfig.App, provider, modelOverride string) (llm.Client, error) {
+ buildCalls++
+ return fakeClient{name: provider, model: modelOverride}, nil
+ }
+
+ first := registry.clientFor(spec, cfg, builder)
+ second := registry.clientFor(spec, cfg, builder)
+ if first == nil || second == nil {
+ t.Fatal("expected alternate provider client")
+ }
+ if buildCalls != 1 {
+ t.Fatalf("expected one build for cached alternate client, got %d", buildCalls)
+ }
+ if first.Name() != "anthropic" || second.Name() != "anthropic" {
+ t.Fatalf("expected anthropic client, got %q and %q", first.Name(), second.Name())
+ }
+}
+
+func TestLLMClientRegistryClientFor_FallsBackToBaseClientOnBuildError(t *testing.T) {
+ base := fakeClient{name: "openai", model: "gpt-5.0"}
+ registry := newLLMClientRegistry()
+ registry.applyOptions(base, "openai")
+
+ spec := requestSpec{provider: "anthropic"}
+ builder := func(appconfig.App, string, string) (llm.Client, error) {
+ return nil, errors.New("boom")
+ }
+
+ got := registry.clientFor(spec, appconfig.App{}, builder)
+ if got != base {
+ t.Fatalf("expected base client fallback, got %#v", got)
+ }
+}
+
+func TestLLMClientRegistryCurrent_ReturnsConfiguredClient(t *testing.T) {
+ registry := newLLMClientRegistry()
+ client := fakeClient{name: "openrouter", model: "gpt-4.1-mini"}
+ registry.applyOptions(client, "openrouter")
+
+ if got := registry.current(); got != client {
+ t.Fatalf("expected configured client, got %#v", got)
+ }
+}