Files
photoreport/apps/api/test/render-process.test.ts
T
sparkandClaude Opus 5.5 64da90d2f2
ci / typescript (push) Successful in 9m59s
ci / rust (push) Successful in 21m53s
feat(develop): Revelar, the synced editor with one engine on web, desktop and server
engine/core renders with the LightCraft pipeline; engine/wasm runs it in the browser; workers/render replays op logs and renders originals natively. Op log with live fan-out and offline outbox; edited thumbnails and deliveries rendered from the original. Revelar page with Basic and optional modules, crop with aspect presets and straighten, before/after, undo/redo, copy/paste settings.

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

54 lines
2.6 KiB
TypeScript

import { mkdtemp, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import path from "node:path";
import exifr from "exifr";
import sharp from "sharp";
import { afterAll, describe, expect, it } from "vitest";
import { RenderProcess } from "../src/develop/engine.js";
import { closeRenderer, renderDelivery } from "../src/delivery/render.js";
const BIN = process.env.RENDER_TEST_BIN;
/** Runs the real Rust render worker (`cargo build --release -p photoreport-render`; RENDER_TEST_BIN=target/release/photoreport-render). */
describe.skipIf(!BIN)("render worker (real binary)", () => {
const engine = new RenderProcess({ bin: BIN ?? "" });
afterAll(async () => {
await engine.close();
await closeRenderer();
});
it("replays commands, and delivers an edited photo upright with its EXIF and our IPTC", async () => {
const replayed = await engine.replay(null, [
{ command: "develop.set", params: { values: { "light.exposure": 1 } } },
{ command: "develop.set", params: { values: { "light.nope": 1 } } },
{ command: "crop.set", params: { rect: { x0: 0, y0: 0, x1: 0.5, y1: 1 }, angle: 0, aspect: null } },
]);
expect(replayed.skipped).toEqual([1]);
expect(replayed.unedited).toBe(false);
const dir = await mkdtemp(path.join(tmpdir(), "pr-render-real-"));
try {
// 600x400 stored, EXIF orientation 6 (rotate 90°): upright it is 400x600.
const original = path.join(dir, "in.jpg");
const pixels = await sharp({ create: { width: 600, height: 400, channels: 3, background: { r: 60, g: 60, b: 60 } } })
.jpeg()
.withMetadata({ orientation: 6 })
.withExifMerge({ IFD0: { Make: "Canon", Model: "Canon EOS R1" } })
.toBuffer();
await writeFile(original, pixels);
const out = await renderDelivery(original, { title: "Rui Costa (ABC)" }, { longEdge: 4000, quality: 95 }, undefined, { engine, settings: replayed.settings });
const meta = await sharp(out).metadata();
// Upright 400x600, cropped to the left half: 200x600.
expect([meta.width, meta.height]).toEqual([200, 600]);
const tags = await exifr.parse(out, { iptc: true, xmp: true });
expect(tags.Orientation === undefined || tags.Orientation === 1 || tags.Orientation === "Horizontal (normal)").toBe(true);
expect(tags.Model).toBe("Canon EOS R1");
expect(tags.ObjectName ?? tags.title?.value ?? tags.title).toContain("Rui Costa");
const { channels } = await sharp(out).stats();
expect(channels[0]!.mean).toBeGreaterThan(75); // +1 EV brightened the grey (60 before)
} finally {
await rm(dir, { recursive: true, force: true });
}
});
});