2025-06-24 18:48:55 -04:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
2025-07-31 05:38:20 +09:00
|
|
|
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
2025-06-24 18:48:55 -04:00
|
|
|
import { Config } from './config.js';
|
|
|
|
|
import { DEFAULT_GEMINI_MODEL, DEFAULT_GEMINI_FLASH_MODEL } from './models.js';
|
2026-01-02 13:19:43 -05:00
|
|
|
import { logFlashFallback } from '../telemetry/loggers.js';
|
|
|
|
|
import { FlashFallbackEvent } from '../telemetry/types.js';
|
2025-08-05 18:52:58 -04:00
|
|
|
|
2025-07-31 05:38:20 +09:00
|
|
|
import fs from 'node:fs';
|
|
|
|
|
|
|
|
|
|
vi.mock('node:fs');
|
2026-01-02 13:19:43 -05:00
|
|
|
vi.mock('../telemetry/loggers.js', () => ({
|
|
|
|
|
logFlashFallback: vi.fn(),
|
|
|
|
|
logRipgrepFallback: vi.fn(),
|
|
|
|
|
}));
|
2025-06-24 18:48:55 -04:00
|
|
|
|
|
|
|
|
describe('Flash Model Fallback Configuration', () => {
|
|
|
|
|
let config: Config;
|
|
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2025-07-31 05:38:20 +09:00
|
|
|
vi.mocked(fs.existsSync).mockReturnValue(true);
|
|
|
|
|
vi.mocked(fs.statSync).mockReturnValue({
|
|
|
|
|
isDirectory: () => true,
|
|
|
|
|
} as fs.Stats);
|
2025-06-24 18:48:55 -04:00
|
|
|
config = new Config({
|
|
|
|
|
sessionId: 'test-session',
|
|
|
|
|
targetDir: '/test',
|
|
|
|
|
debugMode: false,
|
|
|
|
|
cwd: '/test',
|
|
|
|
|
model: DEFAULT_GEMINI_MODEL,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Initialize contentGeneratorConfig for testing
|
|
|
|
|
(
|
|
|
|
|
config as unknown as { contentGeneratorConfig: unknown }
|
|
|
|
|
).contentGeneratorConfig = {
|
|
|
|
|
model: DEFAULT_GEMINI_MODEL,
|
|
|
|
|
authType: 'oauth-personal',
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('getModel', () => {
|
|
|
|
|
it('should return contentGeneratorConfig model if available', () => {
|
|
|
|
|
// Simulate initialized content generator config
|
|
|
|
|
config.setModel(DEFAULT_GEMINI_FLASH_MODEL);
|
|
|
|
|
expect(config.getModel()).toBe(DEFAULT_GEMINI_FLASH_MODEL);
|
|
|
|
|
});
|
|
|
|
|
|
2025-07-21 17:54:44 -04:00
|
|
|
it('should fall back to initial model if contentGeneratorConfig is not available', () => {
|
2025-06-24 18:48:55 -04:00
|
|
|
// Test with fresh config where contentGeneratorConfig might not be set
|
|
|
|
|
const newConfig = new Config({
|
|
|
|
|
sessionId: 'test-session-2',
|
|
|
|
|
targetDir: '/test',
|
|
|
|
|
debugMode: false,
|
|
|
|
|
cwd: '/test',
|
|
|
|
|
model: 'custom-model',
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(newConfig.getModel()).toBe('custom-model');
|
|
|
|
|
});
|
|
|
|
|
});
|
2026-01-02 13:19:43 -05:00
|
|
|
|
|
|
|
|
describe('activateFallbackMode', () => {
|
2026-01-12 12:23:06 -05:00
|
|
|
it('should set model to fallback and log event', () => {
|
2026-01-02 13:19:43 -05:00
|
|
|
config.activateFallbackMode(DEFAULT_GEMINI_FLASH_MODEL);
|
2026-01-12 12:23:06 -05:00
|
|
|
expect(config.getModel()).toBe(DEFAULT_GEMINI_FLASH_MODEL);
|
2026-01-02 13:19:43 -05:00
|
|
|
expect(logFlashFallback).toHaveBeenCalledWith(
|
|
|
|
|
config,
|
|
|
|
|
expect.any(FlashFallbackEvent),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
});
|
2025-06-24 18:48:55 -04:00
|
|
|
});
|