Files
photoreport/apps/api/test/face-process.test.ts
T
sparkandClaude Opus 5.5 3f702c4e23
ci / rust (push) Successful in 2m3s
ci / typescript (push) Successful in 4m26s
feat(faces): detect, group and name players by face; squad reference photos
Faces end to end (YuNet + AuraFace worker in Rust, grouping per event, confirm/merge/ignore, suggestions from known people, loupe boxes), blurred faces kept out of groups (sharpness gate tuned on a real football match), and reference photos for the squad.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01HT6iXLYUUp9pJz5Kza9xCW
2026-10-11 18:41:07 +01:00

33 lines
1.5 KiB
TypeScript

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 });
}
});
});