revert: remove unused Agent PostgreSQL persistence

This commit is contained in:
TJWater CI
2026-08-07 18:06:08 +08:00
parent 649af949c5
commit 2f267af7a3
39 changed files with 1330 additions and 2760 deletions
+47 -45
View File
@@ -1,53 +1,67 @@
import { afterEach, beforeEach, describe, expect, it } from "bun:test";
import { mkdtemp, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { ConversationStore } from "../../src/conversations/store.js";
import { SessionHistoryStore } from "../../src/history/store.js";
import { createTestDatabase } from "../helpers/postgres.js";
describe("SessionHistoryStore", () => {
let conversationStore: ConversationStore;
let tempDir: string;
let store: SessionHistoryStore;
let dispose: (() => Promise<void>) | undefined;
beforeEach(async () => {
const testDb = await createTestDatabase();
conversationStore = new ConversationStore(testDb.db);
store = new SessionHistoryStore(testDb.db);
dispose = testDb.dispose;
await Promise.all([conversationStore.initialize(), store.initialize()]);
tempDir = await mkdtemp(join(tmpdir(), "tjwater-history-"));
store = new SessionHistoryStore(tempDir);
await store.initialize();
});
afterEach(async () => {
await dispose?.();
await rm(tempDir, { force: true, recursive: true });
});
it("stores ordered turns for the durable conversation id", async () => {
await conversationStore.ensure({
actorKey: "actor-1",
projectId: "project-1",
projectKey: "project-1",
sessionId: "thread-1",
userId: "user-1",
});
it("falls back to legacy runtime-session transcripts by client session id and migrates on append", async () => {
await writeFile(
join(tempDir, "actor-1__project-1__runtime-session-1.json"),
JSON.stringify(
{
actorKey: "actor-1",
clientSessionId: "thread-1",
projectKey: "project-1",
sessionId: "runtime-session-1",
turns: [
{
id: "turn-1",
assistantMessage: "先检查泵站流量。",
timestamp: "2026-05-21T00:00:00.000Z",
toolCallCount: 1,
userMessage: "帮我看一下当前异常。",
},
],
updatedAt: "2026-05-21T00:00:00.000Z",
},
null,
2,
),
"utf8",
);
const first = await store.appendTurn(
const recentTurns = await store.getRecentTurns(
{
actorKey: "actor-1",
clientSessionId: "thread-1",
projectKey: "project-1",
sessionId: "thread-1",
},
{
assistantMessage: "先检查泵站流量。",
toolCallCount: 1,
userMessage: "帮我看一下当前异常。",
},
5,
);
expect(first.turns).toHaveLength(1);
expect(recentTurns).toHaveLength(1);
expect(recentTurns[0]?.userMessage).toBe("帮我看一下当前异常。");
const second = await store.appendTurn(
const transcript = await store.appendTurn(
{
actorKey: "actor-1",
clientSessionId: "thread-1",
projectKey: "project-1",
sessionId: "thread-1",
},
@@ -58,31 +72,15 @@ describe("SessionHistoryStore", () => {
},
);
expect(second.sessionId).toBe("thread-1");
expect(second.turns).toHaveLength(2);
expect(second.turns[0]?.userMessage).toBe("帮我看一下当前异常。");
expect(second.turns[1]?.assistantMessage).toBe("已经定位到 3 条疑似异常支路。");
expect(transcript.sessionId).toBe("thread-1");
expect(transcript.turns).toHaveLength(2);
});
it("clones only the kept prefix when forking a thread", async () => {
await conversationStore.ensure({
actorKey: "actor-2",
projectId: "project-2",
projectKey: "project-2",
sessionId: "thread-source",
userId: "user-2",
});
await conversationStore.ensure({
actorKey: "actor-2",
projectId: "project-2",
projectKey: "project-2",
sessionId: "thread-fork",
userId: "user-2",
});
await store.appendTurn(
{
actorKey: "actor-2",
clientSessionId: "thread-source",
projectKey: "project-2",
sessionId: "thread-source",
},
@@ -95,6 +93,7 @@ describe("SessionHistoryStore", () => {
await store.appendTurn(
{
actorKey: "actor-2",
clientSessionId: "thread-source",
projectKey: "project-2",
sessionId: "thread-source",
},
@@ -108,11 +107,13 @@ describe("SessionHistoryStore", () => {
const cloned = await store.cloneThread(
{
actorKey: "actor-2",
clientSessionId: "thread-source",
projectKey: "project-2",
sessionId: "thread-source",
},
{
actorKey: "actor-2",
clientSessionId: "thread-fork",
projectKey: "project-2",
sessionId: "thread-fork",
},
@@ -125,6 +126,7 @@ describe("SessionHistoryStore", () => {
const forkRecentTurns = await store.getRecentTurns(
{
actorKey: "actor-2",
clientSessionId: "thread-fork",
projectKey: "project-2",
sessionId: "thread-fork",
},