File tree Expand file tree Collapse file tree 2 files changed +56
-7
lines changed
Expand file tree Collapse file tree 2 files changed +56
-7
lines changed Original file line number Diff line number Diff line change @@ -176,16 +176,24 @@ const ModelSelector: React.FC<ModelSelectorProps> = ({ onConfigChange }) => {
176176 }
177177 }
178178
179- // Fallback to first available model if not found or invalid
179+ // Fallback to default model or first available model if not found or invalid
180180 if ( ! fullModelName || ! displayName || ( fullModelName && ! models . includes ( fullModelName ) ) ) {
181181 if ( models . length > 0 ) {
182- const firstModel = models [ 0 ] ;
183- fullModelName = firstModel ;
184- // Check if it's a LiteLLM model
185- if ( firstModel && firstModel . includes ( '/' ) ) {
186- displayName = firstModel ;
182+ // First, try to use the default model if it's available
183+ const defaultMapping = MODEL_MAPPINGS . find ( m => m . displayName === DEFAULT_MODEL ) ;
184+ if ( defaultMapping && models . includes ( defaultMapping . fullName ) ) {
185+ fullModelName = defaultMapping . fullName ;
186+ displayName = defaultMapping . displayName ;
187187 } else {
188- displayName = MODEL_MAPPINGS . find ( m => m . fullName === firstModel ) ?. displayName || firstModel ;
188+ // Fallback to first available model
189+ const firstModel = models [ 0 ] ;
190+ fullModelName = firstModel ;
191+ // Check if it's a LiteLLM model
192+ if ( firstModel && firstModel . includes ( '/' ) ) {
193+ displayName = firstModel ;
194+ } else {
195+ displayName = MODEL_MAPPINGS . find ( m => m . fullName === firstModel ) ?. displayName || firstModel ;
196+ }
189197 }
190198 } else {
191199 // Fallback to default if no models available
Original file line number Diff line number Diff line change @@ -95,4 +95,45 @@ describe('ModelSelector', () => {
9595 expect ( mockOnConfigChange ) . toHaveBeenCalledWith ( savedConfig ) ;
9696 } ) ;
9797 } ) ;
98+
99+ it ( 'defaults to default model when no storedConfig exists and GPT 4.1 is first in available models' , async ( ) => {
100+ // Mock models with GPT 4.1 first (simulating the bug scenario)
101+ mockRequestAPI . mockResolvedValue ( {
102+ data : {
103+ models : [
104+ GPT_4_1_MODEL_NAME ,
105+ GPT_5_2_MODEL_NAME ,
106+ CLAUDE_SONNET_MODEL_NAME ,
107+ CLAUDE_HAIKU_MODEL_NAME ,
108+ GEMINI_3_FLASH_MODEL_NAME ,
109+ GEMINI_3_PRO_MODEL_NAME ,
110+ ]
111+ }
112+ } ) ;
113+
114+ // Ensure localStorage is empty (no storedConfig)
115+ localStorage . clear ( ) ;
116+
117+ render ( < ModelSelector onConfigChange = { mockOnConfigChange } /> ) ;
118+
119+ // Wait for models to load
120+ await waitFor ( ( ) => {
121+ expect ( screen . queryByText ( 'Loading models...' ) ) . not . toBeInTheDocument ( ) ;
122+ } ) ;
123+
124+ // Verify that the default model (Haiku 4.5) is selected, not GPT 4.1
125+ expect ( screen . getByText ( DEFAULT_MODEL ) ) . toBeInTheDocument ( ) ;
126+
127+ // Verify onConfigChange was called with Haiku model, not GPT 4.1
128+ await waitFor ( ( ) => {
129+ expect ( mockOnConfigChange ) . toHaveBeenCalledWith ( {
130+ model : DEFAULT_MODEL
131+ } ) ;
132+ } ) ;
133+
134+ // Ensure it was NOT called with GPT 4.1
135+ expect ( mockOnConfigChange ) . not . toHaveBeenCalledWith ( {
136+ model : GPT_4_1_MODEL_NAME
137+ } ) ;
138+ } ) ;
98139} ) ;
You can’t perform that action at this time.
0 commit comments