mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-15 16:41:11 -07:00
Disable tips after 10 runs (#17101)
This commit is contained in:
45
packages/cli/src/test-utils/persistentStateFake.ts
Normal file
45
packages/cli/src/test-utils/persistentStateFake.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2025 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { vi } from 'vitest';
|
||||
|
||||
/**
|
||||
* A fake implementation of PersistentState for testing.
|
||||
* It keeps state in memory and provides spies for get and set.
|
||||
*/
|
||||
export class FakePersistentState {
|
||||
private data: Record<string, unknown> = {};
|
||||
|
||||
get = vi.fn().mockImplementation((key: string) => this.data[key]);
|
||||
|
||||
set = vi.fn().mockImplementation((key: string, value: unknown) => {
|
||||
this.data[key] = value;
|
||||
});
|
||||
|
||||
/**
|
||||
* Helper to reset the fake state between tests.
|
||||
*/
|
||||
reset() {
|
||||
this.data = {};
|
||||
this.get.mockClear();
|
||||
this.set.mockClear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to clear mock call history without wiping data.
|
||||
*/
|
||||
mockClear() {
|
||||
this.get.mockClear();
|
||||
this.set.mockClear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to set initial data for the fake.
|
||||
*/
|
||||
setData(data: Record<string, unknown>) {
|
||||
this.data = { ...data };
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,13 @@ import { type HistoryItemToolGroup, StreamingState } from '../ui/types.js';
|
||||
import { ToolActionsProvider } from '../ui/contexts/ToolActionsContext.js';
|
||||
|
||||
import { type Config } from '@google/gemini-cli-core';
|
||||
import { FakePersistentState } from './persistentStateFake.js';
|
||||
|
||||
export const persistentStateMock = new FakePersistentState();
|
||||
|
||||
vi.mock('../utils/persistentState.js', () => ({
|
||||
persistentState: persistentStateMock,
|
||||
}));
|
||||
|
||||
// Wrapper around ink-testing-library's render that ensures act() is called
|
||||
export const render = (
|
||||
@@ -191,6 +198,7 @@ export const renderWithProviders = (
|
||||
config = configProxy as unknown as Config,
|
||||
useAlternateBuffer = true,
|
||||
uiActions,
|
||||
persistentState,
|
||||
}: {
|
||||
shellFocus?: boolean;
|
||||
settings?: LoadedSettings;
|
||||
@@ -200,6 +208,10 @@ export const renderWithProviders = (
|
||||
config?: Config;
|
||||
useAlternateBuffer?: boolean;
|
||||
uiActions?: Partial<UIActions>;
|
||||
persistentState?: {
|
||||
get?: typeof persistentStateMock.get;
|
||||
set?: typeof persistentStateMock.set;
|
||||
};
|
||||
} = {},
|
||||
): ReturnType<typeof render> & { simulateClick: typeof simulateClick } => {
|
||||
const baseState: UIState = new Proxy(
|
||||
@@ -220,6 +232,15 @@ export const renderWithProviders = (
|
||||
},
|
||||
) as UIState;
|
||||
|
||||
if (persistentState?.get) {
|
||||
persistentStateMock.get.mockImplementation(persistentState.get);
|
||||
}
|
||||
if (persistentState?.set) {
|
||||
persistentStateMock.set.mockImplementation(persistentState.set);
|
||||
}
|
||||
|
||||
persistentStateMock.mockClear();
|
||||
|
||||
const terminalWidth = width ?? baseState.terminalWidth;
|
||||
let finalSettings = settings;
|
||||
if (useAlternateBuffer !== undefined) {
|
||||
|
||||
Reference in New Issue
Block a user