import { describe, test, expect } from 'bun:test'; import { FileMediaStore } from '../src/server.js'; describe('FileMediaStore', () => { test('a directory it cannot use fails each call with the reason, not the process', async () => { const store = new FileMediaStore('/proc/shade-cannot-write-here'); await new Promise((r) => setTimeout(r, 20)); // an unhandled rejection would surface here await expect(store.get('00'.repeat(16))).rejects.toThrow(/ENOENT|EACCES|EROFS|EPERM/); await expect(store.totalBytes()).rejects.toThrow(); }); }); describe('FileMediaStore bodies', () => { test('a body nobody finishes reading holds no file for the garbage collector to close', async () => { const proc = Bun.spawn(['bun', 'run', `${import.meta.dir}/fixtures/abandoned-body.ts`], { stdout: 'pipe', stderr: 'pipe' }); const [out, err, code] = await Promise.all([new Response(proc.stdout).text(), new Response(proc.stderr).text(), proc.exited]); expect(err).not.toContain('closed during garbage collection'); expect(out.trim()).toBe('survived'); expect(code).toBe(0); }, 30_000); });