Menu
popagent
publicLatest change 6edc7e928c57dab23c0973ed3f7ee70b3ebb72d5 - Initial popagent baseline by AkurAI Build
import { describe, expect, test } from "bun:test";
import { HookAuditStore } from "./hook-audit";
import type { HookRunRecord } from "./hooks";
describe("HookAuditStore", () => {
test("keeps the latest bounded session history and deletes it with the session", async () => {
const store = new HookAuditStore(3);
const sessionId = `hook-audit-${crypto.randomUUID()}`;
const started = Date.now();
try {
for (let index = 0; index < 4; index++) {
const timestamp = new Date(started + index * 1_000).toISOString();
const run: HookRunRecord = {
id: crypto.randomUUID(),
eventId: crypto.randomUUID(),
sessionId,
turnId: `turn-${index}`,
eventName: "Stop",
handlerId: `handler-${index}`,
startedAt: timestamp,
completedAt: timestamp,
durationMs: index,
status: "passed",
};
await store.record(run);
}
const retained = await store.listForSession(sessionId);
expect(retained.map((run) => run.handlerId)).toEqual([
"handler-1",
"handler-2",
"handler-3",
]);
expect(await store.storage.db.one<{ count: number }>(
"SELECT COUNT(*)::int AS count FROM popagent_hook_runs WHERE session_id = $1",
[sessionId],
)).toEqual({ count: 3 });
await store.deleteForSession(sessionId);
expect(await store.listForSession(sessionId)).toEqual([]);
} finally {
await store.deleteForSession(sessionId);
}
});
});