Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion src/tools/session-manager/storage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down