@intentius/chant 0.124.91 → 0.124.93

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 (108) hide show
  1. package/dist/__golden__/notify-defaults-plain.json +52 -0
  2. package/dist/__golden__/notify-defaults-relay.json +92 -0
  3. package/dist/ci-comment-commands.d.ts +11 -1
  4. package/dist/ci-comment-commands.d.ts.map +1 -1
  5. package/dist/ci-comment-commands.js +10 -3
  6. package/dist/ci-job-guard.d.ts +22 -8
  7. package/dist/ci-job-guard.d.ts.map +1 -1
  8. package/dist/ci-job-guard.js +93 -49
  9. package/dist/ci-jobs.d.ts +22 -0
  10. package/dist/ci-jobs.d.ts.map +1 -1
  11. package/dist/ci-jobs.js +23 -0
  12. package/dist/ci-product.d.ts +42 -1
  13. package/dist/ci-product.d.ts.map +1 -1
  14. package/dist/ci-product.js +44 -3
  15. package/dist/cli/handlers/pr-comment.d.ts.map +1 -1
  16. package/dist/cli/handlers/pr-comment.js +15 -2
  17. package/dist/cli/handlers/pr.d.ts.map +1 -1
  18. package/dist/cli/handlers/pr.js +4 -1
  19. package/dist/components/pr-pipeline.d.ts +4 -2
  20. package/dist/components/pr-pipeline.d.ts.map +1 -1
  21. package/dist/components/pr-pipeline.js +7 -4
  22. package/dist/components/product-pipeline.d.ts +71 -7
  23. package/dist/components/product-pipeline.d.ts.map +1 -1
  24. package/dist/components/product-pipeline.js +84 -22
  25. package/dist/components/product-plan.d.ts +7 -0
  26. package/dist/components/product-plan.d.ts.map +1 -1
  27. package/dist/components/product-plan.js +1 -0
  28. package/dist/floor-table.data.d.ts.map +1 -1
  29. package/dist/floor-table.data.js +15 -5
  30. package/dist/lexicon.d.ts +59 -1
  31. package/dist/lexicon.d.ts.map +1 -1
  32. package/dist/notify.d.ts +8 -0
  33. package/dist/notify.d.ts.map +1 -1
  34. package/dist/notify.js +8 -3
  35. package/dist/op/before-merge-decide.d.ts +2 -0
  36. package/dist/op/before-merge-decide.d.ts.map +1 -1
  37. package/dist/op/before-merge.d.ts +8 -0
  38. package/dist/op/before-merge.d.ts.map +1 -1
  39. package/dist/op/before-merge.js +6 -0
  40. package/dist/op/index.d.ts +1 -1
  41. package/dist/op/index.d.ts.map +1 -1
  42. package/dist/op/index.js +1 -1
  43. package/dist/op/op-waves-evidence-jobs.d.ts +3 -2
  44. package/dist/op/op-waves-evidence-jobs.d.ts.map +1 -1
  45. package/dist/op/op-waves-evidence-jobs.js +4 -3
  46. package/dist/op/op-waves-follow-on.d.ts +2 -0
  47. package/dist/op/op-waves-follow-on.d.ts.map +1 -1
  48. package/dist/op/op-waves-follow-on.js +8 -2
  49. package/dist/op/op-waves-names.d.ts +145 -0
  50. package/dist/op/op-waves-names.d.ts.map +1 -0
  51. package/dist/op/op-waves-names.js +201 -0
  52. package/dist/op/op-waves-run.d.ts +2 -0
  53. package/dist/op/op-waves-run.d.ts.map +1 -1
  54. package/dist/op/op-waves-run.js +2 -2
  55. package/dist/op/op-waves-stand-down.d.ts +9 -1
  56. package/dist/op/op-waves-stand-down.d.ts.map +1 -1
  57. package/dist/op/op-waves-stand-down.js +14 -2
  58. package/dist/op/op-waves.d.ts +12 -1
  59. package/dist/op/op-waves.d.ts.map +1 -1
  60. package/dist/op/op-waves.js +2 -0
  61. package/dist/pr-forge-job.d.ts +8 -0
  62. package/dist/pr-forge-job.d.ts.map +1 -1
  63. package/dist/pr-forge-job.js +13 -0
  64. package/dist/pr-plan-record.d.ts +3 -1
  65. package/dist/pr-plan-record.d.ts.map +1 -1
  66. package/dist/pr-plan-record.js +1 -1
  67. package/dist/pr-post.d.ts +9 -3
  68. package/dist/pr-post.d.ts.map +1 -1
  69. package/dist/pr-post.js +5 -2
  70. package/dist/release-floors.d.ts +1 -1
  71. package/dist/release-floors.d.ts.map +1 -1
  72. package/dist/release-floors.js +4 -4
  73. package/dist/wave-runtime.mjs +305 -305
  74. package/package.json +1 -1
  75. package/src/__golden__/notify-defaults-plain.json +52 -0
  76. package/src/__golden__/notify-defaults-relay.json +92 -0
  77. package/src/ci-comment-commands.test.ts +19 -5
  78. package/src/ci-comment-commands.ts +18 -3
  79. package/src/ci-job-guard.default-branch.test.ts +125 -0
  80. package/src/ci-job-guard.ts +64 -10
  81. package/src/ci-jobs.ts +26 -0
  82. package/src/ci-product.ts +54 -3
  83. package/src/cli/handlers/pr-comment.ts +12 -2
  84. package/src/cli/handlers/pr.ts +4 -1
  85. package/src/components/pr-pipeline.ts +7 -4
  86. package/src/components/product-job-names.test.ts +176 -0
  87. package/src/components/product-pipeline.ts +143 -31
  88. package/src/components/product-plan.ts +8 -0
  89. package/src/floor-table.data.ts +15 -5
  90. package/src/lexicon.ts +59 -1
  91. package/src/notify-bundle.test.ts +3 -2
  92. package/src/notify-relay-name.test.ts +72 -0
  93. package/src/notify.ts +16 -3
  94. package/src/op/before-merge-decide.ts +2 -0
  95. package/src/op/before-merge.ts +12 -0
  96. package/src/op/index.ts +1 -1
  97. package/src/op/op-waves-evidence-jobs.ts +4 -3
  98. package/src/op/op-waves-follow-on.ts +10 -2
  99. package/src/op/op-waves-names.test.ts +131 -0
  100. package/src/op/op-waves-names.ts +289 -0
  101. package/src/op/op-waves-run.ts +4 -2
  102. package/src/op/op-waves-stand-down.ts +15 -2
  103. package/src/op/op-waves.ts +13 -1
  104. package/src/pr-forge-job.ts +13 -0
  105. package/src/pr-plan-record.ts +4 -2
  106. package/src/pr-post-head.test.ts +116 -0
  107. package/src/pr-post.ts +15 -5
  108. package/src/release-floors.ts +4 -4
