mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-08 07:52:53 +00:00
fix(acp): require allow option for auto approvals
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user