test: harden Telegram approval fallback coverage

This commit is contained in:
Gustavo Madeira Santana
2026-04-01 11:52:50 -04:00
parent 8d1ae4f845
commit ed5d108c9b
3 changed files with 30 additions and 0 deletions

View File

@@ -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: {

View File

@@ -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,
});

View File

@@ -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;
}) {