From 6a050a3c9b288295aa37c7d3e1b92dd226e6fce7 Mon Sep 17 00:00:00 2001 From: danpung2 Date: Wed, 11 Feb 2026 11:32:40 +0900 Subject: [PATCH] test(session-manager): add positive-path tests for todos and transcript --- src/tools/session-manager/storage.test.ts | 46 ++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/src/tools/session-manager/storage.test.ts b/src/tools/session-manager/storage.test.ts index 76507867a7..e2f6eec252 100644 --- a/src/tools/session-manager/storage.test.ts +++ b/src/tools/session-manager/storage.test.ts @@ -26,7 +26,7 @@ mock.module("./constants", () => ({ TOOL_NAME_PREFIX: "session_", })) -const { getAllSessions, getMessageDir, sessionExists, readSessionMessages, readSessionTodos, getSessionInfo } = +const { getAllSessions, getMessageDir, sessionExists, readSessionMessages, readSessionTodos, getSessionInfo, readSessionTranscript } = await import("./storage") const storage = await import("./storage") @@ -135,6 +135,50 @@ describe("session-manager storage", () => { expect(todos).toEqual([]) }) + test("readSessionTodos returns mapped todo items from matching JSON file", async () => { + // given + const sessionID = "ses_test123" + const todoData = [ + { id: "msg_001", content: "implement feature", status: "pending", priority: "high" }, + { id: "msg_002", content: "write tests", status: "completed", priority: "medium" }, + { id: "msg_003", content: "update docs", status: "in_progress", priority: "low" }, + ] + + writeFileSync(join(TEST_TODO_DIR, `${sessionID}_todos.json`), JSON.stringify(todoData)) + + // when + const todos = await readSessionTodos(sessionID) + + // then + expect(todos.length).toBe(3) + expect(todos[0]).toEqual({ id: "msg_001", content: "implement feature", status: "pending", priority: "high" }) + expect(todos[1]).toEqual({ id: "msg_002", content: "write tests", status: "completed", priority: "medium" }) + expect(todos[2]).toEqual({ id: "msg_003", content: "update docs", status: "in_progress", priority: "low" }) + }) + + test("readSessionTranscript returns count of non-empty lines", async () => { + // given + const sessionID = "ses_test123" + + const transcriptContent = [ + '{"role":"user","content":"implement feature"}', + "", + '{"role":"assistant","content":"feature implemented"}', + "", + "", + '{"role":"user","content":"write tests"}', + '{"role":"assistant","content":"tests added"}', + "", + ].join("\n") + writeFileSync(join(TEST_TRANSCRIPT_DIR, `${sessionID}.jsonl`), transcriptContent) + + // when + const lineCount = await readSessionTranscript(sessionID) + + // then + expect(lineCount).toBe(4) + }) + test("getSessionInfo returns null for non-existent session", async () => { // when const info = await getSessionInfo("ses_nonexistent")