@intentius/chant 0.124.84 → 0.124.86

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 (254) hide show
  1. package/dist/bundle-check.d.ts +102 -0
  2. package/dist/bundle-check.d.ts.map +1 -0
  3. package/dist/bundle-check.js +310 -0
  4. package/dist/chant-install.d.ts +100 -0
  5. package/dist/chant-install.d.ts.map +1 -0
  6. package/dist/chant-install.js +158 -0
  7. package/dist/ci-commit.d.ts +19 -6
  8. package/dist/ci-commit.d.ts.map +1 -1
  9. package/dist/ci-commit.js +23 -4
  10. package/dist/ci-evidence-jobs.d.ts +54 -0
  11. package/dist/ci-evidence-jobs.d.ts.map +1 -0
  12. package/dist/ci-evidence-jobs.js +55 -0
  13. package/dist/ci-image.d.ts +274 -0
  14. package/dist/ci-image.d.ts.map +1 -0
  15. package/dist/ci-image.js +635 -0
  16. package/dist/ci-login.d.ts +150 -0
  17. package/dist/ci-login.d.ts.map +1 -0
  18. package/dist/ci-login.js +240 -0
  19. package/dist/ci-product.d.ts +16 -0
  20. package/dist/ci-product.d.ts.map +1 -1
  21. package/dist/ci-product.js +17 -0
  22. package/dist/cli/commands/import-index.js +2 -2
  23. package/dist/cli/handlers/build.d.ts +8 -0
  24. package/dist/cli/handlers/build.d.ts.map +1 -1
  25. package/dist/cli/handlers/build.js +22 -4
  26. package/dist/cli/handlers/ci-check.d.ts.map +1 -1
  27. package/dist/cli/handlers/ci-check.js +57 -2
  28. package/dist/cli/handlers/ci-evidence.d.ts +3 -0
  29. package/dist/cli/handlers/ci-evidence.d.ts.map +1 -0
  30. package/dist/cli/handlers/ci-evidence.js +171 -0
  31. package/dist/cli/handlers/components.js +3 -3
  32. package/dist/cli/handlers/dead-guards.d.ts +3 -0
  33. package/dist/cli/handlers/dead-guards.d.ts.map +1 -0
  34. package/dist/cli/handlers/dead-guards.js +35 -0
  35. package/dist/cli/handlers/graph.js +4 -4
  36. package/dist/cli/handlers/lifecycle.d.ts +2 -1
  37. package/dist/cli/handlers/lifecycle.d.ts.map +1 -1
  38. package/dist/cli/handlers/lifecycle.js +5 -4
  39. package/dist/cli/handlers/local-chant.d.ts +16 -0
  40. package/dist/cli/handlers/local-chant.d.ts.map +1 -0
  41. package/dist/cli/handlers/local-chant.js +109 -0
  42. package/dist/cli/handlers/operator.js +2 -2
  43. package/dist/cli/handlers/search.js +5 -5
  44. package/dist/cli/main.d.ts.map +1 -1
  45. package/dist/cli/main.js +38 -0
  46. package/dist/cli/parse-args.d.ts.map +1 -1
  47. package/dist/cli/parse-args.js +28 -0
  48. package/dist/cli/registry.d.ts +16 -0
  49. package/dist/cli/registry.d.ts.map +1 -1
  50. package/dist/components/check-hooks.d.ts +49 -0
  51. package/dist/components/check-hooks.d.ts.map +1 -1
  52. package/dist/components/check-hooks.js +64 -4
  53. package/dist/components/check-steps.d.ts +17 -0
  54. package/dist/components/check-steps.d.ts.map +1 -1
  55. package/dist/components/check-steps.js +37 -5
  56. package/dist/components/product-pipeline.d.ts +23 -0
  57. package/dist/components/product-pipeline.d.ts.map +1 -1
  58. package/dist/components/product-pipeline.js +6 -2
  59. package/dist/components/product-plan.d.ts +137 -0
  60. package/dist/components/product-plan.d.ts.map +1 -0
  61. package/dist/components/product-plan.js +143 -0
  62. package/dist/components/release-compile.d.ts.map +1 -1
  63. package/dist/components/release-compile.js +2 -2
  64. package/dist/config.d.ts +39 -1
  65. package/dist/config.d.ts.map +1 -1
  66. package/dist/config.js +35 -3
  67. package/dist/dead-guards.d.ts +82 -0
  68. package/dist/dead-guards.d.ts.map +1 -0
  69. package/dist/dead-guards.js +436 -0
  70. package/dist/discovery/files.d.ts +3 -1
  71. package/dist/discovery/files.d.ts.map +1 -1
  72. package/dist/discovery/files.js +5 -3
  73. package/dist/drift-issue.d.ts +152 -0
  74. package/dist/drift-issue.d.ts.map +1 -0
  75. package/dist/drift-issue.js +167 -0
  76. package/dist/floor-table.d.ts +30 -0
  77. package/dist/floor-table.d.ts.map +1 -0
  78. package/dist/floor-table.data.d.ts +3 -0
  79. package/dist/floor-table.data.d.ts.map +1 -0
  80. package/dist/floor-table.data.js +178 -0
  81. package/dist/floor-table.js +56 -0
  82. package/dist/forge-flags.d.ts +90 -0
  83. package/dist/forge-flags.d.ts.map +1 -0
  84. package/dist/forge-flags.js +184 -0
  85. package/dist/lexicon.d.ts +69 -0
  86. package/dist/lexicon.d.ts.map +1 -1
  87. package/dist/lifecycle/gated-op.d.ts +7 -1
  88. package/dist/lifecycle/gated-op.d.ts.map +1 -1
  89. package/dist/lifecycle/gated-op.js +7 -4
  90. package/dist/local-chant.d.ts +98 -0
  91. package/dist/local-chant.d.ts.map +1 -0
  92. package/dist/local-chant.js +307 -0
  93. package/dist/op/activities/predict-behaviour.js +2 -2
  94. package/dist/op/op-waves-evidence-spec.d.ts +13 -0
  95. package/dist/op/op-waves-evidence-spec.d.ts.map +1 -0
  96. package/dist/op/op-waves-evidence-spec.js +21 -0
  97. package/dist/op/op-waves-evidence.d.ts +38 -0
  98. package/dist/op/op-waves-evidence.d.ts.map +1 -0
  99. package/dist/op/op-waves-evidence.js +57 -0
  100. package/dist/op/op-waves-run.d.ts +4 -0
  101. package/dist/op/op-waves-run.d.ts.map +1 -1
  102. package/dist/op/op-waves-run.js +24 -1
  103. package/dist/op/op-waves.d.ts +17 -1
  104. package/dist/op/op-waves.d.ts.map +1 -1
  105. package/dist/op/op-waves.js +23 -0
  106. package/dist/op/schedule-overdue.d.ts +41 -9
  107. package/dist/op/schedule-overdue.d.ts.map +1 -1
  108. package/dist/op/schedule-overdue.js +154 -25
  109. package/dist/plan-summary.d.ts +25 -0
  110. package/dist/plan-summary.d.ts.map +1 -1
  111. package/dist/plan-summary.js +31 -0
  112. package/dist/pr-plan-note.d.ts +35 -0
  113. package/dist/pr-plan-note.d.ts.map +1 -1
  114. package/dist/pr-plan-note.js +10 -0
  115. package/dist/pr-post.d.ts +23 -0
  116. package/dist/pr-post.d.ts.map +1 -1
  117. package/dist/pr-post.js +125 -3
  118. package/dist/release-floors.d.ts +31 -1
  119. package/dist/release-floors.d.ts.map +1 -1
  120. package/dist/release-floors.js +31 -1
  121. package/dist/state-migration.d.ts +24 -0
  122. package/dist/state-migration.d.ts.map +1 -1
  123. package/dist/state-migration.js +100 -5
  124. package/dist/wave-runtime.mjs +305 -298
  125. package/dist/workspace/lexicon-outputs.d.ts.map +1 -1
  126. package/dist/workspace/lexicon-outputs.js +21 -7
  127. package/dist/workspace/reason-codes.d.ts +3 -0
  128. package/dist/workspace/reason-codes.d.ts.map +1 -1
  129. package/dist/workspace/reason-codes.js +4 -0
  130. package/dist/workspace/ref-gate.schema.json +85 -0
  131. package/dist/workspace/search-contract.d.ts +1 -1
  132. package/dist/workspace/search-contract.d.ts.map +1 -1
  133. package/dist/workspace/trust/check-evidence-report.d.ts +51 -0
  134. package/dist/workspace/trust/check-evidence-report.d.ts.map +1 -0
  135. package/dist/workspace/trust/check-evidence-report.js +102 -0
  136. package/dist/workspace/trust/check-evidence.d.ts +126 -0
  137. package/dist/workspace/trust/check-evidence.d.ts.map +1 -0
  138. package/dist/workspace/trust/check-evidence.js +237 -0
  139. package/dist/workspace/trust/local-evidence.d.ts +120 -0
  140. package/dist/workspace/trust/local-evidence.d.ts.map +1 -0
  141. package/dist/workspace/trust/local-evidence.js +259 -0
  142. package/dist/workspace/trust/policy.d.ts +84 -0
  143. package/dist/workspace/trust/policy.d.ts.map +1 -1
  144. package/dist/workspace/trust/policy.js +94 -1
  145. package/dist/workspace/trust/ref-gate-cli.d.ts +33 -0
  146. package/dist/workspace/trust/ref-gate-cli.d.ts.map +1 -0
  147. package/dist/workspace/trust/ref-gate-cli.js +234 -0
  148. package/dist/workspace/trust/ref-gate-fixture.d.ts +38 -0
  149. package/dist/workspace/trust/ref-gate-fixture.d.ts.map +1 -0
  150. package/dist/workspace/trust/ref-gate-fixture.js +97 -0
  151. package/dist/workspace/trust/ref-gate.d.ts +187 -0
  152. package/dist/workspace/trust/ref-gate.d.ts.map +1 -0
  153. package/dist/workspace/trust/ref-gate.js +430 -0
  154. package/dist/workspace/trust/trust-files.d.ts.map +1 -1
  155. package/dist/workspace/trust/trust-files.js +18 -1
  156. package/package.json +1 -1
  157. package/src/bundle-check.test.ts +140 -0
  158. package/src/bundle-check.ts +352 -0
  159. package/src/chant-install.test.ts +112 -0
  160. package/src/chant-install.ts +179 -0
  161. package/src/ci-commit.test.ts +45 -0
  162. package/src/ci-commit.ts +38 -4
  163. package/src/ci-evidence-jobs.ts +67 -0
  164. package/src/ci-image.test.ts +506 -0
  165. package/src/ci-image.ts +822 -0
  166. package/src/ci-login.test.ts +235 -0
  167. package/src/ci-login.ts +307 -0
  168. package/src/ci-product.ts +18 -0
  169. package/src/cli/commands/__fixtures__/source-dir-include/chant.config.json +1 -0
  170. package/src/cli/commands/__fixtures__/source-dir-include/infra.ts +1 -0
  171. package/src/cli/commands/__fixtures__/source-dir-include/scripts/run-on-load.ts +3 -0
  172. package/src/cli/commands/__fixtures__/source-dir-root/chant.config.json +1 -0
  173. package/src/cli/commands/__fixtures__/source-dir-root/infra.test.ts +1 -0
  174. package/src/cli/commands/__fixtures__/source-dir-root/infra.ts +1 -0
  175. package/src/cli/commands/__fixtures__/source-dir-root/scripts/run-on-load.ts +3 -0
  176. package/src/cli/commands/__fixtures__/source-dir-scoped/app.ts +3 -0
  177. package/src/cli/commands/__fixtures__/source-dir-scoped/chant.config.json +1 -0
  178. package/src/cli/commands/__fixtures__/source-dir-scoped/infra/net.ts +1 -0
  179. package/src/cli/commands/__fixtures__/source-dir-scoped/scripts/run-on-load.ts +3 -0
  180. package/src/cli/commands/import-index.ts +2 -2
  181. package/src/cli/handlers/build-source-dir.test.ts +64 -0
  182. package/src/cli/handlers/build.ts +21 -4
  183. package/src/cli/handlers/ci-check.ts +56 -3
  184. package/src/cli/handlers/ci-evidence.ts +162 -0
  185. package/src/cli/handlers/components.ts +3 -3
  186. package/src/cli/handlers/dead-guards.ts +37 -0
  187. package/src/cli/handlers/graph.ts +4 -4
  188. package/src/cli/handlers/lifecycle.ts +5 -4
  189. package/src/cli/handlers/local-chant.ts +106 -0
  190. package/src/cli/handlers/operator.ts +2 -2
  191. package/src/cli/handlers/search.ts +5 -5
  192. package/src/cli/main.test.ts +7 -0
  193. package/src/cli/main.ts +38 -0
  194. package/src/cli/parse-args.ts +21 -0
  195. package/src/cli/registry.ts +16 -0
  196. package/src/components/check-evidence-stage.test.ts +80 -0
  197. package/src/components/check-hooks.ts +84 -4
  198. package/src/components/check-local-evidence-stage.test.ts +141 -0
  199. package/src/components/check-steps.ts +56 -6
  200. package/src/components/product-pipeline.ts +28 -3
  201. package/src/components/product-plan.test.ts +87 -0
  202. package/src/components/product-plan.ts +226 -0
  203. package/src/components/release-compile.ts +2 -2
  204. package/src/config.ts +44 -3
  205. package/src/dead-guards.test.ts +206 -0
  206. package/src/dead-guards.ts +446 -0
  207. package/src/discovery/files.ts +5 -3
  208. package/src/drift-issue-bundle.test.ts +31 -0
  209. package/src/drift-issue.test.ts +206 -0
  210. package/src/drift-issue.ts +274 -0
  211. package/src/fit-note.test.ts +44 -0
  212. package/src/floor-table.data.ts +180 -0
  213. package/src/floor-table.ts +77 -0
  214. package/src/forge-flags.test.ts +110 -0
  215. package/src/forge-flags.ts +208 -0
  216. package/src/gate-decision-bundle.test.ts +1 -0
  217. package/src/lexicon.ts +68 -0
  218. package/src/lifecycle/gated-op.ts +10 -5
  219. package/src/local-chant.e2e.test.ts +94 -0
  220. package/src/local-chant.test.ts +162 -0
  221. package/src/local-chant.ts +341 -0
  222. package/src/op/activities/predict-behaviour.ts +2 -2
  223. package/src/op/op-waves-evidence-spec.ts +24 -0
  224. package/src/op/op-waves-evidence.test.ts +130 -0
  225. package/src/op/op-waves-evidence.ts +57 -0
  226. package/src/op/op-waves-run.ts +25 -1
  227. package/src/op/op-waves.ts +31 -1
  228. package/src/op/schedule-overdue.test.ts +85 -0
  229. package/src/op/schedule-overdue.ts +162 -26
  230. package/src/plan-summary.ts +40 -0
  231. package/src/pr-plan-note.ts +34 -0
  232. package/src/pr-post-plan-note.test.ts +146 -0
  233. package/src/pr-post.ts +127 -3
  234. package/src/release-floors.ts +44 -1
  235. package/src/stage-hooks-bundle.test.ts +1 -0
  236. package/src/state-migration.test.ts +52 -1
  237. package/src/state-migration.ts +107 -5
  238. package/src/workspace/lexicon-outputs.ts +23 -6
  239. package/src/workspace/reason-codes.test.ts +3 -0
  240. package/src/workspace/reason-codes.ts +4 -0
  241. package/src/workspace/ref-gate.schema.json +85 -0
  242. package/src/workspace/trust/check-evidence-report.ts +106 -0
  243. package/src/workspace/trust/check-evidence.test.ts +133 -0
  244. package/src/workspace/trust/check-evidence.ts +257 -0
  245. package/src/workspace/trust/local-evidence.test.ts +127 -0
  246. package/src/workspace/trust/local-evidence.ts +266 -0
  247. package/src/workspace/trust/policy.ts +134 -1
  248. package/src/workspace/trust/ref-gate-cli.ts +244 -0
  249. package/src/workspace/trust/ref-gate-fixture.ts +125 -0
  250. package/src/workspace/trust/ref-gate.e2e.test.ts +76 -0
  251. package/src/workspace/trust/ref-gate.test.ts +247 -0
  252. package/src/workspace/trust/ref-gate.ts +538 -0
  253. package/src/workspace/trust/trust-files.test.ts +16 -0
  254. package/src/workspace/trust/trust-files.ts +41 -1
