{"draft":null,"from":0,"to":1,"files":[{"path":"src/pipeline/test/plan.test.ts","added":88,"removed":0,"diff":"--- /dev/null\n+++ b/src/pipeline/test/plan.test.ts\n@@ -0,0 +1,88 @@\n+// Which pipelines an event starts, and their jobs in waves (abso issue 176).\n+\n+import assert from \"node:assert/strict\";\n+import { describe, it } from \"node:test\";\n+import { type PipelineFile, readPipelineFile } from \"../pipeline.ts\";\n+import { plan, waves } from \"../plan.ts\";\n+\n+const FILE = `pipelines:\n+  ci:\n+    on: [publish, draft]\n+    jobs:\n+      setup:  { run: npm ci }\n+      lint:   { needs: [setup], run: npx biome ci . }\n+      test:   { needs: [setup], run: npm test }\n+      bundle: { needs: [lint, test], run: npm run build, keep: [\"dist/**\"] }\n+    required: [lint, test]\n+  release:\n+    on: [green, hand]\n+    only: shared\n+    jobs:\n+      site: { uses: deploy, from: ci.bundle, worker: w, secrets: [CLOUDFLARE_API_TOKEN] }\n+      tell: { needs: [site], uses: notify, to: [issue] }\n+  nightly:\n+    on: [{ every: \"day 06:00 UTC\" }]\n+    jobs:\n+      drill: { run: node ops/restore-drill.ts }\n+`;\n+const read = (text: string): PipelineFile => {\n+\tconst c = readPipelineFile(text, \"abso.yml\");\n+\tassert.ok(c.ok, c.ok ? \"\" : JSON.stringify(c.problems));\n+\treturn c.file;\n+};\n+const file = read(FILE);\n+const started = (p: ReturnType<typeof plan>) => p.start.map((s) => s.name);\n+\n+describe(\"which pipelines an event starts\", () => {\n+\tit(\"a publish to shared starts ci, in waves that can run side by side\", () => {\n+\t\tconst p = plan(file, { kind: \"publish\", space: \"shared\" });\n+\t\tassert.deepEqual(started(p), [\"ci\"]);\n+\t\tassert.deepEqual(p.start[0]!.waves, [[\"setup\"], [\"lint\", \"test\"], [\"bundle\"]]);\n+\t\tassert.deepEqual(p.start[0]!.required, [\"lint\", \"test\"]);\n+\t\tassert.deepEqual(p.skip, [\n+\t\t\t{ name: \"release\", why: \"doesn't run on publish\" },\n+\t\t\t{ name: \"nightly\", why: \"doesn't run on publish\" },\n+\t\t]);\n+\t});\n+\n+\tit(\"green on shared starts release; green on a named draft doesn't, since release is only shared\", () => {\n+\t\tassert.deepEqual(started(plan(file, { kind: \"green\", space: \"shared\" })), [\"release\"]);\n+\t\tconst p = plan(file, { kind: \"green\", space: \"rename-59\" });\n+\t\tassert.deepEqual(started(p), []);\n+\t\tassert.deepEqual(\n+\t\t\tp.skip.find((s) => s.name === \"release\"),\n+\t\t\t{ name: \"release\", why: \"runs only for shared, not rename-59\" },\n+\t\t);\n+\t});\n+\n+\tit(\"by hand starts only the pipeline named, and only if it runs by hand\", () => {\n+\t\tassert.deepEqual(started(plan(file, { kind: \"hand\", pipeline: \"release\", space: \"shared\" })), [\"release\"]);\n+\t\tconst ci = plan(file, { kind: \"hand\", pipeline: \"ci\", space: \"shared\" });\n+\t\tassert.deepEqual(started(ci), []);\n+\t\tassert.deepEqual(\n+\t\t\tci.skip.find((s) => s.name === \"ci\"),\n+\t\t\t{ name: \"ci\", why: \"doesn't run on hand\" },\n+\t\t);\n+\t});\n+\n+\tit(\"a schedule starts the pipeline with that schedule, on shared\", () => {\n+\t\tassert.deepEqual(started(plan(file, { kind: \"schedule\", every: \"day 06:00 UTC\" })), [\"nightly\"]);\n+\t\tassert.deepEqual(started(plan(file, { kind: \"schedule\", every: \"hour\" })), []);\n+\t});\n+\n+\tit(\"a draft never starts a pipeline holding secrets, even if the file said so\", () => {\n+\t\tconst unchecked: PipelineFile = {\n+\t\t\tdefaults: {},\n+\t\t\tpipelines: [{ ...file.pipelines[1]!, on: [\"draft\"], only: undefined } as never],\n+\t\t};\n+\t\tconst p = plan(unchecked, { kind: \"draft\", space: \"shared\" });\n+\t\tassert.deepEqual(p.start, []);\n+\t\tassert.match(p.skip[0]!.why, /holds secrets, and a draft runs unpublished code/);\n+\t});\n+\n+\tit(\"waves stop on jobs that wait on each other rather than loop\", () => {\n+\t\tconst job = (name: string, needs: string[]) =>\n+\t\t\t({ name, needs, keep: [], cache: [], secrets: [], with: {} }) as never;\n+\t\tassert.throws(() => waves([job(\"a\", [\"b\"]), job(\"b\", [\"a\"])]), /jobs a, b wait on each other/);\n+\t});\n+});"}],"unmatched":[]}