mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-28 22:14:52 -07:00
fix: show parent name in trust folder confirmation (#7331)
Co-authored-by: Hriday Taneja <hridayt@google.com>
This commit is contained in:
@@ -8,19 +8,23 @@ import { renderWithProviders } from '../../test-utils/render.js';
|
|||||||
import { waitFor } from '@testing-library/react';
|
import { waitFor } from '@testing-library/react';
|
||||||
import { vi } from 'vitest';
|
import { vi } from 'vitest';
|
||||||
import { FolderTrustDialog, FolderTrustChoice } from './FolderTrustDialog.js';
|
import { FolderTrustDialog, FolderTrustChoice } from './FolderTrustDialog.js';
|
||||||
import * as process from 'node:process';
|
|
||||||
|
const mockedExit = vi.hoisted(() => vi.fn());
|
||||||
|
const mockedCwd = vi.hoisted(() => vi.fn());
|
||||||
|
|
||||||
vi.mock('process', async () => {
|
vi.mock('process', async () => {
|
||||||
const actual = await vi.importActual('process');
|
const actual = await vi.importActual('process');
|
||||||
return {
|
return {
|
||||||
...actual,
|
...actual,
|
||||||
exit: vi.fn(),
|
exit: mockedExit,
|
||||||
|
cwd: mockedCwd,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('FolderTrustDialog', () => {
|
describe('FolderTrustDialog', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.clearAllMocks();
|
vi.clearAllMocks();
|
||||||
|
mockedCwd.mockReturnValue('/home/user/project');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render the dialog with title and description', () => {
|
it('should render the dialog with title and description', () => {
|
||||||
@@ -78,7 +82,7 @@ describe('FolderTrustDialog', () => {
|
|||||||
stdin.write('r');
|
stdin.write('r');
|
||||||
|
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(process.exit).toHaveBeenCalledWith(0);
|
expect(mockedExit).toHaveBeenCalledWith(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -90,7 +94,25 @@ describe('FolderTrustDialog', () => {
|
|||||||
stdin.write('r');
|
stdin.write('r');
|
||||||
|
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(process.exit).not.toHaveBeenCalled();
|
expect(mockedExit).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('parentFolder display', () => {
|
||||||
|
it('should correctly display the parent folder name for a nested directory', () => {
|
||||||
|
mockedCwd.mockReturnValue('/home/user/project');
|
||||||
|
const { lastFrame } = renderWithProviders(
|
||||||
|
<FolderTrustDialog onSelect={vi.fn()} />,
|
||||||
|
);
|
||||||
|
expect(lastFrame()).toContain('Trust parent folder (user)');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should correctly display an empty parent folder name for a directory directly under root', () => {
|
||||||
|
mockedCwd.mockReturnValue('/project');
|
||||||
|
const { lastFrame } = renderWithProviders(
|
||||||
|
<FolderTrustDialog onSelect={vi.fn()} />,
|
||||||
|
);
|
||||||
|
expect(lastFrame()).toContain('Trust parent folder ()');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import type { RadioSelectItem } from './shared/RadioButtonSelect.js';
|
|||||||
import { RadioButtonSelect } from './shared/RadioButtonSelect.js';
|
import { RadioButtonSelect } from './shared/RadioButtonSelect.js';
|
||||||
import { useKeypress } from '../hooks/useKeypress.js';
|
import { useKeypress } from '../hooks/useKeypress.js';
|
||||||
import * as process from 'node:process';
|
import * as process from 'node:process';
|
||||||
|
import * as path from 'node:path';
|
||||||
|
|
||||||
export enum FolderTrustChoice {
|
export enum FolderTrustChoice {
|
||||||
TRUST_FOLDER = 'trust_folder',
|
TRUST_FOLDER = 'trust_folder',
|
||||||
@@ -45,13 +46,15 @@ export const FolderTrustDialog: React.FC<FolderTrustDialogProps> = ({
|
|||||||
{ isActive: !!isRestarting },
|
{ isActive: !!isRestarting },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const parentFolder = path.basename(path.dirname(process.cwd()));
|
||||||
|
|
||||||
const options: Array<RadioSelectItem<FolderTrustChoice>> = [
|
const options: Array<RadioSelectItem<FolderTrustChoice>> = [
|
||||||
{
|
{
|
||||||
label: 'Trust folder',
|
label: 'Trust folder',
|
||||||
value: FolderTrustChoice.TRUST_FOLDER,
|
value: FolderTrustChoice.TRUST_FOLDER,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Trust parent folder',
|
label: `Trust parent folder (${parentFolder})`,
|
||||||
value: FolderTrustChoice.TRUST_PARENT,
|
value: FolderTrustChoice.TRUST_PARENT,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user