diff --git a/src/auto-reply/reply/session.heartbeat-no-reset.test.ts b/src/auto-reply/reply/session.heartbeat-no-reset.test.ts index fa1d515ccaa..583b59cdd3f 100644 --- a/src/auto-reply/reply/session.heartbeat-no-reset.test.ts +++ b/src/auto-reply/reply/session.heartbeat-no-reset.test.ts @@ -82,6 +82,14 @@ describe("initSessionState - heartbeat should not trigger session reset", () => }); }; + const expectPersistedSession = (sessionStore: Record): SessionEntry => { + const entry = sessionStore["main:user123"]; + if (!entry) { + throw new Error("Expected persisted session for main:user123"); + } + return entry; + }; + it("should NOT reset session when Provider is 'heartbeat'", async () => { // Setup: Create a session entry that is "stale" (older than idle timeout) const now = Date.now(); @@ -191,7 +199,7 @@ describe("initSessionState - heartbeat should not trigger session reset", () => expect(heartbeatResult.sessionEntry.lastInteractionAt).toBe(staleTime); const persistedAfterHeartbeat = loadSessionStore(storePath); - expect(persistedAfterHeartbeat["main:user123"]?.lastInteractionAt).toBe(staleTime); + expect(expectPersistedSession(persistedAfterHeartbeat).lastInteractionAt).toBe(staleTime); const userResult = await initSessionState({ ctx: createBaseCtx({ @@ -278,7 +286,7 @@ describe("initSessionState - heartbeat should not trigger session reset", () => expect(heartbeatResult.sessionId).toBe("legacy-idle-session"); const persistedAfterHeartbeat = loadSessionStore(storePath); - expect(persistedAfterHeartbeat["main:user123"]?.lastInteractionAt).toBeUndefined(); + expect(expectPersistedSession(persistedAfterHeartbeat).lastInteractionAt).toBeUndefined(); const userResult = await initSessionState({ ctx: createBaseCtx({