切换到使用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();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user