



























@@ -336,6 +336,52 @@ describe("waitForAgentJob", () => {
336336expect(fresh?.startedAt).toBe(200);
337337expect(fresh?.endedAt).toBe(210);
338338});
339+340+it("surfaces pending error diagnostics when outer timeout fires before error grace period", async () => {
341+// Preserve the retry grace: the caller timeout may carry the pending error
342+// reason, but it must not cache a terminal error before a later start can
343+// cancel the pending snapshot.
344+vi.useFakeTimers();
345+try {
346+const runId = `run-pending-error-${Date.now()}-${Math.random().toString(36).slice(2)}`;
347+const waitPromise = waitForAgentJob({ runId, timeoutMs: 5_000 });
348+349+emitAgentEvent({
350+ runId,
351+stream: "lifecycle",
352+data: { phase: "error", error: "transient-auth-failure" },
353+});
354+355+await vi.advanceTimersByTimeAsync(6_000);
356+357+const result = await waitPromise;
358+expect(result).not.toBeNull();
359+expect(result?.status).toBe("timeout");
360+expect(result?.error).toBe("transient-auth-failure");
361+expect(result?.pendingError).toBe(true);
362+363+emitAgentEvent({
364+ runId,
365+stream: "lifecycle",
366+data: { phase: "start", startedAt: 12_000 },
367+});
368+emitAgentEvent({
369+ runId,
370+stream: "lifecycle",
371+data: { phase: "end", startedAt: 12_000, endedAt: 12_100 },
372+});
373+374+const recovered = await waitForAgentJob({ runId, timeoutMs: 1_000 });
375+expectRecordFields(recovered, {
376+status: "ok",
377+startedAt: 12_000,
378+endedAt: 12_100,
379+});
380+} finally {
381+vi.clearAllTimers();
382+vi.useRealTimers();
383+}
384+});
339385});
340386341387describe("augmentChatHistoryWithCanvasBlocks", () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。