@@ -15,12 +15,17 @@ import type { Config } from '../config/config.js';
1515import {
1616 DEFAULT_GEMINI_FLASH_LITE_MODEL ,
1717 DEFAULT_GEMINI_MODEL_AUTO ,
18+ PREVIEW_GEMINI_3_1_CUSTOM_TOOLS_MODEL ,
19+ PREVIEW_GEMINI_3_1_MODEL ,
1820} from '../config/models.js' ;
21+ import { AuthType } from '../core/contentGenerator.js' ;
1922
2023const createMockConfig = ( overrides : Partial < Config > = { } ) : Config =>
2124 ( {
2225 getUserTier : ( ) => undefined ,
2326 getModel : ( ) => 'gemini-2.5-pro' ,
27+ getGemini31LaunchedSync : ( ) => false ,
28+ getContentGeneratorConfig : ( ) => ( { authType : undefined } ) ,
2429 ...overrides ,
2530 } ) as unknown as Config ;
2631
@@ -115,6 +120,40 @@ describe('policyHelpers', () => {
115120 expect ( chain [ 0 ] ?. model ) . toBe ( 'gemini-2.5-flash' ) ;
116121 expect ( chain [ 1 ] ?. model ) . toBe ( 'gemini-2.5-pro' ) ;
117122 } ) ;
123+
124+ it ( 'proactively returns Gemini 2.5 chain if Gemini 3 requested but user lacks access' , ( ) => {
125+ const config = createMockConfig ( {
126+ getModel : ( ) => 'auto-gemini-3' ,
127+ getHasAccessToPreviewModel : ( ) => false ,
128+ } ) ;
129+ const chain = resolvePolicyChain ( config ) ;
130+
131+ // Should downgrade to [Pro 2.5, Flash 2.5]
132+ expect ( chain ) . toHaveLength ( 2 ) ;
133+ expect ( chain [ 0 ] ?. model ) . toBe ( 'gemini-2.5-pro' ) ;
134+ expect ( chain [ 1 ] ?. model ) . toBe ( 'gemini-2.5-flash' ) ;
135+ } ) ;
136+
137+ it ( 'returns Gemini 3.1 Pro chain when launched and auto-gemini-3 requested' , ( ) => {
138+ const config = createMockConfig ( {
139+ getModel : ( ) => 'auto-gemini-3' ,
140+ getGemini31LaunchedSync : ( ) => true ,
141+ } ) ;
142+ const chain = resolvePolicyChain ( config ) ;
143+ expect ( chain [ 0 ] ?. model ) . toBe ( PREVIEW_GEMINI_3_1_MODEL ) ;
144+ expect ( chain [ 1 ] ?. model ) . toBe ( 'gemini-3-flash-preview' ) ;
145+ } ) ;
146+
147+ it ( 'returns Gemini 3.1 Pro Custom Tools chain when launched, auth is Gemini, and auto-gemini-3 requested' , ( ) => {
148+ const config = createMockConfig ( {
149+ getModel : ( ) => 'auto-gemini-3' ,
150+ getGemini31LaunchedSync : ( ) => true ,
151+ getContentGeneratorConfig : ( ) => ( { authType : AuthType . USE_GEMINI } ) ,
152+ } ) ;
153+ const chain = resolvePolicyChain ( config ) ;
154+ expect ( chain [ 0 ] ?. model ) . toBe ( PREVIEW_GEMINI_3_1_CUSTOM_TOOLS_MODEL ) ;
155+ expect ( chain [ 1 ] ?. model ) . toBe ( 'gemini-3-flash-preview' ) ;
156+ } ) ;
118157 } ) ;
119158
120159 describe ( 'buildFallbackPolicyContext' , ( ) => {
0 commit comments