test(session-manager): fix storage tests by mocking message-dir dependency
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, test, expect, beforeEach, afterEach, mock } from "bun:test"
|
||||
import { mkdirSync, writeFileSync, rmSync, existsSync } from "node:fs"
|
||||
import { mkdirSync, writeFileSync, rmSync, existsSync, readdirSync } from "node:fs"
|
||||
import { join } from "node:path"
|
||||
import { tmpdir } from "node:os"
|
||||
import { randomUUID } from "node:crypto"
|
||||
@@ -38,6 +38,27 @@ mock.module("../../shared/opencode-storage-paths", () => ({
|
||||
SESSION_STORAGE: TEST_SESSION_STORAGE,
|
||||
}))
|
||||
|
||||
mock.module("../../shared/opencode-message-dir", () => ({
|
||||
getMessageDir: (sessionID: string) => {
|
||||
if (!sessionID.startsWith("ses_")) return null
|
||||
if (/[/\\]|\.\./.test(sessionID)) return null
|
||||
if (!existsSync(TEST_MESSAGE_STORAGE)) return null
|
||||
|
||||
const directPath = join(TEST_MESSAGE_STORAGE, sessionID)
|
||||
if (existsSync(directPath)) {
|
||||
return directPath
|
||||
}
|
||||
|
||||
for (const dir of readdirSync(TEST_MESSAGE_STORAGE)) {
|
||||
const nestedPath = join(TEST_MESSAGE_STORAGE, dir, sessionID)
|
||||
if (existsSync(nestedPath)) {
|
||||
return nestedPath
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
},
|
||||
}))
|
||||
const { getAllSessions, getMessageDir, sessionExists, readSessionMessages, readSessionTodos, getSessionInfo } =
|
||||
await import("./storage")
|
||||
|
||||
@@ -71,8 +92,7 @@ describe("session-manager storage", () => {
|
||||
expect(sessions).toEqual([])
|
||||
})
|
||||
|
||||
// FIXME: Flaky test - fails when run in isolation due to mock.module() order dependency
|
||||
test.skip("getMessageDir finds session in direct path", () => {
|
||||
test("getMessageDir finds session in direct path", () => {
|
||||
// given
|
||||
const sessionID = "ses_test123"
|
||||
const sessionPath = join(TEST_MESSAGE_STORAGE, sessionID)
|
||||
@@ -94,8 +114,7 @@ describe("session-manager storage", () => {
|
||||
expect(exists).toBe(false)
|
||||
})
|
||||
|
||||
// FIXME: Flaky test - fails when run in isolation due to mock.module() order dependency
|
||||
test.skip("sessionExists returns true for existing session", async () => {
|
||||
test("sessionExists returns true for existing session", async () => {
|
||||
// given
|
||||
const sessionID = "ses_exists"
|
||||
const sessionPath = join(TEST_MESSAGE_STORAGE, sessionID)
|
||||
@@ -117,8 +136,7 @@ describe("session-manager storage", () => {
|
||||
expect(messages).toEqual([])
|
||||
})
|
||||
|
||||
// FIXME: Flaky test - fails when run in isolation due to mock.module() order dependency
|
||||
test.skip("readSessionMessages sorts messages by timestamp", async () => {
|
||||
test("readSessionMessages sorts messages by timestamp", async () => {
|
||||
// given
|
||||
const sessionID = "ses_test123"
|
||||
const sessionPath = join(TEST_MESSAGE_STORAGE, sessionID)
|
||||
@@ -158,8 +176,7 @@ describe("session-manager storage", () => {
|
||||
expect(info).toBeNull()
|
||||
})
|
||||
|
||||
// FIXME: Flaky test - fails when run in isolation due to mock.module() order dependency
|
||||
test.skip("getSessionInfo aggregates session metadata correctly", async () => {
|
||||
test("getSessionInfo aggregates session metadata correctly", async () => {
|
||||
// given
|
||||
const sessionID = "ses_test123"
|
||||
const sessionPath = join(TEST_MESSAGE_STORAGE, sessionID)
|
||||
|
||||
Reference in New Issue
Block a user