import { expect, test } from "bun:test"; import { mkdtemp, readFile, rm } from "node:fs/promises"; import { tmpdir } from "node:os"; import { join } from "node:path"; import { newDatabase, newTrack } from "../src/model.ts"; import { writePdb } from "../src/pdb/writer.ts"; import { PAGE_SIZE } from "../src/pdb/pager.ts"; test("writes a multi-page-aligned pdb file", async () => { const dir = await mkdtemp(join(tmpdir(), "maple-ts-")); try { const db = newDatabase(); db.artists.push({ id: 1, name: "A" }); db.albums.push({ id: 1, name: "Alb", artist_id: 1 }); db.tracks.push(newTrack({ id: 1, title: "T", artist_id: 1, album_id: 1, filename: "t.mp3", file_path: "/Contents/A/Alb/t.mp3", })); db.playlist_nodes.push({ id: 1, parent_id: 0, sort_order: 1, name: "P", is_folder: false }); db.playlist_entries.push({ playlist_id: 1, track_id: 1, entry_index: 1 }); const out = join(dir, "export.pdb"); await writePdb(db, out); const buf = await readFile(out); expect(buf.length % PAGE_SIZE).toBe(0); expect(buf.length).toBeGreaterThanOrEqual(PAGE_SIZE * 6); } finally { await rm(dir, { recursive: true, force: true }); } });