import { test, expect, type APIRequestContext, type Page } from "@playwright/test"; import { mkdirSync } from "node:fs"; import path from "node:path"; import { portFor } from "yt-dlp-transcript-common/lib/ports.mjs"; import * as urls from "./urls"; // --------------------------------------------------------------------------- // THE READINESS BAR (umtool redesign L7b; workspace/ReadinessBar.tsx, lib/inbox/readiness.mjs): under the // workspace's top bar, one pill each -- quote check, links, captures, render, X jar -- read from the calls the // Inbox reads (L4), each a click to its fix or its page. Read-only. // // readiness-fixture / readiness-links (READ-ONLY; needs-you-fixture.mjs under their own names): quote checks out // of date (c02 stale, c01 c03 c04 never checked), v1 and `short` rendered with no verdict, c03 never fetched; a // Rumble QR naming its folder (dead). X's jar: the stub editor's services, put up here and taken down after. // --------------------------------------------------------------------------- test.describe.configure({ mode: "serial" }); const P = "reports/readiness-fixture"; const L = "reports/readiness-links"; const STUB = `http://127.0.0.1:${portFor("EDITOR_STUB_PORT")}`; 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 on /settings.", detail: "2 X jobs are queued." }; const services = (request: APIRequestContext, alerts: unknown[]) => request.post(`${STUB}/__stub/services`, { data: { alerts } }); const pill = (page: Page, id: string) => page.locator(`[data-ws-readiness] [data-ready-pill="${id}"]`); const SHOTS = process.env.L7B_SHOTS ?? ""; test.beforeEach(async ({ page, request }) => { test.setTimeout(120_000); await page.setViewportSize({ width: 1366, height: 768 }); await services(request, []); }); test.afterAll(async ({ request }) => { await services(request, []); }); test("five pills under the top bar, the generated banner's row kept; the page still never scrolls", async ({ page }) => { await page.goto(urls.workspaceHref(P)); const bar = page.locator("[data-ws-readiness]"); await expect(bar).toBeVisible({ timeout: 30_000 }); expect(await bar.locator("[data-ready-pill]").evaluateAll((els) => els.map((e) => e.getAttribute("data-ready-pill")))).toEqual(["quote-check", "links", "captures", "render", "x-jar"]); // Right under the top bar. const top = await page.locator("[data-ws-top]").boundingBox(); const row = await bar.boundingBox(); expect(Math.abs(row!.y - (top!.y + top!.height))).toBeLessThan(2); expect(await page.evaluate(() => document.documentElement.scrollHeight <= window.innerHeight)).toBe(true); if (SHOTS) { mkdirSync(SHOTS, { recursive: true }); await page.screenshot({ path: path.join(SHOTS, "ws-readiness.png") }); } }); test("quote check: 4 out of date (the Inbox's quote-check-stale rows), its click home's Run quote-check", async ({ page }) => { await page.goto(urls.workspaceHref(P)); await expect(pill(page, "quote-check")).toHaveAttribute("data-ready-state", "count", { timeout: 30_000 }); await expect(pill(page, "quote-check")).toHaveAttribute("data-ready-count", "4"); await expect(pill(page, "quote-check")).toHaveAttribute("title", /c02: .*cut or quote changed/); await expect(pill(page, "quote-check")).toHaveAttribute("href", urls.homeHref()); }); test("links: the dead Rumble QR is ! (blocking), its click the piece's decisions where Use embed ids is", async ({ page }) => { await page.goto(urls.workspaceHref(L)); await expect(pill(page, "links")).toHaveAttribute("data-ready-state", "bad", { timeout: 30_000 }); await expect(pill(page, "links")).toHaveAttribute("title", /v6nyslug/); await expect(pill(page, "links")).toHaveAttribute("href", urls.projectHref(L, { tab: "overview" })); await pill(page, "links").click(); await expect(page.locator("[data-settle-button='links']").first()).toHaveText("Use embed ids (1)", { timeout: 30_000 }); }); test("captures: a source the build would die at is ! (the reducer's clip-no-cues), its click the piece's decisions", async ({ page }) => { // The fixture's recordings have no cues in the corpus (testchan/playvid, nofetch): blocking, as the Inbox says. await page.goto(urls.workspaceHref(P)); await expect(pill(page, "captures")).toHaveAttribute("data-ready-state", "bad", { timeout: 30_000 }); await expect(pill(page, "captures")).toHaveAttribute("title", /no transcript\.cues\.json/); await expect(pill(page, "captures")).toHaveAttribute("href", urls.projectHref(P, { tab: "overview" })); }); test("captures: on a cut whose sources answer, the clip never fetched is counted, and its click selects that block", async ({ page }) => { // review-pass-fixture: vid1's cues are in the corpus; c03 (vid1 300-302) was never fetched. const W = "reports/review-pass-fixture"; await page.goto(urls.workspaceHref(W)); await expect(pill(page, "captures")).toHaveAttribute("data-ready-count", /\d/, { timeout: 30_000 }); await expect(pill(page, "captures")).toHaveAttribute("data-ready-state", "count"); await expect(pill(page, "captures")).toHaveAttribute("data-ready-count", "1"); await expect(pill(page, "captures")).toHaveAttribute("title", /c03: no media fetched/); await pill(page, "captures").click(); await expect(page.locator('[data-ws-block="c03"]')).toHaveAttribute("aria-selected", "true"); await expect(page).toHaveURL(/[?&]block=c03/); }); test("render: two versions to judge (v1, short), its click the first one's review pass", async ({ page }) => { await page.goto(urls.workspaceHref(P)); await expect(pill(page, "render")).toHaveAttribute("data-ready-state", "count", { timeout: 30_000 }); await expect(pill(page, "render")).toHaveAttribute("data-ready-count", "2"); const href = await pill(page, "render").getAttribute("href"); expect([urls.versionReviewHref(P, "v1"), urls.versionReviewHref(P, "short")]).toContain(href); }); test("X jar: — with no X post and no X work waiting; ! while the editor says X work waits on a stale jar", async ({ page, request }) => { await page.goto(urls.workspaceHref(P)); await expect(pill(page, "x-jar")).toHaveAttribute("data-ready-state", "none", { timeout: 30_000 }); await services(request, [X_ALERT]); await page.reload(); await expect(pill(page, "x-jar")).toHaveAttribute("data-ready-state", "bad", { timeout: 30_000 }); await expect(pill(page, "x-jar")).toHaveAttribute("title", /X cookies are 3 h old/); await expect(pill(page, "x-jar")).toHaveAttribute("href", `${STUB}/settings`); // The API says the same, read-only. const r = (await (await request.get(`/api/report/readiness?project=${encodeURIComponent(P)}`)).json()) as { pills: { id: string; state: string }[] }; const state = Object.fromEntries(r.pills.map((p) => [p.id, p.state])); expect(state).toMatchObject({ "quote-check": "count", render: "count", "x-jar": "bad" }); }); test("X jar: ✓ on a cut with an X post while the editor says nothing waits; — (never ✓) while the editor does not answer, and the page does not wait for it", async ({ page, request }) => { const W = "reports/review-pass-fixture"; // p-5 is an X post await page.goto(urls.workspaceHref(W)); await expect(pill(page, "x-jar")).toHaveAttribute("data-ready-state", "ok", { timeout: 30_000 }); await request.post(`${STUB}/__stub/services`, { data: { alerts: [], down: true } }); const t0 = Date.now(); const r = await request.get(`/api/report/readiness?project=${encodeURIComponent(W)}`); expect(Date.now() - t0).toBeLessThan(5_000); const x = ((await r.json()) as { pills: { id: string; state: string; title: string }[] }).pills.find((p) => p.id === "x-jar"); expect(x).toMatchObject({ state: "none", title: "the editor did not answer: X's jar is not known" }); await page.reload(); await expect(pill(page, "x-jar")).toHaveAttribute("data-ready-state", "none", { timeout: 30_000 }); });