From 1b9645ca32e198e395beaa09127e6af35056db49 Mon Sep 17 00:00:00 2001 From: Heatherm Huang Date: Wed, 17 Jun 2026 08:23:58 +0800 Subject: [PATCH] fix: allow grok scheduler capability routing --- backend/internal/service/account.go | 3 ++ .../service/openai_account_scheduler_test.go | 44 +++++++++++++++++++ .../internal/service/openai_images_test.go | 10 +++++ 3 files changed, 57 insertions(+) diff --git a/backend/internal/service/account.go b/backend/internal/service/account.go index e5f16a3876..8abef78398 100644 --- a/backend/internal/service/account.go +++ b/backend/internal/service/account.go @@ -1258,6 +1258,9 @@ func (a *Account) openAIEndpointCapabilitySet() (map[string]bool, bool) { } func (a *Account) SupportsOpenAIImageCapability(capability OpenAIImagesCapability) bool { + if capability == "" { + return true + } if !a.IsOpenAI() { return false } diff --git a/backend/internal/service/openai_account_scheduler_test.go b/backend/internal/service/openai_account_scheduler_test.go index 4d2fbd7d70..6d8e38d0bc 100644 --- a/backend/internal/service/openai_account_scheduler_test.go +++ b/backend/internal/service/openai_account_scheduler_test.go @@ -475,6 +475,50 @@ func TestOpenAIGatewayService_SelectAccountWithScheduler_DefaultDisabled_Embeddi require.Equal(t, openAIAccountScheduleLayerLoadBalance, decision.Layer) } +func TestOpenAIGatewayService_SelectAccountWithScheduler_DefaultDisabled_AllowsGrokChatAccount(t *testing.T) { + resetOpenAIAdvancedSchedulerSettingCacheForTest() + + ctx := context.Background() + groupID := int64(10113) + accounts := []Account{ + { + ID: 36041, + Platform: PlatformGrok, + Type: AccountTypeOAuth, + Status: StatusActive, + Schedulable: true, + Concurrency: 1, + Priority: 0, + }, + } + cfg := &config.Config{} + cfg.Gateway.Scheduling.LoadBatchEnabled = false + svc := &OpenAIGatewayService{ + accountRepo: schedulerTestOpenAIAccountRepo{accounts: accounts}, + cache: &schedulerTestGatewayCache{}, + cfg: cfg, + concurrencyService: NewConcurrencyService(schedulerTestConcurrencyCache{}), + } + + selection, decision, err := svc.SelectAccountWithSchedulerForCapability( + ctx, + &groupID, + "", + "", + "grok-4.3", + nil, + OpenAIUpstreamTransportAny, + OpenAIEndpointCapabilityChatCompletions, + false, + PlatformGrok, + ) + require.NoError(t, err) + require.NotNil(t, selection) + require.NotNil(t, selection.Account) + require.Equal(t, int64(36041), selection.Account.ID) + require.Equal(t, openAIAccountScheduleLayerLoadBalance, decision.Layer) +} + func TestOpenAIGatewayService_SelectAccountWithScheduler_EnabledUsesAdvancedPreviousResponseRouting(t *testing.T) { resetOpenAIAdvancedSchedulerSettingCacheForTest() diff --git a/backend/internal/service/openai_images_test.go b/backend/internal/service/openai_images_test.go index 74846e0a23..9897bffed0 100644 --- a/backend/internal/service/openai_images_test.go +++ b/backend/internal/service/openai_images_test.go @@ -442,6 +442,16 @@ func TestAccountSupportsOpenAIImageCapability_OAuthSupportsNative(t *testing.T) require.True(t, account.SupportsOpenAIImageCapability(OpenAIImagesCapabilityNative)) } +func TestAccountSupportsOpenAIImageCapability_EmptyRequirementDoesNotRejectGrok(t *testing.T) { + account := &Account{ + Platform: PlatformGrok, + Type: AccountTypeOAuth, + } + + require.True(t, account.SupportsOpenAIImageCapability("")) + require.False(t, account.SupportsOpenAIImageCapability(OpenAIImagesCapabilityBasic)) +} + func TestAccountSupportsOpenAIEndpointCapability(t *testing.T) { t.Run("OpenAI APIKey 默认兼容 chat 和 embeddings", func(t *testing.T) { account := &Account{