@intentius/chant 0.124.90 → 0.124.91

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) 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-product.d.ts +9 -0
  7. package/dist/ci-product.d.ts.map +1 -1
  8. package/dist/ci-product.js +18 -9
  9. package/dist/cli/handlers/pr-comment.js +2 -2
  10. package/dist/cli/handlers/pr.d.ts +2 -2
  11. package/dist/cli/handlers/pr.d.ts.map +1 -1
  12. package/dist/cli/handlers/pr.js +28 -9
  13. package/dist/cli/parse-args.d.ts.map +1 -1
  14. package/dist/cli/parse-args.js +13 -0
  15. package/dist/cli/registry.d.ts +4 -0
  16. package/dist/cli/registry.d.ts.map +1 -1
  17. package/dist/components/pr-checks.d.ts +11 -0
  18. package/dist/components/pr-checks.d.ts.map +1 -1
  19. package/dist/components/pr-checks.js +15 -5
  20. package/dist/components/pr-pipeline.d.ts +9 -2
  21. package/dist/components/pr-pipeline.d.ts.map +1 -1
  22. package/dist/components/pr-pipeline.js +16 -5
  23. package/dist/components/product-pipeline.d.ts.map +1 -1
  24. package/dist/components/product-pipeline.js +6 -3
  25. package/dist/components/product-plan.d.ts +79 -1
  26. package/dist/components/product-plan.d.ts.map +1 -1
  27. package/dist/components/product-plan.js +140 -16
  28. package/dist/floor-table.data.d.ts.map +1 -1
  29. package/dist/floor-table.data.js +14 -9
  30. package/dist/lexicon-module.d.ts +2 -0
  31. package/dist/lexicon-module.d.ts.map +1 -1
  32. package/dist/lexicon-module.js +6 -2
  33. package/dist/planned-files.d.ts +16 -8
  34. package/dist/planned-files.d.ts.map +1 -1
  35. package/dist/planned-files.js +12 -8
  36. package/dist/pr-post.d.ts +6 -0
  37. package/dist/pr-post.d.ts.map +1 -1
  38. package/dist/pr-post.js +5 -4
  39. package/dist/release-floors.d.ts +7 -1
  40. package/dist/release-floors.d.ts.map +1 -1
  41. package/dist/release-floors.js +8 -2
  42. package/dist/wave-runtime.mjs +215 -215
  43. package/package.json +1 -1
  44. package/src/actor.test.ts +14 -1
  45. package/src/actor.ts +8 -6
  46. package/src/audit/core.ts +13 -1
  47. package/src/audit/first-load.test.ts +101 -0
  48. package/src/ci-product.ts +20 -9
  49. package/src/cli/handlers/pr-comment.ts +2 -2
  50. package/src/cli/handlers/pr.ts +23 -9
  51. package/src/cli/parse-args.ts +9 -0
  52. package/src/cli/registry.ts +4 -0
  53. package/src/components/pr-checks.ts +16 -5
  54. package/src/components/pr-pipeline.ts +17 -7
  55. package/src/components/product-pipeline.ts +6 -3
  56. package/src/components/product-plan-names.test.ts +135 -0
  57. package/src/components/product-plan.ts +210 -18
  58. package/src/floor-table.data.ts +14 -9
  59. package/src/lexicon-module.ts +6 -2
  60. package/src/planned-files.test.ts +33 -0
  61. package/src/planned-files.ts +26 -10
  62. package/src/pr-post.ts +11 -4
  63. 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.91",
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
+ });
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
@@ -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,17 @@ 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 = NEXT_RELEASE;
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 = NEXT_RELEASE;
257
+
247
258
  /**
248
259
  * Day-2 actions in the product pipeline (#4654): the `action` comment
249
260
  * command counted as answered by the product's own workflow
@@ -104,8 +104,8 @@ export async function beforeMergeDeps(forge: PrForge, jobs: CommentJobs, env: No
104
104
  const line = env[LOCK_REACH_ENV];
105
105
  const name = (n: number) => (forge.kind === "gitlab" ? `!${n}` : `pull request ${n}`);
106
106
  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 } : {}) })),
107
+ // 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).
108
+ 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
109
  statuses: async (sha) => (await forge.commitStatuses?.(sha)) ?? [],
110
110
  git: (argv, o) => {
111
111
  const r = spawnSync(argv[0]!, argv.slice(1), { encoding: "utf8", ...(o.cwd ? { cwd: o.cwd } : {}) });
@@ -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,6 +2845,8 @@ 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;
2848
2852
  const posted = await postPlanReport({
@@ -2852,6 +2856,7 @@ export async function runComponentsPrPost(ctx: CommandContext): Promise<number>
2852
2856
  head: args.head,
2853
2857
  env: args.env,
2854
2858
  ...(member ? { member } : {}),
2859
+ ...(context ? { context } : {}),
2855
2860
  ...(args.planResult ? { result: args.planResult } : {}),
2856
2861
  // #4289: the plan job could not ask the forge, so the note job does, from the Ops at the commit it checked out.
2857
2862
  overdue: () => overdueOps(forge, member),
@@ -2866,7 +2871,7 @@ export async function runComponentsPrPost(ctx: CommandContext): Promise<number>
2866
2871
  });
2867
2872
  for (const message of posted.warnings) console.error(formatWarning({ message }));
2868
2873
  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` : ""}`));
2874
+ console.error(formatInfo(`pr-post: ${context ?? prStatusContext("plan", member)} ${posted.state}: ${posted.description}${posted.noted ? "; note posted" : ""}${posted.recorded ? `; run ${posted.recorded} recorded` : ""}`));
2870
2875
  return 0;
2871
2876
  }
2872
2877
 
@@ -2953,12 +2958,16 @@ async function runComponentsPrPostStale(ctx: CommandContext): Promise<number> {
2953
2958
  return fail(err instanceof Error ? err.message : String(err));
2954
2959
  }
2955
2960
  // #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];
2961
+ // #5003: a product plan's own status contexts, one a --member in the same order (one with none).
2962
+ const contexts = args.statusContexts;
2963
+ const members: Array<string | undefined> = args.members?.length ? (contexts ? [...args.members] : [...new Set(args.members)]) : [undefined];
2964
+ 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}`);
2965
+ if (args.planJob) return fail("pr-post --plan-job names the GitLab plan job pr-post --open reads; --stale reads no plan job");
2957
2966
  const { markStaleNotes } = await import("../../pr-post");
2958
- for (const member of members) {
2967
+ for (const [i, member] of members.entries()) {
2959
2968
  let done: Awaited<ReturnType<typeof markStaleNotes>>;
2960
2969
  try {
2961
- done = await markStaleNotes({ forge, branch, tip: args.tip, env: args.env, ...(member ? { member } : {}), ...(args.previewComment ? { previewComment: true } : {}) });
2970
+ done = await markStaleNotes({ forge, branch, tip: args.tip, env: args.env, ...(member ? { member } : {}), ...(contexts ? { context: contexts[i]! } : {}), ...(args.previewComment ? { previewComment: true } : {}) });
2962
2971
  } catch (err) {
2963
2972
  return fail(err instanceof Error ? err.message : String(err));
2964
2973
  }
@@ -2998,20 +3007,25 @@ async function runComponentsPrPostOpen(ctx: CommandContext): Promise<number> {
2998
3007
  const top = spawnSync("git", ["rev-parse", "--show-toplevel"], { encoding: "utf-8" });
2999
3008
  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
3009
  const member = args.members?.[0];
3010
+ if (args.statusContexts && args.statusContexts.length > 1) return fail(`pr-post --open takes one --context, not ${args.statusContexts.join(", ")}`);
3011
+ // #5003: the product plan's own status context and plan job.
3012
+ const context = args.statusContexts?.[0];
3001
3013
  const description = await descriptionCheckOf(ctx, forge);
3002
3014
  if (typeof description === "number") return description;
3003
3015
  const artifactDir = relative(realpathSync(top.stdout.trim()), resolve(args.output ?? PR_REPORT_DIR)).split(sep).join("/");
3004
3016
  const { postOpenPlanReports } = await import("../../pr-post");
3005
3017
  const { gitlabPlanJobName } = await import("../../components/pr-pipeline");
3018
+ const planJob = args.planJob ?? gitlabPlanJobName(member);
3006
3019
  let done: Awaited<ReturnType<typeof postOpenPlanReports>>;
3007
3020
  try {
3008
3021
  done = await postOpenPlanReports({
3009
3022
  forge,
3010
3023
  branch,
3011
- job: gitlabPlanJobName(member),
3024
+ job: planJob,
3012
3025
  artifactDir,
3013
3026
  env: args.env,
3014
3027
  ...(member ? { member } : {}),
3028
+ ...(context ? { context } : {}),
3015
3029
  // #4289: the Ops at the commit this pipeline checked out, the target branch's.
3016
3030
  overdue: () => overdueOps(forge, member),
3017
3031
  ...(description ? { description } : {}),
@@ -3034,8 +3048,8 @@ async function runComponentsPrPostOpen(ctx: CommandContext): Promise<number> {
3034
3048
  const posted = p.posted!;
3035
3049
  for (const message of posted.warnings) console.error(formatWarning({ message: `!${p.pr}: ${message}` }));
3036
3050
  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` : ""}`));
3051
+ 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
3052
  }
3039
- if (done.posts.length === 0) console.error(formatInfo(`pr-post: no open merge request into ${branch} has a ${gitlabPlanJobName(member)} job`));
3053
+ if (done.posts.length === 0) console.error(formatInfo(`pr-post: no open merge request into ${branch} has a ${planJob} job`));
3040
3054
  return 0;
3041
3055
  }
@@ -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`. */
@@ -992,8 +993,11 @@ export const PR_PLAN_NOTE_JOB = "plan-note";
992
993
  * merge request's files, so no job in it holds the token. `pr-post --open`
