// Fill by hand (release 32 R2): every empty media field offered, and what a // person writes saved through the manifest writer with no drafted mark (the // operator's: no draft replaces it). Over the S0 kit's synthetic manifests. // // Run with: pnpm test:scripts import assert from "node:assert/strict"; import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises"; import { readFileSync } from "node:fs"; import { tmpdir } from "node:os"; import path from "node:path"; import test from "node:test"; import { fileURLToPath } from "node:url"; import { MANIFEST_NAME } from "./manifest.mjs"; import { applyHandFill, handFillView } from "./hand-fill.mjs"; const HERE = path.dirname(fileURLToPath(import.meta.url)); const kit = (name) => JSON.parse(readFileSync(path.join(HERE, `../../../common/testing/draft/manifests/${name}.video.manifest.json`), "utf8")); async function project(t, manifest) { const dir = await mkdtemp(path.join(tmpdir(), "umtool-hand-fill-")); t.after(() => rm(dir, { recursive: true, force: true })); await writeFile(path.join(dir, MANIFEST_NAME), JSON.stringify(manifest, null, 2) + "\n"); return { dir, read: async () => JSON.parse(await readFile(path.join(dir, MANIFEST_NAME), "utf8")) }; } test("handFillView: each empty field once — clips' on-screen text, the publish texts; the threads as they stand", () => { const v = handFillView(kit("full")); assert.deepEqual( v.empty.map((f) => f.address), ["onscreen/c02", "onscreen/c03", "onscreen/c05", "onscreen/c06", "onscreen/c07", "publish.youtube", "publish.x", "publish.bluesky"], ); assert.equal(v.deck, true); assert.equal(v.flips, null); assert.deepEqual(v.threads.list.map((x) => x.id), ["bakery", "contest"]); assert.equal(v.threads.clips.c04, "contest"); assert.equal(v.clips.length, 7); // A teaser with no lines is offered; a cut with no deck says so. const m = kit("full"); m.timeline.find((e) => e.id === "fin").lines = []; delete m.render.chrome; const w = handFillView(m); assert.ok(w.empty.some((f) => f.address === "teaser/fin/lines")); assert.deepEqual([w.deck, w.threads], [false, null]); }); test("applyHandFill: written unmarked (the operator's), in the field order; a refusal stops and is said", async (t) => { const p = await project(t, kit("full")); const out = await applyHandFill(p.dir, [ { field: "publish.youtube", value: { title: "The bakery and the contest", description: "Synthetic description." } }, { field: "onscreen", entry: "c02", value: { title: "The oven" } }, { field: "publish.x", value: { post: "A synthetic post." } }, ]); assert.equal(out.refused, null); assert.deepEqual(out.written, ["onscreen/c02", "publish.youtube", "publish.x"]); const m = await p.read(); assert.deepEqual(m.timeline.find((e) => e.id === "c02").onscreen, { title: "The oven" }); assert.equal(m.publish.youtube.title, "The bakery and the contest"); assert.equal(m.drafted?.["publish.youtube"], undefined); assert.equal(m.timeline.find((e) => e.id === "c02").drafted?.onscreen, undefined); // Now filled: no longer offered. assert.deepEqual(handFillView(m).empty.map((f) => f.address).filter((a) => a.startsWith("publish")), ["publish.bluesky"]); // Threads by hand, with each clip's thread; then a pair of flips is refused (a cut has one or the other). const th = await applyHandFill(p.dir, [{ field: "render.chrome.threads", value: { list: [{ id: "all", label: "All of it" }], clips: { c01: "all", c02: "all" } } }]); assert.equal(th.refused, null); const m2 = await p.read(); assert.deepEqual(m2.timeline.filter((e) => e.thread).map((e) => [e.id, e.thread]), [["c01", "all"], ["c02", "all"]]); const bad = await applyHandFill(p.dir, [ { field: "onscreen", entry: "c03", value: { title: "Kept" } }, { field: "render.chrome.flips", value: { pairs: [{ id: "p1", topic: "Ovens", then: { entry: "c01", when: "2019", words: "a" }, now: { entry: "c02", when: "2025", words: "b" } }] } }, ]); assert.deepEqual(bad.written, ["onscreen/c03"]); assert.equal(bad.refused?.field, "render.chrome.flips"); assert.ok(bad.refused?.error); await assert.rejects(applyHandFill(p.dir, [{ field: "timeline", value: [] }]), /not a field filled by hand/); await assert.rejects(applyHandFill(p.dir, []), /nothing to write/); });