@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
|
@@ -508,8 +508,9 @@ export const PR_UNLOCK_JOB = "unlock";
|
|
|
508
508
|
* With a product's `bin` (its words), the line runs through it, as the comment lock jobs do
|
|
509
509
|
* (INTENTIUS/plywood#22): a product's job image need not carry `chant` on PATH.
|
|
510
510
|
*/
|
|
511
|
-
export function prLockCommand(forge: ForgeKind, bin?: string): string {
|
|
512
|
-
|
|
511
|
+
export function prLockCommand(forge: ForgeKind, bin?: string, dir: string = PR_LOOP_REPORT_DIR): string {
|
|
512
|
+
// #5003: a product plan's report directory.
|
|
513
|
+
return withProductBin(["chant", "lock", "--from-report", `${dir}/pr-plan.json`,"--pr", '"$PR_NUMBER"', "--head", '"$HEAD_SHA"', "--stage", "plan", "--forge", forge].join(" "), bin);
|
|
513
514
|
}
|
|
514
515
|
|
|
515
516
|
/** `chant unlock` for the pull request that closed; reads `PR_NUMBER`. */
|
|
@@ -992,8 +993,11 @@ export const PR_PLAN_NOTE_JOB = "plan-note";
|
|
|
992
993
|
* merge request's files, so no job in it holds the token. `pr-post --open`
|
|
993
994
|
* asks GitLab for each open merge request's plan job and reads its report
|
|
994
995
|
* from the job's artifacts.
|
|
996
|
+
*
|
|
997
|
+
* `output` (#5003) is the report directory, `--output`: a product plan's
|
|
998
|
+
* `reportDir`, default {@link PR_LOOP_REPORT_DIR}.
|
|
995
999
|
*/
|
|
996
|
-
export function prLoopPostJob(forge: ForgeKind, env: string, member?: string, words?: Pick<CiProductWordsInput, "bin">, opts: { staleNotes?: boolean } & Pick<PrLoopPipelineOptions, "respond" | "decide"> = {}): { command: string; env: Record<string, string> } {
|
|
1000
|
+
export function prLoopPostJob(forge: ForgeKind, env: string, member?: string, words?: Pick<CiProductWordsInput, "bin">, opts: { staleNotes?: boolean; output?: string } & Pick<PrLoopPipelineOptions, "respond" | "decide"> = {}): { command: string; env: Record<string, string> } {
|
|
997
1001
|
// #4629: the responses as CHANT_RESPOND, and with the description check its decide service on the line.
|
|
998
1002
|
const respondEnv = prLoopRespondEnv(opts);
|
|
999
1003
|
const decide = opts.respond?.description === "check" && opts.decide ? ` --decide-backend ${JSON.stringify(opts.decide.backend)} --decide-model ${JSON.stringify(opts.decide.model)}` : "";
|
|
@@ -1001,18 +1005,19 @@ export function prLoopPostJob(forge: ForgeKind, env: string, member?: string, wo
|
|
|
1001
1005
|
return decide || Object.keys(respondEnv).length > 0 ? { command: `${job.command}${decide}`, env: { ...job.env, ...respondEnv } } : job;
|
|
1002
1006
|
}
|
|
1003
1007
|
|
|
1004
|
-
function prLoopPostJobBase(forge: ForgeKind, env: string, member: string | undefined, words: Pick<CiProductWordsInput, "bin"> | undefined, opts: { staleNotes?: boolean }): { command: string; env: Record<string, string> } {
|
|
1008
|
+
function prLoopPostJobBase(forge: ForgeKind, env: string, member: string | undefined, words: Pick<CiProductWordsInput, "bin"> | undefined, opts: { staleNotes?: boolean; output?: string }): { command: string; env: Record<string, string> } {
|
|
1005
1009
|
// #4628: with staleNotes the note carries the target branch's commit, so a later push can mark it stale.
|
|
1006
1010
|
const tip = opts.staleNotes ? ["--tip", '"$TIP_SHA"'] : [];
|
|
1011
|
+
const output = opts.output ?? PR_LOOP_REPORT_DIR;
|
|
1007
1012
|
if (forge === "gitlab") {
|
|
1008
1013
|
return {
|
|
1009
|
-
command: withProductBin(["chant", "components", "pr-post", "--open", "--env", env, "--output",
|
|
1014
|
+
command: withProductBin(["chant", "components", "pr-post", "--open", "--env", env, "--output", output, "--forge", forge, ...(member ? ["--member", member] : []), ...tip].join(" "), words?.bin),
|
|
1010
1015
|
env: opts.staleNotes ? { TIP_SHA: "$CI_COMMIT_SHA" } : {},
|
|
1011
1016
|
};
|
|
1012
1017
|
}
|
|
1013
1018
|
const command = [
|
|
1014
1019
|
"chant", "components", "pr-post", "--pr", '"$PR_NUMBER"', "--head", '"$HEAD_SHA"',
|
|
1015
|
-
"--env", env, "--output",
|
|
1020
|
+
"--env", env, "--output", output, "--forge", forge,
|
|
1016
1021
|
...(member ? ["--member", member] : []),
|
|
1017
1022
|
"--result", '"$PLAN_RESULT"',
|
|
1018
1023
|
...tip,
|
|
@@ -1037,15 +1042,22 @@ export const PR_STALE_JOB = "stale-notes";
|
|
|
1037
1042
|
* `staleNotes`: on a push to the target branch, at its commit, `pr-post
|
|
1038
1043
|
* --stale` marks each open pull request's note posted against another
|
|
1039
1044
|
* commit stale and sets its plan status back to pending. It names the plan
|
|
1040
|
-
* comment with `previewComment`. Undefined without `staleNotes`.
|
|
1045
|
+
* comment with `previewComment`. Undefined without `staleNotes`. A list
|
|
1046
|
+
* of members (#4987, a product plan's targets) marks each one's note.
|
|
1047
|
+
* `contexts` (#5003, a product plan's `statusContext`) are the plan
|
|
1048
|
+
* statuses it sets back to pending, one per member in the same order (one
|
|
1049
|
+
* for none), as `--context`.
|
|
1041
1050
|
*/
|
|
1042
|
-
export function prStaleJob(forge: ForgeKind, env: string, options: Pick<PrLoopPipelineOptions, "staleNotes" | "previewComment" | "branch" | "words"> = {}, member?: string): { command: string; env: Record<string, string> } | undefined {
|
|
1051
|
+
export function prStaleJob(forge: ForgeKind, env: string, options: Pick<PrLoopPipelineOptions, "staleNotes" | "previewComment" | "branch" | "words"> = {}, member?: string | readonly string[], contexts?: readonly string[]): { command: string; env: Record<string, string> } | undefined {
|
|
1043
1052
|
if (!options.staleNotes) return undefined;
|
|
1044
1053
|
const words = resolveProductWords(options.words);
|
|
1054
|
+
const members = member === undefined ? [] : typeof member === "string" ? [member] : [...member];
|
|
1055
|
+
if (contexts !== undefined && contexts.length !== Math.max(1, members.length)) throw new Error(`the stale job sets back ${contexts.length} plan statuses for ${members.length} members; give one context a member`);
|
|
1045
1056
|
const command = [
|
|
1046
1057
|
"chant", "components", "pr-post", "--stale", "--tip", '"$TIP_SHA"', "--env", env, "--forge", forge,
|
|
1047
1058
|
...(options.branch ? ["--branch", JSON.stringify(options.branch)] : []),
|
|
1048
|
-
...(
|
|
1059
|
+
...members.flatMap((m) => ["--member", m]),
|
|
1060
|
+
...(contexts ?? []).flatMap((c) => ["--context", c]),
|
|
1049
1061
|
...(options.previewComment ? ["--preview-comment"] : []),
|
|
1050
1062
|
].join(" ");
|
|
1051
1063
|
return {
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #4987 in the product pipeline: `applyStatus` and a product plan's
|
|
3
|
+
* `staleNotes` come back in `waves.pipeline` for the generators, the stale
|
|
4
|
+
* marking with one `--member` per plan target, and each target's note
|
|
5
|
+
* carries the target branch's commit it was planned against.
|
|
6
|
+
*/
|
|
7
|
+
import { describe, expect, test } from "vitest";
|
|
8
|
+
import type { OpWavesSpec } from "../op/op-waves";
|
|
9
|
+
import { productPipelineJobs } from "./product-pipeline";
|
|
10
|
+
|
|
11
|
+
const words = { product: "terragucci", noun: ["root", "roots"] as [string, string], commands: { plan: "plan" as const, apply: "apply" as const }, approval: "per-wave" as const, op: "tf-apply", bin: "npx --no-install terragucci" };
|
|
12
|
+
const waves: OpWavesSpec = { name: "tf-apply", op: "tf-apply", step: { kind: "terraform-apply", root: "{target}" }, waves: [{ name: "dev", runs: [{ target: "envs/dev" }] }] } as OpWavesSpec;
|
|
13
|
+
const productPlan = { command: "terragucci plan {target} --out {output}", workflow: "terragucci-pr", targets: [{ name: "dev" }, { name: "prod" }] };
|
|
14
|
+
const base = { words, waves, productPlan, staleNotes: true, applyStatus: true };
|
|
15
|
+
|
|
16
|
+
describe("the apply statuses and the stale notes in the product pipeline (#4987)", () => {
|
|
17
|
+
test.each(["github", "forgejo", "gitlab"] as const)("on %s, the waves get the status context and the stale marking per target", (forge) => {
|
|
18
|
+
const jobs = productPipelineJobs(forge, "default", base);
|
|
19
|
+
expect(jobs.waves!.pipeline.applyStatus).toEqual({ context: "terragucci/apply" });
|
|
20
|
+
const stale = jobs.waves!.pipeline.staleNotes!;
|
|
21
|
+
expect(stale.command).toBe(`npx --no-install terragucci components pr-post --stale --tip "$TIP_SHA" --env default --forge ${forge} --member dev --member prod`);
|
|
22
|
+
expect(stale.env.TIP_SHA).toBe(forge === "gitlab" ? "$CI_COMMIT_SHA" : "${{ github.sha }}");
|
|
23
|
+
// The pull request loop's own stale job is not the product plan's.
|
|
24
|
+
expect(jobs.stale).toBeUndefined();
|
|
25
|
+
// Each target's note carries the target branch's commit, so the push can tell it is stale.
|
|
26
|
+
for (const p of jobs.productPlan!) {
|
|
27
|
+
expect(p.post.command).toContain('--tip "$TIP_SHA"');
|
|
28
|
+
expect(p.post.env.TIP_SHA).toBe(forge === "gitlab" ? "$CI_COMMIT_SHA" : "${{ github.event.pull_request.base.sha }}");
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test("the re-plan's note carries its tip too, and the stale line names the re-plan comment", () => {
|
|
33
|
+
const jobs = productPipelineJobs("github", "default", { ...base, productPlan: { ...productPlan, replan: true } });
|
|
34
|
+
const replan = jobs.productPlan![0]!.replan!;
|
|
35
|
+
expect(replan.post.command).toContain('--tip "$TIP_SHA"');
|
|
36
|
+
expect(replan.post.env.TIP_SHA).toBe("${{ github.sha }}");
|
|
37
|
+
expect(jobs.waves!.pipeline.staleNotes!.command).toContain("--preview-comment");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("a member's status context, and nothing without the options", () => {
|
|
41
|
+
expect(productPipelineJobs("github", "default", { ...base, member: "net" }).waves!.pipeline.applyStatus).toEqual({ context: "terragucci/apply/net" });
|
|
42
|
+
expect(productPipelineJobs("github", "default", { words, waves, productPlan }).waves!.pipeline).toEqual({});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test("refused without waves", () => {
|
|
46
|
+
const planOnly = { ...words, commands: { plan: "plan" as const } };
|
|
47
|
+
expect(() => productPipelineJobs("github", "default", { words: planOnly, productPlan, applyStatus: true })).toThrow("applyStatus posts the waves' apply statuses, and there are none");
|
|
48
|
+
expect(() => productPipelineJobs("github", "default", { words: planOnly, productPlan, staleNotes: true })).toThrow("staleNotes with the product plan marks the notes from the waves workflow's push run");
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
CHANT_WORDS,
|
|
31
31
|
CI_PRODUCT_COMMANDS,
|
|
32
32
|
commentLine,
|
|
33
|
+
productStatusContext,
|
|
33
34
|
type CiProductApplyMode,
|
|
34
35
|
type CiProductCommand,
|
|
35
36
|
type CiProductWords,
|
|
@@ -37,16 +38,20 @@ import {
|
|
|
37
38
|
} from "../ci-product-words";
|
|
38
39
|
import { checkJobOptions, PR_LOOP_REPORT_DIR, prActionJob, prCommentLockJobs, prCommentPreviewJob, prLoopJobs, prLoopPostJob, prLoopRunner, prNoteCommandsJob, prStaleJob, withProductBin, type PrActionJob, type PrCommentLockJob, type PrCommentPreviewJob, type PrLoopJob, type PrLoopPipelineOptions } from "./pr-pipeline";
|
|
39
40
|
import type { DriverComponent } from "./driver";
|
|
40
|
-
import type { ScheduledOpSpec } from "../lexicon";
|
|
41
|
+
import type { OpWavesPipelineOptions, ScheduledOpSpec } from "../lexicon";
|
|
41
42
|
import type { CiRunner } from "../ci-jobs";
|
|
42
43
|
import { resolveAgentSpec, type OpAgentSpec } from "../ci-agent";
|
|
43
44
|
import { resolveCommitSpec, type OpCommitSpec } from "../ci-commit";
|
|
44
45
|
import type { CiResponses } from "../ci-respond";
|
|
45
|
-
import { planEvidenceOf, productPlanJobs, productPlanReachLock, type ProductPlanJob, type ProductPlanOptions, type ProductPlanReachLock } from "./product-plan";
|
|
46
|
+
import { planEvidenceOf, productPlanContext, productPlanJobs, productPlanReachLock, type ProductPlanJob, type ProductPlanOptions, type ProductPlanReachLock } from "./product-plan";
|
|
46
47
|
import { gitlabOpenEvidenceDir, type PipelineEvidence } from "../ci-evidence-jobs";
|
|
47
48
|
import { prCheckJob, prRefGateJob, type PrCheckJob, type PrRefGateJob } from "./pr-checks";
|
|
48
49
|
import { COMMENT_JOBS_ENV, PR_COMMENT_JOB, type CommentJobs } from "../ci-comment-commands";
|
|
49
50
|
import { GITHUB_JOB_TOKEN } from "../ci-jobs";
|
|
51
|
+
import type { OpWavesBeforeMerge } from "../op/before-merge";
|
|
52
|
+
import { defaultPipelineFiles, type WavesBeforeMergeJobs } from "../op/before-merge-decide";
|
|
53
|
+
import type { PrApplyRequire } from "../pr-requires";
|
|
54
|
+
import { LOCK_REACH_ENV } from "../lifecycle/reach-locks";
|
|
50
55
|
|
|
51
56
|
/** Where the generator writes a product's waves spec, which chant reads at base (#4550). */
|
|
52
57
|
export const PRODUCT_WAVES_SPEC_DIR = ".chant/op-waves";
|
|
@@ -147,6 +152,43 @@ export interface ProductPipelineOptions extends Omit<PrLoopPipelineOptions, "wor
|
|
|
147
152
|
* there.
|
|
148
153
|
*/
|
|
149
154
|
commentJob?: boolean;
|
|
155
|
+
/**
|
|
156
|
+
* Waves before merge (#4984, maintainer decision 2026-11-10): `/<product>
|
|
157
|
+
* apply [wave-<n>]` on an open pull request runs the waves on its head.
|
|
158
|
+
* The comment job (GitHub, Forgejo; needs `commentJob`) or the note poll
|
|
159
|
+
* (GitLab; needs `noteCommands`) decides it by the product plan's rules
|
|
160
|
+
* (../op/before-merge-decide.ts): this repository's pull request into the
|
|
161
|
+
* default branch, its head unmoved, `requires` met, every plan status
|
|
162
|
+
* passed on the head, none of `pipelineFiles` touched, and with the
|
|
163
|
+
* product plan's `reach` the locks at stage apply. It records the head
|
|
164
|
+
* and the decision's digest on `chant/lifecycle` and starts the waves
|
|
165
|
+
* workflow for it, whose guard admits that head alone. After the last
|
|
166
|
+
* wave, `merge: "auto"` merges the pull request at that head and releases
|
|
167
|
+
* its locks. Needs `waves` (or `componentWaves`).
|
|
168
|
+
*/
|
|
169
|
+
wavesBeforeMerge?: ProductWavesBeforeMerge;
|
|
170
|
+
/**
|
|
171
|
+
* The apply statuses (#4987): the waves workflow posts `<product>/apply`
|
|
172
|
+
* (`<product>/apply/<member>` for a member) on the commit the waves
|
|
173
|
+
* applied, from a job after each wave that runs none of the change's
|
|
174
|
+
* code (`@intentius/chant/op/apply-status`): pending after each wave,
|
|
175
|
+
* success after the last, failed when a run failed. Needs `waves` (or
|
|
176
|
+
* `componentWaves`); the product passes `waves.pipeline` on when it
|
|
177
|
+
* renders them.
|
|
178
|
+
*/
|
|
179
|
+
applyStatus?: boolean;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** {@link ProductPipelineOptions.wavesBeforeMerge} (#4984). */
|
|
183
|
+
export interface ProductWavesBeforeMerge {
|
|
184
|
+
/** The requires the forge is asked before the apply (`apply.requires`). Default every one: approved, mergeable, undiverged, checks. */
|
|
185
|
+
requires?: PrApplyRequire[];
|
|
186
|
+
/** `auto`: merge after the last wave, and release the locks. `manual` (default): reply that it is ready. */
|
|
187
|
+
merge?: "auto" | "manual";
|
|
188
|
+
/** The merge token's secret or CI/CD variable, with `merge: "auto"` (needed on Forgejo and GitLab). */
|
|
189
|
+
mergeTokenSecret?: string;
|
|
190
|
+
/** Paths a change may not touch to apply before merge; one ending in `/` is a directory. Default the forge's workflow directory and `.chant/op-waves/`. */
|
|
191
|
+
pipelineFiles?: string[];
|
|
150
192
|
}
|
|
151
193
|
|
|
152
194
|
/** The comment job (#4946): its command, the values it reads, and the comment prefixes that start it. */
|
|
@@ -183,8 +225,25 @@ export interface ProductPipelineJobs {
|
|
|
183
225
|
applyBeforeMerge?: PrLoopJob;
|
|
184
226
|
/** The comment each command answers, `/<product> <word>`, for the commands the pipeline has a job for. */
|
|
185
227
|
comments: Partial<Record<CiProductCommand, string>>;
|
|
186
|
-
/**
|
|
187
|
-
|
|
228
|
+
/**
|
|
229
|
+
* The apply on merge: the spec with the words' names, its file, and a job
|
|
230
|
+
* per wave (per share or group). With `wavesBeforeMerge` (#4984),
|
|
231
|
+
* `beforeMerge` is the generators' `OpWavesPipelineOptions.beforeMerge`:
|
|
232
|
+
* the product passes it on when it renders the waves.
|
|
233
|
+
*/
|
|
234
|
+
waves?: {
|
|
235
|
+
spec: OpWavesSpec;
|
|
236
|
+
specFile: string;
|
|
237
|
+
jobs: OpWaveJob[];
|
|
238
|
+
beforeMerge?: OpWavesBeforeMerge;
|
|
239
|
+
/**
|
|
240
|
+
* What the generators take from the pipeline (#4987): `beforeMerge`,
|
|
241
|
+
* `applyStatus` and, with `staleNotes`, the stale marking job that runs
|
|
242
|
+
* beside wave 1 on a push (one `--member` per product plan target). The
|
|
243
|
+
* product spreads it into the `OpWavesPipelineOptions` it renders with.
|
|
244
|
+
*/
|
|
245
|
+
pipeline: Pick<OpWavesPipelineOptions, "beforeMerge" | "applyStatus" | "staleNotes">;
|
|
246
|
+
};
|
|
188
247
|
/**
|
|
189
248
|
* The comment lock and unlock jobs (#4588), under `locks: "plan"`:
|
|
190
249
|
* `/<product> lock` keeps the locks the plan took, `/<product> unlock`
|
|
@@ -212,7 +271,7 @@ export interface ProductPipelineJobs {
|
|
|
212
271
|
* lexicon renders the same job from `chant build --pr-loop
|
|
213
272
|
* --note-commands`. Refused on GitHub and Forgejo.
|
|
214
273
|
*/
|
|
215
|
-
noteCommands?: { command: string; runner?: CiRunner };
|
|
274
|
+
noteCommands?: { command: string; runner?: CiRunner; env?: Record<string, string> };
|
|
216
275
|
/**
|
|
217
276
|
* The agent (#4616), with `agent`: the comment it answers, `/<product>
|
|
218
277
|
* agent <ask>`, and the scheduled Op spec whose generated workflow runs
|
|
@@ -351,7 +410,8 @@ export function productPipelineJobs(forge: ForgeKind, env: string, options: Prod
|
|
|
351
410
|
// #4946: the comment job answers every command but a commit word (the commit job's) with a reply, so the words may name any.
|
|
352
411
|
const answered: CiProductCommand[] = options.commentJob ? [...new Set<CiProductCommand>([...jobs, ...CI_PRODUCT_COMMANDS.filter((c) => c !== "commit")])] : jobs;
|
|
353
412
|
const words = assertProductWords({ ...options.words, applyMode }, { jobs: answered });
|
|
354
|
-
const { waves: given, wavesSpecFile, member, agent: _agent, commits: _commits, actions: _actions, componentWaves, productPlan, evidence, commentJob: _commentJob, ...loop } = options;
|
|
413
|
+
const { waves: given, wavesSpecFile, member, agent: _agent, commits: _commits, actions: _actions, componentWaves, productPlan, evidence, commentJob: _commentJob, wavesBeforeMerge, applyStatus: _applyStatus, ...loop } = options;
|
|
414
|
+
if (options.applyStatus && !given && !componentWaves) throw new Error("applyStatus posts the waves' apply statuses, and there are none: give waves (or componentWaves)");
|
|
355
415
|
const { respond } = options;
|
|
356
416
|
// #4629: the pull request loop puts the responses on the apply and note jobs, as `chant build --pr-loop --respond` does.
|
|
357
417
|
const prLoop: PrLoopPipelineOptions = { ...loop, words, gate: options.gate ?? words.prGate };
|
|
@@ -394,7 +454,14 @@ export function productPipelineJobs(forge: ForgeKind, env: string, options: Prod
|
|
|
394
454
|
if (reachLock) out.reachLock = reachLock;
|
|
395
455
|
const action = prActionJob(forge, prLoop);
|
|
396
456
|
if (action) out.action = { ...action, ...(prLoopRunner(options, "apply") !== undefined ? { runner: prLoopRunner(options, "apply")! } : {}) };
|
|
397
|
-
|
|
457
|
+
// #4987: a product plan's notes are marked from the waves workflow's push run, one --member per target, naming the re-plan comment.
|
|
458
|
+
// #5003: with the product's status context, the stale job sets that status back to pending, one a target.
|
|
459
|
+
const planContexts = productPlan?.statusContext !== undefined ? out.productPlan!.map((p) => productPlanContext(p, words)) : undefined;
|
|
460
|
+
const planStale = productPlan
|
|
461
|
+
? prStaleJob(forge, env, { ...prLoop, ...(productPlan.replan ? { previewComment: true } : {}) }, productPlan.targets?.map((t) => t.name) ?? member, planContexts)
|
|
462
|
+
: undefined;
|
|
463
|
+
if (planStale && !options.waves && !options.componentWaves) throw new Error("staleNotes with the product plan marks the notes from the waves workflow's push run, beside wave 1, and there are no waves: give waves (or componentWaves), or drop staleNotes");
|
|
464
|
+
const stale = productPlan ? undefined : prStaleJob(forge, env, prLoop, member);
|
|
398
465
|
if (stale) out.stale = { ...stale, ...defaultRunner };
|
|
399
466
|
// #4785: GitLab's comment commands, polled from the notes; waves on merge are retried by an apply on a merged merge request.
|
|
400
467
|
// #4899: the product plan's comment re-plan runs in the preview's pipeline, so the poll starts it as it starts a preview.
|
|
@@ -420,6 +487,33 @@ export function productPipelineJobs(forge: ForgeKind, env: string, options: Prod
|
|
|
420
487
|
const spec = given ?? (componentWaves
|
|
421
488
|
? componentWavesSpec(componentWaves.components, words, componentWaveSteps({ ...(words.bin ? { bin: words.bin } : {}), env, base: componentWaves.base ?? "HEAD^1", ...(member ? { member } : {}), op, gate: prLoop.gate }), { ...(componentWaves.waveGate ? { gate: componentWaves.waveGate } : {}) })
|
|
422
489
|
: undefined);
|
|
490
|
+
// #4984: the waves before merge: the comment job (the note poll on GitLab) decides an open pull request's apply and starts them.
|
|
491
|
+
const wavesOp = spec ? (words.op ?? spec.name) : undefined;
|
|
492
|
+
let bmJobs: WavesBeforeMergeJobs | undefined;
|
|
493
|
+
if (wavesBeforeMerge) {
|
|
494
|
+
if (!spec || !wavesOp) throw new Error("wavesBeforeMerge runs the waves on an open pull request's head, and there are none: give waves (or componentWaves)");
|
|
495
|
+
if (options.applyBeforeMerge) throw new Error("wavesBeforeMerge and applyBeforeMerge both answer an open pull request's apply; give one");
|
|
496
|
+
if (forge === "gitlab" ? !options.noteCommands : !options.commentJob) throw new Error(`wavesBeforeMerge is decided by ${forge === "gitlab" ? "the note poll: set noteCommands" : "the comment job: set commentJob"}`);
|
|
497
|
+
const targets = productPlan?.targets?.map((t) => t.name);
|
|
498
|
+
bmJobs = {
|
|
499
|
+
...(forge !== "gitlab" ? { workflow: `${wavesOp}.yml` } : {}),
|
|
500
|
+
...(wavesBeforeMerge.requires ? { requires: [...wavesBeforeMerge.requires] } : {}),
|
|
501
|
+
// #5003: the product's own status contexts, when it named them.
|
|
502
|
+
plan: planContexts ?? (targets?.length ? targets.map((t) => productStatusContext(words, "plan", t)) : [productStatusContext(words, "plan", member)]),
|
|
503
|
+
pipelineFiles: wavesBeforeMerge.pipelineFiles ?? defaultPipelineFiles(forge),
|
|
504
|
+
...(productPlan?.reach ? { locks: { ...(productPlan.reach.gate ? { gate: productPlan.reach.gate } : {}) } } : {}),
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
// #4984: GitLab's note poll writes a wave stop for a merged merge request, and decides the waves before merge.
|
|
508
|
+
if (out.noteCommands && spec && wavesOp) {
|
|
509
|
+
out.noteCommands = {
|
|
510
|
+
...out.noteCommands,
|
|
511
|
+
env: {
|
|
512
|
+
[COMMENT_JOBS_ENV]: JSON.stringify({ waves: { op: wavesOp, count: spec.waves.length }, ...(bmJobs ? { wavesBeforeMerge: bmJobs } : {}) }),
|
|
513
|
+
...(bmJobs && productPlan?.reach ? { [LOCK_REACH_ENV]: productPlan.reach.command } : {}),
|
|
514
|
+
},
|
|
515
|
+
};
|
|
516
|
+
}
|
|
423
517
|
// #4946: the comment job answers what no other job of the pipeline takes, so it is told which jobs there are.
|
|
424
518
|
if (options.commentJob) {
|
|
425
519
|
// #4963's re-plan reply answers the same stray comments, so one of the two answers them.
|
|
@@ -434,6 +528,7 @@ export function productPipelineJobs(forge: ForgeKind, env: string, options: Prod
|
|
|
434
528
|
...(given || componentWaves ? { applyOnMerge: true } : {}),
|
|
435
529
|
// #4979: the waves' op (the name productWavesSpec gives them) and count, so a wave-<n> stops a re-run after wave n.
|
|
436
530
|
...(spec ? { waves: { op: words.op ?? spec.name, count: spec.waves.length } } : {}),
|
|
531
|
+
...(bmJobs ? { wavesBeforeMerge: bmJobs } : {}),
|
|
437
532
|
// #4979: the product plan's re-plan takes no flags, so the comment job answers a plan comment that carries them.
|
|
438
533
|
...(productPlan?.replan ? { noPlanFlags: true } : {}),
|
|
439
534
|
...(locks.length > 0 ? { locks: true } : {}),
|
|
@@ -441,7 +536,10 @@ export function productPipelineJobs(forge: ForgeKind, env: string, options: Prod
|
|
|
441
536
|
...(out.commits ? { commits: true } : {}),
|
|
442
537
|
...(options.actions || options.actionJob ? { actions: true } : {}),
|
|
443
538
|
};
|
|
444
|
-
|
|
539
|
+
const comment = productCommentJob(forge, words, commentJobs);
|
|
540
|
+
// #4984: the decision before merge locks what the reach line prints, at stage apply.
|
|
541
|
+
if (bmJobs && productPlan?.reach) comment.env = { ...comment.env, [LOCK_REACH_ENV]: productPlan.reach.command };
|
|
542
|
+
out.comment = { ...comment, ...defaultRunner };
|
|
445
543
|
}
|
|
446
544
|
if (!spec) return { ...out, record: record! };
|
|
447
545
|
const wavesRespond = respond ? Object.fromEntries(Object.entries(respond).filter(([e]) => e !== "description")) : {};
|
|
@@ -459,7 +557,17 @@ export function productPipelineJobs(forge: ForgeKind, env: string, options: Prod
|
|
|
459
557
|
...(Object.keys(wavesRespond).length > 0 ? { respond: { ...(spec.respond ?? {}), ...wavesRespond } } : {}),
|
|
460
558
|
};
|
|
461
559
|
const specFile = wavesSpecFile ?? productWavesSpecFile(named.name);
|
|
462
|
-
|
|
560
|
+
// #4984: what the generator's before-merge mode takes: the merge after the last wave and the lock file it releases.
|
|
561
|
+
const beforeMerge: OpWavesBeforeMerge | undefined = wavesBeforeMerge
|
|
562
|
+
? { ...(wavesBeforeMerge.merge ? { merge: wavesBeforeMerge.merge } : {}), ...(wavesBeforeMerge.mergeTokenSecret ? { mergeTokenSecret: wavesBeforeMerge.mergeTokenSecret } : {}), ...(productPlan?.reach?.gate ? { gate: productPlan.reach.gate } : {}) }
|
|
563
|
+
: undefined;
|
|
564
|
+
// #4987: the apply statuses after each wave, and with a product plan the stale marking beside wave 1, one --member per target.
|
|
565
|
+
const pipeline: Pick<OpWavesPipelineOptions, "beforeMerge" | "applyStatus" | "staleNotes"> = {
|
|
566
|
+
...(beforeMerge ? { beforeMerge } : {}),
|
|
567
|
+
...(options.applyStatus ? { applyStatus: { context: productStatusContext(words, "apply", member) } } : {}),
|
|
568
|
+
...(planStale ? { staleNotes: planStale } : {}),
|
|
569
|
+
};
|
|
570
|
+
return { ...out, waves: { spec: named, specFile, jobs: opWaveJobs(named, specFile, { bin: words.bin, ...(beforeMerge ? { beforeMerge: true } : {}) }), ...(beforeMerge ? { beforeMerge } : {}), pipeline } };
|
|
463
571
|
}
|
|
464
572
|
|
|
465
573
|
/** The capability steps a component waves spec runs (#4545, #4541): argv templates over `{runs}` and `{plans}`. */
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #5003: the product plan keeps a product's names. A plan's own status
|
|
3
|
+
* context reaches every job that reads the plan status (the note job's
|
|
4
|
+
* `pr-post --context`, the stale job, the apply before merge), and `pr-post`
|
|
5
|
+
* posts and marks under it; on GitLab `pr-post --open --plan-job` finds a
|
|
6
|
+
* plan job of the product's name. The forge renders are in each lexicon's
|
|
7
|
+
* `product-plan-pipeline.names.test.ts`.
|
|
8
|
+
*/
|
|
9
|
+
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
10
|
+
import { tmpdir } from "node:os";
|
|
11
|
+
import { join } from "node:path";
|
|
12
|
+
import { afterAll, describe, expect, test } from "vitest";
|
|
13
|
+
import type { OpWavesSpec } from "../op/op-waves";
|
|
14
|
+
import { parseArgs } from "../cli/parse-args";
|
|
15
|
+
import { markStaleNotes, postOpenPlanReports, postPlanReport, prNoteTipMarker } from "../pr-post";
|
|
16
|
+
import { prNoteMarker } from "../pr-loop";
|
|
17
|
+
import { planNoteHandoff, PR_PLAN_NOTE_FILE, type PrPlanNote } from "../pr-plan-note";
|
|
18
|
+
import { withProductWords } from "../ci-product-words";
|
|
19
|
+
import type { ForgeStatus, OpenPullRequest, PrForge } from "../pr-forge";
|
|
20
|
+
import { TERRAGUCCI, TERRAGUCCI_NOTE } from "../__fixtures__/product-words";
|
|
21
|
+
import { productPipelineJobs } from "./product-pipeline";
|
|
22
|
+
import { productPlanJobs, productPlanWorkflowFile } from "./product-plan";
|
|
23
|
+
|
|
24
|
+
const NOTE = JSON.parse(readFileSync(join(import.meta.dirname, "..", "__fixtures__", "pr-loop", "terragucci-plan.note.json"), "utf-8")) as PrPlanNote;
|
|
25
|
+
const HEAD = NOTE.head;
|
|
26
|
+
const dirs: string[] = [];
|
|
27
|
+
afterAll(() => {
|
|
28
|
+
for (const d of dirs) rmSync(d, { recursive: true, force: true });
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
function fakeForge(open: OpenPullRequest[] = []): { forge: PrForge; statuses: Array<{ sha: string; status: ForgeStatus }>; notes: Map<string, string> } {
|
|
32
|
+
const statuses: Array<{ sha: string; status: ForgeStatus }> = [];
|
|
33
|
+
const notes = new Map<string, string>();
|
|
34
|
+
const forge = {
|
|
35
|
+
kind: "github",
|
|
36
|
+
host: "github.com",
|
|
37
|
+
async setStatus(sha: string, status: ForgeStatus) {
|
|
38
|
+
statuses.push({ sha, status });
|
|
39
|
+
},
|
|
40
|
+
async upsertNote(pr: number, marker: string, body: string) {
|
|
41
|
+
notes.set(`${pr} ${marker}`, body);
|
|
42
|
+
return "1";
|
|
43
|
+
},
|
|
44
|
+
async findComment(pr: number, marker: string) {
|
|
45
|
+
const body = notes.get(`${pr} ${marker}`);
|
|
46
|
+
return body === undefined ? undefined : { id: 1, body };
|
|
47
|
+
},
|
|
48
|
+
async openPullRequests(base: string) {
|
|
49
|
+
return open.filter((p) => p.base === base);
|
|
50
|
+
},
|
|
51
|
+
} as unknown as PrForge;
|
|
52
|
+
return { forge, statuses, notes };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const at = { pr: 7, env: "default", state: "success" as const, description: "2 roots planned" };
|
|
56
|
+
|
|
57
|
+
describe("pr-post under a product plan's own status context (#5003)", () => {
|
|
58
|
+
test("the note job posts the status under the context it is given", async () => {
|
|
59
|
+
const { forge, statuses } = fakeForge();
|
|
60
|
+
const dir = mkdtempSync(join(tmpdir(), "chant-pr-post-names-"));
|
|
61
|
+
dirs.push(dir);
|
|
62
|
+
writeFileSync(join(dir, PR_PLAN_NOTE_FILE), JSON.stringify(planNoteHandoff(NOTE, at)));
|
|
63
|
+
await withProductWords(TERRAGUCCI, () => postPlanReport({ forge, dir, pr: 7, head: HEAD, env: "default", result: "success", noteWords: TERRAGUCCI_NOTE, context: "tg/plan-roots" }));
|
|
64
|
+
expect(statuses.map((s) => s.status.context)).toEqual(["tg/plan-roots"]);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test("pr-post --open asks for the plan job it is named and posts under the context", async () => {
|
|
68
|
+
const { forge: base, statuses } = fakeForge();
|
|
69
|
+
const asked: string[] = [];
|
|
70
|
+
const forge = {
|
|
71
|
+
...base,
|
|
72
|
+
kind: "gitlab",
|
|
73
|
+
async mergeRequestJobs(_branch: string, job: string) {
|
|
74
|
+
asked.push(job);
|
|
75
|
+
return [{ pr: 7, head: HEAD, id: 11, status: "success", url: "https://gitlab.example/job/11" }];
|
|
76
|
+
},
|
|
77
|
+
async jobArtifact(_id: number, path: string) {
|
|
78
|
+
return path === "terragucci-report/pr-plan-note.json" ? JSON.stringify(planNoteHandoff(NOTE, at)) : undefined;
|
|
79
|
+
},
|
|
80
|
+
async statusUrl() {
|
|
81
|
+
return undefined;
|
|
82
|
+
},
|
|
83
|
+
setStatus: base.setStatus,
|
|
84
|
+
upsertNote: base.upsertNote,
|
|
85
|
+
findComment: base.findComment,
|
|
86
|
+
} as unknown as PrForge;
|
|
87
|
+
const done = await withProductWords(TERRAGUCCI, () => postOpenPlanReports({ forge, branch: "main", job: "tf-plan", artifactDir: "terragucci-report", env: "default", context: "tg/plan-roots" }));
|
|
88
|
+
expect(asked).toEqual(["tf-plan"]);
|
|
89
|
+
expect(done.posts[0]!.posted).toMatchObject({ noted: true });
|
|
90
|
+
expect(statuses.map((s) => s.status.context)).toEqual(["tg/plan-roots"]);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test("the stale job sets the named status back to pending", async () => {
|
|
94
|
+
const head = "d".repeat(40);
|
|
95
|
+
const { forge, statuses, notes } = fakeForge([{ number: 7, head: "feature", headSha: head, base: "main", fork: false }]);
|
|
96
|
+
notes.set(`7 ${prNoteMarker("default")}`, [prNoteMarker("default"), "body", prNoteTipMarker("a".repeat(40)), ""].join("\n"));
|
|
97
|
+
await withProductWords(TERRAGUCCI, () => markStaleNotes({ forge, branch: "main", tip: "b".repeat(40), env: "default", context: "tg/plan-roots" }));
|
|
98
|
+
expect(statuses).toEqual([{ sha: head, status: expect.objectContaining({ context: "tg/plan-roots", state: "pending" }) }]);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test("the command line takes --context (once a --member with --stale) and --plan-job", () => {
|
|
102
|
+
expect(parseArgs(["components", "pr-post", "--stale", "--member", "dev", "--context", "tg/dev/plan", "--member", "prod", "--context", "tg/prod/plan"]).statusContexts).toEqual(["tg/dev/plan", "tg/prod/plan"]);
|
|
103
|
+
expect(parseArgs(["components", "pr-post", "--open", "--plan-job", "tf-plan"]).planJob).toBe("tf-plan");
|
|
104
|
+
expect(() => parseArgs(["components", "pr-post", "--context", "tg plan"])).toThrow(/--context needs the plan status's context/);
|
|
105
|
+
expect(() => parseArgs(["components", "pr-post", "--plan-job", "--open"])).toThrow(/--plan-job needs the plan job's name/);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
const words = { product: "terragucci", noun: ["root", "roots"] as [string, string], commands: { plan: "plan" as const, apply: "apply" as const }, approval: "per-wave" as const, op: "tf-apply", bin: "npx --no-install terragucci" };
|
|
110
|
+
const waves: OpWavesSpec = { name: "tf-apply", op: "tf-apply", step: { kind: "terraform-apply", root: "{target}" }, waves: [{ name: "dev", runs: [{ target: "envs/dev" }] }] } as OpWavesSpec;
|
|
111
|
+
|
|
112
|
+
describe("the product plan's status context in the pipeline (#5003)", () => {
|
|
113
|
+
const productPlan = { command: "terragucci plan {target} --out {output}", targets: [{ name: "dev" }, { name: "prod" }], statusContext: "tg/{target}/plan" };
|
|
114
|
+
|
|
115
|
+
test.each(["github", "forgejo", "gitlab"] as const)("on %s, the stale job sets each target's own status back", (forge) => {
|
|
116
|
+
const jobs = productPipelineJobs(forge, "default", { words, waves, productPlan, staleNotes: true });
|
|
117
|
+
expect(jobs.waves!.pipeline.staleNotes!.command).toBe(`npx --no-install terragucci components pr-post --stale --tip "$TIP_SHA" --env default --forge ${forge} --member dev --member prod --context tg/dev/plan --context tg/prod/plan`);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test("the apply before merge asks for the product's plan statuses", () => {
|
|
121
|
+
const jobs = productPipelineJobs("github", "default", { words, waves, productPlan, commentJob: true, wavesBeforeMerge: {} });
|
|
122
|
+
expect(jobs.comment!.jobs.wavesBeforeMerge!.plan).toEqual(["tg/dev/plan", "tg/prod/plan"]);
|
|
123
|
+
const gitlab = productPipelineJobs("gitlab", "default", { words, waves, productPlan: { ...productPlan, replan: true }, noteCommands: true, wavesBeforeMerge: {} });
|
|
124
|
+
expect(JSON.stringify(gitlab.noteCommands!.env)).toContain('\\"plan\\":[\\"tg/dev/plan\\",\\"tg/prod/plan\\"]');
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test("without the options the jobs carry no names of their own", () => {
|
|
128
|
+
const [p] = productPlanJobs("github", "default", { plan: { command: "terragucci plan --out {output}" } }, { ...words, aliases: [] } as never);
|
|
129
|
+
expect(p!.context).toBeUndefined();
|
|
130
|
+
expect(p!.reportDir).toBeUndefined();
|
|
131
|
+
expect(productPlanWorkflowFile("gitlab", "default", { workflow: "terragucci" })).toBe(".gitlab/terragucci.gitlab-ci.yml");
|
|
132
|
+
expect(productPlanWorkflowFile("gitlab", "default", { workflowFile: ".gitlab/terragucci.yml" })).toBe(".gitlab/terragucci.yml");
|
|
133
|
+
expect(() => productPlanWorkflowFile("gitlab", "default", { workflowFile: "../ci.yml" })).toThrow(/inside it/);
|
|
134
|
+
});
|
|
135
|
+
});
|
|
@@ -65,6 +65,17 @@ describe("the product plan (#4799)", () => {
|
|
|
65
65
|
expect(() => productPipelineJobs(forge, "default", { words: terragucci, productPlan: { command: "terragucci plan", watches: [drift, drift] } })).toThrow(/name an Op twice/);
|
|
66
66
|
});
|
|
67
67
|
|
|
68
|
+
// #4988: an environment's drift watch scoped to that environment's note, as sql-yodeler warned per environment.
|
|
69
|
+
test.each(["github", "forgejo", "gitlab"] as const)("on %s, a watch's targets reach every target's note job, and a target the plan lacks is refused", (forge) => {
|
|
70
|
+
const staging = { op: "yodel-watch-staging", cron: "0 6 * * *", targets: ["staging"] };
|
|
71
|
+
const prod = { op: "yodel-watch-prod", cron: "0 6 * * *", targets: ["prod"] };
|
|
72
|
+
const jobs = productPipelineJobs(forge, "default", { words: yodel, productPlan: { ...environments, watches: [staging, prod] } }).productPlan!;
|
|
73
|
+
// pr-post --member <target> picks its own (watchesForTarget), so every note job reads the one list.
|
|
74
|
+
for (const j of jobs) expect(JSON.parse(j.post.env[PLAN_WATCHES_ENV]!)).toEqual([staging, prod]);
|
|
75
|
+
expect(() => productPipelineJobs(forge, "default", { words: yodel, productPlan: { ...environments, watches: [{ ...prod, targets: ["dev"] }] } })).toThrow("the product plan's watch yodel-watch-prod names target dev, which the plan does not have");
|
|
76
|
+
expect(() => productPipelineJobs(forge, "default", { words: terragucci, productPlan: { command: "terragucci plan", watches: [prod] } })).toThrow("the product plan's watch yodel-watch-prod names target prod, which the plan cannot scope to: it has no targets");
|
|
77
|
+
});
|
|
78
|
+
|
|
68
79
|
test("the pipeline's passed values reach every target, and a name both give is refused", () => {
|
|
69
80
|
const [staging] = productPipelineJobs("github", "default", { words: yodel, variables: { YODEL_LOG: "info" }, productPlan: environments }).productPlan!;
|
|
70
81
|
expect(staging!.env.YODEL_LOG).toBe("info");
|
|
@@ -82,7 +93,7 @@ describe("the product plan (#4799)", () => {
|
|
|
82
93
|
|
|
83
94
|
test.each([
|
|
84
95
|
["previewComment", { previewComment: true }],
|
|
85
|
-
|
|
96
|
+
// #4987: staleNotes is carried now, one note per target, marked from the waves' push run (product-pipeline.apply-status.test.ts).
|
|
86
97
|
["applyBeforeMerge", { applyBeforeMerge: true }],
|
|
87
98
|
["build", { build: true }],
|
|
88
99
|
])("refuses %s, which the product plan does not carry", (key, extra) => {
|
|
@@ -175,9 +186,17 @@ describe("the re-plan decision and the pending status scripts (#4899)", () => {
|
|
|
175
186
|
const { gitlabReplanCommentIf } = await import("./product-plan");
|
|
176
187
|
expect(gitlabReplanCommentIf({ comments: ["/yodel plan"], gated: [] }, "prod")).toBe("$CHANT_PREVIEW_COMMENT =~ /^\\/yodel plan( +prod)? *$/");
|
|
177
188
|
expect(gitlabReplanCommentIf({ comments: ["/terragucci plan"], gated: [{ comment: "atlantis plan", when: "TG_ATLANTIS_COMMENTS" }] })).toBe(
|
|
178
|
-
"$CHANT_PREVIEW_COMMENT =~ /^\\/terragucci plan( +[A-Za-z0-9_.\\/@+=,:-]
|
|
189
|
+
"$CHANT_PREVIEW_COMMENT =~ /^\\/terragucci plan( +[A-Za-z0-9_.\\/@+=,:][A-Za-z0-9_.\\/@+=,:-]*)? *$/ || ($TG_ATLANTIS_COMMENTS && $CHANT_PREVIEW_COMMENT =~ /^atlantis plan( +[A-Za-z0-9_.\\/@+=,:][A-Za-z0-9_.\\/@+=,:-]*)? *$/)",
|
|
179
190
|
);
|
|
180
191
|
});
|
|
192
|
+
|
|
193
|
+
test("a re-plan word never starts with - (#4984), so a flag is not read as a root", async () => {
|
|
194
|
+
const { isReplanWord } = await import("./product-plan");
|
|
195
|
+
expect(isReplanWord("live/app")).toBe(true);
|
|
196
|
+
expect(isReplanWord("a-b")).toBe(true);
|
|
197
|
+
expect(isReplanWord("--target=x")).toBe(false);
|
|
198
|
+
expect(isReplanWord("-r")).toBe(false);
|
|
199
|
+
});
|
|
181
200
|
});
|
|
182
201
|
|
|
183
202
|
test("PRODUCT_PLAN_STEPS_FLOOR marks the plan-job steps in the ci-product entry", async () => {
|
|
@@ -189,10 +208,9 @@ test("PRODUCT_PLAN_STEPS_FLOOR marks the plan-job steps in the ci-product entry"
|
|
|
189
208
|
describe("what terragucci's and sql-yodeler's plan jobs need (#4963)", () => {
|
|
190
209
|
const trade = { aws: { region: "us-east-1", audience: "sts.amazonaws.com", role: "arn:aws:iam::123456789012:role/plan" } };
|
|
191
210
|
|
|
192
|
-
test("PRODUCT_PLAN_REPLAN_FLOOR is the
|
|
211
|
+
test("PRODUCT_PLAN_REPLAN_FLOOR is the release that shipped it, in the ci-product entry", async () => {
|
|
193
212
|
const ciProduct = (await import("../ci-product")) as Record<string, unknown>;
|
|
194
|
-
|
|
195
|
-
expect(ciProduct.PRODUCT_PLAN_REPLAN_FLOOR).toBe(NEXT_RELEASE);
|
|
213
|
+
expect(ciProduct.PRODUCT_PLAN_REPLAN_FLOOR).toBe("0.124.89");
|
|
196
214
|
expect(typeof ciProduct.planBodyHandoff).toBe("function");
|
|
197
215
|
});
|
|
198
216
|
|