From e683353cabf46f89e663f6098a7bad1a2f2035df Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 15 Feb 2026 15:42:23 +0000 Subject: [PATCH] refactor(test): share corrupt session fixture --- ...ing.runreplyagent-typing-heartbeat.test.ts | 52 ++++++++++++------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/src/auto-reply/reply/agent-runner.heartbeat-typing.runreplyagent-typing-heartbeat.test.ts b/src/auto-reply/reply/agent-runner.heartbeat-typing.runreplyagent-typing-heartbeat.test.ts index 751246d66..9c14f82c7 100644 --- a/src/auto-reply/reply/agent-runner.heartbeat-typing.runreplyagent-typing-heartbeat.test.ts +++ b/src/auto-reply/reply/agent-runner.heartbeat-typing.runreplyagent-typing-heartbeat.test.ts @@ -51,6 +51,27 @@ async function withTempStateDir(fn: (stateDir: string) => Promise): Promis } } +async function writeCorruptGeminiSessionFixture(params: { + stateDir: string; + sessionId: string; + persistStore: boolean; +}) { + const storePath = path.join(params.stateDir, "sessions", "sessions.json"); + const sessionEntry = { sessionId: params.sessionId, updatedAt: Date.now() }; + const sessionStore = { main: sessionEntry }; + + await fs.mkdir(path.dirname(storePath), { recursive: true }); + if (params.persistStore) { + await fs.writeFile(storePath, JSON.stringify(sessionStore), "utf-8"); + } + + const transcriptPath = sessions.resolveSessionTranscriptPath(params.sessionId); + await fs.mkdir(path.dirname(transcriptPath), { recursive: true }); + await fs.writeFile(transcriptPath, "bad", "utf-8"); + + return { storePath, sessionEntry, sessionStore, transcriptPath }; +} + describe("runReplyAgent typing (heartbeat)", () => { installRunReplyAgentTypingHeartbeatTestHooks(); @@ -404,17 +425,12 @@ describe("runReplyAgent typing (heartbeat)", () => { it("resets corrupted Gemini sessions and deletes transcripts", async () => { await withTempStateDir(async (stateDir) => { - const sessionId = "session-corrupt"; - const storePath = path.join(stateDir, "sessions", "sessions.json"); - const sessionEntry = { sessionId, updatedAt: Date.now() }; - const sessionStore = { main: sessionEntry }; - - await fs.mkdir(path.dirname(storePath), { recursive: true }); - await fs.writeFile(storePath, JSON.stringify(sessionStore), "utf-8"); - - const transcriptPath = sessions.resolveSessionTranscriptPath(sessionId); - await fs.mkdir(path.dirname(transcriptPath), { recursive: true }); - await fs.writeFile(transcriptPath, "bad", "utf-8"); + const { storePath, sessionEntry, sessionStore, transcriptPath } = + await writeCorruptGeminiSessionFixture({ + stateDir, + sessionId: "session-corrupt", + persistStore: true, + }); runEmbeddedPiAgentMock.mockImplementationOnce(async () => { throw new Error( @@ -484,14 +500,12 @@ describe("runReplyAgent typing (heartbeat)", () => { .spyOn(sessions, "saveSessionStore") .mockRejectedValueOnce(new Error("boom")); try { - const sessionId = "session-corrupt"; - const storePath = path.join(stateDir, "sessions", "sessions.json"); - const sessionEntry = { sessionId, updatedAt: Date.now() }; - const sessionStore = { main: sessionEntry }; - - const transcriptPath = sessions.resolveSessionTranscriptPath(sessionId); - await fs.mkdir(path.dirname(transcriptPath), { recursive: true }); - await fs.writeFile(transcriptPath, "bad", "utf-8"); + const { storePath, sessionEntry, sessionStore, transcriptPath } = + await writeCorruptGeminiSessionFixture({ + stateDir, + sessionId: "session-corrupt", + persistStore: false, + }); runEmbeddedPiAgentMock.mockImplementationOnce(async () => { throw new Error(