mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-26 16:06:16 +00:00
fix(approvals): restore queue targeting and plugin id prefixes
This commit is contained in:
@@ -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"]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user