// `umtool export --format chapters` on a cut whose deck has markers: its // top-level sections at the second each one's first segment starts (the deck // schedule's), YouTube's rules kept, what was merged said -- the hand // script's rows for Ember draft-24 (report-to-video/fixtures). A deck without // markers lists every entry, as it always did. // // Run with: pnpm test:scripts import assert from "node:assert/strict"; import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import path from "node:path"; import test from "node:test"; import { exportProject } from "./export.mjs"; const EMBER = JSON.parse(readFileSync(new URL("../../report-to-video/fixtures/ember-draft-24-chapters.json", import.meta.url), "utf8")); const FFMETA = (n) => [";FFMETADATA1", "", ...Array.from({ length: n }, (_, i) => ["[CHAPTER]", "TIMEBASE=1/1000", `START=${i * 5000}`, `END=${(i + 1) * 5000}`, `title=Entry ${i + 1}`, ""]).flat()].join("\n"); /** A built cut: the fixture's segments as its timeline (the brand intro is the schedule's own), its deck's markers. */ function project(root, deck) { const dir = path.join(root, `p-${Math.random().toString(36).slice(2)}`); mkdirSync(path.join(dir, "out", "sourced"), { recursive: true }); const timeline = EMBER.segments.slice(1).map(([id], i) => ({ id, type: "clip", video: `v${i}`, start: 0, end: 5 })); writeFileSync(path.join(dir, "video.manifest.json"), JSON.stringify({ slug: "s", title: "A cut", provenance: { siteOrigin: "https://example.test", channelSlug: "chan" }, render: { fps: 30, transition: EMBER.transition, chrome: { engine: "hyperframes", layout: "deck", deck } }, timeline, })); writeFileSync(path.join(dir, "out", "sourced", "chapters.ffmeta"), FFMETA(timeline.length)); writeFileSync(path.join(dir, "out", "sourced", "schedule.json"), JSON.stringify({ version: 1, kind: "deck", fps: 30, transition: EMBER.transition, total: EMBER.total, segments: EMBER.segments.map(([id, start]) => ({ id, start })), })); return dir; } test("chapters from the deck's markers: Ember draft-24's 13 rows, the opening titled by --first or deck.sectionTitle.first", async (t) => { const root = mkdtempSync(path.join(tmpdir(), "umtool-export-chapters-")); t.after(() => rmSync(root, { recursive: true, force: true })); const dir = project(root, { markers: EMBER.markers }); const r = await exportProject(dir, "chapters", { first: EMBER.first }); assert.deepEqual(r.text.trimEnd().split("\n"), EMBER.expected); assert.deepEqual(r.notes, []); // The deck's own first section's title does the same. const titled = project(root, { markers: EMBER.markers, sectionTitle: { first: EMBER.first } }); assert.deepEqual((await exportProject(titled, "chapters")).text.trimEnd().split("\n"), EMBER.expected); // None: the first section takes 0:00, and the note says so. const bare = await exportProject(dir, "chapters"); assert.deepEqual(bare.text.trimEnd().split("\n"), ["0:00 Sex appeal", ...EMBER.expected.slice(2)]); assert.match(bare.notes.join("\n"), /the opening has no title/); }); test("chapters: subsections left out; a deck without markers lists every entry as before", async (t) => { const root = mkdtempSync(path.join(tmpdir(), "umtool-export-chapters-")); t.after(() => rmSync(root, { recursive: true, force: true })); const subs = project(root, { markers: [...EMBER.markers, { after: "tj1", label: "A subsection", level: 2 }] }); const r = await exportProject(subs, "chapters", { first: EMBER.first }); assert.deepEqual(r.text.trimEnd().split("\n"), EMBER.expected); const plain = project(root, {}); const lines = (await exportProject(plain, "chapters")).text.trimEnd().split("\n"); assert.equal(lines.length, EMBER.segments.length - 1); assert.match(lines[0], /^00:00 /); }); test("a cut that opens on the brand intro: the build folded its chapter into the next, and the export reads it so (no 'different cut' refusal)", async (t) => { const root = mkdtempSync(path.join(tmpdir(), "umtool-export-chapters-")); t.after(() => rmSync(root, { recursive: true, force: true })); const dir = path.join(root, "intro"); mkdirSync(path.join(dir, "out", "sourced"), { recursive: true }); const timeline = [{ id: "brand-intro", type: "intro" }, ...[1, 2, 3].map((i) => ({ id: `c${i}`, type: "clip", video: `v${i}`, start: 0, end: 5 }))]; writeFileSync(path.join(dir, "video.manifest.json"), JSON.stringify({ slug: "s", title: "A cut", provenance: { siteOrigin: "https://example.test", channelSlug: "chan" }, render: { fps: 30 }, timeline })); writeFileSync(path.join(dir, "out", "sourced", "chapters.ffmeta"), FFMETA(3)); // 0, 5, 10: c1 (with the intro), c2, c3 const lines = (await exportProject(dir, "chapters")).text.trimEnd().split("\n"); assert.deepEqual(lines.map((l) => l.slice(0, 5)), ["00:00", "00:00", "00:05", "00:10"]); // One chapter short of the entries WITHOUT an intro is still another cut. writeFileSync(path.join(dir, "video.manifest.json"), JSON.stringify({ slug: "s", title: "A cut", render: { fps: 30 }, timeline: timeline.slice(1).concat({ id: "c4", type: "clip", video: "v4", start: 0, end: 5 }) })); await assert.rejects(exportProject(dir, "chapters"), /describes a different cut/); }); test("chapterMarkersOf: the deck's markers, and the opening's title only from a sectionTitle object", async () => { const { chapterMarkersOf } = await import("umtool-report-to-video/build-video"); const deck = (d) => ({ render: { chrome: { deck: d } } }); assert.deepEqual(chapterMarkersOf(deck({ markers: EMBER.markers, sectionTitle: { first: "Open" } })), { markers: EMBER.markers, first: "Open" }); assert.deepEqual(chapterMarkersOf(deck({ markers: EMBER.markers, sectionTitle: false })), { markers: EMBER.markers, first: null }); assert.deepEqual(chapterMarkersOf({}), { markers: null, first: null }); });