From ed5d108c9b3a246e19e32bf540dbbb96ecbba9e6 Mon Sep 17 00:00:00 2001 From: Gustavo Madeira Santana Date: Wed, 1 Apr 2026 11:52:50 -0400 Subject: [PATCH] test: harden Telegram approval fallback coverage --- .../src/exec-approvals-handler.test.ts | 28 +++++++++++++++++++ extensions/telegram/src/exec-approvals.ts | 1 + src/plugin-sdk/approval-client-helpers.ts | 1 + 3 files changed, 30 insertions(+) diff --git a/extensions/telegram/src/exec-approvals-handler.test.ts b/extensions/telegram/src/exec-approvals-handler.test.ts index b79c6e1239b..fb2408a5e33 100644 --- a/extensions/telegram/src/exec-approvals-handler.test.ts +++ b/extensions/telegram/src/exec-approvals-handler.test.ts @@ -243,6 +243,34 @@ describe("TelegramExecApprovalHandler", () => { ); }); + it("delivers plugin approvals when the agent only exists in the Telegram session key", async () => { + const cfg = { + channels: { + telegram: { + execApprovals: { + enabled: true, + approvers: ["8460800771"], + agentFilter: ["main"], + target: "dm", + }, + }, + }, + } as OpenClawConfig; + const { handler, sendMessage } = createHandler(cfg); + + await handler.handleRequested({ + ...pluginRequest, + request: { + ...pluginRequest.request, + agentId: undefined, + }, + }); + + const [chatId, text] = sendMessage.mock.calls[0] ?? []; + expect(chatId).toBe("8460800771"); + expect(text).toContain("Plugin approval required"); + }); + it("does not deliver plugin approvals for a different Telegram account", async () => { const cfg = { channels: { diff --git a/extensions/telegram/src/exec-approvals.ts b/extensions/telegram/src/exec-approvals.ts index 5499ad79dc8..9f814c26260 100644 --- a/extensions/telegram/src/exec-approvals.ts +++ b/extensions/telegram/src/exec-approvals.ts @@ -80,6 +80,7 @@ const telegramExecApprovalProfile = createChannelExecApprovalProfile({ normalizeAccountId(boundAccountId) === normalizeAccountId(accountId) ); }, + // Telegram session keys often carry the only stable agent ID for approval routing. fallbackAgentIdFromSessionKey: true, requireClientEnabledForLocalPromptSuppression: false, }); diff --git a/src/plugin-sdk/approval-client-helpers.ts b/src/plugin-sdk/approval-client-helpers.ts index 4ba5ce44a8d..5edec513507 100644 --- a/src/plugin-sdk/approval-client-helpers.ts +++ b/src/plugin-sdk/approval-client-helpers.ts @@ -82,6 +82,7 @@ export function createChannelExecApprovalProfile(params: { normalizeSenderId?: (value: string) => string | undefined; isTargetRecipient?: (params: ApprovalProfileParams & { senderId?: string | null }) => boolean; matchesRequestAccount?: (params: ApprovalProfileParams & { request: ApprovalRequest }) => boolean; + // Some channels encode the effective agent only in sessionKey for forwarded approvals. fallbackAgentIdFromSessionKey?: boolean; requireClientEnabledForLocalPromptSuppression?: boolean; }) {