import { test } from "node:test"; import assert from "node:assert/strict"; import { COMMANDS } from "./archilyzer"; import { argumentProblem, booleanFlags, resolveCommand, usage } from "./_cli"; import { parseArgv } from "./_parseFlags"; import { defaultPublish } from "../lib/settingsSchema"; import { buildPublishStatus, type PublishInputs } from "../publish/publishPlan"; import { statusLines } from "./publishNow"; // Run with: pnpm --filter yt-dlp-transcript-common exec tsx --test bin/publishNow.test.ts // // `publish status [--json]` and `publish now` (release 18 S3): their rows, and // the status's lines over a hand-built status. `publish now` itself runs the // stage bodies, which the stage tests (publish/stages*.test.ts) cover. test("publish status takes --json and nothing else; publish now takes nothing", () => { const status = resolveCommand(COMMANDS, ["publish", "status"])?.command; assert.deepEqual(status?.path, ["publish", "status"]); assert.deepEqual(status?.flags, { json: "boolean" }); const parsed = parseArgv(["publish", "status", "--json"], booleanFlags(COMMANDS)); assert.deepEqual(parsed, { positionals: ["publish", "status"], flags: { json: true } }); assert.equal(argumentProblem(status!, parsed.flags, []), null); assert.match(argumentProblem(status!, {}, ["x"])!, /unexpected argument "x"/); const now = resolveCommand(COMMANDS, ["publish", "now"])?.command; assert.deepEqual(now?.path, ["publish", "now"]); assert.match(argumentProblem(now!, { force: true }, [])!, /unknown flag --force/); const u = usage(COMMANDS); assert.match(u, /archilyzer publish status\s+\[--json\] the publish status/); assert.match(u, /archilyzer publish now\s+run what Publish now runs .* IN THIS PROCESS under the publish lock, as the editor's queue would \(the CLI has no queue\)/); }); test("the status reads as one row per target, then the plan", () => { const empty = { built: null, deployed: null, bundleProblem: null, deployProblem: null, pagesProblem: null, configChangedAt: null, policy: "off" as const, cloudflareProject: null, url: null, }; const i: PublishInputs = { index: { stamp: null, lastIngestDoneAt: null, configChangedAt: null }, ingestByChannel: {}, commit: null, sites: [{ ...empty, siteId: "alpha", title: "Alpha", private: false, listed: true, members: [], policy: "build" }], hub: empty, homepage: { ...empty, mainHead: null }, settings: defaultPublish(), jobs: [], ended: [], lane: { known: false, running: false, jobId: null, passRunning: false, lastCheckAt: null, nextCheckAt: null, lastPassAt: null, lastPassSummary: null, lastDecision: null, }, }; const lines = statusLines(buildPublishStatus(i, 1_900_000_000_000)); assert.equal(lines[0], "index no index yet"); assert.match(lines[1], /^lane {11}lane off — the lane is off$/); assert.match(lines[3], /^alpha +\| \[build\] +\| built: update the index first \| deployed: not deployed \| live: not checked \| next: build$/); assert.match(lines[4], /^_hub /); assert.match(lines[5], /^_homepage /); assert.equal(lines[7], "Publish now would run:"); assert.match(lines[8], /^ update-index _index — no index stamp yet$/); assert.match(lines[9], /^ build-site alpha — built after the index's first update$/); });