diff --git a/src/hooks/agent-usage-reminder/constants.ts b/src/hooks/agent-usage-reminder/constants.ts index 17be086d..d49b92b5 100644 --- a/src/hooks/agent-usage-reminder/constants.ts +++ b/src/hooks/agent-usage-reminder/constants.ts @@ -1,7 +1,5 @@ import { join } from "node:path"; -import { getOpenCodeStorageDir } from "../../shared/data-path"; - -export const OPENCODE_STORAGE = getOpenCodeStorageDir(); +import { OPENCODE_STORAGE } from "../../shared"; export const AGENT_USAGE_REMINDER_STORAGE = join( OPENCODE_STORAGE, "agent-usage-reminder", diff --git a/src/hooks/atlas/index.test.ts b/src/hooks/atlas/index.test.ts index bf46e538..52025857 100644 --- a/src/hooks/atlas/index.test.ts +++ b/src/hooks/atlas/index.test.ts @@ -9,10 +9,31 @@ import { readBoulderState, } from "../../features/boulder-state" import type { BoulderState } from "../../features/boulder-state" - -import { MESSAGE_STORAGE } from "../../features/hook-message-injector" import { _resetForTesting, subagentSessions } from "../../features/claude-code-session-state" -import { createAtlasHook } from "./index" + +const TEST_STORAGE_ROOT = join(tmpdir(), `atlas-message-storage-${randomUUID()}`) +const TEST_MESSAGE_STORAGE = join(TEST_STORAGE_ROOT, "message") +const TEST_PART_STORAGE = join(TEST_STORAGE_ROOT, "part") + +mock.module("../../features/hook-message-injector/constants", () => ({ + OPENCODE_STORAGE: TEST_STORAGE_ROOT, + MESSAGE_STORAGE: TEST_MESSAGE_STORAGE, + PART_STORAGE: TEST_PART_STORAGE, +})) + +mock.module("../../shared/opencode-message-dir", () => ({ + getMessageDir: (sessionID: string) => { + const dir = join(TEST_MESSAGE_STORAGE, sessionID) + return existsSync(dir) ? dir : null + }, +})) + +mock.module("../../shared/opencode-storage-detection", () => ({ + isSqliteBackend: () => false, +})) + +const { createAtlasHook } = await import("./index") +const { MESSAGE_STORAGE } = await import("../../features/hook-message-injector") describe("atlas hook", () => { let TEST_DIR: string diff --git a/src/hooks/directory-agents-injector/constants.ts b/src/hooks/directory-agents-injector/constants.ts index 3dc2e19f..4adda871 100644 --- a/src/hooks/directory-agents-injector/constants.ts +++ b/src/hooks/directory-agents-injector/constants.ts @@ -1,7 +1,5 @@ import { join } from "node:path"; -import { getOpenCodeStorageDir } from "../../shared/data-path"; - -export const OPENCODE_STORAGE = getOpenCodeStorageDir(); +import { OPENCODE_STORAGE } from "../../shared"; export const AGENTS_INJECTOR_STORAGE = join( OPENCODE_STORAGE, "directory-agents", diff --git a/src/hooks/directory-readme-injector/constants.ts b/src/hooks/directory-readme-injector/constants.ts index f5d9f494..69e1fc5f 100644 --- a/src/hooks/directory-readme-injector/constants.ts +++ b/src/hooks/directory-readme-injector/constants.ts @@ -1,7 +1,5 @@ import { join } from "node:path"; -import { getOpenCodeStorageDir } from "../../shared/data-path"; - -export const OPENCODE_STORAGE = getOpenCodeStorageDir(); +import { OPENCODE_STORAGE } from "../../shared"; export const README_INJECTOR_STORAGE = join( OPENCODE_STORAGE, "directory-readme", diff --git a/src/hooks/interactive-bash-session/constants.ts b/src/hooks/interactive-bash-session/constants.ts index 9b2ce382..2c820591 100644 --- a/src/hooks/interactive-bash-session/constants.ts +++ b/src/hooks/interactive-bash-session/constants.ts @@ -1,7 +1,5 @@ import { join } from "node:path"; -import { getOpenCodeStorageDir } from "../../shared/data-path"; - -export const OPENCODE_STORAGE = getOpenCodeStorageDir(); +import { OPENCODE_STORAGE } from "../../shared"; export const INTERACTIVE_BASH_SESSION_STORAGE = join( OPENCODE_STORAGE, "interactive-bash-session", diff --git a/src/hooks/rules-injector/constants.ts b/src/hooks/rules-injector/constants.ts index 3f8b9f6f..6ac2cbbb 100644 --- a/src/hooks/rules-injector/constants.ts +++ b/src/hooks/rules-injector/constants.ts @@ -1,7 +1,5 @@ import { join } from "node:path"; -import { getOpenCodeStorageDir } from "../../shared/data-path"; - -export const OPENCODE_STORAGE = getOpenCodeStorageDir(); +import { OPENCODE_STORAGE } from "../../shared"; export const RULES_INJECTOR_STORAGE = join(OPENCODE_STORAGE, "rules-injector"); export const PROJECT_MARKERS = [ diff --git a/src/shared/opencode-message-dir.ts b/src/shared/opencode-message-dir.ts index 7e9e94dc..14736e4b 100644 --- a/src/shared/opencode-message-dir.ts +++ b/src/shared/opencode-message-dir.ts @@ -1,11 +1,9 @@ import { existsSync, readdirSync } from "node:fs" import { join } from "node:path" -import { getOpenCodeStorageDir } from "./data-path" +import { MESSAGE_STORAGE } from "./opencode-storage-paths" import { isSqliteBackend } from "./opencode-storage-detection" import { log } from "./logger" -const MESSAGE_STORAGE = join(getOpenCodeStorageDir(), "message") - export function getMessageDir(sessionID: string): string | null { if (!sessionID.startsWith("ses_")) return null if (isSqliteBackend()) return null diff --git a/src/tools/session-manager/storage.test.ts b/src/tools/session-manager/storage.test.ts index 7239a7e0..abeeb951 100644 --- a/src/tools/session-manager/storage.test.ts +++ b/src/tools/session-manager/storage.test.ts @@ -475,9 +475,9 @@ describe("session-manager storage - SDK path (beta mode)", () => { resetSqliteBackendCache: () => {}, })) - // Reset client to ensure "client not set" case is exercised - const { resetStorageClient } = await import("./storage") - resetStorageClient() + // Reset SDK client to ensure "client not set" case is exercised + const { setStorageClient } = await import("./storage") + setStorageClient(null as any) // Re-import without setting client const { readSessionMessages } = await import("./storage")