// ITS OWN ATTACHMENTS COME IN WITH ITS OWN POST (post-item.mjs ownMediaEnterAt; operator, 4 Nov, mid-11 at ~15:58: // "the mr. obvious gif should come in when his post does rather than during the strawb megathread reading"). import assert from "node:assert/strict"; import { test } from "node:test"; import { ownMediaEnterAt, postItemPlan, stepAt, validatePostItem } from "./post-item.mjs"; import { postSegmentArgs, postSegmentKey, postSegmentKeyOf } from "./post-render.mjs"; const at = (h) => `2026-11-04T${String(h).padStart(2, "0")}:00:00.000Z`; /** A take of [text, role] pieces, each one part with its role set (as `umtool posts roles` sets them). */ const narrate = (e, pieces) => { let t = 0; const parts = pieces.map(([text, role], n) => { const seconds = Math.round((text.split(/\s+/).length / 3) * 100) / 100; t += n ? 0.8 : 0; const p = { n: n + 1, para: n * 100, text, start: Math.round(t * 100) / 100, seconds, ...(role ? { role } : {}) }; t += seconds; return p; }); return { ...e, narration: { script: e.text, takes: [{ file: `narration/posts/${e.id}/take-1.wav`, engine: "orpheus", voice: "leo+zac", seconds: Math.round(t * 100) / 100, script: pieces.map((p) => p[0]).join("\n\n"), parts }], pick: 0 } }; }; const gif = { src: "posts-media/ObviousRises-x/11/11_1.mp4", kind: "gif", width: 480, height: 270, seconds: 3 }; const video = { src: "posts-media/ObviousRises-x/11/11_2.mp4", kind: "video", width: 1280, height: 720, seconds: 30, audio: true }; const mega = "STRAWB MEGATHREAD: everything she said, in order, with the receipts for each part of it."; const his = "this is what happens when you push people, they push back."; const base = (extra = {}) => ({ type: "post", id: "p-11", post: "ObviousRises-x/11", platform: "x", author: "MR. OBVIOUS", handle: "ObviousRises", date: at(9), text: his, url: "https://x.com/ObviousRises/status/11", ...extra }); const quoting = (media) => narrate(base({ media, quoted: { id: "5", author: "Strawb", handle: "strawb", date: at(7), text: mega } }), [[mega, "quoted"], [his, "post"]]); test("the item's own GIF comes in when his post's read begins -- the megathread read first shows none of it; crossfaded in from there", () => { const e = quoting([gif]); const plan = postItemPlan(e); assert.ok(plan.follow?.thread, "a threaded read"); const postStart = Math.min(...plan.follow.blocks.filter((b) => b.scope === "post" && b.start !== null).map((b) => b.start)); const quoteStart = Math.min(...plan.follow.blocks.filter((b) => b.scope === "quoted" && b.start !== null).map((b) => b.start)); assert.ok(quoteStart < postStart, "the quote is read first"); assert.equal(plan.enter, postStart); assert.equal(plan.steps[0].at, postStart, "its first step starts with his words"); assert.equal(stepAt(plan, quoteStart + 0.5), null, "nothing of his while the megathread is read"); assert.equal(stepAt(plan, postStart + 0.1)?.items[0].src, gif.src); // The build: the GIF's layer is laid from that moment and faded in there, never from the first frame. const args = postSegmentArgs({ entry: e, box: { width: 1574, height: 886 }, plan, layout: { mode: "side", slot: { x: 900, y: 0, width: 674, height: 886 }, card: { x: 0, y: 0, width: 880, height: 886 } }, cards: { read: "read.png" }, files: ["gif.mp4"], render: { fps: 30 }, outPath: "o.mp4" }); const graph = args[args.indexOf("-filter_complex") + 1]; assert.match(graph, new RegExp(`fade=t=in:st=${postStart}:d=0\\.3:alpha=1\\[m0_0\\]`)); assert.match(graph, new RegExp(`\\[m0_0\\]overlay=x=900:y=\\d+:enable='between\\(t,${postStart},`)); }); test("a video entering with his post starts there -- its offset counted from that moment, its sound too, its trim fitted to what is left", () => { const e = quoting([video]); const plan = postItemPlan(e); const st = plan.steps[0]; assert.equal(st.at, plan.enter); assert.equal(st.srcFrom, 0, "from its own start at that moment"); assert.ok(st.at + st.seconds <= plan.total + 1e-6); const args = postSegmentArgs({ entry: e, box: { width: 1574, height: 886 }, plan, layout: { mode: "side", slot: { x: 900, y: 0, width: 674, height: 886 }, card: { x: 0, y: 0, width: 880, height: 886 } }, cards: { read: "read.png" }, files: ["v.mp4"], render: { fps: 30 }, outPath: "o.mp4" }); const graph = args[args.indexOf("-filter_complex") + 1]; const ms = Math.round(plan.enter * 1000); assert.match(graph, new RegExp(`adelay=${ms}\\|${ms}`), "its sound delayed to his words"); }); test("nothing changes for an item that reads only its post, one with enter: item, or one past the first of a media scene; the key changes only where it enters later", () => { const only = narrate(base({ media: [gif] }), [[his, "post"]]); const p0 = postItemPlan(only); assert.equal(ownMediaEnterAt(only, p0.follow), 0); assert.equal(p0.enter, undefined); assert.equal(p0.steps[0].at, 0); const item = quoting([{ ...gif, enter: "item" }]); assert.equal(postItemPlan(item).enter, undefined); assert.equal(postItemPlan(item).steps[0].at, 0); const e = quoting([gif]); const plan = postItemPlan(e); assert.equal(ownMediaEnterAt(e, plan.follow, { mediaScene: { n: 1 } }), 0, "held through from the item before"); assert.ok(ownMediaEnterAt(e, plan.follow, { mediaScene: { n: 0 } }) > 0, "the first of a media scene still waits"); // The key: `enter` only on the item that enters later. const box = { width: 1574, height: 886 }; const render = { fps: 30, palette: {} }; assert.equal(postSegmentKeyOf({ entry: only, box, render, plan: p0 }).enter, undefined); assert.deepEqual(postSegmentKeyOf({ entry: e, box, render, plan }).enter, { at: plan.enter, fade: 0.3 }); assert.notEqual(postSegmentKey(postSegmentKeyOf({ entry: e, box, render, plan })), postSegmentKey(postSegmentKeyOf({ entry: e, box, render, plan: { ...plan, enter: undefined } }))); // The knob is checked. assert.deepEqual(validatePostItem(quoting([{ ...gif, enter: "later" }])).filter((x) => x.includes("enter")).length, 1); });