434d721b99
- New leaf package `audio` (ADR-0017): SpeechModel/SpeechProvider and TranscriptionModel/TranscriptionProvider with imagegen conventions (zero value = backend default, functional options + Apply, bytes in/out, never URLs). Root re-exports added. - imagegen.Editor (ADR-0018): optional image-to-image interface — EditRequest carries the generation knobs plus Init image and denoising Strength; separate interface so existing Models keep compiling. - provider/llamaswap implements all of it: POST /v1/audio/speech (JSON, raw-audio response, MIME from Content-Type with format fallback), POST /v1/audio/transcriptions (multipart, response_format=json), ListVoices (GET /v1/audio/voices?model=, tolerant of string-list and object-list shapes), POST /sdapi/v1/img2img (txt2img wire + init_images/denoising_strength, shared image decode), and Health(ctx) (GET /health) — a cheap liveness probe for often-offline hosts. - Hermetic httptest coverage for every new wire shape and validation path; README sections + support-matrix footnote updated in the same commit (also corrects the stale /v1/images/generations claim — the image path has been SDAPI since the seed fix). First consumer: mort's llamaswap media tool cluster (status / image / TTS / STT agent tools against the netherstorm host). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AXQxVhXBw8PwFAtsVrXSmj
60 lines
1.5 KiB
Go
60 lines
1.5 KiB
Go
package llamaswap
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestHealth(t *testing.T) {
|
|
var gotPath, gotAuth string
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
gotPath = r.URL.Path
|
|
gotAuth = r.Header.Get("Authorization")
|
|
_, _ = w.Write([]byte("OK"))
|
|
}))
|
|
defer srv.Close()
|
|
|
|
p := New(WithBaseURL(srv.URL), WithToken("tok"), WithHTTPClient(srv.Client()))
|
|
if err := p.Health(context.Background()); err != nil {
|
|
t.Fatalf("Health: %v", err)
|
|
}
|
|
if gotPath != "/health" || gotAuth != "Bearer tok" {
|
|
t.Errorf("path/auth = %q/%q", gotPath, gotAuth)
|
|
}
|
|
}
|
|
|
|
func TestHealthUnhealthyStatus(t *testing.T) {
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
w.WriteHeader(http.StatusBadGateway)
|
|
}))
|
|
defer srv.Close()
|
|
|
|
p := New(WithBaseURL(srv.URL), WithHTTPClient(srv.Client()))
|
|
err := p.Health(context.Background())
|
|
if err == nil || !strings.Contains(err.Error(), "502") {
|
|
t.Errorf("err = %v, want status-502 error", err)
|
|
}
|
|
}
|
|
|
|
func TestHealthUnreachable(t *testing.T) {
|
|
// A closed server: transport error, not an HTTP status.
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}))
|
|
url := srv.URL
|
|
srv.Close()
|
|
|
|
p := New(WithBaseURL(url))
|
|
if err := p.Health(context.Background()); err == nil {
|
|
t.Error("want error for unreachable host")
|
|
}
|
|
}
|
|
|
|
func TestHealthNoBaseURL(t *testing.T) {
|
|
p := New()
|
|
if err := p.Health(context.Background()); err == nil {
|
|
t.Error("want error without base URL")
|
|
}
|
|
}
|