fix(approvals): restore queue targeting and plugin id prefixes

This commit is contained in:
Vincent Koc
2026-03-30 07:36:44 +09:00
parent 7043705ef3
commit 0e47ce58bc
5 changed files with 46 additions and 12 deletions

View File

@@ -49,6 +49,9 @@ vi.mock("./gateway.ts", () => ({
}));
const { handleGatewayEvent } = await import("./app-gateway.ts");
const { addExecApproval } = await vi.importActual<typeof import("./controllers/exec-approval.ts")>(
"./controllers/exec-approval.ts",
);
function createHost() {
return {
@@ -120,3 +123,28 @@ describe("handleGatewayEvent sessions.changed", () => {
expect(loadSessionsMock).toHaveBeenCalledWith(host);
});
});
describe("addExecApproval", () => {
it("keeps the newest approval at the front of the queue", () => {
const queue = addExecApproval(
[
{
id: "approval-old",
kind: "exec",
request: { command: "echo old" },
createdAtMs: 1,
expiresAtMs: Date.now() + 120_000,
},
],
{
id: "approval-new",
kind: "exec",
request: { command: "echo new" },
createdAtMs: 2,
expiresAtMs: Date.now() + 120_000,
},
);
expect(queue.map((entry) => entry.id)).toEqual(["approval-new", "approval-old"]);
});
});

View File

@@ -134,7 +134,7 @@ export function addExecApproval(
entry: ExecApprovalRequest,
): ExecApprovalRequest[] {
const next = pruneExecApprovalQueue(queue).filter((item) => item.id !== entry.id);
next.push(entry);
next.unshift(entry);
return next;
}