@intentius/chant 0.124.88 → 0.124.90
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.
- package/dist/actor.d.ts +36 -1
- package/dist/actor.d.ts.map +1 -1
- package/dist/actor.js +39 -1
- package/dist/chant-install.d.ts.map +1 -1
- package/dist/chant-install.js +1 -2
- package/dist/ci-base.d.ts +30 -0
- package/dist/ci-base.d.ts.map +1 -0
- package/dist/ci-base.js +33 -0
- package/dist/ci-comment-commands.d.ts +193 -0
- package/dist/ci-comment-commands.d.ts.map +1 -0
- package/dist/ci-comment-commands.js +353 -0
- package/dist/ci-comment-replies.d.ts +40 -0
- package/dist/ci-comment-replies.d.ts.map +1 -0
- package/dist/ci-comment-replies.js +59 -0
- package/dist/ci-evidence-from-job.d.ts +25 -0
- package/dist/ci-evidence-from-job.d.ts.map +1 -1
- package/dist/ci-evidence-from-job.js +43 -2
- package/dist/ci-evidence-jobs.d.ts +30 -1
- package/dist/ci-evidence-jobs.d.ts.map +1 -1
- package/dist/ci-evidence-jobs.js +46 -3
- package/dist/ci-image.d.ts +21 -4
- package/dist/ci-image.d.ts.map +1 -1
- package/dist/ci-image.js +62 -10
- package/dist/ci-job-guard.d.ts +42 -45
- package/dist/ci-job-guard.d.ts.map +1 -1
- package/dist/ci-job-guard.js +206 -3
- package/dist/ci-note-commands.d.ts +104 -4
- package/dist/ci-note-commands.d.ts.map +1 -1
- package/dist/ci-note-commands.js +131 -38
- package/dist/ci-product-words.d.ts +42 -0
- package/dist/ci-product-words.d.ts.map +1 -1
- package/dist/ci-product-words.js +25 -0
- package/dist/ci-product.d.ts +72 -1
- package/dist/ci-product.d.ts.map +1 -1
- package/dist/ci-product.js +73 -6
- package/dist/cli/commands/build.d.ts.map +1 -1
- package/dist/cli/commands/build.js +29 -2
- package/dist/cli/handlers/approve.d.ts.map +1 -1
- package/dist/cli/handlers/approve.js +2 -1
- package/dist/cli/handlers/ci-check.d.ts +1 -1
- package/dist/cli/handlers/ci-check.d.ts.map +1 -1
- package/dist/cli/handlers/ci-check.js +17 -7
- package/dist/cli/handlers/ci-evidence.d.ts.map +1 -1
- package/dist/cli/handlers/ci-evidence.js +33 -7
- package/dist/cli/handlers/components.d.ts.map +1 -1
- package/dist/cli/handlers/components.js +3 -1
- package/dist/cli/handlers/generated-check.d.ts +8 -0
- package/dist/cli/handlers/generated-check.d.ts.map +1 -1
- package/dist/cli/handlers/generated-check.js +31 -1
- package/dist/cli/handlers/lock.d.ts.map +1 -1
- package/dist/cli/handlers/lock.js +121 -4
- package/dist/cli/handlers/pr-comment.d.ts +33 -0
- package/dist/cli/handlers/pr-comment.d.ts.map +1 -0
- package/dist/cli/handlers/pr-comment.js +201 -0
- package/dist/cli/handlers/pr-env.d.ts.map +1 -1
- package/dist/cli/handlers/pr-env.js +6 -3
- package/dist/cli/handlers/pr-notes.d.ts.map +1 -1
- package/dist/cli/handlers/pr-notes.js +23 -1
- package/dist/cli/handlers/pr.d.ts +23 -1
- package/dist/cli/handlers/pr.d.ts.map +1 -1
- package/dist/cli/handlers/pr.js +71 -23
- package/dist/cli/handlers/promote.d.ts.map +1 -1
- package/dist/cli/handlers/promote.js +2 -1
- package/dist/cli/handlers/release.d.ts.map +1 -1
- package/dist/cli/handlers/release.js +11 -2
- package/dist/cli/handlers/run-wave.d.ts.map +1 -1
- package/dist/cli/handlers/run-wave.js +180 -4
- package/dist/cli/handlers/run.d.ts.map +1 -1
- package/dist/cli/handlers/run.js +2 -1
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +41 -2
- package/dist/cli/parse-args.d.ts.map +1 -1
- package/dist/cli/parse-args.js +31 -0
- package/dist/cli/registry.d.ts +19 -1
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/components/auto-release.d.ts.map +1 -1
- package/dist/components/auto-release.js +2 -1
- package/dist/components/pr-checks.d.ts +97 -6
- package/dist/components/pr-checks.d.ts.map +1 -1
- package/dist/components/pr-checks.js +107 -13
- package/dist/components/pr-pipeline.d.ts +19 -14
- package/dist/components/pr-pipeline.d.ts.map +1 -1
- package/dist/components/pr-pipeline.js +7 -13
- package/dist/components/product-pipeline.d.ts +96 -3
- package/dist/components/product-pipeline.d.ts.map +1 -1
- package/dist/components/product-pipeline.js +120 -14
- package/dist/components/product-plan.d.ts +203 -6
- package/dist/components/product-plan.d.ts.map +1 -1
- package/dist/components/product-plan.js +250 -43
- package/dist/drift-record.d.ts +7 -0
- package/dist/drift-record.d.ts.map +1 -1
- package/dist/drift-record.js +19 -0
- package/dist/floor-table.data.d.ts.map +1 -1
- package/dist/floor-table.data.js +63 -31
- package/dist/forge-check/contract.d.ts +11 -1
- package/dist/forge-check/contract.d.ts.map +1 -1
- package/dist/forge-check/contract.js +4 -1
- package/dist/forge-check/index.d.ts +2 -0
- package/dist/forge-check/index.d.ts.map +1 -1
- package/dist/forge-check/index.js +2 -0
- package/dist/gate-resume-run.d.ts +9 -1
- package/dist/gate-resume-run.d.ts.map +1 -1
- package/dist/gate-resume-run.js +26 -3
- package/dist/generated-check.d.ts +18 -4
- package/dist/generated-check.d.ts.map +1 -1
- package/dist/generated-check.js +37 -5
- package/dist/image-pins.d.ts +26 -0
- package/dist/image-pins.d.ts.map +1 -0
- package/dist/image-pins.js +19 -0
- package/dist/lexicon.d.ts +93 -4
- package/dist/lexicon.d.ts.map +1 -1
- package/dist/lifecycle/gate-applied.d.ts +9 -0
- package/dist/lifecycle/gate-applied.d.ts.map +1 -1
- package/dist/lifecycle/git.d.ts +11 -0
- package/dist/lifecycle/git.d.ts.map +1 -1
- package/dist/lifecycle/git.js +30 -3
- package/dist/lifecycle/publish-npm.d.ts +11 -0
- package/dist/lifecycle/publish-npm.d.ts.map +1 -1
- package/dist/lifecycle/publish-npm.js +27 -1
- package/dist/lifecycle/reach-locks.d.ts +131 -0
- package/dist/lifecycle/reach-locks.d.ts.map +1 -0
- package/dist/lifecycle/reach-locks.js +118 -0
- package/dist/lifecycle/release-cut.d.ts +3 -1
- package/dist/lifecycle/release-cut.d.ts.map +1 -1
- package/dist/lifecycle/release-cut.js +15 -0
- package/dist/lifecycle/release-images.d.ts.map +1 -1
- package/dist/lifecycle/release-images.js +1 -2
- package/dist/notify-product.d.ts +12 -3
- package/dist/notify-product.d.ts.map +1 -1
- package/dist/notify-product.js +10 -6
- package/dist/op/activities/source-release.d.ts.map +1 -1
- package/dist/op/activities/source-release.js +2 -1
- package/dist/op/activities/source-rollback.d.ts.map +1 -1
- package/dist/op/activities/source-rollback.js +2 -1
- package/dist/op/apply-status.d.ts +84 -0
- package/dist/op/apply-status.d.ts.map +1 -0
- package/dist/op/apply-status.js +106 -0
- package/dist/op/before-merge-decide.d.ts +102 -0
- package/dist/op/before-merge-decide.d.ts.map +1 -0
- package/dist/op/before-merge-decide.js +142 -0
- package/dist/op/before-merge-done.d.ts +56 -0
- package/dist/op/before-merge-done.d.ts.map +1 -0
- package/dist/op/before-merge-done.js +69 -0
- package/dist/op/before-merge-store.d.ts +20 -0
- package/dist/op/before-merge-store.d.ts.map +1 -0
- package/dist/op/before-merge-store.js +48 -0
- package/dist/op/before-merge.d.ts +150 -0
- package/dist/op/before-merge.d.ts.map +1 -0
- package/dist/op/before-merge.js +207 -0
- package/dist/op/follow-on-run.d.ts +117 -0
- package/dist/op/follow-on-run.d.ts.map +1 -0
- package/dist/op/follow-on-run.js +154 -0
- package/dist/op/follow-on-store.d.ts +17 -0
- package/dist/op/follow-on-store.d.ts.map +1 -0
- package/dist/op/follow-on-store.js +54 -0
- package/dist/op/gate.d.ts +6 -0
- package/dist/op/gate.d.ts.map +1 -1
- package/dist/op/gate.js +10 -1
- package/dist/op/index.d.ts +5 -1
- package/dist/op/index.d.ts.map +1 -1
- package/dist/op/index.js +2 -0
- package/dist/op/op-waves-after-plan.d.ts +13 -0
- package/dist/op/op-waves-after-plan.d.ts.map +1 -1
- package/dist/op/op-waves-evidence-jobs.d.ts +10 -2
- package/dist/op/op-waves-evidence-jobs.d.ts.map +1 -1
- package/dist/op/op-waves-evidence-jobs.js +19 -5
- package/dist/op/op-waves-follow-on.d.ts +162 -0
- package/dist/op/op-waves-follow-on.d.ts.map +1 -0
- package/dist/op/op-waves-follow-on.js +355 -0
- package/dist/op/op-waves-render-spec.d.ts +100 -0
- package/dist/op/op-waves-render-spec.d.ts.map +1 -0
- package/dist/op/op-waves-render-spec.js +162 -0
- package/dist/op/op-waves-run.d.ts +148 -6
- package/dist/op/op-waves-run.d.ts.map +1 -1
- package/dist/op/op-waves-run.js +873 -100
- package/dist/op/op-waves-split.d.ts +122 -0
- package/dist/op/op-waves-split.d.ts.map +1 -0
- package/dist/op/op-waves-split.js +166 -0
- package/dist/op/op-waves.d.ts +24 -0
- package/dist/op/op-waves.d.ts.map +1 -1
- package/dist/op/op-waves.js +18 -1
- package/dist/op/schedule-overdue.d.ts +15 -1
- package/dist/op/schedule-overdue.d.ts.map +1 -1
- package/dist/op/schedule-overdue.js +77 -5
- package/dist/op/stage-hooks.d.ts +36 -1
- package/dist/op/stage-hooks.d.ts.map +1 -1
- package/dist/op/stage-hooks.js +17 -3
- package/dist/op/wave-stop.d.ts +67 -0
- package/dist/op/wave-stop.d.ts.map +1 -0
- package/dist/op/wave-stop.js +129 -0
- package/dist/planned-files.d.ts +76 -0
- package/dist/planned-files.d.ts.map +1 -0
- package/dist/planned-files.js +108 -0
- package/dist/pr-forge-job.d.ts +22 -0
- package/dist/pr-forge-job.d.ts.map +1 -0
- package/dist/pr-forge-job.js +46 -0
- package/dist/pr-loop.d.ts +3 -6
- package/dist/pr-loop.d.ts.map +1 -1
- package/dist/pr-loop.js +4 -81
- package/dist/pr-plan-note.d.ts +97 -0
- package/dist/pr-plan-note.d.ts.map +1 -1
- package/dist/pr-plan-note.js +94 -1
- package/dist/pr-post.d.ts +28 -3
- package/dist/pr-post.d.ts.map +1 -1
- package/dist/pr-post.js +146 -13
- package/dist/pr-status.d.ts +16 -0
- package/dist/pr-status.d.ts.map +1 -0
- package/dist/pr-status.js +90 -0
- package/dist/ref-gate-init.d.ts +16 -2
- package/dist/ref-gate-init.d.ts.map +1 -1
- package/dist/ref-gate-init.js +24 -13
- package/dist/release-floors.d.ts +39 -1
- package/dist/release-floors.d.ts.map +1 -1
- package/dist/release-floors.js +63 -25
- package/dist/render-module.d.ts +15 -0
- package/dist/render-module.d.ts.map +1 -0
- package/dist/render-module.js +73 -0
- package/dist/state-migration.d.ts.map +1 -1
- package/dist/state-migration.js +1 -2
- package/dist/wave-blocked.d.ts +7 -1
- package/dist/wave-blocked.d.ts.map +1 -1
- package/dist/wave-blocked.js +7 -2
- package/dist/wave-runtime.mjs +366 -350
- package/dist/workspace/ci-green-cli.d.ts.map +1 -1
- package/dist/workspace/ci-green-cli.js +3 -2
- package/dist/workspace/release-train.d.ts.map +1 -1
- package/dist/workspace/release-train.js +2 -1
- package/dist/workspace/release-workflow.d.ts +4 -3
- package/dist/workspace/release-workflow.d.ts.map +1 -1
- package/dist/workspace/release-workflow.js +10 -7
- package/dist/workspace/trust/check-evidence-report.d.ts +7 -2
- package/dist/workspace/trust/check-evidence-report.d.ts.map +1 -1
- package/dist/workspace/trust/check-evidence-report.js +15 -8
- package/dist/workspace/trust/ref-gate-cli.d.ts +10 -1
- package/dist/workspace/trust/ref-gate-cli.d.ts.map +1 -1
- package/dist/workspace/trust/ref-gate-cli.js +30 -10
- package/dist/workspace/workspace-run.d.ts.map +1 -1
- package/dist/workspace/workspace-run.js +2 -1
- package/package.json +1 -1
- package/src/actor.test.ts +68 -2
- package/src/actor.ts +61 -1
- package/src/chant-install.test.ts +2 -3
- package/src/chant-install.ts +1 -2
- package/src/ci-base.test.ts +41 -0
- package/src/ci-base.ts +43 -0
- package/src/ci-comment-commands.test.ts +439 -0
- package/src/ci-comment-commands.ts +428 -0
- package/src/ci-comment-replies.ts +78 -0
- package/src/ci-commit.test.ts +2 -3
- package/src/ci-evidence-from-job.test.ts +18 -0
- package/src/ci-evidence-from-job.ts +58 -2
- package/src/ci-evidence-jobs.ts +50 -5
- package/src/ci-image.test.ts +130 -10
- package/src/ci-image.ts +85 -12
- package/src/ci-job-guard.before-merge.test.ts +148 -0
- package/src/ci-job-guard.follow-on-record.test.ts +137 -0
- package/src/ci-job-guard.follow-on.test.ts +144 -0
- package/src/ci-job-guard.ts +221 -3
- package/src/ci-note-commands.test.ts +76 -1
- package/src/ci-note-commands.ts +198 -46
- package/src/ci-product-words.ts +59 -0
- package/src/ci-product.ts +90 -6
- package/src/cli/commands/build.test.ts +41 -0
- package/src/cli/commands/build.ts +27 -2
- package/src/cli/handlers/approve.ts +2 -1
- package/src/cli/handlers/ci-check.ts +19 -7
- package/src/cli/handlers/ci-evidence.ts +29 -8
- package/src/cli/handlers/components.ts +3 -1
- package/src/cli/handlers/generated-check.ts +31 -1
- package/src/cli/handlers/lock-reach.test.ts +103 -0
- package/src/cli/handlers/lock.ts +100 -4
- package/src/cli/handlers/pr-comment.ts +187 -0
- package/src/cli/handlers/pr-env.ts +6 -3
- package/src/cli/handlers/pr-notes.ts +30 -6
- package/src/cli/handlers/pr-record.test.ts +1 -1
- package/src/cli/handlers/pr.ts +64 -21
- package/src/cli/handlers/promote.ts +2 -1
- package/src/cli/handlers/release.e2e.test.ts +35 -0
- package/src/cli/handlers/release.ts +14 -2
- package/src/cli/handlers/run-wave.ts +170 -4
- package/src/cli/handlers/run.ts +2 -1
- package/src/cli/main.ts +41 -2
- package/src/cli/parse-args.ts +23 -0
- package/src/cli/registry.ts +19 -1
- package/src/components/auto-release.ts +2 -1
- package/src/components/pr-checks.ts +165 -17
- package/src/components/pr-pipeline.ts +22 -18
- package/src/components/product-pipeline.apply-status.test.ts +50 -0
- package/src/components/product-pipeline.ts +204 -17
- package/src/components/product-plan.test.ts +60 -4
- package/src/components/product-plan.ts +367 -50
- package/src/drift-record.test.ts +20 -0
- package/src/drift-record.ts +16 -0
- package/src/floor-table.data.ts +63 -31
- package/src/forge-check/contract.ts +12 -1
- package/src/forge-check/forge-check.test.ts +17 -0
- package/src/forge-check/index.ts +2 -0
- package/src/gate-resume-run.ts +27 -3
- package/src/generated-check.e2e.test.ts +21 -1
- package/src/generated-check.test.ts +66 -0
- package/src/generated-check.ts +51 -10
- package/src/image-pins.ts +31 -0
- package/src/lexicon.ts +89 -1
- package/src/lifecycle/gate-applied.ts +7 -0
- package/src/lifecycle/git.test.ts +48 -0
- package/src/lifecycle/git.ts +27 -4
- package/src/lifecycle/publish-npm.ts +31 -1
- package/src/lifecycle/reach-locks.test.ts +87 -0
- package/src/lifecycle/reach-locks.ts +169 -0
- package/src/lifecycle/release-cut.ts +17 -1
- package/src/lifecycle/release-images.test.ts +56 -0
- package/src/lifecycle/release-images.ts +1 -2
- package/src/notify-product.ts +19 -8
- package/src/op/activities/source-release.ts +2 -1
- package/src/op/activities/source-rollback.ts +2 -1
- package/src/op/apply-status.test.ts +83 -0
- package/src/op/apply-status.ts +132 -0
- package/src/op/before-merge-decide.ts +190 -0
- package/src/op/before-merge-done.ts +99 -0
- package/src/op/before-merge-store.ts +44 -0
- package/src/op/before-merge.test.ts +201 -0
- package/src/op/before-merge.ts +266 -0
- package/src/op/follow-on-run.ts +206 -0
- package/src/op/follow-on-store.ts +54 -0
- package/src/op/gate-resume.test.ts +27 -0
- package/src/op/gate.ts +16 -1
- package/src/op/index.ts +15 -0
- package/src/op/op-waves-after-plan.ts +13 -0
- package/src/op/op-waves-evidence-jobs.ts +21 -7
- package/src/op/op-waves-follow-on-record.test.ts +152 -0
- package/src/op/op-waves-follow-on.test.ts +247 -0
- package/src/op/op-waves-follow-on.ts +385 -0
- package/src/op/op-waves-notify-words.test.ts +18 -0
- package/src/op/op-waves-render-spec.test.ts +159 -0
- package/src/op/op-waves-render-spec.ts +171 -0
- package/src/op/op-waves-run.ts +973 -94
- package/src/op/op-waves-split-product.test.ts +288 -0
- package/src/op/op-waves-split-step.test.ts +298 -0
- package/src/op/op-waves-split.test.ts +196 -0
- package/src/op/op-waves-split.ts +189 -0
- package/src/op/op-waves.ts +31 -3
- package/src/op/schedule-overdue.test.ts +72 -1
- package/src/op/schedule-overdue.ts +84 -6
- package/src/op/stage-hooks.ts +52 -4
- package/src/op/wave-stop.test.ts +72 -0
- package/src/op/wave-stop.ts +139 -0
- package/src/planned-files.test.ts +80 -0
- package/src/planned-files.ts +134 -0
- package/src/pr-forge-job.test.ts +53 -0
- package/src/pr-forge-job.ts +46 -0
- package/src/pr-loop-narrowed.test.ts +2 -1
- package/src/pr-loop-words.test.ts +2 -1
- package/src/pr-loop.test.ts +1 -2
- package/src/pr-loop.ts +4 -80
- package/src/pr-plan-note.ts +155 -3
- package/src/pr-post-replan.test.ts +144 -0
- package/src/pr-post-subject.test.ts +230 -0
- package/src/pr-post.test.ts +2 -1
- package/src/pr-post.ts +151 -15
- package/src/pr-status.ts +91 -0
- package/src/ref-gate-init.ts +30 -11
- package/src/release-floors.ts +81 -25
- package/src/render-module.ts +73 -0
- package/src/state-migration-record.test.ts +2 -3
- package/src/state-migration.ts +1 -2
- package/src/wave-blocked.ts +9 -4
- package/src/workspace/ci-green-cli.ts +3 -2
- package/src/workspace/ci-green-workflow.test.ts +32 -1
- package/src/workspace/release-train.ts +2 -1
- package/src/workspace/release-workflow.test.ts +36 -5
- package/src/workspace/release-workflow.ts +10 -7
- package/src/workspace/trust/check-evidence-report.ts +15 -8
- package/src/workspace/trust/check-evidence.test.ts +5 -0
- package/src/workspace/trust/ref-gate-cli.ts +30 -8
- package/src/workspace/trust/ref-gate-pieces.test.ts +46 -1
- package/src/workspace/trust/ref-gate.test.ts +10 -0
- package/src/workspace/workspace-run.ts +2 -1
package/src/ci-base.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@intentius/chant/ci-base` (#4966): the base a CI job measures a change
|
|
3
|
+
* from, read off the job's own variables, so a product's check and policy
|
|
4
|
+
* steps need no rule of their own for it (terragucci's `policyBase`).
|
|
5
|
+
*
|
|
6
|
+
* - A pull request's job: its target branch, `origin/<target>`
|
|
7
|
+
* (`GITHUB_BASE_REF` on GitHub and Forgejo, GitLab's
|
|
8
|
+
* `CI_MERGE_REQUEST_TARGET_BRANCH_NAME`).
|
|
9
|
+
* - A push to a branch other than the default branch: `origin/<default>`,
|
|
10
|
+
* so a change that edits a check or a policy on a side branch is still
|
|
11
|
+
* judged by the default branch's.
|
|
12
|
+
* - A push to the default branch, or a job with no branch: no base, and
|
|
13
|
+
* the checkout's own files are the trusted ones.
|
|
14
|
+
*
|
|
15
|
+
* `chant ci check` takes it as its `--base` when none is given.
|
|
16
|
+
*
|
|
17
|
+
* This module imports nothing.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
export interface CiBaseOptions {
|
|
21
|
+
/** A base the caller already has (a flag, a product's own variable); it wins over everything. */
|
|
22
|
+
base?: string;
|
|
23
|
+
/** The default branch. Default GitLab's `CI_DEFAULT_BRANCH`; GitHub and Forgejo jobs carry none, so a product passes its own. */
|
|
24
|
+
defaultBranch?: string;
|
|
25
|
+
/** The remote the branches are fetched from. Default `origin`. */
|
|
26
|
+
remote?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const set = (v: string | undefined): string | undefined => (v && v.trim() ? v.trim() : undefined);
|
|
30
|
+
|
|
31
|
+
/** The base ref for the job `env` describes, as the module comment says; undefined when there is none. */
|
|
32
|
+
export function ciBaseRef(env: Record<string, string | undefined> = process.env, options: CiBaseOptions = {}): string | undefined {
|
|
33
|
+
const given = set(options.base);
|
|
34
|
+
if (given) return given;
|
|
35
|
+
const remote = options.remote ?? "origin";
|
|
36
|
+
const target = set(env.GITHUB_BASE_REF) ?? set(env.CI_MERGE_REQUEST_TARGET_BRANCH_NAME);
|
|
37
|
+
if (target) return `${remote}/${target}`;
|
|
38
|
+
const branch = set(env.GITHUB_REF_NAME) ?? set(env.CI_COMMIT_BRANCH);
|
|
39
|
+
const main = set(options.defaultBranch) ?? set(env.CI_DEFAULT_BRANCH);
|
|
40
|
+
return branch && main && branch !== main ? `${remote}/${main}` : undefined;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { CI_BASE_REF_FLOOR } from "./release-floors";
|
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The comment job on GitHub and Forgejo (#4946): every `/<product>` comment
|
|
3
|
+
* no other job takes gets a reply, a merged pull request's apply runs again,
|
|
4
|
+
* and the words' replies and alias refusals reach both forges.
|
|
5
|
+
*/
|
|
6
|
+
import { describe, expect, test } from "vitest";
|
|
7
|
+
import { answerProductComment, commentRuns, RERUN_APPLY_JOBS, type CommentJobs, type AnswerCommentOptions } from "./ci-comment-commands";
|
|
8
|
+
import { chantNoteRuns, type NoteCommand } from "./ci-note-commands";
|
|
9
|
+
import { assertProductWords, productWordsProblems, resolveProductWords, type CiProductWordsInput } from "./ci-product-words";
|
|
10
|
+
import { commentJobsFromEnv } from "./cli/handlers/pr-comment";
|
|
11
|
+
import type { ForgeReads, PullRequestDetail, RunJob, WorkflowRun } from "./pr-forge-reads";
|
|
12
|
+
|
|
13
|
+
const MERGE = "a".repeat(40);
|
|
14
|
+
const LATER = "b".repeat(40);
|
|
15
|
+
|
|
16
|
+
/** terragucci's words, as its comment.ts reads them: the atlantis aliases, and its own sentences. */
|
|
17
|
+
const tgInput: CiProductWordsInput = {
|
|
18
|
+
product: "terragucci",
|
|
19
|
+
noun: ["root", "roots"],
|
|
20
|
+
commands: { plan: "plan", apply: "apply", lock: "lock", unlock: "unlock", action: "action", agent: "agent", fmt: "commit" },
|
|
21
|
+
aliases: [
|
|
22
|
+
{ from: "atlantis plan", command: "plan", when: "TG_ATLANTIS_COMMENTS", refuse: { "-p": "a root goes by its path, not a project name: write `atlantis plan -d <dir>`", "-w": "`-w` picks a workspace, and terragucci has none" } },
|
|
23
|
+
{ from: "atlantis apply", command: "apply", when: "TG_ATLANTIS_COMMENTS", refuse: { "-d": "`atlantis apply -d` applies one root, and terragucci does not" } },
|
|
24
|
+
],
|
|
25
|
+
replies: {
|
|
26
|
+
apply: "this pipeline does not apply on a comment: re-run the apply job on the forge, or push to the default branch again",
|
|
27
|
+
lock: "this repository applies after merge, so pull requests take no locks",
|
|
28
|
+
unlock: "this repository applies after merge, so no pull request holds a lock and there is nothing to unlock",
|
|
29
|
+
agent: "the agent command is off in this repository; `agent.comment` in terragucci.yml turns it on",
|
|
30
|
+
action: "this pipeline has no action workflow; run `terragucci init` again to write it",
|
|
31
|
+
fork: "a pull request from a fork is not re-planned: its code never runs with this repository's credentials",
|
|
32
|
+
member: "{member} is not a root of this repository. The roots are {members}.",
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
const tg = assertProductWords(tgInput);
|
|
36
|
+
|
|
37
|
+
interface World {
|
|
38
|
+
permission?: string;
|
|
39
|
+
pr?: Partial<PullRequestDetail>;
|
|
40
|
+
runs?: WorkflowRun[];
|
|
41
|
+
jobs?: Record<number, RunJob[]>;
|
|
42
|
+
branch?: WorkflowRun[];
|
|
43
|
+
statuses?: Record<string, Array<{ context: string; targetUrl?: string }>>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const run = (id: number, sha: string, o: Partial<WorkflowRun> = {}): WorkflowRun => ({ id, event: "push", headSha: sha, status: "completed", conclusion: "failure", done: true, pullRequests: [], workflow: "terragucci-apply.yml", url: `https://github.com/acme/infra/actions/runs/${id}`, ...o });
|
|
47
|
+
|
|
48
|
+
function setup(w: World, jobs: CommentJobs, body: string, o: { forge?: "github" | "forgejo"; event?: Record<string, unknown>; env?: Record<string, string> } = {}) {
|
|
49
|
+
const posted: string[] = [];
|
|
50
|
+
const reran: number[] = [];
|
|
51
|
+
const dispatched: Array<[string, string]> = [];
|
|
52
|
+
const reads = {
|
|
53
|
+
kind: o.forge ?? "github",
|
|
54
|
+
permission: async () => w.permission ?? "write",
|
|
55
|
+
pullRequest: async (n: number) => ({ number: n, title: "", body: "", state: "merged", head: "feature", headSha: "c".repeat(40), base: "main", sameRepo: true, mergeCommit: MERGE, ...w.pr }) as PullRequestDetail,
|
|
56
|
+
headRuns: async (sha: string) => (w.runs ?? []).filter((r) => r.headSha === sha),
|
|
57
|
+
runJobs: async (id: number) => w.jobs?.[id] ?? [],
|
|
58
|
+
branchRuns: async () => w.branch ?? [],
|
|
59
|
+
} as unknown as ForgeReads;
|
|
60
|
+
const opts: AnswerCommentOptions = {
|
|
61
|
+
forge: o.forge ?? "github",
|
|
62
|
+
event: {
|
|
63
|
+
action: "created",
|
|
64
|
+
comment: { id: 7, body, user: { login: "alice" } },
|
|
65
|
+
issue: { number: 12, pull_request: {} },
|
|
66
|
+
repository: { full_name: "acme/infra", default_branch: "main", permissions: { push: true } },
|
|
67
|
+
sender: { login: "alice" },
|
|
68
|
+
...o.event,
|
|
69
|
+
},
|
|
70
|
+
repo: "acme/infra",
|
|
71
|
+
reads,
|
|
72
|
+
poster: {
|
|
73
|
+
addComment: async (_n: number, text: string) => {
|
|
74
|
+
posted.push(text);
|
|
75
|
+
return { id: 1 } as never;
|
|
76
|
+
},
|
|
77
|
+
commitStatuses: async (sha: string) => (w.statuses?.[sha] ?? []) as never,
|
|
78
|
+
},
|
|
79
|
+
runs: { rerunFailed: async (id) => (reran.push(id), {}), dispatch: async (wf, ref) => (dispatched.push([wf, ref]), {}) },
|
|
80
|
+
words: tg,
|
|
81
|
+
base: "main",
|
|
82
|
+
jobs,
|
|
83
|
+
...(o.env ? { env: o.env } : {}),
|
|
84
|
+
};
|
|
85
|
+
return { opts, posted, reran, dispatched };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
describe("the comment job replies to what no other job takes (#4946)", () => {
|
|
89
|
+
test("a comment the grammar refuses gets the grammar's reason", async () => {
|
|
90
|
+
const s = setup({}, { preview: true }, "/terragucci frob");
|
|
91
|
+
const got = await answerProductComment(s.opts);
|
|
92
|
+
expect(got.replied).toBe(true);
|
|
93
|
+
expect(s.posted).toEqual([expect.stringMatching(/^terragucci: the commands are `\/terragucci plan`/)]);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test("a command another job answers is left to it, and a commit word to the commit job", async () => {
|
|
97
|
+
for (const body of ["/terragucci plan", "/terragucci plan envs/dev", "/terragucci lock", "/terragucci fmt", "/terragucci fmt x y"]) {
|
|
98
|
+
const s = setup({}, { preview: true, locks: true, commits: true }, body);
|
|
99
|
+
const got = await answerProductComment(s.opts);
|
|
100
|
+
expect(got.replied, body).toBe(false);
|
|
101
|
+
expect(s.posted, body).toEqual([]);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test("a command the pipeline runs no job for gets the product's sentence", async () => {
|
|
106
|
+
const cases: Array<[string, string]> = [
|
|
107
|
+
["/terragucci apply", tgInput.replies!.apply!],
|
|
108
|
+
["/terragucci lock", tgInput.replies!.lock!],
|
|
109
|
+
["/terragucci unlock", tgInput.replies!.unlock!],
|
|
110
|
+
["/terragucci agent fix the tags", tgInput.replies!.agent!],
|
|
111
|
+
["/terragucci action envs/dev action.aws_lambda_invoke.rotate", tgInput.replies!.action!],
|
|
112
|
+
];
|
|
113
|
+
for (const [body, text] of cases) {
|
|
114
|
+
const s = setup({}, { preview: true }, body);
|
|
115
|
+
await answerProductComment(s.opts);
|
|
116
|
+
expect(s.posted, body).toEqual([`terragucci: ${text}`]);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test("chant's own sentences, in a repository's words, when the product gives none", async () => {
|
|
121
|
+
const s = setup({}, {}, "/plywood up");
|
|
122
|
+
s.opts.words = resolveProductWords({ product: "plywood", commands: { preview: "plan", up: "apply" }, verbs: { plan: ["preview", "previewed"], apply: ["update", "updated"] } });
|
|
123
|
+
await answerProductComment(s.opts);
|
|
124
|
+
expect(s.posted).toEqual(["plywood: this repository does not update on a comment: re-run the update job on the forge, or push to the default branch again"]);
|
|
125
|
+
const p = setup({}, {}, "/plywood preview");
|
|
126
|
+
p.opts.words = s.opts.words;
|
|
127
|
+
await answerProductComment(p.opts);
|
|
128
|
+
expect(p.posted).toEqual(["plywood: this repository previews a pull request on each push to it, and no job previews on a comment"]);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test("an alias's flag the product has no counterpart for is refused with the product's reason, only where the alias is on", async () => {
|
|
132
|
+
const on = { TG_ATLANTIS_COMMENTS: "1" };
|
|
133
|
+
const p = setup({}, { preview: true }, "atlantis plan -p orders", { env: on });
|
|
134
|
+
await answerProductComment(p.opts);
|
|
135
|
+
expect(p.posted).toEqual(["terragucci: a root goes by its path, not a project name: write `atlantis plan -d <dir>`"]);
|
|
136
|
+
const a = setup({}, { preview: true }, "atlantis apply -d envs/dev", { env: on });
|
|
137
|
+
await answerProductComment(a.opts);
|
|
138
|
+
expect(a.posted).toEqual(["terragucci: `atlantis apply -d` applies one root, and terragucci does not"]);
|
|
139
|
+
const off = setup({}, { preview: true }, "atlantis plan -p orders");
|
|
140
|
+
expect((await answerProductComment(off.opts)).replied).toBe(false);
|
|
141
|
+
// The alias's -d still names the root where it is not refused.
|
|
142
|
+
const d = setup({}, { preview: true }, "atlantis plan -d envs/dev", { env: on });
|
|
143
|
+
expect((await answerProductComment(d.opts)).reason).toBe("another job answers this comment");
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test("someone without write access gets no reply, on GitHub from the forge and on Forgejo from the event", async () => {
|
|
147
|
+
const gh = setup({ permission: "read" }, {}, "/terragucci frob");
|
|
148
|
+
expect((await answerProductComment(gh.opts)).replied).toBe(false);
|
|
149
|
+
expect(gh.posted).toEqual([]);
|
|
150
|
+
const fj = setup({}, {}, "/terragucci frob", { forge: "forgejo", event: { repository: { full_name: "acme/infra", permissions: { push: false, admin: false } } } });
|
|
151
|
+
expect((await answerProductComment(fj.opts)).replied).toBe(false);
|
|
152
|
+
const other = setup({}, {}, "/terragucci frob", { forge: "forgejo", event: { sender: { login: "mallory" } } });
|
|
153
|
+
expect((await answerProductComment(other.opts)).replied).toBe(false);
|
|
154
|
+
const fine = setup({}, {}, "/terragucci frob", { forge: "forgejo" });
|
|
155
|
+
expect((await answerProductComment(fine.opts)).replied).toBe(true);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
test("a plan the product plan's re-plan skips without a word gets the reason: a target that is none of its own, a fork's with forks: skip", async () => {
|
|
159
|
+
const jobs: CommentJobs = { preview: true, targets: ["staging", "prod"], skipForks: true };
|
|
160
|
+
const qa = setup({}, jobs, "/terragucci plan qa");
|
|
161
|
+
await answerProductComment(qa.opts);
|
|
162
|
+
expect(qa.posted).toEqual(["terragucci: qa is not a root of this repository. The roots are `prod`, `staging`."]);
|
|
163
|
+
const fork = setup({ pr: { state: "open", sameRepo: false } }, jobs, "/terragucci plan");
|
|
164
|
+
await answerProductComment(fork.opts);
|
|
165
|
+
expect(fork.posted).toEqual([`terragucci: ${tgInput.replies!.fork}`]);
|
|
166
|
+
const fine = setup({ pr: { state: "open" } }, jobs, "/terragucci plan prod");
|
|
167
|
+
expect((await answerProductComment(fine.opts)).replied).toBe(false);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
test("a comment not addressed to the product, or not on a pull request, gets nothing", async () => {
|
|
171
|
+
expect((await answerProductComment(setup({}, {}, "looks good").opts)).replied).toBe(false);
|
|
172
|
+
expect((await answerProductComment(setup({}, {}, "/terragucci frob", { event: { issue: { number: 12 } } }).opts)).replied).toBe(false);
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
describe("a merged pull request's apply runs again (#4946)", () => {
|
|
177
|
+
const waves = { 10: [{ id: 1, name: "wave-1-network", status: "completed", conclusion: "success", done: true }, { id: 2, name: "wave-2-apps", status: "completed", conclusion: "failure", done: true }] } as Record<number, RunJob[]>;
|
|
178
|
+
|
|
179
|
+
test("on GitHub the failed jobs of the push run at the merge commit run again", async () => {
|
|
180
|
+
const s = setup({ runs: [run(10, MERGE)], jobs: waves, branch: [run(10, MERGE)] }, { applyOnMerge: true }, "/terragucci apply");
|
|
181
|
+
const got = await answerProductComment(s.opts);
|
|
182
|
+
expect(s.reran).toEqual([10]);
|
|
183
|
+
expect(got.ran).toBe(true);
|
|
184
|
+
expect(s.posted[0]).toBe("terragucci: started the failed jobs of workflow run 10 (https://github.com/acme/infra/actions/runs/10) at pull request 12's merge commit aaaaaaaa again for alice; each wave's gate decides again, and the waves after it follow, each behind its own gate");
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
test("a later apply on the default branch refuses it, and names that run", async () => {
|
|
188
|
+
const s = setup({ runs: [run(10, MERGE)], jobs: waves, branch: [run(11, LATER), run(10, MERGE)], statuses: { [LATER]: [{ context: "terragucci/apply", targetUrl: "https://github.com/acme/infra/actions/runs/11" }] } }, { applyOnMerge: true }, "/terragucci apply");
|
|
189
|
+
await answerProductComment(s.opts);
|
|
190
|
+
expect(s.reran).toEqual([]);
|
|
191
|
+
expect(s.posted[0]).toBe("terragucci: a later apply already ran on main at bbbbbbbb (https://github.com/acme/infra/actions/runs/11), so the merge commit aaaaaaaa of pull request 12 is not applied: comment on the pull request that commit came from, or push again");
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
test("an open, closed, forked or wave-n apply is refused by name, and a run that succeeded is left alone", async () => {
|
|
195
|
+
const replies = async (w: World, body = "/terragucci apply"): Promise<string> => {
|
|
196
|
+
const s = setup({ runs: [run(10, MERGE)], jobs: waves, ...w }, { applyOnMerge: true }, body);
|
|
197
|
+
await answerProductComment(s.opts);
|
|
198
|
+
expect(s.reran).toEqual([]);
|
|
199
|
+
return s.posted[0]!;
|
|
200
|
+
};
|
|
201
|
+
expect(await replies({ pr: { state: "open" } })).toMatch(/^terragucci: pull request 12 is not merged: `\/terragucci apply` runs the apply of a merged pull request again/);
|
|
202
|
+
expect(await replies({ pr: { state: "closed" } })).toBe("terragucci: pull request 12 was closed without merging, so there is nothing of it to apply");
|
|
203
|
+
expect(await replies({ pr: { sameRepo: false } })).toBe(`terragucci: ${tgInput.replies!.fork}`);
|
|
204
|
+
expect(await replies({}, "/terragucci apply wave-2")).toMatch(/cannot stop them; write `\/terragucci apply`/);
|
|
205
|
+
expect(await replies({ pr: { base: "release" } })).toBe("terragucci: pull request 12 was merged into release, not the default branch main, so nothing applied from it");
|
|
206
|
+
expect(await replies({ jobs: { 10: [{ id: 1, name: "wave-1-network", status: "completed", conclusion: "success", done: true }] } })).toBe("terragucci: every apply job of pull request 12's merge commit aaaaaaaa already succeeded");
|
|
207
|
+
expect(await replies({ runs: [run(10, MERGE, { done: false, status: "in_progress" })] })).toBe("terragucci: workflow run 10 at aaaaaaaa is in_progress already, so it is not started again");
|
|
208
|
+
expect(await replies({ runs: [] })).toBe("terragucci: no workflow run at the merge commit aaaaaaaa of pull request 12 has an apply job, so there is nothing to run again; push to main again");
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
test("on Forgejo the waves workflow is dispatched on the default branch, only while the merge commit is its newest push", async () => {
|
|
212
|
+
const head = setup({ runs: [run(10, MERGE)], jobs: waves, branch: [run(10, MERGE)] }, { applyOnMerge: true }, "/terragucci apply", { forge: "forgejo" });
|
|
213
|
+
await answerProductComment(head.opts);
|
|
214
|
+
expect(head.dispatched).toEqual([["terragucci-apply.yml", "main"]]);
|
|
215
|
+
const moved = setup({ runs: [run(10, MERGE)], jobs: waves, branch: [run(11, LATER), run(10, MERGE)] }, { applyOnMerge: true }, "/terragucci apply", { forge: "forgejo" });
|
|
216
|
+
await answerProductComment(moved.opts);
|
|
217
|
+
expect(moved.dispatched).toEqual([]);
|
|
218
|
+
expect(moved.posted[0]).toBe("terragucci: Forgejo starts a workflow again only at the head of main, which is now bbbbbbbb, so the merge commit aaaaaaaa of pull request 12 is not applied again: push to main again");
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
test("the apply before merge answers an open pull request's apply comment", async () => {
|
|
222
|
+
const s = setup({ pr: { state: "open" } }, { applyBeforeMerge: true }, "/terragucci apply");
|
|
223
|
+
expect((await answerProductComment(s.opts)).replied).toBe(false);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
test("the apply jobs a re-run looks for are op waves' and the pull request loop's", () => {
|
|
227
|
+
for (const name of ["wave-1-network", "wave-2-apps-share-1", "wave-3-db-decide", "apply", "apply-wave-2", "orders-apply-wave-1-share-2"]) expect(RERUN_APPLY_JOBS.test(name), name).toBe(true);
|
|
228
|
+
for (const name of ["plan", "plan-note", "comment", "wave-x"]) expect(RERUN_APPLY_JOBS.test(name), name).toBe(false);
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
test("the writes call GitHub's re-run and Forgejo's dispatch", async () => {
|
|
232
|
+
const calls: Array<[string, string]> = [];
|
|
233
|
+
const runs = commentRuns({ apiBase: "https://api.github.com/", repo: "acme/infra", token: "t", fetch: (async (url: string, init: { body: string }) => (calls.push([url, init.body]), { ok: true, status: 204, text: async () => "" })) as never });
|
|
234
|
+
await runs.rerunFailed(10);
|
|
235
|
+
await runs.dispatch("terragucci-apply.yml", "main");
|
|
236
|
+
expect(calls).toEqual([
|
|
237
|
+
["https://api.github.com/repos/acme/infra/actions/runs/10/rerun-failed-jobs", "{}"],
|
|
238
|
+
["https://api.github.com/repos/acme/infra/actions/workflows/terragucci-apply.yml/dispatches", '{"ref":"main"}'],
|
|
239
|
+
]);
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
describe("the GitLab note poll takes the same replies (#4946)", () => {
|
|
244
|
+
const mr = (o: Partial<PullRequestDetail> = {}): PullRequestDetail => ({ number: 3, title: "", body: "", state: "open", head: "feature", base: "main", sameRepo: true, ...o });
|
|
245
|
+
const ask = (body: string, m = mr()): Omit<NoteCommand, "parsed"> => ({ mr: m, note: { id: 41, body, system: false }, role: "developer", base: "main", words: tg });
|
|
246
|
+
|
|
247
|
+
test("a root outside the pipeline's is refused before anything starts, and a fork gets the product's sentence", async () => {
|
|
248
|
+
const runs = chantNoteRuns({ preview: true, members: ["envs/dev", "envs/prod"] });
|
|
249
|
+
expect(await runs({ ...ask("/terragucci plan envs/qa"), parsed: { kind: "plan", member: "envs/qa" } })).toEqual({ kind: "reply", text: "envs/qa is not a root of this repository. The roots are `envs/dev`, `envs/prod`." });
|
|
250
|
+
expect((await runs({ ...ask("/terragucci plan envs/dev"), parsed: { kind: "plan", member: "envs/dev" } })).kind).toBe("pipeline");
|
|
251
|
+
expect(await runs({ ...ask("/terragucci plan", mr({ sameRepo: false })), parsed: { kind: "plan" } })).toEqual({ kind: "reply", text: tgInput.replies!.fork });
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
test("a command with no job gets the product's sentence, and chant's GitLab sentences stay without one", async () => {
|
|
255
|
+
const runs = chantNoteRuns({});
|
|
256
|
+
expect(await runs({ ...ask("/terragucci lock"), parsed: { kind: "lock" } })).toEqual({ kind: "reply", text: tgInput.replies!.lock });
|
|
257
|
+
expect(await runs({ ...ask("/terragucci apply"), parsed: { kind: "apply" } })).toEqual({ kind: "reply", text: tgInput.replies!.apply });
|
|
258
|
+
const plain = resolveProductWords({ product: "plywood", commands: { preview: "plan", up: "apply", lock: "lock" } });
|
|
259
|
+
expect(await runs({ ...ask("/plywood lock"), words: plain, parsed: { kind: "lock" } })).toEqual({ kind: "reply", text: "`/plywood lock` does not run here: this project takes no locks" });
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
describe("the words' replies and alias refusals are checked (#4946)", () => {
|
|
264
|
+
test("a reply is one line, names only its own placeholders, and fills a known slot", () => {
|
|
265
|
+
const problems = productWordsProblems(resolveProductWords({ ...tgInput, replies: { apply: "two\nlines", lock: "no {member} here", member: "{member} of {roots}", nope: "x" } as never }));
|
|
266
|
+
expect(problems).toEqual(expect.arrayContaining([
|
|
267
|
+
"replies.apply is one line of text",
|
|
268
|
+
"replies.lock names {member}, which chant does not fill",
|
|
269
|
+
"replies.member names {roots}, which chant does not fill",
|
|
270
|
+
expect.stringMatching(/^replies\.nope is not one of plan, apply/),
|
|
271
|
+
]));
|
|
272
|
+
expect(productWordsProblems(tg)).toEqual([]);
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
test("a refused flag is a flag, with a one-line reply", () => {
|
|
276
|
+
const problems = productWordsProblems(resolveProductWords({ ...tgInput, aliases: [{ from: "atlantis plan", command: "plan", refuse: { "p": "x", "-w": "" } }] }));
|
|
277
|
+
expect(problems).toEqual(expect.arrayContaining([expect.stringMatching(/refuses "p", and a flag is/), "the alias \"atlantis plan\" refuses -w with no one-line reply"]));
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
test("the comment job reads its jobs from CHANT_COMMENT_JOBS and refuses anything else", () => {
|
|
281
|
+
expect(commentJobsFromEnv('{"preview":true,"locks":false}')).toEqual({ preview: true });
|
|
282
|
+
expect(commentJobsFromEnv('{"targets":["staging","prod"],"skipForks":true}')).toEqual({ targets: ["staging", "prod"], skipForks: true });
|
|
283
|
+
expect(() => commentJobsFromEnv('{"targets":["a b"]}')).toThrow(/list of target names/);
|
|
284
|
+
expect(commentJobsFromEnv(undefined)).toEqual({});
|
|
285
|
+
expect(() => commentJobsFromEnv('{"everything":true}')).toThrow(/not one of/);
|
|
286
|
+
expect(() => commentJobsFromEnv('{"locks":"yes"}')).toThrow(/true or false/);
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
describe("a wave stop on a re-run, and a re-plan comment with flags (#4979)", () => {
|
|
291
|
+
const waves = { 10: [{ id: 1, name: "wave-1-network", status: "completed", conclusion: "failure", done: true }, { id: 2, name: "wave-2-apps", status: "completed", conclusion: "skipped", done: true }, { id: 3, name: "wave-3-edge", status: "completed", conclusion: "skipped", done: true }] } as Record<number, RunJob[]>;
|
|
292
|
+
const jobs: CommentJobs = { applyOnMerge: true, waves: { op: "tf-apply", count: 3 } };
|
|
293
|
+
const withStops = (s: ReturnType<typeof setup>) => {
|
|
294
|
+
const stops: Array<[string, string, unknown]> = [];
|
|
295
|
+
s.opts.stops = async (op, sha, stop) => {
|
|
296
|
+
stops.push([op, sha, stop]);
|
|
297
|
+
};
|
|
298
|
+
s.opts.now = () => "2026-11-10T00:00:00.000Z";
|
|
299
|
+
return stops;
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
test("wave-n writes the stop for the merge commit before the run starts, and the reply says the waves after it wait", async () => {
|
|
303
|
+
const s = setup({ runs: [run(10, MERGE)], jobs: waves, branch: [run(10, MERGE)] }, jobs, "/terragucci apply wave-2");
|
|
304
|
+
const stops = withStops(s);
|
|
305
|
+
const got = await answerProductComment(s.opts);
|
|
306
|
+
expect(stops).toEqual([["tf-apply", MERGE, { through: 2, at: "2026-11-10T00:00:00.000Z", by: "alice", pr: 12 }]]);
|
|
307
|
+
expect(s.reran).toEqual([10]);
|
|
308
|
+
expect(got.ran).toBe(true);
|
|
309
|
+
expect(s.posted[0]).toMatch(/again for alice; .*; it stops after `wave-2`, and the waves after it wait until `\/terragucci apply` runs it again$/);
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
test("an apply without a wave clears the stop, and the last wave stops nothing after it", async () => {
|
|
313
|
+
const plain = setup({ runs: [run(10, MERGE)], jobs: waves, branch: [run(10, MERGE)] }, jobs, "/terragucci apply");
|
|
314
|
+
const cleared = withStops(plain);
|
|
315
|
+
await answerProductComment(plain.opts);
|
|
316
|
+
expect(cleared).toEqual([["tf-apply", MERGE, null]]);
|
|
317
|
+
expect(plain.posted[0]).not.toMatch(/stops after/);
|
|
318
|
+
const last = setup({ runs: [run(10, MERGE)], jobs: waves, branch: [run(10, MERGE)] }, jobs, "/terragucci apply wave-3");
|
|
319
|
+
withStops(last);
|
|
320
|
+
await answerProductComment(last.opts);
|
|
321
|
+
expect(last.posted[0]).not.toMatch(/stops after/);
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
test("a wave the waves do not have is refused, and no run starts or stop is written", async () => {
|
|
325
|
+
const s = setup({ runs: [run(10, MERGE)], jobs: waves, branch: [run(10, MERGE)] }, jobs, "/terragucci apply wave-4");
|
|
326
|
+
const stops = withStops(s);
|
|
327
|
+
await answerProductComment(s.opts);
|
|
328
|
+
expect(s.posted[0]).toBe("terragucci: the apply of this repository runs in 3 waves, so there is no `wave-4`");
|
|
329
|
+
expect(stops).toEqual([]);
|
|
330
|
+
expect(s.reran).toEqual([]);
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
test("a stop that cannot be written fails the job, and nothing is started", async () => {
|
|
334
|
+
const s = setup({ runs: [run(10, MERGE)], jobs: waves, branch: [run(10, MERGE)] }, jobs, "/terragucci apply wave-1");
|
|
335
|
+
s.opts.stops = async () => {
|
|
336
|
+
throw new Error("push refused");
|
|
337
|
+
};
|
|
338
|
+
const got = await answerProductComment(s.opts);
|
|
339
|
+
expect(got.fail).toBe(true);
|
|
340
|
+
expect(got.reason).toMatch(/could not write the wave stop for aaaaaaaa, so nothing was started \(push refused\)/);
|
|
341
|
+
expect(s.reran).toEqual([]);
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
test("on Forgejo the dispatch carries the stop the same way", async () => {
|
|
345
|
+
const s = setup({ runs: [run(10, MERGE)], jobs: waves, branch: [run(10, MERGE)] }, jobs, "/terragucci apply wave-1", { forge: "forgejo" });
|
|
346
|
+
const stops = withStops(s);
|
|
347
|
+
await answerProductComment(s.opts);
|
|
348
|
+
expect(stops).toHaveLength(1);
|
|
349
|
+
expect(s.dispatched).toEqual([["terragucci-apply.yml", "main"]]);
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
test("without the waves' op a wave-n is still refused, as before", async () => {
|
|
353
|
+
const s = setup({ runs: [run(10, MERGE)], jobs: waves }, { applyOnMerge: true }, "/terragucci apply wave-2");
|
|
354
|
+
withStops(s);
|
|
355
|
+
await answerProductComment(s.opts);
|
|
356
|
+
expect(s.posted[0]).toMatch(/cannot stop them/);
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
test("the product plan's re-plan takes no flags, so a plan comment with them gets the reason", async () => {
|
|
360
|
+
for (const body of ["/terragucci plan --target aws_s3_bucket.logs", "/terragucci plan --refresh"]) {
|
|
361
|
+
const s = setup({}, { preview: true, noPlanFlags: true }, body);
|
|
362
|
+
const got = await answerProductComment(s.opts);
|
|
363
|
+
expect(got.replied, body).toBe(true);
|
|
364
|
+
expect(s.posted[0], body).toBe("terragucci: `/terragucci plan` plans whole roots again, every one or the one named after it, so it takes no `--target`, `--refresh` or `--target-dependents`; write `/terragucci plan` or `/terragucci plan <root>`");
|
|
365
|
+
}
|
|
366
|
+
// A plain re-plan is the re-plan's, and a comment preview takes the flags.
|
|
367
|
+
expect((await answerProductComment(setup({}, { preview: true, noPlanFlags: true }, "/terragucci plan envs/dev").opts)).replied).toBe(false);
|
|
368
|
+
expect((await answerProductComment(setup({}, { preview: true }, "/terragucci plan --target aws_s3_bucket.logs").opts)).replied).toBe(false);
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
test("CHANT_COMMENT_JOBS carries the waves and noPlanFlags", () => {
|
|
372
|
+
expect(commentJobsFromEnv('{"waves":{"op":"tf-apply","count":2},"noPlanFlags":true}')).toEqual({ waves: { op: "tf-apply", count: 2 }, noPlanFlags: true });
|
|
373
|
+
expect(() => commentJobsFromEnv('{"waves":{"op":"a b","count":2}}')).toThrow(/waves is \{ op, count \}/);
|
|
374
|
+
expect(() => commentJobsFromEnv('{"waves":{"op":"tf-apply","count":0}}')).toThrow(/waves is \{ op, count \}/);
|
|
375
|
+
});
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
describe("the comment job's apply before merge on the waves (#4984)", () => {
|
|
379
|
+
const bm = { workflow: "tf-apply.yml", plan: ["terragucci/plan"], pipelineFiles: [".github/workflows/"] };
|
|
380
|
+
const jobs: CommentJobs = { applyOnMerge: true, waves: { op: "tf-apply", count: 2 }, wavesBeforeMerge: bm };
|
|
381
|
+
|
|
382
|
+
test("an open pull request's apply is decided, and the waves workflow dispatched on the default branch with the decided head", async () => {
|
|
383
|
+
const { spawnSync } = await import("node:child_process");
|
|
384
|
+
const { mkdtempSync, writeFileSync } = await import("node:fs");
|
|
385
|
+
const { tmpdir } = await import("node:os");
|
|
386
|
+
const { join } = await import("node:path");
|
|
387
|
+
const { beforeMergeDigest } = await import("./op/before-merge");
|
|
388
|
+
const dir = mkdtempSync(join(tmpdir(), "chant-cc-bm-"));
|
|
389
|
+
const git = (...args: string[]) => {
|
|
390
|
+
const r = spawnSync("git", args, { cwd: dir, encoding: "utf-8", env: { ...process.env, GIT_AUTHOR_NAME: "t", GIT_AUTHOR_EMAIL: "t@t", GIT_COMMITTER_NAME: "t", GIT_COMMITTER_EMAIL: "t@t" } });
|
|
391
|
+
if (r.status !== 0) throw new Error(r.stderr);
|
|
392
|
+
return r.stdout.trim();
|
|
393
|
+
};
|
|
394
|
+
git("init", "-q", "-b", "main");
|
|
395
|
+
writeFileSync(join(dir, "main.tf"), "1");
|
|
396
|
+
git("add", ".");
|
|
397
|
+
git("commit", "-q", "-m", "base");
|
|
398
|
+
const baseSha = git("rev-parse", "HEAD");
|
|
399
|
+
git("checkout", "-q", "-b", "feature");
|
|
400
|
+
writeFileSync(join(dir, "main.tf"), "2");
|
|
401
|
+
git("commit", "-q", "-am", "head");
|
|
402
|
+
const head = git("rev-parse", "HEAD");
|
|
403
|
+
git("update-ref", "refs/pull/12/head", head);
|
|
404
|
+
git("checkout", "-q", "main");
|
|
405
|
+
git("remote", "add", "origin", dir);
|
|
406
|
+
const s = setup({ pr: { state: "open", headSha: head, mergeCommit: undefined } }, jobs, "/terragucci apply wave-1");
|
|
407
|
+
const sent: Array<[string, string, Record<string, string> | undefined]> = [];
|
|
408
|
+
const stops: Array<[string, number | null]> = [];
|
|
409
|
+
const at = "2026-11-10T12:00:00.000Z";
|
|
410
|
+
const got = await answerProductComment({
|
|
411
|
+
...s.opts,
|
|
412
|
+
runs: { rerunFailed: async () => ({}), dispatch: async (wf, ref, inputs) => (sent.push([wf, ref, inputs]), {}) },
|
|
413
|
+
beforeMerge: {
|
|
414
|
+
requires: async () => null,
|
|
415
|
+
statuses: async () => [{ context: "terragucci/plan", state: "success" }],
|
|
416
|
+
git: (argv, o) => {
|
|
417
|
+
const r = spawnSync(argv[0]!, argv.slice(1), { encoding: "utf8", ...(o.cwd ? { cwd: o.cwd } : {}) });
|
|
418
|
+
return { status: r.status, stdout: r.stdout ?? "", stderr: r.stderr ?? "" };
|
|
419
|
+
},
|
|
420
|
+
cwd: dir,
|
|
421
|
+
record: async (d) => ({ ...d, digest: beforeMergeDigest("tf-apply", d) }),
|
|
422
|
+
stop: async (h, through) => void stops.push([h, through]),
|
|
423
|
+
now: () => at,
|
|
424
|
+
},
|
|
425
|
+
});
|
|
426
|
+
const digest = beforeMergeDigest("tf-apply", { pr: 12, head, base: baseSha, through: 1, at, by: "alice" });
|
|
427
|
+
expect(sent).toEqual([["tf-apply.yml", "main", { pr: "12", head, digest }]]);
|
|
428
|
+
expect(stops).toEqual([[head, 1]]);
|
|
429
|
+
expect(got).toMatchObject({ command: "apply", ran: true, replied: true });
|
|
430
|
+
expect(s.posted).toEqual([`terragucci: started the waves of tf-apply on pull request 12's head ${head.slice(0, 8)} through wave 1 for alice; each wave's gate decides, and the run says when the head applied`]);
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
test("CHANT_COMMENT_JOBS carries the waves before merge, each field checked", () => {
|
|
434
|
+
expect(commentJobsFromEnv(JSON.stringify(jobs))).toEqual(jobs);
|
|
435
|
+
expect(() => commentJobsFromEnv(JSON.stringify({ wavesBeforeMerge: bm }))).toThrow("wavesBeforeMerge needs waves");
|
|
436
|
+
expect(() => commentJobsFromEnv(JSON.stringify({ ...jobs, wavesBeforeMerge: { ...bm, workflow: "../x" } }))).toThrow("workflow is a workflow file name");
|
|
437
|
+
expect(() => commentJobsFromEnv(JSON.stringify({ ...jobs, wavesBeforeMerge: { ...bm, requires: ["green"] } }))).toThrow("requires is a list of approved, mergeable, undiverged, checks");
|
|
438
|
+
});
|
|
439
|
+
});
|