fix(acp): require allow option for auto approvals

This commit is contained in:
Peter Steinberger
2026-05-24 01:18:05 +01:00
parent bee15d4fa2
commit 25ccadd22a
2 changed files with 24 additions and 4 deletions

View File

@@ -123,13 +123,12 @@ export async function resolvePermissionRequest(
const promptRequired = !classification.autoApprove;
if (!promptRequired) {
const option = allowOption ?? options[0];
if (!option) {
log(`[permission cancelled] ${toolName}: no selectable options`);
if (!allowOption) {
log(`[permission cancelled] ${toolName ?? "unknown"}: missing allow option`);
return cancelledPermission();
}
log(`[permission auto-approved] ${toolName} (${toolKind ?? "unknown"})`);
return selectedPermission(option.optionId);
return selectedPermission(allowOption.optionId);
}
log(

View File

@@ -659,6 +659,27 @@ describe("resolvePermissionRequest", () => {
expect(res).toEqual({ outcome: { outcome: "selected", optionId: "reject-always" } });
});
it("cancels auto-approved requests when no allow option is available", async () => {
const prompt = vi.fn(async () => true);
const log = vi.fn();
const res = await resolvePermissionRequest(
makePermissionRequest({
toolCall: {
toolCallId: "tool-read-no-allow",
title: "read: src/index.ts",
status: "pending",
kind: "read",
},
options: [{ kind: "reject_once", name: "Reject", optionId: "reject" }],
}),
{ prompt, log },
);
expect(prompt).not.toHaveBeenCalled();
expect(log).toHaveBeenCalledWith("[permission cancelled] read: missing allow option");
expect(res).toEqual({ outcome: { outcome: "cancelled" } });
});
it("prompts when tool identity is unknown and can still approve", async () => {
const prompt = vi.fn(async () => true);
const res = await resolvePermissionRequest(