Make config non optional in ToolConfirmationMessage (#7083)

This commit is contained in:
shrutip90
2025-08-26 10:02:22 -07:00
committed by GitHub
parent 52dae2c583
commit 4e49ee4c73
5 changed files with 17 additions and 7 deletions

View File

@@ -10,6 +10,7 @@ import { HistoryItemDisplay } from './HistoryItemDisplay.js';
import type { HistoryItem } from '../types.js'; import type { HistoryItem } from '../types.js';
import { MessageType } from '../types.js'; import { MessageType } from '../types.js';
import { SessionStatsProvider } from '../contexts/SessionContext.js'; import { SessionStatsProvider } from '../contexts/SessionContext.js';
import type { Config } from '@google/gemini-cli-core';
// Mock child components // Mock child components
vi.mock('./messages/ToolGroupMessage.js', () => ({ vi.mock('./messages/ToolGroupMessage.js', () => ({
@@ -17,11 +18,13 @@ vi.mock('./messages/ToolGroupMessage.js', () => ({
})); }));
describe('<HistoryItemDisplay />', () => { describe('<HistoryItemDisplay />', () => {
const mockConfig = {} as unknown as Config;
const baseItem = { const baseItem = {
id: 1, id: 1,
timestamp: 12345, timestamp: 12345,
isPending: false, isPending: false,
terminalWidth: 80, terminalWidth: 80,
config: mockConfig,
}; };
it('renders UserMessage for "user" type', () => { it('renders UserMessage for "user" type', () => {

View File

@@ -29,7 +29,7 @@ interface HistoryItemDisplayProps {
availableTerminalHeight?: number; availableTerminalHeight?: number;
terminalWidth: number; terminalWidth: number;
isPending: boolean; isPending: boolean;
config?: Config; config: Config;
isFocused?: boolean; isFocused?: boolean;
commands?: readonly SlashCommand[]; commands?: readonly SlashCommand[];
} }

View File

@@ -13,6 +13,11 @@ import type {
import { renderWithProviders } from '../../../test-utils/render.js'; import { renderWithProviders } from '../../../test-utils/render.js';
describe('ToolConfirmationMessage', () => { describe('ToolConfirmationMessage', () => {
const mockConfig = {
isTrustedFolder: () => true,
getIdeMode: () => false,
} as unknown as Config;
it('should not display urls if prompt and url are the same', () => { it('should not display urls if prompt and url are the same', () => {
const confirmationDetails: ToolCallConfirmationDetails = { const confirmationDetails: ToolCallConfirmationDetails = {
type: 'info', type: 'info',
@@ -25,6 +30,7 @@ describe('ToolConfirmationMessage', () => {
const { lastFrame } = renderWithProviders( const { lastFrame } = renderWithProviders(
<ToolConfirmationMessage <ToolConfirmationMessage
confirmationDetails={confirmationDetails} confirmationDetails={confirmationDetails}
config={mockConfig}
availableTerminalHeight={30} availableTerminalHeight={30}
terminalWidth={80} terminalWidth={80}
/>, />,
@@ -48,6 +54,7 @@ describe('ToolConfirmationMessage', () => {
const { lastFrame } = renderWithProviders( const { lastFrame } = renderWithProviders(
<ToolConfirmationMessage <ToolConfirmationMessage
confirmationDetails={confirmationDetails} confirmationDetails={confirmationDetails}
config={mockConfig}
availableTerminalHeight={30} availableTerminalHeight={30}
terminalWidth={80} terminalWidth={80}
/>, />,

View File

@@ -23,7 +23,7 @@ import { useKeypress } from '../../hooks/useKeypress.js';
export interface ToolConfirmationMessageProps { export interface ToolConfirmationMessageProps {
confirmationDetails: ToolCallConfirmationDetails; confirmationDetails: ToolCallConfirmationDetails;
config?: Config; config: Config;
isFocused?: boolean; isFocused?: boolean;
availableTerminalHeight?: number; availableTerminalHeight?: number;
terminalWidth: number; terminalWidth: number;
@@ -43,8 +43,8 @@ export const ToolConfirmationMessage: React.FC<
const handleConfirm = async (outcome: ToolConfirmationOutcome) => { const handleConfirm = async (outcome: ToolConfirmationOutcome) => {
if (confirmationDetails.type === 'edit') { if (confirmationDetails.type === 'edit') {
const ideClient = config?.getIdeClient(); const ideClient = config.getIdeClient();
if (config?.getIdeMode()) { if (config.getIdeMode()) {
const cliOutcome = const cliOutcome =
outcome === ToolConfirmationOutcome.Cancel ? 'rejected' : 'accepted'; outcome === ToolConfirmationOutcome.Cancel ? 'rejected' : 'accepted';
await ideClient?.resolveDiffFromCli( await ideClient?.resolveDiffFromCli(
@@ -56,7 +56,7 @@ export const ToolConfirmationMessage: React.FC<
onConfirm(outcome); onConfirm(outcome);
}; };
const isTrustedFolder = config?.isTrustedFolder() !== false; const isTrustedFolder = config.isTrustedFolder() !== false;
useKeypress( useKeypress(
(key) => { (key) => {
@@ -137,7 +137,7 @@ export const ToolConfirmationMessage: React.FC<
value: ToolConfirmationOutcome.ProceedAlways, value: ToolConfirmationOutcome.ProceedAlways,
}); });
} }
if (config?.getIdeMode()) { if (config.getIdeMode()) {
options.push({ options.push({
label: 'No (esc)', label: 'No (esc)',
value: ToolConfirmationOutcome.Cancel, value: ToolConfirmationOutcome.Cancel,

View File

@@ -20,7 +20,7 @@ interface ToolGroupMessageProps {
toolCalls: IndividualToolCallDisplay[]; toolCalls: IndividualToolCallDisplay[];
availableTerminalHeight?: number; availableTerminalHeight?: number;
terminalWidth: number; terminalWidth: number;
config?: Config; config: Config;
isFocused?: boolean; isFocused?: boolean;
} }