feat: improve simulation media tasks
This commit is contained in:
@@ -7,10 +7,96 @@ import (
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/easyai/easyai-ai-gateway/apps/api/internal/store"
|
||||
)
|
||||
|
||||
func TestSimulationClientReturnsImageDemoAssets(t *testing.T) {
|
||||
response, err := (SimulationClient{}).Run(context.Background(), Request{
|
||||
Kind: "images.generations",
|
||||
Model: "gpt-image-1",
|
||||
Body: map[string]any{
|
||||
"prompt": "demo image",
|
||||
"n": 2,
|
||||
"simulationDurationMs": 5,
|
||||
},
|
||||
Candidate: store.RuntimeModelCandidate{Provider: "simulation"},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("run simulation image client: %v", err)
|
||||
}
|
||||
data, _ := response.Result["data"].([]any)
|
||||
if len(data) != 2 || response.ResponseDurationMS <= 0 {
|
||||
t.Fatalf("unexpected simulated image response: %+v duration=%d", response.Result, response.ResponseDurationMS)
|
||||
}
|
||||
item, _ := data[0].(map[string]any)
|
||||
if item["url"] != "/static/simulation/image.svg" || item["assetSource"] != "simulation" {
|
||||
t.Fatalf("unexpected simulated image item: %+v", item)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSimulationClientReturnsVideoDemoAssets(t *testing.T) {
|
||||
response, err := (SimulationClient{}).Run(context.Background(), Request{
|
||||
Kind: "videos.generations",
|
||||
ModelType: "video_generate",
|
||||
Model: "demo-video-model",
|
||||
Body: map[string]any{
|
||||
"prompt": "demo video",
|
||||
"count": 2,
|
||||
"duration": 6,
|
||||
"simulationDurationMs": 5,
|
||||
},
|
||||
Candidate: store.RuntimeModelCandidate{Provider: "simulation"},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("run simulation video client: %v", err)
|
||||
}
|
||||
data, _ := response.Result["data"].([]any)
|
||||
if len(data) != 2 || response.ResponseDurationMS <= 0 {
|
||||
t.Fatalf("unexpected simulated video response: %+v duration=%d", response.Result, response.ResponseDurationMS)
|
||||
}
|
||||
item, _ := data[0].(map[string]any)
|
||||
if item["video_url"] != "/static/simulation/video.mp4" || item["url"] != "/static/simulation/video.mp4" || item["poster"] != "/static/simulation/video-poster.svg" {
|
||||
t.Fatalf("unexpected simulated video item: %+v", item)
|
||||
}
|
||||
if item["duration"] != 6 || item["assetSource"] != "simulation" {
|
||||
t.Fatalf("unexpected simulated video metadata: %+v", item)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSimulationDurationDefaultsByMediaType(t *testing.T) {
|
||||
imageDuration := simulationDuration(Request{Kind: "images.generations"})
|
||||
if imageDuration < 10*time.Second || imageDuration > 30*time.Second {
|
||||
t.Fatalf("image simulation duration should default to 10-30s, got %s", imageDuration)
|
||||
}
|
||||
videoDuration := simulationDuration(Request{Kind: "videos.generations"})
|
||||
if videoDuration < 2*time.Minute || videoDuration > 3*time.Minute {
|
||||
t.Fatalf("video simulation duration should default to 2-3m, got %s", videoDuration)
|
||||
}
|
||||
textDuration := simulationDuration(Request{Kind: "chat.completions"})
|
||||
if textDuration < 800*time.Millisecond || textDuration > 2400*time.Millisecond {
|
||||
t.Fatalf("text simulation duration should keep short defaults, got %s", textDuration)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSimulationDurationCanBeControlledByParams(t *testing.T) {
|
||||
fixedDuration := simulationDuration(Request{Body: map[string]any{"simulationDurationSeconds": 7}})
|
||||
if fixedDuration != 7*time.Second {
|
||||
t.Fatalf("simulationDurationSeconds should set fixed duration, got %s", fixedDuration)
|
||||
}
|
||||
rangeDuration := simulationDuration(Request{
|
||||
Kind: "videos.generations",
|
||||
Body: map[string]any{
|
||||
"simulationMinDurationSeconds": 1,
|
||||
"simulationMaxDurationSeconds": 1,
|
||||
},
|
||||
})
|
||||
if rangeDuration != time.Second {
|
||||
t.Fatalf("simulation duration range params should override video defaults, got %s", rangeDuration)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOpenAIClientChatContract(t *testing.T) {
|
||||
var gotPath string
|
||||
var gotAuth string
|
||||
|
||||
Reference in New Issue
Block a user