import { test, expect } from "@playwright/test"; import { existsSync, readFileSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import * as urls from "./urls"; // --------------------------------------------------------------------------- // Release 28 lane E's media drafts, as umtool shows them (M6): the project // page's YouTube text — previewed from publish.youtube before a build (the // sources, no chapters), copied with Copy, then as a fast build writes it to // out/youtube.txt with the build's own chapters (YouTube's rules) and a moment // link per cited clip. The flips, threads and youtube tasks themselves run // over the fake LLM in common's and the MCP's suites; umtool's "Draft with" // buttons are M9's. Fixture: e2e/fixtures/youtube-fixture.mjs. // --------------------------------------------------------------------------- const HERE = path.dirname(fileURLToPath(import.meta.url)); const FIXTURE = path.join(HERE, "..", ".e2e-song"); const PROJECT = "reports/youtube-fixture"; const DIR = path.join(FIXTURE, "reports", "youtube-fixture"); const TITLE = "The county said yes"; const SUMMARY = "Half a year on, the county said yes, and the fixture says so."; const SOURCES = ["https://archive.example/?v=testchan%2Fvid1&t=3", "https://archive.example/?v=testchan%2Fvid1&t=9"]; test("the YouTube text: a preview before the build, Copy, then out/youtube.txt with chapters and sources", async ({ page, request, context }) => { test.setTimeout(300_000); await context.grantPermissions(["clipboard-read", "clipboard-write"]); await page.goto(urls.section(PROJECT, "youtube")); const section = page.locator("[data-youtube]"); await expect(section).toHaveAttribute("data-youtube", "preview"); await expect(section.locator("[data-youtube-status]")).toContainText("chapters are added by the build"); await expect(section.locator("[data-youtube-status]")).toContainText("drafted by qwen3:8b"); const preview = await section.locator("[data-youtube-text]").textContent(); expect(preview).toBe(`${TITLE}\n\n${SUMMARY}\n\nSources\n${SOURCES.join("\n")}\n`); await section.getByRole("button", { name: "Copy" }).click(); await expect(section.locator("[data-copy]")).toHaveAttribute("data-state", "done"); expect(await page.evaluate(() => navigator.clipboard.readText())).toBe(preview); // A fast build (hard cuts) writes the text with the build's chapters. const start = await request.post("/api/report/build", { data: { project: PROJECT, preset: "fast" } }); expect(start.ok(), await start.text()).toBeTruthy(); const { job } = (await start.json()) as { job: { id: string } }; let done: { state: string; error: string | null } = { state: "running", error: null }; const until = Date.now() + 240_000; while (Date.now() < until) { done = (await (await request.get(`/api/report/build?job=${job.id}`)).json()) as typeof done; if (done.state !== "running") break; await new Promise((r) => setTimeout(r, 400)); } expect(done.state, done.error ?? "").toBe("done"); const file = path.join(DIR, "out", "youtube.txt"); expect(existsSync(file)).toBe(true); const text = readFileSync(file, "utf8"); const [title, , summary, , chaptersHead, ...rest] = text.split("\n"); expect([title, summary, chaptersHead]).toEqual([TITLE, SUMMARY, "Chapters"]); // Five entries; the two under ten seconds after a chapter are folded: three // chapters, the first at 0:00 (the title card), the clips' at 0:10 and 0:2x. const chapters = rest.slice(0, rest.indexOf("")); expect(chapters.length).toBe(3); expect(chapters[0]).toBe("0:00 The YouTube Fixture"); expect(chapters[1]).toMatch(/^0:1\d /); expect(chapters[2]).toMatch(/^0:2\d /); expect(text.endsWith(`\n\nSources\n${SOURCES.join("\n")}\n`)).toBe(true); // The page shows the built text now. await page.reload(); await expect(section).toHaveAttribute("data-youtube", "built"); await expect(section.locator("[data-youtube-status]")).toContainText("out/youtube.txt, built"); expect(await section.locator("[data-youtube-text]").textContent()).toBe(text); });