commit f6a28a5cf1db2bebc8c5894a414c7b8327aecb14
parent 1e3bf96f3409104c096ceb5e97b0c3df23c9f957
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Sun, 18 Oct 2026 17:16:54 -0400
umtool: phrase-finder e2e (two phrases in one search, counts, year bars, contexts with the transcript lit, a suggestion, the last search remembered, Create montage seeded from the search); visual audit covers /tools/phrases; a search's answer folder is made before it is written
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
4 files changed, 110 insertions(+), 1 deletion(-)
diff --git a/umtool/e2e/phrase-finder.spec.ts b/umtool/e2e/phrase-finder.spec.ts
@@ -0,0 +1,105 @@
+import { test, expect } from "@playwright/test";
+import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
+import path from "node:path";
+import { fileURLToPath } from "node:url";
+import * as urls from "./urls";
+
+// Release 34: the phrase finder (/tools/phrases). Two phrases over the fixture
+// corpus (testchan's cue files say "The sweep fixture opens.", "The deliver
+// fixture opens.", "The editor fetch fixture speaks.", "The reuse fixture
+// begins here." …) in one search, run as a job: counts, the year bars, the
+// contexts with their transcript read in place, the comparison, the last
+// search's settings on the next visit, a suggestion from a candidates file,
+// and Create montage landing on a new project seeded from that search.
+
+const HERE = path.dirname(fileURLToPath(import.meta.url));
+const FIXTURE = path.join(HERE, "..", ".e2e-song");
+
+test("the phrase finder searches two phrases in one pass, shows the numbers and contexts, and makes a montage", async ({ page }) => {
+ const slug = "phrase-finder-probe";
+ const dir = path.join(FIXTURE, slug);
+ // A catchphrase report's candidates, as the report writes them (REPORTS_ROOT/<dir>/candidates.json).
+ const cand = path.join(FIXTURE, "phrase-finder-candidates");
+ rmSync(dir, { recursive: true, force: true });
+ mkdirSync(cand, { recursive: true });
+ writeFileSync(path.join(cand, "candidates.json"), JSON.stringify({ scanned: [{ key: "whole sentence", regex: String.raw`\bwhole sentence\b`, instances: 1 }] }));
+ try {
+ await page.goto(urls.phraseFinderHref());
+ await expect(page.locator("[data-rail-sub=tools] a[aria-current=page]")).toHaveText("phrases");
+
+ // Plain words, and an expression.
+ await page.locator("[data-phrase-text]").first().fill("fixture opens");
+ await expect(page.locator("[data-phrase-source]").first()).toContainText("as words");
+ await page.locator("[data-phrase-add]").click();
+ await page.locator("[data-phrase-text]").nth(1).fill("fixture (speaks|begins)");
+ await expect(page.locator("[data-phrase-source]").nth(1)).toContainText("as written: /fixture (speaks|begins)/");
+ // A bad expression says so and cannot be searched.
+ await page.locator("[data-phrase-add]").click();
+ await page.locator("[data-phrase-text]").nth(2).fill("fixture (opens");
+ await expect(page.locator("[data-phrase-error]")).toContainText("not a regular expression");
+ await page.locator("[data-phrase-remove]").nth(2).click();
+ // A suggestion adds a row.
+ await page.locator("[data-phrase-suggestions] summary").click();
+ await page.locator("[data-phrase-suggestion='whole sentence']").click();
+ await expect(page.locator("[data-phrase-text]")).toHaveCount(3);
+ await expect(page.locator("[data-phrase-source]").nth(2)).toContainText("whole sentence · as written");
+
+ await expect(page.locator("[data-phrase-search]")).toBeDisabled();
+ await page.locator("[data-phrase-channel-filter]").fill("testch");
+ await page.locator("[data-phrase-channel=testchan] input").check();
+ await expect(page.locator("[data-phrase-picked=testchan]")).toBeVisible();
+ await page.locator("[data-phrase-search]").click();
+
+ const done = page.locator("[data-phrase-state=done]");
+ await expect(done).toBeVisible({ timeout: 60_000 });
+ expect(page.url()).toContain("/tools/phrases?scan=ps-");
+ await expect(page.locator("[data-phrase-compare-row]")).toHaveCount(3);
+
+ const opens = page.locator("[data-phrase-result=p1]");
+ const n = Number(await opens.locator("[data-phrase-count]").getAttribute("data-phrase-count"));
+ expect(n).toBeGreaterThanOrEqual(2);
+ await expect(opens.locator("[data-phrase-year='2025']")).toHaveAttribute("data-count", String(n));
+ await expect(opens.locator("[data-phrase-other]")).toHaveAttribute("data-phrase-other", String(n));
+ await expect(opens.locator("[data-phrase-sample]")).toHaveCount(Math.min(n, 10));
+ await expect(opens.locator("[data-phrase-sample]").first()).toContainText(/fixture opens/i);
+ await expect(opens.locator("[data-phrase-sample]").first()).toContainText("1 Jan 2025");
+ // The transcript where it was said, its cue lit.
+ await opens.locator("[data-phrase-transcript]").first().click();
+ await expect(opens.locator("[data-phrase-cue=lit]").first()).toContainText(/fixture opens/i);
+ // Play mounts the cited clip (a window on disk, or Fetch clip).
+ await opens.locator("[data-phrase-play]").first().click();
+ await expect(opens.locator("[data-cited-clip]").first()).toBeVisible();
+ const speaks = page.locator("[data-phrase-result=p2]");
+ expect(Number(await speaks.locator("[data-phrase-count]").getAttribute("data-phrase-count"))).toBeGreaterThanOrEqual(2);
+
+ // The next visit opens on this search's settings.
+ await page.goto(urls.phraseFinderHref());
+ await expect(page.locator("[data-phrase-text]").first()).toHaveValue("fixture opens");
+ await expect(page.locator("[data-phrase-picked=testchan]")).toBeVisible();
+ await expect(page.locator("[data-phrase-recent]").first()).toBeVisible();
+ await page.locator("[data-phrase-recent]").first().click();
+ await expect(done).toBeVisible();
+
+ // Create montage: the slug prefilled, a project seeded from this search.
+ const form = page.locator("[data-phrase-montage=p1]");
+ await expect(form.locator("[data-phrase-slug]")).toHaveValue("fixture-opens-montage");
+ await form.locator("[data-phrase-slug]").fill(slug);
+ await form.locator("[data-phrase-create]").click();
+ await page.waitForURL(`**/projects/${slug}`);
+ const doc = JSON.parse(readFileSync(path.join(dir, "video.manifest.json"), "utf8"));
+ const clips = doc.timeline as Array<{ id: string; channel: string; montage: { n: number; of: number; match: string } }>;
+ expect(clips).toHaveLength(n);
+ clips.forEach((c, k) => {
+ expect(c.id).toBe(`s${String(k + 1).padStart(2, "0")}`);
+ expect(c.channel).toBe("testchan");
+ expect(c.montage.match).toMatch(/fixture opens/i);
+ });
+ const scan = JSON.parse(readFileSync(path.join(dir, "phrase-scan.json"), "utf8"));
+ expect(scan.channels).toEqual(["testchan"]);
+ expect(scan.instances).toHaveLength(n);
+ } finally {
+ rmSync(dir, { recursive: true, force: true });
+ rmSync(cand, { recursive: true, force: true });
+ }
+ expect(existsSync(dir)).toBe(false);
+});
diff --git a/umtool/e2e/visual-audit.spec.ts b/umtool/e2e/visual-audit.spec.ts
@@ -59,6 +59,7 @@ const PAGES: [string, string][] = [
),
["tools", urls.toolsHref()],
["tools-find", urls.findHref()],
+ ["tools-phrases", urls.phraseFinderHref()],
["tools-mix", urls.mixHref()],
["tools-song", urls.songToolsHref()],
...["sort", "salvage", "verify", "keeps"].map((m) => [`tools-song-${m}`, urls.pileHref(m)] as [string, string]),
diff --git a/umtool/lib/phrase-finder/cli.mjs b/umtool/lib/phrase-finder/cli.mjs
@@ -12,7 +12,8 @@
// --json prints the summaries, --full every instance. The second form is what
// the page's job runs: the settings in a JSON file, the whole answer written to
// --out, and with --progress one JSON line of progress per few hundred videos.
-import { readFile, rename, writeFile } from "node:fs/promises";
+import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
+import path from "node:path";
import { runPhraseScan } from "./scan.mjs";
import { summarisePhrase } from "./summary.mjs";
@@ -68,6 +69,7 @@ export async function phrasesCommand(args) {
const onProgress = o.progress ? (p) => console.log(JSON.stringify({ progress: p })) : undefined;
const answer = await runPhraseScan(spec, { ...(o.cache ? {} : { cacheDir: null }), onProgress });
if (o.out) {
+ await mkdir(path.dirname(o.out), { recursive: true });
const tmp = `${o.out}.${process.pid}.tmp`;
await writeFile(tmp, JSON.stringify(answer), "utf8");
await rename(tmp, o.out);
diff --git a/umtool/lib/phrase-finder/server.ts b/umtool/lib/phrase-finder/server.ts
@@ -101,6 +101,7 @@ export async function startPhraseScan(raw: unknown): Promise<{ id: string }> {
await pruneScans();
const id = newScanId();
await writeAtomic(specFile(id), JSON.stringify(spec));
+ await mkdir(path.dirname(/* turbopackIgnore: true */ scanFile(id)), { recursive: true });
await writeAtomic(LAST(), JSON.stringify({ channels: spec.channels, prefer: spec.prefer, exclude: spec.exclude, rows: spec.rows.map((r) => ({ text: r.text, mode: r.mode, ...(r.label ? { label: r.label } : {}) })) }));
const job: Job = { id, state: "running", startedAt: Date.now(), endedAt: null, spec, progress: null, error: null, pid: null, log: [] };
reg.jobs.set(id, job);