mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-29 22:44:45 -07:00
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:
@@ -273,6 +273,13 @@ describe('isCustomModel', () => {
|
||||
expect(isCustomModel(GEMINI_MODEL_ALIAS_AUTO)).toBe(false);
|
||||
expect(isCustomModel(GEMINI_MODEL_ALIAS_PRO)).toBe(false);
|
||||
});
|
||||
|
||||
it('should not throw if the model is an array (e.g. from yargs)', () => {
|
||||
// @ts-expect-error - testing invalid runtime input
|
||||
expect(() => isCustomModel(['gemini-2.0-flash', 'gpt-4'])).not.toThrow();
|
||||
// @ts-expect-error - testing invalid runtime input
|
||||
expect(isCustomModel(['gemini-2.0-flash', 'gpt-4'])).toBe(true); // last one is custom
|
||||
});
|
||||
});
|
||||
|
||||
describe('supportsModernFeatures', () => {
|
||||
@@ -431,6 +438,15 @@ describe('resolveModel', () => {
|
||||
const model = resolveModel(customModel);
|
||||
expect(model).toBe(customModel);
|
||||
});
|
||||
|
||||
it('should handle non-string inputs gracefully', () => {
|
||||
// @ts-expect-error - testing invalid runtime input
|
||||
expect(resolveModel(['a', 'b'])).toBe('b');
|
||||
// @ts-expect-error - testing invalid runtime input
|
||||
expect(resolveModel(true)).toBe('true');
|
||||
// @ts-expect-error - testing invalid runtime input
|
||||
expect(resolveModel(null)).toBe('');
|
||||
});
|
||||
});
|
||||
|
||||
describe('hasAccessToPreview logic', () => {
|
||||
|
||||
@@ -109,8 +109,15 @@ export function resolveModel(
|
||||
hasAccessToPreview: boolean = true,
|
||||
config?: ModelCapabilityContext,
|
||||
): string {
|
||||
// Defensive check against non-string inputs at runtime
|
||||
const normalizedModel = Array.isArray(requestedModel)
|
||||
? String(requestedModel.at(-1) ?? '').trim() || ''
|
||||
: typeof requestedModel !== 'string'
|
||||
? String(requestedModel ?? '').trim() || ''
|
||||
: requestedModel.trim() || '';
|
||||
|
||||
if (config?.getExperimentalDynamicModelConfiguration?.() === true) {
|
||||
const resolved = config.modelConfigService.resolveModelId(requestedModel, {
|
||||
const resolved = config.modelConfigService.resolveModelId(normalizedModel, {
|
||||
useGemini3_1,
|
||||
useGemini3_1FlashLite,
|
||||
useCustomTools: useCustomToolModel,
|
||||
@@ -132,7 +139,7 @@ export function resolveModel(
|
||||
}
|
||||
|
||||
let resolved: string;
|
||||
switch (requestedModel) {
|
||||
switch (normalizedModel) {
|
||||
case PREVIEW_GEMINI_MODEL:
|
||||
case PREVIEW_GEMINI_MODEL_AUTO:
|
||||
case GEMINI_MODEL_ALIAS_AUTO:
|
||||
@@ -161,7 +168,7 @@ export function resolveModel(
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
resolved = requestedModel;
|
||||
resolved = normalizedModel;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user