import { test } from "node:test"; import assert from "node:assert/strict"; import { jobSpecDetail } from "./jobDetail"; // Run with: pnpm --filter yt-dlp-transcript-common exec tsx --test jobs/jobDetail.test.ts test("a publish stage reads `run · `", () => { assert.equal( jobSpecDetail("publish-build-site", { kind: "publish-build-site", slug: "jeralyzer", params: { runId: "run-0000abc12-9f8e7d6c", kind: "build-site", target: "jeralyzer" }, }), "run 8e7d6c · jeralyzer", ); assert.equal( jobSpecDetail("publish-update-index", { kind: "publish-update-index", slug: "_index", params: { runId: "cli-abcdef" }, }), "run abcdef · _index", ); }); test("a publish stage with no run id (or no spec) adds nothing", () => { assert.equal(jobSpecDetail("publish-deploy-hub", { kind: "publish-deploy-hub", slug: "_hub" }), undefined); assert.equal(jobSpecDetail("publish-deploy-hub", undefined), undefined); }); test("every other kind is unchanged: fetch-window keeps its phrase, the rest nothing", () => { assert.equal( jobSpecDetail("fetch-window", { kind: "fetch-window", slug: "c", params: { requestedBy: "umtool", manifest: "m", clipId: "c1" }, }), "umtool · m/c1", ); assert.equal(jobSpecDetail("sync", { kind: "sync", slug: "c", params: { runId: "zzzzzzzz" } }), undefined); assert.equal(jobSpecDetail(undefined, undefined), undefined); }); const spec = (kind: string, params: Record) => ({ kind, slug: "c", params }); test("a single window names who asked and for which clip", () => { assert.equal( jobSpecDetail("fetch-window", spec("fetch-window", { requestedBy: "umtool", manifest: "m", clipId: "c01" })), "umtool · m/c01", ); }); test("a batch names who asked, for what, and how many windows", () => { assert.equal( jobSpecDetail("fetch-windows", spec("fetch-windows", { requestedBy: "reports", manifest: "demo-site", items: [{}, {}] })), "reports · demo-site · 2 windows", ); assert.equal( jobSpecDetail("fetch-windows", spec("fetch-windows", { requestedBy: "umtool", items: [{}] })), "umtool · 1 window", ); }); test("other kinds add nothing", () => { assert.equal(jobSpecDetail("sync", spec("sync", { requestedBy: "x" })), undefined); });