// UN-REJECT (owed 6 Nov: removed.json keeps id/window/reason only): `umtool timeline

restore ` puts a // removed clip back from the newest revision that holds it -- claim, quote, cite and edges as they were -- at its // old place, every later write kept; `removed` lists what is still out. // // Run with: pnpm test:scripts import assert from "node:assert/strict"; import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises"; import { tmpdir } from "node:os"; import path from "node:path"; import test from "node:test"; const ROOT = await mkdtemp(path.join(tmpdir(), "umtool-restore-")); process.env.REPORTS_DIR = ROOT; const { MANIFEST_NAME, readRemoved, rejectClip, removeEntry, removedOutOfCut, removedSourceOf, restoreRemoved, updateClip } = await import("./manifest.mjs"); const { timelineCommand } = await import("./timelineCli.mjs"); const C02 = { type: "clip", id: "c02", channel: "chan", video: "v2", start: 30, end: 44, cutStart: 31.2, cutEnd: 42.8, lockEnd: true, cite: 31, quote: "the whole sentence, as cited", citeUrl: "https://example.test/v/chan/v2?t=31", claim: { id: "k1", verdict: "CONTRADICTED", at: 35, label: "1 SEIZURE" }, }; const base = () => ({ schemaVersion: 1, slug: "r", title: "R", provenance: { siteOrigin: "https://example.test", channelSlug: "chan" }, render: { width: 1920, height: 1080, fps: 30 }, timeline: [ { type: "clip", id: "c01", video: "v1", start: 10, end: 20 }, structuredClone(C02), { type: "clip", id: "c03", video: "v3", start: 50, end: 60 }, ], }); async function project(name) { const dir = path.join(ROOT, name); await mkdir(dir, { recursive: true }); await writeFile(path.join(dir, MANIFEST_NAME), JSON.stringify(base(), null, 2) + "\n"); return dir; } const read = async (dir) => JSON.parse(await readFile(path.join(dir, MANIFEST_NAME), "utf8")); const ids = async (dir) => (await read(dir)).timeline.map((e) => e.id); test.after(() => rm(ROOT, { recursive: true, force: true })); test("restore: the rejected clip back as it was, at its old place, every later write kept", async () => { const dir = await project("back"); await rejectClip(dir, "c02", "irrelevant", { note: "off topic" }); assert.deepEqual(await ids(dir), ["c01", "c03"]); // Later writes: c01 trimmed, a clip inserted at the end. The restore must keep both. await updateClip(dir, "c01", { start: 11, end: 19 }); const m = await read(dir); m.timeline.push({ type: "clip", id: "c04", video: "v4", start: 70, end: 80 }); await writeFile(path.join(dir, MANIFEST_NAME), JSON.stringify(m, null, 2) + "\n"); assert.deepEqual(removedOutOfCut(await readRemoved(dir), await read(dir)).map((r) => r.id), ["c02"]); const r = await restoreRemoved(dir, "c02"); assert.equal(r.at, 1); assert.equal(r.after, "c01"); assert.match(r.from, /^revisions\/.*auto-before-reject\.manifest\.json$/); const now = await read(dir); assert.deepEqual(now.timeline.map((e) => e.id), ["c01", "c02", "c03", "c04"]); // The entry as it was before the reject: no rejected verdict, claim/quote/cite/edges intact. assert.deepEqual(now.timeline[1], C02); assert.deepEqual([now.timeline[0].start, now.timeline[0].end], [11, 19], "the trim after the reject is kept"); // Off the list; its line stays on record. assert.deepEqual(removedOutOfCut(await readRemoved(dir), now), []); assert.equal((await readRemoved(dir)).length, 1); await assert.rejects(restoreRemoved(dir, "c02"), /c02 is in the cut already/); }); test("restore: its neighbour before gone too, it goes before the one after; nothing holds it -- refused, naming the insert", async () => { const dir = await project("neighbour"); await rejectClip(dir, "c02", "weak"); await removeEntry(dir, "c01"); await restoreRemoved(dir, "c02"); assert.deepEqual(await ids(dir), ["c02", "c03"]); const bare = await project("bare"); await rejectClip(bare, "c02", "weak"); await rm(path.join(bare, "revisions"), { recursive: true, force: true }); await rm(path.join(bare, `${MANIFEST_NAME}.bak`), { force: true }); await assert.rejects(restoreRemoved(bare, "c02"), /no revision of the manifest holds c02.*insert chan\/v2@30-44/s); assert.deepEqual(await ids(bare), ["c01", "c03"], "nothing written"); }); test("umtool timeline

removed | restore : the list, then the clip back, with an undo point", async () => { const dir = await project("cli"); await rejectClip(dir, "c02", "repeats", { note: "covered by c01" }); const lines = []; const run = (...a) => timelineCommand(a, { root: ROOT, out: (s) => lines.push(s), err: (s) => lines.push(`ERR ${s}`) }); assert.equal(await run("cli", "removed"), 0, lines.join("\n")); assert.match(lines.join("\n"), /c02\s+chan\/v2@30-44\s+.*covered by c01/); assert.match(lines.at(-1), /1 removed clip out of cli -- umtool timeline cli restore puts one back/); assert.equal(await run("cli", "restore", "c02"), 0, lines.join("\n")); assert.match(lines.join("\n"), /restored c02 at 1 \(after c01\), as it was in revisions\//); assert.match(lines.join("\n"), /undo point: revisions\/.*auto-before-restore/); assert.deepEqual(await ids(dir), ["c01", "c02", "c03"]); assert.equal(await run("cli", "removed", "--json"), 0); assert.deepEqual(JSON.parse(lines.at(-1)).removed, []); assert.equal(await run("cli", "restore", "c02"), 1); assert.match(lines.at(-1), /c02 is in the cut already/); }); test("a removed clip names where it came from: its channel on record (the cut's when the clip names none), never `?/`", async () => { const dir = await project("source"); await rejectClip(dir, "c02", "irrelevant"); const [row] = await readRemoved(dir); assert.equal(row.channel, "chan", "the cut's channel, on record"); assert.equal(removedSourceOf(row, await read(dir)), `chan/${C02.video} @ ${C02.start}–${C02.end}`); // An older record with no channel: the cut's, at display; with none anywhere, the video alone. assert.equal(removedSourceOf({ ...row, channel: null }, await read(dir)), `chan/${C02.video} @ ${C02.start}–${C02.end}`); assert.equal(removedSourceOf({ ...row, channel: null }, { provenance: {} }, { dash: "-", at: "@" }), `${C02.video}@${C02.start}-${C02.end}`); assert.equal(removedSourceOf({ id: "x" }, null), "", "no video: the id says it"); });