Files
gadfly/cmd/gadfly/model_test.go
T
steveandClaude Opus 4.8 b23eeb8cbf
Build & push image / build-and-push (push) Successful in 7s
feat: bump majordomo + support llama-swap(s) provider spellings (#7)
Bump majordomo to the latest build and accept every llama-swap spelling
(llama-swap/llama-swaps + un-hyphenated llamaswap/llamaswaps) in gadfly's
endpoint switches; the LLM_* llama-swap(s):// DSN path already worked via
majordomo.Parse. README + error messages + endpointProvider alias tests.

Swarm review: 8/9 clean; qwen3-coder's "Blocking" was a false positive
(claimed llamaswap was untested — it has dedicated test cases). Folded in
its one fair nit (README now lists the un-hyphenated aliases).

gofmt clean, go vet quiet, go test -race green.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Co-authored-by: Steve Dudenhoeffer <[email protected]>
Co-committed-by: Steve Dudenhoeffer <[email protected]>
2026-06-27 23:18:56 +00:00

92 lines
3.2 KiB
Go

package main
import "testing"
func TestEndpointProvider(t *testing.T) {
t.Run("ollama http endpoint registers under its name", func(t *testing.T) {
p, err := endpointProvider("bigbox", "ollama|http://192.168.1.50:11434")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if p.Name() != "bigbox" {
t.Errorf("Name() = %q, want %q", p.Name(), "bigbox")
}
})
t.Run("openai compatible with key", func(t *testing.T) {
if _, err := endpointProvider("gpu", "openai|http://gpu.lan:8000/v1|sk-x"); err != nil {
t.Fatalf("unexpected error: %v", err)
}
})
t.Run("foreman queue registers under its name", func(t *testing.T) {
p, err := endpointProvider("m1", "foreman|http://foreman-m1:8080|tok")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
// WithName(name) must win over the Foreman preset's default "foreman".
if p.Name() != "m1" {
t.Errorf("Name() = %q, want %q", p.Name(), "m1")
}
})
t.Run("foreman without token", func(t *testing.T) {
if _, err := endpointProvider("m5", "foreman|http://foreman-m5:8080"); err != nil {
t.Fatalf("unexpected error: %v", err)
}
})
t.Run("llamaswap registers under its name", func(t *testing.T) {
p, err := endpointProvider("ls", "llamaswap|http://swap.lan:8080|tok")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if p.Name() != "ls" {
t.Errorf("Name() = %q, want %q", p.Name(), "ls")
}
})
t.Run("llamaswap without token", func(t *testing.T) {
if _, err := endpointProvider("ls2", "llamaswap|http://swap.lan:8080"); err != nil {
t.Fatalf("unexpected error: %v", err)
}
})
// All llama-swap spellings (hyphenated/TLS variants mirror majordomo's DSN
// schemes) must resolve to the llamaswap provider.
for _, name := range []string{"llama-swap", "llama-swaps", "llamaswaps"} {
t.Run(name+" alias", func(t *testing.T) {
p, err := endpointProvider("ls", name+"|https://swap.lan:8080|tok")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if p.Name() != "ls" {
t.Errorf("Name() = %q, want %q", p.Name(), "ls")
}
})
}
for _, bad := range []string{"", "ollama", "noprovider-no-pipe", "mystery|http://x"} {
t.Run("rejects "+bad, func(t *testing.T) {
if _, err := endpointProvider("n", bad); err == nil {
t.Errorf("endpointProvider(%q) = nil error, want error", bad)
}
})
}
}
func TestBuildSpec(t *testing.T) {
tests := []struct {
name string
provider string
model string
want string
}{
{"bare id gets provider prefix", "ollama-cloud", "qwen3-coder:480b-cloud", "ollama-cloud/qwen3-coder:480b-cloud"},
{"bare id local ollama", "ollama", "llama3.1", "ollama/llama3.1"},
{"already has provider passes through", "ollama-cloud", "openai/gpt-4o", "openai/gpt-4o"},
{"slashed model name passes through verbatim", "openai", "openai/meta-llama/Llama-3.1", "openai/meta-llama/Llama-3.1"},
{"failover chain passes through", "ollama-cloud", "anthropic/opus-4.8,ollama-cloud/qwen3-coder:480b-cloud", "anthropic/opus-4.8,ollama-cloud/qwen3-coder:480b-cloud"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := buildSpec(tt.provider, tt.model); got != tt.want {
t.Errorf("buildSpec(%q, %q) = %q, want %q", tt.provider, tt.model, got, tt.want)
}
})
}
}