agent-r/test/store.test.ts

40 lines
1.4 KiB
TypeScript

import { mkdtempSync } from "node:fs";
import { tmpdir } from "node:os";
import path from "node:path";
import { describe, expect, test } from "vitest";
import { RunStore } from "../src/store.js";
describe("RunStore", () => {
test("creates runs, tasks, and snapshots", () => {
const tempDir = mkdtempSync(path.join(tmpdir(), "agent-r-store-"));
const store = new RunStore(path.join(tempDir, "state.sqlite"));
const run = store.createRun("Build something", tempDir);
store.replacePendingTasks(run.id, [
{
title: "Task 1",
objective: "Do work",
acceptanceCriteria: ["It works"],
verificationSteps: ["Run tests"],
allowedPaths: ["src"],
},
{
title: "Task 2",
objective: "Do more work",
acceptanceCriteria: ["It still works"],
verificationSteps: ["Run tests again"],
allowedPaths: ["tests"],
},
]);
const claimed = store.claimNextPendingTask(run.id);
expect(claimed?.status).toBe("in_progress");
store.completeTask(claimed!.id, "Finished");
store.addEvent(run.id, "test", "custom", "Recorded a test event.", { ok: true });
const snapshot = store.buildSnapshot(run.id);
expect(snapshot.pendingTasks).toHaveLength(1);
expect(snapshot.completedTasks).toHaveLength(1);
expect(snapshot.recentEvents.at(-1)?.kind).toBe("custom");
});
});