// The cues around a cited second (release 32 R2): the record's cues as compose // reads them, in a window, and its title. A synthetic record in a temp dir. // // Run with: node_modules/.bin/tsx --test publish/citedCues.test.ts import { after, test } from "node:test"; import assert from "node:assert/strict"; import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import path from "node:path"; import { cuesAround } from "./citedCues"; const root = mkdtempSync(path.join(tmpdir(), "cited-cues-")); after(() => rmSync(root, { recursive: true, force: true })); const ts = (s: number) => new Date(s * 1000).toISOString().slice(11, 23); const put = (file: string, text: string) => { mkdirSync(path.dirname(file), { recursive: true }); writeFileSync(file, text); }; const channelsDir = path.join(root, "channels"); const dir = path.join(channelsDir, "synth-hand", "data", "rec1"); put(path.join(dir, "metadata.info.json"), JSON.stringify({ id: "rec1", title: "Synthetic stream", channel: "synth-hand", upload_date: "20260110", duration: 600, webpage_url: "https://www.youtube.com/watch?v=rec1", extractor_key: "Youtube" })); put( path.join(dir, "transcript.en.vtt"), "WEBVTT\nKind: captions\nLanguage: en\n\n" + ([ [10, 14, "The bakery opened in the spring of that year."], [14, 18, "I was there for the first loaf, honestly."], [18, 22, "Nobody believed the oven would hold up."], [40, 44, "Much later."], ] as const) .map(([a, b, t]) => `${ts(a)} --> ${ts(b)}\n${t}\n`) .join("\n"), ); test("cuesAround: the record's cues in a window, and its title; a bad id or no record is null", async () => { const got = await cuesAround("synth-hand", "rec1", 13, 19, { channelsDir }); assert.equal(got?.title, "Synthetic stream"); assert.deepEqual(got?.cues.map((c) => c.start), [10, 14, 18]); assert.equal(await cuesAround("synth-hand", "../x", 0, 10, { channelsDir }), null); assert.equal(await cuesAround("synth-hand", "nope", 0, 10, { channelsDir }), null); });