// The `mirror` config key (release 31, lane D): `of` kept as valid slugs, // trimmed and de-duplicated; nothing usable drops the key, as its siblings do. // // Run with: pnpm --filter yt-dlp-transcript-common exec tsx --test lib/mirrors/config.test.ts import { test } from "node:test"; import assert from "node:assert/strict"; import { coerceMirrorConfig, mirrorSlugs } from "./config"; import { parseChannelConfig } from "../channelConfig"; import { channelConfigSchema } from "../channelConfigSchema"; test("coerceMirrorConfig keeps valid slugs and drops the rest", () => { assert.deepEqual(coerceMirrorConfig({ of: [" a-b ", "c_d", "a-b", "../x", 3, ""] }), { of: ["a-b", "c_d"] }); assert.equal(coerceMirrorConfig({ of: [] }), undefined); assert.equal(coerceMirrorConfig({ of: ["../x"] }), undefined); assert.equal(coerceMirrorConfig({}), undefined); assert.equal(coerceMirrorConfig(["a"]), undefined); assert.equal(coerceMirrorConfig("a"), undefined); assert.deepEqual(mirrorSlugs("a, b c,,a"), ["a", "b", "c"]); }); test("a config.json's mirror reads through both compositions", () => { const raw = { handling: "transcribe", mirror: { of: ["creator-yt", "bad/slug"] } }; assert.deepEqual(parseChannelConfig(raw)?.mirror, { of: ["creator-yt"] }); assert.deepEqual(channelConfigSchema.parse(raw)?.mirror, { of: ["creator-yt"] }); assert.equal("mirror" in (channelConfigSchema.parse({ handling: "transcribe", mirror: { of: [] } }) ?? {}), false); });