import { describe, it, expect, vi } from "vitest";
import { phasePruneRevisions, REVISIONS_KEPT_PER_ENTITY, } from "../dream-cycle/phase-prune-revisions.js";
function fakeSession(prunedCount) {
    const calls = [];
    const session = {
        run: vi.fn(async (query, params) => {
            calls.push({ query, params });
            return {
                records: [
                    {
                        get: (key) => (key === "pruned" ? prunedCount : null),
                    },
                ],
            };
        }),
    };
    return { session, calls };
}
describe("phasePruneRevisions", () => {
    it("returns the pruned count as both proposed and applied (no operator review)", async () => {
        const { session } = fakeSession(7);
        const result = await phasePruneRevisions({
            accountId: "acc-1",
            session,
            config: {},
        });
        expect(result.phase).toBe(5);
        expect(result.name).toBe("prune-revisions");
        expect(result.proposed).toBe(7);
        expect(result.applied).toBe(7);
        expect(result.deferred).toBe(0);
        expect(result.extra?.keptPerEntity).toBe(REVISIONS_KEPT_PER_ENTITY);
    });
    it("scopes the query to the supplied accountId and uses the keep cap", async () => {
        const { session, calls } = fakeSession(0);
        await phasePruneRevisions({
            accountId: "acc-2",
            session,
            config: {},
        });
        expect(calls).toHaveLength(1);
        expect(calls[0].params.accountId).toBe("acc-2");
        expect(calls[0].params.keep).toBe(REVISIONS_KEPT_PER_ENTITY);
        expect(calls[0].query).toContain("DETACH DELETE old");
        expect(calls[0].query).toContain("ORDER BY r.writtenAt DESC");
    });
    it("kept-per-entity cap is 20 (Task 391 spec)", () => {
        expect(REVISIONS_KEPT_PER_ENTITY).toBe(20);
    });
});
//# sourceMappingURL=phase-prune-revisions.test.js.map