import { describe, expect, it, vi } from 'vitest' import { enforceArtifactRetention } from './artifact-retention' describe('artifact retention', () => { it('removes only store-selected expired bytes and finalizes their metadata', async () => { const artifacts = [ { id: 'artifact-1', workspaceId: 'workspace-1', storageKey: 'a'.repeat(64), }, { id: 'artifact-2', workspaceId: 'workspace-1', storageKey: 'b'.repeat(64), }, ] const store = { listExpired: vi.fn().mockResolvedValue(artifacts), finalizeDeletion: vi.fn().mockResolvedValue(true), } const storage = { deleteIfPresent: vi .fn() .mockResolvedValueOnce(true) .mockResolvedValueOnce(false), } await expect( enforceArtifactRetention({ store, storage, now: new Date('2026-07-27T12:00:00.000Z'), }), ).resolves.toEqual({ scanned: 2, deleted: 1, missing: 1 }) expect(store.finalizeDeletion).toHaveBeenCalledTimes(2) }) })