Merge pull request #5913 from xuhaihan/fix/deepseek-responses-account-test

fix(deepseek): route Responses account tests through OpenAI probe
This commit is contained in:
Wesley Liddick
2026-08-21 21:27:01 +08:00
committed by GitHub
3 changed files with 115 additions and 4 deletions
@@ -289,6 +289,8 @@ func (s *AccountTestService) TestAccountConnection(c *gin.Context, accountID int
switch account.GetAPIProtocol() {
case APIProtocolAdaptive:
return s.testCNProviderAdaptiveConnection(c, account, modelID, prompt)
case APIProtocolResponses:
return s.testOpenAIAccountConnection(c, account, modelID, prompt, normalizeAccountTestMode(mode))
case APIProtocolChatCompletions:
return s.testCNProviderChatCompletionsConnection(c, account, modelID, prompt)
case APIProtocolAnthropic:
@@ -690,7 +692,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")
}
@@ -706,7 +708,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))
}
@@ -2040,7 +2042,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")
}
@@ -2052,7 +2054,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,113 @@ 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://relay.example.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://relay.example.com/v1/responses", upstream.requests[0].URL.String())
}
func TestAccountTestService_DeepSeekResponsesRoutesToOpenAIProbe(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: 93,
Platform: PlatformDeepseek,
Type: AccountTypeAPIKey,
Concurrency: 1,
Credentials: map[string]any{
"api_key": "sk-test",
"base_url": "https://relay.example.com/v1",
"api_protocol": APIProtocolResponses,
},
Extra: map[string]any{
openai_compat.ExtraKeyResponsesSupported: true,
},
}
repo := &openAIAccountTestRepo{
mockAccountRepoForGemini: mockAccountRepoForGemini{
accountsByID: map[int64]*Account{93: account},
},
}
svc.accountRepo = repo
err := svc.TestAccountConnection(ctx, account.ID, "gpt-5.4", "", "")
require.NoError(t, err)
require.Len(t, upstream.requests, 1)
require.Equal(t, "https://relay.example.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://relay.example.com/responses", buildOpenAIResponsesURLForPlatform(PlatformDeepseek, "https://relay.example.com"))
require.Equal(t, "https://relay.example.com/v1/responses", buildOpenAIResponsesURLForPlatform(PlatformDeepseek, "https://relay.example.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"))
}