mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-15 14:23:02 -07:00
fix(core): map ProceedAlways to ProceedOnce in Plan Mode to prevent exiting plan mode
This commit is contained in:
@@ -766,6 +766,33 @@ describe('policy.ts', () => {
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('should map ProceedAlways to ProceedOnce in Plan Mode', async () => {
|
||||
const mockConfig = {
|
||||
getApprovalMode: vi.fn().mockReturnValue(ApprovalMode.PLAN),
|
||||
setApprovalMode: vi.fn(),
|
||||
getSessionId: vi.fn().mockReturnValue('test-session-id'),
|
||||
} as unknown as Mocked<Config>;
|
||||
(mockConfig as unknown as { config: Config }).config =
|
||||
mockConfig as Config;
|
||||
const mockMessageBus = {
|
||||
publish: vi.fn(),
|
||||
} as unknown as Mocked<MessageBus>;
|
||||
(mockConfig as unknown as { messageBus: MessageBus }).messageBus =
|
||||
mockMessageBus;
|
||||
const tool = { name: 'replace' } as AnyDeclarativeTool;
|
||||
|
||||
await updatePolicy(
|
||||
tool,
|
||||
ToolConfirmationOutcome.ProceedAlways,
|
||||
undefined,
|
||||
mockConfig,
|
||||
mockMessageBus,
|
||||
);
|
||||
|
||||
expect(mockConfig.setApprovalMode).not.toHaveBeenCalled();
|
||||
expect(mockMessageBus.publish).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('getPolicyDenialError', () => {
|
||||
|
||||
@@ -119,6 +119,17 @@ export async function updatePolicy(
|
||||
messageBus: MessageBus,
|
||||
toolInvocation?: AnyToolInvocation,
|
||||
): Promise<void> {
|
||||
const currentMode = context.config.getApprovalMode();
|
||||
|
||||
// If in Plan Mode, map 'Proceed Always' (Allow for this session) to 'Proceed Once' (Allow once)
|
||||
// to prevent transitioning to AUTO_EDIT mode and updating policy.
|
||||
if (
|
||||
currentMode === ApprovalMode.PLAN &&
|
||||
outcome === ToolConfirmationOutcome.ProceedAlways
|
||||
) {
|
||||
outcome = ToolConfirmationOutcome.ProceedOnce;
|
||||
}
|
||||
|
||||
// Mode Transitions (AUTO_EDIT)
|
||||
if (isAutoEditTransition(tool, outcome)) {
|
||||
context.config.setApprovalMode(ApprovalMode.AUTO_EDIT);
|
||||
@@ -128,7 +139,6 @@ export async function updatePolicy(
|
||||
// Determine persist scope if we are persisting.
|
||||
let persistScope: 'workspace' | 'user' | undefined;
|
||||
let modes: ApprovalMode[] | undefined;
|
||||
const currentMode = context.config.getApprovalMode();
|
||||
|
||||
// If this is an 'Always Allow' selection, we restrict it to the current mode
|
||||
// and more permissive modes.
|
||||
|
||||
Reference in New Issue
Block a user