import { describe, expect, it } from "vitest";
import { createDimSdkPersistence } from "../src/dimsdk/cli/persistence.ts";

describe("dimsdk sessions delete", () => {
  it("deletes via backend even before store is created", async () => {
    const destroyed: string[] = [];
    const backend = {
      list: async () => [],
      get: async () => null,
      create: async () => ({
        id: "new",
        state: {},
        context: { messages: [], messageCount: 0, toolCallCount: 0 },
        stats: { usage: {}, responseCount: 0 },
      }),
      destroy: async (id: string) => {
        destroyed.push(id);
      },
    } as const;

    const { sessions } = createDimSdkPersistence({
      cacheFile: "/tmp/dimsdk-cache.json",
      cache: { version: 1, updatedAt: 0 },
      configFile: "/tmp/dimsdk-config.json",
      config: { version: 1, updatedAt: 0 },
      toolsFile: "/tmp/dimsdk-tools.json",
      tools: { version: 1, updatedAt: 0 },
      sessionsBackend: backend as any,
    });

    expect(sessions).toBeTruthy();
    await sessions!.delete("s1");
    expect(destroyed).toEqual(["s1"]);
  });
});
