import { existsSync } from "node:fs"; import { mkdtemp, rm, writeFile } from "node:fs/promises"; import { tmpdir } from "node:os"; import path from "node:path"; import sharp from "sharp"; import { describe, expect, it } from "vitest"; import { FacePool, FaceProcess } from "../src/faces/process.js"; /** * Talks to the real Rust worker when it is built and the models are present * (FACES_TEST_BIN, FACES_TEST_MODELS); skipped otherwise (CI builds the binary in the Rust job). */ const bin = process.env.FACES_TEST_BIN ?? ""; const models = process.env.FACES_TEST_MODELS ?? ""; const available = !!bin && !!models && existsSync(bin) && existsSync(models); describe.skipIf(!available)("face worker process", () => { it("answers over stdin/stdout, reports errors per photo and survives them", async () => { const dir = await mkdtemp(path.join(tmpdir(), "pr-fp-")); const file = path.join(dir, "empty.jpg"); await writeFile(file, await sharp({ create: { width: 640, height: 480, channels: 3, background: "#808080" } }).jpeg().toBuffer()); const engine = new FacePool([new FaceProcess({ bin, modelsDir: models, embedder: "sface" })]); try { expect(await engine.analyse(file)).toEqual({ width: 640, height: 480, faces: [] }); await expect(engine.analyse(path.join(dir, "missing.jpg"))).rejects.toThrow(); expect((await engine.analyse(file)).faces).toEqual([]); } finally { await engine.close(); await rm(dir, { recursive: true, force: true }); } }); });