From 60d84d621c0437ffc1d7041bdcef806b7719f799 Mon Sep 17 00:00:00 2001 From: erio Date: Sat, 4 Apr 2026 19:18:48 +0800 Subject: [PATCH] fix: remove leftover affinity test cases from gateway_multiplatform_test.go --- .../service/gateway_multiplatform_test.go | 301 ------------------ 1 file changed, 301 deletions(-) diff --git a/backend/internal/service/gateway_multiplatform_test.go b/backend/internal/service/gateway_multiplatform_test.go index b8d3538d5a..5bd0ef16f2 100644 --- a/backend/internal/service/gateway_multiplatform_test.go +++ b/backend/internal/service/gateway_multiplatform_test.go @@ -2155,307 +2155,6 @@ func TestGatewayService_SelectAccountWithLoadAwareness(t *testing.T) { require.Equal(t, int64(2), result.Account.ID, "不应选择被排除的账号") }) - t.Run("无客户端ID时过滤Anthropic OAuth亲和账号-load-aware路径", func(t *testing.T) { - repo := &mockAccountRepoForPlatform{ - accounts: []Account{ - { - ID: 1, - Platform: PlatformAnthropic, - Type: AccountTypeOAuth, - Priority: 1, - Status: StatusActive, - Schedulable: true, - Concurrency: 5, - Extra: map[string]any{ - "client_affinity_enabled": true, - }, - }, - { - ID: 2, - Platform: PlatformAnthropic, - Type: AccountTypeOAuth, - Priority: 2, - Status: StatusActive, - Schedulable: true, - Concurrency: 5, - }, - }, - accountsByID: map[int64]*Account{}, - } - for i := range repo.accounts { - repo.accountsByID[repo.accounts[i].ID] = &repo.accounts[i] - } - - cfg := testConfig() - cfg.Gateway.Scheduling.LoadBatchEnabled = true - - svc := &GatewayService{ - accountRepo: repo, - cache: &mockGatewayCacheForPlatform{}, - cfg: cfg, - concurrencyService: NewConcurrencyService(&mockConcurrencyCache{}), - } - - result, err := svc.SelectAccountWithLoadAwareness(ctx, nil, "", "claude-3-5-sonnet-20241022", nil, "", 0) - require.NoError(t, err) - require.NotNil(t, result) - require.NotNil(t, result.Account) - require.Equal(t, int64(2), result.Account.ID, "无客户端ID时应过滤亲和OAuth账号") - }) - - t.Run("无客户端ID且亲和关闭时-load-aware路径恢复旧逻辑", func(t *testing.T) { - repo := &mockAccountRepoForPlatform{ - accounts: []Account{ - { - ID: 1, - Platform: PlatformAnthropic, - Type: AccountTypeOAuth, - Priority: 1, - Status: StatusActive, - Schedulable: true, - Concurrency: 5, - Extra: map[string]any{ - "affinity_enabled": false, - }, - }, - { - ID: 2, - Platform: PlatformAnthropic, - Type: AccountTypeOAuth, - Priority: 2, - Status: StatusActive, - Schedulable: true, - Concurrency: 5, - }, - }, - accountsByID: map[int64]*Account{}, - } - for i := range repo.accounts { - repo.accountsByID[repo.accounts[i].ID] = &repo.accounts[i] - } - - cfg := testConfig() - cfg.Gateway.Scheduling.LoadBatchEnabled = true - - svc := &GatewayService{ - accountRepo: repo, - cache: &mockGatewayCacheForPlatform{}, - cfg: cfg, - concurrencyService: NewConcurrencyService(&mockConcurrencyCache{}), - } - - result, err := svc.SelectAccountWithLoadAwareness(ctx, nil, "", "claude-3-5-sonnet-20241022", nil, "", 0) - require.NoError(t, err) - require.NotNil(t, result) - require.NotNil(t, result.Account) - require.Equal(t, int64(1), result.Account.ID, "关闭亲和后不应再被无clientID过滤") - }) - - t.Run("有客户端ID时不过滤Anthropic OAuth亲和账号", func(t *testing.T) { - repo := &mockAccountRepoForPlatform{ - accounts: []Account{ - { - ID: 1, - Platform: PlatformAnthropic, - Type: AccountTypeOAuth, - Priority: 1, - Status: StatusActive, - Schedulable: true, - Concurrency: 5, - Extra: map[string]any{ - "client_affinity_enabled": true, - }, - }, - { - ID: 2, - Platform: PlatformAnthropic, - Type: AccountTypeOAuth, - Priority: 2, - Status: StatusActive, - Schedulable: true, - Concurrency: 5, - }, - }, - accountsByID: map[int64]*Account{}, - } - for i := range repo.accounts { - repo.accountsByID[repo.accounts[i].ID] = &repo.accounts[i] - } - - cfg := testConfig() - cfg.Gateway.Scheduling.LoadBatchEnabled = true - - svc := &GatewayService{ - accountRepo: repo, - cache: &mockGatewayCacheForPlatform{}, - cfg: cfg, - concurrencyService: NewConcurrencyService(&mockConcurrencyCache{}), - } - - metadataUserID := "user_0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef_account_test_session_test" - result, err := svc.SelectAccountWithLoadAwareness(ctx, nil, "", "claude-3-5-sonnet-20241022", nil, metadataUserID, 123) - require.NoError(t, err) - require.NotNil(t, result) - require.NotNil(t, result.Account) - require.Equal(t, int64(1), result.Account.ID, "有客户端ID时应允许亲和OAuth账号参与调度") - }) - - t.Run("过滤对Anthropic全类型生效-SetupToken也受影响", func(t *testing.T) { - repo := &mockAccountRepoForPlatform{ - accounts: []Account{ - { - ID: 1, - Platform: PlatformAnthropic, - Type: AccountTypeSetupToken, - Priority: 1, - Status: StatusActive, - Schedulable: true, - Concurrency: 5, - Extra: map[string]any{ - "client_affinity_enabled": true, - }, - }, - { - ID: 2, - Platform: PlatformAnthropic, - Type: AccountTypeOAuth, - Priority: 2, - Status: StatusActive, - Schedulable: true, - Concurrency: 5, - Extra: map[string]any{ - "client_affinity_enabled": true, - }, - }, - { - ID: 3, - Platform: PlatformAnthropic, - Type: AccountTypeOAuth, - Priority: 3, - Status: StatusActive, - Schedulable: true, - Concurrency: 5, - }, - }, - accountsByID: map[int64]*Account{}, - } - for i := range repo.accounts { - repo.accountsByID[repo.accounts[i].ID] = &repo.accounts[i] - } - - cfg := testConfig() - cfg.Gateway.Scheduling.LoadBatchEnabled = true - - svc := &GatewayService{ - accountRepo: repo, - cache: &mockGatewayCacheForPlatform{}, - cfg: cfg, - concurrencyService: NewConcurrencyService(&mockConcurrencyCache{}), - } - - result, err := svc.SelectAccountWithLoadAwareness(ctx, nil, "", "claude-3-5-sonnet-20241022", nil, "", 0) - require.NoError(t, err) - require.NotNil(t, result) - require.NotNil(t, result.Account) - require.Equal(t, int64(3), result.Account.ID, "无客户端ID时,Anthropic SetupToken/OAuth(开启亲和)都应被过滤") - }) - - t.Run("无客户端ID时过滤Anthropic OAuth亲和账号-legacy路径", func(t *testing.T) { - repo := &mockAccountRepoForPlatform{ - accounts: []Account{ - { - ID: 1, - Platform: PlatformAnthropic, - Type: AccountTypeOAuth, - Priority: 1, - Status: StatusActive, - Schedulable: true, - Concurrency: 5, - Extra: map[string]any{ - "client_affinity_enabled": true, - }, - }, - { - ID: 2, - Platform: PlatformAnthropic, - Type: AccountTypeOAuth, - Priority: 2, - Status: StatusActive, - Schedulable: true, - Concurrency: 5, - }, - }, - accountsByID: map[int64]*Account{}, - } - for i := range repo.accounts { - repo.accountsByID[repo.accounts[i].ID] = &repo.accounts[i] - } - - cfg := testConfig() - cfg.Gateway.Scheduling.LoadBatchEnabled = false - - svc := &GatewayService{ - accountRepo: repo, - cache: &mockGatewayCacheForPlatform{}, - cfg: cfg, - concurrencyService: nil, - } - - result, err := svc.SelectAccountWithLoadAwareness(ctx, nil, "", "claude-3-5-sonnet-20241022", nil, "", 0) - require.NoError(t, err) - require.NotNil(t, result) - require.NotNil(t, result.Account) - require.Equal(t, int64(2), result.Account.ID, "legacy路径也应过滤亲和OAuth账号") - }) - - t.Run("无客户端ID且亲和关闭时-legacy路径恢复旧逻辑", func(t *testing.T) { - repo := &mockAccountRepoForPlatform{ - accounts: []Account{ - { - ID: 1, - Platform: PlatformAnthropic, - Type: AccountTypeOAuth, - Priority: 1, - Status: StatusActive, - Schedulable: true, - Concurrency: 5, - Extra: map[string]any{ - "client_affinity_enabled": false, - }, - }, - { - ID: 2, - Platform: PlatformAnthropic, - Type: AccountTypeOAuth, - Priority: 2, - Status: StatusActive, - Schedulable: true, - Concurrency: 5, - }, - }, - accountsByID: map[int64]*Account{}, - } - for i := range repo.accounts { - repo.accountsByID[repo.accounts[i].ID] = &repo.accounts[i] - } - - cfg := testConfig() - cfg.Gateway.Scheduling.LoadBatchEnabled = false - - svc := &GatewayService{ - accountRepo: repo, - cache: &mockGatewayCacheForPlatform{}, - cfg: cfg, - concurrencyService: nil, - } - - result, err := svc.SelectAccountWithLoadAwareness(ctx, nil, "", "claude-3-5-sonnet-20241022", nil, "", 0) - require.NoError(t, err) - require.NotNil(t, result) - require.NotNil(t, result.Account) - require.Equal(t, int64(1), result.Account.ID, "关闭亲和后 legacy 路径不应再被无clientID过滤") - }) - t.Run("粘性命中-不调用GetByID", func(t *testing.T) { repo := &mockAccountRepoForPlatform{ accounts: []Account{