import { describe, expect, it } from "vitest"; import { setReplyPayloadMetadata } from "../reply-payload.js"; import {
createBlockReplyContentKey,
createBlockReplyPayloadKey,
createBlockReplyPipeline,
} from "./block-reply-pipeline.js";
describe("createBlockReplyPayloadKey", () => {
it("produces different keys for payloads differing only by replyToId", () => { const a = createBlockReplyPayloadKey({ text: "hello world", replyToId: "post-1" }); const b = createBlockReplyPayloadKey({ text: "hello world", replyToId: "post-2" }); const c = createBlockReplyPayloadKey({ text: "hello world" });
expect(a).not.toBe(b);
expect(a).not.toBe(c);
});
it("produces different keys for payloads with different text", () => { const a = createBlockReplyPayloadKey({ text: "hello" }); const b = createBlockReplyPayloadKey({ text: "world" });
expect(a).not.toBe(b);
});
it("produces different keys for payloads with different media", () => { const a = createBlockReplyPayloadKey({ text: "hello", mediaUrl: "file:///a.png" }); const b = createBlockReplyPayloadKey({ text: "hello", mediaUrl: "file:///b.png" });
expect(a).not.toBe(b);
});
it("trims whitespace from text for key comparison", () => { const a = createBlockReplyPayloadKey({ text: " hello " }); const b = createBlockReplyPayloadKey({ text: "hello" });
expect(a).toBe(b);
});
});
describe("createBlockReplyContentKey", () => {
it("produces the same key for payloads differing only by replyToId", () => { const a = createBlockReplyContentKey({ text: "hello world", replyToId: "post-1" }); const b = createBlockReplyContentKey({ text: "hello world", replyToId: "post-2" }); const c = createBlockReplyContentKey({ text: "hello world" });
expect(a).toBe(b);
expect(a).toBe(c);
});
});
describe("createBlockReplyPipeline dedup with threading", () => {
it("keeps separate deliveries for same text with different replyToId", async () => { const sent: Array<{ text?: string; replyToId?: string }> = []; const pipeline = createBlockReplyPipeline({
onBlockReply: async (payload) => {
sent.push({ text: payload.text, replyToId: payload.replyToId });
},
timeoutMs: 5000,
});
// Final payload with no replyToId should be recognized as already sent
expect(pipeline.hasSentPayload({ text: "response text" })).toBe(true);
expect(pipeline.hasSentPayload({ text: "response text", replyToId: "other-id" })).toBe(true);
});
it("does not match final assembled text with content that was not streamed", async () => {
let callCount = 0; const pipeline = createBlockReplyPipeline({
onBlockReply: async () => {
callCount += 1; if (callCount === 2) {
await new Promise((resolve) => setTimeout(resolve, 50));
}
},
timeoutMs: 1,
});
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.