// Release 38 lane E: the `video-assist` task on the fake ollama and the fake // Anthropic — every request of the table asked once on each, the answer // checked and written as proposals; nothing applied. import { after, before, test } from "node:test"; import assert from "node:assert/strict"; import { mkdtemp, readFile, rm } from "node:fs/promises"; import os from "node:os"; import path from "node:path"; import { startFakeAnthropic, toolTurn, type FakeAnthropic } from "../../../../testing/llm/fakeAnthropic.mjs"; import { jsonReply, startFakeOllama, PROMPT_CAP_TOKENS, type FakeOllama } from "../../../../testing/llm/fakeOllama.mjs"; import { ASSIST_NOTE, ASSIST_REQUESTS, answerOf, writeAssistProject } from "../../../../testing/clips/assistProject.mjs"; import { readAssistProposals } from "../../videoAssistProposals.mjs"; import { ASSIST_CODE_MODEL, VideoAssistRefusal, cutContextOf, noteReplyOf, noteRequestOf, planVideoAssist, runVideoAssist } from "./videoAssist"; import type { LlmConfig } from "../../../llm"; let tmp: string; let api: FakeAnthropic; let ol: FakeOllama; let llm: LlmConfig; before(async () => { tmp = await mkdtemp(path.join(os.tmpdir(), "video-assist-")); api = await startFakeAnthropic(); ol = await startFakeOllama(); llm = { anthropic: { baseUrl: api.url, env: { ANTHROPIC_API_KEY: api.key } }, ollama: { baseUrl: ol.url } }; }); after(async () => { await api.close(); await ol.close(); await rm(tmp, { recursive: true, force: true }); }); const userOfOllama = (body: { messages: { role: string; content: string }[] }) => body.messages.find((m) => m.role === "user")!.content; for (const [route, model] of [ ["local", "qwen3:8b"], ["api", "claude-sonnet-5-5"], ] as const) { test(`every request of the table on the ${route} model: one ask, the ops checked, assist-proposals.json written, the manifest untouched`, async () => { for (const [i, row] of ASSIST_REQUESTS.entries()) { const dir = path.join(tmp, `${route}-${i}`); const { manifest } = writeAssistProject(dir, { deck: !!row.deck }); const before = await readFile(path.join(dir, "video.manifest.json"), "utf8"); let prompt = ""; if (route === "local") { ol.push((body: { messages: { role: string; content: string }[] }) => { prompt = userOfOllama(body); return jsonReply(answerOf(row)); }); } else { api.push((body: { messages: { content: unknown }[] }) => { prompt = JSON.stringify(body.messages[0]!.content); return toolTurn("answer", answerOf(row)); }); } const out = await runVideoAssist({ project: dir, model, request: row.request, scope: row.scope ?? "all" }, { llm, now: () => new Date("2026-10-20T00:00:00.000Z") }); assert.equal(out.status, "done", row.request); assert.ok(prompt.includes(`THE REQUEST:${route === "api" ? "\\n" : "\n"}${row.request}`), `${row.request}: the request is in the prompt`); const { doc } = await readAssistProposals(dir); assert.ok(doc, row.request); assert.deepEqual(doc!.diff, row.diff, row.request); assert.deepEqual(doc!.ops.map((o) => o.status), row.diff.map(() => "proposed")); assert.equal(doc!.refused.length, row.refused.length, `${row.request}: ${JSON.stringify(doc!.refused)}`); doc!.refused.forEach((r, k) => assert.match(r.why, row.refused[k]!, row.request)); assert.equal(doc!.model, model); assert.equal(doc!.request, row.request); assert.equal(await readFile(path.join(dir, "video.manifest.json"), "utf8"), before, `${row.request}: nothing applied`); assert.ok(manifest); } if (route === "local") { // Every local ask fitted under the GPU's prompt cap (the fake refuses one over it). assert.ok(ol.requests.every((b: { format?: unknown }) => !!b.format), "schema-bound"); } }); } test("the local view is fitted to the prompt cap however long the cut", async () => { const dir = path.join(tmp, "long"); const { manifest } = writeAssistProject(dir); for (let i = 5; i <= 400; i++) manifest.timeline.push({ type: "clip", id: `r${i}`, channel: "c", video: "v", start: i * 60, end: i * 60 + 30, cutStart: i * 60 + 5, cutEnd: i * 60 + 25, quote: "words ".repeat(30) }); await import("node:fs/promises").then((fs) => fs.writeFile(path.join(dir, "video.manifest.json"), JSON.stringify(manifest))); const plan = await planVideoAssist({ project: dir, model: "qwen3:8b", request: "end r333 a second later" }, { llm }); assert.ok(plan.estimate.inputTokens <= PROMPT_CAP_TOKENS, String(plan.estimate.inputTokens)); assert.match(plan.request.user, /- r333: cut 19985–20005 s/); assert.match(plan.request.user, /- r399 \(not shown in full\)/); assert.equal(plan.estimate.usd, 0); const api = await planVideoAssist({ project: dir, model: "claude-sonnet-5-5", request: "quicker joins" }, { llm }); assert.ok(api.estimate.usd > 0); }); test("the code route: a session's answer is checked as a model's, written as claude-code's; junk is refused", async () => { const dir = path.join(tmp, "code"); writeAssistProject(dir); const asked = api.requests.length + ol.requests.length; const out = await runVideoAssist({ project: dir, model: ASSIST_CODE_MODEL, request: "no QR", answers: { ops: [{ op: "look", id: "", key: "qr", value: false }], reply: "QR off." } }, { llm }); assert.equal(out.status, "done"); assert.equal(api.requests.length + ol.requests.length, asked, "no model asked"); const { doc } = await readAssistProposals(dir); assert.equal(doc!.model, "claude-code"); assert.deepEqual(doc!.diff, ["QR code on → off"]); assert.equal(doc!.reply, "QR off."); await assert.rejects(runVideoAssist({ project: dir, model: ASSIST_CODE_MODEL, request: "x", answers: { nope: 1 } }, { llm }), /the session's answer is refused: the answer has no ops list/); }); test("refusals at the ask: no manifest, no request, an API ask over its cap; a note's text is a request only on the whole project", async () => { await assert.rejects(runVideoAssist({ project: path.join(tmp, "none"), model: "qwen3:8b", request: "x" }, { llm }), /holds no video\.manifest\.json/); const dir = path.join(tmp, "refusals"); writeAssistProject(dir, { note: "make the joins quicker" }); await assert.rejects(runVideoAssist({ project: dir, model: "qwen3:8b", request: " " }, { llm }), VideoAssistRefusal); await assert.rejects(runVideoAssist({ project: dir, model: "claude-sonnet-5-5", request: "quicker joins", maxUsd: 0.000001 }, { llm }), /is over its cap/); assert.equal(await noteRequestOf(dir, ASSIST_NOTE), "make the joins quicker"); await assert.rejects(noteRequestOf(dir, "n_absent00"), /no note n_absent00/); }); test("a note taken in the Play view: its text with where it was taken is the request, in the prompt the model reads", async () => { const dir = path.join(tmp, "cut-note"); writeAssistProject(dir, { note: "this drags — start later", anchor: { kind: "cut", t: 72.44, entry: "r002", sourceT: 94.8, take: "short-19" } }); const request = await noteRequestOf(dir, ASSIST_NOTE); assert.equal(request, "this drags — start later (noted while playing take short-19 at 1:12.4, in clip r002 at source 94.8 s)"); assert.equal(cutContextOf({ t: 3 }), "(noted while playing the cut at 0:03.0)"); assert.equal(cutContextOf({ t: 3, entry: "c01", ask: "trim" }), "(noted while playing the cut at 0:03.0, in clip c01; asks for a trim)"); let prompt = ""; ol.push((body: { messages: { role: string; content: string }[] }) => { prompt = userOfOllama(body); return jsonReply({ ops: [], reply: "Nothing to change." }); }); const out = await runVideoAssist({ project: dir, model: "qwen3:8b", request, note: ASSIST_NOTE }, { llm }); assert.equal(out.status, "done"); assert.ok(prompt.includes(`THE REQUEST:\n${request}`), prompt.slice(0, 400)); // A part of the project other than the cut is still the clip editor's. writeAssistProject(path.join(tmp, "entry-note"), { note: "x", anchor: { kind: "entry", entry: "r002" } }); await assert.rejects(noteRequestOf(path.join(tmp, "entry-note"), ASSIST_NOTE), /on a part of the project/); }); test("a note's reply: the proposals in words, the refusals, where to apply", () => { const text = noteReplyOf({ version: 1, promptVersion: "video-assist-1", at: "t", model: "m", request: "r", scope: "all", reply: "Quicker joins.", ops: [{ id: "a1", op: { op: "look" }, diff: "join 0.22 s → 0.15 s", status: "proposed" }], refused: [{ op: {}, why: "render.transition must be a number of seconds from 0 (a hard cut) to 3" }], diff: ["join 0.22 s → 0.15 s"], }); assert.equal(text, "Quicker joins.\nProposed 1 edit — Apply below or in the Build tab's Look panel:\n• join 0.22 s → 0.15 s\n• not done: render.transition must be a number of seconds from 0 (a hard cut) to 3"); });