@cnc-tools/storm 0.14.2 → 0.16.0
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/application.js +3 -1
- package/dist/bin/storm.js +9 -7
- package/dist/build-info.js +1 -1
- package/dist/chunks/chunk-2MAD5NKK.js +108 -0
- package/dist/chunks/{chunk-HDL4WKIB.js → chunk-3L52KNQA.js} +2 -2
- package/dist/chunks/{chunk-GSC6SRTW.js → chunk-5CCP36QQ.js} +1 -1
- package/dist/chunks/{chunk-43MWZLJR.js → chunk-5VXBKPW6.js} +1 -1
- package/dist/chunks/chunk-7EENF73W.js +782 -0
- package/dist/chunks/{chunk-RA4L2ACU.js → chunk-AWBSONHB.js} +88 -34
- package/dist/chunks/chunk-CK2GZEPK.js +40 -0
- package/dist/chunks/{chunk-BRUIATTR.js → chunk-CN4EFA5J.js} +59 -12
- package/dist/chunks/{chunk-I7AN3DIJ.js → chunk-DC2CDHNK.js} +1928 -738
- package/dist/chunks/{chunk-UUBZTGLV.js → chunk-DWEAHX4T.js} +140 -130
- package/dist/chunks/{chunk-T6AZIDZD.js → chunk-F6N34UWB.js} +12 -244
- package/dist/chunks/chunk-FCQUJDA4.js +963 -0
- package/dist/chunks/{chunk-VH2POPW5.js → chunk-FOZWA52V.js} +635 -79
- package/dist/chunks/{chunk-XZCDA5PE.js → chunk-G3PHMXH5.js} +7 -2
- package/dist/chunks/{chunk-3HBPNQ4Y.js → chunk-HVNK3I45.js} +2 -2
- package/dist/chunks/chunk-OIY3DMF2.js +74 -0
- package/dist/chunks/{chunk-GJOEPJJL.js → chunk-P357TZAY.js} +446 -52
- package/dist/chunks/{chunk-UC6DULWY.js → chunk-R7XVBZOY.js} +130 -39
- package/dist/chunks/chunk-TJNFVNKR.js +246 -0
- package/dist/chunks/{chunk-RUPD4TLT.js → chunk-V4IKA3WI.js} +198 -63
- package/dist/chunks/{chunk-BW2ADH7U.js → chunk-VUPZH7J2.js} +1 -1
- package/dist/chunks/{chunk-LUOHJ3LB.js → chunk-Z5PBVG3Y.js} +1131 -468
- package/dist/chunks/{chunk-GQIL3AHY.js → chunk-ZG3WQ4UF.js} +1 -1
- package/dist/chunks/{live-app-SZGEILCQ.js → live-app-WECQOQ4C.js} +28 -23
- package/dist/command-tree.d.ts +2 -2
- package/dist/command-tree.js +2 -2
- package/dist/commands/exec/across-sandboxes-outcomes.d.ts +364 -0
- package/dist/commands/exec/across-sandboxes-outcomes.js +230 -0
- package/dist/commands/exec/across-sandboxes-run.d.ts +180 -0
- package/dist/commands/exec/across-sandboxes-run.js +339 -0
- package/dist/commands/exec/command.d.ts +583 -75
- package/dist/commands/exec/command.js +165 -32
- package/dist/commands/exec/driver-plan.d.ts +8 -2
- package/dist/commands/exec/driver-plan.js +13 -3
- package/dist/commands/exec/exec-words.d.ts +17 -3
- package/dist/commands/exec/exec-words.js +27 -16
- package/dist/commands/exec/live-view.d.ts +3 -4
- package/dist/commands/exec/live-view.js +37 -28
- package/dist/commands/exec/metadata.js +2 -2
- package/dist/commands/exec/mint-failed.d.ts +4 -4
- package/dist/commands/exec/mint-failed.js +6 -6
- package/dist/commands/exec/outcomes.d.ts +533 -73
- package/dist/commands/exec/outcomes.js +203 -67
- package/dist/commands/exec/plan-only.d.ts +10 -0
- package/dist/commands/exec/plan-only.js +45 -0
- package/dist/commands/exec/plan-run.d.ts +54 -35
- package/dist/commands/exec/plan-run.js +81 -38
- package/dist/commands/exec/planned-outcome.d.ts +15 -0
- package/dist/commands/exec/planned-outcome.js +42 -0
- package/dist/commands/exec/progress.d.ts +2 -2
- package/dist/commands/exec/progress.js +35 -18
- package/dist/commands/exec/resource-refusals.d.ts +2 -2
- package/dist/commands/exec/resource-refusals.js +3 -3
- package/dist/commands/exec/run-bin.d.ts +1 -1
- package/dist/commands/exec/run-bin.js +2 -2
- package/dist/commands/exec/run-command.d.ts +344 -63
- package/dist/commands/exec/run-command.js +312 -263
- package/dist/commands/exec/run-metadata.d.ts +42 -8
- package/dist/commands/exec/run-metadata.js +40 -21
- package/dist/commands/exec/run-planned.d.ts +20 -0
- package/dist/commands/exec/run-planned.js +22 -0
- package/dist/commands/exec/sandbox-lines.d.ts +42 -0
- package/dist/commands/exec/sandbox-lines.js +59 -0
- package/dist/commands/exec/sandbox-progress.d.ts +30 -0
- package/dist/commands/exec/sandbox-progress.js +232 -0
- package/dist/commands/exec/sandbox-view.d.ts +19 -0
- package/dist/commands/exec/sandbox-view.js +72 -0
- package/dist/commands/exec/view.d.ts +3 -2
- package/dist/commands/exec/view.js +10 -6
- package/dist/commands/runs/facts.d.ts +53 -10
- package/dist/commands/runs/facts.js +60 -32
- package/dist/commands/runs/list/command.d.ts +82 -4
- package/dist/commands/runs/list/command.js +11 -10
- package/dist/commands/runs/list/metadata.js +1 -1
- package/dist/commands/runs/list/outcomes.d.ts +41 -2
- package/dist/commands/runs/logs/command.d.ts +109 -10
- package/dist/commands/runs/logs/command.js +139 -24
- package/dist/commands/runs/logs/metadata.d.ts +4 -0
- package/dist/commands/runs/logs/metadata.js +14 -7
- package/dist/commands/runs/logs/outcomes.d.ts +52 -3
- package/dist/commands/runs/logs/outcomes.js +110 -6
- package/dist/commands/runs/past-run.d.ts +91 -11
- package/dist/commands/runs/past-run.js +149 -9
- package/dist/commands/runs/show/command.d.ts +574 -12
- package/dist/commands/runs/show/command.js +634 -119
- package/dist/commands/runs/show/metadata.d.ts +17 -0
- package/dist/commands/runs/show/metadata.js +48 -7
- package/dist/commands/runs/show/outcomes.d.ts +279 -6
- package/dist/commands/runs/show/outcomes.js +484 -96
- package/dist/commands/snapshots/build/command.d.ts +109 -18
- package/dist/commands/snapshots/build/command.js +72 -36
- package/dist/commands/snapshots/build/metadata.d.ts +4 -0
- package/dist/commands/snapshots/build/metadata.js +5 -1
- package/dist/commands/snapshots/build/outcomes.d.ts +53 -8
- package/dist/commands/snapshots/build/outcomes.js +26 -3
- package/dist/commands/snapshots/list/command.d.ts +72 -7
- package/dist/commands/snapshots/list/command.js +57 -24
- package/dist/commands/snapshots/list/metadata.d.ts +4 -0
- package/dist/commands/snapshots/list/metadata.js +5 -1
- package/dist/commands/snapshots/list/outcomes.d.ts +31 -0
- package/dist/commands/snapshots/list/outcomes.js +25 -2
- package/dist/commands/suites/list/command.d.ts +129 -0
- package/dist/commands/suites/list/command.js +163 -0
- package/dist/commands/suites/list/metadata.d.ts +11 -0
- package/dist/commands/suites/list/metadata.js +15 -0
- package/dist/commands/suites/list/outcomes.d.ts +91 -0
- package/dist/commands/suites/list/outcomes.js +122 -0
- package/dist/commands/suites/metadata.js +8 -0
- package/dist/commands/test/command.d.ts +1395 -0
- package/dist/commands/test/command.js +581 -0
- package/dist/commands/test/metadata.js +8 -0
- package/dist/commands/test/outcomes.d.ts +768 -0
- package/dist/commands/test/outcomes.js +140 -0
- package/dist/commands/test/plan.d.ts +92 -0
- package/dist/commands/test/plan.js +125 -0
- package/dist/commands/test/test-words.d.ts +12 -0
- package/dist/commands/test/test-words.js +42 -0
- package/dist/config/check-resources.d.ts +14 -0
- package/dist/config/check-resources.js +98 -0
- package/dist/config/check-runner.d.ts +15 -0
- package/dist/config/check-runner.js +79 -0
- package/dist/config/check-suites.d.ts +14 -0
- package/dist/config/check-suites.js +100 -0
- package/dist/config/gateways.d.ts +31 -3
- package/dist/config/index.d.ts +8 -6
- package/dist/config/index.js +5 -4
- package/dist/config/live/config-gateway.js +5 -2
- package/dist/config/live/file-lists-file-gateway.d.ts +4 -0
- package/dist/config/live/file-lists-file-gateway.js +27 -0
- package/dist/config/load.d.ts +32 -14
- package/dist/config/load.js +162 -116
- package/dist/config/resolve.d.ts +3 -2
- package/dist/config/resolve.js +6 -3
- package/dist/config/resolver.d.ts +20 -6
- package/dist/config/resolver.js +11 -8
- package/dist/config/runner.d.ts +23 -0
- package/dist/config/runner.js +4 -0
- package/dist/config/schema.d.ts +39 -19
- package/dist/config/schema.js +50 -10
- package/dist/config/settings-file.d.ts +9 -3
- package/dist/config/settings-file.js +41 -4
- package/dist/config/suite.d.ts +39 -0
- package/dist/config/suite.js +5 -0
- package/dist/config/typed-options.d.ts +1 -6
- package/dist/config/typed-options.js +2 -10
- package/dist/config-file/define.d.ts +45 -24
- package/dist/config-file/define.js +9 -8
- package/dist/config-file/runner.d.ts +11 -0
- package/dist/config-file/runner.js +9 -0
- package/dist/config-file/toolchain.d.ts +13 -7
- package/dist/config-file/toolchain.js +51 -35
- package/dist/context.d.ts +12 -8
- package/dist/context.js +9 -3
- package/dist/core/across-sandboxes.d.ts +43 -0
- package/dist/core/across-sandboxes.js +319 -0
- package/dist/core/before-run.d.ts +5 -3
- package/dist/core/before-run.js +12 -1
- package/dist/core/events.d.ts +62 -6
- package/dist/core/events.js +14 -0
- package/dist/core/index.d.ts +4 -2
- package/dist/core/index.js +3 -1
- package/dist/core/payload.d.ts +2 -1
- package/dist/core/payload.js +2 -1
- package/dist/core/presentations.js +1 -1
- package/dist/core/resource.d.ts +1 -1
- package/dist/core/resources.d.ts +56 -6
- package/dist/core/resources.js +81 -5
- package/dist/core/run-state.js +9 -0
- package/dist/core/run.d.ts +77 -15
- package/dist/core/run.js +150 -86
- package/dist/core/sandbox-end.d.ts +64 -0
- package/dist/core/sandbox-end.js +128 -0
- package/dist/core/timeline.d.ts +4 -4
- package/dist/core/timeline.js +3 -3
- package/dist/credential/live/vercel-cli-gateway.d.ts +7 -0
- package/dist/credential/live/vercel-cli-gateway.js +14 -1
- package/dist/extensions/github/context.d.ts +1 -1
- package/dist/extensions/github/definition.d.ts +11 -9
- package/dist/extensions/github/definition.js +8 -6
- package/dist/extensions/github/extension.d.ts +3 -3
- package/dist/extensions/github/fixture-repo.d.ts +21 -2
- package/dist/extensions/github/fixture-repo.js +31 -2
- package/dist/extensions/github/index.d.ts +2 -2
- package/dist/extensions/github/index.js +2 -2
- package/dist/extensions/github/lifecycle.d.ts +16 -6
- package/dist/extensions/github/lifecycle.js +42 -25
- package/dist/extensions/github/options.d.ts +17 -11
- package/dist/extensions/github/options.js +14 -13
- package/dist/extensions/github/refusals.d.ts +23 -6
- package/dist/extensions/github/refusals.js +34 -12
- package/dist/extensions/github/resource.d.ts +21 -12
- package/dist/extensions/github/resource.js +16 -8
- package/dist/extensions/github/run/payload.d.ts +6 -6
- package/dist/extensions/github/run/payload.js +3 -5
- package/dist/extensions/github/split.d.ts +10 -0
- package/dist/extensions/github/split.js +12 -0
- package/dist/extensions/playwright/driver.js +6 -26
- package/dist/extensions/playwright/extension.js +1 -1
- package/dist/extensions/testserver/commands/pool/create/command.js +8 -8
- package/dist/extensions/testserver/commands/pool/list/command.js +4 -4
- package/dist/extensions/testserver/definition.d.ts +4 -4
- package/dist/extensions/testserver/definition.js +41 -31
- package/dist/extensions/testserver/extension.d.ts +4 -5
- package/dist/extensions/testserver/extension.js +14 -41
- package/dist/extensions/testserver/index.d.ts +1 -1
- package/dist/extensions/testserver/index.js +1 -1
- package/dist/extensions/testserver/lifecycle.d.ts +10 -2
- package/dist/extensions/testserver/lifecycle.js +29 -6
- package/dist/extensions/testserver/options/rules.d.ts +5 -5
- package/dist/extensions/testserver/options/rules.js +10 -8
- package/dist/extensions/testserver/options/sandboxes.d.ts +4 -2
- package/dist/extensions/testserver/options/sandboxes.js +8 -3
- package/dist/extensions/testserver/pool/gateways.d.ts +29 -4
- package/dist/extensions/testserver/pool/index.d.ts +2 -2
- package/dist/extensions/testserver/pool/index.js +1 -1
- package/dist/extensions/testserver/pool/lease.d.ts +10 -0
- package/dist/extensions/testserver/pool/lease.js +21 -0
- package/dist/extensions/testserver/pool/live/pool-store-gateway.js +38 -3
- package/dist/extensions/testserver/refusals.d.ts +12 -0
- package/dist/extensions/testserver/refusals.js +18 -0
- package/dist/extensions/testserver/release.d.ts +16 -0
- package/dist/extensions/testserver/release.js +56 -4
- package/dist/extensions/testserver/resource.d.ts +6 -6
- package/dist/extensions/testserver/resource.js +3 -3
- package/dist/extensions/testserver/split.d.ts +9 -0
- package/dist/extensions/testserver/split.js +22 -0
- package/dist/extensions/testserver/vitest/fixtures.d.ts +5 -5
- package/dist/extensions/testserver/vitest/fixtures.js +9 -38
- package/dist/extensions/vitest/driver.d.ts +7 -0
- package/dist/extensions/vitest/driver.js +33 -37
- package/dist/extensions/vitest/extension.js +1 -1
- package/dist/extensions/vitest/plan/plan-over.d.ts +8 -1
- package/dist/extensions/vitest/plan/plan-over.js +16 -2
- package/dist/extensions.d.ts +17 -16
- package/dist/extensions.js +5 -4
- package/dist/forward-sigterm.js +1 -1
- package/dist/launcher-resolvers/local-services.d.ts +1 -1
- package/dist/live-app.js +4 -3
- package/dist/local-services.js +1 -1
- package/dist/planning/driver-file-lists.d.ts +61 -0
- package/dist/planning/driver-file-lists.js +66 -0
- package/dist/{commands/exec → planning}/driver-refusals.d.ts +11 -10
- package/dist/{commands/exec → planning}/driver-refusals.js +18 -14
- package/dist/planning/file-lists-file.d.ts +58 -0
- package/dist/planning/file-lists-file.js +105 -0
- package/dist/planning/file-lists.d.ts +28 -0
- package/dist/planning/file-lists.js +52 -0
- package/dist/{commands/exec → planning}/final-results.d.ts +1 -1
- package/dist/{commands/exec → planning}/final-results.js +6 -6
- package/dist/planning/plan-only.d.ts +84 -0
- package/dist/planning/plan-only.js +86 -0
- package/dist/{commands/exec → planning}/redaction.d.ts +2 -2
- package/dist/{commands/exec → planning}/redaction.js +5 -4
- package/dist/{commands/exec → planning}/resource-flags.d.ts +5 -12
- package/dist/{commands/exec → planning}/resource-flags.js +6 -16
- package/dist/planning/run-kind-flags.d.ts +20 -0
- package/dist/planning/run-kind-flags.js +48 -0
- package/dist/planning/run-plan.d.ts +29 -0
- package/dist/planning/run-plan.js +4 -0
- package/dist/planning/sandbox-placeholders.d.ts +22 -0
- package/dist/planning/sandbox-placeholders.js +60 -0
- package/dist/planning/suite-not-found.d.ts +37 -0
- package/dist/planning/suite-not-found.js +36 -0
- package/dist/planning/suites.d.ts +43 -0
- package/dist/planning/suites.js +89 -0
- package/dist/{commands/exec → planning}/test-plan.d.ts +8 -3
- package/dist/{commands/exec → planning}/test-plan.js +32 -5
- package/dist/playwright/reporter.d.ts +20 -8
- package/dist/playwright/reporter.js +195 -15
- package/dist/presentation.d.ts +10 -6
- package/dist/presentation.js +13 -15
- package/dist/run-directory/gateways.d.ts +60 -4
- package/dist/run-directory/index.d.ts +4 -4
- package/dist/run-directory/index.js +2 -1
- package/dist/run-directory/live/run-directory-gateway.js +92 -16
- package/dist/run-directory/plan.d.ts +35 -2
- package/dist/run-directory/plan.js +44 -7
- package/dist/run-directory/reader.d.ts +26 -5
- package/dist/run-directory/reader.js +24 -1
- package/dist/run-directory/recording.d.ts +75 -49
- package/dist/run-directory/recording.js +214 -28
- package/dist/run-directory/run-directory.d.ts +22 -1
- package/dist/run-directory/run-directory.js +24 -0
- package/dist/run-directory/run-record.d.ts +144 -21
- package/dist/run-directory/run-record.js +118 -19
- package/dist/run-directory/timeline-facts.js +4 -4
- package/dist/runner/base.d.ts +0 -6
- package/dist/runner/base.js +0 -15
- package/dist/runner/build-snapshots.d.ts +7 -7
- package/dist/runner/build-snapshots.js +19 -24
- package/dist/runner/events.d.ts +29 -8
- package/dist/runner/gateways.d.ts +54 -6
- package/dist/runner/index.d.ts +6 -4
- package/dist/runner/index.js +3 -2
- package/dist/runner/live/sandbox-gateway.js +173 -31
- package/dist/runner/network-policy.d.ts +55 -0
- package/dist/runner/network-policy.js +46 -0
- package/dist/runner/policy-writes.d.ts +40 -0
- package/dist/runner/policy-writes.js +124 -0
- package/dist/runner/prepare.d.ts +16 -16
- package/dist/runner/prepare.js +11 -12
- package/dist/runner/ready.d.ts +39 -10
- package/dist/runner/ready.js +59 -47
- package/dist/runner/recipe-check.d.ts +6 -0
- package/dist/runner/recipe-check.js +29 -0
- package/dist/runner/recipe-secrets.d.ts +67 -0
- package/dist/runner/recipe-secrets.js +230 -0
- package/dist/runner/recipe.d.ts +151 -63
- package/dist/runner/recipe.js +277 -200
- package/dist/runner/sandboxed-command.d.ts +22 -8
- package/dist/runner/sandboxed-command.js +33 -10
- package/dist/runner/scope.d.ts +107 -21
- package/dist/runner/scope.js +274 -54
- package/dist/runner/secrets.d.ts +42 -31
- package/dist/runner/secrets.js +62 -40
- package/dist/runner/session.d.ts +59 -26
- package/dist/runner/session.js +82 -41
- package/dist/runner/snapshot-build.d.ts +8 -5
- package/dist/runner/snapshot-build.js +56 -29
- package/dist/runner/snapshot-choice.d.ts +37 -0
- package/dist/runner/snapshot-choice.js +38 -0
- package/dist/runner/snapshot-inspect.d.ts +4 -4
- package/dist/runner/snapshot-inspect.js +7 -7
- package/dist/runner/snapshot-key.d.ts +27 -17
- package/dist/runner/snapshot-key.js +51 -26
- package/dist/runner/steps.d.ts +13 -5
- package/dist/runner/steps.js +34 -4
- package/dist/runner/time-limit.d.ts +10 -0
- package/dist/runner/time-limit.js +43 -0
- package/dist/sdk/extension/commands.d.ts +1 -7
- package/dist/sdk/extension/driver.d.ts +39 -46
- package/dist/sdk/extension/driver.js +6 -6
- package/dist/sdk/extension/index.d.ts +3 -3
- package/dist/sdk/extension/index.js +3 -4
- package/dist/sdk/extension/lifecycle.d.ts +52 -9
- package/dist/sdk/extension/lifecycle.js +1 -1
- package/dist/sdk/extension/resource-definition.d.ts +16 -12
- package/dist/sdk/extension/resource-definition.js +10 -4
- package/dist/sdk/extension/resource-factory.js +3 -4
- package/dist/sdk/extension/resource.d.ts +2 -2
- package/dist/sdk/extension/secret-source.d.ts +58 -0
- package/dist/sdk/extension/secret-source.js +78 -0
- package/dist/sdk/index.d.ts +2 -2
- package/dist/sdk/index.js +1 -1
- package/dist/sdk/run/launcher.d.ts +1 -1
- package/dist/sdk/run/launcher.js +1 -1
- package/dist/sdk/run/payload.d.ts +16 -1
- package/dist/sdk/run/payload.js +17 -2
- package/dist/sdk/run/present.d.ts +3 -3
- package/dist/sdk/run/present.js +1 -3
- package/dist/sdk/run/redact.js +2 -2
- package/dist/sdk/run/test-events.d.ts +23 -6
- package/dist/sdk/run/test-events.js +6 -4
- package/dist/sdk/run/test-result-writer.d.ts +8 -3
- package/dist/sdk/run/test-result-writer.js +22 -2
- package/dist/{commands/exec → shared}/cleanup.d.ts +3 -3
- package/dist/{commands/exec → shared}/cleanup.js +11 -6
- package/dist/shared/job-summary.d.ts +19 -0
- package/dist/{commands/exec → shared}/job-summary.js +17 -0
- package/dist/shared/sandbox-table.d.ts +48 -0
- package/dist/shared/sandbox-table.js +109 -0
- package/dist/{commands/exec → shared}/snapshot-text.d.ts +1 -1
- package/dist/{commands/exec → shared}/tests-summary.d.ts +22 -6
- package/dist/{commands/exec → shared}/tests-summary.js +74 -31
- package/dist/{commands/exec → shared}/text.d.ts +7 -2
- package/dist/{commands/exec → shared}/text.js +9 -1
- package/dist/{commands/exec → shared}/waterfall.d.ts +8 -6
- package/dist/{commands/exec → shared}/waterfall.js +71 -24
- package/dist/shared/worker-chart.d.ts +172 -0
- package/dist/shared/worker-chart.js +623 -0
- package/dist/vitest/config.d.ts +35 -11
- package/dist/vitest/config.js +47 -14
- package/dist/vitest/index.d.ts +1 -1
- package/dist/vitest/index.js +3 -3
- package/dist/vitest/sequencer.d.ts +23 -0
- package/dist/vitest/sequencer.js +73 -0
- package/dist/vitest/setup.d.ts +1 -0
- package/dist/vitest/setup.js +34 -0
- package/dist/vitest/test-events.d.ts +32 -6
- package/dist/vitest/test-events.js +25 -5
- package/dist/vitest/test-results.d.ts +8 -3
- package/dist/vitest/test-results.js +6 -0
- package/package.json +7 -2
- package/skills/overview.md +23 -17
- package/skills/plan-runs.md +67 -0
- package/skills/read-run-output.md +51 -19
- package/dist/chunks/chunk-E3QU74NX.js +0 -49
- package/dist/chunks/chunk-HP54VHGY.js +0 -201
- package/dist/chunks/chunk-NMVODY3P.js +0 -19
- package/dist/chunks/chunk-TVMEKVOW.js +0 -607
- package/dist/commands/exec/define-run-command.d.ts +0 -671
- package/dist/commands/exec/define-run-command.js +0 -91
- package/dist/commands/exec/job-summary.d.ts +0 -10
- package/dist/commands/exec/worker-chart.d.ts +0 -87
- package/dist/commands/exec/worker-chart.js +0 -343
- package/dist/commands/playwright/command.d.ts +0 -661
- package/dist/commands/playwright/command.js +0 -31
- package/dist/commands/playwright/metadata.js +0 -8
- package/dist/commands/vitest/command.d.ts +0 -662
- package/dist/commands/vitest/command.js +0 -31
- package/dist/commands/vitest/metadata.js +0 -8
- package/dist/config/recipe-run.d.ts +0 -26
- package/dist/config/recipe-run.js +0 -27
- package/dist/sdk/extension/ci.d.ts +0 -2
- package/dist/sdk/extension/ci.js +0 -6
- package/dist/chunks/{chunk-YM6TZV4L.js → chunk-VL7WFTVQ.js} +52 -52
- package/dist/commands/{playwright → suites}/metadata.d.ts +1 -1
- package/dist/commands/{vitest → test}/metadata.d.ts +1 -1
- /package/dist/{commands → shared}/dashboard.d.ts +0 -0
- /package/dist/{commands → shared}/dashboard.js +0 -0
- /package/dist/{commands/exec → shared}/snapshot-text.js +0 -0
|
@@ -1,20 +1,26 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Credential,
|
|
3
|
+
ENV_VAR_NAME_PATTERN,
|
|
4
|
+
ENV_VAR_NAME_RULE,
|
|
3
5
|
NOT_COUNTED,
|
|
4
6
|
booleanOption,
|
|
5
7
|
defaultResourceKey,
|
|
6
8
|
describeMintFailure,
|
|
9
|
+
describeSecretSource,
|
|
7
10
|
describeValue,
|
|
8
11
|
nonEmptyString,
|
|
9
12
|
optionKeyPath,
|
|
13
|
+
readSecretSource,
|
|
14
|
+
readSecretSourceValue,
|
|
10
15
|
resourceCall,
|
|
16
|
+
secretSourceId,
|
|
11
17
|
tokenRequestFailureFacts,
|
|
12
18
|
tokenRequestFailureShape
|
|
13
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-AWBSONHB.js";
|
|
14
20
|
import {
|
|
15
21
|
defineErrors,
|
|
16
22
|
refused
|
|
17
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-VL7WFTVQ.js";
|
|
18
24
|
|
|
19
25
|
// src/config/credential-settle.ts
|
|
20
26
|
import { z } from "zod";
|
|
@@ -56,36 +62,6 @@ function settleCredential(source, scope, project) {
|
|
|
56
62
|
return { ok: true, credential: { source, target: required.target } };
|
|
57
63
|
}
|
|
58
64
|
|
|
59
|
-
// src/runner/secrets.ts
|
|
60
|
-
var RUNNER_SECRET_MIN_LENGTH = 8;
|
|
61
|
-
function stepSecrets(values, names) {
|
|
62
|
-
return Object.fromEntries(
|
|
63
|
-
names.map((name) => {
|
|
64
|
-
const value = ownValue(values, name);
|
|
65
|
-
if (value === void 0) throw new Error(`stepSecrets: no value for runner secret ${name}`);
|
|
66
|
-
return [name, value];
|
|
67
|
-
})
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
function declaredSecretValues(recipe, env) {
|
|
71
|
-
return (recipe?.secrets ?? []).map((name) => ownValue(env, name)).filter((value) => value !== void 0 && value !== "");
|
|
72
|
-
}
|
|
73
|
-
function readRunnerSecrets(recipe, env) {
|
|
74
|
-
const values = [];
|
|
75
|
-
const variables = [];
|
|
76
|
-
for (const name of recipe.secrets) {
|
|
77
|
-
const value = ownValue(env, name);
|
|
78
|
-
if (value === void 0 || value === "") variables.push({ name, problem: "missing" });
|
|
79
|
-
else if (/[\r\n]/.test(value)) variables.push({ name, problem: "multiline" });
|
|
80
|
-
else if (value.length < RUNNER_SECRET_MIN_LENGTH) variables.push({ name, problem: "short" });
|
|
81
|
-
else values.push([name, value]);
|
|
82
|
-
}
|
|
83
|
-
return variables.length === 0 ? { ok: true, values: Object.fromEntries(values) } : { ok: false, variables };
|
|
84
|
-
}
|
|
85
|
-
function ownValue(map, name) {
|
|
86
|
-
return Object.hasOwn(map, name) ? map[name] : void 0;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
65
|
// src/runner/base.ts
|
|
90
66
|
async function resolveBase(checkout, request2) {
|
|
91
67
|
const { repoRoot } = request2;
|
|
@@ -113,107 +89,389 @@ async function resolveBase(checkout, request2) {
|
|
|
113
89
|
}
|
|
114
90
|
return best === void 0 ? { kind: "no-base-ref", refs: refused2 } : { kind: "resolved", ...best };
|
|
115
91
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
92
|
+
|
|
93
|
+
// src/runner/time-limit.ts
|
|
94
|
+
function callWithin(timer, ms, call) {
|
|
95
|
+
const abort = new AbortController();
|
|
96
|
+
const limit = new AbortController();
|
|
97
|
+
return new Promise((resolve, reject) => {
|
|
98
|
+
call(abort.signal).then(
|
|
99
|
+
(answer) => {
|
|
100
|
+
limit.abort();
|
|
101
|
+
resolve(answer);
|
|
102
|
+
},
|
|
103
|
+
(error) => {
|
|
104
|
+
limit.abort();
|
|
105
|
+
reject(error);
|
|
106
|
+
}
|
|
107
|
+
);
|
|
108
|
+
void timer.sleep(ms, limit.signal).then(() => {
|
|
109
|
+
if (limit.signal.aborted) return;
|
|
110
|
+
abort.abort();
|
|
111
|
+
resolve(null);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
var ABORTED = /* @__PURE__ */ Symbol("aborted");
|
|
116
|
+
function untilAborted(promise, signal) {
|
|
117
|
+
if (signal.aborted) return Promise.resolve(ABORTED);
|
|
118
|
+
return new Promise((resolve, reject) => {
|
|
119
|
+
const onAbort = () => resolve(ABORTED);
|
|
120
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
121
|
+
promise.then(
|
|
122
|
+
(answer) => {
|
|
123
|
+
signal.removeEventListener("abort", onAbort);
|
|
124
|
+
resolve(answer);
|
|
125
|
+
},
|
|
126
|
+
(error) => {
|
|
127
|
+
signal.removeEventListener("abort", onAbort);
|
|
128
|
+
reject(error);
|
|
129
|
+
}
|
|
130
|
+
);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// src/runner/network-policy.ts
|
|
135
|
+
var NETWORK_POLICY_WRITE_LIMIT_MS = 1e4;
|
|
136
|
+
function runnerNetworkPolicy(recipe) {
|
|
137
|
+
if (recipe.allowedDomains === void 0) return { kind: "allow-all", credentials: [] };
|
|
138
|
+
return { kind: "custom", allowedDomains: [...recipe.allowedDomains], credentials: [] };
|
|
139
|
+
}
|
|
140
|
+
function withCredentials(base, credentials2) {
|
|
141
|
+
return { ...base, credentials: credentials2 };
|
|
142
|
+
}
|
|
143
|
+
function denyAllPolicy() {
|
|
144
|
+
return { kind: "deny-all" };
|
|
145
|
+
}
|
|
146
|
+
function policyCredentials(policy) {
|
|
147
|
+
return policy.kind === "deny-all" ? [] : policy.credentials;
|
|
148
|
+
}
|
|
149
|
+
async function replaceNetworkPolicy(context, sandbox, policy) {
|
|
150
|
+
const answered = await callWithin(
|
|
151
|
+
context.timer,
|
|
152
|
+
NETWORK_POLICY_WRITE_LIMIT_MS,
|
|
153
|
+
(signal) => context.runnerSandboxes.writeNetworkPolicy(sandbox, policy, signal)
|
|
154
|
+
);
|
|
155
|
+
return answered ?? { ok: false, failure: { kind: "timed-out", limitMs: NETWORK_POLICY_WRITE_LIMIT_MS } };
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// src/runner/policy-writes.ts
|
|
159
|
+
function sandboxPolicyWriter(context, basePolicy, onTimedOut) {
|
|
160
|
+
const states = /* @__PURE__ */ new Map();
|
|
161
|
+
const stateOf = (sandbox) => {
|
|
162
|
+
let state2 = states.get(sandbox);
|
|
163
|
+
if (state2 === void 0) {
|
|
164
|
+
state2 = { last: Promise.resolve(), mayInject: false, timedOut: false, removal: null };
|
|
165
|
+
states.set(sandbox, state2);
|
|
125
166
|
}
|
|
167
|
+
return state2;
|
|
168
|
+
};
|
|
169
|
+
const mayInject = (sandbox) => states.get(sandbox)?.mayInject === true;
|
|
170
|
+
const send = (sandbox, policy, signal) => {
|
|
171
|
+
if (signal?.aborted === true) return Promise.resolve({ ok: false, failure: { kind: "aborted" } });
|
|
172
|
+
const state2 = stateOf(sandbox);
|
|
173
|
+
const injects = policyCredentials(policy).length > 0;
|
|
174
|
+
if (injects) state2.mayInject = true;
|
|
175
|
+
const turn = state2.last;
|
|
176
|
+
let release = () => {
|
|
177
|
+
};
|
|
178
|
+
const mine = new Promise((resolve) => {
|
|
179
|
+
release = resolve;
|
|
180
|
+
});
|
|
181
|
+
state2.last = mine;
|
|
182
|
+
const answer = (async () => {
|
|
183
|
+
if (!await untilTurn(turn, signal)) {
|
|
184
|
+
void turn.then(release);
|
|
185
|
+
return { ok: false, failure: { kind: "aborted" } };
|
|
186
|
+
}
|
|
187
|
+
try {
|
|
188
|
+
if (state2.timedOut) return { ok: false, failure: timedOut() };
|
|
189
|
+
const answered = await replaceNetworkPolicy(context, sandbox, policy);
|
|
190
|
+
if (answered.ok) {
|
|
191
|
+
if (!injects && state2.last === mine) state2.mayInject = false;
|
|
192
|
+
} else if (answered.failure.kind === "timed-out") {
|
|
193
|
+
state2.timedOut = true;
|
|
194
|
+
onTimedOut(sandbox, answered.failure);
|
|
195
|
+
}
|
|
196
|
+
return answered;
|
|
197
|
+
} finally {
|
|
198
|
+
release();
|
|
199
|
+
}
|
|
200
|
+
})();
|
|
201
|
+
const removal = !injects && signal === void 0 ? answer : null;
|
|
202
|
+
state2.removal = removal;
|
|
203
|
+
if (removal !== null) {
|
|
204
|
+
const forget = () => {
|
|
205
|
+
if (state2.removal === removal) state2.removal = null;
|
|
206
|
+
};
|
|
207
|
+
void removal.then(forget, forget);
|
|
208
|
+
}
|
|
209
|
+
return answer;
|
|
210
|
+
};
|
|
211
|
+
return {
|
|
212
|
+
write: send,
|
|
213
|
+
removeInjections: (sandbox) => states.get(sandbox)?.removal ?? send(sandbox, basePolicy, void 0),
|
|
214
|
+
mayInject,
|
|
215
|
+
injectingSandboxes: () => [...states.keys()].filter(mayInject)
|
|
126
216
|
};
|
|
127
217
|
}
|
|
218
|
+
function notRemovedMessage(failure) {
|
|
219
|
+
return failure.kind === "timed-out" ? `its network policy may still hold a credential: a policy write had no answer within ${failure.limitMs / 1e3} seconds and may still take effect, so no write can remove the credential for certain` : `its network policy may still hold a credential: removing the credential failed (${writeFailureMessage(failure)})`;
|
|
220
|
+
}
|
|
221
|
+
function notFencedMessage(failure, injecting) {
|
|
222
|
+
return injecting ? notRemovedMessage(failure) : `giving it no network access failed (${writeFailureMessage(failure)})`;
|
|
223
|
+
}
|
|
224
|
+
function timedOut() {
|
|
225
|
+
return { kind: "timed-out", limitMs: NETWORK_POLICY_WRITE_LIMIT_MS };
|
|
226
|
+
}
|
|
227
|
+
async function untilTurn(turn, signal) {
|
|
228
|
+
if (signal === void 0) {
|
|
229
|
+
await turn;
|
|
230
|
+
return true;
|
|
231
|
+
}
|
|
232
|
+
return await untilAborted(turn, signal) !== ABORTED;
|
|
233
|
+
}
|
|
234
|
+
function writeFailureMessage(failure) {
|
|
235
|
+
if (failure.kind === "timed-out") return `no answer within ${failure.limitMs / 1e3} seconds`;
|
|
236
|
+
if (failure.kind === "aborted") return "aborted";
|
|
237
|
+
return failure.status === void 0 ? failure.message : `HTTP ${failure.status}: ${failure.message}`;
|
|
238
|
+
}
|
|
128
239
|
|
|
129
240
|
// src/runner/scope.ts
|
|
130
241
|
var CREATE_SETTLE_MS = 2e4;
|
|
131
242
|
var SNAPSHOT_SETTLE_MS = 2 * 6e4;
|
|
132
|
-
|
|
243
|
+
var SANDBOX_CALL_LIMIT_MS = 3e4;
|
|
244
|
+
var KEEP_RUNNING_LIMIT_MS = 6e4;
|
|
245
|
+
function runnerSandboxScope(context, progress, settings) {
|
|
133
246
|
const { runnerSandboxes: sandboxes, timer, clock } = context;
|
|
134
|
-
|
|
135
|
-
const creating = /* @__PURE__ */ new Set();
|
|
247
|
+
let phase = { kind: "open", sandboxes: /* @__PURE__ */ new Map(), creating: /* @__PURE__ */ new Set() };
|
|
136
248
|
const saving = /* @__PURE__ */ new Set();
|
|
137
249
|
const notStopped = [];
|
|
138
250
|
const notDeleted = [];
|
|
139
251
|
let kept = null;
|
|
140
252
|
let notKept = null;
|
|
141
|
-
let
|
|
253
|
+
let settling;
|
|
254
|
+
let stoppingOthers;
|
|
255
|
+
let stoppingUnkept;
|
|
256
|
+
let removingOnSignal;
|
|
257
|
+
let fencing;
|
|
258
|
+
let closingScope;
|
|
259
|
+
const stops = /* @__PURE__ */ new Map();
|
|
260
|
+
const isStopping = (sandbox) => stops.has(sandbox);
|
|
261
|
+
const currentPhase = () => phase;
|
|
262
|
+
const beginClosing = () => {
|
|
263
|
+
if (phase.kind === "open") phase = { kind: "settling", sandboxes: phase.sandboxes, creating: phase.creating };
|
|
264
|
+
};
|
|
142
265
|
const track = (set, task) => {
|
|
143
266
|
set.add(task);
|
|
144
267
|
const forget = () => set.delete(task);
|
|
145
268
|
void task.then(forget, forget);
|
|
146
269
|
return task;
|
|
147
270
|
};
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
if (!deleted.ok)
|
|
151
|
-
notDeleted.push({ name: sandbox.name, role: sandbox.role, message: failureMessage(deleted.failure) });
|
|
271
|
+
const recordNotKept = (sandbox, message) => {
|
|
272
|
+
notKept ??= { name: sandbox.name, message };
|
|
152
273
|
};
|
|
153
|
-
const
|
|
154
|
-
const
|
|
155
|
-
if (!
|
|
156
|
-
|
|
274
|
+
const deleteSandbox = async (sandbox) => {
|
|
275
|
+
const deleted = await callWithin(timer, SANDBOX_CALL_LIMIT_MS, (signal) => sandboxes.delete(sandbox, signal));
|
|
276
|
+
if (deleted === null || !deleted.ok)
|
|
277
|
+
notDeleted.push({
|
|
157
278
|
name: sandbox.name,
|
|
158
279
|
role: sandbox.role,
|
|
159
|
-
|
|
160
|
-
message: failureMessage(stopped.failure)
|
|
280
|
+
message: callFailureMessage(deleted, SANDBOX_CALL_LIMIT_MS)
|
|
161
281
|
});
|
|
162
|
-
|
|
282
|
+
};
|
|
283
|
+
const stop = (sandbox) => {
|
|
284
|
+
let stopping = stops.get(sandbox);
|
|
285
|
+
if (stopping === void 0) {
|
|
286
|
+
stopping = (async () => {
|
|
287
|
+
const answer = await callWithin(timer, SANDBOX_CALL_LIMIT_MS, (signal) => sandboxes.stop(sandbox, signal));
|
|
288
|
+
if (answer !== null && answer.ok) return true;
|
|
289
|
+
notStopped.push({
|
|
290
|
+
name: sandbox.name,
|
|
291
|
+
role: sandbox.role,
|
|
292
|
+
timeoutMinutes: Math.round(sandbox.timeoutMs / 6e4),
|
|
293
|
+
message: callFailureMessage(answer, SANDBOX_CALL_LIMIT_MS)
|
|
294
|
+
});
|
|
295
|
+
return false;
|
|
296
|
+
})();
|
|
297
|
+
stops.set(sandbox, stopping);
|
|
163
298
|
}
|
|
164
|
-
|
|
299
|
+
return stopping;
|
|
165
300
|
};
|
|
166
|
-
const
|
|
167
|
-
const
|
|
168
|
-
if (
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
301
|
+
const giveUp = (sandbox, message) => {
|
|
302
|
+
const entry = phase.sandboxes.get(sandbox);
|
|
303
|
+
if (entry?.keep === true) {
|
|
304
|
+
if (message !== void 0) recordNotKept(sandbox, message);
|
|
305
|
+
entry.keep = false;
|
|
306
|
+
}
|
|
307
|
+
return stop(sandbox);
|
|
308
|
+
};
|
|
309
|
+
const policies = sandboxPolicyWriter(context, settings.basePolicy, (sandbox, failure) => {
|
|
310
|
+
void giveUp(sandbox, notFencedMessage(failure, policies.mayInject(sandbox)));
|
|
311
|
+
});
|
|
312
|
+
const stopAndDelete = async (sandbox) => {
|
|
313
|
+
if (await stop(sandbox)) await deleteSandbox(sandbox);
|
|
314
|
+
};
|
|
315
|
+
const stopUnkeptSandbox = async (sandbox) => {
|
|
316
|
+
if (policies.mayInject(sandbox)) await revoke(sandbox);
|
|
317
|
+
await stop(sandbox);
|
|
318
|
+
};
|
|
319
|
+
const fenceKept = async (entry) => {
|
|
320
|
+
const { sandbox } = entry;
|
|
321
|
+
await removingOnSignal;
|
|
322
|
+
let message;
|
|
323
|
+
if (!isStopping(sandbox)) {
|
|
324
|
+
const injecting = policies.mayInject(sandbox);
|
|
325
|
+
const written = await policies.write(sandbox, denyAllPolicy());
|
|
326
|
+
if (!isStopping(sandbox)) {
|
|
327
|
+
if (written.ok) return;
|
|
328
|
+
message = notFencedMessage(written.failure, injecting);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
await giveUp(sandbox, message);
|
|
332
|
+
};
|
|
333
|
+
const revoke = async (sandbox) => {
|
|
334
|
+
let message;
|
|
335
|
+
if (!isStopping(sandbox)) {
|
|
336
|
+
const removed = await policies.removeInjections(sandbox);
|
|
337
|
+
if (removed.ok) return;
|
|
338
|
+
message = notRemovedMessage(removed.failure);
|
|
339
|
+
}
|
|
340
|
+
await giveUp(sandbox, message);
|
|
341
|
+
};
|
|
342
|
+
const revokeEach = async (injecting) => {
|
|
343
|
+
await Promise.allSettled(injecting.map(revoke));
|
|
344
|
+
};
|
|
345
|
+
const keepOrDelete = async (sandbox) => {
|
|
346
|
+
if (isStopping(sandbox)) return await stopAndDelete(sandbox);
|
|
347
|
+
const until = new Date(clock.now().getTime() + settings.keepMs);
|
|
348
|
+
const keeping = await callWithin(
|
|
349
|
+
timer,
|
|
350
|
+
KEEP_RUNNING_LIMIT_MS,
|
|
351
|
+
(signal) => sandboxes.keepRunning(sandbox, { until }, signal)
|
|
352
|
+
);
|
|
353
|
+
if (keeping === null || !keeping.ok) {
|
|
354
|
+
recordNotKept(sandbox, callFailureMessage(keeping, KEEP_RUNNING_LIMIT_MS));
|
|
355
|
+
return await stopAndDelete(sandbox);
|
|
173
356
|
}
|
|
174
357
|
kept = { name: sandbox.name, stopsAt: keeping.value.stopsAt.toISOString() };
|
|
175
358
|
await progress.emit({ kind: "sandbox-kept", ...kept });
|
|
176
359
|
};
|
|
177
|
-
const
|
|
178
|
-
|
|
360
|
+
const settle = () => {
|
|
361
|
+
beginClosing();
|
|
362
|
+
return settling ??= (async () => {
|
|
363
|
+
if (phase.kind === "closing") return phase.sandboxes;
|
|
364
|
+
const { creating, sandboxes: entries } = phase;
|
|
365
|
+
if (saving.size > 0) await progress.emit({ kind: "waiting-for-snapshot", settleMs: SNAPSHOT_SETTLE_MS });
|
|
366
|
+
await Promise.all([
|
|
367
|
+
settleWithin(timer, creating, CREATE_SETTLE_MS),
|
|
368
|
+
settleWithin(timer, saving, SNAPSHOT_SETTLE_MS)
|
|
369
|
+
]);
|
|
370
|
+
phase = { kind: "closing", sandboxes: entries };
|
|
371
|
+
return entries;
|
|
372
|
+
})();
|
|
373
|
+
};
|
|
374
|
+
const stopOthers = () => {
|
|
375
|
+
const entries = settle();
|
|
376
|
+
return stoppingOthers ??= (async () => {
|
|
377
|
+
const unkept = [...(await entries).values()].filter((entry) => !entry.keep);
|
|
378
|
+
await Promise.all(unkept.map(({ sandbox }) => stopUnkeptSandbox(sandbox)));
|
|
379
|
+
})();
|
|
380
|
+
};
|
|
381
|
+
const stopUnkept = () => stoppingUnkept ??= (async () => {
|
|
382
|
+
beginClosing();
|
|
383
|
+
removingOnSignal = revokeEach(policies.injectingSandboxes());
|
|
384
|
+
await Promise.all([removingOnSignal, stopOthers()]);
|
|
385
|
+
})();
|
|
386
|
+
const fence = () => {
|
|
387
|
+
const settled = settle();
|
|
388
|
+
return fencing ??= (async () => {
|
|
389
|
+
const entries = await settled;
|
|
390
|
+
const keptEntry = [...entries.values()].find((entry) => entry.keep);
|
|
391
|
+
await Promise.all([stopOthers(), keptEntry === void 0 ? void 0 : fenceKept(keptEntry)]);
|
|
392
|
+
await removingOnSignal;
|
|
393
|
+
return { runnerSandboxFenced: !notStopped.some(({ role }) => role === "runner") };
|
|
394
|
+
})().finally(() => settings.signal.removeEventListener("abort", onSignal));
|
|
395
|
+
};
|
|
396
|
+
const writable = () => phase.kind === "open";
|
|
397
|
+
const refused2 = { ok: false, failure: { kind: "aborted" } };
|
|
398
|
+
const revokeCredentials = async (sandbox) => {
|
|
399
|
+
if (!writable()) return refused2;
|
|
400
|
+
if (!policies.mayInject(sandbox)) return { ok: true };
|
|
401
|
+
return await policies.removeInjections(sandbox);
|
|
402
|
+
};
|
|
403
|
+
const grantCredentials = async (sandbox, credentials2, signal) => {
|
|
404
|
+
if (!writable() || signal.aborted) return refused2;
|
|
405
|
+
const granted = await policies.write(sandbox, withCredentials(settings.basePolicy, credentials2), signal);
|
|
406
|
+
if (signal.aborted || !writable()) {
|
|
407
|
+
await revokeCredentials(sandbox);
|
|
408
|
+
return refused2;
|
|
409
|
+
}
|
|
410
|
+
if (!granted.ok) await revokeCredentials(sandbox);
|
|
411
|
+
return granted;
|
|
412
|
+
};
|
|
413
|
+
const owned = (start, canKeep = false) => {
|
|
414
|
+
if (phase.kind !== "open") return Promise.resolve({ ok: false, failure: { kind: "aborted" } });
|
|
179
415
|
return track(
|
|
180
|
-
creating,
|
|
416
|
+
phase.creating,
|
|
181
417
|
(async () => {
|
|
182
418
|
const started = await start();
|
|
183
419
|
if (!started.ok) return started;
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
420
|
+
const now = currentPhase();
|
|
421
|
+
switch (now.kind) {
|
|
422
|
+
case "open":
|
|
423
|
+
now.sandboxes.set(started.value, { sandbox: started.value, keep: canKeep && settings.keepMs > 0 });
|
|
424
|
+
return started;
|
|
425
|
+
case "settling":
|
|
426
|
+
now.sandboxes.set(started.value, { sandbox: started.value, keep: false });
|
|
427
|
+
return { ok: false, failure: { kind: "aborted" } };
|
|
428
|
+
case "closing":
|
|
429
|
+
await stopAndDelete(started.value);
|
|
430
|
+
return { ok: false, failure: { kind: "aborted" } };
|
|
187
431
|
}
|
|
188
|
-
live.add(started.value);
|
|
189
|
-
return started;
|
|
190
432
|
})()
|
|
191
433
|
);
|
|
192
434
|
};
|
|
435
|
+
function onSignal() {
|
|
436
|
+
const commandRunning = settings.commandRunning?.() ?? false;
|
|
437
|
+
void progress.emit({ kind: "stopping", commandRunning, keepMs: settings.keepMs }).catch(() => void 0);
|
|
438
|
+
void stopUnkept().catch(() => void 0);
|
|
439
|
+
}
|
|
440
|
+
if (settings.signal.aborted) onSignal();
|
|
441
|
+
else settings.signal.addEventListener("abort", onSignal, { once: true });
|
|
193
442
|
return {
|
|
194
|
-
startBuildSandbox: (access, request2) => owned(() => sandboxes.startBuildSandbox(access, request2)),
|
|
195
|
-
startRunnerSandbox: (access, request2) => owned(() => sandboxes.startRunnerSandbox(access, request2)),
|
|
443
|
+
startBuildSandbox: (access, request2) => owned(() => sandboxes.startBuildSandbox(access, { ...request2, networkPolicy: settings.basePolicy })),
|
|
444
|
+
startRunnerSandbox: (access, request2) => owned(() => sandboxes.startRunnerSandbox(access, { ...request2, networkPolicy: settings.basePolicy }), true),
|
|
445
|
+
grantCredentials,
|
|
446
|
+
revokeCredentials,
|
|
196
447
|
saveSnapshot: (sandbox, request2) => track(
|
|
197
448
|
saving,
|
|
198
449
|
(async () => {
|
|
450
|
+
if (policies.mayInject(sandbox)) {
|
|
451
|
+
const removed = await policies.removeInjections(sandbox);
|
|
452
|
+
if (!removed.ok)
|
|
453
|
+
return { ok: false, failure: { kind: "credential-not-revoked", failure: removed.failure } };
|
|
454
|
+
}
|
|
199
455
|
const saved = await sandboxes.saveSnapshot(sandbox, request2);
|
|
200
|
-
|
|
456
|
+
const now = currentPhase();
|
|
457
|
+
if (saved.ok && now.kind !== "closing" && now.sandboxes.delete(sandbox)) await deleteSandbox(sandbox);
|
|
201
458
|
return saved;
|
|
202
459
|
})()
|
|
203
460
|
),
|
|
461
|
+
fence,
|
|
204
462
|
close() {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
await
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
463
|
+
beginClosing();
|
|
464
|
+
closingScope ??= (async () => {
|
|
465
|
+
await fence();
|
|
466
|
+
const entries = await settle();
|
|
467
|
+
await Promise.all(
|
|
468
|
+
[...entries.values()].map(
|
|
469
|
+
(entry) => entry.keep ? keepOrDelete(entry.sandbox) : stopAndDelete(entry.sandbox)
|
|
470
|
+
)
|
|
471
|
+
);
|
|
214
472
|
return { kept, notKept, notStopped: [...notStopped], notDeleted: [...notDeleted] };
|
|
215
473
|
})();
|
|
216
|
-
return
|
|
474
|
+
return closingScope;
|
|
217
475
|
}
|
|
218
476
|
};
|
|
219
477
|
}
|
|
@@ -226,6 +484,9 @@ async function settleWithin(timer, tasks, ms) {
|
|
|
226
484
|
function failureMessage(failure) {
|
|
227
485
|
return failure.message ?? failure.kind;
|
|
228
486
|
}
|
|
487
|
+
function callFailureMessage(answer, limitMs) {
|
|
488
|
+
return answer === null ? `no answer within ${limitMs / 1e3} seconds` : failureMessage(answer.failure);
|
|
489
|
+
}
|
|
229
490
|
|
|
230
491
|
// src/runner/context.ts
|
|
231
492
|
function runnerPurpose(recipeName) {
|
|
@@ -365,26 +626,34 @@ var systemClock = {
|
|
|
365
626
|
import { z as z2 } from "zod";
|
|
366
627
|
var RUN_PAYLOAD_VARIABLE = "STORM_RUN";
|
|
367
628
|
var RUN_PAYLOAD_VERSION = 3;
|
|
629
|
+
var runPayloadSandboxSchema = z2.object({
|
|
630
|
+
index: z2.number().int().nonnegative(),
|
|
631
|
+
count: z2.number().int().positive(),
|
|
632
|
+
files: z2.array(z2.string().min(1)).optional()
|
|
633
|
+
});
|
|
368
634
|
var runPayloadSchema = z2.object({
|
|
369
635
|
version: z2.literal(RUN_PAYLOAD_VERSION),
|
|
370
636
|
resources: z2.record(z2.string(), z2.object({ definition: z2.string().min(1), payload: z2.unknown() })),
|
|
371
637
|
testEvents: z2.string().min(1).optional(),
|
|
372
|
-
verbose: z2.literal(true).optional()
|
|
638
|
+
verbose: z2.literal(true).optional(),
|
|
639
|
+
sandbox: runPayloadSandboxSchema.optional()
|
|
373
640
|
});
|
|
374
641
|
|
|
375
642
|
// src/sdk/run/test-events.ts
|
|
376
643
|
import { z as z3 } from "zod";
|
|
377
644
|
var where = { file: z3.string(), worker: z3.number().int().nonnegative(), at: z3.number() };
|
|
645
|
+
var fileWhere = { file: z3.string(), worker: z3.number().int().nonnegative().exactOptional(), at: z3.number() };
|
|
646
|
+
var attempt = { id: z3.string().min(1), test: z3.string() };
|
|
378
647
|
var setup = { label: z3.string().min(1), resource: z3.string().min(1) };
|
|
379
648
|
var state = z3.enum(["pass", "fail", "skip"]);
|
|
380
649
|
var testEventSchema = z3.discriminatedUnion("kind", [
|
|
381
|
-
z3.object({ kind: z3.literal("file-started"), ...
|
|
382
|
-
z3.object({ kind: z3.literal("file-finished"), ...
|
|
383
|
-
z3.object({ kind: z3.literal("test-started"), ...where,
|
|
650
|
+
z3.object({ kind: z3.literal("file-started"), ...fileWhere }),
|
|
651
|
+
z3.object({ kind: z3.literal("file-finished"), ...fileWhere }),
|
|
652
|
+
z3.object({ kind: z3.literal("test-started"), ...where, ...attempt, fileTests: z3.number().int().nonnegative() }),
|
|
384
653
|
z3.object({
|
|
385
654
|
kind: z3.literal("test-attempt-finished"),
|
|
386
655
|
...where,
|
|
387
|
-
|
|
656
|
+
...attempt,
|
|
388
657
|
state,
|
|
389
658
|
ms: z3.number().nonnegative()
|
|
390
659
|
}),
|
|
@@ -438,106 +707,230 @@ function redactSecrets(text, secrets) {
|
|
|
438
707
|
return ordered.reduce((redacted, secret) => redacted.split(secret).join(REDACTED), text);
|
|
439
708
|
}
|
|
440
709
|
|
|
441
|
-
// src/runner/
|
|
442
|
-
function
|
|
443
|
-
let
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
flush: () => pending
|
|
449
|
-
};
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
// src/runner/output.ts
|
|
453
|
-
var OUTPUT_TAIL_LINES = 40;
|
|
454
|
-
function lineSplitter() {
|
|
455
|
-
let buffer = "";
|
|
456
|
-
return {
|
|
457
|
-
push(chunk) {
|
|
458
|
-
const end = chunk.lastIndexOf("\n");
|
|
459
|
-
if (end === -1) {
|
|
460
|
-
buffer += chunk;
|
|
461
|
-
return "";
|
|
462
|
-
}
|
|
463
|
-
const lines = buffer + chunk.slice(0, end + 1);
|
|
464
|
-
buffer = chunk.slice(end + 1);
|
|
465
|
-
return lines;
|
|
466
|
-
},
|
|
467
|
-
flush() {
|
|
468
|
-
const rest = buffer;
|
|
469
|
-
buffer = "";
|
|
470
|
-
return rest;
|
|
710
|
+
// src/runner/recipe-check.ts
|
|
711
|
+
function reportUnknownKeys(value, known, path, what, report) {
|
|
712
|
+
let ok = true;
|
|
713
|
+
for (const key of Object.keys(value))
|
|
714
|
+
if (!known.has(key)) {
|
|
715
|
+
report([...path, key], `is not ${what}`);
|
|
716
|
+
ok = false;
|
|
471
717
|
}
|
|
472
|
-
|
|
718
|
+
return ok;
|
|
473
719
|
}
|
|
474
|
-
function
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
720
|
+
function describeRecipeValue(value) {
|
|
721
|
+
if (typeof value === "string") return JSON.stringify(value);
|
|
722
|
+
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
723
|
+
if (value === null) return "null";
|
|
724
|
+
if (value === void 0) return "undefined";
|
|
725
|
+
if (typeof value === "function") return "a function";
|
|
726
|
+
if (Array.isArray(value)) return value.length === 0 ? "an empty array" : "an array";
|
|
727
|
+
if (typeof value === "object") return "an object";
|
|
728
|
+
return `a ${typeof value}`;
|
|
478
729
|
}
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
730
|
+
|
|
731
|
+
// src/runner/recipe-secrets.ts
|
|
732
|
+
var CREDENTIAL_KEYS = /* @__PURE__ */ new Set(["domain", "header", "source", "requests"]);
|
|
733
|
+
var UNSAFE_SECRET_ENV_VAR_KEYS = /* @__PURE__ */ new Set(["name", "source"]);
|
|
734
|
+
var ENV_SOURCE_KEYS = /* @__PURE__ */ new Set(["kind", "name"]);
|
|
735
|
+
var DEFAULT_CREDENTIAL_HEADER = "authorization";
|
|
736
|
+
var HOST_PATTERN = /^(?=.{1,253}$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+$/;
|
|
737
|
+
var HEADER_PATTERN = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
|
|
738
|
+
var REFUSED_HEADERS = /* @__PURE__ */ new Set(["host", "content-length", "transfer-encoding", "connection"]);
|
|
739
|
+
var RESERVED_UNSAFE_SECRET_ENV_VAR_NAMES = /* @__PURE__ */ new Set([
|
|
740
|
+
"PATH",
|
|
741
|
+
"HOME",
|
|
742
|
+
"USER",
|
|
743
|
+
"LOGNAME",
|
|
744
|
+
"SHELL",
|
|
745
|
+
"PWD",
|
|
746
|
+
"TMPDIR",
|
|
747
|
+
"BASH_ENV",
|
|
748
|
+
"ENV",
|
|
749
|
+
"IFS",
|
|
750
|
+
"NODE_OPTIONS",
|
|
751
|
+
"NO_UPDATE_NOTIFIER",
|
|
752
|
+
"FORCE_COLOR",
|
|
753
|
+
"NO_COLOR"
|
|
754
|
+
]);
|
|
755
|
+
var RESERVED_UNSAFE_SECRET_ENV_VAR_PREFIXES = ["LD_", "DYLD_"];
|
|
756
|
+
function credentialSourceIds(recipe) {
|
|
757
|
+
return [...new Set(recipe.credentials.map(({ source }) => secretSourceId(source)))].toSorted();
|
|
488
758
|
}
|
|
489
|
-
function
|
|
490
|
-
if (
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
759
|
+
function checkCredentials(value, report) {
|
|
760
|
+
if (value === void 0) return [];
|
|
761
|
+
if (!Array.isArray(value)) {
|
|
762
|
+
report(
|
|
763
|
+
["credentials"],
|
|
764
|
+
`must be a list of credentials, each { domain, header?, source, requests? }, not ${describeRecipeValue(value)}`
|
|
765
|
+
);
|
|
766
|
+
return void 0;
|
|
767
|
+
}
|
|
768
|
+
let ok = true;
|
|
769
|
+
const checked = [];
|
|
770
|
+
const byTarget = /* @__PURE__ */ new Map();
|
|
771
|
+
const byDomain = /* @__PURE__ */ new Map();
|
|
772
|
+
value.forEach((entry, index) => {
|
|
773
|
+
const path = ["credentials", String(index)];
|
|
774
|
+
const credential = checkCredential(entry, path, report);
|
|
775
|
+
if (credential === void 0) {
|
|
776
|
+
ok = false;
|
|
777
|
+
return;
|
|
778
|
+
}
|
|
779
|
+
const target = `${credential.domain} ${credential.header}`;
|
|
780
|
+
const sameTarget = byTarget.get(target);
|
|
781
|
+
const sameDomain = byDomain.get(credential.domain);
|
|
782
|
+
if (sameTarget !== void 0) {
|
|
783
|
+
report(
|
|
784
|
+
path,
|
|
785
|
+
`goes to the same domain and header as runner.credentials.${sameTarget}: ${credential.header} on ${credential.domain}`
|
|
786
|
+
);
|
|
787
|
+
ok = false;
|
|
788
|
+
} else if (sameDomain !== void 0 && sameDomain.requests !== credential.requests) {
|
|
789
|
+
report(
|
|
790
|
+
[...path, "requests"],
|
|
791
|
+
`can't be ${credential.requests}: runner.credentials.${sameDomain.index} goes to ${credential.domain} with ${sameDomain.requests}, and every credential for one domain has the same requests`
|
|
792
|
+
);
|
|
793
|
+
ok = false;
|
|
794
|
+
}
|
|
795
|
+
if (sameTarget === void 0) byTarget.set(target, index);
|
|
796
|
+
if (sameDomain === void 0) byDomain.set(credential.domain, { index, requests: credential.requests });
|
|
797
|
+
checked.push(credential);
|
|
798
|
+
});
|
|
799
|
+
return ok ? checked : void 0;
|
|
494
800
|
}
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
const
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
801
|
+
function checkCredential(value, path, report) {
|
|
802
|
+
if (!isPlainObject(value)) {
|
|
803
|
+
report(path, `must be { domain, header?, source, requests? }, not ${describeRecipeValue(value)}`);
|
|
804
|
+
return void 0;
|
|
805
|
+
}
|
|
806
|
+
let ok = reportUnknownKeys(value, CREDENTIAL_KEYS, path, "a credential key", report);
|
|
807
|
+
const domain = value["domain"];
|
|
808
|
+
if (typeof domain !== "string" || !HOST_PATTERN.test(domain)) {
|
|
809
|
+
report(
|
|
810
|
+
[...path, "domain"],
|
|
811
|
+
`must be a bare hostname, such as registry.example.com: lowercase letters, digits, dots, and hyphens, with at least one dot, and no scheme, port, path, or wildcard, not ${describeRecipeValue(domain)}`
|
|
812
|
+
);
|
|
813
|
+
ok = false;
|
|
814
|
+
}
|
|
815
|
+
const header = value["header"] === void 0 ? DEFAULT_CREDENTIAL_HEADER : value["header"];
|
|
816
|
+
if (typeof header !== "string" || !HEADER_PATTERN.test(header)) {
|
|
817
|
+
report(
|
|
818
|
+
[...path, "header"],
|
|
819
|
+
`must be an HTTP header name, such as authorization, not ${describeRecipeValue(header)}`
|
|
820
|
+
);
|
|
821
|
+
ok = false;
|
|
822
|
+
} else if (REFUSED_HEADERS.has(header.toLowerCase())) {
|
|
823
|
+
report([...path, "header"], `can't be ${header}: the firewall or HTTP sets it`);
|
|
824
|
+
ok = false;
|
|
825
|
+
}
|
|
826
|
+
const source = checkSecretSource(value["source"], [...path, "source"], report);
|
|
827
|
+
if (source === void 0) ok = false;
|
|
828
|
+
const requests = value["requests"] === void 0 ? "read" : value["requests"];
|
|
829
|
+
if (requests !== "read" && requests !== "all") {
|
|
830
|
+
report([...path, "requests"], `must be "read" or "all", not ${describeRecipeValue(requests)}`);
|
|
831
|
+
ok = false;
|
|
832
|
+
}
|
|
833
|
+
return ok && source !== void 0 ? {
|
|
834
|
+
domain,
|
|
835
|
+
header: header.toLowerCase(),
|
|
836
|
+
source,
|
|
837
|
+
requests
|
|
838
|
+
} : void 0;
|
|
839
|
+
}
|
|
840
|
+
function checkSecretSource(value, path, report) {
|
|
841
|
+
if (!isPlainObject(value)) {
|
|
842
|
+
report(path, `must be a secret source, { kind: "env", name }, not ${describeRecipeValue(value)}`);
|
|
843
|
+
return void 0;
|
|
844
|
+
}
|
|
845
|
+
const kind2 = value["kind"];
|
|
846
|
+
if (kind2 !== "env") {
|
|
847
|
+
report([...path, "kind"], `must be "env", not ${describeRecipeValue(kind2)}`);
|
|
848
|
+
if (kind2 !== void 0) return void 0;
|
|
849
|
+
}
|
|
850
|
+
let ok = kind2 === "env";
|
|
851
|
+
if (!reportUnknownKeys(value, ENV_SOURCE_KEYS, path, "a secret source key", report)) ok = false;
|
|
852
|
+
const name = value["name"];
|
|
853
|
+
if (typeof name !== "string" || !ENV_VAR_NAME_PATTERN.test(name)) {
|
|
854
|
+
report([...path, "name"], `must be ${ENV_VAR_NAME_RULE}, not ${describeRecipeValue(name)}`);
|
|
855
|
+
ok = false;
|
|
856
|
+
}
|
|
857
|
+
return ok ? { kind: "env", name } : void 0;
|
|
858
|
+
}
|
|
859
|
+
function checkUnsafeSecretEnvVars(value, env, credentials2, report) {
|
|
860
|
+
if (value === void 0) return [];
|
|
861
|
+
if (!Array.isArray(value)) {
|
|
862
|
+
report(
|
|
863
|
+
["unsafeSecretEnvVars"],
|
|
864
|
+
`must be a list of unsafe secret environment variables, each { name, source }, not ${describeRecipeValue(value)}`
|
|
865
|
+
);
|
|
866
|
+
return void 0;
|
|
867
|
+
}
|
|
868
|
+
let ok = true;
|
|
869
|
+
const checked = [];
|
|
870
|
+
const seen = /* @__PURE__ */ new Set();
|
|
871
|
+
const credentialSources = new Set((credentials2 ?? []).map(({ source }) => secretSourceId(source)));
|
|
872
|
+
value.forEach((entry, index) => {
|
|
873
|
+
const path = ["unsafeSecretEnvVars", String(index)];
|
|
874
|
+
if (!isPlainObject(entry)) {
|
|
875
|
+
report(path, `must be { name, source }, not ${describeRecipeValue(entry)}`);
|
|
876
|
+
ok = false;
|
|
877
|
+
return;
|
|
514
878
|
}
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
879
|
+
let entryOk = reportUnknownKeys(
|
|
880
|
+
entry,
|
|
881
|
+
UNSAFE_SECRET_ENV_VAR_KEYS,
|
|
882
|
+
path,
|
|
883
|
+
"an unsafe secret environment variable key",
|
|
884
|
+
report
|
|
885
|
+
);
|
|
886
|
+
const name = entry["name"];
|
|
887
|
+
const namePath = [...path, "name"];
|
|
888
|
+
if (typeof name !== "string" || !ENV_VAR_NAME_PATTERN.test(name)) {
|
|
889
|
+
report(namePath, `must be ${ENV_VAR_NAME_RULE}, not ${describeRecipeValue(name)}`);
|
|
890
|
+
entryOk = false;
|
|
891
|
+
} else if (name === RUN_PAYLOAD_VARIABLE) {
|
|
892
|
+
report(namePath, `can't be ${name}: storm sets it for the command`);
|
|
893
|
+
entryOk = false;
|
|
894
|
+
} else if (RESERVED_UNSAFE_SECRET_ENV_VAR_NAMES.has(name)) {
|
|
895
|
+
report(namePath, `can't be ${name}: it changes how the command's shell or programs run`);
|
|
896
|
+
entryOk = false;
|
|
897
|
+
} else if (reservedUnsafeSecretEnvVarPrefix(name) !== void 0) {
|
|
898
|
+
report(
|
|
899
|
+
namePath,
|
|
900
|
+
`can't be ${name}: a name starting with ${reservedUnsafeSecretEnvVarPrefix(name)} changes how the command's programs load`
|
|
901
|
+
);
|
|
902
|
+
entryOk = false;
|
|
903
|
+
} else if (env !== void 0 && Object.hasOwn(env, name)) {
|
|
904
|
+
report(namePath, `can't be ${name}: runner.env already sets it`);
|
|
905
|
+
entryOk = false;
|
|
906
|
+
} else if (seen.has(name)) {
|
|
907
|
+
report(namePath, `names ${name} again`);
|
|
908
|
+
entryOk = false;
|
|
909
|
+
}
|
|
910
|
+
if (typeof name === "string") seen.add(name);
|
|
911
|
+
const source = checkSecretSource(entry["source"], [...path, "source"], report);
|
|
912
|
+
if (source === void 0) {
|
|
913
|
+
entryOk = false;
|
|
914
|
+
} else if (credentialSources.has(secretSourceId(source))) {
|
|
915
|
+
report([...path, "source"], `can't use ${secretSourceId(source)}: runner.credentials already reads it`);
|
|
916
|
+
entryOk = false;
|
|
917
|
+
}
|
|
918
|
+
if (entryOk && source !== void 0) checked.push({ name, source });
|
|
919
|
+
else ok = false;
|
|
920
|
+
});
|
|
921
|
+
return ok ? checked : void 0;
|
|
530
922
|
}
|
|
531
|
-
function
|
|
532
|
-
|
|
533
|
-
return { kind: "sandbox-api-failed", operation, status: 410, message: failure.message };
|
|
534
|
-
return { kind: "sandbox-api-failed", operation, status: failure.status ?? null, message: failure.message };
|
|
923
|
+
function reservedUnsafeSecretEnvVarPrefix(name) {
|
|
924
|
+
return RESERVED_UNSAFE_SECRET_ENV_VAR_PREFIXES.find((prefix) => name.startsWith(prefix));
|
|
535
925
|
}
|
|
536
|
-
function
|
|
537
|
-
|
|
926
|
+
function isPlainObject(value) {
|
|
927
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
928
|
+
const proto = Object.getPrototypeOf(value);
|
|
929
|
+
return proto === Object.prototype || proto === null;
|
|
538
930
|
}
|
|
539
931
|
|
|
540
932
|
// src/runner/recipe.ts
|
|
933
|
+
var MAX_RUNNER_SANDBOXES = 32;
|
|
541
934
|
var RECIPE_DEFAULTS = {
|
|
542
935
|
cwd: ".",
|
|
543
936
|
timeout: "60m",
|
|
@@ -552,32 +945,25 @@ var RECIPE_KEYS = /* @__PURE__ */ new Set([
|
|
|
552
945
|
"cwd",
|
|
553
946
|
"vcpus",
|
|
554
947
|
"env",
|
|
555
|
-
"
|
|
948
|
+
"credentials",
|
|
949
|
+
"unsafeSecretEnvVars",
|
|
950
|
+
"allowedDomains",
|
|
556
951
|
"timeout",
|
|
557
952
|
"keepSandbox",
|
|
558
953
|
"baseRefs",
|
|
559
954
|
"region",
|
|
560
|
-
"runtime"
|
|
955
|
+
"runtime",
|
|
956
|
+
"sandboxes"
|
|
561
957
|
]);
|
|
958
|
+
var SANDBOXES_KEYS = /* @__PURE__ */ new Set(["max", "default"]);
|
|
959
|
+
var SANDBOXES_DEFAULT_RULE_KEYS = /* @__PURE__ */ new Set(["filesPerSandbox", "max"]);
|
|
960
|
+
var VCPUS_RULE_KEYS = /* @__PURE__ */ new Set(["resource", "option", "per", "min", "max"]);
|
|
562
961
|
var SNAPSHOT_KEYS = /* @__PURE__ */ new Set(["vcpus", "summary", "toolchains", "prebuild"]);
|
|
563
962
|
var RUN_KEYS = /* @__PURE__ */ new Set(["install", "build"]);
|
|
564
|
-
var STEP_KEYS = /* @__PURE__ */ new Set(["label", "script"
|
|
963
|
+
var STEP_KEYS = /* @__PURE__ */ new Set(["label", "script"]);
|
|
964
|
+
var TOOLCHAIN_STEP_KEYS = /* @__PURE__ */ new Set(["label", "script", "baseFiles"]);
|
|
565
965
|
var NAME_PATTERN = /^[a-z0-9][a-z0-9-]*$/;
|
|
566
|
-
var
|
|
567
|
-
var RESERVED_SECRET_NAMES = /* @__PURE__ */ new Set([
|
|
568
|
-
"PATH",
|
|
569
|
-
"HOME",
|
|
570
|
-
"USER",
|
|
571
|
-
"LOGNAME",
|
|
572
|
-
"SHELL",
|
|
573
|
-
"PWD",
|
|
574
|
-
"TMPDIR",
|
|
575
|
-
"BASH_ENV",
|
|
576
|
-
"ENV",
|
|
577
|
-
"IFS",
|
|
578
|
-
"NODE_OPTIONS"
|
|
579
|
-
]);
|
|
580
|
-
var RESERVED_SECRET_PREFIXES = ["LD_", "DYLD_"];
|
|
966
|
+
var ALLOWED_DOMAIN_PATTERN = /^(?:\*\.)?(?=.{1,253}$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+$/;
|
|
581
967
|
function checkRecipe(value) {
|
|
582
968
|
const problems = [];
|
|
583
969
|
const report = (path, problem) => problems.push({ path, problem });
|
|
@@ -592,17 +978,16 @@ function checkRecipe(value) {
|
|
|
592
978
|
["name"],
|
|
593
979
|
`must be lowercase letters, digits and dashes, starting with a letter or digit, not ${describeRecipeValue(name)}`
|
|
594
980
|
);
|
|
595
|
-
const
|
|
596
|
-
const
|
|
597
|
-
const run = checkRun(value["run"], declared, report);
|
|
981
|
+
const snapshot = checkSnapshot(value["snapshot"], report);
|
|
982
|
+
const run = checkRun(value["run"], report);
|
|
598
983
|
const cwd = orDefault(value["cwd"], RECIPE_DEFAULTS.cwd);
|
|
599
984
|
if (!isRelativePath(cwd))
|
|
600
985
|
report(["cwd"], `must be a path relative to the repository's root, without "..", not ${describeRecipeValue(cwd)}`);
|
|
601
|
-
const vcpus = value["vcpus"];
|
|
602
|
-
if (typeof vcpus !== "function" && !isPositiveInteger(vcpus))
|
|
603
|
-
report(["vcpus"], `must be a positive whole number, or a function of the run, not ${describeRecipeValue(vcpus)}`);
|
|
986
|
+
const vcpus = checkVcpus(value["vcpus"], report);
|
|
604
987
|
const env = checkEnv(value["env"], report);
|
|
605
|
-
const
|
|
988
|
+
const credentials2 = checkCredentials(value["credentials"], report);
|
|
989
|
+
const unsafeSecretEnvVars = checkUnsafeSecretEnvVars(value["unsafeSecretEnvVars"], env, credentials2, report);
|
|
990
|
+
const allowedDomains = checkAllowedDomains(value["allowedDomains"], report);
|
|
606
991
|
const timeout = orDefault(value["timeout"], RECIPE_DEFAULTS.timeout);
|
|
607
992
|
const timeoutMinutes = typeof timeout === "string" ? parseTtl(timeout) : void 0;
|
|
608
993
|
if (timeoutMinutes === void 0)
|
|
@@ -617,13 +1002,19 @@ function checkRecipe(value) {
|
|
|
617
1002
|
["keepSandbox"],
|
|
618
1003
|
`must be 0, or a whole number of minutes or hours up to 5h, not ${describeRecipeValue(keepSandbox)}`
|
|
619
1004
|
);
|
|
1005
|
+
else if (unsafeSecretEnvVars !== void 0 && unsafeSecretEnvVars.length > 0 && keepSandboxMinutes !== void 0 && keepSandboxMinutes > 0)
|
|
1006
|
+
report(
|
|
1007
|
+
["keepSandbox"],
|
|
1008
|
+
"can't be above 0 when runner.unsafeSecretEnvVars is set: a run that passes secrets into the runner sandbox's environment never keeps its runner sandbox"
|
|
1009
|
+
);
|
|
620
1010
|
const baseRefs = checkBaseRefs(value["baseRefs"], report);
|
|
621
1011
|
const region = orDefault(value["region"], RECIPE_DEFAULTS.region);
|
|
622
1012
|
if (!isNonEmptyString(region)) report(["region"], `must be a non-empty string, not ${describeRecipeValue(region)}`);
|
|
623
1013
|
const runtime = orDefault(value["runtime"], RECIPE_DEFAULTS.runtime);
|
|
624
1014
|
if (!isNonEmptyString(runtime))
|
|
625
1015
|
report(["runtime"], `must be a non-empty string, not ${describeRecipeValue(runtime)}`);
|
|
626
|
-
|
|
1016
|
+
const sandboxes = checkSandboxes(value["sandboxes"], report);
|
|
1017
|
+
if (problems.length > 0 || snapshot === void 0 || run === void 0 || vcpus === void 0 || env === void 0 || credentials2 === void 0 || unsafeSecretEnvVars === void 0 || allowedDomains === null || baseRefs === void 0 || timeoutMinutes === void 0 || sandboxes === false)
|
|
627
1018
|
return { ok: false, problems };
|
|
628
1019
|
return {
|
|
629
1020
|
ok: true,
|
|
@@ -634,22 +1025,143 @@ function checkRecipe(value) {
|
|
|
634
1025
|
cwd,
|
|
635
1026
|
vcpus,
|
|
636
1027
|
env,
|
|
637
|
-
|
|
1028
|
+
credentials: credentials2,
|
|
1029
|
+
unsafeSecretEnvVars,
|
|
1030
|
+
...allowedDomains === void 0 ? {} : { allowedDomains },
|
|
638
1031
|
timeout,
|
|
639
1032
|
timeoutMinutes,
|
|
640
1033
|
keepSandboxMinutes,
|
|
641
1034
|
baseRefs,
|
|
642
1035
|
region,
|
|
643
|
-
runtime
|
|
1036
|
+
runtime,
|
|
1037
|
+
...sandboxes === void 0 ? {} : { sandboxes }
|
|
644
1038
|
}
|
|
645
1039
|
};
|
|
646
1040
|
}
|
|
647
|
-
function
|
|
648
|
-
if (value
|
|
649
|
-
if (
|
|
650
|
-
|
|
1041
|
+
function checkVcpus(value, report) {
|
|
1042
|
+
if (isPositiveInteger(value)) return value;
|
|
1043
|
+
if (typeof value === "function") {
|
|
1044
|
+
report(["vcpus"], "can't be a function: use a positive whole number, or { resource, option, per, min, max }");
|
|
1045
|
+
return void 0;
|
|
1046
|
+
}
|
|
1047
|
+
if (!isRecord(value)) {
|
|
1048
|
+
report(
|
|
1049
|
+
["vcpus"],
|
|
1050
|
+
`must be a positive whole number, or { resource, option, per, min, max }, not ${describeRecipeValue(value)}`
|
|
1051
|
+
);
|
|
1052
|
+
return void 0;
|
|
1053
|
+
}
|
|
1054
|
+
let ok = reportUnknownKeys(value, VCPUS_RULE_KEYS, ["vcpus"], "a runner recipe vcpus rule key", report);
|
|
1055
|
+
const resource = value["resource"];
|
|
1056
|
+
if (!isNonEmptyString(resource)) {
|
|
1057
|
+
report(["vcpus", "resource"], `must be a non-empty string, not ${describeRecipeValue(resource)}`);
|
|
1058
|
+
ok = false;
|
|
1059
|
+
}
|
|
1060
|
+
const option = value["option"];
|
|
1061
|
+
if (!isNonEmptyString(option)) {
|
|
1062
|
+
report(["vcpus", "option"], `must be a non-empty string, not ${describeRecipeValue(option)}`);
|
|
1063
|
+
ok = false;
|
|
1064
|
+
}
|
|
1065
|
+
const per = value["per"];
|
|
1066
|
+
if (!isPositiveInteger(per)) {
|
|
1067
|
+
report(["vcpus", "per"], `must be a positive whole number, not ${describeRecipeValue(per)}`);
|
|
1068
|
+
ok = false;
|
|
1069
|
+
}
|
|
1070
|
+
const min = value["min"];
|
|
1071
|
+
if (!isPositiveInteger(min)) {
|
|
1072
|
+
report(["vcpus", "min"], `must be a positive whole number, not ${describeRecipeValue(min)}`);
|
|
1073
|
+
ok = false;
|
|
1074
|
+
}
|
|
1075
|
+
const max = value["max"];
|
|
1076
|
+
if (!isPositiveInteger(max)) {
|
|
1077
|
+
report(["vcpus", "max"], `must be a positive whole number, not ${describeRecipeValue(max)}`);
|
|
1078
|
+
ok = false;
|
|
1079
|
+
} else if (isPositiveInteger(min) && max < min) {
|
|
1080
|
+
report(["vcpus", "max"], `must be at least vcpus.min (${min}), not ${max}`);
|
|
1081
|
+
ok = false;
|
|
1082
|
+
}
|
|
1083
|
+
return ok ? {
|
|
1084
|
+
resource,
|
|
1085
|
+
option,
|
|
1086
|
+
per,
|
|
1087
|
+
min,
|
|
1088
|
+
max
|
|
1089
|
+
} : void 0;
|
|
1090
|
+
}
|
|
1091
|
+
function checkSandboxes(value, report) {
|
|
1092
|
+
if (value === void 0) return void 0;
|
|
1093
|
+
if (!isRecord(value)) {
|
|
1094
|
+
report(["sandboxes"], `must be an object with max, not ${describeRecipeValue(value)}`);
|
|
1095
|
+
return false;
|
|
1096
|
+
}
|
|
1097
|
+
let ok = reportUnknownKeys(value, SANDBOXES_KEYS, ["sandboxes"], "a runner recipe sandboxes key", report);
|
|
1098
|
+
const max = value["max"];
|
|
1099
|
+
if (!isPositiveInteger(max) || max > MAX_RUNNER_SANDBOXES) {
|
|
1100
|
+
report(
|
|
1101
|
+
["sandboxes", "max"],
|
|
1102
|
+
`must be a whole number from 1 to ${MAX_RUNNER_SANDBOXES}, not ${describeRecipeValue(max)}`
|
|
1103
|
+
);
|
|
1104
|
+
ok = false;
|
|
1105
|
+
}
|
|
1106
|
+
const rawDefault = value["default"];
|
|
1107
|
+
let sandboxesDefault;
|
|
1108
|
+
if (rawDefault !== void 0) {
|
|
1109
|
+
const checkedDefault = checkSandboxesDefault(rawDefault, report);
|
|
1110
|
+
if (checkedDefault === void 0) ok = false;
|
|
1111
|
+
else sandboxesDefault = checkedDefault;
|
|
1112
|
+
}
|
|
1113
|
+
if (!ok) return false;
|
|
1114
|
+
return {
|
|
1115
|
+
max,
|
|
1116
|
+
...sandboxesDefault === void 0 ? {} : { default: sandboxesDefault }
|
|
1117
|
+
};
|
|
1118
|
+
}
|
|
1119
|
+
function checkSandboxesDefault(value, report) {
|
|
1120
|
+
if (isPositiveInteger(value) && value <= MAX_RUNNER_SANDBOXES) return value;
|
|
1121
|
+
if (typeof value === "function") {
|
|
1122
|
+
report(
|
|
1123
|
+
["sandboxes", "default"],
|
|
1124
|
+
`can't be a function: use a whole number from 1 to ${MAX_RUNNER_SANDBOXES}, or { filesPerSandbox, max? }`
|
|
1125
|
+
);
|
|
1126
|
+
return void 0;
|
|
1127
|
+
}
|
|
1128
|
+
if (!isRecord(value)) {
|
|
1129
|
+
report(
|
|
1130
|
+
["sandboxes", "default"],
|
|
1131
|
+
`must be a whole number from 1 to ${MAX_RUNNER_SANDBOXES}, or { filesPerSandbox, max? }, not ${describeRecipeValue(value)}`
|
|
1132
|
+
);
|
|
1133
|
+
return void 0;
|
|
1134
|
+
}
|
|
1135
|
+
let ok = reportUnknownKeys(
|
|
1136
|
+
value,
|
|
1137
|
+
SANDBOXES_DEFAULT_RULE_KEYS,
|
|
1138
|
+
["sandboxes", "default"],
|
|
1139
|
+
"a runner recipe sandboxes default rule key",
|
|
1140
|
+
report
|
|
1141
|
+
);
|
|
1142
|
+
const filesPerSandbox = value["filesPerSandbox"];
|
|
1143
|
+
if (!isPositiveInteger(filesPerSandbox)) {
|
|
1144
|
+
report(
|
|
1145
|
+
["sandboxes", "default", "filesPerSandbox"],
|
|
1146
|
+
`must be a positive whole number, not ${describeRecipeValue(filesPerSandbox)}`
|
|
1147
|
+
);
|
|
1148
|
+
ok = false;
|
|
1149
|
+
}
|
|
1150
|
+
const max = value["max"];
|
|
1151
|
+
if (max !== void 0 && (!isPositiveInteger(max) || max > MAX_RUNNER_SANDBOXES)) {
|
|
1152
|
+
report(
|
|
1153
|
+
["sandboxes", "default", "max"],
|
|
1154
|
+
`must be a whole number from 1 to ${MAX_RUNNER_SANDBOXES}, not ${describeRecipeValue(max)}`
|
|
1155
|
+
);
|
|
1156
|
+
ok = false;
|
|
1157
|
+
}
|
|
1158
|
+
if (!ok) return void 0;
|
|
1159
|
+
return {
|
|
1160
|
+
filesPerSandbox,
|
|
1161
|
+
...max === void 0 ? {} : { max }
|
|
1162
|
+
};
|
|
651
1163
|
}
|
|
652
|
-
function checkSnapshot(value,
|
|
1164
|
+
function checkSnapshot(value, report) {
|
|
653
1165
|
if (!isRecord(value)) {
|
|
654
1166
|
report(
|
|
655
1167
|
["snapshot"],
|
|
@@ -668,8 +1180,8 @@ function checkSnapshot(value, declared, report) {
|
|
|
668
1180
|
report(["snapshot", "summary"], `must be a non-empty string, not ${describeRecipeValue(summary)}`);
|
|
669
1181
|
ok = false;
|
|
670
1182
|
}
|
|
671
|
-
const toolchains = checkSteps(value["toolchains"], ["snapshot", "toolchains"],
|
|
672
|
-
const prebuild = checkSteps(value["prebuild"], ["snapshot", "prebuild"],
|
|
1183
|
+
const toolchains = checkSteps(value["toolchains"], ["snapshot", "toolchains"], true, report);
|
|
1184
|
+
const prebuild = checkSteps(value["prebuild"], ["snapshot", "prebuild"], false, report);
|
|
673
1185
|
if (!ok || toolchains === void 0 || prebuild === void 0) return void 0;
|
|
674
1186
|
return {
|
|
675
1187
|
vcpus,
|
|
@@ -678,31 +1190,49 @@ function checkSnapshot(value, declared, report) {
|
|
|
678
1190
|
prebuild
|
|
679
1191
|
};
|
|
680
1192
|
}
|
|
681
|
-
function checkRun(value,
|
|
1193
|
+
function checkRun(value, report) {
|
|
682
1194
|
if (!isRecord(value)) {
|
|
683
1195
|
report(["run"], `must be an object of install and build steps, not ${describeRecipeValue(value)}`);
|
|
684
1196
|
return void 0;
|
|
685
1197
|
}
|
|
686
1198
|
const ok = reportUnknownKeys(value, RUN_KEYS, ["run"], "a runner recipe run key", report);
|
|
687
|
-
const install = checkStep(value["install"], ["run", "install"],
|
|
688
|
-
const build = checkStep(value["build"], ["run", "build"],
|
|
1199
|
+
const install = checkStep(value["install"], ["run", "install"], false, report);
|
|
1200
|
+
const build = checkStep(value["build"], ["run", "build"], false, report);
|
|
689
1201
|
return ok && install !== void 0 && build !== void 0 ? { install, build } : void 0;
|
|
690
1202
|
}
|
|
691
|
-
function checkSteps(value, path,
|
|
692
|
-
if (typeof value === "function")
|
|
1203
|
+
function checkSteps(value, path, allowBaseFiles, report) {
|
|
1204
|
+
if (typeof value === "function") {
|
|
1205
|
+
report(
|
|
1206
|
+
path,
|
|
1207
|
+
allowBaseFiles ? "can't be a function: use a list of { label, script, baseFiles? } steps and declare the base files each step reads" : "can't be a function: use a list of { label, script } steps (prebuild steps already see the base's files)"
|
|
1208
|
+
);
|
|
1209
|
+
return void 0;
|
|
1210
|
+
}
|
|
693
1211
|
if (!Array.isArray(value)) {
|
|
694
|
-
report(path, `must be a list of steps,
|
|
1212
|
+
report(path, `must be a list of steps, not ${describeRecipeValue(value)}`);
|
|
695
1213
|
return void 0;
|
|
696
1214
|
}
|
|
697
|
-
const steps = value.map(
|
|
1215
|
+
const steps = value.map(
|
|
1216
|
+
(step, index) => allowBaseFiles ? checkStep(step, [...path, String(index)], true, report) : checkStep(step, [...path, String(index)], false, report)
|
|
1217
|
+
);
|
|
698
1218
|
return steps.every((step) => step !== void 0) ? steps : void 0;
|
|
699
1219
|
}
|
|
700
|
-
function checkStep(value, path,
|
|
1220
|
+
function checkStep(value, path, allowBaseFiles, report) {
|
|
701
1221
|
if (!isRecord(value)) {
|
|
702
|
-
|
|
1222
|
+
const shape = allowBaseFiles ? "{ label, script, baseFiles? }" : "{ label, script }";
|
|
1223
|
+
report(path, `must be a step, ${shape}, not ${describeRecipeValue(value)}`);
|
|
703
1224
|
return void 0;
|
|
704
1225
|
}
|
|
705
|
-
|
|
1226
|
+
const allowedKeys = allowBaseFiles ? TOOLCHAIN_STEP_KEYS : STEP_KEYS;
|
|
1227
|
+
let ok = true;
|
|
1228
|
+
for (const key of Object.keys(value)) {
|
|
1229
|
+
if (allowedKeys.has(key)) continue;
|
|
1230
|
+
report(
|
|
1231
|
+
[...path, key],
|
|
1232
|
+
key === "secrets" ? "is not a step key: every recipe step gets every credential runner.credentials declares" : key === "baseFiles" ? "is only allowed on snapshot.toolchains steps: this step already sees the base's files" : "is not a step key"
|
|
1233
|
+
);
|
|
1234
|
+
ok = false;
|
|
1235
|
+
}
|
|
706
1236
|
const label = value["label"];
|
|
707
1237
|
const script = value["script"];
|
|
708
1238
|
if (!isNonEmptyString(label)) {
|
|
@@ -713,33 +1243,42 @@ function checkStep(value, path, declared, report) {
|
|
|
713
1243
|
report([...path, "script"], `must be a non-empty string, not ${describeRecipeValue(script)}`);
|
|
714
1244
|
ok = false;
|
|
715
1245
|
}
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
1246
|
+
if (!allowBaseFiles) return ok ? { label, script } : void 0;
|
|
1247
|
+
const baseFiles = checkBaseFiles(value["baseFiles"], [...path, "baseFiles"], report);
|
|
1248
|
+
if (baseFiles === null) ok = false;
|
|
1249
|
+
if (!ok || baseFiles === null) return void 0;
|
|
1250
|
+
return {
|
|
1251
|
+
label,
|
|
1252
|
+
script,
|
|
1253
|
+
...baseFiles === void 0 || baseFiles.length === 0 ? {} : { baseFiles }
|
|
1254
|
+
};
|
|
719
1255
|
}
|
|
720
|
-
function
|
|
721
|
-
if (value === void 0) return
|
|
1256
|
+
function checkBaseFiles(value, path, report) {
|
|
1257
|
+
if (value === void 0) return void 0;
|
|
722
1258
|
if (!Array.isArray(value)) {
|
|
723
|
-
report(path, `must be a list of
|
|
724
|
-
return
|
|
1259
|
+
report(path, `must be a list of relative file paths, not ${describeRecipeValue(value)}`);
|
|
1260
|
+
return null;
|
|
725
1261
|
}
|
|
726
1262
|
let ok = true;
|
|
727
1263
|
const seen = /* @__PURE__ */ new Set();
|
|
728
|
-
|
|
1264
|
+
const checked = [];
|
|
1265
|
+
value.forEach((entry, index) => {
|
|
729
1266
|
const at = [...path, String(index)];
|
|
730
|
-
if (
|
|
731
|
-
report(
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
1267
|
+
if (!isRelativeFilePath(entry)) {
|
|
1268
|
+
report(
|
|
1269
|
+
at,
|
|
1270
|
+
`must be a relative file path without leading "/", "./", "..", or trailing "/", not ${describeRecipeValue(entry)}`
|
|
1271
|
+
);
|
|
735
1272
|
ok = false;
|
|
736
|
-
} else if (seen.has(
|
|
737
|
-
report(at, `
|
|
1273
|
+
} else if (seen.has(entry)) {
|
|
1274
|
+
report(at, `lists ${entry} again`);
|
|
738
1275
|
ok = false;
|
|
1276
|
+
} else {
|
|
1277
|
+
seen.add(entry);
|
|
1278
|
+
checked.push(entry);
|
|
739
1279
|
}
|
|
740
|
-
if (typeof name === "string") seen.add(name);
|
|
741
1280
|
});
|
|
742
|
-
return ok ?
|
|
1281
|
+
return ok ? checked : null;
|
|
743
1282
|
}
|
|
744
1283
|
function checkEnv(value, report) {
|
|
745
1284
|
if (value === void 0) return {};
|
|
@@ -760,44 +1299,39 @@ function checkEnv(value, report) {
|
|
|
760
1299
|
}
|
|
761
1300
|
return ok ? env : void 0;
|
|
762
1301
|
}
|
|
763
|
-
function
|
|
764
|
-
if (value === void 0) return
|
|
1302
|
+
function checkAllowedDomains(value, report) {
|
|
1303
|
+
if (value === void 0) return void 0;
|
|
765
1304
|
if (!Array.isArray(value)) {
|
|
766
|
-
report(
|
|
767
|
-
|
|
1305
|
+
report(
|
|
1306
|
+
["allowedDomains"],
|
|
1307
|
+
`must be a list of domains, such as ["registry.npmjs.org", "*.example.com"], not ${describeRecipeValue(value)}`
|
|
1308
|
+
);
|
|
1309
|
+
return null;
|
|
1310
|
+
}
|
|
1311
|
+
if (value.length === 0) {
|
|
1312
|
+
report(["allowedDomains"], "must list at least one domain: leave the key out for full access");
|
|
1313
|
+
return null;
|
|
768
1314
|
}
|
|
769
1315
|
let ok = true;
|
|
770
1316
|
const seen = /* @__PURE__ */ new Set();
|
|
771
|
-
value.forEach((
|
|
772
|
-
const
|
|
773
|
-
if (
|
|
1317
|
+
value.forEach((domain, index) => {
|
|
1318
|
+
const at = ["allowedDomains", String(index)];
|
|
1319
|
+
if (domain === "*") {
|
|
1320
|
+
report(at, "can't be *, which would allow every domain: leave runner.allowedDomains out for full access");
|
|
1321
|
+
ok = false;
|
|
1322
|
+
} else if (typeof domain !== "string" || !ALLOWED_DOMAIN_PATTERN.test(domain)) {
|
|
774
1323
|
report(
|
|
775
|
-
|
|
776
|
-
`must be
|
|
1324
|
+
at,
|
|
1325
|
+
`must be a hostname, such as example.com, or a wildcard with one leading *., such as *.example.com: lowercase letters, digits, dots, and hyphens, with at least one dot, and no scheme, port, or path, not ${describeRecipeValue(domain)}`
|
|
777
1326
|
);
|
|
778
1327
|
ok = false;
|
|
779
|
-
} else if (
|
|
780
|
-
report(
|
|
781
|
-
ok = false;
|
|
782
|
-
} else if (Object.hasOwn(STEP_ENV, name)) {
|
|
783
|
-
report(path, `can't be ${name}: storm sets it for every step`);
|
|
784
|
-
ok = false;
|
|
785
|
-
} else if (RESERVED_SECRET_NAMES.has(name)) {
|
|
786
|
-
report(path, `can't be ${name}: it changes how a step's shell or programs run`);
|
|
787
|
-
ok = false;
|
|
788
|
-
} else if (reservedPrefix(name) !== void 0) {
|
|
789
|
-
report(path, `can't be ${name}: a name starting with ${reservedPrefix(name)} changes how a step's programs load`);
|
|
790
|
-
ok = false;
|
|
791
|
-
} else if (seen.has(name)) {
|
|
792
|
-
report(path, `names ${name} again`);
|
|
1328
|
+
} else if (seen.has(domain)) {
|
|
1329
|
+
report(at, `lists ${domain} again`);
|
|
793
1330
|
ok = false;
|
|
794
1331
|
}
|
|
795
|
-
if (typeof
|
|
1332
|
+
if (typeof domain === "string") seen.add(domain);
|
|
796
1333
|
});
|
|
797
|
-
return ok ? [...value] :
|
|
798
|
-
}
|
|
799
|
-
function reservedPrefix(name) {
|
|
800
|
-
return RESERVED_SECRET_PREFIXES.find((prefix) => name.startsWith(prefix));
|
|
1334
|
+
return ok ? [...value] : null;
|
|
801
1335
|
}
|
|
802
1336
|
function checkBaseRefs(value, report) {
|
|
803
1337
|
if (value === void 0) return [...RECIPE_DEFAULTS.baseRefs];
|
|
@@ -814,72 +1348,34 @@ function checkBaseRefs(value, report) {
|
|
|
814
1348
|
});
|
|
815
1349
|
return ok ? [...value] : void 0;
|
|
816
1350
|
}
|
|
817
|
-
function
|
|
818
|
-
|
|
819
|
-
for (const
|
|
820
|
-
if (
|
|
821
|
-
|
|
822
|
-
ok = false;
|
|
823
|
-
}
|
|
824
|
-
return ok;
|
|
825
|
-
}
|
|
826
|
-
async function resolveSteps(steps, context, declared) {
|
|
827
|
-
if (typeof steps !== "function")
|
|
828
|
-
return {
|
|
829
|
-
ok: true,
|
|
830
|
-
steps: steps.map(({ label, script, secrets }) => ({ label, script, secrets: [...secrets ?? []] }))
|
|
831
|
-
};
|
|
832
|
-
let returned;
|
|
833
|
-
try {
|
|
834
|
-
returned = await steps(context);
|
|
835
|
-
} catch (error) {
|
|
836
|
-
return { ok: false, problem: `threw at base ${context.base.slice(0, 12)}: ${errorMessage(error)}` };
|
|
1351
|
+
function declaredBaseFilePaths(toolchains) {
|
|
1352
|
+
const paths = /* @__PURE__ */ new Set();
|
|
1353
|
+
for (const step of toolchains) {
|
|
1354
|
+
if (step.baseFiles === void 0) continue;
|
|
1355
|
+
for (const file of step.baseFiles) paths.add(file);
|
|
837
1356
|
}
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
const
|
|
843
|
-
|
|
844
|
-
);
|
|
845
|
-
const
|
|
846
|
-
if (
|
|
1357
|
+
return [...paths].toSorted((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
1358
|
+
}
|
|
1359
|
+
function resolveVcpus(recipe, run) {
|
|
1360
|
+
if (typeof recipe.vcpus === "number") return { ok: true, vcpus: recipe.vcpus };
|
|
1361
|
+
const { resource, option, per, min, max } = recipe.vcpus;
|
|
1362
|
+
const options = Object.hasOwn(run.resources, resource) ? run.resources[resource] : void 0;
|
|
1363
|
+
if (options === void 0) return { ok: true, vcpus: min };
|
|
1364
|
+
const raw = Object.hasOwn(options, option) ? options[option] : void 0;
|
|
1365
|
+
if (typeof raw !== "number" || !Number.isFinite(raw) || raw < 0) {
|
|
847
1366
|
return {
|
|
848
1367
|
ok: false,
|
|
849
|
-
problem: `
|
|
1368
|
+
problem: `resource "${resource}" option "${option}" must be a non-negative number, not ${describeRecipeValue(raw)}`
|
|
850
1369
|
};
|
|
851
|
-
return { ok: true, steps: checked };
|
|
852
|
-
}
|
|
853
|
-
function resolveVcpus(recipe, { run, resourceKeys }) {
|
|
854
|
-
if (typeof recipe.vcpus !== "function") return { ok: true, vcpus: recipe.vcpus };
|
|
855
|
-
let returned;
|
|
856
|
-
try {
|
|
857
|
-
returned = recipe.vcpus(run);
|
|
858
|
-
} catch (error) {
|
|
859
|
-
return { ok: false, problem: `threw for ${describeResourceKeys(resourceKeys)}: ${errorMessage(error)}` };
|
|
860
1370
|
}
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
problem: `must return a positive whole number, not ${describeRecipeValue(returned)} for ${describeResourceKeys(resourceKeys)}`
|
|
864
|
-
};
|
|
865
|
-
}
|
|
866
|
-
function describeResourceKeys(names) {
|
|
867
|
-
const last = names.at(-1);
|
|
868
|
-
if (last === void 0) return "a run with no resource";
|
|
869
|
-
return `a run with ${names.length === 1 ? last : `${names.slice(0, -1).join(", ")} and ${last}`}`;
|
|
870
|
-
}
|
|
871
|
-
function describeRecipeValue(value) {
|
|
872
|
-
if (typeof value === "string") return JSON.stringify(value);
|
|
873
|
-
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
874
|
-
if (value === null) return "null";
|
|
875
|
-
if (value === void 0) return "undefined";
|
|
876
|
-
if (typeof value === "function") return "a function";
|
|
877
|
-
if (Array.isArray(value)) return value.length === 0 ? "an empty array" : "an array";
|
|
878
|
-
if (typeof value === "object") return "an object";
|
|
879
|
-
return `a ${typeof value}`;
|
|
1371
|
+
const perSandbox = Math.ceil(raw / Math.max(1, run.sandboxes));
|
|
1372
|
+
return { ok: true, vcpus: Math.min(max, Math.max(min, per * perSandbox)) };
|
|
880
1373
|
}
|
|
881
|
-
function
|
|
882
|
-
|
|
1374
|
+
function resolveSandboxCountDefault(sandboxesDefault, testPlan) {
|
|
1375
|
+
if (typeof sandboxesDefault === "number") return sandboxesDefault;
|
|
1376
|
+
if (testPlan.kind !== "counted") return 1;
|
|
1377
|
+
const limit = sandboxesDefault.max ?? MAX_RUNNER_SANDBOXES;
|
|
1378
|
+
return Math.max(1, Math.min(limit, Math.ceil(testPlan.files / sandboxesDefault.filesPerSandbox)));
|
|
883
1379
|
}
|
|
884
1380
|
function orDefault(value, fallback) {
|
|
885
1381
|
return value === void 0 ? fallback : value;
|
|
@@ -896,9 +1392,15 @@ function isPositiveInteger(value) {
|
|
|
896
1392
|
function isRelativePath(value) {
|
|
897
1393
|
return typeof value === "string" && value.length > 0 && !value.startsWith("/") && !value.split(/[/\\]/).includes("..");
|
|
898
1394
|
}
|
|
1395
|
+
function isRelativeFilePath(value) {
|
|
1396
|
+
if (typeof value !== "string" || value.length === 0) return false;
|
|
1397
|
+
if (value.startsWith("/") || value.endsWith("/") || value.includes("\\") || value.includes("\0")) return false;
|
|
1398
|
+
const segments = value.split("/");
|
|
1399
|
+
return segments.every((segment) => segment.length > 0 && segment !== "." && segment !== "..");
|
|
1400
|
+
}
|
|
899
1401
|
|
|
900
1402
|
// src/runner/snapshot-key.ts
|
|
901
|
-
var SNAPSHOT_FORMAT =
|
|
1403
|
+
var SNAPSHOT_FORMAT = 5;
|
|
902
1404
|
var SANDBOX_ROOT = "/vercel/sandbox";
|
|
903
1405
|
var STAGED_FILES = {
|
|
904
1406
|
baseTarball: "base.tgz",
|
|
@@ -946,30 +1448,173 @@ function applyScript(staging, root = SANDBOX_ROOT) {
|
|
|
946
1448
|
);
|
|
947
1449
|
}
|
|
948
1450
|
function snapshotKey(steps) {
|
|
949
|
-
const text = (list) => list.flatMap(({ label, script
|
|
1451
|
+
const text = (list) => list.flatMap(({ label, script }) => [label, script]);
|
|
1452
|
+
const baseFiles = [...steps.baseFiles].toSorted((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0);
|
|
950
1453
|
return createHash2("sha256").update(
|
|
951
1454
|
[
|
|
952
1455
|
`format=${SNAPSHOT_FORMAT}`,
|
|
1456
|
+
`credentials=${[...new Set(steps.credentials)].toSorted().join(",")}`,
|
|
1457
|
+
`baseFiles=${baseFiles.length}`,
|
|
1458
|
+
...baseFiles.flatMap(({ path, text: content }) => [path, content]),
|
|
953
1459
|
...text(steps.toolchains),
|
|
954
1460
|
baseIndexScript("<base>", "<staging>"),
|
|
955
1461
|
...text(steps.prebuild)
|
|
956
1462
|
].join("\0")
|
|
957
1463
|
).digest("hex");
|
|
958
1464
|
}
|
|
959
|
-
async function
|
|
960
|
-
const
|
|
961
|
-
const { snapshot
|
|
962
|
-
const
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
1465
|
+
async function snapshotInputsAt(checkout, request2) {
|
|
1466
|
+
const { repoRoot, base, recipe } = request2;
|
|
1467
|
+
const { snapshot } = recipe;
|
|
1468
|
+
const baseFiles = [];
|
|
1469
|
+
for (const path of declaredBaseFilePaths(snapshot.toolchains)) {
|
|
1470
|
+
const file = await checkout.readFileAt({ repoRoot, commit: base, path });
|
|
1471
|
+
if (file.kind === "missing") {
|
|
1472
|
+
return {
|
|
1473
|
+
ok: false,
|
|
1474
|
+
path: ["snapshot", "toolchains"],
|
|
1475
|
+
problem: `declared base file "${path}" doesn't exist at base ${base.slice(0, 12)}`
|
|
1476
|
+
};
|
|
1477
|
+
}
|
|
1478
|
+
if (file.kind === "failed") {
|
|
1479
|
+
return {
|
|
1480
|
+
ok: false,
|
|
1481
|
+
path: ["snapshot", "toolchains"],
|
|
1482
|
+
problem: `can't read declared base file "${path}" at base ${base.slice(0, 12)}: ${file.failure.message}`
|
|
1483
|
+
};
|
|
1484
|
+
}
|
|
1485
|
+
baseFiles.push({ path, text: file.text });
|
|
1486
|
+
}
|
|
966
1487
|
return {
|
|
967
1488
|
ok: true,
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
1489
|
+
baseFiles,
|
|
1490
|
+
key: snapshotKey({
|
|
1491
|
+
credentials: credentialSourceIds(recipe),
|
|
1492
|
+
baseFiles,
|
|
1493
|
+
toolchains: snapshot.toolchains,
|
|
1494
|
+
prebuild: snapshot.prebuild
|
|
1495
|
+
})
|
|
1496
|
+
};
|
|
1497
|
+
}
|
|
1498
|
+
|
|
1499
|
+
// src/runner/events.ts
|
|
1500
|
+
function progressQueue(progress) {
|
|
1501
|
+
let pending = Promise.resolve();
|
|
1502
|
+
return {
|
|
1503
|
+
add(event) {
|
|
1504
|
+
pending = pending.then(() => progress.emit(event));
|
|
1505
|
+
},
|
|
1506
|
+
flush: () => pending
|
|
1507
|
+
};
|
|
1508
|
+
}
|
|
1509
|
+
|
|
1510
|
+
// src/runner/output.ts
|
|
1511
|
+
var OUTPUT_TAIL_LINES = 40;
|
|
1512
|
+
function lineSplitter() {
|
|
1513
|
+
let buffer = "";
|
|
1514
|
+
return {
|
|
1515
|
+
push(chunk) {
|
|
1516
|
+
const end = chunk.lastIndexOf("\n");
|
|
1517
|
+
if (end === -1) {
|
|
1518
|
+
buffer += chunk;
|
|
1519
|
+
return "";
|
|
1520
|
+
}
|
|
1521
|
+
const lines = buffer + chunk.slice(0, end + 1);
|
|
1522
|
+
buffer = chunk.slice(end + 1);
|
|
1523
|
+
return lines;
|
|
1524
|
+
},
|
|
1525
|
+
flush() {
|
|
1526
|
+
const rest = buffer;
|
|
1527
|
+
buffer = "";
|
|
1528
|
+
return rest;
|
|
1529
|
+
}
|
|
1530
|
+
};
|
|
1531
|
+
}
|
|
1532
|
+
function rewritePaths(text, fromRoot, toRoot) {
|
|
1533
|
+
const from = `${fromRoot.replace(/\/+$/, "")}/`;
|
|
1534
|
+
const to = `${toRoot.replace(/\/+$/, "")}/`;
|
|
1535
|
+
return text.split(from).join(to);
|
|
1536
|
+
}
|
|
1537
|
+
function outputTail(limit = OUTPUT_TAIL_LINES) {
|
|
1538
|
+
const kept = [];
|
|
1539
|
+
return {
|
|
1540
|
+
add(line) {
|
|
1541
|
+
kept.push(line);
|
|
1542
|
+
if (kept.length > limit) kept.shift();
|
|
1543
|
+
},
|
|
1544
|
+
lines: () => [...kept]
|
|
1545
|
+
};
|
|
1546
|
+
}
|
|
1547
|
+
function splitLines(text) {
|
|
1548
|
+
if (text === "") return [];
|
|
1549
|
+
const lines = text.split("\n");
|
|
1550
|
+
if (lines.at(-1) === "") lines.pop();
|
|
1551
|
+
return lines;
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1554
|
+
// src/runner/steps.ts
|
|
1555
|
+
var STEP_ENV = {
|
|
1556
|
+
HUSKY: "0",
|
|
1557
|
+
COREPACK_ENABLE_DOWNLOAD_PROMPT: "0",
|
|
1558
|
+
COREPACK_ENABLE_STRICT: "0",
|
|
1559
|
+
npm_config_update_notifier: "false"
|
|
1560
|
+
};
|
|
1561
|
+
async function runStep(context, request2, progress, signal) {
|
|
1562
|
+
const { phase, label } = request2;
|
|
1563
|
+
const startedAt = context.clock.now().getTime();
|
|
1564
|
+
await progress.emit({ kind: "step-started", phase, label });
|
|
1565
|
+
const queue = progressQueue(progress);
|
|
1566
|
+
const tail = outputTail();
|
|
1567
|
+
const splitters = { stdout: lineSplitter(), stderr: lineSplitter() };
|
|
1568
|
+
const emit = (stream, text) => {
|
|
1569
|
+
for (const line of splitLines(text)) {
|
|
1570
|
+
tail.add(line);
|
|
1571
|
+
queue.add({ kind: "step-output", phase, stream, line });
|
|
1572
|
+
}
|
|
1573
|
+
};
|
|
1574
|
+
const ran = await context.runnerSandboxes.runScript(
|
|
1575
|
+
request2.sandbox,
|
|
1576
|
+
{ script: request2.script, env: { ...STEP_ENV } },
|
|
1577
|
+
({ stream, data }) => emit(stream, splitters[stream].push(data)),
|
|
1578
|
+
signal
|
|
1579
|
+
);
|
|
1580
|
+
emit("stdout", splitters.stdout.flush());
|
|
1581
|
+
emit("stderr", splitters.stderr.flush());
|
|
1582
|
+
await queue.flush();
|
|
1583
|
+
if (!ran.ok) return { kind: "sandbox-failed", failure: ran.failure };
|
|
1584
|
+
if (ran.value.exitCode !== 0) return { kind: "exited", exitCode: ran.value.exitCode, tail: tail.lines() };
|
|
1585
|
+
const ms = context.clock.now().getTime() - startedAt;
|
|
1586
|
+
await progress.emit({ kind: "step-finished", phase, label, ms });
|
|
1587
|
+
return { kind: "succeeded", ms };
|
|
1588
|
+
}
|
|
1589
|
+
function networkPolicyStop(operation, around, failure) {
|
|
1590
|
+
if (failure.kind === "aborted") return { kind: "aborted" };
|
|
1591
|
+
return {
|
|
1592
|
+
kind: "failed",
|
|
1593
|
+
failure: failure.kind === "timed-out" ? {
|
|
1594
|
+
kind: "network-policy-failed",
|
|
1595
|
+
operation,
|
|
1596
|
+
around,
|
|
1597
|
+
reason: "timed-out",
|
|
1598
|
+
status: null,
|
|
1599
|
+
message: `no answer within ${failure.limitMs / 1e3} seconds`
|
|
1600
|
+
} : {
|
|
1601
|
+
kind: "network-policy-failed",
|
|
1602
|
+
operation,
|
|
1603
|
+
around,
|
|
1604
|
+
reason: "api",
|
|
1605
|
+
status: failure.status ?? null,
|
|
1606
|
+
message: failure.message
|
|
1607
|
+
}
|
|
971
1608
|
};
|
|
972
1609
|
}
|
|
1610
|
+
function sandboxApiFailure(operation, failure) {
|
|
1611
|
+
if (failure.kind === "snapshot-gone")
|
|
1612
|
+
return { kind: "sandbox-api-failed", operation, status: 410, message: failure.message };
|
|
1613
|
+
return { kind: "sandbox-api-failed", operation, status: failure.status ?? null, message: failure.message };
|
|
1614
|
+
}
|
|
1615
|
+
function sandboxStop(operation, failure) {
|
|
1616
|
+
return failure.kind === "aborted" ? { kind: "aborted" } : { kind: "failed", failure: sandboxApiFailure(operation, failure) };
|
|
1617
|
+
}
|
|
973
1618
|
|
|
974
1619
|
// src/runner/snapshot-build.ts
|
|
975
1620
|
var BUILD_SANDBOX_TIMEOUT_MS = 30 * 6e4;
|
|
@@ -984,7 +1629,7 @@ async function buildSnapshot(context, request2, control, progress) {
|
|
|
984
1629
|
kind: "snapshot-build-started",
|
|
985
1630
|
base,
|
|
986
1631
|
why: request2.why,
|
|
987
|
-
summary: recipe.snapshot.summary ?? [...
|
|
1632
|
+
summary: recipe.snapshot.summary ?? [...recipe.snapshot.toolchains, ...recipe.snapshot.prebuild].map(({ label }) => label).join(", ")
|
|
988
1633
|
});
|
|
989
1634
|
const [started, archive] = await Promise.all([
|
|
990
1635
|
scope.startBuildSandbox(access, {
|
|
@@ -1016,36 +1661,57 @@ async function buildSnapshot(context, request2, control, progress) {
|
|
|
1016
1661
|
signal
|
|
1017
1662
|
);
|
|
1018
1663
|
if (!staged.ok) return sandboxStop("upload", staged.failure);
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1664
|
+
if (prepared.baseFiles.length > 0) {
|
|
1665
|
+
const encoder = new TextEncoder();
|
|
1666
|
+
const placed = await context.runnerSandboxes.placeBaseFiles(
|
|
1667
|
+
sandbox,
|
|
1668
|
+
prepared.baseFiles.map(({ path, text }) => ({ name: path, content: encoder.encode(text) })),
|
|
1669
|
+
signal
|
|
1670
|
+
);
|
|
1671
|
+
if (!placed.ok) return sandboxStop("upload", placed.failure);
|
|
1672
|
+
}
|
|
1024
1673
|
const steps = [
|
|
1025
|
-
...
|
|
1674
|
+
...recipe.snapshot.toolchains,
|
|
1026
1675
|
{ label: BASE_INDEX_LABEL, script: baseIndexScript(base, staged.value.directory) },
|
|
1027
|
-
...
|
|
1676
|
+
...recipe.snapshot.prebuild
|
|
1028
1677
|
];
|
|
1029
1678
|
await progress.emit({ kind: "output-started", section: "snapshot", sandbox: sandbox.name, region: recipe.region });
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1679
|
+
let stop;
|
|
1680
|
+
if (request2.credentials.length > 0) {
|
|
1681
|
+
const granted = await scope.grantCredentials(sandbox, request2.credentials, signal);
|
|
1682
|
+
if (!granted.ok) stop = networkPolicyStop("inject", "snapshot-steps", granted.failure);
|
|
1683
|
+
}
|
|
1684
|
+
if (stop === void 0) {
|
|
1685
|
+
for (const step of steps) {
|
|
1686
|
+
if (signal.aborted) {
|
|
1687
|
+
stop = { kind: "aborted" };
|
|
1688
|
+
break;
|
|
1689
|
+
}
|
|
1690
|
+
const ran = await runStep(context, { sandbox, phase: "snapshot", ...step }, progress, signal);
|
|
1691
|
+
if (ran.kind === "succeeded") continue;
|
|
1692
|
+
stop = ran.kind === "exited" ? {
|
|
1693
|
+
kind: "failed",
|
|
1694
|
+
failure: {
|
|
1695
|
+
kind: "snapshot-build-step-failed",
|
|
1696
|
+
label: step.label,
|
|
1697
|
+
exitCode: ran.exitCode,
|
|
1698
|
+
tail: ran.tail
|
|
1699
|
+
}
|
|
1700
|
+
} : sandboxStop("run-script", ran.failure);
|
|
1701
|
+
break;
|
|
1702
|
+
}
|
|
1043
1703
|
}
|
|
1044
|
-
await progress.emit({
|
|
1704
|
+
await progress.emit({
|
|
1705
|
+
kind: "output-ended",
|
|
1706
|
+
section: "snapshot",
|
|
1707
|
+
outcome: stop === void 0 ? "finished" : stop.kind === "aborted" ? "stopped" : "failed"
|
|
1708
|
+
});
|
|
1709
|
+
if (stop !== void 0) return stop;
|
|
1045
1710
|
if (signal.aborted) return { kind: "aborted" };
|
|
1046
1711
|
await progress.emit({ kind: "snapshot-saving" });
|
|
1047
1712
|
const saved = await scope.saveSnapshot(sandbox, { expirationMs: SNAPSHOT_EXPIRATION_MS });
|
|
1048
|
-
if (!saved.ok)
|
|
1713
|
+
if (!saved.ok)
|
|
1714
|
+
return saved.failure.kind === "credential-not-revoked" ? networkPolicyStop("remove", "snapshot-save", saved.failure.failure) : sandboxStop("save-snapshot", saved.failure);
|
|
1049
1715
|
const savedAt = context.clock.now();
|
|
1050
1716
|
const entry = {
|
|
1051
1717
|
teamId: access.teamId,
|
|
@@ -1101,12 +1767,12 @@ async function prepareSnapshotBuild(context, request2) {
|
|
|
1101
1767
|
if (commit.value === null) return { kind: "ref-not-found", ref };
|
|
1102
1768
|
base = commit.value;
|
|
1103
1769
|
}
|
|
1104
|
-
const
|
|
1105
|
-
if (!
|
|
1770
|
+
const inputs = await snapshotInputsAt(checkout, { repoRoot, base, recipe });
|
|
1771
|
+
if (!inputs.ok) return { kind: "invalid-recipe", path: inputs.path, problem: inputs.problem };
|
|
1106
1772
|
const listed = await context.runnerSnapshots.listEntries();
|
|
1107
1773
|
const now = context.clock.now();
|
|
1108
1774
|
const cached = (listed.ok ? listed.value.entries : []).filter(
|
|
1109
|
-
(entry) => entry.base === base && entry.recipeName === recipe.name && entry.region === recipe.region && entry.runtime === recipe.runtime && entry.snapshotKey ===
|
|
1775
|
+
(entry) => entry.base === base && entry.recipeName === recipe.name && entry.region === recipe.region && entry.runtime === recipe.runtime && entry.snapshotKey === inputs.key && hasTimeLeft(entry, now)
|
|
1110
1776
|
);
|
|
1111
1777
|
const atMergeBase = base === mergeBase?.commit;
|
|
1112
1778
|
let commitsAfterBase = null;
|
|
@@ -1122,9 +1788,8 @@ async function prepareSnapshotBuild(context, request2) {
|
|
|
1122
1788
|
recipe,
|
|
1123
1789
|
repoRoot,
|
|
1124
1790
|
base,
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
snapshotKey: steps.key,
|
|
1791
|
+
baseFiles: inputs.baseFiles,
|
|
1792
|
+
snapshotKey: inputs.key,
|
|
1128
1793
|
commitsAfterBase
|
|
1129
1794
|
},
|
|
1130
1795
|
head: head2.value,
|
|
@@ -1138,25 +1803,21 @@ async function prepareSnapshotBuild(context, request2) {
|
|
|
1138
1803
|
}
|
|
1139
1804
|
async function buildSnapshots(context, request2, control, progress) {
|
|
1140
1805
|
const { signal } = control;
|
|
1141
|
-
const scope = runnerSandboxScope(context, progress, {
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
};
|
|
1146
|
-
if (signal.aborted) stop();
|
|
1147
|
-
else signal.addEventListener("abort", stop, { once: true });
|
|
1806
|
+
const scope = runnerSandboxScope(context, progress, {
|
|
1807
|
+
keepMs: 0,
|
|
1808
|
+
basePolicy: runnerNetworkPolicy(request2.build.plan.recipe),
|
|
1809
|
+
signal
|
|
1810
|
+
});
|
|
1148
1811
|
try {
|
|
1149
1812
|
const ended = await buildIn(context, request2, { scope, signal }, progress);
|
|
1150
|
-
signal.removeEventListener("abort", stop);
|
|
1151
1813
|
return { ...ended, cleanup: await scope.close() };
|
|
1152
1814
|
} catch (error) {
|
|
1153
|
-
signal.removeEventListener("abort", stop);
|
|
1154
1815
|
await scope.close();
|
|
1155
1816
|
throw error;
|
|
1156
1817
|
}
|
|
1157
1818
|
}
|
|
1158
1819
|
async function buildIn(context, request2, control, progress) {
|
|
1159
|
-
const { build, access, user,
|
|
1820
|
+
const { build, access, user, credentials: credentials2 } = request2;
|
|
1160
1821
|
const { signal } = control;
|
|
1161
1822
|
if (signal.aborted) return { kind: "aborted", snapshot: null };
|
|
1162
1823
|
const cached = build.cached.find((entry2) => entry2.teamId === access.teamId && entry2.projectId === access.projectId);
|
|
@@ -1168,7 +1829,7 @@ async function buildIn(context, request2, control, progress) {
|
|
|
1168
1829
|
prepared: build.plan,
|
|
1169
1830
|
access,
|
|
1170
1831
|
user,
|
|
1171
|
-
|
|
1832
|
+
credentials: credentials2,
|
|
1172
1833
|
why: why === "no-snapshot" ? { kind: why, rejected: [] } : { kind: why }
|
|
1173
1834
|
},
|
|
1174
1835
|
control,
|
|
@@ -1191,6 +1852,50 @@ function localUserName() {
|
|
|
1191
1852
|
}
|
|
1192
1853
|
}
|
|
1193
1854
|
|
|
1855
|
+
// src/runner/secrets.ts
|
|
1856
|
+
function declaredSecretValues(recipe, env) {
|
|
1857
|
+
if (recipe === void 0) return [];
|
|
1858
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1859
|
+
const values = [];
|
|
1860
|
+
for (const { source } of [...recipe.credentials, ...recipe.unsafeSecretEnvVars]) {
|
|
1861
|
+
const id = secretSourceId(source);
|
|
1862
|
+
if (seen.has(id)) continue;
|
|
1863
|
+
seen.add(id);
|
|
1864
|
+
const value = readSecretSourceValue(source, env);
|
|
1865
|
+
if (value !== void 0) values.push(value);
|
|
1866
|
+
}
|
|
1867
|
+
return values;
|
|
1868
|
+
}
|
|
1869
|
+
function readCredentials(recipe, env) {
|
|
1870
|
+
const read = readUniqueSources(recipe.credentials, env, ({ domain, header, requests }, value) => ({
|
|
1871
|
+
domain,
|
|
1872
|
+
header,
|
|
1873
|
+
value,
|
|
1874
|
+
requests
|
|
1875
|
+
}));
|
|
1876
|
+
return read.ok ? { ok: true, credentials: read.items } : read;
|
|
1877
|
+
}
|
|
1878
|
+
function readUnsafeSecretEnvVars(recipe, env) {
|
|
1879
|
+
const read = readUniqueSources(recipe.unsafeSecretEnvVars, env, ({ name }, value) => [name, value]);
|
|
1880
|
+
return read.ok ? { ok: true, values: Object.fromEntries(read.items) } : read;
|
|
1881
|
+
}
|
|
1882
|
+
function readUniqueSources(entries, env, map) {
|
|
1883
|
+
const cache = /* @__PURE__ */ new Map();
|
|
1884
|
+
const variables = [];
|
|
1885
|
+
const items = [];
|
|
1886
|
+
for (const entry of entries) {
|
|
1887
|
+
const id = secretSourceId(entry.source);
|
|
1888
|
+
let read = cache.get(id);
|
|
1889
|
+
if (read === void 0) {
|
|
1890
|
+
read = readSecretSource(entry.source, env);
|
|
1891
|
+
cache.set(id, read);
|
|
1892
|
+
if (!read.ok) variables.push({ name: describeSecretSource(entry.source), problem: read.problem });
|
|
1893
|
+
}
|
|
1894
|
+
if (read.ok) items.push(map(entry, read.value));
|
|
1895
|
+
}
|
|
1896
|
+
return variables.length === 0 ? { ok: true, items } : { ok: false, variables };
|
|
1897
|
+
}
|
|
1898
|
+
|
|
1194
1899
|
// src/runner/snapshot-inspect.ts
|
|
1195
1900
|
async function inspectSnapshotCache(context, request2) {
|
|
1196
1901
|
const { checkout, runnerSnapshots } = context;
|
|
@@ -1232,15 +1937,15 @@ async function inspectSnapshotCache(context, request2) {
|
|
|
1232
1937
|
};
|
|
1233
1938
|
}
|
|
1234
1939
|
const mergeBase = resolved.base;
|
|
1235
|
-
const
|
|
1236
|
-
if (!
|
|
1940
|
+
const inputs = await snapshotInputsAt(checkout, { repoRoot, base: mergeBase, recipe });
|
|
1941
|
+
if (!inputs.ok) return { kind: "invalid-recipe", path: inputs.path, problem: inputs.problem };
|
|
1237
1942
|
const afterBase = await checkout.commitCount({ repoRoot, from: mergeBase, to: "HEAD" });
|
|
1238
1943
|
if (!afterBase.ok) return { kind: "checkout-failed", failure: afterBase.failure };
|
|
1239
1944
|
const read = classifySnapshotEntries(context, {
|
|
1240
1945
|
entries,
|
|
1241
1946
|
recipe,
|
|
1242
1947
|
base: mergeBase,
|
|
1243
|
-
snapshotKey:
|
|
1948
|
+
snapshotKey: inputs.key,
|
|
1244
1949
|
commitsAfterBase: afterBase.value
|
|
1245
1950
|
});
|
|
1246
1951
|
const owners = new Map(read.candidates.map(({ entry }) => [`${entry.teamId}\0${entry.projectId}`, entry]));
|
|
@@ -1617,6 +2322,16 @@ function liveRunnerSandboxGateway() {
|
|
|
1617
2322
|
return { ok: false, failure: sandboxFailure(error, signal) };
|
|
1618
2323
|
}
|
|
1619
2324
|
},
|
|
2325
|
+
async placeBaseFiles(sandbox, files, signal) {
|
|
2326
|
+
if (files.length === 0) return { ok: true };
|
|
2327
|
+
const holder = holding(sandbox);
|
|
2328
|
+
try {
|
|
2329
|
+
await holder.sandbox.writeFiles(writes(SANDBOX_ROOT, files), signal === void 0 ? void 0 : { signal });
|
|
2330
|
+
return { ok: true };
|
|
2331
|
+
} catch (error) {
|
|
2332
|
+
return { ok: false, failure: sandboxFailure(error, signal) };
|
|
2333
|
+
}
|
|
2334
|
+
},
|
|
1620
2335
|
async runScript(sandbox, request2, onOutput, signal) {
|
|
1621
2336
|
const holder = holding(sandbox);
|
|
1622
2337
|
try {
|
|
@@ -1655,14 +2370,21 @@ function liveRunnerSandboxGateway() {
|
|
|
1655
2370
|
const holder = holding(sandbox);
|
|
1656
2371
|
if (kill.aborted) return { ok: false, failure: { kind: "aborted" } };
|
|
1657
2372
|
try {
|
|
1658
|
-
const cmd = await resolveExecutable(holder, request2);
|
|
1659
|
-
if (kill.aborted) return { ok: false, failure: { kind: "aborted" } };
|
|
1660
|
-
const
|
|
2373
|
+
const cmd = await untilAborted(resolveExecutable(holder, request2, kill), kill);
|
|
2374
|
+
if (cmd === ABORTED || kill.aborted) return { ok: false, failure: { kind: "aborted" } };
|
|
2375
|
+
const starting = startDetached(holder, {
|
|
1661
2376
|
cmd: "setpriv",
|
|
1662
2377
|
args: [...DROP_CAPABILITIES_ARGS, cmd, ...request2.args],
|
|
1663
2378
|
cwd: request2.cwd,
|
|
1664
2379
|
env: { ...request2.env }
|
|
1665
2380
|
});
|
|
2381
|
+
const command = await untilAborted(starting, kill);
|
|
2382
|
+
if (command === ABORTED) {
|
|
2383
|
+
starting.then((late) => late?.kill("SIGTERM").catch(() => {
|
|
2384
|
+
})).catch(() => {
|
|
2385
|
+
});
|
|
2386
|
+
return { ok: false, failure: { kind: "aborted" } };
|
|
2387
|
+
}
|
|
1666
2388
|
if (command === void 0) return { ok: false, failure: { kind: "aborted" } };
|
|
1667
2389
|
const terminate = () => {
|
|
1668
2390
|
command.kill("SIGTERM").catch(() => {
|
|
@@ -1759,6 +2481,19 @@ function liveRunnerSandboxGateway() {
|
|
|
1759
2481
|
return { ok: false, failure: sandboxFailure(error, signal) };
|
|
1760
2482
|
}
|
|
1761
2483
|
},
|
|
2484
|
+
async writeNetworkPolicy(sandbox, policy, signal) {
|
|
2485
|
+
const holder = holding(sandbox);
|
|
2486
|
+
if (signal?.aborted === true) return { ok: false, failure: { kind: "aborted" } };
|
|
2487
|
+
const networkPolicy = sdkNetworkPolicy(policy);
|
|
2488
|
+
try {
|
|
2489
|
+
await holder.sandbox.update({ networkPolicy }, signal === void 0 ? void 0 : { signal });
|
|
2490
|
+
return { ok: true };
|
|
2491
|
+
} catch (error) {
|
|
2492
|
+
const failure = sandboxFailure(error, signal);
|
|
2493
|
+
if (failure.kind !== "api") return { ok: false, failure };
|
|
2494
|
+
return { ok: false, failure: { ...failure, message: hideCredentialValues(failure.message, policy) } };
|
|
2495
|
+
}
|
|
2496
|
+
},
|
|
1762
2497
|
async saveSnapshot(sandbox, request2) {
|
|
1763
2498
|
const holder = holding(sandbox);
|
|
1764
2499
|
try {
|
|
@@ -1784,11 +2519,12 @@ function liveRunnerSandboxGateway() {
|
|
|
1784
2519
|
return { ok: false, failure: sandboxFailure(error, void 0) };
|
|
1785
2520
|
}
|
|
1786
2521
|
},
|
|
1787
|
-
async keepRunning(sandbox, request2) {
|
|
2522
|
+
async keepRunning(sandbox, request2, signal) {
|
|
1788
2523
|
const holder = holding(sandbox);
|
|
1789
2524
|
holder.keeping = true;
|
|
1790
|
-
await
|
|
1791
|
-
const stillRunning = (await Promise.all([...holder.running].map((command) => endProcess(holder, command)))).filter((ended) => !ended).length;
|
|
2525
|
+
if (!await settledUnlessAborted(holder.starting, signal)) return { ok: false, failure: { kind: "aborted" } };
|
|
2526
|
+
const stillRunning = (await Promise.all([...holder.running].map((command) => endProcess(holder, command, signal)))).filter((ended) => !ended).length;
|
|
2527
|
+
if (isAborted(signal)) return { ok: false, failure: { kind: "aborted" } };
|
|
1792
2528
|
if (stillRunning > 0)
|
|
1793
2529
|
return {
|
|
1794
2530
|
ok: false,
|
|
@@ -1801,28 +2537,32 @@ function liveRunnerSandboxGateway() {
|
|
|
1801
2537
|
const stopsAt = holder.sandbox.expiresAt;
|
|
1802
2538
|
const short = request2.until.getTime() - (stopsAt?.getTime() ?? Date.now());
|
|
1803
2539
|
if (short <= 0 && stopsAt !== void 0) return { ok: true, value: { stopsAt } };
|
|
1804
|
-
await holder.sandbox.extendTimeout(short);
|
|
2540
|
+
if (signal === void 0) await holder.sandbox.extendTimeout(short);
|
|
2541
|
+
else await holder.sandbox.extendTimeout(short, { signal });
|
|
1805
2542
|
return { ok: true, value: { stopsAt: holder.sandbox.expiresAt ?? request2.until } };
|
|
1806
2543
|
} catch (error) {
|
|
1807
|
-
return { ok: false, failure: sandboxFailure(error,
|
|
2544
|
+
return { ok: false, failure: sandboxFailure(error, signal) };
|
|
1808
2545
|
}
|
|
1809
2546
|
},
|
|
1810
|
-
async stop(sandbox) {
|
|
2547
|
+
async stop(sandbox, signal) {
|
|
1811
2548
|
const holder = holding(sandbox);
|
|
2549
|
+
if (isAborted(signal)) return { ok: false, failure: { kind: "aborted" } };
|
|
1812
2550
|
try {
|
|
1813
|
-
await holder.sandbox.stop();
|
|
2551
|
+
if (signal === void 0) await holder.sandbox.stop();
|
|
2552
|
+
else await holder.sandbox.stop({ signal });
|
|
1814
2553
|
return { ok: true };
|
|
1815
2554
|
} catch (error) {
|
|
1816
|
-
return { ok: false, failure: sandboxFailure(error,
|
|
2555
|
+
return { ok: false, failure: sandboxFailure(error, signal) };
|
|
1817
2556
|
}
|
|
1818
2557
|
},
|
|
1819
|
-
async delete(sandbox) {
|
|
2558
|
+
async delete(sandbox, signal) {
|
|
1820
2559
|
const holder = holding(sandbox);
|
|
2560
|
+
if (isAborted(signal)) return { ok: false, failure: { kind: "aborted" } };
|
|
1821
2561
|
try {
|
|
1822
|
-
await holder.sandbox.delete({ deleteOrphanSnapshots: false });
|
|
2562
|
+
await holder.sandbox.delete({ deleteOrphanSnapshots: false, ...signal === void 0 ? {} : { signal } });
|
|
1823
2563
|
return { ok: true };
|
|
1824
2564
|
} catch (error) {
|
|
1825
|
-
return { ok: false, failure: sandboxFailure(error,
|
|
2565
|
+
return { ok: false, failure: sandboxFailure(error, signal) };
|
|
1826
2566
|
}
|
|
1827
2567
|
}
|
|
1828
2568
|
};
|
|
@@ -1836,9 +2576,45 @@ function placement(request2) {
|
|
|
1836
2576
|
resources: { vcpus: request2.vcpus },
|
|
1837
2577
|
timeout: request2.timeoutMs,
|
|
1838
2578
|
persistent: false,
|
|
1839
|
-
tags: { ...request2.tags }
|
|
2579
|
+
tags: { ...request2.tags },
|
|
2580
|
+
networkPolicy: sdkNetworkPolicy(request2.networkPolicy)
|
|
1840
2581
|
};
|
|
1841
2582
|
}
|
|
2583
|
+
function sdkNetworkPolicy(policy) {
|
|
2584
|
+
switch (policy.kind) {
|
|
2585
|
+
case "allow-all":
|
|
2586
|
+
if (policy.credentials.length === 0) return "allow-all";
|
|
2587
|
+
return { allow: { "*": [], ...injectionRules(policy.credentials) } };
|
|
2588
|
+
case "custom":
|
|
2589
|
+
return {
|
|
2590
|
+
allow: {
|
|
2591
|
+
...Object.fromEntries(policy.allowedDomains.map((domain) => [domain, []])),
|
|
2592
|
+
...injectionRules(policy.credentials)
|
|
2593
|
+
}
|
|
2594
|
+
};
|
|
2595
|
+
case "deny-all":
|
|
2596
|
+
return "deny-all";
|
|
2597
|
+
}
|
|
2598
|
+
}
|
|
2599
|
+
function injectionRules(credentials2) {
|
|
2600
|
+
const byDomain = /* @__PURE__ */ new Map();
|
|
2601
|
+
for (const { domain, header, value, requests } of credentials2) {
|
|
2602
|
+
const group = byDomain.get(domain) ?? { requests, headers: {} };
|
|
2603
|
+
if (group.requests !== requests)
|
|
2604
|
+
throw new Error(`writeNetworkPolicy: the credentials for ${domain} differ in requests`);
|
|
2605
|
+
group.headers[header] = value;
|
|
2606
|
+
byDomain.set(domain, group);
|
|
2607
|
+
}
|
|
2608
|
+
const rules = {};
|
|
2609
|
+
for (const [domain, { requests, headers }] of byDomain)
|
|
2610
|
+
rules[domain] = requests === "all" ? [{ transform: [{ headers }] }] : [{ match: { method: ["GET", "HEAD"] }, transform: [{ headers }] }, { response: { statusCode: 403 } }];
|
|
2611
|
+
return rules;
|
|
2612
|
+
}
|
|
2613
|
+
function hideCredentialValues(message, policy) {
|
|
2614
|
+
let hidden = message;
|
|
2615
|
+
for (const { value } of policyCredentials(policy)) if (value !== "") hidden = hidden.split(value).join("<token>");
|
|
2616
|
+
return hidden;
|
|
2617
|
+
}
|
|
1842
2618
|
function writes(directory, files) {
|
|
1843
2619
|
return files.map((file) => ({ path: `${directory}/${file.name}`, content: file.content }));
|
|
1844
2620
|
}
|
|
@@ -1855,16 +2631,17 @@ async function stagingDirectory(holder, signal) {
|
|
|
1855
2631
|
holder.staging = directory;
|
|
1856
2632
|
return directory;
|
|
1857
2633
|
}
|
|
1858
|
-
async function resolveExecutable(holder, request2) {
|
|
2634
|
+
async function resolveExecutable(holder, request2, signal) {
|
|
1859
2635
|
if (request2.cmd.includes("/")) return request2.cmd;
|
|
1860
2636
|
const found = await holder.sandbox.runCommand({
|
|
1861
2637
|
cmd: "bash",
|
|
1862
2638
|
args: ["-c", 'command -v -- "$1"', "_", request2.cmd],
|
|
1863
2639
|
cwd: request2.cwd,
|
|
1864
|
-
env: { ...request2.env }
|
|
2640
|
+
env: { ...request2.env },
|
|
2641
|
+
signal
|
|
1865
2642
|
});
|
|
1866
2643
|
if (found.exitCode !== 0) return request2.cmd;
|
|
1867
|
-
const path = (await found.stdout()).trim();
|
|
2644
|
+
const path = (await found.stdout({ signal })).trim();
|
|
1868
2645
|
return path.startsWith("/") ? path : request2.cmd;
|
|
1869
2646
|
}
|
|
1870
2647
|
async function startDetached(holder, params) {
|
|
@@ -1886,30 +2663,53 @@ async function follow(holder, command, onOutput, signal) {
|
|
|
1886
2663
|
holder.running.delete(command);
|
|
1887
2664
|
return { exitCode: typeof finished.exitCode === "number" ? finished.exitCode : null };
|
|
1888
2665
|
}
|
|
1889
|
-
async function endProcess(holder, command) {
|
|
1890
|
-
for (const [
|
|
2666
|
+
async function endProcess(holder, command, signal) {
|
|
2667
|
+
for (const [kill, graceMs] of [
|
|
1891
2668
|
["SIGTERM", TERMINATE_GRACE_MS],
|
|
1892
2669
|
["SIGKILL", KILL_GRACE_MS]
|
|
1893
2670
|
]) {
|
|
1894
|
-
|
|
1895
|
-
|
|
2671
|
+
if (isAborted(signal)) return false;
|
|
2672
|
+
await withinLimit(graceMs, signal, (limit) => command.kill(kill, { abortSignal: limit })).catch(() => void 0);
|
|
2673
|
+
if (await endsWithin(command, graceMs, signal)) {
|
|
1896
2674
|
holder.running.delete(command);
|
|
1897
2675
|
return true;
|
|
1898
2676
|
}
|
|
1899
2677
|
}
|
|
1900
2678
|
return false;
|
|
1901
2679
|
}
|
|
1902
|
-
async function endsWithin(command, ms) {
|
|
1903
|
-
const timeout = new AbortController();
|
|
1904
|
-
const timer = setTimeout(() => timeout.abort(), ms);
|
|
2680
|
+
async function endsWithin(command, ms, signal) {
|
|
1905
2681
|
try {
|
|
1906
|
-
await command.wait({ signal:
|
|
2682
|
+
await withinLimit(ms, signal, (limit) => command.wait({ signal: limit }));
|
|
1907
2683
|
return true;
|
|
1908
2684
|
} catch {
|
|
1909
2685
|
return false;
|
|
2686
|
+
}
|
|
2687
|
+
}
|
|
2688
|
+
async function withinLimit(ms, signal, call) {
|
|
2689
|
+
if (isAborted(signal)) throw new DOMException("This operation was aborted", "AbortError");
|
|
2690
|
+
const limit = new AbortController();
|
|
2691
|
+
const timer = setTimeout(() => limit.abort(), ms);
|
|
2692
|
+
const onAbort = () => limit.abort();
|
|
2693
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
2694
|
+
const aborted = new Promise((_, reject) => {
|
|
2695
|
+
limit.signal.addEventListener("abort", () => reject(new DOMException("This operation was aborted", "AbortError")), {
|
|
2696
|
+
once: true
|
|
2697
|
+
});
|
|
2698
|
+
});
|
|
2699
|
+
try {
|
|
2700
|
+
return await Promise.race([call(limit.signal), aborted]);
|
|
1910
2701
|
} finally {
|
|
1911
2702
|
clearTimeout(timer);
|
|
2703
|
+
signal?.removeEventListener("abort", onAbort);
|
|
2704
|
+
}
|
|
2705
|
+
}
|
|
2706
|
+
async function settledUnlessAborted(tasks, signal) {
|
|
2707
|
+
if (isAborted(signal)) return false;
|
|
2708
|
+
if (signal === void 0 || tasks.size === 0) {
|
|
2709
|
+
await Promise.allSettled(tasks);
|
|
2710
|
+
return true;
|
|
1912
2711
|
}
|
|
2712
|
+
return await untilAborted(Promise.allSettled(tasks), signal) !== ABORTED;
|
|
1913
2713
|
}
|
|
1914
2714
|
function isAborted(signal) {
|
|
1915
2715
|
return signal?.aborted === true;
|
|
@@ -2114,9 +2914,9 @@ async function prepareRunner(context, request2) {
|
|
|
2114
2914
|
const submodules2 = await checkout.submodules({ repoRoot });
|
|
2115
2915
|
if (!submodules2.ok) return { kind: "checkout-failed", failure: submodules2.failure };
|
|
2116
2916
|
if (submodules2.value.length > 0) return { kind: "submodules", paths: [...submodules2.value] };
|
|
2117
|
-
const
|
|
2118
|
-
if (!
|
|
2119
|
-
const vcpus = resolveVcpus(recipe, request2.
|
|
2917
|
+
const inputs = await snapshotInputsAt(checkout, { repoRoot, base, recipe });
|
|
2918
|
+
if (!inputs.ok) return { kind: "invalid-recipe", path: inputs.path, problem: inputs.problem };
|
|
2919
|
+
const vcpus = resolveVcpus(recipe, request2.vcpuRun);
|
|
2120
2920
|
if (!vcpus.ok) return { kind: "invalid-recipe", path: ["vcpus"], problem: vcpus.problem };
|
|
2121
2921
|
const upload = await checkout.assembleUpload({ repoRoot, base });
|
|
2122
2922
|
if (!upload.ok) return { kind: "checkout-failed", failure: upload.failure };
|
|
@@ -2127,7 +2927,7 @@ async function prepareRunner(context, request2) {
|
|
|
2127
2927
|
entries: listing.entries,
|
|
2128
2928
|
recipe,
|
|
2129
2929
|
base,
|
|
2130
|
-
snapshotKey:
|
|
2930
|
+
snapshotKey: inputs.key,
|
|
2131
2931
|
commitsAfterBase: afterBase.value
|
|
2132
2932
|
});
|
|
2133
2933
|
return {
|
|
@@ -2137,9 +2937,8 @@ async function prepareRunner(context, request2) {
|
|
|
2137
2937
|
repoRoot,
|
|
2138
2938
|
base,
|
|
2139
2939
|
baseRef: resolved.ref,
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
snapshotKey: steps.key,
|
|
2940
|
+
baseFiles: inputs.baseFiles,
|
|
2941
|
+
snapshotKey: inputs.key,
|
|
2143
2942
|
vcpus: vcpus.vcpus,
|
|
2144
2943
|
upload: upload.value,
|
|
2145
2944
|
candidates: cache.candidates,
|
|
@@ -2150,141 +2949,44 @@ async function prepareRunner(context, request2) {
|
|
|
2150
2949
|
};
|
|
2151
2950
|
}
|
|
2152
2951
|
|
|
2153
|
-
// src/runner/sandboxed-command.ts
|
|
2154
|
-
import { posix } from "node:path";
|
|
2155
|
-
function sandboxedCommand(request2) {
|
|
2156
|
-
const [first = "", ...rest] = request2.argv.map((argument) => rewritePaths(argument, request2.repoRoot, SANDBOX_ROOT));
|
|
2157
|
-
const cmd = first.includes("/") && !first.startsWith("/") ? posix.join(request2.cwd, first) : first;
|
|
2158
|
-
return { cmd, args: rest };
|
|
2159
|
-
}
|
|
2160
|
-
function sandboxEnvironment(request2) {
|
|
2161
|
-
const bins = [
|
|
2162
|
-
.../* @__PURE__ */ new Set([posix.join(request2.cwd, "node_modules/.bin"), posix.join(SANDBOX_ROOT, "node_modules/.bin")])
|
|
2163
|
-
];
|
|
2164
|
-
return {
|
|
2165
|
-
PATH: [...bins, request2.loginPath].filter((part) => part !== "").join(":"),
|
|
2166
|
-
NO_UPDATE_NOTIFIER: "1",
|
|
2167
|
-
...request2.env["FORCE_COLOR"] !== void 0 || request2.env["NO_COLOR"] !== void 0 ? {} : request2.color === "on" ? { FORCE_COLOR: "1" } : request2.color === "off" ? { NO_COLOR: "1" } : {},
|
|
2168
|
-
...request2.env,
|
|
2169
|
-
[RUN_PAYLOAD_VARIABLE]: request2.runPayload
|
|
2170
|
-
};
|
|
2171
|
-
}
|
|
2172
|
-
var SANDBOX_TEST_EVENTS_PATH = "/tmp/storm-test-events.jsonl";
|
|
2173
|
-
async function runCommandInSandbox(context, request2, control, progress) {
|
|
2174
|
-
const { runner } = request2;
|
|
2175
|
-
const terminal = context.runnerTerminal;
|
|
2176
|
-
const command = sandboxedCommand({ argv: request2.argv, repoRoot: runner.repoRoot, cwd: runner.cwd });
|
|
2177
|
-
const env = sandboxEnvironment({
|
|
2178
|
-
cwd: runner.cwd,
|
|
2179
|
-
loginPath: runner.loginPath,
|
|
2180
|
-
color: terminal.color,
|
|
2181
|
-
env: runner.env,
|
|
2182
|
-
runPayload: request2.runPayload
|
|
2183
|
-
});
|
|
2184
|
-
await progress.emit({ kind: "command-output-started", sandbox: runner.sandbox.name, region: runner.region });
|
|
2185
|
-
const startedAt = context.clock.now().getTime();
|
|
2186
|
-
const splitters = { stdout: lineSplitter(), stderr: lineSplitter() };
|
|
2187
|
-
const write = (stream, text) => {
|
|
2188
|
-
if (text === "") return;
|
|
2189
|
-
const local = rewritePaths(text, SANDBOX_ROOT, runner.repoRoot);
|
|
2190
|
-
if (stream === "stdout") terminal.writeStdout(local);
|
|
2191
|
-
else terminal.writeStderr(local);
|
|
2192
|
-
};
|
|
2193
|
-
const following = followTestEvents(context, runner, request2.testEvents, control.kill);
|
|
2194
|
-
const ran = await context.runnerSandboxes.runCommand(
|
|
2195
|
-
runner.sandbox,
|
|
2196
|
-
{ cmd: command.cmd, args: command.args, cwd: runner.cwd, env },
|
|
2197
|
-
({ stream, data }) => write(stream, splitters[stream].push(data)),
|
|
2198
|
-
control.kill
|
|
2199
|
-
);
|
|
2200
|
-
const ms = context.clock.now().getTime() - startedAt;
|
|
2201
|
-
write("stdout", splitters.stdout.flush());
|
|
2202
|
-
write("stderr", splitters.stderr.flush());
|
|
2203
|
-
await following?.end(ran.ok && !control.kill.aborted);
|
|
2204
|
-
if (!ran.ok) {
|
|
2205
|
-
if (ran.failure.kind !== "aborted")
|
|
2206
|
-
return { kind: "failed", failure: sandboxApiFailure("run-command", ran.failure) };
|
|
2207
|
-
await progress.emit({ kind: "command-stopped", command: posix.basename(command.cmd) });
|
|
2208
|
-
return { kind: "killed" };
|
|
2209
|
-
}
|
|
2210
|
-
return { kind: "exited", exitCode: ran.value.exitCode, ms };
|
|
2211
|
-
}
|
|
2212
|
-
function followTestEvents(context, runner, testEvents, kill) {
|
|
2213
|
-
if (testEvents === void 0) return void 0;
|
|
2214
|
-
const stop = new AbortController();
|
|
2215
|
-
const splitter = lineSplitter();
|
|
2216
|
-
let handed = 0;
|
|
2217
|
-
const hand = (lines) => {
|
|
2218
|
-
for (const line of lines) {
|
|
2219
|
-
handed += 1;
|
|
2220
|
-
testEvents.onLine(line);
|
|
2221
|
-
}
|
|
2222
|
-
};
|
|
2223
|
-
const followed = context.runnerSandboxes.followTestEvents(
|
|
2224
|
-
runner.sandbox,
|
|
2225
|
-
{ path: SANDBOX_TEST_EVENTS_PATH },
|
|
2226
|
-
({ data }) => hand(splitLines(splitter.push(data))),
|
|
2227
|
-
stop.signal
|
|
2228
|
-
);
|
|
2229
|
-
return {
|
|
2230
|
-
async end(complete) {
|
|
2231
|
-
stop.abort();
|
|
2232
|
-
await followed;
|
|
2233
|
-
if (!complete) {
|
|
2234
|
-
hand(splitLines(splitter.flush()));
|
|
2235
|
-
return;
|
|
2236
|
-
}
|
|
2237
|
-
const reader = lineSplitter();
|
|
2238
|
-
let read = false;
|
|
2239
|
-
const result = await context.runnerSandboxes.readTestEvents(
|
|
2240
|
-
runner.sandbox,
|
|
2241
|
-
{ path: SANDBOX_TEST_EVENTS_PATH, fromLine: handed + 1 },
|
|
2242
|
-
({ data }) => {
|
|
2243
|
-
if (!read) {
|
|
2244
|
-
splitter.flush();
|
|
2245
|
-
read = true;
|
|
2246
|
-
}
|
|
2247
|
-
hand(splitLines(reader.push(data)));
|
|
2248
|
-
},
|
|
2249
|
-
kill
|
|
2250
|
-
);
|
|
2251
|
-
hand(splitLines(read ? reader.flush() : splitter.flush()));
|
|
2252
|
-
if (!result.ok && result.failure.kind === "api") testEvents.onIncomplete(result.failure.message);
|
|
2253
|
-
}
|
|
2254
|
-
};
|
|
2255
|
-
}
|
|
2256
|
-
|
|
2257
2952
|
// src/runner/ready.ts
|
|
2258
|
-
import { posix
|
|
2953
|
+
import { posix } from "node:path";
|
|
2259
2954
|
var APPLY_LABEL = "Applying your changes";
|
|
2260
2955
|
async function readyRunner(context, request2, control, progress) {
|
|
2956
|
+
const chosen = await chooseSnapshot(context, request2, control, progress);
|
|
2957
|
+
if (chosen.kind !== "ok") return chosen;
|
|
2958
|
+
return await readyFromSnapshot(context, { ...request2, snapshot: chosen.value }, control, progress);
|
|
2959
|
+
}
|
|
2960
|
+
async function chooseSnapshot(context, request2, control, progress) {
|
|
2261
2961
|
const { prepared, access } = request2;
|
|
2262
|
-
|
|
2263
|
-
const { scope, signal } = control;
|
|
2264
|
-
const now = () => context.clock.now().getTime();
|
|
2265
|
-
if (signal.aborted) return { kind: "aborted" };
|
|
2962
|
+
if (control.signal.aborted) return { kind: "aborted" };
|
|
2266
2963
|
const pick = pickSnapshot(prepared.candidates, access);
|
|
2267
|
-
let entry;
|
|
2268
2964
|
if (pick !== void 0) {
|
|
2269
|
-
|
|
2965
|
+
const { entry } = pick;
|
|
2270
2966
|
await progress.emit({
|
|
2271
2967
|
kind: "snapshot-reused",
|
|
2272
2968
|
snapshotId: entry.snapshotId,
|
|
2273
2969
|
base: entry.base,
|
|
2274
2970
|
builtBehind: pick.builtBehind
|
|
2275
2971
|
});
|
|
2276
|
-
|
|
2277
|
-
const why = { kind: "no-snapshot", rejected: snapshotRejections(prepared, access) };
|
|
2278
|
-
const building = await buildSnapshot(
|
|
2279
|
-
context,
|
|
2280
|
-
{ prepared, access, user: request2.user, secrets: request2.secrets, why },
|
|
2281
|
-
control,
|
|
2282
|
-
progress
|
|
2283
|
-
);
|
|
2284
|
-
if (building.kind !== "ok") return building;
|
|
2285
|
-
({ entry } = building.value);
|
|
2972
|
+
return { kind: "ok", value: { entry, built: false } };
|
|
2286
2973
|
}
|
|
2287
|
-
const
|
|
2974
|
+
const why = { kind: "no-snapshot", rejected: snapshotRejections(prepared, access) };
|
|
2975
|
+
const building = await buildSnapshot(
|
|
2976
|
+
context,
|
|
2977
|
+
{ prepared, access, user: request2.user, credentials: request2.credentials, why },
|
|
2978
|
+
control,
|
|
2979
|
+
progress
|
|
2980
|
+
);
|
|
2981
|
+
if (building.kind !== "ok") return building;
|
|
2982
|
+
return { kind: "ok", value: { entry: building.value.entry, built: true } };
|
|
2983
|
+
}
|
|
2984
|
+
async function readyFromSnapshot(context, request2, control, progress) {
|
|
2985
|
+
const { prepared, access } = request2;
|
|
2986
|
+
const { entry, built } = request2.snapshot;
|
|
2987
|
+
const { recipe, repoRoot } = prepared;
|
|
2988
|
+
const { scope, signal } = control;
|
|
2989
|
+
const now = () => context.clock.now().getTime();
|
|
2288
2990
|
if (signal.aborted) return { kind: "aborted" };
|
|
2289
2991
|
await progress.emit({ kind: "runner-sandbox-starting", snapshotId: entry.snapshotId });
|
|
2290
2992
|
const startedAt = now();
|
|
@@ -2327,28 +3029,20 @@ async function readyRunner(context, request2, control, progress) {
|
|
|
2327
3029
|
if (applied.kind !== "ok") return applied;
|
|
2328
3030
|
const loginPath = await context.runnerSandboxes.loginPath(sandbox, signal);
|
|
2329
3031
|
if (!loginPath.ok) return sandboxStop("login-path", loginPath.failure);
|
|
3032
|
+
if (request2.credentials.length > 0) {
|
|
3033
|
+
const granted = await scope.grantCredentials(sandbox, request2.credentials, signal);
|
|
3034
|
+
if (!granted.ok) return networkPolicyStop("inject", "run-steps", granted.failure);
|
|
3035
|
+
}
|
|
2330
3036
|
const installed = await stage(
|
|
2331
3037
|
context,
|
|
2332
|
-
{
|
|
2333
|
-
sandbox,
|
|
2334
|
-
phase: "install",
|
|
2335
|
-
step: recipe.run.install,
|
|
2336
|
-
secrets: stepSecrets(request2.secrets, recipe.run.install.secrets),
|
|
2337
|
-
region: recipe.region
|
|
2338
|
-
},
|
|
3038
|
+
{ sandbox, phase: "install", step: recipe.run.install, region: recipe.region },
|
|
2339
3039
|
signal,
|
|
2340
3040
|
progress
|
|
2341
3041
|
);
|
|
2342
3042
|
if (installed.kind !== "ok") return installed;
|
|
2343
3043
|
const builtOutputs = await stage(
|
|
2344
3044
|
context,
|
|
2345
|
-
{
|
|
2346
|
-
sandbox,
|
|
2347
|
-
phase: "build",
|
|
2348
|
-
step: recipe.run.build,
|
|
2349
|
-
secrets: stepSecrets(request2.secrets, recipe.run.build.secrets),
|
|
2350
|
-
region: recipe.region
|
|
2351
|
-
},
|
|
3045
|
+
{ sandbox, phase: "build", step: recipe.run.build, region: recipe.region },
|
|
2352
3046
|
signal,
|
|
2353
3047
|
progress
|
|
2354
3048
|
);
|
|
@@ -2367,7 +3061,7 @@ async function readyRunner(context, request2, control, progress) {
|
|
|
2367
3061
|
region: recipe.region,
|
|
2368
3062
|
runtime: recipe.runtime,
|
|
2369
3063
|
repoRoot,
|
|
2370
|
-
cwd:
|
|
3064
|
+
cwd: posix.join(SANDBOX_ROOT, recipe.cwd),
|
|
2371
3065
|
env: recipe.env,
|
|
2372
3066
|
loginPath: loginPath.value
|
|
2373
3067
|
}
|
|
@@ -2394,104 +3088,324 @@ function stagedChanges(upload) {
|
|
|
2394
3088
|
...upload.untrackedTarball === void 0 ? [] : [{ name: STAGED_FILES.untrackedTarball, content: upload.untrackedTarball }]
|
|
2395
3089
|
];
|
|
2396
3090
|
}
|
|
2397
|
-
async function stage(context, request2, signal, progress) {
|
|
2398
|
-
if (signal.aborted) return { kind: "aborted" };
|
|
2399
|
-
const { sandbox, phase, step } = request2;
|
|
2400
|
-
const section = phase === "apply" ? void 0 : phase;
|
|
2401
|
-
if (section !== void 0)
|
|
2402
|
-
await progress.emit({ kind: "output-started", section, sandbox: sandbox.name, region: request2.region });
|
|
2403
|
-
const ran = await runStep(
|
|
2404
|
-
|
|
2405
|
-
{
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
const
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
3091
|
+
async function stage(context, request2, signal, progress) {
|
|
3092
|
+
if (signal.aborted) return { kind: "aborted" };
|
|
3093
|
+
const { sandbox, phase, step } = request2;
|
|
3094
|
+
const section = phase === "apply" ? void 0 : phase;
|
|
3095
|
+
if (section !== void 0)
|
|
3096
|
+
await progress.emit({ kind: "output-started", section, sandbox: sandbox.name, region: request2.region });
|
|
3097
|
+
const ran = await runStep(context, { sandbox, phase, label: step.label, script: step.script }, progress, signal);
|
|
3098
|
+
if (ran.kind === "succeeded") {
|
|
3099
|
+
if (section !== void 0) await progress.emit({ kind: "output-ended", section, outcome: "finished" });
|
|
3100
|
+
return { kind: "ok", value: ran.ms };
|
|
3101
|
+
}
|
|
3102
|
+
const stop = ran.kind === "exited" ? {
|
|
3103
|
+
kind: "failed",
|
|
3104
|
+
failure: { kind: `${phase}-failed`, label: step.label, exitCode: ran.exitCode, tail: ran.tail }
|
|
3105
|
+
} : sandboxStop("run-script", ran.failure);
|
|
3106
|
+
if (section !== void 0)
|
|
3107
|
+
await progress.emit({ kind: "output-ended", section, outcome: stop.kind === "aborted" ? "stopped" : "failed" });
|
|
3108
|
+
return stop;
|
|
3109
|
+
}
|
|
3110
|
+
|
|
3111
|
+
// src/runner/snapshot-choice.ts
|
|
3112
|
+
async function chooseSnapshotForRun(context, request2, control, progress) {
|
|
3113
|
+
const { signal, stop } = control;
|
|
3114
|
+
const stageSignal = stop === void 0 ? signal : AbortSignal.any([signal, stop]);
|
|
3115
|
+
const scope = runnerSandboxScope(context, progress, {
|
|
3116
|
+
keepMs: 0,
|
|
3117
|
+
basePolicy: runnerNetworkPolicy(request2.prepared.recipe),
|
|
3118
|
+
signal
|
|
3119
|
+
});
|
|
3120
|
+
try {
|
|
3121
|
+
const chosen = await chooseSnapshot(context, request2, { scope, signal: stageSignal }, progress);
|
|
3122
|
+
const cleanup = await scope.close();
|
|
3123
|
+
if (chosen.kind !== "ok") return { ...chosen, cleanup };
|
|
3124
|
+
if (stageSignal.aborted) return { kind: "aborted", cleanup };
|
|
3125
|
+
return { kind: "chosen", snapshot: chosen.value, cleanup };
|
|
3126
|
+
} catch (error) {
|
|
3127
|
+
await scope.close();
|
|
3128
|
+
throw error;
|
|
3129
|
+
}
|
|
3130
|
+
}
|
|
3131
|
+
|
|
3132
|
+
// src/runner/sandboxed-command.ts
|
|
3133
|
+
import { posix as posix2 } from "node:path";
|
|
3134
|
+
function sandboxedCommand(request2) {
|
|
3135
|
+
const [first = "", ...rest] = request2.argv.map((argument) => rewritePaths(argument, request2.repoRoot, SANDBOX_ROOT));
|
|
3136
|
+
const cmd = first.includes("/") && !first.startsWith("/") ? posix2.join(request2.cwd, first) : first;
|
|
3137
|
+
return { cmd, args: rest };
|
|
3138
|
+
}
|
|
3139
|
+
function sandboxEnvironment(request2) {
|
|
3140
|
+
const bins = [
|
|
3141
|
+
.../* @__PURE__ */ new Set([posix2.join(request2.cwd, "node_modules/.bin"), posix2.join(SANDBOX_ROOT, "node_modules/.bin")])
|
|
3142
|
+
];
|
|
3143
|
+
return {
|
|
3144
|
+
PATH: [...bins, request2.loginPath].filter((part) => part !== "").join(":"),
|
|
3145
|
+
NO_UPDATE_NOTIFIER: "1",
|
|
3146
|
+
...request2.env["FORCE_COLOR"] !== void 0 || request2.env["NO_COLOR"] !== void 0 ? {} : request2.color === "on" ? { FORCE_COLOR: "1" } : request2.color === "off" ? { NO_COLOR: "1" } : {},
|
|
3147
|
+
...request2.env,
|
|
3148
|
+
...request2.unsafeSecretEnvVars,
|
|
3149
|
+
[RUN_PAYLOAD_VARIABLE]: request2.runPayload
|
|
3150
|
+
};
|
|
3151
|
+
}
|
|
3152
|
+
var TEST_EVENTS_END_LIMIT_MS = 3e4;
|
|
3153
|
+
var SANDBOX_TEST_EVENTS_PATH = "/tmp/storm-test-events.jsonl";
|
|
3154
|
+
async function runCommandInSandbox(context, request2, control, progress) {
|
|
3155
|
+
const { runner } = request2;
|
|
3156
|
+
const terminal = context.runnerTerminal;
|
|
3157
|
+
const command = sandboxedCommand({ argv: request2.argv, repoRoot: runner.repoRoot, cwd: runner.cwd });
|
|
3158
|
+
const env = sandboxEnvironment({
|
|
3159
|
+
cwd: runner.cwd,
|
|
3160
|
+
loginPath: runner.loginPath,
|
|
3161
|
+
color: terminal.color,
|
|
3162
|
+
env: runner.env,
|
|
3163
|
+
...request2.unsafeSecretEnvVars === void 0 ? {} : { unsafeSecretEnvVars: request2.unsafeSecretEnvVars },
|
|
3164
|
+
runPayload: request2.runPayload
|
|
3165
|
+
});
|
|
3166
|
+
await progress.emit({ kind: "command-output-started", sandbox: runner.sandbox.name, region: runner.region });
|
|
3167
|
+
const startedAt = context.clock.now().getTime();
|
|
3168
|
+
const splitters = { stdout: lineSplitter(), stderr: lineSplitter() };
|
|
3169
|
+
const write = (stream, text) => {
|
|
3170
|
+
if (text === "") return;
|
|
3171
|
+
const local = rewritePaths(text, SANDBOX_ROOT, runner.repoRoot);
|
|
3172
|
+
if (stream === "stdout") terminal.writeStdout(local);
|
|
3173
|
+
else terminal.writeStderr(local);
|
|
3174
|
+
};
|
|
3175
|
+
const following = followTestEvents(context, runner, request2.testEvents, control.kill);
|
|
3176
|
+
const ran = await context.runnerSandboxes.runCommand(
|
|
3177
|
+
runner.sandbox,
|
|
3178
|
+
{ cmd: command.cmd, args: command.args, cwd: runner.cwd, env },
|
|
3179
|
+
({ stream, data }) => write(stream, splitters[stream].push(data)),
|
|
3180
|
+
control.kill
|
|
3181
|
+
);
|
|
3182
|
+
const ms = context.clock.now().getTime() - startedAt;
|
|
3183
|
+
write("stdout", splitters.stdout.flush());
|
|
3184
|
+
write("stderr", splitters.stderr.flush());
|
|
3185
|
+
await following?.end(ran.ok && !control.kill.aborted);
|
|
3186
|
+
if (!ran.ok) {
|
|
3187
|
+
if (ran.failure.kind !== "aborted")
|
|
3188
|
+
return { kind: "failed", failure: sandboxApiFailure("run-command", ran.failure) };
|
|
3189
|
+
await progress.emit({ kind: "command-stopped", command: posix2.basename(command.cmd) });
|
|
3190
|
+
return { kind: "killed" };
|
|
3191
|
+
}
|
|
3192
|
+
return { kind: "exited", exitCode: ran.value.exitCode, ms };
|
|
3193
|
+
}
|
|
3194
|
+
function followTestEvents(context, runner, testEvents, kill) {
|
|
3195
|
+
if (testEvents === void 0) return void 0;
|
|
3196
|
+
const stop = new AbortController();
|
|
3197
|
+
const splitter = lineSplitter();
|
|
3198
|
+
let handed = 0;
|
|
3199
|
+
const hand = (lines) => {
|
|
3200
|
+
for (const line of lines) {
|
|
3201
|
+
handed += 1;
|
|
3202
|
+
testEvents.onLine(line);
|
|
3203
|
+
}
|
|
3204
|
+
};
|
|
3205
|
+
const followed = context.runnerSandboxes.followTestEvents(
|
|
3206
|
+
runner.sandbox,
|
|
3207
|
+
{ path: SANDBOX_TEST_EVENTS_PATH },
|
|
3208
|
+
({ data }) => hand(splitLines(splitter.push(data))),
|
|
3209
|
+
stop.signal
|
|
3210
|
+
);
|
|
3211
|
+
return {
|
|
3212
|
+
async end(complete) {
|
|
3213
|
+
stop.abort();
|
|
3214
|
+
const stopped = await callWithin(context.timer, TEST_EVENTS_END_LIMIT_MS, () => followed);
|
|
3215
|
+
if (stopped === null) {
|
|
3216
|
+
hand(splitLines(splitter.flush()));
|
|
3217
|
+
if (complete) testEvents.onIncomplete(`following the test events file didn't stop within ${limitWords()}`);
|
|
3218
|
+
return;
|
|
3219
|
+
}
|
|
3220
|
+
if (!complete) {
|
|
3221
|
+
hand(splitLines(splitter.flush()));
|
|
3222
|
+
return;
|
|
3223
|
+
}
|
|
3224
|
+
const reader = lineSplitter();
|
|
3225
|
+
let read = false;
|
|
3226
|
+
const result = await callWithin(
|
|
3227
|
+
context.timer,
|
|
3228
|
+
TEST_EVENTS_END_LIMIT_MS,
|
|
3229
|
+
(signal) => context.runnerSandboxes.readTestEvents(
|
|
3230
|
+
runner.sandbox,
|
|
3231
|
+
{ path: SANDBOX_TEST_EVENTS_PATH, fromLine: handed + 1 },
|
|
3232
|
+
({ data }) => {
|
|
3233
|
+
if (!read) {
|
|
3234
|
+
splitter.flush();
|
|
3235
|
+
read = true;
|
|
3236
|
+
}
|
|
3237
|
+
hand(splitLines(reader.push(data)));
|
|
3238
|
+
},
|
|
3239
|
+
AbortSignal.any([kill, signal])
|
|
3240
|
+
)
|
|
3241
|
+
);
|
|
3242
|
+
hand(splitLines(read ? reader.flush() : splitter.flush()));
|
|
3243
|
+
if (result === null)
|
|
3244
|
+
testEvents.onIncomplete(`the final read of the test events file had no answer within ${limitWords()}`);
|
|
3245
|
+
else if (!result.ok && result.failure.kind === "api") testEvents.onIncomplete(result.failure.message);
|
|
3246
|
+
}
|
|
3247
|
+
};
|
|
3248
|
+
}
|
|
3249
|
+
function limitWords() {
|
|
3250
|
+
return `${TEST_EVENTS_END_LIMIT_MS / 1e3} seconds`;
|
|
2426
3251
|
}
|
|
2427
3252
|
|
|
2428
3253
|
// src/runner/session.ts
|
|
2429
3254
|
function openRunnerSession(context, request2, control, progress) {
|
|
2430
3255
|
const { signal, cleanup } = control;
|
|
2431
|
-
const
|
|
2432
|
-
const
|
|
3256
|
+
const unsafeSecretEnvVars = request2.unsafeSecretEnvVars ?? {};
|
|
3257
|
+
const hasUnsafeSecretEnvVars = Object.keys(unsafeSecretEnvVars).length > 0;
|
|
3258
|
+
if (hasUnsafeSecretEnvVars && request2.keepMs > 0)
|
|
3259
|
+
throw new Error("a runner session with unsafeSecretEnvVars can't keep its runner sandbox");
|
|
3260
|
+
let commandRunning = false;
|
|
3261
|
+
const scope = runnerSandboxScope(context, progress, {
|
|
3262
|
+
keepMs: request2.keepMs,
|
|
3263
|
+
basePolicy: runnerNetworkPolicy(request2.prepared.recipe),
|
|
3264
|
+
signal,
|
|
3265
|
+
commandRunning: () => commandRunning
|
|
3266
|
+
});
|
|
3267
|
+
let cleaning;
|
|
3268
|
+
const cleanUp = () => cleaning ??= (async () => {
|
|
3269
|
+
let runnerSandboxFenced = false;
|
|
3270
|
+
try {
|
|
3271
|
+
try {
|
|
3272
|
+
await cleanup.startCleanup();
|
|
3273
|
+
} finally {
|
|
3274
|
+
({ runnerSandboxFenced } = await scope.fence());
|
|
3275
|
+
}
|
|
3276
|
+
} finally {
|
|
3277
|
+
try {
|
|
3278
|
+
await cleanup.release({ runnerSandboxFenced });
|
|
3279
|
+
} finally {
|
|
3280
|
+
await scope.close();
|
|
3281
|
+
}
|
|
3282
|
+
}
|
|
3283
|
+
return { ...await scope.close(), target: request2.target };
|
|
3284
|
+
})();
|
|
2433
3285
|
let readying = false;
|
|
2434
3286
|
let readied;
|
|
2435
|
-
let commandRunning = false;
|
|
2436
|
-
const stop = () => {
|
|
2437
|
-
void progress.emit({ kind: "stopping", commandRunning, keepMs: request2.keepMs }).catch(() => void 0);
|
|
2438
|
-
void scope.close().catch(() => void 0);
|
|
2439
|
-
};
|
|
2440
|
-
if (signal.aborted) stop();
|
|
2441
|
-
else signal.addEventListener("abort", stop, { once: true });
|
|
2442
3287
|
return {
|
|
2443
3288
|
async ready(access, laneSignal) {
|
|
2444
3289
|
if (readying) throw new Error("the runner session readies its runner sandbox once");
|
|
2445
3290
|
readying = true;
|
|
2446
|
-
const { prepared, user,
|
|
2447
|
-
const
|
|
2448
|
-
|
|
2449
|
-
{ prepared, access, user, secrets },
|
|
2450
|
-
{ scope, signal: laneSignal },
|
|
2451
|
-
progress
|
|
2452
|
-
);
|
|
3291
|
+
const { prepared, user, credentials: credentials2, snapshot } = request2;
|
|
3292
|
+
const stage2 = { scope, signal: laneSignal };
|
|
3293
|
+
const outcome = snapshot === void 0 ? await readyRunner(context, { prepared, access, user, credentials: credentials2 }, stage2, progress) : await readyFromSnapshot(context, { prepared, access, user, credentials: credentials2, snapshot }, stage2, progress);
|
|
2453
3294
|
if (outcome.kind === "ready") readied = outcome.runner;
|
|
2454
3295
|
return outcome;
|
|
2455
3296
|
},
|
|
2456
3297
|
async runCommand(command) {
|
|
2457
3298
|
if (readied === void 0) throw new Error("the runner session's runner sandbox isn't ready");
|
|
3299
|
+
const runner = readied;
|
|
2458
3300
|
commandRunning = true;
|
|
2459
|
-
return await runCommandInSandbox(
|
|
2460
|
-
context,
|
|
2461
|
-
{
|
|
2462
|
-
runner: readied,
|
|
2463
|
-
argv: command.argv,
|
|
2464
|
-
runPayload: command.runPayload,
|
|
2465
|
-
...command.testEvents === void 0 ? {} : { testEvents: command.testEvents }
|
|
2466
|
-
},
|
|
2467
|
-
{ kill: signal },
|
|
2468
|
-
progress
|
|
2469
|
-
);
|
|
2470
|
-
},
|
|
2471
|
-
async finish() {
|
|
2472
|
-
commandRunning = false;
|
|
2473
|
-
await cleanup.startCleanup();
|
|
2474
|
-
const facts = await closeScope();
|
|
2475
|
-
signal.removeEventListener("abort", stop);
|
|
2476
|
-
await cleanup.release();
|
|
2477
|
-
return facts;
|
|
2478
|
-
},
|
|
2479
|
-
async close() {
|
|
2480
|
-
signal.removeEventListener("abort", stop);
|
|
2481
3301
|
try {
|
|
2482
|
-
|
|
3302
|
+
const run = () => runCommandInSandbox(
|
|
3303
|
+
context,
|
|
3304
|
+
{
|
|
3305
|
+
runner,
|
|
3306
|
+
argv: command.argv,
|
|
3307
|
+
runPayload: command.runPayload,
|
|
3308
|
+
...hasUnsafeSecretEnvVars ? { unsafeSecretEnvVars } : {},
|
|
3309
|
+
...command.testEvents === void 0 ? {} : { testEvents: command.testEvents }
|
|
3310
|
+
},
|
|
3311
|
+
{ kill: signal },
|
|
3312
|
+
progress
|
|
3313
|
+
);
|
|
3314
|
+
const resourceCredentials = command.credentials ?? [];
|
|
3315
|
+
const granted = request2.credentials.length > 0 || resourceCredentials.length > 0;
|
|
3316
|
+
try {
|
|
3317
|
+
if (resourceCredentials.length > 0) {
|
|
3318
|
+
const both = await scope.grantCredentials(
|
|
3319
|
+
runner.sandbox,
|
|
3320
|
+
[...request2.credentials, ...resourceCredentials],
|
|
3321
|
+
signal
|
|
3322
|
+
);
|
|
3323
|
+
if (!both.ok) {
|
|
3324
|
+
const stop = networkPolicyStop("inject", "command", both.failure);
|
|
3325
|
+
return stop.kind === "aborted" ? { kind: "killed" } : { kind: "failed", failure: stop.failure };
|
|
3326
|
+
}
|
|
3327
|
+
}
|
|
3328
|
+
return await run();
|
|
3329
|
+
} finally {
|
|
3330
|
+
if (granted) await scope.revokeCredentials(runner.sandbox);
|
|
3331
|
+
}
|
|
2483
3332
|
} finally {
|
|
2484
|
-
|
|
3333
|
+
commandRunning = false;
|
|
2485
3334
|
}
|
|
3335
|
+
},
|
|
3336
|
+
async cleanUp() {
|
|
3337
|
+
return await cleanUp();
|
|
2486
3338
|
}
|
|
2487
3339
|
};
|
|
2488
3340
|
}
|
|
2489
3341
|
|
|
2490
3342
|
// src/config/load.ts
|
|
2491
|
-
import { dirname, join as join2 } from "node:path";
|
|
3343
|
+
import { basename, dirname, join as join2 } from "node:path";
|
|
3344
|
+
|
|
3345
|
+
// src/config/check-runner.ts
|
|
3346
|
+
var FACTORY_HINT = "must be made by vercelSandbox({ \u2026 }) or launchMachine()";
|
|
3347
|
+
function checkRunner(value, inherited, definitions = []) {
|
|
3348
|
+
if (!isRecord2(value)) {
|
|
3349
|
+
return { ok: false, problems: [{ path: [], problem: `${FACTORY_HINT}, not ${describeValue(value)}` }] };
|
|
3350
|
+
}
|
|
3351
|
+
const kind2 = value["kind"];
|
|
3352
|
+
if (kind2 === "launch-machine") {
|
|
3353
|
+
const extraKeys = Object.keys(value).filter((key) => key !== "kind");
|
|
3354
|
+
if (extraKeys.length > 0) {
|
|
3355
|
+
return { ok: false, problems: [{ path: [], problem: `${FACTORY_HINT}, not an object` }] };
|
|
3356
|
+
}
|
|
3357
|
+
return { ok: true, value: { kind: "launch-machine" } };
|
|
3358
|
+
}
|
|
3359
|
+
if (kind2 === "vercel-sandbox") {
|
|
3360
|
+
const extraKeys = Object.keys(value).filter((key) => key !== "kind" && key !== "options");
|
|
3361
|
+
const options = value["options"];
|
|
3362
|
+
if (extraKeys.length > 0 || !isRecord2(options)) {
|
|
3363
|
+
return { ok: false, problems: [{ path: [], problem: `${FACTORY_HINT}, not an object` }] };
|
|
3364
|
+
}
|
|
3365
|
+
const rawOptions = inherited === void 0 ? options : {
|
|
3366
|
+
...inherited,
|
|
3367
|
+
...Object.fromEntries(Object.entries(options).filter(([, entry]) => entry !== void 0))
|
|
3368
|
+
};
|
|
3369
|
+
const checked = checkRecipe(rawOptions);
|
|
3370
|
+
if (!checked.ok) return checked;
|
|
3371
|
+
const vcpusProblems = checkVcpusRuleDefinitions(checked.value.vcpus, definitions);
|
|
3372
|
+
if (vcpusProblems.length > 0) return { ok: false, problems: vcpusProblems };
|
|
3373
|
+
return { ok: true, value: { kind: "vercel-sandbox", recipe: checked.value } };
|
|
3374
|
+
}
|
|
3375
|
+
return { ok: false, problems: [{ path: [], problem: `${FACTORY_HINT}, not ${describeValue(value)}` }] };
|
|
3376
|
+
}
|
|
3377
|
+
function checkVcpusRuleDefinitions(vcpus, definitions) {
|
|
3378
|
+
if (typeof vcpus === "number") return [];
|
|
3379
|
+
const definition = definitions.find((each) => each.name === vcpus.resource);
|
|
3380
|
+
if (definition === void 0) {
|
|
3381
|
+
const known = definitions.length === 0 ? "none" : definitions.map((each) => each.name).join(", ");
|
|
3382
|
+
return [{ path: ["vcpus", "resource"], problem: `is not a resource; storm has ${known}` }];
|
|
3383
|
+
}
|
|
3384
|
+
if (!Object.hasOwn(definition.options, vcpus.option)) {
|
|
3385
|
+
const optionNames = Object.keys(definition.options);
|
|
3386
|
+
const available = optionNames.length === 0 ? "none" : optionNames.join(", ");
|
|
3387
|
+
return [
|
|
3388
|
+
{
|
|
3389
|
+
path: ["vcpus", "option"],
|
|
3390
|
+
problem: `is not a ${definition.name} option; ${definition.name} has ${available}`
|
|
3391
|
+
}
|
|
3392
|
+
];
|
|
3393
|
+
}
|
|
3394
|
+
return [];
|
|
3395
|
+
}
|
|
3396
|
+
function rawVercelSandboxOptions(value) {
|
|
3397
|
+
if (!isRecord2(value) || value["kind"] !== "vercel-sandbox") return void 0;
|
|
3398
|
+
const options = value["options"];
|
|
3399
|
+
return isRecord2(options) ? options : void 0;
|
|
3400
|
+
}
|
|
3401
|
+
function isRecord2(value) {
|
|
3402
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3403
|
+
}
|
|
2492
3404
|
|
|
2493
3405
|
// src/config/schema.ts
|
|
2494
3406
|
var CONFIG_FILE_NAME = "storm.config.ts";
|
|
3407
|
+
var CONFIG_FILE_NAMES = [CONFIG_FILE_NAME, "storm.config.mts"];
|
|
3408
|
+
var CONFIG_FILE_NAMES_TEXT = CONFIG_FILE_NAMES.join(" or ");
|
|
2495
3409
|
function checkWith(schema, value) {
|
|
2496
3410
|
const parsed = schema.safeParse(value);
|
|
2497
3411
|
if (parsed.success) return { ok: true, value: parsed.data };
|
|
@@ -2500,87 +3414,47 @@ function checkWith(schema, value) {
|
|
|
2500
3414
|
problems: parsed.error.issues.map(({ path, message }) => ({ path: path.map(String), problem: message }))
|
|
2501
3415
|
};
|
|
2502
3416
|
}
|
|
3417
|
+
function checkStringList(value) {
|
|
3418
|
+
if (!Array.isArray(value)) {
|
|
3419
|
+
return { ok: false, problems: [{ path: [], problem: `must be a list of strings, not ${describeValue(value)}` }] };
|
|
3420
|
+
}
|
|
3421
|
+
const problems = [];
|
|
3422
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
3423
|
+
if (typeof value[index] !== "string") {
|
|
3424
|
+
problems.push({ path: [String(index)], problem: `must be a string, not ${describeValue(value[index])}` });
|
|
3425
|
+
}
|
|
3426
|
+
}
|
|
3427
|
+
return problems.length === 0 ? { ok: true, value: [...value] } : { ok: false, problems };
|
|
3428
|
+
}
|
|
3429
|
+
function checkDriver(value, drivers) {
|
|
3430
|
+
const checked = checkWith(nonEmptyString, value);
|
|
3431
|
+
if (!checked.ok) return checked;
|
|
3432
|
+
if (!drivers.includes(checked.value)) {
|
|
3433
|
+
const available = drivers.length === 0 ? "none" : drivers.join(", ");
|
|
3434
|
+
return { ok: false, problems: [{ path: [], problem: `is not a driver; storm has ${available}` }] };
|
|
3435
|
+
}
|
|
3436
|
+
return checked;
|
|
3437
|
+
}
|
|
2503
3438
|
var SETTING_CHECKS = {
|
|
2504
3439
|
scope: (value) => checkWith(nonEmptyString, value),
|
|
2505
3440
|
project: (value) => checkWith(nonEmptyString, value),
|
|
2506
|
-
|
|
3441
|
+
driver: (value, { drivers }) => checkDriver(value, drivers),
|
|
3442
|
+
args: checkStringList,
|
|
3443
|
+
runner: (value, { topLevelRunnerOptions, definitions }) => checkRunner(value, topLevelRunnerOptions, definitions),
|
|
2507
3444
|
testPlan: (value) => checkWith(booleanOption, value)
|
|
2508
3445
|
};
|
|
2509
3446
|
function isConfigSettingKey(key) {
|
|
2510
3447
|
return Object.hasOwn(SETTING_CHECKS, key);
|
|
2511
3448
|
}
|
|
2512
|
-
function checkSettingValue(key, value) {
|
|
2513
|
-
return SETTING_CHECKS[key](value);
|
|
3449
|
+
function checkSettingValue(key, value, context) {
|
|
3450
|
+
return SETTING_CHECKS[key](value, context);
|
|
2514
3451
|
}
|
|
2515
3452
|
|
|
2516
|
-
// src/config/
|
|
2517
|
-
|
|
2518
|
-
if (await gateway.hasConfigFile(startDirectory)) return join2(startDirectory, CONFIG_FILE_NAME);
|
|
2519
|
-
const root = await worktreeRoot(gateway, startDirectory);
|
|
2520
|
-
if (root === void 0) return void 0;
|
|
2521
|
-
for (let directory = startDirectory; directory !== root; ) {
|
|
2522
|
-
directory = dirname(directory);
|
|
2523
|
-
if (await gateway.hasConfigFile(directory)) return join2(directory, CONFIG_FILE_NAME);
|
|
2524
|
-
}
|
|
2525
|
-
return void 0;
|
|
2526
|
-
}
|
|
2527
|
-
async function worktreeRoot(gateway, directory) {
|
|
2528
|
-
for (let current = directory; ; current = dirname(current)) {
|
|
2529
|
-
if (await gateway.isWorktreeRoot(current)) return current;
|
|
2530
|
-
if (dirname(current) === current) return void 0;
|
|
2531
|
-
}
|
|
2532
|
-
}
|
|
2533
|
-
async function loadConfig(gateway, startDirectory, definitions) {
|
|
2534
|
-
const path = await findConfigFile(gateway, startDirectory);
|
|
2535
|
-
if (path === void 0) return { kind: "none" };
|
|
2536
|
-
const imported = await gateway.importConfig(path);
|
|
2537
|
-
switch (imported.kind) {
|
|
2538
|
-
case "import-failed":
|
|
2539
|
-
return {
|
|
2540
|
-
kind: "invalid",
|
|
2541
|
-
path,
|
|
2542
|
-
problems: [{ key: null, location: imported.location ?? null, problem: imported.message }]
|
|
2543
|
-
};
|
|
2544
|
-
case "no-default-export":
|
|
2545
|
-
return {
|
|
2546
|
-
kind: "invalid",
|
|
2547
|
-
path,
|
|
2548
|
-
problems: [fileProblem("has no default export; export default defineConfig({ \u2026 })")]
|
|
2549
|
-
};
|
|
2550
|
-
case "default-export":
|
|
2551
|
-
return checkFile(path, imported.value, definitions);
|
|
2552
|
-
}
|
|
2553
|
-
}
|
|
2554
|
-
function checkFile(path, value, definitions) {
|
|
2555
|
-
if (!isRecord2(value))
|
|
2556
|
-
return {
|
|
2557
|
-
kind: "invalid",
|
|
2558
|
-
path,
|
|
2559
|
-
problems: [fileProblem(`must default-export an object, not ${describeValue(value)}`)]
|
|
2560
|
-
};
|
|
2561
|
-
const settings = {};
|
|
2562
|
-
const problems = [];
|
|
2563
|
-
let resources = {};
|
|
2564
|
-
for (const [key, keyValue] of Object.entries(value)) {
|
|
2565
|
-
if (key === "resources") resources = checkResources(keyValue, definitions, problems);
|
|
2566
|
-
else if (isConfigSettingKey(key)) {
|
|
2567
|
-
if (keyValue !== void 0) checkSetting(key, keyValue, settings, problems);
|
|
2568
|
-
} else problems.push({ key, location: null, problem: `is not a ${CONFIG_FILE_NAME} key` });
|
|
2569
|
-
}
|
|
2570
|
-
if (problems.length > 0) return { kind: "invalid", path, problems };
|
|
2571
|
-
return { kind: "loaded", path, values: { settings, resources } };
|
|
2572
|
-
}
|
|
2573
|
-
function checkSetting(key, value, settings, problems) {
|
|
2574
|
-
const checked = checkSettingValue(key, value);
|
|
2575
|
-
if (checked.ok) Object.assign(settings, { [key]: checked.value });
|
|
2576
|
-
else
|
|
2577
|
-
for (const { path: inside, problem } of checked.problems)
|
|
2578
|
-
problems.push({ key: [key, ...inside].join("."), location: null, problem });
|
|
2579
|
-
}
|
|
2580
|
-
function checkResources(value, definitions, problems) {
|
|
3453
|
+
// src/config/check-resources.ts
|
|
3454
|
+
function checkResources(value, definitions, problems, at) {
|
|
2581
3455
|
if (value === void 0) return {};
|
|
2582
|
-
if (!
|
|
2583
|
-
problems.push({ key:
|
|
3456
|
+
if (!isRecord3(value)) {
|
|
3457
|
+
problems.push({ key: at, location: null, problem: `must be an object, not ${describeValue(value)}` });
|
|
2584
3458
|
return {};
|
|
2585
3459
|
}
|
|
2586
3460
|
const byName = new Map(definitions.map((definition) => [definition.name, definition]));
|
|
@@ -2591,7 +3465,7 @@ function checkResources(value, definitions, problems) {
|
|
|
2591
3465
|
const definition = byName.get(named !== void 0 && byName.has(named) ? named : key);
|
|
2592
3466
|
if (named !== void 0 && definition !== void 0 && key !== defaultResourceKey(definition)) {
|
|
2593
3467
|
problems.push({
|
|
2594
|
-
key:
|
|
3468
|
+
key: `${at}.${key}`,
|
|
2595
3469
|
location: null,
|
|
2596
3470
|
problem: `holds a ${named} resource; for now a resource's key must be its definition's name: name its key ${defaultResourceKey(definition)}`
|
|
2597
3471
|
});
|
|
@@ -2599,27 +3473,27 @@ function checkResources(value, definitions, problems) {
|
|
|
2599
3473
|
}
|
|
2600
3474
|
if (definition === void 0) {
|
|
2601
3475
|
problems.push({
|
|
2602
|
-
key:
|
|
3476
|
+
key: `${at}.${key}`,
|
|
2603
3477
|
location: null,
|
|
2604
3478
|
problem: `is not a resource; resources holds ${holds}`
|
|
2605
3479
|
});
|
|
2606
3480
|
continue;
|
|
2607
3481
|
}
|
|
2608
3482
|
if (resource === void 0) continue;
|
|
2609
|
-
const options = checkResource(definition, key
|
|
3483
|
+
const options = checkResource(definition, `${at}.${key}`, resource, problems);
|
|
2610
3484
|
if (options !== void 0) found[key] = { definition: definition.name, options };
|
|
2611
3485
|
}
|
|
2612
3486
|
return found;
|
|
2613
3487
|
}
|
|
2614
3488
|
function entryName(value) {
|
|
2615
|
-
return
|
|
3489
|
+
return isRecord3(value) && typeof value["name"] === "string" ? value["name"] : void 0;
|
|
2616
3490
|
}
|
|
2617
|
-
function checkResource(definition,
|
|
3491
|
+
function checkResource(definition, at, value, problems) {
|
|
2618
3492
|
const { name } = definition;
|
|
2619
|
-
const options =
|
|
2620
|
-
if (!
|
|
3493
|
+
const options = isRecord3(value) && value["name"] === name ? value["options"] : void 0;
|
|
3494
|
+
if (!isRecord3(options)) {
|
|
2621
3495
|
problems.push({
|
|
2622
|
-
key:
|
|
3496
|
+
key: at,
|
|
2623
3497
|
location: null,
|
|
2624
3498
|
problem: `must be made by ${resourceCall(name)}, not ${describeValue(value)}`
|
|
2625
3499
|
});
|
|
@@ -2628,7 +3502,7 @@ function checkResource(definition, key, value, problems) {
|
|
|
2628
3502
|
const checked = {};
|
|
2629
3503
|
let valid = true;
|
|
2630
3504
|
for (const [option, optionValue] of Object.entries(options)) {
|
|
2631
|
-
const path =
|
|
3505
|
+
const path = `${at}.${option}`;
|
|
2632
3506
|
const rule = Object.hasOwn(definition.options, option) ? definition.options[option] : void 0;
|
|
2633
3507
|
if (rule === void 0) {
|
|
2634
3508
|
valid = false;
|
|
@@ -2646,7 +3520,276 @@ function checkResource(definition, key, value, problems) {
|
|
|
2646
3520
|
}
|
|
2647
3521
|
return valid ? checked : void 0;
|
|
2648
3522
|
}
|
|
2649
|
-
function
|
|
3523
|
+
function isRecord3(value) {
|
|
3524
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3525
|
+
}
|
|
3526
|
+
|
|
3527
|
+
// src/config/suite.ts
|
|
3528
|
+
var SUITE_NAME_PATTERN = /^[a-z0-9][a-z0-9-]*$/u;
|
|
3529
|
+
|
|
3530
|
+
// src/config/check-suites.ts
|
|
3531
|
+
var SUITE_KEYS = /* @__PURE__ */ new Set(["driver", "args", "runner", "resources"]);
|
|
3532
|
+
function checkSuites(value, options, problems) {
|
|
3533
|
+
if (value === void 0) return {};
|
|
3534
|
+
if (!isRecord4(value)) {
|
|
3535
|
+
problems.push({ key: "suites", location: null, problem: `must be an object, not ${describeValue(value)}` });
|
|
3536
|
+
return {};
|
|
3537
|
+
}
|
|
3538
|
+
const settingContext = {
|
|
3539
|
+
definitions: options.definitions,
|
|
3540
|
+
drivers: options.drivers,
|
|
3541
|
+
topLevelRunnerOptions: options.topLevelRunnerOptions
|
|
3542
|
+
};
|
|
3543
|
+
const checked = {};
|
|
3544
|
+
for (const [name, raw] of Object.entries(value)) {
|
|
3545
|
+
const at = `suites.${name}`;
|
|
3546
|
+
if (!SUITE_NAME_PATTERN.test(name)) {
|
|
3547
|
+
problems.push({
|
|
3548
|
+
key: at,
|
|
3549
|
+
location: null,
|
|
3550
|
+
problem: "must hold only lowercase letters, digits, and hyphens, starting with a letter or a digit"
|
|
3551
|
+
});
|
|
3552
|
+
}
|
|
3553
|
+
if (!isRecord4(raw)) {
|
|
3554
|
+
problems.push({ key: at, location: null, problem: `must be an object, not ${describeValue(raw)}` });
|
|
3555
|
+
continue;
|
|
3556
|
+
}
|
|
3557
|
+
let driver;
|
|
3558
|
+
let hasOwnDriverKey = false;
|
|
3559
|
+
let args;
|
|
3560
|
+
let runner;
|
|
3561
|
+
let resources = {};
|
|
3562
|
+
for (const [key, keyValue] of Object.entries(raw)) {
|
|
3563
|
+
if (!SUITE_KEYS.has(key)) {
|
|
3564
|
+
problems.push({ key: `${at}.${key}`, location: null, problem: "is not a suite key" });
|
|
3565
|
+
continue;
|
|
3566
|
+
}
|
|
3567
|
+
if (keyValue === void 0) continue;
|
|
3568
|
+
if (key === "driver") {
|
|
3569
|
+
hasOwnDriverKey = true;
|
|
3570
|
+
const result = checkSettingValue("driver", keyValue, settingContext);
|
|
3571
|
+
if (result.ok) driver = result.value;
|
|
3572
|
+
else
|
|
3573
|
+
for (const { path: inside, problem } of result.problems)
|
|
3574
|
+
problems.push({ key: [`${at}.driver`, ...inside].join("."), location: null, problem });
|
|
3575
|
+
} else if (key === "args") {
|
|
3576
|
+
const result = checkSettingValue("args", keyValue, settingContext);
|
|
3577
|
+
if (result.ok) args = result.value;
|
|
3578
|
+
else
|
|
3579
|
+
for (const { path: inside, problem } of result.problems)
|
|
3580
|
+
problems.push({ key: [`${at}.args`, ...inside].join("."), location: null, problem });
|
|
3581
|
+
} else if (key === "runner") {
|
|
3582
|
+
const result = checkSettingValue("runner", keyValue, settingContext);
|
|
3583
|
+
if (result.ok) runner = result.value;
|
|
3584
|
+
else
|
|
3585
|
+
for (const { path: inside, problem } of result.problems)
|
|
3586
|
+
problems.push({ key: [`${at}.runner`, ...inside].join("."), location: null, problem });
|
|
3587
|
+
} else if (key === "resources") {
|
|
3588
|
+
resources = checkResources(keyValue, options.definitions, problems, `${at}.resources`);
|
|
3589
|
+
}
|
|
3590
|
+
}
|
|
3591
|
+
if (!hasOwnDriverKey && !options.hasTopLevelDriver) {
|
|
3592
|
+
problems.push({
|
|
3593
|
+
key: `${at}.driver`,
|
|
3594
|
+
location: null,
|
|
3595
|
+
problem: "must name a driver when the top level names none"
|
|
3596
|
+
});
|
|
3597
|
+
}
|
|
3598
|
+
checked[name] = {
|
|
3599
|
+
...driver === void 0 ? {} : { driver },
|
|
3600
|
+
...args === void 0 ? {} : { args },
|
|
3601
|
+
...runner === void 0 ? {} : { runner },
|
|
3602
|
+
resources
|
|
3603
|
+
};
|
|
3604
|
+
}
|
|
3605
|
+
return checked;
|
|
3606
|
+
}
|
|
3607
|
+
function isRecord4(value) {
|
|
3608
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3609
|
+
}
|
|
3610
|
+
|
|
3611
|
+
// src/config/load.ts
|
|
3612
|
+
async function findConfigFile(gateway, startDirectory) {
|
|
3613
|
+
const here = await lookIn(gateway, startDirectory);
|
|
3614
|
+
if (here !== void 0) return here;
|
|
3615
|
+
const root = await worktreeRoot(gateway, startDirectory);
|
|
3616
|
+
if (root === void 0) return { kind: "none" };
|
|
3617
|
+
for (let directory = startDirectory; directory !== root; ) {
|
|
3618
|
+
directory = dirname(directory);
|
|
3619
|
+
const found = await lookIn(gateway, directory);
|
|
3620
|
+
if (found !== void 0) return found;
|
|
3621
|
+
}
|
|
3622
|
+
return { kind: "none" };
|
|
3623
|
+
}
|
|
3624
|
+
async function lookIn(gateway, directory) {
|
|
3625
|
+
const [first, second, ...rest] = (await gateway.configFileNames(directory)).map((name) => join2(directory, name));
|
|
3626
|
+
if (first === void 0) return void 0;
|
|
3627
|
+
if (second === void 0) return { kind: "found", path: first };
|
|
3628
|
+
return { kind: "conflict", paths: [first, second, ...rest] };
|
|
3629
|
+
}
|
|
3630
|
+
async function worktreeRoot(gateway, directory) {
|
|
3631
|
+
for (let current = directory; ; current = dirname(current)) {
|
|
3632
|
+
if (await gateway.isWorktreeRoot(current)) return current;
|
|
3633
|
+
if (dirname(current) === current) return void 0;
|
|
3634
|
+
}
|
|
3635
|
+
}
|
|
3636
|
+
async function loadConfig(gateway, startDirectory, definitions, drivers) {
|
|
3637
|
+
const found = await findConfigFile(gateway, startDirectory);
|
|
3638
|
+
if (found.kind === "none") return { kind: "none" };
|
|
3639
|
+
if (found.kind === "conflict") {
|
|
3640
|
+
const [path2, ...others] = found.paths;
|
|
3641
|
+
const names = others.map((other) => basename(other)).join(" and ");
|
|
3642
|
+
return {
|
|
3643
|
+
kind: "invalid",
|
|
3644
|
+
path: path2,
|
|
3645
|
+
problems: [
|
|
3646
|
+
fileProblem(
|
|
3647
|
+
`is in the same directory as ${names}, so storm can't tell which config file applies; keep one of them`
|
|
3648
|
+
)
|
|
3649
|
+
]
|
|
3650
|
+
};
|
|
3651
|
+
}
|
|
3652
|
+
const { path } = found;
|
|
3653
|
+
const imported = await gateway.importConfig(path);
|
|
3654
|
+
switch (imported.kind) {
|
|
3655
|
+
case "import-failed":
|
|
3656
|
+
return {
|
|
3657
|
+
kind: "invalid",
|
|
3658
|
+
path,
|
|
3659
|
+
problems: [{ key: null, location: imported.location ?? null, problem: imported.message }]
|
|
3660
|
+
};
|
|
3661
|
+
case "no-default-export":
|
|
3662
|
+
return {
|
|
3663
|
+
kind: "invalid",
|
|
3664
|
+
path,
|
|
3665
|
+
problems: [fileProblem("has no default export; export default defineConfig({ \u2026 })")]
|
|
3666
|
+
};
|
|
3667
|
+
case "default-export":
|
|
3668
|
+
return checkFile(path, imported.value, definitions, drivers);
|
|
3669
|
+
}
|
|
3670
|
+
}
|
|
3671
|
+
function checkFile(path, value, definitions, drivers) {
|
|
3672
|
+
if (!isRecord5(value))
|
|
3673
|
+
return {
|
|
3674
|
+
kind: "invalid",
|
|
3675
|
+
path,
|
|
3676
|
+
problems: [fileProblem(`must default-export an object, not ${describeValue(value)}`)]
|
|
3677
|
+
};
|
|
3678
|
+
const settings = {};
|
|
3679
|
+
const problems = [];
|
|
3680
|
+
let resources = {};
|
|
3681
|
+
let rawSuites;
|
|
3682
|
+
let hasSuitesKey = false;
|
|
3683
|
+
const settingContext = { definitions, drivers };
|
|
3684
|
+
const hasTopLevelDriver = value["driver"] !== void 0;
|
|
3685
|
+
for (const [key, keyValue] of Object.entries(value)) {
|
|
3686
|
+
if (key === "resources") resources = checkResources(keyValue, definitions, problems, "resources");
|
|
3687
|
+
else if (key === "suites") {
|
|
3688
|
+
hasSuitesKey = true;
|
|
3689
|
+
rawSuites = keyValue;
|
|
3690
|
+
} else if (isConfigSettingKey(key)) {
|
|
3691
|
+
if (keyValue !== void 0) checkSetting(key, keyValue, settings, settingContext, problems);
|
|
3692
|
+
} else problems.push({ key, location: null, problem: `is not a ${basename(path)} key` });
|
|
3693
|
+
}
|
|
3694
|
+
if (settings.args !== void 0 && !hasTopLevelDriver) {
|
|
3695
|
+
problems.push({ key: "args", location: null, problem: "requires a top-level driver" });
|
|
3696
|
+
}
|
|
3697
|
+
const suites = hasSuitesKey ? checkSuites(
|
|
3698
|
+
rawSuites,
|
|
3699
|
+
{
|
|
3700
|
+
definitions,
|
|
3701
|
+
drivers,
|
|
3702
|
+
hasTopLevelDriver,
|
|
3703
|
+
topLevelRunnerOptions: rawVercelSandboxOptions(value["runner"])
|
|
3704
|
+
},
|
|
3705
|
+
problems
|
|
3706
|
+
) : {};
|
|
3707
|
+
checkPlainData(value, problems);
|
|
3708
|
+
if (problems.length > 0) return { kind: "invalid", path, problems };
|
|
3709
|
+
return { kind: "loaded", path, values: { settings, resources, suites } };
|
|
3710
|
+
}
|
|
3711
|
+
function checkPlainData(root, problems) {
|
|
3712
|
+
const reported = new Set(problems.map(({ key }) => key).filter((key) => key !== null));
|
|
3713
|
+
const visiting = /* @__PURE__ */ new Set();
|
|
3714
|
+
const addProblem = (path, problem) => {
|
|
3715
|
+
const key = path.join(".");
|
|
3716
|
+
if (reported.has(key)) return;
|
|
3717
|
+
reported.add(key);
|
|
3718
|
+
problems.push({ key: key.length === 0 ? null : key, location: null, problem });
|
|
3719
|
+
};
|
|
3720
|
+
const visit = (current, path) => {
|
|
3721
|
+
if (current === null || typeof current === "string" || typeof current === "boolean") return;
|
|
3722
|
+
if (current === void 0) {
|
|
3723
|
+
addProblem(path, "must be plain data (JSON cannot hold undefined in an array)");
|
|
3724
|
+
return;
|
|
3725
|
+
}
|
|
3726
|
+
if (typeof current === "number") {
|
|
3727
|
+
if (!Number.isFinite(current)) addProblem(path, `must be plain data (JSON cannot hold ${String(current)})`);
|
|
3728
|
+
return;
|
|
3729
|
+
}
|
|
3730
|
+
if (typeof current === "function") {
|
|
3731
|
+
addProblem(path, "must be plain data (JSON cannot hold a function)");
|
|
3732
|
+
return;
|
|
3733
|
+
}
|
|
3734
|
+
if (typeof current === "symbol") {
|
|
3735
|
+
addProblem(path, "must be plain data (JSON cannot hold a symbol)");
|
|
3736
|
+
return;
|
|
3737
|
+
}
|
|
3738
|
+
if (typeof current === "bigint") {
|
|
3739
|
+
addProblem(path, "must be plain data (JSON cannot hold a bigint)");
|
|
3740
|
+
return;
|
|
3741
|
+
}
|
|
3742
|
+
if (typeof current !== "object") return;
|
|
3743
|
+
if (visiting.has(current)) {
|
|
3744
|
+
addProblem(path, "must be plain data (circular reference)");
|
|
3745
|
+
return;
|
|
3746
|
+
}
|
|
3747
|
+
if (Array.isArray(current)) {
|
|
3748
|
+
visiting.add(current);
|
|
3749
|
+
for (let index = 0; index < current.length; index += 1) visit(current[index], [...path, String(index)]);
|
|
3750
|
+
visiting.delete(current);
|
|
3751
|
+
return;
|
|
3752
|
+
}
|
|
3753
|
+
const proto = Object.getPrototypeOf(current);
|
|
3754
|
+
if (proto !== Object.prototype && proto !== null) {
|
|
3755
|
+
addProblem(path, `must be plain data (expected a plain object, not ${describeNonPlainObject(proto)})`);
|
|
3756
|
+
return;
|
|
3757
|
+
}
|
|
3758
|
+
visiting.add(current);
|
|
3759
|
+
const isRunnerWrapper = path.length === 1 && path[0] === "runner" || path.length === 3 && path[0] === "suites" && path[2] === "runner";
|
|
3760
|
+
const unwrapRunnerOptions = isRunnerWrapper && current["kind"] === "vercel-sandbox";
|
|
3761
|
+
const isResourceWrapper = path.length === 2 && path[0] === "resources" || path.length === 4 && path[0] === "suites" && path[2] === "resources";
|
|
3762
|
+
const unwrapResourceOptions = isResourceWrapper && typeof current["name"] === "string";
|
|
3763
|
+
for (const [key, entry] of Object.entries(current)) {
|
|
3764
|
+
if (entry === void 0) continue;
|
|
3765
|
+
if ((unwrapRunnerOptions || unwrapResourceOptions) && key === "options" && isPlainObject2(entry)) {
|
|
3766
|
+
visit(entry, path);
|
|
3767
|
+
continue;
|
|
3768
|
+
}
|
|
3769
|
+
visit(entry, [...path, key]);
|
|
3770
|
+
}
|
|
3771
|
+
visiting.delete(current);
|
|
3772
|
+
};
|
|
3773
|
+
visit(root, []);
|
|
3774
|
+
}
|
|
3775
|
+
function isPlainObject2(value) {
|
|
3776
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
3777
|
+
const proto = Object.getPrototypeOf(value);
|
|
3778
|
+
return proto === Object.prototype || proto === null;
|
|
3779
|
+
}
|
|
3780
|
+
function describeNonPlainObject(proto) {
|
|
3781
|
+
const ctor = typeof proto === "object" && proto !== null ? proto.constructor : void 0;
|
|
3782
|
+
if (typeof ctor === "function" && ctor.name.length > 0 && ctor.name !== "Object") return ctor.name;
|
|
3783
|
+
return "a non-plain object";
|
|
3784
|
+
}
|
|
3785
|
+
function checkSetting(key, value, settings, context, problems) {
|
|
3786
|
+
const checked = checkSettingValue(key, value, context);
|
|
3787
|
+
if (checked.ok) Object.assign(settings, { [key]: checked.value });
|
|
3788
|
+
else
|
|
3789
|
+
for (const { path: inside, problem } of checked.problems)
|
|
3790
|
+
problems.push({ key: [key, ...inside].join("."), location: null, problem });
|
|
3791
|
+
}
|
|
3792
|
+
function isRecord5(value) {
|
|
2650
3793
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2651
3794
|
}
|
|
2652
3795
|
function fileProblem(problem) {
|
|
@@ -2750,9 +3893,6 @@ function givenOptionsOf(_definition, values) {
|
|
|
2750
3893
|
function settingsOf(_definition, settings) {
|
|
2751
3894
|
return settings;
|
|
2752
3895
|
}
|
|
2753
|
-
function resourceOptionsOf(_definition, value) {
|
|
2754
|
-
return value;
|
|
2755
|
-
}
|
|
2756
3896
|
|
|
2757
3897
|
// src/config/resolve.ts
|
|
2758
3898
|
function resolveSettings(flags, file) {
|
|
@@ -2760,6 +3900,8 @@ function resolveSettings(flags, file) {
|
|
|
2760
3900
|
return {
|
|
2761
3901
|
scope: pick(flags.scope, file?.scope),
|
|
2762
3902
|
project: pick(flags.project, file?.project),
|
|
3903
|
+
driver: pick(void 0, file?.driver),
|
|
3904
|
+
args: pick(void 0, file?.args),
|
|
2763
3905
|
runner: pick(void 0, file?.runner),
|
|
2764
3906
|
testPlan: pick(void 0, file?.testPlan)
|
|
2765
3907
|
};
|
|
@@ -2844,7 +3986,7 @@ function planResources(resources, run) {
|
|
|
2844
3986
|
const merged = settingsFor(run);
|
|
2845
3987
|
const settings = merged;
|
|
2846
3988
|
planned.push(...plannedOptions(definition, key, settings));
|
|
2847
|
-
const refused2 = definition.check(merged);
|
|
3989
|
+
const refused2 = definition.check(merged, run);
|
|
2848
3990
|
if (refused2.length === 0)
|
|
2849
3991
|
resolved[key] = {
|
|
2850
3992
|
definition: definition.name,
|
|
@@ -2897,11 +4039,37 @@ function plannedOptions(definition, key, settings) {
|
|
|
2897
4039
|
}
|
|
2898
4040
|
|
|
2899
4041
|
// src/config/settings-file.ts
|
|
2900
|
-
async function loadSettingsFile(gateway, cwd, definitions) {
|
|
2901
|
-
const loaded = await loadConfig(gateway, cwd, definitions);
|
|
4042
|
+
async function loadSettingsFile(gateway, cwd, definitions, drivers) {
|
|
4043
|
+
const loaded = await loadConfig(gateway, cwd, definitions, drivers);
|
|
2902
4044
|
if (loaded.kind === "invalid") return refused(invalidConfig(loaded.path, loaded.problems));
|
|
2903
4045
|
return loaded.kind === "loaded" ? { ok: true, path: loaded.path, values: loaded.values, definitions } : { ok: true, path: null, values: void 0, definitions };
|
|
2904
4046
|
}
|
|
4047
|
+
function effectiveConfig(file, suite) {
|
|
4048
|
+
if (suite === null || file.values === void 0 || !Object.hasOwn(file.values.suites, suite)) return file;
|
|
4049
|
+
const suiteConfig = file.values.suites[suite];
|
|
4050
|
+
if (suiteConfig === void 0) return file;
|
|
4051
|
+
const resourceEntries = Object.entries(suiteConfig.resources);
|
|
4052
|
+
if (suiteConfig.runner === void 0 && resourceEntries.length === 0) return file;
|
|
4053
|
+
const baseResources = file.values.resources;
|
|
4054
|
+
let resources = baseResources;
|
|
4055
|
+
if (resourceEntries.length > 0) {
|
|
4056
|
+
const merged = { ...baseResources };
|
|
4057
|
+
for (const [key, suiteResource] of resourceEntries) {
|
|
4058
|
+
const top = baseResources[key];
|
|
4059
|
+
merged[key] = top !== void 0 && top.definition === suiteResource.definition ? { definition: suiteResource.definition, options: { ...top.options, ...suiteResource.options } } : { definition: suiteResource.definition, options: { ...suiteResource.options } };
|
|
4060
|
+
}
|
|
4061
|
+
resources = merged;
|
|
4062
|
+
}
|
|
4063
|
+
const settings = suiteConfig.runner === void 0 ? file.values.settings : { ...file.values.settings, runner: suiteConfig.runner };
|
|
4064
|
+
return {
|
|
4065
|
+
...file,
|
|
4066
|
+
values: {
|
|
4067
|
+
settings,
|
|
4068
|
+
suites: file.values.suites,
|
|
4069
|
+
resources
|
|
4070
|
+
}
|
|
4071
|
+
};
|
|
4072
|
+
}
|
|
2905
4073
|
function fileSettings(file, flags) {
|
|
2906
4074
|
return resolveSettings(flags, file.values?.settings);
|
|
2907
4075
|
}
|
|
@@ -3016,10 +4184,10 @@ async function request(env, timeoutMs) {
|
|
|
3016
4184
|
return classifyTokenResponse({ status: response.status, body: await response.text() }, token);
|
|
3017
4185
|
} catch (error) {
|
|
3018
4186
|
if (signal.aborted) return { ok: false, failure: { kind: "timeout", seconds } };
|
|
3019
|
-
return { ok: false, failure: { kind: "unreachable", said: said(
|
|
4187
|
+
return { ok: false, failure: { kind: "unreachable", said: said(errorMessage(error), token) } };
|
|
3020
4188
|
}
|
|
3021
4189
|
}
|
|
3022
|
-
function
|
|
4190
|
+
function errorMessage(error) {
|
|
3023
4191
|
if (!(error instanceof Error)) return String(error);
|
|
3024
4192
|
const cause = error.cause;
|
|
3025
4193
|
return cause instanceof Error && cause.message !== "" ? `${error.message}: ${cause.message}` : error.message;
|
|
@@ -3127,7 +4295,7 @@ function runVercel(args) {
|
|
|
3127
4295
|
args,
|
|
3128
4296
|
{
|
|
3129
4297
|
cwd: tmpdir(),
|
|
3130
|
-
env:
|
|
4298
|
+
env: vercelEnvironment(process.env),
|
|
3131
4299
|
timeout: VERCEL_TIMEOUT_MS,
|
|
3132
4300
|
maxBuffer: 16 * 1024 * 1024,
|
|
3133
4301
|
encoding: "utf8"
|
|
@@ -3141,6 +4309,11 @@ function runVercel(args) {
|
|
|
3141
4309
|
}
|
|
3142
4310
|
});
|
|
3143
4311
|
}
|
|
4312
|
+
function vercelEnvironment(host) {
|
|
4313
|
+
const env = { ...host, NO_COLOR: "1", NO_UPDATE_NOTIFIER: "1" };
|
|
4314
|
+
delete env["VERCEL_TOKEN"];
|
|
4315
|
+
return env;
|
|
4316
|
+
}
|
|
3144
4317
|
function failedRun(error, stdout, stderr) {
|
|
3145
4318
|
const fields = typeof error === "object" && error !== null ? error : {};
|
|
3146
4319
|
const out = typeof stdout === "string" ? stdout : "";
|
|
@@ -3190,7 +4363,7 @@ function githubActionsSource(context) {
|
|
|
3190
4363
|
let inFlight;
|
|
3191
4364
|
const request2 = async () => {
|
|
3192
4365
|
await context.progress.emit({ kind: "requesting-token" });
|
|
3193
|
-
for (let
|
|
4366
|
+
for (let attempt2 = 1; ; attempt2 += 1) {
|
|
3194
4367
|
const sentAt = context.clock.now().getTime();
|
|
3195
4368
|
const outcome = await context.gateway.request();
|
|
3196
4369
|
if (outcome.ok) {
|
|
@@ -3199,11 +4372,11 @@ function githubActionsSource(context) {
|
|
|
3199
4372
|
}
|
|
3200
4373
|
const { failure } = outcome;
|
|
3201
4374
|
if (failure.kind === "variables-missing") return { ok: false, failure: { source: "github-actions", failure } };
|
|
3202
|
-
const wait = RETRY_WAITS_MS[
|
|
4375
|
+
const wait = RETRY_WAITS_MS[attempt2 - 1];
|
|
3203
4376
|
if (wait === void 0 || !isRetryable(failure))
|
|
3204
4377
|
return {
|
|
3205
4378
|
ok: false,
|
|
3206
|
-
failure: { source: "github-actions", failure: { kind: "request-failed", attempts:
|
|
4379
|
+
failure: { source: "github-actions", failure: { kind: "request-failed", attempts: attempt2, last: failure } }
|
|
3207
4380
|
};
|
|
3208
4381
|
await context.timer.sleep(wait);
|
|
3209
4382
|
}
|
|
@@ -3298,11 +4471,14 @@ function credentialResolver(gateways) {
|
|
|
3298
4471
|
|
|
3299
4472
|
// src/config/live/config-gateway.ts
|
|
3300
4473
|
import { stat } from "node:fs/promises";
|
|
3301
|
-
import { basename, join as join3 } from "node:path";
|
|
4474
|
+
import { basename as basename2, join as join3 } from "node:path";
|
|
3302
4475
|
import { pathToFileURL } from "node:url";
|
|
3303
4476
|
function liveConfigGateway() {
|
|
3304
4477
|
return {
|
|
3305
|
-
|
|
4478
|
+
configFileNames: async (directory) => {
|
|
4479
|
+
const kinds = await Promise.all(CONFIG_FILE_NAMES.map((name) => kind(join3(directory, name))));
|
|
4480
|
+
return CONFIG_FILE_NAMES.filter((_, index) => kinds[index] === "file");
|
|
4481
|
+
},
|
|
3306
4482
|
isWorktreeRoot: async (directory) => await kind(join3(directory, ".git")) !== void 0,
|
|
3307
4483
|
importConfig: async (path) => {
|
|
3308
4484
|
try {
|
|
@@ -3323,7 +4499,7 @@ async function kind(path) {
|
|
|
3323
4499
|
}
|
|
3324
4500
|
function importFailure(error, path) {
|
|
3325
4501
|
if (!(error instanceof Error)) return { kind: "import-failed", message: String(error) };
|
|
3326
|
-
const location = errorLocation(error,
|
|
4502
|
+
const location = errorLocation(error, basename2(path));
|
|
3327
4503
|
return { kind: "import-failed", message: error.message, ...location === void 0 ? {} : { location } };
|
|
3328
4504
|
}
|
|
3329
4505
|
function errorLocation(error, name) {
|
|
@@ -3343,28 +4519,38 @@ function errorLocation(error, name) {
|
|
|
3343
4519
|
return void 0;
|
|
3344
4520
|
}
|
|
3345
4521
|
|
|
3346
|
-
// src/config/
|
|
3347
|
-
|
|
3348
|
-
function
|
|
3349
|
-
const
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
4522
|
+
// src/config/live/file-lists-file-gateway.ts
|
|
4523
|
+
import { readFile as readFile2 } from "node:fs/promises";
|
|
4524
|
+
async function readStream(stream) {
|
|
4525
|
+
const chunks = [];
|
|
4526
|
+
for await (const chunk of stream) chunks.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk);
|
|
4527
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
4528
|
+
}
|
|
4529
|
+
function liveFileListsFileGateway(stdin = process.stdin) {
|
|
4530
|
+
return {
|
|
4531
|
+
readFileListsFile: async ({ path }) => {
|
|
4532
|
+
let text;
|
|
4533
|
+
try {
|
|
4534
|
+
text = path === "-" ? await readStream(stdin) : await readFile2(path, "utf8");
|
|
4535
|
+
} catch (error) {
|
|
4536
|
+
return { kind: "unreadable", message: error instanceof Error ? error.message : String(error) };
|
|
4537
|
+
}
|
|
4538
|
+
try {
|
|
4539
|
+
return { kind: "read", value: JSON.parse(text) };
|
|
4540
|
+
} catch (error) {
|
|
4541
|
+
return { kind: "not-json", message: error instanceof Error ? error.message : String(error) };
|
|
4542
|
+
}
|
|
3358
4543
|
}
|
|
3359
4544
|
};
|
|
3360
|
-
return { run: Object.freeze(run), resourceKeys: Object.keys(resources) };
|
|
3361
4545
|
}
|
|
3362
4546
|
|
|
3363
4547
|
// src/config/resolver.ts
|
|
3364
4548
|
function configResolver(launcher) {
|
|
4549
|
+
const loadFile = () => loadSettingsFile(launcher.gateway, launcher.cwd, launcher.definitions, launcher.drivers);
|
|
3365
4550
|
return {
|
|
4551
|
+
loadFile,
|
|
3366
4552
|
async load(definition, options, target) {
|
|
3367
|
-
const file = await
|
|
4553
|
+
const file = await loadFile();
|
|
3368
4554
|
if (!file.ok) return file;
|
|
3369
4555
|
const settings = fileSettings(file, target);
|
|
3370
4556
|
const key = defaultResourceKey(definition);
|
|
@@ -3391,9 +4577,6 @@ export {
|
|
|
3391
4577
|
credentialSourceErrors,
|
|
3392
4578
|
credentialResolver,
|
|
3393
4579
|
configErrors,
|
|
3394
|
-
RUNNER_SECRET_MIN_LENGTH,
|
|
3395
|
-
declaredSecretValues,
|
|
3396
|
-
readRunnerSecrets,
|
|
3397
4580
|
RUNNER_SNAPSHOTS_SUBPATH,
|
|
3398
4581
|
parseKeepTime,
|
|
3399
4582
|
systemTimer,
|
|
@@ -3402,6 +4585,8 @@ export {
|
|
|
3402
4585
|
testEventLine,
|
|
3403
4586
|
parseTestEvent,
|
|
3404
4587
|
redactSecrets,
|
|
4588
|
+
MAX_RUNNER_SANDBOXES,
|
|
4589
|
+
resolveSandboxCountDefault,
|
|
3405
4590
|
lineSplitter,
|
|
3406
4591
|
prepareSnapshotBuild,
|
|
3407
4592
|
buildSnapshots,
|
|
@@ -3412,14 +4597,19 @@ export {
|
|
|
3412
4597
|
liveRunnerSnapshotCacheGateway,
|
|
3413
4598
|
unavailableRunnerSnapshotCacheGateway,
|
|
3414
4599
|
prepareRunner,
|
|
4600
|
+
chooseSnapshotForRun,
|
|
3415
4601
|
SANDBOX_TEST_EVENTS_PATH,
|
|
4602
|
+
declaredSecretValues,
|
|
4603
|
+
readCredentials,
|
|
4604
|
+
readUnsafeSecretEnvVars,
|
|
3416
4605
|
openRunnerSession,
|
|
3417
4606
|
inspectSnapshotCache,
|
|
3418
4607
|
CONFIG_FILE_NAME,
|
|
4608
|
+
CONFIG_FILE_NAMES_TEXT,
|
|
3419
4609
|
liveConfigGateway,
|
|
4610
|
+
liveFileListsFileGateway,
|
|
3420
4611
|
findConfigFile,
|
|
3421
|
-
|
|
3422
|
-
loadSettingsFile,
|
|
4612
|
+
effectiveConfig,
|
|
3423
4613
|
fileSettings,
|
|
3424
4614
|
settleRunResources,
|
|
3425
4615
|
invalidConfig,
|