切换到使用pg数据库
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import { afterEach, beforeEach, describe, expect, it } from "bun:test";
|
||||
|
||||
import { ConversationStore } from "../../src/conversations/store.js";
|
||||
import { RuntimeSessionStore } from "../../src/session/runtimeSessionStore.js";
|
||||
import { createTestDatabase } from "../helpers/postgres.js";
|
||||
|
||||
describe("RuntimeSessionStore", () => {
|
||||
let conversationStore: ConversationStore;
|
||||
let store: RuntimeSessionStore;
|
||||
let dispose: (() => Promise<void>) | undefined;
|
||||
|
||||
beforeEach(async () => {
|
||||
const testDb = await createTestDatabase();
|
||||
conversationStore = new ConversationStore(testDb.db);
|
||||
store = new RuntimeSessionStore(testDb.db);
|
||||
dispose = testDb.dispose;
|
||||
await Promise.all([conversationStore.initialize(), store.initialize()]);
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await dispose?.();
|
||||
});
|
||||
|
||||
it("stores and releases runtime sessions by runtime session id", async () => {
|
||||
await conversationStore.ensure({
|
||||
actorKey: "actor-1",
|
||||
projectId: "project-1",
|
||||
projectKey: "project-1",
|
||||
sessionId: "chat-session-1",
|
||||
userId: "user-1",
|
||||
});
|
||||
|
||||
await store.write({
|
||||
runtimeSessionId: "runtime-session-1",
|
||||
actorKey: "actor-1",
|
||||
allowLearningWrite: true,
|
||||
sessionId: "chat-session-1",
|
||||
learningMode: "interactive",
|
||||
projectId: "project-id-1",
|
||||
projectKey: "project-1",
|
||||
traceId: "trace-1",
|
||||
});
|
||||
|
||||
const runtimeContext = await store.read("runtime-session-1");
|
||||
expect(runtimeContext?.sessionId).toBe("chat-session-1");
|
||||
expect(runtimeContext?.runtimeSessionId).toBe("runtime-session-1");
|
||||
|
||||
await store.release("runtime-session-1");
|
||||
expect(await store.read("runtime-session-1")).toBeNull();
|
||||
expect((await store.read("runtime-session-1", { includeReleased: true }))?.releasedAt).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -1,51 +0,0 @@
|
||||
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");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user