AkurAI Build
Menu

popagent

public

Latest change 62f685314a2172a23c717ce4fe12027a662a406c - Make tests clean up persistent state by AkurAI Build

import { beforeAll, describe, expect, test } from "bun:test";
import { SessionStore } from "./sessions";

const store = new SessionStore();

beforeAll(() => store.init());

describe("SessionStore", () => {
  test("creates, lists, updates, and reloads sessions", async () => {
    const created = await store.create("cx/gpt-5.6-sol");
    try {
      expect(await store.list()).toContainEqual(
        expect.objectContaining({ id: created.id, title: "New chat", model: "cx/gpt-5.6-sol" }),
      );

      const messages = [
        { id: "user-1", role: "user", parts: [{ type: "text", text: "Plan a trip to Oslo" }] },
        { id: "assistant-1", role: "assistant", parts: [{ type: "text", text: "Sure." }] },
      ];
      await store.save(created.id, { model: "cx/gpt-5.6-sol", messages, expectedRevision: created.revision });

      expect(await store.get(created.id)).toEqual(
        expect.objectContaining({ id: created.id, title: "Plan a trip to Oslo", messages }),
      );
    } finally {
      await store.delete(created.id);
    }
  });

  test("returns undefined for an unknown session", async () => {
    expect(await store.get("missing")).toBeUndefined();
  });
});