openclaw/extensions/feishu/src/streaming-card.test.ts
rexl2018 3bf6ed181e
Feishu: harden streaming merge semantics and final reply dedupe (#33245)
* Feishu: close duplicate final gap and cover routing precedence

* Feishu: resolve reviewer duplicate-final and routing feedback

* Feishu: tighten streaming send-mode option typing

* Feishu: fix reverse-overlap streaming merge ordering

* Feishu: align streaming final dedupe test expectation

* Feishu: allow distinct streaming finals while deduping repeats

---------

Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
2026-03-04 21:32:35 -06:00

55 lines
1.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { describe, expect, it } from "vitest";
import { mergeStreamingText, resolveStreamingCardSendMode } from "./streaming-card.js";
describe("mergeStreamingText", () => {
it("prefers the latest full text when it already includes prior text", () => {
expect(mergeStreamingText("hello", "hello world")).toBe("hello world");
});
it("keeps previous text when the next partial is empty or redundant", () => {
expect(mergeStreamingText("hello", "")).toBe("hello");
expect(mergeStreamingText("hello world", "hello")).toBe("hello world");
});
it("appends fragmented chunks without injecting newlines", () => {
expect(mergeStreamingText("hello wor", "ld")).toBe("hello world");
expect(mergeStreamingText("line1", "line2")).toBe("line1line2");
});
it("merges overlap between adjacent partial snapshots", () => {
expect(mergeStreamingText("好的,让我", "让我再读取一遍")).toBe("好的,让我再读取一遍");
expect(mergeStreamingText("revision_id: 552", "2一点变化都没有")).toBe(
"revision_id: 552一点变化都没有",
);
expect(mergeStreamingText("abc", "cabc")).toBe("cabc");
});
});
describe("resolveStreamingCardSendMode", () => {
it("prefers message.reply when reply target and root id both exist", () => {
expect(
resolveStreamingCardSendMode({
replyToMessageId: "om_parent",
rootId: "om_topic_root",
}),
).toBe("reply");
});
it("falls back to root create when reply target is absent", () => {
expect(
resolveStreamingCardSendMode({
rootId: "om_topic_root",
}),
).toBe("root_create");
});
it("uses create mode when no reply routing fields are provided", () => {
expect(resolveStreamingCardSendMode()).toBe("create");
expect(
resolveStreamingCardSendMode({
replyInThread: true,
}),
).toBe("create");
});
});