@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
package/src/chant-install.ts
CHANGED
|
@@ -18,12 +18,25 @@
|
|
|
18
18
|
* {@link chantArgv} runs the package's `bin/chant` with the node running
|
|
19
19
|
* now: the bin picks the compiled CLI in an installed package and the source
|
|
20
20
|
* in a checkout (#3878), so a product never chooses between them.
|
|
21
|
+
*
|
|
22
|
+
* #4889: {@link runChant} spawns that chant and returns its output and its
|
|
23
|
+
* last `--json` document ({@link lastJsonLine}), and
|
|
24
|
+
* {@link installResolveFallback} and {@link fallbackImportArgs} resolve any
|
|
25
|
+
* bare specifier a file with no `node_modules` above it imports, in the
|
|
26
|
+
* product's process and in chant's children, from the product's install
|
|
27
|
+
* (SQL Yodeler's `resolve-fallback.ts` and `process.ts`, terragucci's
|
|
28
|
+
* `runChant` in `resume.ts`).
|
|
21
29
|
*/
|
|
22
30
|
|
|
31
|
+
import { spawn } from "node:child_process";
|
|
23
32
|
import { existsSync, readFileSync } from "node:fs";
|
|
24
33
|
import * as nodeModule from "node:module";
|
|
25
|
-
import { delimiter, dirname, join, resolve } from "node:path";
|
|
26
|
-
import { fileURLToPath } from "node:url";
|
|
34
|
+
import { delimiter, dirname, join, resolve, sep } from "node:path";
|
|
35
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
36
|
+
import { NEXT_RELEASE } from "./release-floors";
|
|
37
|
+
|
|
38
|
+
/** The first chant with `runChant`, `lastJsonLine`, `installResolveFallback` and `fallbackImportArgs` in `@intentius/chant/chant-install` (#4889): a product runs chant and reads its `--json` document, and a file with no `node_modules` above it imports the product's packages, with no code of the product's own. */
|
|
39
|
+
export const CHANT_RUN_FLOOR = NEXT_RELEASE;
|
|
27
40
|
|
|
28
41
|
/** Where a chant package is installed. */
|
|
29
42
|
export interface ChantInstall {
|
|
@@ -177,3 +190,231 @@ export function installChantResolveFallback(from: string = import.meta.url): boo
|
|
|
177
190
|
flags[FALLBACK] = true;
|
|
178
191
|
return true;
|
|
179
192
|
}
|
|
193
|
+
|
|
194
|
+
// ── #4889: any bare specifier, for a file with no node_modules above it ────
|
|
195
|
+
|
|
196
|
+
/** A bare specifier: a package name, not a relative or absolute path, a URL, a `node:` builtin or a `#` import. */
|
|
197
|
+
export function isBareSpecifier(specifier: string): boolean {
|
|
198
|
+
return !/^(\.{0,2}\/|[a-zA-Z][a-zA-Z0-9+.-]*:)/.test(specifier) && !specifier.startsWith("#");
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** Whether the file at `url` has a `node_modules` directory in its own directory or any above it. A URL that is not a file's counts as having one. */
|
|
202
|
+
export function hasNodeModulesAbove(url: unknown): boolean {
|
|
203
|
+
if (typeof url !== "string" || !url.startsWith("file:")) return true;
|
|
204
|
+
for (let dir = dirname(fileURLToPath(url)); ; ) {
|
|
205
|
+
if (existsSync(join(dir, "node_modules"))) return true;
|
|
206
|
+
const up = dirname(dir);
|
|
207
|
+
if (up === dir) return false;
|
|
208
|
+
dir = up;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* The file URL a bare specifier is retried from: a file beside the
|
|
214
|
+
* `node_modules` directory that holds `from` (by default this module, in
|
|
215
|
+
* the chant the product depends on), so the retry finds the product's own
|
|
216
|
+
* packages first; `from` itself when it is in no `node_modules`, as in a
|
|
217
|
+
* chant checkout. SQL Yodeler's `ownModules`.
|
|
218
|
+
*/
|
|
219
|
+
export function fallbackParent(from: string = import.meta.url): string {
|
|
220
|
+
const path = from.startsWith("file:") ? fileURLToPath(from) : from;
|
|
221
|
+
const marker = `${sep}node_modules${sep}`;
|
|
222
|
+
const at = path.lastIndexOf(marker);
|
|
223
|
+
if (at < 0) return from.startsWith("file:") ? from : pathToFileURL(from).href;
|
|
224
|
+
return pathToFileURL(join(path.slice(0, at), "chant-resolve-fallback.js")).href;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* A resolve hook (SQL Yodeler's `resolve-fallback.ts`): a bare specifier
|
|
229
|
+
* Node could not find, imported by a file with no `node_modules` in its
|
|
230
|
+
* directory or any above it, resolves from `parent`. chant's commit job
|
|
231
|
+
* runs a product's command in a git worktree outside the checkout the job
|
|
232
|
+
* installed, so a `chant.config.ts` or an Op there imports chant, its
|
|
233
|
+
* lexicons and the product by name and finds none of them. A file that has
|
|
234
|
+
* an install of its own, and any other failure, is left as Node reports it.
|
|
235
|
+
*/
|
|
236
|
+
export function bareResolveFallback(parent: string) {
|
|
237
|
+
return (specifier: string, context: Record<string, unknown>, next: NextResolve): ResolveResult => {
|
|
238
|
+
try {
|
|
239
|
+
return next(specifier, context);
|
|
240
|
+
} catch (err) {
|
|
241
|
+
const code = (err as { code?: unknown }).code;
|
|
242
|
+
if (code !== "ERR_MODULE_NOT_FOUND" && code !== "MODULE_NOT_FOUND") throw err;
|
|
243
|
+
if (!isBareSpecifier(specifier) || context.parentURL === parent || hasNodeModulesAbove(context.parentURL)) throw err;
|
|
244
|
+
return next(specifier, { ...context, parentURL: parent });
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* {@link bareResolveFallback} as module source for a child's `--import`,
|
|
251
|
+
* with `PARENT` bound: the same checks, written for Node's synchronous
|
|
252
|
+
* `registerHooks` and, on a Node without it, the asynchronous `register`,
|
|
253
|
+
* whose `next` returns a promise.
|
|
254
|
+
*/
|
|
255
|
+
function hooksSource(parent: string): string {
|
|
256
|
+
return [
|
|
257
|
+
'import { existsSync } from "node:fs";',
|
|
258
|
+
'import { dirname, join } from "node:path";',
|
|
259
|
+
'import { fileURLToPath } from "node:url";',
|
|
260
|
+
`const PARENT = ${JSON.stringify(parent)};`,
|
|
261
|
+
'const bare = (s) => !/^(\\.{0,2}\\/|[a-zA-Z][a-zA-Z0-9+.-]*:)/.test(s) && !s.startsWith("#");',
|
|
262
|
+
"function installed(url) {",
|
|
263
|
+
' if (typeof url !== "string" || !url.startsWith("file:")) return true;',
|
|
264
|
+
" for (let d = dirname(fileURLToPath(url)); ; ) {",
|
|
265
|
+
' if (existsSync(join(d, "node_modules"))) return true;',
|
|
266
|
+
" const up = dirname(d);",
|
|
267
|
+
" if (up === d) return false;",
|
|
268
|
+
" d = up;",
|
|
269
|
+
" }",
|
|
270
|
+
"}",
|
|
271
|
+
"function retry(specifier, context, next, e) {",
|
|
272
|
+
' if (!e || (e.code !== "ERR_MODULE_NOT_FOUND" && e.code !== "MODULE_NOT_FOUND") || !bare(specifier) || context.parentURL === PARENT || installed(context.parentURL)) throw e;',
|
|
273
|
+
" return next(specifier, { ...context, parentURL: PARENT });",
|
|
274
|
+
"}",
|
|
275
|
+
"export function resolve(specifier, context, next) {",
|
|
276
|
+
" let r;",
|
|
277
|
+
" try { r = next(specifier, context); } catch (e) { return retry(specifier, context, next, e); }",
|
|
278
|
+
' return r && typeof r.then === "function" ? r.catch((e) => retry(specifier, context, next, e)) : r;',
|
|
279
|
+
"}",
|
|
280
|
+
].join("\n");
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
const dataUrl = (source: string): string => `data:text/javascript,${encodeURIComponent(source)}`;
|
|
284
|
+
|
|
285
|
+
const BARE_FALLBACK = Symbol.for("chant.bareResolveFallback");
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Install {@link bareResolveFallback} once in this process, retrying from
|
|
289
|
+
* `parent` (default {@link fallbackParent}). A product's bin calls it before
|
|
290
|
+
* it loads a repository's `chant.config.ts` or Ops. Uses Node's
|
|
291
|
+
* `module.registerHooks` where it has one, else `module.register`. Returns
|
|
292
|
+
* whether it is installed: false on a Node with neither.
|
|
293
|
+
*/
|
|
294
|
+
export function installResolveFallback(parent: string = fallbackParent()): boolean {
|
|
295
|
+
const flags = globalThis as { [BARE_FALLBACK]?: boolean };
|
|
296
|
+
if (flags[BARE_FALLBACK]) return true;
|
|
297
|
+
const m = nodeModule as unknown as { registerHooks?: RegisterHooks; register?: (url: string) => unknown };
|
|
298
|
+
if (typeof m.registerHooks === "function") m.registerHooks({ resolve: bareResolveFallback(parent) });
|
|
299
|
+
else if (typeof m.register === "function") m.register(dataUrl(hooksSource(parent)));
|
|
300
|
+
else return false;
|
|
301
|
+
flags[BARE_FALLBACK] = true;
|
|
302
|
+
return true;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* The node arguments that install {@link bareResolveFallback} in a chant
|
|
307
|
+
* child (`chant build`, `chant run`), before its own imports of the
|
|
308
|
+
* repository's files: one `--import` of a `data:` module, so it loads the
|
|
309
|
+
* same from a product's `src/` under tsx and from its bundle. Pass them as
|
|
310
|
+
* {@link chantArgv}'s `nodeArgs`, or {@link runChant}'s `resolveFallback`.
|
|
311
|
+
*/
|
|
312
|
+
export function fallbackImportArgs(parent: string = fallbackParent()): string[] {
|
|
313
|
+
const hooks = dataUrl(hooksSource(parent));
|
|
314
|
+
const registrar = [
|
|
315
|
+
'import * as m from "node:module";',
|
|
316
|
+
`import { resolve } from ${JSON.stringify(hooks)};`,
|
|
317
|
+
`if (typeof m.registerHooks === "function") m.registerHooks({ resolve }); else m.register(${JSON.stringify(hooks)});`,
|
|
318
|
+
].join("\n");
|
|
319
|
+
return ["--import", dataUrl(registrar)];
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// ── #4889: running chant and reading its --json document ──────────────────
|
|
323
|
+
|
|
324
|
+
/** What {@link runChant} returns once the child exits. */
|
|
325
|
+
export interface ChantRun {
|
|
326
|
+
/** The exit code; 128 when a signal ended it. */
|
|
327
|
+
code: number;
|
|
328
|
+
stdout: string;
|
|
329
|
+
stderr: string;
|
|
330
|
+
/** {@link lastJsonLine} of `stdout`: the `--json` document, when the command printed one. */
|
|
331
|
+
json?: unknown;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
export interface RunChantOptions {
|
|
335
|
+
/** The directory chant runs in. Default the current one. */
|
|
336
|
+
cwd?: string;
|
|
337
|
+
/** The environment the child starts from, before {@link chantEnv}. Default `process.env`. */
|
|
338
|
+
env?: NodeJS.ProcessEnv;
|
|
339
|
+
/**
|
|
340
|
+
* A chant executable to run as it is (a product's `--chant` flag): no
|
|
341
|
+
* node in front of it, so `nodeArgs` and `resolveFallback` do not apply.
|
|
342
|
+
*/
|
|
343
|
+
chant?: string;
|
|
344
|
+
/** The install to run. Default {@link bundledChant}, else the first of `from` that {@link installedChant} finds, else `chant` on PATH. */
|
|
345
|
+
install?: ChantInstall;
|
|
346
|
+
/** Directories to look for an install from when this module is in none (terragucci looks from the repository). */
|
|
347
|
+
from?: readonly string[];
|
|
348
|
+
/** Node arguments before the bin, such as a product's own `--import`. */
|
|
349
|
+
nodeArgs?: readonly string[];
|
|
350
|
+
/** Install {@link bareResolveFallback} in the child (`true` from {@link fallbackParent}, or a parent URL). */
|
|
351
|
+
resolveFallback?: boolean | string;
|
|
352
|
+
/** `FORCE_COLOR=0` and `NO_COLOR=1`, for output a product reads. */
|
|
353
|
+
noColor?: boolean;
|
|
354
|
+
/** `inherit` writes the child's output to this process's and captures none. Default `pipe`. */
|
|
355
|
+
stdio?: "pipe" | "inherit";
|
|
356
|
+
/** Each chunk as it arrives, for output a person watches. */
|
|
357
|
+
onStdout?: (text: string) => void;
|
|
358
|
+
onStderr?: (text: string) => void;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Run `chant <args>` and resolve with its exit code, its output and its
|
|
363
|
+
* `--json` document (#4889; SQL Yodeler's `runChant`, terragucci's in
|
|
364
|
+
* `resume.ts`). The chant is the product's own ({@link chantArgv}) with its
|
|
365
|
+
* bin first on PATH ({@link chantEnv}). Never rejects on a non-zero exit;
|
|
366
|
+
* rejects when the child cannot start.
|
|
367
|
+
*/
|
|
368
|
+
export function runChant(args: readonly string[], options: RunChantOptions = {}): Promise<ChantRun> {
|
|
369
|
+
const install = options.chant === undefined ? (options.install ?? bundledChant() ?? installedChant(options.from ?? [])) : undefined;
|
|
370
|
+
const fallback = options.resolveFallback === true ? fallbackImportArgs() : typeof options.resolveFallback === "string" ? fallbackImportArgs(options.resolveFallback) : [];
|
|
371
|
+
const [command, ...argv] = install ? chantArgv(args, { install, nodeArgs: [...fallback, ...(options.nodeArgs ?? [])] }) : [options.chant ?? "chant", ...args];
|
|
372
|
+
const env = { ...chantEnv(options.env ?? process.env, install), ...(options.noColor ? { FORCE_COLOR: "0", NO_COLOR: "1" } : {}) };
|
|
373
|
+
const piped = options.stdio !== "inherit";
|
|
374
|
+
return new Promise((done, reject) => {
|
|
375
|
+
const child = spawn(command!, argv, { cwd: options.cwd ?? process.cwd(), env, stdio: ["ignore", piped ? "pipe" : "inherit", piped ? "pipe" : "inherit"] });
|
|
376
|
+
let stdout = "";
|
|
377
|
+
let stderr = "";
|
|
378
|
+
child.stdout?.setEncoding("utf8");
|
|
379
|
+
child.stderr?.setEncoding("utf8");
|
|
380
|
+
child.stdout?.on("data", (chunk: string) => {
|
|
381
|
+
stdout += chunk;
|
|
382
|
+
options.onStdout?.(chunk);
|
|
383
|
+
});
|
|
384
|
+
child.stderr?.on("data", (chunk: string) => {
|
|
385
|
+
stderr += chunk;
|
|
386
|
+
options.onStderr?.(chunk);
|
|
387
|
+
});
|
|
388
|
+
child.on("error", reject);
|
|
389
|
+
child.on("close", (code, signal) => {
|
|
390
|
+
const json = lastJsonLine(stdout);
|
|
391
|
+
done({ code: code ?? (signal ? 128 : 1), stdout, stderr, ...(json !== undefined ? { json } : {}) });
|
|
392
|
+
});
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* The last line of `stdout` that parses as a JSON object: chant prints its
|
|
398
|
+
* `--json` document as one line, after any log lines. A pretty-printed
|
|
399
|
+
* document is read from the first `{` to the end. Undefined when there is
|
|
400
|
+
* none.
|
|
401
|
+
*/
|
|
402
|
+
export function lastJsonLine(stdout: string): unknown {
|
|
403
|
+
const lines = stdout.split("\n").map((l) => l.trim()).filter((l) => l.startsWith("{"));
|
|
404
|
+
for (const line of lines.reverse()) {
|
|
405
|
+
try {
|
|
406
|
+
return JSON.parse(line) as unknown;
|
|
407
|
+
} catch {
|
|
408
|
+
// A log line that starts with "{"; keep looking.
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
const at = stdout.indexOf("{");
|
|
412
|
+
if (at >= 0) {
|
|
413
|
+
try {
|
|
414
|
+
return JSON.parse(stdout.slice(at)) as unknown;
|
|
415
|
+
} catch {
|
|
416
|
+
// Not JSON.
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
return undefined;
|
|
420
|
+
}
|
package/src/ci-commit.test.ts
CHANGED
|
@@ -35,7 +35,8 @@ import {
|
|
|
35
35
|
type CommitSettings,
|
|
36
36
|
type OpCommitSpec,
|
|
37
37
|
} from "./ci-commit";
|
|
38
|
-
import {
|
|
38
|
+
import { COMMENT_LEAVES_COMMIT_FLOOR } from "./ci-product";
|
|
39
|
+
import { assertProductWords, commitWordOf, parseProductComment } from "./ci-product-words";
|
|
39
40
|
import { PLYWOOD } from "./__fixtures__/product-words";
|
|
40
41
|
import { NEXT_RELEASE } from "./release-floors";
|
|
41
42
|
import type { OpRunRecord, OpRunRecordInput } from "./op/runtime";
|
|
@@ -574,7 +575,7 @@ describe("the comment's argument (#4820)", () => {
|
|
|
574
575
|
expect(refused.result).toBe("refused");
|
|
575
576
|
});
|
|
576
577
|
|
|
577
|
-
test("the floor is the
|
|
578
|
+
test("the floor is the release that shipped it", () => {
|
|
578
579
|
expect(CI_COMMIT_ARG_FLOOR).toBe("0.124.78");
|
|
579
580
|
});
|
|
580
581
|
});
|
|
@@ -617,8 +618,53 @@ describe("a comment refused as it is read gets a reply (#4838)", () => {
|
|
|
617
618
|
expect(long.replies[0]).toMatch(new RegExp(`^plywood: \`/plywood fmt x{84}\\.\\.\\.\` was refused`));
|
|
618
619
|
});
|
|
619
620
|
|
|
620
|
-
test("the floor is the
|
|
621
|
-
expect(CI_COMMIT_REFUSAL_REPLY_FLOOR).toBe(
|
|
621
|
+
test("the floor is the release that shipped it", () => {
|
|
622
|
+
expect(CI_COMMIT_REFUSAL_REPLY_FLOOR).toBe("0.124.86");
|
|
623
|
+
});
|
|
624
|
+
});
|
|
625
|
+
|
|
626
|
+
describe("a comment job leaves the commit job's words to it, so a comment gets one reply (#4890)", () => {
|
|
627
|
+
const named = () => settings({ commentArg: { pattern: "^[a-z0-9]+(?:[-_][a-z0-9]+)*$", position: 1 } });
|
|
628
|
+
/** What a comment job that is not the commit job makes of the comment: a refusal is a reply. */
|
|
629
|
+
const commentJob = (body: string, leaveCommit: boolean) => parseProductComment(words, body, {}, {}, { leaveCommit });
|
|
630
|
+
|
|
631
|
+
test("a malformed comment for a commit word is answered by the commit job alone", async () => {
|
|
632
|
+
for (const [s, body] of [
|
|
633
|
+
[settings(), "/plywood fmt now"],
|
|
634
|
+
[named(), "/plywood fmt Bad"],
|
|
635
|
+
[settings(), "/plywood fmt\nand more"],
|
|
636
|
+
[settings(), "/plywood\tfmt now"],
|
|
637
|
+
] as const) {
|
|
638
|
+
const w = world();
|
|
639
|
+
await cycle(w, s, { event: comment(body) });
|
|
640
|
+
expect(w.replies, body).toHaveLength(1);
|
|
641
|
+
// Without leaveCommit the comment job refused it too: the second reply #4890 is about.
|
|
642
|
+
expect(commentJob(body, false), body).toMatchObject({ kind: "refused" });
|
|
643
|
+
expect(commentJob(body, true), body).toBeUndefined();
|
|
644
|
+
expect(commitWordOf(words, body), body).toBe("fmt");
|
|
645
|
+
}
|
|
646
|
+
});
|
|
647
|
+
|
|
648
|
+
test("a well-formed commit comment is the commit job's too, and every other comment is still the comment job's", () => {
|
|
649
|
+
expect(commentJob("/plywood fmt", true)).toBeUndefined();
|
|
650
|
+
expect(commentJob("/plywood up now", true)).toMatchObject({ kind: "refused" });
|
|
651
|
+
expect(commentJob("/plywood up", true)).toEqual({ kind: "apply" });
|
|
652
|
+
expect(commentJob("/plywood fmtx", true)).toMatchObject({ kind: "refused", reason: expect.stringMatching(/the commands are/) });
|
|
653
|
+
expect(commentJob("/plywood", true)).toMatchObject({ kind: "refused" });
|
|
654
|
+
expect(commentJob("/plywoodfmt", true)).toBeUndefined();
|
|
655
|
+
expect(commitWordOf(words, "/plywood up")).toBeUndefined();
|
|
656
|
+
expect(commitWordOf(words, "/plywood constructor")).toBeUndefined();
|
|
657
|
+
expect(commitWordOf(words, 7)).toBeUndefined();
|
|
658
|
+
});
|
|
659
|
+
|
|
660
|
+
test("an alias for a commit word is left to the commit job", () => {
|
|
661
|
+
const aliased = assertProductWords({ ...PLYWOOD, commands: { ...PLYWOOD.commands, fmt: "commit" as const }, aliases: [{ from: "pw fmt", command: "commit" as const }] });
|
|
662
|
+
expect(parseProductComment(aliased, "pw fmt")).toEqual({ kind: "commit", word: "fmt" });
|
|
663
|
+
expect(parseProductComment(aliased, "pw fmt", {}, {}, { leaveCommit: true })).toBeUndefined();
|
|
664
|
+
});
|
|
665
|
+
|
|
666
|
+
test("the floor is the next release", () => {
|
|
667
|
+
expect(COMMENT_LEAVES_COMMIT_FLOOR).toBe(NEXT_RELEASE);
|
|
622
668
|
});
|
|
623
669
|
});
|
|
624
670
|
|
|
@@ -685,7 +731,7 @@ describe("the harness's BREAK switch for land (#4836)", () => {
|
|
|
685
731
|
expect(out).toMatchObject({ result: "refused", reason: "the base moved" });
|
|
686
732
|
});
|
|
687
733
|
|
|
688
|
-
test("the floor is the
|
|
734
|
+
test("the floor is the release that shipped it", () => {
|
|
689
735
|
expect(CI_COMMIT_HARNESS_BREAK_FLOOR).toBe("0.124.78");
|
|
690
736
|
});
|
|
691
737
|
});
|
package/src/ci-commit.ts
CHANGED
|
@@ -29,7 +29,6 @@ import { spawn } from "node:child_process";
|
|
|
29
29
|
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
30
30
|
import { join } from "node:path";
|
|
31
31
|
import { CHANT_EXIT } from "./exit-codes";
|
|
32
|
-
import { NEXT_RELEASE } from "./release-floors";
|
|
33
32
|
import { FORGE_TOKEN_VARS } from "./ci-handover";
|
|
34
33
|
import { agentForbiddenPaths, AgentError, branchOk, errText, LOGIN, readSmall, SHA, type AgentGit } from "./ci-agent";
|
|
35
34
|
import { COMMIT_COMMENT_ARG, parseProductComment, type CiProductWords } from "./ci-product-words";
|
|
@@ -55,7 +54,7 @@ export const CI_COMMIT_ARG_FLOOR = "0.124.78";
|
|
|
55
54
|
/** The first chant whose `commit land` reads {@link COMMIT_HARNESS_BREAK_ENV} in a BREAK arm of chant's e2e harness (#4836). */
|
|
56
55
|
export const CI_COMMIT_HARNESS_BREAK_FLOOR = "0.124.78";
|
|
57
56
|
/** The first chant whose `commit land` replies to a comment refused as it is read, such as a bad argument or a stray word (#4838). */
|
|
58
|
-
export const CI_COMMIT_REFUSAL_REPLY_FLOOR =
|
|
57
|
+
export const CI_COMMIT_REFUSAL_REPLY_FLOOR = "0.124.86";
|
|
59
58
|
|
|
60
59
|
/** What starts a commit run: a person's comment, or a check job's finding. */
|
|
61
60
|
export type CommitTrigger = "comment" | "check";
|
package/src/ci-control.ts
CHANGED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The claim files a check's step leaves for a signer in another job (#4926),
|
|
3
|
+
* and the variable that names which step or job each check's pass is read
|
|
4
|
+
* from. No import beyond node's, so the wave runner and the generators carry
|
|
5
|
+
* it at no cost.
|
|
6
|
+
*
|
|
7
|
+
* A step that ran a check writes `<dir>/<check>.json` (`:` turned into `-`):
|
|
8
|
+
* the check's name, whether the step saw it pass, and what it said (the
|
|
9
|
+
* claim the statement digests). The step runs the change's code, so the file
|
|
10
|
+
* is data and never enough on its own: `chant ci evidence sign --from-job`
|
|
11
|
+
* signs a check only when the forge reports that step (on GitLab, that job)
|
|
12
|
+
* concluded `success` and the file says the check passed
|
|
13
|
+
* (./ci-evidence-from-job.ts).
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
17
|
+
import { join } from "node:path";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The variable a `--from-job` signing step reads its sources from: JSON,
|
|
21
|
+
* each check to the job (default `--from-job`'s) and the step whose
|
|
22
|
+
* conclusion stands for it. A check with no step is read from its job's
|
|
23
|
+
* own status, as on GitLab.
|
|
24
|
+
*/
|
|
25
|
+
export const EVIDENCE_SOURCES_ENV = "CHANT_EVIDENCE_SOURCES";
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* What a generated wave command step signs itself (#4926), set by the
|
|
29
|
+
* generator beside the wave's evidence job: `plan` signs `plan:<wave>` and
|
|
30
|
+
* leaves `policy:<wave>` to the evidence job, which reads the policy step's
|
|
31
|
+
* result; `job` signs nothing and leaves both. Either way the step writes
|
|
32
|
+
* `plan:<wave>`'s claim file for that job. Unset, the step signs both as it
|
|
33
|
+
* did (#4870). See ./op/op-waves-evidence.ts.
|
|
34
|
+
*/
|
|
35
|
+
export const WAVE_EVIDENCE_ENV = "CHANT_WAVE_EVIDENCE";
|
|
36
|
+
|
|
37
|
+
/** Where one check's pass is read from (#4926). */
|
|
38
|
+
export interface EvidenceSourceSpec {
|
|
39
|
+
/** The job's name in the run. Default: `--from-job`'s. */
|
|
40
|
+
job?: string;
|
|
41
|
+
/** The step's name in that job, as the forge lists it. Without it, the job's own result. */
|
|
42
|
+
step?: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** What a check's step wrote for its signer. */
|
|
46
|
+
export interface CheckClaimFile {
|
|
47
|
+
check: string;
|
|
48
|
+
passed: boolean;
|
|
49
|
+
/** What the check said, digested into the statement's `claim`. */
|
|
50
|
+
claim?: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** The file name a check's claim is kept under: `plan:dev` is `plan-dev.json`. */
|
|
54
|
+
export function checkClaimFileName(check: string): string {
|
|
55
|
+
return `${check.replace(/[^A-Za-z0-9._-]/g, "-")}.json`;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Write a check's claim file in `dir`. Returns its path. */
|
|
59
|
+
export function writeCheckClaimFile(dir: string, file: CheckClaimFile): string {
|
|
60
|
+
mkdirSync(dir, { recursive: true });
|
|
61
|
+
const path = join(dir, checkClaimFileName(file.check));
|
|
62
|
+
writeFileSync(path, JSON.stringify({ check: file.check, passed: file.passed, ...(file.claim !== undefined ? { claim: file.claim } : {}) }, null, 2) + "\n");
|
|
63
|
+
return path;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** A check's claim file in `dir`, or why there is none that counts. Read as data: a file for another check, or of another shape, does not count. */
|
|
67
|
+
export function readCheckClaimFile(dir: string, check: string): CheckClaimFile | { problem: string } {
|
|
68
|
+
const name = checkClaimFileName(check);
|
|
69
|
+
let doc: unknown;
|
|
70
|
+
try {
|
|
71
|
+
doc = JSON.parse(readFileSync(join(dir, name), "utf-8"));
|
|
72
|
+
} catch {
|
|
73
|
+
return { problem: `the job left no readable ${name}` };
|
|
74
|
+
}
|
|
75
|
+
const d = doc && typeof doc === "object" ? (doc as Record<string, unknown>) : {};
|
|
76
|
+
if (d.check !== check || typeof d.passed !== "boolean" || (d.claim !== undefined && typeof d.claim !== "string")) return { problem: `${name} is not ${check}'s claim file` };
|
|
77
|
+
return { check, passed: d.passed, ...(typeof d.claim === "string" ? { claim: d.claim } : {}) };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** The sources `CHANT_EVIDENCE_SOURCES` names, or why they do not read. A step name alone stands for `{ step }`. */
|
|
81
|
+
export function parseEvidenceSources(raw: string | undefined): { sources: Record<string, EvidenceSourceSpec> } | { problem: string } {
|
|
82
|
+
if (raw === undefined || raw.trim() === "") return { sources: {} };
|
|
83
|
+
let doc: unknown;
|
|
84
|
+
try {
|
|
85
|
+
doc = JSON.parse(raw);
|
|
86
|
+
} catch (err) {
|
|
87
|
+
return { problem: `${EVIDENCE_SOURCES_ENV} is not JSON: ${err instanceof Error ? err.message : String(err)}` };
|
|
88
|
+
}
|
|
89
|
+
if (!doc || typeof doc !== "object" || Array.isArray(doc)) return { problem: `${EVIDENCE_SOURCES_ENV} must map each check to its job and step` };
|
|
90
|
+
const out: Record<string, EvidenceSourceSpec> = {};
|
|
91
|
+
for (const [check, v] of Object.entries(doc as Record<string, unknown>)) {
|
|
92
|
+
if (typeof v === "string" && v !== "") out[check] = { step: v };
|
|
93
|
+
else if (v && typeof v === "object" && !Array.isArray(v)) {
|
|
94
|
+
const o = v as Record<string, unknown>;
|
|
95
|
+
if ((o.job !== undefined && (typeof o.job !== "string" || o.job === "")) || (o.step !== undefined && (typeof o.step !== "string" || o.step === ""))) {
|
|
96
|
+
return { problem: `${EVIDENCE_SOURCES_ENV}: ${check}'s job and step must be names` };
|
|
97
|
+
}
|
|
98
|
+
out[check] = { ...(typeof o.job === "string" ? { job: o.job } : {}), ...(typeof o.step === "string" ? { step: o.step } : {}) };
|
|
99
|
+
} else return { problem: `${EVIDENCE_SOURCES_ENV}: ${check} must name a step, or { job, step }` };
|
|
100
|
+
}
|
|
101
|
+
return { sources: out };
|
|
102
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #4926: `chant ci evidence sign --from-job` against a fake forge. It signs
|
|
3
|
+
* only the checks whose steps passed, refuses a job of another commit or
|
|
4
|
+
* run, gives a failed policy step no `policy:` evidence whatever its claim
|
|
5
|
+
* file says, and each statement names the run, job and step it relied on.
|
|
6
|
+
* The forge's job records come through the real reads with a fake `fetch`;
|
|
7
|
+
* the signing is a real runner key over a local repository.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { execFileSync } from "node:child_process";
|
|
11
|
+
import { generateKeyPairSync } from "node:crypto";
|
|
12
|
+
import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
|
|
13
|
+
import { tmpdir } from "node:os";
|
|
14
|
+
import { join } from "node:path";
|
|
15
|
+
import { describe, expect, test } from "vitest";
|
|
16
|
+
import type { ForgeFetch } from "./pr-forge";
|
|
17
|
+
import { githubReads, gitlabReads, type ForgeReads, type RunJob } from "./pr-forge-reads";
|
|
18
|
+
import { checksFromJob, signFromJob } from "./ci-evidence-from-job";
|
|
19
|
+
import { checkClaimFileName, parseEvidenceSources, readCheckClaimFile, writeCheckClaimFile } from "./ci-evidence-claims";
|
|
20
|
+
import { loadRunnerKey } from "./workspace/trust/dsse";
|
|
21
|
+
import { readCheckEvidence } from "./workspace/trust/check-evidence";
|
|
22
|
+
|
|
23
|
+
const SHA = "a".repeat(40);
|
|
24
|
+
const PLAN_STEP = "Plan, gate and apply wave 1 (dev)";
|
|
25
|
+
const POLICY_STEP = "Check wave 1 (dev)'s plans against the policy";
|
|
26
|
+
const SOURCES = { "plan:dev": { step: PLAN_STEP }, "policy:dev": { step: POLICY_STEP } };
|
|
27
|
+
|
|
28
|
+
/** A run's jobs as GitHub lists them, through the real reads. */
|
|
29
|
+
function githubRun(run: number, jobs: unknown[]): Pick<ForgeReads, "runJobs"> {
|
|
30
|
+
const fetch: ForgeFetch = async (url) => {
|
|
31
|
+
const u = new URL(url);
|
|
32
|
+
if (u.pathname !== `/repos/acme/infra/actions/runs/${run}/jobs`) return { ok: false, status: 404, text: async () => "{}" };
|
|
33
|
+
return { ok: true, status: 200, text: async () => JSON.stringify({ total_count: jobs.length, jobs }) };
|
|
34
|
+
};
|
|
35
|
+
return githubReads({ apiBase: "https://api.github.com", repo: "acme/infra", token: "t", fetch });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const step = (name: string, conclusion: string, number: number) => ({ name, status: "completed", conclusion, number });
|
|
39
|
+
const waveJob = (over: Record<string, unknown> = {}, steps = [step(POLICY_STEP, "success", 4), step(PLAN_STEP, "success", 5)]) => ({ id: 77, run_id: 9, name: "wave-1-dev", status: "completed", conclusion: "success", head_sha: SHA, steps, ...over });
|
|
40
|
+
|
|
41
|
+
describe("the forge's record of a job (#4926)", () => {
|
|
42
|
+
test("github and forgejo name the commit and the steps; gitlab names the pipeline's commit and no steps", async () => {
|
|
43
|
+
const [job] = await githubRun(9, [waveJob()]).runJobs(9);
|
|
44
|
+
expect(job).toMatchObject({ id: 77, run: 9, headSha: SHA, conclusion: "success" });
|
|
45
|
+
expect(job!.steps).toEqual([{ name: POLICY_STEP, number: 4, status: "completed", conclusion: "success" }, { name: PLAN_STEP, number: 5, status: "completed", conclusion: "success" }]);
|
|
46
|
+
const fetch: ForgeFetch = async () => ({ ok: true, status: 200, text: async () => JSON.stringify([{ id: 5, name: "wave-1-dev-policy", status: "failed", pipeline: { id: 9, sha: SHA }, commit: { id: SHA } }]) });
|
|
47
|
+
const [gl] = await gitlabReads({ apiBase: "https://gitlab.com/api/v4", project: "acme/infra", token: "t", fetch }).runJobs(9);
|
|
48
|
+
expect(gl).toEqual({ id: 5, name: "wave-1-dev-policy", status: "failed", done: true, run: 9, headSha: SHA });
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe("which checks a job's record lets the evidence job sign (#4926)", () => {
|
|
53
|
+
const claims = (files: Array<{ check: string; passed: boolean; claim?: string }>): string => {
|
|
54
|
+
const dir = mkdtempSync(join(tmpdir(), "chant-4926-claims-"));
|
|
55
|
+
for (const f of files) writeCheckClaimFile(dir, f);
|
|
56
|
+
return dir;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
test("signs only the checks whose steps passed, each with the run, job and step it read", async () => {
|
|
60
|
+
const reads = githubRun(9, [waveJob({}, [step(POLICY_STEP, "failure", 4), step(PLAN_STEP, "success", 5)])]);
|
|
61
|
+
const got = await checksFromJob({ reads, run: 9, sha: SHA, fromJob: "wave-1-dev", checks: ["plan:dev", "policy:dev"], sources: SOURCES });
|
|
62
|
+
expect(got).toEqual({
|
|
63
|
+
sign: [{ check: "plan:dev", source: { run: 9, job: 77, step: PLAN_STEP } }],
|
|
64
|
+
skipped: [{ check: "policy:dev", reason: `step ${JSON.stringify(POLICY_STEP)} of job wave-1-dev concluded failure` }],
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("a failed policy step gets no policy evidence even when its claim file says it passed", async () => {
|
|
69
|
+
const dir = claims([{ check: "plan:dev", passed: true, claim: "sha256:1" }, { check: "policy:dev", passed: true, claim: "[]" }]);
|
|
70
|
+
const reads = githubRun(9, [waveJob({ conclusion: "failure" }, [step(POLICY_STEP, "failure", 4), step(PLAN_STEP, "success", 5)])]);
|
|
71
|
+
const got = await checksFromJob({ reads, run: 9, sha: SHA, fromJob: "wave-1-dev", checks: ["plan:dev", "policy:dev"], sources: SOURCES, claims: dir });
|
|
72
|
+
expect("sign" in got && got.sign.map((s) => [s.check, s.claim])).toEqual([["plan:dev", "sha256:1"]]);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test("a passed step whose claim file says the check did not pass, or left none, signs nothing", async () => {
|
|
76
|
+
const dir = claims([{ check: "policy:dev", passed: false }]);
|
|
77
|
+
const got = await checksFromJob({ reads: githubRun(9, [waveJob()]), run: 9, sha: SHA, fromJob: "wave-1-dev", checks: ["plan:dev", "policy:dev"], sources: SOURCES, claims: dir });
|
|
78
|
+
expect(got).toEqual({
|
|
79
|
+
sign: [],
|
|
80
|
+
skipped: [
|
|
81
|
+
{ check: "plan:dev", reason: `the job left no readable ${checkClaimFileName("plan:dev")}` },
|
|
82
|
+
{ check: "policy:dev", reason: "job wave-1-dev's claim file says policy:dev did not pass" },
|
|
83
|
+
],
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test("a job of another commit or another run is refused", async () => {
|
|
88
|
+
const other = "b".repeat(40);
|
|
89
|
+
expect(await checksFromJob({ reads: githubRun(9, [waveJob({ head_sha: other })]), run: 9, sha: SHA, fromJob: "wave-1-dev", checks: ["plan:dev"], sources: SOURCES })).toEqual({
|
|
90
|
+
refused: `job wave-1-dev (77) ran for commit ${other.slice(0, 12)}, not this run's ${SHA.slice(0, 12)}`,
|
|
91
|
+
});
|
|
92
|
+
expect(await checksFromJob({ reads: githubRun(9, [waveJob({ run_id: 8 })]), run: 9, sha: SHA, fromJob: "wave-1-dev", checks: ["plan:dev"], sources: SOURCES })).toEqual({ refused: "job wave-1-dev (77) belongs to run 8, not this run 9" });
|
|
93
|
+
expect(await checksFromJob({ reads: githubRun(9, []), run: 9, sha: SHA, fromJob: "wave-1-dev", checks: ["plan:dev"] })).toEqual({ refused: "run 9 has no job named wave-1-dev" });
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test("on gitlab a check is read from its job's status, the policy from the policy job", async () => {
|
|
97
|
+
const jobs: RunJob[] = [
|
|
98
|
+
{ id: 40, name: "wave-1-dev", status: "success", done: true, run: 9, headSha: SHA },
|
|
99
|
+
{ id: 41, name: "wave-1-dev-policy", status: "failed", done: true, run: 9, headSha: SHA },
|
|
100
|
+
];
|
|
101
|
+
const got = await checksFromJob({ reads: { runJobs: async () => jobs }, run: 9, sha: SHA, fromJob: "wave-1-dev", checks: ["plan:dev", "policy:dev"], sources: { "policy:dev": { job: "wave-1-dev-policy" } } });
|
|
102
|
+
expect(got).toEqual({ sign: [{ check: "plan:dev", source: { run: 9, job: 40 } }], skipped: [{ check: "policy:dev", reason: "job wave-1-dev-policy ended failed" }] });
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test("the sources and claim files read as data", () => {
|
|
106
|
+
expect(parseEvidenceSources('{"plan:dev":"Plan","policy:dev":{"job":"p"}}')).toEqual({ sources: { "plan:dev": { step: "Plan" }, "policy:dev": { job: "p" } } });
|
|
107
|
+
expect(parseEvidenceSources("[]")).toHaveProperty("problem");
|
|
108
|
+
const dir = mkdtempSync(join(tmpdir(), "chant-4926-claim-"));
|
|
109
|
+
writeFileSync(join(dir, checkClaimFileName("policy:dev")), JSON.stringify({ check: "policy:prod", passed: true }));
|
|
110
|
+
expect(readCheckClaimFile(dir, "policy:dev")).toEqual({ problem: "policy-dev.json is not policy:dev's claim file" });
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
function git(cwd: string, ...args: string[]): string {
|
|
115
|
+
return execFileSync("git", ["-c", "user.name=t", "-c", "user.email=t@example.invalid", "-c", "init.defaultBranch=main", ...args], { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] }).trim();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
describe("signFromJob (#4926)", () => {
|
|
119
|
+
test("signs the passed checks over the run's commit, with the source in the statement, and refuses another commit", async () => {
|
|
120
|
+
const cwd = mkdtempSync(join(tmpdir(), "chant-4926-sign-"));
|
|
121
|
+
const { privateKey } = generateKeyPairSync("ed25519");
|
|
122
|
+
const pem = privateKey.export({ format: "pem", type: "pkcs8" }).toString();
|
|
123
|
+
git(cwd, "init", "--quiet");
|
|
124
|
+
mkdirSync(join(cwd, ".chant"));
|
|
125
|
+
writeFileSync(join(cwd, ".chant/trust.json"), JSON.stringify({ schema: 1, runners: [{ principal: "ci", class: "runner", key: loadRunnerKey(pem).publicKey }] }));
|
|
126
|
+
git(cwd, "add", ".");
|
|
127
|
+
git(cwd, "commit", "--quiet", "-m", "base");
|
|
128
|
+
const base = git(cwd, "rev-parse", "HEAD");
|
|
129
|
+
writeFileSync(join(cwd, "main.tf"), "# change\n");
|
|
130
|
+
git(cwd, "add", "main.tf");
|
|
131
|
+
git(cwd, "commit", "--quiet", "-m", "merge");
|
|
132
|
+
const head = git(cwd, "rev-parse", "HEAD");
|
|
133
|
+
const reads = githubRun(9, [waveJob({ head_sha: head }, [step(POLICY_STEP, "failure", 4), step(PLAN_STEP, "success", 5)])]);
|
|
134
|
+
const env = { GITHUB_RUN_ID: "9", GITHUB_SHA: head, CHANT_EVIDENCE_SOURCES: JSON.stringify(SOURCES) } as NodeJS.ProcessEnv;
|
|
135
|
+
const logs: string[] = [];
|
|
136
|
+
const done = await signFromJob({ repo: cwd, base, fromJob: "wave-1-dev", checks: ["plan:dev", "policy:dev"], reads, env, key: pem, push: false, log: (l) => logs.push(l) });
|
|
137
|
+
expect(done).toMatchObject({ signed: [{ check: "plan:dev", runner: "ci", commit: head, source: { run: 9, job: 77, step: PLAN_STEP } }] });
|
|
138
|
+
expect((await readCheckEvidence(cwd, head, base, ["plan:dev", "policy:dev"])).map((v) => v.status)).toEqual(["current", "missing"]);
|
|
139
|
+
const note = git(cwd, "notes", "--ref", "refs/notes/chant/evidence", "show", head);
|
|
140
|
+
const statement = JSON.parse(Buffer.from(JSON.parse(note.split("\n")[0]!).payload, "base64").toString("utf8"));
|
|
141
|
+
expect(statement.predicate.source).toEqual({ run: 9, job: 77, step: PLAN_STEP });
|
|
142
|
+
expect(logs.some((l) => l.startsWith("ci evidence: policy:dev not signed: step"))).toBe(true);
|
|
143
|
+
expect(await signFromJob({ repo: cwd, base, fromJob: "wave-1-dev", checks: ["plan:dev"], at: base, reads, env, key: pem, push: false, log: () => {} })).toEqual({
|
|
144
|
+
refused: `--at names ${base.slice(0, 12)}, and this run is for ${head.slice(0, 12)}; --from-job signs only the run's own commit`,
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
});
|