Files
majordomo/builtin_llamaswap_test.go
T
steve 96c612e707
CI / Tidy (pull_request) Successful in 9m25s
CI / Build & Test (pull_request) Successful in 10m15s
feat(llamaswap): add llama-swap provider + canonical imagegen interface
Add provider/llamaswap, a tailored provider for llama-swap (the model-swapping
proxy over llama.cpp / stable-diffusion.cpp). Its chat path delegates to
provider/openai at {base}/v1 — no duplicated wire client (ADR-0007) — with
legacy max_tokens, a Bearer no-key placeholder for keyless local instances, and
a timeout-free client so cold model swaps rely on context deadlines. The
"tailored" surface is concrete management methods (ListModels / Running /
Unload) that don't belong on the canonical llm.Provider interface. The
llama-swap:// DSN scheme builds an http base URL (local-first); a no-URL
built-in errors clearly on use, mirroring foreman.

Add imagegen, a new canonical text-to-image interface separate from llm
(Request/Result/Model/Provider; Image = llm.ImagePart so generated images feed
straight back into chat). First backend is llama-swap via OpenAI
/v1/images/generations (b64_json, bytes-only). Re-exported from the root. v1 is
txt2img only.

Hermetic httptest coverage for chat delegation, management endpoints, image
decode, and scheme wiring. ADR-0015 + ADR-0016, README support matrix +
image-gen section, CLAUDE.md package map, and progress.md updated in the same
commit.

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

66 lines
1.9 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)
}
}
// 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")
}
}