import { test, expect } from "@playwright/test"; import { copyFileSync, existsSync, readFileSync, rmSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import * as urls from "./urls"; // --------------------------------------------------------------------------- // Claim-group proposals on the Cut tab (lane L4). Propose groups starts the // editor's `propose-groups` job (the editor stub's canned model: each // section's first two clips as one claim, and one group across the first // boundary, which the check refuses -- written through common's own checker // and writer); the proposals come back as rows; nothing in the manifest moves // until Accept, which writes ONE group through the structural writer (an undo // point first) and its bar appears in the cut; Reject marks and writes // nothing. // // group-proposals-fixture the deck on; §0 c01 c02 | §1 "Two" c03 c04 | // §2 "Three" c05 c06; no groups. WRITES its // manifest, group-proposals.json and revisions/. // --------------------------------------------------------------------------- const HERE = path.dirname(fileURLToPath(import.meta.url)); const FIXTURE = path.join(HERE, "..", ".e2e-song"); const PROJECT = "reports/group-proposals-fixture"; const DIR = path.join(FIXTURE, "reports", "group-proposals-fixture"); const MANIFEST = path.join(DIR, "video.manifest.json"); const read = (name: string) => { try { return JSON.parse(readFileSync(path.join(DIR, name), "utf8")); } catch { return null; } }; const stubRequests = (): { route: string; task?: string; project?: string; request?: string }[] => { try { return JSON.parse(readFileSync(path.join(FIXTURE, "editor-stub.requests.json"), "utf8")); } catch { return []; } }; test.beforeAll(() => { if (!existsSync(`${MANIFEST}.pristine`)) copyFileSync(MANIFEST, `${MANIFEST}.pristine`); }); test.beforeEach(() => { copyFileSync(`${MANIFEST}.pristine`, MANIFEST); for (const f of ["group-proposals.json", ".propose-groups-job.json"]) rmSync(path.join(DIR, f), { force: true }); rmSync(path.join(DIR, "revisions"), { recursive: true, force: true }); }); test("Propose groups: the rows, nothing written; Accept writes one group and its bar appears; Reject writes nothing; a refusal shown", async ({ page }) => { test.setTimeout(120_000); await page.goto(urls.section(PROJECT, "timeline")); await expect(page.getByTestId("timeline-undo")).toBeEnabled(); const panel = page.getByTestId("group-proposals"); await expect(panel.getByTestId("propose-groups-start")).toBeEnabled(); const before = readFileSync(MANIFEST, "utf8"); await panel.getByTestId("propose-groups-request").fill("by claim"); await panel.getByTestId("propose-groups-start").click(); await expect(panel.getByTestId("propose-groups-job")).toHaveAttribute("data-job-status", "done", { timeout: 20_000 }); expect(stubRequests().filter((r) => r.route === "report-draft" && r.task === "propose-groups").map((r) => [r.project, r.request])).toEqual([[DIR, "by claim"]]); await expect(panel.locator("[data-proposal]")).toHaveCount(3); await expect(panel.locator("[data-proposal='p1']")).toContainText("c01 c02"); await expect(panel.locator("[data-proposals-refused]")).toContainText("not proposed:"); expect(readFileSync(MANIFEST, "utf8")).toBe(before); expect(read("group-proposals.json").groups.map((g: { status: string }) => g.status)).toEqual(["proposed", "proposed", "proposed"]); // Accept p2: one group in the manifest, an undo point, its bar in the cut. await panel.locator("[data-proposal-accept='p2']").click(); await expect(panel.locator("[data-proposal='p2']")).toHaveAttribute("data-proposal-status", "accepted"); const m = read("video.manifest.json"); expect(m.groups).toEqual([{ id: "g1", section: 1, claim: "Section 1: the opening claim, said twice", ids: ["c03", "c04"] }]); expect(m.timeline.map((e: { id: string }) => e.id)).toEqual(["c01", "c02", "c03", "c04", "c05", "c06"]); await expect(page.locator("li[data-group-bar='g1']")).toBeVisible(); // Reject p3: marked, the manifest as it was. const after = readFileSync(MANIFEST, "utf8"); await panel.locator("[data-proposal-reject='p3']").click(); await expect(panel.locator("[data-proposal='p3']")).toHaveAttribute("data-proposal-status", "rejected"); expect(readFileSync(MANIFEST, "utf8")).toBe(after); // Undo (the Cut tab's) takes the accepted group back; p1 still fits the cut. await page.getByTestId("timeline-undo").click(); await expect.poll(() => read("video.manifest.json").groups ?? null).toBeNull(); await expect(panel.locator("[data-proposal-accept='p1']")).toBeEnabled(); });