@intentius/chant 0.124.89 → 0.124.91
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actor.d.ts +5 -3
- package/dist/actor.d.ts.map +1 -1
- package/dist/actor.js +7 -5
- package/dist/audit/core.d.ts.map +1 -1
- package/dist/audit/core.js +11 -1
- package/dist/ci-comment-commands.d.ts +18 -2
- package/dist/ci-comment-commands.d.ts.map +1 -1
- package/dist/ci-comment-commands.js +30 -2
- package/dist/ci-job-guard.d.ts +42 -45
- package/dist/ci-job-guard.d.ts.map +1 -1
- package/dist/ci-job-guard.js +206 -3
- package/dist/ci-note-commands.d.ts +41 -1
- package/dist/ci-note-commands.d.ts.map +1 -1
- package/dist/ci-note-commands.js +64 -5
- package/dist/ci-product.d.ts +50 -1
- package/dist/ci-product.d.ts.map +1 -1
- package/dist/ci-product.js +52 -6
- package/dist/cli/handlers/pr-comment.d.ts +13 -1
- package/dist/cli/handlers/pr-comment.d.ts.map +1 -1
- package/dist/cli/handlers/pr-comment.js +90 -1
- package/dist/cli/handlers/pr-notes.d.ts.map +1 -1
- package/dist/cli/handlers/pr-notes.js +23 -1
- package/dist/cli/handlers/pr.d.ts +2 -2
- package/dist/cli/handlers/pr.d.ts.map +1 -1
- package/dist/cli/handlers/pr.js +41 -20
- package/dist/cli/handlers/run-wave.d.ts.map +1 -1
- package/dist/cli/handlers/run-wave.js +154 -4
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +17 -0
- package/dist/cli/parse-args.d.ts.map +1 -1
- package/dist/cli/parse-args.js +28 -0
- package/dist/cli/registry.d.ts +12 -1
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/components/pr-checks.d.ts +39 -1
- package/dist/components/pr-checks.d.ts.map +1 -1
- package/dist/components/pr-checks.js +45 -2
- package/dist/components/pr-pipeline.d.ts +11 -3
- package/dist/components/pr-pipeline.d.ts.map +1 -1
- package/dist/components/pr-pipeline.js +20 -7
- package/dist/components/product-pipeline.d.ts +54 -2
- package/dist/components/product-pipeline.d.ts.map +1 -1
- package/dist/components/product-pipeline.js +63 -6
- package/dist/components/product-plan.d.ts +92 -2
- package/dist/components/product-plan.d.ts.map +1 -1
- package/dist/components/product-plan.js +172 -22
- package/dist/floor-table.data.d.ts.map +1 -1
- package/dist/floor-table.data.js +37 -23
- package/dist/lexicon-module.d.ts +2 -0
- package/dist/lexicon-module.d.ts.map +1 -1
- package/dist/lexicon-module.js +6 -2
- package/dist/lexicon.d.ts +82 -4
- package/dist/lexicon.d.ts.map +1 -1
- package/dist/lifecycle/gate-applied.d.ts +9 -0
- package/dist/lifecycle/gate-applied.d.ts.map +1 -1
- package/dist/op/apply-status.d.ts +84 -0
- package/dist/op/apply-status.d.ts.map +1 -0
- package/dist/op/apply-status.js +106 -0
- package/dist/op/before-merge-decide.d.ts +102 -0
- package/dist/op/before-merge-decide.d.ts.map +1 -0
- package/dist/op/before-merge-decide.js +142 -0
- package/dist/op/before-merge-done.d.ts +56 -0
- package/dist/op/before-merge-done.d.ts.map +1 -0
- package/dist/op/before-merge-done.js +69 -0
- package/dist/op/before-merge-store.d.ts +20 -0
- package/dist/op/before-merge-store.d.ts.map +1 -0
- package/dist/op/before-merge-store.js +48 -0
- package/dist/op/before-merge.d.ts +150 -0
- package/dist/op/before-merge.d.ts.map +1 -0
- package/dist/op/before-merge.js +207 -0
- package/dist/op/follow-on-run.d.ts +117 -0
- package/dist/op/follow-on-run.d.ts.map +1 -0
- package/dist/op/follow-on-run.js +154 -0
- package/dist/op/follow-on-store.d.ts +17 -0
- package/dist/op/follow-on-store.d.ts.map +1 -0
- package/dist/op/follow-on-store.js +54 -0
- package/dist/op/gate.d.ts +6 -0
- package/dist/op/gate.d.ts.map +1 -1
- package/dist/op/gate.js +10 -1
- package/dist/op/index.d.ts +3 -1
- package/dist/op/index.d.ts.map +1 -1
- package/dist/op/index.js +1 -0
- package/dist/op/op-waves-after-plan.d.ts +13 -0
- package/dist/op/op-waves-after-plan.d.ts.map +1 -1
- package/dist/op/op-waves-evidence-jobs.d.ts +4 -1
- package/dist/op/op-waves-evidence-jobs.d.ts.map +1 -1
- package/dist/op/op-waves-evidence-jobs.js +10 -2
- package/dist/op/op-waves-follow-on.d.ts +162 -0
- package/dist/op/op-waves-follow-on.d.ts.map +1 -0
- package/dist/op/op-waves-follow-on.js +355 -0
- package/dist/op/op-waves-run.d.ts +146 -6
- package/dist/op/op-waves-run.d.ts.map +1 -1
- package/dist/op/op-waves-run.js +871 -99
- package/dist/op/op-waves-split.d.ts +122 -0
- package/dist/op/op-waves-split.d.ts.map +1 -0
- package/dist/op/op-waves-split.js +166 -0
- package/dist/op/op-waves.d.ts +20 -0
- package/dist/op/op-waves.d.ts.map +1 -1
- package/dist/op/op-waves.js +15 -1
- package/dist/op/schedule-overdue.d.ts +15 -1
- package/dist/op/schedule-overdue.d.ts.map +1 -1
- package/dist/op/schedule-overdue.js +18 -2
- package/dist/op/stage-hooks.d.ts +36 -1
- package/dist/op/stage-hooks.d.ts.map +1 -1
- package/dist/op/stage-hooks.js +17 -3
- package/dist/op/wave-stop.d.ts +4 -1
- package/dist/op/wave-stop.d.ts.map +1 -1
- package/dist/op/wave-stop.js +4 -2
- package/dist/planned-files.d.ts +16 -8
- package/dist/planned-files.d.ts.map +1 -1
- package/dist/planned-files.js +12 -8
- package/dist/pr-post.d.ts +6 -0
- package/dist/pr-post.d.ts.map +1 -1
- package/dist/pr-post.js +7 -5
- package/dist/release-floors.d.ts +9 -1
- package/dist/release-floors.d.ts.map +1 -1
- package/dist/release-floors.js +27 -19
- package/dist/wave-blocked.d.ts +7 -1
- package/dist/wave-blocked.d.ts.map +1 -1
- package/dist/wave-blocked.js +7 -2
- package/dist/wave-runtime.mjs +364 -351
- package/package.json +1 -1
- package/src/actor.test.ts +14 -1
- package/src/actor.ts +8 -6
- package/src/audit/core.ts +13 -1
- package/src/audit/first-load.test.ts +101 -0
- package/src/ci-comment-commands.test.ts +63 -0
- package/src/ci-comment-commands.ts +43 -4
- package/src/ci-image.test.ts +1 -2
- package/src/ci-job-guard.before-merge.test.ts +148 -0
- package/src/ci-job-guard.follow-on-record.test.ts +137 -0
- package/src/ci-job-guard.follow-on.test.ts +144 -0
- package/src/ci-job-guard.ts +221 -3
- package/src/ci-note-commands.test.ts +76 -1
- package/src/ci-note-commands.ts +96 -7
- package/src/ci-product.ts +65 -6
- package/src/cli/handlers/pr-comment.ts +85 -2
- package/src/cli/handlers/pr-notes.ts +30 -6
- package/src/cli/handlers/pr.ts +34 -17
- package/src/cli/handlers/run-wave.ts +144 -4
- package/src/cli/main.ts +17 -0
- package/src/cli/parse-args.ts +20 -0
- package/src/cli/registry.ts +12 -1
- package/src/components/pr-checks.ts +66 -2
- package/src/components/pr-pipeline.ts +21 -9
- package/src/components/product-pipeline.apply-status.test.ts +50 -0
- package/src/components/product-pipeline.ts +117 -9
- package/src/components/product-plan-names.test.ts +135 -0
- package/src/components/product-plan.test.ts +23 -5
- package/src/components/product-plan.ts +248 -25
- package/src/floor-table.data.ts +37 -23
- package/src/lexicon-module.ts +6 -2
- package/src/lexicon.ts +78 -1
- package/src/lifecycle/gate-applied.ts +7 -0
- package/src/op/apply-status.test.ts +83 -0
- package/src/op/apply-status.ts +132 -0
- package/src/op/before-merge-decide.ts +190 -0
- package/src/op/before-merge-done.ts +99 -0
- package/src/op/before-merge-store.ts +44 -0
- package/src/op/before-merge.test.ts +201 -0
- package/src/op/before-merge.ts +266 -0
- package/src/op/follow-on-run.ts +206 -0
- package/src/op/follow-on-store.ts +54 -0
- package/src/op/gate.ts +16 -1
- package/src/op/index.ts +5 -0
- package/src/op/op-waves-after-plan.ts +13 -0
- package/src/op/op-waves-evidence-jobs.ts +11 -3
- package/src/op/op-waves-follow-on-record.test.ts +152 -0
- package/src/op/op-waves-follow-on.test.ts +247 -0
- package/src/op/op-waves-follow-on.ts +385 -0
- package/src/op/op-waves-render-spec.test.ts +1 -2
- package/src/op/op-waves-run.ts +971 -93
- package/src/op/op-waves-split-product.test.ts +288 -0
- package/src/op/op-waves-split-step.test.ts +298 -0
- package/src/op/op-waves-split.test.ts +196 -0
- package/src/op/op-waves-split.ts +189 -0
- package/src/op/op-waves.ts +28 -3
- package/src/op/schedule-overdue.test.ts +29 -1
- package/src/op/schedule-overdue.ts +27 -3
- package/src/op/stage-hooks.ts +52 -4
- package/src/op/wave-stop.ts +5 -3
- package/src/planned-files.test.ts +33 -0
- package/src/planned-files.ts +26 -10
- package/src/pr-post.ts +13 -5
- package/src/release-floors.ts +31 -19
- package/src/wave-blocked.ts +9 -4
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #4998: the guard admits a follow-on run only for the wave the newest
|
|
3
|
+
* record job of its chain started, as its record on `chant/lifecycle`
|
|
4
|
+
* names it. A wave started by hand past it (wave N+3 of a chain at N+1),
|
|
5
|
+
* or an earlier wave run again after the chain went on, is refused, on
|
|
6
|
+
* each forge, by checkJob and by the `node -e` program alike.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { spawnSync } from "node:child_process";
|
|
10
|
+
import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
|
|
11
|
+
import { tmpdir } from "node:os";
|
|
12
|
+
import { join } from "node:path";
|
|
13
|
+
import { beforeAll, describe, expect, test } from "vitest";
|
|
14
|
+
import { checkJob, describeJobGuard, JOB_GUARD_ENV, JOB_GUARD_JS, jobSeen, type JobGuardForge, type JobGuardSpec } from "./ci-job-guard";
|
|
15
|
+
import { CHANT_EXIT } from "./exit-codes";
|
|
16
|
+
import { beforeMergeDigest, beforeMergePath, renderBeforeMerge, type BeforeMergeRecord } from "./op/before-merge";
|
|
17
|
+
import { followOnPath, followOnRecordProblems, parseFollowOn, renderFollowOn, type FollowOnRecord } from "./op/follow-on-run";
|
|
18
|
+
|
|
19
|
+
const HEAD = "a".repeat(40);
|
|
20
|
+
const BASE = "c".repeat(40);
|
|
21
|
+
const PUSHED = "d".repeat(40);
|
|
22
|
+
const UNRECORDED = "e".repeat(40);
|
|
23
|
+
const decision = { pr: 7, head: HEAD, base: BASE, at: "2026-11-10T12:00:00.000Z", by: "alice" };
|
|
24
|
+
const record: BeforeMergeRecord = { ...decision, digest: beforeMergeDigest("deploy", decision) };
|
|
25
|
+
const decided = { CHANT_BEFORE_MERGE_PR: "7", CHANT_BEFORE_MERGE_HEAD: HEAD, CHANT_BEFORE_MERGE_DIGEST: record.digest };
|
|
26
|
+
|
|
27
|
+
// The rest wave is wave 3 (N); its record job started wave 4 (N+1), which is where each chain stands.
|
|
28
|
+
const chained = (key: string, wave: number, extra: Partial<FollowOnRecord> = {}): FollowOnRecord => ({ key, wave, from: wave - 1, run: "41", at: "2026-11-10T12:30:00.000Z", outcomes: { vpc: { status: "applied", wave: 3, at: "2026-11-10T12:20:00.000Z" } }, ...extra });
|
|
29
|
+
const headChain = chained(HEAD, 4, { pr: 7, digest: record.digest });
|
|
30
|
+
const pushChain = chained(PUSHED, 4, { commit: PUSHED });
|
|
31
|
+
const restOn = (forge: JobGuardForge): JobGuardSpec => ({ forge, job: "the plan job of wave 3 (rest) of deploy", branches: ["main"], beforeMerge: { op: "deploy" }, rest: 3 });
|
|
32
|
+
|
|
33
|
+
describe("the follow-on records (#4998)", () => {
|
|
34
|
+
test("parse keeps a well-formed entry, drops a malformed one, and renders the newest chains", () => {
|
|
35
|
+
const text = renderFollowOn({ version: 1, chains: { [HEAD]: headChain, [PUSHED]: pushChain } });
|
|
36
|
+
expect(parseFollowOn(text).chains).toEqual({ [HEAD]: headChain, [PUSHED]: pushChain });
|
|
37
|
+
const bad = JSON.stringify({ version: 1, chains: { [HEAD]: { ...headChain, wave: 1 }, [PUSHED]: { ...pushChain, key: HEAD }, main: pushChain } });
|
|
38
|
+
expect(parseFollowOn(bad).chains).toEqual({});
|
|
39
|
+
expect(parseFollowOn("not json").chains).toEqual({});
|
|
40
|
+
expect(followOnPath("deploy")).toBe("_waves/deploy.follow-on.json");
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test("the lines: no record, another wave, another decision", () => {
|
|
44
|
+
expect(followOnRecordProblems("deploy", "4", HEAD, record.digest, headChain)).toEqual([]);
|
|
45
|
+
expect(followOnRecordProblems("deploy", "6", HEAD, record.digest, headChain)).toEqual([`follow-on: the newest record job of deploy for head ${HEAD.slice(0, 12)} started wave 4, and this run names wave 6`]);
|
|
46
|
+
expect(followOnRecordProblems("deploy", "4", UNRECORDED, undefined, null)).toEqual([`follow-on: no record job of deploy started a follow-on for commit ${UNRECORDED.slice(0, 12)}, so this run applies nothing`]);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe("checkJob refuses a follow-on its chain's record does not name (#4998)", () => {
|
|
51
|
+
const at = { ref: "refs/heads/main" };
|
|
52
|
+
for (const forge of ["github", "gitlab", "forgejo"] as const) {
|
|
53
|
+
const seenAt = forge === "gitlab" ? { ref: "main", refProtected: "true" } : at;
|
|
54
|
+
test(`${forge}: a wave started by hand past the chain's (wave 6 of a chain at wave 4) is refused`, () => {
|
|
55
|
+
const r = checkJob(restOn(forge), { ...seenAt, beforeMerge: { pr: "7", head: HEAD, digest: record.digest }, beforeMergeRecord: record, followOn: { wave: "6" }, followOnRecord: headChain });
|
|
56
|
+
expect(r.problems).toEqual([`follow-on: the newest record job of deploy for head ${HEAD.slice(0, 12)} started wave 4, and this run names wave 6`]);
|
|
57
|
+
expect(r.checked).not.toContain("follow-on wave 6");
|
|
58
|
+
const push = checkJob(restOn(forge), { ...seenAt, followOn: { wave: "6", commit: PUSHED }, followOnRecord: pushChain });
|
|
59
|
+
expect(push.problems).toEqual([`follow-on: the newest record job of deploy for commit ${PUSHED.slice(0, 12)} started wave 4, and this run names wave 6`]);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
test("an earlier wave run again once the chain went on is refused; the wave the record names is admitted", () => {
|
|
64
|
+
const moved = chained(PUSHED, 5, { commit: PUSHED });
|
|
65
|
+
expect(checkJob(restOn("github"), { ...at, followOn: { wave: "4", commit: PUSHED }, followOnRecord: moved }).problems).toEqual([
|
|
66
|
+
`follow-on: the newest record job of deploy for commit ${PUSHED.slice(0, 12)} started wave 5, and this run names wave 4`,
|
|
67
|
+
]);
|
|
68
|
+
expect(checkJob(restOn("github"), { ...at, followOn: { wave: "5", commit: PUSHED }, followOnRecord: moved }).checked).toContain(`follow-on wave 5 at ${PUSHED.slice(0, 12)}`);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test("records that cannot be read refuse the run, and a run that is no follow-on reads none", async () => {
|
|
72
|
+
expect(checkJob(restOn("github"), { ...at, followOn: { wave: "4", commit: PUSHED }, followOnError: "could not fetch chant/lifecycle: denied" }).problems).toEqual([
|
|
73
|
+
"follow-on: the follow-on records on chant/lifecycle could not be read: could not fetch chant/lifecycle: denied",
|
|
74
|
+
]);
|
|
75
|
+
const reads: string[] = [];
|
|
76
|
+
const reader = (_f: JobGuardForge, _e: NodeJS.ProcessEnv, path: string) => (reads.push(path), null);
|
|
77
|
+
await jobSeen(restOn("github"), { GITHUB_REF: "refs/heads/main", CHANT_WAVES_WAVE: "3" }, fetch, reader);
|
|
78
|
+
await jobSeen(restOn("github"), { GITHUB_REF: "refs/heads/main", CHANT_WAVES_WAVE: "2", CHANT_WAVES_COMMIT: PUSHED }, fetch, reader);
|
|
79
|
+
expect(reads).toEqual([]);
|
|
80
|
+
const seen = await jobSeen(restOn("github"), { GITHUB_REF: "refs/heads/main", CHANT_WAVES_WAVE: "4", CHANT_WAVES_COMMIT: PUSHED }, fetch, reader);
|
|
81
|
+
expect(reads).toEqual(["_waves/deploy.follow-on.json"]);
|
|
82
|
+
expect(seen.followOnRecord).toBeNull();
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
describe("the node -e program agrees on each forge (#4998)", () => {
|
|
87
|
+
let server = "";
|
|
88
|
+
beforeAll(() => {
|
|
89
|
+
server = mkdtempSync(join(tmpdir(), "chant-guard-follow-on-record-"));
|
|
90
|
+
const work = mkdtempSync(join(tmpdir(), "chant-guard-follow-on-record-work-"));
|
|
91
|
+
const git = (cwd: string, ...args: string[]) => {
|
|
92
|
+
const r = spawnSync("git", args, { cwd, encoding: "utf-8", env: { ...process.env, GIT_AUTHOR_NAME: "t", GIT_AUTHOR_EMAIL: "t@t", GIT_COMMITTER_NAME: "t", GIT_COMMITTER_EMAIL: "t@t" } });
|
|
93
|
+
if (r.status !== 0) throw new Error(r.stderr);
|
|
94
|
+
};
|
|
95
|
+
mkdirSync(join(server, "acme"), { recursive: true });
|
|
96
|
+
git(join(server, "acme"), "init", "-q", "--bare", "infra.git");
|
|
97
|
+
git(work, "init", "-q", "-b", "chant/lifecycle");
|
|
98
|
+
mkdirSync(join(work, "_waves"));
|
|
99
|
+
writeFileSync(join(work, beforeMergePath("deploy")), renderBeforeMerge({ version: 1, heads: { [HEAD]: record } }));
|
|
100
|
+
writeFileSync(join(work, followOnPath("deploy")), renderFollowOn({ version: 1, chains: { [HEAD]: headChain, [PUSHED]: pushChain } }));
|
|
101
|
+
git(work, "add", ".");
|
|
102
|
+
git(work, "commit", "-q", "-m", "decide and follow on");
|
|
103
|
+
git(work, "push", "-q", join(server, "acme", "infra.git"), "chant/lifecycle");
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const node = (spec: JobGuardSpec, env: Record<string, string>) =>
|
|
107
|
+
spawnSync(process.execPath, ["-e", JOB_GUARD_JS], { env: { PATH: process.env.PATH ?? "", HOME: process.env.HOME ?? "", [JOB_GUARD_ENV]: JSON.stringify(spec), ...env }, encoding: "utf-8" });
|
|
108
|
+
const forgeEnv = (forge: JobGuardForge): Record<string, string> =>
|
|
109
|
+
forge === "gitlab"
|
|
110
|
+
? { CI_SERVER_URL: `file://${server}`, CI_PROJECT_PATH: "acme/infra", CI_JOB_TOKEN: "t", CI_COMMIT_REF_NAME: "main", CI_COMMIT_REF_PROTECTED: "true" }
|
|
111
|
+
: { GITHUB_SERVER_URL: `file://${server}`, GITHUB_REPOSITORY: "acme/infra", GITHUB_TOKEN: "t", GITHUB_REF: "refs/heads/main" };
|
|
112
|
+
|
|
113
|
+
const cases: Array<[string, JobGuardForge, Record<string, string>, boolean]> = [];
|
|
114
|
+
for (const forge of ["github", "gitlab", "forgejo"] as const) {
|
|
115
|
+
cases.push(
|
|
116
|
+
[`${forge}: the wave the record job started, of the decided head`, forge, { ...decided, CHANT_WAVES_WAVE: "4" }, true],
|
|
117
|
+
[`${forge}: a wave started by hand past it, of the decided head`, forge, { ...decided, CHANT_WAVES_WAVE: "6" }, false],
|
|
118
|
+
[`${forge}: the wave the record job started, of a push`, forge, { CHANT_WAVES_WAVE: "4", CHANT_WAVES_COMMIT: PUSHED }, true],
|
|
119
|
+
[`${forge}: a wave started by hand past it, of a push`, forge, { CHANT_WAVES_WAVE: "6", CHANT_WAVES_COMMIT: PUSHED }, false],
|
|
120
|
+
[`${forge}: a push no record job followed on`, forge, { CHANT_WAVES_WAVE: "4", CHANT_WAVES_COMMIT: UNRECORDED }, false],
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
for (const [name, forge, extra, ok] of cases) {
|
|
125
|
+
test(name, async () => {
|
|
126
|
+
const spec = restOn(forge);
|
|
127
|
+
const env = { ...forgeEnv(forge), ...extra };
|
|
128
|
+
const r = node(spec, env);
|
|
129
|
+
const want = describeJobGuard(spec, checkJob(spec, await jobSeen(spec, { ...process.env, ...env }, (() => Promise.reject(new Error("no fetch"))) as unknown as typeof fetch)));
|
|
130
|
+
expect(want.ok).toBe(ok);
|
|
131
|
+
expect(r.status).toBe(ok ? 0 : CHANT_EXIT.misplaced);
|
|
132
|
+
expect(r.stdout.trim().split("\n").filter(Boolean)).toEqual(want.out);
|
|
133
|
+
expect(r.stderr.trim().split("\n").filter(Boolean)).toEqual(want.err);
|
|
134
|
+
if (!ok) expect(want.err[0]).toMatch(/follow-on: (the newest record job of deploy .* started wave 4, and this run names wave 6|no record job of deploy started a follow-on)/);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
});
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #4992: the guard admits a follow-on run of the rest wave only in a job of
|
|
3
|
+
* the rest wave, only for a wave after it, and only as the same decided
|
|
4
|
+
* head: a follow-on for another head or digest is refused as any run of
|
|
5
|
+
* one is. A push's follow-on names its commit. The `node -e` program agrees
|
|
6
|
+
* with checkJob, reading the decision from a real repository.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { spawnSync } from "node:child_process";
|
|
10
|
+
import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
|
|
11
|
+
import { tmpdir } from "node:os";
|
|
12
|
+
import { join } from "node:path";
|
|
13
|
+
import { beforeAll, describe, expect, test } from "vitest";
|
|
14
|
+
import { checkJob, describeJobGuard, JOB_GUARD_ENV, JOB_GUARD_JS, jobGuardSpec, jobSeen, parseJobGuardSpec, type JobGuardSpec } from "./ci-job-guard";
|
|
15
|
+
import { CHANT_EXIT } from "./exit-codes";
|
|
16
|
+
import { beforeMergeDigest, beforeMergePath, renderBeforeMerge, type BeforeMergeRecord } from "./op/before-merge";
|
|
17
|
+
import { followOnPath, renderFollowOn, type FollowOnRecord } from "./op/follow-on-run";
|
|
18
|
+
|
|
19
|
+
const HEAD = "a".repeat(40);
|
|
20
|
+
const OTHER = "b".repeat(40);
|
|
21
|
+
const BASE = "c".repeat(40);
|
|
22
|
+
const PUSHED = "d".repeat(40);
|
|
23
|
+
const decision = { pr: 7, head: HEAD, base: BASE, at: "2026-11-10T12:00:00.000Z", by: "alice" };
|
|
24
|
+
const record: BeforeMergeRecord = { ...decision, digest: beforeMergeDigest("deploy", decision) };
|
|
25
|
+
const run = { pr: "7", head: HEAD, digest: record.digest };
|
|
26
|
+
|
|
27
|
+
/** #4998: the record a record job wrote when it started wave `wave` of the chain keyed `key`. */
|
|
28
|
+
const chained = (key: string, wave: number, extra: Partial<FollowOnRecord> = {}): FollowOnRecord => ({ key, wave, from: wave - 1, run: "41", at: "2026-11-10T12:30:00.000Z", outcomes: {}, ...extra });
|
|
29
|
+
const headChain = chained(HEAD, 4, { pr: 7, digest: record.digest });
|
|
30
|
+
const pushChain = chained(PUSHED, 4, { commit: PUSHED });
|
|
31
|
+
|
|
32
|
+
const rest: JobGuardSpec ={ forge: "github", job: "the plan job of wave 3 (rest) of deploy", branches: ["main"], beforeMerge: { op: "deploy" }, rest: 3 };
|
|
33
|
+
const earlier: JobGuardSpec = { forge: "github", job: "the plan job of wave 2 (layer) of deploy", branches: ["main"], beforeMerge: { op: "deploy" } };
|
|
34
|
+
const at = { ref: "refs/heads/main" };
|
|
35
|
+
|
|
36
|
+
describe("checkJob in a follow-on run (#4992)", () => {
|
|
37
|
+
test("the rest wave's jobs admit a follow-on of the decided head for a later wave", () => {
|
|
38
|
+
const r = checkJob(rest, { ...at, beforeMerge: run, beforeMergeRecord: record, followOn: { wave: "4" }, followOnRecord: headChain });
|
|
39
|
+
expect(r.problems).toEqual([]);
|
|
40
|
+
expect(r.checked).toEqual(["ref refs/heads/main", `before merge: pull request 7's decided head ${HEAD.slice(0, 12)}`, "follow-on wave 4"]);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test("a follow-on for another head or another digest is refused", () => {
|
|
44
|
+
expect(checkJob(rest, { ...at, beforeMerge: { ...run, head: OTHER }, beforeMergeRecord: null, followOn: { wave: "4" }, followOnRecord: null }).problems).toEqual([
|
|
45
|
+
`before merge: no decision on chant/lifecycle names head ${OTHER.slice(0, 12)} of deploy, so this run applies nothing`,
|
|
46
|
+
`follow-on: no record job of deploy started a follow-on for head ${OTHER.slice(0, 12)}, so this run applies nothing`,
|
|
47
|
+
]);
|
|
48
|
+
const other = `sha256:${"0".repeat(64)}`;
|
|
49
|
+
expect(checkJob(rest, { ...at, beforeMerge: { ...run, digest: other }, beforeMergeRecord: record, followOn: { wave: "4" }, followOnRecord: headChain }).problems).toEqual([
|
|
50
|
+
`before merge: the run carries digest ${other}, and the decision for head ${HEAD.slice(0, 12)} has ${record.digest}`,
|
|
51
|
+
`follow-on: wave 4 of head ${HEAD.slice(0, 12)} was started for the decision with digest ${record.digest}, and the run carries ${other}`,
|
|
52
|
+
]);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test("the rest wave's own number is no follow-on, and a run that is none is checked as before", () => {
|
|
56
|
+
expect(checkJob(rest, { ...at, beforeMerge: run, beforeMergeRecord: record, followOn: { wave: "3" } }).problems).toEqual([]);
|
|
57
|
+
expect(checkJob(rest, { ...at }).checked).toEqual(["ref refs/heads/main"]);
|
|
58
|
+
expect(checkJob(earlier, { ...at }).checked).toEqual(["ref refs/heads/main"]);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test("a wave that is not after the rest wave, a job of another wave, and a commit beside a decided head are refused", () => {
|
|
62
|
+
expect(checkJob(rest, { ...at, beforeMerge: run, beforeMergeRecord: record, followOn: { wave: "2" } }).problems).toEqual(['follow-on: the run\'s wave "2" is no wave after wave 3']);
|
|
63
|
+
expect(checkJob(rest, { ...at, beforeMerge: run, beforeMergeRecord: record, followOn: { wave: "4; rm -rf /" } }).problems).toEqual(['follow-on: the run\'s wave "4; rm -rf /" is no wave after wave 3']);
|
|
64
|
+
expect(checkJob(earlier, { ...at, beforeMerge: run, beforeMergeRecord: record, followOn: { wave: "4" } }).problems).toEqual([
|
|
65
|
+
"follow-on: the run names wave 4 and commit none, and this job is none of the rest wave's, which alone runs in a follow-on",
|
|
66
|
+
]);
|
|
67
|
+
expect(checkJob(rest, { ...at, beforeMerge: run, beforeMergeRecord: record, followOn: { wave: "4", commit: PUSHED } }).problems).toEqual([
|
|
68
|
+
`follow-on: a follow-on of a decided head checks out that head, and the run names the commit ${PUSHED} too`,
|
|
69
|
+
]);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test("a push's follow-on names the commit it goes on with", () => {
|
|
73
|
+
const r = checkJob(rest, { ...at, followOn: { wave: "4", commit: PUSHED }, followOnRecord: pushChain });
|
|
74
|
+
expect(r.problems).toEqual([]);
|
|
75
|
+
expect(r.checked).toEqual(["ref refs/heads/main", `follow-on wave 4 at ${PUSHED.slice(0, 12)}`]);
|
|
76
|
+
expect(checkJob(rest, { ...at, followOn: { wave: "4" } }).problems).toEqual(["follow-on: a push's follow-on names the commit it goes on with, and the run's none is not a commit sha"]);
|
|
77
|
+
expect(checkJob(rest, { ...at, followOn: { wave: "4", commit: "main" } }).problems).toEqual(['follow-on: a push\'s follow-on names the commit it goes on with, and the run\'s "main" is not a commit sha']);
|
|
78
|
+
expect(checkJob(rest, { ...at, followOn: { commit: PUSHED } }).problems).toEqual([`follow-on: the run names the commit ${PUSHED} and no wave after wave 3, so it is no follow-on`]);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test("jobGuardSpec carries the rest wave, the parse checks it, and jobSeen reads the variables", async () => {
|
|
82
|
+
expect(jobGuardSpec({ forge: "gitlab", job: "w", branches: ["main"], rest: 3 }).rest).toBe(3);
|
|
83
|
+
expect(() => parseJobGuardSpec(JSON.stringify({ ...rest, rest: "3" }))).toThrow("rest is the rest wave's number");
|
|
84
|
+
const seen = await jobSeen(rest, { GITHUB_REF: "refs/heads/main", CHANT_WAVES_WAVE: " 4 ", CHANT_WAVES_COMMIT: PUSHED });
|
|
85
|
+
expect(seen.followOn).toEqual({ wave: "4", commit: PUSHED });
|
|
86
|
+
expect((await jobSeen(rest, { GITHUB_REF: "refs/heads/main" })).followOn).toBeUndefined();
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
describe("the node -e program agrees in a follow-on run", () => {
|
|
91
|
+
let server = "";
|
|
92
|
+
beforeAll(() => {
|
|
93
|
+
server = mkdtempSync(join(tmpdir(), "chant-guard-follow-on-"));
|
|
94
|
+
const work = mkdtempSync(join(tmpdir(), "chant-guard-follow-on-work-"));
|
|
95
|
+
const git = (cwd: string, ...args: string[]) => {
|
|
96
|
+
const r = spawnSync("git", args, { cwd, encoding: "utf-8", env: { ...process.env, GIT_AUTHOR_NAME: "t", GIT_AUTHOR_EMAIL: "t@t", GIT_COMMITTER_NAME: "t", GIT_COMMITTER_EMAIL: "t@t" } });
|
|
97
|
+
if (r.status !== 0) throw new Error(r.stderr);
|
|
98
|
+
};
|
|
99
|
+
mkdirSync(join(server, "acme"), { recursive: true });
|
|
100
|
+
git(join(server, "acme"), "init", "-q", "--bare", "infra.git");
|
|
101
|
+
git(work, "init", "-q", "-b", "chant/lifecycle");
|
|
102
|
+
mkdirSync(join(work, "_waves"));
|
|
103
|
+
writeFileSync(join(work, beforeMergePath("deploy")), renderBeforeMerge({ version: 1, heads: { [HEAD]: record } }));
|
|
104
|
+
writeFileSync(join(work, followOnPath("deploy")), renderFollowOn({ version: 1, chains: { [HEAD]: headChain, [PUSHED]: pushChain } }));
|
|
105
|
+
git(work, "add", ".");
|
|
106
|
+
git(work, "commit", "-q", "-m", "decide");
|
|
107
|
+
git(work, "push", "-q", join(server, "acme", "infra.git"), "chant/lifecycle");
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
const node = (spec: JobGuardSpec, env: Record<string, string>) =>
|
|
111
|
+
spawnSync(process.execPath, ["-e", JOB_GUARD_JS], { env: { PATH: process.env.PATH ?? "", HOME: process.env.HOME ?? "", [JOB_GUARD_ENV]: JSON.stringify(spec), ...env }, encoding: "utf-8" });
|
|
112
|
+
const forgeEnv = (spec: JobGuardSpec): Record<string, string> =>
|
|
113
|
+
spec.forge === "gitlab"
|
|
114
|
+
? { CI_SERVER_URL: `file://${server}`, CI_PROJECT_PATH: "acme/infra", CI_JOB_TOKEN: "t", CI_COMMIT_REF_NAME: "main", CI_COMMIT_REF_PROTECTED: "true" }
|
|
115
|
+
: { GITHUB_SERVER_URL: `file://${server}`, GITHUB_REPOSITORY: "acme/infra", GITHUB_TOKEN: "t", GITHUB_REF: "refs/heads/main" };
|
|
116
|
+
const decided = { CHANT_BEFORE_MERGE_PR: "7", CHANT_BEFORE_MERGE_HEAD: HEAD, CHANT_BEFORE_MERGE_DIGEST: record.digest };
|
|
117
|
+
const gl: JobGuardSpec = { ...rest, forge: "gitlab" };
|
|
118
|
+
const fj: JobGuardSpec = { ...rest, forge: "forgejo" };
|
|
119
|
+
|
|
120
|
+
const cases: Array<[string, JobGuardSpec, Record<string, string>, boolean]> = [
|
|
121
|
+
["GitHub: a follow-on of the decided head", rest, { ...decided, CHANT_WAVES_WAVE: "4" }, true],
|
|
122
|
+
["GitLab: a follow-on of the decided head", gl, { ...decided, CHANT_WAVES_WAVE: "4" }, true],
|
|
123
|
+
["Forgejo: a push's follow-on", fj, { CHANT_WAVES_WAVE: "4", CHANT_WAVES_COMMIT: PUSHED }, true],
|
|
124
|
+
["GitHub: the rest wave's own number in a run that is none", rest, { ...decided, CHANT_WAVES_WAVE: "3" }, true],
|
|
125
|
+
["GitHub: a follow-on for another head", rest, { ...decided, CHANT_BEFORE_MERGE_HEAD: OTHER, CHANT_WAVES_WAVE: "4" }, false],
|
|
126
|
+
["GitLab: a follow-on for another digest", gl, { ...decided, CHANT_BEFORE_MERGE_DIGEST: `sha256:${"0".repeat(64)}`, CHANT_WAVES_WAVE: "4" }, false],
|
|
127
|
+
["Forgejo: a follow-on in a job of an earlier wave", { ...earlier, forge: "forgejo" }, { ...decided, CHANT_WAVES_WAVE: "4" }, false],
|
|
128
|
+
["GitHub: a wave before the rest wave", rest, { ...decided, CHANT_WAVES_WAVE: "1" }, false],
|
|
129
|
+
["GitLab: a push's follow-on with no commit", gl, { CHANT_WAVES_WAVE: "4" }, false],
|
|
130
|
+
["GitHub: a commit beside a decided head", rest, { ...decided, CHANT_WAVES_WAVE: "4", CHANT_WAVES_COMMIT: PUSHED }, false],
|
|
131
|
+
];
|
|
132
|
+
|
|
133
|
+
for (const [name, spec, extra, ok] of cases) {
|
|
134
|
+
test(name, async () => {
|
|
135
|
+
const env = { ...forgeEnv(spec), ...extra };
|
|
136
|
+
const r = node(spec, env);
|
|
137
|
+
const want = describeJobGuard(spec, checkJob(spec, await jobSeen(spec, { ...process.env, ...env }, (() => Promise.reject(new Error("no fetch"))) as unknown as typeof fetch)));
|
|
138
|
+
expect(want.ok).toBe(ok);
|
|
139
|
+
expect(r.status).toBe(ok ? 0 : CHANT_EXIT.misplaced);
|
|
140
|
+
expect(r.stdout.trim().split("\n").filter(Boolean)).toEqual(want.out);
|
|
141
|
+
expect(r.stderr.trim().split("\n").filter(Boolean)).toEqual(want.err);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
});
|
package/src/ci-job-guard.ts
CHANGED
|
@@ -41,9 +41,41 @@
|
|
|
41
41
|
* label. Someone who can edit the workflow can delete it too: the forge's
|
|
42
42
|
* environment and runner settings and the cloud role's trust are what keep
|
|
43
43
|
* a job out.
|
|
44
|
+
*
|
|
45
|
+
* Before merge (#4984): a waves workflow with a before-merge mode carries
|
|
46
|
+
* `beforeMerge: { op }`. A run started for an open pull request's head
|
|
47
|
+
* names it in `CHANT_BEFORE_MERGE_PR`, `CHANT_BEFORE_MERGE_HEAD` and
|
|
48
|
+
* `CHANT_BEFORE_MERGE_DIGEST` (./op/before-merge.ts), and still runs on one
|
|
49
|
+
* of the spec's branches. The guard then fetches `chant/lifecycle` into a
|
|
50
|
+
* directory of its own, with the job's token (GitHub and Forgejo
|
|
51
|
+
* `GITHUB_TOKEN`, GitLab `CI_JOB_TOKEN`), reads the decision for that head,
|
|
52
|
+
* and admits the run only when the pull request and the digest are the
|
|
53
|
+
* decision's and the decision's fields still give its digest. A job of a
|
|
54
|
+
* workflow without the mode refuses any run that names a head.
|
|
55
|
+
*
|
|
56
|
+
* A follow-on run (#4992, ./op/follow-on-run.ts): a job of a `rest` wave
|
|
57
|
+
* carries `rest: <its wave number>`. A run the rest wave's record job
|
|
58
|
+
* started names a later wave in `CHANT_WAVES_WAVE`, with the same decision
|
|
59
|
+
* (admitted as above, so a follow-on for another head or digest is refused)
|
|
60
|
+
* or, for a push, the pushed commit in `CHANT_WAVES_COMMIT`. The guard
|
|
61
|
+
* admits it only in a job of the rest wave and only for a wave after it; any
|
|
62
|
+
* other job refuses a run that names either variable.
|
|
63
|
+
*
|
|
64
|
+
* #4998: and only for the wave the newest record job of its chain started.
|
|
65
|
+
* The guard reads the follow-on records of the op (`_waves/<op>.follow-on.json`
|
|
66
|
+
* on `chant/lifecycle`, as it reads the decisions) and admits the run when
|
|
67
|
+
* the entry for its decided head, or a push's commit, names the run's wave
|
|
68
|
+
* and, before merge, the run's decision digest. A wave started by hand past
|
|
69
|
+
* the one the chain reached is refused, though each wave's gate would ask.
|
|
44
70
|
*/
|
|
71
|
+
import { spawnSync } from "node:child_process";
|
|
72
|
+
import { mkdtempSync } from "node:fs";
|
|
73
|
+
import { tmpdir } from "node:os";
|
|
74
|
+
import { join } from "node:path";
|
|
45
75
|
import { isRunnerGroup, type CiRunner } from "./ci-jobs";
|
|
46
76
|
import { CHANT_EXIT } from "./exit-codes";
|
|
77
|
+
import { BEFORE_MERGE_DIGEST_ENV, BEFORE_MERGE_HEAD_ENV, BEFORE_MERGE_PR_ENV, beforeMergePath, beforeMergeProblems, beforeMergeRunFromEnv, isBeforeMergeRun, parseBeforeMerge, type BeforeMergeRecord, type BeforeMergeRun } from "./op/before-merge";
|
|
78
|
+
import { followOnPath, followOnProblems, followOnRecordProblems, followOnRunFromEnv, OP_WAVES_COMMIT_ENV, OP_WAVES_WAVE_ENV, parseFollowOn, type FollowOnRecord, type FollowOnRun } from "./op/follow-on-run";
|
|
47
79
|
|
|
48
80
|
/** The variable the generated step carries its expectation in. */
|
|
49
81
|
export const JOB_GUARD_ENV = "CHANT_JOB_GUARD";
|
|
@@ -68,6 +100,10 @@ export interface JobGuardSpec {
|
|
|
68
100
|
runnerTags?: string[];
|
|
69
101
|
/** GitHub and Forgejo: the runner must be self-hosted. */
|
|
70
102
|
selfHosted?: boolean;
|
|
103
|
+
/** The waves have a before-merge mode (#4984): a run that names a head runs only as op `op`'s recorded decision. */
|
|
104
|
+
beforeMerge?: { op: string };
|
|
105
|
+
/** The job is one of the `rest` wave's (#4992), rendered as this wave: a follow-on run may name a later one. */
|
|
106
|
+
rest?: number;
|
|
71
107
|
}
|
|
72
108
|
|
|
73
109
|
/** What the job sees. Undefined: the forge did not say. */
|
|
@@ -80,6 +116,18 @@ export interface JobSeen {
|
|
|
80
116
|
refProtected?: string;
|
|
81
117
|
runnerTags?: string[];
|
|
82
118
|
runnerEnvironment?: string;
|
|
119
|
+
/** The decision the run names (#4984), from its variables. */
|
|
120
|
+
beforeMerge?: BeforeMergeRun;
|
|
121
|
+
/** The recorded decision for that head; null when there is none. Read only when the spec has a before-merge mode. */
|
|
122
|
+
beforeMergeRecord?: BeforeMergeRecord | null;
|
|
123
|
+
/** Why the decisions could not be read, when they could not. */
|
|
124
|
+
beforeMergeError?: string;
|
|
125
|
+
/** The follow-on variables the run names (#4992). */
|
|
126
|
+
followOn?: FollowOnRun;
|
|
127
|
+
/** The follow-on record of the run's chain (#4998); null when there is none. Read only for a follow-on the rest wave's job would admit. */
|
|
128
|
+
followOnRecord?: FollowOnRecord | null;
|
|
129
|
+
/** Why the follow-on records could not be read, when they could not. */
|
|
130
|
+
followOnError?: string;
|
|
83
131
|
}
|
|
84
132
|
|
|
85
133
|
export interface JobGuardResult {
|
|
@@ -104,6 +152,10 @@ export interface JobGuardInput {
|
|
|
104
152
|
runner?: CiRunner;
|
|
105
153
|
/** GitHub: the job may request an OIDC token (`id-token: write`), so the guard can read its environment. */
|
|
106
154
|
idToken?: boolean;
|
|
155
|
+
/** The waves' before-merge mode (#4984), with the op its decisions are recorded under. */
|
|
156
|
+
beforeMerge?: { op: string };
|
|
157
|
+
/** The job is one of the `rest` wave's (#4992), whose number this is. */
|
|
158
|
+
rest?: number;
|
|
107
159
|
}
|
|
108
160
|
|
|
109
161
|
/**
|
|
@@ -121,6 +173,8 @@ export function jobGuardSpec(input: JobGuardInput): JobGuardSpec {
|
|
|
121
173
|
branches: [...input.branches],
|
|
122
174
|
...(input.forge === "gitlab" && labels.length > 0 ? { runnerTags: labels } : {}),
|
|
123
175
|
...(input.forge !== "gitlab" && labels.includes("self-hosted") ? { selfHosted: true } : {}),
|
|
176
|
+
...(input.beforeMerge ? { beforeMerge: { op: input.beforeMerge.op } } : {}),
|
|
177
|
+
...(input.rest !== undefined ? { rest: input.rest } : {}),
|
|
124
178
|
};
|
|
125
179
|
}
|
|
126
180
|
|
|
@@ -140,6 +194,8 @@ export function parseJobGuardSpec(raw: string | undefined): JobGuardSpec {
|
|
|
140
194
|
if (!Array.isArray(o.branches) || o.branches.some((b) => typeof b !== "string")) throw new Error(`${JOB_GUARD_ENV}.branches is not a list of branches`);
|
|
141
195
|
if (o.forgeEnvironment !== undefined && typeof o.forgeEnvironment !== "string") throw new Error(`${JOB_GUARD_ENV}.forgeEnvironment is not a name`);
|
|
142
196
|
if (o.runnerTags !== undefined && (!Array.isArray(o.runnerTags) || o.runnerTags.some((t) => typeof t !== "string"))) throw new Error(`${JOB_GUARD_ENV}.runnerTags is not a list of tags`);
|
|
197
|
+
if (o.beforeMerge !== undefined && (typeof o.beforeMerge !== "object" || o.beforeMerge === null || typeof o.beforeMerge.op !== "string")) throw new Error(`${JOB_GUARD_ENV}.beforeMerge is { op }`);
|
|
198
|
+
if (o.rest !== undefined && (!Number.isInteger(o.rest) || o.rest < 1)) throw new Error(`${JOB_GUARD_ENV}.rest is the rest wave's number`);
|
|
143
199
|
return o as JobGuardSpec;
|
|
144
200
|
}
|
|
145
201
|
|
|
@@ -194,6 +250,34 @@ export function checkJob(expect: JobGuardSpec, seen: JobSeen): JobGuardResult {
|
|
|
194
250
|
else out.checked.push(`ref ${seen.ref}`);
|
|
195
251
|
}
|
|
196
252
|
|
|
253
|
+
// #4984: a run started for an open pull request's head runs only as the decision recorded for it.
|
|
254
|
+
const run = seen.beforeMerge;
|
|
255
|
+
if (run && isBeforeMergeRun(run)) {
|
|
256
|
+
if (!expect.beforeMerge) out.problems.push(`before merge: the run names pull request ${run.pr ?? "none"}'s head ${run.head ?? "none"}, and this job applies only the pushes to its branches`);
|
|
257
|
+
else if (seen.beforeMergeError !== undefined) out.problems.push(`before merge: the decisions on chant/lifecycle could not be read: ${seen.beforeMergeError}`);
|
|
258
|
+
else {
|
|
259
|
+
const problems = beforeMergeProblems(expect.beforeMerge.op, run, seen.beforeMergeRecord ?? undefined);
|
|
260
|
+
if (problems.length > 0) out.problems.push(...problems);
|
|
261
|
+
else out.checked.push(`before merge: pull request ${run.pr}'s decided head ${run.head!.slice(0, 12)}`);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// #4992: a follow-on run of the rest wave, admitted in the rest wave's jobs alone and for a later wave.
|
|
266
|
+
const bmRun = run !== undefined && isBeforeMergeRun(run);
|
|
267
|
+
const follow = followOnProblems(expect.rest, seen.followOn ?? {}, bmRun);
|
|
268
|
+
out.problems.push(...follow.problems);
|
|
269
|
+
if (follow.checked) {
|
|
270
|
+
// #4998: and only for the wave the newest record job of its chain started.
|
|
271
|
+
const key = (bmRun ? run!.head : seen.followOn?.commit) ?? "";
|
|
272
|
+
const rec = !expect.beforeMerge
|
|
273
|
+
? ["follow-on: this job names no op whose follow-on records it reads, so it admits no follow-on"]
|
|
274
|
+
: seen.followOnError !== undefined
|
|
275
|
+
? [`follow-on: the follow-on records on chant/lifecycle could not be read: ${seen.followOnError}`]
|
|
276
|
+
: followOnRecordProblems(expect.beforeMerge.op, seen.followOn!.wave!, key, bmRun ? (run!.digest ?? "") : undefined, seen.followOnRecord);
|
|
277
|
+
if (rec.length > 0) out.problems.push(...rec);
|
|
278
|
+
else out.checked.push(follow.checked);
|
|
279
|
+
}
|
|
280
|
+
|
|
197
281
|
if (expect.forge === "gitlab") {
|
|
198
282
|
const want = expect.runnerTags ?? [];
|
|
199
283
|
if (want.length > 0) {
|
|
@@ -224,7 +308,71 @@ async function githubClaims(env: NodeJS.ProcessEnv, fetchFn: typeof fetch): Prom
|
|
|
224
308
|
}
|
|
225
309
|
|
|
226
310
|
/** What the job sees, from the forge's variables, and on GitHub from its token's claims when the forge environment is to be checked. */
|
|
227
|
-
export async function jobSeen(expect: JobGuardSpec, env: NodeJS.ProcessEnv = process.env, fetchFn: typeof fetch = fetch): Promise<JobSeen> {
|
|
311
|
+
export async function jobSeen(expect: JobGuardSpec, env: NodeJS.ProcessEnv = process.env, fetchFn: typeof fetch = fetch, readLifecycle: LifecycleFileReader = lifecycleFileByGit): Promise<JobSeen> {
|
|
312
|
+
const seen = await forgeSeen(expect, env, fetchFn);
|
|
313
|
+
// #4992: the follow-on variables, whatever else the run names.
|
|
314
|
+
const follow = followOnRunFromEnv(env);
|
|
315
|
+
if (follow.wave !== undefined || follow.commit !== undefined) seen.followOn = follow;
|
|
316
|
+
// #4984: the decision a run names, read only when the spec has a before-merge mode.
|
|
317
|
+
const run = beforeMergeRunFromEnv(env);
|
|
318
|
+
const bm = isBeforeMergeRun(run);
|
|
319
|
+
if (bm) {
|
|
320
|
+
seen.beforeMerge = run;
|
|
321
|
+
if (expect.beforeMerge && run.head) {
|
|
322
|
+
try {
|
|
323
|
+
const text = readLifecycle(expect.forge, env, beforeMergePath(expect.beforeMerge.op));
|
|
324
|
+
seen.beforeMergeRecord = parseBeforeMerge(text).heads[run.head] ?? null;
|
|
325
|
+
} catch (e) {
|
|
326
|
+
seen.beforeMergeError = (e as Error).message;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
// #4998: the record of the run's chain, read only for a follow-on the rest wave's job would admit.
|
|
331
|
+
const key = bm ? run.head : follow.commit;
|
|
332
|
+
if (expect.beforeMerge && key && followOnProblems(expect.rest, follow, bm).checked !== undefined) {
|
|
333
|
+
try {
|
|
334
|
+
seen.followOnRecord = parseFollowOn(readLifecycle(expect.forge, env, followOnPath(expect.beforeMerge.op))).chains[key] ?? null;
|
|
335
|
+
} catch (e) {
|
|
336
|
+
seen.followOnError = (e as Error).message;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
return seen;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/** Reads one file of `chant/lifecycle` as the remote has it; null when the branch has no such file (#4984). */
|
|
343
|
+
export type LifecycleFileReader = (forge: JobGuardForge, env: NodeJS.ProcessEnv, path: string) => string | null;
|
|
344
|
+
|
|
345
|
+
/** The repository's git URL and the job token's basic credentials, as the guard fetches with them (#4984). */
|
|
346
|
+
export function guardRemote(forge: JobGuardForge, env: NodeJS.ProcessEnv): { url: string; user: string; token: string } {
|
|
347
|
+
if (forge === "gitlab") {
|
|
348
|
+
if (!env.CI_SERVER_URL || !env.CI_PROJECT_PATH) throw new Error("the job names no repository (no CI_SERVER_URL or CI_PROJECT_PATH)");
|
|
349
|
+
return { url: `${env.CI_SERVER_URL.replace(/\/+$/, "")}/${env.CI_PROJECT_PATH}.git`, user: "gitlab-ci-token", token: env.CI_JOB_TOKEN ?? "" };
|
|
350
|
+
}
|
|
351
|
+
if (!env.GITHUB_SERVER_URL || !env.GITHUB_REPOSITORY) throw new Error("the job names no repository (no GITHUB_SERVER_URL or GITHUB_REPOSITORY)");
|
|
352
|
+
return { url: `${env.GITHUB_SERVER_URL.replace(/\/+$/, "")}/${env.GITHUB_REPOSITORY}.git`, user: "x-access-token", token: env.GITHUB_TOKEN ?? "" };
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* {@link LifecycleFileReader} through git: `chant/lifecycle` fetched at depth
|
|
357
|
+
* one into a directory of the guard's own, outside the checkout, with the
|
|
358
|
+
* token as a basic credential header, and the file shown from it. The
|
|
359
|
+
* `node -e` program does the same.
|
|
360
|
+
*/
|
|
361
|
+
export const lifecycleFileByGit: LifecycleFileReader = (forge, env, path) => {
|
|
362
|
+
const remote = guardRemote(forge, env);
|
|
363
|
+
const dir = mkdtempSync(join(tmpdir(), "chant-guard-"));
|
|
364
|
+
const git = (args: string[]) => spawnSync("git", args, { cwd: dir, encoding: "utf-8", env: { ...env, GIT_TERMINAL_PROMPT: "0" } });
|
|
365
|
+
const init = git(["init", "-q"]);
|
|
366
|
+
if (init.status !== 0) throw new Error(`git init failed: ${(init.stderr || "").trim()}`);
|
|
367
|
+
const auth = `Authorization: Basic ${Buffer.from(`${remote.user}:${remote.token}`).toString("base64")}`;
|
|
368
|
+
const fetched = git(["-c", `http.extraHeader=${auth}`, "fetch", "-q", "--depth=1", remote.url, "refs/heads/chant/lifecycle"]);
|
|
369
|
+
if (fetched.status !== 0) throw new Error(`could not fetch chant/lifecycle: ${(fetched.stderr || "").trim().split("\n").pop()}`);
|
|
370
|
+
const shown = git(["show", `FETCH_HEAD:${path}`]);
|
|
371
|
+
return shown.status === 0 ? shown.stdout : null;
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
/** What the forge's own variables and token say, before the decision is read. */
|
|
375
|
+
async function forgeSeen(expect: JobGuardSpec, env: NodeJS.ProcessEnv, fetchFn: typeof fetch): Promise<JobSeen> {
|
|
228
376
|
if (expect.forge === "gitlab") {
|
|
229
377
|
return {
|
|
230
378
|
forgeEnvironment: env.CI_ENVIRONMENT_NAME || null,
|
|
@@ -262,6 +410,68 @@ export function describeJobGuard(expect: JobGuardSpec, result: JobGuardResult):
|
|
|
262
410
|
return { ok: true, out: [`${at}: ${result.checked.length ? result.checked.join(", ") : "nothing to check"}${skipped}`], err: [] };
|
|
263
411
|
}
|
|
264
412
|
|
|
413
|
+
/**
|
|
414
|
+
* The before-merge part of the `node -e` program (#4984): the run's three
|
|
415
|
+
* variables, the read of `chant/lifecycle` as {@link lifecycleFileByGit}
|
|
416
|
+
* does it, the decision entry as {@link parseBeforeMerge} keeps it, and the
|
|
417
|
+
* lines of {@link beforeMergeProblems}, digest included. No single quote,
|
|
418
|
+
* since the program is one shell word in single quotes.
|
|
419
|
+
*/
|
|
420
|
+
const BM_PATH = beforeMergePath("\u0000").split("\u0000") as [string, string];
|
|
421
|
+
/** Each apostrophe in the program's strings as `'`, since the whole program is one single-quoted shell word. */
|
|
422
|
+
const noQuote = (s: string): string => s.replace(/'/g, "\\u0027");
|
|
423
|
+
const BEFORE_MERGE_JS = [
|
|
424
|
+
`const bmV=[${JSON.stringify(BEFORE_MERGE_PR_ENV)},${JSON.stringify(BEFORE_MERGE_HEAD_ENV)},${JSON.stringify(BEFORE_MERGE_DIGEST_ENV)}].map((k)=>String(E[k]||"").trim());`,
|
|
425
|
+
'const bmRun={};if(bmV[0])bmRun.pr=bmV[0];if(bmV[1])bmRun.head=bmV[1];if(bmV[2])bmRun.digest=bmV[2];const bmOn=Boolean(bmV[0]||bmV[1]||bmV[2]);',
|
|
426
|
+
"const SHA=/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;",
|
|
427
|
+
String.raw`const bmRead=(file)=>{const cp=require("child_process"),fs=require("fs"),os=require("os"),pa=require("path");let url,user,tok;`,
|
|
428
|
+
String.raw`if(x.forge==="gitlab"){if(!E.CI_SERVER_URL||!E.CI_PROJECT_PATH)throw new Error("the job names no repository (no CI_SERVER_URL or CI_PROJECT_PATH)");url=E.CI_SERVER_URL.replace(/\/+$/,"")+"/"+E.CI_PROJECT_PATH+".git";user="gitlab-ci-token";tok=E.CI_JOB_TOKEN||""}`,
|
|
429
|
+
String.raw`else{if(!E.GITHUB_SERVER_URL||!E.GITHUB_REPOSITORY)throw new Error("the job names no repository (no GITHUB_SERVER_URL or GITHUB_REPOSITORY)");url=E.GITHUB_SERVER_URL.replace(/\/+$/,"")+"/"+E.GITHUB_REPOSITORY+".git";user="x-access-token";tok=E.GITHUB_TOKEN||""}`,
|
|
430
|
+
String.raw`const d=fs.mkdtempSync(pa.join(os.tmpdir(),"chant-guard-"));const g=(a)=>cp.spawnSync("git",a,{cwd:d,encoding:"utf-8",env:Object.assign({},E,{GIT_TERMINAL_PROMPT:"0"})});`,
|
|
431
|
+
String.raw`const i=g(["init","-q"]);if(i.status!==0)throw new Error("git init failed: "+String(i.stderr||"").trim());`,
|
|
432
|
+
String.raw`const f=g(["-c","http.extraHeader=Authorization: Basic "+Buffer.from(user+":"+tok).toString("base64"),"fetch","-q","--depth=1",url,"refs/heads/chant/lifecycle"]);`,
|
|
433
|
+
String.raw`if(f.status!==0)throw new Error("could not fetch chant/lifecycle: "+String(f.stderr||"").trim().split("\n").pop());`,
|
|
434
|
+
String.raw`const o=g(["show","FETCH_HEAD:"+file]);return o.status===0?o.stdout:null};`,
|
|
435
|
+
String.raw`const bmEntry=(t,h)=>{let v;try{v=JSON.parse(t===null?"null":t)}catch(e){return null}const hs=v&&typeof v==="object"&&v.version===1?v.heads:undefined;if(!hs||typeof hs!=="object"||!SHA.test(h))return null;const e=hs[h];`,
|
|
436
|
+
String.raw`if(!e||typeof e!=="object"||e.head!==h||!Number.isInteger(e.pr)||e.pr<1||typeof e.base!=="string"||!SHA.test(e.base)||typeof e.at!=="string"||typeof e.by!=="string"||typeof e.digest!=="string")return null;`,
|
|
437
|
+
String.raw`if(e.through!==undefined&&(!Number.isInteger(e.through)||e.through<1))return null;const r={pr:e.pr,head:h,base:e.base,at:e.at,by:e.by,digest:e.digest};if(e.through!==undefined)r.through=e.through;return r};`,
|
|
438
|
+
`const bmSeen=(s)=>{if(!bmOn)return s;s.beforeMerge=bmRun;if(!x.beforeMerge||!bmRun.head)return s;try{s.rec=bmEntry(bmRead(${JSON.stringify(BM_PATH[0])}+x.beforeMerge.op+${JSON.stringify(BM_PATH[1])}),bmRun.head)}catch(e){s.bmErr=e&&e.message?e.message:String(e)}return s};`,
|
|
439
|
+
'const shownJ=(v)=>v===undefined||v===""?"none":JSON.stringify(v);',
|
|
440
|
+
String.raw`const bmProblems=(op,r,rec)=>{const p=[];if(!r.pr||!/^[1-9][0-9]{0,9}$/.test(r.pr))p.push("before merge: the run's pull request "+shownJ(r.pr)+" is not a number");`,
|
|
441
|
+
String.raw`if(!r.head||!SHA.test(r.head))p.push("before merge: the run's head "+shownJ(r.head)+" is not a commit sha");`,
|
|
442
|
+
String.raw`if(!r.digest||!/^sha256:[0-9a-f]{64}$/.test(r.digest))p.push("before merge: the run's digest "+shownJ(r.digest)+" is not a sha256 digest");`,
|
|
443
|
+
String.raw`if(p.length)return p;const h=r.head.slice(0,12);if(!rec)return["before merge: no decision on chant/lifecycle names head "+h+" of "+op+", so this run applies nothing"];`,
|
|
444
|
+
String.raw`if(rec.pr!==Number(r.pr))p.push("before merge: the decision for head "+h+" is pull request "+rec.pr+"'s, not "+r.pr+"'s");`,
|
|
445
|
+
String.raw`if(rec.digest!==r.digest)p.push("before merge: the run carries digest "+r.digest+", and the decision for head "+h+" has "+rec.digest);`,
|
|
446
|
+
String.raw`const dg="sha256:"+require("crypto").createHash("sha256").update(JSON.stringify(["chant-before-merge/1",op,rec.pr,rec.head,rec.base,rec.through===undefined?0:rec.through,rec.at,rec.by])).digest("hex");`,
|
|
447
|
+
String.raw`if(dg!==rec.digest)p.push("before merge: the decision for head "+h+" was changed after it was made: its fields give another digest");return p};`,
|
|
448
|
+
].map(noQuote);
|
|
449
|
+
|
|
450
|
+
const FO_PATH = followOnPath("\u0000").split("\u0000") as [string, string];
|
|
451
|
+
/**
|
|
452
|
+
* The follow-on part of the program (#4992): the run's two variables and the lines of {@link followOnProblems}, and
|
|
453
|
+
* (#4998) the read of the chain's record and the lines of {@link followOnRecordProblems}. After {@link BEFORE_MERGE_JS},
|
|
454
|
+
* whose `SHA`, `bmRead` and decision variables it reads.
|
|
455
|
+
*/
|
|
456
|
+
const FOLLOW_ON_JS = [
|
|
457
|
+
`const foV=[${JSON.stringify(OP_WAVES_WAVE_ENV)},${JSON.stringify(OP_WAVES_COMMIT_ENV)}].map((k)=>String(E[k]||"").trim());const foRun={};if(foV[0])foRun.wave=foV[0];if(foV[1])foRun.commit=foV[1];`,
|
|
458
|
+
String.raw`const foProblems=(rest,r,bm)=>{const w=r.wave,c=r.commit;`,
|
|
459
|
+
String.raw`if(rest===undefined){if(w===undefined&&c===undefined)return{p:[]};return{p:["follow-on: the run names wave "+(w===undefined?"none":w)+" and commit "+(c===undefined?"none":c)+", and this job is none of the rest wave's, which alone runs in a follow-on"]}}`,
|
|
460
|
+
String.raw`if(w===undefined||w===String(rest)){if(c===undefined)return{p:[]};return{p:["follow-on: the run names the commit "+c+" and no wave after wave "+rest+", so it is no follow-on"]}}`,
|
|
461
|
+
String.raw`if(!/^[1-9][0-9]{0,5}$/.test(w)||Number(w)<=rest)return{p:["follow-on: the run's wave "+JSON.stringify(w)+" is no wave after wave "+rest]};`,
|
|
462
|
+
String.raw`if(bm){if(c!==undefined)return{p:["follow-on: a follow-on of a decided head checks out that head, and the run names the commit "+c+" too"]};return{p:[],c:"follow-on wave "+w}}`,
|
|
463
|
+
String.raw`if(c===undefined||!SHA.test(c))return{p:["follow-on: a push's follow-on names the commit it goes on with, and the run's "+(c===undefined?"none":JSON.stringify(c))+" is not a commit sha"]};`,
|
|
464
|
+
String.raw`return{p:[],c:"follow-on wave "+w+" at "+c.slice(0,12)}};`,
|
|
465
|
+
// #4998: the record of the run's chain, as parseFollowOn keeps an entry, and the lines of followOnRecordProblems.
|
|
466
|
+
String.raw`const foEntry=(t,k)=>{let v;try{v=JSON.parse(t===null?"null":t)}catch(e){return null}const cs=v&&typeof v==="object"&&v.version===1?v.chains:undefined;if(!cs||typeof cs!=="object"||!SHA.test(k))return null;const e=cs[k];const W=(n,m)=>Number.isInteger(n)&&n>=m;`,
|
|
467
|
+
String.raw`if(!e||typeof e!=="object"||e.key!==k||!W(e.wave,2)||!W(e.from,1)||typeof e.run!=="string"||typeof e.at!=="string")return null;`,
|
|
468
|
+
String.raw`if((e.digest!==undefined&&typeof e.digest!=="string")||(e.pr!==undefined&&!W(e.pr,1))||(e.commit!==undefined&&(typeof e.commit!=="string"||!SHA.test(e.commit)))||!e.outcomes||typeof e.outcomes!=="object")return null;return e};`,
|
|
469
|
+
`const foSeen=(s)=>{const k=bmOn?bmRun.head:foRun.commit;if(!x.beforeMerge||!k||foProblems(x.rest,foRun,bmOn).c===undefined)return s;try{s.foRec=foEntry(bmRead(${JSON.stringify(FO_PATH[0])}+x.beforeMerge.op+${JSON.stringify(FO_PATH[1])}),k)}catch(e){s.foErr=e&&e.message?e.message:String(e)}return s};`,
|
|
470
|
+
String.raw`const foRecProblems=(op,w,k,dg,rec)=>{const what=dg!==undefined?"head":"commit";const sh=k.slice(0,12);if(!rec)return["follow-on: no record job of "+op+" started a follow-on for "+what+" "+sh+", so this run applies nothing"];const p=[];`,
|
|
471
|
+
String.raw`if(String(rec.wave)!==w)p.push("follow-on: the newest record job of "+op+" for "+what+" "+sh+" started wave "+rec.wave+", and this run names wave "+w);`,
|
|
472
|
+
String.raw`if(dg!==undefined&&rec.digest!==dg)p.push("follow-on: wave "+rec.wave+" of "+what+" "+sh+" was started for the decision with digest "+(rec.digest===undefined?"none":rec.digest)+", and the run carries "+dg);return p};`,
|
|
473
|
+
].map(noQuote);
|
|
474
|
+
|
|
265
475
|
/**
|
|
266
476
|
* The guard as one `node -e` program: the same checks as {@link checkJob},
|
|
267
477
|
* {@link jobSeen} and {@link describeJobGuard}, reading {@link JOB_GUARD_ENV}.
|
|
@@ -278,15 +488,17 @@ export const JOB_GUARD_JS = [
|
|
|
278
488
|
"if(!x||![\"github\",\"gitlab\",\"forgejo\"].includes(x.forge)||!Array.isArray(x.branches))fail(\"" + JOB_GUARD_ENV + " is not a guard spec\");",
|
|
279
489
|
'const tags=(r)=>{if(r===undefined)return undefined;const t=r.trim();if(t.startsWith("[")){try{const v=JSON.parse(t);if(Array.isArray(v))return v.map(String)}catch(e){}}return t===""?[]:t.split(",").map((s)=>s.trim()).filter((s)=>s!=="")};',
|
|
280
490
|
'const claimsOf=(tok)=>{const p=tok.split(".")[1];if(!p)throw new Error("the forge\\u0027s OIDC token is not a JWT");const c=JSON.parse(Buffer.from(p.replace(/-/g,"+").replace(/_/g,"/"),"base64").toString("utf-8"));if(!c||typeof c!=="object")throw new Error("the forge\\u0027s OIDC token has no claims");return c};',
|
|
491
|
+
...BEFORE_MERGE_JS,
|
|
492
|
+
...FOLLOW_ON_JS,
|
|
281
493
|
"async function seenOf(){",
|
|
282
|
-
'if(x.forge==="gitlab")return{forgeEnvironment:E.CI_ENVIRONMENT_NAME||null,ref:E.CI_COMMIT_REF_NAME,refProtected:E.CI_COMMIT_REF_PROTECTED,runnerTags:tags(E.CI_RUNNER_TAGS)};',
|
|
494
|
+
'if(x.forge==="gitlab")return foSeen(bmSeen({forgeEnvironment:E.CI_ENVIRONMENT_NAME||null,ref:E.CI_COMMIT_REF_NAME,refProtected:E.CI_COMMIT_REF_PROTECTED,runnerTags:tags(E.CI_RUNNER_TAGS)}));',
|
|
283
495
|
"const s={ref:E.GITHUB_REF};let c;",
|
|
284
496
|
'if(x.forge==="github"&&x.forgeEnvironment!==undefined){try{',
|
|
285
497
|
'if(!E.ACTIONS_ID_TOKEN_REQUEST_URL||!E.ACTIONS_ID_TOKEN_REQUEST_TOKEN)throw new Error("the job may request no OIDC token (no ACTIONS_ID_TOKEN_REQUEST_URL); it needs the id-token: write permission");',
|
|
286
498
|
'const r=await fetch(E.ACTIONS_ID_TOKEN_REQUEST_URL+"&audience="+encodeURIComponent(A),{headers:{authorization:"bearer "+E.ACTIONS_ID_TOKEN_REQUEST_TOKEN}});',
|
|
287
499
|
'if(!r.ok)throw new Error("the OIDC token request answered "+r.status);const v=(await r.json()).value;if(typeof v!=="string")throw new Error("the OIDC token request answered no token");',
|
|
288
500
|
'c=claimsOf(v);s.forgeEnvironment=typeof c.environment==="string"&&c.environment!==""?c.environment:null}catch(e){s.forgeEnvironmentError=e&&e.message?e.message:String(e)}}',
|
|
289
|
-
'const run=c&&typeof c.runner_environment==="string"?c.runner_environment:E.RUNNER_ENVIRONMENT;if(run)s.runnerEnvironment=run;return s}',
|
|
501
|
+
'const run=c&&typeof c.runner_environment==="string"?c.runner_environment:E.RUNNER_ENVIRONMENT;if(run)s.runnerEnvironment=run;return foSeen(bmSeen(s))}',
|
|
290
502
|
"seenOf().then((s)=>{const P=[],C=[],S=[];const fe=x.forgeEnvironment;",
|
|
291
503
|
'if(x.forge==="forgejo")S.push("forge environment (Forgejo has none)");',
|
|
292
504
|
'else if(fe!==undefined){if(s.forgeEnvironmentError!==undefined)P.push("forge environment: expected "+fe+", and it could not be read: "+s.forgeEnvironmentError);else if(s.forgeEnvironment!==fe)P.push("forge environment: expected "+fe+", found "+shown(s.forgeEnvironment));else C.push("forge environment "+fe)}',
|
|
@@ -295,6 +507,12 @@ export const JOB_GUARD_JS = [
|
|
|
295
507
|
'else if(x.forge==="gitlab"){if(!s.ref||!b.includes(s.ref))P.push("ref: expected "+b.join(" or ")+", found "+shown(s.ref));else C.push("ref "+s.ref);',
|
|
296
508
|
'if(s.refProtected!=="true")P.push("ref: expected a protected ref (CI_COMMIT_REF_PROTECTED true), found "+shown(s.refProtected));else C.push("protected ref")}',
|
|
297
509
|
'else{const refs=b.map((v)=>"refs/heads/"+v);if(!s.ref||!refs.includes(s.ref))P.push("ref: expected "+refs.join(" or ")+", found "+shown(s.ref));else C.push("ref "+s.ref)}',
|
|
510
|
+
...[
|
|
511
|
+
String.raw`if(s.beforeMerge){const r=s.beforeMerge;if(!x.beforeMerge)P.push("before merge: the run names pull request "+(r.pr||"none")+"'s head "+(r.head||"none")+", and this job applies only the pushes to its branches");`,
|
|
512
|
+
String.raw`else if(s.bmErr!==undefined)P.push("before merge: the decisions on chant/lifecycle could not be read: "+s.bmErr);`,
|
|
513
|
+
String.raw`else{const Q=bmProblems(x.beforeMerge.op,r,s.rec||undefined);if(Q.length)P.push(...Q);else C.push("before merge: pull request "+r.pr+"'s decided head "+r.head.slice(0,12))}}`,
|
|
514
|
+
].map(noQuote),
|
|
515
|
+
"{const F=foProblems(x.rest,foRun,bmOn);P.push(...F.p);if(F.c){const G=!x.beforeMerge?[\"follow-on: this job names no op whose follow-on records it reads, so it admits no follow-on\"]:s.foErr!==undefined?[\"follow-on: the follow-on records on chant/lifecycle could not be read: \"+s.foErr]:foRecProblems(x.beforeMerge.op,foRun.wave,(bmOn?bmRun.head:foRun.commit)||\"\",bmOn?(bmRun.digest||\"\"):undefined,s.foRec);if(G.length)P.push(...G);else C.push(F.c)}}",
|
|
298
516
|
'if(x.forge==="gitlab"){const w=x.runnerTags||[];if(w.length>0){const h=s.runnerTags;const miss=w.filter((t)=>!(h||[]).includes(t));',
|
|
299
517
|
'if(h===undefined)P.push("runner: expected tags "+w.join(", ")+", and the job has no CI_RUNNER_TAGS");else if(miss.length>0)P.push("runner: expected tags "+w.join(", ")+", found "+(h.length?h.join(", "):"none"));else C.push("runner tags "+w.join(", "))}}',
|
|
300
518
|
'else if(x.selfHosted){if(s.runnerEnvironment===undefined)S.push("runner (the runner says nothing about itself: no RUNNER_ENVIRONMENT)");else if(s.runnerEnvironment!=="self-hosted")P.push("runner: expected self-hosted, found "+s.runnerEnvironment);else C.push("self-hosted runner")}',
|