8e82a23555
CI / docker (push) Successful in 2m49s
Add model input defaults (including prompt), workflow model editing, and ingress API docs. Co-authored-by: Cursor <cursoragent@cursor.com>
56 lines
1.6 KiB
Go
56 lines
1.6 KiB
Go
package prediction
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/rose_cat707/luminary/internal/model"
|
|
)
|
|
|
|
func TestValidateInputWithDefaultsOverride(t *testing.T) {
|
|
overrides := map[string]any{"width": float64(768), "steps": float64(30)}
|
|
out, err := ValidateInputWithDefaults(model.WorkflowTxt2Img, map[string]any{
|
|
"prompt": "hello",
|
|
}, overrides)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if out["width"] != 768 && out["width"] != float64(768) {
|
|
t.Fatalf("width got %#v", out["width"])
|
|
}
|
|
if out["steps"] != 30 && out["steps"] != float64(30) {
|
|
t.Fatalf("steps got %#v", out["steps"])
|
|
}
|
|
}
|
|
|
|
func TestOpenAPISchemaUsesModelDefaults(t *testing.T) {
|
|
schema := OpenAPISchemaForWorkflow(model.WorkflowTxt2Img, "flux", "desc", map[string]any{
|
|
"width": float64(768),
|
|
})
|
|
components := schema["components"].(map[string]any)
|
|
schemas := components["schemas"].(map[string]any)
|
|
input := schemas["Input"].(map[string]any)
|
|
props := input["properties"].(map[string]any)
|
|
width := props["width"].(map[string]any)
|
|
if width["default"] != float64(768) {
|
|
t.Fatalf("unexpected width default %#v", width["default"])
|
|
}
|
|
}
|
|
|
|
func TestValidateInputPromptDefault(t *testing.T) {
|
|
overrides := map[string]any{"prompt": "a scenic landscape"}
|
|
out, err := ValidateInputWithDefaults(model.WorkflowTxt2Img, map[string]any{}, overrides)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if out["prompt"] != "a scenic landscape" {
|
|
t.Fatalf("prompt got %#v", out["prompt"])
|
|
}
|
|
}
|
|
|
|
func TestValidateInputRequiredWithoutDefault(t *testing.T) {
|
|
_, err := ValidateInputWithDefaults(model.WorkflowTxt2Img, map[string]any{}, map[string]any{})
|
|
if err == nil {
|
|
t.Fatal("expected missing prompt error")
|
|
}
|
|
}
|