fix(video): PR #492 - 合并统一轮询并保留本地出站安全策略
This commit is contained in:
commit
ebcca7e3d5
17 files changed
+1219
-227
No files matched your search
@@ -213,7 +213,7 @@ func TestRunVideoTaskUsesDeclarativeAgnesJSONProtocol(t *testing.T) {
|
||||
defer server.Close()
|
||||
|
||||
ctx := withProtocolRegistry(context.Background(), center.registrySnapshot())
|
||||
result, err := runVideoTask(ctx, canvasGenerationInput{
|
||||
result, err := runVideoTaskForTest(ctx, canvasGenerationInput{
|
||||
Mode: "video",
|
||||
Prompt: "make it move",
|
||||
Config: providerConfig{BaseURL: server.URL + "/v1", APIKey: "test-key", InterfaceType: "agnes-video", Model: "agnes-video-2.5", VideoSeconds: "5", Size: "16:9", VQuality: "720P"},
|
||||
@@ -261,7 +261,7 @@ func TestRunVideoTaskDownloadsAuthenticatedDeclarativeResult(t *testing.T) {
|
||||
defer server.Close()
|
||||
|
||||
ctx := withProtocolRegistry(context.Background(), center.registrySnapshot())
|
||||
result, err := runVideoTask(ctx, canvasGenerationInput{
|
||||
result, err := runVideoTaskForTest(ctx, canvasGenerationInput{
|
||||
Mode: "video", Prompt: "cinematic shot",
|
||||
Config: providerConfig{BaseURL: server.URL, APIKey: "test-key", InterfaceType: "newapi", Model: "sora-2", VideoSeconds: "5", Size: "1280x720"},
|
||||
})
|
||||
@@ -932,7 +932,7 @@ func TestProviderPayloadErrorCategoryPrefersProviderCodeOverModerationWording(t
|
||||
|
||||
func TestRunVideoTaskRequiresOfficialPluginWhenRegistryEmpty(t *testing.T) {
|
||||
ctx := withProtocolRegistry(context.Background(), emptyProtocolRegistry)
|
||||
_, err := runVideoTask(ctx, canvasGenerationInput{
|
||||
_, err := runVideoTaskForTest(ctx, canvasGenerationInput{
|
||||
Prompt: "make it move",
|
||||
Config: providerConfig{BaseURL: "https://example.com", APIKey: "key", Model: "MiniMax-H3", InterfaceType: "minimax-video"},
|
||||
})
|
||||
@@ -1629,7 +1629,7 @@ func TestRunVideoTaskUsesNewAPIForAnyVideoModel(t *testing.T) {
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
result, err := runVideoTask(context.Background(), canvasGenerationInput{
|
||||
result, err := runVideoTaskForTest(context.Background(), canvasGenerationInput{
|
||||
Prompt: "make it move",
|
||||
Config: providerConfig{BaseURL: server.URL + "/v1", APIKey: "test-key", Model: "custom-video-v1"},
|
||||
})
|
||||
@@ -1646,6 +1646,85 @@ func TestRunVideoTaskUsesNewAPIForAnyVideoModel(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunVideoTaskRetriesTransientPollFailureWithoutRecreating(t *testing.T) {
|
||||
t.Setenv("CANVAS_ALLOW_PRIVATE_UPSTREAMS", "true")
|
||||
createCalls := 0
|
||||
pollCalls := 0
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method + " " + r.URL.Path {
|
||||
case "POST /v1/videos":
|
||||
createCalls++
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_, _ = w.Write([]byte(`{"id":"video-1","status":"queued"}`))
|
||||
case "GET /v1/videos/video-1":
|
||||
pollCalls++
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
if pollCalls == 1 {
|
||||
w.WriteHeader(http.StatusServiceUnavailable)
|
||||
_, _ = w.Write([]byte(`{"message":"temporary outage"}`))
|
||||
return
|
||||
}
|
||||
_, _ = w.Write([]byte(`{"id":"video-1","status":"completed"}`))
|
||||
case "GET /v1/videos/video-1/content":
|
||||
w.Header().Set("Content-Type", "video/mp4")
|
||||
_, _ = w.Write([]byte("video"))
|
||||
default:
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
result, err := runVideoTaskWithPolicy(context.Background(), canvasGenerationInput{
|
||||
Prompt: "make it move",
|
||||
Config: providerConfig{BaseURL: server.URL + "/v1", APIKey: "test-key", Model: "custom-video-v1"},
|
||||
}, fastVideoPollPolicy())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if result["mode"] != "video" || createCalls != 1 || pollCalls != 2 {
|
||||
t.Fatalf("result = %#v, create calls = %d, poll calls = %d", result, createCalls, pollCalls)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunVideoTaskRetriesDownloadWithoutRepolling(t *testing.T) {
|
||||
t.Setenv("CANVAS_ALLOW_PRIVATE_UPSTREAMS", "true")
|
||||
pollCalls := 0
|
||||
downloadCalls := 0
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method + " " + r.URL.Path {
|
||||
case "POST /v1/videos":
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_, _ = w.Write([]byte(`{"id":"video-1","status":"queued"}`))
|
||||
case "GET /v1/videos/video-1":
|
||||
pollCalls++
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_, _ = w.Write([]byte(`{"id":"video-1","status":"completed"}`))
|
||||
case "GET /v1/videos/video-1/content":
|
||||
downloadCalls++
|
||||
if downloadCalls == 1 {
|
||||
w.WriteHeader(http.StatusBadGateway)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "video/mp4")
|
||||
_, _ = w.Write([]byte("video"))
|
||||
default:
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
result, err := runVideoTaskWithPolicy(context.Background(), canvasGenerationInput{
|
||||
Prompt: "make it move",
|
||||
Config: providerConfig{BaseURL: server.URL + "/v1", APIKey: "test-key", Model: "custom-video-v1"},
|
||||
}, fastVideoPollPolicy())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if result["mode"] != "video" || pollCalls != 1 || downloadCalls != 2 {
|
||||
t.Fatalf("result = %#v, poll calls = %d, download calls = %d", result, pollCalls, downloadCalls)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunVideoTaskSendsOnlyDeclaredResolutionName(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
@@ -1689,7 +1768,7 @@ func TestRunVideoTaskSendsOnlyDeclaredResolutionName(t *testing.T) {
|
||||
if test.withoutProfile {
|
||||
profile = nil
|
||||
}
|
||||
_, err := runVideoTask(context.Background(), canvasGenerationInput{
|
||||
_, err := runVideoTaskForTest(context.Background(), canvasGenerationInput{
|
||||
Prompt: "synthetic prompt",
|
||||
Config: providerConfig{BaseURL: server.URL + "/v1", APIKey: "test-key", Model: "public-video", VideoSeconds: "8", Size: "16:9", VQuality: test.quality},
|
||||
VideoCapability: profile,
|
||||
@@ -1731,7 +1810,7 @@ func TestRunVideoTaskUsesNestedURLBeforeResultURL(t *testing.T) {
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
result, err := runVideoTask(context.Background(), canvasGenerationInput{
|
||||
result, err := runVideoTaskForTest(context.Background(), canvasGenerationInput{
|
||||
Prompt: "make it move",
|
||||
Config: providerConfig{BaseURL: server.URL, APIKey: "test-key", Model: "grok-imagine-video-1.5-1080p", VideoSeconds: "15"},
|
||||
})
|
||||
@@ -1782,7 +1861,7 @@ func TestRunVideoTaskUsesJSONForGrokVideo(t *testing.T) {
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
result, err := runVideoTask(context.Background(), canvasGenerationInput{
|
||||
result, err := runVideoTaskForTest(context.Background(), canvasGenerationInput{
|
||||
Prompt: "make it move",
|
||||
Config: providerConfig{BaseURL: server.URL + "/v1", APIKey: "test-key", Model: "grok-video", VideoSeconds: "10"},
|
||||
ReferenceImages: []providerMedia{{ID: "image-1", DataURL: testReferenceImageDataURL}},
|
||||
@@ -1840,7 +1919,7 @@ func TestRunVideoTaskUsesXAIVideoGenerationEndpoint(t *testing.T) {
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
result, err := runVideoTask(context.Background(), canvasGenerationInput{
|
||||
result, err := runVideoTaskForTest(context.Background(), canvasGenerationInput{
|
||||
Prompt: "make it move",
|
||||
Config: providerConfig{
|
||||
BaseURL: server.URL + "/v1",
|
||||
@@ -1882,7 +1961,7 @@ func TestRunVideoTaskXAIVideoRejectsUnreachableResultURL(t *testing.T) {
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
_, err := runVideoTask(context.Background(), canvasGenerationInput{
|
||||
_, err := runVideoTaskForTest(context.Background(), canvasGenerationInput{
|
||||
Prompt: "make it move",
|
||||
Config: providerConfig{
|
||||
BaseURL: server.URL + "/v1",
|
||||
@@ -2061,7 +2140,7 @@ func TestVolcengineArkVideoProtocolUsesContentTaskAndDownloadsResult(t *testing.
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
result, err := runVideoTask(context.Background(), canvasGenerationInput{
|
||||
result, err := runVideoTaskForTest(context.Background(), canvasGenerationInput{
|
||||
Prompt: "make it move",
|
||||
Config: providerConfig{BaseURL: server.URL + "/api/v3", APIKey: "test-key", Model: "doubao-seedance-test", InterfaceType: "volcengine-ark-video"},
|
||||
ReferenceImages: []providerMedia{{ID: "start", URL: server.URL + "/reference.png"}},
|
||||
@@ -2257,7 +2336,7 @@ func TestRunNewAPIChannel1VideoTaskDownloadsSucceededObject(t *testing.T) {
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
result, err := runVideoTask(context.Background(), canvasGenerationInput{
|
||||
result, err := runVideoTaskForTest(context.Background(), canvasGenerationInput{
|
||||
Prompt: "make it move",
|
||||
Config: providerConfig{BaseURL: server.URL + "/v1", APIKey: "test-key", Model: "seedance-2.0", InterfaceType: "newapi-channel-1"},
|
||||
})
|
||||
@@ -2321,7 +2400,7 @@ func TestRunNewAPIChannel2VideoTaskDownloadsTemporaryResult(t *testing.T) {
|
||||
profile := DefaultModelCapabilityConfigForModel("newapi-channel-2", "grok-image-video").Video
|
||||
profile.Resolutions = []string{"720p"}
|
||||
profile.DefaultResolution = "720p"
|
||||
result, err := runVideoTask(context.Background(), canvasGenerationInput{
|
||||
result, err := runVideoTaskForTest(context.Background(), canvasGenerationInput{
|
||||
Prompt: "make it move",
|
||||
Config: providerConfig{BaseURL: server.URL, APIKey: "test-key", Model: "grok-image-video", InterfaceType: "newapi-channel-2", VideoSeconds: "15", Size: "9:16", VQuality: "720", VideoGenerateAudio: "true"},
|
||||
ReferenceImages: []providerMedia{
|
||||
@@ -2376,7 +2455,7 @@ func TestRunNewAPIChannel2VideoTaskResumesOriginalProviderTaskWithoutAnotherPost
|
||||
ctx := withProviderAnalytics(context.Background(), nil, model.Task{
|
||||
ID: "task-1", Type: "canvas_video", ProviderRequestID: "existing-provider-task", InputJSON: string(inputJSON),
|
||||
})
|
||||
result, err := runVideoTask(ctx, input)
|
||||
result, err := runVideoTaskForTest(ctx, input)
|
||||
if err != nil {
|
||||
t.Fatalf("runVideoTask() error = %v", err)
|
||||
}
|
||||
@@ -2393,7 +2472,7 @@ func TestRunNewAPIChannel2VideoTaskReturnsTypedDeadlineWhenPollingWindowEnds(t *
|
||||
ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(-time.Second))
|
||||
defer cancel()
|
||||
ctx = withProviderAnalytics(ctx, nil, model.Task{ID: "task-1", Type: "canvas_video", ProviderRequestID: "existing-provider-task"})
|
||||
_, err := runVideoTask(ctx, canvasGenerationInput{
|
||||
_, err := runVideoTaskForTest(ctx, canvasGenerationInput{
|
||||
Mode: "video",
|
||||
Config: providerConfig{InterfaceType: string(model.ChannelInterfaceNewAPIChannel2), Model: "video-model", BaseURL: "https://example.com", APIKey: "key"},
|
||||
})
|
||||
@@ -2427,7 +2506,7 @@ func TestRunGeminiVeoVideoTaskUsesLongRunningOperation(t *testing.T) {
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
result, err := runVideoTask(context.Background(), canvasGenerationInput{
|
||||
result, err := runVideoTaskForTest(context.Background(), canvasGenerationInput{
|
||||
Prompt: "make it move",
|
||||
Config: providerConfig{BaseURL: server.URL, APIKey: "test-key", APIFormat: "gemini", Model: "veo-test", InterfaceType: "gemini-veo", VideoSeconds: "6", Size: "16:9", VQuality: "720"},
|
||||
})
|
||||
@@ -2632,7 +2711,7 @@ func TestRunNovitaVideoTaskDownloadsSucceededVideo(t *testing.T) {
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
result, err := runVideoTask(context.Background(), canvasGenerationInput{
|
||||
result, err := runVideoTaskForTest(context.Background(), canvasGenerationInput{
|
||||
Prompt: "make it move",
|
||||
Config: providerConfig{BaseURL: server.URL, APIKey: "test-key", Model: "kling2.5_turbo_pro_t2v", InterfaceType: "novita-video", VideoSeconds: "5", Size: "16:9"},
|
||||
})
|
||||
@@ -2665,7 +2744,7 @@ func TestRunNovitaVideoTaskReturnsFailureReason(t *testing.T) {
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
_, err := runVideoTask(context.Background(), canvasGenerationInput{
|
||||
_, err := runVideoTaskForTest(context.Background(), canvasGenerationInput{
|
||||
Prompt: "make it move",
|
||||
Config: providerConfig{BaseURL: server.URL, APIKey: "test-key", Model: "kling2.5_turbo_pro_t2v", InterfaceType: "novita-video"},
|
||||
})
|
||||
@@ -2711,7 +2790,7 @@ func TestRunMiniMaxVideoTaskCreatesPollsAndDownloads(t *testing.T) {
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
result, err := runVideoTask(context.Background(), canvasGenerationInput{
|
||||
result, err := runVideoTaskForTest(context.Background(), canvasGenerationInput{
|
||||
Mode: "video",
|
||||
Prompt: "make it move",
|
||||
Config: providerConfig{BaseURL: server.URL, APIKey: "test-key", Model: "MiniMax-H3", InterfaceType: "minimax-video", VideoSeconds: "5", VQuality: "768P", Size: "16:9"},
|
||||
@@ -2747,7 +2826,7 @@ func TestRunMiniMaxVideoTaskSendsOfficial2KResolution(t *testing.T) {
|
||||
_, _ = w.Write([]byte(`{}`))
|
||||
}))
|
||||
defer server.Close()
|
||||
_, err := runVideoTask(context.Background(), canvasGenerationInput{
|
||||
_, err := runVideoTaskForTest(context.Background(), canvasGenerationInput{
|
||||
Mode: "video", Prompt: "make it move",
|
||||
Config: providerConfig{BaseURL: server.URL, APIKey: "test-key", Model: "MiniMax-H3", InterfaceType: "minimax-video", VideoSeconds: "6", VQuality: "2K"},
|
||||
})
|
||||
@@ -2792,7 +2871,7 @@ func TestRunMiniMaxVideoTaskUsesExplicitReferenceRoles(t *testing.T) {
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
_, err := runVideoTask(context.Background(), canvasGenerationInput{
|
||||
_, err := runVideoTaskForTest(context.Background(), canvasGenerationInput{
|
||||
Mode: "video",
|
||||
Prompt: "保持角色一致",
|
||||
Config: providerConfig{BaseURL: server.URL, APIKey: "test-key", Model: "MiniMax-H3", InterfaceType: "minimax-video", VideoSeconds: "6", VQuality: "768P", Size: "16:9"},
|
||||
@@ -2821,7 +2900,7 @@ func TestRunMiniMaxVideoTaskReturnsFailureReason(t *testing.T) {
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
_, err := runVideoTask(context.Background(), canvasGenerationInput{
|
||||
_, err := runVideoTaskForTest(context.Background(), canvasGenerationInput{
|
||||
Mode: "video",
|
||||
Prompt: "make it move",
|
||||
Config: providerConfig{BaseURL: server.URL, APIKey: "test-key", Model: "MiniMax-H3", InterfaceType: "minimax-video", VideoSeconds: "6"},
|
||||
|
||||
Reference in new issue
Block a user