fix(cli): disableYoloMode shouldn't enforce default approval mode against args (#16155)

This commit is contained in:
Pyush Sinha
2026-01-08 11:48:03 -08:00
committed by GitHub
parent 1a4ae41397
commit f8138262fa
2 changed files with 39 additions and 1 deletions

View File

@@ -2413,6 +2413,45 @@ describe('Policy Engine Integration in loadCliConfig', () => {
});
});
describe('loadCliConfig disableYoloMode', () => {
beforeEach(() => {
vi.resetAllMocks();
vi.mocked(os.homedir).mockReturnValue('/mock/home/user');
vi.stubEnv('GEMINI_API_KEY', 'test-api-key');
vi.spyOn(ExtensionManager.prototype, 'getExtensions').mockReturnValue([]);
vi.mocked(isWorkspaceTrusted).mockReturnValue({
isTrusted: true,
source: undefined,
});
});
afterEach(() => {
vi.unstubAllEnvs();
vi.restoreAllMocks();
});
it('should allow auto_edit mode even if yolo mode is disabled', async () => {
process.argv = ['node', 'script.js', '--approval-mode=auto_edit'];
const argv = await parseArguments({} as Settings);
const settings: Settings = {
security: { disableYoloMode: true },
};
const config = await loadCliConfig(settings, 'test-session', argv);
expect(config.getApprovalMode()).toBe(ApprovalMode.AUTO_EDIT);
});
it('should throw if YOLO mode is attempted when disableYoloMode is true', async () => {
process.argv = ['node', 'script.js', '--yolo'];
const argv = await parseArguments({} as Settings);
const settings: Settings = {
security: { disableYoloMode: true },
};
await expect(loadCliConfig(settings, 'test-session', argv)).rejects.toThrow(
'Cannot start in YOLO mode since it is disabled by your admin',
);
});
});
describe('loadCliConfig secureModeEnabled', () => {
beforeEach(() => {
vi.resetAllMocks();

View File

@@ -520,7 +520,6 @@ export async function loadCliConfig(
'Cannot start in YOLO mode since it is disabled by your admin',
);
}
approvalMode = ApprovalMode.DEFAULT;
} else if (approvalMode === ApprovalMode.YOLO) {
debugLogger.warn(
'YOLO mode is enabled. All tool calls will be automatically approved.',