import test from "node:test"; import assert from "node:assert/strict"; import { writeFile } from "node:fs/promises"; import path from "node:path"; import { callPost, setupOpsCorpus } from "../_testCorpus"; // Run with: // pnpm -C editor exec tsx --test "app/api/ops/retry-bucket/route.test.ts" // // retry-bucket and transcribe-bucket narrow a bucket with "ids", and every id // must be in it. Moved from e2e/ops-api.spec.ts (release 19, A2b): refused // before any job, from a report written by hand. const corpus = await setupOpsCorpus("title-filter-channel"); const SLUG = "test-filter"; // A report by hand, so the bucket is known without a regen. await writeFile( path.join(corpus.transcripts, "channels", SLUG, "snapshot.json"), JSON.stringify({ buckets: { downloadedNoTranscript: ["in-bucket-1"] } }), ); const retry = (await import("./route")).POST; const transcribe = (await import("../transcribe-bucket/route")).POST; test.after(() => corpus.cleanup()); test("retry-bucket and transcribe-bucket ids must be in the bucket: a stray is refused, named, and nothing runs", async () => { const stray = await callPost(retry, { slug: SLUG, bucket: "downloadedNoTranscript", ids: ["stray-aaa", "stray-bbb"], }); assert.equal(stray.status, 400); assert.match(String(stray.body.error), /2 of "ids" not in .*: stray-aaa, stray-bbb/); // transcribe-bucket narrows the same bucket by the same rule. const strayT = await callPost(transcribe, { slug: SLUG, ids: ["stray-ccc"] }); assert.equal(strayT.status, 400); assert.match(String(strayT.body.error), /1 of "ids" not in .*: stray-ccc/); // An empty list is not "the whole bucket". const empty = await callPost(retry, { slug: SLUG, bucket: "downloadedNoTranscript", ids: [], }); assert.equal(empty.status, 400); assert.deepEqual(await corpus.listJobIds(), []); });