mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-28 15:10:04 +00:00
fix(core): allow redirection in YOLO and AUTO_EDIT modes without sandboxing (#26542)
This commit is contained in:
@@ -1898,6 +1898,30 @@ describe('PolicyEngine', () => {
|
|||||||
expect(result.decision).toBe(PolicyDecision.ALLOW);
|
expect(result.decision).toBe(PolicyDecision.ALLOW);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should NOT downgrade to ASK_USER for redirected commands in YOLO mode even without sandbox', async () => {
|
||||||
|
const rules: PolicyRule[] = [
|
||||||
|
{
|
||||||
|
toolName: 'run_shell_command',
|
||||||
|
decision: PolicyDecision.ALLOW,
|
||||||
|
priority: 10,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
engine = new PolicyEngine({
|
||||||
|
rules,
|
||||||
|
approvalMode: ApprovalMode.YOLO,
|
||||||
|
sandboxManager: new NoopSandboxManager(),
|
||||||
|
});
|
||||||
|
|
||||||
|
const command = 'npm test 2>&1 | tail -80';
|
||||||
|
const { decision } = await engine.check(
|
||||||
|
{ name: 'run_shell_command', args: { command } },
|
||||||
|
undefined,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(decision).toBe(PolicyDecision.ALLOW);
|
||||||
|
});
|
||||||
|
|
||||||
it('should return ALLOW in YOLO mode even if shell command parsing fails', async () => {
|
it('should return ALLOW in YOLO mode even if shell command parsing fails', async () => {
|
||||||
const { splitCommands } = await import('../utils/shell-utils.js');
|
const { splitCommands } = await import('../utils/shell-utils.js');
|
||||||
const rules: PolicyRule[] = [
|
const rules: PolicyRule[] = [
|
||||||
|
|||||||
@@ -288,12 +288,11 @@ export class PolicyEngine {
|
|||||||
if (allowRedirection) return false;
|
if (allowRedirection) return false;
|
||||||
if (!hasRedirection(command)) return false;
|
if (!hasRedirection(command)) return false;
|
||||||
|
|
||||||
// Do not downgrade (do not ask user) if sandboxing is enabled and in AUTO_EDIT or YOLO
|
// Do not downgrade (do not ask user) if in AUTO_EDIT or YOLO mode.
|
||||||
const sandboxEnabled = !(this.sandboxManager instanceof NoopSandboxManager);
|
// These modes trust the agent's actions (YOLO) or specific task (AUTO_EDIT).
|
||||||
if (
|
if (
|
||||||
sandboxEnabled &&
|
this.approvalMode === ApprovalMode.AUTO_EDIT ||
|
||||||
(this.approvalMode === ApprovalMode.AUTO_EDIT ||
|
this.approvalMode === ApprovalMode.YOLO
|
||||||
this.approvalMode === ApprovalMode.YOLO)
|
|
||||||
) {
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user