@intentius/chant 0.124.55 → 0.124.56
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/ci-agent.d.ts.map +1 -1
- package/dist/ci-agent.js +1 -2
- package/dist/ci-audit/attribution.d.ts +111 -0
- package/dist/ci-audit/attribution.d.ts.map +1 -0
- package/dist/ci-audit/attribution.js +194 -0
- package/dist/ci-audit/audit-log.d.ts +144 -0
- package/dist/ci-audit/audit-log.d.ts.map +1 -0
- package/dist/ci-audit/audit-log.js +149 -0
- package/dist/ci-audit/index.d.ts +12 -0
- package/dist/ci-audit/index.d.ts.map +1 -0
- package/dist/ci-audit/index.js +12 -0
- package/dist/ci-audit/unrecorded.d.ts +74 -0
- package/dist/ci-audit/unrecorded.d.ts.map +1 -0
- package/dist/ci-audit/unrecorded.js +95 -0
- package/dist/ci-audit.d.ts +3 -0
- package/dist/ci-audit.d.ts.map +1 -0
- package/dist/ci-audit.js +2 -0
- package/dist/ci-control.d.ts.map +1 -1
- package/dist/ci-control.js +3 -4
- package/dist/ci-estate.d.ts +24 -0
- package/dist/ci-estate.d.ts.map +1 -1
- package/dist/ci-estate.js +1 -2
- package/dist/ci-identity.d.ts.map +1 -1
- package/dist/ci-identity.js +2 -3
- package/dist/ci-job-guard.d.ts +139 -0
- package/dist/ci-job-guard.d.ts.map +1 -0
- package/dist/ci-job-guard.js +287 -0
- package/dist/ci-jobs.d.ts +7 -0
- package/dist/ci-jobs.d.ts.map +1 -1
- package/dist/ci-jobs.js +7 -0
- package/dist/ci-product-words.d.ts +7 -1
- package/dist/ci-product-words.d.ts.map +1 -1
- package/dist/ci-product-words.js +38 -4
- package/dist/ci-product.d.ts +35 -0
- package/dist/ci-product.d.ts.map +1 -1
- package/dist/ci-product.js +38 -3
- package/dist/ci-respond-run.d.ts +73 -0
- package/dist/ci-respond-run.d.ts.map +1 -0
- package/dist/ci-respond-run.js +247 -0
- package/dist/ci-respond.d.ts +189 -0
- package/dist/ci-respond.d.ts.map +1 -0
- package/dist/ci-respond.js +285 -0
- package/dist/cli/handlers/audit-log.d.ts +12 -0
- package/dist/cli/handlers/audit-log.d.ts.map +1 -0
- package/dist/cli/handlers/audit-log.js +81 -0
- package/dist/cli/handlers/build.d.ts +7 -0
- package/dist/cli/handlers/build.d.ts.map +1 -1
- package/dist/cli/handlers/build.js +81 -0
- package/dist/cli/handlers/ci-check-job.d.ts +11 -0
- package/dist/cli/handlers/ci-check-job.d.ts.map +1 -0
- package/dist/cli/handlers/ci-check-job.js +27 -0
- package/dist/cli/handlers/ci-check.d.ts.map +1 -1
- package/dist/cli/handlers/ci-check.js +38 -9
- package/dist/cli/handlers/e2e-safe-run.d.ts +12 -0
- package/dist/cli/handlers/e2e-safe-run.d.ts.map +1 -0
- package/dist/cli/handlers/e2e-safe-run.js +23 -0
- package/dist/cli/handlers/pr.d.ts +5 -0
- package/dist/cli/handlers/pr.d.ts.map +1 -1
- package/dist/cli/handlers/pr.js +259 -4
- package/dist/cli/handlers/run-wave.js +89 -1
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +56 -2
- package/dist/cli/parse-args.d.ts.map +1 -1
- package/dist/cli/parse-args.js +107 -0
- package/dist/cli/registry.d.ts +38 -0
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/components/adoption.d.ts.map +1 -1
- package/dist/components/adoption.js +1 -2
- package/dist/components/capability.d.ts +37 -0
- package/dist/components/capability.d.ts.map +1 -1
- package/dist/components/capability.js +25 -0
- package/dist/components/check-hooks.d.ts +4 -1
- package/dist/components/check-hooks.d.ts.map +1 -1
- package/dist/components/check-steps.d.ts +74 -0
- package/dist/components/check-steps.d.ts.map +1 -0
- package/dist/components/check-steps.js +102 -0
- package/dist/components/ci-services.d.ts.map +1 -1
- package/dist/components/ci-services.js +1 -2
- package/dist/components/driver.d.ts +12 -0
- package/dist/components/driver.d.ts.map +1 -1
- package/dist/components/driver.js +35 -1
- package/dist/components/groups.d.ts.map +1 -1
- package/dist/components/groups.js +4 -3
- package/dist/components/pr-env-ledger.d.ts.map +1 -1
- package/dist/components/pr-env-ledger.js +1 -2
- package/dist/components/pr-environment.d.ts +1 -1
- package/dist/components/pr-environment.d.ts.map +1 -1
- package/dist/components/pr-environment.js +1 -1
- package/dist/components/pr-pipeline.d.ts +129 -3
- package/dist/components/pr-pipeline.d.ts.map +1 -1
- package/dist/components/pr-pipeline.js +153 -17
- package/dist/components/pr-run.d.ts +8 -0
- package/dist/components/pr-run.d.ts.map +1 -1
- package/dist/components/pr-run.js +9 -4
- package/dist/components/product-pipeline.d.ts +35 -2
- package/dist/components/product-pipeline.d.ts.map +1 -1
- package/dist/components/product-pipeline.js +24 -5
- package/dist/components/wave-plan.d.ts +8 -0
- package/dist/components/wave-plan.d.ts.map +1 -1
- package/dist/components/wave-plan.js +18 -2
- package/dist/e2e-harness/bucket.d.ts +21 -0
- package/dist/e2e-harness/bucket.d.ts.map +1 -0
- package/dist/e2e-harness/bucket.js +61 -0
- package/dist/e2e-harness/claim.d.ts +70 -0
- package/dist/e2e-harness/claim.d.ts.map +1 -0
- package/dist/e2e-harness/claim.js +98 -0
- package/dist/e2e-harness/driver.d.ts +64 -0
- package/dist/e2e-harness/driver.d.ts.map +1 -0
- package/dist/e2e-harness/driver.js +243 -0
- package/dist/e2e-harness/forgejo.d.ts +77 -0
- package/dist/e2e-harness/forgejo.d.ts.map +1 -0
- package/dist/e2e-harness/forgejo.js +205 -0
- package/dist/e2e-harness/git.d.ts +32 -0
- package/dist/e2e-harness/git.d.ts.map +1 -0
- package/dist/e2e-harness/git.js +67 -0
- package/dist/e2e-harness/index.d.ts +22 -0
- package/dist/e2e-harness/index.d.ts.map +1 -0
- package/dist/e2e-harness/index.js +48 -0
- package/dist/e2e-harness/jobs.d.ts +8 -0
- package/dist/e2e-harness/jobs.d.ts.map +1 -0
- package/dist/e2e-harness/jobs.js +34 -0
- package/dist/e2e-harness/pins.d.ts +45 -0
- package/dist/e2e-harness/pins.d.ts.map +1 -0
- package/dist/e2e-harness/pins.js +44 -0
- package/dist/e2e-harness/ports.d.ts +113 -0
- package/dist/e2e-harness/ports.d.ts.map +1 -0
- package/dist/e2e-harness/ports.js +4 -0
- package/dist/e2e-harness/reports.d.ts +45 -0
- package/dist/e2e-harness/reports.d.ts.map +1 -0
- package/dist/e2e-harness/reports.js +57 -0
- package/dist/e2e-harness/safe-run-cli.d.ts +17 -0
- package/dist/e2e-harness/safe-run-cli.d.ts.map +1 -0
- package/dist/e2e-harness/safe-run-cli.js +43 -0
- package/dist/e2e-harness/safe-run.d.ts +61 -0
- package/dist/e2e-harness/safe-run.d.ts.map +1 -0
- package/dist/e2e-harness/safe-run.js +172 -0
- package/dist/e2e-harness/scenario.d.ts +11 -0
- package/dist/e2e-harness/scenario.d.ts.map +1 -0
- package/dist/e2e-harness/scenario.js +89 -0
- package/dist/e2e-harness/schemas/demo-cycle.schema.json +282 -0
- package/dist/e2e-harness/schemas/demo-step.schema.json +245 -0
- package/dist/e2e-harness/schemas/e2e-claim-row.schema.json +33 -0
- package/dist/e2e-harness/schemas/e2e-claims.schema.json +18 -0
- package/dist/e2e-harness/schemas/e2e-scenario.schema.json +150 -0
- package/dist/e2e-harness/schemas/index.d.ts +191 -0
- package/dist/e2e-harness/schemas/index.d.ts.map +1 -0
- package/dist/e2e-harness/schemas/index.js +62 -0
- package/dist/e2e-harness/stack.d.ts +124 -0
- package/dist/e2e-harness/stack.d.ts.map +1 -0
- package/dist/e2e-harness/stack.js +207 -0
- package/dist/e2e-harness/steps.d.ts +11 -0
- package/dist/e2e-harness/steps.d.ts.map +1 -0
- package/dist/e2e-harness/steps.js +22 -0
- package/dist/e2e-harness.d.ts +3 -0
- package/dist/e2e-harness.d.ts.map +1 -0
- package/dist/e2e-harness.js +2 -0
- package/dist/exit-codes.d.ts +7 -1
- package/dist/exit-codes.d.ts.map +1 -1
- package/dist/exit-codes.js +7 -1
- package/dist/lexicon.d.ts +46 -0
- package/dist/lexicon.d.ts.map +1 -1
- package/dist/lifecycle/gate-ledger.d.ts.map +1 -1
- package/dist/lifecycle/gate-ledger.js +2 -3
- package/dist/lifecycle/gated-request.d.ts.map +1 -1
- package/dist/lifecycle/gated-request.js +1 -2
- package/dist/lifecycle/query.d.ts.map +1 -1
- package/dist/lifecycle/query.js +4 -5
- package/dist/lifecycle/release-catalog.d.ts.map +1 -1
- package/dist/lifecycle/release-catalog.js +1 -1
- package/dist/lifecycle/release-ledger.d.ts.map +1 -1
- package/dist/lifecycle/release-ledger.js +1 -2
- package/dist/lifecycle/release-status.d.ts +20 -0
- package/dist/lifecycle/release-status.d.ts.map +1 -1
- package/dist/lifecycle/release-status.js +1 -22
- package/dist/lifecycle/wave-plans.d.ts +23 -7
- package/dist/lifecycle/wave-plans.d.ts.map +1 -1
- package/dist/lifecycle/wave-plans.js +9 -2
- package/dist/op/approval-status.d.ts +103 -0
- package/dist/op/approval-status.d.ts.map +1 -0
- package/dist/op/approval-status.js +197 -0
- package/dist/op/index.d.ts +1 -1
- package/dist/op/index.d.ts.map +1 -1
- package/dist/op/index.js +1 -1
- package/dist/op/op-waves-capability-spec.d.ts +8 -0
- package/dist/op/op-waves-capability-spec.d.ts.map +1 -1
- package/dist/op/op-waves-capability-spec.js +21 -0
- package/dist/op/op-waves-release.d.ts.map +1 -1
- package/dist/op/op-waves-release.js +1 -2
- package/dist/op/op-waves-run.d.ts +7 -2
- package/dist/op/op-waves-run.d.ts.map +1 -1
- package/dist/op/op-waves-run.js +96 -4
- package/dist/op/op-waves-stand-down.d.ts.map +1 -1
- package/dist/op/op-waves-stand-down.js +1 -2
- package/dist/op/op-waves.d.ts +35 -0
- package/dist/op/op-waves.d.ts.map +1 -1
- package/dist/op/op-waves.js +46 -6
- package/dist/op/runtime.d.ts +4 -0
- package/dist/op/runtime.d.ts.map +1 -1
- package/dist/op/runtime.js +2 -3
- package/dist/otlp.d.ts.map +1 -1
- package/dist/otlp.js +1 -2
- package/dist/parallelism.d.ts +17 -0
- package/dist/parallelism.d.ts.map +1 -0
- package/dist/parallelism.js +33 -0
- package/dist/policy-source.d.ts.map +1 -1
- package/dist/policy-source.js +1 -2
- package/dist/pr-forge.d.ts.map +1 -1
- package/dist/pr-forge.js +56 -39
- package/dist/pr-loop.d.ts +9 -0
- package/dist/pr-loop.d.ts.map +1 -1
- package/dist/pr-loop.js +22 -3
- package/dist/pr-merge.d.ts +64 -0
- package/dist/pr-merge.d.ts.map +1 -0
- package/dist/pr-merge.js +78 -0
- package/dist/pr-post.d.ts +70 -1
- package/dist/pr-post.d.ts.map +1 -1
- package/dist/pr-post.js +116 -5
- package/dist/pr-report-url.d.ts.map +1 -1
- package/dist/pr-report-url.js +1 -2
- package/dist/release-floors.d.ts +1 -1
- package/dist/release-floors.js +1 -1
- package/dist/run-event.d.ts.map +1 -1
- package/dist/run-event.js +1 -2
- package/dist/scheduled-op-cloud.d.ts +32 -0
- package/dist/scheduled-op-cloud.d.ts.map +1 -0
- package/dist/scheduled-op-cloud.js +69 -0
- package/dist/wave-runtime.mjs +340 -327
- package/dist/workspace/ci-lock-grain.d.ts +5 -0
- package/dist/workspace/ci-lock-grain.d.ts.map +1 -1
- package/dist/workspace/ci-lock-grain.js +1 -7
- package/dist/workspace/ci-run.d.ts.map +1 -1
- package/dist/workspace/ci-run.js +5 -1
- package/dist/workspace/pr-report.schema.json +5 -0
- package/package.json +1 -1
- package/src/ci-agent.ts +1 -2
- package/src/ci-audit/__fixtures__/cloudtrail-lookup-bucket.json +37 -0
- package/src/ci-audit/__fixtures__/cloudtrail-writes-window.json +59 -0
- package/src/ci-audit/attribution.ts +260 -0
- package/src/ci-audit/audit-log.ts +220 -0
- package/src/ci-audit/ci-audit.test.ts +175 -0
- package/src/ci-audit/index.ts +15 -0
- package/src/ci-audit/unrecorded.ts +140 -0
- package/src/ci-audit.ts +2 -0
- package/src/ci-control.ts +3 -4
- package/src/ci-estate.ts +1 -2
- package/src/ci-identity-database.test.ts +2 -3
- package/src/ci-identity-targets.test.ts +1 -3
- package/src/ci-identity.ts +2 -3
- package/src/ci-job-guard.test.ts +154 -0
- package/src/ci-job-guard.ts +319 -0
- package/src/ci-jobs.ts +8 -0
- package/src/ci-product-comment-targets.test.ts +45 -0
- package/src/ci-product-words.ts +35 -6
- package/src/ci-product.ts +55 -3
- package/src/ci-respond-run.ts +291 -0
- package/src/ci-respond.test.ts +264 -0
- package/src/ci-respond.ts +412 -0
- package/src/cli/handlers/audit-log.ts +74 -0
- package/src/cli/handlers/build-pr-loop-flags.test.ts +98 -0
- package/src/cli/handlers/build.ts +69 -0
- package/src/cli/handlers/ci-check-job.test.ts +114 -0
- package/src/cli/handlers/ci-check-job.ts +33 -0
- package/src/cli/handlers/ci-check.ts +38 -8
- package/src/cli/handlers/e2e-safe-run.ts +27 -0
- package/src/cli/handlers/pr-plan-comment-targets.test.ts +166 -0
- package/src/cli/handlers/pr-plan-flags.test.ts +161 -0
- package/src/cli/handlers/pr.ts +228 -4
- package/src/cli/handlers/run-wave.ts +79 -1
- package/src/cli/main.test.ts +1 -1
- package/src/cli/main.ts +56 -2
- package/src/cli/parse-args.ts +77 -0
- package/src/cli/registry.ts +38 -0
- package/src/components/adoption.ts +1 -2
- package/src/components/capability.ts +50 -0
- package/src/components/check-hooks.ts +4 -1
- package/src/components/check-steps.test.ts +70 -0
- package/src/components/check-steps.ts +158 -0
- package/src/components/ci-services.ts +1 -2
- package/src/components/driver.ts +35 -1
- package/src/components/groups.ts +4 -2
- package/src/components/plan-flags.test.ts +46 -0
- package/src/components/pr-comment-preview-targets.test.ts +34 -0
- package/src/components/pr-env-ledger.ts +1 -2
- package/src/components/pr-env-run-bundle.test.ts +0 -20
- package/src/components/pr-environment.ts +1 -1
- package/src/components/pr-pipeline-runners.test.ts +80 -0
- package/src/components/pr-pipeline.ts +232 -17
- package/src/components/pr-run.ts +17 -6
- package/src/components/pr-stale-job.test.ts +34 -0
- package/src/components/product-pipeline.ts +50 -8
- package/src/components/wave-plan.ts +18 -2
- package/src/e2e-harness/__project__/chant.config.ts +4 -0
- package/src/e2e-harness/__project__/src/compose.ts +33 -0
- package/src/e2e-harness/bucket.ts +69 -0
- package/src/e2e-harness/claim.test.ts +150 -0
- package/src/e2e-harness/claim.ts +140 -0
- package/src/e2e-harness/driver.test.ts +304 -0
- package/src/e2e-harness/driver.ts +294 -0
- package/src/e2e-harness/forgejo.ts +267 -0
- package/src/e2e-harness/git.ts +96 -0
- package/src/e2e-harness/index.ts +50 -0
- package/src/e2e-harness/jobs.ts +35 -0
- package/src/e2e-harness/pins.ts +52 -0
- package/src/e2e-harness/ports.ts +130 -0
- package/src/e2e-harness/reports.ts +79 -0
- package/src/e2e-harness/safe-run-cli.test.ts +102 -0
- package/src/e2e-harness/safe-run-cli.ts +54 -0
- package/src/e2e-harness/safe-run.ts +198 -0
- package/src/e2e-harness/scenario.ts +89 -0
- package/src/e2e-harness/schemas/README.md +62 -0
- package/src/e2e-harness/schemas/demo-cycle.schema.json +282 -0
- package/src/e2e-harness/schemas/demo-step.schema.json +245 -0
- package/src/e2e-harness/schemas/e2e-claim-row.schema.json +33 -0
- package/src/e2e-harness/schemas/e2e-claims.schema.json +18 -0
- package/src/e2e-harness/schemas/e2e-scenario.schema.json +150 -0
- package/src/e2e-harness/schemas/index.ts +220 -0
- package/src/e2e-harness/schemas.test.ts +145 -0
- package/src/e2e-harness/stack.test.ts +124 -0
- package/src/e2e-harness/stack.ts +306 -0
- package/src/e2e-harness/steps.ts +30 -0
- package/src/e2e-harness.ts +2 -0
- package/src/exit-codes.test.ts +3 -2
- package/src/exit-codes.ts +7 -1
- package/src/gate-decision-bundle.test.ts +0 -2
- package/src/lexicon.ts +48 -0
- package/src/lifecycle/control-entries-ledger.test.ts +2 -3
- package/src/lifecycle/gate-ledger.ts +2 -3
- package/src/lifecycle/gated-request.ts +1 -2
- package/src/lifecycle/query.ts +4 -5
- package/src/lifecycle/release-catalog.test.ts +3 -4
- package/src/lifecycle/release-catalog.ts +1 -1
- package/src/lifecycle/release-ledger.ts +1 -2
- package/src/lifecycle/release-status.test.ts +3 -4
- package/src/lifecycle/release-status.ts +1 -2
- package/src/lifecycle/wave-plans.ts +33 -5
- package/src/op/approval-status.test.ts +134 -0
- package/src/op/approval-status.ts +235 -0
- package/src/op/gate-review.test.ts +2 -1
- package/src/op/index.ts +2 -0
- package/src/op/op-waves-after-plan.test.ts +12 -0
- package/src/op/op-waves-capability-spec.ts +20 -0
- package/src/op/op-waves-parallelism.test.ts +89 -0
- package/src/op/op-waves-pull-request.test.ts +78 -1
- package/src/op/op-waves-release.ts +1 -2
- package/src/op/op-waves-run.ts +94 -4
- package/src/op/op-waves-stand-down.ts +1 -2
- package/src/op/op-waves.ts +63 -6
- package/src/op/runtime.ts +6 -3
- package/src/otlp.ts +1 -2
- package/src/parallelism.test.ts +38 -0
- package/src/parallelism.ts +33 -0
- package/src/policy-source.ts +1 -2
- package/src/pr-forge-bundle.test.ts +1 -1
- package/src/pr-forge.ts +54 -35
- package/src/pr-loop-bundle.test.ts +1 -1
- package/src/pr-loop-narrowed.test.ts +63 -0
- package/src/pr-loop.ts +30 -3
- package/src/pr-merge.test.ts +100 -0
- package/src/pr-merge.ts +105 -0
- package/src/pr-post-stale.test.ts +163 -0
- package/src/pr-post.ts +159 -5
- package/src/pr-report-url.ts +1 -2
- package/src/product-subpaths-plain-node.e2e.test.ts +1 -0
- package/src/release-floors.ts +1 -1
- package/src/run-event.ts +1 -2
- package/src/scheduled-op-cloud.ts +68 -0
- package/src/stage-hooks-bundle.test.ts +0 -2
- package/src/workspace/ci-lock-grain.ts +1 -2
- package/src/workspace/ci-run.ts +5 -1
- package/src/workspace/pr-report.schema.json +5 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The plans an op-waves `pr-review` wave records for a
|
|
3
|
-
* (#3684, #3865): `_wave-plans/<name>/<head>.json` on `chant/lifecycle`,
|
|
2
|
+
* The plans an op-waves `pr-review` or `pull-request` wave records for a
|
|
3
|
+
* pull request's head (#3684, #3865, #4630): `_wave-plans/<name>/<head>.json` on `chant/lifecycle`,
|
|
4
4
|
* written by `chant run wave --record-plans` (`../op/op-waves-run.ts`) and read
|
|
5
5
|
* after the merge, where the review of that head approves the digests it
|
|
6
6
|
* planned and only those (`../op/gate-review.ts`).
|
|
@@ -22,7 +22,28 @@ export interface HeadPlans {
|
|
|
22
22
|
/** The commit the waves were planned at: a pull request's head. */
|
|
23
23
|
head: string;
|
|
24
24
|
timestamp: string;
|
|
25
|
-
waves: Array<
|
|
25
|
+
waves: Array<HeadPlanWave>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* One wave's plan at the head. `changes` and `destructive` (#4630) are the
|
|
30
|
+
* plan's facts a gate policy reads: some run changes something, some run's
|
|
31
|
+
* plan is destructive. A record from an older chant has neither, and a
|
|
32
|
+
* reader takes such a wave as changing.
|
|
33
|
+
*/
|
|
34
|
+
export interface HeadPlanWave {
|
|
35
|
+
wave: number;
|
|
36
|
+
name: string;
|
|
37
|
+
digest: string;
|
|
38
|
+
changes?: boolean;
|
|
39
|
+
destructive?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* The digest of the wave's change set at the head, when its plans file
|
|
42
|
+
* gave one (#4630, `pull-request` waves). The document is stored under
|
|
43
|
+
* `_change-sets/`, and the approval status checks the pull request's own
|
|
44
|
+
* approval against it.
|
|
45
|
+
*/
|
|
46
|
+
changeSet?: string;
|
|
26
47
|
}
|
|
27
48
|
|
|
28
49
|
/** Where {@link HeadPlans} for `head` live on `chant/lifecycle`: `_wave-plans/<name>/<head>.json`. */
|
|
@@ -50,9 +71,16 @@ export function parseHeadPlans(text: string | null): HeadPlans | null {
|
|
|
50
71
|
const waves: HeadPlans["waves"] = [];
|
|
51
72
|
for (const w of r.waves) {
|
|
52
73
|
if (w === null || typeof w !== "object") return null;
|
|
53
|
-
const { wave, name, digest } = w as Record<string, unknown>;
|
|
74
|
+
const { wave, name, digest, changes, destructive, changeSet } = w as Record<string, unknown>;
|
|
54
75
|
if (typeof wave !== "number" || typeof name !== "string" || typeof digest !== "string") return null;
|
|
55
|
-
waves.push({
|
|
76
|
+
waves.push({
|
|
77
|
+
wave,
|
|
78
|
+
name,
|
|
79
|
+
digest,
|
|
80
|
+
...(typeof changes === "boolean" ? { changes } : {}),
|
|
81
|
+
...(typeof destructive === "boolean" ? { destructive } : {}),
|
|
82
|
+
...(typeof changeSet === "string" && changeSet !== "" ? { changeSet } : {}),
|
|
83
|
+
});
|
|
56
84
|
}
|
|
57
85
|
return { version: 1, name: r.name, head: r.head, timestamp: r.timestamp, waves };
|
|
58
86
|
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #4630: `<product>/approval` on an open pull request's head, from the
|
|
3
|
+
* policy at base, the head's recorded plans and the forge's reviews, on
|
|
4
|
+
* fake GitHub, GitLab and Forgejo forges.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { describe, expect, test } from "vitest";
|
|
8
|
+
import { assertProductWords } from "../ci-product-words";
|
|
9
|
+
import type { HeadPlans } from "../lifecycle/wave-plans";
|
|
10
|
+
import { parseHeadPlans } from "../lifecycle/wave-plans";
|
|
11
|
+
import type { ForgeStatus, PrApprovalResult } from "../pr-forge";
|
|
12
|
+
import { approvalStatusOf, headWaveHolds, postApprovalStatus, postOpenApprovalStatuses } from "./approval-status";
|
|
13
|
+
import type { OpWavesSpec } from "./op-waves";
|
|
14
|
+
import type { OpWaveShowAtBase } from "./op-waves-run";
|
|
15
|
+
|
|
16
|
+
const HEAD = "a".repeat(40);
|
|
17
|
+
const BASE = "b".repeat(40);
|
|
18
|
+
|
|
19
|
+
const SPEC: OpWavesSpec = {
|
|
20
|
+
name: "plywood-up",
|
|
21
|
+
op: "plywood-up",
|
|
22
|
+
plan: ["./bin/plan", "{target}", "{plan}"],
|
|
23
|
+
waves: [
|
|
24
|
+
{ name: "dev", runs: [{ target: "dev" }], gate: "never", approval: "pr-review" },
|
|
25
|
+
{ name: "prod", runs: [{ target: "prod" }], gate: "on-destructive", approval: "pr-review" },
|
|
26
|
+
],
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/** The spec as it stands at base: what the policy is read from. */
|
|
30
|
+
const atBase = (spec: OpWavesSpec | null): OpWaveShowAtBase => () => ({ sha: BASE, text: spec ? JSON.stringify(spec) : null });
|
|
31
|
+
|
|
32
|
+
const plans = (waves: HeadPlans["waves"]): HeadPlans => ({ version: 1, name: SPEC.name, head: HEAD, timestamp: "2026-10-28T00:00:00Z", waves });
|
|
33
|
+
|
|
34
|
+
function fakeForge(kind: "github" | "gitlab" | "forgejo", approval: PrApprovalResult) {
|
|
35
|
+
const statuses: Array<{ sha: string; status: ForgeStatus }> = [];
|
|
36
|
+
const asked: Array<{ pr: number; head: string }> = [];
|
|
37
|
+
const forge = {
|
|
38
|
+
kind,
|
|
39
|
+
runUrl: "https://ci.example/run/1",
|
|
40
|
+
async prApproved(pr: number, head: string) {
|
|
41
|
+
asked.push({ pr, head });
|
|
42
|
+
return approval;
|
|
43
|
+
},
|
|
44
|
+
async setStatus(sha: string, status: ForgeStatus) {
|
|
45
|
+
statuses.push({ sha, status });
|
|
46
|
+
},
|
|
47
|
+
async openPullRequests() {
|
|
48
|
+
return [
|
|
49
|
+
{ number: 3, head: "feature", headSha: HEAD, base: "main", baseSha: BASE, fork: false },
|
|
50
|
+
{ number: 4, head: "fork-branch", headSha: "c".repeat(40), base: "main", fork: true },
|
|
51
|
+
];
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
return { forge, statuses, asked };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const approved: PrApprovalResult = { passed: true, reason: "approved", approvers: ["github:lee"], excluded: [] };
|
|
58
|
+
const notApproved: PrApprovalResult = { passed: false, reason: "no writer other than the author approved a1b2c3d4", approvers: [], excluded: [] };
|
|
59
|
+
|
|
60
|
+
describe("which waves the gate will hold (#4630)", () => {
|
|
61
|
+
test("never holds nothing, on-destructive holds a destructive plan, always holds a change; no facts read as a change", () => {
|
|
62
|
+
expect(headWaveHolds("never", { changes: true, destructive: true })).toBe(false);
|
|
63
|
+
expect(headWaveHolds("on-destructive", { changes: true, destructive: false })).toBe(false);
|
|
64
|
+
expect(headWaveHolds("on-destructive", { changes: true, destructive: true })).toBe(true);
|
|
65
|
+
expect(headWaveHolds("always", { changes: false })).toBe(false);
|
|
66
|
+
expect(headWaveHolds("always", {})).toBe(true);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test("the plans record keeps the facts, and an older record without them still parses", () => {
|
|
70
|
+
const text = JSON.stringify(plans([{ wave: 1, name: "dev", digest: "d1", changes: true, destructive: false }]));
|
|
71
|
+
expect(parseHeadPlans(text)?.waves[0]).toEqual({ wave: 1, name: "dev", digest: "d1", changes: true, destructive: false });
|
|
72
|
+
expect(parseHeadPlans(JSON.stringify(plans([{ wave: 1, name: "dev", digest: "d1" }])))?.waves[0]).toEqual({ wave: 1, name: "dev", digest: "d1" });
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
describe("<product>/approval on the head (#4630)", () => {
|
|
77
|
+
for (const kind of ["github", "gitlab", "forgejo"] as const) {
|
|
78
|
+
test(`pending while a held wave has no approving review, success once it has (${kind})`, async () => {
|
|
79
|
+
const recorded = plans([
|
|
80
|
+
{ wave: 1, name: "dev", digest: "d1", changes: true, destructive: true },
|
|
81
|
+
{ wave: 2, name: "prod", digest: "d2", changes: true, destructive: true },
|
|
82
|
+
]);
|
|
83
|
+
const words = assertProductWords({ product: "plywood" });
|
|
84
|
+
const waiting = fakeForge(kind, notApproved);
|
|
85
|
+
const status = await postApprovalStatus({ spec: SPEC, specFile: "waves.json", forge: waiting.forge, pr: 3, head: HEAD, base: BASE, show: atBase(SPEC), readPlans: async () => recorded }, words);
|
|
86
|
+
expect(status).toMatchObject({ state: "pending", waits: [2] });
|
|
87
|
+
expect(waiting.statuses).toEqual([{ sha: HEAD, status: { context: "plywood/approval", state: "pending", description: expect.stringContaining("wave 2 wait"), url: "https://ci.example/run/1" } }]);
|
|
88
|
+
expect(waiting.asked).toEqual([{ pr: 3, head: HEAD }]);
|
|
89
|
+
|
|
90
|
+
const done = fakeForge(kind, approved);
|
|
91
|
+
const ok = await postApprovalStatus({ spec: SPEC, specFile: "waves.json", forge: done.forge, pr: 3, head: HEAD, base: BASE, show: atBase(SPEC), readPlans: async () => recorded }, words);
|
|
92
|
+
expect(ok).toMatchObject({ state: "success", approvers: ["github:lee"] });
|
|
93
|
+
expect(done.statuses[0]!.status.description).toContain("by github:lee");
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
test("a plan no gate holds is success without asking for reviews", async () => {
|
|
98
|
+
const { forge, asked } = fakeForge("github", notApproved);
|
|
99
|
+
const status = await approvalStatusOf({
|
|
100
|
+
spec: SPEC,
|
|
101
|
+
specFile: "waves.json",
|
|
102
|
+
forge,
|
|
103
|
+
pr: 3,
|
|
104
|
+
head: HEAD,
|
|
105
|
+
base: BASE,
|
|
106
|
+
show: atBase(SPEC),
|
|
107
|
+
readPlans: async () => plans([{ wave: 1, name: "dev", digest: "d1", changes: true }, { wave: 2, name: "prod", digest: "d2", changes: true, destructive: false }]),
|
|
108
|
+
});
|
|
109
|
+
expect(status).toMatchObject({ state: "success", waits: [] });
|
|
110
|
+
expect(asked).toEqual([]);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test("the policy is read at base: a head that loosens it still waits", async () => {
|
|
114
|
+
const loosened: OpWavesSpec = { ...SPEC, waves: SPEC.waves.map((w) => ({ ...w, gate: "never" as const })) };
|
|
115
|
+
const strict: OpWavesSpec = { ...SPEC, waves: SPEC.waves.map((w) => ({ ...w, gate: "always" as const })) };
|
|
116
|
+
const { forge } = fakeForge("forgejo", notApproved);
|
|
117
|
+
const status = await approvalStatusOf({ spec: loosened, specFile: "waves.json", forge, pr: 3, head: HEAD, base: BASE, show: atBase(strict), readPlans: async () => plans([{ wave: 1, name: "dev", digest: "d1", changes: true }, { wave: 2, name: "prod", digest: "d2", changes: true }]) });
|
|
118
|
+
expect(status).toMatchObject({ state: "pending", waits: [1, 2] });
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test("plans not recorded yet are pending; no pr-review wave at base is success", async () => {
|
|
122
|
+
const { forge } = fakeForge("github", approved);
|
|
123
|
+
expect(await approvalStatusOf({ spec: SPEC, specFile: "waves.json", forge, pr: 3, head: HEAD, base: BASE, show: atBase(SPEC), readPlans: async () => null })).toMatchObject({ state: "pending", description: expect.stringContaining("not recorded yet") });
|
|
124
|
+
const ledgerOnly: OpWavesSpec = { ...SPEC, waves: SPEC.waves.map(({ approval: _a, ...w }) => w) };
|
|
125
|
+
expect(await approvalStatusOf({ spec: SPEC, specFile: "waves.json", forge, pr: 3, head: HEAD, base: BASE, show: atBase(ledgerOnly), readPlans: async () => null })).toMatchObject({ state: "success" });
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test("--open posts on every open merge request from the repository, and leaves forks out", async () => {
|
|
129
|
+
const { forge, statuses } = fakeForge("gitlab", notApproved);
|
|
130
|
+
const done = await postOpenApprovalStatuses({ spec: SPEC, specFile: "waves.json", forge, branch: "main", show: atBase(SPEC), readPlans: async () => plans([{ wave: 2, name: "prod", digest: "d2", changes: true, destructive: true }]) }, assertProductWords({ product: "plywood" }));
|
|
131
|
+
expect(done.posted.map((p) => p.pr)).toEqual([3]);
|
|
132
|
+
expect(statuses.map((s) => s.sha)).toEqual([HEAD]);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The approval status before merge (#4630): `<product>/approval` on an open
|
|
3
|
+
* pull request's head says whether the waves its merge will run wait for an
|
|
4
|
+
* approval. It covers the waves whose approval at base is `pr-review` and,
|
|
5
|
+
* under the 2026-10-28 ruling, the waves whose approval is `pull-request`.
|
|
6
|
+
*
|
|
7
|
+
* - `pending` while a wave whose gate the plan will hold has no approval
|
|
8
|
+
* that would pass it: under `pr-review` an approving review of that head,
|
|
9
|
+
* by a writer other than its author; under `pull-request` the pull
|
|
10
|
+
* request's own approval (below).
|
|
11
|
+
* - `success` once every such wave has one, or when no wave's gate holds
|
|
12
|
+
* the plan.
|
|
13
|
+
*
|
|
14
|
+
* Which waves the gate holds is read the way the wave job reads it after the
|
|
15
|
+
* merge: each wave's approval mode and policy from the spec at the pull
|
|
16
|
+
* request's base (`readOpWavePolicy`), applied to the facts the head's plans
|
|
17
|
+
* record (`chant run wave --record-plans`, `../lifecycle/wave-plans.ts`):
|
|
18
|
+
* whether a run changes anything and whether a plan is destructive. A head
|
|
19
|
+
* whose plans are not recorded yet is pending, since nothing says its waves
|
|
20
|
+
* pass.
|
|
21
|
+
*
|
|
22
|
+
* The pull request's own approval, for a `pull-request` wave: an approval at
|
|
23
|
+
* the pull request's gate (`approvals.pullRequest.gate` at base) whose
|
|
24
|
+
* change set covers the wave's change set at the head, as the merged wave
|
|
25
|
+
* checks it (`planCoveredBy`). The approval is read on the pull request's
|
|
26
|
+
* op (`pr-<n>`), where the product's approve line records it, and on the
|
|
27
|
+
* spec's op, which the merged wave reads. The head's change set is the one
|
|
28
|
+
* `--record-plans` stored for the wave; a record without one is pending.
|
|
29
|
+
*
|
|
30
|
+
* The status job reads only: the pull request, its reviews and
|
|
31
|
+
* `chant/lifecycle`. It writes the one commit status. On GitHub and Forgejo
|
|
32
|
+
* it runs after the record-plans job and on every review; on GitLab, whose
|
|
33
|
+
* approvals start no pipeline, a scheduled pipeline of the target branch
|
|
34
|
+
* posts it for every open merge request (`--open`). An approval recorded on
|
|
35
|
+
* the ledger starts no run on any forge: the next push, review or `--open`
|
|
36
|
+
* run posts it. The status advises: the gate after the merge decides, from
|
|
37
|
+
* the ledger and the merged review.
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
import { activeProductWords, productStatusContext, type CiProductWords } from "../ci-product-words";
|
|
41
|
+
import type { ChangeSetDocument } from "../change-set";
|
|
42
|
+
import type { GateResolutionRecord } from "../lifecycle/gate-ledger";
|
|
43
|
+
import type { HeadPlans } from "../lifecycle/wave-plans";
|
|
44
|
+
import type { PrApproverFilter, PrForge } from "../pr-forge";
|
|
45
|
+
import type { OpWaveGatePolicy, OpWavesSpec } from "./op-waves";
|
|
46
|
+
import type { OpWaveShowAtBase } from "./op-waves-run";
|
|
47
|
+
|
|
48
|
+
/** What the status says. */
|
|
49
|
+
export interface ApprovalStatus {
|
|
50
|
+
state: "pending" | "success";
|
|
51
|
+
description: string;
|
|
52
|
+
/** The waves whose gate the plan will hold, by number. */
|
|
53
|
+
waits: number[];
|
|
54
|
+
/** Who approved the head, when someone did. */
|
|
55
|
+
approvers: string[];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface ApprovalStatusInput {
|
|
59
|
+
spec: OpWavesSpec;
|
|
60
|
+
/** The spec's path, which the policy is read from at `base`. */
|
|
61
|
+
specFile: string;
|
|
62
|
+
forge: Pick<PrForge, "prApproved" | "kind">;
|
|
63
|
+
pr: number;
|
|
64
|
+
/** The pull request's head commit. */
|
|
65
|
+
head: string;
|
|
66
|
+
/** The pull request's base commit, which the policy is read at. */
|
|
67
|
+
base: string;
|
|
68
|
+
cwd?: string;
|
|
69
|
+
/** The head's recorded plans. Default: `chant/lifecycle` at `cwd`. */
|
|
70
|
+
readPlans?: (name: string, head: string) => Promise<HeadPlans | null>;
|
|
71
|
+
/** How the spec is read at base. Default `git show`. */
|
|
72
|
+
show?: OpWaveShowAtBase;
|
|
73
|
+
/** Who may approve, as the forge's requires check takes it. */
|
|
74
|
+
approvers?: PrApproverFilter;
|
|
75
|
+
/** The resolutions on one op's gate ledger, for a `pull-request` wave. Default: `chant/lifecycle` at `cwd`. */
|
|
76
|
+
readResolutions?: (op: string) => Promise<GateResolutionRecord[]>;
|
|
77
|
+
/** A stored change set by digest, for a `pull-request` wave. Default: `_change-sets/` on `chant/lifecycle` at `cwd`. */
|
|
78
|
+
changeSets?: (digest: string) => Promise<ChangeSetDocument | undefined>;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Whether `policy` holds a wave with these facts. A record with no facts reads as changing, so it holds under `always`. */
|
|
82
|
+
export function headWaveHolds(policy: OpWaveGatePolicy, facts: { changes?: boolean; destructive?: boolean }): boolean {
|
|
83
|
+
if (policy === "never") return false;
|
|
84
|
+
if (facts.changes === false) return false;
|
|
85
|
+
if (policy === "on-destructive") return facts.destructive === true;
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const short = (sha: string): string => sha.slice(0, 8);
|
|
90
|
+
const cut = (text: string): string => (text.length > 135 ? `${text.slice(0, 132)}...` : text);
|
|
91
|
+
|
|
92
|
+
/** The status for one pull request's head. Throws only when the spec cannot be read at base. */
|
|
93
|
+
export async function approvalStatusOf(input: ApprovalStatusInput): Promise<ApprovalStatus> {
|
|
94
|
+
const cwd = input.cwd ?? process.cwd();
|
|
95
|
+
const { readOpWavePolicy } = await import("./op-waves-run");
|
|
96
|
+
const rulesOf = (name: string) => readOpWavePolicy(input.specFile, name, input.base, cwd, ...(input.show ? [input.show] : []));
|
|
97
|
+
const asked = input.spec.waves
|
|
98
|
+
.map((w, i) => ({ k: i + 1, wave: w, rules: rulesOf(w.name) }))
|
|
99
|
+
.filter(({ rules }) => rules.approval === "pr-review" || rules.approval === "pull-request");
|
|
100
|
+
if (asked.length === 0) return { state: "success", description: "no wave takes its approval from the pull request", waits: [], approvers: [] };
|
|
101
|
+
const plans = await (input.readPlans ?? ((name, head) => ledgerHeadPlans(name, head, cwd)))(input.spec.name, input.head);
|
|
102
|
+
if (!plans) {
|
|
103
|
+
return { state: "pending", description: cut(`the plans of ${short(input.head)} are not recorded yet, so every wave may wait`), waits: asked.map((r) => r.k), approvers: [] };
|
|
104
|
+
}
|
|
105
|
+
const factsOf = (k: number) => plans.waves.find((w) => w.wave === k);
|
|
106
|
+
const holding = asked.filter(({ k, rules }) => headWaveHolds(rules.policy, factsOf(k) ?? {}));
|
|
107
|
+
const waits = holding.map((r) => r.k);
|
|
108
|
+
if (waits.length === 0) return { state: "success", description: cut(`no wave waits for an approval at ${short(input.head)}`), waits, approvers: [] };
|
|
109
|
+
|
|
110
|
+
const unmet: string[] = [];
|
|
111
|
+
const approvers = new Set<string>();
|
|
112
|
+
// pr-review: one approving review of the head answers every such wave.
|
|
113
|
+
const byReview = holding.filter((r) => r.rules.approval === "pr-review").map((r) => r.k);
|
|
114
|
+
if (byReview.length > 0) {
|
|
115
|
+
const which = wavesLabel(byReview);
|
|
116
|
+
if (!input.forge.prApproved) unmet.push(`${which}: ${input.forge.kind} cannot say who approved the head`);
|
|
117
|
+
else {
|
|
118
|
+
const approved = await input.forge.prApproved(input.pr, input.head, input.approvers);
|
|
119
|
+
if (approved.passed && approved.approvers.length > 0) for (const a of approved.approvers) approvers.add(a);
|
|
120
|
+
else unmet.push(`${which}: ${approved.reason}`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
// pull-request: the pull request's own approval, whose change set must cover each wave's.
|
|
124
|
+
const byPullRequest = holding.filter((r) => r.rules.approval === "pull-request");
|
|
125
|
+
if (byPullRequest.length > 0) {
|
|
126
|
+
const read = pullRequestApprovalReader(input, cwd);
|
|
127
|
+
for (const { k, rules } of byPullRequest) {
|
|
128
|
+
const got = await read(rules.pullRequestGate, factsOf(k)?.changeSet);
|
|
129
|
+
if (got.approvedBy) approvers.add(got.approvedBy);
|
|
130
|
+
else unmet.push(`wave ${k}: ${got.reason}`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
const which = wavesLabel(waits);
|
|
134
|
+
if (unmet.length > 0) return { state: "pending", description: cut(`${which} wait: ${unmet.join("; ")}`), waits, approvers: [] };
|
|
135
|
+
const by = [...approvers];
|
|
136
|
+
return { state: "success", description: cut(`${which} approved at ${short(input.head)} by ${by.join(", ")}`), waits, approvers: by };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const wavesLabel = (ks: readonly number[]): string => `wave${ks.length === 1 ? "" : "s"} ${ks.join(", ")}`;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* How a `pull-request` wave's approval is found before merge: the newest
|
|
143
|
+
* approval at the pull request's gate, on the pull request's op or the
|
|
144
|
+
* spec's, whose change set covers the wave's change set at the head.
|
|
145
|
+
*/
|
|
146
|
+
function pullRequestApprovalReader(input: ApprovalStatusInput, cwd: string) {
|
|
147
|
+
const resolutionsOf = input.readResolutions ?? ((op: string) => ledgerResolutions(op, cwd));
|
|
148
|
+
const changeSetOf = input.changeSets ?? ((digest: string) => ledgerChangeSet(digest, cwd));
|
|
149
|
+
let all: Promise<GateResolutionRecord[]> | undefined;
|
|
150
|
+
const resolutions = () =>
|
|
151
|
+
(all ??= (async () => {
|
|
152
|
+
// The pull request's op, as `prOp` (../pr-loop.ts) names it, and the spec's.
|
|
153
|
+
const ops = [...new Set([`pr-${input.pr}`, input.spec.name])];
|
|
154
|
+
return (await Promise.all(ops.map((op) => resolutionsOf(op)))).flat();
|
|
155
|
+
})());
|
|
156
|
+
return async (gate: string | undefined, digest: string | undefined): Promise<{ approvedBy?: string; reason: string }> => {
|
|
157
|
+
if (!gate) return { reason: "the spec at base names no approvals.pullRequest.gate" };
|
|
158
|
+
if (!digest) return { reason: `the plans of ${short(input.head)} carry no change set to check the pull request's approval against` };
|
|
159
|
+
const fresh = await changeSetOf(digest).catch(() => undefined);
|
|
160
|
+
if (!fresh) return { reason: `the change set ${digest} of ${short(input.head)} is not stored` };
|
|
161
|
+
const approvals = (await resolutions()).filter((r) => r.gate === gate && (r.changeSet ?? r.planDigest)).sort((a, b) => (a.timestamp < b.timestamp ? 1 : -1));
|
|
162
|
+
if (approvals.length === 0) return { reason: `the pull request's gate ${gate} has no approval` };
|
|
163
|
+
const { planCoveredBy } = await import("../components/pr-run");
|
|
164
|
+
let reason = `no approval at ${gate} covers its plans`;
|
|
165
|
+
for (const r of approvals) {
|
|
166
|
+
const approvedDigest = (r.changeSet ?? r.planDigest)!;
|
|
167
|
+
const approved = approvedDigest === fresh.digest ? fresh : await changeSetOf(approvedDigest).catch(() => undefined);
|
|
168
|
+
if (!approved) {
|
|
169
|
+
reason = `the change set ${approvedDigest} the approval at ${gate} names is not stored`;
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
const why = fresh.members.map((m) => planCoveredBy(approved, fresh, m.member)).find((w) => w !== undefined);
|
|
173
|
+
if (why === undefined) return { approvedBy: r.resolvedBy, reason: "" };
|
|
174
|
+
reason = why;
|
|
175
|
+
}
|
|
176
|
+
return { reason };
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** Post the status on the head. Returns what was posted. */
|
|
181
|
+
export async function postApprovalStatus(
|
|
182
|
+
input: ApprovalStatusInput & { forge: Pick<PrForge, "prApproved" | "kind" | "setStatus" | "runUrl"> },
|
|
183
|
+
words: CiProductWords = activeProductWords(),
|
|
184
|
+
): Promise<ApprovalStatus> {
|
|
185
|
+
const status = await approvalStatusOf(input);
|
|
186
|
+
await input.forge.setStatus(input.head, {
|
|
187
|
+
context: productStatusContext(words, "approval"),
|
|
188
|
+
state: status.state,
|
|
189
|
+
description: status.description,
|
|
190
|
+
...(input.forge.runUrl ? { url: input.forge.runUrl } : {}),
|
|
191
|
+
});
|
|
192
|
+
return status;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Post the status on every open pull request into `branch` (#4630), for
|
|
197
|
+
* GitLab's scheduled pipeline: the forge names each head and base. One
|
|
198
|
+
* that fails is a warning, and the rest are posted.
|
|
199
|
+
*/
|
|
200
|
+
export async function postOpenApprovalStatuses(
|
|
201
|
+
input: Omit<ApprovalStatusInput, "pr" | "head" | "base"> & { forge: Pick<PrForge, "prApproved" | "kind" | "setStatus" | "runUrl" | "openPullRequests">; branch: string },
|
|
202
|
+
words: CiProductWords = activeProductWords(),
|
|
203
|
+
): Promise<{ posted: Array<{ pr: number; status: ApprovalStatus }>; warnings: string[] }> {
|
|
204
|
+
if (!input.forge.openPullRequests) throw new Error(`${input.forge.kind} cannot list its open pull requests, so --open is not for it`);
|
|
205
|
+
const posted: Array<{ pr: number; status: ApprovalStatus }> = [];
|
|
206
|
+
const warnings: string[] = [];
|
|
207
|
+
for (const open of await input.forge.openPullRequests(input.branch)) {
|
|
208
|
+
if (open.fork) continue;
|
|
209
|
+
try {
|
|
210
|
+
const status = await postApprovalStatus({ ...input, pr: open.number, head: open.headSha, base: open.baseSha ?? input.branch }, words);
|
|
211
|
+
posted.push({ pr: open.number, status });
|
|
212
|
+
} catch (err) {
|
|
213
|
+
warnings.push(`!${open.number}: ${err instanceof Error ? err.message : String(err)}`);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return { posted, warnings };
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
async function ledgerHeadPlans(name: string, head: string, cwd: string): Promise<HeadPlans | null> {
|
|
220
|
+
const { gitLedgerReadPort, requireLifecycleLedger } = await import("../lifecycle/git");
|
|
221
|
+
const { readHeadPlans } = await import("../lifecycle/wave-plans");
|
|
222
|
+
await requireLifecycleLedger({ cwd });
|
|
223
|
+
return readHeadPlans(gitLedgerReadPort({ cwd }), name, head);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
async function ledgerResolutions(op: string, cwd: string): Promise<GateResolutionRecord[]> {
|
|
227
|
+
const { readGateLedger } = await import("../lifecycle/gate-ledger");
|
|
228
|
+
return (await readGateLedger(op, { cwd })).resolutions;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
async function ledgerChangeSet(digest: string, cwd: string): Promise<ChangeSetDocument | undefined> {
|
|
232
|
+
const { readStoredChangeSet } = await import("../lifecycle/change-set-store");
|
|
233
|
+
const got = await readStoredChangeSet(digest, { cwd });
|
|
234
|
+
return got.status === "found" ? got.document : undefined;
|
|
235
|
+
}
|
|
@@ -177,7 +177,8 @@ describe("a pr-review wave (#3684)", () => {
|
|
|
177
177
|
const h = harness(digest("a"));
|
|
178
178
|
let written: unknown;
|
|
179
179
|
const recorded = await recordOpWaveHeadPlans({ spec: spec("pr-review"), cwd: h.cwd, exec: h.exec, head: HEAD, now: "t", write: async (p) => void (written = p) });
|
|
180
|
-
|
|
180
|
+
// #4630: the record keeps whether the wave changes anything and whether it is destructive.
|
|
181
|
+
expect(recorded.waves).toEqual([{ wave: 1, name: "prod", digest: set(digest("a")), changes: true, destructive: false }]);
|
|
181
182
|
expect(written).toEqual(recorded);
|
|
182
183
|
});
|
|
183
184
|
});
|
package/src/op/index.ts
CHANGED
|
@@ -11,6 +11,7 @@ import type { OpWavesSpec } from "./op-waves";
|
|
|
11
11
|
import { assertOpWavesSpec } from "./op-waves";
|
|
12
12
|
import { runOpWave, opWavePlanPath, type OpWaveShowAtBase } from "./op-waves-run";
|
|
13
13
|
import { memoryGateLedgerPort } from "./gate";
|
|
14
|
+
import { NEXT_RELEASE } from "../release-floors";
|
|
14
15
|
import { CapabilityRegistry, type Capability } from "../components/capability";
|
|
15
16
|
import type { ChangeSetPart } from "../change-set";
|
|
16
17
|
import type { OpRunRecordInput } from "./runtime";
|
|
@@ -274,3 +275,14 @@ describe("after-plan hooks in the job's process (#4614)", () => {
|
|
|
274
275
|
expect(activeProductWaveHook()).toBeUndefined();
|
|
275
276
|
});
|
|
276
277
|
});
|
|
278
|
+
|
|
279
|
+
describe("opWavePlanPath", () => {
|
|
280
|
+
test("is exported from the op entry beside opWavePlansPath, and names one target's plan file", async () => {
|
|
281
|
+
const entry = await import("./index");
|
|
282
|
+
expect(entry.opWavePlanPath).toBe(opWavePlanPath);
|
|
283
|
+
expect(entry.OP_WAVE_PLAN_PATH_FLOOR).toBe(NEXT_RELEASE);
|
|
284
|
+
const spec = { name: "demo" };
|
|
285
|
+
expect(entry.opWavePlanPath(spec, 2, "stacks/a b")).toBe(".chant/op-waves/demo/wave-2/stacks_a_b.plan.json");
|
|
286
|
+
expect(entry.opWavePlanPath(spec, 2, "x")).not.toBe(entry.opWavePlansPath(spec, 2));
|
|
287
|
+
});
|
|
288
|
+
});
|
|
@@ -73,6 +73,26 @@ export function opWaveStepProblems(spec: Pick<OpWavesSpec, "step" | "plan" | "ap
|
|
|
73
73
|
return problems;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
/**
|
|
77
|
+
* What is wrong with the spec's and each wave's `parallelism` (#4625), empty
|
|
78
|
+
* when nothing is. Runs applied at once need the capability step, whose
|
|
79
|
+
* apply is one call per run with no gate in it. The whole-number check
|
|
80
|
+
* matches ../parallelism.ts's parallelismProblem, kept here so the spec
|
|
81
|
+
* module (and the bundles that hold it) do not load that file's run loop.
|
|
82
|
+
*/
|
|
83
|
+
export function opWaveParallelismProblems(spec: Pick<OpWavesSpec, "parallelism" | "step" | "waves">): string[] {
|
|
84
|
+
const problems: string[] = [];
|
|
85
|
+
for (const [field, value] of [["parallelism", spec.parallelism] as const, ...spec.waves.map((w) => [`wave "${w.name}" parallelism`, w.parallelism] as const)]) {
|
|
86
|
+
if (value === undefined) continue;
|
|
87
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 1) {
|
|
88
|
+
problems.push(`${field} is ${JSON.stringify(value)}; give a whole number of 1 or more, the most that run at once`);
|
|
89
|
+
} else if (value > 1 && spec.step === undefined) {
|
|
90
|
+
problems.push(`${field} is ${value}, and runs apply at once only through \`step\`; drop it or give step`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return problems;
|
|
94
|
+
}
|
|
95
|
+
|
|
76
96
|
/** What is wrong with a spec's `holds`, empty when nothing is. */
|
|
77
97
|
export function opWaveHoldsProblems(holds: unknown): string[] {
|
|
78
98
|
if (holds === undefined) return [];
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs a wave applies at once (#4625): `parallelism` on the spec or a wave,
|
|
3
|
+
* with a capability step, at most that many applies in flight, a run
|
|
4
|
+
* waiting for an earlier run it depends on and blocked when that failed.
|
|
5
|
+
* Written for the ci-products post-merge pass.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { describe, expect, test } from "vitest";
|
|
9
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
import { tmpdir } from "node:os";
|
|
12
|
+
import { assertOpWavesSpec, type OpWavesSpec } from "./op-waves";
|
|
13
|
+
import { runOpWave, type OpWaveShowAtBase } from "./op-waves-run";
|
|
14
|
+
import { memoryGateLedgerPort } from "./gate";
|
|
15
|
+
import { CapabilityRegistry, type Capability } from "../components/capability";
|
|
16
|
+
|
|
17
|
+
const digest = (n: string) => `sha256:${n.repeat(64)}`;
|
|
18
|
+
|
|
19
|
+
function capability(opts: { fail?: string[]; delayMs?: number } = {}) {
|
|
20
|
+
const seen = { running: 0, most: 0, order: [] as string[] };
|
|
21
|
+
const cap: Capability<Record<string, unknown>, unknown> = {
|
|
22
|
+
kind: "fake-apply",
|
|
23
|
+
async plan(_ctx, input) {
|
|
24
|
+
const root = String(input.root);
|
|
25
|
+
return { member: root, planDigest: digest("1"), artifact: {}, changeSet: { member: { member: root, lexicon: "terraform", planner: "chant", status: "planned", planDigest: digest("1"), holes: [] }, entries: [] } };
|
|
26
|
+
},
|
|
27
|
+
async run(_ctx, input) {
|
|
28
|
+
const root = String(input.root);
|
|
29
|
+
seen.running++;
|
|
30
|
+
seen.most = Math.max(seen.most, seen.running);
|
|
31
|
+
await new Promise((r) => setTimeout(r, opts.delayMs ?? 5));
|
|
32
|
+
seen.running--;
|
|
33
|
+
seen.order.push(root);
|
|
34
|
+
if (opts.fail?.includes(root)) throw new Error(`${root} broke`);
|
|
35
|
+
return { applied: root };
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
return { registry: new CapabilityRegistry().register(cap), seen };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const spec = (parallelism: number, runs: OpWavesSpec["waves"][number]["runs"]): OpWavesSpec => ({
|
|
42
|
+
name: "roots",
|
|
43
|
+
op: "tf-apply",
|
|
44
|
+
parallelism,
|
|
45
|
+
step: { kind: "fake-apply", root: "{target}" },
|
|
46
|
+
waves: [{ name: "dev", runs, gate: "never" }],
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
async function run(s: OpWavesSpec, registry: CapabilityRegistry) {
|
|
50
|
+
const cwd = mkdtempSync(join(tmpdir(), "op-waves-par-"));
|
|
51
|
+
const show: OpWaveShowAtBase = () => ({ sha: "b".repeat(40), text: JSON.stringify(s) });
|
|
52
|
+
try {
|
|
53
|
+
return await runOpWave({ spec: s, specFile: "waves.json", wave: 1, cwd, show, gates: memoryGateLedgerPort(), capabilities: registry });
|
|
54
|
+
} finally {
|
|
55
|
+
rmSync(cwd, { recursive: true, force: true });
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
describe("runs applied at once (#4625)", () => {
|
|
60
|
+
test("at most parallelism applies in flight, and the result keeps the wave's order", async () => {
|
|
61
|
+
const { registry, seen } = capability();
|
|
62
|
+
const result = await run(spec(2, [{ target: "a" }, { target: "b" }, { target: "c" }, { target: "d" }]), registry);
|
|
63
|
+
expect(result).toMatchObject({ exitCode: 0, applied: ["a", "b", "c", "d"] });
|
|
64
|
+
expect(seen.most).toBe(2);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test("a run waits for an earlier run it depends on, and is blocked when that one failed", async () => {
|
|
68
|
+
const { registry, seen } = capability({ fail: ["a"] });
|
|
69
|
+
const result = await run(spec(3, [{ target: "a" }, { target: "b", dependsOn: ["a"] }, { target: "c" }, { target: "d", dependsOn: ["b"] }]), registry);
|
|
70
|
+
expect(result.exitCode).toBe(1);
|
|
71
|
+
expect(result.failed).toEqual(["a"]);
|
|
72
|
+
expect(result.applied).toEqual(["c"]);
|
|
73
|
+
expect(result.blocked).toEqual({ b: "a", d: "a" });
|
|
74
|
+
expect(seen.order).not.toContain("b");
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test("one at a time when the spec says nothing", async () => {
|
|
78
|
+
const { registry, seen } = capability();
|
|
79
|
+
const { parallelism: _p, ...plain } = spec(1, [{ target: "a" }, { target: "b" }]);
|
|
80
|
+
await run(plain, registry);
|
|
81
|
+
expect(seen.most).toBe(1);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test("the spec refuses a parallelism over 1 without a step, and one that is not a whole number", () => {
|
|
85
|
+
const { step: _s, ...noStep } = spec(2, [{ target: "a" }]);
|
|
86
|
+
expect(() => assertOpWavesSpec({ ...noStep, apply: ["./apply", "{target}"], plan: ["./plan", "{target}", "{plan}"] })).toThrow(/apply at once only through `step`/);
|
|
87
|
+
expect(() => assertOpWavesSpec(spec(0, [{ target: "a" }]))).toThrow(/whole number of 1 or more/);
|
|
88
|
+
});
|
|
89
|
+
});
|