@intentius/chant 0.124.90 → 0.124.92

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.
Files changed (99) hide show
  1. package/dist/actor.d.ts +5 -3
  2. package/dist/actor.d.ts.map +1 -1
  3. package/dist/actor.js +7 -5
  4. package/dist/audit/core.d.ts.map +1 -1
  5. package/dist/audit/core.js +11 -1
  6. package/dist/ci-comment-commands.d.ts +11 -1
  7. package/dist/ci-comment-commands.d.ts.map +1 -1
  8. package/dist/ci-comment-commands.js +10 -3
  9. package/dist/ci-product.d.ts +27 -1
  10. package/dist/ci-product.d.ts.map +1 -1
  11. package/dist/ci-product.js +36 -10
  12. package/dist/cli/handlers/pr-comment.d.ts.map +1 -1
  13. package/dist/cli/handlers/pr-comment.js +17 -4
  14. package/dist/cli/handlers/pr.d.ts +2 -2
  15. package/dist/cli/handlers/pr.d.ts.map +1 -1
  16. package/dist/cli/handlers/pr.js +32 -10
  17. package/dist/cli/parse-args.d.ts.map +1 -1
  18. package/dist/cli/parse-args.js +13 -0
  19. package/dist/cli/registry.d.ts +4 -0
  20. package/dist/cli/registry.d.ts.map +1 -1
  21. package/dist/components/pr-checks.d.ts +11 -0
  22. package/dist/components/pr-checks.d.ts.map +1 -1
  23. package/dist/components/pr-checks.js +15 -5
  24. package/dist/components/pr-pipeline.d.ts +13 -4
  25. package/dist/components/pr-pipeline.d.ts.map +1 -1
  26. package/dist/components/pr-pipeline.js +23 -9
  27. package/dist/components/product-pipeline.d.ts +41 -7
  28. package/dist/components/product-pipeline.d.ts.map +1 -1
  29. package/dist/components/product-pipeline.js +63 -23
  30. package/dist/components/product-plan.d.ts +86 -1
  31. package/dist/components/product-plan.d.ts.map +1 -1
  32. package/dist/components/product-plan.js +141 -16
  33. package/dist/floor-table.data.d.ts.map +1 -1
  34. package/dist/floor-table.data.js +18 -9
  35. package/dist/lexicon-module.d.ts +2 -0
  36. package/dist/lexicon-module.d.ts.map +1 -1
  37. package/dist/lexicon-module.js +6 -2
  38. package/dist/lexicon.d.ts +42 -1
  39. package/dist/lexicon.d.ts.map +1 -1
  40. package/dist/op/before-merge-decide.d.ts +2 -0
  41. package/dist/op/before-merge-decide.d.ts.map +1 -1
  42. package/dist/op/op-waves-evidence-jobs.d.ts +3 -2
  43. package/dist/op/op-waves-evidence-jobs.d.ts.map +1 -1
  44. package/dist/op/op-waves-evidence-jobs.js +4 -3
  45. package/dist/op/op-waves-follow-on.d.ts +2 -0
  46. package/dist/op/op-waves-follow-on.d.ts.map +1 -1
  47. package/dist/op/op-waves-follow-on.js +8 -2
  48. package/dist/op/op-waves-names.d.ts +122 -0
  49. package/dist/op/op-waves-names.d.ts.map +1 -0
  50. package/dist/op/op-waves-names.js +151 -0
  51. package/dist/planned-files.d.ts +16 -8
  52. package/dist/planned-files.d.ts.map +1 -1
  53. package/dist/planned-files.js +12 -8
  54. package/dist/pr-forge-job.d.ts +8 -0
  55. package/dist/pr-forge-job.d.ts.map +1 -1
  56. package/dist/pr-forge-job.js +13 -0
  57. package/dist/pr-plan-record.d.ts +3 -1
  58. package/dist/pr-plan-record.d.ts.map +1 -1
  59. package/dist/pr-plan-record.js +1 -1
  60. package/dist/pr-post.d.ts +15 -3
  61. package/dist/pr-post.d.ts.map +1 -1
  62. package/dist/pr-post.js +10 -6
  63. package/dist/release-floors.d.ts +7 -1
  64. package/dist/release-floors.d.ts.map +1 -1
  65. package/dist/release-floors.js +8 -2
  66. package/dist/wave-runtime.mjs +276 -276
  67. package/package.json +1 -1
  68. package/src/actor.test.ts +14 -1
  69. package/src/actor.ts +8 -6
  70. package/src/audit/core.ts +13 -1
  71. package/src/audit/first-load.test.ts +101 -0
  72. package/src/ci-comment-commands.test.ts +19 -5
  73. package/src/ci-comment-commands.ts +18 -3
  74. package/src/ci-product.ts +42 -10
  75. package/src/cli/handlers/pr-comment.ts +14 -4
  76. package/src/cli/handlers/pr.ts +27 -10
  77. package/src/cli/parse-args.ts +9 -0
  78. package/src/cli/registry.ts +4 -0
  79. package/src/components/pr-checks.ts +16 -5
  80. package/src/components/pr-pipeline.ts +24 -11
  81. package/src/components/product-job-names.test.ts +176 -0
  82. package/src/components/product-pipeline.ts +101 -31
  83. package/src/components/product-plan-names.test.ts +135 -0
  84. package/src/components/product-plan.ts +218 -18
  85. package/src/floor-table.data.ts +18 -9
  86. package/src/lexicon-module.ts +6 -2
  87. package/src/lexicon.ts +42 -1
  88. package/src/op/before-merge-decide.ts +2 -0
  89. package/src/op/op-waves-evidence-jobs.ts +4 -3
  90. package/src/op/op-waves-follow-on.ts +10 -2
  91. package/src/op/op-waves-names.test.ts +131 -0
  92. package/src/op/op-waves-names.ts +241 -0
  93. package/src/planned-files.test.ts +33 -0
  94. package/src/planned-files.ts +26 -10
  95. package/src/pr-forge-job.ts +13 -0
  96. package/src/pr-plan-record.ts +4 -2
  97. package/src/pr-post-head.test.ts +116 -0
  98. package/src/pr-post.ts +26 -9
  99. package/src/release-floors.ts +11 -2
