From f75c4161f2ecb3042b2ded97e7be4d29e6a199d2 Mon Sep 17 00:00:00 2001 From: xuhaihan Date: Thu, 20 Aug 2026 01:16:57 +0800 Subject: [PATCH] fix(deepseek): make account test links platform-aware --- .../internal/service/account_test_service.go | 8 +-- .../account_test_service_openai_test.go | 67 +++++++++++++++++++ backend/internal/service/cn_providers_test.go | 2 + 3 files changed, 73 insertions(+), 4 deletions(-) diff --git a/backend/internal/service/account_test_service.go b/backend/internal/service/account_test_service.go index 49d5c76295..b75c2a4c9b 100644 --- a/backend/internal/service/account_test_service.go +++ b/backend/internal/service/account_test_service.go @@ -688,7 +688,7 @@ func (s *AccountTestService) testOpenAIAccountConnection(c *gin.Context, account apiURL = chatgptCodexAPIURL } else if credentialAccount.Type == "apikey" { // API Key - use Platform API - authToken = credentialAccount.GetOpenAIApiKey() + authToken = credentialAccount.GetOpenAIProtocolAPIKey() if authToken == "" { return s.sendErrorAndEnd(c, "No API key available") } @@ -704,7 +704,7 @@ func (s *AccountTestService) testOpenAIAccountConnection(c *gin.Context, account if !openai_compat.ShouldUseResponsesAPI(account.Extra) { return s.testOpenAIChatCompletionsConnection(c, account, testModelID, prompt, normalizedBaseURL, authToken) } - apiURL = buildOpenAIResponsesURL(normalizedBaseURL) + apiURL = buildOpenAIResponsesURLForPlatform(credentialAccount.Platform, normalizedBaseURL) } else { return s.sendErrorAndEnd(c, fmt.Sprintf("Unsupported account type: %s", account.Type)) } @@ -2038,7 +2038,7 @@ func (s *AccountTestService) testOpenAICompactConnection(c *gin.Context, account } apiURL = chatgptCodexAPIURL case account.Type == AccountTypeAPIKey: - authToken = account.GetOpenAIApiKey() + authToken = account.GetOpenAIProtocolAPIKey() if authToken == "" { return s.sendErrorAndEnd(c, "No API key available") } @@ -2050,7 +2050,7 @@ func (s *AccountTestService) testOpenAICompactConnection(c *gin.Context, account if err != nil { return s.sendErrorAndEnd(c, fmt.Sprintf("Invalid base URL: %s", err.Error())) } - apiURL = buildOpenAIResponsesURL(normalizedBaseURL) + apiURL = buildOpenAIResponsesURLForPlatform(account.Platform, normalizedBaseURL) default: return s.sendErrorAndEnd(c, fmt.Sprintf("Unsupported account type: %s", account.Type)) } diff --git a/backend/internal/service/account_test_service_openai_test.go b/backend/internal/service/account_test_service_openai_test.go index 2cd63ebe3f..1ffb317533 100644 --- a/backend/internal/service/account_test_service_openai_test.go +++ b/backend/internal/service/account_test_service_openai_test.go @@ -248,6 +248,73 @@ func TestAccountTestService_OpenAIStreamEOFBeforeCompletedFails(t *testing.T) { require.NotContains(t, recorder.Body.String(), `"success":true`) } +func TestAccountTestService_DeepSeekCustomBaseURLUsesV1ResponsesPath(t *testing.T) { + gin.SetMode(gin.TestMode) + ctx, _ := newTestContext() + + resp := newJSONResponse(http.StatusOK, "") + resp.Body = io.NopCloser(strings.NewReader(`data: {"type":"response.completed"} + +`)) + upstream := &queuedHTTPUpstream{responses: []*http.Response{resp}} + svc := &AccountTestService{ + httpUpstream: upstream, + cfg: &config.Config{Security: config.SecurityConfig{URLAllowlist: config.URLAllowlistConfig{Enabled: false}}}, + } + account := &Account{ + ID: 91, + Platform: PlatformDeepseek, + Type: AccountTypeAPIKey, + Concurrency: 1, + Credentials: map[string]any{ + "api_key": "sk-test", + "base_url": "https://token.cvte.com/v1", + "api_protocol": APIProtocolResponses, + }, + Extra: map[string]any{ + openai_compat.ExtraKeyResponsesSupported: true, + }, + } + + err := svc.testOpenAIAccountConnection(ctx, account, "gpt-5.4", "", "") + require.NoError(t, err) + require.Len(t, upstream.requests, 1) + require.Equal(t, "https://token.cvte.com/v1/responses", upstream.requests[0].URL.String()) +} + +func TestAccountTestService_DeepSeekDefaultBaseURLUsesNativeResponsesPath(t *testing.T) { + gin.SetMode(gin.TestMode) + ctx, _ := newTestContext() + + resp := newJSONResponse(http.StatusOK, "") + resp.Body = io.NopCloser(strings.NewReader(`data: {"type":"response.completed"} + +`)) + upstream := &queuedHTTPUpstream{responses: []*http.Response{resp}} + svc := &AccountTestService{ + httpUpstream: upstream, + cfg: &config.Config{Security: config.SecurityConfig{URLAllowlist: config.URLAllowlistConfig{Enabled: false}}}, + } + account := &Account{ + ID: 92, + Platform: PlatformDeepseek, + Type: AccountTypeAPIKey, + Concurrency: 1, + Credentials: map[string]any{ + "api_key": "sk-test", + "api_protocol": APIProtocolResponses, + }, + Extra: map[string]any{ + openai_compat.ExtraKeyResponsesSupported: true, + }, + } + + err := svc.testOpenAIAccountConnection(ctx, account, "gpt-5.4", "", "") + require.NoError(t, err) + require.Len(t, upstream.requests, 1) + require.Equal(t, "https://api.deepseek.com/responses", upstream.requests[0].URL.String()) +} + func TestAccountTestService_OpenAI429PersistsSnapshotAndRateLimitState(t *testing.T) { gin.SetMode(gin.TestMode) ctx, _ := newTestContext() diff --git a/backend/internal/service/cn_providers_test.go b/backend/internal/service/cn_providers_test.go index 8f46e828e1..cb12dbdee3 100644 --- a/backend/internal/service/cn_providers_test.go +++ b/backend/internal/service/cn_providers_test.go @@ -635,6 +635,8 @@ func TestBuildUpstreamModelsRequest_AnthropicProtocol(t *testing.T) { func TestBuildOpenAIResponsesURLForPlatform(t *testing.T) { t.Parallel() require.Equal(t, "https://api.deepseek.com/responses", buildOpenAIResponsesURLForPlatform(PlatformDeepseek, "https://api.deepseek.com")) + require.Equal(t, "https://token.cvte.com/responses", buildOpenAIResponsesURLForPlatform(PlatformDeepseek, "https://token.cvte.com")) + require.Equal(t, "https://token.cvte.com/v1/responses", buildOpenAIResponsesURLForPlatform(PlatformDeepseek, "https://token.cvte.com/v1")) require.Equal(t, "https://api.openai.com/v1/responses", buildOpenAIResponsesURLForPlatform(PlatformOpenAI, "https://api.openai.com")) require.Equal(t, "https://open.bigmodel.cn/api/paas/v4/responses", buildOpenAIResponsesURLForPlatform(PlatformZhipu, "https://open.bigmodel.cn/api/paas/v4")) }