import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import { PondPermissionCache, PondPermissionContext } from './pond-permission-cache'; const CTX: PondPermissionContext = { grants: [], labelParents: {} }; describe('PondPermissionCache (issue #52)', () => { beforeEach(() => vi.useFakeTimers()); afterEach(() => vi.useRealTimers()); it('serves a stored context and drops it on invalidate', () => { const cache = new PondPermissionCache(); cache.set('pond-1', CTX); expect(cache.get('pond-1')).toBe(CTX); cache.invalidate('pond-1'); expect(cache.get('pond-1')).toBeUndefined(); }); it('invalidating one pond leaves others untouched', () => { const cache = new PondPermissionCache(); cache.set('pond-1', CTX); cache.set('pond-2', CTX); cache.invalidate('pond-1'); expect(cache.get('pond-2')).toBe(CTX); }); it('expires entries after the TTL (multi-process staleness bound)', () => { const cache = new PondPermissionCache(); cache.set('pond-1', CTX); vi.advanceTimersByTime(PondPermissionCache.TTL_MS - 1); expect(cache.get('pond-1')).toBe(CTX); vi.advanceTimersByTime(2); expect(cache.get('pond-1')).toBeUndefined(); }); });