fix: avoid duplicate feishu permission-error dispatch replies (#27381) (thanks @byungsker)
This commit is contained in:
@@ -9,6 +9,7 @@ const {
|
||||
mockSendMessageFeishu,
|
||||
mockGetMessageFeishu,
|
||||
mockDownloadMessageResourceFeishu,
|
||||
mockCreateFeishuClient,
|
||||
} = vi.hoisted(() => ({
|
||||
mockCreateFeishuReplyDispatcher: vi.fn(() => ({
|
||||
dispatcher: vi.fn(),
|
||||
@@ -22,6 +23,7 @@ const {
|
||||
contentType: "video/mp4",
|
||||
fileName: "clip.mp4",
|
||||
}),
|
||||
mockCreateFeishuClient: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("./reply-dispatcher.js", () => ({
|
||||
@@ -37,6 +39,10 @@ vi.mock("./media.js", () => ({
|
||||
downloadMessageResourceFeishu: mockDownloadMessageResourceFeishu,
|
||||
}));
|
||||
|
||||
vi.mock("./client.js", () => ({
|
||||
createFeishuClient: mockCreateFeishuClient,
|
||||
}));
|
||||
|
||||
function createRuntimeEnv(): RuntimeEnv {
|
||||
return {
|
||||
log: vi.fn(),
|
||||
@@ -72,6 +78,13 @@ describe("handleFeishuMessage command authorization", () => {
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
mockCreateFeishuClient.mockReturnValue({
|
||||
contact: {
|
||||
user: {
|
||||
get: vi.fn().mockResolvedValue({ data: { user: { name: "Sender" } } }),
|
||||
},
|
||||
},
|
||||
});
|
||||
setFeishuRuntime({
|
||||
system: {
|
||||
enqueueSystemEvent: vi.fn(),
|
||||
@@ -417,4 +430,67 @@ describe("handleFeishuMessage command authorization", () => {
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("dispatches once and appends permission notice to the main agent body", async () => {
|
||||
mockShouldComputeCommandAuthorized.mockReturnValue(false);
|
||||
mockCreateFeishuClient.mockReturnValue({
|
||||
contact: {
|
||||
user: {
|
||||
get: vi.fn().mockRejectedValue({
|
||||
response: {
|
||||
data: {
|
||||
code: 99991672,
|
||||
msg: "permission denied https://open.feishu.cn/app/cli_test",
|
||||
},
|
||||
},
|
||||
}),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const cfg: ClawdbotConfig = {
|
||||
channels: {
|
||||
feishu: {
|
||||
appId: "cli_test",
|
||||
appSecret: "sec_test",
|
||||
groups: {
|
||||
"oc-group": {
|
||||
requireMention: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} as ClawdbotConfig;
|
||||
|
||||
const event: FeishuMessageEvent = {
|
||||
sender: {
|
||||
sender_id: {
|
||||
open_id: "ou-perm",
|
||||
},
|
||||
},
|
||||
message: {
|
||||
message_id: "msg-perm-1",
|
||||
chat_id: "oc-group",
|
||||
chat_type: "group",
|
||||
message_type: "text",
|
||||
content: JSON.stringify({ text: "hello group" }),
|
||||
},
|
||||
};
|
||||
|
||||
await dispatchMessage({ cfg, event });
|
||||
|
||||
expect(mockDispatchReplyFromConfig).toHaveBeenCalledTimes(1);
|
||||
expect(mockFinalizeInboundContext).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
BodyForAgent: expect.stringContaining(
|
||||
"Permission grant URL: https://open.feishu.cn/app/cli_test",
|
||||
),
|
||||
}),
|
||||
);
|
||||
expect(mockFinalizeInboundContext).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
BodyForAgent: expect.stringContaining("ou-perm: hello group"),
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user