Files
majordomo/builtin_llamaswap_test.go
steve de2b2f0f28
CI / Tidy (pull_request) Successful in 9m43s
CI / Build & Test (pull_request) Successful in 10m26s
Adversarial Review (Gadfly) / review (pull_request) Successful in 11m47s
feat(llamaswap): add llama-swaps (TLS) DSN scheme
llama-swap was http-only by DSN, pushing TLS-fronted instances onto the openai://
scheme (which loses the management/image methods). Add a "llama-swaps" scheme
that builds an https base URL, alongside "llama-swap" (http, local-first) —
mirroring redis/rediss. Both share one factory; llama-swaps is scheme-only (no
default built-in). The choice stays explicit because a DSN has no reliable
http-vs-https signal.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-27 17:58:59 -04:00

88 lines
2.5 KiB
Go

package majordomo
import (
"testing"
"gitea.stevedudenhoeffer.com/steve/majordomo/imagegen"
"gitea.stevedudenhoeffer.com/steve/majordomo/provider/llamaswap"
)
// TestLlamaSwapScheme covers the env-DSN wiring: a llama-swap:// DSN defines a
// named provider that builds an http:// base URL (local-first, unlike the
// https-always default), is first-class in Parse, and satisfies both the chat
// (llm.Provider) and image (imagegen.Provider) contracts.
func TestLlamaSwapScheme(t *testing.T) {
r := newTestRegistry(t)
if err := r.LoadEnv(map[string]string{
"LLM_LS": "llama-swap://tok@box.local:8080",
}); err != nil {
t.Fatalf("LoadEnv: %v", err)
}
p, ok := r.Provider("ls")
if !ok {
t.Fatal("provider \"ls\" not registered")
}
lp, ok := p.(*llamaswap.Provider)
if !ok {
t.Fatalf("provider is %T, want *llamaswap.Provider", p)
}
if lp.Name() != "ls" {
t.Errorf("name = %q, want ls", lp.Name())
}
// Local-first: http, not the DSN's https-always BaseURL.
if want := "http://box.local:8080"; lp.BaseURL() != want {
t.Errorf("baseURL = %q, want %q", lp.BaseURL(), want)
}
// Satisfies the image-generation contract too.
var _ imagegen.Provider = lp
if _, err := lp.ImageModel("sd"); err != nil {
t.Errorf("ImageModel: %v", err)
}
// First-class chain element.
m, err := r.Parse("ls/qwen3:14b")
if err != nil {
t.Fatalf("Parse: %v", err)
}
if got := targetsOf(t, m); len(got) != 1 || got[0] != "ls/qwen3:14b" {
t.Errorf("targets = %v", got)
}
}
// TestLlamaSwapsScheme: the "llama-swaps" scheme builds an https base URL for a
// TLS-fronted instance (vs "llama-swap" which is http local-first).
func TestLlamaSwapsScheme(t *testing.T) {
r := newTestRegistry(t)
if err := r.LoadEnv(map[string]string{
"LLM_LST": "llama-swaps://tok@swap.example.com",
}); err != nil {
t.Fatalf("LoadEnv: %v", err)
}
p, ok := r.Provider("lst")
if !ok {
t.Fatal("provider \"lst\" not registered")
}
lp, ok := p.(*llamaswap.Provider)
if !ok {
t.Fatalf("provider is %T, want *llamaswap.Provider", p)
}
if want := "https://swap.example.com"; lp.BaseURL() != want {
t.Errorf("baseURL = %q, want %q", lp.BaseURL(), want)
}
}
// TestLlamaSwapBuiltinNoURL: the no-DSN built-in resolves but errors clearly on
// use (mirrors foreman), rather than silently hitting a wrong host.
func TestLlamaSwapBuiltinNoURL(t *testing.T) {
r := newTestRegistry(t)
p, ok := r.Provider(ProviderLlamaSwap)
if !ok {
t.Fatal("built-in llama-swap provider not registered")
}
if _, err := p.Model("m"); err == nil {
t.Error("expected error from no-URL built-in Model")
}
}