fix(runtime): 本地任务恢复 - 恢复本地画布和延迟视频任务
This commit is contained in:
1 parent
ea657f179d
commit
bda114b29e
13 files changed
+739
-67
No files matched your search
@@ -1,7 +1,10 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"infinite-canvas/backend/internal/model"
|
||||
"infinite-canvas/backend/internal/repository"
|
||||
@@ -10,6 +13,76 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func TestVideoTaskTimeoutHasFiveMinuteSafetyFloor(t *testing.T) {
|
||||
policy := defaultRuntimePolicy().Task
|
||||
policy.VideoTimeoutMinutes = 1
|
||||
policy.ImageTimeoutMinutes = 1
|
||||
if got := taskExecutionTimeoutWithPolicy("canvas_video", policy); got != 5*time.Minute {
|
||||
t.Fatalf("video timeout = %s, want 5m", got)
|
||||
}
|
||||
if got := taskExecutionTimeoutWithPolicy("canvas_image", policy); got != time.Minute {
|
||||
t.Fatalf("image timeout = %s, want 1m", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOnlyResumableNewAPIChannel2VideoDeadlinesStayRunning(t *testing.T) {
|
||||
svc := &Service{}
|
||||
input, err := json.Marshal(canvasGenerationInput{Mode: "video", Config: providerConfig{BaseURL: "https://example.com", InterfaceType: string(model.ChannelInterfaceNewAPIChannel2)}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
base := model.Task{ID: "task-1", Type: "canvas_video", ProviderRequestID: "provider-task-1"}
|
||||
if !svc.shouldDeferVideoProviderTask(base, string(input), context.DeadlineExceeded) {
|
||||
t.Fatal("resumable NewAPI Channel 2 deadline should remain running")
|
||||
}
|
||||
if svc.shouldDeferVideoProviderTask(model.Task{ID: "task-2", Type: "canvas_video"}, string(input), context.DeadlineExceeded) {
|
||||
t.Fatal("missing provider task id must not be deferred")
|
||||
}
|
||||
if svc.shouldDeferVideoProviderTask(base, string(input), context.Canceled) {
|
||||
t.Fatal("explicit cancellation must not be deferred")
|
||||
}
|
||||
other, err := json.Marshal(canvasGenerationInput{Mode: "video", Config: providerConfig{BaseURL: "https://example.com", InterfaceType: string(model.ChannelInterfaceNewAPIVideo)}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if svc.shouldDeferVideoProviderTask(base, string(other), context.DeadlineExceeded) {
|
||||
t.Fatal("providers without a verified query-only resume contract must fail closed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestResumableVideoDeadlineUsesResolvedSystemChannelProtocol(t *testing.T) {
|
||||
db, err := gorm.Open(sqlite.Open("file:"+newID()+"?mode=memory&cache=shared"), &gorm.Config{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.AutoMigrate(&model.ModelChannel{}, &model.ChannelModel{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
channel := model.ModelChannel{
|
||||
ID: "channel-video", UserID: "admin", Scope: model.ChannelScopeSystem, Enabled: true, Name: "Video",
|
||||
BaseURL: "https://example.com", APIKey: "test-key", APIFormat: "openai", ModelsJSON: `["video-model"]`,
|
||||
}
|
||||
channelModel := model.ChannelModel{
|
||||
ID: "model-video", ChannelID: channel.ID, ModelKey: "video-model", Capability: "video",
|
||||
Protocol: model.ChannelInterfaceNewAPIChannel2, Enabled: true, PriceConfigured: true,
|
||||
}
|
||||
if err := db.Create(&channel).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.Create(&channelModel).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
input, err := json.Marshal(canvasGenerationInput{Mode: "video", Config: providerConfig{ChannelID: channel.ID, Model: "video-model"}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
svc := New(repository.New(db), t.TempDir())
|
||||
task := model.Task{ID: "task-system", Type: "canvas_video", ProviderRequestID: "provider-task-1"}
|
||||
if !svc.shouldDeferVideoProviderTask(task, string(input), context.DeadlineExceeded) {
|
||||
t.Fatal("system-channel task must use the resolved model protocol when deciding query-only recovery")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRuntimePolicyDefaultsAndSelfUseModeValidate(t *testing.T) {
|
||||
if err := validateRuntimePolicy(defaultRuntimePolicy()); err != nil {
|
||||
t.Fatalf("default runtime policy error = %v", err)
|
||||
|
||||
Reference in new issue
Block a user