@@ -89,7 +89,7 @@
89
89
  * the wave (exit 8). See `./op-waves-run.ts`.
90
90
  */
91
91
 
92
- import type { OpEnvironment, OpSetupStep } from "../lexicon";
92
+ import type { OpEnvironment, OpSetupStep, OpWaveJobInputs } from "../lexicon";
93
93
  import type { CiRunner } from "../ci-jobs";
94
94
  import type { CloudTradeSpec } from "../ci-identity";
95
95
  import { gatePointProblems, type GatePoint } from "./gate-point";
@@ -99,6 +99,7 @@ import { notifyConfigProblem, type NotifyConfig } from "../notify";
99
99
  import type { CiResponses } from "../ci-respond";
100
100
  import { WAVE_GATE_NAME_PATTERN, waveGateNameFrom, waveShare } from "../wave-layout";
101
101
  import { waveOutcomeFileName } from "../wave-blocked";
102
+ import { opWavesEvidenceProblems, type OpWavesEvidence } from "./op-waves-evidence-spec";
102
103
  import { opWaveHoldsProblems, opWaveParallelismProblems, opWaveStepProblems, type OpWaveHolds, type OpWaveStep } from "./op-waves-capability-spec";
103
104
  import { opWaveReleaseProblems, type OpWaveReleaseNames } from "./op-waves-release";
