mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-27 21:44:25 -07:00
fix: Add a message about permissions command on startup in untrusted … (#10755)
This commit is contained in:
@@ -31,6 +31,7 @@ describe('useFolderTrust', () => {
|
||||
let loadTrustedFoldersSpy: vi.SpyInstance;
|
||||
let isWorkspaceTrustedSpy: vi.SpyInstance;
|
||||
let onTrustChange: (isTrusted: boolean | undefined) => void;
|
||||
let addItem: vi.Mock;
|
||||
|
||||
beforeEach(() => {
|
||||
mockSettings = {
|
||||
@@ -54,6 +55,7 @@ describe('useFolderTrust', () => {
|
||||
isWorkspaceTrustedSpy = vi.spyOn(trustedFolders, 'isWorkspaceTrusted');
|
||||
mockedCwd.mockReturnValue('/test/path');
|
||||
onTrustChange = vi.fn();
|
||||
addItem = vi.fn();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -63,7 +65,7 @@ describe('useFolderTrust', () => {
|
||||
it('should not open dialog when folder is already trusted', () => {
|
||||
isWorkspaceTrustedSpy.mockReturnValue({ isTrusted: true, source: 'file' });
|
||||
const { result } = renderHook(() =>
|
||||
useFolderTrust(mockSettings, onTrustChange),
|
||||
useFolderTrust(mockSettings, onTrustChange, addItem),
|
||||
);
|
||||
expect(result.current.isFolderTrustDialogOpen).toBe(false);
|
||||
expect(onTrustChange).toHaveBeenCalledWith(true);
|
||||
@@ -72,7 +74,7 @@ describe('useFolderTrust', () => {
|
||||
it('should not open dialog when folder is already untrusted', () => {
|
||||
isWorkspaceTrustedSpy.mockReturnValue({ isTrusted: false, source: 'file' });
|
||||
const { result } = renderHook(() =>
|
||||
useFolderTrust(mockSettings, onTrustChange),
|
||||
useFolderTrust(mockSettings, onTrustChange, addItem),
|
||||
);
|
||||
expect(result.current.isFolderTrustDialogOpen).toBe(false);
|
||||
expect(onTrustChange).toHaveBeenCalledWith(false);
|
||||
@@ -84,19 +86,37 @@ describe('useFolderTrust', () => {
|
||||
source: undefined,
|
||||
});
|
||||
const { result } = renderHook(() =>
|
||||
useFolderTrust(mockSettings, onTrustChange),
|
||||
useFolderTrust(mockSettings, onTrustChange, addItem),
|
||||
);
|
||||
expect(result.current.isFolderTrustDialogOpen).toBe(true);
|
||||
expect(onTrustChange).toHaveBeenCalledWith(undefined);
|
||||
});
|
||||
|
||||
it('should send a message if the folder is untrusted', () => {
|
||||
isWorkspaceTrustedSpy.mockReturnValue({ isTrusted: false, source: 'file' });
|
||||
renderHook(() => useFolderTrust(mockSettings, onTrustChange, addItem));
|
||||
expect(addItem).toHaveBeenCalledWith(
|
||||
{
|
||||
text: 'This folder is not trusted. Some features may be disabled. Use the `/permissions` command to change the trust level.',
|
||||
type: 'info',
|
||||
},
|
||||
expect.any(Number),
|
||||
);
|
||||
});
|
||||
|
||||
it('should not send a message if the folder is trusted', () => {
|
||||
isWorkspaceTrustedSpy.mockReturnValue({ isTrusted: true, source: 'file' });
|
||||
renderHook(() => useFolderTrust(mockSettings, onTrustChange, addItem));
|
||||
expect(addItem).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should handle TRUST_FOLDER choice', () => {
|
||||
isWorkspaceTrustedSpy.mockReturnValue({
|
||||
isTrusted: undefined,
|
||||
source: undefined,
|
||||
});
|
||||
const { result } = renderHook(() =>
|
||||
useFolderTrust(mockSettings, onTrustChange),
|
||||
useFolderTrust(mockSettings, onTrustChange, addItem),
|
||||
);
|
||||
|
||||
act(() => {
|
||||
@@ -118,7 +138,7 @@ describe('useFolderTrust', () => {
|
||||
source: undefined,
|
||||
});
|
||||
const { result } = renderHook(() =>
|
||||
useFolderTrust(mockSettings, onTrustChange),
|
||||
useFolderTrust(mockSettings, onTrustChange, addItem),
|
||||
);
|
||||
|
||||
act(() => {
|
||||
@@ -139,7 +159,7 @@ describe('useFolderTrust', () => {
|
||||
source: undefined,
|
||||
});
|
||||
const { result } = renderHook(() =>
|
||||
useFolderTrust(mockSettings, onTrustChange),
|
||||
useFolderTrust(mockSettings, onTrustChange, addItem),
|
||||
);
|
||||
|
||||
act(() => {
|
||||
@@ -161,7 +181,7 @@ describe('useFolderTrust', () => {
|
||||
source: undefined,
|
||||
});
|
||||
const { result } = renderHook(() =>
|
||||
useFolderTrust(mockSettings, onTrustChange),
|
||||
useFolderTrust(mockSettings, onTrustChange, addItem),
|
||||
);
|
||||
|
||||
act(() => {
|
||||
@@ -179,7 +199,7 @@ describe('useFolderTrust', () => {
|
||||
it('should set isRestarting to true when trust status changes from false to true', () => {
|
||||
isWorkspaceTrustedSpy.mockReturnValue({ isTrusted: false, source: 'file' }); // Initially untrusted
|
||||
const { result } = renderHook(() =>
|
||||
useFolderTrust(mockSettings, onTrustChange),
|
||||
useFolderTrust(mockSettings, onTrustChange, addItem),
|
||||
);
|
||||
|
||||
act(() => {
|
||||
@@ -196,7 +216,7 @@ describe('useFolderTrust', () => {
|
||||
source: undefined,
|
||||
});
|
||||
const { result } = renderHook(() =>
|
||||
useFolderTrust(mockSettings, onTrustChange),
|
||||
useFolderTrust(mockSettings, onTrustChange, addItem),
|
||||
);
|
||||
|
||||
act(() => {
|
||||
|
||||
Reference in New Issue
Block a user