Treat undefined same as true for isTrustedFolder (#7073)
This commit is contained in:
parent
b6cca01161
commit
97ce197f38
4 changed files with 39 additions and 5 deletions
|
|
@ -136,6 +136,24 @@ describe('ToolConfirmationMessage', () => {
|
||||||
expect(lastFrame()).toContain(alwaysAllowText);
|
expect(lastFrame()).toContain(alwaysAllowText);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should show "allow always" when folder trust is undefined', () => {
|
||||||
|
const mockConfig = {
|
||||||
|
isTrustedFolder: () => undefined,
|
||||||
|
getIdeMode: () => false,
|
||||||
|
} as unknown as Config;
|
||||||
|
|
||||||
|
const { lastFrame } = renderWithProviders(
|
||||||
|
<ToolConfirmationMessage
|
||||||
|
confirmationDetails={details}
|
||||||
|
config={mockConfig}
|
||||||
|
availableTerminalHeight={30}
|
||||||
|
terminalWidth={80}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(lastFrame()).toContain(alwaysAllowText);
|
||||||
|
});
|
||||||
|
|
||||||
it('should NOT show "allow always" when folder is untrusted', () => {
|
it('should NOT show "allow always" when folder is untrusted', () => {
|
||||||
const mockConfig = {
|
const mockConfig = {
|
||||||
isTrustedFolder: () => false,
|
isTrustedFolder: () => false,
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,8 @@ export const ToolConfirmationMessage: React.FC<
|
||||||
onConfirm(outcome);
|
onConfirm(outcome);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const isTrustedFolder = config?.isTrustedFolder() !== false;
|
||||||
|
|
||||||
useKeypress(
|
useKeypress(
|
||||||
(key) => {
|
(key) => {
|
||||||
if (!isFocused) return;
|
if (!isFocused) return;
|
||||||
|
|
@ -129,7 +131,7 @@ export const ToolConfirmationMessage: React.FC<
|
||||||
label: 'Yes, allow once',
|
label: 'Yes, allow once',
|
||||||
value: ToolConfirmationOutcome.ProceedOnce,
|
value: ToolConfirmationOutcome.ProceedOnce,
|
||||||
});
|
});
|
||||||
if (config?.isTrustedFolder()) {
|
if (isTrustedFolder) {
|
||||||
options.push({
|
options.push({
|
||||||
label: 'Yes, allow always',
|
label: 'Yes, allow always',
|
||||||
value: ToolConfirmationOutcome.ProceedAlways,
|
value: ToolConfirmationOutcome.ProceedAlways,
|
||||||
|
|
@ -168,7 +170,7 @@ export const ToolConfirmationMessage: React.FC<
|
||||||
label: 'Yes, allow once',
|
label: 'Yes, allow once',
|
||||||
value: ToolConfirmationOutcome.ProceedOnce,
|
value: ToolConfirmationOutcome.ProceedOnce,
|
||||||
});
|
});
|
||||||
if (config?.isTrustedFolder()) {
|
if (isTrustedFolder) {
|
||||||
options.push({
|
options.push({
|
||||||
label: `Yes, allow always ...`,
|
label: `Yes, allow always ...`,
|
||||||
value: ToolConfirmationOutcome.ProceedAlways,
|
value: ToolConfirmationOutcome.ProceedAlways,
|
||||||
|
|
@ -208,7 +210,7 @@ export const ToolConfirmationMessage: React.FC<
|
||||||
label: 'Yes, allow once',
|
label: 'Yes, allow once',
|
||||||
value: ToolConfirmationOutcome.ProceedOnce,
|
value: ToolConfirmationOutcome.ProceedOnce,
|
||||||
});
|
});
|
||||||
if (config?.isTrustedFolder()) {
|
if (isTrustedFolder) {
|
||||||
options.push({
|
options.push({
|
||||||
label: 'Yes, allow always',
|
label: 'Yes, allow always',
|
||||||
value: ToolConfirmationOutcome.ProceedAlways,
|
value: ToolConfirmationOutcome.ProceedAlways,
|
||||||
|
|
@ -253,7 +255,7 @@ export const ToolConfirmationMessage: React.FC<
|
||||||
label: 'Yes, allow once',
|
label: 'Yes, allow once',
|
||||||
value: ToolConfirmationOutcome.ProceedOnce,
|
value: ToolConfirmationOutcome.ProceedOnce,
|
||||||
});
|
});
|
||||||
if (config?.isTrustedFolder()) {
|
if (isTrustedFolder) {
|
||||||
options.push({
|
options.push({
|
||||||
label: `Yes, always allow tool "${mcpProps.toolName}" from server "${mcpProps.serverName}"`,
|
label: `Yes, always allow tool "${mcpProps.toolName}" from server "${mcpProps.serverName}"`,
|
||||||
value: ToolConfirmationOutcome.ProceedAlwaysTool, // Cast until types are updated
|
value: ToolConfirmationOutcome.ProceedAlwaysTool, // Cast until types are updated
|
||||||
|
|
|
||||||
|
|
@ -685,4 +685,18 @@ describe('setApprovalMode with folder trust', () => {
|
||||||
expect(() => config.setApprovalMode(ApprovalMode.AUTO_EDIT)).not.toThrow();
|
expect(() => config.setApprovalMode(ApprovalMode.AUTO_EDIT)).not.toThrow();
|
||||||
expect(() => config.setApprovalMode(ApprovalMode.DEFAULT)).not.toThrow();
|
expect(() => config.setApprovalMode(ApprovalMode.DEFAULT)).not.toThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should NOT throw an error when setting any mode if trustedFolder is undefined', () => {
|
||||||
|
const config = new Config({
|
||||||
|
sessionId: 'test',
|
||||||
|
targetDir: '.',
|
||||||
|
debugMode: false,
|
||||||
|
model: 'test-model',
|
||||||
|
cwd: '.',
|
||||||
|
trustedFolder: undefined, // Undefined
|
||||||
|
});
|
||||||
|
expect(() => config.setApprovalMode(ApprovalMode.YOLO)).not.toThrow();
|
||||||
|
expect(() => config.setApprovalMode(ApprovalMode.AUTO_EDIT)).not.toThrow();
|
||||||
|
expect(() => config.setApprovalMode(ApprovalMode.DEFAULT)).not.toThrow();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -564,7 +564,7 @@ export class Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
setApprovalMode(mode: ApprovalMode): void {
|
setApprovalMode(mode: ApprovalMode): void {
|
||||||
if (!this.isTrustedFolder() && mode !== ApprovalMode.DEFAULT) {
|
if (this.isTrustedFolder() === false && mode !== ApprovalMode.DEFAULT) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'Cannot enable privileged approval modes in an untrusted folder.',
|
'Cannot enable privileged approval modes in an untrusted folder.',
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue