import { test } from "node:test"; import assert from "node:assert/strict"; import { parseChannelConfig } from "./channelConfig"; import { channelConfigSchema } from "./channelConfigSchema"; import { BATCH_DOWNLOAD_MODES, channelDownloadsAreManual, manualDownloadsRefusal, } from "./manualDownloads"; // Run with: // pnpm --filter yt-dlp-transcript-common exec tsx --test lib/manualDownloads.test.ts // // A channel that downloads only what it is asked for (2026-10-29). The one // predicate every lane and controller asks, the refusal the batch downloads // give, and the key's coercion (controller/manualDownloadsConfig.test.ts // writes it through patchChannelConfig). test("the predicate: only an explicit manual is manual", () => { assert.equal(channelDownloadsAreManual({ downloadMode: "manual" }), true); assert.equal(channelDownloadsAreManual({ downloadMode: "auto" }), false); assert.equal(channelDownloadsAreManual({}), false); assert.equal(channelDownloadsAreManual(null), false); assert.equal(channelDownloadsAreManual(undefined), false); }); test("the batch downloads refuse on a manual channel; a single video, a sync and an automatic channel do not", () => { for (const mode of BATCH_DOWNLOAD_MODES) { const refusal = manualDownloadsRefusal("harmful", { downloadMode: "manual" }, mode); assert.ok(refusal, mode); assert.match(refusal!, /manual downloads/); assert.match(refusal!, new RegExp(mode)); assert.equal(manualDownloadsRefusal("harmful", {}, mode), null, `${mode} on an automatic channel`); } for (const mode of ["sync", "store-playlist", "download-one-audio", "download-missing-subs", "import-one"]) { assert.equal( manualDownloadsRefusal("harmful", { downloadMode: "manual" }, mode), null, `${mode} runs on a manual channel`, ); } }); test("config.json: manual and auto are kept, anything else is dropped, by both readers", () => { for (const [raw, want] of [ ["manual", "manual"], ["auto", "auto"], ["Manual", undefined], [true, undefined], ] as const) { const file = { handling: "youtube", downloadMode: raw }; assert.equal(parseChannelConfig(file)?.downloadMode, want, String(raw)); assert.equal(channelConfigSchema.parse(file)?.downloadMode, want, String(raw)); if (want === undefined) { assert.equal("downloadMode" in parseChannelConfig(file)!, false); assert.equal("downloadMode" in channelConfigSchema.parse(file)!, false); } } // Absent stays absent: an automatic channel's file is byte for byte as before. assert.equal("downloadMode" in parseChannelConfig({ handling: "youtube" })!, false); });