add stable media support and sync skillhub UI

This commit is contained in:
wtgoku
2026-04-08 23:17:42 +08:00
parent ff4f370763
commit 4b20dc5e37
32 changed files with 6269 additions and 393 deletions
+63
View File
@@ -3,6 +3,7 @@ package server
import (
"context"
"encoding/base64"
"encoding/json"
"io"
"net/http"
"net/http/httptest"
@@ -85,6 +86,58 @@ func TestSubmitImageToVideoTaskUsesMultipartInputReference(t *testing.T) {
}
}
func TestSubmitImageToVideoTaskUsesURLImagesForViduModels(t *testing.T) {
var gotBody map[string]any
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/v1/videos" {
http.NotFound(w, r)
return
}
if got := r.Header.Get("Content-Type"); got != "application/json" {
t.Fatalf("expected application/json content type, got %q", got)
}
if err := json.NewDecoder(r.Body).Decode(&gotBody); err != nil {
t.Fatalf("decode request body: %v", err)
}
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"id":"task_vidu_url_123","status":"queued"}`))
}))
defer srv.Close()
client := newNewAPIClient(Config{NewAPIBaseURL: srv.URL})
taskID, err := client.submitImageToVideoTask(context.Background(), "sk-test", "viduq2-pro-fast", map[string]any{
"prompt": "animate this still gently",
"duration_s": 5,
"aspect_ratio": "9:16",
}, imageEditReference{
Filename: "reference.png",
ContentType: "image/png",
URL: "https://media.popi.test/m/demo/reference.png",
})
if err != nil {
t.Fatalf("submitImageToVideoTask: %v", err)
}
if taskID != "task_vidu_url_123" {
t.Fatalf("expected task id task_vidu_url_123, got %q", taskID)
}
if gotBody["model"] != "viduq2-pro-fast" {
t.Fatalf("unexpected model: %#v", gotBody["model"])
}
images, ok := gotBody["images"].([]any)
if !ok || len(images) != 1 || images[0] != "https://media.popi.test/m/demo/reference.png" {
t.Fatalf("expected one image url, got %#v", gotBody["images"])
}
if gotBody["duration"] != float64(5) {
t.Fatalf("unexpected duration: %#v", gotBody["duration"])
}
metadata, ok := gotBody["metadata"].(map[string]any)
if !ok || metadata["aspect_ratio"] != "9:16" {
t.Fatalf("unexpected metadata: %#v", gotBody["metadata"])
}
}
func TestFetchVideoTaskFallsBackToGenericTaskEnvelope(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
@@ -176,6 +229,7 @@ func TestExecuteImageToVideoJobCompletesAndArtifactCanBeRead(t *testing.T) {
if err != nil {
t.Fatalf("NewWithConfig: %v", err)
}
server.cfg.PublicBaseURL = "http://127.0.0.1:8080"
token, _, ok, err := server.store.createSession("sk-test-upstream")
if err != nil {
@@ -241,6 +295,15 @@ func TestExecuteImageToVideoJobCompletesAndArtifactCanBeRead(t *testing.T) {
if item.ContentType != "video/mp4" {
t.Fatalf("expected video/mp4 artifact, got %q", item.ContentType)
}
if item.MediaID == "" {
t.Fatalf("expected media id on persisted artifact, got %#v", item)
}
if item.URL == "" {
t.Fatalf("expected stable url on persisted artifact, got %#v", item)
}
if item.StorageStatus != "ready" {
t.Fatalf("expected ready storage status, got %#v", item.StorageStatus)
}
if !strings.HasSuffix(item.Filename, ".mp4") {
t.Fatalf("expected .mp4 filename, got %q", item.Filename)
}