fix(cli): refactor test config loading and mock debugLogger in test-setup (#24389)

This commit is contained in:
matt korwel
2026-03-31 20:11:02 -07:00
committed by GitHub
parent 8ae5b56b5b
commit c9ed5e41b1
2 changed files with 27 additions and 9 deletions

View File

@@ -42,6 +42,7 @@ import {
type OverflowState,
} from '../ui/contexts/OverflowContext.js';
import { makeFakeConfig } from '@google/gemini-cli-core';
import { type Config } from '@google/gemini-cli-core';
import { FakePersistentState } from './persistentStateFake.js';
import { AppContext, type AppState } from '../ui/contexts/AppContext.js';
@@ -51,7 +52,6 @@ import { themeManager, DEFAULT_THEME } from '../ui/themes/theme-manager.js';
import { DefaultLight } from '../ui/themes/builtin/light/default-light.js';
import { pickDefaultThemeName } from '../ui/themes/theme.js';
import { generateSvgForTerminal } from './svg.js';
import { loadCliConfig, type CliArgs } from '../config/config.js';
export const persistentStateMock = new FakePersistentState();
@@ -666,12 +666,11 @@ export const renderWithProviders = async (
const terminalWidth = width ?? baseState.terminalWidth;
if (!config) {
config = await loadCliConfig(
settings.merged,
'random-session-id',
{} as unknown as CliArgs,
{ cwd: '/' },
);
config = makeFakeConfig({
useAlternateBuffer: settings.merged.ui?.useAlternateBuffer,
showMemoryUsage: settings.merged.ui?.showMemoryUsage,
accessibility: settings.merged.ui?.accessibility,
});
}
const mainAreaWidth = providedUiState?.mainAreaWidth ?? terminalWidth;

View File

@@ -6,7 +6,7 @@
import { vi, beforeEach, afterEach } from 'vitest';
import { format } from 'node:util';
import { coreEvents } from '@google/gemini-cli-core';
import { coreEvents, debugLogger } from '@google/gemini-cli-core';
import { themeManager } from './src/ui/themes/theme-manager.js';
import { mockInkSpinner } from './src/test-utils/mockSpinner.js';
@@ -42,10 +42,25 @@ import './src/test-utils/customMatchers.js';
let consoleErrorSpy: vi.SpyInstance;
let actWarnings: Array<{ message: string; stack: string }> = [];
let logSpy: vi.SpyInstance;
let warnSpy: vi.SpyInstance;
let errorSpy: vi.SpyInstance;
let debugSpy: vi.SpyInstance;
beforeEach(() => {
// Reset themeManager state to ensure test isolation
themeManager.resetForTesting();
// Mock debugLogger to avoid test output noise
logSpy = vi.spyOn(debugLogger, 'log').mockImplementation(() => {});
warnSpy = vi.spyOn(debugLogger, 'warn').mockImplementation((...args) => {
console.warn(...args);
});
errorSpy = vi.spyOn(debugLogger, 'error').mockImplementation((...args) => {
console.error(...args);
});
debugSpy = vi.spyOn(debugLogger, 'debug').mockImplementation(() => {});
actWarnings = [];
consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation((...args) => {
const firstArg = args[0];
@@ -88,8 +103,12 @@ beforeEach(() => {
afterEach(() => {
consoleErrorSpy.mockRestore();
vi.unstubAllEnvs();
logSpy?.mockRestore();
warnSpy?.mockRestore();
errorSpy?.mockRestore();
debugSpy?.mockRestore();
vi.unstubAllEnvs();
if (actWarnings.length > 0) {
const messages = actWarnings
.map(({ message, stack }) => `${message}\n${stack}`)