@@ -0,0 +1,116 @@
1
+ /**
2
+ * #5020: on GitHub the note job names the pull request's head
3
+ * (`github.event.pull_request.head.sha`), while the plan job checked out
4
+ * the run's merge preview (`github.sha`). `pr-post --head <head>` takes a
5
+ * report, a plan note hand-off or a run record for that merge preview as the
6
+ * head's, and for the head itself (terragucci's plan verb writes its
7
+ * hand-off for the head), and posts the status on the head.
8
+ */
9
+ import { execFileSync } from "node:child_process";
10
+ import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
11
+ import { tmpdir } from "node:os";
12
+ import { join } from "node:path";
13
+ import { afterAll, describe, expect, test } from "vitest";
14
+ import { PLAN_RECORD_JS, PLAN_RUN_RECORD_ENV } from "./components/product-plan";
15
+ import { plannedForHead } from "./pr-forge-job";
16
+ import type { ForgeStatus, PrForge } from "./pr-forge";
17
+ import type { PrReport } from "./pr-loop";
18
+ import { planBodyHandoff, PR_PLAN_NOTE_FILE } from "./pr-plan-note";
19
+ import { PLAN_RUN_RECORD_FILE, readPlanRunRecord } from "./pr-plan-record";
20
+ import { postPlanReport, readPlanNoteHandoff } from "./pr-post";
21
+
22
+ const REPORT = JSON.parse(readFileSync(join(import.meta.dirname, "__fixtures__", "pr-loop", "pr-plan.golden.json"), "utf-8")) as PrReport;
23
+ const HEAD = "a".repeat(40);
24
+ const MERGE = "b".repeat(40);
25
+ const OTHER = "c".repeat(40);
26
+
27
+ const dirs: string[] = [];
28
+ afterAll(() => {
29
+ for (const d of dirs) rmSync(d, { recursive: true, force: true });
30
+ });
31
+ const tmp = (): string => {
32
+ const d = mkdtempSync(join(tmpdir(), "chant-5020-"));
33
+ dirs.push(d);
34
+ return d;
35
+ };
36
+
37
+ function eventEnv(event = "pull_request"): Record<string, string> {
38
+ const path = join(tmp(), "event.json");
39
+ writeFileSync(path, JSON.stringify({ number: 12, pull_request: { number: 12, head: { sha: HEAD } } }));
40
+ return { GITHUB_EVENT_NAME: event, GITHUB_SHA: MERGE, GITHUB_EVENT_PATH: path };
41
+ }
42
+
43
+ function fakeForge(): { forge: PrForge; statuses: string[] } {
44
+ const statuses: string[] = [];
45
+ const forge = {
46
+ kind: "github",
47
+ host: "github.com",
48
+ async setStatus(sha: string, _status: ForgeStatus) {
49
+ statuses.push(sha);
50
+ },
51
+ async upsertNote() {
52
+ return "1";
53
+ },
54
+ } as unknown as PrForge;
55
+ return { forge, statuses };
56
+ }
57
+
58
+ describe("the commit a pull_request run's plan job planned for the head (#5020)", () => {
59
+ test("the merge preview, when --head is the event's head", () => {
60
+ expect(plannedForHead(HEAD, eventEnv())).toBe(MERGE);
61
+ });
62
+
63
+ test("nothing for another head, another event, a run of the head itself, or no event", () => {
64
+ expect(plannedForHead(OTHER, eventEnv())).toBeUndefined();
65
+ expect(plannedForHead(HEAD, eventEnv("push"))).toBeUndefined();
66
+ expect(plannedForHead(HEAD, { ...eventEnv(), GITHUB_SHA: HEAD })).toBeUndefined();
67
+ expect(plannedForHead(HEAD, { GITHUB_SHA: MERGE })).toBeUndefined();
68
+ });
69
+ });
70
+
71
+ describe("pr-post for the head takes the merge preview's report as the head's (#5020)", () => {
72
+ const at = { pr: REPORT.pr!, head: HEAD, planned: MERGE, env: REPORT.env };
73
+ const reportDir = (head: string): string => {
74
+ const d = tmp();
75
+ writeFileSync(join(d, "pr-plan.json"), JSON.stringify({ ...REPORT, head }));
76
+ return d;
77
+ };
78
+
79
+ test.each([
80
+ ["the merge preview the plan job checked out", MERGE],
81
+ ["the head", HEAD],
82
+ ])("a report for %s posts on the head", async (_what, head) => {
83
+ const { forge, statuses } = fakeForge();
84
+ const r = await postPlanReport({ forge, dir: reportDir(head), ...at, result: "success" });
85
+ expect(r.refused).toBeUndefined();
86
+ expect(r.state).toBe("success");
87
+ expect(statuses).toEqual([HEAD]);
88
+ });
89
+
90
+ test("a report for another commit is refused, and so is the merge preview's when nothing says the plan job checked it out", async () => {
91
+ const other = await postPlanReport({ forge: fakeForge().forge, dir: reportDir(OTHER), ...at });
92
+ expect(other.refused).toMatch(/the report is for head/);
93
+ const { planned: _planned, ...bare } = at;
94
+ const merge = await postPlanReport({ forge: fakeForge().forge, dir: reportDir(MERGE), ...bare });
95
+ expect(merge.refused).toMatch(/the report is for head/);
96
+ });
97
+
98
+ test("a product's plan note hand-off for the merge preview or the head is the head's", () => {
99
+ for (const head of [MERGE, HEAD]) {
100
+ const d = tmp();
101
+ writeFileSync(join(d, PR_PLAN_NOTE_FILE), JSON.stringify(planBodyHandoff("planned", { pr: 12, head, env: "prod", state: "success", description: "planned" })));
102
+ expect(readPlanNoteHandoff({ dir: d, pr: 12, head: HEAD, planned: MERGE, env: "prod" })).toHaveProperty("handoff");
103
+ if (head === MERGE) expect(readPlanNoteHandoff({ dir: d, pr: 12, head: HEAD, env: "prod" })).toEqual({ refused: expect.stringMatching(/for head/) });
104
+ }
105
+ });
106
+
107
+ test("the plan job's run record of the merge preview is the head's", () => {
108
+ const d = tmp();
109
+ const config = JSON.stringify({ op: "pr-plan", env: "prod", labels: { Env: "prod", Pipeline: "pr", Job: "plan" } });
110
+ execFileSync(process.execPath, ["-e", PLAN_RECORD_JS, d], { cwd: d, env: { ...process.env, [PLAN_RUN_RECORD_ENV]: config, CHANT_PLAN_EXIT: "0", CHANT_PLAN_STARTED: "2026-11-10T00:00:00Z" } });
111
+ const file = join(d, PLAN_RUN_RECORD_FILE);
112
+ writeFileSync(file, JSON.stringify({ ...JSON.parse(readFileSync(file, "utf-8")), gitSha: MERGE }));
113
+ expect(readPlanRunRecord(d, { env: "prod", head: HEAD, planned: MERGE })).toHaveProperty("record");
114
+ expect(readPlanRunRecord(d, { env: "prod", head: HEAD })).toEqual({ refused: expect.stringMatching(/for commit/) });
115
+ });
116
+ });
package/src/pr-post.ts CHANGED
@@ -54,8 +54,14 @@ export interface PlanPostInput {
54
54
  dir: string;
55
55
  /** The pull request, from the forge's event. */
56
56
  pr: number;
57
- /** The commit the plan job checked out, from the forge's event. */
57
+ /** The pull request's head, from the forge's event: the commit the statuses go on. */
58
58
  head: string;
59
+ /**
60
+ * The commit the plan job checked out when it is not `head` (#5020): a
61
+ * GitHub `pull_request` run's merge preview (`GITHUB_SHA`). A report, plan
62
+ * note or run record for it counts as the head's.
63
+ */
64
+ planned?: string;
59
65
  env: string;
60
66
  member?: string;
61
67
  /** The plan status's context (#5003, a product plan's `statusContext`), in place of {@link prStatusContext}'s. */
@@ -142,12 +148,15 @@ export interface PlanPostResult {
142
148
 
143
149
  const SHA = /^[0-9a-f]{40}$/;
144
150
 
151
+ /** Whether `sha` is the head a caller posts for, or the merge preview its plan job checked out for it (#5020). */
152
+ const isPlannedHead = (sha: string, input: Pick<PlanPostInput, "head" | "planned">): boolean => sha === input.head || (input.planned !== undefined && sha === input.planned);
153
+
145
154
  /**
146
155
  * Read the plan report under `dir` and check it is the one the caller ran:
147
156
  * a plan report for the same pull request, head, environment and member.
148
157
  * Returns the report, or why it is not used.
149
158
  */
150
- export function readPlanReport(input: Pick<PlanPostInput, "dir" | "pr" | "head" | "env" | "member">): { report: PrReport } | { refused: string } {
159
+ export function readPlanReport(input: Pick<PlanPostInput, "dir" | "pr" | "head" | "planned" | "env" | "member">): { report: PrReport } | { refused: string } {
151
160
  const file = join(input.dir, PR_PLAN_REPORT_FILE);
152
161
  if (!existsSync(file)) return { refused: "the plan job wrote no report" };
153
162
  let doc: unknown;
@@ -160,7 +169,7 @@ export function readPlanReport(input: Pick<PlanPostInput, "dir" | "pr" | "head"
160
169
  const r = doc as Record<string, unknown>;
161
170
  if (r.stage !== "plan") return { refused: `the report is not a plan report (stage ${JSON.stringify(r.stage)})` };
162
171
  if (r.pr !== input.pr) return { refused: `the report is for pull request ${JSON.stringify(r.pr)}, not ${input.pr}` };
163
- if (typeof r.head !== "string" || !SHA.test(r.head) || r.head !== input.head) return { refused: `the report is for head ${JSON.stringify(r.head)}, not ${input.head}` };
172
+ if (typeof r.head !== "string" || !SHA.test(r.head) || !isPlannedHead(r.head, input)) return { refused: `the report is for head ${JSON.stringify(r.head)}, not ${input.head}` };
164
173
  if (r.env !== input.env) return { refused: `the report is for environment ${JSON.stringify(r.env)}, not ${input.env}` };
165
174
  if ((r.member ?? undefined) !== input.member) return { refused: `the report is for member ${JSON.stringify(r.member ?? null)}, not ${JSON.stringify(input.member ?? null)}` };
166
175
  if (!Array.isArray(r.members) || !r.changeSet || typeof r.changeSet !== "object" || !r.selection || typeof r.selection !== "object" || !r.approval || typeof r.approval !== "object") {
@@ -370,6 +379,7 @@ async function keepRunRecord(input: PlanPostInput, warnings: string[]): Promise<
370
379
  const read = readPlanRunRecord(input.dir, {
371
380
  env: input.env,
372
381
  head: input.head,
382
+ ...(input.planned ? { planned: input.planned } : {}),
373
383
  ...(input.member ? { target: input.member } : {}),
374
384
  ...(input.result ? { result: input.result } : {}),
375
385
  ...(input.recordRun.origin ? { origin: input.recordRun.origin } : {}),
@@ -437,7 +447,7 @@ async function postOutcome(
437
447
  * Read a product's plan note hand-off under `dir` (#4799) and check it is the
438
448
  * one the caller ran, as {@link readPlanReport} checks a report.
439
449
  */
440
- export function readPlanNoteHandoff(input: Pick<PlanPostInput, "dir" | "pr" | "head" | "env" | "member">): { handoff: PrPlanNoteHandoff | PrPlanBodyHandoff } | { refused: string } {
450
+ export function readPlanNoteHandoff(input: Pick<PlanPostInput, "dir" | "pr" | "head" | "planned" | "env" | "member">): { handoff: PrPlanNoteHandoff | PrPlanBodyHandoff } | { refused: string } {
441
451
  let doc: unknown;
442
452
  try {
443
453
  doc = JSON.parse(readFileSync(join(input.dir, PR_PLAN_NOTE_FILE), "utf-8"));
@@ -449,7 +459,7 @@ export function readPlanNoteHandoff(input: Pick<PlanPostInput, "dir" | "pr" | "h
449
459
  if (r.kind !== "plan-note-handoff") return { refused: `the file is not a plan note hand-off (kind ${JSON.stringify(r.kind)})` };
450
460
  if (r.contract !== PR_PLAN_NOTE_CONTRACT) return { refused: `the plan note follows contract ${JSON.stringify(r.contract)}, and this chant reads ${PR_PLAN_NOTE_CONTRACT}` };
451
461
  if (r.pr !== input.pr) return { refused: `the plan note is for pull request ${JSON.stringify(r.pr)}, not ${input.pr}` };
452
- if (typeof r.head !== "string" || !SHA.test(r.head) || r.head !== input.head) return { refused: `the plan note is for head ${JSON.stringify(r.head)}, not ${input.head}` };
462
+ if (typeof r.head !== "string" || !SHA.test(r.head) || !isPlannedHead(r.head, input)) return { refused: `the plan note is for head ${JSON.stringify(r.head)}, not ${input.head}` };
453
463
  if (r.env !== input.env) return { refused: `the plan note is for environment ${JSON.stringify(r.env)}, not ${input.env}` };
454
464
  if ((r.member ?? undefined) !== input.member) return { refused: `the plan note is for ${JSON.stringify(r.member ?? null)}, not ${JSON.stringify(input.member ?? null)}` };
455
465
  if (r.state !== "success" && r.state !== "failure" && r.state !== "pending") return { refused: `the plan note's state ${JSON.stringify(r.state)} is not success, failure or pending` };
@@ -19,7 +19,7 @@
19
19
  * this constant to the next patch (#4501). The check fails while a floor
20
20
  * still names this constant after its version shipped.
21
21
  */
22
- export const NEXT_RELEASE = "0.124.91";
22
+ export const NEXT_RELEASE = "0.124.93";
23
23
 
24
24
  /** The first chant with `chant dev local` and `chant dev bundle-check`, `@intentius/chant/local-chant` and `@intentius/chant/bundle-check` (`chantRuntimeTarget`, `chantExternalPlugin`, `checkBundle`): a product built against a chant checkout, and its bundle checked, without its own scripts (#4787). */
25
25
  export const LOCAL_CHANT_FLOOR = "0.124.86";
@@ -211,7 +211,7 @@ export const GITLAB_WAVE_KEY_SCOPE_FLOOR = "0.124.89";
211
211
  export const ACTOR_ORDER_FLOOR = "0.124.89";
212
212
 
213
213
  /** The first chant whose `actorOf({ env, repo })` runs `git config` in `repo` with the `env` it is given rather than the process's, so a job's `GIT_CONFIG_GLOBAL` or `HOME` picks the `user.name` it reads (#5005). */
214
- export const ACTOR_GIT_ENV_FLOOR = NEXT_RELEASE;
214
+ export const ACTOR_GIT_ENV_FLOOR = "0.124.91";
215
215
 
216
216
  /** The first chant with `@intentius/chant/ci-base` (`ciBaseRef`), the base a CI job measures a change from (the pull request's target branch, else the default branch for a push to another branch), and whose `chant ci check` defaults `--base` to it (#4966). */
217
217
  export const CI_BASE_REF_FLOOR = "0.124.89";
@@ -220,7 +220,7 @@ export const CI_BASE_REF_FLOOR = "0.124.89";
220
220
  export const PLANNED_FILES_FLOOR = "0.124.89";
221
221
 
222
222
  /** The first chant whose `planFile` in `@intentius/chant/planned-files` takes bytes (`Uint8Array` or `Buffer`) as well as text: `writePlannedFiles` writes them unchanged and the plan compares them with the file byte for byte (#5006). */
223
- export const PLANNED_BYTES_FLOOR = NEXT_RELEASE;
223
+ export const PLANNED_BYTES_FLOOR = "0.124.91";
224
224
 
225
225
  /** The first chant whose `pipelineContract` takes `jobs`, the jobs a product builds from its own config, beside or in place of `pipelines`, so a product's forge check gets the required statuses and `refGateStatus` from chant (#4966). */
226
226
  export const FORGE_CHECK_OWN_JOBS_FLOOR = "0.124.89";
@@ -238,4 +238,4 @@ export const RUNTIME_WAVES_SPEC_FLOOR = "0.124.89";
238
238
  export const GITLAB_WAVE_EVIDENCE_RETRY_FLOOR = "0.124.89";
239
239
 
240
240
  /** The first chant whose terraform lexicon's engine runs carry what a product's own command tracing read: `runBinary` and the engine runner's `exec` and `execSync` answer stderr apart (`Ran.stderr`) and a spawn failure's message (`Ran.error`), a hook's `after` gets a binary that could not be started as a null code with `error`, `commandTrace` ends that span with the message, and `composeCommandHooks` runs a product's own hook and `commandTrace` as one `onCommand` (#5007). */
241
- export const TERRAFORM_COMMAND_TRACE_FLOOR = NEXT_RELEASE;
241
+ export const TERRAFORM_COMMAND_TRACE_FLOOR = "0.124.91";