46 lines
1.7 KiB
TypeScript
46 lines
1.7 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import { mkdtemp, rm } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { tmpdir } from "node:os";
|
|
import type { UserInteraction } from "@great-agent/agent-core";
|
|
import { createDataLayout, ensureDataLayout } from "../layout/data-layout";
|
|
import { FileInteractionRepository } from "./file-interaction-repository";
|
|
|
|
describe("FileInteractionRepository", () => {
|
|
test("在所属 Run 下持久化并恢复交互状态", async () => {
|
|
const root = await mkdtemp(join(tmpdir(), "great-agent-interactions-"));
|
|
try {
|
|
const layout = createDataLayout(root);
|
|
await ensureDataLayout(layout);
|
|
const repository = new FileInteractionRepository(layout);
|
|
const pending: UserInteraction = {
|
|
id: "interaction_1",
|
|
runId: "run_1",
|
|
conversationId: "conversation_1",
|
|
messageId: "message_1",
|
|
toolCallId: "tool_1",
|
|
toolArguments: "{}",
|
|
kind: "confirmation",
|
|
question: "确认吗?",
|
|
required: true,
|
|
status: "pending",
|
|
createdAt: "2026-08-14T00:00:00Z",
|
|
};
|
|
await repository.create(pending);
|
|
expect(await repository.findPendingByRun("run_1")).toEqual(pending);
|
|
await repository.update({
|
|
...pending,
|
|
status: "resolved",
|
|
answer: { kind: "confirmation", confirmed: true },
|
|
resolvedAt: "2026-08-14T00:01:00Z",
|
|
});
|
|
expect(
|
|
(await repository.listByConversation("conversation_1"))[0]?.status,
|
|
).toBe("resolved");
|
|
expect(await repository.findPendingByRun("run_1")).toBeNull();
|
|
} finally {
|
|
await rm(root, { recursive: true });
|
|
}
|
|
});
|
|
});
|