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