import { test, expect } from "@playwright/test"; import { readFileSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import * as urls from "./urls"; // --------------------------------------------------------------------------- // Montage operations in the app (release 35 O1), on the clip deck, against the // editor stub (e2e/fixtures/editor-stub-fetch-windows.mjs): Fetch windows' dry // run (the groups per platform) -> Start (one job, followed to its end) -> the // window the stub refused (the Rumble embed lookup, 403) named -> Use stand-in // (the instance's YouTube alternate, on the clip, its ruling moved) -> Fetch // windows again asks for the stand-in's window -> Restore puts the clip back // exactly. Fixture: e2e/fixtures/montage-ops-fixture.mjs. // --------------------------------------------------------------------------- const HERE = path.dirname(fileURLToPath(import.meta.url)); const FIXTURE = path.join(HERE, "..", ".e2e-song"); const PROJECT = "reports/montage-ops-fixture"; const DIR = path.join(FIXTURE, "reports", "montage-ops-fixture"); const read = (f: string) => JSON.parse(readFileSync(path.join(DIR, f), "utf8")); const requests = () => (JSON.parse(readFileSync(path.join(FIXTURE, "editor-stub.requests.json"), "utf8")) as Record[]).filter( (r) => r.route === "fetch-windows" && r.requestedBy === `umtool:${PROJECT}`, ); test("Fetch windows, a refused window, Use stand-in, Fetch again, Restore — on the clip deck", async ({ page }) => { test.setTimeout(120_000); await page.setViewportSize({ width: 1366, height: 900 }); const before = readFileSync(path.join(DIR, "video.manifest.json"), "utf8"); const asked = requests().length; await page.goto(urls.clipDeckHref(PROJECT)); const panel = page.locator("[data-fetch-windows]"); await expect(panel.locator("[data-fetch-items]")).toHaveAttribute("data-fetch-items", "2"); // The dry run: both windows on the Rumble queue, nothing on disk. await panel.locator('[data-action="fetch-windows"]').click(); const plan = panel.locator("[data-fetch-plan]"); await expect(plan.locator('[data-fetch-group="rumble"]')).toHaveText("rumble: 2 windows to fetch"); await expect(plan.locator("[data-fetch-cached]")).toHaveText("0 already on disk"); const dry = requests().slice(asked); expect(dry).toHaveLength(1); expect(dry[0]).toMatchObject({ dryRun: true, storedUrl: "fallback", manifest: path.join(DIR, "video.manifest.json"), items: [ { slug: "opsrumble", id: "vok1", from: 97.5, to: 105.5, clipId: "s01", pad: 3, reason: "The Montage Ops Fixture montage" }, { slug: "opsrumble", id: "vrefuse1", from: 197.5, to: 205.5, clipId: "s02", pad: 3, reason: "The Montage Ops Fixture montage" }, ], }); // Start: one job, followed to its end; the refused window named. await plan.locator('[data-action="fetch-start"]').click(); const job = panel.locator("[data-fetch-job]"); await expect(job).toHaveCount(1); await expect(job).toHaveAttribute("data-fetch-job-status", "failed", { timeout: 30_000 }); await expect(panel.locator('[data-fetch-failed="s02"]')).toContainText("network — ERROR: [Rumble] vrefuse1: Unable to download JSON metadata: HTTP Error 403: Forbidden"); const runs = read("fetch-runs.json").runs as { dryRun: boolean; jobIds: string[]; jobs?: Record }[]; expect(runs.map((r) => r.dryRun)).toEqual([true, false]); const started = runs[1]; expect(started.jobs?.[started.jobIds[0]]?.failed.map((f) => f.clipId)).toEqual(["s02"]); // The stand-in: the instance's YouTube alternate. const offer = page.locator('[data-stand-in="s02"]'); await expect(offer).toContainText("s02: the opsrumble copy refused (403) — the YouTube upload says it (opsyt/yalt1 @210.0)"); await offer.locator('[data-action="use-stand-in"]').click(); await expect(page.locator('[data-stand-in-switched="s02"]')).toContainText("s02: from opsyt/yalt1 — the opsrumble copy refused (403)", { timeout: 15_000 }); const switched = read("video.manifest.json").timeline[1]; expect(switched).toMatchObject({ channel: "opsyt", video: "yalt1", start: 207.5, end: 215.5, cutStart: 210, cutEnd: 213, note: "from the YouTube upload: the Rumble copy refused (403)", fallbackFrom: { channel: "opsrumble", video: "vrefuse1", start: 197.5, end: 205.5, cutStart: 200, cutEnd: 203, reason: "403" }, }); expect(Object.keys(read("montage-rulings.json").rulings)).toEqual(["opsyt/yalt1@210.00"]); // Fetch windows again: s01 is on disk now, the stand-in's window goes on the YouTube queue. await panel.locator('[data-action="fetch-windows"]').click(); await expect(plan.locator('[data-fetch-group="youtube"]')).toHaveText("youtube: 1 window to fetch"); await expect(plan.locator("[data-fetch-cached]")).toHaveText("1 already on disk"); expect(requests().at(-1)).toMatchObject({ dryRun: true, items: [{ clipId: "s01" }, { slug: "opsyt", id: "yalt1", from: 207.5, to: 215.5, clipId: "s02" }] }); await plan.locator('[data-action="fetch-dismiss"]').click(); // Restore: the clip exactly as it was, its ruling back; the stand-in offered again. await page.locator('[data-stand-in-switched="s02"] [data-action="restore-stand-in"]').click(); await expect(page.locator('[data-stand-in="s02"]')).toBeVisible({ timeout: 15_000 }); expect(readFileSync(path.join(DIR, "video.manifest.json"), "utf8")).toBe(before); expect(Object.keys(read("montage-rulings.json").rulings)).toEqual(["opsrumble/vrefuse1@200.00"]); });