Add ModelChain support to ModelConfigService and make ModelDialog dynamic (#22914)

This commit is contained in:
kevinjwang1
2026-03-19 15:22:26 -07:00
committed by GitHub
parent 0e66f545ca
commit 06a7873c51
11 changed files with 1014 additions and 18 deletions
@@ -19,6 +19,8 @@ import {
PREVIEW_GEMINI_3_1_MODEL,
} from '../config/models.js';
import { AuthType } from '../core/contentGenerator.js';
import { ModelConfigService } from '../services/modelConfigService.js';
import { DEFAULT_MODEL_CONFIGS } from '../config/defaultModelConfigs.js';
const createMockConfig = (overrides: Partial<Config> = {}): Config => {
const config = {
@@ -163,6 +165,66 @@ describe('policyHelpers', () => {
});
});
describe('resolvePolicyChain behavior is identical between dynamic and legacy implementations', () => {
const testCases = [
{ name: 'Default Auto', model: DEFAULT_GEMINI_MODEL_AUTO },
{ name: 'Gemini 3 Auto', model: 'auto-gemini-3' },
{ name: 'Flash Lite', model: DEFAULT_GEMINI_FLASH_LITE_MODEL },
{
name: 'Gemini 3 Auto (3.1 Enabled)',
model: 'auto-gemini-3',
useGemini31: true,
},
{
name: 'Gemini 3 Auto (3.1 + Custom Tools)',
model: 'auto-gemini-3',
useGemini31: true,
authType: AuthType.USE_GEMINI,
},
{
name: 'Gemini 3 Auto (No Access)',
model: 'auto-gemini-3',
hasAccess: false,
},
{ name: 'Concrete Model (2.5 Pro)', model: 'gemini-2.5-pro' },
{ name: 'Custom Model', model: 'my-custom-model' },
{
name: 'Wrap Around',
model: DEFAULT_GEMINI_MODEL_AUTO,
wrapsAround: true,
},
];
testCases.forEach(
({ name, model, useGemini31, hasAccess, authType, wrapsAround }) => {
it(`achieves parity for: ${name}`, () => {
const createBaseConfig = (dynamic: boolean) =>
createMockConfig({
getExperimentalDynamicModelConfiguration: () => dynamic,
getModel: () => model,
getGemini31LaunchedSync: () => useGemini31 ?? false,
getHasAccessToPreviewModel: () => hasAccess ?? true,
getContentGeneratorConfig: () => ({ authType }),
modelConfigService: new ModelConfigService(DEFAULT_MODEL_CONFIGS),
});
const legacyChain = resolvePolicyChain(
createBaseConfig(false),
model,
wrapsAround,
);
const dynamicChain = resolvePolicyChain(
createBaseConfig(true),
model,
wrapsAround,
);
expect(dynamicChain).toEqual(legacyChain);
});
},
);
});
describe('buildFallbackPolicyContext', () => {
it('returns remaining candidates after the failed model', () => {
const chain = [