diff --git a/extensions/feishu/src/reply-dispatcher.test.ts b/extensions/feishu/src/reply-dispatcher.test.ts index f1d77c5c9ca..61120a20514 100644 --- a/extensions/feishu/src/reply-dispatcher.test.ts +++ b/extensions/feishu/src/reply-dispatcher.test.ts @@ -21,6 +21,33 @@ const addTypingIndicatorMock = vi.hoisted(() => vi.fn(async () => ({ messageId: const removeTypingIndicatorMock = vi.hoisted(() => vi.fn(async () => {})); const streamingInstances = vi.hoisted((): StreamingSessionStub[] => []); +function mergeStreamingText( + previousText: string | undefined, + nextText: string | undefined, +): string { + const previous = typeof previousText === "string" ? previousText : ""; + const next = typeof nextText === "string" ? nextText : ""; + if (!next) { + return previous; + } + if (!previous || next === previous) { + return next; + } + if (next.startsWith(previous) || next.includes(previous)) { + return next; + } + if (previous.startsWith(next) || previous.includes(next)) { + return previous; + } + const maxOverlap = Math.min(previous.length, next.length); + for (let overlap = maxOverlap; overlap > 0; overlap -= 1) { + if (previous.slice(-overlap) === next.slice(0, overlap)) { + return `${previous}${next.slice(overlap)}`; + } + } + return `${previous}${next}`; +} + vi.mock("./accounts.js", () => ({ resolveFeishuAccount: resolveFeishuAccountMock, resolveFeishuRuntimeAccount: resolveFeishuAccountMock, @@ -38,10 +65,9 @@ vi.mock("./typing.js", () => ({ addTypingIndicator: addTypingIndicatorMock, removeTypingIndicator: removeTypingIndicatorMock, })); -vi.mock("./streaming-card.js", async () => { - const actual = await vi.importActual("./streaming-card.js"); +vi.mock("./streaming-card.js", () => { return { - mergeStreamingText: actual.mergeStreamingText, + mergeStreamingText, FeishuStreamingSession: class { active = false; start = vi.fn(async () => {