// A media draft run for real over a fixture iteration, its model the fake // ollama scripted with the task's recorded run (`runs/.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 --projects [--model qwen3:8b] \ // [--entries c01,c02] [--force] [--job ] // // 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(/* turbopackIgnore: true */ fileURLToPath(import.meta.url)); const ROOT = path.resolve(/* turbopackIgnore: true */ 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 --article --n --articles --projects [--model m] [--entries a,b] [--force] [--job id]"); process.exit(2); } const run = JSON.parse(await readFile(path.join(/* turbopackIgnore: true */ 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);