// CHECK JOINS (check-joins.mjs): the measured check of a rendered take's joins -- its pure parts. import assert from "node:assert/strict"; import { test } from "node:test"; import { cardRegion, concatFiles, edgeOf, joinBoundaries, jumpOf, joinRelation, joinVerdict, joinsTable, masterStarts, parseFrameMeta, postsDrawnBy, rankJoins } from "./check-joins.mjs"; const at = (h) => `2026-11-04T${String(h).padStart(2, "0")}:00:00.000Z`; const narrate = (e, parts) => ({ ...e, narration: { takes: [{ file: `narration/${e.id}.wav`, seconds: 6, parts: parts.map((p) => ({ text: p.join(" ") })) }], picked: 0 } }); const post = (id, text, h, extra = {}) => ({ type: "post", id: `p-${id}`, post: `ObviousRises-x/${id}`, platform: "x", author: "MR. OBVIOUS", handle: "ObviousRises", date: at(h), text, url: `https://x.com/ObviousRises/status/${id}`, ...extra }); const ref = (id, text, h) => ({ id, author: "MR. OBVIOUS", handle: "ObviousRises", date: at(h), text }); test("CHECK JOINS: the boundaries where the next item draws a post the one before showed, their relation and planned join; the master's starts from the files as the concat reads them; worst first", () => { const a = narrate(post("10", "mercy", 7), [["mercy"]]); const b = narrate(post("11", "notice", 8, { parents: [ref("10", "mercy", 7)] }), [["notice"]]); const c = narrate(post("99", "unrelated", 9), [["unrelated"]]); const tl = [a, b, c]; assert.deepEqual([...postsDrawnBy(b).entries()], [["11", "post"], ["10", "parent"]]); assert.equal(joinRelation(a, b), "self-reply"); assert.equal(joinRelation(a, { ...b, handle: "Other" }), "reply to it"); assert.equal(joinRelation(a, { ...c, quoted: { id: "10", text: "mercy" } }), "quotes it"); const schedule = { fps: 30, segments: [{ id: "p-10", type: "post", start: 0, duration: 15.9 }, { id: "p-11", type: "post", start: 15.9, duration: 10 }, { id: "p-99", type: "post", start: 25.9, duration: 5 }] }; const rows = joinBoundaries(tl, schedule); assert.deepEqual(rows.map((r) => [r.from, r.to, r.shared, r.relation, r.join]), [["p-10", "p-11", ["10"], "self-reply", 0.6]]); assert.equal(joinBoundaries(tl, schedule, undefined, { all: true }).length, 2); // The audio a few ms longer than the video: every later segment later than the schedule says. assert.deepEqual(masterStarts(schedule, [15.905, 10.003, 5]), [0, 15.905, 25.908]); assert.deepEqual(masterStarts(schedule, []), [0, 15.9, 25.9]); assert.deepEqual(concatFiles("ffconcat version 1.0\nfile '/a/b.mp4'\nfile '/a/it'\\''s.mp4'\n"), ["/a/b.mp4", "/a/it's.mp4"]); assert.deepEqual(parseFrameMeta("frame:0 pts:512 pts_time:0.0333\nlavfi.signalstats.YAVG=0.5\nframe:1 pts:1024 pts_time:0.0667\nlavfi.signalstats.YAVG=9.25\n", "lavfi.signalstats.YAVG"), [{ t: 0.0333, v: 0.5 }, { t: 0.0667, v: 9.25 }]); // A cut: one step alone; a dissolve: many alike. assert.equal(jumpOf([{ t: 0, v: 0 }, { t: 1, v: 9 }, { t: 2, v: 0.2 }]).jump, 8.8); assert.ok(jumpOf([{ t: 0, v: 2 }, { t: 1, v: 2.5 }, { t: 2, v: 2.2 }, { t: 3, v: 1.9 }]).jump < 0.5); // Over the cards, not the slots: a card beside a video is its own column. const box = { x: 173, y: 2, width: 1574, height: 886 }; const withVideo = { ...a, media: [{ src: "v.mp4", kind: "video", width: 1280, height: 720, seconds: 10 }] }; const reg = cardRegion([withVideo], box); assert.ok(reg.width < box.width * 0.6 && reg.x >= box.x && reg.width % 2 === 0 && reg.height % 2 === 0); assert.deepEqual(cardRegion([], box), box); // THE EDGE: mid-7's 2357 boundary on main (the carried post switching at frame 1) against the lane's dissolve. const series = (vals, t0 = 692.1) => vals.map((v, k) => ({ t: t0 + k / 30, v })); assert.equal(edgeOf(series([0, 0, 0.4, 10.4, 3.6, 0, 4.7]), 692.153), 10.4); assert.equal(edgeOf(series([0, 0, 0.1, 0, 3.9, 0, 5.3]), 692.153), 0.1); // A video playing across the boundary: its own change is not the join's. assert.ok(edgeOf(series([4, 3.8, 0, 4.1, 3.9, 4.2, 0, 4.0, 4.1], 692.0), 692.153) < 0.5); const measured = [{ from: "a", to: "b", shared: ["1"], relation: "self-reply", join: 0.6, t: 1, edge: 10.4, ssim: 0.79, jump: 10.7 }, { from: "c", to: "d", shared: ["2"], relation: "manual thread", join: 0.6, t: 2, edge: 0.1, ssim: 0.998, jump: 1.2 }]; assert.deepEqual(rankJoins(measured).map((r) => r.from), ["a", "c"]); assert.equal(joinVerdict(measured[0]), "JUMPS"); assert.equal(joinVerdict(measured[1]), "join"); assert.equal(joinVerdict({ ...measured[0], join: null }), "cut"); assert.match(joinsTable(measured), /a → b\s+self-reply\s+1\s+0\.6s\s+10\.4\s+0\.790\s+10\.7\s+JUMPS/); });