import fs from "node:fs"; import os from "node:os"; import path from "node:path"; import { afterEach, describe, expect, it } from "vitest"; import { ensureLinuxSharedLibraryAliases } from "./embedded-postgres-native.js"; describe("embedded Postgres native runtime", () => { const tempDirs: string[] = []; afterEach(() => { for (const tempDir of tempDirs.splice(0)) { fs.rmSync(tempDir, { recursive: true, force: true }); } }); it.runIf(process.platform !== "win32")("creates soname aliases for bundled patch-level shared libraries", async () => { const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "paperclip-embedded-pg-libs-")); tempDirs.push(tempDir); fs.writeFileSync(path.join(tempDir, "libicuuc.so.60.2"), ""); fs.writeFileSync(path.join(tempDir, "libicui18n.so.60.2"), ""); fs.writeFileSync(path.join(tempDir, "README.md"), ""); const created = await ensureLinuxSharedLibraryAliases(tempDir); expect(created.map((file) => path.basename(file)).sort()).toEqual([ "libicui18n.so.60", "libicuuc.so.60", ]); expect(fs.readlinkSync(path.join(tempDir, "libicuuc.so.60"))).toBe("libicuuc.so.60.2"); }); it.runIf(process.platform !== "win32")("is idempotent when aliases already exist", async () => { const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "paperclip-embedded-pg-libs-")); tempDirs.push(tempDir); fs.writeFileSync(path.join(tempDir, "libicuuc.so.60.2"), ""); await ensureLinuxSharedLibraryAliases(tempDir); const second = await ensureLinuxSharedLibraryAliases(tempDir); expect(second).toEqual([]); expect(fs.readlinkSync(path.join(tempDir, "libicuuc.so.60"))).toBe("libicuuc.so.60.2"); }); });