
























@@ -191,10 +191,20 @@ describe("handleGatewayEvent sessions.changed", () => {
191191flushChatQueueForEventMock.mockReset();
192192applySessionsChangedEventMock
193193.mockReset()
194-.mockImplementation((state: { chatRunId: string | null }) => {
195-state.chatRunId = null;
196-return { applied: true, change: "updated", clearedChatRun: true };
197-});
194+.mockImplementation(
195+(state: { chatRunId: string | null; sessionKey: string; chatRunStatus?: unknown }) => {
196+const runId = state.chatRunId;
197+const sessionKey = state.sessionKey;
198+state.chatRunStatus = null;
199+state.chatRunId = null;
200+return {
201+applied: true,
202+change: "updated",
203+clearedChatRun: true,
204+clearedChatRunStatus: { phase: "done", runId, sessionKey },
205+};
206+},
207+);
198208const host = createHost();
199209host.chatRunId = "run-1";
200210const payload = {
@@ -223,9 +233,16 @@ describe("handleGatewayEvent sessions.changed", () => {
223233flushChatQueueForEventMock.mockReset();
224234applySessionsChangedEventMock
225235.mockReset()
226-.mockImplementation((state: { chatRunId: string | null }) => {
236+.mockImplementation((state: { chatRunId: string | null; sessionKey: string }) => {
237+const runId = state.chatRunId;
238+const sessionKey = state.sessionKey;
227239state.chatRunId = null;
228-return { applied: true, change: "updated", clearedChatRun: true };
240+return {
241+applied: true,
242+change: "updated",
243+clearedChatRun: true,
244+clearedChatRunStatus: { phase: "done", runId, sessionKey },
245+};
229246});
230247let resolveHistory!: () => void;
231248loadChatHistoryMock.mockReturnValue(
@@ -255,10 +272,16 @@ describe("handleGatewayEvent sessions.changed", () => {
255272.pendingSessionMessageReloadSessionKey,
256273).toBeNull();
257274expect(flushChatQueueForEventMock).not.toHaveBeenCalled();
275+expect((host as typeof host & { chatRunStatus?: unknown }).chatRunStatus).toBeUndefined();
258276259277resolveHistory();
260278await Promise.resolve();
261279280+expect((host as typeof host & { chatRunStatus?: unknown }).chatRunStatus).toMatchObject({
281+phase: "done",
282+runId: "run-1",
283+sessionKey: "agent:main:main",
284+});
262285expect(flushChatQueueForEventMock).toHaveBeenCalledWith(host);
263286expect(loadSessionsMock).not.toHaveBeenCalled();
264287});
@@ -270,9 +293,16 @@ describe("handleGatewayEvent sessions.changed", () => {
270293flushChatQueueForEventMock.mockReset();
271294applySessionsChangedEventMock
272295.mockReset()
273-.mockImplementation((state: { chatRunId: string | null }) => {
296+.mockImplementation((state: { chatRunId: string | null; sessionKey: string }) => {
297+const runId = state.chatRunId;
298+const sessionKey = state.sessionKey;
274299state.chatRunId = null;
275-return { applied: true, change: "updated", clearedChatRun: true };
300+return {
301+applied: true,
302+change: "updated",
303+clearedChatRun: true,
304+clearedChatRunStatus: { phase: "done", runId, sessionKey },
305+};
276306});
277307let resolveHistory!: () => void;
278308loadChatHistoryMock.mockReturnValue(
@@ -504,9 +534,16 @@ describe("handleGatewayEvent session.message", () => {
504534flushChatQueueForEventMock.mockReset();
505535applySessionsChangedEventMock
506536.mockReset()
507-.mockImplementation((state: { chatRunId: string | null }) => {
537+.mockImplementation((state: { chatRunId: string | null; sessionKey: string }) => {
538+const runId = state.chatRunId;
539+const sessionKey = state.sessionKey;
508540state.chatRunId = null;
509-return { applied: true, change: "updated", clearedChatRun: true };
541+return {
542+applied: true,
543+change: "updated",
544+clearedChatRun: true,
545+clearedChatRunStatus: { phase: "done", runId, sessionKey },
546+};
510547});
511548let resolveHistory!: () => void;
512549loadChatHistoryMock.mockReturnValue(
@@ -532,10 +569,16 @@ describe("handleGatewayEvent session.message", () => {
532569expect(loadChatHistoryMock).toHaveBeenCalledTimes(1);
533570expect(loadChatHistoryMock).toHaveBeenCalledWith(host);
534571expect(flushChatQueueForEventMock).not.toHaveBeenCalled();
572+expect((host as typeof host & { chatRunStatus?: unknown }).chatRunStatus).toBeUndefined();
535573536574resolveHistory();
537575await Promise.resolve();
538576577+expect((host as typeof host & { chatRunStatus?: unknown }).chatRunStatus).toMatchObject({
578+phase: "done",
579+runId: "run-1",
580+sessionKey: "agent:qa:main",
581+});
539582expect(flushChatQueueForEventMock).toHaveBeenCalledWith(host);
540583});
541584@@ -558,6 +601,7 @@ describe("handleGatewayEvent session.message", () => {
558601expect(loadSessionsMock).toHaveBeenCalledWith(host, {
559602activeMinutes: 10,
560603limit: 25,
604+publishChatRunStatus: false,
561605});
562606await Promise.resolve();
563607expect(loadChatHistoryMock).not.toHaveBeenCalled();
@@ -570,6 +614,21 @@ describe("handleGatewayEvent session.message", () => {
570614flushChatQueueForEventMock.mockReset();
571615loadSessionsMock.mockReset().mockImplementation(async (state) => {
572616state.chatRunId = null;
617+state.sessionsResult = {
618+ts: 1,
619+path: "(multiple)",
620+count: 1,
621+defaults: { modelProvider: null, model: null, contextTokens: null },
622+sessions: [
623+{
624+key: "agent:qa:main",
625+kind: "direct",
626+updatedAt: 1,
627+hasActiveRun: false,
628+status: "done",
629+},
630+],
631+};
573632});
574633const host = createHost();
575634host.sessionKey = "agent:qa:main";
@@ -586,6 +645,11 @@ describe("handleGatewayEvent session.message", () => {
586645await Promise.resolve();
587646588647expect(host.chatRunId).toBeNull();
648+expect((host as typeof host & { chatRunStatus?: unknown }).chatRunStatus).toMatchObject({
649+phase: "done",
650+runId: "run-stale",
651+sessionKey: "agent:qa:main",
652+});
589653expect(clearPendingQueueItemsForRunMock).toHaveBeenCalledWith(host, "run-stale");
590654expect(loadChatHistoryMock).toHaveBeenCalledTimes(1);
591655expect(loadChatHistoryMock).toHaveBeenCalledWith(host);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。