@@ -986,6 +986,15 @@ export function parseArgs(args: string[]): ParsedArgs {
986
986
  // `chant components pr-post --not-affected <argument>` (#4963): the re-plan's argument, which may be empty; pr-post checks it.
987
987
  if (i + 1 >= args.length) throw new Error('--not-affected needs the re-plan\'s argument, empty for none: --not-affected "$CHANT_PLAN_ARGUMENT"');
988
988
  result.notAffected = args[++i];
989
+ } else if (arg === "--context") {
990
+ // `chant components pr-post --context <context>` (#5003): the product plan's own plan status context; with --stale, one a --member.
991
+ const value = args[++i];
992
+ if (!value || !/^[A-Za-z0-9][A-Za-z0-9_.\/:-]*$/.test(value)) throw new Error(`--context needs the plan status's context, letters, digits and _./:-: got "${value ?? ""}"`);
993
+ result.statusContexts = [...(result.statusContexts ?? []), value];
994
+ } else if (arg === "--plan-job") {
995
+ // `chant components pr-post --open --plan-job <name>` (#5003): the product plan's own GitLab plan job, whose artifacts hold the report.
996
+ result.planJob = args[++i];
997
+ if (!result.planJob || !/^[A-Za-z0-9_][A-Za-z0-9_-]*$/.test(result.planJob)) throw new Error(`--plan-job needs the plan job's name: got "${result.planJob ?? ""}"`);
989
998
  } else if (arg === "--evidence-dir") {
990
999
  // `chant components pr-post --open --evidence-dir <dir>` (#4914): each merge request's evidence.json, from the GitLab signing job.
991
1000
  result.evidenceDir = args[++i];
@@ -615,6 +615,10 @@ export interface ParsedArgs {
615
615
  recordRun?: string;
616
616
  /** `chant components pr-post --not-affected <argument>` (#4963): the argument a re-plan was narrowed to, which gets a "not affected" reply when the change reaches nothing. */
617
617
  notAffected?: string;
618
+ /** `chant components pr-post --context <context>` (#5003): the product plan's own plan status context; with `--stale`, one a `--member`. */
619
+ statusContexts?: string[];
620
+ /** `chant components pr-post --open --plan-job <name>` (#5003): the product plan's own GitLab plan job, whose artifacts hold the report. */
621
+ planJob?: string;
618
622
  /** `chant components pr-post --open --evidence-dir <dir>` (#4914): where the GitLab signing job kept each merge request's `evidence.json`, for the note's checks line. */
619
623
  evidenceDir?: string;
620
624
  /** `chant ci evidence sign --open --no-forks` (#4914): sign for no merge request from a fork. */
@@ -165,18 +165,29 @@ function insideCheckout(path: string, glob = false): boolean {
165
165
 
166
166
  /** The check job's extra artifacts (#4988), or undefined when they name nothing; refused off GitLab and for a path outside the checkout. */
167
167
  function checkArtifacts(forge: ForgeKind, artifacts: PrCheckArtifacts | undefined): PrCheckArtifacts | undefined {
168
+ return gitlabJobArtifacts(forge, artifacts, { job: "the check job", last: "the check is the job's last step" });
169
+ }
170
+
171
+ /**
172
+ * A GitLab job's extra artifacts (#4988; #5004, the product plan's plan
173
+ * job), or undefined when they name nothing. Refused off GitLab, where
174
+ * `who.last` says why no upload can follow, for a path outside the
175
+ * checkout, a report type that is not a lower-case word, and
176
+ * `coverage_report`, which takes a format besides a path.
177
+ */
178
+ export function gitlabJobArtifacts(forge: ForgeKind, artifacts: PrCheckArtifacts | undefined, who: { job: string; last: string }): PrCheckArtifacts | undefined {
168
179
  const paths = artifacts?.paths ?? [];
169
180
  const reports = Object.entries(artifacts?.reports ?? {});
170
181
  if (paths.length === 0 && reports.length === 0) return undefined;
171
- if (forge !== "gitlab") throw new Error("the check job's artifacts are GitLab's artifacts:paths and artifacts:reports; on GitHub and Forgejo the check is the job's last step, so leave artifacts out there");
182
+ if (forge !== "gitlab") throw new Error(`${who.job}'s artifacts are GitLab's artifacts:paths and artifacts:reports; on GitHub and Forgejo ${who.last}, so leave artifacts out there`);
172
183
  for (const p of paths) {
173
- if (!insideCheckout(p, true)) throw new Error(`the check job's artifact path ${JSON.stringify(p)} is not a relative path inside the checkout`);
184
+ if (!insideCheckout(p, true)) throw new Error(`${who.job}'s artifact path ${JSON.stringify(p)} is not a relative path inside the checkout`);
174
185
  }
175
186
  for (const [type, value] of reports) {
176
- if (!/^[a-z][a-z_]*$/.test(type)) throw new Error(`the check job's artifact report ${JSON.stringify(type)} is not a GitLab report type`);
177
- if (type === "coverage_report") throw new Error("the check job's artifact reports take a path for each report type, and GitLab's coverage_report takes a format besides; keep it in a job of the product's own");
187
+ if (!/^[a-z][a-z_]*$/.test(type)) throw new Error(`${who.job}'s artifact report ${JSON.stringify(type)} is not a GitLab report type`);
188
+ if (type === "coverage_report") throw new Error(`${who.job}'s artifact reports take a path for each report type, and GitLab's coverage_report takes a format besides; keep it in a job of the product's own`);
178
189
  const list = Array.isArray(value) ? value : [value];
179
- if (list.length === 0 || list.some((p) => !insideCheckout(p, true))) throw new Error(`the check job's ${type} report ${JSON.stringify(value)} is not a relative path inside the checkout`);
190
+ if (list.length === 0 || list.some((p) => !insideCheckout(p, true))) throw new Error(`${who.job}'s ${type} report ${JSON.stringify(value)} is not a relative path inside the checkout`);
180
191
  }
181
192
  return { ...(paths.length > 0 ? { paths } : {}), ...(reports.length > 0 ? { reports: Object.fromEntries(reports) } : {}) };
182
193
  }
@@ -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
- return withProductBin(["chant", "lock", "--from-report", `${PR_LOOP_REPORT_DIR}/pr-plan.json`, "--pr", '"$PR_NUMBER"', "--head", '"$HEAD_SHA"', "--stage", "plan", "--forge", forge].join(" "), bin);
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`. */
@@ -982,9 +983,11 @@ export const PR_PLAN_NOTE_JOB = "plan-note";
982
983
  * and Forgejo it runs in a fresh job after the plan, at the target branch's
983
984
  * commit, and posts the note and the `chant/plan` status from the report
984
985
  * the plan job handed on, with the forge token the plan job never held.
985
- * `HEAD_SHA` is the commit the plan job checked out, `PR_NUMBER` the pull
986
+ * `HEAD_SHA` is the pull request's head (#5020), `PR_NUMBER` the pull
986
987
  * request, and `PLAN_RESULT` the plan job's result, which fails the status
987
- * when the plan job failed.
988
+ * when the plan job failed. A GitHub plan job checks out the merge preview
989
+ * (`github.sha`), and `pr-post` takes a report for it as the head's
990
+ * (`pullRequestHeads` in ../pr-forge-job.ts).
988
991
  *
989
992
  * On GitLab (#4328) it runs `pr-post --open` in a pipeline of the target
990
993
  * branch, which GitLab builds from that branch's files and gives the
@@ -992,8 +995,11 @@ export const PR_PLAN_NOTE_JOB = "plan-note";
992
995
  * merge request's files, so no job in it holds the token. `pr-post --open`
993
996
  * asks GitLab for each open merge request's plan job and reads its report
994
997
  * from the job's artifacts.
998
+ *
999
+ * `output` (#5003) is the report directory, `--output`: a product plan's
1000
+ * `reportDir`, default {@link PR_LOOP_REPORT_DIR}.
995
1001
  */
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> } {
1002
+ 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
1003
  // #4629: the responses as CHANT_RESPOND, and with the description check its decide service on the line.
998
1004
  const respondEnv = prLoopRespondEnv(opts);
999
1005
  const decide = opts.respond?.description === "check" && opts.decide ? ` --decide-backend ${JSON.stringify(opts.decide.backend)} --decide-model ${JSON.stringify(opts.decide.model)}` : "";
@@ -1001,18 +1007,19 @@ export function prLoopPostJob(forge: ForgeKind, env: string, member?: string, wo
1001
1007
  return decide || Object.keys(respondEnv).length > 0 ? { command: `${job.command}${decide}`, env: { ...job.env, ...respondEnv } } : job;
1002
1008
  }
1003
1009
 
1004
- function prLoopPostJobBase(forge: ForgeKind, env: string, member: string | undefined, words: Pick<CiProductWordsInput, "bin"> | undefined, opts: { staleNotes?: boolean }): { command: string; env: Record<string, string> } {
1010
+ 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
1011
  // #4628: with staleNotes the note carries the target branch's commit, so a later push can mark it stale.
1006
1012
  const tip = opts.staleNotes ? ["--tip", '"$TIP_SHA"'] : [];
1013
+ const output = opts.output ?? PR_LOOP_REPORT_DIR;
1007
1014
  if (forge === "gitlab") {
1008
1015
  return {
1009
- command: withProductBin(["chant", "components", "pr-post", "--open", "--env", env, "--output", PR_LOOP_REPORT_DIR, "--forge", forge, ...(member ? ["--member", member] : []), ...tip].join(" "), words?.bin),
1016
+ command: withProductBin(["chant", "components", "pr-post", "--open", "--env", env, "--output", output, "--forge", forge, ...(member ? ["--member", member] : []), ...tip].join(" "), words?.bin),
1010
1017
  env: opts.staleNotes ? { TIP_SHA: "$CI_COMMIT_SHA" } : {},
1011
1018
  };
1012
1019
  }
1013
1020
  const command = [
1014
1021
  "chant", "components", "pr-post", "--pr", '"$PR_NUMBER"', "--head", '"$HEAD_SHA"',
1015
- "--env", env, "--output", PR_LOOP_REPORT_DIR, "--forge", forge,
1022
+ "--env", env, "--output", output, "--forge", forge,
1016
1023
  ...(member ? ["--member", member] : []),
1017
1024
  "--result", '"$PLAN_RESULT"',
1018
1025
  ...tip,
@@ -1021,7 +1028,8 @@ function prLoopPostJobBase(forge: ForgeKind, env: string, member: string | undef
1021
1028
  command: withProductBin(command, words?.bin),
1022
1029
  env: {
1023
1030
  PR_NUMBER: "${{ github.event.pull_request.number }}",
1024
- HEAD_SHA: "${{ github.sha }}",
1031
+ // #5020: the head, where the forge shows and requires the status; GitHub's github.sha is the merge preview.
1032
+ HEAD_SHA: "${{ github.event.pull_request.head.sha }}",
1025
1033
  PLAN_RESULT: "${{ needs.plan.result }}",
1026
1034
  ...(opts.staleNotes ? { TIP_SHA: "${{ github.event.pull_request.base.sha }}" } : {}),
1027
1035
  GITHUB_TOKEN: GITHUB_JOB_TOKEN,
@@ -1039,15 +1047,20 @@ export const PR_STALE_JOB = "stale-notes";
1039
1047
  * commit stale and sets its plan status back to pending. It names the plan
1040
1048
  * comment with `previewComment`. Undefined without `staleNotes`. A list
1041
1049
  * of members (#4987, a product plan's targets) marks each one's note.
1050
+ * `contexts` (#5003, a product plan's `statusContext`) are the plan
1051
+ * statuses it sets back to pending, one per member in the same order (one
1052
+ * for none), as `--context`.
1042
1053
  */
1043
- export function prStaleJob(forge: ForgeKind, env: string, options: Pick<PrLoopPipelineOptions, "staleNotes" | "previewComment" | "branch" | "words"> = {}, member?: string | readonly string[]): { command: string; env: Record<string, string> } | undefined {
1054
+ 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 {
1044
1055
  if (!options.staleNotes) return undefined;
1045
1056
  const words = resolveProductWords(options.words);
1046
1057
  const members = member === undefined ? [] : typeof member === "string" ? [member] : [...member];
1058
+ 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`);
1047
1059
  const command = [
1048
1060
  "chant", "components", "pr-post", "--stale", "--tip", '"$TIP_SHA"', "--env", env, "--forge", forge,
1049
1061
  ...(options.branch ? ["--branch", JSON.stringify(options.branch)] : []),
1050
1062
  ...members.flatMap((m) => ["--member", m]),
1063
+ ...(contexts ?? []).flatMap((c) => ["--context", c]),
1051
1064
  ...(options.previewComment ? ["--preview-comment"] : []),
1052
1065
  ].join(" ");
1053
1066
  return {
@@ -1318,7 +1331,7 @@ export function prEnvJobs(forge: ForgeKind, options: PrLoopPipelineOptions = {},
1318
1331
  jobName: PR_ENV_POST_JOB,
1319
1332
  command: ["chant", "components", "pr-env", "post", "--pr", '"$PR_NUMBER"', "--head", '"$HEAD_SHA"', ...common, ...(github ? ["--result", '"$UP_RESULT"'] : [])].join(" "),
1320
1333
  env: github
1321
- ? { PR_NUMBER: prNumber, HEAD_SHA: "${{ github.sha }}", UP_RESULT: "${{ needs.env-up.result }}", ...token }
1334
+ ? { PR_NUMBER: prNumber, HEAD_SHA: "${{ github.event.pull_request.head.sha }}", UP_RESULT: "${{ needs.env-up.result }}", ...token }
1322
1335
  : { PR_NUMBER: prNumber, HEAD_SHA: "$CI_COMMIT_SHA", BASE_SHA: "$CI_MERGE_REQUEST_DIFF_BASE_SHA" },
1323
1336
  },
1324
1337
  {
@@ -0,0 +1,176 @@
1
+ /**
2
+ * #5027: the product pipeline names its comment job and its waves' jobs as
3
+ * the product does. The comment job takes `commentJob.jobName` (terragucci's
4
+ * `apply-comment`), and a merged pull request's re-run looks for the waves'
5
+ * jobs under the same `jobNames` the Op waves generator renders (#5022), so
6
+ * terragucci's `apply-wave-<k>`, its shares, its group jobs and `apply-rest`
7
+ * run again. Without them the job is `comment` and the re-run's pattern is
8
+ * `RERUN_APPLY_JOBS`, as before.
9
+ */
10
+ import { describe, expect, test } from "vitest";
11
+ import type { OpWavesSpec } from "../op/op-waves";
12
+ import type { OpWavesJobRef } from "../op/op-waves-names";
13
+ import { answerProductComment, RERUN_APPLY_JOBS, rerunApplyJobs, type AnswerCommentOptions, type CommentJobs } from "../ci-comment-commands";
14
+ import { assertProductWords } from "../ci-product-words";
15
+ import { commentJobsFromEnv } from "../cli/handlers/pr-comment";
16
+ import type { ForgeReads, PullRequestDetail, RunJob, WorkflowRun } from "../pr-forge-reads";
17
+ import { PR_COMMENT_JOB } from "../ci-comment-commands";
18
+ import { productPipelineJobs } from "./product-pipeline";
19
+
20
+ 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: "terragucci" };
21
+
22
+ /** The waves of PR 5026's names goldens: a canary, a wide wave with shares, a wave of job groups (one with shares) and a rest wave. */
23
+ const waves = {
24
+ name: "tf-apply",
25
+ op: "tf-apply",
26
+ planWave: ["terragucci", "plan-wave", "{runs}", "{plans}"],
27
+ apply: ["terragucci", "apply", "{target}", "--plan", "{plan}"],
28
+ waves: [
29
+ { name: "canary", runs: [], discover: true },
30
+ { name: "wide", runs: [], discover: true, shares: 2 },
31
+ { name: "regions", runs: [], discover: true, jobs: [{ name: "east", runs: ["east/*"] }, { name: "west", runs: ["west/*"], shares: 2 }] },
32
+ { name: "rest", runs: [], discover: true, rest: true },
33
+ ],
34
+ } as unknown as OpWavesSpec;
35
+
36
+ /** terragucci's names, as PR 5026's names goldens give them. */
37
+ const terragucciJob = (j: OpWavesJobRef): string | undefined => {
38
+ const w = j.rest ? "apply-rest" : `apply-wave-${j.wave}`;
39
+ const part = `${j.group !== undefined ? `-${j.group}` : ""}${j.share !== undefined ? `-share-${j.share}` : ""}`;
40
+ switch (j.role) {
41
+ case "wave":
42
+ case "decide":
43
+ return w;
44
+ case "share":
45
+ case "group":
46
+ case "apply":
47
+ return `${w}${part}`;
48
+ case "plan":
49
+ case "gate":
50
+ case "record":
51
+ return `${w}-${j.role}`;
52
+ case "apply-status":
53
+ return j.wave === waves.waves.length ? "apply-done" : `${w}-status`;
54
+ case "before-merge-done":
55
+ return "pr-merge";
56
+ case "control":
57
+ return "control";
58
+ default:
59
+ return undefined;
60
+ }
61
+ };
62
+
63
+ const PUSH_JOBS = ["apply-wave-1", "apply-wave-2", "apply-wave-2-share-1", "apply-wave-2-share-2", "apply-wave-3", "apply-wave-3-east", "apply-wave-3-west-share-1", "apply-wave-3-west-share-2", "apply-rest"];
64
+ const productPlan = { command: "terragucci plan --out {output}", replan: true };
65
+ const env = (jobs: { comment?: { env: Record<string, string> } }): CommentJobs => JSON.parse(jobs.comment!.env.CHANT_COMMENT_JOBS!);
66
+
67
+ describe("the comment job's name (#5027)", () => {
68
+ test("is the product's, and comment by default", () => {
69
+ const named = productPipelineJobs("github", "default", { words, waves, productPlan, commentJob: { jobName: "apply-comment" } });
70
+ expect(named.comment!.jobName).toBe("apply-comment");
71
+ for (const commentJob of [true, {}] as const) expect(productPipelineJobs("github", "default", { words, waves, productPlan, commentJob }).comment!.jobName).toBe(PR_COMMENT_JOB);
72
+ expect(PR_COMMENT_JOB).toBe("comment");
73
+ });
74
+
75
+ test("a name the forge cannot take is refused", () => {
76
+ expect(() => productPipelineJobs("github", "default", { words, waves, productPlan, commentJob: { jobName: "apply comment" } })).toThrow(/commentJob\.jobName "apply comment" is not a job name/);
77
+ expect(() => productPipelineJobs("forgejo", "default", { words, waves, productPlan, commentJob: { jobName: "1st" } })).toThrow(/not a job name/);
78
+ });
79
+ });
80
+
81
+ describe("the re-run's jobs follow the waves' names (#5027)", () => {
82
+ test("by default the comment job carries no list and the re-run keeps RERUN_APPLY_JOBS", () => {
83
+ const jobs = productPipelineJobs("github", "default", { words, waves, productPlan, commentJob: true });
84
+ expect(env(jobs).applyJobs).toBeUndefined();
85
+ expect(jobs.comment!.jobs.applyJobs).toBeUndefined();
86
+ expect(jobs.waves!.pipeline.jobNames).toBeUndefined();
87
+ expect(jobs.waves!.jobs.map((j) => j.jobName)).toEqual(["wave-1-canary", "wave-2-wide-decide", "wave-2-wide-share-1", "wave-2-wide-share-2", "wave-3-regions-decide", "wave-3-regions-east", "wave-3-regions-west-share-1", "wave-3-regions-west-share-2", "wave-4-rest"]);
88
+ expect(rerunApplyJobs({})).toBe(RERUN_APPLY_JOBS);
89
+ expect(rerunApplyJobs({ applyJobs: [] })).toBe(RERUN_APPLY_JOBS);
90
+ });
91
+
92
+ test("with terragucci's names the comment job looks for apply-wave-<k>, its shares, its groups and apply-rest", () => {
93
+ const jobs = productPipelineJobs("github", "default", { words, waves, productPlan, commentJob: { jobName: "apply-comment" }, wavesJobNames: terragucciJob });
94
+ expect(env(jobs).applyJobs).toEqual(PUSH_JOBS);
95
+ expect(jobs.waves!.jobs.map((j) => j.jobName)).toEqual(PUSH_JOBS);
96
+ expect(jobs.waves!.jobs.find((j) => j.jobName === "apply-wave-2-share-1")!.needs).toEqual(["apply-wave-2"]);
97
+ // The generator is handed the same names, so the jobs it renders are the ones the re-run looks for.
98
+ expect(jobs.waves!.pipeline.jobNames).toBe(terragucciJob);
99
+ const pattern = rerunApplyJobs(env(jobs));
100
+ for (const name of PUSH_JOBS) expect(pattern.test(name), name).toBe(true);
101
+ for (const name of ["apply-comment", "apply-wave-1-evidence", "apply-wave-1-status", "apply-done", "stale-notes", "control", "apply-wave-10", "xapply-rest", "wave-1-canary"]) expect(pattern.test(name), name).toBe(false);
102
+ // chant's pattern skips the group jobs and the rest wave, which is what #5027 is about.
103
+ expect(["apply-wave-3-east", "apply-wave-3-west-share-1", "apply-rest"].filter((n) => RERUN_APPLY_JOBS.test(n))).toEqual([]);
104
+ });
105
+
106
+ test("before merge the split jobs are looked for too, by the same names", () => {
107
+ const jobs = productPipelineJobs("github", "default", { words, waves, productPlan, commentJob: { jobName: "apply-comment" }, wavesJobNames: terragucciJob, wavesBeforeMerge: { workflowFile: "terragucci.yml", dispatchInputs: { pr: "apply_pr", head: "apply_head", digest: "apply_digest" } } });
108
+ const names = env(jobs).applyJobs!;
109
+ for (const name of [...PUSH_JOBS, "apply-wave-1-plan", "apply-wave-1-gate", "apply-wave-1-record", "apply-wave-2-share-2", "apply-wave-3-west-share-1", "apply-rest-plan", "apply-rest-record"]) expect(names, name).toContain(name);
110
+ expect(new Set(names).size).toBe(names.length);
111
+ expect(jobs.waves!.pipeline).toMatchObject({ workflowFile: "terragucci.yml", jobNames: terragucciJob });
112
+ });
113
+
114
+ test("is refused without waves, and the generator's checks hold", () => {
115
+ expect(() => productPipelineJobs("github", "default", { words, productPlan, commentJob: true, wavesJobNames: terragucciJob })).toThrow(/wavesJobNames names the waves' jobs, and there are none/);
116
+ expect(() => productPipelineJobs("github", "default", { words, waves, productPlan, commentJob: true, wavesJobNames: () => "apply" })).toThrow(/names two jobs apply/);
117
+ });
118
+
119
+ test("the job reads the list from CHANT_COMMENT_JOBS, and refuses one that is not job names", () => {
120
+ expect(commentJobsFromEnv(JSON.stringify({ applyOnMerge: true, applyJobs: PUSH_JOBS })).applyJobs).toEqual(PUSH_JOBS);
121
+ expect(commentJobsFromEnv(JSON.stringify({ applyJobs: [] })).applyJobs).toBeUndefined();
122
+ expect(() => commentJobsFromEnv(JSON.stringify({ applyJobs: ["apply-rest", "a b"] }))).toThrow(/applyJobs is a list of job names/);
123
+ expect(() => commentJobsFromEnv(JSON.stringify({ applyJobs: "apply-rest" }))).toThrow(/applyJobs is a list of job names/);
124
+ });
125
+ });
126
+
127
+ describe("a merged pull request's apply runs terragucci's jobs again (#5027)", () => {
128
+ const MERGE = "a".repeat(40);
129
+ const run: WorkflowRun = { id: 10, event: "push", headSha: MERGE, status: "completed", conclusion: "failure", done: true, pullRequests: [], workflow: "terragucci.yml", url: "https://github.com/acme/infra/actions/runs/10" };
130
+ const job = (id: number, name: string, conclusion: string): RunJob => ({ id, name, status: "completed", conclusion, done: true }) as RunJob;
131
+
132
+ const answer = async (jobs: CommentJobs, runJobs: RunJob[], forge: "github" | "forgejo" = "github") => {
133
+ const posted: string[] = [];
134
+ const reran: number[] = [];
135
+ const dispatched: string[] = [];
136
+ const reads = {
137
+ kind: forge,
138
+ permission: async () => "write",
139
+ pullRequest: async (n: number) => ({ number: n, title: "", body: "", state: "merged", head: "feature", headSha: "c".repeat(40), base: "main", sameRepo: true, mergeCommit: MERGE }) as PullRequestDetail,
140
+ headRuns: async () => [run],
141
+ runJobs: async () => runJobs,
142
+ branchRuns: async () => [run],
143
+ } as unknown as ForgeReads;
144
+ const opts: AnswerCommentOptions = {
145
+ forge,
146
+ event: { action: "created", comment: { id: 7, body: "/terragucci apply", user: { login: "alice" } }, issue: { number: 12, pull_request: {} }, repository: { full_name: "acme/infra", permissions: { push: true } }, sender: { login: "alice" } },
147
+ repo: "acme/infra",
148
+ reads,
149
+ poster: { addComment: async (_n: number, text: string) => (posted.push(text), { id: 1 } as never), commitStatuses: async () => [] as never },
150
+ runs: { rerunFailed: async (id) => (reran.push(id), {}), dispatch: async (wf) => (dispatched.push(wf), {}) },
151
+ words: assertProductWords(words),
152
+ base: "main",
153
+ jobs,
154
+ };
155
+ const got = await answerProductComment(opts);
156
+ return { got, posted, reran, dispatched };
157
+ };
158
+
159
+ test("a run whose only failure is apply-rest is started again, where chant's pattern would see the earlier waves' successes alone", async () => {
160
+ const jobs = productPipelineJobs("github", "default", { words, waves, productPlan, commentJob: { jobName: "apply-comment" }, wavesJobNames: terragucciJob });
161
+ const runJobs = [...PUSH_JOBS.slice(0, -1).map((n, i) => job(i + 1, n, "success")), job(99, "apply-rest", "failure"), job(100, "apply-comment", "failure")];
162
+ const named = await answer(commentJobsFromEnv(jobs.comment!.env.CHANT_COMMENT_JOBS), runJobs);
163
+ expect(named.reran).toEqual([10]);
164
+ expect(named.got.ran).toBe(true);
165
+ const chant = await answer({ applyOnMerge: true }, runJobs);
166
+ expect(chant.reran).toEqual([]);
167
+ expect(chant.posted[0]).toMatch(/already succeeded/);
168
+ });
169
+
170
+ test("on Forgejo a failed group job dispatches the workflow again", async () => {
171
+ const jobs = productPipelineJobs("forgejo", "default", { words, waves, productPlan, commentJob: { jobName: "apply-comment" }, wavesJobNames: terragucciJob });
172
+ const runJobs = [job(1, "apply-wave-1", "success"), job(2, "apply-wave-3-east", "failure")];
173
+ const got = await answer(commentJobsFromEnv(jobs.comment!.env.CHANT_COMMENT_JOBS), runJobs, "forgejo");
174
+ expect(got.dispatched).toEqual(["terragucci.yml"]);
175
+ });
176
+ });
@@ -43,13 +43,15 @@ import type { CiRunner } from "../ci-jobs";
43
43
  import { resolveAgentSpec, type OpAgentSpec } from "../ci-agent";
44
44
  import { resolveCommitSpec, type OpCommitSpec } from "../ci-commit";
45
45
  import type { CiResponses } from "../ci-respond";
46
- 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";
47
47
  import { gitlabOpenEvidenceDir, type PipelineEvidence } from "../ci-evidence-jobs";
48
48
  import { prCheckJob, prRefGateJob, type PrCheckJob, type PrRefGateJob } from "./pr-checks";
49
49
  import { COMMENT_JOBS_ENV, PR_COMMENT_JOB, type CommentJobs } from "../ci-comment-commands";
50
50
  import { GITHUB_JOB_TOKEN } from "../ci-jobs";
51
51
  import type { OpWavesBeforeMerge } from "../op/before-merge";
52
52
  import { defaultPipelineFiles, type WavesBeforeMergeJobs } from "../op/before-merge-decide";
53
+ import { opWavesDispatchInputs, opWavesInputsRenamed, opWavesNamer, opWavesWorkflowFile, type OpWavesJobNames } from "../op/op-waves-names";
54
+ import { opWaveSplitJobs } from "../op/op-waves-split";
53
55
  import type { PrApplyRequire } from "../pr-requires";
54
56
  import { LOCK_REACH_ENV } from "../lifecycle/reach-locks";
55
57
 
@@ -149,9 +151,19 @@ export interface ProductPipelineOptions extends Omit<PrLoopPipelineOptions, "wor
149
151
  * chant's), and with waves on merge the re-run of a merged pull request's
150
152
  * apply. The jobs it leaves comments to are the ones these options write.
151
153
  * On GitLab the note-commands job answers every note already; refused
152
- * there.
154
+ * there. `{ jobName }` (#5027) names the job, such as terragucci's
155
+ * `apply-comment`. Default `comment`.
153
156
  */
154
- commentJob?: boolean;
157
+ commentJob?: boolean | ProductCommentJobOptions;
158
+ /**
159
+ * The waves' job names (#5027), the Op waves generators' `jobNames`
160
+ * (#5022): `waves.pipeline` carries them to the generator, `waves.jobs`
161
+ * takes them, and the comment job's re-run of a merged pull request's
162
+ * apply looks for the jobs under them (`CHANT_COMMENT_JOBS`
163
+ * `applyJobs`). Absent: chant's names, and the re-run looks for
164
+ * `RERUN_APPLY_JOBS`. Needs `waves` (or `componentWaves`).
165
+ */
166
+ wavesJobNames?: OpWavesJobNames;
155
167
  /**
156
168
  * Waves before merge (#4984, maintainer decision 2026-11-10): `/<product>
157
169
  * apply [wave-<n>]` on an open pull request runs the waves on its head.
@@ -189,11 +201,32 @@ export interface ProductWavesBeforeMerge {
189
201
  mergeTokenSecret?: string;
190
202
  /** 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
203
  pipelineFiles?: string[];
204
+ /**
205
+ * GitHub and Forgejo (#5022): the workflow the waves are in, which the
206
+ * comment job dispatches, such as `terragucci.yml`. Default `<op>.yml`.
207
+ * The product passes `waves.pipeline` on, which carries it as the
208
+ * generator's `workflowFile`.
209
+ */
210
+ workflowFile?: string;
211
+ /**
212
+ * GitHub and Forgejo (#5022): the waves workflow's names of the inputs
213
+ * `pr`, `head` and `digest`, which the comment job dispatches with, so
214
+ * they never meet the product's own. `waves.pipeline` carries them as
215
+ * the generator's `dispatchInputs`. Default chant's.
216
+ */
217
+ dispatchInputs?: Partial<Record<"pr" | "head" | "digest", string>>;
218
+ }
219
+
220
+ /** {@link ProductPipelineOptions.commentJob}'s settings (#5027). */
221
+ export interface ProductCommentJobOptions {
222
+ /** The comment job's name in the workflow, such as `apply-comment`. Default {@link PR_COMMENT_JOB}. */
223
+ jobName?: string;
192
224
  }
193
225
 
194
226
  /** The comment job (#4946): its command, the values it reads, and the comment prefixes that start it. */
195
227
  export interface ProductCommentJob {
196
- jobName: typeof PR_COMMENT_JOB;
228
+ /** {@link PR_COMMENT_JOB}, or the product's `commentJob.jobName` (#5027). */
229
+ jobName: string;
197
230
  /** `<bin> components pr-comment --forge <forge>`. */
198
231
  command: string;
199
232
  /** `GITHUB_TOKEN` and {@link COMMENT_JOBS_ENV}. */
@@ -241,8 +274,10 @@ export interface ProductPipelineJobs {
241
274
  * `applyStatus` and, with `staleNotes`, the stale marking job that runs
242
275
  * beside wave 1 on a push (one `--member` per product plan target). The
243
276
  * product spreads it into the `OpWavesPipelineOptions` it renders with.
277
+ * #5022: with them, `wavesBeforeMerge`'s `workflowFile` and
278
+ * `dispatchInputs`, which the comment job dispatches by.
244
279
  */
245
- pipeline: Pick<OpWavesPipelineOptions, "beforeMerge" | "applyStatus" | "staleNotes">;
280
+ pipeline: Pick<OpWavesPipelineOptions, "beforeMerge" | "applyStatus" | "staleNotes" | "workflowFile" | "dispatchInputs" | "jobNames">;
246
281
  };
247
282
  /**
248
283
  * The comment lock and unlock jobs (#4588), under `locks: "plan"`:
@@ -410,7 +445,7 @@ export function productPipelineJobs(forge: ForgeKind, env: string, options: Prod
410
445
  // #4946: the comment job answers every command but a commit word (the commit job's) with a reply, so the words may name any.
411
446
  const answered: CiProductCommand[] = options.commentJob ? [...new Set<CiProductCommand>([...jobs, ...CI_PRODUCT_COMMANDS.filter((c) => c !== "commit")])] : jobs;
412
447
  const words = assertProductWords({ ...options.words, applyMode }, { jobs: answered });
413
- const { waves: given, wavesSpecFile, member, agent: _agent, commits: _commits, actions: _actions, componentWaves, productPlan, evidence, commentJob: _commentJob, wavesBeforeMerge, applyStatus: _applyStatus, ...loop } = options;
448
+ const { waves: given, wavesSpecFile, member, agent: _agent, commits: _commits, actions: _actions, componentWaves, productPlan, evidence, commentJob: _commentJob, wavesBeforeMerge, applyStatus: _applyStatus, wavesJobNames, ...loop } = options;
414
449
  if (options.applyStatus && !given && !componentWaves) throw new Error("applyStatus posts the waves' apply statuses, and there are none: give waves (or componentWaves)");
415
450
  const { respond } = options;
416
451
  // #4629: the pull request loop puts the responses on the apply and note jobs, as `chant build --pr-loop --respond` does.
@@ -455,8 +490,10 @@ export function productPipelineJobs(forge: ForgeKind, env: string, options: Prod
455
490
  const action = prActionJob(forge, prLoop);
456
491
  if (action) out.action = { ...action, ...(prLoopRunner(options, "apply") !== undefined ? { runner: prLoopRunner(options, "apply")! } : {}) };
457
492
  // #4987: a product plan's notes are marked from the waves workflow's push run, one --member per target, naming the re-plan comment.
493
+ // #5003: with the product's status context, the stale job sets that status back to pending, one a target.
494
+ const planContexts = productPlan?.statusContext !== undefined ? out.productPlan!.map((p) => productPlanContext(p, words)) : undefined;
458
495
  const planStale = productPlan
459
- ? prStaleJob(forge, env, { ...prLoop, ...(productPlan.replan ? { previewComment: true } : {}) }, productPlan.targets?.map((t) => t.name) ?? member)
496
+ ? prStaleJob(forge, env, { ...prLoop, ...(productPlan.replan ? { previewComment: true } : {}) }, productPlan.targets?.map((t) => t.name) ?? member, planContexts)
460
497
  : undefined;
461
498
  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");
462
499
  const stale = productPlan ? undefined : prStaleJob(forge, env, prLoop, member);
@@ -493,10 +530,16 @@ export function productPipelineJobs(forge: ForgeKind, env: string, options: Prod
493
530
  if (options.applyBeforeMerge) throw new Error("wavesBeforeMerge and applyBeforeMerge both answer an open pull request's apply; give one");
494
531
  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"}`);
495
532
  const targets = productPlan?.targets?.map((t) => t.name);
533
+ if (forge === "gitlab" && (wavesBeforeMerge.workflowFile !== undefined || wavesBeforeMerge.dispatchInputs !== undefined)) throw new Error("wavesBeforeMerge.workflowFile and dispatchInputs name a GitHub or Forgejo workflow; GitLab's note poll starts a pipeline with variables");
534
+ // #5022: the product's workflow and input names, checked as the generator checks them.
535
+ const workflowFile = opWavesWorkflowFile({ name: wavesOp }, wavesBeforeMerge.workflowFile);
536
+ const dispatchInputs = wavesBeforeMerge.dispatchInputs ? opWavesDispatchInputs(wavesBeforeMerge.dispatchInputs) : undefined;
496
537
  bmJobs = {
497
- ...(forge !== "gitlab" ? { workflow: `${wavesOp}.yml` } : {}),
538
+ ...(forge !== "gitlab" ? { workflow: workflowFile } : {}),
539
+ ...(dispatchInputs && opWavesInputsRenamed(dispatchInputs) ? { inputs: { pr: dispatchInputs.pr, head: dispatchInputs.head, digest: dispatchInputs.digest } } : {}),
498
540
  ...(wavesBeforeMerge.requires ? { requires: [...wavesBeforeMerge.requires] } : {}),
499
- plan: targets?.length ? targets.map((t) => productStatusContext(words, "plan", t)) : [productStatusContext(words, "plan", member)],
541
+ // #5003: the product's own status contexts, when it named them.
542
+ plan: planContexts ?? (targets?.length ? targets.map((t) => productStatusContext(words, "plan", t)) : [productStatusContext(words, "plan", member)]),
500
543
  pipelineFiles: wavesBeforeMerge.pipelineFiles ?? defaultPipelineFiles(forge),
501
544
  ...(productPlan?.reach ? { locks: { ...(productPlan.reach.gate ? { gate: productPlan.reach.gate } : {}) } } : {}),
502
545
  };
@@ -511,6 +554,27 @@ export function productPipelineJobs(forge: ForgeKind, env: string, options: Prod
511
554
  },
512
555
  };
513
556
  }
557
+ const wavesRespond = respond ? Object.fromEntries(Object.entries(respond).filter(([e]) => e !== "description")) : {};
558
+ // #4625: the waves run on the apply runner and with the plan's parallelism, unless the spec names its own.
559
+ const applyRunner = prLoopRunner(options, "apply");
560
+ const named = spec
561
+ ? {
562
+ ...productWavesSpec(
563
+ {
564
+ ...spec,
565
+ ...(spec.runner === undefined && applyRunner !== undefined ? { runner: applyRunner } : {}),
566
+ ...(spec.parallelism === undefined && options.parallelism !== undefined && spec.step !== undefined ? { parallelism: options.parallelism } : {}),
567
+ },
568
+ words,
569
+ ),
570
+ ...(Object.keys(wavesRespond).length > 0 ? { respond: { ...(spec.respond ?? {}), ...wavesRespond } } : {}),
571
+ }
572
+ : undefined;
573
+ const specFile = named ? (wavesSpecFile ?? productWavesSpecFile(named.name)) : undefined;
574
+ if (wavesJobNames !== undefined && !named) throw new Error("wavesJobNames names the waves' jobs, and there are none: give waves (or componentWaves)");
575
+ // #5027: the waves' jobs under the product's names, the same the generator gives them from the same jobNames.
576
+ const waveJobs = named && specFile ? opWaveJobs(named, specFile, { bin: words.bin, ...(wavesBeforeMerge ? { beforeMerge: true } : {}) }) : undefined;
577
+ const namedWaveJobs = waveJobs && wavesJobNames ? opWavesNamer(named!, forge, wavesJobNames).jobs(waveJobs) : waveJobs;
514
578
  // #4946: the comment job answers what no other job of the pipeline takes, so it is told which jobs there are.
515
579
  if (options.commentJob) {
516
580
  // #4963's re-plan reply answers the same stray comments, so one of the two answers them.
@@ -532,39 +596,43 @@ export function productPipelineJobs(forge: ForgeKind, env: string, options: Prod
532
596
  ...(out.agent ? { agent: true } : {}),
533
597
  ...(out.commits ? { commits: true } : {}),
534
598
  ...(options.actions || options.actionJob ? { actions: true } : {}),
599
+ // #5027: a re-run looks for the waves' jobs by the product's names; without them, by chant's pattern.
600
+ ...(namedWaveJobs && wavesJobNames ? { applyJobs: productApplyJobs(named!, waveJobs!, namedWaveJobs, forge, wavesJobNames, wavesBeforeMerge !== undefined) } : {}),
535
601
  };
536
- const comment = productCommentJob(forge, words, commentJobs);
602
+ const comment = productCommentJob(forge, words, commentJobs, typeof options.commentJob === "object" ? options.commentJob.jobName : undefined);
537
603
  // #4984: the decision before merge locks what the reach line prints, at stage apply.
538
604
  if (bmJobs && productPlan?.reach) comment.env = { ...comment.env, [LOCK_REACH_ENV]: productPlan.reach.command };
539
605
  out.comment = { ...comment, ...defaultRunner };
540
606
  }
541
- if (!spec) return { ...out, record: record! };
542
- const wavesRespond = respond ? Object.fromEntries(Object.entries(respond).filter(([e]) => e !== "description")) : {};
543
- // #4625: the waves run on the apply runner and with the plan's parallelism, unless the spec names its own.
544
- const applyRunner = prLoopRunner(options, "apply");
545
- const named = {
546
- ...productWavesSpec(
547
- {
548
- ...spec,
549
- ...(spec.runner === undefined && applyRunner !== undefined ? { runner: applyRunner } : {}),
550
- ...(spec.parallelism === undefined && options.parallelism !== undefined && spec.step !== undefined ? { parallelism: options.parallelism } : {}),
551
- },
552
- words,
553
- ),
554
- ...(Object.keys(wavesRespond).length > 0 ? { respond: { ...(spec.respond ?? {}), ...wavesRespond } } : {}),
555
- };
556
- const specFile = wavesSpecFile ?? productWavesSpecFile(named.name);
607
+ if (!named || !specFile || !namedWaveJobs) return { ...out, record: record! };
557
608
  // #4984: what the generator's before-merge mode takes: the merge after the last wave and the lock file it releases.
558
609
  const beforeMerge: OpWavesBeforeMerge | undefined = wavesBeforeMerge
559
610
  ? { ...(wavesBeforeMerge.merge ? { merge: wavesBeforeMerge.merge } : {}), ...(wavesBeforeMerge.mergeTokenSecret ? { mergeTokenSecret: wavesBeforeMerge.mergeTokenSecret } : {}), ...(productPlan?.reach?.gate ? { gate: productPlan.reach.gate } : {}) }
560
611
  : undefined;
561
612
  // #4987: the apply statuses after each wave, and with a product plan the stale marking beside wave 1, one --member per target.
562
- const pipeline: Pick<OpWavesPipelineOptions, "beforeMerge" | "applyStatus" | "staleNotes"> = {
613
+ const pipeline: Pick<OpWavesPipelineOptions, "beforeMerge" | "applyStatus" | "staleNotes" | "workflowFile" | "dispatchInputs" | "jobNames"> = {
563
614
  ...(beforeMerge ? { beforeMerge } : {}),
615
+ // #5027: the same job names the comment job's re-run looks for.
616
+ ...(wavesJobNames ? { jobNames: wavesJobNames } : {}),
617
+ // #5022: the workflow and input names the comment job dispatches, for the generator.
618
+ ...(wavesBeforeMerge?.workflowFile ? { workflowFile: wavesBeforeMerge.workflowFile } : {}),
619
+ ...(wavesBeforeMerge?.dispatchInputs ? { dispatchInputs: { ...wavesBeforeMerge.dispatchInputs } } : {}),
564
620
  ...(options.applyStatus ? { applyStatus: { context: productStatusContext(words, "apply", member) } } : {}),
565
621
  ...(planStale ? { staleNotes: planStale } : {}),
566
622
  };
567
- return { ...out, waves: { spec: named, specFile, jobs: opWaveJobs(named, specFile, { bin: words.bin, ...(beforeMerge ? { beforeMerge: true } : {}) }), ...(beforeMerge ? { beforeMerge } : {}), pipeline } };
623
+ return { ...out, waves: { spec: named, specFile, jobs: namedWaveJobs, ...(beforeMerge ? { beforeMerge } : {}), pipeline } };
624
+ }
625
+
626
+ /**
627
+ * The waves' jobs a re-run looks for, by the product's names (#5027): each
628
+ * wave's job, its deciding, share and job group jobs, and before merge the
629
+ * split jobs, named as the Op waves generator names them from the same
630
+ * `jobNames`.
631
+ */
632
+ function productApplyJobs(spec: OpWavesSpec, chantJobs: readonly OpWaveJob[], named: readonly OpWaveJob[], forge: ForgeKind, jobNames: OpWavesJobNames, split: boolean): string[] {
633
+ const out = named.map((j) => j.jobName);
634
+ if (split) out.push(...opWavesNamer(spec, forge, jobNames).jobs(opWaveSplitJobs(spec, chantJobs)).map((j) => j.jobName));
635
+ return [...new Set(out)];
568
636
  }
569
637
 
570
638
  /** The capability steps a component waves spec runs (#4545, #4541): argv templates over `{runs}` and `{plans}`. */
@@ -681,13 +749,15 @@ export function componentWavesSpec(
681
749
  * --forge <forge>` through the words' bin, the jobs it leaves comments to as
682
750
  * {@link COMMENT_JOBS_ENV}, and the comment prefixes the forge's `if:`
683
751
  * starts it on. Throws on GitLab, whose note-commands job answers every
684
- * note.
752
+ * note. `jobName` is the product's name for the job (#5027), default
753
+ * {@link PR_COMMENT_JOB}.
685
754
  */
686
- export function productCommentJob(forge: ForgeKind, words: CiProductWords, jobs: CommentJobs): ProductCommentJob {
755
+ export function productCommentJob(forge: ForgeKind, words: CiProductWords, jobs: CommentJobs, jobName: string = PR_COMMENT_JOB): ProductCommentJob {
687
756
  if (forge === "gitlab") throw new Error("the comment job answers a GitHub or Forgejo comment; on GitLab the note-commands job (noteCommands) answers every note, so drop commentJob");
688
757
  for (const a of words.aliases) if (/['\\]/.test(a.from)) throw new Error(`the alias ${JSON.stringify(a.from)} holds a quote, which the comment job's condition cannot carry`);
758
+ if (typeof jobName !== "string" || !/^[A-Za-z_][A-Za-z0-9_-]*$/.test(jobName)) throw new Error(`commentJob.jobName ${JSON.stringify(jobName)} is not a job name of letters, digits, _ and -, starting with a letter or _`);
689
759
  return {
690
- jobName: PR_COMMENT_JOB,
760
+ jobName,
691
761
  command: withProductBin(`chant components pr-comment --forge ${forge}`, words.bin),
692
762
  env: { GITHUB_TOKEN: GITHUB_JOB_TOKEN, [COMMENT_JOBS_ENV]: JSON.stringify(jobs) },
693
763
  prefixes: [`/${words.product}`, ...words.aliases.map((a) => a.from)],