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"; import { openPanel } from "./panels"; // --------------------------------------------------------------------------- // The clip editor (release 35 C2): a person hops in on an assistant's clips. // The Cut tab links it; the strip colours the turns by role and marks the // laughs; a nudge trims (the clip is "edited by you"); K keeps and the ruling // follows the clip when its start moves; a word click puts the playhead there // and Split here cuts the clip in two; Merge with next joins them; Restore // puts the assistant's version back; X cuts; a comment is a note anchored to // the clip and an agent's reply shows in its thread; an unused proposal is // brought in; "This is the host" writes the speaker's role (the clip // finder's writer) and offers Re-propose. Fixture: e2e/fixtures/clip-editor-fixture.mjs. // --------------------------------------------------------------------------- const HERE = path.dirname(fileURLToPath(import.meta.url)); const FIXTURE = path.join(HERE, "..", ".e2e-song"); const PROJECT = "reports/clip-editor-fixture"; const DIR = path.join(FIXTURE, "reports", "clip-editor-fixture"); type Clip = { id: string; start: number; end: number; cutStart?: number; cutEnd?: number; quote?: string; assist?: { by: string; proposal?: string; edits: { what: string }[] } }; const json = (name: string) => { try { return JSON.parse(readFileSync(path.join(DIR, name), "utf8")); } catch { return null; } }; const clips = (): Clip[] => (json("video.manifest.json")?.timeline ?? []).filter((e: { type: string }) => e.type === "clip"); const clip = (id: string) => clips().find((c) => c.id === id) ?? null; const ruling = (at: string) => (json("montage-rulings.json")?.rulings ?? {})[`testchan/vid1@${at}`]?.verdict ?? null; test("the clip editor: trim, keep (the ruling follows), split, merge, restore, cut, comment + an agent's reply, bring in, the host", async ({ page, request }) => { test.setTimeout(150_000); await page.setViewportSize({ width: 1366, height: 900 }); // The Cut tab links the editor for a cut that is not a montage. await page.goto(urls.section(PROJECT, "cut")); await openPanel(page, "options", "cut"); await openPanel(page, "advanced", "cut"); const link = page.locator("[data-clip-editor-link]"); await expect(link).toHaveAttribute("data-clip-editor-link", "3"); await expect(link).toContainText("Clip editor — 3 clips · 3 by the assistant"); await link.click(); const editor = page.locator("[data-clip-editor]"); await expect(editor).toHaveAttribute("data-clip-editor", "r001"); await expect(page.locator("[data-editor-provenance]")).toHaveText("by the assistant · 0.80 · host laughs at the line"); await expect(page.locator("[data-editor-player]")).not.toHaveAttribute("data-editor-player", "looking", { timeout: 15_000 }); // The strip: turns by role, laughs, the words. await expect(page.locator('[data-turn-role="host"]')).toHaveCount(3); await expect(page.locator('[data-turn-role="subject"]')).toHaveCount(3); await expect(page.locator("[data-laugh]")).toHaveCount(2); await expect(page.locator("[data-editor-words]")).toHaveAttribute("data-editor-words", "words"); await expect(page.locator("[data-editor-proposals]")).toHaveAttribute("data-editor-proposals", "2"); // A nudge trims: out +0.5. The clip is the operator's now. await page.locator('[data-nudge="out:0.5"]').click(); await expect.poll(() => clip("r001")?.cutEnd).toBe(3.5); expect(clip("r001")?.assist?.by).toBe("operator"); await expect(page.locator("[data-editor-provenance]")).toContainText("edited by you · the assistant scored it 0.80 · 1 edit"); // K keeps; moving the in point moves the ruling with the clip. await page.keyboard.press("k"); await expect.poll(() => ruling("1.00")).toBe("keep"); await page.locator('[data-nudge="in:0.5"]').click(); await expect.poll(() => ruling("1.50")).toBe("keep"); expect(ruling("1.00")).toBeNull(); await expect(page.locator("[data-editor-ruling]")).toHaveAttribute("data-editor-ruling", "keep"); // A word puts the playhead there; Split here. await page.locator('[data-word-t="2.4"]').click(); await expect(page.locator("[data-playhead]")).toHaveCount(1); await page.locator('[data-action="split"]').click(); await expect.poll(() => clip("r001-2")?.cutStart).toBe(2.4); expect(clip("r001")?.cutEnd).toBe(2.4); expect(clip("r001-2")?.quote).toBe("sentence. And"); await expect(page.locator('[data-editor-row="r001-2"]')).toHaveCount(1); // Merge with next joins them again. await page.locator('[data-action="merge"]').click(); await expect.poll(() => clip("r001-2")).toBeNull(); expect([clip("r001")?.cutStart, clip("r001")?.cutEnd]).toEqual([1.5, 3.5]); // Restore the assistant's version: the edges, and the clip is the assistant's again. await page.locator('[data-action="restore"]').click(); await expect.poll(() => clip("r001")?.cutStart).toBe(1); expect(clip("r001")?.cutEnd).toBe(3); expect(clip("r001")?.assist?.by).toBe("assistant"); expect(clip("r001")?.assist?.edits.map((e) => e.what)).toEqual(["trim", "trim", "split", "merge", "restore"]); await expect.poll(() => ruling("1.00")).toBe("keep"); await expect(page.locator("[data-editor-provenance]")).toHaveText("by the assistant · 0.80 · host laughs at the line"); // → the next clip; X cuts it. await page.keyboard.press("ArrowRight"); await expect(editor).toHaveAttribute("data-clip-editor", "r002"); await page.keyboard.press("x"); await expect.poll(() => ruling("4.00")).toBe("cut"); // A comment: a note anchored to the clip. await page.locator("[data-clip-note-input]").fill("tighten the start, he breathes first"); await page.locator("[data-clip-note-add]").click(); await expect(page.locator('[data-clip-notes="r002"] [data-note-id]')).toHaveCount(1); type Note = { id: string; status: string; anchor: { kind: string; entry?: string }; replies: { author: string; text: string }[] }; const notes = (): Note[] => json("notes.json")?.notes ?? []; await expect.poll(() => notes().length).toBe(1); expect(notes()[0].anchor).toEqual({ kind: "entry", entry: "r002" }); // An agent replies (as the MCP's notes tool does); the thread shows it. 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 umtool-e2e-token" }, data: { token: read.token, op: { op: "reply", id: notes()[0].id, text: "moved the in point to the breath" } }, }); expect(replied.ok()).toBe(true); await page.reload(); await expect(editor).toHaveAttribute("data-clip-editor", "r002"); const thread = page.locator('[data-clip-notes="r002"] [data-note-id]'); await expect(thread.locator("[data-note-reply]")).toContainText("moved the in point to the breath"); await thread.locator('[data-note-action="resolve"]').click(); await expect.poll(() => notes()[0].status).toBe("resolved"); await expect(page.locator('[data-clip-notes="r002"]')).toHaveAttribute("data-open-notes", "0"); // Bring in an unused proposal: it is a clip, the operator's, and leaves the list. await page.locator('[data-bring-in="p004"]').click(); await expect(editor).toHaveAttribute("data-clip-editor", "vid1-9"); await expect(page.locator("[data-editor-proposals]")).toHaveAttribute("data-editor-proposals", "1"); expect(clip("vid1-9")).toMatchObject({ start: 7.5, end: 13.5, cutStart: 9, cutEnd: 12, assist: { by: "operator", proposal: "p004" } }); expect(clips().map((c) => c.id)).toEqual(["r001", "r002", "r003", "vid1-9"]); // "This is the host" on a subject turn: the role is the operator's; Re-propose is offered. await page.locator('[data-turn-speaker="1"]').first().click(); await page.locator('[data-set-host="1"]').click(); await expect.poll(() => json("reactions.json")?.speakers?.[1]).toMatchObject({ index: 1, role: "host", how: "operator" }); // The clip finder's writer: one host, so the other speaker is handed back as "other". expect(json("reactions.json")?.speakers?.[0]?.role).toBe("other"); await expect(page.locator("[data-repropose-button]")).toBeEnabled(); await expect(page.locator('[data-turn-role="subject"]')).toHaveCount(0); await expect(page.locator('[data-turn-role="other"]')).toHaveCount(3); });