fix: model persistence for all scenarios (#21051)

This commit is contained in:
Sri Pasumarthi
2026-03-03 19:28:12 -08:00
committed by GitHub
parent fdfd626f28
commit 5bd21a240d
2 changed files with 20 additions and 3 deletions

View File

@@ -2198,6 +2198,23 @@ describe('Config getHooks', () => {
expect(onModelChange).not.toHaveBeenCalled();
});
it('should call onModelChange when persisting a model that was previously temporary', () => {
const onModelChange = vi.fn();
const config = new Config({
...baseParams,
model: 'some-other-model',
onModelChange,
});
// Temporary selection
config.setModel(DEFAULT_GEMINI_MODEL, true);
expect(onModelChange).not.toHaveBeenCalled();
// Persist selection of the same model
config.setModel(DEFAULT_GEMINI_MODEL, false);
expect(onModelChange).toHaveBeenCalledWith(DEFAULT_GEMINI_MODEL);
});
});
});

View File

@@ -1403,9 +1403,9 @@ export class Config implements McpContext {
// When the user explicitly sets a model, that becomes the active model.
this._activeModel = newModel;
coreEvents.emitModelChanged(newModel);
if (this.onModelChange && !isTemporary) {
this.onModelChange(newModel);
}
}
if (this.onModelChange && !isTemporary) {
this.onModelChange(newModel);
}
this.modelAvailabilityService.reset();
}