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"; // --------------------------------------------------------------------------- // The video assistant (release 38 lane E) on the Build tab's Look panel. An // Ask ("make the joins 0.15 s with less smear") starts the editor's // `video-assist` job (the editor stub's canned model answers through common's // own checker and writer); its proposals come back as a diff list; nothing in // the manifest moves until Apply, which writes through updateRender; the // panel's fields read the new look. A second ask ("louder, and 5 seconds // between clips") shows its refusal with the reason, and Dismiss changes // nothing but the marks. A note on the whole project, asked, is the request // too; the agent's reply carries an Apply. Fixture: // e2e/fixtures/video-assist-fixture.mjs. // --------------------------------------------------------------------------- const HERE = path.dirname(fileURLToPath(import.meta.url)); const FIXTURE = path.join(HERE, "..", ".e2e-song"); const PROJECT = "reports/video-assist-fixture"; const DIR = path.join(FIXTURE, "reports", "video-assist-fixture"); const TOKEN = "umtool-e2e-token"; const json = (name: string) => { try { return JSON.parse(readFileSync(path.join(DIR, name), "utf8")); } catch { return null; } }; const manifestText = () => readFileSync(path.join(DIR, "video.manifest.json"), "utf8"); const render = () => json("video.manifest.json")?.render ?? {}; const stubRequests = (): { route: string; task?: string; project?: string; request?: string; note?: string }[] => { try { return JSON.parse(readFileSync(path.join(FIXTURE, "editor-stub.requests.json"), "utf8")); } catch { return []; } }; test("Ask on the Look panel: the diff, Apply through the look's writer, a refusal shown, Dismiss writes nothing; a project note asked", async ({ page, request }) => { test.setTimeout(120_000); await page.setViewportSize({ width: 1366, height: 900 }); await page.goto(urls.section(PROJECT, "build")); await expect(page.locator("[data-look-panel]")).toHaveAttribute("data-look-panel", ""); const box = page.locator('[data-assist-box="all"]'); await expect(box).toHaveAttribute("data-assist-route", "local"); await expect(box.locator("[data-assist-status]")).toContainText("On the local model (qwen3:8b), through the GPU: it waits while a transcription runs."); // The manual path is right there: the slide's knobs are fields. await expect(page.locator("[data-look-slide-smear]")).toHaveValue("0.5"); // ---- an ask: the proposals, nothing applied --------------------------------- const before = manifestText(); await box.locator("[data-assist-input]").fill("make the joins 0.15 s with less smear"); await box.locator("[data-assist-ask]").click(); await expect(box.locator("[data-assist-job]")).toHaveAttribute("data-assist-job", "done", { timeout: 20_000 }); expect(stubRequests().filter((r) => r.route === "report-draft" && r.task === "video-assist").map((r) => [r.project, r.request])).toEqual([[DIR, "make the joins 0.15 s with less smear"]]); const list = box.locator("[data-assist-proposals]"); await expect(list).toHaveAttribute("data-assist-proposals", "2"); await expect(list.locator('[data-assist-op="a1"]')).toContainText("join 0.22 s → 0.15 s"); await expect(list.locator('[data-assist-op="a2"]')).toContainText("smear 0.5 → 0.3"); await expect(list.locator("[data-assist-reply]")).toHaveText("Done as asked."); expect(manifestText()).toBe(before); // ---- Apply one, then the rest: through updateRender; the panel reads it back await list.locator('[data-assist-apply="a1"]').click(); await expect(list.locator('[data-assist-op="a1"]')).toHaveAttribute("data-assist-status", "applied"); expect(render().transition).toBe(0.15); expect(render().slide).toBeUndefined(); await expect(page.locator("[data-look-transition]")).toHaveValue("0.15"); await list.locator("[data-assist-apply-all]").click(); await expect(list.locator('[data-assist-op="a2"]')).toHaveAttribute("data-assist-status", "applied"); expect(render().slide).toEqual({ blur: 0.3 }); await expect(page.locator("[data-look-slide-smear]")).toHaveValue("0.3"); expect(json("assist-proposals.json")?.ops?.map((o: { status: string }) => o.status)).toEqual(["applied", "applied"]); await expect(list.locator("[data-assist-apply-all]")).toHaveCount(0); // ---- a second ask: one proposed, one refused with the reason; Dismiss ---- await box.locator("[data-assist-input]").fill("louder, and 5 seconds between clips"); await box.locator("[data-assist-ask]").click(); await expect(box.locator("[data-assist-job]")).toHaveAttribute("data-assist-job", "done", { timeout: 20_000 }); await expect(list).toHaveAttribute("data-assist-proposals", "1"); await expect(list.locator('[data-assist-op="a1"]')).toContainText("loudness as recorded → -14 LUFS"); await expect(list.locator("[data-assist-refused]")).toHaveText("not proposed: render.transition must be a number of seconds from 0 (a hard cut) to 3"); const applied = manifestText(); await list.locator("[data-assist-dismiss]").click(); await expect(list.locator('[data-assist-op="a1"]')).toHaveAttribute("data-assist-status", "dismissed"); expect(manifestText()).toBe(applied); expect(render().loudness).toBeUndefined(); // ---- a note on the whole project, asked: its text is the request ---------- await box.locator("[data-assist-note-input]").fill("no QR, please"); await box.locator("[data-assist-note-add]").click(); const thread = box.locator("[data-assist-notes] [data-note-id]"); await expect(thread).toHaveCount(1); const noteId = (await thread.getAttribute("data-note-id"))!; await thread.locator('[data-note-action="assist"]').click(); await expect(box.locator("[data-assist-job]")).toHaveAttribute("data-assist-job", "done", { timeout: 20_000 }); expect(stubRequests().filter((r) => r.task === "video-assist" && r.note).map((r) => [r.project, r.note])).toEqual([[DIR, noteId]]); // The QR is already off in this cut: the checks say so (nothing proposed). await expect(list).toHaveAttribute("data-assist-proposals", "0"); await expect(list.locator("[data-assist-refused]")).toHaveText("not proposed: QR code is already that"); // The agent's reply with an assist proposal (posted here: the stub cannot reach umtool) shows its Apply only while current. const at = json("assist-proposals.json").at as string; const read = await (await request.get(`/api/notes?project=${encodeURIComponent(PROJECT)}`)).json(); const replied = await request.post(`/api/notes?project=${encodeURIComponent(PROJECT)}`, { headers: { authorization: `Bearer ${TOKEN}` }, data: { token: read.token, op: { op: "reply", id: noteId, text: "No edit proposed.", proposal: { kind: "assist", at, ops: 1 } } }, }); expect(replied.ok()).toBe(true); await page.reload(); const reply = page.locator('[data-assist-notes] [data-reply-proposal="assist"]'); await expect(reply).toContainText("1 edit"); await expect(reply).toContainText("nothing waiting"); });