import { test } from "node:test"; import assert from "node:assert/strict"; import { parseJobSpec } from "./jobSpec"; // Run with: pnpm --filter yt-dlp-transcript-common exec tsx --test common/jobs/jobSpec.test.ts test("parses a minimal spec and rejects malformed input", () => { assert.deepEqual(parseJobSpec({ kind: "sync", slug: "chan" }), { kind: "sync", slug: "chan", }); assert.equal(parseJobSpec(null), null); assert.equal(parseJobSpec("sync"), null); assert.equal(parseJobSpec({ kind: "", slug: "chan" }), null); assert.equal(parseJobSpec({ kind: "sync" }), null); }); test("accepts every replay bucket, including the auto-caption lane", () => { for (const bucket of [ "partialDownloads", "noTranscript", "downloadedNoTranscript", "incompleteTranscript", "shortAudio", "needsCookies", "autoSubsOnly", "downloadedAutoSubsOnly", "supersededAutoSubs", ]) { const spec = parseJobSpec({ kind: "retry-bucket", slug: "chan", bucket }); assert.equal(spec?.bucket, bucket); } // Unknown buckets invalidate the whole spec. assert.equal( parseJobSpec({ kind: "retry-bucket", slug: "chan", bucket: "nope" }), null, ); }); test("carries flag params verbatim (e.g. forceCookies)", () => { const spec = parseJobSpec({ kind: "retry-bucket", slug: "chan", bucket: "needsCookies", params: { queueKey: "youtube", forceCookies: true }, }); assert.deepEqual(spec?.params, { queueKey: "youtube", forceCookies: true }); // Array params are rejected (params must be a plain object). assert.equal( parseJobSpec({ kind: "sync", slug: "chan", params: [] })?.params, undefined, ); });