- MCP
- code on this site's /mcp
- CLI
- none: the JSON below is the answer
- JSON
- /christopher/abso-core/files/src/pipeline/test/plan.test.ts?format=json
88 linesinfra-split 94% · rename 6%Last change rename in version 101, 3 versions changed it
1// Which pipelines an event starts, and their jobs in waves (abso issue 176).
3import assert from "node:assert/strict";
4import { describe, it } from "node:test";
5import { type PipelineFile, readPipelineFile } from "../pipeline.ts";
6import { plan, waves } from "../plan.ts";
8const FILE = `pipelines:
9 ci:
10 on: [push, draft]
11 jobs:
12 setup: { run: npm ci }
13 lint: { needs: [setup], run: npx biome ci . }
14 test: { needs: [setup], run: npm test }
15 bundle: { needs: [lint, test], run: npm run build, keep: ["dist/**"] }
16 required: [lint, test]
17 release:
18 on: [green, hand]
19 only: shared
20 jobs:
21 site: { uses: deploy, from: ci.bundle, worker: w, secrets: [CLOUDFLARE_API_TOKEN] }
22 tell: { needs: [site], uses: notify, to: [issue] }
23 nightly:
24 on: [{ every: "day 06:00 UTC" }]
25 jobs:
26 drill: { run: node ops/restore-drill.ts }
27`;
28const read = (text: string): PipelineFile => {
29 const c = readPipelineFile(text, "abso.yml");
30 assert.ok(c.ok, c.ok ? "" : JSON.stringify(c.problems));
31 return c.file;
32};
33const file = read(FILE);
34const started = (p: ReturnType<typeof plan>) => p.start.map((s) => s.name);
36describe("which pipelines an event starts", () => {
37 it("a push to shared starts ci, in waves that can run side by side", () => {
38 const p = plan(file, { kind: "publish", space: "shared" });
39 assert.deepEqual(started(p), ["ci"]);
40 assert.deepEqual(p.start[0]!.waves, [["setup"], ["lint", "test"], ["bundle"]]);
41 assert.deepEqual(p.start[0]!.required, ["lint", "test"]);
42 assert.deepEqual(p.skip, [
43 { name: "release", why: "doesn't run on push" },
44 { name: "nightly", why: "doesn't run on push" },
45 ]);
46 });
48 it("green on shared starts release; green on a named draft doesn't, since release is only shared", () => {
49 assert.deepEqual(started(plan(file, { kind: "green", space: "shared" })), ["release"]);
50 const p = plan(file, { kind: "green", space: "rename-59" });
51 assert.deepEqual(started(p), []);
52 assert.deepEqual(
53 p.skip.find((s) => s.name === "release"),
54 { name: "release", why: "runs only for shared, not rename-59" },
55 );
56 });
58 it("by hand starts only the pipeline named, and only if it runs by hand", () => {
59 assert.deepEqual(started(plan(file, { kind: "hand", pipeline: "release", space: "shared" })), ["release"]);
60 const ci = plan(file, { kind: "hand", pipeline: "ci", space: "shared" });
61 assert.deepEqual(started(ci), []);
62 assert.deepEqual(
63 ci.skip.find((s) => s.name === "ci"),
64 { name: "ci", why: "doesn't run on hand" },
65 );
66 });
68 it("a schedule starts the pipeline with that schedule, on shared", () => {
69 assert.deepEqual(started(plan(file, { kind: "schedule", every: "day 06:00 UTC" })), ["nightly"]);
70 assert.deepEqual(started(plan(file, { kind: "schedule", every: "hour" })), []);
71 });
73 it("a draft never starts a pipeline holding secrets, even if the file said so", () => {
74 const unchecked: PipelineFile = {
75 defaults: {},
76 pipelines: [{ ...file.pipelines[1]!, on: ["draft"], only: undefined } as never],
77 };
78 const p = plan(unchecked, { kind: "draft", space: "shared" });
79 assert.deepEqual(p.start, []);
80 assert.match(p.skip[0]!.why, /holds secrets, and a draft runs unpushed code/);
81 });
83 it("waves stop on jobs that wait on each other rather than loop", () => {
84 const job = (name: string, needs: string[]) =>
85 ({ name, needs, keep: [], cache: [], secrets: [], with: {} }) as never;
86 assert.throws(() => waves([job("a", ["b"]), job("b", ["a"])]), /jobs a, b wait on each other/);
87 });
88});