迁移音频生成与语音合成到 gateway 并补充 simulation 测试
This commit is contained in:
@@ -72,6 +72,50 @@ func TestPlanTaskResponseKeepsAsyncTaskModeForOtherAPIV1Tasks(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPlanTaskResponseKeepsCompatibleSyncForAudioOpenAPIUnlessAsync(t *testing.T) {
|
||||
for _, item := range []struct {
|
||||
kind string
|
||||
path string
|
||||
}{
|
||||
{kind: "song.generations", path: "/api/v1/song/generations"},
|
||||
{kind: "music.generations", path: "/api/v1/music/generations"},
|
||||
{kind: "speech.generations", path: "/api/v1/speech/generations"},
|
||||
} {
|
||||
t.Run(item.kind, func(t *testing.T) {
|
||||
req := httptest.NewRequest(http.MethodPost, item.path, nil)
|
||||
plan := planTaskResponse(item.kind, true, map[string]any{"stream": true}, req)
|
||||
if plan.asyncMode {
|
||||
t.Fatalf("%s should default to synchronous compatible response", item.path)
|
||||
}
|
||||
if !plan.compatibleMode {
|
||||
t.Fatalf("%s should return compatible response payloads", item.path)
|
||||
}
|
||||
if plan.streamMode {
|
||||
t.Fatal("audio OpenAPI endpoints should stay JSON-only even when stream=true is present")
|
||||
}
|
||||
|
||||
asyncReq := httptest.NewRequest(http.MethodPost, item.path, nil)
|
||||
asyncReq.Header.Set("X-Async", "true")
|
||||
asyncPlan := planTaskResponse(item.kind, true, map[string]any{}, asyncReq)
|
||||
if !asyncPlan.asyncMode || !asyncPlan.compatibleMode {
|
||||
t.Fatalf("%s should support X-Async while keeping compatible mode, got %+v", item.path, asyncPlan)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAPIKeyScopeAllowedRecognizesAudioAndMusicAliases(t *testing.T) {
|
||||
if !apiKeyScopeAllowed(&auth.User{APIKeyID: "key", APIKeyScopes: []string{"audio_generate"}}, "song.generations") {
|
||||
t.Fatal("audio_generate scope should allow song generations")
|
||||
}
|
||||
if !apiKeyScopeAllowed(&auth.User{APIKeyID: "key", APIKeyScopes: []string{"text_to_speech"}}, "speech.generations") {
|
||||
t.Fatal("text_to_speech scope should allow speech generations")
|
||||
}
|
||||
if apiKeyScopeAllowed(&auth.User{APIKeyID: "key", APIKeyScopes: []string{"image"}}, "speech.generations") {
|
||||
t.Fatal("image scope should not allow speech generations")
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriteCompatibleTaskResponseReturnsJSONWhenStreamIsFalse(t *testing.T) {
|
||||
executor := &fakeTaskExecutor{output: map[string]any{"id": "chatcmpl-test", "object": "chat.completion"}}
|
||||
req := httptest.NewRequest(http.MethodPost, "/api/v1/chat/completions", nil)
|
||||
|
||||
Reference in New Issue
Block a user