mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-21 01:07:46 +00:00
Force restart on trust level change to reload settings (#6713)
This commit is contained in:
@@ -82,7 +82,9 @@ describe('useFolderTrust', () => {
|
||||
});
|
||||
|
||||
it('should handle TRUST_FOLDER choice', () => {
|
||||
isWorkspaceTrustedSpy.mockReturnValue(undefined);
|
||||
isWorkspaceTrustedSpy
|
||||
.mockReturnValueOnce(undefined)
|
||||
.mockReturnValueOnce(true);
|
||||
const { result } = renderHook(() =>
|
||||
useFolderTrust(mockSettings, onTrustChange),
|
||||
);
|
||||
@@ -102,12 +104,13 @@ describe('useFolderTrust', () => {
|
||||
});
|
||||
|
||||
it('should handle TRUST_PARENT choice', () => {
|
||||
isWorkspaceTrustedSpy.mockReturnValue(undefined);
|
||||
isWorkspaceTrustedSpy
|
||||
.mockReturnValueOnce(undefined)
|
||||
.mockReturnValueOnce(true);
|
||||
const { result } = renderHook(() =>
|
||||
useFolderTrust(mockSettings, onTrustChange),
|
||||
);
|
||||
|
||||
isWorkspaceTrustedSpy.mockReturnValue(true);
|
||||
act(() => {
|
||||
result.current.handleFolderTrustSelect(FolderTrustChoice.TRUST_PARENT);
|
||||
});
|
||||
@@ -120,13 +123,14 @@ describe('useFolderTrust', () => {
|
||||
expect(onTrustChange).toHaveBeenLastCalledWith(true);
|
||||
});
|
||||
|
||||
it('should handle DO_NOT_TRUST choice', () => {
|
||||
isWorkspaceTrustedSpy.mockReturnValue(undefined);
|
||||
it('should handle DO_NOT_TRUST choice and trigger restart', () => {
|
||||
isWorkspaceTrustedSpy
|
||||
.mockReturnValueOnce(undefined)
|
||||
.mockReturnValueOnce(false);
|
||||
const { result } = renderHook(() =>
|
||||
useFolderTrust(mockSettings, onTrustChange),
|
||||
);
|
||||
|
||||
isWorkspaceTrustedSpy.mockReturnValue(false);
|
||||
act(() => {
|
||||
result.current.handleFolderTrustSelect(FolderTrustChoice.DO_NOT_TRUST);
|
||||
});
|
||||
@@ -135,8 +139,9 @@ describe('useFolderTrust', () => {
|
||||
'/test/path',
|
||||
TrustLevel.DO_NOT_TRUST,
|
||||
);
|
||||
expect(result.current.isFolderTrustDialogOpen).toBe(false);
|
||||
expect(onTrustChange).toHaveBeenLastCalledWith(false);
|
||||
expect(result.current.isRestarting).toBe(true);
|
||||
expect(result.current.isFolderTrustDialogOpen).toBe(true);
|
||||
});
|
||||
|
||||
it('should do nothing for default choice', () => {
|
||||
@@ -156,4 +161,34 @@ describe('useFolderTrust', () => {
|
||||
expect(result.current.isFolderTrustDialogOpen).toBe(true);
|
||||
expect(onTrustChange).toHaveBeenCalledWith(undefined);
|
||||
});
|
||||
|
||||
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, onTrustChange),
|
||||
);
|
||||
|
||||
act(() => {
|
||||
result.current.handleFolderTrustSelect(FolderTrustChoice.TRUST_FOLDER);
|
||||
});
|
||||
|
||||
expect(result.current.isRestarting).toBe(true);
|
||||
expect(result.current.isFolderTrustDialogOpen).toBe(true); // Dialog should stay open
|
||||
});
|
||||
|
||||
it('should not set isRestarting to true when trust status does not change', () => {
|
||||
isWorkspaceTrustedSpy
|
||||
.mockReturnValueOnce(undefined)
|
||||
.mockReturnValueOnce(true); // Initially undefined, then trust
|
||||
const { result } = renderHook(() =>
|
||||
useFolderTrust(mockSettings, onTrustChange),
|
||||
);
|
||||
|
||||
act(() => {
|
||||
result.current.handleFolderTrustSelect(FolderTrustChoice.TRUST_FOLDER);
|
||||
});
|
||||
|
||||
expect(result.current.isRestarting).toBe(false);
|
||||
expect(result.current.isFolderTrustDialogOpen).toBe(false); // Dialog should close
|
||||
});
|
||||
});
|
||||
|
||||
@@ -20,6 +20,7 @@ export const useFolderTrust = (
|
||||
) => {
|
||||
const [isTrusted, setIsTrusted] = useState<boolean | undefined>(undefined);
|
||||
const [isFolderTrustDialogOpen, setIsFolderTrustDialogOpen] = useState(false);
|
||||
const [isRestarting, setIsRestarting] = useState(false);
|
||||
|
||||
const { folderTrust, folderTrustFeature } = settings.merged;
|
||||
useEffect(() => {
|
||||
@@ -38,6 +39,8 @@ export const useFolderTrust = (
|
||||
const cwd = process.cwd();
|
||||
let trustLevel: TrustLevel;
|
||||
|
||||
const wasTrusted = isTrusted ?? true;
|
||||
|
||||
switch (choice) {
|
||||
case FolderTrustChoice.TRUST_FOLDER:
|
||||
trustLevel = TrustLevel.TRUST_FOLDER;
|
||||
@@ -53,20 +56,27 @@ export const useFolderTrust = (
|
||||
}
|
||||
|
||||
trustedFolders.setValue(cwd, trustLevel);
|
||||
const trusted = isWorkspaceTrusted({
|
||||
folderTrust,
|
||||
folderTrustFeature,
|
||||
} as Settings);
|
||||
setIsTrusted(trusted);
|
||||
setIsFolderTrustDialogOpen(false);
|
||||
onTrustChange(trusted);
|
||||
const newIsTrusted =
|
||||
trustLevel === TrustLevel.TRUST_FOLDER ||
|
||||
trustLevel === TrustLevel.TRUST_PARENT;
|
||||
setIsTrusted(newIsTrusted);
|
||||
onTrustChange(newIsTrusted);
|
||||
|
||||
const needsRestart = wasTrusted !== newIsTrusted;
|
||||
if (needsRestart) {
|
||||
setIsRestarting(true);
|
||||
setIsFolderTrustDialogOpen(true);
|
||||
} else {
|
||||
setIsFolderTrustDialogOpen(false);
|
||||
}
|
||||
},
|
||||
[onTrustChange, folderTrust, folderTrustFeature],
|
||||
[onTrustChange, isTrusted],
|
||||
);
|
||||
|
||||
return {
|
||||
isTrusted,
|
||||
isFolderTrustDialogOpen,
|
||||
handleFolderTrustSelect,
|
||||
isRestarting,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user