test(feishu): avoid loading streaming card module in dispatcher tests

This commit is contained in:
Vincent Koc 2026-04-03 20:54:22 +09:00
parent d888ce242b
commit fbc4fa6ac3
1 changed files with 29 additions and 3 deletions

View File

@ -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<typeof import("./streaming-card.js")>("./streaming-card.js");
vi.mock("./streaming-card.js", () => {
return {
mergeStreamingText: actual.mergeStreamingText,
mergeStreamingText,
FeishuStreamingSession: class {
active = false;
start = vi.fn(async () => {