From 98ed7f57c609acdcf28503f5915e3ba87f5ec7e8 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 7 Mar 2026 17:35:14 +0000 Subject: [PATCH] refactor(feishu): dedupe non-streaming reply dispatcher setup --- .../feishu/src/reply-dispatcher.test.ts | 62 +++++++------------ 1 file changed, 24 insertions(+), 38 deletions(-) diff --git a/extensions/feishu/src/reply-dispatcher.test.ts b/extensions/feishu/src/reply-dispatcher.test.ts index b7a1292a4..744532320 100644 --- a/extensions/feishu/src/reply-dispatcher.test.ts +++ b/extensions/feishu/src/reply-dispatcher.test.ts @@ -106,6 +106,28 @@ describe("createFeishuReplyDispatcher streaming behavior", () => { }); }); + function setupNonStreamingAutoDispatcher() { + resolveFeishuAccountMock.mockReturnValue({ + accountId: "main", + appId: "app_id", + appSecret: "app_secret", + domain: "feishu", + config: { + renderMode: "auto", + streaming: false, + }, + }); + + createFeishuReplyDispatcher({ + cfg: {} as never, + agentId: "agent", + runtime: { log: vi.fn(), error: vi.fn() } as never, + chatId: "oc_chat", + }); + + return createReplyDispatcherWithTypingMock.mock.calls[0]?.[0]; + } + it("skips typing indicator when account typingIndicator is disabled", async () => { resolveFeishuAccountMock.mockReturnValue({ accountId: "main", @@ -312,25 +334,7 @@ describe("createFeishuReplyDispatcher streaming behavior", () => { expect(sendMarkdownCardFeishuMock).not.toHaveBeenCalled(); }); it("suppresses duplicate final text while still sending media", async () => { - resolveFeishuAccountMock.mockReturnValue({ - accountId: "main", - appId: "app_id", - appSecret: "app_secret", - domain: "feishu", - config: { - renderMode: "auto", - streaming: false, - }, - }); - - createFeishuReplyDispatcher({ - cfg: {} as never, - agentId: "agent", - runtime: { log: vi.fn(), error: vi.fn() } as never, - chatId: "oc_chat", - }); - - const options = createReplyDispatcherWithTypingMock.mock.calls[0]?.[0]; + const options = setupNonStreamingAutoDispatcher(); await options.deliver({ text: "plain final" }, { kind: "final" }); await options.deliver( { text: "plain final", mediaUrl: "https://example.com/a.png" }, @@ -352,25 +356,7 @@ describe("createFeishuReplyDispatcher streaming behavior", () => { }); it("keeps distinct non-streaming final payloads", async () => { - resolveFeishuAccountMock.mockReturnValue({ - accountId: "main", - appId: "app_id", - appSecret: "app_secret", - domain: "feishu", - config: { - renderMode: "auto", - streaming: false, - }, - }); - - createFeishuReplyDispatcher({ - cfg: {} as never, - agentId: "agent", - runtime: { log: vi.fn(), error: vi.fn() } as never, - chatId: "oc_chat", - }); - - const options = createReplyDispatcherWithTypingMock.mock.calls[0]?.[0]; + const options = setupNonStreamingAutoDispatcher(); await options.deliver({ text: "notice header" }, { kind: "final" }); await options.deliver({ text: "actual answer body" }, { kind: "final" });