993
994
  * asks GitLab for each open merge request's plan job and reads its report
994
995
  * from the job's artifacts.
996
+ *
997
+ * `output` (#5003) is the report directory, `--output`: a product plan's
998
+ * `reportDir`, default {@link PR_LOOP_REPORT_DIR}.
995
999
  */
996
- export function prLoopPostJob(forge: ForgeKind, env: string, member?: string, words?: Pick<CiProductWordsInput, "bin">, opts: { staleNotes?: boolean } & Pick<PrLoopPipelineOptions, "respond" | "decide"> = {}): { command: string; env: Record<string, string> } {
1000
+ export function prLoopPostJob(forge: ForgeKind, env: string, member?: string, words?: Pick<CiProductWordsInput, "bin">, opts: { staleNotes?: boolean; output?: string } & Pick<PrLoopPipelineOptions, "respond" | "decide"> = {}): { command: string; env: Record<string, string> } {
997
1001
  // #4629: the responses as CHANT_RESPOND, and with the description check its decide service on the line.
998
1002
  const respondEnv = prLoopRespondEnv(opts);
999
1003
  const decide = opts.respond?.description === "check" && opts.decide ? ` --decide-backend ${JSON.stringify(opts.decide.backend)} --decide-model ${JSON.stringify(opts.decide.model)}` : "";
@@ -1001,18 +1005,19 @@ export function prLoopPostJob(forge: ForgeKind, env: string, member?: string, wo
1001
1005
  return decide || Object.keys(respondEnv).length > 0 ? { command: `${job.command}${decide}`, env: { ...job.env, ...respondEnv } } : job;
1002
1006
  }
1003
1007
 
1004
- function prLoopPostJobBase(forge: ForgeKind, env: string, member: string | undefined, words: Pick<CiProductWordsInput, "bin"> | undefined, opts: { staleNotes?: boolean }): { command: string; env: Record<string, string> } {
1008
+ function prLoopPostJobBase(forge: ForgeKind, env: string, member: string | undefined, words: Pick<CiProductWordsInput, "bin"> | undefined, opts: { staleNotes?: boolean; output?: string }): { command: string; env: Record<string, string> } {
1005
1009
  // #4628: with staleNotes the note carries the target branch's commit, so a later push can mark it stale.
1006
1010
  const tip = opts.staleNotes ? ["--tip", '"$TIP_SHA"'] : [];
1011
+ const output = opts.output ?? PR_LOOP_REPORT_DIR;
1007
1012
  if (forge === "gitlab") {
1008
1013
  return {
1009
- command: withProductBin(["chant", "components", "pr-post", "--open", "--env", env, "--output", PR_LOOP_REPORT_DIR, "--forge", forge, ...(member ? ["--member", member] : []), ...tip].join(" "), words?.bin),
1014
+ command: withProductBin(["chant", "components", "pr-post", "--open", "--env", env, "--output", output, "--forge", forge, ...(member ? ["--member", member] : []), ...tip].join(" "), words?.bin),
1010
1015
  env: opts.staleNotes ? { TIP_SHA: "$CI_COMMIT_SHA" } : {},
1011
1016
  };
1012
1017
  }
1013
1018
  const command = [
1014
1019
  "chant", "components", "pr-post", "--pr", '"$PR_NUMBER"', "--head", '"$HEAD_SHA"',
1015
- "--env", env, "--output", PR_LOOP_REPORT_DIR, "--forge", forge,
1020
+ "--env", env, "--output", output, "--forge", forge,
1016
1021
  ...(member ? ["--member", member] : []),
1017
1022
  "--result", '"$PLAN_RESULT"',
1018
1023
  ...tip,
@@ -1039,15 +1044,20 @@ export const PR_STALE_JOB = "stale-notes";
1039
1044
  * commit stale and sets its plan status back to pending. It names the plan
1040
1045
  * comment with `previewComment`. Undefined without `staleNotes`. A list
1041
1046
  * of members (#4987, a product plan's targets) marks each one's note.
1047
+ * `contexts` (#5003, a product plan's `statusContext`) are the plan
1048
+ * statuses it sets back to pending, one per member in the same order (one
1049
+ * for none), as `--context`.
1042
1050
  */
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 {
1051
+ export function prStaleJob(forge: ForgeKind, env: string, options: Pick<PrLoopPipelineOptions, "staleNotes" | "previewComment" | "branch" | "words"> = {}, member?: string | readonly string[], contexts?: readonly string[]): { command: string; env: Record<string, string> } | undefined {
1044
1052
  if (!options.staleNotes) return undefined;
1045
1053
  const words = resolveProductWords(options.words);
1046
1054
  const members = member === undefined ? [] : typeof member === "string" ? [member] : [...member];
1055
+ if (contexts !== undefined && contexts.length !== Math.max(1, members.length)) throw new Error(`the stale job sets back ${contexts.length} plan statuses for ${members.length} members; give one context a member`);
1047
1056
  const command = [
1048
1057
  "chant", "components", "pr-post", "--stale", "--tip", '"$TIP_SHA"', "--env", env, "--forge", forge,
1049
1058
  ...(options.branch ? ["--branch", JSON.stringify(options.branch)] : []),
1050
1059
  ...members.flatMap((m) => ["--member", m]),
1060
+ ...(contexts ?? []).flatMap((c) => ["--context", c]),
1051
1061
  ...(options.previewComment ? ["--preview-comment"] : []),
1052
1062
  ].join(" ");
1053
1063
  return {
@@ -43,7 +43,7 @@ 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";
@@ -455,8 +455,10 @@ export function productPipelineJobs(forge: ForgeKind, env: string, options: Prod
455
455
  const action = prActionJob(forge, prLoop);
456
456
  if (action) out.action = { ...action, ...(prLoopRunner(options, "apply") !== undefined ? { runner: prLoopRunner(options, "apply")! } : {}) };
457
457
  // #4987: a product plan's notes are marked from the waves workflow's push run, one --member per target, naming the re-plan comment.
458
+ // #5003: with the product's status context, the stale job sets that status back to pending, one a target.
459
+ const planContexts = productPlan?.statusContext !== undefined ? out.productPlan!.map((p) => productPlanContext(p, words)) : undefined;
458
460
  const planStale = productPlan
459
- ? prStaleJob(forge, env, { ...prLoop, ...(productPlan.replan ? { previewComment: true } : {}) }, productPlan.targets?.map((t) => t.name) ?? member)
461
+ ? prStaleJob(forge, env, { ...prLoop, ...(productPlan.replan ? { previewComment: true } : {}) }, productPlan.targets?.map((t) => t.name) ?? member, planContexts)
460
462
  : undefined;
461
463
  if (planStale && !options.waves && !options.componentWaves) throw new Error("staleNotes with the product plan marks the notes from the waves workflow's push run, beside wave 1, and there are no waves: give waves (or componentWaves), or drop staleNotes");
462
464
  const stale = productPlan ? undefined : prStaleJob(forge, env, prLoop, member);
@@ -496,7 +498,8 @@ export function productPipelineJobs(forge: ForgeKind, env: string, options: Prod
496
498
  bmJobs = {
497
499
  ...(forge !== "gitlab" ? { workflow: `${wavesOp}.yml` } : {}),
498
500
  ...(wavesBeforeMerge.requires ? { requires: [...wavesBeforeMerge.requires] } : {}),
499
- plan: targets?.length ? targets.map((t) => productStatusContext(words, "plan", t)) : [productStatusContext(words, "plan", member)],
501
+ // #5003: the product's own status contexts, when it named them.
502
+ plan: planContexts ?? (targets?.length ? targets.map((t) => productStatusContext(words, "plan", t)) : [productStatusContext(words, "plan", member)]),
500
503
  pipelineFiles: wavesBeforeMerge.pipelineFiles ?? defaultPipelineFiles(forge),
501
504
  ...(productPlan?.reach ? { locks: { ...(productPlan.reach.gate ? { gate: productPlan.reach.gate } : {}) } } : {}),
502
505
  };