feat(canvas): 画布媒体工作流 - 支持批量连线、失败重试与模型能力增强

合并 PR #230。保留当前主线样式与组件结构,吸收批量连线、失败批次重试、媒体模型能力和相关后端增强,并修复集成检查发现的分辨率选择器启用条件与测试稳定性问题。
This commit is contained in:
WindC0X authored and GitHub committed 2026-08-15 15:48:16 +08:00
1 parent b0c3159f8e
commit 0e251c3c8f
48 files changed
+1582 -83

No files matched your search

+1 -1
View File
@@ -8,6 +8,7 @@ require (
github.com/tencentyun/cos-go-sdk-v5 v0.7.75
github.com/volcengine/volc-sdk-golang v1.0.253
golang.org/x/crypto v0.54.0
golang.org/x/net v0.57.0
gorm.io/driver/postgres v1.6.2
gorm.io/driver/sqlite v1.6.0
gorm.io/gorm v1.31.2
@@ -53,7 +54,6 @@ require (
go.mongodb.org/mongo-driver/v2 v2.8.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
golang.org/x/arch v0.29.0 // indirect
golang.org/x/net v0.57.0 // indirect
golang.org/x/sync v0.22.0 // indirect
golang.org/x/sys v0.47.0 // indirect
golang.org/x/text v0.40.0 // indirect
+54 -1
View File
@@ -2,6 +2,7 @@ package service
import (
"encoding/json"
"errors"
"fmt"
"sort"
"strconv"
@@ -97,7 +98,7 @@ func DefaultModelCapabilityConfig(protocol string) *ModelCapabilityConfig {
func DefaultImageCapabilityConfig(protocol string, modelName string) *ImageCapabilityConfig {
image := &ImageCapabilityConfig{
References: ImageReferenceConfig{PromptMaxChars: 32000, MaxImages: 16, MaxImageBytes: 30 * 1024 * 1024, MaskSupported: true},
Size: ImageSizeConfig{Parameter: "size", Values: []string{"1:1", "3:2", "2:3", "4:3", "3:4", "16:9", "21:9", "9:16", "2048x2048", "2048x1152", "1152x2048", "3840x2160", "2160x3840"}, Default: "1:1", AllowCustom: true},
Size: ImageSizeConfig{Parameter: "size", Values: defaultImageSizeValues(), Default: "1:1", AllowCustom: true},
Quality: ImageQualityConfig{Supported: true, Values: []string{"auto", "low", "medium", "high"}, Default: "auto"},
TransparentBackground: VideoBooleanConfig{Supported: true, Default: false},
ResponseFormat: ParameterSupport{Supported: true},
@@ -142,6 +143,15 @@ func DefaultImageCapabilityConfig(protocol string, modelName string) *ImageCapab
return image
}
func defaultImageSizeValues() []string {
return []string{
"auto", "1:1", "3:2", "2:3", "4:3", "3:4", "16:9", "21:9", "9:16",
"1024x1024", "1360x1024", "1024x1360", "1536x1024", "1024x1536", "1024x1280", "1280x1024", "2048x878", "1824x1024", "1024x1824",
"2048x2048", "2304x1728", "1728x2304", "2496x1664", "1664x2496", "1792x2240", "2240x1792", "3136x1344", "2752x1536", "1536x2752",
"2880x2880", "3264x2448", "2448x3264", "3504x2336", "2336x3504", "2560x3200", "3200x2560", "3808x1632", "3840x2160", "2160x3840",
}
}
func DefaultModelCapabilityConfigForModel(protocol string, modelName string) *ModelCapabilityConfig {
video := &VideoCapabilityConfig{
References: VideoReferenceConfig{PromptMaxChars: 1000, MaxImages: 9, MaxImageBytes: 30 * 1024 * 1024, MaxVideos: 0, MaxVideoBytes: 0, MaxVideoDuration: 0, MaxAudios: 0, MaxAudioBytes: 0, MaxAudioDuration: 0},
@@ -412,6 +422,14 @@ func validateImageTask(profile *ImageCapabilityConfig, input canvasGenerationInp
if profile == nil {
return nil
}
modelName := strings.TrimPrefix(strings.ToLower(strings.TrimSpace(input.Config.Model)), "models/")
if input.Config.InterfaceType == string(model.ChannelInterfaceGrokImage) && modelName == "grok-imagine-image-quality" {
const maxPromptBytes = 8000
promptBytes := len(withSystemPrompt(input.Config, input.Prompt))
if promptBytes > maxPromptBytes {
return BadAuthRequest(fmt.Sprintf("Grok 图片完整提示词为 %d UTF-8 字节,超过上游 %d 字节限制。系统不会自动删改;请精简当前输入、连线文本、角色卡、画风或模板内容后重试", promptBytes, maxPromptBytes))
}
}
if len(input.ReferenceImages) > profile.References.MaxImages {
return BadAuthRequest(fmt.Sprintf("当前图片模型最多支持 %d 张参考图", profile.References.MaxImages))
}
@@ -426,6 +444,11 @@ func validateImageTask(profile *ImageCapabilityConfig, input canvasGenerationInp
if profile.Size.Parameter != "none" && !profile.Size.AllowCustom && strings.TrimSpace(input.Config.Size) != "" && !containsCapabilityString(profile.Size.Values, input.Config.Size) {
return BadAuthRequest("图片尺寸不在当前模型支持范围内")
}
if profile.Size.Parameter == "size" && profile.Size.AllowCustom && strings.HasPrefix(modelName, "gpt-image-2") && !containsCapabilityString(profile.Size.Values, input.Config.Size) {
if err := validateGPTImage2CustomSize(input.Config.Size); err != nil {
return BadAuthRequest(err.Error())
}
}
if profile.Quality.Supported && strings.TrimSpace(input.Config.Quality) != "" && !containsCapabilityString(profile.Quality.Values, input.Config.Quality) {
return BadAuthRequest("图片质量不在当前模型支持范围内")
}
@@ -436,6 +459,36 @@ func validateImageTask(profile *ImageCapabilityConfig, input canvasGenerationInp
return nil
}
func validateGPTImage2CustomSize(value string) error {
value = strings.ToLower(strings.TrimSpace(strings.ReplaceAll(value, "×", "x")))
if value == "" || value == "auto" {
return nil
}
parts := strings.Split(value, "x")
if len(parts) != 2 {
return errors.New("自定义图片尺寸请使用宽x高,例如 3840x1920")
}
width, widthErr := strconv.Atoi(parts[0])
height, heightErr := strconv.Atoi(parts[1])
if widthErr != nil || heightErr != nil || width <= 0 || height <= 0 {
return errors.New("图片尺寸必须是正整数")
}
if width%16 != 0 || height%16 != 0 {
return errors.New("图片尺寸宽高必须是 16 的倍数")
}
if max(width, height) > 3840 {
return errors.New("图片尺寸最长边不能超过 3840px")
}
if max(width, height) > min(width, height)*3 {
return errors.New("图片宽高比不能超过 3:1")
}
pixels := int64(width) * int64(height)
if pixels < 655360 || pixels > 8294400 {
return errors.New("图片总像素需在 655360 到 8294400 之间")
}
return nil
}
func videoDurationAllowed(value VideoDurationConfig, seconds int) bool {
if value.Selection == "enum" {
return containsInt(value.Values, seconds)
@@ -0,0 +1,64 @@
package service
import (
"fmt"
"strings"
"testing"
)
func TestValidateImageTaskRejectsOversizedGrokPromptByUTF8Bytes(t *testing.T) {
prompt := strings.Repeat("中", 4001)
input := canvasGenerationInput{
Mode: "image",
Prompt: prompt,
Config: providerConfig{InterfaceType: "grok-image", Model: "grok-imagine-image-quality"},
}
err := validateImageTask(DefaultImageCapabilityConfig("grok-image", "grok-imagine-image-quality"), input)
if err == nil {
t.Fatal("validateImageTask() error = nil")
}
wantBytes := fmt.Sprintf("%d UTF-8 字节", len(prompt))
if !strings.Contains(err.Error(), wantBytes) || !strings.Contains(err.Error(), "8000") || !strings.Contains(err.Error(), "连线文本") {
t.Fatalf("validateImageTask() error = %q", err)
}
}
func TestValidateImageTaskDoesNotApplyQualityPromptLimitToGrokLite(t *testing.T) {
prompt := strings.Repeat("中", 4001)
input := canvasGenerationInput{
Mode: "image",
Prompt: prompt,
Config: providerConfig{InterfaceType: "grok-image", Model: "grok-imagine-image"},
}
if err := validateImageTask(DefaultImageCapabilityConfig("grok-image", "grok-imagine-image"), input); err != nil {
t.Fatalf("validateImageTask() error = %q", err)
}
}
func TestValidateImageTaskEnforcesGPTImage2CustomSizeLimits(t *testing.T) {
profile := DefaultImageCapabilityConfig("openai-image", "gpt-image-2")
profile.Size.AllowCustom = true
valid := canvasGenerationInput{Mode: "image", Config: providerConfig{InterfaceType: "openai-image", Model: "gpt-image-2", Size: "3840x1920"}}
if err := validateImageTask(profile, valid); err != nil {
t.Fatalf("validateImageTask(valid) error = %v", err)
}
tests := map[string]string{
"4096x2048": "最长边",
"3840x2161": "16 的倍数",
"3840x1024": "宽高比",
"640x640": "总像素",
}
for size, want := range tests {
t.Run(size, func(t *testing.T) {
input := canvasGenerationInput{Mode: "image", Config: providerConfig{InterfaceType: "openai-image", Model: "gpt-image-2", Size: size}}
err := validateImageTask(profile, input)
if err == nil || !strings.Contains(err.Error(), want) {
t.Fatalf("validateImageTask(%s) error = %v, want %q", size, err, want)
}
})
}
}
+32
View File
@@ -13,6 +13,8 @@ import (
"os"
"strings"
"time"
"golang.org/x/net/http/httpproxy"
)
const (
@@ -248,11 +250,16 @@ func blockedOutboundHeader(name string) bool {
func newOutboundTransport(resolveHost func(context.Context, string) ([]net.IP, error)) *http.Transport {
dialer := &net.Dialer{Timeout: 15 * time.Second, KeepAlive: 30 * time.Second}
return &http.Transport{
Proxy: outboundProxyFromEnvironment,
DialContext: func(ctx context.Context, network string, address string) (net.Conn, error) {
host, port, err := net.SplitHostPort(address)
if err != nil {
return nil, err
}
// 代理地址由部署者通过环境变量配置;目标 URL 仍在请求前经过 SSRF 校验。
if configuredProxyHost(host) {
return dialer.DialContext(ctx, network, address)
}
addresses, err := resolveHost(ctx, host)
if err != nil {
return nil, err
@@ -268,6 +275,31 @@ func newOutboundTransport(resolveHost func(context.Context, string) ([]net.IP, e
}
}
func outboundProxyFromEnvironment(req *http.Request) (*url.URL, error) {
if req == nil || req.URL == nil {
return nil, nil
}
return httpproxy.FromEnvironment().ProxyFunc()(req.URL)
}
func configuredProxyHost(host string) bool {
host = normalizeOutboundHost(host)
for _, name := range []string{"HTTPS_PROXY", "https_proxy", "HTTP_PROXY", "http_proxy"} {
raw := strings.TrimSpace(os.Getenv(name))
if raw == "" {
continue
}
if !strings.Contains(raw, "://") {
raw = "http://" + raw
}
parsed, err := url.Parse(raw)
if err == nil && normalizeOutboundHost(parsed.Hostname()) == host {
return true
}
}
return false
}
func validateOutboundHost(host string) error {
_, err := resolveOutboundHost(context.Background(), host)
return err
+37
View File
@@ -5,10 +5,47 @@ import (
"net"
"net/http"
"net/http/httptest"
"net/url"
"testing"
"time"
)
func TestOutboundTransportUsesEnvironmentProxyAndHonorsNoProxy(t *testing.T) {
t.Setenv("HTTP_PROXY", "http://172.24.176.1:10808")
t.Setenv("HTTPS_PROXY", "http://172.24.176.1:10808")
t.Setenv("NO_PROXY", ".se7endot.top,100.64.0.0/10")
transport := newOutboundTransport(resolveOutboundHost)
proxiedRequest, _ := http.NewRequest(http.MethodGet, "https://api.mikoto.vip/v1/models", nil)
proxyURL, err := transport.Proxy(proxiedRequest)
if err != nil {
t.Fatal(err)
}
wantProxy, _ := url.Parse("http://172.24.176.1:10808")
if proxyURL == nil || proxyURL.String() != wantProxy.String() {
t.Fatalf("proxy = %v, want %v", proxyURL, wantProxy)
}
directRequest, _ := http.NewRequest(http.MethodGet, "https://api.se7endot.top/v1/models", nil)
proxyURL, err = transport.Proxy(directRequest)
if err != nil {
t.Fatal(err)
}
if proxyURL != nil {
t.Fatalf("NO_PROXY request proxy = %v, want nil", proxyURL)
}
}
func TestConfiguredProxyHostIsTrustedAsDeploymentEgress(t *testing.T) {
t.Setenv("HTTPS_PROXY", "http://172.24.176.1:10808")
if !configuredProxyHost("172.24.176.1") {
t.Fatal("configuredProxyHost() rejected the configured private proxy")
}
if configuredProxyHost("172.24.176.2") {
t.Fatal("configuredProxyHost() accepted an unrelated private host")
}
}
func TestNormalizeOutboundHeadersAllowsCustomUserAgent(t *testing.T) {
headers, err := NormalizeOutboundHeaders([]OutboundHeader{{Name: "user-agent", Value: "Custom Gateway/2.0"}, {Name: "X-Gateway-Tenant", Value: "tenant-a"}})
if err != nil {
+12 -2
View File
@@ -685,7 +685,7 @@ func runImageTask(ctx context.Context, input canvasGenerationInput) (map[string]
if imageTransparentBackgroundSupported(input.ImageCapability) && input.Config.TransparentBackground == "true" {
writeField(writer, "background", "transparent")
}
if imageQualitySupported(input.ImageCapability) && input.Config.Quality != "" {
if imageQualitySupported(input.ImageCapability) && input.Config.Quality != "" && !strings.EqualFold(strings.TrimSpace(input.Config.Quality), "auto") {
writeField(writer, "quality", normalizeImageQuality(input.Config.Quality))
}
if key, value := imageSizeParameter(input.ImageCapability, input.Config.Size); value != "" {
@@ -722,7 +722,7 @@ func runImageTask(ctx context.Context, input canvasGenerationInput) (map[string]
if imageTransparentBackgroundSupported(input.ImageCapability) && input.Config.TransparentBackground == "true" {
body["background"] = "transparent"
}
if imageQualitySupported(input.ImageCapability) && input.Config.Quality != "" {
if imageQualitySupported(input.ImageCapability) && input.Config.Quality != "" && !strings.EqualFold(strings.TrimSpace(input.Config.Quality), "auto") {
body["quality"] = normalizeImageQuality(input.Config.Quality)
}
if key, value := imageSizeParameter(input.ImageCapability, input.Config.Size); value != "" {
@@ -1451,6 +1451,16 @@ func runVideoTask(ctx context.Context, input canvasGenerationInput) (map[string]
status := strings.ToLower(stringField(state, "status"))
if status == "completed" || status == "succeeded" || status == "success" || status == "done" {
if videoURL := newAPIVideoResultURL(state); videoURL != "" {
if input.Config.InterfaceType == "xai-video" {
if _, validationErr := ValidateOutboundURL(videoURL); validationErr != nil {
data, mimeType, err := getBinary(ctx, input.Config, "/videos/"+id+"/content")
if err != nil {
return nil, err
}
mimeType = normalizedMediaMimeType(mimeType, data)
return map[string]interface{}{"mode": "video", "video": map[string]interface{}{"dataUrl": dataURL(mimeType, data), "mimeType": mimeType}}, nil
}
}
data, mimeType, err := getProviderExternalBinary(withProviderRequestKind(ctx, "download"), input.Config, videoURL)
if err != nil {
return nil, fmt.Errorf("视频结果下载失败(任务 %s):%w", id, err)
+78
View File
@@ -179,6 +179,37 @@ func TestVolcengineArkImageRejectsMaskBeforeRequest(t *testing.T) {
}
}
func TestRunImageTaskOmitsAutomaticQualityAndSize(t *testing.T) {
t.Setenv("CANVAS_ALLOW_PRIVATE_UPSTREAMS", "true")
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var body map[string]interface{}
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
t.Fatalf("decode request body: %v", err)
}
if _, exists := body["quality"]; exists {
t.Errorf("quality = %#v, want omitted for auto", body["quality"])
}
if _, exists := body["size"]; exists {
t.Errorf("size = %#v, want omitted for auto", body["size"])
}
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"data":[{"b64_json":"aGVsbG8="}]}`))
}))
defer server.Close()
profile := DefaultImageCapabilityConfig("openai-image", "gpt-image-2")
profile.Size = ImageSizeConfig{Parameter: "size", Values: []string{"auto", "1024x1024"}, Default: "1024x1024", AllowCustom: false}
profile.Quality = ImageQualityConfig{Supported: true, Values: []string{"auto", "low", "medium", "high"}, Default: "high"}
_, err := runImageTask(context.Background(), canvasGenerationInput{
Prompt: "a product photo",
Config: providerConfig{BaseURL: server.URL, APIKey: "key", Model: "gpt-image-2", InterfaceType: "openai-image", Size: "auto", Quality: "auto"},
ImageCapability: profile,
})
if err != nil {
t.Fatalf("runImageTask() error = %v", err)
}
}
func TestRunGrokImageTaskUsesJSONEditContract(t *testing.T) {
t.Setenv("CANVAS_ALLOW_PRIVATE_UPSTREAMS", "true")
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -754,6 +785,53 @@ func TestRunVideoTaskUsesXAIVideoGenerationEndpoint(t *testing.T) {
}
}
func TestRunVideoTaskXAIVideoUsesContentEndpointForLoopbackResultURL(t *testing.T) {
t.Setenv("CANVAS_ALLOWED_PRIVATE_UPSTREAM_HOSTS", "127.0.0.1")
paths := make([]string, 0, 3)
var server *httptest.Server
server = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
paths = append(paths, r.Method+" "+r.URL.Path)
switch r.Method + " " + r.URL.Path {
case "POST /v1/videos/generations":
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"request_id":"video-loopback"}`))
case "GET /v1/videos/video-loopback":
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"status":"done","video":{"url":"http://127.0.0.2:1/unreachable.mp4"}}`))
case "GET /v1/videos/video-loopback/content":
if authorization := r.Header.Get("Authorization"); authorization != "Bearer test-key" {
t.Errorf("content Authorization = %q, want Bearer test-key", authorization)
}
w.Header().Set("Content-Type", "video/mp4")
_, _ = w.Write([]byte("video"))
default:
http.NotFound(w, r)
}
}))
defer server.Close()
result, err := runVideoTask(context.Background(), canvasGenerationInput{
Prompt: "make it move",
Config: providerConfig{
BaseURL: server.URL + "/v1",
APIKey: "test-key",
Model: "grok-imagine-video",
InterfaceType: "xai-video",
},
})
if err != nil {
t.Fatalf("runVideoTask() error = %v", err)
}
video, ok := result["video"].(map[string]interface{})
if !ok || video["dataUrl"] != "data:video/mp4;base64,dmlkZW8=" {
t.Fatalf("video = %#v", result["video"])
}
want := "POST /v1/videos/generations,GET /v1/videos/video-loopback,GET /v1/videos/video-loopback/content"
if got := strings.Join(paths, ","); got != want {
t.Fatalf("paths = %q, want %q", got, want)
}
}
func TestXAIVideoBodyWithoutStartFramePutsAllImagesIntoReferenceImages(t *testing.T) {
body, err := xaiVideoRequestBody(canvasGenerationInput{
Prompt: "make it move",
@@ -61,7 +61,10 @@ func imageSizeParameter(profile *ImageCapabilityConfig, value string) (string, s
return "size", normalizePixelSize(value)
}
value = strings.TrimSpace(value)
if value == "" || value == "auto" {
if strings.EqualFold(value, "auto") {
return "", ""
}
if value == "" {
value = strings.TrimSpace(profile.Size.Default)
}
switch profile.Size.Parameter {
+22 -1
View File
@@ -1175,6 +1175,7 @@ func (s *Service) processAgentStoryboardTask(ctx context.Context, task model.Tas
text, _ := result["text"].(string)
plan, err := parseAgentStoryboardPlan(text)
if err == nil {
normalizeAutomaticStoryboardDurations(&plan, 0)
err = validateStoryboardPlan(plan, 0, 0, input.Characters)
}
if err != nil {
@@ -1183,6 +1184,9 @@ func (s *Service) processAgentStoryboardTask(ctx context.Context, task model.Tas
return nil, nil, err
}
}
if complexityErr := validateStoryboardComplexity(plan); complexityErr != nil {
_ = s.log(task.UserID, task.ID, "warn", "分镜复杂度建议", complexityErr.Error())
}
return s.buildAgentStoryboardResult(task, plan, assets, input.ProjectStyle)
}
@@ -1219,6 +1223,7 @@ func (s *Service) processStoryboardRowsTask(ctx context.Context, task model.Task
text, _ := result["text"].(string)
plan, err := parseAgentStoryboardPlan(text)
if err == nil {
normalizeAutomaticStoryboardDurations(&plan, input.ShotDuration)
err = validateStoryboardPlan(plan, input.ShotDuration, input.ShotCount, input.Characters)
}
if err != nil {
@@ -1227,6 +1232,9 @@ func (s *Service) processStoryboardRowsTask(ctx context.Context, task model.Task
return nil, nil, err
}
}
if complexityErr := validateStoryboardComplexity(plan); complexityErr != nil {
_ = s.log(task.UserID, task.ID, "warn", "分镜复杂度建议", complexityErr.Error())
}
rows := make([]map[string]any, 0, len(plan.Shots))
for index, shot := range plan.Shots {
imagePromptVariables := storyboardImagePromptValues(input.ProjectStyle.Prompt, plan.StyleGuide, shot)
@@ -1277,6 +1285,7 @@ func (s *Service) repairStoryboardPlan(ctx context.Context, task model.Task, inp
repairedText, _ := repaired["text"].(string)
plan, parseErr := parseAgentStoryboardPlan(repairedText)
if parseErr == nil {
normalizeAutomaticStoryboardDurations(&plan, shotDuration)
parseErr = validateStoryboardPlan(plan, shotDuration, shotCount, input.Characters)
}
if parseErr == nil {
@@ -1420,7 +1429,7 @@ func validateStoryboardPlan(plan agentStoryboardPlan, shotDuration int, shotCoun
if err := validateStoryboardCharacterIDs(plan, characters); err != nil {
return err
}
return validateStoryboardComplexity(plan)
return nil
}
func validateStoryboardShotCount(plan agentStoryboardPlan, target int) error {
@@ -1463,6 +1472,18 @@ func validateStoryboardComplexity(plan agentStoryboardPlan) error {
return fmt.Errorf("镜头复杂度超限:%s", strings.Join(issues, ";"))
}
func normalizeAutomaticStoryboardDurations(plan *agentStoryboardPlan, target int) {
if plan == nil || target != 0 {
return
}
for index := range plan.Shots {
shot := &plan.Shots[index]
dialogueLength := utf8.RuneCountInString(strings.TrimSpace(shot.Dialogue))
requiredDuration := (dialogueLength + 4) / 5
shot.Duration = min(60, max(1, shot.Duration, requiredDuration))
}
}
func validateStoryboardCharacterIDs(plan agentStoryboardPlan, characters []storyboardCharacterCard) error {
allowed := make(map[string]bool, len(characters))
for _, character := range characters {
@@ -73,6 +73,20 @@ func TestValidateStoryboardComplexityRejectsOverloadedShot(t *testing.T) {
}
}
func TestValidateStoryboardPlanTreatsComplexityAsAdvisory(t *testing.T) {
plan := agentStoryboardPlan{Shots: []agentStoryboardShot{{
Duration: 8,
CharacterIDs: []string{"a", "b", "c"},
MustHave: []string{"一", "二", "三", "四"},
Motion: "航拍推进并升降",
}}}
characters := []storyboardCharacterCard{{AssetID: "a"}, {AssetID: "b"}, {AssetID: "c"}}
if err := validateStoryboardPlan(plan, 0, 0, characters); err != nil {
t.Fatalf("complexity should be advisory for an otherwise valid plan: %v", err)
}
}
func TestValidateStoryboardComplexityAcceptsSingleDirectedMove(t *testing.T) {
plan := agentStoryboardPlan{Shots: []agentStoryboardShot{{
Duration: 8, CharacterIDs: []string{"a", "b"}, MustHave: []string{"身份稳定", "动作落点", "结尾状态"}, TimeBeats: "0-2秒:建立;2-6秒:动作;6-8秒:反应", Motion: "缓慢推近后停住", Dialogue: "你终于来了。",
@@ -82,6 +96,22 @@ func TestValidateStoryboardComplexityAcceptsSingleDirectedMove(t *testing.T) {
}
}
func TestNormalizeAutomaticStoryboardDurationsPreservesLongDialogue(t *testing.T) {
plan := agentStoryboardPlan{Shots: []agentStoryboardShot{{
Duration: 8,
Dialogue: strings.Repeat("字", 50),
}}}
normalizeAutomaticStoryboardDurations(&plan, 0)
if plan.Shots[0].Duration < 10 {
t.Fatalf("duration = %d, want at least 10", plan.Shots[0].Duration)
}
if err := validateStoryboardComplexity(plan); err != nil {
t.Fatalf("normalized automatic duration should pass: %v", err)
}
}
func TestMatchStoryboardAssetsForShotPrioritizesCurrentCharacterCards(t *testing.T) {
assets := []storyboardAsset{
{ID: "environment", Title: "天宫", Tags: []string{"场景:天宫"}},