AkurAI Build
Menu

popagent

public

Latest change 99d92c06b60aa592036b546fad6f57fa7b899194 - Stop learning from runs that ran out of steps, and sweep every checkout by AkurAI Build

import { describe, expect, test } from "bun:test";
import { runMaintenanceOnce } from "./maintenance";

describe("runMaintenanceOnce", () => {
  test("prunes episodes and cleans hook audit", async () => {
    const calls: string[] = [];
    await runMaintenanceOnce({
      memory: { pruneEpisodes: async () => { calls.push("pruneEpisodes"); } },
      audit: { cleanupAll: async () => { calls.push("cleanupAll"); } },
      observability: { prune: async () => { calls.push("pruneObservability"); } },
    });
    expect(calls.sort()).toEqual(["cleanupAll", "pruneEpisodes", "pruneObservability"]);
  });

  test("refreshes every registered workspace checkout", async () => {
    const synced: string[] = [];
    await runMaintenanceOnce({
      memory: { pruneEpisodes: async () => undefined as never },
      audit: { cleanupAll: async () => undefined as never },
      workspaces: {
        list: async () => [{ id: "default" }, { id: "mail-1" }, { id: "monitor-1" }] as never,
        sync: async (workspaceId: string) => { synced.push(workspaceId); },
      },
    });
    expect(synced).toEqual(["default", "mail-1", "monitor-1"]);
  });

  test("propagates store failures to the caller", async () => {
    await expect(runMaintenanceOnce({
      memory: { pruneEpisodes: async () => { throw new Error("prune failed"); } },
      audit: { cleanupAll: async () => undefined },
    })).rejects.toThrow("prune failed");
  });
});