// Room at a clip's edges in umtool (release 36 lane E): render.room through // updateRender (the Look panel's writer), a clip's `room` through updateClip // and the clip editor's `room` operation, and what the clip editor's view // says of it. Synthetic. // // Run with: pnpm test:scripts import assert from "node:assert/strict"; import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises"; import { tmpdir } from "node:os"; import path from "node:path"; import test from "node:test"; import { MANIFEST_NAME, RenderRefused, manifestToken, updateClip, updateRender } from "./manifest.mjs"; import { clipEditorView, runClipEditorOp } from "./clipEditor.mjs"; import { SITELESS_LOOK } from "../projects/scaffold.mjs"; import { validateLook } from "umtool-report-to-video/look"; const manifest = (render = {}) => ({ schemaVersion: 1, slug: "room", provenance: { channelSlug: "chan" }, render: { width: 1920, height: 1080, fps: 30, palette: { bg: "#000000" }, ...render }, timeline: [ { type: "clip", id: "r001", video: "v1", start: 10, end: 20, cutStart: 11, cutEnd: 19, quote: "q" }, { type: "clip", id: "r002", video: "v1", start: 30, end: 40 }, ], }); async function project(render = {}) { const dir = await mkdtemp(path.join(tmpdir(), "umtool-room-")); await writeFile(path.join(dir, MANIFEST_NAME), JSON.stringify(manifest(render), null, 2) + "\n"); return { id: "reports/room", dir, kind: "report" }; } const read = async (dir) => JSON.parse(await readFile(path.join(dir, MANIFEST_NAME), "utf8")); test("the site-less seed's look: 0.22 s blur slides with room at both edges, and the build's validators take it", () => { assert.equal(SITELESS_LOOK.transition, 0.22); assert.equal(SITELESS_LOOK.transitionStyle, "blurslide"); assert.deepEqual(SITELESS_LOOK.room, { tail: true, head: true }); assert.deepEqual(validateLook({ render: { ...SITELESS_LOOK }, timeline: [] }), []); }); test("updateRender: render.room is a look key; null removes it; a bad one is refused in the build's words", async () => { const p = await project({ transition: 0.4 }); try { const r = await updateRender(p.dir, { room: { tail: true, head: false } }, { token: await manifestToken(p.dir) }); assert.deepEqual(r.look.room, { tail: true, head: false }); assert.deepEqual((await read(p.dir)).render.room, { tail: true, head: false }); await assert.rejects(updateRender(p.dir, { room: { tail: "on" } }), (e) => e instanceof RenderRefused && /render\.room\.tail must be true or false/.test(e.errors.join(";"))); await updateRender(p.dir, { room: null }); assert.equal((await read(p.dir)).render.room, undefined); } finally { await rm(p.dir, { recursive: true, force: true }); } }); test("updateClip: a clip's room -- false, per-edge booleans, null removes it; a bad one refused", async () => { const p = await project({ room: { tail: true, head: true } }); try { await updateClip(p.dir, "r001", { room: false }); assert.equal((await read(p.dir)).timeline[0].room, false); await updateClip(p.dir, "r001", { room: { tail: false } }); assert.deepEqual((await read(p.dir)).timeline[0].room, { tail: false }); await updateClip(p.dir, "r001", { room: null }); assert.equal("room" in (await read(p.dir)).timeline[0], false); await assert.rejects(updateClip(p.dir, "r001", { room: { middle: true } }), /room\.middle is not a setting here/); // The cut itself is untouched by a room edit. const e = (await read(p.dir)).timeline[0]; assert.deepEqual([e.cutStart, e.cutEnd], [11, 19]); } finally { await rm(p.dir, { recursive: true, force: true }); } }); test("the clip editor: the view says each clip's edges and the cut's room; the room op writes the override", async () => { const p = await project({ transition: 0.4, room: { tail: true, head: true } }); try { let view = await clipEditorView(p); assert.deepEqual(view.room, { tail: true, head: true, minGap: null, maxS: null, join: 0.4 }); assert.deepEqual(view.clips.map((c) => c.roomEdges), [{ tail: true, head: true }, { tail: true, head: true }]); assert.equal(view.clips[0].room, null); const off = await runClipEditorOp(p, { op: "room", clip: "r001", room: false, token: view.token }); view = off.view; assert.equal(view.clips[0].room, false); assert.equal(view.clips[0].roomEdges, null); const on = await runClipEditorOp(p, { op: "room", clip: "r001", room: null, token: view.token }); assert.equal(on.view.clips[0].roomEdges.tail, true); await assert.rejects(runClipEditorOp(p, { op: "room", clip: "r001", room: "yes" }), /room is false, \{tail\?, head\?\}, or null/); // A cut with no room: a clip can still ask for its own. const q = await project({ transition: 0 }); try { const v = await clipEditorView(q); assert.deepEqual(v.room, { tail: false, head: false, minGap: null, maxS: null, join: 0 }); const r = await runClipEditorOp(q, { op: "room", clip: "r002", room: { tail: true, head: true }, token: v.token }); assert.deepEqual(r.view.clips[1].roomEdges, { tail: true, head: true }); } finally { await rm(q.dir, { recursive: true, force: true }); } } finally { await rm(p.dir, { recursive: true, force: true }); } });