






















@@ -268,6 +268,89 @@ describe("connectGateway", () => {
268268expect(host.eventLogBuffer[0]?.event).toBe("presence");
269269});
270270271+it("marks orphaned run state interrupted after reconnect hello", () => {
272+vi.useFakeTimers();
273+try {
274+const host = createHost() as TestGatewayHost & {
275+chatRunStatus?: unknown;
276+chatStreamStartedAt?: number | null;
277+compactionStatus?: unknown;
278+compactionClearTimer?: ReturnType<typeof setTimeout> | null;
279+fallbackStatus?: unknown;
280+fallbackClearTimer?: ReturnType<typeof setTimeout> | null;
281+sessionsResult?: {
282+ts: number;
283+path: string;
284+count: number;
285+defaults: Record<string, unknown>;
286+sessions: Array<Record<string, unknown>>;
287+};
288+};
289+host.chatRunId = "run-1";
290+host.chatStream = "Working...";
291+host.chatStreamStartedAt = 100;
292+host.compactionStatus = {
293+phase: "active",
294+runId: "run-1",
295+startedAt: 100,
296+completedAt: null,
297+};
298+host.compactionClearTimer = setTimeout(() => undefined, 1_000);
299+host.fallbackStatus = {
300+selected: "openai/gpt-5.5",
301+active: "anthropic/claude-sonnet-4-6",
302+attempts: [],
303+occurredAt: 100,
304+};
305+host.fallbackClearTimer = setTimeout(() => undefined, 1_000);
306+host.toolStreamById.set("tool-1", {} as never);
307+host.toolStreamOrder = ["tool-1"];
308+host.chatToolMessages = [{ role: "assistant" }];
309+host.sessionsResult = {
310+ts: 0,
311+path: "",
312+count: 1,
313+defaults: {},
314+sessions: [
315+{
316+key: "main",
317+kind: "direct",
318+updatedAt: 1,
319+hasActiveRun: true,
320+status: "running",
321+startedAt: 100,
322+},
323+],
324+};
325+326+connectGateway(host);
327+const client = requireGatewayClient();
328+client.emitHello();
329+330+expect(host.chatRunId).toBeNull();
331+expect(host.chatStream).toBeNull();
332+expect(host.chatStreamStartedAt).toBeNull();
333+expect(host.compactionStatus).toBeNull();
334+expect(host.compactionClearTimer).toBeNull();
335+expect(host.fallbackStatus).toBeNull();
336+expect(host.fallbackClearTimer).toBeNull();
337+expect(host.toolStreamOrder).toStrictEqual([]);
338+expect(host.chatToolMessages).toStrictEqual([]);
339+expect(host.chatRunStatus).toMatchObject({
340+phase: "interrupted",
341+runId: "run-1",
342+sessionKey: "main",
343+});
344+expect(host.sessionsResult.sessions[0]).toMatchObject({
345+hasActiveRun: false,
346+status: "killed",
347+abortedLastRun: true,
348+});
349+} finally {
350+vi.useRealTimers();
351+}
352+});
353+271354it("applies update.available only from active client", () => {
272355const host = createHost();
273356此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。