import { afterEach, beforeEach, describe, expect, it } from "bun:test"; import { mkdtemp, rm } from "node:fs/promises"; import { tmpdir } from "node:os"; import { join } from "node:path"; import { buildToolSessionScopeKey, ToolSessionContextStore, } from "../../src/session/toolContextStore.js"; describe("ToolSessionContextStore", () => { let tempDir: string; let store: ToolSessionContextStore; beforeEach(async () => { tempDir = await mkdtemp(join(tmpdir(), "tjwater-tool-context-")); store = new ToolSessionContextStore(tempDir); await store.initialize(); }); afterEach(async () => { await rm(tempDir, { force: true, recursive: true }); }); it("writes interactive aliases under scoped session keys", async () => { const sessionScopeKey = buildToolSessionScopeKey( "actor-1", "project-1", "chat-session-1", ); await store.write({ actorKey: "actor-1", allowLearningWrite: true, clientSessionId: "chat-session-1", learningMode: "interactive", projectId: "project-id-1", projectKey: "project-1", sessionId: "runtime-session-1", sessionScopeKey, traceId: "trace-1", }); const runtimeContext = await store.read("runtime-session-1"); const scopedContext = await store.read(sessionScopeKey); expect(runtimeContext?.clientSessionId).toBe("chat-session-1"); expect(scopedContext?.sessionScopeKey).toBe(sessionScopeKey); expect(scopedContext?.sessionId).toBe("runtime-session-1"); }); });