import { test, expect, type Page } from "@playwright/test"; import { existsSync, readFileSync, rmSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import { REFRESH_ARTICLE, REFRESH_NEW, makeRefreshFixture } from "./fixtures/refresh-fixture.mjs"; import * as urls from "./urls"; import { WARM_TIMEOUT, warm } from "./warm"; // --------------------------------------------------------------------------- // Refresh (plans/umtool-redesign.md, R4) on the refresh fixture // (e2e/fixtures/refresh-fixture.mjs, written here and removed after): the // plan from the article's ⋯ menu — the iteration refreshed and its queries, // each channel's fetches (a held platform skipped), the site built, the cap — // with nothing written until Refresh; the daily check finding the recording // the report's sweep never saw, the Inbox's suggestion card and the Next // card, whose action opens the plan; then the refresh run as one editor job // (the stub: running, then done with its refresh.json), and the Overview's // summary of what it found. // --------------------------------------------------------------------------- const HERE = path.dirname(fileURLToPath(import.meta.url)); const FIXTURE = path.join(HERE, "..", ".e2e-song"); const ARTICLES = path.join(FIXTURE, "articles"); const STUB_LOG = path.join(FIXTURE, "editor-stub.requests.json"); const CHECK_FILE = path.join(FIXTURE, ".umtool", "refresh-check.json"); const PIECE = `a:articles/${REFRESH_ARTICLE}`; const page_ = () => urls.articleHref({ site: "articles", id: REFRESH_ARTICLE }); const stubAsked = (): Record[] => { try { return JSON.parse(readFileSync(STUB_LOG, "utf8")) as Record[]; } catch { return []; } }; const dialog = (page: Page) => page.locator(`dialog[data-refresh-dialog='${REFRESH_ARTICLE}']`); test.beforeAll(async ({ playwright }) => { test.setTimeout(WARM_TIMEOUT); makeRefreshFixture({ articles: ARTICLES, source: `local:${path.join(FIXTURE, "research-public")}` }); await warm(playwright, [page_(), "/", "/api/articles/refresh?article=refreshfix", "/api/articles/refresh/check"]); }); test.afterAll(() => { rmSync(path.join(ARTICLES, REFRESH_ARTICLE), { recursive: true, force: true }); rmSync(CHECK_FILE, { force: true }); }); test("the ⋯ menu's Refresh: the plan — the iteration, its queries, the fetches (a held platform skipped), the build, the cap — and nothing written until Refresh", async ({ page }) => { await page.goto(page_()); await page.getByRole("button", { name: "More" }).click(); await page.getByRole("button", { name: "Refresh…" }).click(); const d = dialog(page); await expect(d).toBeVisible(); const plan = d.locator(`[data-refresh-plan='${REFRESH_ARTICLE}']`); await expect(plan).toContainText("i1"); await expect(plan.locator("[data-refresh-queries]")).toHaveText("“lighthouse budget”"); await expect(plan.locator("[data-refresh-channel='harbor-radio']")).toContainText("sync → refresh-report → transcribe-bucket (what lands)"); await expect(plan.locator("[data-refresh-channel='otherchan']")).toContainText("skipped — rumble is held"); await expect(plan.locator("[data-refresh-build='priv']")).toContainText("locally, if anything changed — never deployed"); await expect(plan.locator("[data-refresh-cap]")).toContainText("spends up to $5.00"); // The plan was the editor's dry run; no iteration was made. expect(stubAsked().filter((r) => r.route === "report-draft" && r.task === "refresh").at(-1)).toMatchObject({ article: REFRESH_ARTICLE, dryRun: true }); expect(existsSync(path.join(ARTICLES, REFRESH_ARTICLE, "iterations", "2"))).toBe(false); await d.getByRole("button", { name: "Cancel" }).click(); await expect(d).toBeHidden(); }); test("the daily check finds the recording the sweep never saw: the Inbox's suggestion card, and the Next card, open the plan", async ({ page, request }) => { const r = await request.post("/api/articles/refresh/check", { data: { article: REFRESH_ARTICLE, force: true } }); expect(r.ok()).toBe(true); const out = (await r.json()) as { checked: { article: string; newCount: number; newIds: string[]; titles: string[]; since: string }[] }; expect(out.checked).toHaveLength(1); expect(out.checked[0]).toMatchObject({ article: REFRESH_ARTICLE, status: "checked", newCount: 1, newIds: [REFRESH_NEW.id], titles: [REFRESH_NEW.title] }); await page.goto(urls.homeHref()); const card = page.locator(`[data-lit-line][data-piece='${PIECE}'][data-card='refresh-available']`); await expect(card).toBeVisible(); await expect(card).toContainText(`1 new recording mentions this since 2026-10-14: ${REFRESH_NEW.title}`); await expect(page.locator(`[data-group=review] [data-piece='${PIECE}'][data-card='refresh-available']`)).toBeVisible(); const action = card.locator("[data-action-link]"); await expect(action).toHaveText("Refresh"); await expect(action).toHaveAttribute("href", `/articles/${REFRESH_ARTICLE}?refresh=1`); // The piece's Next card is the same call, and its action opens the plan. await page.goto(page_()); await expect(page.locator("[data-next-kind='refresh-available']")).toBeVisible(); await page.locator("[data-next-action] a").click(); await expect(page).toHaveURL(new RegExp(`/articles/${REFRESH_ARTICLE}\\?refresh=1$`)); await expect(dialog(page)).toBeVisible(); await expect(dialog(page).locator("[data-refresh-queries]")).toHaveText("“lighthouse budget”"); await dialog(page).getByRole("button", { name: "Cancel" }).click(); await expect(page).toHaveURL(new RegExp(`/articles/${REFRESH_ARTICLE}$`)); }); test("Refresh: one editor job, then the Overview says what it found — the new recording, the quote that changed; the Review card", async ({ page }) => { test.setTimeout(60_000); await page.goto(urls.articleHref({ site: "articles", id: REFRESH_ARTICLE }, { refresh: true })); await expect(dialog(page).locator("[data-refresh-plan]")).toBeVisible(); await dialog(page).getByRole("button", { name: "Refresh", exact: true }).click(); await expect(page.locator("[data-refresh-started]")).toContainText("Refresh i2 is running"); expect(stubAsked().filter((r) => r.route === "report-draft" && r.task === "refresh").at(-1)).toMatchObject({ article: REFRESH_ARTICLE, iteration: 1 }); // The Overview follows it (it reads again while the refresh runs). const summary = page.locator("[data-refresh-summary='2']"); await expect(summary).toBeVisible(); await expect(summary).toHaveAttribute("data-refresh-state", "updated", { timeout: 20_000 }); await expect(summary.locator("[data-refresh-line]")).toHaveText("1 new recording matches · 1 quote changed"); await expect(summary.locator("[data-refresh-new]")).toContainText(REFRESH_NEW.title); await expect(summary.locator("[data-refresh-drifted]")).toContainText("now: “the lighthouse budget was not approved that year”"); await expect(summary.locator("[data-refresh-steps]")).toContainText("build priv done"); await expect(summary.getByRole("link", { name: "Review in Iterations →" })).toHaveAttribute("href", `/articles/${REFRESH_ARTICLE}?tab=iterations`); // A refresh with a report is a finished iteration to review; the suggestion is spent. await page.goto(urls.homeHref()); await expect(page.locator(`[data-lit-line][data-piece='${PIECE}'][data-card='iteration-ready']`)).toBeVisible(); await expect(page.locator(`[data-lit-line][data-piece='${PIECE}'][data-card='refresh-available']`)).toHaveCount(0); }); test("the Iterations tab: the refresh's outcome on its card, and Refresh… opens the plan", async ({ page }) => { await page.goto(urls.articleHref({ site: "articles", id: REFRESH_ARTICLE }, { tab: "iterations" })); await expect(page.locator("[data-iteration='2'][data-kind='refresh'] [data-refresh-outcome='updated']")).toContainText("1 new recording matches · 1 quote changed"); await page.locator("[data-refresh-open='iterations']").click(); await expect(dialog(page).locator("[data-refresh-plan]")).toBeVisible(); await dialog(page).getByRole("button", { name: "Cancel" }).click(); await expect(dialog(page)).toBeHidden(); }); test("1366×768: the plan fits without scrolling the page", async ({ page }) => { await page.setViewportSize({ width: 1366, height: 768 }); await page.goto(urls.articleHref({ site: "articles", id: REFRESH_ARTICLE }, { refresh: true })); const d = dialog(page); await expect(d.locator("[data-refresh-plan]")).toBeVisible(); const box = await d.boundingBox(); expect(box).not.toBeNull(); expect(box!.y).toBeGreaterThanOrEqual(0); expect(box!.y + box!.height).toBeLessThanOrEqual(768); await expect(d.getByRole("button", { name: "Refresh", exact: true })).toBeInViewport(); });