fix(core): handle non-string model flags in resolution (#26069)

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This commit is contained in:
Adib234
2026-04-28 13:11:15 -04:00
committed by GitHub
parent 58a57b72ae
commit b0ffa3b51e
4 changed files with 128 additions and 4 deletions
+94
View File
@@ -804,6 +804,100 @@ describe('loadCliConfig', () => {
vi.restoreAllMocks();
});
describe('Model resolution', () => {
it('should handle multiple --model flags by taking the last one', async () => {
const argv = {
query: undefined,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
model: ['gemini-1.5-pro', 'gemini-2.0-flash'] as any,
sandbox: undefined,
debug: false,
prompt: undefined,
promptInteractive: undefined,
yolo: undefined,
approvalMode: undefined,
policy: undefined,
adminPolicy: undefined,
allowedMcpServerNames: undefined,
allowedTools: undefined,
extensions: undefined,
listExtensions: false,
listSessions: false,
deleteSession: undefined,
screenReader: undefined,
isCommand: false,
rawOutput: false,
acceptRawOutputRisk: false,
startupMessages: [],
resume: undefined,
includeDirectories: [],
useWriteTodos: false,
outputFormat: undefined,
fakeResponses: undefined,
recordResponses: undefined,
skipTrust: false,
};
const settings = createTestMergedSettings();
const config = await loadCliConfig(
settings,
'test-session',
argv as unknown as CliArgs,
{
cwd: process.cwd(),
},
);
expect(config.getModel()).toBe('gemini-2.0-flash');
});
it('should handle non-string model flags by coercing to string', async () => {
const argv = {
query: undefined,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
model: true as any,
sandbox: undefined,
debug: false,
prompt: undefined,
promptInteractive: undefined,
yolo: undefined,
approvalMode: undefined,
policy: undefined,
adminPolicy: undefined,
allowedMcpServerNames: undefined,
allowedTools: undefined,
extensions: undefined,
listExtensions: false,
listSessions: false,
deleteSession: undefined,
screenReader: undefined,
isCommand: false,
rawOutput: false,
acceptRawOutputRisk: false,
startupMessages: [],
resume: undefined,
includeDirectories: [],
useWriteTodos: false,
outputFormat: undefined,
fakeResponses: undefined,
recordResponses: undefined,
skipTrust: false,
};
const settings = createTestMergedSettings();
const config = await loadCliConfig(
settings,
'test-session',
argv as unknown as CliArgs,
{
cwd: process.cwd(),
},
);
expect(config.getModel()).toBe('true');
});
});
describe('Proxy configuration', () => {
const originalProxyEnv: { [key: string]: string | undefined } = {};
const proxyEnvVars = [
+8 -1
View File
@@ -841,9 +841,16 @@ export async function loadCliConfig(
);
const defaultModel = PREVIEW_GEMINI_MODEL_AUTO;
const specifiedModel =
const rawModel =
argv.model || process.env['GEMINI_MODEL'] || settings.model?.name;
// Ensure specifiedModel is a string (e.g. if yargs parsed multiple --model as an array)
const specifiedModel = Array.isArray(rawModel)
? String(rawModel.at(-1) ?? '').trim() || ''
: rawModel === undefined
? undefined
: String(rawModel ?? '').trim() || '';
const resolvedModel =
specifiedModel === GEMINI_MODEL_ALIAS_AUTO
? defaultModel