commit 8e0e468207aca51a9569ad93695fdceadabbf0de
parent 7356a819a6fa769fafb54ee777361dffd7d51a62
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Wed, 4 Nov 2026 13:05:18 -0500
umtool: the clock placed by its own post's counts row on a threaded card, judged over the read; e2e post-captions (a caption added on the bench and drawn in Play, CJK by Noto Sans CJK, over no word read while it is up; the clock run forward and rewound)
A threaded card draws a counts row per tile: the clock sits by the post's own (data-thread-tile="post"), else
the last, placed as the card is at the read's end and judged over no word at its start, middle and end (the
render and Play alike).
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
2 files changed, 130 insertions(+), 1 deletion(-)
diff --git a/umtool/e2e/post-captions.spec.ts b/umtool/e2e/post-captions.spec.ts
@@ -0,0 +1,127 @@
+import { test, expect, type Page } from "@playwright/test";
+import { copyFileSync, existsSync, readFileSync, rmSync, writeFileSync } from "node:fs";
+import path from "node:path";
+import { fileURLToPath } from "node:url";
+import * as urls from "./urls";
+
+// ---------------------------------------------------------------------------
+// A POST ITEM's CAPTION and CLOCK (report-to-video/post-caption.mjs,
+// post-clock.mjs; knobs.md, "A caption", "The clock"). Fixture:
+// e2e/fixtures/post-narration-fixture.mjs -- p-11 "The video speaks for
+// itself." narrated by a 2 s take (no word timings: the reading estimate),
+// p-12 four pictures, p-13 words only; all dated 30 Oct 10:00 UTC.
+//
+// POST_CAPTIONS_SHOTS=<dir> screenshots there
+// ---------------------------------------------------------------------------
+
+const HERE = path.dirname(fileURLToPath(import.meta.url));
+const DIR = path.join(HERE, "..", ".e2e-song", "reports", "post-narration-fixture");
+const MANIFEST = path.join(DIR, "video.manifest.json");
+const PROJECT = "reports/post-narration-fixture";
+const SHOTS = process.env.POST_CAPTIONS_SHOTS ?? null;
+
+type Entry = { id: string; date?: string; fx?: Array<Record<string, unknown>> };
+const manifest = () => JSON.parse(readFileSync(MANIFEST, "utf8")) as { timeline: Entry[]; render: Record<string, unknown> };
+const timeline = () => manifest().timeline;
+
+test.beforeAll(() => {
+ if (!existsSync(`${MANIFEST}.pristine`)) copyFileSync(MANIFEST, `${MANIFEST}.pristine`);
+});
+test.beforeEach(() => {
+ test.setTimeout(120_000);
+ copyFileSync(`${MANIFEST}.pristine`, MANIFEST);
+ rmSync(path.join(DIR, "revisions"), { recursive: true, force: true });
+ rmSync(path.join(DIR, "notes.json"), { force: true });
+});
+
+type Box = { x: number; y: number; width: number; height: number };
+const overlap = (a: Box, b: Box) => Math.max(0, Math.min(a.x + a.width, b.x + b.width) - Math.max(a.x, b.x)) * Math.max(0, Math.min(a.y + a.height, b.y + b.height) - Math.max(a.y, b.y));
+/** In the card frame: the box of `sel` and of every card word. */
+const boxesIn = (page: Page, sel: string) =>
+ page.frameLocator('[data-post-card-frame="read"]').locator("body").evaluate((body, s) => {
+ const r = (el: Element) => {
+ const b = el.getBoundingClientRect();
+ return { x: b.left, y: b.top, width: b.width, height: b.height };
+ };
+ const el = body.ownerDocument.querySelector(s);
+ return { el: el ? r(el) : null, words: Array.from(body.ownerDocument.querySelectorAll("[data-w]")).map((w) => ({ id: w.getAttribute("data-w"), ...r(w) })) };
+ }, sel);
+
+test("A CAPTION (operator, 4 Nov: 不動心 on \"Fudōshin\"): click a word -> type the text -> Caption here -> saved, timed by the reading estimate; Play shows the chip (CJK drawn) by the phrase as it is read, over no word read while it is up", async ({ page }) => {
+ await page.setViewportSize({ width: 1500, height: 1100 });
+ await page.goto(urls.postBenchHref(PROJECT, "p-11"));
+ const panel = page.locator('[data-post-zoom-panel="p-11"]');
+ await panel.locator('[data-post-zoom-word="2"]').click();
+ await expect(panel.locator("[data-post-caption-here]")).toBeDisabled();
+ await panel.locator("[data-post-caption-text]").fill("不動心 · speaks — a test of the chip");
+ await panel.locator("[data-post-caption-here]").click();
+ await expect(panel.locator('[data-post-caption-fx="0"]')).toBeVisible();
+ expect(timeline().find((e) => e.id === "p-11")!.fx).toEqual([{ kind: "caption", match: "speaks", text: "不動心 · speaks — a test of the chip" }]);
+ // Its time: no word timings, so the read spread over its script by characters (0.4 + 10/29 of 2 s).
+ const at = Number(await panel.locator("[data-post-caption-at]").getAttribute("data-post-caption-at"));
+ expect(at).toBeGreaterThan(0.9);
+ expect(at).toBeLessThan(1.3);
+ await expect(panel.locator('[data-post-caption-fx="0"]')).toContainText("the reading estimate");
+ await expect(page.locator('[data-post-bench-caption-mark="0"]')).toBeVisible();
+ // A knob: place above, one write.
+ await panel.locator('[data-post-caption-knob="place"]').selectOption("above");
+ await expect.poll(() => timeline().find((e) => e.id === "p-11")!.fx?.[0]?.place).toBe("above");
+ // The bench's own player mounts the chip.
+ await expect(page.locator('[data-post-play="p-11"]')).toHaveAttribute("data-post-captions", "1", { timeout: 15_000 });
+ if (SHOTS) await page.screenshot({ path: path.join(SHOTS, "post-caption-bench.png") });
+
+ // Play the cut: up from its lead-in, the chip in the card page, by the phrase.
+ await page.goto(urls.playHref(PROJECT, { bare: true, clip: "p-11" }));
+ const player = page.locator('[data-post-play="p-11"]');
+ await expect(player).toHaveAttribute("data-post-captions", "1", { timeout: 15_000 });
+ await page.locator("[data-play-toggle]").click();
+ await expect(player).toHaveAttribute("data-post-caption-fx", "0", { timeout: 15_000 });
+ await page.locator("[data-play-toggle]").click();
+ const chip = page.frameLocator('[data-post-card-frame="read"]').locator('[data-post-fx-caption="0"]');
+ await expect(chip).toContainText("不動心");
+ await expect.poll(() => chip.evaluate((el) => Number((el as HTMLElement).style.opacity))).toBeGreaterThan(0);
+ // CJK is drawn by a face this machine has, not boxes.
+ expect(await chip.evaluate((el) => el.ownerDocument.fonts.check("27px 'Noto Sans CJK JP'", "不動心"))).toBe(true);
+ // Never over the words read while it is up ("for itself." after "speaks"); never in the card's words.
+ const { el, words } = await boxesIn(page, '[data-post-fx-caption="0"]');
+ expect(el).not.toBeNull();
+ for (const w of words.filter((x) => x.id === "post:3" || x.id === "post:4")) expect(overlap(el!, w)).toBe(0);
+ expect(await chip.evaluate((el) => el.closest("[data-post-card]") === null && !el.querySelector("[data-w], [data-post-block]"))).toBe(true);
+ // Its underline under the phrase.
+ await expect(page.frameLocator('[data-post-card-frame="read"]').locator('[data-post-fx-caption-mark="0"]')).toHaveCount(1);
+ if (SHOTS) await page.screenshot({ path: path.join(SHOTS, "post-caption-play.png") });
+});
+
+test("THE CLOCK: each item's own time on its card, run FORWARD from the clock item before (the gap flashing) and REWOUND when the next is earlier; Play draws it over no word", async ({ page }) => {
+ const m = manifest();
+ const set = (id: string, o: Record<string, unknown>) => Object.assign(m.timeline.find((e) => e.id === id)!, o);
+ set("p-11", { fx: [{ kind: "clock" }] });
+ set("p-12", { date: "2026-10-30T10:38:00.000Z", fx: [{ kind: "clock" }] });
+ set("p-13", { date: "2026-10-28T09:00:00.000Z", fx: [{ kind: "clock" }] });
+ writeFileSync(MANIFEST, JSON.stringify(m, null, 2) + "\n");
+ await page.setViewportSize({ width: 1500, height: 1000 });
+
+ // Forward: p-12 after p-11, 38 minutes on (America/New_York: 6:00 AM -> 6:38 AM).
+ await page.goto(urls.playHref(PROJECT, { bare: true, clip: "p-12" }));
+ const p12 = page.locator('[data-post-play="p-12"]');
+ await expect(p12).toHaveAttribute("data-post-clock-mode", "forward", { timeout: 15_000 });
+ await page.locator("[data-play-toggle]").click();
+ await expect(p12).toHaveAttribute("data-post-clock-gap", "+38 min", { timeout: 15_000 });
+ await expect(p12).toHaveAttribute("data-post-clock", "6:38 AM Fri 30 Oct", { timeout: 15_000 });
+ await page.locator("[data-play-toggle]").click();
+ const clock = page.frameLocator('[data-post-card-frame="read"]').locator("[data-post-clock]");
+ await expect(clock).toContainText("ET");
+ const { el, words } = await boxesIn(page, "[data-post-clock]");
+ for (const w of words) expect(overlap(el!, w)).toBe(0);
+ if (SHOTS) await page.screenshot({ path: path.join(SHOTS, "post-clock-forward.png") });
+
+ // Rewind: p-13 is two days earlier than p-12.
+ await page.goto(urls.playHref(PROJECT, { bare: true, clip: "p-13" }));
+ const p13 = page.locator('[data-post-play="p-13"]');
+ await expect(p13).toHaveAttribute("data-post-clock-mode", "rewind", { timeout: 15_000 });
+ await page.locator("[data-play-toggle]").click();
+ await expect(p13).toHaveAttribute("data-post-clock-gap", /^⟲ rewind −2 d 1 h/, { timeout: 15_000 });
+ await expect(p13).toHaveAttribute("data-post-clock", "5:00 AM Wed 28 Oct", { timeout: 15_000 });
+ await page.locator("[data-play-toggle]").click();
+ if (SHOTS) await page.screenshot({ path: path.join(SHOTS, "post-clock-rewind.png") });
+});
diff --git a/umtool/report-to-video/post-clock.mjs b/umtool/report-to-video/post-clock.mjs
@@ -282,7 +282,9 @@ export function measureClockPlace(arg, doc = document) {
const c = card.getBoundingClientRect();
const words = Array.from(doc.querySelectorAll("[data-w]")).flatMap((el) => Array.from(el.getClientRects())).filter((r) => r.width > 0);
const hit = (r) => words.filter((w) => Math.min(r.x + r.width, w.right) - Math.max(r.x, w.left) > 1 && Math.min(r.y + r.height, w.bottom) - Math.max(r.y, w.top) > 1).length;
- const counts = card.querySelector(".counts");
+ // Its own post's counts row (a threaded card draws one per tile: the post's tile, else the last).
+ const all = Array.from(card.querySelectorAll(".counts"));
+ const counts = card.querySelector('[data-thread-tile="post"] .counts') || all[all.length - 1] || null;
const cb = counts ? counts.getBoundingClientRect() : null;
const x = Math.round(c.right - arg.inset - arg.size.width);
// Bottom: centred on the counts row when there is one, else in the card's foot.