





















@@ -97,6 +97,24 @@ function acceptedApprovalId(source: MockCallSource) {
9797return id as string;
9898}
9999100+function expectPluginApprovalId(value: unknown, label: string): string {
101+expect(value, label).toBeTypeOf("string");
102+if (typeof value !== "string") {
103+throw new Error(`${label} must be a string`);
104+}
105+expect(value.startsWith("plugin:"), label).toBe(true);
106+const uuid = value.slice("plugin:".length);
107+expect(uuid).toHaveLength(36);
108+expect(uuid.split("-").map((part) => part.length)).toEqual([8, 4, 4, 4, 12]);
109+expect(
110+uuid
111+.split("-")
112+.every((part) => part.length > 0 && [...part].every((char) => /[0-9a-f]/.test(char))),
113+label,
114+).toBe(true);
115+return value;
116+}
117+100118function broadcastCall(opts: GatewayRequestHandlerOptions, index = 0) {
101119const call = mockCall(
102120opts.context.broadcast as unknown as MockCallSource,
@@ -336,7 +354,7 @@ describe("createPluginApprovalHandlers", () => {
336354);
337355await handlers["plugin.approval.request"](opts);
338356const result = respond.mock.calls[0]?.[1] as Record<string, unknown> | undefined;
339-expect(result?.id).toEqual(expect.stringMatching(/^plugin:/));
357+expectPluginApprovalId(result?.id, "generated plugin approval id");
340358});
341359342360it("passes plugin-prefixed IDs directly to manager.create", async () => {
@@ -353,7 +371,7 @@ describe("createPluginApprovalHandlers", () => {
353371await handlers["plugin.approval.request"](opts);
354372355373expect(createSpy).toHaveBeenCalledTimes(1);
356-expect(createSpy.mock.calls[0]?.[2]).toEqual(expect.stringMatching(/^plugin:/));
374+expectPluginApprovalId(createSpy.mock.calls[0]?.[2], "manager.create approval id");
357375});
358376359377it("rejects plugin-provided id field", async () => {
@@ -433,13 +451,14 @@ describe("createPluginApprovalHandlers", () => {
433451);
434452expect(approvals).toHaveLength(1);
435453const approval = requireRecord(approvals[0], "approval");
436-expect(approval.id).toEqual(expect.stringMatching(/^plugin:/));
454+const listedApprovalId = expectPluginApprovalId(approval.id, "listed approval id");
437455const request = requireRecord(approval.request, "approval request");
438456expect(request.title).toBe("Sensitive action");
439457expect(request.description).toBe("Desc");
440458expect(responseCall(listRespond as unknown as MockCallSource).error).toBeUndefined();
441459442460const approvalId = acceptedApprovalId(respond as unknown as MockCallSource);
461+expect(listedApprovalId).toBe(approvalId);
443462manager.resolve(approvalId, "allow-once");
444463await handlerPromise;
445464});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。