fix(deepseek): make account test links platform-aware

This commit is contained in:
xuhaihan
2026-08-20 18:18:44 +08:00
parent 2bc139ab52
commit f75c4161f2
3 changed files with 73 additions and 4 deletions
@@ -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))
}
@@ -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()
@@ -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"))
}