// lane/thread-scenes, the writers: `posts set-item` parent.= (a whole thread, by hand), parent..media, // media.add / media.=off (an attachment from a project file, measured), link.add (a linked post), thread.group // (a manual thread), panel=, thread.map=; and `timeline threads --write` gathering a group in date order. import assert from "node:assert/strict"; import { execFileSync } from "node:child_process"; import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises"; import { tmpdir } from "node:os"; import path from "node:path"; import { after, test } from "node:test"; import { postItemPatchOf, postsCommand } from "./postsCli.mjs"; const ROOT = await mkdtemp(path.join(tmpdir(), "umtool-thread-scenes-")); after(() => rm(ROOT, { recursive: true, force: true })); const REPORTS = path.join(ROOT, "reports"); const item = (id, o = {}) => ({ type: "post", id: `p-${id}`, post: `subj-x/${id}`, platform: "x", author: "THE SUBJECT", handle: "Subject", date: "2026-10-30T10:00:00.000Z", text: `Words of post ${id}.`, ...o }); async function project(name, timeline) { const dir = path.join(REPORTS, name); await mkdir(dir, { recursive: true }); await writeFile(path.join(dir, "video.manifest.json"), JSON.stringify({ schemaVersion: 1, slug: name, title: name, provenance: { siteOrigin: "" }, render: { width: 1920, height: 1080, fps: 30 }, timeline }, null, 2)); return { id: name, dir }; } const manifest = async (p) => JSON.parse(await readFile(path.join(p.dir, "video.manifest.json"), "utf8")); const cli = async (args) => { const lines = []; const errs = []; const code = await postsCommand(args, { root: REPORTS, out: (s) => lines.push(s), err: (s) => errs.push(s) }); return { code, out: lines.join("\n"), err: errs.join("\n") }; }; let ffmpeg = true; try { execFileSync("ffmpeg", ["-version"], { stdio: "ignore" }); } catch { ffmpeg = false; } test("set-item parent.=: an ancestor added at the next index, replaced, dropped; parent..media and media.add measured from project files", { skip: !ffmpeg && "no ffmpeg" }, async () => { const p = await project("chain", [item("1", { parents: [{ id: "900", handle: "grok", author: "Grok", date: "2026-10-30T09:00:00.000Z", text: "An answer." }] })]); await mkdir(path.join(p.dir, "posts-media", "x", "1"), { recursive: true }); execFileSync("ffmpeg", ["-v", "error", "-y", "-f", "lavfi", "-i", "color=c=red:s=692x141", "-frames:v", "1", path.join(p.dir, "posts-media/x/1/wide.png")]); const justin = JSON.stringify({ id: "800", handle: "@JustinInYT1", author: "Justin", date: "2026-10-30T08:00:00.000Z", text: "@grok is that a threat?" }); assert.deepEqual(postItemPatchOf([`parent.1=${justin}`]).parents["1"].ref.handle, "JustinInYT1"); const add = await cli(["set-item", "chain", "p-1", `parent.1=${justin}`, "parent.1.media=posts-media/x/1/wide.png", "media.add=posts-media/x/1/wide.png", "panel=top", "thread.group=grok", "thread.map=both"]); assert.equal(add.code, 0, add.err); let e = (await manifest(p)).timeline[0]; assert.deepEqual(e.parents.map((x) => x.id), ["900", "800"]); assert.deepEqual(e.parents[1].media, [{ src: "posts-media/x/1/wide.png", kind: "image", width: 692, height: 141 }]); assert.deepEqual(e.media, [{ src: "posts-media/x/1/wide.png", kind: "image", width: 692, height: 141 }]); assert.equal(e.panel, "top"); assert.deepEqual(e.thread, { group: "grok", map: "both" }); // Past the next index: refused; a field a post has not: refused; a file not there: refused. assert.match((await cli(["set-item", "chain", "p-1", `parent.5=${justin}`])).err, /the next one is 2/); assert.match((await cli(["set-item", "chain", "p-1", 'parent.2={"id":"7","likes":3}'])).err, /likes is not a post's field/); assert.match((await cli(["set-item", "chain", "p-1", "media.add=posts-media/none.png"])).err, /not in the project/); // Replaced, then dropped; the attachment removed. assert.equal((await cli(["set-item", "chain", "p-1", 'parent.0={"id":"901","handle":"grok","text":"Another answer.","date":"2026-10-30T09:30:00.000Z"}', "media.0=off", "thread.group=off"])).code, 0); e = (await manifest(p)).timeline[0]; assert.deepEqual(e.parents.map((x) => [x.id, x.text]), [["901", "Another answer."], ["800", "@grok is that a threat?"]]); assert.equal(e.media, undefined); assert.deepEqual(e.thread, { map: "both" }); assert.equal((await cli(["set-item", "chain", "p-1", "parent.1=off"])).code, 0); assert.deepEqual((await manifest(p)).timeline[0].parents.map((x) => x.id), ["901"]); }); test("set-item link.add: a post its words link to, with a picture and the words read off it; link.=off drops it", { skip: !ffmpeg && "no ffmpeg" }, async () => { const p = await project("links", [item("2", { text: "this you? https://x.com/Infinity_Virus_/status/2116805001309823299" })]); await mkdir(path.join(p.dir, "posts-media", "iv"), { recursive: true }); execFileSync("ffmpeg", ["-v", "error", "-y", "-f", "lavfi", "-i", "color=c=blue:s=600x4029", "-frames:v", "1", path.join(p.dir, "posts-media/iv/1.jpg")]); const ref = JSON.stringify({ id: "2116805001309823299", handle: "Infinity_Virus_", author: "Infinity", date: "2026-11-01T08:10:15.000Z", text: "Ya try to be civil and they go insane", media: ["posts-media/iv/1.jpg"] }); const r = await cli(["set-item", "links", "p-2", `link.add=${ref}`, "link.0.transcript=Line one of the messages.\n\nLine two of them."]); assert.equal(r.code, 0, r.err); const e = (await manifest(p)).timeline[0]; assert.equal(e.links[0].media[0].height, 4029); assert.equal(e.links[0].transcript, "Line one of the messages.\n\nLine two of them."); assert.equal((await cli(["set-item", "links", "p-2", "link.0=off"])).code, 0); assert.equal((await manifest(p)).timeline[0].links, undefined); }); test("timeline insert post-json: a post no archive holds (Kirsche's reply kept only as a picture) -- its author, handle, date, words and its picture, measured; refused as the build would", { skip: !ffmpeg && "no ffmpeg" }, async () => { const { timelineCommand } = await import("./timelineCli.mjs"); const p = await project("synthetic", [item("1")]); await mkdir(path.join(p.dir, "posts-media", "KirscheVerstahl-x", "2115523442074087838"), { recursive: true }); execFileSync("ffmpeg", ["-v", "error", "-y", "-f", "lavfi", "-i", "color=c=gray:s=1127x500", "-frames:v", "1", path.join(p.dir, "posts-media/KirscheVerstahl-x/2115523442074087838/2115523442074087838_1.jpg")]); const json = JSON.stringify({ post: "KirscheVerstahl-x/2115523442074087838", author: "Kirsche", handle: "@KirscheVerstahl", date: "2026-10-28T19:17:00.000Z", text: "@ObviousRises", media: ["posts-media/KirscheVerstahl-x/2115523442074087838/2115523442074087838_1.jpg"] }); const lines = []; const errs = []; const code = await timelineCommand(["synthetic", "insert", "--after", "p-1", `post-json:${json}`], { root: REPORTS, out: (s) => lines.push(s), err: (s) => errs.push(s) }); assert.equal(code, 0, errs.join("\n")); const e = (await manifest(p)).timeline[1]; assert.equal(e.id, "p-2115523442074087838"); assert.equal(e.handle, "KirscheVerstahl"); assert.deepEqual(e.media, [{ src: "posts-media/KirscheVerstahl-x/2115523442074087838/2115523442074087838_1.jpg", kind: "image", width: 1127, height: 500 }]); const bad = await timelineCommand(["synthetic", "insert", "--after", "p-1", 'post-json:{"post":"x","text":"a"}'], { root: REPORTS, out: () => {}, err: (s) => errs.push(s) }); assert.notEqual(bad, 0); assert.match(errs.join("\n"), /post must be \//); });