Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/cli/src/ui/AppContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ Logging in with Google... Please restart Gemini CLI to continue.
const [showIdeRestartPrompt, setShowIdeRestartPrompt] = useState(false);

const { isFolderTrustDialogOpen, handleFolderTrustSelect, isRestarting } =
useFolderTrust(settings, config, setIsTrustedFolder);
useFolderTrust(settings, config, setIsTrustedFolder, refreshStatic);
const { needsRestart: ideNeedsRestart } = useIdeTrustListener();
const isInitialMount = useRef(true);

Expand Down
11 changes: 7 additions & 4 deletions packages/cli/src/ui/components/AppHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@ interface AppHeaderProps {
export const AppHeader = ({ version }: AppHeaderProps) => {
const settings = useSettings();
const config = useConfig();
const { nightly } = useUIState();
const { nightly, isFolderTrustDialogOpen } = useUIState();
const showTips =
!isFolderTrustDialogOpen &&
!settings.merged.ui?.hideTips &&
!config.getScreenReader();

return (
<Box flexDirection="column">
{!(settings.merged.ui?.hideBanner || config.getScreenReader()) && (
<Header version={version} nightly={nightly} />
)}
{!(settings.merged.ui?.hideTips || config.getScreenReader()) && (
<Tips config={config} />
)}
{showTips && <Tips config={config} />}
</Box>
);
};
49 changes: 38 additions & 11 deletions packages/cli/src/ui/hooks/useFolderTrust.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@ describe('useFolderTrust', () => {
let loadTrustedFoldersSpy: vi.SpyInstance;
let isWorkspaceTrustedSpy: vi.SpyInstance;
let onTrustChange: (isTrusted: boolean | undefined) => void;
let refreshStatic: () => void;

beforeEach(() => {
mockSettings = {
merged: {
folderTrustFeature: true,
folderTrust: undefined,
security: {
folderTrust: {
enabled: true,
},
},
},
setValue: vi.fn(),
} as unknown as LoadedSettings;
Expand All @@ -49,6 +53,7 @@ describe('useFolderTrust', () => {
isWorkspaceTrustedSpy = vi.spyOn(trustedFolders, 'isWorkspaceTrusted');
(process.cwd as vi.Mock).mockReturnValue('/test/path');
onTrustChange = vi.fn();
refreshStatic = vi.fn();
});

afterEach(() => {
Expand All @@ -58,7 +63,7 @@ describe('useFolderTrust', () => {
it('should not open dialog when folder is already trusted', () => {
isWorkspaceTrustedSpy.mockReturnValue(true);
const { result } = renderHook(() =>
useFolderTrust(mockSettings, mockConfig, onTrustChange),
useFolderTrust(mockSettings, mockConfig, onTrustChange, refreshStatic),
);
expect(result.current.isFolderTrustDialogOpen).toBe(false);
expect(onTrustChange).toHaveBeenCalledWith(true);
Expand All @@ -67,7 +72,7 @@ describe('useFolderTrust', () => {
it('should not open dialog when folder is already untrusted', () => {
isWorkspaceTrustedSpy.mockReturnValue(false);
const { result } = renderHook(() =>
useFolderTrust(mockSettings, mockConfig, onTrustChange),
useFolderTrust(mockSettings, mockConfig, onTrustChange, refreshStatic),
);
expect(result.current.isFolderTrustDialogOpen).toBe(false);
expect(onTrustChange).toHaveBeenCalledWith(false);
Expand All @@ -76,7 +81,7 @@ describe('useFolderTrust', () => {
it('should open dialog when folder trust is undefined', () => {
isWorkspaceTrustedSpy.mockReturnValue(undefined);
const { result } = renderHook(() =>
useFolderTrust(mockSettings, mockConfig, onTrustChange),
useFolderTrust(mockSettings, mockConfig, onTrustChange, refreshStatic),
);
expect(result.current.isFolderTrustDialogOpen).toBe(true);
expect(onTrustChange).toHaveBeenCalledWith(undefined);
Expand All @@ -87,7 +92,7 @@ describe('useFolderTrust', () => {
.mockReturnValueOnce(undefined)
.mockReturnValueOnce(true);
const { result } = renderHook(() =>
useFolderTrust(mockSettings, mockConfig, onTrustChange),
useFolderTrust(mockSettings, mockConfig, onTrustChange, refreshStatic),
);

isWorkspaceTrustedSpy.mockReturnValue(true);
Expand All @@ -109,7 +114,7 @@ describe('useFolderTrust', () => {
.mockReturnValueOnce(undefined)
.mockReturnValueOnce(true);
const { result } = renderHook(() =>
useFolderTrust(mockSettings, mockConfig, onTrustChange),
useFolderTrust(mockSettings, mockConfig, onTrustChange, refreshStatic),
);

act(() => {
Expand All @@ -129,7 +134,7 @@ describe('useFolderTrust', () => {
.mockReturnValueOnce(undefined)
.mockReturnValueOnce(false);
const { result } = renderHook(() =>
useFolderTrust(mockSettings, mockConfig, onTrustChange),
useFolderTrust(mockSettings, mockConfig, onTrustChange, refreshStatic),
);

act(() => {
Expand All @@ -148,7 +153,7 @@ describe('useFolderTrust', () => {
it('should do nothing for default choice', () => {
isWorkspaceTrustedSpy.mockReturnValue(undefined);
const { result } = renderHook(() =>
useFolderTrust(mockSettings, mockConfig, onTrustChange),
useFolderTrust(mockSettings, mockConfig, onTrustChange, refreshStatic),
);

act(() => {
Expand All @@ -166,7 +171,7 @@ describe('useFolderTrust', () => {
it('should set isRestarting to true when trust status changes from false to true', () => {
isWorkspaceTrustedSpy.mockReturnValueOnce(false).mockReturnValueOnce(true); // Initially untrusted, then trusted
const { result } = renderHook(() =>
useFolderTrust(mockSettings, mockConfig, onTrustChange),
useFolderTrust(mockSettings, mockConfig, onTrustChange, refreshStatic),
);

act(() => {
Expand All @@ -182,7 +187,7 @@ describe('useFolderTrust', () => {
.mockReturnValueOnce(undefined)
.mockReturnValueOnce(true); // Initially undefined, then trust
const { result } = renderHook(() =>
useFolderTrust(mockSettings, mockConfig, onTrustChange),
useFolderTrust(mockSettings, mockConfig, onTrustChange, refreshStatic),
);

act(() => {
Expand All @@ -192,4 +197,26 @@ describe('useFolderTrust', () => {
expect(result.current.isRestarting).toBe(false);
expect(result.current.isFolderTrustDialogOpen).toBe(false); // Dialog should close
});

it('should call refreshStatic when dialog opens and closes', () => {
isWorkspaceTrustedSpy.mockReturnValue(undefined);
const { result } = renderHook(() =>
useFolderTrust(mockSettings, mockConfig, onTrustChange, refreshStatic),
);

// The hook runs, isFolderTrustDialogOpen becomes true, useEffect triggers.
// It's called once on mount, and once when the dialog state changes.
expect(refreshStatic).toHaveBeenCalledTimes(2);
expect(result.current.isFolderTrustDialogOpen).toBe(true);

// Now, simulate closing the dialog
isWorkspaceTrustedSpy.mockReturnValue(true); // So the state update works
act(() => {
result.current.handleFolderTrustSelect(FolderTrustChoice.TRUST_FOLDER);
});

// The state isFolderTrustDialogOpen becomes false, useEffect triggers again
expect(refreshStatic).toHaveBeenCalledTimes(3);
expect(result.current.isFolderTrustDialogOpen).toBe(false);
});
});
7 changes: 7 additions & 0 deletions packages/cli/src/ui/hooks/useFolderTrust.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const useFolderTrust = (
settings: LoadedSettings,
config: Config,
onTrustChange: (isTrusted: boolean | undefined) => void,
refreshStatic: () => void,
) => {
const [isTrusted, setIsTrusted] = useState<boolean | undefined>(undefined);
const [isFolderTrustDialogOpen, setIsFolderTrustDialogOpen] = useState(false);
Expand All @@ -33,6 +34,12 @@ export const useFolderTrust = (
onTrustChange(trusted);
}, [folderTrust, onTrustChange, settings.merged]);

useEffect(() => {
// When the folder trust dialog is about to open/close, we need to force a refresh
// of the static content to ensure the Tips are hidden/shown correctly.
refreshStatic();
}, [isFolderTrustDialogOpen, refreshStatic]);

const handleFolderTrustSelect = useCallback(
(choice: FolderTrustChoice) => {
const trustedFolders = loadTrustedFolders();
Expand Down
Loading