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"; // --------------------------------------------------------------------------- // Who is speaking, per montage clip (release 34): the Cut tab's "Score the // voices" runs `umtool voice-match` as a job and every row then carries its // score. The engine is the test kit's fake embedder (playwright.config.ts), so // nothing here needs python or a model. // // voice-fixture WRITES voice-match.json. Five clips with their windows in // the corpus: four of one voice (three ruled keep), one of // another (v02) // --------------------------------------------------------------------------- const HERE = path.dirname(fileURLToPath(import.meta.url)); const PROJECT = "reports/voice-fixture"; const FILE = path.join(HERE, "..", ".e2e-song", "reports", "voice-fixture", "voice-match.json"); test("Score the voices: a job writes voice-match.json and each clip row shows its score", async ({ page }) => { await page.goto(urls.section(PROJECT, "cut")); await openPanel(page, "options", "cut"); await openPanel(page, "advanced", "cut"); const panel = page.locator("[data-voice-match-panel]"); await expect(panel).toBeVisible(); await expect(page.locator("[data-voice-summary]")).toHaveCount(0); await expect(page.locator("[data-entry] [data-voice]")).toHaveCount(0); await panel.locator("[data-voice-reference]").selectOption("auto"); await panel.getByRole("button", { name: "Score the voices" }).click(); await expect(page.locator("[data-voice-summary]")).toContainText("4 likely · 0 unsure · 1 unlikely of 5 scored", { timeout: 60_000 }); await expect(page.locator("[data-voice-summary]")).toContainText("against 3 clips ruled keep"); await expect(page.locator("[data-entry='v02'] [data-voice]")).toHaveAttribute("data-voice", "unlikely"); await expect(page.locator("[data-entry='v01'] [data-voice]")).toHaveAttribute("data-voice", "likely"); await expect(page.locator("[data-entry='v05'] [data-voice]")).toContainText(/voice \d\.\d\d · likely/); // The file, in the shape the audition deck reads: keyed by the source moment. const doc = JSON.parse(readFileSync(FILE, "utf8")); expect(doc.version).toBe(1); expect(doc.model).toBe("titanet-small"); expect(doc.reference.kind).toBe("rulings"); expect(Object.keys(doc.clips).sort()).toEqual(["voicechan/voice1@2.00", "voicechan/voice2@2.00", "voicechan/voice3@2.00", "voicechan/voice4@2.00", "voicechan/voice5@2.00"]); const guest = doc.clips["voicechan/voice2@2.00"]; expect(guest.label).toBe("unlikely"); expect(guest.id).toBe("v02"); expect(typeof guest.score).toBe("number"); expect(guest.speechSeconds).toBeGreaterThan(1); // Run again: the button says so, and the same input scores the same. await expect(panel.getByRole("button", { name: "Score the voices again" })).toBeVisible(); }); test("the clip deck carries Score the voices, and its cards show the scores voice-match.json holds", async ({ page }) => { // After the test above: voice-match.json is there. await page.goto(urls.clipDeckHref(PROJECT, { show: "all" })); const panel = page.locator("[data-voice-match-panel]"); await expect(panel).toBeVisible(); await expect(panel.locator("[data-voice-summary]")).toContainText("1 unlikely of 5 scored"); await expect(panel.getByRole("button", { name: "Score the voices again" })).toBeVisible(); // The deck puts the doubtful clip first, with its score (lane N1 reads the file). await expect(page.locator("[data-card-voice]").first()).toHaveAttribute("data-card-voice", "unlikely"); }); test("the route refuses what is not a report video, and a project that does not exist", async ({ request }) => { expect((await request.post("/api/report/voice-match", { data: { project: "reports/no-such-project" } })).status()).toBe(404); expect((await request.post("/api/report/voice-match", { data: "nope", headers: { "content-type": "application/json" } })).status()).toBe(400); const r = await request.get(`/api/report/voice-match?project=${encodeURIComponent(PROJECT)}`); expect(r.status()).toBe(200); });