Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit d8ffb741037d903ac41d1815a6a3e84a6fbeb58f
parent a99ac31cda3ffd28a7f8927f8e541e082d0d0a4e
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Mon, 19 Oct 2026 15:18:46 -0400

umtool e2e: clips-suggest.spec.ts — labels, the sort, stale, Suggest, Ask, Apply

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Diffstat:
Aumtool/e2e/clips-suggest.spec.ts | 128+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aumtool/e2e/fixtures/clips-suggest-fixture.mjs | 88+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/e2e/fixtures/editor-stub.mjs | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/e2e/fixtures/make-fixture.mjs | 3+++
4 files changed, 273 insertions(+), 0 deletions(-)

diff --git a/umtool/e2e/clips-suggest.spec.ts b/umtool/e2e/clips-suggest.spec.ts @@ -0,0 +1,128 @@ +import { test, expect } from "@playwright/test"; +import { readFileSync, writeFileSync } from "node:fs"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; + +// --------------------------------------------------------------------------- +// The assistant in the clip editor (release 36 lane D) — optional, every +// part: the labels from clip-suggestions.json on each clip and unused +// proposal (the why under the selected clip), "Sort by the assistant's rank" +// reorders both lists, a later proposal pass marks the labels stale (shown, +// not hidden), Suggest starts the editor's `clips-suggest` job (the editor +// stub labels every proposal through common's writer) and shows its end; Ask +// the assistant on a comment sends the note to the editor; an agent's reply +// with a trim proposal shows Apply, and Apply performs the trim through the +// clip editor's writer — only then. Fixture: e2e/fixtures/clips-suggest-fixture.mjs. +// --------------------------------------------------------------------------- + +const HERE = path.dirname(fileURLToPath(import.meta.url)); +const FIXTURE = path.join(HERE, "..", ".e2e-song"); +const PROJECT = "reports/clips-suggest-fixture"; +const DIR = path.join(FIXTURE, "reports", "clips-suggest-fixture"); +const TOKEN = "umtool-e2e-token"; + +const json = (name: string) => { + try { + return JSON.parse(readFileSync(path.join(DIR, name), "utf8")); + } catch { + return null; + } +}; +type Clip = { id: string; cutStart?: number; cutEnd?: number; assist?: { by: string } }; +const clip = (id: string): Clip | null => (json("video.manifest.json")?.timeline ?? []).find((e: Clip & { type: string }) => e.type === "clip" && e.id === id) ?? null; +const stubRequests = (): { route: string; task?: string; project?: string; note?: string }[] => { + try { + return JSON.parse(readFileSync(path.join(FIXTURE, "editor-stub.requests.json"), "utf8")); + } catch { + return []; + } +}; + +test("the assistant's labels, the sort, stale, Suggest, Ask, and Apply on the operator's click", async ({ page, request }) => { + test.setTimeout(120_000); + await page.setViewportSize({ width: 1366, height: 900 }); + await page.goto(`/projects/${PROJECT}/clips`); + const editor = page.locator("[data-clip-editor]"); + await expect(editor).toHaveAttribute("data-clip-editor", "r001"); + + // The labels: on each clip, on each unused proposal; the selected clip's why. + const panel = page.locator("[data-suggest-panel]"); + await expect(panel).toHaveAttribute("data-suggest-panel", "5"); + await expect(panel).toHaveAttribute("data-suggest-state", "fresh"); + await expect(page.locator('[data-editor-row="r001"] [data-suggest-label="p001"]')).toHaveText("the complete sentence"); + await expect(page.locator('[data-proposal="p005"] [data-suggest-label="p005"]')).toHaveText("a quiet chuckle"); + await expect(page.locator('[data-proposal="p005"] [data-suggest-label="p005"]')).toHaveAttribute("title", "Why p005 lands."); + await expect(page.locator('[data-suggest-why="p001"]')).toContainText("the complete sentence · the assistant ranks it 3 · Why p001 lands."); + + // Sort by the assistant's rank: both lists reorder; off again, the cut's order. + const rows = page.locator("[data-editor-list] [data-editor-row]"); + const proposals = page.locator("[data-editor-proposals] [data-proposal]"); + await expect(rows).toHaveText([/^r001/, /^r002/, /^r003/]); + await page.locator("[data-suggest-sort]").check(); + await expect(rows.first()).toHaveAttribute("data-editor-row", "r003"); + expect(await rows.evaluateAll((els) => els.map((e) => e.getAttribute("data-editor-row")))).toEqual(["r003", "r001", "r002"]); + expect(await proposals.evaluateAll((els) => els.map((e) => e.getAttribute("data-proposal")))).toEqual(["p005", "p004"]); + await page.locator("[data-suggest-sort]").uncheck(); + expect(await rows.evaluateAll((els) => els.map((e) => e.getAttribute("data-editor-row")))).toEqual(["r001", "r002", "r003"]); + + // A later proposal pass: the labels are marked stale, never hidden. + const reactions = json("reactions.json"); + writeFileSync(path.join(DIR, "reactions.json"), JSON.stringify({ ...reactions, proposedAt: "2026-02-01T00:00:00.000Z" })); + await page.reload(); + await expect(panel).toHaveAttribute("data-suggest-state", "stale"); + await expect(page.locator("[data-suggest-stale-line]")).toHaveText("Stale: the proposals were made again after these labels."); + await expect(page.locator('[data-editor-row="r001"] [data-suggest-label="p001"]')).toHaveAttribute("data-suggest-stale", ""); + + // Suggest: the editor's clips-suggest job on this project; its end shows, the labels are fresh. + await page.locator("[data-suggest-button]").click(); + await expect(page.locator("[data-suggest-job]")).toHaveAttribute("data-suggest-job", "done", { timeout: 20_000 }); + await expect(page.locator("[data-suggest-job]")).toHaveText("5 proposals labelled on qwen3:8b"); + await expect(panel).toHaveAttribute("data-suggest-state", "fresh"); + await expect(page.locator('[data-editor-row="r001"] [data-suggest-label="p001"]')).toHaveText("stub label p001"); + expect(stubRequests().filter((r) => r.route === "report-draft" && r.task === "clips-suggest").map((r) => [r.project, r.note ?? null])).toEqual([[DIR, null]]); + expect(json("clip-suggestions.json")?.items?.p005?.rank).toBe(1); + + // A comment on r002, and Ask the assistant: the note goes to the editor. + await page.locator('[data-editor-row="r002"]').click(); + await expect(editor).toHaveAttribute("data-clip-editor", "r002"); + await page.locator("[data-clip-note-input]").fill("start it half a second later"); + await page.locator("[data-clip-note-add]").click(); + const thread = page.locator('[data-clip-notes="r002"] [data-note-id]'); + await expect(thread).toHaveCount(1); + const noteId = (await thread.getAttribute("data-note-id"))!; + await thread.locator('[data-note-action="ask"]').click(); + await expect(page.locator("[data-ask-job]")).toHaveAttribute("data-ask-job", "done", { timeout: 20_000 }); + expect(stubRequests().filter((r) => r.task === "clips-suggest" && r.note).map((r) => [r.project, r.note])).toEqual([[DIR, noteId]]); + + // The agent's reply carries a trim (the reply the job posts, posted here: the stub cannot reach umtool). + 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: "Start it on the breath at 4.5 s.", proposal: { kind: "trim", clip: "r002", from: 4.5, to: 6, basis: { cutStart: 4, cutEnd: 6 } } } }, + }); + expect(replied.ok()).toBe(true); + // The page's own write may not carry one: a proposal is an agent's. + const forged = await request.post(`/api/notes?project=${encodeURIComponent(PROJECT)}`, { + data: { op: { op: "reply", id: noteId, text: "x", proposal: { kind: "cut", clip: "r002" } } }, + }); + expect(forged.status()).toBe(400); + await page.reload(); + await expect(editor).toHaveAttribute("data-clip-editor", "r002"); + const proposal = page.locator('[data-clip-notes="r002"] [data-reply-proposal="trim"]'); + await expect(proposal).toContainText("trim r002 to 0:04.5–0:06.0 (1.5 s)"); + // Nothing moved until the click. + expect([clip("r002")?.cutStart, clip("r002")?.cutEnd]).toEqual([4, 6]); + await proposal.locator('[data-apply-proposal="trim"]').click(); + await expect.poll(() => clip("r002")?.cutStart).toBe(4.5); + expect(clip("r002")?.cutEnd).toBe(6); + expect(clip("r002")?.assist?.by).toBe("operator"); + await expect(page.locator("[data-editor-status]")).toHaveText("Applied: trim r002 to 0:04.5–0:06.0 (1.5 s)"); + // The operator's "Applied" reply answers it: no second Apply. + await expect(proposal.locator("[data-reply-proposal-answered]")).toHaveCount(1); + await expect(proposal.locator("[data-apply-proposal]")).toHaveCount(0); + const notes = json("notes.json")?.notes ?? []; + expect(notes[0].replies.map((r: { author: string; text: string }) => [r.author, r.text])).toEqual([ + ["agent", "Start it on the breath at 4.5 s."], + ["operator", "Applied: trim r002 to 0:04.5–0:06.0 (1.5 s)"], + ]); +}); diff --git a/umtool/e2e/fixtures/clips-suggest-fixture.mjs b/umtool/e2e/fixtures/clips-suggest-fixture.mjs @@ -0,0 +1,88 @@ +// What clips-suggest.spec.ts reads and writes (release 36 lane D): the clip +// editor's three assistant clips on vid1 (the clip editor fixture's cut, +// copied under its own name so the two specs never edit one project), its +// reactions.json and words.json, every window cached — and the assistant's +// labels for the five proposals (clip-suggestions.json, as the editor's +// `clips-suggest` task writes it), ranked so the sort reorders both lists: +// +// p003 (r003) 1 · p005 (unused) 2 · p001 (r001) 3 · p004 (unused) 4 · p002 (r002) 5 +// +// The spec posts the agent's reply itself (the editor stub cannot reach +// umtool), as the clip-editor spec does. Synthetic, like every fixture. +import { copyFileSync, mkdirSync, writeFileSync } from "node:fs"; +import path from "node:path"; + +const write = (dir, name, doc) => { + mkdirSync(dir, { recursive: true }); + writeFileSync(path.join(dir, name), JSON.stringify(doc, null, 2) + "\n"); +}; + +export const SUGGEST_PROPOSED_AT = "2026-01-01T00:00:00.000Z"; + +/** + * @param {{ reports: string, manifest: Function, cachedWindow: string, cues: Array<[number, number, string]> }} o + */ +export function makeClipsSuggestFixture({ reports, manifest, cachedWindow, cues }) { + const dir = path.join(reports, "clips-suggest-fixture"); + const assist = (p, s, e, cs, ce, score, why) => ({ by: "assistant", proposal: p, score, why, original: { start: s, end: e, cutStart: cs, cutEnd: ce }, edits: [] }); + const clip = (id, s, e, cs, ce, p, score, why, quote) => ({ type: "clip", id, video: "vid1", start: s, end: e, cutStart: cs, cutEnd: ce, quote, assist: assist(p, s, e, cs, ce, score, why) }); + const doc = manifest("clips-suggest-fixture", "The Clips Suggest Fixture", { siteOrigin: "https://archive.example" }, [ + clip("r001", 0.5, 3.5, 1, 3, "p001", 0.8, "host laughs at the line", "This is a complete sentence."), + clip("r002", 4, 6.5, 4, 6, "p002", 0.7, "a comment", "And this one runs on"), + clip("r003", 6.5, 8.5, 6.5, 8.5, "p003", 0.6, "a short comment", "of that it finishes here."), + ]); + doc.render.fetchPad = 0; + write(dir, "video.manifest.json", doc); + + const words = []; + for (const [start, end, text] of cues) { + const ws = text.split(/\s+/).filter(Boolean); + const step = (end - start) / ws.length; + ws.forEach((w, i) => words.push({ w, start: +(start + i * step).toFixed(2), end: +(start + (i + 0.8) * step).toFixed(2) })); + } + write(dir, "words.json", { words }); + const proposals = [ + { id: "p001", start: 1, end: 3, score: 0.8, moments: ["m001"], used: true, clipId: "r001", why: "host laughs at the line" }, + { id: "p002", start: 4, end: 6, score: 0.7, moments: [], used: true, clipId: "r002", why: "a comment" }, + { id: "p003", start: 6.5, end: 8.5, score: 0.6, moments: [], used: true, clipId: "r003", why: "a short comment" }, + { id: "p004", start: 9, end: 12, score: 0.5, moments: [], used: false, clipId: null, why: "a long comment" }, + { id: "p005", start: 13, end: 15, score: 0.3, moments: [], used: false, clipId: null, why: "a chuckle" }, + ]; + write(dir, "reactions.json", { + version: 1, + source: { channel: "testchan", video: "vid1", duration: 21, words: "words.json", diarization: { generatedAt: "2026-01-01T00:00:00.000Z", engine: "sherpa-onnx" } }, + params: { target: 600, laughMin: 0.25, mergeGap: 6, setupMax: 20, clipMax: 75 }, + proposedAt: SUGGEST_PROPOSED_AT, + speakers: [ + { index: 0, role: "host", label: "Host", seconds: 9, turns: 4, how: "auto" }, + { index: 1, role: "subject", label: "Subject", seconds: 12, turns: 3, how: "auto" }, + ], + turns: [ + { start: 0, end: 2.2, speaker: 1 }, + { start: 2.4, end: 3.8, speaker: 0 }, + { start: 4, end: 6.2, speaker: 1 }, + { start: 6.4, end: 9, speaker: 0 }, + { start: 9.2, end: 15, speaker: 1 }, + { start: 15.2, end: 21, speaker: 0 }, + ], + laughs: [{ start: 2.6, end: 3.2, score: 0.71, speaker: 0 }], + moments: [{ id: "m001", t: 2.6, end: 3.2, kind: "laugh", score: 0.71, speaker: 0, text: "" }], + proposals, + }); + const ranks = { p003: 1, p005: 2, p001: 3, p004: 4, p002: 5 }; + const labels = { p001: "the complete sentence", p002: "a run-on line", p003: "how it finishes", p004: "the long comment", p005: "a quiet chuckle" }; + write(dir, "clip-suggestions.json", { + model: "qwen3:8b", + at: "2026-01-01T01:00:00.000Z", + proposedAt: SUGGEST_PROPOSED_AT, + promptVersion: "clips-suggest-1", + items: Object.fromEntries( + proposals + .map((p) => [p.id, { label: labels[p.id], why: `Why ${p.id} lands.`, rank: ranks[p.id], score: 11 - ranks[p.id] * 2, start: p.start, end: p.end }]) + .sort((a, b) => a[1].rank - b[1].rank), + ), + }); + mkdirSync(path.join(dir, "out", "clips-raw"), { recursive: true }); + copyFileSync(cachedWindow, path.join(dir, "out", "clips-raw", "vid1_0.00-9.00.mp4")); + return { dir }; +} diff --git a/umtool/e2e/fixtures/editor-stub.mjs b/umtool/e2e/fixtures/editor-stub.mjs @@ -23,6 +23,8 @@ import { portFor } from "yt-dlp-transcript-common/lib/ports.mjs"; import { applyDraft, draftedOf, isCodeDraft, makeProvenance, ownerOf } from "yt-dlp-transcript-common/lib/report/drafted.mjs"; import { fileURLToPath } from "node:url"; import { fetchWindowsRoute } from "./editor-stub-fetch-windows.mjs"; +import { readReactions } from "yt-dlp-transcript-common/lib/clips/reactions.mjs"; +import { readSuggestions, suggestionsDocOf, writeSuggestions } from "yt-dlp-transcript-common/lib/clips/suggest.mjs"; const PORT = portFor("EDITOR_STUB_PORT"); const CHANNELS = process.env.CHANNELS_DIR ?? ""; @@ -599,6 +601,49 @@ function cannedRun(job, body) { job.log.push(`${task}: ${summary}`, `@@report-draft ${JSON.stringify({ article, iteration: n, task, status, summary })}`); } +// A `clips-suggest` report-draft (release 36 lane D): labels for every +// proposal of body.project, written through common's one writer as the real +// task does ("stub label <id>", scored so the LAST proposal ranks first); an +// Ask (body.note) ends with no reply — the stub cannot reach umtool, so a spec +// posts the agent's reply itself. +function startClipsSuggest(body) { + if (typeof body.project !== "string" || !body.project.startsWith("/")) throw new Error('"project" is the reactions project\'s absolute directory'); + const id = `stub-suggest-${nextJob++}`; + const ask = typeof body.note === "string"; + const job = { id, article: null, n: 0, task: "clips-suggest", status: "queued", at: Date.now(), log: [`report-draft clips-suggest ${ask ? `ask ${body.note}` : "labels"} (stub)`], timers: [] }; + draftJobs.set(id, job); + job.timers.push( + setTimeout(() => { + job.status = "running"; + job.progress = { metric: "entries", initial: 0, current: 0, target: 1 }; + job.log.push("asking the stub model"); + }, 300), + ); + job.timers.push( + setTimeout(async () => { + try { + if (ask) { + job.log.push(`replied to ${body.note} (stub: no reply posted)`, `@@report-draft ${JSON.stringify({ article: "", iteration: 0, task: "clips-suggest", kind: "ask", status: "done", summary: `asked about ${body.note} (stub)` })}`); + } else { + const reactions = await readReactions(body.project); + if (!reactions) throw new Error(`${body.project} holds no reactions.json`); + const fresh = reactions.proposals.map((p, i) => ({ id: p.id, label: `stub label ${p.id}`, why: `The stub likes ${p.id}.`, score: Math.min(10, i + 1) })); + const prev = (await readSuggestions(body.project)).doc; + await writeSuggestions(body.project, suggestionsDocOf({ model: generation.models.local, at: new Date().toISOString(), reactions, fresh, prev })); + const summary = `${fresh.length} proposals labelled on ${generation.models.local}`; + job.log.push(summary, `@@report-draft ${JSON.stringify({ article: "", iteration: 0, task: "clips-suggest", kind: "labels", status: "done", summary, suggestions: { labelled: fresh.length, refused: 0, failed: 0 } })}`); + } + job.progress = { metric: "entries", initial: 0, current: 1, target: 1 }; + job.status = "done"; + } catch (err) { + job.log.push(String(err.message)); + job.status = "failed"; + } + }, 1500), + ); + return { jobId: id, iteration: 0 }; +} + function startCannedDraft(body, id) { const { task, article } = body; const n = body.iteration; @@ -808,6 +853,7 @@ function cancelDraft(id) { job.status = "cancelled"; job.log.push("cancelled"); job.child?.kill(); + if (job.task === "clips-suggest") return true; const it = readIt(job.article, job.n); if (job.task === "narrate" || MEDIA_RUN.has(job.task) || MEDIA_TASKS.has(job.task)) { patchIt(job.article, job.n, { steps: it.steps.map((s) => (s.jobId === id ? { ...s, status: "cancelled" } : s)) }); @@ -869,6 +915,14 @@ function generationRoute(req, res, url, auth) { return readBody(req, (body) => { requests.push({ route: "report-draft", ...(body ?? {}), authorization: auth }); record(); + // Release 36 lane D: the clip finder's labels (a project, not an article). + if (body?.task === "clips-suggest") { + try { + return json(res, 202, { ok: true, ...startClipsSuggest(body) }); + } catch (err) { + return json(res, 400, { ok: false, error: String(err.message) }); + } + } if (!body || !body.task || !body.article) return json(res, 400, { ok: false, error: "task and article are required" }); if (body.feedback === "refuse") return json(res, 400, { ok: false, error: "the stub refuses this feedback" }); try { diff --git a/umtool/e2e/fixtures/make-fixture.mjs b/umtool/e2e/fixtures/make-fixture.mjs @@ -36,6 +36,7 @@ import { makeBenchShellFixture } from "./bench-shell-fixture.mjs"; import { makeYoutubeFixture } from "./youtube-fixture.mjs"; import { makeBoardFixture, makeResearchFixture } from "./research-fixture.mjs"; import { makeRunTraceFixture } from "./run-trace-fixture.mjs"; +import { makeClipsSuggestFixture } from "./clips-suggest-fixture.mjs"; const CODE = path.resolve(path.dirname(new URL(import.meta.url).pathname), "..", "..", "song"); const dest = path.resolve(process.argv[2] ?? path.join(process.cwd(), ".e2e-song")); @@ -1814,6 +1815,8 @@ makeClipEditorFixture({ reports, manifest, cachedWindow: path.join(REPORT, "out" makeBenchShellFixture({ reports, manifest, cachedWindow: path.join(REPORT, "out", "clips-raw", "vid1_0.00-9.00.mp4") }); // Release 28 M6: the YouTube text, previewed and built (media-draft-e.spec.ts). makeYoutubeFixture({ reports, manifest, cachedWindow: path.join(REPORT, "out", "clips-raw", "vid1_0.00-9.00.mp4") }); +// Release 36 lane D: the assistant's labels, Suggest, Ask and Apply in the clip editor (clips-suggest.spec.ts). +makeClipsSuggestFixture({ reports, manifest, cachedWindow: path.join(REPORT, "out", "clips-raw", "vid1_0.00-9.00.mp4"), cues: CUES.vid1 }); // TWO MORE cached windows for vid1, and they are the regression rather than // decoration.