






















1-import { describe, expect, it } from "vitest";
1+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
22import { setReplyPayloadMetadata } from "../reply-payload.js";
33import {
44createBlockReplyContentKey,
@@ -15,6 +15,14 @@ const waitForAbort = (signal: AbortSignal | undefined): Promise<void> =>
1515signal.addEventListener("abort", () => resolve(), { once: true });
1616});
171718+beforeEach(() => {
19+vi.useRealTimers();
20+});
21+22+afterEach(() => {
23+vi.useRealTimers();
24+});
25+1826describe("createBlockReplyPayloadKey", () => {
1927it("produces different keys for payloads differing only by replyToId", () => {
2028const a = createBlockReplyPayloadKey({ text: "hello world", replyToId: "post-1" });
@@ -284,6 +292,8 @@ describe("createBlockReplyPipeline dedup with threading", () => {
284292285293describe("createBlockReplyPipeline content coverage dedup", () => {
286294it("matches final assembled text to successfully streamed text chunks after abort", async () => {
295+vi.useFakeTimers();
296+287297let callCount = 0;
288298const pipeline = createBlockReplyPipeline({
289299onBlockReply: async (_payload, options) => {
@@ -298,14 +308,18 @@ describe("createBlockReplyPipeline content coverage dedup", () => {
298308pipeline.enqueue({ text: "First paragraph." });
299309pipeline.enqueue({ text: "Second paragraph." });
300310pipeline.enqueue({ text: "Third paragraph." });
301-await pipeline.flush({ force: true });
311+const flushing = pipeline.flush({ force: true });
312+await vi.advanceTimersByTimeAsync(1);
313+await flushing;
302314303315expect(pipeline.didStream()).toBe(true);
304316expect(pipeline.isAborted()).toBe(true);
305317expect(pipeline.hasSentPayload({ text: "First paragraph.\n\nSecond paragraph." })).toBe(true);
306318});
307319308320it("does not match final assembled text with content that was not streamed", async () => {
321+vi.useFakeTimers();
322+309323let callCount = 0;
310324const pipeline = createBlockReplyPipeline({
311325onBlockReply: async (_payload, options) => {
@@ -319,7 +333,9 @@ describe("createBlockReplyPipeline content coverage dedup", () => {
319333320334pipeline.enqueue({ text: "First paragraph." });
321335pipeline.enqueue({ text: "Second paragraph." });
322-await pipeline.flush({ force: true });
336+const flushing = pipeline.flush({ force: true });
337+await vi.advanceTimersByTimeAsync(1);
338+await flushing;
323339324340expect(pipeline.didStream()).toBe(true);
325341expect(pipeline.isAborted()).toBe(true);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。