From c3c13ea3817e06bb1bd06015ec6128951c6613c0 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sun, 12 Apr 2026 05:27:02 +0100 Subject: [PATCH] test(telegram): dedupe exec approval resolver cases --- .../src/exec-approval-resolver.test.ts | 91 +++++++++---------- 1 file changed, 42 insertions(+), 49 deletions(-) diff --git a/extensions/telegram/src/exec-approval-resolver.test.ts b/extensions/telegram/src/exec-approval-resolver.test.ts index 5eaeb1c13bb..82e05193d4e 100644 --- a/extensions/telegram/src/exec-approval-resolver.test.ts +++ b/extensions/telegram/src/exec-approval-resolver.test.ts @@ -10,6 +10,38 @@ vi.mock("openclaw/plugin-sdk/approval-gateway-runtime", () => ({ })); describe("resolveTelegramExecApproval", () => { + async function invokeResolver(params: { + approvalId: string; + decision: string; + senderId: string; + allowPluginFallback?: boolean; + }) { + const { resolveTelegramExecApproval } = await import("./exec-approval-resolver.js"); + + await resolveTelegramExecApproval({ + cfg: {} as never, + gatewayUrl: undefined, + ...params, + }); + } + + function expectApprovalGatewayCall(params: { + approvalId: string; + decision: string; + senderId: string; + allowPluginFallback?: boolean; + }) { + expect(approvalGatewayRuntimeHoisted.resolveApprovalOverGatewaySpy).toHaveBeenCalledWith({ + cfg: {} as never, + approvalId: params.approvalId, + decision: params.decision, + senderId: params.senderId, + gatewayUrl: undefined, + allowPluginFallback: params.allowPluginFallback, + clientDisplayName: `Telegram approval (${params.senderId})`, + }); + } + beforeEach(() => { approvalGatewayRuntimeHoisted.resolveApprovalOverGatewaySpy .mockReset() @@ -17,88 +49,49 @@ describe("resolveTelegramExecApproval", () => { }); it("routes plugin approval ids through plugin.approval.resolve", async () => { - const { resolveTelegramExecApproval } = await import("./exec-approval-resolver.js"); - - await resolveTelegramExecApproval({ - cfg: {} as never, + await invokeResolver({ approvalId: "plugin:abc123", decision: "allow-once", senderId: "9", }); - expect(approvalGatewayRuntimeHoisted.resolveApprovalOverGatewaySpy).toHaveBeenCalledWith({ - cfg: {} as never, + expectApprovalGatewayCall({ approvalId: "plugin:abc123", decision: "allow-once", senderId: "9", - gatewayUrl: undefined, - allowPluginFallback: undefined, - clientDisplayName: "Telegram approval (9)", }); }); - it("falls back to plugin.approval.resolve when exec approval ids are unknown", async () => { - const { resolveTelegramExecApproval } = await import("./exec-approval-resolver.js"); - - await resolveTelegramExecApproval({ - cfg: {} as never, + it.each([ + "falls back to plugin.approval.resolve when exec approval ids are unknown", + "falls back to plugin.approval.resolve for structured approval-not-found errors", + ])("%s", async () => { + await invokeResolver({ approvalId: "legacy-plugin-123", decision: "allow-always", senderId: "9", allowPluginFallback: true, }); - expect(approvalGatewayRuntimeHoisted.resolveApprovalOverGatewaySpy).toHaveBeenCalledWith({ - cfg: {} as never, - approvalId: "legacy-plugin-123", - decision: "allow-always", - senderId: "9", - gatewayUrl: undefined, - allowPluginFallback: true, - clientDisplayName: "Telegram approval (9)", - }); - }); - - it("falls back to plugin.approval.resolve for structured approval-not-found errors", async () => { - const { resolveTelegramExecApproval } = await import("./exec-approval-resolver.js"); - - await resolveTelegramExecApproval({ - cfg: {} as never, + expectApprovalGatewayCall({ approvalId: "legacy-plugin-123", decision: "allow-always", senderId: "9", allowPluginFallback: true, }); - - expect(approvalGatewayRuntimeHoisted.resolveApprovalOverGatewaySpy).toHaveBeenCalledWith({ - cfg: {} as never, - approvalId: "legacy-plugin-123", - decision: "allow-always", - senderId: "9", - gatewayUrl: undefined, - allowPluginFallback: true, - clientDisplayName: "Telegram approval (9)", - }); }); it("passes fallback disablement through unchanged", async () => { - const { resolveTelegramExecApproval } = await import("./exec-approval-resolver.js"); - - await resolveTelegramExecApproval({ - cfg: {} as never, + await invokeResolver({ approvalId: "legacy-plugin-123", decision: "allow-always", senderId: "9", }); - expect(approvalGatewayRuntimeHoisted.resolveApprovalOverGatewaySpy).toHaveBeenCalledWith({ - cfg: {} as never, + expectApprovalGatewayCall({ approvalId: "legacy-plugin-123", decision: "allow-always", senderId: "9", - gatewayUrl: undefined, - allowPluginFallback: undefined, - clientDisplayName: "Telegram approval (9)", }); }); });