Archilyzer · Source

archilyzer

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

commit 0a76bd77a3713a014519d5585a1e7ae9e6260e9e
parent 92915c63024ba2dcf2a67f40cb9b841a95fe6ea5
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Tue, 13 Oct 2026 22:50:59 -0400

umtool: e2e media-draft.spec — cut, onscreen and teaser through the editor stub, run for real on the fake model

The stub runs a media task's report-draft as the common task over the
fixture iteration's project (common/testing/draft/runMediaStep.ts, a tsx
child), its model the fake ollama scripted with the kit's recorded run; the
task records its own step. Fixture `mdraft`: three done iterations, each
with the kit's basic cut. umtool's generate forwards `entries`.

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

Diffstat:
Acommon/testing/draft/runMediaStep.ts | 73+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/app/api/articles/generate/route.ts | 5++++-
Mumtool/e2e/fixtures/editor-stub.mjs | 52++++++++++++++++++++++++++++++++++++++++++++++++++--
Mumtool/e2e/fixtures/make-fixture.mjs | 3+++
Aumtool/e2e/fixtures/media-draft-fixture.mjs | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aumtool/e2e/media-draft.spec.ts | 87+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/lib/articles/generation.ts | 2+-
7 files changed, 276 insertions(+), 4 deletions(-)

