





















@@ -120,6 +120,68 @@ describe("draft-stream-controls", () => {
120120expect(deleteMessage).toHaveBeenCalledWith("m-4");
121121});
122122123+it("lifecycle clear cancels pending draft text instead of flushing it", async () => {
124+vi.useFakeTimers();
125+vi.setSystemTime(0);
126+try {
127+const state = { stopped: false, final: false };
128+let messageId: string | undefined = "m-6";
129+const sendOrEditStreamMessage = vi.fn(async () => true);
130+const deleteMessage = vi.fn(async () => {});
131+132+const lifecycle = createFinalizableDraftLifecycle({
133+throttleMs: 250,
134+ state,
135+ sendOrEditStreamMessage,
136+readMessageId: () => messageId,
137+clearMessageId: () => {
138+messageId = undefined;
139+},
140+isValidMessageId: (value): value is string => typeof value === "string",
141+ deleteMessage,
142+warnPrefix: "cleanup failed",
143+});
144+145+lifecycle.update("pending draft");
146+await lifecycle.clear();
147+148+expect(state.stopped).toBe(true);
149+expect(sendOrEditStreamMessage).not.toHaveBeenCalled();
150+expect(deleteMessage).toHaveBeenCalledWith("m-6");
151+} finally {
152+vi.useRealTimers();
153+}
154+});
155+156+it("lifecycle stop flushes pending final draft text", async () => {
157+vi.useFakeTimers();
158+vi.setSystemTime(0);
159+try {
160+const state = { stopped: false, final: false };
161+const sendOrEditStreamMessage = vi.fn(async () => true);
162+163+const lifecycle = createFinalizableDraftLifecycle({
164+throttleMs: 250,
165+ state,
166+ sendOrEditStreamMessage,
167+readMessageId: () => "m-7",
168+clearMessageId: () => {},
169+isValidMessageId: (value): value is string => typeof value === "string",
170+deleteMessage: async () => {},
171+warnPrefix: "cleanup failed",
172+});
173+174+lifecycle.update("final draft");
175+await lifecycle.stop();
176+177+expect(state.final).toBe(true);
178+expect(sendOrEditStreamMessage).toHaveBeenCalledTimes(1);
179+expect(sendOrEditStreamMessage).toHaveBeenCalledWith("final draft");
180+} finally {
181+vi.useRealTimers();
182+}
183+});
184+123185it("lifecycle seal ignores late updates without clearing the preview id", async () => {
124186const state = { stopped: false, final: false };
125187let messageId: string | undefined = "m-5";
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。