import { describe, expect, test } from "bun:test" import { canDisposeDirectory, pickDirectoriesToEvict } from "./global-sync/eviction" describe("pickDirectoriesToEvict", () => { test("keeps pinned stores and evicts idle stores", () => { const now = 5_000 const picks = pickDirectoriesToEvict({ stores: ["a", "b", "c", "d"], state: new Map([ ["a", { lastAccessAt: 1_000 }], ["b", { lastAccessAt: 4_900 }], ["c", { lastAccessAt: 4_800 }], ["d", { lastAccessAt: 3_000 }], ]), pins: new Set(["a"]), max: 2, ttl: 1_500, now, }) expect(picks).toEqual(["d", "c"]) }) }) describe("canDisposeDirectory", () => { test("rejects pinned or inflight directories", () => { expect( canDisposeDirectory({ directory: "dir", hasStore: true, pinned: true, booting: false, loadingSessions: false, }), ).toBe(false) expect( canDisposeDirectory({ directory: "dir", hasStore: true, pinned: false, booting: true, loadingSessions: false, }), ).toBe(false) expect( canDisposeDirectory({ directory: "dir", hasStore: true, pinned: false, booting: false, loadingSessions: true, }), ).toBe(false) }) test("accepts idle unpinned directory store", () => { expect( canDisposeDirectory({ directory: "dir", hasStore: true, pinned: false, booting: false, loadingSessions: false, }), ).toBe(true) }) })