diff --git a/common/testing/draft/runMediaStep.ts b/common/testing/draft/runMediaStep.ts @@ -0,0 +1,73 @@ +// A media draft run for real over a fixture iteration, its model the fake +// ollama scripted with the task's recorded run (`runs/<task>.json`) — what +// umtool's e2e editor stub does with a `report-draft` of a media task +// (release 28: umtool/e2e/media-draft.spec.ts). Test-only; synthetic. +// +// tsx common/testing/draft/runMediaStep.ts --task cut --article mdraft --n 1 \ +// --articles <ARTICLES_DIR> --projects <projectsRoot> [--model qwen3:8b] \ +// [--entries c01,c02] [--force] [--job <id>] +// +// The task records its own step on the iteration (running, then its end). The +// last line printed is `@@report-draft {article, iteration, task, status, +// summary}`; the exit code is 0 when the step is done. + +import { mkdir, readFile } from "node:fs/promises"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; +import { startFakeOllama } from "../llm/fakeOllama.mjs"; +import { isStepTask } from "../../lib/generationSettings"; +import { loadDeckChecks, runTask, type TaskInput } from "../../lib/report/draft/tasks/index"; + +const HERE = path.dirname(fileURLToPath(import.meta.url)); +const ROOT = path.resolve(HERE, "../../.."); + +const argv = process.argv.slice(2); +const flag = (name: string) => { + const i = argv.indexOf(`--${name}`); + return i < 0 ? undefined : argv[i + 1]; +}; +const task = flag("task") ?? ""; +const article = flag("article") ?? ""; +const n = Number(flag("n")); +const articlesDir = flag("articles") ?? ""; +const projectsRoot = flag("projects") ?? ""; +if (!isStepTask(task) || !article || !Number.isInteger(n) || !articlesDir || !projectsRoot) { + console.error("usage: runMediaStep.ts --task <media task> --article <id> --n <i> --articles <dir> --projects <dir> [--model m] [--entries a,b] [--force] [--job id]"); + process.exit(2); +} + +const run = JSON.parse(await readFile(path.join(HERE, "runs", `${task}.json`), "utf8")) as { model: string; turns: unknown[] }; +const ol = await startFakeOllama(); +ol.push(...(run.turns as never[])); +const exportIndexDir = path.join(articlesDir, "..", ".export-index-media-draft"); +await mkdir(exportIndexDir, { recursive: true }); +const entries = flag("entries")?.split(",").map((x) => x.trim()).filter(Boolean); +const jobId = flag("job"); +const input = { + task, + article, + n, + model: flag("model") ?? run.model, + projectsRoot, + ...(entries?.length ? { entries } : {}), + ...(argv.includes("--force") ? { force: true } : {}), + ...(jobId ? { jobId } : {}), +} as TaskInput; +let code = 1; +try { + const res = await runTask(input, { + llm: { ollama: { baseUrl: ol.url } }, + corpus: { source: "none", tools: [], call: async () => "" }, + cuesOf: async () => null, + paths: { articlesDir, exportIndexDir }, + log: (l) => console.log(l), + deckChecks: () => loadDeckChecks(ROOT), + }); + console.log(`@@report-draft ${JSON.stringify({ article, iteration: n, task, status: res.status, summary: res.summary })}`); + code = res.status === "done" ? 0 : 1; +} catch (e) { + console.log(`@@report-draft ${JSON.stringify({ article, iteration: n, task, status: "failed", summary: (e as Error).message })}`); +} finally { + await ol.close(); +} +process.exit(code); diff --git a/umtool/app/api/articles/generate/route.ts b/umtool/app/api/articles/generate/route.ts @@ -4,7 +4,7 @@ export const dynamic = "force-dynamic"; // START A GENERATION (release 27 S8): the body is `pnpm ops report-draft`'s — // { task, article, iteration?, model?, extractorModel?, feedback?, question?, -// channels?, from?, to?, copyOf?, maxUsd?, cards?, force?, autonomy? } — +// channels?, from?, to?, copyOf?, maxUsd?, cards?, entries?, force?, autonomy? } — // forwarded to the editor, which // creates the iteration and runs the job. Answers { ok, jobId, iteration }. // @@ -13,6 +13,9 @@ export const dynamic = "force-dynamic"; // a new iteration task revise-report | revise-video, iteration, feedback // copy with model the iteration's task, copyOf, model // narration task narrate, iteration, model (a step) +// a media draft task cut | onscreen | teaser | flips | threads | +// youtube, iteration, model, entries?, force? (a step, +// release 28) // research task research, question, channels?, model, autonomy // (release 27 S11: its queue is /api/articles/research) // continue research task sweep, iteration (the research run), model diff --git a/umtool/e2e/fixtures/editor-stub.mjs b/umtool/e2e/fixtures/editor-stub.mjs @@ -16,10 +16,11 @@ // entry, ready when its own endpoint answers. import http from "node:http"; -import { spawnSync } from "node:child_process"; +import { spawn, spawnSync } from "node:child_process"; import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, writeFileSync, statSync } from "node:fs"; import path from "node:path"; import { portFor } from "yt-dlp-transcript-common/lib/ports.mjs"; +import { fileURLToPath } from "node:url"; const PORT = portFor("EDITOR_STUB_PORT"); const CHANNELS = process.env.CHANNELS_DIR ?? ""; @@ -358,10 +359,56 @@ function continuation(article, rn, force) { return { kind: "sweep", parent: rn, copyOf: null, question: r.question, scope: { channels } }; } +// The media drafts (release 28) run FOR REAL: the common task over the +// fixture iteration's project, its model the fake ollama scripted with the +// test kit's recorded run (common/testing/draft/runMediaStep.ts, a child under +// tsx). The task records its own step; the job follows the child. +const REPO = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../.."); +const MEDIA_RUN = new Set(["cut", "onscreen", "teaser"]); +function startMediaDraft(body, id) { + const { task, article } = body; + const n = body.iteration; + const it = readIt(article, n); + if (it.status !== "done") throw new Error(`"${article}" i${n} is ${it.status}: a ${task} draft runs over a done iteration`); + const job = { id, article, n, task, status: "queued", log: [`report-draft ${task} ${article} i${n} (stub: the task, the fake model)`], timers: [], child: null }; + draftJobs.set(id, job); + const args = [ + path.join(REPO, "common/testing/draft/runMediaStep.ts"), + "--task", task, "--article", article, "--n", String(n), "--articles", ARTICLES, "--projects", GEN_PROJECTS, "--job", id, + ...(body.model ? ["--model", body.model] : []), + ...(Array.isArray(body.entries) ? ["--entries", body.entries.join(",")] : []), + ...(body.force ? ["--force"] : []), + ]; + job.timers.push( + setTimeout(() => { + if (job.status !== "queued") return; + job.status = "running"; + const child = spawn(path.join(REPO, "node_modules/.bin/tsx"), args, { cwd: REPO, stdio: ["ignore", "pipe", "pipe"] }); + job.child = child; + let buf = ""; + const take = (d) => { + buf += d; + const lines = buf.split("\n"); + buf = lines.pop(); + job.log.push(...lines.filter(Boolean)); + }; + child.stdout.on("data", take); + child.stderr.on("data", take); + child.on("close", (code) => { + if (buf) job.log.push(buf); + if (job.status === "cancelled") return; + job.status = code === 0 ? "done" : "failed"; + }); + }, 500), + ); + return { jobId: id, iteration: n }; +} + function startDraft(body) { const { task, article } = body; const now = new Date().toISOString(); const id = `stub-draft-${nextJob++}`; + if (MEDIA_RUN.has(task)) return startMediaDraft(body, id); let n; if (task === "narrate") { n = body.iteration; @@ -413,8 +460,9 @@ function cancelDraft(id) { for (const t of job.timers) clearTimeout(t); job.status = "cancelled"; job.log.push("cancelled"); + job.child?.kill(); const it = readIt(job.article, job.n); - if (job.task === "narrate") { + if (job.task === "narrate" || MEDIA_RUN.has(job.task)) { patchIt(job.article, job.n, { steps: it.steps.map((s) => (s.jobId === id ? { ...s, status: "cancelled" } : s)) }); } else { patchIt(job.article, job.n, { status: "cancelled", endedAt: new Date().toISOString() }); diff --git a/umtool/e2e/fixtures/make-fixture.mjs b/umtool/e2e/fixtures/make-fixture.mjs @@ -24,6 +24,7 @@ import { SONG_DATA } from "../../song/paths.mjs"; import { songCapabilities } from "./song-capabilities.mjs"; import { makeSitesFixture } from "./sites-fixture.mjs"; import { makeIterationsFixture } from "./iterations-fixture.mjs"; +import { makeMediaDraftFixture } from "./media-draft-fixture.mjs"; import { makeDeleteFixture } from "./delete-fixture.mjs"; import { makeDraftReviewFixture } from "./draft-review-fixture.mjs"; @@ -1916,6 +1917,8 @@ writeProject("timeline-fixture", { const { sites: SITES, articles: ARTICLES } = makeSitesFixture({ dest, reports, channels: CHANNELS }); // Release 27: an article in the making (zeta), its projects, today's usage. makeIterationsFixture({ dest, articles: ARTICLES }); +// Release 28: the media drafts' article (mdraft), one iteration per task. +makeMediaDraftFixture({ dest, articles: ARTICLES }); // The release 27 follow-up's deletes: psi (in the making) and // reports/delete-fixture (a project with two takes); article-delete.spec.ts // writes its draft (omega) itself. diff --git a/umtool/e2e/fixtures/media-draft-fixture.mjs b/umtool/e2e/fixtures/media-draft-fixture.mjs @@ -0,0 +1,58 @@ +// What media-draft.spec.ts drafts on (release 28 M1–M3; lane E's tasks add +// iterations): `mdraft`, an article in the making whose done iterations each +// have a video project made from the S0 test kit's basic report — the +// converter's cut, its order marked as code's. One iteration per task, so no +// spec depends on another's draft: +// +// articles/mdraft/iterations/{1,2,3} sweep, qwen3:8b, done; the kit's report +// gen-projects/mdraft/i{1,2,3}/ video.manifest.json (the kit's basic +// cut) and report.json +// i1 the cut task's i2 the onscreen task's i3 the teaser task's +// +// The editor stub runs the media task for real over it, its model the fake +// ollama scripted with the kit's recorded run (common/testing/draft/ +// runMediaStep.ts). Synthetic: the kit's invented channel and lines. +import { mkdirSync, readFileSync, writeFileSync } from "node:fs"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; + +const KIT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../../common/testing/draft"); +const AT = "2026-10-13T10:00:00.000Z"; +export const MEDIA_DRAFT_ARTICLE = "mdraft"; +export const MEDIA_DRAFT_ITERATIONS = { cut: 1, onscreen: 2, teaser: 3 }; + +const put = (file, value) => { + mkdirSync(path.dirname(file), { recursive: true }); + writeFileSync(file, typeof value === "string" ? value : JSON.stringify(value, null, 2) + "\n"); +}; + +export function makeMediaDraftFixture({ dest, articles }) { + const report = JSON.parse(readFileSync(path.join(KIT, "reports", "basic.report.json"), "utf8")); + const manifest = readFileSync(path.join(KIT, "manifests", "basic.video.manifest.json"), "utf8"); + for (const n of Object.values(MEDIA_DRAFT_ITERATIONS)) { + const dir = path.join(articles, MEDIA_DRAFT_ARTICLE, "iterations", String(n)); + const project = path.join(dest, "gen-projects", MEDIA_DRAFT_ARTICLE, `i${n}`); + put(path.join(dir, "iteration.json"), { + format: "archilyzer-iteration", + version: 1, + article: MEDIA_DRAFT_ARTICLE, + n, + kind: "sweep", + parent: null, + copyOf: null, + model: "qwen3:8b", + question: "What does the baker say about the bakery?", + scope: { channels: ["synth-kitchen"] }, + status: "done", + usage: {}, + steps: [], + projectDir: project, + createdAt: AT, + updatedAt: AT, + endedAt: AT, + }); + put(path.join(dir, "report.json"), { ...report, id: MEDIA_DRAFT_ARTICLE }); + put(path.join(project, "video.manifest.json"), manifest); + put(path.join(project, "report.json"), { ...report, id: MEDIA_DRAFT_ARTICLE }); + } +} diff --git a/umtool/e2e/media-draft.spec.ts b/umtool/e2e/media-draft.spec.ts @@ -0,0 +1,87 @@ +import { test, expect, type Page } from "@playwright/test"; +import { readFileSync } from "node:fs"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; +import { WARM_TIMEOUT, warm } from "./warm"; + +// --------------------------------------------------------------------------- +// The media drafts (release 28 M1–M3; lane E adds flips, threads, youtube): +// each task asked through umtool's generate, run by the editor stub FOR REAL +// — the common task over the fixture iteration's project, its model the fake +// ollama scripted with the test kit's recorded run — and followed on the +// iteration to its step's end, shown on the Iterations tab. Then the project's manifest +// says what was drafted, marked with its provenance. +// +// mdraft an article in the making; i1, i2, i3 each a done sweep with the +// kit's basic cut (fixtures/media-draft-fixture.mjs) +// --------------------------------------------------------------------------- + +const HERE = path.dirname(fileURLToPath(import.meta.url)); +const FIXTURE = path.join(HERE, "..", ".e2e-song"); +const STUB_LOG = path.join(FIXTURE, "editor-stub.requests.json"); +const ARTICLE = "mdraft"; +const manifestOf = (n: number) => JSON.parse(readFileSync(path.join(FIXTURE, "gen-projects", ARTICLE, `i${n}`, "video.manifest.json"), "utf8")); +const draftFileOf = (n: number, task: string) => JSON.parse(readFileSync(path.join(FIXTURE, "gen-projects", ARTICLE, `i${n}`, `${task}-draft.json`), "utf8")); +const lastAsked = () => + (JSON.parse(readFileSync(STUB_LOG, "utf8")) as { route?: string; [k: string]: unknown }[]).filter((r) => r.route === "report-draft").at(-1); +const ids = (m: { timeline: { id: string }[] }) => m.timeline.map((e) => e.id); +const entry = (m: { timeline: { id: string }[] }, id: string) => m.timeline.find((e) => e.id === id) as Record<string, any>; + +test.beforeAll(async ({ playwright }) => { + test.setTimeout(WARM_TIMEOUT); + await warm(playwright, [`/articles/${ARTICLE}`, `/api/articles/iterations?article=${ARTICLE}`, "/api/articles/policy"]); +}); + +// Ask for the task on iteration n, and follow its step to its end on the tab. +async function draft(page: Page, task: string, n: number, status = "done") { + const r = await page.request.post("/api/articles/generate", { data: { task, article: ARTICLE, iteration: n, model: "qwen3:8b" } }); + expect(r.status(), await r.text()).toBe(200); + expect(await r.json()).toMatchObject({ ok: true, iteration: n }); + expect(lastAsked()).toMatchObject({ task, article: ARTICLE, iteration: n, model: "qwen3:8b", authorization: "Bearer umtool-e2e-token" }); + // The job runs in the stub (a child under tsx); its step is the iteration's. + await expect + .poll( + async () => { + const list = (await (await page.request.get(`/api/articles/iterations?article=${ARTICLE}`)).json()) as { + iterations: { n: number; steps: { task: string; status: string }[] }[]; + }; + return list.iterations.find((i) => i.n === n)?.steps.find((s) => s.task === task)?.status ?? "none"; + }, + { timeout: 60_000, intervals: [1000] }, + ) + .toBe(status); + await page.goto(`/articles/${ARTICLE}?tab=iterations`); + await expect(page.locator(`[data-iteration='${n}'] [data-step='${task}']`)).toHaveAttribute("data-step-status", status); +} + +test("cut: the clips and their order drafted from the report's citations, the timeline built from the entries it had", async ({ page }) => { + test.setTimeout(120_000); + const before = manifestOf(1); + expect(before.drafted.timeline).toMatchObject({ task: "convert", model: "code" }); + await draft(page, "cut", 1); + const m = manifestOf(1); + expect(ids(m)).toEqual(["title", "the-contest", "c04", "c06", "the-bakery", "c03", "c01"]); + expect(entry(m, "c04")).toEqual(entry(before, "c04")); + expect(m.drafted.timeline).toMatchObject({ task: "cut", model: "qwen3:8b", iteration: 1, attempt: 2 }); + expect(draftFileOf(1, "cut").units.cut.applied).toBe("applied"); +}); + +test("onscreen: each clip's title and subtitle, several to an ask; a clip with no clean draft left as it was", async ({ page }) => { + test.setTimeout(120_000); + await draft(page, "onscreen", 2); + const m = manifestOf(2); + expect(entry(m, "c01").onscreen).toEqual({ title: "She will not sell to a chain", subtitle: '"I would never sell the bakery to a chain"' }); + expect(entry(m, "c01").drafted.onscreen).toMatchObject({ task: "onscreen", model: "qwen3:8b", iteration: 2, attempt: 1 }); + expect(entry(m, "c04").drafted.onscreen.attempt).toBe(2); + expect(entry(m, "c06").onscreen).toBeUndefined(); + expect(draftFileOf(2, "onscreen").units.c06.attempts).toHaveLength(2); +}); + +test("teaser: a cut with none gets one after its last clip, its lines drafted and checked by the build's validator", async ({ page }) => { + test.setTimeout(120_000); + await draft(page, "teaser", 3); + const m = manifestOf(3); + expect(ids(m).slice(-2)).toEqual(["c06", "teaser"]); + expect(entry(m, "teaser")).toMatchObject({ type: "teaser", lines: ["Synth Kitchen", "The bakery", "The contest", "What the baker says"] }); + expect(entry(m, "teaser").drafted.lines).toMatchObject({ task: "teaser", attempt: 2 }); +}); diff --git a/umtool/lib/articles/generation.ts b/umtool/lib/articles/generation.ts @@ -216,7 +216,7 @@ export async function cancelDraftJob(id: string): Promise<void> { // The body umtool sends to `report-draft`: the action's own keys, nothing else // (the editor refuses an unknown key; this refuses it first, by name). -const DRAFT_KEYS = ["task", "article", "iteration", "model", "extractorModel", "feedback", "question", "channels", "from", "to", "copyOf", "maxUsd", "cards", "force", "autonomy"]; +const DRAFT_KEYS = ["task", "article", "iteration", "model", "extractorModel", "feedback", "question", "channels", "from", "to", "copyOf", "maxUsd", "cards", "entries", "force", "autonomy"]; export async function enqueueDraft(body: Record<string, unknown>): Promise<{ jobId: string; iteration: number }> { const out: Record<string, unknown> = {};