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";
// ---------------------------------------------------------------------------
// PICTURE-ONLY POSTS (report-to-video/post-picture.mjs; knobs.md, "Picture-only posts"; operator, 5 Nov, the Mr.
// Obvious mid cut at 26:53: "the "It's time to stop" gif shows while Obvious is speaking rather than it being a
// picture-only response like the MW post, we need to handle this because it's a standard type of post"):
// - a reply's parent that is only "@him" and a GIF has its own beat before the reply's read: lit, alone, its GIF
// drawn IN ITS CARD (the page plays it) -- never in the slot -- and the reply's read after it, the GIF's card
// small and dim, still never in the slot;
// - an item that is only "@him" and a picture is a card alone, its picture inside it where its words would be;
// - the post bench says which posts are picture-only and sets the knob.
// Fixture: e2e/fixtures/post-narration-fixture.mjs's items, rewritten here.
//
// PICTURE_REPLIES_SHOTS=
screenshots there
// ---------------------------------------------------------------------------
const HERE = path.dirname(fileURLToPath(import.meta.url));
const REPORTS = path.join(HERE, "..", ".e2e-song", "reports");
const DIR = path.join(REPORTS, "post-narration-fixture");
const MANIFEST = path.join(DIR, "video.manifest.json");
const PROJECT = "reports/post-narration-fixture";
const SHOTS = process.env.PICTURE_REPLIES_SHOTS ?? null;
const REPLY = "Then do not antagonize me, that is something the whole community needs to learn about me.";
const GIF = { src: "posts-media/narrchan-x/11/11_1.mp4", kind: "gif", width: 320, height: 180, seconds: 2.5 };
function takeOf(text: string) {
const seconds = Math.round((text.split(/\s+/).length / 3) * 100) / 100;
return { file: "narration/posts/11/take-1.orpheus-zac.wav", engine: "orpheus", voice: "zac", seconds, script: text, parts: [{ n: 1, para: 0, text, start: 0, seconds, role: "post" }] };
}
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 });
const m = JSON.parse(readFileSync(MANIFEST, "utf8"));
const byId = (id: string) => m.timeline.find((x: { id: string }) => x.id === id);
// His reply to a post that is only "@narrsubject" and a GIF.
const reply = { ...structuredClone(byId("p-12")), id: "p-41", post: "narrchan-x/41", text: REPLY, date: "2026-10-30T07:00:00.000Z", narration: { script: REPLY, takes: [takeOf(REPLY)], pick: 0 } };
delete reply.media;
reply.parents = [{ id: "40", author: "Furri", handle: "furri_m", date: "2026-10-30T06:58:00.000Z", text: "@narrsubject", media: [GIF] }];
// A reply of somebody else's that is only "@narrsubject" and a picture.
const pic = { ...structuredClone(byId("p-12")), id: "p-42", post: "othchan-x/42", author: "Kir", handle: "kir_v", text: "@narrsubject", date: "2026-10-30T08:00:00.000Z", media: [{ src: "posts-media/narrchan-x/12/12_2.png", kind: "image", width: 320, height: 180 }], panel: "side" };
// A manual thread: her picture-only reply (its read the words on her picture), then his answer to it.
const SEEN = "Its words, as read off her picture, out loud.";
Object.assign(pic, { thread: { group: "kp" }, narration: { script: SEEN, takes: [takeOf(SEEN)], pick: 0 } });
const ANSWER = "Normally I do not respond to stuff like this, but you called me something, so here we go.";
const answer = { ...structuredClone(byId("p-12")), id: "p-43", post: "narrchan-x/43", text: ANSWER, date: "2026-10-30T09:00:00.000Z", thread: { group: "kp" }, narration: { script: ANSWER, takes: [takeOf(ANSWER)], pick: 0 } };
delete answer.media;
// His reply to a post that is only "@narrsubject" and a VIDEO WITH ITS SOUND (the meme from its original upload).
const meme = { ...structuredClone(reply), id: "p-44", post: "narrchan-x/44", date: "2026-10-30T11:00:00.000Z" };
meme.parents = [{ id: "45", author: "Furri", handle: "furri_m", date: "2026-10-30T10:58:00.000Z", text: "@narrsubject", media: [{ src: "posts-media/narrchan-x/11/11_1.mp4", kind: "video", width: 320, height: 180, seconds: 4, audio: true }] }];
m.timeline = [reply, pic, answer, byId("p-13"), meme];
writeFileSync(MANIFEST, JSON.stringify(m, null, 2) + "\n");
});
async function playAt(page: Page, id: string, at: number) {
await page.goto(urls.playHref(PROJECT, { bare: true, clip: id, at }));
const player = page.locator(`[data-post-play="${id}"]`);
await expect(player).toBeVisible({ timeout: 15_000 });
const frame = page.frameLocator('[data-post-card-frame="read"]');
await expect(frame.locator("body")).toHaveAttribute("data-post-ready", "1", { timeout: 15_000 });
await expect.poll(async () => Math.abs(Number(await player.getAttribute("data-post-s")) - at)).toBeLessThan(0.3);
return { player, frame };
}
const opacityOf = (frame: ReturnType, sel: string) => frame.locator(sel).evaluate((el) => {
let op = 1;
for (let e: Element | null = el; e; e = e.parentElement) op *= Number(getComputedStyle(e).opacity);
return op;
});
test("A PICTURE-ONLY PARENT has its own beat before his read: its GIF in its own card, alone and lit -- then his read, the GIF's card small and dim, never a GIF in the slot", async ({ page }) => {
await page.setViewportSize({ width: 1366, height: 1000 });
{
const { player, frame } = await playAt(page, "p-41", 1);
await expect(player).toHaveAttribute("data-post-pics", "parent:0");
await expect(player).toHaveAttribute("data-post-beat", "parent:0");
// Drawn IN the parent's card (the page plays it), where its words would be -- its mention small.
await expect(frame.locator('[data-thread-tile="parent:0"] [data-post-pic="parent:0"] video')).toHaveCount(1);
await expect(frame.locator('[data-thread-tile="parent:0"] .pmen')).toContainText("@narrsubject");
await expect(frame.locator("[data-thread-media]")).toHaveCount(0);
// Never over the slot.
await expect(page.locator('[data-post-panel="parent:0"]')).toHaveCount(0);
await expect(frame.locator("[data-post-slot]")).toHaveCount(0);
// (The card's frame may be swapped in once more as Play settles: read again until it holds.)
await expect(async () => expect(await opacityOf(frame, '[data-thread-tile="parent:0"]')).toBeGreaterThan(0.95)).toPass({ timeout: 10_000 });
const pic = await frame.locator('[data-post-pic="parent:0"]').boundingBox({ timeout: 10_000 });
expect(pic && pic.width > 300 && Math.abs(pic.width / pic.height - 16 / 9) < 0.05, "at the tile's width, its aspect kept").toBe(true);
if (SHOTS) await page.screenshot({ path: path.join(SHOTS, "picture-beat.png") });
}
{
// His read: after the beat (2.5 s) and the lead.
const { player, frame } = await playAt(page, "p-41", 5);
await expect(player).not.toHaveAttribute("data-post-beat", /./);
await expect(page.locator('[data-post-panel="parent:0"]')).toHaveCount(0);
await expect(async () => expect(await opacityOf(frame, '[data-thread-tile="parent:0"]')).toBeLessThan(0.7)).toPass({ timeout: 10_000 });
await expect(async () => expect(await opacityOf(frame, '[data-thread-tile="post"]')).toBeGreaterThan(0.95)).toPass({ timeout: 10_000 });
if (SHOTS) await page.screenshot({ path: path.join(SHOTS, "picture-read.png") });
}
});
test("A PICTURE-ONLY ITEM is a card alone, its picture inside it where its words would be -- no slot, whatever its panel says", async ({ page }) => {
await page.setViewportSize({ width: 1366, height: 1000 });
const { player, frame } = await playAt(page, "p-42", 0.5);
await expect(player).toHaveAttribute("data-post-layout", "text");
await expect(player).toHaveAttribute("data-post-pics", "post");
await expect(frame.locator('[data-post-card] [data-post-pic="post"] img')).toHaveCount(1);
await expect(frame.locator("[data-post-slot]")).toHaveCount(0);
const pic = await frame.locator('[data-post-pic="post"]').boundingBox();
const card = await frame.locator("[data-post-card]").boundingBox();
expect(pic && card && pic.width > card.width * 0.8, "the card's width").toBe(true);
if (SHOTS) await page.screenshot({ path: path.join(SHOTS, "picture-item.png") });
});
test("THE POST BENCH's picture-only block: the parent picture-only by the rule, the knob turns it off and Save writes it", async ({ page }) => {
await page.setViewportSize({ width: 1500, height: 1100 });
await page.goto(urls.postBenchHref(PROJECT, "p-41"));
const row = page.locator('[data-post-bench-picture-row="parent.0"]');
await expect(row).toHaveAttribute("data-picture-only", "1", { timeout: 15_000 });
await expect(row).toContainText("its beat 2.5 s before the read");
await page.locator('[data-post-bench-picture-knob="parent.0"]').selectOption("off");
await expect(row).toHaveAttribute("data-picture-only", "0");
await page.locator("[data-post-bench-save]").click();
await expect.poll(() => JSON.parse(readFileSync(MANIFEST, "utf8")).timeline.find((e: { id: string }) => e.id === "p-41").parents[0].pictureOnly).toBe(false);
});
test("CARRIED AS CONTEXT a picture-only post keeps its picture: his answer's card keeps her card on top, her picture in it (small and dim), never in the slot, no beat again", async ({ page }) => {
await page.setViewportSize({ width: 1366, height: 1000 });
const { player, frame } = await playAt(page, "p-43", 3);
await expect(player).toHaveAttribute("data-post-pics", "conv:42");
await expect(player).not.toHaveAttribute("data-post-beat", /./);
await expect(frame.locator('[data-thread-tile="conv:42"] [data-post-pic="conv:42"] img')).toHaveCount(1);
await expect(page.locator('[data-post-panel="conv:42"]')).toHaveCount(0);
await expect(frame.locator("[data-post-slot]")).toHaveCount(0);
await expect(async () => expect(await opacityOf(frame, '[data-thread-tile="conv:42"]')).toBeLessThan(0.7)).toPass({ timeout: 10_000 });
const pic = await frame.locator('[data-post-pic="conv:42"]').boundingBox({ timeout: 10_000 });
expect(pic && pic.width > 50 && Math.abs(pic.width / pic.height - 16 / 9) < 0.08, "its aspect kept").toBe(true);
if (SHOTS) await page.screenshot({ path: path.join(SHOTS, "picture-context.png") });
});
test("A PICTURE-ONLY VIDEO WITH ITS SOUND speaks through its beat in Play: the card's own video unmuted on Play's clock, its whole length the beat; muted once his read comes", async ({ page }) => {
await page.setViewportSize({ width: 1366, height: 1000 });
const { player, frame } = await playAt(page, "p-44", 0.5);
await expect(player).toHaveAttribute("data-post-beat", "parent:0");
await expect(player).toHaveAttribute("data-post-pic-sound", "parent:0");
await expect(frame.locator('[data-post-pic="parent:0"] video')).toHaveCount(1);
await page.locator("[data-play-toggle]").click();
await expect.poll(async () => frame.locator('[data-post-pic="parent:0"] video').evaluate((v) => (v as HTMLVideoElement).muted), { timeout: 10_000 }).toBe(false);
await page.locator("[data-play-toggle]").click();
// Its beat is the clip's 4 s; after it, his read -- the video muted.
const { player: p2, frame: f2 } = await playAt(page, "p-44", 6);
await expect(p2).not.toHaveAttribute("data-post-pic-sound", /./);
await expect.poll(async () => f2.locator('[data-post-pic="parent:0"] video').evaluate((v) => (v as HTMLVideoElement).muted)).toBe(true);
});