104
105
  import { CONTROL_DISPATCH_JOB, CONTROL_NAME, controlSettingsProblems, resolveControlTarget, type ControlSettingsInput, type ControlTarget } from "../control/dispatch";
@@ -556,6 +557,13 @@ export interface OpWavesSpec {
556
557
  hooks?: OpWaveHooks;
557
558
  /** What happens to an approval once a wave applies under it (#3784). Read at the base commit. */
558
559
  approvals?: OpWavesApprovals;
560
+ /**
561
+ * Check evidence (#4870): `requires` names the checks whose current
562
+ * evidence the applied commit's tree needs, read at base, such as the
563
+ * `plan` and `policy` a pull request's plan note job signed. A wave whose
564
+ * commit lacks one plans and applies nothing. See ./op-waves-evidence.ts.
565
+ */
566
+ evidence?: OpWavesEvidence;
559
567
  /**
560
568
  * Who may override a run the product's policy denied at plan time (#3821).
561
569
  * A plan entry with `denied` refuses the wave unless an override on
@@ -820,6 +828,24 @@ export function opWaveBinArgv(bin?: string): string[] {
820
828
  return words.length > 0 ? words : ["chant"];
821
829
  }
822
830
 
831
+ /**
832
+ * A product's inputs for each wave's jobs (#4791, `OpWavesPipelineOptions.waveJobs`),
833
+ * by wave index from 0. Throws on a key that names none of the spec's waves,
834
+ * so a renamed wave cannot drop its login or report without a word.
835
+ */
836
+ export function opWaveJobInputsByWave(spec: Pick<OpWavesSpec, "name" | "waves">, waveJobs: Readonly<Record<string, OpWaveJobInputs>> | undefined): Array<OpWaveJobInputs | undefined> {
837
+ const names = spec.waves.map((w) => w.name);
838
+ for (const key of Object.keys(waveJobs ?? {})) {
839
+ if (!names.includes(key)) throw new Error(`Op waves "${spec.name}": waveJobs names the wave "${key}", which the spec does not have (${names.join(", ")}).`);
840
+ }
841
+ return names.map((name) => waveJobs?.[name]);
842
+ }
843
+
844
+ /** A wave job's artifact name (#4791): `{job}` in `name` is the job's name. */
845
+ export function opWaveJobArtifactName(name: string, jobName: string): string {
846
+ return name.split("{job}").join(jobName);
847
+ }
848
+
823
849
  /** The command a resume job runs, through the product's bin when it has one (#4607). */
824
850
  export function opWavesResumeCommand(spec: Pick<OpWavesSpec, "name">, bin?: string): string[] {
825
851
  return [...opWaveBinArgv(bin), "run", "resume", "--op", spec.name];
@@ -954,6 +980,10 @@ export function assertOpWavesSpec(spec: OpWavesSpec): void {
954
980
  const problems = opWaveHoldsProblems(spec.holds);
955
981
  if (problems.length > 0) throw new Error(`${where}: ${problems.join("; ")}.`);
956
982
  }
983
+ {
984
+ const problems = opWavesEvidenceProblems((spec as { evidence?: unknown }).evidence);
985
+ if (problems.length > 0) throw new Error(`${where}: ${problems.join("; ")}.`);
986
+ }
957
987
  if (spec.labels !== undefined) {
958
988
  const l = spec.labels as unknown;
959
989
  if (l === null || typeof l !== "object" || Array.isArray(l) || !Object.values(l as Record<string, unknown>).every((v) => typeof v === "string")) {
@@ -224,6 +224,91 @@ describe("checkOverdueOps", () => {
224
224
  expect(opPipelineFile(root, "gitlab", "drift")).toBe("ops.gitlab-ci.yml");
225
225
  expect(opPipelineFile(root, "gitlab", "other")).toBeUndefined();
226
226
  });
227
+
228
+ // #4789: the schedule can be in a file the generator wrote below the root.
229
+ const selects = (op: string) => `drift:\n rules:\n - if: $CI_PIPELINE_SOURCE == "schedule" && $CHANT_SCHEDULED_OP == "${op}"\n`;
230
+
231
+ test("gitlab: a member's file that .gitlab-ci.yml includes, below the root", async () => {
232
+ const root = repo(
233
+ {
234
+ ".gitlab-ci.yml": "include:\n - local: apps/web/web-ops.gitlab-ci.yml\n - project: other/group\n file: ci.yml\n",
235
+ "apps/web/web-ops.gitlab-ci.yml": selects("drift"),
236
+ },
237
+ "2026-10-01T00:00:00Z",
238
+ );
239
+ const asked: string[] = [];
240
+ const found = await checkOverdueOps({
241
+ watches: [{ op: "drift", cron: "0 6 * * *" }],
242
+ forge: forgeWith("gitlab", async (q) => {
243
+ asked.push(q.workflow);
244
+ return { noSchedule: true };
245
+ }),
246
+ repoRoot: root,
247
+ now: new Date("2026-10-22T00:00:00Z"),
248
+ log: () => {},
249
+ });
250
+ expect(asked).toEqual(["web-ops.gitlab-ci.yml"]);
251
+ expect(found.map((o) => [o.op, o.neverRan])).toEqual([["drift", true]]);
252
+ });
253
+
254
+ test("gitlab: an include given as a string, a child pipeline's include, and a file under .gitlab/", () => {
255
+ const root = repo(
256
+ {
257
+ ".gitlab-ci.yml": 'include: "ci/main.yml"\n',
258
+ "ci/main.yml": "child:\n trigger:\n include: ci/child.yml\n",
259
+ "ci/child.yml": selects("child-op"),
260
+ ".gitlab/yodel-watch.gitlab-ci.yml": selects("watch-prod"),
261
+ "deep/nested/ops.gitlab-ci.yml": selects("deep-op"),
262
+ },
263
+ "2026-10-01T00:00:00Z",
264
+ );
265
+ expect(opPipelineFile(root, "gitlab", "child-op")).toBe("ci/child.yml");
266
+ expect(opPipelineFile(root, "gitlab", "watch-prod")).toBe(".gitlab/yodel-watch.gitlab-ci.yml");
267
+ expect(opPipelineFile(root, "gitlab", "deep-op")).toBe("deep/nested/ops.gitlab-ci.yml");
268
+ expect(opPipelineFile(root, "gitlab", "none")).toBeUndefined();
269
+ });
270
+
271
+ test("github and forgejo: a workflow under another name whose name is the Op's, or a .yaml file", () => {
272
+ const root = repo(
273
+ {
274
+ ".github/workflows/scheduled-drift.yml": "name: drift\non:\n schedule:\n - cron: '0 6 * * *'\n",
275
+ ".forgejo/workflows/drift.yaml": "name: drift\n",
276
+ ".github/workflows/other.yml": "name: other-op\n",
277
+ },
278
+ "2026-10-01T00:00:00Z",
279
+ );
280
+ expect(opPipelineFile(root, "github", "drift")).toBe(".github/workflows/scheduled-drift.yml");
281
+ expect(opPipelineFile(root, "forgejo", "drift")).toBe(".forgejo/workflows/drift.yaml");
282
+ expect(opPipelineFile(root, "github", "missing")).toBeUndefined();
283
+ });
284
+
285
+ test("a product's own files and schedule rule: the first file present, its selector asked and named", async () => {
286
+ const schedule = { variable: "TERRAGUCCI_SCHEDULE", not: ["comments", "resume"] };
287
+ const root = repo(
288
+ {
289
+ ".gitlab-ci.yml": "include:\n - local: .gitlab/terragucci.yml\n",
290
+ ".gitlab/terragucci.yml": 'drift:\n rules:\n - if: $CI_PIPELINE_SOURCE == "schedule" && $TERRAGUCCI_SCHEDULE != "comments" && $TERRAGUCCI_SCHEDULE != "resume"\n',
291
+ ".github/workflows/terragucci.yml": "name: terragucci\n",
292
+ },
293
+ "2026-10-01T00:00:00Z",
294
+ );
295
+ const files = [".github/workflows/terragucci-drift.yml", ".github/workflows/terragucci.yml"];
296
+ expect(opPipelineFile(root, "github", { op: "tf-drift", files })).toBe(".github/workflows/terragucci.yml");
297
+ expect(opPipelineFile(root, "gitlab", { op: "tf-drift", schedule })).toBe(".gitlab/terragucci.yml");
298
+ const asked: unknown[] = [];
299
+ const found = await checkOverdueOps({
300
+ watches: [{ op: "tf-drift", cron: "0 6 * * *", schedule }],
301
+ forge: forgeWith("gitlab", async (q) => {
302
+ asked.push(q.schedule);
303
+ return { noSchedule: true };
304
+ }),
305
+ repoRoot: root,
306
+ now: new Date("2026-10-22T00:00:00Z"),
307
+ log: () => {},
308
+ });
309
+ expect(asked).toEqual([schedule]);
310
+ expect(found[0]?.message).toContain("No active pipeline schedule is picked by the Op's rule, one whose TERRAGUCCI_SCHEDULE is none of comments, resume.");
311
+ });
227
312
  });
228
313
 
229
314
  describe("the plan note", () => {
@@ -15,16 +15,32 @@
15
15
  * not answer is a line in the log and no verdict.
16
16
  */
17
17
  import { spawnSync } from "node:child_process";
18
- import { existsSync, readdirSync, readFileSync } from "node:fs";
18
+ import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
19
19
  import { join } from "node:path";
20
20
  import type { OpConfig } from "./types";
21
21
  import { cronFiresUtc } from "./cron";
22
- import type { ForgeKind, PrForge, ScheduledRuns } from "../pr-forge";
22
+ import type { ForgeKind, PrForge, ScheduledRuns, ScheduledRunsQuery } from "../pr-forge";
23
+ import { parseYAMLDocument, splitYAMLDocuments } from "../yaml";
23
24
 
24
25
  /** One scheduled watch or reconcile Op the plan job checks. */
25
26
  export interface ScheduledWatch {
26
27
  op: string;
27
28
  cron: string;
29
+ /**
30
+ * The files a product's generator wrote for the job, relative to the
31
+ * repository root (#4789). The first one in the checkout is the Op's
32
+ * pipeline file. Left out, {@link opPipelineFile} looks for the file
33
+ * `chant run --generate` writes, then reads every workflow or pipeline
34
+ * file it finds.
35
+ */
36
+ files?: readonly string[];
37
+ /**
38
+ * GitLab: the schedule selector of the job's `rules: if:` when it is not
39
+ * `CHANT_SCHEDULED_OP` set to `op` (#4789), as `scheduledRuns` takes it
40
+ * (#4813). The check finds the file by it, asks the forge with it, and a
41
+ * missing schedule's line names it.
42
+ */
43
+ schedule?: ScheduledRunsQuery["schedule"];
28
44
  }
29
45
 
30
46
  /** An Op the plan note warns about. */
@@ -56,36 +72,145 @@ export function scheduledWatches(ops: Iterable<OpConfig>): ScheduledWatch[] {
56
72
  }
57
73
 
58
74
  /**
59
- * The file `chant run --generate <forge>` writes for an Op, relative to the
60
- * repository root: `<dir>/<op>.yml` on GitHub and Forgejo, `<member>-<op>.yml`
61
- * in a workspace member. GitLab puts every Op in one file, so the root's
62
- * `*.gitlab-ci.yml` files are read for the one whose rules select the Op.
63
- * Undefined when the checkout has no such file, so an Op that some other
75
+ * The pipeline file an Op's scheduled job is in, relative to the repository
76
+ * root, or undefined when the checkout has none, so an Op that some other
64
77
  * scheduler runs is never checked.
78
+ *
79
+ * With `files` (a product's own generator, #4789), the first of them in the
80
+ * checkout. Otherwise, on GitHub and Forgejo, the file `chant run --generate
81
+ * <forge>` writes, `<dir>/<op>.yml` (`<member>-<op>.yml` in a workspace
82
+ * member, or `.yaml`), and failing that the first workflow in `<dir>` whose
83
+ * `name:` is the Op's. On GitLab a scheduled job can be in any pipeline
84
+ * file, so each one {@link gitlabPipelineFiles} finds is read for the one
85
+ * whose rules select the Op (#4789).
65
86
  */
66
- export function opPipelineFile(repoRoot: string, forge: ForgeKind, op: string, member?: string): string | undefined {
67
- const base = member ? `${member}-${op}` : op;
87
+ export function opPipelineFile(repoRoot: string, forge: ForgeKind, watch: string | Pick<ScheduledWatch, "op" | "files" | "schedule">, member?: string): string | undefined {
88
+ const w = typeof watch === "string" ? { op: watch } : watch;
89
+ if (w.files) return w.files.find((f) => existsSync(join(repoRoot, f)));
90
+ const base = member ? `${member}-${w.op}` : w.op;
68
91
  if (forge === "github" || forge === "forgejo") {
69
- const path = `.${forge}/workflows/${base}.yml`;
70
- return existsSync(join(repoRoot, path)) ? path : undefined;
92
+ const dir = `.${forge}/workflows`;
93
+ const exact = [`${dir}/${base}.yml`, `${dir}/${base}.yaml`].find((p) => existsSync(join(repoRoot, p)));
94
+ if (exact) return exact;
95
+ return listDir(join(repoRoot, dir))
96
+ .filter((n) => /\.ya?ml$/.test(n))
97
+ .sort()
98
+ .map((n) => `${dir}/${n}`)
99
+ .find((p) => {
100
+ const name = yamlDocs(repoRoot, p)[0]?.name;
101
+ return name === base || name === w.op;
102
+ });
71
103
  }
72
- // The gitlab lexicon's cron rule: `$CHANT_SCHEDULED_OP == "<op>"`.
73
- const selector = `$CHANT_SCHEDULED_OP == "${op}"`;
74
- let names: string[];
75
- try {
76
- names = readdirSync(repoRoot).filter((n) => n.endsWith(".gitlab-ci.yml")).sort();
77
- } catch {
78
- return undefined;
79
- }
80
- return names.find((n) => {
104
+ const selects = gitlabSelector(w);
105
+ return gitlabPipelineFiles(repoRoot).find((p) => {
81
106
  try {
82
- return readFileSync(join(repoRoot, n), "utf8").includes(selector);
107
+ return selects(readFileSync(join(repoRoot, p), "utf8"));
83
108
  } catch {
84
109
  return false;
85
110
  }
86
111
  });
87
112
  }
88
113
 
114
+ /**
115
+ * Whether a GitLab file's text holds the job's schedule rule. The gitlab
116
+ * lexicon's cron rule tests `$CHANT_SCHEDULED_OP == "<op>"`. A `schedule`
117
+ * selector's rule tests its variable against its value, or against each of
118
+ * its `not` values with `!=`.
119
+ */
120
+ function gitlabSelector(w: Pick<ScheduledWatch, "op" | "schedule">): (text: string) => boolean {
121
+ const s = w.schedule ?? { variable: "CHANT_SCHEDULED_OP", value: w.op };
122
+ const needles = s.value !== undefined ? [`$${s.variable} == "${s.value}"`] : s.not?.length ? s.not.map((n) => `$${s.variable} != "${n}"`) : [`$${s.variable}`];
123
+ return (text) => needles.every((n) => text.includes(n));
124
+ }
125
+
126
+ /** Directories the walk for pipeline files never enters. */
127
+ const SKIP_DIRS = new Set([".git", "node_modules", ".chant", "dist"]);
128
+
129
+ /**
130
+ * Every GitLab pipeline file in the checkout, relative to the root, in the
131
+ * order {@link opPipelineFile} reads them (#4789): the root's
132
+ * `*.gitlab-ci.yml`, then the local files `.gitlab-ci.yml` includes and
133
+ * the child pipelines they trigger (`trigger: include:`), then every file
134
+ * under `.gitlab/` and every `*.gitlab-ci.yml` further down. An include
135
+ * with a wildcard or a variable is not followed; the walk finds its files
136
+ * when they are under `.gitlab/` or named `*.gitlab-ci.yml`.
137
+ */
138
+ export function gitlabPipelineFiles(repoRoot: string): string[] {
139
+ const out: string[] = [];
140
+ const add = (p: string) => {
141
+ if (!out.includes(p) && existsSync(join(repoRoot, p))) out.push(p);
142
+ };
143
+ for (const n of listDir(repoRoot).filter((n) => n.endsWith(".gitlab-ci.yml")).sort()) add(n);
144
+ const queue = existsSync(join(repoRoot, ".gitlab-ci.yml")) ? [".gitlab-ci.yml"] : [];
145
+ const seen = new Set<string>();
146
+ while (queue.length > 0) {
147
+ const file = queue.shift()!;
148
+ if (seen.has(file)) continue;
149
+ seen.add(file);
150
+ for (const doc of yamlDocs(repoRoot, file)) {
151
+ for (const inc of localIncludes(doc)) {
152
+ add(inc);
153
+ queue.push(inc);
154
+ }
155
+ }
156
+ }
157
+ const walk = (dir: string, depth: number, underGitlab: boolean) => {
158
+ if (depth > 8) return;
159
+ for (const n of listDir(join(repoRoot, dir)).sort()) {
160
+ const rel = dir ? `${dir}/${n}` : n;
161
+ let isDir: boolean;
162
+ try {
163
+ isDir = statSync(join(repoRoot, rel)).isDirectory();
164
+ } catch {
165
+ continue;
166
+ }
167
+ if (isDir) {
168
+ if (!SKIP_DIRS.has(n)) walk(rel, depth + 1, underGitlab || rel === ".gitlab");
169
+ } else if (dir !== "" && (n.endsWith(".gitlab-ci.yml") || (underGitlab && /\.ya?ml$/.test(n)))) add(rel);
170
+ }
171
+ };
172
+ walk("", 0, false);
173
+ return out;
174
+ }
175
+
176
+ /** The local files a GitLab document includes, with each job's `trigger: include:`, as paths from the root. */
177
+ function localIncludes(doc: Record<string, unknown>): string[] {
178
+ const paths: string[] = [];
179
+ const read = (inc: unknown) => {
180
+ for (const entry of Array.isArray(inc) ? inc : [inc]) {
181
+ // A string include is local unless it is a URL; a mapping is local only with `local:`.
182
+ const path = typeof entry === "string" ? (/^https?:\/\//.test(entry) ? undefined : entry) : isRecord(entry) && typeof entry.local === "string" ? entry.local : undefined;
183
+ if (path && !path.includes("*") && !path.includes("$")) paths.push(path.replace(/^\/+/, ""));
184
+ }
185
+ };
186
+ read(doc.include);
187
+ for (const job of Object.values(doc)) {
188
+ if (isRecord(job) && isRecord(job.trigger)) read(job.trigger.include);
189
+ }
190
+ return paths;
191
+ }
192
+
193
+ const isRecord = (v: unknown): v is Record<string, unknown> => typeof v === "object" && v !== null && !Array.isArray(v);
194
+
195
+ function listDir(dir: string): string[] {
196
+ try {
197
+ return readdirSync(dir);
198
+ } catch {
199
+ return [];
200
+ }
201
+ }
202
+
203
+ /** A YAML file's mapping documents, or none when it cannot be read or parsed. */
204
+ function yamlDocs(repoRoot: string, path: string): Record<string, unknown>[] {
205
+ try {
206
+ return splitYAMLDocuments(readFileSync(join(repoRoot, path), "utf8"))
207
+ .map((d) => parseYAMLDocument(d))
208
+ .filter(isRecord);
209
+ } catch {
210
+ return [];
211
+ }
212
+ }
213
+
89
214
  /** When `path` was first committed (ISO 8601), if the checkout's history has it. */
90
215
  export function fileAdded(repoRoot: string, path: string): string | undefined {
91
216
  const r = spawnSync("git", ["-C", repoRoot, "log", "--format=%cI", "--diff-filter=A", "--", path], { encoding: "utf-8" });
@@ -99,6 +224,15 @@ const HINT: Record<ForgeKind, string> = {
99
224
  forgejo: "Check that Actions is on for the repository and a runner is up, or run the workflow by hand",
100
225
  };
101
226
 
227
+ /** GitLab: what no active schedule does, in the words of the job's selector (#4789). */
228
+ function noScheduleLine(watch: ScheduledWatch): string {
229
+ const s = watch.schedule;
230
+ if (!s) return `No active pipeline schedule sets CHANT_SCHEDULED_OP to ${watch.op}`;
231
+ if (s.value !== undefined) return `No active pipeline schedule sets ${s.variable} to ${s.value}`;
232
+ if (s.not?.length) return `No active pipeline schedule is picked by the Op's rule, one whose ${s.variable} is none of ${s.not.join(", ")}`;
233
+ return `No active pipeline schedule sets ${s.variable}`;
234
+ }
235
+
102
236
  /**
103
237
  * Whether one Op is overdue: its cron has fired at least twice since its
104
238
  * last run, or since `added` when no run is on record. Undefined when it is
@@ -113,7 +247,7 @@ export function overdueVerdict(watch: ScheduledWatch, forge: ForgeKind, runs: Sc
113
247
  const why = runs.disabled
114
248
  ? `GitHub has turned the workflow off (${runs.disabled}). Turn it on again under Actions`
115
249
  : forge === "gitlab" && runs.noSchedule
116
- ? `No active pipeline schedule sets CHANT_SCHEDULED_OP to ${watch.op}. Add one with the cron \`${watch.cron}\` under CI/CD > Schedules`
250
+ ? `${noScheduleLine(watch)}. Add one with the cron \`${watch.cron}\` under CI/CD > Schedules`
117
251
  : HINT[forge];
118
252
  return {
119
253
  op: watch.op,
@@ -128,11 +262,13 @@ export function overdueVerdict(watch: ScheduledWatch, forge: ForgeKind, runs: Sc
128
262
  * The plan job's check over every scheduled watch or reconcile Op that has a
129
263
  * generated pipeline file. Each Op the forge will not answer for is a line
130
264
  * in `log` and no verdict. A forge client with no `scheduledRuns` checks
131
- * nothing.
265
+ * nothing. A product with its own generator passes each job's `files` and,
266
+ * on GitLab, its `schedule` selector, and needs no lookup of its own
267
+ * (#4789); `forge` is any client with `kind` and `scheduledRuns`.
132
268
  */
133
269
  export async function checkOverdueOps(input: {
134
270
  watches: readonly ScheduledWatch[];
135
- forge: PrForge;
271
+ forge: Pick<PrForge, "kind" | "scheduledRuns">;
136
272
  repoRoot: string;
137
273
  member?: string;
138
274
  now: Date;
@@ -142,11 +278,11 @@ export async function checkOverdueOps(input: {
142
278
  if (!forge.scheduledRuns) return [];
143
279
  const out: OverdueOp[] = [];
144
280
  for (const watch of input.watches) {
145
- const file = opPipelineFile(input.repoRoot, forge.kind, watch.op, input.member);
281
+ const file = opPipelineFile(input.repoRoot, forge.kind, watch, input.member);
146
282
  if (!file) continue;
147
283
  let runs: ScheduledRuns;
148
284
  try {
149
- runs = await forge.scheduledRuns({ op: watch.op, workflow: file.split("/").pop()! });
285
+ runs = await forge.scheduledRuns({ op: watch.op, workflow: file.split("/").pop()!, ...(watch.schedule ? { schedule: watch.schedule } : {}) });
150
286
  } catch (err) {
151
287
  input.log(`schedule check: ${forge.kind} did not say when Op ${watch.op} last ran, so it is not checked: ${(err instanceof Error ? err.message : String(err)).split("\n")[0]}`);
152
288
  continue;
@@ -56,6 +56,7 @@
56
56
  */
57
57
 
58
58
  import { computePlanDigest, PLAN_DIGEST_PREFIX } from "./lifecycle/plan-digest";
59
+ import type { ForgeKind } from "./pr-forge";
59
60
  import type { ChangeSetAction, ChangeSetAttribute, ChangeSetDocument, ChangeSetEntry, ChangeSetMember, ChangeSetSideEffect } from "./change-set";
60
61
 
61
62
  /** The schema a plan summary names in `$schema`. */
@@ -77,6 +78,45 @@ export const GITHUB_COMMENT_LIMIT = 65_536;
77
78
  */
78
79
  export const GITLAB_NOTE_LIMIT = 1_000_000;
79
80
 
81
+ /**
82
+ * The most characters a note on `forge` may hold (#4800): {@link GITLAB_NOTE_LIMIT}
83
+ * on GitLab, {@link GITHUB_COMMENT_LIMIT} on GitHub and Forgejo, and on a
84
+ * forge not known yet, so a note that fits there fits everywhere.
85
+ */
86
+ export function noteLimit(forge?: ForgeKind): number {
87
+ return forge === "gitlab" ? GITLAB_NOTE_LIMIT : GITHUB_COMMENT_LIMIT;
88
+ }
89
+
90
+ export interface FitNoteOptions {
91
+ /** The most characters the note may hold, closing line included. Default {@link GITHUB_COMMENT_LIMIT}. */
92
+ limit?: number;
93
+ /** What follows the cut, in the product's words; `{cut}` becomes the characters kept. Default {@link NOTE_CUT_LINE}. */
94
+ tail?: string;
95
+ }
96
+
97
+ /** What {@link fitNote} writes after a cut. */
98
+ export const NOTE_CUT_LINE = "\n\nThe note was cut at {cut} characters; the run's report has all of it.";
99
+
100
+ /**
101
+ * `body` as it is when it fits `limit`, else its start and the closing line,
102
+ * the two together at most `limit` (#4800). Length is counted in UTF-16 units,
103
+ * JavaScript's `length`, which is never less than the code points a forge
104
+ * counts, and the cut never splits a surrogate pair. This is the one
105
+ * truncation products call in place of their own `MAX_NOTE` and
106
+ * `COMMENT_LIMIT` copies; a renderer that drops whole blocks, as
107
+ * {@link renderPlanSummaryMarkdown} does, compares against {@link noteLimit}.
108
+ */
109
+ export function fitNote(body: string, options: FitNoteOptions = {}): string {
110
+ const limit = options.limit ?? GITHUB_COMMENT_LIMIT;
111
+ if (body.length <= limit) return body;
112
+ const tail = options.tail ?? NOTE_CUT_LINE;
113
+ let cut = Math.max(0, limit - tail.replaceAll("{cut}", String(limit)).length);
114
+ const code = body.charCodeAt(cut - 1);
115
+ if (code >= 0xd800 && code <= 0xdbff) cut--;
116
+ const closing = tail.replaceAll("{cut}", String(cut));
117
+ return (body.slice(0, cut) + closing).slice(0, limit);
118
+ }
119
+
80
120
  /** What a group's units are: whole members, or the instances of one member. */
81
121
  export type PlanSummaryUnit = "member" | "instance";
82
122
 
@@ -33,6 +33,40 @@ export const PR_PLAN_NOTE_FLOOR = "0.124.78";
33
33
  /** The read contract a {@link PrPlanNote} follows. */
34
34
  export const PR_PLAN_NOTE_CONTRACT = 1;
35
35
 
36
+ /**
37
+ * The file a product's plan verb writes its plan note hand-off to (#4799),
38
+ * beside where `pr-plan` writes `pr-plan.json`: chant's plan-note job posts
39
+ * it with `pr-post`.
40
+ */
41
+ export const PR_PLAN_NOTE_FILE = "pr-plan-note.json";
42
+
43
+ /**
44
+ * A product's plan note, handed from its plan job to chant's plan-note job
45
+ * (#4799). `pr-post` checks `pr`, `head`, `env` and `member` against its own
46
+ * flags, renders `note` with the pipeline's note words, and sets the plan
47
+ * status to `state` with `description`, or to failure when the plan job
48
+ * failed. Everything in it is read as data: it was written by the change's
49
+ * code.
50
+ */
51
+ export interface PrPlanNoteHandoff {
52
+ kind: "plan-note-handoff";
53
+ contract: typeof PR_PLAN_NOTE_CONTRACT;
54
+ pr: number;
55
+ /** The commit planned: the same as `note.head`. */
56
+ head: string;
57
+ env: string;
58
+ /** The target (an environment, a member) the note is for, as `pr-post --member` names it. */
59
+ member?: string;
60
+ state: "success" | "failure" | "pending";
61
+ description: string;
62
+ note: PrPlanNote;
63
+ }
64
+
65
+ /** The hand-off for `note` (#4799), as a product's plan verb writes it to {@link PR_PLAN_NOTE_FILE}. */
66
+ export function planNoteHandoff(note: PrPlanNote, at: { pr: number; env: string; member?: string; state: PrPlanNoteHandoff["state"]; description: string }): PrPlanNoteHandoff {
67
+ return { kind: "plan-note-handoff", contract: PR_PLAN_NOTE_CONTRACT, pr: at.pr, head: note.head, env: at.env, ...(at.member !== undefined ? { member: at.member } : {}), state: at.state, description: at.description, note };
68
+ }
69
+
36
70
  /** One change line of a group, as chant's plan summary groups them. */
37
71
  export interface PrPlanNoteChange {
38
72
  line: string;
@@ -0,0 +1,146 @@
1
+ /**
2
+ * #4799: chant's plan-note job posts a product's plan note hand-off, which
3
+ * the product's plan verb wrote in place of pr-plan's report. It is read as
4
+ * data, as a report is: the pull request, head, environment and member are
5
+ * the caller's, a forged marker is defused, and the waves marker chant
6
+ * renders from the note's waves is kept for the product to read back.
7
+ */
8
+ import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
9
+ import { tmpdir } from "node:os";
10
+ import { join } from "node:path";
11
+ import { afterAll, describe, expect, test } from "vitest";
12
+ import { postOpenPlanReports, postPlanReport } from "./pr-post";
13
+ import { prNoteMarker } from "./pr-loop";
14
+ import { planNoteHandoff, PR_PLAN_NOTE_FILE, renderPlanNote, type PrPlanNote } from "./pr-plan-note";
15
+ import { withProductWords, assertProductWords } from "./ci-product-words";
16
+ import type { ForgeStatus, PrForge } from "./pr-forge";
17
+ import { TERRAGUCCI, TERRAGUCCI_NOTE } from "./__fixtures__/product-words";
18
+
19
+ const NOTE = JSON.parse(readFileSync(join(import.meta.dirname, "__fixtures__", "pr-loop", "terragucci-plan.note.json"), "utf-8")) as PrPlanNote;
20
+ const HEAD = NOTE.head;
21
+ const dirs: string[] = [];
22
+ afterAll(() => {
23
+ for (const d of dirs) rmSync(d, { recursive: true, force: true });
24
+ });
25
+
26
+ function handoffDir(doc: unknown): string {
27
+ const dir = mkdtempSync(join(tmpdir(), "chant-pr-post-note-"));
28
+ dirs.push(dir);
29
+ writeFileSync(join(dir, PR_PLAN_NOTE_FILE), JSON.stringify(doc));
30
+ return dir;
31
+ }
32
+
33
+ function fakeForge(): { forge: PrForge; statuses: Array<{ sha: string; status: ForgeStatus }>; notes: Array<{ pr: number; marker: string; body: string }> } {
34
+ const statuses: Array<{ sha: string; status: ForgeStatus }> = [];
35
+ const notes: Array<{ pr: number; marker: string; body: string }> = [];
36
+ const forge = {
37
+ kind: "github",
38
+ host: "github.com",
39
+ async setStatus(sha: string, status: ForgeStatus) {
40
+ statuses.push({ sha, status });
41
+ },
42
+ async upsertNote(pr: number, marker: string, body: string) {
43
+ notes.push({ pr, marker, body });
44
+ return "1";
45
+ },
46
+ async findComment() {
47
+ return undefined;
48
+ },
49
+ } as unknown as PrForge;
50
+ return { forge, statuses, notes };
51
+ }
52
+
53
+ const words = assertProductWords(TERRAGUCCI);
54
+ const at = { pr: 7, env: "default", state: "pending" as const, description: "1 wave waits for an approval" };
55
+
56
+ describe("pr-post posts a product's plan note hand-off (#4799)", () => {
57
+ test("renders the note in the product's words under chant's marker, and sets the status the hand-off gives", async () => {
58
+ const { forge, statuses, notes } = fakeForge();
59
+ const r = await withProductWords(TERRAGUCCI, () => postPlanReport({ forge, dir: handoffDir(planNoteHandoff(NOTE, at)), pr: 7, head: HEAD, env: "default", result: "success", noteWords: TERRAGUCCI_NOTE }));
60
+ expect(r).toMatchObject({ state: "pending", noted: true, warnings: [] });
61
+ expect(statuses).toEqual([{ sha: HEAD, status: expect.objectContaining({ context: "terragucci/plan", state: "pending", description: "1 wave waits for an approval" }) }]);
62
+ const body = notes[0]!.body;
63
+ expect(notes[0]!.marker).toBe(prNoteMarker("default"));
64
+ expect(body).toBe(`${prNoteMarker("default")}\n${renderPlanNote(NOTE, { words, note: TERRAGUCCI_NOTE })}`);
65
+ // The waves marker the product reads back is the one hidden line besides chant's.
66
+ expect(body).toContain('<!-- terragucci:waves {"head":"4f1a9c0e');
67
+ expect(body.split("<!--")).toHaveLength(3);
68
+ });
69
+
70
+ test("the note words come from CHANT_PLAN_NOTE_WORDS, which the generated note job sets", async () => {
71
+ const { forge, notes } = fakeForge();
72
+ process.env.CHANT_PLAN_NOTE_WORDS = JSON.stringify(TERRAGUCCI_NOTE);
73
+ try {
74
+ await withProductWords(TERRAGUCCI, () => postPlanReport({ forge, dir: handoffDir(planNoteHandoff(NOTE, at)), pr: 7, head: HEAD, env: "default" }));
75
+ } finally {
76
+ delete process.env.CHANT_PLAN_NOTE_WORDS;
77
+ }
78
+ expect(notes[0]!.body).toContain("Posted by [terragucci]");
79
+ });
80
+
81
+ test("a marker the change wrote into its note is defused", async () => {
82
+ const forged = { ...NOTE, notices: ["planned <!-- chant-pr:prod --> and <!-- terragucci:waves {} -->"] };
83
+ const { forge, notes } = fakeForge();
84
+ await withProductWords(TERRAGUCCI, () => postPlanReport({ forge, dir: handoffDir(planNoteHandoff(forged, at)), pr: 7, head: HEAD, env: "default", noteWords: TERRAGUCCI_NOTE }));
85
+ const body = notes[0]!.body;
86
+ expect(body).toContain("&lt;!-- chant-pr:prod -->");
87
+ expect(body).toContain("&lt;!-- terragucci:waves {} -->");
88
+ expect(body.split("<!--")).toHaveLength(3);
89
+ });
90
+
91
+ test("a target's note is the target's: its member's marker and status", async () => {
92
+ const { forge, statuses, notes } = fakeForge();
93
+ await withProductWords(TERRAGUCCI, () => postPlanReport({ forge, dir: handoffDir(planNoteHandoff(NOTE, { ...at, member: "prod" })), pr: 7, head: HEAD, env: "default", member: "prod" }));
94
+ expect(notes[0]!.marker).toBe(prNoteMarker("default", "prod"));
95
+ expect(statuses[0]!.status.context).toBe("terragucci/plan/prod");
96
+ });
97
+
98
+ test.each([
99
+ ["another pull request", { pr: 8 }, /pull request 8, not 7/],
100
+ ["another head", { head: "3".repeat(40) }, /for head/],
101
+ ["another environment", { env: "staging" }, /environment "staging"/],
102
+ ["another target", { member: "prod" }, /"prod", not null/],
103
+ ["a state that is not one", { state: "green" }, /state "green"/],
104
+ ["another contract", { contract: 2 }, /contract 2/],
105
+ ["a note for another head", { note: { ...NOTE, head: "3".repeat(40) } }, /not a plan note for its head/],
106
+ ])("refuses a hand-off for %s and fails the status", async (_what, change, error) => {
107
+ const { forge, statuses, notes } = fakeForge();
108
+ const r = await postPlanReport({ forge, dir: handoffDir({ ...planNoteHandoff(NOTE, at), ...change }), pr: 7, head: HEAD, env: "default" });
109
+ expect(r.refused).toMatch(error);
110
+ expect(r.noted).toBe(false);
111
+ expect(notes).toEqual([]);
112
+ expect(statuses[0]!.status.state).toBe("failure");
113
+ });
114
+
115
+ test("a plan job that failed fails the status whatever the hand-off says", async () => {
116
+ const { forge, statuses } = fakeForge();
117
+ await postPlanReport({ forge, dir: handoffDir(planNoteHandoff(NOTE, { ...at, state: "success" })), pr: 7, head: HEAD, env: "default", result: "failure" });
118
+ expect(statuses[0]!.status).toMatchObject({ state: "failure", description: expect.stringMatching(/^the plan job failed; /) });
119
+ });
120
+
121
+ test("on GitLab, pr-post --open reads the hand-off from the plan job's artifacts when it kept no report", async () => {
122
+ const { forge: base, notes } = fakeForge();
123
+ const asked: string[] = [];
124
+ const forge = {
125
+ ...base,
126
+ kind: "gitlab",
127
+ async mergeRequestJobs() {
128
+ return [{ pr: 7, head: HEAD, id: 11, status: "success", url: "https://gitlab.example/job/11" }];
129
+ },
130
+ async jobArtifact(_id: number, path: string) {
131
+ asked.push(path);
132
+ return path.endsWith(PR_PLAN_NOTE_FILE) ? JSON.stringify(planNoteHandoff(NOTE, { ...at, member: "prod" })) : undefined;
133
+ },
134
+ async statusUrl() {
135
+ return undefined;
136
+ },
137
+ setStatus: base.setStatus,
138
+ upsertNote: base.upsertNote,
139
+ findComment: base.findComment,
140
+ } as unknown as PrForge;
141
+ const done = await postOpenPlanReports({ forge, branch: "main", job: "prod-plan", artifactDir: ".chant/pr", env: "default", member: "prod" });
142
+ expect(asked).toEqual([".chant/pr/pr-plan.json", ".chant/pr/pr-plan-note.json"]);
143
+ expect(done.posts[0]!.posted).toMatchObject({ noted: true });
144
+ expect(notes[0]!.marker).toBe(prNoteMarker("default", "prod"));
145
+ });
146
+ });