@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intentius/chant",
3
- "version": "0.124.90",
3
+ "version": "0.124.92",
4
4
  "description": "Declarative infrastructure-as-code toolkit — TypeScript on Node.js",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://intentius.io/chant",
package/src/actor.test.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /** #4911: one actor fallback for the lexicons' gated requests and the products' requesters. */
2
2
  import { execFileSync } from "node:child_process";
3
- import { mkdtempSync, readdirSync, readFileSync, statSync } from "node:fs";
3
+ import { mkdtempSync, readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
4
4
  import { tmpdir } from "node:os";
5
5
  import { join, relative } from "node:path";
6
6
  import { beforeAll, describe, expect, test } from "vitest";
@@ -45,6 +45,19 @@ describe("actorOf", () => {
45
45
  expect(actorOrder({ triggering: true, repo })).toEqual(["GITHUB_TRIGGERING_ACTOR", "GITHUB_ACTOR", "GITLAB_USER_LOGIN", "git:user.name", "USER", "USERNAME"]);
46
46
  });
47
47
 
48
+ /** #5005: git reads the config the given env names, not the process's. */
49
+ test("git config runs with the env it is given", () => {
50
+ const home = mkdtempSync(join(tmpdir(), "chant-actor-home-"));
51
+ const bare = mkdtempSync(join(tmpdir(), "chant-actor-bare-"));
52
+ execFileSync("git", ["init", "-q", bare]);
53
+ const global = join(home, "gitconfig");
54
+ writeFileSync(global, "[user]\n\tname = Job Identity\n");
55
+ const base = { PATH: process.env.PATH, HOME: home, GIT_CONFIG_NOSYSTEM: "1", USER: "me" };
56
+ expect(actorOf({ env: { ...base, GIT_CONFIG_GLOBAL: global }, repo: bare })).toBe("Job Identity");
57
+ expect(actorOf({ env: { ...base, GIT_CONFIG_GLOBAL: join(home, "none") }, repo: bare })).toBe("me");
58
+ expect(actorOf({ env: { ...base, GIT_CONFIG_GLOBAL: global }, repo })).toBe("Ada Person");
59
+ });
60
+
48
61
  test("the forge and the login can be left out, and the fallback named", () => {
49
62
  expect(actorOf({ env: { GITHUB_ACTOR: "octo", USER: "me" }, forge: false, repo })).toBe("Ada Person");
50
63
  expect(actorOf({ env: { USER: "me" }, triggering: true, login: false, fallback: "" })).toBe("");
package/src/actor.ts CHANGED
@@ -30,7 +30,7 @@ export function actorFromEnv(env: Record<string, string | undefined> = process.e
30
30
 
31
31
  /** Which of the places {@link actorOf} reads, and the answer when none is set. */
32
32
  export interface ActorOptions {
33
- /** The variables. Default `process.env`. */
33
+ /** The variables, and the environment the `git config` for `repo` runs with (#5005). Default `process.env`. */
34
34
  env?: Record<string, string | undefined>;
35
35
  /** Read `GITHUB_TRIGGERING_ACTOR` first: who re-ran the job, ahead of who started the run. Default false. */
36
36
  triggering?: boolean;
@@ -56,8 +56,8 @@ export function actorOrder(options: Omit<ActorOptions, "env" | "fallback"> = {})
56
56
  ];
57
57
  }
58
58
 
59
- function gitConfig(repo: string, key: string): string | undefined {
60
- const r = spawnSync("git", ["-C", repo, "config", key], { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] });
59
+ function gitConfig(repo: string, key: string, env: Record<string, string | undefined>): string | undefined {
60
+ const r = spawnSync("git", ["-C", repo, "config", key], { encoding: "utf-8", env, stdio: ["ignore", "pipe", "ignore"] });
61
61
  return r.status === 0 ? r.stdout.trim() : undefined;
62
62
  }
63
63
 
@@ -65,15 +65,17 @@ function gitConfig(repo: string, key: string): string | undefined {
65
65
  * The first place of {@link actorOrder} set to something other than blanks,
66
66
  * else `fallback` (#4966). With no options it answers as
67
67
  * {@link actorFromEnv}. A git config key is read only when every place
68
- * before it is empty, so a job with a forge actor runs no git.
68
+ * before it is empty, so a job with a forge actor runs no git. git runs
69
+ * with `env`, so a job's `GIT_CONFIG_GLOBAL` or `HOME` picks the config it
70
+ * reads, not the process's (#5005).
69
71
  */
70
72
  export function actorOf(options: ActorOptions = {}): string {
71
73
  const env = options.env ?? process.env;
72
74
  for (const place of actorOrder(options)) {
73
- const v = (place.startsWith("git:") ? gitConfig(options.repo!, place.slice(4)) : env[place])?.trim();
75
+ const v = (place.startsWith("git:") ? gitConfig(options.repo!, place.slice(4), env) : env[place])?.trim();
74
76
  if (v) return v;
75
77
  }
76
78
  return options.fallback ?? "unknown";
77
79
  }
78
80
 
79
- export { ACTOR_ORDER_FLOOR } from "./release-floors";
81
+ export { ACTOR_GIT_ENV_FLOOR, ACTOR_ORDER_FLOOR } from "./release-floors";
package/src/audit/core.ts CHANGED
@@ -27,7 +27,7 @@ import { applyInlineSuppressions, type SuppressionMetaFinding } from "../lint/su
27
27
  import type { SerializerResult } from "../serializer";
28
28
  import type { AuditEntitiesInput, LexiconPlugin } from "../lexicon";
29
29
  import type { Declarable } from "../declarable";
30
- import { lexiconModulePath, lexiconPackagesToInstall, lexiconSourceLabel } from "../lexicon-module";
30
+ import { isPackageNotFound, lexiconModulePath, lexiconPackagesToInstall, lexiconSourceLabel } from "../lexicon-module";
31
31
 
32
32
  /**
33
33
  * The lexicon whose post-synth checks run against an audited file. Any lexicon
@@ -166,6 +166,18 @@ async function load(names: string[]): Promise<LexiconPlugin[]> {
166
166
  `Could not load the lexicon module ${paths.join(", ")} needed to audit ${names.join("/")} workflows.\n(${detail})`,
167
167
  );
168
168
  }
169
+ // chant#4881 — only a package that can't be resolved is missing. Any other
170
+ // failure (a module the package imports, its `init()`, a cross-lexicon
171
+ // conflict) is reported as itself, so nobody is told to install a package
172
+ // they have.
173
+ if (paths.length === 0 && !pkgs.some((pkg) => isPackageNotFound(err, pkg))) {
174
+ const generated = /[\\/]generated[\\/]index\b/.test(detail)
175
+ ? " Its src/generated/ code is missing; in a source checkout, run the lexicon's `npm run generate`."
176
+ : "";
177
+ throw new Error(
178
+ `The lexicon package ${pkgs.join(", ")} needed to audit ${names.join("/")} workflows is installed but failed to load: ${detail}${generated}`,
179
+ );
180
+ }
169
181
  const fromPath = paths.length > 0 ? ` The lexicon module ${paths.join(", ")} is declared by path and has nothing to install.` : "";
170
182
  throw new MissingLexiconError(
171
183
  `Missing lexicon package needed to audit ${names.join("/")} workflows. Install it with: npm i ${pkgs.join(" ")}${fromPath}\n(${detail})`,
@@ -0,0 +1,101 @@
1
+ /**
2
+ * chant#4881 — the first `auditFiles` call for a lexicon, in a fresh module
3
+ * graph, either gets findings or reports why it can't. `MissingLexiconError`
4
+ * is kept for a package that can't be resolved. A package that resolves but
5
+ * fails to load (here, one whose barrel re-exports a `generated/` module that
6
+ * was never generated, as a source checkout's lexicons do before
7
+ * `npm run generate`) is reported as that failure, not as missing.
8
+ *
9
+ * Each test re-imports `./core` after `vi.resetModules()`, so no earlier load
10
+ * of the same lexicon can warm it.
11
+ */
12
+ import { describe, test, expect, beforeAll, afterAll, beforeEach, vi } from "vitest";
13
+ import { mkdtemp, mkdir, rm, writeFile } from "node:fs/promises";
14
+ import { tmpdir } from "node:os";
15
+ import { join } from "node:path";
16
+ import type { AuditInput } from "./core";
17
+
18
+ const GOOD = "zz4881good";
19
+ const BROKEN = "zz4881broken";
20
+ let project: string;
21
+
22
+ const plugin = (name: string) => `export const ${name}Plugin = {
23
+ name: "${name}",
24
+ serializer: { name: "${name}", serialize: () => "" },
25
+ generate: async () => {},
26
+ validate: async () => {},
27
+ coverage: async () => {},
28
+ package: async () => {},
29
+ postSynthChecks: () => [{
30
+ id: "ZZ4881",
31
+ description: "flags every audited file",
32
+ check: (ctx) => [...ctx.outputs.keys()].map((key) => ({ checkId: "ZZ4881", severity: "error", message: "flagged " + key })),
33
+ }],
34
+ };
35
+ `;
36
+
37
+ async function writeLexicon(name: string, index: string): Promise<void> {
38
+ const dir = join(project, "node_modules", "@intentius", `chant-lexicon-${name}`);
39
+ await mkdir(dir, { recursive: true });
40
+ await writeFile(
41
+ join(dir, "package.json"),
42
+ JSON.stringify({ name: `@intentius/chant-lexicon-${name}`, version: "0.0.1", type: "module", exports: { ".": { default: "./index.js" } } }),
43
+ );
44
+ await writeFile(join(dir, "index.js"), index);
45
+ }
46
+
47
+ beforeAll(async () => {
48
+ project = await mkdtemp(join(tmpdir(), "chant-4881-"));
49
+ await writeFile(join(project, "package.json"), JSON.stringify({ name: "chant-4881-project", private: true }));
50
+ await writeLexicon(GOOD, plugin(GOOD));
51
+ await writeLexicon(BROKEN, `${plugin(BROKEN)}export * from "./generated/index.js";\n`);
52
+ });
53
+
54
+ afterAll(async () => {
55
+ await rm(project, { recursive: true, force: true });
56
+ });
57
+
58
+ beforeEach(() => {
59
+ vi.resetModules();
60
+ });
61
+
62
+ /** One `auditFiles` call from a fresh module graph, run from the fixture project. */
63
+ async function auditOnce(lexicon: string): Promise<{ result?: unknown; error?: unknown; MissingLexiconError: Function }> {
64
+ const core = await import("./core");
65
+ const input: AuditInput = { path: "ci.yml", content: "name: ci\n", lexicon };
66
+ const cwd = process.cwd();
67
+ process.chdir(project);
68
+ try {
69
+ return { result: await core.auditFiles([input]), MissingLexiconError: core.MissingLexiconError };
70
+ } catch (error) {
71
+ return { error, MissingLexiconError: core.MissingLexiconError };
72
+ } finally {
73
+ process.chdir(cwd);
74
+ }
75
+ }
76
+
77
+ describe("the first load of a lexicon (#4881)", () => {
78
+ test("an installed lexicon gets findings on the first call", async () => {
79
+ const { result, error } = await auditOnce(GOOD);
80
+ expect(error).toBeUndefined();
81
+ expect(result).toEqual([expect.objectContaining({ checkId: "ZZ4881", file: "ci.yml", lexicon: GOOD })]);
82
+ });
83
+
84
+ test("an uninstalled lexicon gets MissingLexiconError", async () => {
85
+ const { error, MissingLexiconError } = await auditOnce("zz4881absent");
86
+ expect(error).toBeInstanceOf(MissingLexiconError);
87
+ expect((error as Error).message).toContain("npm i @intentius/chant-lexicon-zz4881absent");
88
+ });
89
+
90
+ test("an installed lexicon that fails to load reports the failure, not a missing package", async () => {
91
+ const { error, MissingLexiconError } = await auditOnce(BROKEN);
92
+ expect(error).toBeInstanceOf(Error);
93
+ expect(error).not.toBeInstanceOf(MissingLexiconError);
94
+ const message = (error as Error).message;
95
+ expect(message).toContain(`@intentius/chant-lexicon-${BROKEN}`);
96
+ expect(message).toContain("is installed but failed to load");
97
+ expect(message).toMatch(/generated[\\/]index/);
98
+ expect(message).toContain("npm run generate");
99
+ expect(message).not.toContain("npm i ");
100
+ });
101
+ });
@@ -380,6 +380,23 @@ describe("the comment job's apply before merge on the waves (#4984)", () => {
380
380
  const jobs: CommentJobs = { applyOnMerge: true, waves: { op: "tf-apply", count: 2 }, wavesBeforeMerge: bm };
381
381
 
382
382
  test("an open pull request's apply is decided, and the waves workflow dispatched on the default branch with the decided head", async () => {
383
+ const { sent, stops, got, posted, head, digest } = await decideAndDispatch(jobs);
384
+ expect(sent).toEqual([["tf-apply.yml", "main", { pr: "12", head, digest }]]);
385
+ expect(stops).toEqual([[head, 1]]);
386
+ expect(got).toMatchObject({ command: "apply", ran: true, replied: true });
387
+ expect(posted).toEqual([`terragucci: started the waves of tf-apply on pull request 12's head ${head.slice(0, 8)} through wave 1 for alice; each wave's gate decides, and the run says when the head applied`]);
388
+ });
389
+
390
+ test("#5022: a product's workflow is dispatched with the product's input names", async () => {
391
+ const named: CommentJobs = { ...jobs, wavesBeforeMerge: { ...bm, workflow: "terragucci.yml", inputs: { pr: "apply_pr", head: "apply_head", digest: "apply_digest" } } };
392
+ expect(commentJobsFromEnv(JSON.stringify(named))).toEqual(named);
393
+ expect(() => commentJobsFromEnv(JSON.stringify({ ...jobs, wavesBeforeMerge: { ...bm, inputs: { wave: "w" } } }))).toThrow("inputs names the inputs pr, head and digest");
394
+ expect(() => commentJobsFromEnv(JSON.stringify({ ...jobs, wavesBeforeMerge: { ...bm, inputs: { pr: "a b" } } }))).toThrow("inputs names the inputs pr, head and digest");
395
+ const { sent, head, digest } = await decideAndDispatch(named);
396
+ expect(sent).toEqual([["terragucci.yml", "main", { apply_pr: "12", apply_head: head, apply_digest: digest }]]);
397
+ });
398
+
399
+ async function decideAndDispatch(jobs: CommentJobs) {
383
400
  const { spawnSync } = await import("node:child_process");
384
401
  const { mkdtempSync, writeFileSync } = await import("node:fs");
385
402
  const { tmpdir } = await import("node:os");
@@ -424,11 +441,8 @@ describe("the comment job's apply before merge on the waves (#4984)", () => {
424
441
  },
425
442
  });
426
443
  const digest = beforeMergeDigest("tf-apply", { pr: 12, head, base: baseSha, through: 1, at, by: "alice" });
427
- expect(sent).toEqual([["tf-apply.yml", "main", { pr: "12", head, digest }]]);
428
- expect(stops).toEqual([[head, 1]]);
429
- expect(got).toMatchObject({ command: "apply", ran: true, replied: true });
430
- expect(s.posted).toEqual([`terragucci: started the waves of tf-apply on pull request 12's head ${head.slice(0, 8)} through wave 1 for alice; each wave's gate decides, and the run says when the head applied`]);
431
- });
444
+ return { sent, stops, got, posted: s.posted, head, digest };
445
+ }
432
446
 
433
447
  test("CHANT_COMMENT_JOBS carries the waves before merge, each field checked", () => {
434
448
  expect(commentJobsFromEnv(JSON.stringify(jobs))).toEqual(jobs);
@@ -57,7 +57,7 @@ import { ForgeApiError, type ForgeFetch, type PrForge } from "./pr-forge";
57
57
  import type { ForgeReads, PullRequestDetail } from "./pr-forge-reads";
58
58
  import type { DecideBeforeMergeInput, WavesBeforeMergeJobs } from "./op/before-merge-decide";
59
59
 
60
- /** The comment job's name in a generated workflow (#4946). */
60
+ /** The comment job's name in a generated workflow (#4946), unless the product names it (#5027: the product pipeline's `commentJob.jobName`, such as terragucci's `apply-comment`). */
61
61
  export const PR_COMMENT_JOB = "comment";
62
62
 
63
63
  /** The variable the comment job reads the pipeline's jobs from, as JSON ({@link CommentJobs}), written by the generator (#4946). */
@@ -102,6 +102,14 @@ export interface CommentJobs extends Omit<ChantNoteJobs, "members"> {
102
102
  * `chant/lifecycle`, and dispatches the waves workflow for it.
103
103
  */
104
104
  wavesBeforeMerge?: WavesBeforeMergeJobs;
105
+ /**
106
+ * The waves' apply jobs by the names the product gave them (#5027, the
107
+ * Op waves generator's `jobNames`, such as terragucci's `apply-wave-<k>`,
108
+ * `apply-wave-<k>-share-<n>`, its group jobs and `apply-rest`). A re-run
109
+ * of a merged pull request's apply looks for these. Absent:
110
+ * {@link RERUN_APPLY_JOBS}.
111
+ */
112
+ applyJobs?: readonly string[];
105
113
  }
106
114
 
107
115
  /** What the decision before merge reads and writes with (#4984), the comment job's handler's. */
@@ -117,6 +125,12 @@ export type CommentWaveStops = (op: string, sha: string, stop: { through: number
117
125
  */
118
126
  export const RERUN_APPLY_JOBS = /^(?:wave-([1-9][0-9]*)-[a-z0-9][a-z0-9_-]*|(?:[a-z0-9][a-z0-9-]*-)?apply(?:-wave-([1-9][0-9]*)(?:-share-[1-9][0-9]*)?)?)$/;
119
127
 
128
+ /** The apply jobs a re-run looks for (#5027): exactly `jobs.applyJobs` when the product named them, else {@link RERUN_APPLY_JOBS}. */
129
+ export function rerunApplyJobs(jobs: Pick<CommentJobs, "applyJobs">): RegExp {
130
+ if (!jobs.applyJobs?.length) return RERUN_APPLY_JOBS;
131
+ return new RegExp(`^(?:${jobs.applyJobs.map((n) => n.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|")})$`);
132
+ }
133
+
120
134
  /** The writes a re-run makes, with the job's token. */
121
135
  export interface CommentRuns {
122
136
  /** GitHub: `POST /repos/{repo}/actions/runs/{run}/rerun-failed-jobs`. */
@@ -327,7 +341,8 @@ export async function answerProductComment(o: AnswerCommentOptions): Promise<Com
327
341
  count: o.jobs.waves.count,
328
342
  jobs: bm,
329
343
  words: o.words,
330
- start: (r) => o.runs.dispatch(workflow, o.base, { pr: String(r.pr), head: r.head, digest: r.digest }),
344
+ // #5022: under the waves workflow's input names, the product's when it renamed them.
345
+ start: (r) => o.runs.dispatch(workflow, o.base, { [bm.inputs?.pr ?? "pr"]: String(r.pr), [bm.inputs?.head ?? "head"]: r.head, [bm.inputs?.digest ?? "digest"]: r.digest }),
331
346
  });
332
347
  if (done.kind === "fail") return broke(done.reason, command);
333
348
  return reply(done.text, done.kind === "ran", done.kind === "ran" ? done.url : undefined);
@@ -359,7 +374,7 @@ export async function answerProductComment(o: AnswerCommentOptions): Promise<Com
359
374
  return start(run, jobs, ctx);
360
375
  }
361
376
  : start;
362
- const done = await retryApply({ reads: o.reads, forge: o.poster, words: o.words, base: o.base }, o.forge, pr, user, { kind: "retry", sha: mergeCommit, jobs: RERUN_APPLY_JOBS }, rerun);
377
+ const done = await retryApply({ reads: o.reads, forge: o.poster, words: o.words, base: o.base }, o.forge, pr, user, { kind: "retry", sha: mergeCommit, jobs: rerunApplyJobs(o.jobs) }, rerun);
363
378
  if (done.kind === "fail") return broke(done.reason, command);
364
379
  const stopped = done.kind === "ran" && wave !== undefined && waves && wave < waves.count ? `; it stops after \`wave-${wave}\`, and the waves after it wait until \`/${o.words.product} ${typedApply(o.words)}\` runs it again` : "";
365
380
  return reply(`${done.text}${stopped}`, done.kind === "ran", done.kind === "ran" ? done.url : undefined);
package/src/ci-product.ts CHANGED
@@ -10,10 +10,10 @@
10
10
  */
11
11
 
12
12
  import type { CiProductWords, CiProductWordsInput } from "./ci-product-words";
13
- import { NEXT_RELEASE } from "./release-floors";
14
13
  import type { ProductMcpHook } from "./cli/mcp/product-tools";
15
14
  import type { ProductWaveHook } from "./op/op-waves-after-plan";
16
15
  import { OTLP_EXPORTER_FLOOR } from "./otlp";
16
+ import { NEXT_RELEASE } from "./release-floors";
17
17
 
18
18
  /**
19
19
  * The first chant with the product pipeline (#4550): the words, the
@@ -152,7 +152,7 @@ export const COMMENT_LEAVES_COMMIT_FLOOR = "0.124.88";
152
152
  * The first chant with the comment job on GitHub and Forgejo and the replies to commands no job runs (#4946): `commentJob` in the product pipeline (`chant components pr-comment`, `answerProductComment` in `@intentius/chant/ci-comment-commands`), which replies to a refusal and to a command the pipeline runs no job for, and with waves on merge starts a merged pull request's apply again; the words' `replies` and an alias's `refuse`, which the GitLab note poll reads too, as `chantNoteRuns`' `members`; `retryApply`; and `locks: "plan"` in GitHub's and Forgejo's product plan, with the lock, unlock and comment lock jobs.
153
153
  */
154
154
  export const COMMENT_COMMANDS_FLOOR = "0.124.89";
155
- export { answerProductComment, answeredElsewhere, COMMENT_JOBS_ENV, commentRuns, PR_COMMENT_JOB, RERUN_APPLY_JOBS, type CommentJobs, type CommentOutcome, type CommentRuns, type AnswerCommentOptions } from "./ci-comment-commands";
155
+ export { answerProductComment, answeredElsewhere, COMMENT_JOBS_ENV, commentRuns, PR_COMMENT_JOB, RERUN_APPLY_JOBS, rerunApplyJobs, type CommentJobs, type CommentOutcome, type CommentRuns, type AnswerCommentOptions } from "./ci-comment-commands";
156
156
  export { forkReply, memberReply, notRunReply } from "./ci-comment-replies";
157
157
  export type { CiProductCommentReplies } from "./ci-product-words";
158
158
  export { productCommentJob, type ProductCommentJob } from "./components/product-pipeline";
@@ -174,7 +174,7 @@ export { setWaveStop, waveStopAt, waveStopLine, type WaveStop } from "./op/wave-
174
174
  /**
175
175
  * The first chant whose Op waves run before merge (#4984): `wavesBeforeMerge` in the product pipeline, where the comment job (GitHub, Forgejo) or the note poll (GitLab) decides `/<product> apply [wave-<n>]` on an open pull request (`decideWavesBeforeMerge`, `@intentius/chant/op/before-merge-decide`), records the head and its digest on `chant/lifecycle` (`_waves/<op>.before-merge.json`) and starts the waves for it; the generators' `beforeMerge`, whose guard admits that head alone, whose jobs check it out and read the base from the default branch, and whose `before-merge-done` job merges and releases the locks (`chant run wave --merge`); `waveJobs.<wave>.prelude`; the GitLab note poll's wave stop (`chantNoteRuns`' `waves`); a re-plan word that never starts with `-`; and the terraform lexicon's reach helpers (`@intentius/chant-lexicon-terraform/reach`).
176
176
  */
177
- export const WAVES_BEFORE_MERGE_FLOOR = NEXT_RELEASE;
177
+ export const WAVES_BEFORE_MERGE_FLOOR = "0.124.90";
178
178
  export { BEFORE_MERGE_DIGEST_ENV, BEFORE_MERGE_DONE_JOB, BEFORE_MERGE_HEAD_ENV, BEFORE_MERGE_PR_ENV, beforeMergeDigest, beforeMergePath, beforeMergeProblems, WAVES_BASE_ENV, type BeforeMergeDecision, type BeforeMergeRecord, type OpWavesBeforeMerge } from "./op/before-merge";
179
179
  export { decideWavesBeforeMerge, defaultPipelineFiles, type WavesBeforeMergeJobs } from "./op/before-merge-decide";
180
180
  export type { ProductWavesBeforeMerge } from "./components/product-pipeline";
@@ -182,37 +182,37 @@ export type { ProductWavesBeforeMerge } from "./components/product-pipeline";
182
182
  /**
183
183
  * The first chant whose Op waves post the apply statuses (#4987): the generators' `applyStatus`, a job `apply-status-<n>` after each wave at the default branch's commit that posts `<product>/apply` on the commit the waves applied (a before-merge run's decided head) with `chant run wave --apply-status` (`@intentius/chant/op/apply-status`), and the product pipeline's `applyStatus`; whose product plan takes `staleNotes`, each target's note carrying the target branch's commit and a `stale-notes` job beside wave 1 on a push marking each target's note (`pr-post --stale` with one `--member` per target); whose `productPipelineJobs` returns `waves.pipeline` for the generators; and whose GitLab reach line reaches the lock and note-commands jobs unexpanded (`expand: false`).
184
184
  */
185
- export const WAVES_APPLY_STATUS_FLOOR = NEXT_RELEASE;
185
+ export const WAVES_APPLY_STATUS_FLOOR = "0.124.90";
186
186
  export { applyStatusJobName, opWaveApplyStatus, postOpWaveApplyStatus, type OpWaveApplyStatus, type OpWavesApplyStatus } from "./op/apply-status";
187
187
 
188
188
  /**
189
189
  * The first chant whose before-merge waves never run the change's code beside a write token (#4987): with `beforeMerge` each wave is a plan job (the change's code, a checkout with no credentials kept, a read-only token; GitLab drops `CHANT_FORGE_TOKEN` and the job token), a gate job at the default branch with the token, an applying job on the saved plan with no write token, and a record job at the default branch that writes the run records (`chant run wave --phase plan|gate|apply|record`, `@intentius/chant/op/op-waves-split`). A `rest` wave is refused with `beforeMerge`.
190
190
  */
191
- export const WAVES_BEFORE_MERGE_SPLIT_FLOOR = NEXT_RELEASE;
191
+ export const WAVES_BEFORE_MERGE_SPLIT_FLOOR = "0.124.90";
192
192
  export { opWaveSplitJobs, type OpWavePhase, type OpWaveSplitJob } from "./op/op-waves-split";
193
193
 
194
194
  /**
195
195
  * The first chant whose split before-merge waves take a `step` spec, Forgejo's hand-off, holds on other gates and one approval per wave (#4992): the plan job saves each run's step plan, the gate job leases the rows they change (no heartbeat; the decision names the lease) before it spends the approval, the applying job plans its runs again through the step and applies each whose digest the decision holds, and the record job writes the release records and lets go of the rows; a hook in the plan or apply job that holds the wave on another gate reads it with no write token and leaves its pending fact to the gate or record job; on Forgejo the plan and applying jobs hand their files on as job outputs (`packJs`), never through the artifact upload, and the gate and record jobs keep them as the artifacts; the plan job names no environment on GitHub (a wave's `planEnvironment` when set; on GitLab it prepares it), so the environment's reviewers are asked once. A `rest` wave splits from {@link WAVES_BEFORE_MERGE_REST_FLOOR} on.
196
196
  */
197
- export const WAVES_BEFORE_MERGE_STEP_FLOOR = NEXT_RELEASE;
197
+ export const WAVES_BEFORE_MERGE_STEP_FLOOR = "0.124.90";
198
198
  export type { OpWaveSavedStep, OpWaveSplitHandoff, OpWaveSplitLease } from "./op/op-waves-run";
199
199
 
200
200
  /**
201
201
  * The first chant whose split waves run a product's own process in every job (#4994): the product wave hook's `hooks` (`runChantInProcess(["run", "wave", ..., "--phase", <phase>], words, { wave: { afterPlan, capabilities, hookExec, runHooks, hooks } })`, `RunOpWaveOptions.inProcessHooks`) serves a spec hook by its name in the process of whichever job runs it, plan, gate or applying job or the one-job shape, in place of a command that called back over a socket; `opWaveProductStateDir` is where the plan job's code keeps what the later jobs read; a `record: true` hold in the plan job is spent by the gate job for a re-run of the hook at the wave's commit (an applied line with `rerun.head`), which the next run's plan job runs and its gate job finishes (`holdsFinished`); and `waveJobs.<wave>.artifact.path` takes a list and `waveJobs.<wave>.gate` gives the gate job a report and an artifact, so a product's own upload steps go through chant's Forgejo hand-off.
202
202
  */
203
- export const WAVES_PRODUCT_HOOKS_FLOOR = NEXT_RELEASE;
203
+ export const WAVES_PRODUCT_HOOKS_FLOOR = "0.124.90";
204
204
  export type { OpWaveHandedFinished, OpWaveInProcessHook, OpWaveInProcessHookCall } from "./op/op-waves-run";
205
205
  export { opWaveProductStateDir } from "./op/op-waves-split";
206
206
 
207
207
  /**
208
208
  * The first chant whose split before-merge waves take a `rest` wave (#4992): its four jobs run one wave per run, the wave `CHANT_WAVES_WAVE` names (their own by default), and its record job, once the run applied and the plan found another wave, starts the waves workflow again for it (GitHub and Forgejo: a dispatch with the inputs `wave` and the decision's `pr`, `head` and `digest`, or a push's `commit`; GitLab: a pipeline with the same variables, with `CHANT_FORGE_TOKEN`), whose guard admits it as the same decided head; the jobs of the waves before it do not run in that follow-on; the record job's note (`rest-wave.json` beside the outcomes, `@intentius/chant/op/op-waves-follow-on`) tells `before-merge-done`, the control dispatch and the apply status that a run which started a follow-on is not the last.
209
209
  */
210
- export const WAVES_BEFORE_MERGE_REST_FLOOR = NEXT_RELEASE;
210
+ export const WAVES_BEFORE_MERGE_REST_FLOOR = "0.124.90";
211
211
 
212
212
  /**
213
213
  * The first chant whose rest wave's record job records each follow-on it starts on `chant/lifecycle` before it starts it (#4998): `_waves/<op>.follow-on.json` keeps, per decided head or pushed commit, the wave started, the run that started it, the decision (`pr`, `digest`) or the `commit`, and the outcomes of every run of the chain so far; the guard admits a follow-on only for the wave that record names, so a wave started by hand past it is refused; and the last run's control dispatch, apply status and `before-merge-done` add up the outcomes of every run of the chain (the note's `chain`), so a chain whose last wave changed nothing reports `applied`.
214
214
  */
215
- export const WAVES_FOLLOW_ON_RECORD_FLOOR = NEXT_RELEASE;
215
+ export const WAVES_FOLLOW_ON_RECORD_FLOOR = "0.124.90";
216
216
 
217
217
  /**
218
218
  * The first chant whose product plan takes `watches`, the product's own scheduled jobs the note job's `pr-post` checks for having stopped with the job's token (#4888), and whose `checkOverdueOps` and `overdueOpsAt` take a product's `logPrefix` and `label`.
@@ -223,7 +223,7 @@ export { PLAN_WATCHES_ENV, watchesForTarget } from "./op/schedule-overdue";
223
223
  /**
224
224
  * The first chant whose product plan's `watches` take `targets` (#4988): a watch scoped to those targets is checked by their notes alone, and the note of another target checks neither it nor the discovered Op of its name (`watchesForTarget`).
225
225
  */
226
- export const PRODUCT_PLAN_WATCH_TARGETS_FLOOR = NEXT_RELEASE;
226
+ export const PRODUCT_PLAN_WATCH_TARGETS_FLOOR = "0.124.90";
227
227
 
228
228
  /**
229
229
  * The first chant whose product plan takes `record` (#4899): the plan step writes the plan job's run record into the hand-off, and the note job keeps it as Op `pr-plan` on `chant/lifecycle` with `pr-post --record-run <plan job>` (`--open` on GitLab), as `chant ci run plan --in-place` records `pr-plan`'s.
@@ -244,6 +244,38 @@ export { planBodyHandoff, PLAN_BODY_LIMIT, type PrPlanBodyHandoff } from "./pr-p
244
244
  export const PRODUCT_PLAN_SUBJECT_FLOOR = "0.124.89";
245
245
  export { PLAN_SUBJECT_LIMIT, planSubjectProblem, sinceLastLine, subjectChanges, type PrPlanSubject, type PrPlanSubjectPartWords } from "./pr-plan-note";
246
246
 
247
+ /**
248
+ * The first chant whose product plan keeps a product's own names (#5003): `workflowFile` (the generators' `path`), `jobNames` (the plan, note, re-plan and re-plan note jobs, with `{target}`), `statusContext` (which `pr-post --context`, the pending step, the stale job and the apply before merge use) and `reportDir` (`{output}`, the hand-off, the artifact's path and `pr-post --output`), and whose `pr-post --open` finds a plan job of the product's name (`--plan-job`).
249
+ */
250
+ export const PRODUCT_PLAN_NAMES_FLOOR = "0.124.91";
251
+ export { productPlanContext, productPlanReportDir, productPlanWorkflowFile } from "./components/product-plan";
252
+
253
+ /**
254
+ * The first chant whose GitLab product plan job keeps a product's own artifacts beside the report directory (#5004): `productPlan.artifacts: { paths, reports }`, as `artifacts:paths` and `artifacts:reports`, such as terragucci's `terraform` report for the merge request's widget, with `{target}` and `{output}` filled. GitHub and Forgejo refuse it.
255
+ */
256
+ export const PRODUCT_PLAN_ARTIFACTS_FLOOR = "0.124.91";
257
+
258
+ /**
259
+ * The first chant whose GitHub and Forgejo product plan, after a `login` or with `idTokens`, starts every step after the checkout but the login's without `ACTIONS_ID_TOKEN_REQUEST_URL` and `ACTIONS_ID_TOKEN_REQUEST_TOKEN` (#5021), as after a `trade`: the setup, the probe and the plan step, in the plan and the re-plan job, so the change's code can request no token. A product's own `idTokens` leave them in the plan step, whose verb requests them.
260
+ */
261
+ export const PRODUCT_PLAN_LOGIN_TOKENS_FLOOR = NEXT_RELEASE;
262
+
263
+ /**
264
+ * The first chant whose pull request jobs on GitHub and Forgejo name the pull request's head, `github.event.pull_request.head.sha`, where `github.sha` named the merge preview (#5020): the product plan's pending step (`CHANT_PENDING_SHA`), the note job's `HEAD_SHA` (the product plan's, the pull request loop's and the product pipeline's) and the `env-post` job's. `pr-post --head <head>` takes a report, a plan note hand-off or a run record for the head or for the run's merge preview the plan job checked out (`plannedForHead`), so a product's plan verb may write its hand-off for either.
265
+ */
266
+ export const PR_HEAD_SHA_FLOOR = NEXT_RELEASE;
267
+
268
+ /**
269
+ * The first chant whose Op waves generators keep a product's own names (#5022): `jobNames` (every job they write: a wave's, deciding, share and job group jobs, a split wave's plan, gate, apply and record jobs, the policy and evidence jobs, the apply status, stale, before-merge done and control jobs; `needs:`, `if:`, `{job}` and `--from-job` follow it), `stageNames` (GitLab), `artifactNames` (the outcome, decision, saved plan and check claims artifacts, and the pattern a wave job downloads the earlier outcomes with), `workflowFile` (the generators' file and the follow-on's dispatch), `runIf` (the jobs go in the product's own workflow, each running on a push it admits or a before-merge or follow-on dispatch, with its own permissions; on GitLab joined to every rule) and `dispatchInputs` (the dispatch inputs' names, which the comment job's dispatch and the follow-on use), with `buildForgejoOpWavesDoc` for the Forgejo jobs, and whose product pipeline's `wavesBeforeMerge` takes `workflowFile` and `dispatchInputs`.
270
+ */
271
+ export const OP_WAVES_NAMES_FLOOR = NEXT_RELEASE;
272
+
273
+ /**
274
+ * The first chant whose product pipeline names its comment job and its waves' jobs as the product does (#5027): `commentJob: { jobName }` (default `comment`, such as terragucci's `apply-comment`), refused when another job of the workflow has the name, and `wavesJobNames`, the Op waves generators' `jobNames`, which `waves.pipeline` carries to the generator and `waves.jobs` takes, and under which the comment job's re-run of a merged pull request's apply looks for the waves' jobs (`CHANT_COMMENT_JOBS` `applyJobs`, `rerunApplyJobs`), so terragucci's `apply-wave-<k>`, `-share-<n>`, group jobs and `apply-rest` run again. Without them the job is `comment` and the re-run looks for `RERUN_APPLY_JOBS`, as before.
275
+ */
276
+ export const PRODUCT_JOB_NAMES_FLOOR = NEXT_RELEASE;
277
+ export { opWavesArtifacts, opWavesDispatchInputs, opWavesNamer, opWavesWorkflowFile, type OpWavesArtifactNames, type OpWavesDispatchInput, type OpWavesJobNames, type OpWavesJobRef, type OpWavesJobRole, type OpWavesStageNames, type OpWavesStageRef } from "./op/op-waves-names";
278
+
247
279
  /**
248
280
  * Day-2 actions in the product pipeline (#4654): the `action` comment
249
281
  * command counted as answered by the product's own workflow
@@ -34,7 +34,7 @@ export function commentJobsFromEnv(raw: string | undefined): CommentJobs {
34
34
  if (raw === undefined || raw.trim() === "") return {};
35
35
  const v: unknown = JSON.parse(raw);
36
36
  if (typeof v !== "object" || v === null || Array.isArray(v)) throw new Error(`${COMMENT_JOBS_ENV} is a JSON object of the jobs the pipeline has`);
37
- const known = new Set(["preview", "applyBeforeMerge", "applyOnMerge", "locks", "agent", "commits", "actions", "skipForks", "targets", "noPlanFlags", "waves", "wavesBeforeMerge"]);
37
+ const known = new Set(["preview", "applyBeforeMerge", "applyOnMerge", "locks", "agent", "commits", "actions", "skipForks", "targets", "noPlanFlags", "waves", "wavesBeforeMerge", "applyJobs"]);
38
38
  const jobs: Record<string, unknown> = {};
39
39
  for (const [k, x] of Object.entries(v)) {
40
40
  if (!known.has(k)) throw new Error(`${COMMENT_JOBS_ENV} names ${JSON.stringify(k)}, which is not one of ${[...known].join(", ")}`);
@@ -55,6 +55,12 @@ export function commentJobsFromEnv(raw: string | undefined): CommentJobs {
55
55
  if (x.length > 0) jobs.targets = x;
56
56
  continue;
57
57
  }
58
+ // #5027: the waves' apply jobs by the product's names, which a re-run looks for.
59
+ if (k === "applyJobs") {
60
+ if (!Array.isArray(x) || x.some((t) => typeof t !== "string" || !/^[A-Za-z0-9_][A-Za-z0-9_.-]*$/.test(t))) throw new Error(`${COMMENT_JOBS_ENV}.applyJobs is a list of job names`);
61
+ if (x.length > 0) jobs.applyJobs = x;
62
+ continue;
63
+ }
58
64
  if (typeof x !== "boolean") throw new Error(`${COMMENT_JOBS_ENV}.${k} is true or false`);
59
65
  if (x) jobs[k] = true;
60
66
  }
@@ -66,15 +72,19 @@ export function commentJobsFromEnv(raw: string | undefined): CommentJobs {
66
72
  export function wavesBeforeMergeOf(x: unknown): WavesBeforeMergeJobs {
67
73
  const what = `${COMMENT_JOBS_ENV}.wavesBeforeMerge`;
68
74
  const o = x as Partial<WavesBeforeMergeJobs> | null;
69
- if (!o || typeof o !== "object" || Array.isArray(o)) throw new Error(`${what} is { workflow?, requires?, plan, pipelineFiles, locks? }`);
75
+ if (!o || typeof o !== "object" || Array.isArray(o)) throw new Error(`${what} is { workflow?, inputs?, requires?, plan, pipelineFiles, locks? }`);
70
76
  const strings = (v: unknown): v is string[] => Array.isArray(v) && v.every((s) => typeof s === "string" && s.trim() !== "" && !/[\r\n]/.test(s));
71
77
  if (o.workflow !== undefined && (typeof o.workflow !== "string" || !/^[A-Za-z0-9][A-Za-z0-9._-]*\.ya?ml$/.test(o.workflow))) throw new Error(`${what}.workflow is a workflow file name, like deploy.yml`);
72
78
  if (o.requires !== undefined && (!Array.isArray(o.requires) || o.requires.some((r) => !(PR_APPLY_REQUIRES as readonly string[]).includes(r)))) throw new Error(`${what}.requires is a list of ${PR_APPLY_REQUIRES.join(", ")}`);
73
79
  if (!strings(o.plan)) throw new Error(`${what}.plan is the list of plan statuses that must pass on the head`);
74
80
  if (!strings(o.pipelineFiles)) throw new Error(`${what}.pipelineFiles is the list of paths a change may not touch`);
75
81
  if (o.locks !== undefined && (typeof o.locks !== "object" || o.locks === null || (o.locks.gate !== undefined && (typeof o.locks.gate !== "string" || !/^[A-Za-z0-9][A-Za-z0-9_.-]{0,127}$/.test(o.locks.gate))))) throw new Error(`${what}.locks is { gate? }`);
82
+ // #5022: the waves workflow's input names, the product's.
83
+ const inputs = o.inputs;
84
+ if (inputs !== undefined && (typeof inputs !== "object" || inputs === null || Object.entries(inputs).some(([k, n]) => !["pr", "head", "digest"].includes(k) || typeof n !== "string" || !/^[A-Za-z_][A-Za-z0-9_-]*$/.test(n)))) throw new Error(`${what}.inputs names the inputs pr, head and digest`);
76
85
  return {
77
86
  ...(o.workflow ? { workflow: o.workflow } : {}),
87
+ ...(inputs ? { inputs: { ...inputs } } : {}),
78
88
  ...(o.requires ? { requires: [...o.requires] } : {}),
79
89
  plan: [...o.plan],
80
90
  pipelineFiles: [...o.pipelineFiles],
@@ -104,8 +114,8 @@ export async function beforeMergeDeps(forge: PrForge, jobs: CommentJobs, env: No
104
114
  const line = env[LOCK_REACH_ENV];
105
115
  const name = (n: number) => (forge.kind === "gitlab" ? `!${n}` : `pull request ${n}`);
106
116
  return {
107
- // The plan and apply statuses never hold the apply back: the plan status is asked for by name.
108
- requires: async (pr, head) => unmetRequires(await checkPrRequires(forge, pr, head, { ignore: [productStatusContext(words, "apply"), productStatusContext(words, "plan"), `${productStatusContext(words, "plan")}/`], ...(bm.requires ? { only: bm.requires } : {}) })),
117
+ // The plan and apply statuses never hold the apply back: the plan status is asked for by name (#5003: the product plan's own names too).
118
+ requires: async (pr, head) => unmetRequires(await checkPrRequires(forge, pr, head, { ignore: [...new Set([productStatusContext(words, "apply"), productStatusContext(words, "plan"), `${productStatusContext(words, "plan")}/`, ...bm.plan])], ...(bm.requires ? { only: bm.requires } : {}) })),
109
119
  statuses: async (sha) => (await forge.commitStatuses?.(sha)) ?? [],
110
120
  git: (argv, o) => {
111
121
  const r = spawnSync(argv[0]!, argv.slice(1), { encoding: "utf8", ...(o.cwd ? { cwd: o.cwd } : {}) });
@@ -120,7 +120,7 @@ import {
120
120
  import { prStatusDescription, prStatusState } from "../../pr-status";
121
121
  import { FORGE_KINDS, forgeFromEnv, forgePrincipalOf, type ForgeKind, type PrForge } from "../../pr-forge";
122
122
  // #4964: a status for a pull_request run's merge preview goes on the pull request's head.
123
- import { forgeFromJobEnv } from "../../pr-forge-job";
123
+ import { forgeFromJobEnv, plannedForHead } from "../../pr-forge-job";
124
124
  import { GITHUB_COMMENT_LIMIT, GITLAB_NOTE_LIMIT } from "../../plan-summary";
125
125
  import { upsertPlanNote } from "../../pr-post";
126
126
  import { activeProductWords, commandWord, parseProductComment, productContext } from "../../ci-product-words";
@@ -2816,8 +2816,8 @@ function writeWaveChangeSet(ctx: CommandContext, wave: number, doc: PrPlanSet["d
2816
2816
  }
2817
2817
 
2818
2818
  /**
2819
- * chant components pr-post --pr <n> --head <sha> --env <env> --forge <kind> [--member <name>] [--output <dir>] [--result <result>] [--not-affected <argument>] (#4295, #4963)
2820
- * chant components pr-post --open --env <env> --forge gitlab [--branch <branch>] [--member <name>] [--output <dir>] (#4328)
2819
+ * chant components pr-post --pr <n> --head <sha> --env <env> --forge <kind> [--member <name>] [--output <dir>] [--result <result>] [--not-affected <argument>] [--context <context>] (#4295, #4963, #5003)
2820
+ * chant components pr-post --open --env <env> --forge gitlab [--branch <branch>] [--member <name>] [--output <dir>] [--context <context>] [--plan-job <name>] (#4328, #5003)
2821
2821
  *
2822
2822
  * Post the plan note and the `chant/plan` status from the report a plan job
2823
2823
  * wrote with `pr-plan --no-status`, in a job that runs none of the change's
@@ -2835,6 +2835,8 @@ export async function runComponentsPrPost(ctx: CommandContext): Promise<number>
2835
2835
  if (!args.env) return fail("pr-post needs the environment the plan was for: --env <env>");
2836
2836
  if (!args.forge || !(FORGE_KINDS as readonly string[]).includes(args.forge)) return fail(`pr-post posts to a forge: --forge ${FORGE_KINDS.join("|")}`);
2837
2837
  if (args.members && args.members.length > 1) return fail(`pr-post takes one --member, not ${args.members.join(", ")}`);
2838
+ if (args.statusContexts && args.statusContexts.length > 1) return fail(`pr-post takes one --context, not ${args.statusContexts.join(", ")}`);
2839
+ if (args.planJob) return fail("pr-post --plan-job names the GitLab plan job pr-post --open reads; a post for one pull request reads its report from --output");
2838
2840
  let forge: PrForge;
2839
2841
  try {
2840
2842
  forge = forgeFromJobEnv(args.forge as ForgeKind);
@@ -2843,15 +2845,21 @@ export async function runComponentsPrPost(ctx: CommandContext): Promise<number>
2843
2845
  }
2844
2846
  const { postPlanReport } = await import("../../pr-post");
2845
2847
  const member = args.members?.[0];
2848
+ // #5003: the product plan's own status context.
2849
+ const context = args.statusContexts?.[0];
2846
2850
  const description = await descriptionCheckOf(ctx, forge);
2847
2851
  if (typeof description === "number") return description;
2852
+ // #5020: --head is the pull request's head; a GitHub plan job checked out the run's merge preview, whose report is the head's.
2853
+ const planned = args.forge === "gitlab" ? undefined : plannedForHead(args.head);
2848
2854
  const posted = await postPlanReport({
2849
2855
  forge,
2850
2856
  dir: resolve(args.output ?? PR_REPORT_DIR),
2851
2857
  pr: args.pr,
2852
2858
  head: args.head,
2859
+ ...(planned ? { planned } : {}),
2853
2860
  env: args.env,
2854
2861
  ...(member ? { member } : {}),
2862
+ ...(context ? { context } : {}),
2855
2863
  ...(args.planResult ? { result: args.planResult } : {}),
2856
2864
  // #4289: the plan job could not ask the forge, so the note job does, from the Ops at the commit it checked out.
2857
2865
  overdue: () => overdueOps(forge, member),
@@ -2866,7 +2874,7 @@ export async function runComponentsPrPost(ctx: CommandContext): Promise<number>
2866
2874
  });
2867
2875
  for (const message of posted.warnings) console.error(formatWarning({ message }));
2868
2876
  if (posted.refused) console.error(formatWarning({ message: `the plan report was not used: ${posted.refused}` }));
2869
- console.error(formatInfo(`pr-post: ${prStatusContext("plan", member)} ${posted.state}: ${posted.description}${posted.noted ? "; note posted" : ""}${posted.recorded ? `; run ${posted.recorded} recorded` : ""}`));
2877
+ console.error(formatInfo(`pr-post: ${context ?? prStatusContext("plan", member)} ${posted.state}: ${posted.description}${posted.noted ? "; note posted" : ""}${posted.recorded ? `; run ${posted.recorded} recorded` : ""}`));
2870
2878
  return 0;
2871
2879
  }
2872
2880
 
@@ -2953,12 +2961,16 @@ async function runComponentsPrPostStale(ctx: CommandContext): Promise<number> {
2953
2961
  return fail(err instanceof Error ? err.message : String(err));
2954
2962
  }
2955
2963
  // #4987: a product plan's targets each have their note, so --member may be given once per target.
2956
- const members: Array<string | undefined> = args.members?.length ? [...new Set(args.members)] : [undefined];
2964
+ // #5003: a product plan's own status contexts, one a --member in the same order (one with none).
2965
+ const contexts = args.statusContexts;
2966
+ const members: Array<string | undefined> = args.members?.length ? (contexts ? [...args.members] : [...new Set(args.members)]) : [undefined];
2967
+ if (contexts && contexts.length !== members.length) return fail(`pr-post --stale takes one --context a --member (one with none), and got ${contexts.length} for ${members.length}`);
2968
+ if (args.planJob) return fail("pr-post --plan-job names the GitLab plan job pr-post --open reads; --stale reads no plan job");
2957
2969
  const { markStaleNotes } = await import("../../pr-post");
2958
- for (const member of members) {
2970
+ for (const [i, member] of members.entries()) {
2959
2971
  let done: Awaited<ReturnType<typeof markStaleNotes>>;
2960
2972
  try {
2961
- done = await markStaleNotes({ forge, branch, tip: args.tip, env: args.env, ...(member ? { member } : {}), ...(args.previewComment ? { previewComment: true } : {}) });
2973
+ done = await markStaleNotes({ forge, branch, tip: args.tip, env: args.env, ...(member ? { member } : {}), ...(contexts ? { context: contexts[i]! } : {}), ...(args.previewComment ? { previewComment: true } : {}) });
2962
2974
  } catch (err) {
2963
2975
  return fail(err instanceof Error ? err.message : String(err));
2964
2976
  }
@@ -2998,20 +3010,25 @@ async function runComponentsPrPostOpen(ctx: CommandContext): Promise<number> {
2998
3010
  const top = spawnSync("git", ["rev-parse", "--show-toplevel"], { encoding: "utf-8" });
2999
3011
  if (top.status !== 0) return fail("pr-post --open reads the plan report's path from the repository root, and this directory is not in a git repository");
3000
3012
  const member = args.members?.[0];
3013
+ if (args.statusContexts && args.statusContexts.length > 1) return fail(`pr-post --open takes one --context, not ${args.statusContexts.join(", ")}`);
3014
+ // #5003: the product plan's own status context and plan job.
3015
+ const context = args.statusContexts?.[0];
3001
3016
  const description = await descriptionCheckOf(ctx, forge);
3002
3017
  if (typeof description === "number") return description;
3003
3018
  const artifactDir = relative(realpathSync(top.stdout.trim()), resolve(args.output ?? PR_REPORT_DIR)).split(sep).join("/");
3004
3019
  const { postOpenPlanReports } = await import("../../pr-post");
3005
3020
  const { gitlabPlanJobName } = await import("../../components/pr-pipeline");
3021
+ const planJob = args.planJob ?? gitlabPlanJobName(member);
3006
3022
  let done: Awaited<ReturnType<typeof postOpenPlanReports>>;
3007
3023
  try {
3008
3024
  done = await postOpenPlanReports({
3009
3025
  forge,
3010
3026
  branch,
3011
- job: gitlabPlanJobName(member),
3027
+ job: planJob,
3012
3028
  artifactDir,
3013
3029
  env: args.env,
3014
3030
  ...(member ? { member } : {}),
3031
+ ...(context ? { context } : {}),
3015
3032
  // #4289: the Ops at the commit this pipeline checked out, the target branch's.
3016
3033
  overdue: () => overdueOps(forge, member),
3017
3034
  ...(description ? { description } : {}),
@@ -3034,8 +3051,8 @@ async function runComponentsPrPostOpen(ctx: CommandContext): Promise<number> {
3034
3051
  const posted = p.posted!;
3035
3052
  for (const message of posted.warnings) console.error(formatWarning({ message: `!${p.pr}: ${message}` }));
3036
3053
  if (posted.refused) console.error(formatWarning({ message: `!${p.pr}: the plan report was not used: ${posted.refused}` }));
3037
- console.error(formatInfo(`pr-post: !${p.pr} ${prStatusContext("plan", member)} ${posted.state}: ${posted.description}${posted.noted ? "; note posted" : ""}${posted.recorded ? `; run ${posted.recorded} recorded` : ""}`));
3054
+ console.error(formatInfo(`pr-post: !${p.pr} ${context ?? prStatusContext("plan", member)} ${posted.state}: ${posted.description}${posted.noted ? "; note posted" : ""}${posted.recorded ? `; run ${posted.recorded} recorded` : ""}`));
3038
3055
  }
3039
- if (done.posts.length === 0) console.error(formatInfo(`pr-post: no open merge request into ${branch} has a ${gitlabPlanJobName(member)} job`));
3056
+ if (done.posts.length === 0) console.error(formatInfo(`pr-post: no open merge request into ${branch} has a ${planJob} job`));
3040
3057
  return 0;
3041
3058
  }