import test from "node:test"; import assert from "node:assert/strict"; import { callPost, holdPublishQueue, setupOpsCorpus } from "../_testCorpus"; // Run with: // pnpm -C editor exec tsx --test "app/api/ops/build-site/route.test.ts" // // build-site and build-deploy speak the same body — `siteId` or `siteIds`, // never both, never neither — and refuse before any job. Moved from // e2e/ops-api.spec.ts (release 19, A2b). The publish queue is held throughout, // so a stage a regressed refusal failed to stop could only queue. const corpus = await setupOpsCorpus("title-filter-channel"); const buildSite = (await import("./route")).POST; const buildDeploy = (await import("../build-deploy/route")).POST; await holdPublishQueue(); test.after(() => corpus.cleanup()); test("build-site and build-deploy each take siteId or siteIds, and refuse both or neither", async () => { for (const [action, handler] of [ ["build-site", buildSite], ["build-deploy", buildDeploy], ] as const) { const both = await callPost(handler, { siteId: "a", siteIds: ["a"] }); assert.equal(both.status, 400, action); assert.match(String(both.body.error), /not both/, action); const neither = await callPost(handler, {}); assert.equal(neither.status, 400, action); assert.match(String(neither.body.error), /siteId/, action); // `all` is still exclusive of either spelling. const withAll = await callPost(handler, { all: true, siteId: "a" }); assert.equal(withAll.status, 400, action); assert.match(String(withAll.body.error), /not both/, action); // A MALFORMED ID IS A 400 BEFORE ANY JOB STARTS: an id list of // ["good", "BAD"] used to queue the first build, throw on the second and // answer 500 with no ids at all. const bad = await callPost(handler, { siteIds: ["buildsite", "BAD ID"] }); assert.equal(bad.status, 400, action); assert.match(String(bad.body.error), /not a valid site id/, action); assert.equal(bad.body.jobs, undefined, action); } assert.deepEqual(await corpus.listJobIds(), []); }); test("build-deploy refuses a preview alongside all rather than building everything", async () => { const { status, body } = await callPost(buildDeploy, { all: true, preview: "tags-exclude" }); assert.equal(status, 400); assert.match(String(body.error), /"preview" is not supported with "all"/); assert.deepEqual(await corpus.listJobIds(), []); });