兼容接口现在以入口协议作为最终响应协议,同协议保留官方 Wire 响应,跨协议统一转换成功、任务状态与错误结构。 同时修正异步提交状态边界,持久化兼容公开任务标识和官方提交响应,并新增迁移、流式响应及协议契约测试。 验证:go vet ./...;go test ./...;govulncheck ./...;pnpm lint;pnpm test;pnpm build;pnpm audit --audit-level high;pnpm openapi;全部 CI 脚本。
39 lines
1.6 KiB
Go
39 lines
1.6 KiB
Go
package httpapi
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/easyai/easyai-ai-gateway/apps/api/internal/store"
|
|
)
|
|
|
|
func TestVolcesCompatibleTaskPreservesNativeOfficialFieldsWithoutGatewayExtensions(t *testing.T) {
|
|
now := time.Date(2026, 7, 18, 8, 0, 0, 0, time.UTC)
|
|
task := store.GatewayTask{
|
|
ID: "gateway-task-1", Kind: "videos.generations", Status: "succeeded", Model: "doubao-seedance-2-0-mini-260615",
|
|
RemoteTaskID: "cgt-upstream-1", CreatedAt: now, UpdatedAt: now.Add(time.Second),
|
|
Result: map[string]any{
|
|
"raw": map[string]any{
|
|
"id": "cgt-upstream-1", "model": "doubao-seedance-2-0-mini-260615", "status": "succeeded",
|
|
"content": map[string]any{"video_url": "https://example.com/out.mp4"}, "usage": map[string]any{"total_tokens": 9},
|
|
"future_official_field": "preserved",
|
|
},
|
|
},
|
|
Billings: []any{map[string]any{"amount": 3}}, BillingSummary: map[string]any{"currency": "resource"}, FinalChargeAmount: 3,
|
|
Attempts: []store.TaskAttempt{{Provider: "volces"}},
|
|
}
|
|
got := volcesCompatibleTask(task)
|
|
if got["id"] != task.RemoteTaskID || got["status"] != "succeeded" || got["future_official_field"] != "preserved" {
|
|
t.Fatalf("unexpected compatibility identity/status: %+v", got)
|
|
}
|
|
content, _ := got["content"].(map[string]any)
|
|
if content["video_url"] != "https://example.com/out.mp4" || got["usage"] == nil {
|
|
t.Fatalf("official fields were lost: %+v", got)
|
|
}
|
|
for _, forbidden := range []string{"gateway_task_id", "gateway_status", "billings", "billing_summary", "final_charge_amount", "upstream_task_id"} {
|
|
if _, ok := got[forbidden]; ok {
|
|
t.Fatalf("compatibility response contains gateway extension %q: %+v", forbidden, got)
|
|
}
|
|
}
|
|
}
|