// Tests for the posts region (slice P1): the card page (chrome-posts.mjs), its
// window arithmetic, the plan the page runs, compose-chrome's posts path, and
// the overlay that lays each window on the cut -- including one real ffmpeg
// run proving the frames outside a window are untouched.
//
// Run with: pnpm test:scripts
import assert from "node:assert/strict";
import { spawnSync } from "node:child_process";
import { chmodSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import path from "node:path";
import test from "node:test";
import { fileURLToPath } from "node:url";
import {
postDate, postParagraphs, postsCues, postsHtml, postWho, snapWindow, windowPosts,
} from "./chrome-posts.mjs";
import { postSchedule, postsGeometry, postWindows, validatePosts } from "./deck.mjs";
import { applyChromeArgs, chromeOverlayChain, chromeRegions, postsRegions } from "./build-video.mjs";
const HERE = path.dirname(fileURLToPath(import.meta.url));
const RENDER = {
width: 1920,
height: 1080,
fps: 30,
transition: 0.5,
palette: { bg: "#12101a", fg: "#f4f1ea", muted: "#9a93ad", accent: "#a97bff", amber: "#ffc860" },
chrome: { engine: "hyperframes", layout: "deck", deck: {} },
};
const CLIPS = [
{ id: "c1", type: "clip", date: "2024-09-05" },
{ id: "c2", type: "clip", date: "2024-10-01" },
{ id: "c3", type: "clip", date: "2025-06-01" },
];
const SEGS = [
{ id: "c1", start: 0, duration: 10 },
{ id: "c2", start: 9.5, duration: 10 },
{ id: "c3", start: 19, duration: 9.5 },
];
const POST = (id, date, extra = {}) => ({
id, platform: "bluesky", author: "Pirate Software", handle: "piratesoftware.live", date,
text: `words of ${id}`, url: `https://bsky.app/profile/piratesoftware.live/post/${id}`, ...extra,
});
const HOSTILE = POST("evil", "2024-11-27T02:36:13.745Z", {
platform: "x",
handle: '">
',
author: "bold",
text: "\nsecond line & 'quotes'\n\nnew paragraph",
});
/** A schedule as the build writes one, posts placed by the core. */
function schedule(posts = [POST("a", "2024-10-19T17:01:17.640Z"), HOSTILE, POST("z", "2026-01-22")]) {
const placed = postSchedule({ posts, entries: CLIPS, segments: SEGS, D: 0.5, total: 28.5, render: RENDER });
return {
version: 1, kind: "deck", estimated: false, fps: 30, transition: 0.5, total: 28.5, multiChannel: false,
segments: SEGS.map((s) => ({ ...s, type: "clip", end: s.start + s.duration, title: "", subtitle: "", qrUrl: null, hideDeck: false })),
posts: placed,
};
}
const FONTS = { regular: "assets/DeckSans.ttf", bold: "assets/DeckSansBold.ttf" };
const dataOf = (html) => JSON.parse(/