import { test } from "node:test"; import assert from "node:assert/strict"; import { createHash } from "node:crypto"; import { lstat, mkdir, mkdtemp, readdir, readFile, readlink, rm, stat, utimes, writeFile } from "node:fs/promises"; import { tmpdir } from "node:os"; import { rmSync } from "node:fs"; import path from "node:path"; // Run with: // pnpm --filter yt-dlp-transcript-common exec tsx --test controller/compressText.captions.test.ts // // THE MIGRATION OVER CAPTIONS (lane text-compress-captions, slice 5): // `compress-text {kinds: ["captions"]}` over a temp corpus — a dry run that // touches nothing and counts the equal-size en / en-orig pairs, a real run, // its limit, the refusals (two forms of different content listed and both // kept, a recent file, a `.part`, a recording), every kill point finished by // the job, the check, and the restore. The live chat is left alone unless it // is asked for, and captions unless they are. Synthetic names only. const ROOT = await mkdtemp(path.join(tmpdir(), "compress-captions-")); process.env.TRANSCRIPTS_DIR = path.join(ROOT, "transcripts"); process.env.SETTINGS_FILE = path.join(ROOT, "settings.json"); await mkdir(process.env.TRANSCRIPTS_DIR, { recursive: true }); await writeFile(process.env.SETTINGS_FILE, "{}"); test.after(() => rm(ROOT, { recursive: true, force: true })); const { getPaths } = await import("../lib/paths"); const { compressText } = await import("./compressText"); const { readStoredText } = await import("../lib/storedText-server"); const { CompressKill } = await import("../lib/storedText-write-server"); const paths = getPaths(); const CAPTIONS = ["captions"] as const; const vtt = (seed: string, cues: number) => "WEBVTT\nKind: captions\nLanguage: en\n\n" + Array.from({ length: cues }, (_, i) => { const s = String(i).padStart(2, "0"); return `00:00:${s}.000 --> 00:00:${s}.900 align:start position:0%\n${seed} ${i} ${createHash("md5").update(seed + i).digest("hex")}\n`; }).join("\n"); const CHAT = "transcript.live_chat.json"; const OLD = 1_700_000_000; type Videos = Record>; async function channel(slug: string, videos: Videos): Promise { const channelDir = path.join(paths.channelsDir, slug); await mkdir(path.join(channelDir, "data"), { recursive: true }); await writeFile(path.join(channelDir, "config.json"), JSON.stringify({ handling: "youtube", url: `https://www.youtube.com/@${slug}` })); for (const [id, files] of Object.entries(videos)) { const dir = path.join(channelDir, "data", id); await mkdir(dir, { recursive: true }); await writeFile(path.join(dir, "metadata.info.json"), JSON.stringify({ id })); for (const [name, text] of Object.entries(files)) { await writeFile(path.join(dir, name), text); // Old enough for the quiet period; sub-millisecond times. await utimes(path.join(dir, name), OLD, OLD + 0.123457); } } } const dirOf = (slug: string, id: string) => path.join(paths.channelsDir, slug, "data", id); const names = async (slug: string, id: string) => (await readdir(dirOf(slug, id))).sort(); const leftovers = async (slug: string, id: string) => (await readdir(dirOf(slug, id))).filter((e) => e.startsWith(".")); async function tree(dir: string): Promise { const out: string[] = []; async function walk(d: string): Promise { for (const e of (await readdir(d).catch(() => [] as string[])).sort()) { const p = path.join(d, e); const l = await lstat(p); if (l.isSymbolicLink()) out.push(`${p} -> ${await readlink(p)} ${l.mtimeMs}`); else if (l.isDirectory()) { out.push(`${p}/ ${l.mtimeMs}`); await walk(p); } else out.push(`${p} ${l.size} ${l.mtimeMs} ${createHash("sha256").update(await readFile(p)).digest("hex")}`); } } await walk(dir); return out; } const PAIR = vtt("pair", 40); const A: Videos = { a1: { "transcript.en.vtt": PAIR, "transcript.en-orig.vtt": PAIR, "transcript.es.vtt": vtt("es", 30) }, a2: { "transcript.en.vtt": vtt("served", 20), "transcript.en-orig.vtt": vtt("spoken", 25), [CHAT]: '{"replayChatItemAction":{}}\n'.repeat(50) }, }; await channel("alpha", A); test("a dry run over captions: per channel and kind, ~20 %, the equal-size pairs — and touches NOTHING", async () => { const before = await tree(ROOT); const lines: string[] = []; const r = await compressText({ paths, slugs: ["alpha"], kinds: CAPTIONS, dryRun: true, onLog: (l) => lines.push(l) }); assert.deepEqual(await tree(ROOT), before, "not one entry changed, not one mtime"); assert.deepEqual(r.kinds, ["captions"]); const alpha = r.channels[0]; const c = alpha.byKind!.captions!; assert.equal(c.plainFiles, 5); const bytes = Object.values(A).flatMap((v) => Object.entries(v)).filter(([n]) => n.endsWith(".vtt")).reduce((a, [, t]) => a + t.length, 0); assert.equal(c.plainBytes, bytes); assert.equal(c.estimateAfterBytes, Math.round(bytes * 0.2)); assert.equal(c.pairsEqualSize, 1, "a1's pair; a2's differ in size"); assert.equal(c.pairsEqualSizeBytes, PAIR.length); assert.equal(alpha.byKind!["live-chat"], undefined, "the chat is not asked"); assert.equal(alpha.plainFiles, 5, "the channel's totals are the kinds asked"); assert.match(lines.join(""), /caption file\(s\).*estimate, 20 %.*en \/ en-orig pairs of equal size: 1/); assert.match(lines.join(""), /Nothing was written/); // And with no kinds: the live chat alone, as before captions were a kind. const chatOnly = await compressText({ paths, slugs: ["alpha"], dryRun: true, onLog: () => {} }); assert.deepEqual(chatOnly.kinds, ["live-chat"]); assert.equal(chatOnly.channels[0].plainFiles, 1); }); test("a real run: every caption compressed, read back the same, with the same times; the chat untouched; a limit; a re-run", async () => { const mt = async (id: string, n: string) => (await stat(path.join(dirOf("alpha", id), n))).mtimeMs; const times: Record = {}; for (const [id, files] of Object.entries(A)) for (const n of Object.keys(files)) times[`${id}/${n}`] = await mt(id, n); const first = await compressText({ paths, slugs: ["alpha"], kinds: CAPTIONS, quietMs: 0, limit: 2, onLog: () => {} }); assert.equal(first.stopped, "limit"); assert.equal(first.channels[0].compressed, 2); const rest = await compressText({ paths, slugs: ["alpha"], kinds: CAPTIONS, quietMs: 0, onLog: () => {} }); assert.equal(rest.channels[0].compressed, 3); assert.equal(rest.channels[0].already, 2); for (const [id, files] of Object.entries(A)) { for (const [n, text] of Object.entries(files)) { if (n === CHAT) continue; assert.equal(await readStoredText(dirOf("alpha", id), n, "utf8"), text, `${id}/${n}`); assert.equal(await mt(id, `${n}.zst`), times[`${id}/${n}`], `${id}/${n}: the same mtimeMs`); } } assert.deepEqual(await names("alpha", "a1"), ["metadata.info.json", "transcript.en-orig.vtt.zst", "transcript.en.vtt.zst", "transcript.es.vtt.zst"]); assert.ok((await names("alpha", "a2")).includes(CHAT), "the chat is not a caption: left as it was"); const again = await compressText({ paths, slugs: ["alpha"], kinds: CAPTIONS, quietMs: 0, onLog: () => {} }); assert.equal(again.channels[0].compressed, 0); const check = await compressText({ paths, slugs: ["alpha"], kinds: CAPTIONS, verify: true, onLog: () => {} }); assert.equal(check.channels[0].verified, 5); assert.deepEqual(check.channels[0].problems, []); }); test("two forms of DIFFERENT content: refused, both kept, and listed — nothing removes a stored copy because another arrived", async () => { await channel("beta", { b1: { "transcript.en.vtt": vtt("old", 20) } }); await compressText({ paths, slugs: ["beta"], kinds: CAPTIONS, quietMs: 0, onLog: () => {} }); // A re-fetch (or Set as transcript) lands a new plain file beside it. await writeFile(path.join(dirOf("beta", "b1"), "transcript.en.vtt"), vtt("new", 21)); await utimes(path.join(dirOf("beta", "b1"), "transcript.en.vtt"), OLD, OLD); const lines: string[] = []; const r = await compressText({ paths, slugs: ["beta"], kinds: CAPTIONS, quietMs: 0, onLog: (l) => lines.push(l) }); const c = r.channels[0].byKind!.captions!; assert.equal(c.compressed, 0); assert.deepEqual(c.refused?.map((x) => [x.id, x.name, x.reason]), [["b1", "transcript.en.vtt", "both-differ"]]); assert.match(lines.join(""), /b1\/transcript\.en\.vtt: refused — both-differ.*both files are kept/); assert.match(lines.join(""), /1 refused with both forms kept/); assert.deepEqual(await names("beta", "b1"), ["metadata.info.json", "transcript.en.vtt", "transcript.en.vtt.zst"]); assert.equal(await readStoredText(dirOf("beta", "b1"), "transcript.en.vtt", "utf8"), vtt("new", 21), "plain is the truth"); const check = await compressText({ paths, slugs: ["beta"], kinds: CAPTIONS, verify: true, onLog: () => {} }); assert.deepEqual(check.channels[0].problems?.map((p) => p.status), ["differs"]); }); test("left alone and counted: a recent file, a `.part` beside it, a video recording", async () => { await channel("gamma", { g1: { "transcript.en.vtt": vtt("recent", 10) }, g2: { "transcript.en.vtt": vtt("partial", 10), "transcript.es.vtt.part": "half" }, g3: { "transcript.en.vtt": vtt("live", 10), "live-recording.json": JSON.stringify({ status: "recording" }) }, g4: { "transcript.en.vtt": vtt("refetch", 10), "transcript.en.vtt.part": "a download of the same track" }, }); // The quiet period asks the later of mtime and ctime: every file here was // just made (ctime now), so the run's clock is 20 minutes on, and g1's // mtime 15 minutes on — written 5 minutes before the run, by its clock. const t0 = Date.now(); await utimes(path.join(dirOf("gamma", "g1"), "transcript.en.vtt"), (t0 + 15 * 60_000) / 1000, (t0 + 15 * 60_000) / 1000); const r = await compressText({ paths, slugs: ["gamma"], kinds: CAPTIONS, now: () => t0 + 20 * 60_000, onLog: () => {} }); const c = r.channels[0].byKind!.captions!; assert.equal(c.compressed, 1, "g2's en track only"); assert.deepEqual(c.skipped, { recent: 1, recording: 1, partial: 1 }); // The `.part` is of another track: the en track itself is not partial, and // the es one has no plain form (only its partial): nothing to compress. assert.equal((await names("gamma", "g2")).includes("transcript.en.vtt.zst"), true); for (const id of ["g1", "g3", "g4"]) assert.equal((await names("gamma", id)).includes("transcript.en.vtt"), true, id); }); const killAt = (point: string) => (p: string) => { if (p === point) throw new CompressKill(p as never); }; test("every kill point, then a job run: a whole copy at each point, and the job finishes it", async () => { const points = ["compressing", "written", "verified", "placed", "retired"] as const; // One channel per point: a run over a channel would first finish a video an // earlier point left, and stop there. for (const p of points) { const slug = `delta-${p}`; await channel(slug, { k1: { "transcript.en-orig.vtt": vtt(p, 30) } }); await assert.rejects( compressText({ paths, slugs: [slug], kinds: CAPTIONS, quietMs: 0, onLog: () => {}, compressOpts: { pid: 999_999_990, crashAt: killAt(p) } }), CompressKill, p, ); // A whole copy, readable, whatever was left. assert.equal(await readStoredText(dirOf(slug, "k1"), "transcript.en-orig.vtt", "utf8"), vtt(p, 30), `${p}: read back`); if (p === "retired") { assert.ok(!(await names(slug, "k1")).includes("transcript.en-orig.vtt"), "retired: the plain name is absent"); assert.equal((await leftovers(slug, "k1")).length, 1, "the set-aside original"); } // The job's survey sees the file as work, whatever the point. const plan = await compressText({ paths, slugs: [slug], kinds: CAPTIONS, dryRun: true, onLog: () => {} }); assert.equal(plan.channels[0].pending, 1, `${p}: work for the job`); const r = await compressText({ paths, slugs: [slug], kinds: CAPTIONS, quietMs: 0, onLog: () => {} }); assert.deepEqual(r.channels[0].failed, [], p); assert.deepEqual(await leftovers(slug, "k1"), [], `${p}: no leftover`); assert.deepEqual(await names(slug, "k1"), ["metadata.info.json", "transcript.en-orig.vtt.zst"], p); assert.equal(await readStoredText(dirOf(slug, "k1"), "transcript.en-orig.vtt", "utf8"), vtt(p, 30), p); } }); test("restore over captions: the dry run is exact and touches nothing; a restore, killed, re-run — the plain files with their times", async () => { await channel("eta", { h1: { "transcript.en.vtt": vtt("h1", 30), "transcript.de.vtt": vtt("de", 12) } }); const before: Record = {}; for (const n of ["transcript.en.vtt", "transcript.de.vtt"]) before[n] = (await stat(path.join(dirOf("eta", "h1"), n))).mtimeMs; await compressText({ paths, slugs: ["eta"], kinds: CAPTIONS, quietMs: 0, onLog: () => {} }); const tr = await tree(dirOf("eta", "h1")); const plan = await compressText({ paths, slugs: ["eta"], kinds: CAPTIONS, restore: true, dryRun: true, onLog: () => {} }); assert.deepEqual(await tree(dirOf("eta", "h1")), tr); assert.equal(plan.channels[0].estimateAfterBytes, vtt("h1", 30).length + vtt("de", 12).length); await assert.rejects( compressText({ paths, slugs: ["eta"], kinds: CAPTIONS, restore: true, onLog: () => {}, compressOpts: { pid: 999_999_991, crashAt: killAt("restore-placed") } }), CompressKill, ); const r = await compressText({ paths, slugs: ["eta"], kinds: CAPTIONS, restore: true, onLog: () => {} }); assert.ok((r.channels[0].restored ?? 0) >= 1); assert.deepEqual(await names("eta", "h1"), ["metadata.info.json", "transcript.de.vtt", "transcript.en.vtt"]); for (const n of ["transcript.en.vtt", "transcript.de.vtt"]) { assert.equal((await stat(path.join(dirOf("eta", "h1"), n))).mtimeMs, before[n], `${n}: the index key`); } assert.equal(await readFile(path.join(dirOf("eta", "h1"), "transcript.en.vtt"), "utf8"), vtt("h1", 30)); }); test("both kinds: the live chat first, then the captions — each counted under its own kind", async () => { await channel("theta", { t1: { "transcript.en.vtt": vtt("t1", 10), [CHAT]: '{"replayChatItemAction":{}}\n'.repeat(80) } }); const lines: string[] = []; const r = await compressText({ paths, slugs: ["theta"], kinds: ["captions", "live-chat"], quietMs: 0, onLog: (l) => lines.push(l) }); assert.deepEqual(r.kinds, ["live-chat", "captions"], "the walk's order whatever was asked"); assert.equal(r.channels[0].byKind!["live-chat"]!.compressed, 1); assert.equal(r.channels[0].byKind!.captions!.compressed, 1); assert.equal(r.channels[0].compressed, 2); const text = lines.join(""); assert.ok(text.indexOf("[live-chat]") < text.indexOf("[captions]"), text); assert.deepEqual(await names("theta", "t1"), ["metadata.info.json", "transcript.en.vtt.zst", `${CHAT}.zst`]); }); test("a caption that is a link into media/ (none on this corpus: the classifier never tiers one) is handled like a tiered chat", async () => { const { symlink } = await import("node:fs/promises"); await channel("iota", { i1: {} }); const channelDir = path.join(paths.channelsDir, "iota"); await mkdir(path.join(channelDir, "media", "i1"), { recursive: true }); await writeFile(path.join(channelDir, "media", "i1", "transcript.en.vtt"), vtt("linked", 15)); await symlink(path.join("..", "..", "media", "i1", "transcript.en.vtt"), path.join(dirOf("iota", "i1"), "transcript.en.vtt")); const r = await compressText({ paths, slugs: ["iota"], kinds: CAPTIONS, quietMs: 0, onLog: () => {} }); assert.equal(r.channels[0].compressed, 1); // The stored bytes beside the original's, on the same drive, with a link of their own. assert.deepEqual(await readdir(path.join(channelDir, "media", "i1")), ["transcript.en.vtt.zst"]); assert.equal(await readlink(path.join(dirOf("iota", "i1"), "transcript.en.vtt.zst")), path.join("..", "..", "media", "i1", "transcript.en.vtt.zst")); assert.equal(await readStoredText(dirOf("iota", "i1"), "transcript.en.vtt", "utf8"), vtt("linked", 15)); }); // REVIEW-1 F2: A DELETED CAPTION NEVER COMES BACK FROM A STOPPED RUN'S // SET-ASIDE. A run killed at "retired" leaves the stored form and // `.transcript.en.vtt.retire--` (the whole original). Every // deleter removes the set-aside with the forms; and a set-aside found with NO // stored form beside it (a deletion some other way) is not adopted: kept, // listed for a person. test("killed at retired, then the caption deleted by each deleter: the next captions run leaves it deleted", async () => { const { purgeSupersededAutoSubs } = await import("./purgeSupersededAutoSubs"); const { removeStoredText, removeStoredTextForm } = await import("../lib/storedText-write-server"); const ASR = "WEBVTT\nKind: captions\nLanguage: en\n\n00:00:00.000 --> 00:00:05.000 align:start position:0%\n" + "First<00:00:01.000> caption\n\n00:01:00.000 --> 00:01:50.000 align:start position:0%\n" + "Second<00:01:10.000> caption\n"; const deleters: Record Promise> = { purge: (_dir, slug) => purgeSupersededAutoSubs({ channelSlug: slug, paths, onLog: () => {} }), "removeStoredText (the clear-transcript fix)": (dir) => removeStoredText(dir, "transcript.en.vtt"), "the files card (the stored form)": (dir) => removeStoredTextForm(dir, "transcript.en.vtt.zst"), }; let n = 0; for (const [who, del] of Object.entries(deleters)) { const slug = `kappa-${n++}`; await channel(slug, { k1: { "transcript.en.vtt": ASR, "transcript.json": JSON.stringify({ transcription: [{ text: "ours" }] }) } }); await assert.rejects( compressText({ paths, slugs: [slug], kinds: CAPTIONS, quietMs: 0, onLog: () => {}, compressOpts: { pid: 999_999_989, crashAt: killAt("retired") } }), CompressKill, ); assert.equal((await leftovers(slug, "k1")).length, 1, `${who}: the set-aside is there`); await del(dirOf(slug, "k1"), slug); assert.deepEqual(await leftovers(slug, "k1"), [], `${who}: the deleter took the set-aside too`); await compressText({ paths, slugs: [slug], kinds: CAPTIONS, quietMs: 0, onLog: () => {} }); assert.deepEqual( (await names(slug, "k1")).filter((f) => f.includes(".vtt")), [], `${who}: still deleted, in every form`, ); } }); test("a set-aside with no stored form beside it (deleted some other way) is NOT adopted: kept, listed for a person", async () => { await channel("lambda", { l1: { "transcript.en.vtt": vtt("l1", 20) } }); await assert.rejects( compressText({ paths, slugs: ["lambda"], kinds: CAPTIONS, quietMs: 0, onLog: () => {}, compressOpts: { pid: 999_999_988, crashAt: killAt("retired") } }), CompressKill, ); // Deleted by hand: the stored form only (the set-aside left). await rm(path.join(dirOf("lambda", "l1"), "transcript.en.vtt.zst")); const lines: string[] = []; const r = await compressText({ paths, slugs: ["lambda"], kinds: CAPTIONS, quietMs: 0, onLog: (l) => lines.push(l) }); const c = r.channels[0].byKind!.captions!; assert.deepEqual(c.refused?.map((x) => [x.name, x.reason]), [["transcript.en.vtt", "retired-kept"]]); assert.match(lines.join(""), /not adopted \(no stored form\)/); assert.equal((await names("lambda", "l1")).includes("transcript.en.vtt"), false, "not brought back"); assert.equal((await leftovers("lambda", "l1")).length, 1, "kept for a person"); }); // REVIEW-1 N2: a pair refused once is recorded — the next run's survey counts // it as waiting for a person (listed once by the dry run), not as work, and // it is work again as soon as either form changes. test("both forms differ: refused ONCE and recorded; later runs list it as waiting, not work, until a form changes", async () => { await channel("mu", { m1: { "transcript.en.vtt": vtt("old", 20) } }); await compressText({ paths, slugs: ["mu"], kinds: CAPTIONS, quietMs: 0, onLog: () => {} }); await writeFile(path.join(dirOf("mu", "m1"), "transcript.en.vtt"), vtt("new", 21)); await utimes(path.join(dirOf("mu", "m1"), "transcript.en.vtt"), OLD, OLD); const first = await compressText({ paths, slugs: ["mu"], kinds: CAPTIONS, quietMs: 0, onLog: () => {} }); assert.equal(first.channels[0].byKind!.captions!.refused?.length, 1); const plan = await compressText({ paths, slugs: ["mu"], kinds: CAPTIONS, dryRun: true, onLog: () => {} }); assert.equal(plan.channels[0].pending, 0, "not work: the job is not started for it"); assert.deepEqual(plan.channels[0].byKind!.captions!.differs, [{ id: "m1", name: "transcript.en.vtt" }]); assert.match(plan.lines.join("\n"), /both forms differ, waiting for a person \(settle on the files card\): 1 — m1\/transcript\.en\.vtt/); const lines: string[] = []; const again = await compressText({ paths, slugs: ["mu"], kinds: CAPTIONS, quietMs: 0, onLog: (l) => lines.push(l) }); assert.equal(again.channels[0].byKind!.captions!.refused?.length, 0, "not refused again"); assert.match(lines.join(""), /1 with both forms differing still wait for a person/); // A person settles it (the older stored copy deleted): work again — compressed. await rm(path.join(dirOf("mu", "m1"), "transcript.en.vtt.zst")); const settled = await compressText({ paths, slugs: ["mu"], kinds: CAPTIONS, quietMs: 0, onLog: () => {} }); assert.equal(settled.channels[0].compressed, 1); assert.equal(await readStoredText(dirOf("mu", "m1"), "transcript.en.vtt", "utf8"), vtt("new", 21)); }); // REVIEW-2 N3: the original removed OUTSIDE the lock between the compressor's // last look and its set-aside — yt-dlp's own overwrite deletes the plain // caption and fetches after. The verified stored copy is KEPT: if the fetch // fails it is the caption. test("the original vanishes just before its set-aside (yt-dlp's overwrite): the verified stored copy is kept", async () => { await channel("nu", { n1: { "transcript.en.vtt": vtt("n1", 20) } }); const plain = path.join(dirOf("nu", "n1"), "transcript.en.vtt"); const lines: string[] = []; const r = await compressText({ paths, slugs: ["nu"], kinds: CAPTIONS, quietMs: 0, onLog: (l) => lines.push(l), compressOpts: { crashAt: (p) => { if (p === "placed") rmSync(plain); }, }, }); assert.equal(r.channels[0].byKind!.captions!.changed, 1); assert.deepEqual(await names("nu", "n1"), ["metadata.info.json", "transcript.en.vtt.zst"]); assert.equal(await readStoredText(dirOf("nu", "n1"), "transcript.en.vtt", "utf8"), vtt("n1", 20)); assert.match(lines.join(""), /was removed while it was being compressed: the verified stored copy is kept/); }); // REVIEW-2 N2: a deleter that cannot make the file's lock (a full disk, a // read-only dir) REFUSES, removes nothing, throws nothing, leaves no temp. test("a deleter that cannot make its lock refuses: nothing removed, no throw, no lock temp left", async () => { const { chmod } = await import("node:fs/promises"); const { removeStoredText, removeStoredTextForm } = await import("../lib/storedText-write-server"); const { purgeSupersededAutoSubs } = await import("./purgeSupersededAutoSubs"); const ASR = "WEBVTT\nKind: captions\nLanguage: en\n\n00:00:00.000 --> 00:00:05.000 align:start position:0%\n" + "First<00:00:01.000> caption\n\n00:01:00.000 --> 00:01:50.000 align:start position:0%\n" + "Second<00:01:10.000> caption\n"; await channel("xi", { x1: { "transcript.en.vtt": ASR, "transcript.json": JSON.stringify({ transcription: [{ text: "ours" }] }) } }); await compressText({ paths, slugs: ["xi"], kinds: CAPTIONS, quietMs: 0, onLog: () => {} }); const d = dirOf("xi", "x1"); const before = await names("xi", "x1"); await chmod(d, 0o555); try { const a = await removeStoredText(d, "transcript.en.vtt"); assert.ok("refused" in a && /not deleted: the stored-text lock cannot be made/.test(a.refused), JSON.stringify(a)); const b = await removeStoredTextForm(d, "transcript.en.vtt.zst"); assert.ok(typeof b === "object" && "refused" in b, JSON.stringify(b)); const logs: string[] = []; const p = await purgeSupersededAutoSubs({ channelSlug: "xi", paths, onLog: (m) => logs.push(m) }); assert.equal(p.removedFiles, 0); assert.match(logs.join("\n"), /Kept x1\/transcript\.en\.vtt — transcript\.en\.vtt not deleted/); } finally { await chmod(d, 0o755); } assert.deepEqual(await names("xi", "x1"), before, "nothing removed, no lock temp left"); });