commit 7a4aafd567f13423bdb04e73e51a44f19c870536
parent b5e33d680f2684753ba1d1b3afb7ae98216027f7
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Mon, 26 Oct 2026 07:22:16 -0400
Takes: a finished take's render is a build variants can encode; a window's log says what timed it
makeTake leaves the render in the take's out/ as <slug>.mp4 too, a hard link of
preview.mp4 (unlinked before a rebuild renders, so a build writing in place never
writes into the old preview). variantsState/builtTakes fall back to a take's
finished preview.mp4 (buildFileOf), and `umtool variants --take` and Deliver's
Make variants point the encoder at it with --source. windowEntries names the
entries the schedule did not time; the take log says whether the schedule or the
estimates timed the window, and whether the schedule is older than the manifest.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
9 files changed, 184 insertions(+), 32 deletions(-)
diff --git a/umtool/app/api/report/deliver/route.ts b/umtool/app/api/report/deliver/route.ts
@@ -13,7 +13,7 @@ import { readClipDetail } from "@/lib/projects/report.mjs";
import { projectRef } from "@/lib/projects";
import type { Step } from "@/lib/trim";
import { refuseCaller } from "@/lib/report/caller";
-import { outDirOf, variantsState } from "@/lib/report/variantsView.mjs";
+import { buildFileOf, outDirOf, variantsState } from "@/lib/report/variantsView.mjs";
import { kindMakesTakes } from "@/lib/projects/kinds.mjs";
import { readManifest } from "@/lib/projects/report.mjs";
@@ -245,7 +245,9 @@ async function startVariants(body: Record<string, unknown>) {
return Response.json({ error: `a job is already running (${running.kind})`, running: jobView(running) }, { status: 409 });
}
try {
- const job = startJob(`variants ${project.id}${take ? ` (take ${take})` : ""}`, variantsSteps(project, outDirOf(project, take)), { project: project.id });
+ // A take whose render is only its preview.mp4: the encoder is pointed at it.
+ const source = state.built.from === "preview" ? ((await buildFileOf(project, state.slug, take))?.abs ?? null) : null;
+ const job = startJob(`variants ${project.id}${take ? ` (take ${take})` : ""}`, variantsSteps(project, outDirOf(project, take), process.env, { source }), { project: project.id });
return Response.json({ ok: true, action: "variants", take, job: jobView(job) }, { headers: { "cache-control": "no-store" } });
} catch (e) {
return Response.json({ error: e instanceof Error ? e.message : String(e) }, { status: 409 });
diff --git a/umtool/e2e/fixtures/variants.e2e.mjs b/umtool/e2e/fixtures/variants.e2e.mjs
@@ -14,7 +14,10 @@ const slug = manifest.slug;
const ladder = Array.isArray(manifest.render?.variants)
? manifest.render.variants
: [{ name: "master" }, { name: "1080p", height: 1080, crf: 22 }, { name: "720p", height: 720, crf: 23 }, { name: "fit24", maxMiB: 24 }];
-const source = await readFile(path.join(outDir, `${slug}.mp4`));
+// --source <file>: a take whose render is only its preview.mp4 (variantsView buildFileOf).
+const at = process.argv.indexOf("--source");
+const srcFile = at > 0 && process.argv[at + 1] ? path.resolve(process.argv[at + 1]) : path.join(outDir, `${slug}.mp4`);
+const source = await readFile(srcFile);
const items = [];
for (const [i, v] of ladder.entries()) {
const bytes = v.name === "master" ? source : source.subarray(0, Math.max(1, Math.floor(source.length / (i + 1))));
@@ -23,4 +26,4 @@ for (const [i, v] of ladder.entries()) {
items.push({ name: v.name, path: `${slug}.${v.name}.mp4`, width: Math.round((height * 16) / 9), height, bytes: bytes.length, kbps: 1000 });
console.log(`variant ${v.name}: ${bytes.length} bytes (stub)`);
}
-await writeFile(path.join(outDir, "variants.json"), JSON.stringify({ at: new Date().toISOString(), source: `${slug}.mp4`, items }, null, 2) + "\n");
+await writeFile(path.join(outDir, "variants.json"), JSON.stringify({ at: new Date().toISOString(), source: path.basename(srcFile), items }, null, 2) + "\n");
diff --git a/umtool/lib/report/driver.mjs b/umtool/lib/report/driver.mjs
@@ -627,22 +627,27 @@ export function rebuildReportSteps(project, variants) {
* itself (heavy-gate.mjs), as build-video does. The out dir is computed from
* the project and a take id by the caller, never sent by a client.
*
+ * `source`: the file to encode when it is not `<out>/<slug>.mp4` -- a take
+ * whose render is only its preview.mp4 (variantsView buildFileOf), as
+ * `--source <file>`.
+ *
* E2E_UMTOOL_VARIANTS_SCRIPT (test-only, playwright.config.ts) names a stub
* encoder with the same command line.
*
* @param {{ dir: string }} project
* @param {string} outDir
* @param {Record<string, string | undefined>} [env]
+ * @param {{ source?: string | null }} [opts]
* @returns {import("../trim").Step[]}
*/
-export function variantsSteps(project, outDir, env = process.env) {
+export function variantsSteps(project, outDir, env = process.env, { source = null } = {}) {
const bin = env.E2E_UMTOOL_VARIANTS_SCRIPT || script("variants.mjs");
return [
{
cwd: PIPELINE_DIR,
env: {},
label: `make the variants of ${path.relative(project.dir, outDir) || "out"}`,
- argv: ["node", bin, outDir],
+ argv: ["node", bin, outDir, ...(source ? ["--source", source] : [])],
// A size-capped variant is two passes over the whole cut, per variant.
timeoutMs: 90 * 60_000,
},
diff --git a/umtool/lib/report/knobs.test.mjs b/umtool/lib/report/knobs.test.mjs
@@ -28,7 +28,7 @@ const {
updateVariants,
} = await import("./manifest.mjs");
const knobs = await import("./knobs.mjs");
-const { variantsState, variantFile } = await import("./variantsView.mjs");
+const { buildFileOf, variantsState, variantFile } = await import("./variantsView.mjs");
const base = () => ({
slug: "t",
@@ -209,3 +209,21 @@ test("variantsState: the build, the variants made, the sync report with the lags
assert.equal(await variantFile({ dir }, { slug: "t" }, "../t"), null);
await assert.rejects(variantsState({ id: "p", dir }, await read(dir), "../x"), /not a take id/);
});
+
+test("variantsState on a take: its out/<slug>.mp4, else its finished preview.mp4 (the encoder pointed at it)", async () => {
+ const dir = await project();
+ const takeDir = path.join(dir, "takes", "final");
+ await mkdir(path.join(takeDir, "out"), { recursive: true });
+ // A work dir with a preview but no take.json is not a build.
+ await writeFile(path.join(takeDir, "preview.mp4"), "p".repeat(70));
+ assert.equal((await variantsState({ id: "p", dir }, await read(dir), "final")).built, null);
+ await writeFile(path.join(takeDir, "take.json"), JSON.stringify({ id: "final", group: "takes", order: 1, label: "Final", kind: "different", preview: "preview.mp4" }));
+ let s = await variantsState({ id: "p", dir }, await read(dir), "final");
+ assert.deepEqual([s.built?.size, s.built?.from], [70, "preview"]);
+ assert.equal((await buildFileOf({ dir }, "t", "final"))?.abs, path.join(takeDir, "preview.mp4"));
+ assert.deepEqual(s.takes, ["final"]);
+ // The build's own name wins when it is there.
+ await writeFile(path.join(takeDir, "out", "t.mp4"), "b".repeat(90));
+ s = await variantsState({ id: "p", dir }, await read(dir), "final");
+ assert.deepEqual([s.built?.size, s.built?.from], [90, "build"]);
+});
diff --git a/umtool/lib/report/knobsCli.mjs b/umtool/lib/report/knobsCli.mjs
@@ -37,7 +37,7 @@ import {
} from "./manifest.mjs";
import { CLAIM_KNOBS, STAMP_KNOB_DEFAULTS, VARIANTS_DEFAULT, rawMarksOf, stampingEntryId, variantsOf } from "./knobs.mjs";
import { variantsSteps } from "./driver.mjs";
-import { outDirOf, variantsState } from "./variantsView.mjs";
+import { buildFileOf, outDirOf, variantsState } from "./variantsView.mjs";
export const AUDIO_KNOBS = Object.freeze(["offset", "gain", "fadeIn", "fadeOut"]);
export const BLUR_KNOBS = Object.freeze(["on", "caption", "strength", "from", "to"]);
@@ -390,7 +390,9 @@ export async function variantsCommand(args, { root = REPORTS_ROOT, out = (s) =>
const before = await variantsState(project, manifest, take);
if (!flags.has("--list")) {
if (!before.built) throw new CliError(take ? `take ${take} has no build to make variants of` : "this cut has not been built yet — build it first");
- const [step] = variantsSteps(project, outDirOf(project, take), env);
+ if (before.built.from === "preview") (json ? err : out)(`take ${take}: no out/${before.slug}.mp4 -- making the variants of its preview.mp4`);
+ const src = before.built.from === "preview" ? (await buildFileOf(project, before.slug, take))?.abs ?? null : null;
+ const [step] = variantsSteps(project, outDirOf(project, take), env, { source: src });
const log = json ? (s) => err(s) : out;
log(`$ ${step.argv.join(" ")}`);
const code = await new Promise((resolve) => {
diff --git a/umtool/lib/report/knobsCli.test.mjs b/umtool/lib/report/knobsCli.test.mjs
@@ -129,6 +129,25 @@ test("umtool variants: refuses an unbuilt cut; makes the ladder (stub encoder) a
assert.equal(s.sync.items[0].flagged, true);
});
+test("umtool variants --take: a finished take whose render is only its preview.mp4 gets its ladder", async () => {
+ const dir = await project("take-vars");
+ const takeDir = path.join(dir, "takes", "final-1026");
+ await mkdir(path.join(takeDir, "out"), { recursive: true });
+ await writeFile(path.join(takeDir, "video.manifest.json"), JSON.stringify(MANIFEST, null, 2) + "\n");
+ await writeFile(path.join(takeDir, "preview.mp4"), Buffer.alloc(4096, 2));
+ await writeFile(path.join(takeDir, "take.json"), JSON.stringify({ id: "final-1026", group: "takes", order: 1, label: "Final", kind: "different", preview: "preview.mp4" }));
+ const { lines, run } = runner((args, o) => variantsCommand(args, { ...o, env: { ...process.env, E2E_UMTOOL_VARIANTS_SCRIPT: STUB } }));
+ assert.equal(await run("take-vars", "--take", "final-1026"), 0, lines.join("\n"));
+ assert.ok(lines.some((l) => /making the variants of its preview\.mp4/.test(l)), lines.join("\n"));
+ assert.ok(lines.some((l) => /--source .*preview\.mp4/.test(l)), lines.join("\n"));
+ lines.length = 0;
+ assert.equal(await run("take-vars", "--take", "final-1026", "--list", "--json"), 0);
+ const s = JSON.parse(lines.join("\n"));
+ assert.equal(s.built.from, "preview");
+ assert.deepEqual(s.made.items.map((i) => [i.name, i.exists]), [["master", true], ["1080p", true], ["720p", true], ["fit24", true]]);
+ assert.equal((await readFile(path.join(takeDir, "out", "huck.master.mp4"))).length, 4096);
+});
+
test("umtool set blur.*: on, caption (text whatever it parses as), strength, a span; blur.on= clears it all; render.blur=off by umtool look", async () => {
const dir = await project("blur");
const { lines, run } = runner(setCommand);
diff --git a/umtool/lib/report/takeMaker.mjs b/umtool/lib/report/takeMaker.mjs
@@ -14,6 +14,11 @@
// takes/<id>/video.manifest.json the WHOLE patched manifest -- what a pick
// copies over the project's
// takes/<id>/preview.mp4 the render (the window, or the full cut)
+// takes/<id>/out/<slug>.mp4 the same file, a HARD LINK, where a build
+// leaves its cut: `umtool variants --take`
+// and Deliver make the ladder of it (where
+// the link cannot be made -- out/ on another
+// filesystem -- they read the preview)
// takes/<id>/out/ the take's own render scratch; its
// clips-raw/ and narration/ are LINKS to the
// project's out/ (the fetched media is
@@ -38,7 +43,7 @@
// Plain ESM: the CLI (`umtool take`) runs it with bare node, and the app's
// pages import the parts they show (the styles, the staleness check).
import { createHash } from "node:crypto";
-import { lstat, mkdir, readFile, rename, rm, stat, symlink, writeFile } from "node:fs/promises";
+import { link, lstat, mkdir, readFile, rename, rm, stat, symlink, unlink, writeFile } from "node:fs/promises";
import path from "node:path";
import { pathToFileURL } from "node:url";
import { mergePatch } from "umtool-report-to-video/montage-styles";
@@ -252,20 +257,26 @@ export const sourcedEntries = (timeline) => (Array.isArray(timeline) ? timeline
* Timed by `schedule` (the deck's out/sourced/schedule.json: `segments[{ id,
* start, duration }]`) when it names every entry, else by estimatedSeconds
* laid end to end. At least one entry: a window past the end gets the last.
+ * A schedule built before clips were inserted misses them, so a cut edited
+ * since its last build is timed by the estimates; `missing` names the entries
+ * the schedule did not time (all of them when there is none).
*
* @param {Array<Record<string, any>>} timeline
* @param {{ at: number, dur: number }} win
* @param {{ segments?: Array<{ id: string, start: number, duration: number }> } | null} [schedule]
- * @returns {{ ids: string[], basis: "schedule" | "estimate", total: number }}
+ * @returns {{ ids: string[], basis: "schedule" | "estimate", total: number, missing: string[] }}
*/
export function windowEntries(timeline, win, schedule = null) {
const entries = sourcedEntries(timeline);
if (!entries.length) throw new Error("the manifest's timeline is empty");
- const segs = new Map((schedule?.segments ?? []).map((s) => [s.id, s]));
- const useSchedule = entries.every((e) => {
- const s = segs.get(e.id);
- return s && Number.isFinite(Number(s.start)) && Number.isFinite(Number(s.duration));
- });
+ const segs = new Map((Array.isArray(schedule?.segments) ? schedule.segments : []).filter(isObj).map((s) => [s.id, s]));
+ const missing = entries
+ .filter((e) => {
+ const s = segs.get(e.id);
+ return !(s && Number.isFinite(Number(s.start)) && Number.isFinite(Number(s.duration)));
+ })
+ .map((e) => e.id);
+ const useSchedule = missing.length === 0;
let t = 0;
const spans = entries.map((e) => {
if (useSchedule) {
@@ -281,7 +292,26 @@ export function windowEntries(timeline, win, schedule = null) {
const to = win.at + win.dur;
let ids = spans.filter((s) => s.from < to && s.to > from).map((s) => s.id);
if (!ids.length) ids = [spans[spans.length - 1].id];
- return { ids, basis: useSchedule ? "schedule" : "estimate", total };
+ return { ids, basis: useSchedule ? "schedule" : "estimate", total, missing };
+}
+
+/**
+ * The take log's line about what timed the window: the deck's schedule (and
+ * whether it is older than the manifest -- a re-trim since the last build
+ * moves the window's edges), or the estimates and why.
+ *
+ * @param {{ ids: string[], basis: string, missing: string[] }} covered
+ * @param {{ schedule: boolean, scheduleOlder: boolean }} facts
+ */
+export function windowBasisLine(covered, { schedule, scheduleOlder }) {
+ const n = covered.ids.length;
+ const what = `the window covers ${n} entr${n === 1 ? "y" : "ies"} (${covered.ids.join(", ")})`;
+ if (covered.basis === "schedule") {
+ return `${what}, timed by out/sourced/schedule.json${scheduleOlder ? " — older than the manifest: a clip re-cut since the last build may move the window's edges" : ""}`;
+ }
+ if (!schedule) return `${what}, timed by the manifest's own lengths (estimates): there is no out/sourced/schedule.json — build the cut for exact times`;
+ const few = covered.missing.slice(0, 6).join(", ") + (covered.missing.length > 6 ? `, +${covered.missing.length - 6} more` : "");
+ return `${what}, timed by the manifest's own lengths (estimates): out/sourced/schedule.json${scheduleOlder ? " is older than the manifest and" : ""} does not time ${few} — rebuild the cut for exact times`;
}
/**
@@ -490,8 +520,11 @@ export async function makeTake(projectDir, rawSpec, opts = {}) {
/** @type {null | { ids: string[], basis: string, total: number }} */
let covered = null;
if (spec.window !== "full") {
- const schedule = await readJson(path.join(projectDir, "out", "sourced", "schedule.json"));
+ const scheduleFile = path.join(projectDir, "out", "sourced", "schedule.json");
+ const schedule = await readJson(scheduleFile);
covered = windowEntries(base.timeline, spec.window, schedule);
+ const [schedSt, manSt] = await Promise.all([stat(scheduleFile).catch(() => null), stat(path.join(projectDir, MANIFEST)).catch(() => null)]);
+ log(`${spec.id}: ${windowBasisLine(covered, { schedule: !!schedule, scheduleOlder: !!(schedSt && manSt && schedSt.mtimeMs < manSt.mtimeMs) })}`);
const present = new Set(sourcedEntries(ruled.manifest.timeline).map((e) => e.id));
const ids = withPatchEntries(ruled.manifest.timeline, base.timeline, covered.ids).filter((id) => present.has(id));
if (!ids.length) throw new Error(`${spec.id}: the patch or the clip rulings removed every entry the window covers (${covered.ids.join(", ")})`);
@@ -512,9 +545,15 @@ export async function makeTake(projectDir, rawSpec, opts = {}) {
const renderPath = renderManifestPath(projectDir, spec.id);
await writeFile(renderPath, serialise(renderDoc), "utf8");
+ // The last make's hard link of preview.mp4 is unlinked first: a build that
+ // wrote the cut in place would otherwise write INTO the old preview, and a
+ // failed rebuild must leave the old take whole.
+ const preview = path.join(takeDir, PREVIEW);
+ await unlinkIfSameFile(path.join(takeOut, `${String(manifest.slug ?? "")}.mp4`), preview);
+
const transition = Number(manifest.render?.transition ?? 0);
const xfade = patches.some((p) => getPath(p, "render.transition") !== undefined) && transition > 0;
- emit({ ev: "take", id: spec.id, phase: "render", window: spec.window, entries: covered?.ids ?? null });
+ emit({ ev: "take", id: spec.id, phase: "render", window: spec.window, entries: covered?.ids ?? null, basis: covered?.basis ?? null });
let file;
try {
const render = opts.render ?? (await import("./takeRender.mjs")).renderTake;
@@ -531,8 +570,8 @@ export async function makeTake(projectDir, rawSpec, opts = {}) {
await rm(renderPath, { force: true });
}
- const preview = path.join(takeDir, PREVIEW);
await moveFile(file, preview);
+ await keepBuildName(preview, file, (line) => log(`${spec.id}: ${line}`));
await rename(nextManifest, path.join(takeDir, MANIFEST));
const seconds = opts.probe ? await opts.probe(preview) : null;
@@ -567,6 +606,25 @@ export async function makeTake(projectDir, rawSpec, opts = {}) {
return { id: spec.id, skipped: false, take: doc };
}
+/** Remove `file` when it is a hard link of `of` (the same inode); anything else is left. */
+async function unlinkIfSameFile(file, of) {
+ const [a, b] = await Promise.all([lstat(file).catch(() => null), lstat(of).catch(() => null)]);
+ if (a && b && a.isFile() && a.ino === b.ino && a.dev === b.dev) await unlink(file);
+}
+
+/**
+ * The render back where the build left it, as a hard link of the preview: the
+ * take's out/ is then a built out/ like the project's (variants, Deliver). Not
+ * possible across filesystems; the readers fall back to the preview then.
+ */
+async function keepBuildName(preview, file, log) {
+ try {
+ await link(preview, file);
+ } catch (err) {
+ log(`the render is only ${PREVIEW} (no ${path.basename(file)} link in out/: ${/** @type {any} */ (err)?.code ?? err})`);
+ }
+}
+
/** Rename, or copy and remove across filesystems (a take's out/ may be on the media root). */
async function moveFile(from, to) {
try {
diff --git a/umtool/lib/report/takeMaker.test.mjs b/umtool/lib/report/takeMaker.test.mjs
@@ -25,6 +25,7 @@ import {
takeIsStale,
takeSteps,
uniqueTakeId,
+ windowBasisLine,
windowEntries,
windowManifest,
withPatchEntries,
@@ -72,10 +73,10 @@ function stubRender({ fail = null } = {}) {
await writeFile(file, `render of ${doc.timeline.map((e) => e.id).join(",")}`);
return { file };
};
- return { render, calls };
+ return { render, calls, logs: [] };
}
-const opts = (r, extra = {}) => ({ render: r.render, styles: STYLES, probe: async () => 12.345, now: () => new Date("2026-10-17T12:00:00Z"), ...extra });
+const opts = (r, extra = {}) => ({ render: r.render, styles: STYLES, probe: async () => 12.345, now: () => new Date("2026-10-17T12:00:00Z"), log: (l) => r.logs?.push(l), ...extra });
test("mergePatch is RFC 7386: objects merge, null removes, arrays and scalars replace, nothing is mutated", () => {
const target = { a: 1, b: { c: 2, d: [1, 2] }, e: "x" };
@@ -116,16 +117,21 @@ test("patchFromSets: dotted paths, JSON values when they parse, strings otherwis
test("windowEntries: by the manifest's own lengths, or by the deck's schedule when it names every entry", () => {
// s01 0–10, s02 10–15, s03 15–25, k1 25–28, s04 28–33
- assert.deepEqual(windowEntries(MANIFEST.timeline, { at: 12, dur: 5 }), { ids: ["s02", "s03"], basis: "estimate", total: 33 });
+ assert.deepEqual(windowEntries(MANIFEST.timeline, { at: 12, dur: 5 }), { ids: ["s02", "s03"], basis: "estimate", total: 33, missing: ["s01", "s02", "s03", "k1", "s04"] });
assert.deepEqual(windowEntries(MANIFEST.timeline, { at: 0, dur: 60 }).ids, ["s01", "s02", "s03", "k1", "s04"]);
// Past the end: the last entry, never nothing.
assert.deepEqual(windowEntries(MANIFEST.timeline, { at: 500, dur: 10 }).ids, ["s04"]);
// A clip's cut, not its extent, is what plays.
assert.deepEqual(windowEntries([clip("a", 0, 100, { cutStart: 10, cutEnd: 12 }), clip("b", 0, 3)], { at: 2.5, dur: 1 }).ids, ["b"]);
const schedule = { segments: ["s01", "s02", "s03", "k1", "s04"].map((id, i) => ({ id, start: i * 2, duration: 2 })) };
- assert.deepEqual(windowEntries(MANIFEST.timeline, { at: 3, dur: 2 }, schedule), { ids: ["s02", "s03"], basis: "schedule", total: 10 });
- // A schedule that misses an entry is not trusted.
- assert.equal(windowEntries(MANIFEST.timeline, { at: 3, dur: 2 }, { segments: schedule.segments.slice(1) }).basis, "estimate");
+ assert.deepEqual(windowEntries(MANIFEST.timeline, { at: 3, dur: 2 }, schedule), { ids: ["s02", "s03"], basis: "schedule", total: 10, missing: [] });
+ // A schedule that misses an entry is not trusted -- one built before a clip
+ // was inserted -- and says which it missed.
+ const old = windowEntries(MANIFEST.timeline, { at: 3, dur: 2 }, { segments: schedule.segments.slice(1) });
+ assert.deepEqual([old.basis, old.missing], ["estimate", ["s01"]]);
+ assert.match(windowBasisLine(old, { schedule: true, scheduleOlder: true }), /estimates.*schedule\.json is older than the manifest and does not time s01 — rebuild/);
+ assert.match(windowBasisLine(windowEntries(MANIFEST.timeline, { at: 3, dur: 2 }, schedule), { schedule: true, scheduleOlder: false }), /covers 2 entries \(s02, s03\), timed by out\/sourced\/schedule\.json$/);
+ assert.match(windowBasisLine(windowEntries(MANIFEST.timeline, { at: 3, dur: 2 }), { schedule: false, scheduleOlder: false }), /there is no out\/sourced\/schedule\.json/);
// Only the default cut's entries.
assert.deepEqual(windowEntries([clip("a", 0, 5), clip("f", 0, 5, { variant: "full" }), clip("b", 0, 5)], { at: 6, dur: 1 }).ids, ["b"]);
});
@@ -159,6 +165,11 @@ test("makeTake: the style's patch then the take's, rendered from beside the proj
assert.equal(await readlink(link), path.join(dir, "out", "clips-raw"));
// The preview was moved into the take; take.json says how it was made.
assert.match(await readFile(path.join(takeDir, "preview.mp4"), "utf8"), /render of s02,s03/);
+ // ...and left where the build put it, as a hard link: the take's out/ is a built out/ (variants, Deliver).
+ const [pv, built] = await Promise.all([lstat(path.join(takeDir, "preview.mp4")), lstat(path.join(takeDir, "out", "fixture.mp4"))]);
+ assert.equal(built.ino, pv.ino);
+ // The log says what timed the window.
+ assert.ok(r.logs.some((l) => /^flash: the window covers 2 entries \(s02, s03\), timed by the manifest's own lengths \(estimates\): there is no out\/sourced\/schedule\.json/.test(l)), r.logs.join("\n"));
const t = JSON.parse(await readFile(path.join(takeDir, "take.json"), "utf8"));
assert.equal(t.kind, "different");
assert.equal(t.group, "montage");
@@ -253,6 +264,14 @@ test("makeTake: an existing take is skipped unless forced; a failed rebuild leav
await assert.rejects(makeTake(dir, { id: "t", label: "T", patch: { render: { crf: 99 } } }, opts(bad, { force: true })), /could not be cut/);
const after = await Promise.all(["take.json", "video.manifest.json", "preview.mp4"].map((f) => readFile(path.join(takeDir, f), "utf8")));
assert.deepEqual(after, before);
+ // A rebuild whose build writes the cut IN PLACE and then fails: the old
+ // preview's hard link was unlinked first, so the preview is untouched.
+ const inPlace = { render: async (job) => {
+ await writeFile(path.join(job.outDir, `${job.slug}.mp4`), "half a render");
+ throw new Error("build-video exited 1");
+ }, logs: [] };
+ await assert.rejects(makeTake(dir, { id: "t", label: "T", patch: { render: { crf: 99 } } }, opts(inPlace, { force: true })), /exited 1/);
+ assert.equal(await readFile(path.join(takeDir, "preview.mp4"), "utf8"), before[2]);
await assert.rejects(lstat(renderManifestPath(dir, "t")), "the render manifest is removed on failure too");
// A first make that fails writes no take.json: the listing shows nothing.
await assert.rejects(makeTake(dir, { id: "never", label: "Never" }, opts(bad)));
diff --git a/umtool/lib/report/variantsView.mjs b/umtool/lib/report/variantsView.mjs
@@ -11,13 +11,18 @@
//
// `<out>` is the project's out/, or a take's (takes/<id>/out).
//
+// A TAKE's render ends as takes/<id>/preview.mp4 (whatever take.json names);
+// makeTake leaves it in the take's out/ as `<slug>.mp4` too, a hard link. A
+// take made before that, or whose out/ is on another filesystem, has only the
+// preview: it is then the build, and the encoder is pointed at it (--source).
+//
// Plain ESM: `umtool variants` runs it under bare node.
import { readdir, readFile, stat } from "node:fs/promises";
import path from "node:path";
import { DEFAULT_VARIANT, variantPaths } from "umtool-report-to-video/build-video";
import { resolveInRoots } from "../paths.mjs";
import { VARIANT_NAME_RE, VARIANTS_DEFAULT, variantsOf } from "./knobs.mjs";
-import { isTakeId, takesDirOf } from "./takes.mjs";
+import { isTakeId, parseTake, TAKE_FILE, takesDirOf } from "./takes.mjs";
const isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v);
const fin = (v) => typeof v === "number" && Number.isFinite(v);
@@ -53,14 +58,34 @@ async function readJson(file) {
}
}
-/** The takes with a build in their out/ (their `<slug>.mp4`), by id. */
+/**
+ * The file a build's variants are made of: `<out>/<slug>.mp4`, or -- for a
+ * take with none -- the take's finished preview (take.json written, so the
+ * render is done). `from` says which.
+ *
+ * @param {{ dir: string }} project
+ * @param {string} slug
+ * @param {string | null} [take]
+ * @returns {Promise<{ abs: string, size: number, mtimeMs: number, from: "build" | "preview" } | null>}
+ */
+export async function buildFileOf(project, slug, take = null) {
+ const got = await fileInfo(variantPaths(outDirOf(project, take), slug, DEFAULT_VARIANT).final);
+ if (got) return { ...got, from: "build" };
+ if (!take) return null;
+ const takeDir = path.join(takesDirOf(project.dir), take);
+ const parsed = parseTake(take, await readJson(path.join(takeDir, TAKE_FILE)));
+ if (!("take" in parsed) || !parsed.take) return null;
+ const preview = await fileInfo(path.join(takeDir, parsed.take.preview));
+ return preview ? { ...preview, from: "preview" } : null;
+}
+
+/** The takes with a build (their out/'s `<slug>.mp4`, else their finished preview), by id. */
export async function builtTakes(project, slug) {
const dirs = await readdir(takesDirOf(project.dir), { withFileTypes: true }).catch(() => []);
const out = [];
for (const d of dirs) {
if (!isTakeId(d.name)) continue;
- const got = await fileInfo(variantPaths(outDirOf(project, d.name), slug, DEFAULT_VARIANT).final);
- if (got) out.push(d.name);
+ if (await buildFileOf(project, slug, d.name)) out.push(d.name);
}
return out.sort();
}
@@ -76,7 +101,7 @@ export async function builtTakes(project, slug) {
export async function variantsState(project, manifest, take = null) {
const slug = manifest.slug ?? path.basename(project.dir);
const outDir = outDirOf(project, take);
- const built = await fileInfo(variantPaths(outDir, slug, DEFAULT_VARIANT).final);
+ const built = await buildFileOf(project, slug, take);
const doc = await readJson(path.join(outDir, "variants.json"));
const items = [];
if (isObj(doc) && Array.isArray(doc.items)) {
@@ -118,7 +143,8 @@ export async function variantsState(project, manifest, take = null) {
return {
take: take || null,
slug,
- built: built ? { size: built.size, mtimeMs: built.mtimeMs } : null,
+ // `from: "preview"`: a take whose out/ holds no `<slug>.mp4`, made of its preview.mp4.
+ built: built ? { size: built.size, mtimeMs: built.mtimeMs, from: built.from } : null,
ladder: variantsOf(render),
ladderIsDefault: !Array.isArray(render.variants),
ladderDefault: VARIANTS_DEFAULT,