From bcdec7bfb9cb94c562a2c5b1fc51fe8f0ff0cf9b Mon Sep 17 00:00:00 2001 From: Shakker Date: Mon, 11 May 2026 13:47:44 +0100 Subject: [PATCH] test: pin plugin approval ids --- .../server-methods/plugin-approval.test.ts | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/gateway/server-methods/plugin-approval.test.ts b/src/gateway/server-methods/plugin-approval.test.ts index 9638640d7bd..1a30671f6f9 100644 --- a/src/gateway/server-methods/plugin-approval.test.ts +++ b/src/gateway/server-methods/plugin-approval.test.ts @@ -97,6 +97,24 @@ function acceptedApprovalId(source: MockCallSource) { return id as string; } +function expectPluginApprovalId(value: unknown, label: string): string { + expect(value, label).toBeTypeOf("string"); + if (typeof value !== "string") { + throw new Error(`${label} must be a string`); + } + expect(value.startsWith("plugin:"), label).toBe(true); + const uuid = value.slice("plugin:".length); + expect(uuid).toHaveLength(36); + expect(uuid.split("-").map((part) => part.length)).toEqual([8, 4, 4, 4, 12]); + expect( + uuid + .split("-") + .every((part) => part.length > 0 && [...part].every((char) => /[0-9a-f]/.test(char))), + label, + ).toBe(true); + return value; +} + function broadcastCall(opts: GatewayRequestHandlerOptions, index = 0) { const call = mockCall( opts.context.broadcast as unknown as MockCallSource, @@ -336,7 +354,7 @@ describe("createPluginApprovalHandlers", () => { ); await handlers["plugin.approval.request"](opts); const result = respond.mock.calls[0]?.[1] as Record | undefined; - expect(result?.id).toEqual(expect.stringMatching(/^plugin:/)); + expectPluginApprovalId(result?.id, "generated plugin approval id"); }); it("passes plugin-prefixed IDs directly to manager.create", async () => { @@ -353,7 +371,7 @@ describe("createPluginApprovalHandlers", () => { await handlers["plugin.approval.request"](opts); expect(createSpy).toHaveBeenCalledTimes(1); - expect(createSpy.mock.calls[0]?.[2]).toEqual(expect.stringMatching(/^plugin:/)); + expectPluginApprovalId(createSpy.mock.calls[0]?.[2], "manager.create approval id"); }); it("rejects plugin-provided id field", async () => { @@ -433,13 +451,14 @@ describe("createPluginApprovalHandlers", () => { ); expect(approvals).toHaveLength(1); const approval = requireRecord(approvals[0], "approval"); - expect(approval.id).toEqual(expect.stringMatching(/^plugin:/)); + const listedApprovalId = expectPluginApprovalId(approval.id, "listed approval id"); const request = requireRecord(approval.request, "approval request"); expect(request.title).toBe("Sensitive action"); expect(request.description).toBe("Desc"); expect(responseCall(listRespond as unknown as MockCallSource).error).toBeUndefined(); const approvalId = acceptedApprovalId(respond as unknown as MockCallSource); + expect(listedApprovalId).toBe(approvalId); manager.resolve(approvalId, "allow-once"); await handlerPromise; });