commit e9fcb3c52c0d6b21aba1011bca1c08b8f7164eea
parent ca21d22b0dfe3e2d00294cfc3108e0326250eb17
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Wed, 4 Nov 2026 16:52:37 -0500
umtool: play-preload.spec -- a fast burst of ten narrated posts (pace: fast, the clock on, ~1.3-2 s each) played in Play with every post-item request slowed 300-800 ms; each item's card must be drawn for >= 90% of its seconds while the clock runs, and its voice heard (operator, 4 Nov: "The rapid sections on play the cut don't load fast enough such that most of it is cut out")
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
3 files changed, 224 insertions(+), 0 deletions(-)
diff --git a/umtool/e2e/fixtures/make-fixture.mjs b/umtool/e2e/fixtures/make-fixture.mjs
@@ -55,6 +55,7 @@ import { makeReelFixture } from "./reel-fixture.mjs";
import { makeIntakeFixture } from "./intake-fixture.mjs";
import { makePostItemsFixture } from "./post-items-fixture.mjs";
import { makePostNarrationFixture } from "./post-narration-fixture.mjs";
+import { makePlayPreloadFixture } from "./play-preload-fixture.mjs";
import { makePostComboFixture } from "./post-combo-fixture.mjs";
import { makeMediaScenesFixture } from "./media-scenes-fixture.mjs";
@@ -1915,6 +1916,8 @@ makeIntakeFixture({ reports, channels: CHANNELS, deckManifest, cachedWindow: pat
makePostItemsFixture({ reports, channels: CHANNELS, deckManifest, cachedWindow: path.join(REPORT, "out", "clips-raw", "vid1_0.00-9.00.mp4") });
// Narrated post items (report-to-video/post-narration.mjs): a take read over a video, four pictures cycling (post-narration.spec.ts).
makePostNarrationFixture({ reports, deckManifest });
+// A fast burst of narrated posts (Play's prefetch and its gate: play-preload.spec.ts).
+makePlayPreloadFixture({ reports, deckManifest });
// The combo counter (report-to-video/post-combo.mjs): one GIF answering three people (post-combo.spec.ts).
makePostComboFixture({ reports, channels: CHANNELS, deckManifest });
// Media scenes and the band censor (post-media-scene.mjs, post-censor.mjs): one picture answered three times in a row (media-scenes.spec.ts).
diff --git a/umtool/e2e/fixtures/play-preload-fixture.mjs b/umtool/e2e/fixtures/play-preload-fixture.mjs
@@ -0,0 +1,82 @@
+// A FAST BURST OF POST ITEMS (operator, 4 Nov: "The rapid sections on play the
+// cut don't load fast enough such that most of it is cut out"): Play's
+// prefetch and its gate (PlayCut.tsx, playEngine/postPreload.ts, engine.ts
+// `gate`), played by play-preload.spec.ts with every post-item request slowed.
+//
+// play-preload-fixture pp-1 … pp-10 ten narrated posts at `pace: "fast"`, the
+// clock on: each read by a take of
+// 0.6-1.3 s (a tone), so each item is
+// ~1.3-2 s, back to back; pp-3, pp-6 and
+// pp-9 carry a picture, pp-5 a 1.2 s video;
+// pp-10 a stinger an hour EARLIER (the
+// clock rewinds). The deck on. Read only.
+//
+// Synthetic, like every fixture.
+import { mkdirSync, writeFileSync } from "node:fs";
+import { spawnSync } from "node:child_process";
+import path from "node:path";
+
+const ff = (args) => {
+ const r = spawnSync("ffmpeg", ["-v", "error", "-y", ...args]);
+ if (r.status !== 0) throw new Error(`ffmpeg ${args.join(" ")}: ${String(r.stderr)}`);
+};
+
+/** The burst: id, its take's seconds, its attachment. */
+export const PLAY_PRELOAD_ITEMS = [
+ ["pp-1", 0.8, null],
+ ["pp-2", 0.6, null],
+ ["pp-3", 1.0, "image"],
+ ["pp-4", 0.7, null],
+ ["pp-5", 1.1, "video"],
+ ["pp-6", 0.9, "image"],
+ ["pp-7", 0.6, null],
+ ["pp-8", 1.3, null],
+ ["pp-9", 0.8, "image"],
+ ["pp-10", 0.9, null],
+];
+
+/** @param {{ reports: string, deckManifest: Function }} o */
+export function makePlayPreloadFixture({ reports, deckManifest }) {
+ const name = "play-preload-fixture";
+ const dir = path.join(reports, name);
+ const chan = "burstchan-x";
+ const colours = ["red", "green", "blue", "yellow", "purple", "orange", "cyan", "white", "pink", "gray"];
+ const timeline = PLAY_PRELOAD_ITEMS.map(([id, secs, kind], k) => {
+ const n = id.slice(3);
+ const media = path.join(dir, "posts-media", chan, n);
+ mkdirSync(media, { recursive: true });
+ const takes = path.join(dir, "narration", "posts", n);
+ mkdirSync(takes, { recursive: true });
+ ff(["-f", "lavfi", "-i", `sine=frequency=${300 + 40 * k}:sample_rate=48000:duration=${secs}`, "-ac", "1", "-c:a", "pcm_s16le", path.join(takes, "take-1.orpheus-zac.wav")]);
+ const att = [];
+ if (kind === "image") {
+ ff(["-f", "lavfi", "-i", `color=c=${colours[k]}:size=320x180`, "-frames:v", "1", path.join(media, `${n}_1.png`)]);
+ att.push({ src: `posts-media/${chan}/${n}/${n}_1.png`, kind: "image", width: 320, height: 180 });
+ } else if (kind === "video") {
+ ff([
+ "-f", "lavfi", "-i", "testsrc=size=320x180:rate=30:duration=1.2",
+ "-f", "lavfi", "-i", "sine=frequency=880:duration=1.2",
+ "-c:v", "libx264", "-pix_fmt", "yuv420p", "-c:a", "aac", "-ar", "48000", "-ac", "2", "-shortest", path.join(media, `${n}_1.mp4`),
+ ]);
+ att.push({ src: `posts-media/${chan}/${n}/${n}_1.mp4`, kind: "video", seconds: 1.2, width: 320, height: 180, audio: true });
+ }
+ const text = `Burst post ${n}: you want to die? ${"again ".repeat(k % 3)}`.trim();
+ // A minute apart, the stinger an hour back (the clock rewinds).
+ const date = new Date(Date.UTC(2026, 10, 4, 9, id === "pp-10" ? 0 : 10 + k)).toISOString();
+ return {
+ type: "post", id, post: `${chan}/${n}`, platform: "x", author: "Burst Subject", handle: "burstsubject",
+ date, text, url: `https://x.com/burstsubject/status/${n}`, engagement: { likes: k }, subjects: ["burstsubject"],
+ ...(att.length ? { media: att } : {}),
+ narration: {
+ script: text, pace: "fast",
+ takes: [{ file: `narration/posts/${n}/take-1.orpheus-zac.wav`, engine: "orpheus", voice: "zac", seconds: secs, script: text, at: "2026-11-04T00:00:00.000Z" }],
+ pick: 0,
+ },
+ };
+ });
+ const m = deckManifest(name, "The Play Preload Fixture", timeline);
+ m.provenance = { ...m.provenance, channelSlug: chan };
+ m.render = { ...m.render, posts: { ...(m.render.posts ?? {}), clock: { on: true } } };
+ writeFileSync(path.join(dir, "video.manifest.json"), JSON.stringify(m, null, 2) + "\n");
+ return { dir };
+}
diff --git a/umtool/e2e/play-preload.spec.ts b/umtool/e2e/play-preload.spec.ts
@@ -0,0 +1,139 @@
+import { test, expect, type Page } from "@playwright/test";
+import * as urls from "./urls";
+
+// ---------------------------------------------------------------------------
+// A FAST BURST, PLAYED IN FULL ON A SLOW NETWORK (operator, 4 Nov: "The rapid
+// sections on play the cut don't load fast enough such that most of it is cut
+// out. Can we maybe preload?"). Fixture: e2e/fixtures/play-preload-fixture.mjs --
+// ten narrated posts at `pace: "fast"`, ~1.3-2 s each, the clock on, three with
+// a picture and one with a video.
+//
+// Every post item's request (the card's page, its faces, the takes, the
+// attachments) is held 300-800 ms before it goes on. Play fetches the items
+// ahead (playEngine/postPreload.ts) and holds its clock on an item that is not
+// ready (engine.ts `gate`), so each item is played in full: its card drawn
+// for at least 90% of its seconds on the cut's clock while the clock runs, and
+// its voice heard. What it waited is printed (and in the console: "[play] held").
+// ---------------------------------------------------------------------------
+
+const PROJECT = "reports/play-preload-fixture";
+const IDS = ["pp-1", "pp-2", "pp-3", "pp-4", "pp-5", "pp-6", "pp-7", "pp-8", "pp-9", "pp-10"];
+
+test.use({ launchOptions: { args: ["--autoplay-policy=no-user-gesture-required"] } });
+test.beforeEach(() => test.setTimeout(180_000));
+
+const root = (page: Page) => page.locator("[data-play-cut]");
+
+/** 300-800 ms, the same for a URL every run. */
+const delayOf = (url: string) => {
+ let h = 2166136261;
+ for (let i = 0; i < url.length; i += 1) h = Math.imul(h ^ url.charCodeAt(i), 16777619) >>> 0;
+ return 300 + (h % 501);
+};
+
+async function throttle(page: Page) {
+ const seen = { n: 0 };
+ await page.route(/\/api\/report\/(post-item|file)\?/, async (route) => {
+ if (route.request().method() !== "GET") return route.continue();
+ seen.n += 1;
+ await new Promise((r) => setTimeout(r, delayOf(route.request().url())));
+ await route.continue().catch(() => {});
+ });
+ return seen;
+}
+
+/** Every animation frame from now: the post item on screen, its second, its card drawn, its voice, the clock's state. */
+const startSampling = (page: Page) =>
+ page.evaluate(() => {
+ const w = window as unknown as { __pp: unknown[]; __ppStop?: boolean };
+ w.__pp = [];
+ w.__ppStop = false;
+ const loop = () => {
+ const cut = document.querySelector("[data-play-cut]");
+ const p = document.querySelector("[data-post-play]");
+ if (cut && p) {
+ const id = p.getAttribute("data-post-play");
+ const f = p.querySelector('iframe[data-post-card-frame="read"]') as HTMLIFrameElement | null;
+ const body = f?.contentDocument?.body;
+ const a = p.querySelector("audio[data-post-narration-audio]") as HTMLAudioElement | null;
+ w.__pp.push({
+ id,
+ s: Number(p.getAttribute("data-post-s")),
+ card: !!body && body.getAttribute("data-post-ready") === "1" && body.getAttribute("data-post-item") === id && f!.style.visibility !== "hidden",
+ voice: !!a && !a.paused && a.currentTime > 0.02,
+ state: cut.getAttribute("data-play-state"),
+ });
+ }
+ if (!w.__ppStop) requestAnimationFrame(loop);
+ };
+ requestAnimationFrame(loop);
+ });
+
+type Sample = { id: string; s: number; card: boolean; voice: boolean; state: string };
+type Report = { id: string; seconds: number; covered: number; voice: boolean };
+
+/** Per item: the share of its seconds (0.1 s at a time, as the page shows it: from-start to to-start) drawn while the clock ran, and its voice. */
+async function coverage(page: Page, ids: string[]): Promise<{ items: Report[]; waits: { count: number; ms: number; last: unknown[] } }> {
+ const { samples, items, waits } = await page.evaluate(() => {
+ const w = window as unknown as { __pp: Sample[]; __ppStop?: boolean; __umtoolPlayEngine?: { plan: { items: { id: string; start: number; from: number; to: number }[] }; stats: { waits: { count: number; ms: number; last: unknown[] } } } };
+ w.__ppStop = true;
+ const e = w.__umtoolPlayEngine!;
+ return { samples: w.__pp, items: e.plan.items.map((x) => ({ id: x.id, start: x.start, from: x.from, to: x.to })), waits: e.stats.waits };
+ });
+ const out: Report[] = [];
+ for (const id of ids) {
+ const it = items.find((x) => x.id === id)!;
+ const s0 = it.from - it.start;
+ const n = Math.max(1, Math.ceil((it.to - it.from) * 10 - 1e-6));
+ const lit = new Set<number>();
+ let voice = false;
+ for (const x of samples) {
+ if (x.id !== id) continue;
+ voice ||= x.voice;
+ if (!x.card || x.state !== "playing") continue;
+ const k = Math.floor((x.s - s0) * 10 + 1e-6);
+ if (k >= 0 && k < n) lit.add(k);
+ }
+ out.push({ id, seconds: Math.round((it.to - it.from) * 100) / 100, covered: Math.round((lit.size / n) * 100) / 100, voice });
+ }
+ return { items: out, waits };
+}
+
+async function playToEnd(page: Page) {
+ await startSampling(page);
+ await page.locator("[data-play-toggle]").click();
+ await expect(root(page)).toHaveAttribute("data-play-state", "ended", { timeout: 120_000 });
+}
+
+function judge(label: string, r: Awaited<ReturnType<typeof coverage>>, requests: number) {
+ console.log(`play-preload ${label}: ${requests} slowed requests; held ${r.waits.count} time(s), ${(r.waits.ms / 1000).toFixed(2)} s in all`);
+ for (const x of r.items) console.log(` ${x.id.padEnd(6)} ${x.seconds.toFixed(2)} s card drawn ${(x.covered * 100).toFixed(0)}% voice ${x.voice ? "heard" : "NOT HEARD"}`);
+ for (const x of r.items) {
+ expect.soft(x.covered, `${x.id}: its card drawn for at least 90% of its ${x.seconds} s`).toBeGreaterThanOrEqual(0.9);
+ expect.soft(x.voice, `${x.id}: its narration started`).toBe(true);
+ }
+}
+
+test("THE BURST, SLOWED: every item of a fast run plays in full -- its card drawn for >= 90% of its seconds, its voice heard", async ({ page }) => {
+ await page.setViewportSize({ width: 1366, height: 1000 });
+ const seen = await throttle(page);
+ await page.goto(urls.playHref(PROJECT, { bare: true, clip: "pp-1" }));
+ await expect(root(page)).toHaveAttribute("data-play-item", "pp-1");
+ await expect(root(page)).toHaveAttribute("data-play-compose", "ready", { timeout: 60_000 });
+ await expect(page.locator('[data-post-play="pp-1"]')).toHaveCount(1);
+ await playToEnd(page);
+ judge("from the top", await coverage(page, IDS), seen.n);
+});
+
+test("A JUMP INTO THE BURST: the items after a seek are fetched from there, and play in full", async ({ page }) => {
+ await page.setViewportSize({ width: 1366, height: 1000 });
+ const seen = await throttle(page);
+ await page.goto(urls.playHref(PROJECT, { bare: true, clip: "pp-1" }));
+ await expect(root(page)).toHaveAttribute("data-play-item", "pp-1");
+ await expect(root(page)).toHaveAttribute("data-play-compose", "ready", { timeout: 60_000 });
+ // N: the next item, five times -- a seek to pp-6.
+ for (let k = 0; k < 5; k += 1) await page.keyboard.press("n");
+ await expect(root(page)).toHaveAttribute("data-play-item", "pp-6");
+ await playToEnd(page);
+ judge("after a jump to pp-6", await coverage(page, IDS.slice(5)), seen.n);
+});