|
| 1 | +//go:build unit |
| 2 | + |
| 3 | +package service |
| 4 | + |
| 5 | +import ( |
| 6 | + "context" |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/Wei-Shaw/sub2api/internal/config" |
| 10 | + "github.com/stretchr/testify/require" |
| 11 | +) |
| 12 | + |
| 13 | +func TestOpenAIGatewayService_SelectAccountWithScheduler_UsesWSPassthroughSnapshotFlags(t *testing.T) { |
| 14 | + ctx := context.Background() |
| 15 | + groupID := int64(10105) |
| 16 | + account := &Account{ |
| 17 | + ID: 35001, |
| 18 | + Platform: PlatformOpenAI, |
| 19 | + Type: AccountTypeOAuth, |
| 20 | + Status: StatusActive, |
| 21 | + Schedulable: true, |
| 22 | + Concurrency: 10, |
| 23 | + Extra: map[string]any{ |
| 24 | + "openai_oauth_responses_websockets_v2_mode": OpenAIWSIngressModePassthrough, |
| 25 | + }, |
| 26 | + } |
| 27 | + |
| 28 | + snapshotCache := &openAISnapshotCacheStub{ |
| 29 | + snapshotAccounts: []*Account{account}, |
| 30 | + accountsByID: map[int64]*Account{account.ID: account}, |
| 31 | + } |
| 32 | + cfg := &config.Config{} |
| 33 | + cfg.Gateway.OpenAIWS.Enabled = true |
| 34 | + cfg.Gateway.OpenAIWS.OAuthEnabled = true |
| 35 | + cfg.Gateway.OpenAIWS.APIKeyEnabled = true |
| 36 | + cfg.Gateway.OpenAIWS.ResponsesWebsocketsV2 = true |
| 37 | + cfg.Gateway.OpenAIWS.ModeRouterV2Enabled = true |
| 38 | + cfg.Gateway.OpenAIWS.IngressModeDefault = OpenAIWSIngressModeCtxPool |
| 39 | + |
| 40 | + svc := &OpenAIGatewayService{ |
| 41 | + accountRepo: stubOpenAIAccountRepo{accounts: []Account{*account}}, |
| 42 | + cache: &stubGatewayCache{}, |
| 43 | + cfg: cfg, |
| 44 | + schedulerSnapshot: &SchedulerSnapshotService{cache: snapshotCache}, |
| 45 | + concurrencyService: NewConcurrencyService(stubConcurrencyCache{}), |
| 46 | + } |
| 47 | + |
| 48 | + selection, decision, err := svc.SelectAccountWithScheduler( |
| 49 | + ctx, |
| 50 | + &groupID, |
| 51 | + "", |
| 52 | + "session_hash_ws_passthrough", |
| 53 | + "gpt-5.1", |
| 54 | + nil, |
| 55 | + OpenAIUpstreamTransportResponsesWebsocketV2, |
| 56 | + ) |
| 57 | + require.NoError(t, err) |
| 58 | + require.NotNil(t, selection) |
| 59 | + require.NotNil(t, selection.Account) |
| 60 | + require.Equal(t, account.ID, selection.Account.ID) |
| 61 | + require.Equal(t, openAIAccountScheduleLayerLoadBalance, decision.Layer) |
| 62 | +} |
0 commit comments