fix(patch): cherry-pick a6d1245 to release/v0.21.1-pr-15214 to patch version v0.21.1 and create version 0.21.2 (#15227)

Co-authored-by: Sehoon Shon <sshon@google.com>
This commit is contained in:
gemini-cli-robot
2025-12-17 15:26:19 -08:00
committed by GitHub
parent f69619e2ec
commit 97eab144bc
2 changed files with 26 additions and 9 deletions

View File

@@ -38,6 +38,7 @@ import {
DEFAULT_GEMINI_MODEL,
DEFAULT_GEMINI_MODEL_AUTO,
PREVIEW_GEMINI_MODEL,
PREVIEW_GEMINI_MODEL_AUTO,
} from './models.js';
vi.mock('fs', async (importOriginal) => {
@@ -1834,6 +1835,15 @@ describe('Config Quota & Preview Model Access', () => {
expect(config.getModel()).toBe(nonPreviewModel);
});
it('should switch to preview auto model if enabling preview features while using default auto model', () => {
config.setPreviewFeatures(false);
config.setModel(DEFAULT_GEMINI_MODEL_AUTO);
config.setPreviewFeatures(true);
expect(config.getModel()).toBe(PREVIEW_GEMINI_MODEL_AUTO);
});
it('should NOT reset model if enabling preview features', () => {
config.setPreviewFeatures(false);
config.setModel(PREVIEW_GEMINI_MODEL); // Just pretending it was set somehow

View File

@@ -52,6 +52,7 @@ import {
DEFAULT_THINKING_MODE,
isPreviewModel,
PREVIEW_GEMINI_MODEL,
PREVIEW_GEMINI_MODEL_AUTO,
} from './models.js';
import { shouldAttemptBrowserLaunch } from '../utils/browser.js';
import type { MCPOAuthConfig } from '../mcp/oauth-provider.js';
@@ -732,8 +733,6 @@ export class Config {
// Initialize BaseLlmClient now that the ContentGenerator is available
this.baseLlmClient = new BaseLlmClient(this.contentGenerator, this);
const previewFeatures = this.getPreviewFeatures();
const codeAssistServer = getCodeAssistServer(this);
if (codeAssistServer) {
if (codeAssistServer.projectId) {
@@ -745,7 +744,7 @@ export class Config {
this.setExperiments(experiments);
// If preview features have not been set and the user authenticated through Google, we enable preview based on remote config only if it's true
if (previewFeatures === undefined) {
if (this.getPreviewFeatures() === undefined) {
const remotePreviewFeatures =
experiments.flags[ExperimentFlags.ENABLE_PREVIEW]?.boolValue;
if (remotePreviewFeatures === true) {
@@ -969,14 +968,22 @@ export class Config {
}
setPreviewFeatures(previewFeatures: boolean) {
// If it's using a preview model and it's turning off previewFeatures,
// switch the model to the default auto mode.
if (this.previewFeatures && !previewFeatures) {
if (isPreviewModel(this.getModel())) {
this.setModel(DEFAULT_GEMINI_MODEL_AUTO);
}
// No change in state, no action needed
if (this.previewFeatures === previewFeatures) {
return;
}
this.previewFeatures = previewFeatures;
const currentModel = this.getModel();
// Case 1: Disabling preview features while on a preview model
if (!previewFeatures && isPreviewModel(currentModel)) {
this.setModel(DEFAULT_GEMINI_MODEL_AUTO);
}
// Case 2: Enabling preview features while on the default auto model
else if (previewFeatures && currentModel === DEFAULT_GEMINI_MODEL_AUTO) {
this.setModel(PREVIEW_GEMINI_MODEL_AUTO);
}
}
getHasAccessToPreviewModel(): boolean {