feat(api): 统一官方兼容接口响应协议
兼容接口现在以入口协议作为最终响应协议,同协议保留官方 Wire 响应,跨协议统一转换成功、任务状态与错误结构。 同时修正异步提交状态边界,持久化兼容公开任务标识和官方提交响应,并新增迁移、流式响应及协议契约测试。 验证:go vet ./...;go test ./...;govulncheck ./...;pnpm lint;pnpm test;pnpm build;pnpm audit --audit-level high;pnpm openapi;全部 CI 脚本。
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
package clients
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/easyai/easyai-ai-gateway/apps/api/internal/store"
|
||||
)
|
||||
|
||||
func TestLocalUnsupportedKindDoesNotMarkUpstreamSubmissionStarted(t *testing.T) {
|
||||
started, responseReceived := false, false
|
||||
_, err := (VolcesClient{}).Run(context.Background(), Request{
|
||||
Kind: "speech.generations",
|
||||
Candidate: store.RuntimeModelCandidate{
|
||||
Provider: "volces", Credentials: map[string]any{"apiKey": "test"},
|
||||
},
|
||||
OnUpstreamSubmissionStarted: func() error { started = true; return nil },
|
||||
OnUpstreamResponseReceived: func() error { responseReceived = true; return nil },
|
||||
})
|
||||
if err == nil || ErrorCode(err) != "unsupported_kind" {
|
||||
t.Fatalf("expected local unsupported_kind, got %v", err)
|
||||
}
|
||||
if started || responseReceived {
|
||||
t.Fatalf("local validation must remain not_submitted: started=%v response=%v", started, responseReceived)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNetworkDisconnectMarksSubmittingWithoutResponseReceived(t *testing.T) {
|
||||
upstream := httptest.NewServer(http.HandlerFunc(func(http.ResponseWriter, *http.Request) {}))
|
||||
baseURL := upstream.URL
|
||||
upstream.Close()
|
||||
started, responseReceived := false, false
|
||||
_, err := (VolcesClient{HTTPClient: upstream.Client()}).Run(context.Background(), Request{
|
||||
Kind: "images.generations",
|
||||
Body: map[string]any{"prompt": "test"},
|
||||
Candidate: store.RuntimeModelCandidate{
|
||||
Provider: "volces", BaseURL: baseURL, ModelName: "seedream-test",
|
||||
Credentials: map[string]any{"apiKey": "test"},
|
||||
},
|
||||
OnUpstreamSubmissionStarted: func() error { started = true; return nil },
|
||||
OnUpstreamResponseReceived: func() error { responseReceived = true; return nil },
|
||||
})
|
||||
if err == nil || ErrorCode(err) != "network" {
|
||||
t.Fatalf("expected network error, got %v", err)
|
||||
}
|
||||
if !started || responseReceived {
|
||||
t.Fatalf("network disconnect must remain submitting: started=%v response=%v", started, responseReceived)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user