import { test } from "node:test"; import assert from "node:assert/strict"; import { access, mkdir, mkdtemp, readFile, rm, symlink, writeFile } from "node:fs/promises"; import { tmpdir } from "node:os"; import path from "node:path"; import type { Paths } from "../lib/paths"; import { cleanAudioForVideo, cleanAudioFromTranscribed, planAudioClean, } from "./cleanAudioFromTranscribed"; import type { VerifyProbes } from "./verifyBeforeClean"; import type { CheckRequestDeps } from "./availabilityVerdict"; import { runCleanAudioJob, uncheckedReasonFor } from "./cleanAudioJob"; import { parseChannelConfig } from "../lib/channelConfig"; import { channelConfigSchema } from "../lib/channelConfigSchema"; import { EnumerationIncompleteError } from "../ytdlp/runYtdlp"; import { loadSavedVideo, persistSourceVideo } from "../lib/savedVideo-server"; import { createChannel, readChannelConfig } from "./channels"; // Run with: // pnpm --filter yt-dlp-transcript-common exec tsx --test controller/cleanUnchecked.test.ts // // CLEAN WITHOUT CHECKING (lane clean-unverified). The availability verdict is // the ONE gate skipped; every other protection holds. Temp corpus, temp // settings; every probe is a stub that throws, so a test that reaches the // network fails loudly — and each asserts its probe was never called. const ROOT = await mkdtemp(path.join(tmpdir(), "clean-unchecked-")); process.env.SETTINGS_FILE = path.join(ROOT, "settings.json"); process.env.E2E_AVAILABILITY_PROBE_GAP_MS = "0"; async function settings(diarization: Record, over: Record = {}) { await writeFile( process.env.SETTINGS_FILE!, JSON.stringify({ verifyAvailabilityBeforeClean: true, diarization: { enabled: true, segModel: "/m/seg.onnx", embModel: "/m/emb.onnx", ...diarization }, ...over, }), ); } const VOICEPRINTS = [{ speaker: 0, seconds: 4, embedded: 1, centroid: Array.from({ length: 192 }, (_, i) => (i === 0 ? 1 : 0)), embeddingModel: "emb.onnx" }]; function sidecar(voiceprints: boolean): string { return JSON.stringify({ videoId: "v", generatedAt: "2026-08-07T00:00:00.000Z", speakers: 1, turns: [{ start: 0, end: 4, speaker: 0 }], engine: { engine: "sherpa-onnx", segmentationModel: "seg.onnx", embeddingModel: "emb.onnx", threshold: 0.9 }, ...(voiceprints ? { voiceprints: VOICEPRINTS } : {}), }); } // Probes that count their calls and throw — the source "rate-limits" every ask. function throwingProbes() { const calls = { quick: 0, full: 0, backoff: 0 }; const probes: VerifyProbes = { quick: async () => { calls.quick++; throw new Error("HTTP Error 429: Too Many Requests"); }, full: async () => { calls.full++; throw new Error("HTTP Error 429: Too Many Requests"); }, recordBackoff: async () => { calls.backoff++; }, }; return { calls, probes }; } const NO_CHECK: CheckRequestDeps = { start: async () => { throw new Error("a test asked for a real availability check"); }, platformRefusal: async () => null, serviceAlert: async () => null, }; let n = 0; async function corpus(config: Record = {}) { const dir = path.join(ROOT, `c${n++}`); const paths = { channelsDir: path.join(dir, "channels"), transcriptsDir: dir, savedVideosDir: path.join(dir, "saved"), ytdlpBin: path.join(dir, "no-such-ytdlp"), } as unknown as Paths; await mkdir(path.join(paths.channelsDir, "ch", "data"), { recursive: true }); await writeFile( path.join(paths.channelsDir, "ch", "config.json"), JSON.stringify({ handling: "transcribe", name: "ch", url: "https://www.twitch.tv/example", ...config }), ); const video = async ( id: string, o: { transcript?: boolean; diarization?: "plain" | "voiceprints"; doNotClean?: boolean; gone?: boolean; bytes?: number; uploadDate?: string; } = {}, ) => { const v = path.join(paths.channelsDir, "ch", "data", id); await mkdir(v, { recursive: true }); if (o.uploadDate) await writeFile(path.join(v, "metadata.info.json"), JSON.stringify({ id, upload_date: o.uploadDate })); if (o.transcript !== false) await writeFile(path.join(v, "transcript.json"), "{}"); await writeFile(path.join(v, "audio.mp3"), Buffer.alloc(o.bytes ?? 1000)); if (o.diarization === "plain") await writeFile(path.join(v, "diarization.json"), sidecar(false)); if (o.diarization === "voiceprints") await writeFile(path.join(v, "diarization.json"), sidecar(true)); if (o.doNotClean) { await writeFile(path.join(v, "do-not-clean.json"), JSON.stringify({ setAt: "now", note: "deleted from source (pre-clean check): deleted" })); } if (o.gone) { await writeFile(path.join(v, "availability.json"), JSON.stringify({ checkedAt: new Date().toISOString(), availability: "deleted" })); } return v; }; return { paths, video }; } const exists = (f: string) => access(f).then(() => true, () => false); async function seed(video: Awaited>["video"]) { return { expired: await video("expired", { diarization: "voiceprints", gone: true, bytes: 3000 }), plain: await video("listed", { diarization: "voiceprints", bytes: 2000 }), pinned: await video("pinned", { diarization: "voiceprints", doNotClean: true }), noprint: await video("noprint", { diarization: "plain" }), nodiar: await video("nodiar"), untranscribed: await video("untranscribed", { transcript: false, diarization: "voiceprints" }), }; } test("unchecked: removes transcribed audio though every probe would throw, asks none, keeps every other protection", async () => { await settings({}); const { paths, video } = await corpus(); const v = await seed(video); const { calls, probes } = throwingProbes(); const logs: string[] = []; const r = await cleanAudioFromTranscribed({ channelSlug: "ch", paths, onLog: (m) => logs.push(m), unchecked: "button", probes }); assert.deepEqual(calls, { quick: 0, full: 0, backoff: 0 }, "the source was never asked"); // Gone from source and expired VODs go too: that is what was asked for. assert.equal(await exists(path.join(v.expired, "audio.mp3")), false); assert.equal(await exists(path.join(v.plain, "audio.mp3")), false); assert.equal(await exists(path.join(v.expired, "do-not-clean.json")), false, "no pin written"); // Every other protection holds. assert.equal(await exists(path.join(v.pinned, "audio.mp3")), true, "do-not-clean"); assert.equal(await exists(path.join(v.noprint, "audio.mp3")), true, "awaiting voice fingerprint"); assert.equal(await exists(path.join(v.nodiar, "audio.mp3")), true, "awaiting diarization"); assert.equal(await exists(path.join(v.untranscribed, "audio.mp3")), true, "not transcribed"); assert.equal(r.cleanedDirs, 2); assert.equal(r.bytesFreed, 5000); assert.equal(r.unverified, 0); assert.equal(r.pinned, 0); assert.equal(r.stopped, undefined); assert.ok(logs[0]?.startsWith("Clean without checking:"), logs.join("\n")); }); test("the dry plan counts exactly what the unchecked clean removes, and asks nothing", async () => { await settings({}); const { paths, video } = await corpus(); const v = await seed(video); const plan = await planAudioClean({ channelSlug: "ch", paths }); assert.deepEqual(plan, { inspected: 6, ids: ["expired", "listed"], videos: 2, files: 2, bytes: 5000, protected: 1, awaitingDiarization: 1, awaitingVoiceprint: 1, // The pinned video's mark carries the gate's note but no `by` (written // before marks said who set them): the operator's, never in the opt-in's // group (lane mark-provenance). sourceGone: { ids: [], videos: 0, files: 0, bytes: 0, inferred: { ids: [], videos: 0, files: 0, bytes: 0 } }, }); // Nothing was deleted by the plan. assert.equal(await exists(path.join(v.plain, "audio.mp3")), true); const { probes } = throwingProbes(); const r = await cleanAudioFromTranscribed({ channelSlug: "ch", paths, onLog: () => {}, unchecked: "button", probes }); assert.equal(r.removedFiles, plan.files); assert.equal(r.bytesFreed, plan.bytes); assert.equal(r.cleanedDirs, plan.videos); }); test("checked: unchanged — the same gate runs, pins the gone, cleans the listed, and logs as before", async () => { await settings({}); const { paths, video } = await corpus(); const v = await seed(video); let quick = 0; const probes: VerifyProbes = { quick: async () => { quick++; return { knownCount: 6, freshCount: 6, maybeMissingCount: 0, ids: [] }; }, full: async () => { throw new Error("no suspects: tier C is not reached"); }, }; const logs: string[] = []; const r = await cleanAudioFromTranscribed({ channelSlug: "ch", paths, onLog: (m) => logs.push(m), probes }); assert.equal(quick, 1); assert.equal(await exists(path.join(v.expired, "audio.mp3")), true, "tier A pins the cached gone"); assert.equal(await exists(path.join(v.expired, "do-not-clean.json")), true); assert.equal(await exists(path.join(v.plain, "audio.mp3")), false); assert.equal(r.pinned, 1); assert.equal(r.stopped, undefined); assert.ok(!logs.some((l) => l.includes("without checking")), logs.join("\n")); assert.ok(logs.includes("Verify before clean: all 1 candidate(s) still listed on the source."), logs.join("\n")); assert.ok( logs.includes( "Cleaned 1 audio file(s) from 1 of 6 video dir(s). Skipped 4 (1 protected, 1 gone-from-source pinned, 0 unverified, 1 awaiting diarization, 1 awaiting voice fingerprint).", ), logs.join("\n"), ); }); test("checked: a rate-limited listing cleans nothing unverified and says why it stopped", async () => { await settings({}); const { paths, video } = await corpus(); const v = await seed(video); const { calls, probes } = throwingProbes(); // A rate-limited listing is what runYtdlp throws for a 429 on it. probes.quick = async () => { calls.quick++; throw new EnumerationIncompleteError(1, "twitch", null, 0); }; const r = await cleanAudioFromTranscribed({ channelSlug: "ch", paths, onLog: () => {}, probes }); assert.equal(calls.quick, 1); assert.equal(calls.backoff, 1, "the platform cooldown is recorded, as Sync does"); assert.equal(r.cleanedDirs, 0); assert.equal(await exists(path.join(v.plain, "audio.mp3")), true); assert.deepEqual(r.stopped && { kind: r.stopped.kind, platform: r.stopped.platform }, { kind: "rate-limit", platform: "twitch" }); }); test("checked: a listing that fails for another reason is an error stop, not a rate limit, and records no cooldown", async () => { await settings({}); const { paths, video } = await corpus(); await seed(video); const { calls, probes } = throwingProbes(); probes.quick = async () => { calls.quick++; throw new Error("yt-dlp exited with code 1"); }; const r = await cleanAudioFromTranscribed({ channelSlug: "ch", paths, onLog: () => {}, probes }); assert.equal(r.cleanedDirs, 0); assert.equal(r.stopped?.kind, "error"); assert.equal(calls.backoff, 0); }); test("the channel key: absent = checked (no reason), true = unchecked by the channel setting", () => { assert.equal(uncheckedReasonFor(parseChannelConfig({ handling: "transcribe", name: "a" })), undefined); assert.equal(uncheckedReasonFor(parseChannelConfig({ handling: "transcribe", name: "a", cleanAudioWithoutChecking: false })), undefined); assert.equal(uncheckedReasonFor(parseChannelConfig({ handling: "transcribe", name: "a", cleanAudioWithoutChecking: true })), "channel-setting"); assert.equal(uncheckedReasonFor(null), undefined); // The schema keeps it (true) and omits anything else. assert.equal(channelConfigSchema.parse({ handling: "transcribe", cleanAudioWithoutChecking: true })?.cleanAudioWithoutChecking, true); assert.equal("cleanAudioWithoutChecking" in (channelConfigSchema.parse({ handling: "transcribe", cleanAudioWithoutChecking: "yes" }) ?? {}), false); }); test("key on: the sweep the action runs asks nothing and keeps the protections", async () => { await settings({}); const { paths, video } = await corpus({ cleanAudioWithoutChecking: true }); const v = await seed(video); const config = JSON.parse(await readFile(path.join(paths.channelsDir, "ch", "config.json"), "utf8")); const { calls, probes } = throwingProbes(); const r = await cleanAudioFromTranscribed({ channelSlug: "ch", paths, onLog: () => {}, unchecked: uncheckedReasonFor(parseChannelConfig(config)), probes, }); assert.deepEqual(calls, { quick: 0, full: 0, backoff: 0 }); assert.equal(r.cleanedDirs, 2); assert.equal(await exists(path.join(v.pinned, "audio.mp3")), true); assert.equal(await exists(path.join(v.noprint, "audio.mp3")), true); assert.equal(await exists(path.join(v.untranscribed, "audio.mp3")), true); }); test("key on: clean after capture asks no check, reads no verdict, and cleans an expired VOD — protections still hold", async () => { await settings({}); const { paths, video } = await corpus({ cleanAudioWithoutChecking: true }); const v = await seed(video); const logs: string[] = []; const one = (id: string) => cleanAudioForVideo({ channelSlug: "ch", paths, videoId: id, onLog: (m) => logs.push(m), checkDeps: NO_CHECK }); assert.equal((await one("expired")).outcome, "cleaned"); assert.equal(await exists(path.join(v.expired, "audio.mp3")), false); assert.equal((await one("listed")).outcome, "cleaned"); assert.equal((await one("pinned")).gate, "do-not-clean"); assert.equal((await one("noprint")).gate, "awaiting-voiceprint"); assert.equal((await one("untranscribed")).gate, "no-transcript"); assert.ok(logs.some((l) => l.includes("without checking")), logs.join("\n")); }); test("key off: clean after capture is unchanged — no verdict, held awaiting a check", async () => { await settings({}); const { paths, video } = await corpus(); const v = await video("v1", { diarization: "voiceprints" }); let started = 0; const out = await cleanAudioForVideo({ channelSlug: "ch", paths, videoId: "v1", onLog: () => {}, checkDeps: { start: async () => (started++, { ok: true, jobId: "x" }) as never, platformRefusal: async () => null, serviceAlert: async () => null }, }); assert.equal(out.gate, "awaiting-availability"); assert.equal(started, 1); assert.equal(await exists(path.join(v, "audio.mp3")), true); }); // --- Review 1 ----------------------------------------------------------------- test("F1 (BLOCKING): an unchecked sweep never prunes a saved video container — a rolled-out keep-latest container of an expired VOD survives", async () => { await settings({ enabled: false }); const { paths, video } = await corpus({ keepLatest: 1 }); // The newest video is in the window; the old one rolled out of it, has a // transcript, audio and a saved container kept by the window — and is gone // from the source (its VOD expired). The container may be its only copy. await video("new", { uploadDate: "20261101" }); const old = await video("old", { uploadDate: "20261001", gone: true }); await writeFile(path.join(old, "source-media.mp4"), "container-bytes"); await persistSourceVideo({ videoDir: old, sourceFilename: "source-media.mp4", storeDir: path.join(paths.savedVideosDir, "ch", "old"), keepReason: "keep-latest", }); const { calls, probes } = throwingProbes(); const logs: string[] = []; const r = await cleanAudioFromTranscribed({ channelSlug: "ch", paths, onLog: (m) => logs.push(m), unchecked: "button", probes }); assert.deepEqual(calls, { quick: 0, full: 0, backoff: 0 }); assert.equal(await exists(path.join(old, "audio.mp3")), false, "its audio is what was asked to go"); assert.notEqual(await loadSavedVideo(old), null, "the saved container is untouched"); assert.equal(await exists(path.join(paths.savedVideosDir, "ch", "old", "source-media.mp4")), true); assert.equal(r.prunedSavedVideos, 0); assert.ok(logs.some((l) => l.startsWith("Saved-video retention prune skipped")), logs.join("\n")); // The keep-latest window held its audio in the unchecked path too. assert.equal(await exists(path.join(paths.channelsDir, "ch", "data", "new", "audio.mp3")), true, "in the keep-latest window"); }); test("the keep-latest window: the unchecked sweep and its plan both keep it", async () => { await settings({ enabled: false }); const { paths, video } = await corpus({ keepLatest: 2 }); const a = await video("a", { uploadDate: "20261103" }); const b = await video("b", { uploadDate: "20261102" }); const c = await video("c", { uploadDate: "20261101" }); const plan = await planAudioClean({ channelSlug: "ch", paths }); assert.deepEqual(plan.ids, ["c"]); assert.equal(plan.protected, 2); const { probes } = throwingProbes(); await cleanAudioFromTranscribed({ channelSlug: "ch", paths, onLog: () => {}, unchecked: "button", onlyIds: plan.ids, probes }); assert.equal(await exists(path.join(a, "audio.mp3")), true); assert.equal(await exists(path.join(b, "audio.mp3")), true); assert.equal(await exists(path.join(c, "audio.mp3")), false); }); test("F2: plan, then the corpus changes, then the run — it removes only the intersection and leaves the newly eligible", async () => { await settings({}); const { paths, video } = await corpus(); const p1 = await video("p1", { diarization: "voiceprints" }); const p2 = await video("p2", { diarization: "voiceprints" }); const later = await video("later", { diarization: "plain" }); // awaiting a fingerprint at plan time const plan = await planAudioClean({ channelSlug: "ch", paths }); assert.deepEqual(plan.ids, ["p1", "p2"]); assert.equal(plan.awaitingVoiceprint, 1); // Meanwhile: p2 is marked do not clean; "later" gets its fingerprints. await writeFile(path.join(p2, "do-not-clean.json"), JSON.stringify({ setAt: "now" })); await writeFile(path.join(later, "diarization.json"), sidecar(true)); const { calls, probes } = throwingProbes(); const logs: string[] = []; const r = await cleanAudioFromTranscribed({ channelSlug: "ch", paths, onLog: (m) => logs.push(m), unchecked: "button", onlyIds: plan.ids, probes, }); assert.deepEqual(calls, { quick: 0, full: 0, backoff: 0 }); assert.equal(await exists(path.join(p1, "audio.mp3")), false); assert.equal(await exists(path.join(p2, "audio.mp3")), true, "became protected since: skipped"); assert.equal(await exists(path.join(later, "audio.mp3")), true, "newly eligible: not in the confirmed plan"); assert.equal(r.cleanedDirs, 1); assert.equal(r.notInPlan, 1); assert.equal(r.planNoLongerEligible, 1); assert.ok(logs.some((l) => l.includes("left for the next run (not in the confirmed plan)")), logs.join("\n")); }); test("tier-linked audio: the plan counts the bytes through the link, and the sweep removes link and bytes", async () => { await settings({ enabled: false }); const { paths, video } = await corpus(); const v = await video("t1", { bytes: 1 }); // Tier the audio: the real file in channels/ch/media/t1/, a relative link in data/t1/. const mediaDir = path.join(paths.channelsDir, "ch", "media", "t1"); await mkdir(mediaDir, { recursive: true }); await writeFile(path.join(mediaDir, "audio.mp3"), Buffer.alloc(4096)); await rm(path.join(v, "audio.mp3")); await symlink("../../media/t1/audio.mp3", path.join(v, "audio.mp3")); const plan = await planAudioClean({ channelSlug: "ch", paths }); assert.equal(plan.bytes, 4096); const { probes } = throwingProbes(); const r = await cleanAudioFromTranscribed({ channelSlug: "ch", paths, onLog: () => {}, unchecked: "button", onlyIds: plan.ids, probes }); assert.equal(r.bytesFreed, 4096); assert.equal(await exists(path.join(mediaDir, "audio.mp3")), false, "the bytes on the media tier go with the link"); }); test("an unreachable drive or a relocation in flight: the plan refuses, and the sweep removes nothing", async () => { await settings({ enabled: false }); for (const hold of ["relocating", "unmounted"] as const) { const { paths, video } = await corpus( hold === "unmounted" ? { mediaDir: "/nonexistent-drive/ch/media" } : {}, ); const v = await video("v1"); const channelDir = path.join(paths.channelsDir, "ch"); if (hold === "relocating") { await writeFile( path.join(channelDir, ".relocating.json"), JSON.stringify({ target: "/elsewhere/ch/media", direction: "out", startedAt: "now", phase: "copy", scope: "media" }), ); } else { await symlink("/nonexistent-drive/ch/media", path.join(channelDir, "media")); } const why = hold === "relocating" ? /relocation/ : /does not exist/; await assert.rejects(planAudioClean({ channelSlug: "ch", paths }), why); const { probes } = throwingProbes(); await assert.rejects( cleanAudioFromTranscribed({ channelSlug: "ch", paths, onLog: () => {}, unchecked: "button", onlyIds: ["v1"], probes }), why, ); assert.equal(await exists(path.join(v, "audio.mp3")), true, `${hold}: nothing removed`); } }); test("an empty transcript.json counts as transcribed in both paths alike (parity: the name decides, as before this lane)", async () => { await settings({ enabled: false }); const { paths, video } = await corpus(); await video("e1"); // transcript.json is "{}" const plan = await planAudioClean({ channelSlug: "ch", paths }); assert.deepEqual(plan.ids, ["e1"]); }); test("key on: clean after capture still holds a whole-recording channel's audio and a URL-less channel's", async () => { await settings({ enabled: false }); const whole = await corpus({ cleanAudioWithoutChecking: true, url: "https://rumble.com/c/example", platform: "rumble" }); const w = await whole.video("w1"); const out1 = await cleanAudioForVideo({ channelSlug: "ch", paths: whole.paths, videoId: "w1", onLog: () => {}, checkDeps: NO_CHECK }); assert.equal(out1.gate, "whole-recording"); assert.equal(await exists(path.join(w, "audio.mp3")), true); const nourl = await corpus({ cleanAudioWithoutChecking: true, url: undefined }); const u = await nourl.video("u1"); const out2 = await cleanAudioForVideo({ channelSlug: "ch", paths: nourl.paths, videoId: "u1", onLog: () => {}, checkDeps: NO_CHECK }); assert.equal(out2.gate, "no-source-url"); assert.equal(await exists(path.join(u, "audio.mp3")), true); }); test("no leak: a channel beside a key-on one is cleaned checked", async () => { await settings({ enabled: false }); const { paths, video } = await corpus({ cleanAudioWithoutChecking: true }); await video("k1"); // A second channel in the same corpus, key absent. const other = path.join(paths.channelsDir, "other", "data", "o1"); await mkdir(other, { recursive: true }); await writeFile(path.join(paths.channelsDir, "other", "config.json"), JSON.stringify({ handling: "transcribe", name: "o", url: "https://www.twitch.tv/other" })); await writeFile(path.join(other, "transcript.json"), "{}"); await writeFile(path.join(other, "audio.mp3"), Buffer.alloc(10)); assert.equal(uncheckedReasonFor(await readChannelConfig(paths, "other")), undefined); assert.equal(uncheckedReasonFor(await readChannelConfig(paths, "ch")), "channel-setting"); let started = 0; const out = await cleanAudioForVideo({ channelSlug: "other", paths, videoId: "o1", onLog: () => {}, checkDeps: { start: async () => (started++, { ok: true, jobId: "x" }) as never, platformRefusal: async () => null, serviceAlert: async () => null }, }); assert.equal(out.gate, "awaiting-availability", "the other channel is checked"); assert.equal(started, 1); }); test("a new channel never starts with cleanAudioWithoutChecking: createChannel drops it", async () => { const { paths } = await corpus(); await createChannel(paths, "fresh", parseChannelConfig({ handling: "transcribe", name: "f", cleanAudioWithoutChecking: true })!); const cfg = JSON.parse(await readFile(path.join(paths.channelsDir, "fresh", "config.json"), "utf8")); assert.equal("cleanAudioWithoutChecking" in cfg, false); assert.equal(cfg.name, "f"); }); // --- Review 2 ----------------------------------------------------------------- test("review 2 F1: a checked clean the source rate-limits prunes no saved container — across the whole retry chain", async () => { await settings({ enabled: false }); const { paths, video } = await corpus({ keepLatest: 1, url: "https://rumble.com/c/example" }); await video("new", { uploadDate: "20261101" }); // Rolled out of the window, gone upstream, never probed: only the listing // could have found it gone, and the listing is rate-limited. const old = await video("old", { uploadDate: "20261001" }); await writeFile(path.join(old, "source-media.mp4"), "container-bytes"); await persistSourceVideo({ videoDir: old, sourceFilename: "source-media.mp4", storeDir: path.join(paths.savedVideosDir, "ch", "old"), keepReason: "keep-latest", }); const { calls, probes } = throwingProbes(); probes.quick = async () => { calls.quick++; throw new EnumerationIncompleteError(1, "rumble", null, 0); }; const T = Date.parse("2026-11-21T03:00:00.000Z"); const retries: Array = [ undefined, { attempt: 1, of: "j0", notBefore: T - 1, platform: "rumble" }, { attempt: 2, of: "j0", notBefore: T - 1, platform: "rumble" }, ]; const ends: string[] = []; for (const retry of retries) { const logs: string[] = []; const out = await runCleanAudioJob({ channelSlug: "ch", paths, jobId: retry ? `j${retry.attempt}` : "j0", ...(retry ? { retry } : {}), onLog: (m) => logs.push(m), deps: { probes, now: () => T, cooldownRemainingMs: async () => 0, scheduleRetry: async (r) => ({ ok: true, id: `${r.of}.retry${r.attempt}` }) }, }); ends.push(out.end); assert.notEqual(await loadSavedVideo(old), null, `the container survives step ${retry?.attempt ?? 0}`); assert.ok( logs.some((l) => l.startsWith("Saved-video retention prune skipped: the availability check did not complete (rate-limited by rumble)")), logs.join("\n"), ); } assert.deepEqual(ends, ["deferred", "deferred", "failed"]); assert.equal(await exists(path.join(old, "audio.mp3")), true, "nothing unverified was cleaned"); });