@intentius/chant 0.124.86 → 0.124.88
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/action-pins.d.ts +1 -0
- package/dist/action-pins.d.ts.map +1 -1
- package/dist/action-pins.js +2 -0
- package/dist/actor.d.ts +12 -0
- package/dist/actor.d.ts.map +1 -0
- package/dist/actor.js +18 -0
- package/dist/bundle-check.d.ts +20 -5
- package/dist/bundle-check.d.ts.map +1 -1
- package/dist/bundle-check.js +20 -5
- package/dist/chant-install.d.ts +98 -0
- package/dist/chant-install.d.ts.map +1 -1
- package/dist/chant-install.js +204 -2
- package/dist/ci-commit.d.ts.map +1 -1
- package/dist/ci-commit.js +1 -2
- package/dist/ci-control.d.ts +1 -1
- package/dist/ci-control.d.ts.map +1 -1
- package/dist/ci-control.js +1 -1
- package/dist/ci-evidence-claims.d.ts +59 -0
- package/dist/ci-evidence-claims.d.ts.map +1 -0
- package/dist/ci-evidence-claims.js +87 -0
- package/dist/ci-evidence-from-job.d.ts +103 -0
- package/dist/ci-evidence-from-job.d.ts.map +1 -0
- package/dist/ci-evidence-from-job.js +162 -0
- package/dist/ci-evidence-jobs.d.ts +69 -10
- package/dist/ci-evidence-jobs.d.ts.map +1 -1
- package/dist/ci-evidence-jobs.js +72 -8
- package/dist/ci-handover.d.ts +12 -0
- package/dist/ci-handover.d.ts.map +1 -1
- package/dist/ci-handover.js +15 -3
- package/dist/ci-identity.d.ts +32 -6
- package/dist/ci-identity.d.ts.map +1 -1
- package/dist/ci-identity.js +40 -8
- package/dist/ci-image.d.ts +47 -9
- package/dist/ci-image.d.ts.map +1 -1
- package/dist/ci-image.js +45 -18
- package/dist/ci-jobs.d.ts +1 -1
- package/dist/ci-jobs.d.ts.map +1 -1
- package/dist/ci-jobs.js +7 -2
- package/dist/ci-login.d.ts +75 -13
- package/dist/ci-login.d.ts.map +1 -1
- package/dist/ci-login.js +89 -37
- package/dist/ci-product-words.d.ts +20 -1
- package/dist/ci-product-words.d.ts.map +1 -1
- package/dist/ci-product-words.js +27 -1
- package/dist/ci-product.d.ts +20 -1
- package/dist/ci-product.d.ts.map +1 -1
- package/dist/ci-product.js +21 -2
- package/dist/cli/handlers/approve-confirm.d.ts +14 -0
- package/dist/cli/handlers/approve-confirm.d.ts.map +1 -1
- package/dist/cli/handlers/approve-confirm.js +46 -0
- package/dist/cli/handlers/build.d.ts +1 -1
- package/dist/cli/handlers/build.d.ts.map +1 -1
- package/dist/cli/handlers/build.js +22 -1
- package/dist/cli/handlers/ci-check.d.ts.map +1 -1
- package/dist/cli/handlers/ci-check.js +38 -14
- package/dist/cli/handlers/ci-evidence.d.ts.map +1 -1
- package/dist/cli/handlers/ci-evidence.js +238 -26
- package/dist/cli/handlers/ci-forge-check.d.ts.map +1 -1
- package/dist/cli/handlers/ci-forge-check.js +34 -17
- package/dist/cli/handlers/generated-check.d.ts +3 -0
- package/dist/cli/handlers/generated-check.d.ts.map +1 -0
- package/dist/cli/handlers/generated-check.js +41 -0
- package/dist/cli/handlers/lifecycle.d.ts.map +1 -1
- package/dist/cli/handlers/lifecycle.js +3 -0
- package/dist/cli/handlers/local-chant.d.ts +13 -0
- package/dist/cli/handlers/local-chant.d.ts.map +1 -1
- package/dist/cli/handlers/local-chant.js +42 -1
- package/dist/cli/handlers/pr.d.ts.map +1 -1
- package/dist/cli/handlers/pr.js +42 -5
- package/dist/cli/handlers/run-wave.js +8 -0
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +38 -4
- package/dist/cli/parse-args.d.ts.map +1 -1
- package/dist/cli/parse-args.js +66 -0
- package/dist/cli/registry.d.ts +24 -0
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/components/check-hooks.d.ts +10 -0
- package/dist/components/check-hooks.d.ts.map +1 -1
- package/dist/components/check-hooks.js +21 -3
- package/dist/components/check-steps.js +1 -1
- package/dist/components/pr-checks.d.ts +105 -0
- package/dist/components/pr-checks.d.ts.map +1 -0
- package/dist/components/pr-checks.js +119 -0
- package/dist/components/pr-pipeline.d.ts +34 -0
- package/dist/components/pr-pipeline.d.ts.map +1 -1
- package/dist/components/pr-pipeline.js +14 -1
- package/dist/components/product-pipeline.d.ts +16 -1
- package/dist/components/product-pipeline.d.ts.map +1 -1
- package/dist/components/product-pipeline.js +17 -2
- package/dist/components/product-plan.d.ts +262 -3
- package/dist/components/product-plan.d.ts.map +1 -1
- package/dist/components/product-plan.js +243 -11
- package/dist/config.d.ts +10 -6
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +11 -6
- package/dist/control/consumers.d.ts +6 -0
- package/dist/control/consumers.d.ts.map +1 -1
- package/dist/control/consumers.js +6 -0
- package/dist/dead-guards.d.ts.map +1 -1
- package/dist/dead-guards.js +9 -6
- package/dist/discovery/files.d.ts +1 -1
- package/dist/discovery/files.js +1 -1
- package/dist/drift-issue.d.ts +20 -3
- package/dist/drift-issue.d.ts.map +1 -1
- package/dist/drift-issue.js +16 -0
- package/dist/drift-record.d.ts +45 -5
- package/dist/drift-record.d.ts.map +1 -1
- package/dist/drift-record.js +27 -6
- package/dist/floor-table.d.ts +6 -6
- package/dist/floor-table.d.ts.map +1 -1
- package/dist/floor-table.data.d.ts.map +1 -1
- package/dist/floor-table.data.js +58 -20
- package/dist/floor-table.js +10 -7
- package/dist/forge-check/contract.d.ts +8 -0
- 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/forge-flags.d.ts +10 -0
- package/dist/forge-flags.d.ts.map +1 -1
- package/dist/forge-flags.js +31 -0
- package/dist/forge-remote.d.ts +47 -0
- package/dist/forge-remote.d.ts.map +1 -0
- package/dist/forge-remote.js +69 -0
- package/dist/generated-check.d.ts +74 -0
- package/dist/generated-check.d.ts.map +1 -0
- package/dist/generated-check.js +216 -0
- package/dist/lexicon.d.ts +16 -0
- package/dist/lexicon.d.ts.map +1 -1
- package/dist/lifecycle/publish-npm.d.ts +15 -0
- package/dist/lifecycle/publish-npm.d.ts.map +1 -1
- package/dist/lifecycle/publish-npm.js +49 -3
- package/dist/lifecycle/release-images.d.ts +22 -1
- package/dist/lifecycle/release-images.d.ts.map +1 -1
- package/dist/lifecycle/release-images.js +27 -3
- package/dist/lifecycle/release-ledger.d.ts +4 -3
- package/dist/lifecycle/release-ledger.d.ts.map +1 -1
- package/dist/lifecycle/release-ledger.js +3 -2
- package/dist/local-chant.d.ts +57 -3
- package/dist/local-chant.d.ts.map +1 -1
- package/dist/local-chant.js +122 -13
- package/dist/op/op-waves-evidence-jobs.d.ts +92 -0
- package/dist/op/op-waves-evidence-jobs.d.ts.map +1 -0
- package/dist/op/op-waves-evidence-jobs.js +112 -0
- package/dist/op/op-waves-evidence.d.ts +17 -4
- package/dist/op/op-waves-evidence.d.ts.map +1 -1
- package/dist/op/op-waves-evidence.js +32 -10
- package/dist/op/op-waves-run.d.ts +12 -1
- package/dist/op/op-waves-run.d.ts.map +1 -1
- package/dist/op/op-waves-run.js +54 -3
- package/dist/op/op-waves.d.ts +8 -0
- package/dist/op/op-waves.d.ts.map +1 -1
- package/dist/op/op-waves.js +10 -0
- package/dist/op/schedule-overdue.d.ts +39 -2
- package/dist/op/schedule-overdue.d.ts.map +1 -1
- package/dist/op/schedule-overdue.js +89 -7
- package/dist/pr-forge-reads.d.ts +21 -1
- package/dist/pr-forge-reads.d.ts.map +1 -1
- package/dist/pr-forge-reads.js +19 -1
- package/dist/pr-forge.d.ts +7 -1
- package/dist/pr-forge.d.ts.map +1 -1
- package/dist/pr-forge.js +7 -2
- package/dist/pr-plan-note.d.ts +24 -0
- package/dist/pr-plan-note.d.ts.map +1 -1
- package/dist/pr-plan-note.js +11 -1
- package/dist/pr-plan-record.d.ts +47 -0
- package/dist/pr-plan-record.d.ts.map +1 -0
- package/dist/pr-plan-record.js +89 -0
- package/dist/pr-post.d.ts +40 -0
- package/dist/pr-post.d.ts.map +1 -1
- package/dist/pr-post.js +79 -6
- package/dist/pr-requires.d.ts +8 -0
- package/dist/pr-requires.d.ts.map +1 -1
- package/dist/pr-requires.js +3 -1
- package/dist/ref-gate-init.d.ts +76 -0
- package/dist/ref-gate-init.d.ts.map +1 -0
- package/dist/ref-gate-init.js +144 -0
- package/dist/ref-gate-rules.d.ts +19 -0
- package/dist/ref-gate-rules.d.ts.map +1 -0
- package/dist/ref-gate-rules.js +17 -0
- package/dist/release-floors.d.ts +51 -1
- package/dist/release-floors.d.ts.map +1 -1
- package/dist/release-floors.js +66 -16
- package/dist/state-migration.d.ts +23 -0
- package/dist/state-migration.d.ts.map +1 -1
- package/dist/state-migration.js +39 -3
- package/dist/state-unlock.d.ts +32 -1
- package/dist/state-unlock.d.ts.map +1 -1
- package/dist/state-unlock.js +31 -0
- package/dist/wave-runtime.mjs +310 -303
- package/dist/workspace/ci-green-cli.d.ts.map +1 -1
- package/dist/workspace/ci-green-cli.js +13 -7
- package/dist/workspace/ci-green.d.ts.map +1 -1
- package/dist/workspace/ci-green.js +4 -3
- package/dist/workspace/drift-cli.d.ts +1 -1
- package/dist/workspace/drift-cli.d.ts.map +1 -1
- package/dist/workspace/drift-cli.js +5 -12
- package/dist/workspace/forge-work.d.ts +3 -2
- package/dist/workspace/forge-work.d.ts.map +1 -1
- package/dist/workspace/forge-work.js +7 -17
- package/dist/workspace/lexicon-outputs.js +2 -2
- package/dist/workspace/release-workflow.d.ts +26 -3
- package/dist/workspace/release-workflow.d.ts.map +1 -1
- package/dist/workspace/release-workflow.js +48 -6
- package/dist/workspace/trust/check-evidence-report.d.ts +25 -0
- package/dist/workspace/trust/check-evidence-report.d.ts.map +1 -1
- package/dist/workspace/trust/check-evidence-report.js +20 -0
- package/dist/workspace/trust/check-evidence.d.ts +59 -13
- package/dist/workspace/trust/check-evidence.d.ts.map +1 -1
- package/dist/workspace/trust/check-evidence.js +101 -24
- package/dist/workspace/trust/ci-tag-statement.d.ts +2 -2
- package/dist/workspace/trust/ci-tag-statement.d.ts.map +1 -1
- package/dist/workspace/trust/dsse.d.ts +40 -2
- package/dist/workspace/trust/dsse.d.ts.map +1 -1
- package/dist/workspace/trust/dsse.js +34 -2
- package/dist/workspace/trust/evidence.d.ts +7 -2
- package/dist/workspace/trust/evidence.d.ts.map +1 -1
- package/dist/workspace/trust/evidence.js +5 -0
- package/dist/workspace/trust/keyless-fixture.d.ts +41 -0
- package/dist/workspace/trust/keyless-fixture.d.ts.map +1 -0
- package/dist/workspace/trust/keyless-fixture.js +161 -0
- package/dist/workspace/trust/keyless.d.ts +202 -0
- package/dist/workspace/trust/keyless.d.ts.map +1 -0
- package/dist/workspace/trust/keyless.js +488 -0
- package/dist/workspace/trust/local-evidence.d.ts +3 -0
- package/dist/workspace/trust/local-evidence.d.ts.map +1 -1
- package/dist/workspace/trust/op-run-statement.d.ts +2 -2
- package/dist/workspace/trust/op-run-statement.d.ts.map +1 -1
- package/dist/workspace/trust/open-evidence.d.ts +67 -0
- package/dist/workspace/trust/open-evidence.d.ts.map +1 -0
- package/dist/workspace/trust/open-evidence.js +92 -0
- package/dist/workspace/trust/policy.d.ts +56 -1
- package/dist/workspace/trust/policy.d.ts.map +1 -1
- package/dist/workspace/trust/policy.js +103 -2
- package/dist/workspace/trust/ref-gate-cli.d.ts.map +1 -1
- package/dist/workspace/trust/ref-gate-cli.js +65 -3
- package/dist/workspace/trust/ref-gate.d.ts +62 -3
- package/dist/workspace/trust/ref-gate.d.ts.map +1 -1
- package/dist/workspace/trust/ref-gate.js +75 -8
- package/dist/workspace/trust/run-statement.d.ts +3 -3
- package/dist/workspace/trust/run-statement.d.ts.map +1 -1
- package/dist/workspace/trust/runner-identity.d.ts +56 -0
- package/dist/workspace/trust/runner-identity.d.ts.map +1 -0
- package/dist/workspace/trust/runner-identity.js +65 -0
- package/dist/workspace/trust/trust-files.d.ts.map +1 -1
- package/dist/workspace/trust/trust-files.js +8 -1
- package/package.json +1 -1
- package/src/action-pins.ts +2 -0
- package/src/actor.test.ts +12 -0
- package/src/actor.ts +19 -0
- package/src/bundle-check.test.ts +22 -0
- package/src/bundle-check.ts +33 -5
- package/src/chant-install.test.ts +109 -1
- package/src/chant-install.ts +243 -2
- package/src/ci-commit.test.ts +51 -5
- package/src/ci-commit.ts +1 -2
- package/src/ci-control.ts +1 -0
- package/src/ci-evidence-claims.ts +102 -0
- package/src/ci-evidence-from-job.test.ts +147 -0
- package/src/ci-evidence-from-job.ts +195 -0
- package/src/ci-evidence-jobs.ts +85 -10
- package/src/ci-handover.ts +16 -3
- package/src/ci-identity.test.ts +3 -3
- package/src/ci-identity.ts +51 -11
- package/src/ci-image.test.ts +60 -10
- package/src/ci-image.ts +78 -19
- package/src/ci-jobs.ts +7 -2
- package/src/ci-login.test.ts +131 -3
- package/src/ci-login.token-drop.test.ts +204 -0
- package/src/ci-login.ts +137 -39
- package/src/ci-product-words.ts +30 -0
- package/src/ci-product.ts +26 -1
- package/src/cli/commands/__fixtures__/source-dir-root/migrations/0001-init/backfill.ts +3 -0
- package/src/cli/handlers/approve-confirm.test.ts +35 -0
- package/src/cli/handlers/approve-confirm.ts +44 -0
- package/src/cli/handlers/build-source-dir.test.ts +4 -0
- package/src/cli/handlers/build.ts +20 -2
- package/src/cli/handlers/ci-check.ts +35 -13
- package/src/cli/handlers/ci-evidence-open.test.ts +164 -0
- package/src/cli/handlers/ci-evidence.ts +223 -24
- package/src/cli/handlers/ci-forge-check.ts +22 -9
- package/src/cli/handlers/generated-check.ts +39 -0
- package/src/cli/handlers/lifecycle.test.ts +20 -0
- package/src/cli/handlers/lifecycle.ts +4 -0
- package/src/cli/handlers/local-chant.ts +39 -1
- package/src/cli/handlers/pr.ts +43 -5
- package/src/cli/handlers/run-wave.ts +7 -0
- package/src/cli/main.ts +38 -4
- package/src/cli/parse-args.ts +46 -0
- package/src/cli/registry.ts +24 -0
- package/src/components/check-hooks.ts +25 -3
- package/src/components/check-report-summary.test.ts +78 -0
- package/src/components/check-steps.ts +1 -1
- package/src/components/pr-checks.ts +159 -0
- package/src/components/pr-pipeline.ts +41 -1
- package/src/components/product-pipeline.ts +25 -3
- package/src/components/product-plan.test.ts +102 -1
- package/src/components/product-plan.ts +419 -14
- package/src/config.ts +13 -8
- package/src/control/consumers.ts +7 -0
- package/src/dead-guards.test.ts +27 -5
- package/src/dead-guards.ts +9 -6
- package/src/discovery/files.ts +1 -1
- package/src/drift-issue.test.ts +29 -1
- package/src/drift-issue.ts +28 -3
- package/src/drift-record.test.ts +25 -0
- package/src/drift-record.ts +55 -6
- package/src/floor-table.data.ts +58 -20
- package/src/floor-table.ts +12 -9
- package/src/forge-check/contract.ts +11 -1
- package/src/forge-check/forge-check.test.ts +8 -0
- package/src/forge-check/index.ts +2 -0
- package/src/forge-flags.test.ts +25 -1
- package/src/forge-flags.ts +34 -0
- package/src/forge-remote.test.ts +37 -0
- package/src/forge-remote.ts +79 -0
- package/src/generated-check.e2e.test.ts +98 -0
- package/src/generated-check.test.ts +104 -0
- package/src/generated-check.ts +269 -0
- package/src/lexicon.ts +17 -0
- package/src/lifecycle/publish-npm.ts +56 -3
- package/src/lifecycle/release-catalog.test.ts +2 -2
- package/src/lifecycle/release-images-dockerfile.test.ts +20 -0
- package/src/lifecycle/release-images.test.ts +44 -0
- package/src/lifecycle/release-images.ts +39 -3
- package/src/lifecycle/release-ledger.ts +4 -3
- package/src/local-chant.e2e.test.ts +81 -6
- package/src/local-chant.test.ts +22 -3
- package/src/local-chant.ts +130 -13
- package/src/op/op-waves-evidence-jobs.ts +134 -0
- package/src/op/op-waves-evidence.test.ts +37 -4
- package/src/op/op-waves-evidence.ts +32 -11
- package/src/op/op-waves-run.ts +57 -2
- package/src/op/op-waves.ts +11 -0
- package/src/op/schedule-overdue.test.ts +83 -1
- package/src/op/schedule-overdue.ts +107 -9
- package/src/pr-forge-reads-compare.test.ts +2 -1
- package/src/pr-forge-reads.ts +37 -1
- package/src/pr-forge.ts +14 -3
- package/src/pr-plan-note.ts +32 -3
- package/src/pr-plan-record.test.ts +75 -0
- package/src/pr-plan-record.ts +101 -0
- package/src/pr-post-plan-note.test.ts +60 -0
- package/src/pr-post.test.ts +30 -0
- package/src/pr-post.ts +110 -6
- package/src/pr-requires.test.ts +20 -0
- package/src/pr-requires.ts +10 -1
- package/src/ref-gate-init.ts +189 -0
- package/src/ref-gate-rules.ts +26 -0
- package/src/release-floors.ts +88 -16
- package/src/state-migration-record.test.ts +90 -0
- package/src/state-migration.test.ts +1 -1
- package/src/state-migration.ts +52 -3
- package/src/state-unlock.test.ts +33 -1
- package/src/state-unlock.ts +49 -1
- package/src/workspace/ci-green-cli.ts +12 -6
- package/src/workspace/ci-green.ts +4 -3
- package/src/workspace/drift-cli.ts +6 -18
- package/src/workspace/forge-work.ts +7 -14
- package/src/workspace/lexicon-outputs.ts +2 -2
- package/src/workspace/release-workflow.test.ts +70 -0
- package/src/workspace/release-workflow.ts +56 -8
- package/src/workspace/trust/check-evidence-report.ts +33 -0
- package/src/workspace/trust/check-evidence.test.ts +3 -3
- package/src/workspace/trust/check-evidence.ts +110 -28
- package/src/workspace/trust/ci-tag-statement.ts +2 -2
- package/src/workspace/trust/dsse.ts +48 -4
- package/src/workspace/trust/evidence.ts +7 -2
- package/src/workspace/trust/keyless-fixture.ts +214 -0
- package/src/workspace/trust/keyless.test.ts +220 -0
- package/src/workspace/trust/keyless.ts +557 -0
- package/src/workspace/trust/local-evidence.ts +3 -1
- package/src/workspace/trust/op-run-statement.ts +2 -2
- package/src/workspace/trust/open-evidence.ts +129 -0
- package/src/workspace/trust/policy.ts +129 -2
- package/src/workspace/trust/ref-gate-cli.ts +59 -3
- package/src/workspace/trust/ref-gate-pieces.test.ts +175 -0
- package/src/workspace/trust/ref-gate.e2e.test.ts +17 -0
- package/src/workspace/trust/ref-gate.ts +90 -8
- package/src/workspace/trust/run-statement.ts +3 -3
- package/src/workspace/trust/runner-identity.ts +92 -0
- package/src/workspace/trust/trust-files.test.ts +6 -0
- package/src/workspace/trust/trust-files.ts +14 -1
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `chant ci evidence sign --open` (#4914): the GitLab signing job, in a
|
|
3
|
+
* pipeline of the target branch, signs the checks of every open merge
|
|
4
|
+
* request into the branch from its newest pipeline's job.
|
|
5
|
+
*
|
|
6
|
+
* A merge request pipeline is built from the merge request's own files, so
|
|
7
|
+
* a job there that holds the runner key (or asks for a signing token) runs
|
|
8
|
+
* whatever the change wrote. The plan notes pipeline (#4328) is the target
|
|
9
|
+
* branch's: its jobs come from the branch's files, and its protected
|
|
10
|
+
* variables reach it. So the signing moves there, as the note posting did:
|
|
11
|
+
* for each open merge request GitLab names the newest pipeline's `job`
|
|
12
|
+
* (`plan`, `<target>-plan`, `check`), the report is read from that job's
|
|
13
|
+
* artifacts as data, the head is fetched, and the checks are signed for
|
|
14
|
+
* the head as `sign --from-report` signs them. What was signed and why the
|
|
15
|
+
* rest were not is kept as `<out>/<iid>/evidence.json`, with the merge
|
|
16
|
+
* request and the head, which the note job reads (`pr-post --open
|
|
17
|
+
* --evidence-dir`, ../../pr-post.ts) for the note's "Checks:" line.
|
|
18
|
+
*
|
|
19
|
+
* A job that has not settled is left for the next pipeline. A merge request
|
|
20
|
+
* whose report does not read, whose head does not fetch, or that the forge
|
|
21
|
+
* refuses is a warning, and the others go on.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
25
|
+
import { join } from "node:path";
|
|
26
|
+
import type { PrForge } from "../../pr-forge";
|
|
27
|
+
import { CHECK_EVIDENCE_FILE, type CheckEvidenceNote, type OpenEvidenceFile } from "./check-evidence-report";
|
|
28
|
+
|
|
29
|
+
/** The report files a job's artifact is read for, in order: a plan report, a product's plan note hand-off, then a check job's report. */
|
|
30
|
+
export const OPEN_PLAN_FILES = ["pr-plan.json", "pr-plan-note.json"] as const;
|
|
31
|
+
export const OPEN_CHECK_FILE = "check-hooks.json";
|
|
32
|
+
|
|
33
|
+
/** What {@link signOpenReports} signs for. */
|
|
34
|
+
export interface OpenEvidenceInput {
|
|
35
|
+
/**
|
|
36
|
+
* A GitLab client with {@link PrForge.mergeRequestJobs} and
|
|
37
|
+
* {@link PrForge.jobArtifact}, and with `noForks` {@link PrForge.openPullRequests},
|
|
38
|
+
* which says which merge requests come from a fork. The fork test is read
|
|
39
|
+
* here, not in `mergeRequestJobs`, to keep it out of the pull request loop's
|
|
40
|
+
* bundle (its ceiling, pr-loop-bundle.test.ts).
|
|
41
|
+
*/
|
|
42
|
+
forge: Pick<PrForge, "kind" | "mergeRequestJobs" | "jobArtifact" | "openPullRequests">;
|
|
43
|
+
/** The branch the merge requests merge into: the pipeline's own. */
|
|
44
|
+
branch: string;
|
|
45
|
+
/** The job whose report is signed: `plan`, `<target>-plan` or `check`. */
|
|
46
|
+
job: string;
|
|
47
|
+
/** The report directory from the repository root, as the job kept it as its artifact. */
|
|
48
|
+
artifactDir: string;
|
|
49
|
+
/** Where each merge request's report and `evidence.json` go: `<out>/<iid>/`. */
|
|
50
|
+
out: string;
|
|
51
|
+
/** Sign for no merge request from a fork, as a product plan with `forks: "skip"` plans none. */
|
|
52
|
+
noForks?: boolean;
|
|
53
|
+
/** Fetch merge request `pr`'s head into this checkout; true once the commit is here. */
|
|
54
|
+
fetchHead: (pr: number, head: string) => boolean;
|
|
55
|
+
/** Sign the checks of the report in `dir` for `head`, given the job's result, as `sign --from-report` does. */
|
|
56
|
+
sign: (dir: string, head: string, result: "success" | "failure" | "cancelled") => Promise<CheckEvidenceNote>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** What {@link signOpenReports} did for one merge request. */
|
|
60
|
+
export interface OpenEvidence {
|
|
61
|
+
pr: number;
|
|
62
|
+
head: string;
|
|
63
|
+
/** What was signed and what was not, as kept in `evidence.json`. */
|
|
64
|
+
note?: CheckEvidenceNote;
|
|
65
|
+
/** Why nothing was signed: the job has not settled, left no report, or its head did not fetch. */
|
|
66
|
+
skipped?: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Sign every open merge request's settled `job` into `branch` (#4914). */
|
|
70
|
+
export async function signOpenReports(input: OpenEvidenceInput): Promise<{ done: OpenEvidence[]; warnings: string[] }> {
|
|
71
|
+
const { forge } = input;
|
|
72
|
+
if (!forge.mergeRequestJobs || !forge.jobArtifact) {
|
|
73
|
+
throw new Error(`ci evidence sign --open reads the jobs of open merge requests, which ${forge.kind} cannot say; it is for GitLab`);
|
|
74
|
+
}
|
|
75
|
+
const done: OpenEvidence[] = [];
|
|
76
|
+
const warnings: string[] = [];
|
|
77
|
+
const at = input.artifactDir.replace(/\/+$/, "");
|
|
78
|
+
let forks = new Set<number>();
|
|
79
|
+
if (input.noForks) {
|
|
80
|
+
if (!forge.openPullRequests) throw new Error(`ci evidence sign --open --no-forks reads which merge requests come from a fork, which ${forge.kind} cannot say`);
|
|
81
|
+
forks = new Set((await forge.openPullRequests(input.branch)).filter((p) => p.fork).map((p) => p.number));
|
|
82
|
+
}
|
|
83
|
+
for (const job of await forge.mergeRequestJobs(input.branch, input.job)) {
|
|
84
|
+
if (forks.has(job.pr)) {
|
|
85
|
+
done.push({ pr: job.pr, head: job.head, skipped: "the merge request is from a fork" });
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
const result = job.status === "success" ? "success" : job.status === "failed" ? "failure" : job.status === "canceled" ? "cancelled" : undefined;
|
|
89
|
+
if (!result) {
|
|
90
|
+
done.push({ pr: job.pr, head: job.head, skipped: `the ${input.job} job is ${job.status}` });
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
const dir = join(input.out, String(job.pr));
|
|
95
|
+
mkdirSync(dir, { recursive: true });
|
|
96
|
+
// A plan report wins over a check report, as `sign --from-report` reads a directory.
|
|
97
|
+
let found = false;
|
|
98
|
+
for (const file of OPEN_PLAN_FILES) {
|
|
99
|
+
const text = await forge.jobArtifact(job.id, `${at}/${file}`);
|
|
100
|
+
if (text === undefined) continue;
|
|
101
|
+
writeFileSync(join(dir, file), text);
|
|
102
|
+
found = true;
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
if (!found) {
|
|
106
|
+
const text = await forge.jobArtifact(job.id, `${at}/${OPEN_CHECK_FILE}`);
|
|
107
|
+
if (text !== undefined) {
|
|
108
|
+
writeFileSync(join(dir, OPEN_CHECK_FILE), text);
|
|
109
|
+
found = true;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (!found) {
|
|
113
|
+
done.push({ pr: job.pr, head: job.head, skipped: `the ${input.job} job left no report under ${at}` });
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
if (!input.fetchHead(job.pr, job.head)) {
|
|
117
|
+
done.push({ pr: job.pr, head: job.head, skipped: `the head ${job.head.slice(0, 12)} did not fetch` });
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
const note = await input.sign(dir, job.head, result);
|
|
121
|
+
const kept: OpenEvidenceFile = { pr: job.pr, head: job.head, ...note };
|
|
122
|
+
writeFileSync(join(dir, CHECK_EVIDENCE_FILE), JSON.stringify(kept, null, 2) + "\n");
|
|
123
|
+
done.push({ pr: job.pr, head: job.head, note });
|
|
124
|
+
} catch (err) {
|
|
125
|
+
warnings.push(`!${job.pr}: ${err instanceof Error ? err.message : String(err)}`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return { done, warnings };
|
|
129
|
+
}
|
|
@@ -26,6 +26,9 @@ import { z } from "zod";
|
|
|
26
26
|
import type { RecordSource } from "../record-source";
|
|
27
27
|
import { DEFAULT_SIGNERS_PATH, TRUST_CONFIG_PATH, parseAllowedSigners, type ExcludedSigner, type Signer } from "./trust-files";
|
|
28
28
|
import type { PasskeySigner } from "../../lifecycle/gate-webauthn";
|
|
29
|
+
import { execFileSync } from "node:child_process";
|
|
30
|
+
import { DEFAULT_FULCIO_URL, DEFAULT_SIGNING_AUDIENCE, DEFAULT_TIMESTAMP_URL, keylessVerifier, parseTrustedRoot, type KeylessRoots } from "./keyless";
|
|
31
|
+
import type { DsseSignature, KeylessCheck } from "./dsse";
|
|
29
32
|
|
|
30
33
|
export {
|
|
31
34
|
DEFAULT_SIGNERS_PATH,
|
|
@@ -49,6 +52,9 @@ const repoPath = z
|
|
|
49
52
|
message: "a path inside the repository, with / separators and no ..",
|
|
50
53
|
});
|
|
51
54
|
|
|
55
|
+
/** An http or https URL (#4869): an OIDC issuer, a certificate or timestamp authority. */
|
|
56
|
+
const httpUrl = z.string().regex(/^https?:\/\/[^\s]+$/, "an http or https URL");
|
|
57
|
+
|
|
52
58
|
/** A check name a ref rule requires (#4867): it is also part of an override's subject. */
|
|
53
59
|
export const REF_CHECK_NAME = /^[A-Za-z0-9][A-Za-z0-9._:-]*$/;
|
|
54
60
|
/** A ref pattern (#4867): a full ref name, where `*` matches within one `/` segment and `**` matches across them. */
|
|
@@ -102,6 +108,40 @@ export const trustConfigSchema = z
|
|
|
102
108
|
.strict(),
|
|
103
109
|
)
|
|
104
110
|
.optional(),
|
|
111
|
+
/**
|
|
112
|
+
* CI identities that sign runner statements keyless (#4869): each an
|
|
113
|
+
* OIDC issuer and a pattern over the subject alternative name of the
|
|
114
|
+
* certificate the job's token was traded for, which names the
|
|
115
|
+
* repository, the workflow and the ref. `trustedRoot` is a file in
|
|
116
|
+
* sigstore's `trusted_root.json` format with the certificate and
|
|
117
|
+
* timestamp authorities. `fulcio`, `timestamp` and `audience` tell a
|
|
118
|
+
* signing job where to trade its token; sigstore's public instances by
|
|
119
|
+
* default. With `since`, a statement over that commit or any commit not
|
|
120
|
+
* a strict ancestor of it counts only when signed keyless; a runner key's
|
|
121
|
+
* statement over an earlier commit still counts.
|
|
122
|
+
*/
|
|
123
|
+
keyless: z
|
|
124
|
+
.object({
|
|
125
|
+
trustedRoot: repoPath,
|
|
126
|
+
identities: z
|
|
127
|
+
.array(
|
|
128
|
+
z
|
|
129
|
+
.object({
|
|
130
|
+
principal: z.string().min(1),
|
|
131
|
+
class: z.enum(["runner", "service"]),
|
|
132
|
+
issuer: httpUrl,
|
|
133
|
+
subject: z.string().min(1),
|
|
134
|
+
})
|
|
135
|
+
.strict(),
|
|
136
|
+
)
|
|
137
|
+
.min(1),
|
|
138
|
+
since: fullCommit.optional(),
|
|
139
|
+
fulcio: httpUrl.optional(),
|
|
140
|
+
timestamp: httpUrl.optional(),
|
|
141
|
+
audience: z.string().min(1).optional(),
|
|
142
|
+
})
|
|
143
|
+
.strict()
|
|
144
|
+
.optional(),
|
|
105
145
|
/**
|
|
106
146
|
* Passkeys that sign gate approvals for people (#4646): a WebAuthn
|
|
107
147
|
* credential's id, its public key as base64url DER SubjectPublicKeyInfo,
|
|
@@ -256,6 +296,30 @@ export interface RunnerKey {
|
|
|
256
296
|
key: string;
|
|
257
297
|
}
|
|
258
298
|
|
|
299
|
+
/** A CI identity that signs runner statements keyless (#4869), with the trusted root it is verified against. */
|
|
300
|
+
export interface RunnerIdentity {
|
|
301
|
+
principal: string;
|
|
302
|
+
class: "runner" | "service";
|
|
303
|
+
issuer: string;
|
|
304
|
+
/** A pattern over the certificate's subject alternative name: `*` within a `/` segment, `**` across. */
|
|
305
|
+
subject: string;
|
|
306
|
+
roots: KeylessRoots;
|
|
307
|
+
/** Verifies one keyless signature against this identity and its trusted root (./dsse.ts's `TrustedIdentity`). */
|
|
308
|
+
verifyKeyless(message: Buffer, signature: DsseSignature): KeylessCheck;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/** A runner as a statement's verifier takes it: a key, or a keyless identity. */
|
|
312
|
+
export type Runner = RunnerKey | RunnerIdentity;
|
|
313
|
+
|
|
314
|
+
/** Where a keyless signing job trades its token (#4869), and from which commit only keyless statements count. */
|
|
315
|
+
export interface KeylessPolicy {
|
|
316
|
+
since?: string;
|
|
317
|
+
fulcio: string;
|
|
318
|
+
timestamp: string;
|
|
319
|
+
audience: string;
|
|
320
|
+
trustedRoot: string;
|
|
321
|
+
}
|
|
322
|
+
|
|
259
323
|
/** The policy a check applies, as read at base. */
|
|
260
324
|
export interface TrustPolicy {
|
|
261
325
|
/** The full commit id the policy was read at, or null when there is no base. */
|
|
@@ -270,6 +334,10 @@ export interface TrustPolicy {
|
|
|
270
334
|
adopted: Array<{ from?: string; to: string }>;
|
|
271
335
|
/** Runner and service keys that may sign runner evidence (#2553). */
|
|
272
336
|
runners: RunnerKey[];
|
|
337
|
+
/** CI identities that sign runner statements keyless (#4869). Absent on a policy built by hand: none. */
|
|
338
|
+
runnerIdentities?: RunnerIdentity[];
|
|
339
|
+
/** The keyless settings (#4869), when `keyless` is set and its trusted root reads. */
|
|
340
|
+
keyless?: KeylessPolicy;
|
|
273
341
|
/** Runner entries that are not used, and why. */
|
|
274
342
|
excludedRunners: Array<{ principal: string; reason: string }>;
|
|
275
343
|
/** Passkeys that sign people's gate approvals (#4646). Absent on a policy built by hand: none. */
|
|
@@ -296,10 +364,37 @@ export interface TrustPolicy {
|
|
|
296
364
|
signersAt?: (commit: string) => { version: number; signers: Signer[] } | null;
|
|
297
365
|
}
|
|
298
366
|
|
|
299
|
-
/** Paths whose change is a protected write under `policy`: the config, the signers file and its rotation file (#2553). */
|
|
367
|
+
/** Paths whose change is a protected write under `policy`: the config, the signers file and its rotation file (#2553), and the keyless trusted root (#4869). */
|
|
300
368
|
export function protectedPaths(policy: TrustPolicy): string[] {
|
|
301
369
|
const s = policy.signersPath;
|
|
302
|
-
return [...new Set([TRUST_CONFIG_PATH, s, posix.join(posix.dirname(s), `${posix.basename(s)}.rotation.json`)])].sort();
|
|
370
|
+
return [...new Set([TRUST_CONFIG_PATH, s, posix.join(posix.dirname(s), `${posix.basename(s)}.rotation.json`), ...(policy.keyless ? [policy.keyless.trustedRoot] : [])])].sort();
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* The runners whose statements over `commit` count (#4869): the runner keys
|
|
375
|
+
* and the keyless identities. With `keyless.since`, a runner key counts
|
|
376
|
+
* only for a commit that is a strict ancestor of `since`, the way
|
|
377
|
+
* `ci.green.signedSince` judges tags by position in history; a `since` the
|
|
378
|
+
* clone does not have leaves the keys out. Without `at`, under `since`, only
|
|
379
|
+
* the identities.
|
|
380
|
+
*/
|
|
381
|
+
export function runnersAt(policy: TrustPolicy, at?: { repo: string; commit: string }): Runner[] {
|
|
382
|
+
const ids = policy.runnerIdentities ?? [];
|
|
383
|
+
const since = policy.keyless?.since;
|
|
384
|
+
if (!since) return [...policy.runners, ...ids];
|
|
385
|
+
if (!at || !strictAncestor(at.repo, at.commit, since)) return ids;
|
|
386
|
+
return [...policy.runners, ...ids];
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
function strictAncestor(repo: string, commit: string, of: string): boolean {
|
|
390
|
+
try {
|
|
391
|
+
const full = execFileSync("git", ["rev-parse", "--verify", "--quiet", `${commit}^{commit}`], { cwd: repo, encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] }).trim();
|
|
392
|
+
if (full === of) return false;
|
|
393
|
+
execFileSync("git", ["merge-base", "--is-ancestor", full, of], { cwd: repo, stdio: "ignore" });
|
|
394
|
+
return true;
|
|
395
|
+
} catch {
|
|
396
|
+
return false;
|
|
397
|
+
}
|
|
303
398
|
}
|
|
304
399
|
|
|
305
400
|
/** Principals allowed to change the policy: the admins when any are granted, otherwise every signer. */
|
|
@@ -355,6 +450,7 @@ export function readTrustPolicy(source: RecordSource, base: string | null): Trus
|
|
|
355
450
|
runners.push(r);
|
|
356
451
|
}
|
|
357
452
|
}
|
|
453
|
+
const { runnerIdentities, keyless } = keylessOf(config, source, humanNames, excludedRunners);
|
|
358
454
|
return {
|
|
359
455
|
base,
|
|
360
456
|
signersPath,
|
|
@@ -365,6 +461,7 @@ export function readTrustPolicy(source: RecordSource, base: string | null): Trus
|
|
|
365
461
|
adopted: config.adopted ?? [],
|
|
366
462
|
runners,
|
|
367
463
|
excludedRunners,
|
|
464
|
+
...(keyless ? { runnerIdentities, keyless } : {}),
|
|
368
465
|
passkeys: config.passkeys ?? [],
|
|
369
466
|
admitted: admittedOf(config),
|
|
370
467
|
refs: (config.refs ?? []).map((r) => ({ ...r, checks: r.checks.map((c) => ({ ...c, action: c.action ?? "block" })) })),
|
|
@@ -387,6 +484,36 @@ function localOf(config: TrustConfig, runners: readonly RunnerKey[]): LocalEvide
|
|
|
387
484
|
return { keys, excluded, checks: (config.local?.checks ?? []).map((c) => ({ check: c.check, from: c.from ?? ["person"] })) };
|
|
388
485
|
}
|
|
389
486
|
|
|
487
|
+
/**
|
|
488
|
+
* The keyless identities (#4869), each with the trusted root read through
|
|
489
|
+
* `source`. A trusted root that cannot be read leaves every identity out,
|
|
490
|
+
* with the reason in `excluded`; the runner keys still count.
|
|
491
|
+
*/
|
|
492
|
+
function keylessOf(config: TrustConfig, source: RecordSource, humanNames: Set<string>, excluded: Array<{ principal: string; reason: string }>): { runnerIdentities: RunnerIdentity[]; keyless?: KeylessPolicy } {
|
|
493
|
+
const k = config.keyless;
|
|
494
|
+
if (!k) return { runnerIdentities: [] };
|
|
495
|
+
// Kept when the root does not read, so `since` still leaves the keys out: fail closed.
|
|
496
|
+
const keyless: KeylessPolicy = { ...(k.since ? { since: k.since } : {}), fulcio: k.fulcio ?? DEFAULT_FULCIO_URL, timestamp: k.timestamp ?? DEFAULT_TIMESTAMP_URL, audience: k.audience ?? DEFAULT_SIGNING_AUDIENCE, trustedRoot: k.trustedRoot };
|
|
497
|
+
let roots: KeylessRoots;
|
|
498
|
+
try {
|
|
499
|
+
const text = readOptional(source, k.trustedRoot);
|
|
500
|
+
if (text === undefined) throw new Error("the file is not there");
|
|
501
|
+
roots = parseTrustedRoot(text);
|
|
502
|
+
} catch (err) {
|
|
503
|
+
for (const i of k.identities) excluded.push({ principal: i.principal, reason: `the keyless trusted root ${k.trustedRoot} cannot be read: ${err instanceof Error ? err.message : String(err)}` });
|
|
504
|
+
return { runnerIdentities: [], keyless };
|
|
505
|
+
}
|
|
506
|
+
const runnerIdentities: RunnerIdentity[] = [];
|
|
507
|
+
for (const i of k.identities) {
|
|
508
|
+
if (humanNames.has(i.principal)) excluded.push({ principal: i.principal, reason: "the signers file lists this principal; a keyless identity is a CI job's, never a signer's" });
|
|
509
|
+
else {
|
|
510
|
+
const verify = keylessVerifier({ ...i, roots });
|
|
511
|
+
runnerIdentities.push({ ...i, roots, verifyKeyless: (message, signature) => verify(message, signature) });
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
return { runnerIdentities, keyless };
|
|
515
|
+
}
|
|
516
|
+
|
|
390
517
|
/** The admitted signers, by return id. Two entries for one return add up. */
|
|
391
518
|
function admittedOf(config: TrustConfig): Record<string, Signer[]> {
|
|
392
519
|
const out: Record<string, Signer[]> = {};
|
|
@@ -48,6 +48,7 @@ const OVERRIDE_REQUEST_HOURS = 72;
|
|
|
48
48
|
const USAGE =
|
|
49
49
|
"chant workspace ref-gate check --ref <ref> [--at <rev>] [--base <rev>] [--dry-run] [--ledger <file>] [--json]\n" +
|
|
50
50
|
" chant workspace ref-gate status --ref <ref> [--at <rev>] [--base <rev>] [--dry-run] [--ledger <file>] [--json]\n" +
|
|
51
|
+
" chant workspace ref-gate status --open --ref refs/heads/<branch> [--base <rev>] [--dry-run] [--ledger <file>] [--json]\n" +
|
|
51
52
|
" chant workspace ref-gate pre-receive|pre-push [--ledger <file>] [--dry-run] [--json] (git hook input on stdin)\n" +
|
|
52
53
|
" chant workspace ref-gate attach --envelope <file> [--at <rev>]\n" +
|
|
53
54
|
" chant workspace ref-gate install --hook pre-receive|pre-push [--git-dir <dir>] [--chant <command>]";
|
|
@@ -82,7 +83,7 @@ function repoHere(): { repo: string; bare: boolean } | null {
|
|
|
82
83
|
return { repo: top, bare: false };
|
|
83
84
|
}
|
|
84
85
|
|
|
85
|
-
function print(json: boolean | undefined, decisions: RefDecision[], ledger: string | undefined, stream: "out" | "err"): void {
|
|
86
|
+
function print(json: boolean | undefined, decisions: RefDecision[], ledger: string | undefined, stream: "out" | "err", site?: RefGateSite): void {
|
|
86
87
|
const ok = decisions.every((d) => d.decision === "admit");
|
|
87
88
|
if (json) {
|
|
88
89
|
console.log(JSON.stringify({ ...head(), ok, ...(ledger ? { ledger } : {}), decisions }, null, 2));
|
|
@@ -90,7 +91,7 @@ function print(json: boolean | undefined, decisions: RefDecision[], ledger: stri
|
|
|
90
91
|
}
|
|
91
92
|
for (const d of decisions) {
|
|
92
93
|
if (d.status === null && d.checks.length === 0 && !d.error) continue;
|
|
93
|
-
const text = describeDecision(d).join("\n");
|
|
94
|
+
const text = describeDecision(d, site ? { site } : {}).join("\n");
|
|
94
95
|
if (stream === "err" || d.decision === "refuse") console.error(text);
|
|
95
96
|
else console.log(text);
|
|
96
97
|
}
|
|
@@ -161,7 +162,7 @@ export async function runWorkspaceRefGate(ctx: CommandContext): Promise<number>
|
|
|
161
162
|
try {
|
|
162
163
|
if (sub === "pre-receive") {
|
|
163
164
|
const r = runPreReceive(here.repo, stdin, { ...(args.ledger ? { ledger: args.ledger } : {}), now });
|
|
164
|
-
print(args.json, r.decisions, r.ledger, "err");
|
|
165
|
+
print(args.json, r.decisions, r.ledger, "err", "pre-receive");
|
|
165
166
|
return r.ok ? 0 : 1;
|
|
166
167
|
}
|
|
167
168
|
const r = runPrePush(here.repo, stdin, { ...(args.ledger ? { ledger: args.ledger } : {}), now, base: (repo) => resolveBase(repo).commit });
|
|
@@ -176,6 +177,10 @@ export async function runWorkspaceRefGate(ctx: CommandContext): Promise<number>
|
|
|
176
177
|
|
|
177
178
|
// check and status: one update, from a checkout or a CI job.
|
|
178
179
|
if (!args.ref || !args.ref.startsWith("refs/")) return usage("--ref <ref> is required, as a full ref name such as refs/heads/main");
|
|
180
|
+
if (args.open) {
|
|
181
|
+
if (sub !== "status") return usage("--open sets the status of every open pull request, so it goes with status");
|
|
182
|
+
return statusOpen(here.repo, args.ref, args.base, args.ledger, args.dryRun === true, args.json, now);
|
|
183
|
+
}
|
|
179
184
|
const at = commitOf(here.repo, args.at ?? "HEAD");
|
|
180
185
|
if (!at) return fail(args.json, "revision-unknown", `--at ${args.at ?? "HEAD"} names no commit`);
|
|
181
186
|
const resolved = resolveBase(here.repo, args.base);
|
|
@@ -203,6 +208,57 @@ export async function runWorkspaceRefGate(ctx: CommandContext): Promise<number>
|
|
|
203
208
|
return d.decision === "admit" ? 0 : 1;
|
|
204
209
|
}
|
|
205
210
|
|
|
211
|
+
/**
|
|
212
|
+
* `status --open --ref refs/heads/<branch>` (#4935): the status of every open
|
|
213
|
+
* pull request into the branch, from a pipeline of the branch. GitLab sets a
|
|
214
|
+
* commit status only with the protected token a target-branch pipeline holds
|
|
215
|
+
* (#4328), so its generated `ref-gate` job runs here, beside the plan notes.
|
|
216
|
+
* Each head is fetched and decided as `status --at <head>` decides it, against
|
|
217
|
+
* the policy at `base` (default this checkout's `HEAD`, the branch's commit).
|
|
218
|
+
* A head that does not fetch, or a forge that refuses one status, is said
|
|
219
|
+
* and the others go on. Exits 0 once each is set, whatever it decided: each
|
|
220
|
+
* pull request's status says it.
|
|
221
|
+
*/
|
|
222
|
+
async function statusOpen(repo: string, ref: string, baseRev: string | undefined, ledgerFlag: string | undefined, dryRun: boolean, json: boolean | undefined, now: string): Promise<number> {
|
|
223
|
+
if (!ref.startsWith("refs/heads/")) return usage("--open names the branch the pull requests merge into: --ref refs/heads/<branch>");
|
|
224
|
+
const base = commitOf(repo, baseRev ?? "HEAD");
|
|
225
|
+
if (!base) return fail(json, "revision-unknown", `--base ${baseRev ?? "HEAD"} names no commit`);
|
|
226
|
+
const { detectForge, forgeFromEnv } = await import("../../pr-forge");
|
|
227
|
+
const kind = detectForge();
|
|
228
|
+
if (!kind && !dryRun) {
|
|
229
|
+
console.error(formatError({ message: "no forge detected, so no status was set", hint: "run it in a GitHub, GitLab or Forgejo job, or pass --dry-run" }));
|
|
230
|
+
return 1;
|
|
231
|
+
}
|
|
232
|
+
const forge = kind ? forgeFromEnv(kind) : undefined;
|
|
233
|
+
if (!forge?.openPullRequests) return fail(json, "ref-update-invalid", `--open lists the open pull requests, which ${kind ?? "no"} forge client here can`);
|
|
234
|
+
const branch = ref.slice("refs/heads/".length);
|
|
235
|
+
const ledger = ledgerFlag ?? refGateLedgerPath(repo);
|
|
236
|
+
const decisions: RefDecision[] = [];
|
|
237
|
+
for (const pr of await forge.openPullRequests(branch)) {
|
|
238
|
+
const fetched = spawnSync("git", ["fetch", "--quiet", "--no-tags", "origin", pr.headSha], { cwd: repo, encoding: "utf-8" });
|
|
239
|
+
if (!commitOf(repo, pr.headSha)) {
|
|
240
|
+
console.error(`chant ref gate: #${pr.number}'s head ${pr.headSha.slice(0, 8)} did not fetch${fetched.stderr ? ` (${fetched.stderr.trim().split("\n")[0]})` : ""}, so its status is left as it is`);
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
const spent = spentOverrides(readRefGateLedger(ledger));
|
|
244
|
+
const d = decideRefUpdate({ repo, update: { ref, old: base, new: pr.headSha }, base, spent, now });
|
|
245
|
+
decisions.push(d);
|
|
246
|
+
if (dryRun) {
|
|
247
|
+
if (d.status !== null) console.error(`chant ref gate: would set ${d.status} to ${d.decision === "admit" ? "success" : "failure"} on #${pr.number} at ${pr.headSha.slice(0, 8)}`);
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
appendRefGateLedger(ledger, [{ ...d, version: 1, kind: "ref-update", site: "status", timestamp: now }]);
|
|
251
|
+
try {
|
|
252
|
+
await postRefGateStatus(forge, d);
|
|
253
|
+
} catch (err) {
|
|
254
|
+
console.error(`chant ref gate: could not set the status on #${pr.number}: ${err instanceof Error ? err.message : String(err)}`);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
print(json, decisions, dryRun ? undefined : ledger, "err");
|
|
258
|
+
if (decisions.length === 0) console.error(`chant ref gate: no open pull request into ${branch} to set a status on`);
|
|
259
|
+
return 0;
|
|
260
|
+
}
|
|
261
|
+
|
|
206
262
|
/** The commit status a forge requires for `d`'s ref: `success` when it is admitted, `failure` naming the missing checks when not. */
|
|
207
263
|
export async function postRefGateStatus(forge: { setStatus(sha: string, status: { context: string; state: "success" | "failure"; description: string }): Promise<void> }, d: RefDecision): Promise<void> {
|
|
208
264
|
if (d.status === null || d.new === null) return;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #4913: the ref gate's pieces a product uses without code of its own. The
|
|
3
|
+
* rules read at base (`@intentius/chant/ref-gate-rules`), the status a forge
|
|
4
|
+
* check requires, the init pieces that write `.chant/trust.json`, the hook
|
|
5
|
+
* and the runner key hint (`@intentius/chant/ref-gate-init`), and a
|
|
6
|
+
* pre-receive refusal that prints the command recording the request for an
|
|
7
|
+
* override from the checkout.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { existsSync, readFileSync, realpathSync, statSync, writeFileSync } from "node:fs";
|
|
11
|
+
import { join } from "node:path";
|
|
12
|
+
import { describe, expect, test } from "vitest";
|
|
13
|
+
import { refGateInitPlan, RefGateInitError, writeRefGateInit } from "../../ref-gate-init";
|
|
14
|
+
import { REF_GATE_STATUS, refGateRulesAt, refGateStatusFor } from "../../ref-gate-rules";
|
|
15
|
+
import { decideRefUpdate, describeDecision, requestCommand } from "./ref-gate";
|
|
16
|
+
import { REF_GATE_HOOK_MARK } from "./ref-gate-cli";
|
|
17
|
+
import { GateRepos, RUNNER, runnerKey, trustJson } from "./ref-gate-fixture";
|
|
18
|
+
|
|
19
|
+
const CHECKS = [
|
|
20
|
+
{ check: "plan", command: "chant ci run plan" },
|
|
21
|
+
{ check: "lint", action: "warn" as const, command: "npm run lint" },
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
describe("the ref gate's rules as a library (#4913)", () => {
|
|
25
|
+
test("rules for a ref come from the policy at base, and a change that drops them does not count", () => {
|
|
26
|
+
const r = new GateRepos("4913-rules");
|
|
27
|
+
const ci = runnerKey();
|
|
28
|
+
r.write(".chant/trust.json", trustJson(ci, CHECKS, {}));
|
|
29
|
+
const base = r.commit("policy");
|
|
30
|
+
r.write(".chant/trust.json", JSON.stringify({ schema: 1 }));
|
|
31
|
+
r.commit("drop the rules");
|
|
32
|
+
|
|
33
|
+
const atBase = refGateRulesAt(r.work, { ref: "refs/heads/main", base });
|
|
34
|
+
expect(atBase).toEqual({
|
|
35
|
+
ref: "refs/heads/main",
|
|
36
|
+
base,
|
|
37
|
+
matched: true,
|
|
38
|
+
status: REF_GATE_STATUS,
|
|
39
|
+
checks: [
|
|
40
|
+
{ check: "plan", action: "block", command: "chant ci run plan" },
|
|
41
|
+
{ check: "lint", action: "warn", command: "npm run lint" },
|
|
42
|
+
],
|
|
43
|
+
problems: [],
|
|
44
|
+
});
|
|
45
|
+
expect(refGateRulesAt(r.work, { ref: "refs/heads/release/2", base }).matched).toBe(true);
|
|
46
|
+
expect(refGateRulesAt(r.work, { ref: "refs/heads/feature", base })).toMatchObject({ matched: false, status: null, checks: [], problems: [] });
|
|
47
|
+
// At the change itself the rules are gone, which is why a product reads them at base.
|
|
48
|
+
expect(refGateRulesAt(r.work, { ref: "refs/heads/main", base: "HEAD" }).matched).toBe(false);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test("a base that names no commit, or a policy that can't be read, is a problem", () => {
|
|
52
|
+
const r = new GateRepos("4913-problems");
|
|
53
|
+
r.write(".chant/trust.json", "{ not json");
|
|
54
|
+
const base = r.commit("broken policy");
|
|
55
|
+
expect(refGateRulesAt(r.work, { ref: "refs/heads/main", base: "nope" }).problems[0]).toContain("--base nope names no commit");
|
|
56
|
+
const broken = refGateRulesAt(r.work, { ref: "refs/heads/main", base });
|
|
57
|
+
expect(broken.matched).toBe(false);
|
|
58
|
+
expect(broken.problems[0]).toContain(".chant/trust.json is not JSON");
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test("the status a forge check requires: the policy's own name, at origin/<default> when the checkout has it", () => {
|
|
62
|
+
const r = new GateRepos("4913-status");
|
|
63
|
+
const ci = runnerKey();
|
|
64
|
+
r.write(".chant/trust.json", JSON.stringify({ schema: 1, runners: [{ principal: RUNNER, class: "runner", key: ci.pub }], refs: [{ ref: "refs/heads/main", checks: CHECKS, status: "acme/gate" }] }));
|
|
65
|
+
r.commit("policy");
|
|
66
|
+
r.push("main");
|
|
67
|
+
r.git(["fetch", "-q", "origin"]);
|
|
68
|
+
// A local change that drops the rule does not move what the forge's default branch requires.
|
|
69
|
+
r.write(".chant/trust.json", JSON.stringify({ schema: 1 }));
|
|
70
|
+
r.commit("drop locally");
|
|
71
|
+
expect(refGateStatusFor(r.work, "main")).toEqual({ status: "acme/gate" });
|
|
72
|
+
expect(refGateStatusFor(r.work, "trunk").note).toContain("matches refs/heads/trunk, so the ref-gate job sets no status there");
|
|
73
|
+
const bare = new GateRepos("4913-status-head");
|
|
74
|
+
bare.write(".chant/trust.json", "[]");
|
|
75
|
+
bare.commit("not a policy");
|
|
76
|
+
expect(refGateStatusFor(bare.work, "main").problem).toContain("the trust policy can't be read");
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
describe("the ref gate's init pieces (#4913)", () => {
|
|
81
|
+
test("a checkout with no trust policy gets one with the rule, the pre-push hook and the runner key hint", () => {
|
|
82
|
+
const r = new GateRepos("4913-init-new");
|
|
83
|
+
r.write("README.md", "hi\n");
|
|
84
|
+
r.commit("start");
|
|
85
|
+
const plan = refGateInitPlan(r.work, { checks: CHECKS, chant: "npx chant", runner: "ci:acme/infra", runnerKeySecret: "CHANT_RUNNER_KEY" });
|
|
86
|
+
const trust = plan.files.find((f) => f.path.endsWith(".chant/trust.json"))!;
|
|
87
|
+
expect(trust.status).toBe("created");
|
|
88
|
+
expect(JSON.parse(trust.content)).toEqual({ schema: 1, refs: [{ ref: "refs/heads/main", checks: [{ check: "plan", command: "chant ci run plan" }, { check: "lint", action: "warn", command: "npm run lint" }] }] });
|
|
89
|
+
const hook = plan.files.find((f) => f.path.endsWith("pre-push"))!;
|
|
90
|
+
expect(hook).toMatchObject({ status: "created", mode: 0o755, local: true });
|
|
91
|
+
expect(hook.path.startsWith(join(realpathSync(r.work), ".git"))).toBe(true);
|
|
92
|
+
expect(hook.content).toContain(REF_GATE_HOOK_MARK);
|
|
93
|
+
expect(hook.content).toContain("exec npx chant workspace ref-gate pre-push");
|
|
94
|
+
const hint = plan.notes.find((n) => n.includes("no runner key"))!;
|
|
95
|
+
expect(hint).toContain("chant workspace trust runner add ci:acme/infra --key runner.pem");
|
|
96
|
+
expect(hint).toContain("the CHANT_RUNNER_KEY secret");
|
|
97
|
+
expect(plan.notes.some((n) => n.includes("protected write"))).toBe(true);
|
|
98
|
+
|
|
99
|
+
writeRefGateInit(plan);
|
|
100
|
+
expect(statSync(hook.path).mode & 0o777).toBe(0o755);
|
|
101
|
+
const base = r.commit("ref gate");
|
|
102
|
+
// What init wrote is what the gate reads.
|
|
103
|
+
expect(refGateRulesAt(r.work, { ref: "refs/heads/main", base })).toMatchObject({ matched: true, status: REF_GATE_STATUS, checks: [{ check: "plan", action: "block" }, { check: "lint", action: "warn" }] });
|
|
104
|
+
const again = refGateInitPlan(r.work, { checks: CHECKS, chant: "npx chant" });
|
|
105
|
+
expect(again.files.map((f) => f.status)).toEqual(["unchanged", "unchanged"]);
|
|
106
|
+
expect(again.notes.some((n) => n.includes("already has a refs rule for refs/heads/main"))).toBe(true);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test("an existing policy keeps its text and gets the rule added; one with a runner gets no hint", () => {
|
|
110
|
+
const r = new GateRepos("4913-init-edit");
|
|
111
|
+
const ci = runnerKey();
|
|
112
|
+
const before = `{\n "schema": 1,\n "runners": [{ "principal": "${RUNNER}", "class": "runner", "key": "${ci.pub}" }]\n}\n`;
|
|
113
|
+
r.write(".chant/trust.json", before);
|
|
114
|
+
r.commit("runner only");
|
|
115
|
+
const plan = refGateInitPlan(r.work, { branch: "trunk", checks: [{ check: "plan", command: "chant ci run plan" }], status: "acme/gate", prePush: false });
|
|
116
|
+
expect(plan.files).toHaveLength(1);
|
|
117
|
+
const trust = plan.files[0]!;
|
|
118
|
+
expect(trust.status).toBe("updated");
|
|
119
|
+
expect(trust.content.startsWith(`{\n "schema": 1,\n "runners": [{ "principal": "${RUNNER}"`)).toBe(true);
|
|
120
|
+
expect(JSON.parse(trust.content).refs).toEqual([{ ref: "refs/heads/trunk", checks: [{ check: "plan", command: "chant ci run plan" }], status: "acme/gate" }]);
|
|
121
|
+
expect(plan.notes.some((n) => n.includes("no runner key"))).toBe(false);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test("a rule that covers the branch, a policy that does not read, and a hook that is not chant's are left as they are", () => {
|
|
125
|
+
const r = new GateRepos("4913-init-leave");
|
|
126
|
+
r.write(".chant/trust.json", JSON.stringify({ schema: 1, refs: [{ ref: "refs/heads/*", checks: [{ check: "lint", command: "npm run lint" }] }] }));
|
|
127
|
+
r.commit("a wide rule");
|
|
128
|
+
const hooks = join(r.work, ".git", "hooks");
|
|
129
|
+
writeFileSync(join(hooks, "pre-push"), "#!/bin/sh\necho mine\n");
|
|
130
|
+
const plan = refGateInitPlan(r.work, { checks: CHECKS });
|
|
131
|
+
expect(plan.files.map((f) => [f.path.endsWith(".chant/trust.json"), f.status])).toEqual([[true, "unchanged"]]);
|
|
132
|
+
expect(plan.notes.some((n) => n.includes("already has a refs rule for refs/heads/main (refs/heads/*)"))).toBe(true);
|
|
133
|
+
expect(plan.notes.some((n) => n.includes("is not chant's ref gate hook"))).toBe(true);
|
|
134
|
+
expect(readFileSync(join(hooks, "pre-push"), "utf-8")).toContain("echo mine");
|
|
135
|
+
|
|
136
|
+
r.write(".chant/trust.json", "{ not json");
|
|
137
|
+
const bad = refGateInitPlan(r.work, { checks: CHECKS, prePush: false });
|
|
138
|
+
expect(bad.files).toEqual([]);
|
|
139
|
+
expect(bad.notes[0]).toContain("does not read as chant's trust policy");
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
test("options no rule can hold, or a directory outside git, are refused", () => {
|
|
143
|
+
const r = new GateRepos("4913-init-refuse");
|
|
144
|
+
r.commit("start");
|
|
145
|
+
expect(() => refGateInitPlan(r.work, { checks: [] })).toThrow(RefGateInitError);
|
|
146
|
+
expect(() => refGateInitPlan(r.work, { checks: [{ check: "has space", command: "x" }] })).toThrow("is not a check name");
|
|
147
|
+
expect(() => refGateInitPlan(r.work, { branch: "release/*", checks: CHECKS })).toThrow(RefGateInitError);
|
|
148
|
+
expect(() => refGateInitPlan(r.home, { checks: CHECKS })).toThrow("is not in a git checkout");
|
|
149
|
+
expect(existsSync(join(r.work, ".chant/trust.json"))).toBe(false);
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
describe("the request for an override from a push the remote refused (#4913)", () => {
|
|
154
|
+
test("the pre-receive refusal prints the exact command that records it in the checkout, then the override and the push", () => {
|
|
155
|
+
const r = new GateRepos("4913-request");
|
|
156
|
+
const ci = runnerKey();
|
|
157
|
+
r.write(".chant/trust.json", trustJson(ci, CHECKS));
|
|
158
|
+
const base = r.commit("policy");
|
|
159
|
+
r.write("app/a.txt", "change\n");
|
|
160
|
+
const head = r.commit("a change");
|
|
161
|
+
const d = decideRefUpdate({ repo: r.work, update: { ref: "refs/heads/main", old: base, new: head }, base, lifecycle: null });
|
|
162
|
+
expect(d.decision).toBe("refuse");
|
|
163
|
+
expect(requestCommand(d)).toBe(`chant workspace ref-gate check --ref refs/heads/main --at ${head} --base ${base}`);
|
|
164
|
+
|
|
165
|
+
const remote = describeDecision(d, { site: "pre-receive" }).join("\n");
|
|
166
|
+
expect(remote).toContain("record the request for an override in your checkout (this remote can't)");
|
|
167
|
+
expect(remote).toContain(` chant workspace ref-gate check --ref refs/heads/main --at ${head} --base ${base}`);
|
|
168
|
+
expect(remote).toContain(`chant approve policy-override ref-gate-${head.slice(0, 12)}-plan --rule plan`);
|
|
169
|
+
expect(remote).toContain(`git push origin chant/lifecycle ${head}:refs/heads/main`);
|
|
170
|
+
expect(remote).not.toContain("lint --rule");
|
|
171
|
+
|
|
172
|
+
const local = describeDecision(d).join("\n");
|
|
173
|
+
expect(local).toContain(`the pre-push hook records it, or chant workspace ref-gate check --ref refs/heads/main --at ${head} --base ${base}`);
|
|
174
|
+
});
|
|
175
|
+
});
|
|
@@ -60,6 +60,23 @@ describe("the ref gate's hooks", () => {
|
|
|
60
60
|
expect(r.run(r.origin, ["rev-parse", "main"]).trim()).toBe(head);
|
|
61
61
|
}, 60_000);
|
|
62
62
|
|
|
63
|
+
test("a push only the remote refused prints the command that records the request for an override, and it does from the checkout (#4913)", () => {
|
|
64
|
+
const { r, base, head } = setup("e2e-request");
|
|
65
|
+
const installed = chant(r, r.work, ["workspace", "ref-gate", "install", "--hook", "pre-receive", "--git-dir", r.origin, "--chant", CHANT]);
|
|
66
|
+
expect(installed.status, installed.stderr).toBe(0);
|
|
67
|
+
const refused = push(r, `${head}:refs/heads/main`);
|
|
68
|
+
expect(refused.status).not.toBe(0);
|
|
69
|
+
const printed = refused.stderr.split("\n").map((l) => l.replace(/^remote:\s*/, "").trim()).find((l) => l.startsWith("chant workspace ref-gate check "));
|
|
70
|
+
expect(printed).toBe(`chant workspace ref-gate check --ref refs/heads/main --at ${head} --base ${base}`);
|
|
71
|
+
|
|
72
|
+
const recorded = chant(r, r.work, printed!.split(" ").slice(1));
|
|
73
|
+
expect(recorded.status).toBe(1);
|
|
74
|
+
expect(recorded.stderr).toContain("is recorded on chant/lifecycle");
|
|
75
|
+
const ledger = r.git(["show", "chant/lifecycle:_gates/policy-override.jsonl"]);
|
|
76
|
+
expect(ledger).toContain(`"gate":"ref-gate-${head.slice(0, 12)}-plan"`);
|
|
77
|
+
expect(ledger).toContain(`"gate":"ref-gate-${head.slice(0, 12)}-policy"`);
|
|
78
|
+
}, 60_000);
|
|
79
|
+
|
|
63
80
|
test("chant's pre-push hook refuses the same push before the network", () => {
|
|
64
81
|
const { r, ci, base, head } = setup("e2e-push");
|
|
65
82
|
const installed = chant(r, r.work, ["workspace", "ref-gate", "install", "--hook", "pre-push", "--chant", CHANT]);
|