import { test, expect, type APIRequestContext, type Page } from "@playwright/test"; import { mkdirSync, readFileSync, rmSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import { portFor } from "yt-dlp-transcript-common/lib/ports.mjs"; import { NY_CASE, NY_EMBED, NY_LINKS, NY_PROJECT, NY_TITLE } from "./fixtures/needs-you-fixture.mjs"; import * as urls from "./urls"; import { warm, WARM_TIMEOUT } from "./warm"; // --------------------------------------------------------------------------- // WHAT NEEDS YOU (umtool redesign L4): home is the Inbox, widened -- // // each new kind from its fixture (fixtures/needs-you-fixture.mjs): versions to judge, clips not walked, quote // checks out of date, a live case's new transcripts, X's jar (the stub editor's services, only while X work // waits), and a dead Rumble QR with Use embed ids; // one-press actions that change the file: Play and judge (verdicts.json), Use embed ids (the manifest's // siteVideo), Run quote-check (a step on the durable queue); // the Quick clip box: a moment found, its edges nudged, rendered (the stub editor's window), its share line; // the rail keeps navigation only: Running and the Recent cuts are on home. // // The tests run in order: Quick clip before Run quote-check, which leaves a step on the queue (cancelled after). // --------------------------------------------------------------------------- test.describe.configure({ mode: "serial" }); const HERE = path.dirname(fileURLToPath(import.meta.url)); const FIXTURE = path.join(HERE, "..", ".e2e-song"); const P = `reports/${NY_PROJECT}`; const L = `reports/${NY_LINKS}`; const DIR = path.join(FIXTURE, "reports", NY_PROJECT); const LDIR = path.join(FIXTURE, "reports", NY_LINKS); const STUB = `http://127.0.0.1:${portFor("EDITOR_STUB_PORT")}`; const QUICK_PROJECT = "quick-clips/basicyt-quickvid-10"; const SHOTS = process.env.E2E_NEEDS_YOU_SHOTS ?? ""; const shot = async (page: Page, name: string) => { if (!SHOTS) return; mkdirSync(SHOTS, { recursive: true }); await page.screenshot({ path: path.join(SHOTS, `${name}.png`) }); }; const card = (page: Page, kind: string, piece: string | null = null) => page.locator(`[data-card='${kind}']${piece ? `[data-piece='${piece}']` : ""}`); const json = (file: string) => JSON.parse(readFileSync(file, "utf8")); const X_ALERT = { service: "x", label: "X", family: "x", state: "stale", kind: "jar-age", since: "2026-11-09T09:00:00.000Z", raisedAt: "2026-11-09T09:00:00.000Z", headline: "X cookies are 3 h old (limit 60 min)", fix: "Refresh cookies (or Connect X account) on /settings — then Recheck.", detail: "2 X jobs are queued.", }; const services = (request: APIRequestContext, alerts: unknown[]) => request.post(`${STUB}/__stub/services`, { data: { alerts } }); let queued: string | null = null; test.beforeAll(async ({ playwright }) => { test.setTimeout(WARM_TIMEOUT); await warm(playwright, ["/", "/api/browse/decisions", urls.playHref(P, { take: "short" }), `/api/report/quick-clip/strip?moment=${encodeURIComponent("basicyt/quickvid@10-14")}`]); }); test.afterAll(async ({ request }) => { await services(request, []); if (queued) await request.post(`/api/queue?cancel=${queued}`); rmSync(path.join(FIXTURE, "quick-clips", "basicyt-quickvid-10"), { recursive: true, force: true }); rmSync(path.join(FIXTURE, "channels", "basicyt", "data", "quickvid", "clips"), { recursive: true, force: true }); }); test("each new call is on home from its fixture -- versions, clips, quote checks, the case, the Rumble QR; X's jar only while X work waits", async ({ page, request }) => { test.setTimeout(120_000); await page.setViewportSize({ width: 1366, height: 768 }); await services(request, []); await page.goto("/"); const piece = `p:${P}`; const versions = card(page, "version-unjudged", piece); await expect(versions).toBeVisible({ timeout: 60_000 }); await expect(versions.locator("[data-card-title]")).toContainText(`${NY_TITLE} · 2 versions to judge`); await expect(versions.locator("[data-action-link]")).toHaveText("Play and judge"); await expect(page.locator(`[data-group=review] [data-card='version-unjudged'][data-piece='${piece}']`)).toHaveCount(1); const walk = card(page, "clips-unwalked", piece); await expect(walk.locator("[data-card-title]")).toContainText("3 clips not walked"); await expect(walk.locator("[data-action-link]")).toHaveAttribute("href", urls.clipBenchHref(P, "c02")); const checks = card(page, "quote-check-stale", piece); await expect(checks.locator("[data-card-title]")).toContainText("4 quote checks out of date"); await expect(checks.locator("[data-count]")).toHaveText("4"); await expect(checks.locator("[data-settle-button='quote-check']")).toHaveText("Run quote-check"); // A one-press card's title still goes where it is settled. await expect(checks.locator("[data-card-link]")).toHaveAttribute("href", urls.projectHref(P)); const theCase = card(page, "case-new-cues", `c:${NY_CASE}`); await expect(theCase.locator("[data-card-title]")).toContainText("1 new transcript since the last scan"); await expect(theCase.locator("[data-action-link]")).toHaveAttribute("href", `/research/${NY_CASE}/pipeline`); const links = page.locator(`[data-group=blocking] [data-card='link-dead'][data-piece='p:${L}']`); await expect(links.locator("[data-settle-button='links']")).toHaveText("Use embed ids (1)"); // X's jar: nothing while no X work waits; the editor's three lines once its alert is up. await expect(card(page, "x-jar-stale")).toHaveCount(0); await services(request, [X_ALERT]); await page.reload(); const x = page.locator("[data-group=blocking] [data-card='x-jar-stale']"); await expect(x).toBeVisible({ timeout: 30_000 }); await expect(x).toContainText("X cookies are 3 h old (limit 60 min)"); await expect(x).toContainText("2 X jobs are queued."); await expect(x.locator("[data-action-link]")).toHaveText("Refresh X's cookies"); await expect(x.locator("[data-action-link]")).toHaveAttribute("href", `${STUB}/settings`); await shot(page, "needs-you-home"); // The API keeps one row per decision. const items = ((await (await request.get("/api/browse/decisions")).json()) as { items: { kind: string; project: string; target: string }[] }).items; expect(items.filter((d) => d.kind === "version-unjudged" && d.project === P).map((d) => d.target).sort()).toEqual(["short", "v1"]); expect(items.filter((d) => d.kind === "clips-unwalked" && d.project === P).map((d) => d.target)).toEqual(["c02", "c03", "c04"]); expect(items.filter((d) => d.kind === "quote-check-stale" && d.project === P).map((d) => d.target)).toEqual(["c01", "c02", "c03", "c04"]); // X's jar is a machine call (lib/machine.ts): on the page and the rail's count, not a piece's row. expect(items.some((d) => d.kind === "x-jar-stale")).toBe(false); expect(items.filter((d) => d.kind === "case-new-cues").map((d) => (d as { piece?: string }).piece)).toContain(`c:${NY_CASE}`); await services(request, []); await page.reload(); await expect(card(page, "x-jar-stale")).toHaveCount(0); }); test("the rail keeps navigation only: Running and the Recent cuts are on home", async ({ page }) => { await page.setViewportSize({ width: 1366, height: 768 }); await page.goto(urls.playHref(P, { take: "short" })); await expect(page.locator("[data-play-take='short']")).toBeVisible({ timeout: 60_000 }); await page.goto("/"); const rail = page.locator("[data-app-rail]"); await expect(rail).toBeVisible(); await expect(rail.locator("[data-rail-section=pins], [data-home-section=running], [data-home-section=recent-cuts]")).toHaveCount(0); await expect(rail).not.toContainText("Pinned"); const aside = page.locator("[data-home-aside]"); await expect(aside.locator("[data-home-section=running]")).toBeVisible(); await expect(aside.locator("[data-quick-clip]")).toBeVisible(); // Play remembered the cut: it is a Recent cut on home. await expect(aside.locator(`[data-recent-cut='${P}']`)).toBeVisible(); }); test("Play and judge: the card opens Play on the version; Like writes verdicts.json and the card counts one fewer", async ({ page }) => { test.setTimeout(120_000); await page.setViewportSize({ width: 1366, height: 768 }); await page.goto("/"); const versions = card(page, "version-unjudged", `p:${P}`); await versions.locator("[data-action-link]").click(); // Play keeps where it is in its address (clip, at): the version is the take. await expect(page).toHaveURL(/\/play\?take=short(&|$)/); const verdict = page.locator("[data-play-take='short'] [data-play-verdict]"); await expect(verdict.locator("[data-play-verdict-button='like']")).toBeEnabled({ timeout: 60_000 }); await shot(page, "needs-you-play-judge"); await verdict.locator("[data-play-verdict-button='like']").click(); await expect(verdict).toHaveAttribute("data-play-verdict", "like"); await expect(verdict.locator("[data-play-verdict-button='like']")).toHaveAttribute("aria-pressed", "true"); expect(json(path.join(DIR, "takes", "verdicts.json")).short?.verdict).toBe("like"); await page.goto("/"); const left = card(page, "version-unjudged", `p:${P}`); await expect(left.locator("[data-card-title]")).toContainText("1 version to judge"); await expect(left.locator("[data-action-link]")).toHaveAttribute("href", urls.playHref(P, { take: "v1" })); // The saved version too: judged where it plays (its base, frozen). await left.locator("[data-action-link]").click(); await page.locator("[data-play-take='v1'] [data-play-verdict-button='no']").click(); await expect(page.locator("[data-play-take='v1'] [data-play-verdict]")).toHaveAttribute("data-play-verdict", "no"); expect(json(path.join(DIR, "takes", "verdicts.json")).v1?.verdict).toBe("no"); await page.goto("/"); await expect(card(page, "version-unjudged", `p:${P}`)).toHaveCount(0); }); test("Use embed ids: one press on the dead Rumble QR writes the clip's siteVideo, and the card goes", async ({ page }) => { test.setTimeout(120_000); await page.goto("/"); const links = page.locator(`[data-card='link-dead'][data-piece='p:${L}']`); await links.locator("[data-settle-button='links']").click(); await expect(links.locator("[data-settle-said]")).toContainText("fixed n01", { timeout: 60_000 }); const n01 = (json(path.join(LDIR, "video.manifest.json")).timeline as { id: string; siteVideo?: string }[]).find((e) => e.id === "n01"); expect(n01?.siteVideo).toBe(NY_EMBED); // One undo point before the rewrite, as `umtool links --fix` takes. await page.reload(); await expect(page.locator(`[data-card='link-dead'][data-piece='p:${L}']`)).toHaveCount(0); }); test("Quick clip: a moment link found, the edges nudged on its words, rendered, the share line copied", async ({ page, context }) => { test.setTimeout(300_000); await context.grantPermissions(["clipboard-read", "clipboard-write"]); await page.setViewportSize({ width: 1366, height: 768 }); await page.goto("/"); const box = page.locator("[data-quick-clip]"); const input = box.locator("[data-quick-clip-input]"); // A platform link names no channel: the one channel holding the recording is found; its span is its sentence. await input.fill("https://www.youtube.com/watch?v=quickvid&t=10"); await box.locator("[data-quick-clip-find]").click(); await expect(box.locator("[data-quick-clip-strip]")).toHaveAttribute("data-quick-clip-strip", "basicyt/quickvid@10-30", { timeout: 30_000 }); await input.fill("nothing here"); await box.locator("[data-quick-clip-find]").click(); await expect(box.locator("[data-quick-clip-error]")).toContainText("not a moment"); await input.fill("basicyt/quickvid@10-14"); await box.locator("[data-quick-clip-find]").click(); await expect(box.locator("[data-quick-clip-strip]")).toHaveAttribute("data-quick-clip-strip", "basicyt/quickvid@10-14", { timeout: 30_000 }); await expect(box.locator("[data-editor-words]")).toContainText("a synthetic tone"); await box.locator("[data-quick-clip-nudge='start:0.5']").click(); await box.locator("[data-quick-clip-nudge='end:-0.5']").click(); await box.locator("[data-quick-clip-nudge='end:0.5']").click(); await expect(box.locator("[data-quick-clip-spec]")).toHaveText("umtool clip basicyt/quickvid@10.5-14"); await shot(page, "needs-you-quick-clip"); await box.locator("[data-quick-clip-render]").click(); await expect(box).toHaveAttribute("data-quick-clip", "done", { timeout: 240_000 }); await expect(box.locator("[data-quick-clip-done]")).toHaveAttribute("data-quick-clip-done", QUICK_PROJECT); const made = json(path.join(FIXTURE, QUICK_PROJECT, "video.manifest.json")); expect(made.render.mode).toBe("basic"); expect(made.timeline.map((e: { video: string; start: number }) => `${e.video}@${e.start}`)).toEqual(["quickvid@10.5"]); const copy = box.locator('[data-share-copy="quick-clip"]'); await copy.click(); await expect(copy).toHaveAttribute("data-share-state", /copied|shown/, { timeout: 60_000 }); await expect(box.locator('[data-share-line-box="quick-clip"] [data-share-line]')).toHaveText("https://www.youtube.com/watch?v=quickvid&t=10s"); await shot(page, "needs-you-quick-clip-done"); // A quick clip is shared, not judged or walked: no version to judge, no clips to walk. const items = ((await (await page.request.get("/api/browse/decisions")).json()) as { items: { project: string; kind: string }[] }).items; expect(items.filter((d) => d.project === QUICK_PROJECT && (d.kind === "version-unjudged" || d.kind === "clips-unwalked"))).toEqual([]); }); test("Run quote-check: one press queues `umtool quote-check` on the card's clips", async ({ page, request }) => { test.setTimeout(120_000); await page.goto("/"); const checks = card(page, "quote-check-stale", `p:${P}`); await checks.locator("[data-settle-button='quote-check']").click(); const said = checks.locator("[data-settle-said]"); await expect(said).toContainText(/queued as q\d+ — 4 clips/, { timeout: 30_000 }); queued = /queued as (q\d+)/.exec((await said.textContent()) ?? "")?.[1] ?? null; const view = (await (await request.get(`/api/queue?project=${encodeURIComponent(P)}&all=1`)).json()) as { steps: { qid: string; argv?: string[]; label?: string }[] }; const step = view.steps.find((s) => s.qid === queued); expect(step, JSON.stringify(view.steps)).toBeTruthy(); expect(JSON.stringify(step)).toContain("quote-check"); expect(JSON.stringify(step)).toContain("c01,c02,c03,c04"); // Off the queue again: it would hold the app's one job runner for the specs after this one. expect((await request.post(`/api/queue?cancel=${queued}`)).ok()).toBe(true); queued = null; });