@cnc-tools/storm 0.9.1 → 0.10.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/bin/storm.js +11 -2
- package/dist/application.d.ts +5 -5
- package/dist/application.js +11 -9
- package/dist/bin/storm.js +24 -20
- package/dist/build-info.js +1 -1
- package/dist/chunks/chunk-AGWW3HDT.js +2559 -0
- package/dist/chunks/{chunk-RRQ2ZGSE.js → chunk-AKKNF3WZ.js} +847 -336
- package/dist/chunks/chunk-H2VCSNVU.js +351 -0
- package/dist/chunks/chunk-J6ZNYUDV.js +21 -0
- package/dist/chunks/{chunk-WV6WQFC6.js → chunk-JQ2HK4RN.js} +15 -26
- package/dist/chunks/chunk-OVXD7GES.js +841 -0
- package/dist/chunks/chunk-VJQLMGOH.js +4716 -0
- package/dist/chunks/chunk-WF4KJ7YG.js +431 -0
- package/dist/chunks/chunk-XHJGHJBW.js +1509 -0
- package/dist/chunks/chunk-YF3ICDBY.js +10 -0
- package/dist/chunks/chunk-ZJ2USLAT.js +4420 -0
- package/dist/chunks/{live-app-X3PW2W42.js → live-app-RIJM3QFD.js} +30 -22
- package/dist/command-tree.d.ts +3 -0
- package/dist/command-tree.js +3 -0
- package/dist/commands/dashboard.d.ts +1 -1
- package/dist/commands/dashboard.js +1 -1
- package/dist/commands/exec/cleanup.d.ts +27 -43
- package/dist/commands/exec/cleanup.js +20 -54
- package/dist/commands/exec/command.d.ts +72 -544
- package/dist/commands/exec/command.js +58 -25
- package/dist/commands/exec/job-summary.d.ts +2 -2
- package/dist/commands/exec/job-summary.js +3 -3
- package/dist/commands/exec/live-view.d.ts +9 -9
- package/dist/commands/exec/live-view.js +48 -41
- package/dist/commands/exec/metadata.d.ts +0 -65
- package/dist/commands/exec/metadata.js +2 -61
- package/dist/commands/exec/mint-failed.d.ts +1 -1
- package/dist/commands/exec/mint-failed.js +8 -8
- package/dist/commands/exec/outcomes.d.ts +63 -468
- package/dist/commands/exec/outcomes.js +42 -69
- package/dist/commands/exec/plan-run.d.ts +150 -0
- package/dist/commands/exec/plan-run.js +121 -0
- package/dist/commands/exec/progress.d.ts +25 -15
- package/dist/commands/exec/progress.js +61 -40
- package/dist/commands/exec/redaction.d.ts +3 -3
- package/dist/commands/exec/redaction.js +4 -4
- package/dist/commands/exec/resource-flags.d.ts +50 -0
- package/dist/commands/exec/resource-flags.js +125 -0
- package/dist/commands/exec/resource-refusals.d.ts +64 -0
- package/dist/commands/exec/resource-refusals.js +58 -0
- package/dist/commands/exec/run-collector.d.ts +15 -10
- package/dist/commands/exec/run-collector.js +5 -5
- package/dist/commands/exec/run-command.d.ts +80 -165
- package/dist/commands/exec/run-command.js +264 -275
- package/dist/commands/exec/run-metadata.d.ts +20 -43
- package/dist/commands/exec/run-metadata.js +18 -37
- package/dist/commands/exec/run-record.d.ts +67 -58
- package/dist/commands/exec/run-record.js +15 -32
- package/dist/commands/exec/test-plan.d.ts +45 -0
- package/dist/commands/exec/test-plan.js +59 -0
- package/dist/commands/exec/tests-summary.d.ts +5 -5
- package/dist/commands/exec/tests-summary.js +2 -2
- package/dist/commands/exec/text.d.ts +8 -2
- package/dist/commands/exec/text.js +8 -0
- package/dist/commands/exec/timeline-facts.d.ts +57 -0
- package/dist/commands/exec/timeline-facts.js +92 -0
- package/dist/commands/exec/view.d.ts +5 -7
- package/dist/commands/exec/view.js +21 -13
- package/dist/commands/exec/waterfall.d.ts +2 -9
- package/dist/commands/exec/waterfall.js +9 -30
- package/dist/commands/exec/worker-chart.d.ts +1 -1
- package/dist/commands/ext/metadata.d.ts +4 -0
- package/dist/commands/ext/metadata.js +8 -0
- package/dist/commands/runs/facts.d.ts +9 -5
- package/dist/commands/runs/facts.js +26 -14
- package/dist/commands/runs/list/command.d.ts +15 -8
- package/dist/commands/runs/list/command.js +38 -32
- package/dist/commands/runs/list/metadata.d.ts +16 -14
- package/dist/commands/runs/list/metadata.js +17 -15
- package/dist/commands/runs/list/outcomes.d.ts +6 -2
- package/dist/commands/runs/logs/command.d.ts +3 -4
- package/dist/commands/runs/logs/command.js +44 -41
- package/dist/commands/runs/logs/metadata.d.ts +17 -15
- package/dist/commands/runs/logs/metadata.js +20 -18
- package/dist/commands/runs/past-run.d.ts +3 -9
- package/dist/commands/runs/past-run.js +2 -17
- package/dist/commands/runs/show/command.d.ts +57 -42
- package/dist/commands/runs/show/command.js +87 -79
- package/dist/commands/runs/show/metadata.d.ts +20 -18
- package/dist/commands/runs/show/metadata.js +20 -18
- package/dist/commands/runs/show/outcomes.d.ts +27 -19
- package/dist/commands/runs/show/outcomes.js +8 -6
- package/dist/commands/vitest/command.d.ts +94 -559
- package/dist/commands/vitest/command.js +71 -94
- package/dist/commands/vitest/metadata.d.ts +0 -65
- package/dist/commands/vitest/metadata.js +2 -41
- package/dist/commands/vitest/outcomes.d.ts +44 -274
- package/dist/commands/vitest/outcomes.js +7 -14
- package/dist/config/credential-resolver.d.ts +131 -0
- package/dist/config/credential-resolver.js +69 -0
- package/dist/{credential/settle.d.ts → config/credential-settle.d.ts} +1 -2
- package/dist/config/errors.d.ts +1 -1
- package/dist/config/errors.js +5 -5
- package/dist/config/index.d.ts +7 -6
- package/dist/config/index.js +13 -9
- package/dist/config/load.d.ts +16 -13
- package/dist/config/load.js +55 -40
- package/dist/config/recipe-run.d.ts +26 -0
- package/dist/config/recipe-run.js +27 -0
- package/dist/config/resolve.d.ts +103 -15
- package/dist/config/resolve.js +137 -47
- package/dist/config/resolver.d.ts +40 -0
- package/dist/config/resolver.js +31 -0
- package/dist/config/schema.d.ts +13 -17
- package/dist/config/schema.js +14 -35
- package/dist/config/settings-file.d.ts +28 -16
- package/dist/config/settings-file.js +39 -24
- package/dist/config/typed-options.d.ts +21 -0
- package/dist/config/typed-options.js +28 -0
- package/dist/config-file/define.d.ts +33 -31
- package/dist/config-file/define.js +14 -4
- package/dist/config-file/toolchain.d.ts +1 -1
- package/dist/context.d.ts +37 -24
- package/dist/context.js +16 -8
- package/dist/core/before-run.d.ts +37 -0
- package/dist/core/before-run.js +44 -0
- package/dist/core/events.d.ts +55 -46
- package/dist/core/gateways.d.ts +17 -18
- package/dist/core/index.d.ts +12 -12
- package/dist/core/index.js +12 -8
- package/dist/core/launcher-supplies.d.ts +11 -0
- package/dist/core/launcher-supplies.js +28 -0
- package/dist/core/mint.js +2 -2
- package/dist/core/payload.d.ts +13 -14
- package/dist/core/payload.js +9 -8
- package/dist/core/presentations.d.ts +37 -37
- package/dist/core/presentations.js +49 -56
- package/dist/core/reports.d.ts +5 -0
- package/dist/core/reports.js +13 -0
- package/dist/core/resource-registry.d.ts +54 -0
- package/dist/core/resource-registry.js +57 -0
- package/dist/core/resource-reports.d.ts +36 -0
- package/dist/core/resource-reports.js +38 -0
- package/dist/core/resource.d.ts +135 -243
- package/dist/core/resource.js +7 -5
- package/dist/core/resources-of.d.ts +16 -0
- package/dist/core/resources-of.js +8 -0
- package/dist/core/resources.d.ts +96 -84
- package/dist/core/resources.js +168 -165
- package/dist/core/run-directory.d.ts +10 -11
- package/dist/core/run-directory.js +9 -9
- package/dist/core/run-state.d.ts +29 -41
- package/dist/core/run-state.js +56 -60
- package/dist/core/run.d.ts +77 -66
- package/dist/core/run.js +83 -74
- package/dist/core/state-directory.js +4 -3
- package/dist/core/timeline.d.ts +42 -24
- package/dist/core/timeline.js +45 -27
- package/dist/core/timing.d.ts +3 -3
- package/dist/core/timing.js +1 -1
- package/dist/credential/gateways.d.ts +1 -80
- package/dist/credential/index.d.ts +3 -5
- package/dist/credential/index.js +7 -5
- package/dist/credential/live/github-actions-token-response.js +1 -1
- package/dist/credential/live/vercel-cli-gateway.d.ts +2 -1
- package/dist/credential/live/vercel-cli-gateway.js +1 -1
- package/dist/credential/live/vercel-output.d.ts +1 -1
- package/dist/credential/source.d.ts +16 -59
- package/dist/credential/source.js +21 -7
- package/dist/credential/target.d.ts +1 -1
- package/dist/extension-commands.d.ts +14 -0
- package/dist/extension-commands.js +20 -0
- package/dist/extensions/github/definition.d.ts +26 -0
- package/dist/extensions/github/definition.js +29 -0
- package/dist/extensions/github/extension.d.ts +18 -0
- package/dist/extensions/github/extension.js +6 -0
- package/dist/{resources → extensions}/github/fixture-repo.d.ts +11 -8
- package/dist/{resources → extensions}/github/fixture-repo.js +8 -4
- package/dist/extensions/github/index.d.ts +13 -0
- package/dist/extensions/github/index.js +17 -0
- package/dist/extensions/github/lifecycle.d.ts +30 -0
- package/dist/extensions/github/lifecycle.js +69 -0
- package/dist/extensions/github/live/world.d.ts +6 -0
- package/dist/extensions/github/live/world.js +16 -0
- package/dist/extensions/github/options.d.ts +36 -0
- package/dist/extensions/github/options.js +36 -0
- package/dist/extensions/github/refusals.d.ts +32 -0
- package/dist/extensions/github/refusals.js +43 -0
- package/dist/extensions/github/release.d.ts +17 -0
- package/dist/extensions/github/release.js +34 -0
- package/dist/extensions/github/resource.d.ts +36 -0
- package/dist/extensions/github/resource.js +21 -0
- package/dist/extensions/github/run/payload.d.ts +27 -0
- package/dist/extensions/github/run/payload.js +42 -0
- package/dist/extensions/github/world.d.ts +15 -0
- package/dist/extensions/github/world.js +3 -0
- package/dist/extensions/testserver/canceled.d.ts +7 -0
- package/dist/extensions/testserver/canceled.js +27 -0
- package/dist/extensions/testserver/command-tree.d.ts +6 -0
- package/dist/extensions/testserver/command-tree.js +21 -0
- package/dist/extensions/testserver/commands/app.d.ts +22 -0
- package/dist/extensions/testserver/commands/app.js +5 -0
- package/dist/{resources/testserver/commands → extensions/testserver/commands/pool}/create/command.d.ts +277 -237
- package/dist/{resources/testserver/commands → extensions/testserver/commands/pool}/create/command.js +105 -140
- package/dist/extensions/testserver/commands/pool/create/metadata.d.ts +33 -0
- package/dist/extensions/testserver/commands/pool/create/metadata.js +55 -0
- package/dist/{resources/testserver/commands → extensions/testserver/commands/pool}/create/outcomes.d.ts +132 -112
- package/dist/{resources/testserver/commands → extensions/testserver/commands/pool}/create/outcomes.js +6 -24
- package/dist/{resources/testserver/commands → extensions/testserver/commands/pool}/list/command.d.ts +3 -4
- package/dist/{resources/testserver/commands → extensions/testserver/commands/pool}/list/command.js +30 -28
- package/dist/extensions/testserver/commands/pool/list/metadata.d.ts +11 -0
- package/dist/{resources/testserver/commands → extensions/testserver/commands/pool}/list/metadata.js +7 -5
- package/dist/{resources/testserver/commands → extensions/testserver/commands/pool}/list/outcomes.js +1 -1
- package/dist/extensions/testserver/commands/pool/metadata.d.ts +3 -0
- package/dist/extensions/testserver/commands/pool/metadata.js +7 -0
- package/dist/extensions/testserver/commands/tree.d.ts +2 -0
- package/dist/extensions/testserver/commands/tree.js +6 -0
- package/dist/{resources → extensions}/testserver/credential-facts.d.ts +6 -40
- package/dist/{resources → extensions}/testserver/credential-facts.js +13 -35
- package/dist/extensions/testserver/definition.d.ts +57 -0
- package/dist/extensions/testserver/definition.js +71 -0
- package/dist/{resources → extensions}/testserver/events.d.ts +5 -4
- package/dist/extensions/testserver/events.js +4 -0
- package/dist/extensions/testserver/extension.d.ts +46 -0
- package/dist/extensions/testserver/extension.js +68 -0
- package/dist/extensions/testserver/index.d.ts +20 -0
- package/dist/extensions/testserver/index.js +31 -0
- package/dist/extensions/testserver/lifecycle.d.ts +24 -0
- package/dist/extensions/testserver/lifecycle.js +116 -0
- package/dist/{core → extensions/testserver}/limit.js +1 -0
- package/dist/extensions/testserver/live/world.d.ts +8 -0
- package/dist/extensions/testserver/live/world.js +38 -0
- package/dist/{resources/testserver/sandbox → extensions/testserver/options}/channels.d.ts +1 -1
- package/dist/extensions/testserver/options/index.d.ts +5 -0
- package/dist/extensions/testserver/options/index.js +11 -0
- package/dist/extensions/testserver/options/rules.d.ts +69 -0
- package/dist/extensions/testserver/options/rules.js +92 -0
- package/dist/extensions/testserver/options/sandboxes.d.ts +29 -0
- package/dist/extensions/testserver/options/sandboxes.js +33 -0
- package/dist/extensions/testserver/options/ttl.d.ts +23 -0
- package/dist/extensions/testserver/options/ttl.js +42 -0
- package/dist/{resources → extensions}/testserver/pool/channels.d.ts +3 -3
- package/dist/{resources → extensions}/testserver/pool/channels.js +2 -2
- package/dist/{resources → extensions}/testserver/pool/create.d.ts +1 -2
- package/dist/{resources → extensions}/testserver/pool/create.js +2 -1
- package/dist/{resources → extensions}/testserver/pool/index.d.ts +0 -1
- package/dist/{resources → extensions}/testserver/pool/index.js +2 -3
- package/dist/{resources → extensions}/testserver/pool/inspect.d.ts +1 -1
- package/dist/{resources → extensions}/testserver/pool/lease.d.ts +1 -1
- package/dist/extensions/testserver/pool/live/pool-store-gateway.d.ts +12 -0
- package/dist/{resources → extensions}/testserver/pool/live/pool-store-gateway.js +4 -4
- package/dist/{resources → extensions}/testserver/pool/pull-request.d.ts +8 -5
- package/dist/{resources → extensions}/testserver/pool/pull-request.js +2 -2
- package/dist/extensions/testserver/pr-build-facts.d.ts +156 -0
- package/dist/extensions/testserver/pr-build-facts.js +309 -0
- package/dist/extensions/testserver/presentation.d.ts +11 -0
- package/dist/{resources → extensions}/testserver/presentation.js +35 -56
- package/dist/{resources/testserver/lane.d.ts → extensions/testserver/progress.d.ts} +10 -6
- package/dist/{resources/testserver/lane.js → extensions/testserver/progress.js} +21 -16
- package/dist/extensions/testserver/provision.d.ts +160 -0
- package/dist/{resources/testserver/provider.js → extensions/testserver/provision.js} +80 -108
- package/dist/{resources → extensions}/testserver/pull-request/gateways.d.ts +1 -1
- package/dist/extensions/testserver/pull-request/gateways.js +5 -0
- package/dist/{resources → extensions}/testserver/pull-request/index.js +2 -2
- package/dist/{resources → extensions}/testserver/pull-request/live/github-token-gateway.d.ts +4 -4
- package/dist/{resources → extensions}/testserver/pull-request/live/github-token-gateway.js +4 -4
- package/dist/extensions/testserver/refusals.d.ts +72 -0
- package/dist/extensions/testserver/refusals.js +117 -0
- package/dist/extensions/testserver/release.d.ts +14 -0
- package/dist/extensions/testserver/release.js +26 -0
- package/dist/extensions/testserver/resource.d.ts +57 -0
- package/dist/extensions/testserver/resource.js +19 -0
- package/dist/extensions/testserver/result.d.ts +55 -0
- package/dist/extensions/testserver/result.js +98 -0
- package/dist/extensions/testserver/run/connection.d.ts +21 -0
- package/dist/extensions/testserver/run/connection.js +39 -0
- package/dist/extensions/testserver/run-sandbox.d.ts +16 -0
- package/dist/extensions/testserver/run-sandbox.js +11 -0
- package/dist/{resources → extensions}/testserver/sandbox/create.d.ts +1 -11
- package/dist/{resources → extensions}/testserver/sandbox/create.js +0 -15
- package/dist/{resources → extensions}/testserver/sandbox/gateways.d.ts +1 -1
- package/dist/{resources → extensions}/testserver/sandbox/index.d.ts +1 -3
- package/dist/extensions/testserver/sandbox/index.js +6 -0
- package/dist/extensions/testserver/testserver-sdk.d.ts +1 -0
- package/dist/extensions/testserver/testserver-sdk.js +4 -0
- package/dist/{vercel-cli → extensions/testserver/vercel-cli}/arguments.js +1 -1
- package/dist/{vercel-cli → extensions/testserver/vercel-cli}/context.js +1 -1
- package/dist/{vercel-cli → extensions/testserver/vercel-cli}/driver.d.ts +1 -1
- package/dist/{vercel-cli → extensions/testserver/vercel-cli}/gateways.js +1 -1
- package/dist/{vercel-cli → extensions/testserver/vercel-cli}/index.js +4 -4
- package/dist/{vercel-cli → extensions/testserver/vercel-cli}/invocation.d.ts +1 -1
- package/dist/{vercel-cli → extensions/testserver/vercel-cli}/invocation.js +1 -1
- package/dist/{vercel-cli → extensions/testserver/vercel-cli}/redaction.js +1 -1
- package/dist/{vercel-cli → extensions/testserver/vercel-cli}/report.d.ts +1 -1
- package/dist/{vercel-cli → extensions/testserver/vercel-cli}/report.js +1 -1
- package/dist/{vercel-cli → extensions/testserver/vercel-cli}/verbose.js +1 -1
- package/dist/extensions/testserver/vitest/config.d.ts +28 -0
- package/dist/extensions/testserver/vitest/config.js +39 -0
- package/dist/{vitest → extensions/testserver/vitest}/container-scope.d.ts +25 -14
- package/dist/{vitest → extensions/testserver/vitest}/container-scope.js +55 -17
- package/dist/extensions/testserver/vitest/container-start.d.ts +19 -0
- package/dist/extensions/testserver/vitest/container-start.js +31 -0
- package/dist/{vitest → extensions/testserver/vitest}/diagnostics.d.ts +66 -29
- package/dist/{vitest → extensions/testserver/vitest}/diagnostics.js +146 -50
- package/dist/{vitest → extensions/testserver/vitest}/fixtures.d.ts +5 -5
- package/dist/{vitest → extensions/testserver/vitest}/fixtures.js +33 -21
- package/dist/extensions/testserver/vitest/index.d.ts +3 -0
- package/dist/extensions/testserver/vitest/index.js +10 -0
- package/dist/extensions/testserver/vitest/sandbox.d.ts +25 -0
- package/dist/extensions/testserver/vitest/sandbox.js +43 -0
- package/dist/{vitest → extensions/testserver/vitest}/types.d.ts +1 -1
- package/dist/extensions/testserver/world.d.ts +25 -0
- package/dist/extensions/testserver/world.js +4 -0
- package/dist/extensions.d.ts +153 -0
- package/dist/extensions.js +53 -0
- package/dist/help-logo.js +5 -5
- package/dist/launch.js +46 -0
- package/dist/launcher-resolvers/index.d.ts +1 -0
- package/dist/launcher-resolvers/index.js +7 -0
- package/dist/live-app.js +11 -7
- package/dist/presentation.js +2 -2
- package/dist/runner/base.js +1 -1
- package/dist/runner/context.js +1 -1
- package/dist/runner/events.js +1 -1
- package/dist/runner/gateways.d.ts +11 -11
- package/dist/runner/gateways.js +1 -1
- package/dist/runner/index.d.ts +4 -4
- package/dist/runner/index.js +1 -1
- package/dist/runner/live/sandbox-gateway.js +4 -4
- package/dist/runner/live/terminal.d.ts +1 -1
- package/dist/runner/live/terminal.js +1 -1
- package/dist/runner/prepare.d.ts +13 -12
- package/dist/runner/prepare.js +3 -3
- package/dist/runner/ready.js +2 -2
- package/dist/runner/recipe.d.ts +24 -20
- package/dist/runner/recipe.js +19 -17
- package/dist/runner/{remote-command.d.ts → sandboxed-command.d.ts} +18 -19
- package/dist/runner/{remote-command.js → sandboxed-command.js} +21 -22
- package/dist/runner/scope.d.ts +3 -3
- package/dist/runner/secrets.js +1 -1
- package/dist/runner/snapshot-key.d.ts +1 -1
- package/dist/runner/snapshot-key.js +4 -4
- package/dist/runner/snapshot-save.js +3 -3
- package/dist/sdk/extension/commands.d.ts +71 -0
- package/dist/sdk/extension/commands.js +31 -0
- package/dist/{credential/diagnosis.d.ts → sdk/extension/credential-diagnosis.d.ts} +1 -7
- package/dist/{credential/diagnosis.js → sdk/extension/credential-diagnosis.js} +2 -11
- package/dist/sdk/extension/credential-source.d.ts +132 -0
- package/dist/sdk/extension/credential-source.js +5 -0
- package/dist/{credential → sdk/extension}/credential.d.ts +8 -7
- package/dist/{credential → sdk/extension}/credential.js +9 -6
- package/dist/sdk/extension/index.d.ts +15 -0
- package/dist/sdk/extension/index.js +39 -0
- package/dist/sdk/extension/launcher-supplies.d.ts +24 -0
- package/dist/sdk/extension/launcher-supplies.js +3 -0
- package/dist/sdk/extension/lifecycle.d.ts +211 -0
- package/dist/sdk/extension/lifecycle.js +9 -0
- package/dist/sdk/extension/presentation.d.ts +31 -0
- package/dist/sdk/extension/presentation.js +7 -0
- package/dist/sdk/extension/progress.d.ts +75 -0
- package/dist/sdk/extension/progress.js +8 -0
- package/dist/sdk/extension/reports.d.ts +15 -0
- package/dist/sdk/extension/reports.js +5 -0
- package/dist/sdk/extension/resource-definition.d.ts +204 -0
- package/dist/sdk/extension/resource-definition.js +24 -0
- package/dist/sdk/extension/resource-factory.d.ts +10 -0
- package/dist/sdk/extension/resource-factory.js +15 -0
- package/dist/sdk/extension/resource.d.ts +60 -0
- package/dist/sdk/extension/resource.js +42 -0
- package/dist/sdk/extension/rules.d.ts +16 -0
- package/dist/sdk/extension/rules.js +30 -0
- package/dist/sdk/extension/span.d.ts +8 -0
- package/dist/sdk/extension/span.js +4 -0
- package/dist/sdk/extension/time.d.ts +11 -0
- package/dist/sdk/extension/time.js +4 -0
- package/dist/sdk/extension/token-request-facts.d.ts +39 -0
- package/dist/sdk/extension/token-request-facts.js +35 -0
- package/dist/sdk/index.d.ts +4 -7
- package/dist/sdk/index.js +7 -15
- package/dist/sdk/run/contract.d.ts +32 -0
- package/dist/sdk/run/contract.js +12 -0
- package/dist/sdk/run/launcher.d.ts +5 -0
- package/dist/sdk/run/launcher.js +6 -0
- package/dist/sdk/run/payload.d.ts +58 -0
- package/dist/sdk/run/payload.js +73 -0
- package/dist/sdk/run/present.d.ts +11 -0
- package/dist/sdk/run/present.js +4 -0
- package/dist/sdk/run/redact.d.ts +5 -0
- package/dist/sdk/run/redact.js +12 -0
- package/dist/time/duration.js +2 -2
- package/dist/time/index.js +2 -1
- package/dist/time/time.d.ts +2 -11
- package/dist/time/time.js +2 -2
- package/dist/{sdk → vendor/testserver-sdk}/container/api-request.d.ts +14 -2
- package/dist/vendor/testserver-sdk/container/api-request.js +68 -0
- package/dist/{sdk → vendor/testserver-sdk}/container/container.d.ts +74 -24
- package/dist/{sdk → vendor/testserver-sdk}/container/container.js +180 -90
- package/dist/vendor/testserver-sdk/container/external.d.ts +111 -0
- package/dist/vendor/testserver-sdk/container/external.js +76 -0
- package/dist/vendor/testserver-sdk/container/gateways.d.ts +156 -0
- package/dist/{sdk → vendor/testserver-sdk}/container/index.d.ts +2 -1
- package/dist/{sdk → vendor/testserver-sdk}/container/index.js +2 -1
- package/dist/vendor/testserver-sdk/container/live/container-gateway.d.ts +22 -0
- package/dist/vendor/testserver-sdk/container/live/container-gateway.js +165 -0
- package/dist/vendor/testserver-sdk/container/recorder.d.ts +69 -0
- package/dist/vendor/testserver-sdk/container/recorder.js +121 -0
- package/dist/{sdk → vendor/testserver-sdk}/factories/build.d.ts +33 -12
- package/dist/{sdk → vendor/testserver-sdk}/factories/build.js +36 -14
- package/dist/vendor/testserver-sdk/factories/definition.d.ts +39 -0
- package/dist/{sdk → vendor/testserver-sdk}/factories/definition.js +1 -1
- package/dist/{sdk → vendor/testserver-sdk}/factories/definitions.d.ts +7 -4
- package/dist/{sdk → vendor/testserver-sdk}/factories/definitions.js +10 -0
- package/dist/vendor/testserver-sdk/factories/gateways.d.ts +31 -0
- package/dist/vendor/testserver-sdk/factories/index.d.ts +4 -0
- package/dist/{sdk → vendor/testserver-sdk}/factories/index.js +3 -3
- package/dist/vendor/testserver-sdk/index.d.ts +6 -0
- package/dist/vendor/testserver-sdk/index.js +11 -0
- package/dist/{sdk → vendor/testserver-sdk}/proxy/exchange.d.ts +2 -1
- package/dist/{sdk → vendor/testserver-sdk}/proxy/exchange.js +8 -4
- package/dist/{sdk → vendor/testserver-sdk}/proxy/faulted-exchange.js +7 -2
- package/dist/{sdk → vendor/testserver-sdk}/proxy/faults.d.ts +2 -1
- package/dist/{sdk → vendor/testserver-sdk}/proxy/records.d.ts +10 -1
- package/dist/{sdk → vendor/testserver-sdk}/proxy/records.js +13 -0
- package/dist/{sdk → vendor/testserver-sdk}/records/index.d.ts +1 -1
- package/dist/{sdk → vendor/testserver-sdk}/records/records.d.ts +17 -1
- package/dist/vendor/testserver-sdk/testserver/external-ids.d.ts +38 -0
- package/dist/vendor/testserver-sdk/testserver/external-ids.js +46 -0
- package/dist/vendor/testserver-sdk/testserver/failure.d.ts +101 -0
- package/dist/vendor/testserver-sdk/testserver/failure.js +108 -0
- package/dist/vendor/testserver-sdk/testserver/index.d.ts +7 -0
- package/dist/vendor/testserver-sdk/testserver/index.js +11 -0
- package/dist/{sdk → vendor/testserver-sdk}/testserver/live/request.d.ts +8 -10
- package/dist/{sdk → vendor/testserver-sdk}/testserver/live/request.js +8 -6
- package/dist/vendor/testserver-sdk/testserver/routes.d.ts +60 -0
- package/dist/vendor/testserver-sdk/testserver/routes.js +84 -0
- package/dist/vendor/testserver-sdk/testserver/service-ids.d.ts +31 -0
- package/dist/{sdk → vendor/testserver-sdk}/testserver/service-ids.js +27 -4
- package/dist/vitest/config.d.ts +2 -28
- package/dist/vitest/config.js +6 -36
- package/dist/vitest/gateways.js +1 -1
- package/dist/vitest/index.d.ts +2 -3
- package/dist/vitest/index.js +5 -9
- package/dist/vitest/plan.d.ts +1 -16
- package/dist/vitest/plan.js +4 -36
- package/dist/vitest/test-events.d.ts +1 -18
- package/dist/vitest/test-events.js +2 -31
- package/package.json +52 -23
- package/skills/overview.md +9 -9
- package/skills/read-run-output.md +25 -2
- package/skills/testserver-builds.md +8 -8
- package/dist/chunks/chunk-5CQCRX2L.js +0 -5768
- package/dist/chunks/chunk-5U5Q6VZR.js +0 -556
- package/dist/chunks/chunk-7O6UN63H.js +0 -63
- package/dist/chunks/chunk-NX55IJ5S.js +0 -1842
- package/dist/chunks/chunk-OCZJE5XV.js +0 -910
- package/dist/chunks/chunk-S5NAIZYS.js +0 -13
- package/dist/chunks/chunk-UHO5OCEX.js +0 -360
- package/dist/chunks/chunk-WBIHJM7D.js +0 -188
- package/dist/combine-errors.d.ts +0 -11
- package/dist/combine-errors.js +0 -19
- package/dist/commands/exec/testserver-flags.d.ts +0 -48
- package/dist/commands/exec/testserver-flags.js +0 -80
- package/dist/config/by-name.d.ts +0 -24
- package/dist/config/by-name.js +0 -26
- package/dist/config/resource-config.d.ts +0 -132
- package/dist/config/resource-config.js +0 -19
- package/dist/config/set.d.ts +0 -27
- package/dist/config/set.js +0 -71
- package/dist/core/command-provider.d.ts +0 -126
- package/dist/core/command-provider.js +0 -13
- package/dist/core/command-slots.d.ts +0 -73
- package/dist/core/command-slots.js +0 -140
- package/dist/core/keyed.d.ts +0 -12
- package/dist/core/keyed.js +0 -24
- package/dist/core/lane.d.ts +0 -46
- package/dist/core/lane.js +0 -5
- package/dist/core/presentation.d.ts +0 -87
- package/dist/core/presentation.js +0 -5
- package/dist/core/provider.d.ts +0 -79
- package/dist/core/provider.js +0 -5
- package/dist/resource-commands.d.ts +0 -13
- package/dist/resource-commands.js +0 -22
- package/dist/resources/github/cleanup.d.ts +0 -23
- package/dist/resources/github/cleanup.js +0 -39
- package/dist/resources/github/command.d.ts +0 -126
- package/dist/resources/github/command.js +0 -117
- package/dist/resources/github/config.d.ts +0 -16
- package/dist/resources/github/config.js +0 -37
- package/dist/resources/github/events.d.ts +0 -26
- package/dist/resources/github/events.js +0 -2
- package/dist/resources/github/index.d.ts +0 -12
- package/dist/resources/github/index.js +0 -15
- package/dist/resources/github/live/gateways.d.ts +0 -6
- package/dist/resources/github/live/gateways.js +0 -13
- package/dist/resources/github/presentation.d.ts +0 -13
- package/dist/resources/github/presentation.js +0 -43
- package/dist/resources/github/provider.d.ts +0 -66
- package/dist/resources/github/provider.js +0 -58
- package/dist/resources/github/resource-provider.d.ts +0 -6
- package/dist/resources/github/resource-provider.js +0 -20
- package/dist/resources/github/resource.d.ts +0 -33
- package/dist/resources/github/resource.js +0 -12
- package/dist/resources/testserver/cleanup.d.ts +0 -14
- package/dist/resources/testserver/cleanup.js +0 -22
- package/dist/resources/testserver/command-tree.d.ts +0 -4
- package/dist/resources/testserver/command-tree.js +0 -12
- package/dist/resources/testserver/command.d.ts +0 -520
- package/dist/resources/testserver/command.js +0 -252
- package/dist/resources/testserver/commands/app.d.ts +0 -18
- package/dist/resources/testserver/commands/app.js +0 -3
- package/dist/resources/testserver/commands/create/metadata.d.ts +0 -31
- package/dist/resources/testserver/commands/create/metadata.js +0 -53
- package/dist/resources/testserver/commands/list/metadata.d.ts +0 -9
- package/dist/resources/testserver/config.d.ts +0 -18
- package/dist/resources/testserver/config.js +0 -88
- package/dist/resources/testserver/events.js +0 -4
- package/dist/resources/testserver/index.d.ts +0 -16
- package/dist/resources/testserver/index.js +0 -25
- package/dist/resources/testserver/live/gateways.d.ts +0 -8
- package/dist/resources/testserver/live/gateways.js +0 -39
- package/dist/resources/testserver/options.d.ts +0 -5
- package/dist/resources/testserver/options.js +0 -5
- package/dist/resources/testserver/pool/directory.d.ts +0 -4
- package/dist/resources/testserver/pool/directory.js +0 -5
- package/dist/resources/testserver/pool/live/pool-store-gateway.d.ts +0 -12
- package/dist/resources/testserver/pr-build-facts.d.ts +0 -130
- package/dist/resources/testserver/pr-build-facts.js +0 -261
- package/dist/resources/testserver/presentation.d.ts +0 -9
- package/dist/resources/testserver/provider.d.ts +0 -187
- package/dist/resources/testserver/pull-request/gateways.js +0 -5
- package/dist/resources/testserver/ran.d.ts +0 -92
- package/dist/resources/testserver/ran.js +0 -156
- package/dist/resources/testserver/resource-provider.d.ts +0 -12
- package/dist/resources/testserver/resource-provider.js +0 -32
- package/dist/resources/testserver/resource.d.ts +0 -36
- package/dist/resources/testserver/resource.js +0 -10
- package/dist/resources/testserver/run-sandbox.d.ts +0 -13
- package/dist/resources/testserver/run-sandbox.js +0 -6
- package/dist/resources/testserver/sandbox/index.js +0 -8
- package/dist/resources.d.ts +0 -702
- package/dist/resources.js +0 -83
- package/dist/sdk/container/api-request.js +0 -46
- package/dist/sdk/container/gateways.d.ts +0 -108
- package/dist/sdk/container/live/container-gateway.d.ts +0 -17
- package/dist/sdk/container/live/container-gateway.js +0 -114
- package/dist/sdk/factories/definition.d.ts +0 -28
- package/dist/sdk/factories/gateways.d.ts +0 -25
- package/dist/sdk/factories/index.d.ts +0 -5
- package/dist/sdk/factories/live/factory-gateway.d.ts +0 -10
- package/dist/sdk/factories/live/factory-gateway.js +0 -29
- package/dist/sdk/host.d.ts +0 -2
- package/dist/sdk/host.js +0 -7
- package/dist/sdk/payload/index.d.ts +0 -2
- package/dist/sdk/payload/index.js +0 -4
- package/dist/sdk/payload/payload.d.ts +0 -47
- package/dist/sdk/payload/payload.js +0 -74
- package/dist/sdk/testserver/failure.d.ts +0 -73
- package/dist/sdk/testserver/failure.js +0 -61
- package/dist/sdk/testserver/index.d.ts +0 -5
- package/dist/sdk/testserver/index.js +0 -8
- package/dist/sdk/testserver/service-ids.d.ts +0 -19
- package/dist/vitest/sandbox.d.ts +0 -22
- package/dist/vitest/sandbox.js +0 -41
- /package/dist/{credential/settle.js → config/credential-settle.js} +0 -0
- /package/dist/{resources → extensions}/github/gateways.d.ts +0 -0
- /package/dist/{resources → extensions}/github/gateways.js +0 -0
- /package/dist/{resources → extensions}/github/live/fixture-repo-gateway.d.ts +0 -0
- /package/dist/{resources → extensions}/github/live/fixture-repo-gateway.js +0 -0
- /package/dist/{resources/testserver/commands → extensions/testserver/commands/pool}/list/outcomes.d.ts +0 -0
- /package/dist/{core → extensions/testserver}/limit.d.ts +0 -0
- /package/dist/{resources/testserver/sandbox → extensions/testserver/options}/build-reference.d.ts +0 -0
- /package/dist/{resources/testserver/sandbox → extensions/testserver/options}/build-reference.js +0 -0
- /package/dist/{resources/testserver/sandbox → extensions/testserver/options}/channels.js +0 -0
- /package/dist/{resources → extensions}/testserver/pool/gateways.d.ts +0 -0
- /package/dist/{resources → extensions}/testserver/pool/gateways.js +0 -0
- /package/dist/{resources → extensions}/testserver/pool/host.d.ts +0 -0
- /package/dist/{resources → extensions}/testserver/pool/host.js +0 -0
- /package/dist/{resources → extensions}/testserver/pool/inspect.js +0 -0
- /package/dist/{resources → extensions}/testserver/pool/lease.js +0 -0
- /package/dist/{resources → extensions}/testserver/pool/live/pool-records.d.ts +0 -0
- /package/dist/{resources → extensions}/testserver/pool/live/pool-records.js +0 -0
- /package/dist/{resources → extensions}/testserver/pool/staleness.d.ts +0 -0
- /package/dist/{resources → extensions}/testserver/pool/staleness.js +0 -0
- /package/dist/{resources → extensions}/testserver/pull-request/index.d.ts +0 -0
- /package/dist/{resources → extensions}/testserver/pull-request/live/github-rest.d.ts +0 -0
- /package/dist/{resources → extensions}/testserver/pull-request/live/github-rest.js +0 -0
- /package/dist/{resources → extensions}/testserver/pull-request/live/pull-request-gateway.d.ts +0 -0
- /package/dist/{resources → extensions}/testserver/pull-request/live/pull-request-gateway.js +0 -0
- /package/dist/{resources → extensions}/testserver/pull-request/live/testserver-workflow-gateway.d.ts +0 -0
- /package/dist/{resources → extensions}/testserver/pull-request/live/testserver-workflow-gateway.js +0 -0
- /package/dist/{resources → extensions}/testserver/sandbox/create-failure.d.ts +0 -0
- /package/dist/{resources → extensions}/testserver/sandbox/create-failure.js +0 -0
- /package/dist/{resources → extensions}/testserver/sandbox/gateways.js +0 -0
- /package/dist/{resources → extensions}/testserver/sandbox/live/builds-response.d.ts +0 -0
- /package/dist/{resources → extensions}/testserver/sandbox/live/builds-response.js +0 -0
- /package/dist/{resources → extensions}/testserver/sandbox/live/control-plane-gateway.d.ts +0 -0
- /package/dist/{resources → extensions}/testserver/sandbox/live/control-plane-gateway.js +0 -0
- /package/dist/{resources → extensions}/testserver/sandbox/live/create-response.d.ts +0 -0
- /package/dist/{resources → extensions}/testserver/sandbox/live/create-response.js +0 -0
- /package/dist/{resources → extensions}/testserver/sandbox/live/fetch-failure.d.ts +0 -0
- /package/dist/{resources → extensions}/testserver/sandbox/live/fetch-failure.js +0 -0
- /package/dist/{resources → extensions}/testserver/sandbox/live/health-check-gateway.d.ts +0 -0
- /package/dist/{resources → extensions}/testserver/sandbox/live/health-check-gateway.js +0 -0
- /package/dist/{resources → extensions}/testserver/sandbox/live/sse.d.ts +0 -0
- /package/dist/{resources → extensions}/testserver/sandbox/live/sse.js +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/ansi.d.ts +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/ansi.js +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/arguments.d.ts +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/auth-config.d.ts +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/auth-config.js +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/clock.d.ts +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/clock.js +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/config-files.d.ts +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/config-files.js +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/context.d.ts +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/driver.js +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/entry.d.ts +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/entry.js +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/environment.d.ts +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/environment.js +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/errors.d.ts +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/errors.js +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/gateways.d.ts +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/index.d.ts +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/keys.d.ts +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/keys.js +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/live/config-files.d.ts +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/live/config-files.js +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/live/process-gateway.d.ts +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/live/process-gateway.js +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/redaction.d.ts +0 -0
- /package/dist/{vercel-cli → extensions/testserver/vercel-cli}/verbose.d.ts +0 -0
- /package/dist/{vitest → extensions/testserver/vitest}/types.js +0 -0
- /package/dist/sdk/{payload → run}/test-events.d.ts +0 -0
- /package/dist/sdk/{payload → run}/test-events.js +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/container/feature-flags.d.ts +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/container/feature-flags.js +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/container/gateways.js +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/factories/gateways.js +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/proxy/faulted-exchange.d.ts +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/proxy/faults.js +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/proxy/index.d.ts +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/proxy/index.js +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/proxy/proxy.d.ts +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/proxy/proxy.js +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/records/body.d.ts +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/records/body.js +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/records/index.js +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/records/records.js +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/seed/index.d.ts +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/seed/index.js +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/seed/seed.d.ts +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/seed/seed.js +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/testserver/clock.d.ts +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/testserver/clock.js +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/testserver/live/connect-failure.d.ts +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/testserver/live/connect-failure.js +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/testserver/test-id.d.ts +0 -0
- /package/dist/{sdk → vendor/testserver-sdk}/testserver/test-id.js +0 -0
|
@@ -0,0 +1,4716 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CREATE_CONCURRENCY,
|
|
3
|
+
Credential,
|
|
4
|
+
NOT_COUNTED,
|
|
5
|
+
TESTSERVER_REPO,
|
|
6
|
+
buildMatch,
|
|
7
|
+
createFailureText,
|
|
8
|
+
createPooledSandbox,
|
|
9
|
+
defaultResourceKey,
|
|
10
|
+
defineResource,
|
|
11
|
+
describeCreateFailure,
|
|
12
|
+
describeCredentialFailure,
|
|
13
|
+
describeMintFailure,
|
|
14
|
+
describeTtl,
|
|
15
|
+
describeValue,
|
|
16
|
+
leaseUsable,
|
|
17
|
+
liveControlPlaneGateway,
|
|
18
|
+
liveHealthCheckGateway,
|
|
19
|
+
livePoolStoreGateway,
|
|
20
|
+
mayLeaveSandbox,
|
|
21
|
+
minTimeLeftMinutes,
|
|
22
|
+
minutesSince,
|
|
23
|
+
nonEmptyString,
|
|
24
|
+
optionKeyPath,
|
|
25
|
+
parseBuildReference,
|
|
26
|
+
releaseLeases,
|
|
27
|
+
resolveBuild,
|
|
28
|
+
resolvePrBuild,
|
|
29
|
+
resourceCall,
|
|
30
|
+
shortSha,
|
|
31
|
+
testserverPoolRules,
|
|
32
|
+
tokenRequestFailureFacts,
|
|
33
|
+
tokenRequestFailureShape,
|
|
34
|
+
ttlMinutes,
|
|
35
|
+
unavailablePoolStoreGateway
|
|
36
|
+
} from "./chunk-XHJGHJBW.js";
|
|
37
|
+
import {
|
|
38
|
+
defineErrors,
|
|
39
|
+
refused
|
|
40
|
+
} from "./chunk-ZJ2USLAT.js";
|
|
41
|
+
|
|
42
|
+
// src/runner/live/user.ts
|
|
43
|
+
import { userInfo } from "node:os";
|
|
44
|
+
function localUserName() {
|
|
45
|
+
try {
|
|
46
|
+
return userInfo().username;
|
|
47
|
+
} catch {
|
|
48
|
+
return "unknown";
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/runner/base.ts
|
|
53
|
+
async function resolveBase(checkout, request2) {
|
|
54
|
+
const { repoRoot } = request2;
|
|
55
|
+
const refused2 = [];
|
|
56
|
+
let best;
|
|
57
|
+
for (const ref of request2.baseRefs) {
|
|
58
|
+
const candidate = await checkout.baseCandidate({ repoRoot, ref });
|
|
59
|
+
if (candidate.kind === "failed") return candidate;
|
|
60
|
+
if (candidate.kind === "missing-ref") {
|
|
61
|
+
refused2.push({ ref, reason: "missing" });
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (candidate.kind === "unrelated") {
|
|
65
|
+
refused2.push({ ref, reason: "unrelated" });
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (best === void 0) {
|
|
69
|
+
best = { base: candidate.base, ref };
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
if (candidate.base === best.base) continue;
|
|
73
|
+
const newer = await checkout.contains({ repoRoot, ancestor: best.base, descendant: candidate.base });
|
|
74
|
+
if (!newer.ok) return { kind: "failed", failure: newer.failure };
|
|
75
|
+
if (newer.value) best = { base: candidate.base, ref };
|
|
76
|
+
}
|
|
77
|
+
return best === void 0 ? { kind: "no-base-ref", refs: refused2 } : { kind: "resolved", ...best };
|
|
78
|
+
}
|
|
79
|
+
function baseStepContext(checkout, request2) {
|
|
80
|
+
const { repoRoot, base } = request2;
|
|
81
|
+
return {
|
|
82
|
+
base,
|
|
83
|
+
readBaseFile: async (path) => {
|
|
84
|
+
const file = await checkout.readFileAt({ repoRoot, commit: base, path });
|
|
85
|
+
if (file.kind === "found") return file.text;
|
|
86
|
+
if (file.kind === "missing") throw new Error(`${path} doesn't exist at ${base.slice(0, 12)}`);
|
|
87
|
+
throw new Error(`can't read ${path} at ${base.slice(0, 12)}: ${file.failure.message}`);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// src/runner/events.ts
|
|
93
|
+
function progressQueue(progress) {
|
|
94
|
+
let pending = Promise.resolve();
|
|
95
|
+
return {
|
|
96
|
+
add(event) {
|
|
97
|
+
pending = pending.then(() => progress.emit(event));
|
|
98
|
+
},
|
|
99
|
+
flush: () => pending
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// src/runner/live/checkout-gateway.ts
|
|
104
|
+
import { execFile, spawn } from "node:child_process";
|
|
105
|
+
|
|
106
|
+
// src/runner/live/git-output.ts
|
|
107
|
+
function splitNul(output) {
|
|
108
|
+
const text = typeof output === "string" ? output : Buffer.from(output).toString("utf8");
|
|
109
|
+
return text.split("\0").filter((entry) => entry.length > 0);
|
|
110
|
+
}
|
|
111
|
+
function submodulePaths(entries) {
|
|
112
|
+
return entries.filter((entry) => entry.startsWith("160000 ")).map((entry) => entry.slice(entry.indexOf(" ") + 1));
|
|
113
|
+
}
|
|
114
|
+
function partitionUntracked(entries) {
|
|
115
|
+
const files = [];
|
|
116
|
+
const nestedRepositories = [];
|
|
117
|
+
for (const entry of entries) {
|
|
118
|
+
if (entry.endsWith("/")) nestedRepositories.push(entry.slice(0, -1));
|
|
119
|
+
else files.push(entry);
|
|
120
|
+
}
|
|
121
|
+
return { files, nestedRepositories };
|
|
122
|
+
}
|
|
123
|
+
function displayCommand(command, args) {
|
|
124
|
+
return [command, ...args].map(shellQuote).join(" ");
|
|
125
|
+
}
|
|
126
|
+
function shellQuote(argument) {
|
|
127
|
+
return /^[\w@%+=:,./^{}-]+$/.test(argument) ? argument : `'${argument.replaceAll("'", `'\\''`)}'`;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// src/runner/live/checkout-gateway.ts
|
|
131
|
+
var GIT_MAX_BUFFER = 1024 * 1024 * 1024;
|
|
132
|
+
var DIFF_OPTIONS = [
|
|
133
|
+
"--no-color",
|
|
134
|
+
"--no-ext-diff",
|
|
135
|
+
"--no-textconv",
|
|
136
|
+
"--no-renames",
|
|
137
|
+
"--no-relative",
|
|
138
|
+
"--ignore-submodules"
|
|
139
|
+
];
|
|
140
|
+
function liveCheckoutGateway() {
|
|
141
|
+
return {
|
|
142
|
+
repositoryRoot: ({ cwd }) => repositoryRoot(cwd),
|
|
143
|
+
head: ({ repoRoot }) => head(repoRoot),
|
|
144
|
+
baseCandidate: ({ repoRoot, ref }) => baseCandidate(repoRoot, ref),
|
|
145
|
+
contains: ({ repoRoot, ancestor, descendant }) => contains(repoRoot, ancestor, descendant),
|
|
146
|
+
commitTime: ({ repoRoot, commit }) => commitTime(repoRoot, commit),
|
|
147
|
+
readFileAt: ({ repoRoot, commit, path }) => readFileAt(repoRoot, commit, path),
|
|
148
|
+
submodules: ({ repoRoot }) => submodules(repoRoot),
|
|
149
|
+
assembleUpload: ({ repoRoot, base }) => assembleUpload(repoRoot, base),
|
|
150
|
+
baseArchive: ({ repoRoot, base }) => baseArchive(repoRoot, base)
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
async function repositoryRoot(cwd) {
|
|
154
|
+
const run = await git(cwd, ["rev-parse", "--show-toplevel"]);
|
|
155
|
+
return run.ok ? { ok: true, value: run.stdout.toString("utf8").trim() } : run;
|
|
156
|
+
}
|
|
157
|
+
async function head(repoRoot) {
|
|
158
|
+
const [commit, branch, status] = await Promise.all([
|
|
159
|
+
git(repoRoot, ["rev-parse", "--verify", "HEAD"]),
|
|
160
|
+
git(repoRoot, ["symbolic-ref", "--quiet", "--short", "HEAD"]),
|
|
161
|
+
git(repoRoot, ["status", "--porcelain", "-z", "--untracked-files=normal"])
|
|
162
|
+
]);
|
|
163
|
+
if (!commit.ok) return commit;
|
|
164
|
+
if (!branch.ok && branch.exitCode !== 1) return branch;
|
|
165
|
+
if (!status.ok) return status;
|
|
166
|
+
return {
|
|
167
|
+
ok: true,
|
|
168
|
+
value: {
|
|
169
|
+
branch: branch.ok ? branch.stdout.toString("utf8").trim() : null,
|
|
170
|
+
commit: commit.stdout.toString("utf8").trim(),
|
|
171
|
+
dirty: status.stdout.length > 0
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
async function baseCandidate(repoRoot, ref) {
|
|
176
|
+
const exists = await git(repoRoot, ["rev-parse", "--verify", "--quiet", `${ref}^{commit}`]);
|
|
177
|
+
if (!exists.ok) return exists.exitCode === 1 ? { kind: "missing-ref" } : { kind: "failed", failure: exists.failure };
|
|
178
|
+
const mergeBase = await git(repoRoot, ["merge-base", "HEAD", ref]);
|
|
179
|
+
if (!mergeBase.ok)
|
|
180
|
+
return mergeBase.exitCode === 1 ? { kind: "unrelated" } : { kind: "failed", failure: mergeBase.failure };
|
|
181
|
+
return { kind: "merge-base", base: mergeBase.stdout.toString("utf8").trim() };
|
|
182
|
+
}
|
|
183
|
+
async function contains(repoRoot, ancestor, descendant) {
|
|
184
|
+
const present = await git(repoRoot, ["cat-file", "-e", `${ancestor}^{commit}`]);
|
|
185
|
+
if (!present.ok) return { ok: true, value: false };
|
|
186
|
+
const run = await git(repoRoot, ["merge-base", "--is-ancestor", ancestor, descendant]);
|
|
187
|
+
if (run.ok) return { ok: true, value: true };
|
|
188
|
+
return run.exitCode === 1 ? { ok: true, value: false } : run;
|
|
189
|
+
}
|
|
190
|
+
async function commitTime(repoRoot, commit) {
|
|
191
|
+
const run = await git(repoRoot, ["show", "-s", "--format=%ct", `${commit}^{commit}`]);
|
|
192
|
+
if (!run.ok) return run;
|
|
193
|
+
const seconds = Number(run.stdout.toString("utf8").trim());
|
|
194
|
+
return Number.isSafeInteger(seconds) ? { ok: true, value: seconds * 1e3 } : { ok: false, failure: { message: `git show printed no commit time for ${commit}` } };
|
|
195
|
+
}
|
|
196
|
+
async function readFileAt(repoRoot, commit, path) {
|
|
197
|
+
const object = `${commit}:${path}`;
|
|
198
|
+
const type = await git(repoRoot, ["cat-file", "-t", object]);
|
|
199
|
+
if (!type.ok || type.stdout.toString("utf8").trim() !== "blob") return { kind: "missing" };
|
|
200
|
+
const run = await git(repoRoot, ["cat-file", "blob", object]);
|
|
201
|
+
return run.ok ? { kind: "found", text: run.stdout.toString("utf8") } : { kind: "failed", failure: run.failure };
|
|
202
|
+
}
|
|
203
|
+
async function submodules(repoRoot) {
|
|
204
|
+
const run = await git(repoRoot, ["ls-files", "--stage", "-z"]);
|
|
205
|
+
return run.ok ? { ok: true, value: submodulePaths(splitNul(run.stdout)) } : run;
|
|
206
|
+
}
|
|
207
|
+
async function assembleUpload(repoRoot, base) {
|
|
208
|
+
const [patch, others] = await Promise.all([
|
|
209
|
+
git(repoRoot, [
|
|
210
|
+
"diff",
|
|
211
|
+
"--binary",
|
|
212
|
+
// A user's `diff.context=0` makes patches that need special flags to apply.
|
|
213
|
+
"--unified=3",
|
|
214
|
+
...DIFF_OPTIONS,
|
|
215
|
+
"--src-prefix=a/",
|
|
216
|
+
"--dst-prefix=b/",
|
|
217
|
+
base
|
|
218
|
+
]),
|
|
219
|
+
git(repoRoot, ["ls-files", "--others", "--exclude-standard", "-z"])
|
|
220
|
+
]);
|
|
221
|
+
if (!patch.ok) return patch;
|
|
222
|
+
if (!others.ok) return others;
|
|
223
|
+
const { files, nestedRepositories } = partitionUntracked(splitNul(others.stdout));
|
|
224
|
+
let untrackedTarball;
|
|
225
|
+
if (files.length > 0) {
|
|
226
|
+
const tarball = await createTarball(repoRoot, files);
|
|
227
|
+
if (!tarball.ok) return tarball;
|
|
228
|
+
untrackedTarball = tarball.value;
|
|
229
|
+
}
|
|
230
|
+
return { ok: true, value: { patch: patch.stdout, untracked: files, untrackedTarball, nestedRepositories } };
|
|
231
|
+
}
|
|
232
|
+
async function baseArchive(repoRoot, base) {
|
|
233
|
+
const [tarball, fileList] = await Promise.all([
|
|
234
|
+
// LF line endings, as the patch has them: with `core.autocrlf=true`, the Git for Windows default, `git archive`
|
|
235
|
+
// writes CRLF files the patch doesn't apply to.
|
|
236
|
+
git(repoRoot, ["-c", "core.autocrlf=false", "-c", "core.eol=lf", "archive", "--format=tar.gz", base]),
|
|
237
|
+
git(repoRoot, ["ls-tree", "-r", "--name-only", "-z", "--full-tree", base])
|
|
238
|
+
]);
|
|
239
|
+
if (!tarball.ok) return tarball;
|
|
240
|
+
if (!fileList.ok) return fileList;
|
|
241
|
+
return {
|
|
242
|
+
ok: true,
|
|
243
|
+
value: { tarball: tarball.stdout, fileList: fileList.stdout, files: splitNul(fileList.stdout).length }
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
function git(repoRoot, args) {
|
|
247
|
+
const argv = ["-C", repoRoot, ...args];
|
|
248
|
+
return new Promise((resolve) => {
|
|
249
|
+
execFile(
|
|
250
|
+
"git",
|
|
251
|
+
argv,
|
|
252
|
+
{ encoding: "buffer", maxBuffer: GIT_MAX_BUFFER, env: { ...process.env, GIT_OPTIONAL_LOCKS: "0" } },
|
|
253
|
+
(error, stdout, stderr) => {
|
|
254
|
+
if (error === null) {
|
|
255
|
+
resolve({ ok: true, stdout });
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
const subcommand = args.find((arg, index) => arg !== "-c" && args[index - 1] !== "-c") ?? "";
|
|
259
|
+
const detail = stderr.toString("utf8").trim() || error.message;
|
|
260
|
+
resolve({
|
|
261
|
+
ok: false,
|
|
262
|
+
exitCode: typeof error.code === "number" ? error.code : void 0,
|
|
263
|
+
failure: { message: `git ${subcommand} failed: ${detail}`, displayCommand: displayCommand("git", argv) }
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
);
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
function createTarball(repoRoot, paths) {
|
|
270
|
+
const args = ["--null", "-czf", "-", "-C", repoRoot, "-T", "-"];
|
|
271
|
+
const command = displayCommand("tar", args);
|
|
272
|
+
return new Promise((resolve) => {
|
|
273
|
+
const child = spawn("tar", args, {
|
|
274
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
275
|
+
env: { ...process.env, COPYFILE_DISABLE: "1" }
|
|
276
|
+
});
|
|
277
|
+
const chunks = [];
|
|
278
|
+
const errors = [];
|
|
279
|
+
let stdinError;
|
|
280
|
+
let spawnError;
|
|
281
|
+
child.stdout.on("data", (chunk) => chunks.push(chunk));
|
|
282
|
+
child.stderr.on("data", (chunk) => errors.push(chunk));
|
|
283
|
+
child.stdin.on("error", (error) => {
|
|
284
|
+
stdinError = error;
|
|
285
|
+
});
|
|
286
|
+
child.once("error", (error) => {
|
|
287
|
+
spawnError = error;
|
|
288
|
+
});
|
|
289
|
+
child.once("close", (code) => {
|
|
290
|
+
const stderr = Buffer.concat(errors).toString("utf8").trim();
|
|
291
|
+
if (spawnError !== void 0)
|
|
292
|
+
resolve({ ok: false, failure: { message: `tar failed: ${spawnError.message}`, displayCommand: command } });
|
|
293
|
+
else if (code !== 0)
|
|
294
|
+
resolve({
|
|
295
|
+
ok: false,
|
|
296
|
+
failure: { message: `tar failed (exit ${code ?? "none"}): ${stderr}`, displayCommand: command }
|
|
297
|
+
});
|
|
298
|
+
else if (stdinError !== void 0)
|
|
299
|
+
resolve({
|
|
300
|
+
ok: false,
|
|
301
|
+
failure: { message: `tar didn't read the whole path list: ${stdinError.message}`, displayCommand: command }
|
|
302
|
+
});
|
|
303
|
+
else resolve({ ok: true, value: Buffer.concat(chunks) });
|
|
304
|
+
});
|
|
305
|
+
child.stdin.end(paths.map((path) => `${path}\0`).join(""));
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// src/runner/snapshot-key.ts
|
|
310
|
+
import { createHash } from "node:crypto";
|
|
311
|
+
|
|
312
|
+
// src/time/duration.ts
|
|
313
|
+
var MIN_TTL_MINUTES = 10;
|
|
314
|
+
var MAX_TTL_MINUTES = 300;
|
|
315
|
+
function parseDuration(text) {
|
|
316
|
+
const match = /^(\d+)([mh])$/.exec(text);
|
|
317
|
+
if (match === null) return void 0;
|
|
318
|
+
const amount = Number(match[1]);
|
|
319
|
+
if (!Number.isSafeInteger(amount)) return void 0;
|
|
320
|
+
return match[2] === "h" ? amount * 60 : amount;
|
|
321
|
+
}
|
|
322
|
+
function parseTtl(text) {
|
|
323
|
+
const minutes = parseDuration(text);
|
|
324
|
+
return minutes !== void 0 && minutes >= MIN_TTL_MINUTES && minutes <= MAX_TTL_MINUTES ? minutes : void 0;
|
|
325
|
+
}
|
|
326
|
+
function parseKeepTime(text) {
|
|
327
|
+
if (text === "0") return 0;
|
|
328
|
+
const minutes = parseDuration(text);
|
|
329
|
+
return minutes !== void 0 && minutes <= MAX_TTL_MINUTES ? minutes : void 0;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// src/time/time.ts
|
|
333
|
+
var systemTimer = {
|
|
334
|
+
sleep: (ms, signal) => new Promise((resolve) => {
|
|
335
|
+
if (signal?.aborted === true) {
|
|
336
|
+
resolve();
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
const done = () => {
|
|
340
|
+
clearTimeout(timeout);
|
|
341
|
+
signal?.removeEventListener("abort", done);
|
|
342
|
+
resolve();
|
|
343
|
+
};
|
|
344
|
+
const timeout = setTimeout(done, ms);
|
|
345
|
+
signal?.addEventListener("abort", done, { once: true });
|
|
346
|
+
})
|
|
347
|
+
};
|
|
348
|
+
var systemClock = {
|
|
349
|
+
now: () => /* @__PURE__ */ new Date()
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
// src/sdk/run/payload.ts
|
|
353
|
+
import { z } from "zod";
|
|
354
|
+
var RUN_PAYLOAD_VARIABLE = "STORM_RUN";
|
|
355
|
+
var RUN_PAYLOAD_VERSION = 3;
|
|
356
|
+
var runPayloadSchema = z.object({
|
|
357
|
+
version: z.literal(RUN_PAYLOAD_VERSION),
|
|
358
|
+
resources: z.record(z.string(), z.object({ definition: z.string().min(1), payload: z.unknown() })),
|
|
359
|
+
testEvents: z.string().min(1).optional(),
|
|
360
|
+
verbose: z.literal(true).optional()
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
// src/sdk/run/test-events.ts
|
|
364
|
+
import { z as z2 } from "zod";
|
|
365
|
+
var where = { file: z2.string(), worker: z2.number().int().positive(), at: z2.number() };
|
|
366
|
+
var state = z2.enum(["pass", "fail", "skip"]);
|
|
367
|
+
var testEventSchema = z2.discriminatedUnion("kind", [
|
|
368
|
+
z2.object({ kind: z2.literal("file-started"), ...where }),
|
|
369
|
+
z2.object({ kind: z2.literal("file-finished"), ...where }),
|
|
370
|
+
z2.object({ kind: z2.literal("test-started"), ...where, test: z2.string(), fileTests: z2.number().int().nonnegative() }),
|
|
371
|
+
z2.object({
|
|
372
|
+
kind: z2.literal("test-attempt-finished"),
|
|
373
|
+
...where,
|
|
374
|
+
test: z2.string(),
|
|
375
|
+
state,
|
|
376
|
+
ms: z2.number().nonnegative()
|
|
377
|
+
}),
|
|
378
|
+
z2.object({ kind: z2.literal("container-starting"), ...where }),
|
|
379
|
+
z2.object({
|
|
380
|
+
kind: z2.literal("container-started"),
|
|
381
|
+
...where,
|
|
382
|
+
ms: z2.number().nonnegative(),
|
|
383
|
+
ok: z2.boolean(),
|
|
384
|
+
warmupMs: z2.number().nonnegative().exactOptional(),
|
|
385
|
+
warmupFailed: z2.number().int().nonnegative().exactOptional()
|
|
386
|
+
}),
|
|
387
|
+
z2.object({
|
|
388
|
+
kind: z2.literal("test-result"),
|
|
389
|
+
id: z2.string().min(1),
|
|
390
|
+
file: z2.string(),
|
|
391
|
+
test: z2.string(),
|
|
392
|
+
state,
|
|
393
|
+
retryCount: z2.number().int().nonnegative(),
|
|
394
|
+
flaky: z2.boolean(),
|
|
395
|
+
at: z2.number(),
|
|
396
|
+
errors: z2.array(
|
|
397
|
+
z2.object({
|
|
398
|
+
name: z2.string(),
|
|
399
|
+
message: z2.string(),
|
|
400
|
+
stack: z2.string().exactOptional(),
|
|
401
|
+
diff: z2.string().exactOptional()
|
|
402
|
+
})
|
|
403
|
+
).exactOptional(),
|
|
404
|
+
output: z2.object({ text: z2.string(), droppedChars: z2.number().int().nonnegative() }).exactOptional()
|
|
405
|
+
})
|
|
406
|
+
]);
|
|
407
|
+
function testEventLine(event) {
|
|
408
|
+
return JSON.stringify(event);
|
|
409
|
+
}
|
|
410
|
+
function parseTestEvent(line2) {
|
|
411
|
+
let json;
|
|
412
|
+
try {
|
|
413
|
+
json = JSON.parse(line2);
|
|
414
|
+
} catch {
|
|
415
|
+
return void 0;
|
|
416
|
+
}
|
|
417
|
+
const parsed = testEventSchema.safeParse(json);
|
|
418
|
+
return parsed.success ? parsed.data : void 0;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
// src/sdk/run/redact.ts
|
|
422
|
+
var REDACTED = "<token>";
|
|
423
|
+
function redactSecrets(text, secrets) {
|
|
424
|
+
const ordered = [...secrets].filter((secret) => secret !== "").toSorted((a, b) => b.length - a.length);
|
|
425
|
+
return ordered.reduce((redacted, secret) => redacted.split(secret).join(REDACTED), text);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// src/runner/output.ts
|
|
429
|
+
var OUTPUT_TAIL_LINES = 40;
|
|
430
|
+
function lineSplitter() {
|
|
431
|
+
let buffer = "";
|
|
432
|
+
return {
|
|
433
|
+
push(chunk) {
|
|
434
|
+
const end = chunk.lastIndexOf("\n");
|
|
435
|
+
if (end === -1) {
|
|
436
|
+
buffer += chunk;
|
|
437
|
+
return "";
|
|
438
|
+
}
|
|
439
|
+
const lines = buffer + chunk.slice(0, end + 1);
|
|
440
|
+
buffer = chunk.slice(end + 1);
|
|
441
|
+
return lines;
|
|
442
|
+
},
|
|
443
|
+
flush() {
|
|
444
|
+
const rest = buffer;
|
|
445
|
+
buffer = "";
|
|
446
|
+
return rest;
|
|
447
|
+
}
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
function rewritePaths(text, fromRoot, toRoot) {
|
|
451
|
+
const from = `${fromRoot.replace(/\/+$/, "")}/`;
|
|
452
|
+
const to = `${toRoot.replace(/\/+$/, "")}/`;
|
|
453
|
+
return text.split(from).join(to);
|
|
454
|
+
}
|
|
455
|
+
function outputTail(limit = OUTPUT_TAIL_LINES) {
|
|
456
|
+
const kept = [];
|
|
457
|
+
return {
|
|
458
|
+
add(line2) {
|
|
459
|
+
kept.push(line2);
|
|
460
|
+
if (kept.length > limit) kept.shift();
|
|
461
|
+
},
|
|
462
|
+
lines: () => [...kept]
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
function splitLines(text) {
|
|
466
|
+
if (text === "") return [];
|
|
467
|
+
const lines = text.split("\n");
|
|
468
|
+
if (lines.at(-1) === "") lines.pop();
|
|
469
|
+
return lines;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
// src/runner/steps.ts
|
|
473
|
+
var STEP_ENV = {
|
|
474
|
+
HUSKY: "0",
|
|
475
|
+
COREPACK_ENABLE_DOWNLOAD_PROMPT: "0",
|
|
476
|
+
COREPACK_ENABLE_STRICT: "0",
|
|
477
|
+
npm_config_update_notifier: "false"
|
|
478
|
+
};
|
|
479
|
+
async function runStep(context, request2, progress, signal) {
|
|
480
|
+
const { phase, label } = request2;
|
|
481
|
+
const startedAt = context.clock.now().getTime();
|
|
482
|
+
await progress.emit({ kind: "step-started", phase, label });
|
|
483
|
+
const queue = progressQueue(progress);
|
|
484
|
+
const tail = outputTail();
|
|
485
|
+
const splitters = { stdout: lineSplitter(), stderr: lineSplitter() };
|
|
486
|
+
const emit = (stream, text) => {
|
|
487
|
+
for (const line2 of splitLines(text)) {
|
|
488
|
+
tail.add(line2);
|
|
489
|
+
queue.add({ kind: "step-output", phase, stream, line: line2 });
|
|
490
|
+
}
|
|
491
|
+
};
|
|
492
|
+
const ran = await context.runnerSandboxes.runScript(
|
|
493
|
+
request2.sandbox,
|
|
494
|
+
{ script: request2.script, env: { ...STEP_ENV, ...request2.secrets } },
|
|
495
|
+
({ stream, data }) => emit(stream, splitters[stream].push(data)),
|
|
496
|
+
signal
|
|
497
|
+
);
|
|
498
|
+
emit("stdout", splitters.stdout.flush());
|
|
499
|
+
emit("stderr", splitters.stderr.flush());
|
|
500
|
+
await queue.flush();
|
|
501
|
+
if (!ran.ok) return { kind: "sandbox-failed", failure: ran.failure };
|
|
502
|
+
if (ran.value.exitCode !== 0) return { kind: "exited", exitCode: ran.value.exitCode, tail: tail.lines() };
|
|
503
|
+
const ms = context.clock.now().getTime() - startedAt;
|
|
504
|
+
await progress.emit({ kind: "step-finished", phase, label, ms });
|
|
505
|
+
return { kind: "succeeded", ms };
|
|
506
|
+
}
|
|
507
|
+
function sandboxApiFailure(operation, failure) {
|
|
508
|
+
if (failure.kind === "snapshot-gone")
|
|
509
|
+
return { kind: "sandbox-api-failed", operation, status: 410, message: failure.message };
|
|
510
|
+
return { kind: "sandbox-api-failed", operation, status: failure.status ?? null, message: failure.message };
|
|
511
|
+
}
|
|
512
|
+
function sandboxStop(operation, failure) {
|
|
513
|
+
return failure.kind === "aborted" ? { kind: "aborted" } : { kind: "failed", failure: sandboxApiFailure(operation, failure) };
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
// src/runner/recipe.ts
|
|
517
|
+
var RECIPE_DEFAULTS = {
|
|
518
|
+
cwd: ".",
|
|
519
|
+
timeout: "60m",
|
|
520
|
+
baseRefs: ["main", "origin/main"],
|
|
521
|
+
region: "iad1",
|
|
522
|
+
runtime: "node22"
|
|
523
|
+
};
|
|
524
|
+
var RECIPE_KEYS = /* @__PURE__ */ new Set([
|
|
525
|
+
"name",
|
|
526
|
+
"snapshot",
|
|
527
|
+
"run",
|
|
528
|
+
"cwd",
|
|
529
|
+
"vcpus",
|
|
530
|
+
"env",
|
|
531
|
+
"secrets",
|
|
532
|
+
"timeout",
|
|
533
|
+
"keepSandbox",
|
|
534
|
+
"baseRefs",
|
|
535
|
+
"region",
|
|
536
|
+
"runtime"
|
|
537
|
+
]);
|
|
538
|
+
var SNAPSHOT_KEYS = /* @__PURE__ */ new Set(["vcpus", "summary", "toolchains", "prebuild"]);
|
|
539
|
+
var RUN_KEYS = /* @__PURE__ */ new Set(["install", "build"]);
|
|
540
|
+
var STEP_KEYS = /* @__PURE__ */ new Set(["label", "script", "secrets"]);
|
|
541
|
+
var NAME_PATTERN = /^[a-z0-9][a-z0-9-]*$/;
|
|
542
|
+
var VARIABLE_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
543
|
+
var RESERVED_SECRET_NAMES = /* @__PURE__ */ new Set([
|
|
544
|
+
"PATH",
|
|
545
|
+
"HOME",
|
|
546
|
+
"USER",
|
|
547
|
+
"LOGNAME",
|
|
548
|
+
"SHELL",
|
|
549
|
+
"PWD",
|
|
550
|
+
"TMPDIR",
|
|
551
|
+
"BASH_ENV",
|
|
552
|
+
"ENV",
|
|
553
|
+
"IFS",
|
|
554
|
+
"NODE_OPTIONS"
|
|
555
|
+
]);
|
|
556
|
+
var RESERVED_SECRET_PREFIXES = ["LD_", "DYLD_"];
|
|
557
|
+
function checkRecipe(value) {
|
|
558
|
+
const problems = [];
|
|
559
|
+
const report = (path, problem2) => problems.push({ path, problem: problem2 });
|
|
560
|
+
if (!isRecord(value)) {
|
|
561
|
+
report([], `must be an object, not ${describeRecipeValue(value)}`);
|
|
562
|
+
return { ok: false, problems };
|
|
563
|
+
}
|
|
564
|
+
reportUnknownKeys(value, RECIPE_KEYS, [], "a runner recipe key", report);
|
|
565
|
+
const name = value["name"];
|
|
566
|
+
if (typeof name !== "string" || !NAME_PATTERN.test(name))
|
|
567
|
+
report(
|
|
568
|
+
["name"],
|
|
569
|
+
`must be lowercase letters, digits and dashes, starting with a letter or digit, not ${describeRecipeValue(name)}`
|
|
570
|
+
);
|
|
571
|
+
const declared = declaredSecrets(value["secrets"]);
|
|
572
|
+
const snapshot = checkSnapshot(value["snapshot"], declared, report);
|
|
573
|
+
const run = checkRun(value["run"], declared, report);
|
|
574
|
+
const cwd = orDefault(value["cwd"], RECIPE_DEFAULTS.cwd);
|
|
575
|
+
if (!isRelativePath(cwd))
|
|
576
|
+
report(["cwd"], `must be a path relative to the repository's root, without "..", not ${describeRecipeValue(cwd)}`);
|
|
577
|
+
const vcpus = value["vcpus"];
|
|
578
|
+
if (typeof vcpus !== "function" && !isPositiveInteger(vcpus))
|
|
579
|
+
report(["vcpus"], `must be a positive whole number, or a function of the run, not ${describeRecipeValue(vcpus)}`);
|
|
580
|
+
const env = checkEnv(value["env"], report);
|
|
581
|
+
const secrets = checkSecrets(value["secrets"], report);
|
|
582
|
+
const timeout = orDefault(value["timeout"], RECIPE_DEFAULTS.timeout);
|
|
583
|
+
const timeoutMinutes = typeof timeout === "string" ? parseTtl(timeout) : void 0;
|
|
584
|
+
if (timeoutMinutes === void 0)
|
|
585
|
+
report(
|
|
586
|
+
["timeout"],
|
|
587
|
+
`must be a whole number of minutes or hours from 10m to 5h, not ${describeRecipeValue(timeout)}`
|
|
588
|
+
);
|
|
589
|
+
const keepSandbox = value["keepSandbox"];
|
|
590
|
+
const keepSandboxMinutes = typeof keepSandbox === "string" ? parseKeepTime(keepSandbox) : void 0;
|
|
591
|
+
if (keepSandbox !== void 0 && keepSandboxMinutes === void 0)
|
|
592
|
+
report(
|
|
593
|
+
["keepSandbox"],
|
|
594
|
+
`must be 0, or a whole number of minutes or hours up to 5h, not ${describeRecipeValue(keepSandbox)}`
|
|
595
|
+
);
|
|
596
|
+
const baseRefs = checkBaseRefs(value["baseRefs"], report);
|
|
597
|
+
const region = orDefault(value["region"], RECIPE_DEFAULTS.region);
|
|
598
|
+
if (!isNonEmptyString(region)) report(["region"], `must be a non-empty string, not ${describeRecipeValue(region)}`);
|
|
599
|
+
const runtime = orDefault(value["runtime"], RECIPE_DEFAULTS.runtime);
|
|
600
|
+
if (!isNonEmptyString(runtime))
|
|
601
|
+
report(["runtime"], `must be a non-empty string, not ${describeRecipeValue(runtime)}`);
|
|
602
|
+
if (problems.length > 0 || snapshot === void 0 || run === void 0 || env === void 0 || secrets === void 0 || baseRefs === void 0 || timeoutMinutes === void 0)
|
|
603
|
+
return { ok: false, problems };
|
|
604
|
+
return {
|
|
605
|
+
ok: true,
|
|
606
|
+
value: {
|
|
607
|
+
name,
|
|
608
|
+
snapshot,
|
|
609
|
+
run,
|
|
610
|
+
cwd,
|
|
611
|
+
vcpus,
|
|
612
|
+
env,
|
|
613
|
+
secrets,
|
|
614
|
+
timeout,
|
|
615
|
+
timeoutMinutes,
|
|
616
|
+
keepSandboxMinutes,
|
|
617
|
+
baseRefs,
|
|
618
|
+
region,
|
|
619
|
+
runtime
|
|
620
|
+
}
|
|
621
|
+
};
|
|
622
|
+
}
|
|
623
|
+
function declaredSecrets(value) {
|
|
624
|
+
if (value === void 0) return /* @__PURE__ */ new Set();
|
|
625
|
+
if (!Array.isArray(value)) return void 0;
|
|
626
|
+
return new Set(value.filter((name) => typeof name === "string"));
|
|
627
|
+
}
|
|
628
|
+
function checkSnapshot(value, declared, report) {
|
|
629
|
+
if (!isRecord(value)) {
|
|
630
|
+
report(
|
|
631
|
+
["snapshot"],
|
|
632
|
+
`must be an object of vcpus, toolchains, prebuild and an optional summary, not ${describeRecipeValue(value)}`
|
|
633
|
+
);
|
|
634
|
+
return void 0;
|
|
635
|
+
}
|
|
636
|
+
let ok = reportUnknownKeys(value, SNAPSHOT_KEYS, ["snapshot"], "a runner recipe snapshot key", report);
|
|
637
|
+
const vcpus = value["vcpus"];
|
|
638
|
+
if (!isPositiveInteger(vcpus)) {
|
|
639
|
+
report(["snapshot", "vcpus"], `must be a positive whole number, not ${describeRecipeValue(vcpus)}`);
|
|
640
|
+
ok = false;
|
|
641
|
+
}
|
|
642
|
+
const summary = value["summary"];
|
|
643
|
+
if (summary !== void 0 && !isNonEmptyString(summary)) {
|
|
644
|
+
report(["snapshot", "summary"], `must be a non-empty string, not ${describeRecipeValue(summary)}`);
|
|
645
|
+
ok = false;
|
|
646
|
+
}
|
|
647
|
+
const toolchains = checkSteps(value["toolchains"], ["snapshot", "toolchains"], declared, report);
|
|
648
|
+
const prebuild = checkSteps(value["prebuild"], ["snapshot", "prebuild"], declared, report);
|
|
649
|
+
if (!ok || toolchains === void 0 || prebuild === void 0) return void 0;
|
|
650
|
+
return {
|
|
651
|
+
vcpus,
|
|
652
|
+
...summary === void 0 ? {} : { summary },
|
|
653
|
+
toolchains,
|
|
654
|
+
prebuild
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
function checkRun(value, declared, report) {
|
|
658
|
+
if (!isRecord(value)) {
|
|
659
|
+
report(["run"], `must be an object of install and build steps, not ${describeRecipeValue(value)}`);
|
|
660
|
+
return void 0;
|
|
661
|
+
}
|
|
662
|
+
const ok = reportUnknownKeys(value, RUN_KEYS, ["run"], "a runner recipe run key", report);
|
|
663
|
+
const install = checkStep(value["install"], ["run", "install"], declared, report);
|
|
664
|
+
const build = checkStep(value["build"], ["run", "build"], declared, report);
|
|
665
|
+
return ok && install !== void 0 && build !== void 0 ? { install, build } : void 0;
|
|
666
|
+
}
|
|
667
|
+
function checkSteps(value, path, declared, report) {
|
|
668
|
+
if (typeof value === "function") return value;
|
|
669
|
+
if (!Array.isArray(value)) {
|
|
670
|
+
report(path, `must be a list of steps, or a function that returns one, not ${describeRecipeValue(value)}`);
|
|
671
|
+
return void 0;
|
|
672
|
+
}
|
|
673
|
+
const steps = value.map((step, index) => checkStep(step, [...path, String(index)], declared, report));
|
|
674
|
+
return steps.every((step) => step !== void 0) ? steps : void 0;
|
|
675
|
+
}
|
|
676
|
+
function checkStep(value, path, declared, report) {
|
|
677
|
+
if (!isRecord(value)) {
|
|
678
|
+
report(path, `must be a step, { label, script }, not ${describeRecipeValue(value)}`);
|
|
679
|
+
return void 0;
|
|
680
|
+
}
|
|
681
|
+
let ok = reportUnknownKeys(value, STEP_KEYS, path, "a step key", report);
|
|
682
|
+
const label = value["label"];
|
|
683
|
+
const script = value["script"];
|
|
684
|
+
if (!isNonEmptyString(label)) {
|
|
685
|
+
report([...path, "label"], `must be a non-empty string, not ${describeRecipeValue(label)}`);
|
|
686
|
+
ok = false;
|
|
687
|
+
}
|
|
688
|
+
if (!isNonEmptyString(script)) {
|
|
689
|
+
report([...path, "script"], `must be a non-empty string, not ${describeRecipeValue(script)}`);
|
|
690
|
+
ok = false;
|
|
691
|
+
}
|
|
692
|
+
const secrets = checkStepSecrets(value["secrets"], [...path, "secrets"], declared, report);
|
|
693
|
+
if (secrets === void 0) ok = false;
|
|
694
|
+
return ok && secrets !== void 0 ? { label, script, secrets } : void 0;
|
|
695
|
+
}
|
|
696
|
+
function checkStepSecrets(value, path, declared, report) {
|
|
697
|
+
if (value === void 0) return [];
|
|
698
|
+
if (!Array.isArray(value)) {
|
|
699
|
+
report(path, `must be a list of names runner.secrets declares, not ${describeRecipeValue(value)}`);
|
|
700
|
+
return void 0;
|
|
701
|
+
}
|
|
702
|
+
let ok = true;
|
|
703
|
+
const seen = /* @__PURE__ */ new Set();
|
|
704
|
+
value.forEach((name, index) => {
|
|
705
|
+
const at = [...path, String(index)];
|
|
706
|
+
if (typeof name !== "string") {
|
|
707
|
+
report(at, `must be a name runner.secrets declares, not ${describeRecipeValue(name)}`);
|
|
708
|
+
ok = false;
|
|
709
|
+
} else if (declared !== void 0 && !declared.has(name)) {
|
|
710
|
+
report(at, `names ${name}, which runner.secrets doesn't declare`);
|
|
711
|
+
ok = false;
|
|
712
|
+
} else if (seen.has(name)) {
|
|
713
|
+
report(at, `names ${name} again`);
|
|
714
|
+
ok = false;
|
|
715
|
+
}
|
|
716
|
+
if (typeof name === "string") seen.add(name);
|
|
717
|
+
});
|
|
718
|
+
return ok ? [...value] : void 0;
|
|
719
|
+
}
|
|
720
|
+
function checkEnv(value, report) {
|
|
721
|
+
if (value === void 0) return {};
|
|
722
|
+
if (!isRecord(value)) {
|
|
723
|
+
report(["env"], `must be an object of strings, not ${describeRecipeValue(value)}`);
|
|
724
|
+
return void 0;
|
|
725
|
+
}
|
|
726
|
+
let ok = true;
|
|
727
|
+
const env = {};
|
|
728
|
+
for (const [key, variable] of Object.entries(value)) {
|
|
729
|
+
if (key === RUN_PAYLOAD_VARIABLE) {
|
|
730
|
+
report(["env", key], "can't be set: storm sets it for the command");
|
|
731
|
+
ok = false;
|
|
732
|
+
} else if (typeof variable !== "string") {
|
|
733
|
+
report(["env", key], `must be a string, not ${describeRecipeValue(variable)}`);
|
|
734
|
+
ok = false;
|
|
735
|
+
} else env[key] = variable;
|
|
736
|
+
}
|
|
737
|
+
return ok ? env : void 0;
|
|
738
|
+
}
|
|
739
|
+
function checkSecrets(value, report) {
|
|
740
|
+
if (value === void 0) return [];
|
|
741
|
+
if (!Array.isArray(value)) {
|
|
742
|
+
report(["secrets"], `must be a list of environment variable names, not ${describeRecipeValue(value)}`);
|
|
743
|
+
return void 0;
|
|
744
|
+
}
|
|
745
|
+
let ok = true;
|
|
746
|
+
const seen = /* @__PURE__ */ new Set();
|
|
747
|
+
value.forEach((name, index) => {
|
|
748
|
+
const path = ["secrets", String(index)];
|
|
749
|
+
if (typeof name !== "string" || !VARIABLE_PATTERN.test(name)) {
|
|
750
|
+
report(
|
|
751
|
+
path,
|
|
752
|
+
`must be an environment variable name, letters, digits and underscores, not starting with a digit, not ${describeRecipeValue(name)}`
|
|
753
|
+
);
|
|
754
|
+
ok = false;
|
|
755
|
+
} else if (name === RUN_PAYLOAD_VARIABLE) {
|
|
756
|
+
report(path, `can't be ${name}: storm sets it for the command`);
|
|
757
|
+
ok = false;
|
|
758
|
+
} else if (Object.hasOwn(STEP_ENV, name)) {
|
|
759
|
+
report(path, `can't be ${name}: storm sets it for every step`);
|
|
760
|
+
ok = false;
|
|
761
|
+
} else if (RESERVED_SECRET_NAMES.has(name)) {
|
|
762
|
+
report(path, `can't be ${name}: it changes how a step's shell or programs run`);
|
|
763
|
+
ok = false;
|
|
764
|
+
} else if (reservedPrefix(name) !== void 0) {
|
|
765
|
+
report(path, `can't be ${name}: a name starting with ${reservedPrefix(name)} changes how a step's programs load`);
|
|
766
|
+
ok = false;
|
|
767
|
+
} else if (seen.has(name)) {
|
|
768
|
+
report(path, `names ${name} again`);
|
|
769
|
+
ok = false;
|
|
770
|
+
}
|
|
771
|
+
if (typeof name === "string") seen.add(name);
|
|
772
|
+
});
|
|
773
|
+
return ok ? [...value] : void 0;
|
|
774
|
+
}
|
|
775
|
+
function reservedPrefix(name) {
|
|
776
|
+
return RESERVED_SECRET_PREFIXES.find((prefix) => name.startsWith(prefix));
|
|
777
|
+
}
|
|
778
|
+
function checkBaseRefs(value, report) {
|
|
779
|
+
if (value === void 0) return [...RECIPE_DEFAULTS.baseRefs];
|
|
780
|
+
if (!Array.isArray(value) || value.length === 0) {
|
|
781
|
+
report(["baseRefs"], `must be a non-empty list of refs, not ${describeRecipeValue(value)}`);
|
|
782
|
+
return void 0;
|
|
783
|
+
}
|
|
784
|
+
let ok = true;
|
|
785
|
+
value.forEach((ref, index) => {
|
|
786
|
+
if (!isNonEmptyString(ref)) {
|
|
787
|
+
report(["baseRefs", String(index)], `must be a non-empty string, not ${describeRecipeValue(ref)}`);
|
|
788
|
+
ok = false;
|
|
789
|
+
}
|
|
790
|
+
});
|
|
791
|
+
return ok ? [...value] : void 0;
|
|
792
|
+
}
|
|
793
|
+
function reportUnknownKeys(value, known, path, what, report) {
|
|
794
|
+
let ok = true;
|
|
795
|
+
for (const key of Object.keys(value))
|
|
796
|
+
if (!known.has(key)) {
|
|
797
|
+
report([...path, key], `is not ${what}`);
|
|
798
|
+
ok = false;
|
|
799
|
+
}
|
|
800
|
+
return ok;
|
|
801
|
+
}
|
|
802
|
+
async function resolveSteps(steps, context, declared) {
|
|
803
|
+
if (typeof steps !== "function")
|
|
804
|
+
return {
|
|
805
|
+
ok: true,
|
|
806
|
+
steps: steps.map(({ label, script, secrets }) => ({ label, script, secrets: [...secrets ?? []] }))
|
|
807
|
+
};
|
|
808
|
+
let returned;
|
|
809
|
+
try {
|
|
810
|
+
returned = await steps(context);
|
|
811
|
+
} catch (error) {
|
|
812
|
+
return { ok: false, problem: `threw at base ${context.base.slice(0, 12)}: ${errorMessage(error)}` };
|
|
813
|
+
}
|
|
814
|
+
if (!Array.isArray(returned))
|
|
815
|
+
return { ok: false, problem: `must return a list of steps, not ${describeRecipeValue(returned)}` };
|
|
816
|
+
const problems = [];
|
|
817
|
+
const names = new Set(declared);
|
|
818
|
+
const checked = returned.map(
|
|
819
|
+
(step, index) => checkStep(step, [String(index)], names, (path, problem2) => problems.push({ path, problem: problem2 }))
|
|
820
|
+
);
|
|
821
|
+
const first = problems[0];
|
|
822
|
+
if (first !== void 0)
|
|
823
|
+
return {
|
|
824
|
+
ok: false,
|
|
825
|
+
problem: `must return a list of { label, script } steps, but item ${first.path.join(".")} ${first.problem}`
|
|
826
|
+
};
|
|
827
|
+
return { ok: true, steps: checked };
|
|
828
|
+
}
|
|
829
|
+
function resolveVcpus(recipe, { run, resourceKeys }) {
|
|
830
|
+
if (typeof recipe.vcpus !== "function") return { ok: true, vcpus: recipe.vcpus };
|
|
831
|
+
let returned;
|
|
832
|
+
try {
|
|
833
|
+
returned = recipe.vcpus(run);
|
|
834
|
+
} catch (error) {
|
|
835
|
+
return { ok: false, problem: `threw for ${describeResourceKeys(resourceKeys)}: ${errorMessage(error)}` };
|
|
836
|
+
}
|
|
837
|
+
return isPositiveInteger(returned) ? { ok: true, vcpus: returned } : {
|
|
838
|
+
ok: false,
|
|
839
|
+
problem: `must return a positive whole number, not ${describeRecipeValue(returned)} for ${describeResourceKeys(resourceKeys)}`
|
|
840
|
+
};
|
|
841
|
+
}
|
|
842
|
+
function describeResourceKeys(names) {
|
|
843
|
+
const last = names.at(-1);
|
|
844
|
+
if (last === void 0) return "a run with no resource";
|
|
845
|
+
return `a run with ${names.length === 1 ? last : `${names.slice(0, -1).join(", ")} and ${last}`}`;
|
|
846
|
+
}
|
|
847
|
+
function describeRecipeValue(value) {
|
|
848
|
+
if (typeof value === "string") return JSON.stringify(value);
|
|
849
|
+
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
850
|
+
if (value === null) return "null";
|
|
851
|
+
if (value === void 0) return "undefined";
|
|
852
|
+
if (typeof value === "function") return "a function";
|
|
853
|
+
if (Array.isArray(value)) return value.length === 0 ? "an empty array" : "an array";
|
|
854
|
+
if (typeof value === "object") return "an object";
|
|
855
|
+
return `a ${typeof value}`;
|
|
856
|
+
}
|
|
857
|
+
function errorMessage(error) {
|
|
858
|
+
return error instanceof Error ? error.message : String(error);
|
|
859
|
+
}
|
|
860
|
+
function orDefault(value, fallback) {
|
|
861
|
+
return value === void 0 ? fallback : value;
|
|
862
|
+
}
|
|
863
|
+
function isRecord(value) {
|
|
864
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
865
|
+
}
|
|
866
|
+
function isNonEmptyString(value) {
|
|
867
|
+
return typeof value === "string" && value.length > 0;
|
|
868
|
+
}
|
|
869
|
+
function isPositiveInteger(value) {
|
|
870
|
+
return typeof value === "number" && Number.isInteger(value) && value > 0;
|
|
871
|
+
}
|
|
872
|
+
function isRelativePath(value) {
|
|
873
|
+
return typeof value === "string" && value.length > 0 && !value.startsWith("/") && !value.split(/[/\\]/).includes("..");
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
// src/runner/snapshot-key.ts
|
|
877
|
+
var SNAPSHOT_FORMAT = 2;
|
|
878
|
+
var SANDBOX_ROOT = "/vercel/sandbox";
|
|
879
|
+
var STAGED_FILES = {
|
|
880
|
+
baseTarball: "base.tgz",
|
|
881
|
+
baseFileList: "base-files",
|
|
882
|
+
patch: "run.patch",
|
|
883
|
+
untrackedTarball: "untracked.tgz",
|
|
884
|
+
untrackedFileList: "untracked-files"
|
|
885
|
+
};
|
|
886
|
+
var GIT_IDENTITY = "-c user.email=storm-runner@vercel.invalid -c user.name='storm runner' -c commit.gpgsign=false";
|
|
887
|
+
var RESET_TO_BASE = [
|
|
888
|
+
"root=$(git rev-list --max-parents=0 HEAD)",
|
|
889
|
+
'git reset -q --hard "$root"',
|
|
890
|
+
"git clean -ffdq"
|
|
891
|
+
];
|
|
892
|
+
function bashScript(lines) {
|
|
893
|
+
return ["set -euo pipefail", `cd ${SANDBOX_ROOT}`, ...lines].join("\n");
|
|
894
|
+
}
|
|
895
|
+
function baseIndexScript(base, staging) {
|
|
896
|
+
const tarball = `${staging}/${STAGED_FILES.baseTarball}`;
|
|
897
|
+
const fileList = `${staging}/${STAGED_FILES.baseFileList}`;
|
|
898
|
+
return bashScript([
|
|
899
|
+
`tar --warning=no-unknown-keyword -xzf ${tarball} -C ${SANDBOX_ROOT}`,
|
|
900
|
+
`rm -f ${tarball}`,
|
|
901
|
+
"git -c init.defaultBranch=main init -q",
|
|
902
|
+
`git --literal-pathspecs add -f --pathspec-from-file=${fileList} --pathspec-file-nul`,
|
|
903
|
+
`rm -f ${fileList}`,
|
|
904
|
+
`git ${GIT_IDENTITY} commit -q --no-verify -m 'base ${base}'`
|
|
905
|
+
]);
|
|
906
|
+
}
|
|
907
|
+
function applyScript(staging) {
|
|
908
|
+
const patch = `${staging}/${STAGED_FILES.patch}`;
|
|
909
|
+
const tarball = `${staging}/${STAGED_FILES.untrackedTarball}`;
|
|
910
|
+
const fileList = `${staging}/${STAGED_FILES.untrackedFileList}`;
|
|
911
|
+
return bashScript([
|
|
912
|
+
...RESET_TO_BASE,
|
|
913
|
+
// A build may have rewritten tracked files with the same content.
|
|
914
|
+
"git update-index -q --refresh || true",
|
|
915
|
+
`if [ -s ${patch} ]; then git apply --index --binary ${patch}; fi`,
|
|
916
|
+
`if [ -s ${tarball} ]; then`,
|
|
917
|
+
` tar --warning=no-unknown-keyword -xzf ${tarball} -C ${SANDBOX_ROOT}`,
|
|
918
|
+
` git --literal-pathspecs add -f --pathspec-from-file=${fileList} --pathspec-file-nul`,
|
|
919
|
+
"fi",
|
|
920
|
+
`git ${GIT_IDENTITY} commit -q --no-verify --allow-empty -m run`,
|
|
921
|
+
`rm -f ${patch} ${tarball} ${fileList}`
|
|
922
|
+
]);
|
|
923
|
+
}
|
|
924
|
+
function snapshotKey(steps) {
|
|
925
|
+
const text = (list) => list.flatMap(({ label, script, secrets }) => [label, script, `secrets=${(secrets ?? []).toSorted().join(",")}`]);
|
|
926
|
+
return createHash("sha256").update(
|
|
927
|
+
[
|
|
928
|
+
`format=${SNAPSHOT_FORMAT}`,
|
|
929
|
+
...text(steps.toolchains),
|
|
930
|
+
baseIndexScript("<base>", "<staging>"),
|
|
931
|
+
...text(steps.prebuild)
|
|
932
|
+
].join("\0")
|
|
933
|
+
).digest("hex");
|
|
934
|
+
}
|
|
935
|
+
async function snapshotStepsAt(checkout, request2) {
|
|
936
|
+
const context = baseStepContext(checkout, request2);
|
|
937
|
+
const { snapshot, secrets } = request2.recipe;
|
|
938
|
+
const toolchains = await resolveSteps(snapshot.toolchains, context, secrets);
|
|
939
|
+
if (!toolchains.ok) return { ok: false, path: ["snapshot", "toolchains"], problem: toolchains.problem };
|
|
940
|
+
const prebuild = await resolveSteps(snapshot.prebuild, context, secrets);
|
|
941
|
+
if (!prebuild.ok) return { ok: false, path: ["snapshot", "prebuild"], problem: prebuild.problem };
|
|
942
|
+
return {
|
|
943
|
+
ok: true,
|
|
944
|
+
toolchains: toolchains.steps,
|
|
945
|
+
prebuild: prebuild.steps,
|
|
946
|
+
key: snapshotKey({ toolchains: toolchains.steps, prebuild: prebuild.steps })
|
|
947
|
+
};
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
// src/runner/live/sandbox-errors.ts
|
|
951
|
+
function apiStatus(error) {
|
|
952
|
+
if (typeof error !== "object" || error === null) return void 0;
|
|
953
|
+
const response = error.response;
|
|
954
|
+
if (typeof response !== "object" || response === null) return void 0;
|
|
955
|
+
const status = response.status;
|
|
956
|
+
return typeof status === "number" ? status : void 0;
|
|
957
|
+
}
|
|
958
|
+
function isAbortError(error) {
|
|
959
|
+
return typeof error === "object" && error !== null && error.name === "AbortError";
|
|
960
|
+
}
|
|
961
|
+
function sandboxFailure(error, signal) {
|
|
962
|
+
if (signal?.aborted === true || isAbortError(error)) return { kind: "aborted" };
|
|
963
|
+
return { kind: "api", status: apiStatus(error), message: error instanceof Error ? error.message : String(error) };
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
// src/runner/live/sandbox-gateway.ts
|
|
967
|
+
var TERMINATE_GRACE_MS = 1e4;
|
|
968
|
+
var KILL_GRACE_MS = 5e3;
|
|
969
|
+
var STDERR_MESSAGE_CHARS = 1e3;
|
|
970
|
+
var SNAPSHOT_GONE_STATUS = 410;
|
|
971
|
+
function liveRunnerSandboxGateway() {
|
|
972
|
+
let loading;
|
|
973
|
+
const sdk = () => loading ??= import("@vercel/sandbox");
|
|
974
|
+
const held = /* @__PURE__ */ new WeakMap();
|
|
975
|
+
const holding = (sandbox) => {
|
|
976
|
+
const found = held.get(sandbox);
|
|
977
|
+
if (found === void 0) throw new Error(`liveRunnerSandboxGateway: sandbox ${sandbox.name} isn't one it started`);
|
|
978
|
+
return found;
|
|
979
|
+
};
|
|
980
|
+
const adopt = (sandbox, role, timeoutMs) => {
|
|
981
|
+
const handle = Object.freeze({ name: sandbox.name, role, timeoutMs });
|
|
982
|
+
held.set(handle, { sandbox, staging: void 0, running: /* @__PURE__ */ new Set(), starting: /* @__PURE__ */ new Set(), keeping: false });
|
|
983
|
+
return handle;
|
|
984
|
+
};
|
|
985
|
+
return {
|
|
986
|
+
async startBuildSandbox(access, request2, signal) {
|
|
987
|
+
try {
|
|
988
|
+
const { Sandbox } = await sdk();
|
|
989
|
+
const sandbox = await Sandbox.create({
|
|
990
|
+
...credentials(access),
|
|
991
|
+
// oxlint-disable-next-line typescript/no-deprecated -- the recipe names a runtime; moving to `image` changes the recipe format.
|
|
992
|
+
runtime: request2.runtime,
|
|
993
|
+
...placement(request2),
|
|
994
|
+
...signal === void 0 ? {} : { signal }
|
|
995
|
+
});
|
|
996
|
+
return { ok: true, value: adopt(sandbox, "snapshot-build", request2.timeoutMs) };
|
|
997
|
+
} catch (error) {
|
|
998
|
+
return { ok: false, failure: sandboxFailure(error, signal) };
|
|
999
|
+
}
|
|
1000
|
+
},
|
|
1001
|
+
async startRunnerSandbox(access, request2, signal) {
|
|
1002
|
+
try {
|
|
1003
|
+
const { Sandbox } = await sdk();
|
|
1004
|
+
const sandbox = await Sandbox.create({
|
|
1005
|
+
...credentials(access),
|
|
1006
|
+
source: { type: "snapshot", snapshotId: request2.snapshotId },
|
|
1007
|
+
...placement(request2),
|
|
1008
|
+
...signal === void 0 ? {} : { signal }
|
|
1009
|
+
});
|
|
1010
|
+
return { ok: true, value: adopt(sandbox, "runner", request2.timeoutMs) };
|
|
1011
|
+
} catch (error) {
|
|
1012
|
+
const failure = sandboxFailure(error, signal);
|
|
1013
|
+
if (failure.kind === "api" && apiStatus(error) === SNAPSHOT_GONE_STATUS)
|
|
1014
|
+
return { ok: false, failure: { kind: "snapshot-gone", message: failure.message } };
|
|
1015
|
+
return { ok: false, failure };
|
|
1016
|
+
}
|
|
1017
|
+
},
|
|
1018
|
+
async upload(sandbox, files, signal) {
|
|
1019
|
+
const holder = holding(sandbox);
|
|
1020
|
+
try {
|
|
1021
|
+
const directory = await stagingDirectory(holder, signal);
|
|
1022
|
+
if (typeof directory !== "string") return { ok: false, failure: directory };
|
|
1023
|
+
await holder.sandbox.writeFiles(writes(directory, files), signal === void 0 ? void 0 : { signal });
|
|
1024
|
+
return { ok: true, value: { directory } };
|
|
1025
|
+
} catch (error) {
|
|
1026
|
+
return { ok: false, failure: sandboxFailure(error, signal) };
|
|
1027
|
+
}
|
|
1028
|
+
},
|
|
1029
|
+
async runScript(sandbox, request2, onOutput, signal) {
|
|
1030
|
+
const holder = holding(sandbox);
|
|
1031
|
+
try {
|
|
1032
|
+
const command = await startDetached(holder, {
|
|
1033
|
+
cmd: "bash",
|
|
1034
|
+
args: ["-lc", request2.script],
|
|
1035
|
+
cwd: SANDBOX_ROOT,
|
|
1036
|
+
env: { ...request2.env },
|
|
1037
|
+
...signal === void 0 ? {} : { signal }
|
|
1038
|
+
});
|
|
1039
|
+
if (command === void 0) return { ok: false, failure: { kind: "aborted" } };
|
|
1040
|
+
return { ok: true, value: await follow(holder, command, onOutput, signal) };
|
|
1041
|
+
} catch (error) {
|
|
1042
|
+
return { ok: false, failure: sandboxFailure(error, signal) };
|
|
1043
|
+
}
|
|
1044
|
+
},
|
|
1045
|
+
async loginPath(sandbox, signal) {
|
|
1046
|
+
const holder = holding(sandbox);
|
|
1047
|
+
try {
|
|
1048
|
+
const finished = await holder.sandbox.runCommand({
|
|
1049
|
+
cmd: "bash",
|
|
1050
|
+
args: ["-lc", 'printf %s "$PATH"'],
|
|
1051
|
+
...signal === void 0 ? {} : { signal }
|
|
1052
|
+
});
|
|
1053
|
+
if (finished.exitCode !== 0)
|
|
1054
|
+
return {
|
|
1055
|
+
ok: false,
|
|
1056
|
+
failure: { kind: "api", status: void 0, message: `reading the login PATH exited ${finished.exitCode}` }
|
|
1057
|
+
};
|
|
1058
|
+
return { ok: true, value: await finished.stdout(signal === void 0 ? void 0 : { signal }) };
|
|
1059
|
+
} catch (error) {
|
|
1060
|
+
return { ok: false, failure: sandboxFailure(error, signal) };
|
|
1061
|
+
}
|
|
1062
|
+
},
|
|
1063
|
+
async runCommand(sandbox, request2, onOutput, kill) {
|
|
1064
|
+
const holder = holding(sandbox);
|
|
1065
|
+
if (kill.aborted) return { ok: false, failure: { kind: "aborted" } };
|
|
1066
|
+
try {
|
|
1067
|
+
const cmd = await resolveExecutable(holder, request2);
|
|
1068
|
+
if (kill.aborted) return { ok: false, failure: { kind: "aborted" } };
|
|
1069
|
+
const command = await startDetached(holder, {
|
|
1070
|
+
cmd,
|
|
1071
|
+
args: [...request2.args],
|
|
1072
|
+
cwd: request2.cwd,
|
|
1073
|
+
env: { ...request2.env }
|
|
1074
|
+
});
|
|
1075
|
+
if (command === void 0) return { ok: false, failure: { kind: "aborted" } };
|
|
1076
|
+
const terminate = () => {
|
|
1077
|
+
command.kill("SIGTERM").catch(() => {
|
|
1078
|
+
});
|
|
1079
|
+
};
|
|
1080
|
+
if (kill.aborted) terminate();
|
|
1081
|
+
else kill.addEventListener("abort", terminate, { once: true });
|
|
1082
|
+
try {
|
|
1083
|
+
return { ok: true, value: await follow(holder, command, onOutput, kill) };
|
|
1084
|
+
} finally {
|
|
1085
|
+
kill.removeEventListener("abort", terminate);
|
|
1086
|
+
}
|
|
1087
|
+
} catch (error) {
|
|
1088
|
+
return { ok: false, failure: sandboxFailure(error, kill) };
|
|
1089
|
+
}
|
|
1090
|
+
},
|
|
1091
|
+
async followTestEvents(sandbox, request2, onOutput, stop) {
|
|
1092
|
+
const holder = holding(sandbox);
|
|
1093
|
+
if (stop.aborted) return { ok: true };
|
|
1094
|
+
try {
|
|
1095
|
+
const command = await startDetached(holder, { cmd: "tail", args: ["-n", "+1", "-F", request2.path] });
|
|
1096
|
+
if (command === void 0) return { ok: true };
|
|
1097
|
+
const end = () => {
|
|
1098
|
+
command.kill("SIGTERM").catch(() => {
|
|
1099
|
+
});
|
|
1100
|
+
};
|
|
1101
|
+
if (stop.aborted) end();
|
|
1102
|
+
else stop.addEventListener("abort", end, { once: true });
|
|
1103
|
+
try {
|
|
1104
|
+
await follow(
|
|
1105
|
+
holder,
|
|
1106
|
+
command,
|
|
1107
|
+
(chunk) => {
|
|
1108
|
+
if (chunk.stream === "stdout") onOutput(chunk);
|
|
1109
|
+
},
|
|
1110
|
+
stop
|
|
1111
|
+
);
|
|
1112
|
+
} finally {
|
|
1113
|
+
stop.removeEventListener("abort", end);
|
|
1114
|
+
}
|
|
1115
|
+
return { ok: true };
|
|
1116
|
+
} catch (error) {
|
|
1117
|
+
const failure = sandboxFailure(error, stop);
|
|
1118
|
+
return failure.kind === "aborted" ? { ok: true } : { ok: false, failure };
|
|
1119
|
+
}
|
|
1120
|
+
},
|
|
1121
|
+
async readTestEvents(sandbox, request2, onOutput, signal) {
|
|
1122
|
+
const holder = holding(sandbox);
|
|
1123
|
+
if (signal?.aborted === true) return { ok: false, failure: { kind: "aborted" } };
|
|
1124
|
+
try {
|
|
1125
|
+
const command = await startDetached(holder, {
|
|
1126
|
+
cmd: "bash",
|
|
1127
|
+
args: [
|
|
1128
|
+
"-c",
|
|
1129
|
+
'test -e "$1" || exit 0; exec tail -n +"$2" -- "$1"',
|
|
1130
|
+
"_",
|
|
1131
|
+
request2.path,
|
|
1132
|
+
String(request2.fromLine)
|
|
1133
|
+
]
|
|
1134
|
+
});
|
|
1135
|
+
if (command === void 0) return { ok: false, failure: { kind: "aborted" } };
|
|
1136
|
+
const end = () => {
|
|
1137
|
+
command.kill("SIGTERM").catch(() => {
|
|
1138
|
+
});
|
|
1139
|
+
};
|
|
1140
|
+
if (isAborted(signal)) end();
|
|
1141
|
+
else signal?.addEventListener("abort", end, { once: true });
|
|
1142
|
+
let stderr = "";
|
|
1143
|
+
try {
|
|
1144
|
+
const exit = await follow(
|
|
1145
|
+
holder,
|
|
1146
|
+
command,
|
|
1147
|
+
(chunk) => {
|
|
1148
|
+
if (chunk.stream === "stdout") onOutput(chunk);
|
|
1149
|
+
else if (stderr.length < STDERR_MESSAGE_CHARS)
|
|
1150
|
+
stderr += chunk.data.slice(0, STDERR_MESSAGE_CHARS - stderr.length);
|
|
1151
|
+
},
|
|
1152
|
+
signal
|
|
1153
|
+
);
|
|
1154
|
+
if (exit.exitCode === 0) return { ok: true };
|
|
1155
|
+
const reason = stderr.trim();
|
|
1156
|
+
return {
|
|
1157
|
+
ok: false,
|
|
1158
|
+
failure: {
|
|
1159
|
+
kind: "api",
|
|
1160
|
+
status: void 0,
|
|
1161
|
+
message: `reading the test events file exited ${exit.exitCode ?? "without a code"}${reason === "" ? "" : `: ${reason}`}`
|
|
1162
|
+
}
|
|
1163
|
+
};
|
|
1164
|
+
} finally {
|
|
1165
|
+
signal?.removeEventListener("abort", end);
|
|
1166
|
+
}
|
|
1167
|
+
} catch (error) {
|
|
1168
|
+
return { ok: false, failure: sandboxFailure(error, signal) };
|
|
1169
|
+
}
|
|
1170
|
+
},
|
|
1171
|
+
async saveSnapshot(sandbox, request2) {
|
|
1172
|
+
const holder = holding(sandbox);
|
|
1173
|
+
try {
|
|
1174
|
+
const snapshot = await holder.sandbox.snapshot({ expiration: request2.expirationMs });
|
|
1175
|
+
if (snapshot.status !== "created")
|
|
1176
|
+
return {
|
|
1177
|
+
ok: false,
|
|
1178
|
+
failure: {
|
|
1179
|
+
kind: "api",
|
|
1180
|
+
status: void 0,
|
|
1181
|
+
message: `snapshot ${snapshot.snapshotId} is ${snapshot.status}`
|
|
1182
|
+
}
|
|
1183
|
+
};
|
|
1184
|
+
return {
|
|
1185
|
+
ok: true,
|
|
1186
|
+
value: {
|
|
1187
|
+
snapshotId: snapshot.snapshotId,
|
|
1188
|
+
expiresAt: snapshot.expiresAt?.toISOString(),
|
|
1189
|
+
sizeBytes: snapshot.sizeBytes
|
|
1190
|
+
}
|
|
1191
|
+
};
|
|
1192
|
+
} catch (error) {
|
|
1193
|
+
return { ok: false, failure: sandboxFailure(error, void 0) };
|
|
1194
|
+
}
|
|
1195
|
+
},
|
|
1196
|
+
async keepRunning(sandbox, request2) {
|
|
1197
|
+
const holder = holding(sandbox);
|
|
1198
|
+
holder.keeping = true;
|
|
1199
|
+
await Promise.allSettled(holder.starting);
|
|
1200
|
+
const stillRunning = (await Promise.all([...holder.running].map((command) => endProcess(holder, command)))).filter((ended2) => !ended2).length;
|
|
1201
|
+
if (stillRunning > 0)
|
|
1202
|
+
return {
|
|
1203
|
+
ok: false,
|
|
1204
|
+
failure: {
|
|
1205
|
+
kind: "processes-running",
|
|
1206
|
+
message: `${stillRunning} ${stillRunning === 1 ? "process" : "processes"} the run started didn't end after SIGKILL`
|
|
1207
|
+
}
|
|
1208
|
+
};
|
|
1209
|
+
try {
|
|
1210
|
+
const stopsAt = holder.sandbox.expiresAt;
|
|
1211
|
+
const short = request2.until.getTime() - (stopsAt?.getTime() ?? Date.now());
|
|
1212
|
+
if (short <= 0 && stopsAt !== void 0) return { ok: true, value: { stopsAt } };
|
|
1213
|
+
await holder.sandbox.extendTimeout(short);
|
|
1214
|
+
return { ok: true, value: { stopsAt: holder.sandbox.expiresAt ?? request2.until } };
|
|
1215
|
+
} catch (error) {
|
|
1216
|
+
return { ok: false, failure: sandboxFailure(error, void 0) };
|
|
1217
|
+
}
|
|
1218
|
+
},
|
|
1219
|
+
async stop(sandbox) {
|
|
1220
|
+
const holder = holding(sandbox);
|
|
1221
|
+
try {
|
|
1222
|
+
await holder.sandbox.stop();
|
|
1223
|
+
return { ok: true };
|
|
1224
|
+
} catch (error) {
|
|
1225
|
+
return { ok: false, failure: sandboxFailure(error, void 0) };
|
|
1226
|
+
}
|
|
1227
|
+
},
|
|
1228
|
+
async delete(sandbox) {
|
|
1229
|
+
const holder = holding(sandbox);
|
|
1230
|
+
try {
|
|
1231
|
+
await holder.sandbox.delete({ deleteOrphanSnapshots: false });
|
|
1232
|
+
return { ok: true };
|
|
1233
|
+
} catch (error) {
|
|
1234
|
+
return { ok: false, failure: sandboxFailure(error, void 0) };
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
};
|
|
1238
|
+
}
|
|
1239
|
+
function credentials(access) {
|
|
1240
|
+
return { token: access.credential.reveal(), teamId: access.teamId, projectId: access.projectId };
|
|
1241
|
+
}
|
|
1242
|
+
function placement(request2) {
|
|
1243
|
+
return {
|
|
1244
|
+
region: request2.region,
|
|
1245
|
+
resources: { vcpus: request2.vcpus },
|
|
1246
|
+
timeout: request2.timeoutMs,
|
|
1247
|
+
persistent: false,
|
|
1248
|
+
tags: { ...request2.tags }
|
|
1249
|
+
};
|
|
1250
|
+
}
|
|
1251
|
+
function writes(directory, files) {
|
|
1252
|
+
return files.map((file) => ({ path: `${directory}/${file.name}`, content: file.content }));
|
|
1253
|
+
}
|
|
1254
|
+
async function stagingDirectory(holder, signal) {
|
|
1255
|
+
if (holder.staging !== void 0) return holder.staging;
|
|
1256
|
+
const made = await holder.sandbox.runCommand({
|
|
1257
|
+
cmd: "mktemp",
|
|
1258
|
+
args: ["-d", "-t", "storm-runner.XXXXXXXX"],
|
|
1259
|
+
...signal === void 0 ? {} : { signal }
|
|
1260
|
+
});
|
|
1261
|
+
if (made.exitCode !== 0)
|
|
1262
|
+
return { kind: "api", status: void 0, message: `mktemp exited ${made.exitCode} making a staging directory` };
|
|
1263
|
+
const directory = (await made.stdout(signal === void 0 ? void 0 : { signal })).trim();
|
|
1264
|
+
holder.staging = directory;
|
|
1265
|
+
return directory;
|
|
1266
|
+
}
|
|
1267
|
+
async function resolveExecutable(holder, request2) {
|
|
1268
|
+
if (request2.cmd.includes("/")) return request2.cmd;
|
|
1269
|
+
const found = await holder.sandbox.runCommand({
|
|
1270
|
+
cmd: "bash",
|
|
1271
|
+
args: ["-c", 'command -v -- "$1"', "_", request2.cmd],
|
|
1272
|
+
cwd: request2.cwd,
|
|
1273
|
+
env: { ...request2.env }
|
|
1274
|
+
});
|
|
1275
|
+
if (found.exitCode !== 0) return request2.cmd;
|
|
1276
|
+
const path = (await found.stdout()).trim();
|
|
1277
|
+
return path.startsWith("/") ? path : request2.cmd;
|
|
1278
|
+
}
|
|
1279
|
+
async function startDetached(holder, params) {
|
|
1280
|
+
if (holder.keeping) return void 0;
|
|
1281
|
+
const starting = holder.sandbox.runCommand({ ...params, detached: true });
|
|
1282
|
+
holder.starting.add(starting);
|
|
1283
|
+
try {
|
|
1284
|
+
const command = await starting;
|
|
1285
|
+
holder.running.add(command);
|
|
1286
|
+
return command;
|
|
1287
|
+
} finally {
|
|
1288
|
+
holder.starting.delete(starting);
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
async function follow(holder, command, onOutput, signal) {
|
|
1292
|
+
const options = signal === void 0 ? void 0 : { signal };
|
|
1293
|
+
for await (const log of command.logs(options)) onOutput({ stream: log.stream, data: log.data });
|
|
1294
|
+
const finished = await command.wait(options);
|
|
1295
|
+
holder.running.delete(command);
|
|
1296
|
+
return { exitCode: typeof finished.exitCode === "number" ? finished.exitCode : null };
|
|
1297
|
+
}
|
|
1298
|
+
async function endProcess(holder, command) {
|
|
1299
|
+
for (const [signal, graceMs] of [
|
|
1300
|
+
["SIGTERM", TERMINATE_GRACE_MS],
|
|
1301
|
+
["SIGKILL", KILL_GRACE_MS]
|
|
1302
|
+
]) {
|
|
1303
|
+
await command.kill(signal).catch(() => void 0);
|
|
1304
|
+
if (await endsWithin(command, graceMs)) {
|
|
1305
|
+
holder.running.delete(command);
|
|
1306
|
+
return true;
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
return false;
|
|
1310
|
+
}
|
|
1311
|
+
async function endsWithin(command, ms) {
|
|
1312
|
+
const timeout = new AbortController();
|
|
1313
|
+
const timer = setTimeout(() => timeout.abort(), ms);
|
|
1314
|
+
try {
|
|
1315
|
+
await command.wait({ signal: timeout.signal });
|
|
1316
|
+
return true;
|
|
1317
|
+
} catch {
|
|
1318
|
+
return false;
|
|
1319
|
+
} finally {
|
|
1320
|
+
clearTimeout(timer);
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
function isAborted(signal) {
|
|
1324
|
+
return signal?.aborted === true;
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1327
|
+
// src/runner/live/terminal.ts
|
|
1328
|
+
function liveRunnerTerminal(options) {
|
|
1329
|
+
const stdout = options.stdout ?? process.stdout;
|
|
1330
|
+
const stderr = options.stderr ?? process.stderr;
|
|
1331
|
+
let failed = false;
|
|
1332
|
+
let listening = false;
|
|
1333
|
+
const fail = () => {
|
|
1334
|
+
failed = true;
|
|
1335
|
+
};
|
|
1336
|
+
const write = (stream, text) => {
|
|
1337
|
+
if (failed) return;
|
|
1338
|
+
if (!listening) {
|
|
1339
|
+
stdout.on("error", fail);
|
|
1340
|
+
stderr.on("error", fail);
|
|
1341
|
+
listening = true;
|
|
1342
|
+
}
|
|
1343
|
+
try {
|
|
1344
|
+
stream.write(text);
|
|
1345
|
+
} catch {
|
|
1346
|
+
fail();
|
|
1347
|
+
}
|
|
1348
|
+
};
|
|
1349
|
+
return {
|
|
1350
|
+
color: stdout.isTTY === true && options.env["NO_COLOR"] === void 0,
|
|
1351
|
+
writeStdout: (text) => write(stdout, text),
|
|
1352
|
+
writeStderr: (text) => write(stderr, text)
|
|
1353
|
+
};
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1356
|
+
// src/runner/live/snapshot-cache-gateway.ts
|
|
1357
|
+
import { randomBytes } from "node:crypto";
|
|
1358
|
+
import { mkdir, readdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
|
|
1359
|
+
import { join } from "node:path";
|
|
1360
|
+
|
|
1361
|
+
// src/runner/snapshot-cache.ts
|
|
1362
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
1363
|
+
var RUNNER_SNAPSHOTS_SUBPATH = ["runner", "snapshots"];
|
|
1364
|
+
var SNAPSHOT_EXPIRATION_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
1365
|
+
var SNAPSHOT_MIN_REMAINING_MS = 60 * 60 * 1e3;
|
|
1366
|
+
function snapshotEntryIdentity(entry) {
|
|
1367
|
+
return createHash2("sha256").update(
|
|
1368
|
+
[
|
|
1369
|
+
entry.teamId,
|
|
1370
|
+
entry.projectId,
|
|
1371
|
+
entry.region,
|
|
1372
|
+
entry.runtime,
|
|
1373
|
+
entry.recipeName,
|
|
1374
|
+
entry.snapshotKey,
|
|
1375
|
+
entry.base,
|
|
1376
|
+
...isBranchEntry(entry) ? [entry.branch, entry.repoRoot] : []
|
|
1377
|
+
].join("\0")
|
|
1378
|
+
).digest("hex").slice(0, 32);
|
|
1379
|
+
}
|
|
1380
|
+
function isBranchEntry(entry) {
|
|
1381
|
+
return entry.branch !== void 0 && entry.head !== void 0 && entry.repoRoot !== void 0;
|
|
1382
|
+
}
|
|
1383
|
+
function snapshotEntryFileName(entry) {
|
|
1384
|
+
return `${snapshotEntryIdentity(entry)}.json`;
|
|
1385
|
+
}
|
|
1386
|
+
function isExpiredEntry(entry, now) {
|
|
1387
|
+
return Date.parse(entry.expiresAt) <= now.getTime();
|
|
1388
|
+
}
|
|
1389
|
+
function hasTimeLeft(entry, now) {
|
|
1390
|
+
return Date.parse(entry.expiresAt) - now.getTime() > SNAPSHOT_MIN_REMAINING_MS;
|
|
1391
|
+
}
|
|
1392
|
+
async function findSnapshotCandidates(context, request2) {
|
|
1393
|
+
const { checkout, runnerSnapshots } = context;
|
|
1394
|
+
const { repoRoot, recipe, branch } = request2;
|
|
1395
|
+
const notes = [];
|
|
1396
|
+
const listed = await runnerSnapshots.listEntries();
|
|
1397
|
+
if (!listed.ok) return { candidates: [], notes: [{ kind: "cache-unreadable", failure: listed.failure }] };
|
|
1398
|
+
const now = context.clock.now();
|
|
1399
|
+
const live = [];
|
|
1400
|
+
for (const entry of listed.value.entries) {
|
|
1401
|
+
if (isExpiredEntry(entry, now)) {
|
|
1402
|
+
const removed = await runnerSnapshots.removeEntry(entry);
|
|
1403
|
+
if (!removed.ok) notes.push({ kind: "expired-entry-not-removed", entry, failure: removed.failure });
|
|
1404
|
+
continue;
|
|
1405
|
+
}
|
|
1406
|
+
if (entry.region === recipe.region && entry.runtime === recipe.runtime && entry.recipeName === recipe.name && (isBranchEntry(entry) ? entry.branch === branch && entry.repoRoot === repoRoot : entry.branch === void 0) && hasTimeLeft(entry, now))
|
|
1407
|
+
live.push(entry);
|
|
1408
|
+
}
|
|
1409
|
+
const keysByBase = /* @__PURE__ */ new Map();
|
|
1410
|
+
for (const base of new Set(live.map((entry) => entry.base))) {
|
|
1411
|
+
const contained = await checkout.contains({ repoRoot, ancestor: base, descendant: "HEAD" });
|
|
1412
|
+
if (!contained.ok) {
|
|
1413
|
+
notes.push({ kind: "candidate-check-failed", base, failure: contained.failure });
|
|
1414
|
+
continue;
|
|
1415
|
+
}
|
|
1416
|
+
if (!contained.value) continue;
|
|
1417
|
+
const steps = await snapshotStepsAt(checkout, { repoRoot, base, recipe });
|
|
1418
|
+
if (!steps.ok) {
|
|
1419
|
+
notes.push({ kind: "candidate-steps-failed", base, path: steps.path, problem: steps.problem });
|
|
1420
|
+
continue;
|
|
1421
|
+
}
|
|
1422
|
+
keysByBase.set(base, steps.key);
|
|
1423
|
+
}
|
|
1424
|
+
const matching = live.filter((entry) => keysByBase.get(entry.base) === entry.snapshotKey);
|
|
1425
|
+
const commitTimes = /* @__PURE__ */ new Map();
|
|
1426
|
+
for (const base of new Set(matching.map((entry) => entry.base))) {
|
|
1427
|
+
const time = await checkout.commitTime({ repoRoot, commit: base });
|
|
1428
|
+
if (time.ok) commitTimes.set(base, time.value);
|
|
1429
|
+
else notes.push({ kind: "candidate-check-failed", base, failure: time.failure });
|
|
1430
|
+
}
|
|
1431
|
+
const bases = [...commitTimes.keys()];
|
|
1432
|
+
const ancestors = new Map(bases.map((base) => [base, []]));
|
|
1433
|
+
for (const ancestor of bases)
|
|
1434
|
+
for (const descendant of bases) {
|
|
1435
|
+
if (ancestor === descendant) continue;
|
|
1436
|
+
const contained = await checkout.contains({ repoRoot, ancestor, descendant });
|
|
1437
|
+
if (!contained.ok) notes.push({ kind: "candidate-check-failed", base: ancestor, failure: contained.failure });
|
|
1438
|
+
else if (contained.value) ancestors.get(descendant)?.push(ancestor);
|
|
1439
|
+
}
|
|
1440
|
+
const candidates = matching.flatMap((entry) => {
|
|
1441
|
+
const commitTime2 = commitTimes.get(entry.base);
|
|
1442
|
+
return commitTime2 === void 0 ? [] : [{ entry, commitTime: commitTime2, ancestorBases: [...ancestors.get(entry.base) ?? []] }];
|
|
1443
|
+
});
|
|
1444
|
+
return { candidates, notes };
|
|
1445
|
+
}
|
|
1446
|
+
function pickSnapshot(candidates, owner) {
|
|
1447
|
+
const owned = candidates.filter(({ entry }) => entry.teamId === owner.teamId && entry.projectId === owner.projectId).toSorted((a, b) => b.commitTime - a.commitTime || Date.parse(b.entry.expiresAt) - Date.parse(a.entry.expiresAt));
|
|
1448
|
+
const nearest = owned.find(
|
|
1449
|
+
(candidate) => owned.every(
|
|
1450
|
+
(other) => other.entry.base === candidate.entry.base || candidate.ancestorBases.includes(other.entry.base)
|
|
1451
|
+
)
|
|
1452
|
+
) ?? owned[0];
|
|
1453
|
+
if (nearest === void 0) return void 0;
|
|
1454
|
+
return owned.filter(({ entry }) => entry.base === nearest.entry.base).toSorted(
|
|
1455
|
+
(a, b) => Number(isBranchEntry(b.entry)) - Number(isBranchEntry(a.entry)) || Date.parse(b.entry.expiresAt) - Date.parse(a.entry.expiresAt)
|
|
1456
|
+
)[0];
|
|
1457
|
+
}
|
|
1458
|
+
async function dropBranchSnapshots(runnerSnapshots, request2) {
|
|
1459
|
+
const { branch, repoRoot, owner, recipe } = request2;
|
|
1460
|
+
const listed = await runnerSnapshots.listEntries();
|
|
1461
|
+
if (!listed.ok) return { snapshotIds: [], failures: [listed.failure] };
|
|
1462
|
+
const snapshotIds = [];
|
|
1463
|
+
const failures = [];
|
|
1464
|
+
for (const entry of listed.value.entries) {
|
|
1465
|
+
if (!isBranchEntry(entry) || entry.branch !== branch || entry.repoRoot !== repoRoot || entry.teamId !== owner.teamId || entry.projectId !== owner.projectId || entry.region !== recipe.region || entry.runtime !== recipe.runtime || entry.recipeName !== recipe.name)
|
|
1466
|
+
continue;
|
|
1467
|
+
const removed = await runnerSnapshots.removeEntry(entry);
|
|
1468
|
+
if (removed.ok) snapshotIds.push(entry.snapshotId);
|
|
1469
|
+
else failures.push(removed.failure);
|
|
1470
|
+
}
|
|
1471
|
+
return { snapshotIds, failures };
|
|
1472
|
+
}
|
|
1473
|
+
|
|
1474
|
+
// src/runner/live/snapshot-records.ts
|
|
1475
|
+
import { z as z3 } from "zod";
|
|
1476
|
+
var isoTime = z3.string().refine((value) => !Number.isNaN(Date.parse(value)), { message: "not a time" });
|
|
1477
|
+
var nonEmpty = z3.string().min(1);
|
|
1478
|
+
var entrySchema = z3.object({
|
|
1479
|
+
version: z3.literal(1),
|
|
1480
|
+
teamId: nonEmpty,
|
|
1481
|
+
projectId: nonEmpty,
|
|
1482
|
+
region: nonEmpty,
|
|
1483
|
+
runtime: nonEmpty,
|
|
1484
|
+
recipeName: nonEmpty,
|
|
1485
|
+
snapshotKey: nonEmpty,
|
|
1486
|
+
base: nonEmpty,
|
|
1487
|
+
branch: nonEmpty.exactOptional(),
|
|
1488
|
+
head: nonEmpty.exactOptional(),
|
|
1489
|
+
repoRoot: nonEmpty.exactOptional(),
|
|
1490
|
+
snapshotId: nonEmpty,
|
|
1491
|
+
createdAt: isoTime,
|
|
1492
|
+
expiresAt: isoTime
|
|
1493
|
+
}).refine(
|
|
1494
|
+
(entry) => {
|
|
1495
|
+
const present = [entry.branch, entry.head, entry.repoRoot].filter((value) => value !== void 0).length;
|
|
1496
|
+
return present === 0 || present === 3;
|
|
1497
|
+
},
|
|
1498
|
+
{ message: "has some of branch, head and repoRoot without the others" }
|
|
1499
|
+
);
|
|
1500
|
+
function parseSnapshotEntry(text) {
|
|
1501
|
+
let json;
|
|
1502
|
+
try {
|
|
1503
|
+
json = JSON.parse(text);
|
|
1504
|
+
} catch {
|
|
1505
|
+
return { ok: false, reason: "not JSON" };
|
|
1506
|
+
}
|
|
1507
|
+
const version = typeof json === "object" && json !== null ? json.version : void 0;
|
|
1508
|
+
if (version !== 1) return { ok: false, reason: `unknown version ${JSON.stringify(version) ?? "(none)"}` };
|
|
1509
|
+
const parsed = entrySchema.safeParse(json);
|
|
1510
|
+
if (!parsed.success) {
|
|
1511
|
+
const issue = parsed.error.issues[0];
|
|
1512
|
+
const where2 = issue === void 0 || issue.path.length === 0 ? "the record" : issue.path.join(".");
|
|
1513
|
+
return { ok: false, reason: `${where2}: ${issue?.message ?? "invalid"}` };
|
|
1514
|
+
}
|
|
1515
|
+
const { version: _version, ...entry } = parsed.data;
|
|
1516
|
+
return { ok: true, value: entry };
|
|
1517
|
+
}
|
|
1518
|
+
function snapshotEntryText(entry) {
|
|
1519
|
+
const { teamId, projectId, region, runtime, recipeName, snapshotKey: snapshotKey2, base, branch, head: head2, repoRoot } = entry;
|
|
1520
|
+
const { snapshotId, createdAt, expiresAt } = entry;
|
|
1521
|
+
const record = {
|
|
1522
|
+
version: 1,
|
|
1523
|
+
teamId,
|
|
1524
|
+
projectId,
|
|
1525
|
+
region,
|
|
1526
|
+
runtime,
|
|
1527
|
+
recipeName,
|
|
1528
|
+
snapshotKey: snapshotKey2,
|
|
1529
|
+
base,
|
|
1530
|
+
...branch === void 0 ? {} : { branch },
|
|
1531
|
+
...head2 === void 0 ? {} : { head: head2 },
|
|
1532
|
+
...repoRoot === void 0 ? {} : { repoRoot },
|
|
1533
|
+
snapshotId,
|
|
1534
|
+
createdAt,
|
|
1535
|
+
expiresAt
|
|
1536
|
+
};
|
|
1537
|
+
return `${JSON.stringify(record, null, 2)}
|
|
1538
|
+
`;
|
|
1539
|
+
}
|
|
1540
|
+
|
|
1541
|
+
// src/runner/live/snapshot-cache-gateway.ts
|
|
1542
|
+
var DIRECTORY_MODE = 448;
|
|
1543
|
+
var FILE_MODE = 384;
|
|
1544
|
+
var ENTRY_FILE_NAME = /^[0-9a-f]{32}\.json$/;
|
|
1545
|
+
function liveRunnerSnapshotCacheGateway(options) {
|
|
1546
|
+
const { directory } = options;
|
|
1547
|
+
return {
|
|
1548
|
+
listEntries: () => listEntries(directory),
|
|
1549
|
+
writeEntry: (entry) => writeEntry(directory, entry),
|
|
1550
|
+
removeEntry: (entry) => removeEntry(directory, entry)
|
|
1551
|
+
};
|
|
1552
|
+
}
|
|
1553
|
+
function unavailableRunnerSnapshotCacheGateway(location, reason) {
|
|
1554
|
+
const failure = { path: location, message: reason };
|
|
1555
|
+
const fail = async () => ({ ok: false, failure });
|
|
1556
|
+
return { listEntries: fail, writeEntry: fail, removeEntry: fail };
|
|
1557
|
+
}
|
|
1558
|
+
async function listEntries(directory) {
|
|
1559
|
+
let names;
|
|
1560
|
+
try {
|
|
1561
|
+
names = await readdir(directory);
|
|
1562
|
+
} catch (error) {
|
|
1563
|
+
if (errorCode(error) === "ENOENT") return { ok: true, value: { directory, entries: [], unreadable: [] } };
|
|
1564
|
+
return { ok: false, failure: failureAt(directory, error) };
|
|
1565
|
+
}
|
|
1566
|
+
const entries = [];
|
|
1567
|
+
const unreadable = [];
|
|
1568
|
+
for (const name of names.filter((name2) => ENTRY_FILE_NAME.test(name2)).toSorted()) {
|
|
1569
|
+
const file = join(directory, name);
|
|
1570
|
+
let text;
|
|
1571
|
+
try {
|
|
1572
|
+
text = await readFile(file, "utf8");
|
|
1573
|
+
} catch (error) {
|
|
1574
|
+
if (errorCode(error) === "ENOENT") continue;
|
|
1575
|
+
unreadable.push({ file, reason: error instanceof Error ? error.message : String(error) });
|
|
1576
|
+
continue;
|
|
1577
|
+
}
|
|
1578
|
+
const parsed = parseSnapshotEntry(text);
|
|
1579
|
+
if (!parsed.ok) unreadable.push({ file, reason: parsed.reason });
|
|
1580
|
+
else if (snapshotEntryFileName(parsed.value) !== name)
|
|
1581
|
+
unreadable.push({ file, reason: "its name isn't its entry's identity" });
|
|
1582
|
+
else entries.push(parsed.value);
|
|
1583
|
+
}
|
|
1584
|
+
return { ok: true, value: { directory, entries, unreadable } };
|
|
1585
|
+
}
|
|
1586
|
+
async function writeEntry(directory, entry) {
|
|
1587
|
+
try {
|
|
1588
|
+
await mkdir(directory, { recursive: true, mode: DIRECTORY_MODE });
|
|
1589
|
+
} catch (error) {
|
|
1590
|
+
return { ok: false, failure: failureAt(directory, error) };
|
|
1591
|
+
}
|
|
1592
|
+
const name = snapshotEntryFileName(entry);
|
|
1593
|
+
const path = join(directory, name);
|
|
1594
|
+
const temp = join(directory, `.${name}.${process.pid}.${randomBytes(6).toString("hex")}.tmp`);
|
|
1595
|
+
try {
|
|
1596
|
+
await writeFile(temp, snapshotEntryText(entry), { mode: FILE_MODE, flag: "wx" });
|
|
1597
|
+
await rename(temp, path);
|
|
1598
|
+
return { ok: true };
|
|
1599
|
+
} catch (error) {
|
|
1600
|
+
await unlink(temp).catch(() => {
|
|
1601
|
+
});
|
|
1602
|
+
return { ok: false, failure: failureAt(path, error) };
|
|
1603
|
+
}
|
|
1604
|
+
}
|
|
1605
|
+
async function removeEntry(directory, entry) {
|
|
1606
|
+
const path = join(directory, snapshotEntryFileName(entry));
|
|
1607
|
+
try {
|
|
1608
|
+
await unlink(path);
|
|
1609
|
+
return { ok: true };
|
|
1610
|
+
} catch (error) {
|
|
1611
|
+
if (errorCode(error) === "ENOENT") return { ok: true };
|
|
1612
|
+
return { ok: false, failure: failureAt(path, error) };
|
|
1613
|
+
}
|
|
1614
|
+
}
|
|
1615
|
+
function errorCode(error) {
|
|
1616
|
+
const code = typeof error === "object" && error !== null ? error.code : void 0;
|
|
1617
|
+
return typeof code === "string" ? code : void 0;
|
|
1618
|
+
}
|
|
1619
|
+
function failureAt(path, error) {
|
|
1620
|
+
return { path, message: error instanceof Error ? error.message : String(error) };
|
|
1621
|
+
}
|
|
1622
|
+
|
|
1623
|
+
// src/runner/prepare.ts
|
|
1624
|
+
async function prepareRunner(context, request2) {
|
|
1625
|
+
const { checkout } = context;
|
|
1626
|
+
const { recipe } = request2;
|
|
1627
|
+
const root = await checkout.repositoryRoot({ cwd: request2.cwd });
|
|
1628
|
+
if (!root.ok) return { kind: "checkout-failed", failure: root.failure };
|
|
1629
|
+
const repoRoot = root.value;
|
|
1630
|
+
const head2 = await checkout.head({ repoRoot });
|
|
1631
|
+
if (!head2.ok) return { kind: "checkout-failed", failure: head2.failure };
|
|
1632
|
+
const resolved = await resolveBase(checkout, { repoRoot, baseRefs: recipe.baseRefs });
|
|
1633
|
+
if (resolved.kind === "failed") return { kind: "checkout-failed", failure: resolved.failure };
|
|
1634
|
+
if (resolved.kind === "no-base-ref") return resolved;
|
|
1635
|
+
const { base } = resolved;
|
|
1636
|
+
const submodules2 = await checkout.submodules({ repoRoot });
|
|
1637
|
+
if (!submodules2.ok) return { kind: "checkout-failed", failure: submodules2.failure };
|
|
1638
|
+
if (submodules2.value.length > 0) return { kind: "submodules", paths: [...submodules2.value] };
|
|
1639
|
+
const steps = await snapshotStepsAt(checkout, { repoRoot, base, recipe });
|
|
1640
|
+
if (!steps.ok) return { kind: "invalid-recipe", path: steps.path, problem: steps.problem };
|
|
1641
|
+
const vcpus = resolveVcpus(recipe, request2.vcpusRun);
|
|
1642
|
+
if (!vcpus.ok) return { kind: "invalid-recipe", path: ["vcpus"], problem: vcpus.problem };
|
|
1643
|
+
const upload = await checkout.assembleUpload({ repoRoot, base });
|
|
1644
|
+
if (!upload.ok) return { kind: "checkout-failed", failure: upload.failure };
|
|
1645
|
+
const cache = request2.rebuild ? { candidates: [], notes: [] } : await findSnapshotCandidates(context, { repoRoot, recipe, branch: head2.value.branch });
|
|
1646
|
+
return {
|
|
1647
|
+
kind: "ok",
|
|
1648
|
+
prepared: {
|
|
1649
|
+
recipe,
|
|
1650
|
+
repoRoot,
|
|
1651
|
+
head: head2.value,
|
|
1652
|
+
base,
|
|
1653
|
+
baseRef: resolved.ref,
|
|
1654
|
+
toolchains: steps.toolchains,
|
|
1655
|
+
prebuild: steps.prebuild,
|
|
1656
|
+
snapshotKey: steps.key,
|
|
1657
|
+
vcpus: vcpus.vcpus,
|
|
1658
|
+
upload: upload.value,
|
|
1659
|
+
candidates: cache.candidates,
|
|
1660
|
+
rebuild: request2.rebuild,
|
|
1661
|
+
notes: cache.notes,
|
|
1662
|
+
save: !request2.saveSnapshot ? null : head2.value.branch === null ? { kind: "skipped", reason: "detached-head" } : { kind: "branch", branch: head2.value.branch }
|
|
1663
|
+
}
|
|
1664
|
+
};
|
|
1665
|
+
}
|
|
1666
|
+
|
|
1667
|
+
// src/runner/ready.ts
|
|
1668
|
+
import { posix } from "node:path";
|
|
1669
|
+
|
|
1670
|
+
// src/runner/context.ts
|
|
1671
|
+
function runnerPurpose(recipeName) {
|
|
1672
|
+
return `storm-runner-${recipeName}`;
|
|
1673
|
+
}
|
|
1674
|
+
function runnerTags(recipeName, role, user) {
|
|
1675
|
+
return { purpose: runnerPurpose(recipeName), user, role };
|
|
1676
|
+
}
|
|
1677
|
+
|
|
1678
|
+
// src/runner/secrets.ts
|
|
1679
|
+
var RUNNER_SECRET_MIN_LENGTH = 8;
|
|
1680
|
+
function stepSecrets(values, names) {
|
|
1681
|
+
return Object.fromEntries(
|
|
1682
|
+
names.map((name) => {
|
|
1683
|
+
const value = ownValue(values, name);
|
|
1684
|
+
if (value === void 0) throw new Error(`stepSecrets: no value for runner secret ${name}`);
|
|
1685
|
+
return [name, value];
|
|
1686
|
+
})
|
|
1687
|
+
);
|
|
1688
|
+
}
|
|
1689
|
+
function readRunnerSecrets(recipe, env) {
|
|
1690
|
+
const values = [];
|
|
1691
|
+
const variables = [];
|
|
1692
|
+
for (const name of recipe.secrets) {
|
|
1693
|
+
const value = ownValue(env, name);
|
|
1694
|
+
if (value === void 0 || value === "") variables.push({ name, problem: "missing" });
|
|
1695
|
+
else if (/[\r\n]/.test(value)) variables.push({ name, problem: "multiline" });
|
|
1696
|
+
else if (value.length < RUNNER_SECRET_MIN_LENGTH) variables.push({ name, problem: "short" });
|
|
1697
|
+
else values.push([name, value]);
|
|
1698
|
+
}
|
|
1699
|
+
return variables.length === 0 ? { ok: true, values: Object.fromEntries(values) } : { ok: false, variables };
|
|
1700
|
+
}
|
|
1701
|
+
function ownValue(map, name) {
|
|
1702
|
+
return Object.hasOwn(map, name) ? map[name] : void 0;
|
|
1703
|
+
}
|
|
1704
|
+
|
|
1705
|
+
// src/runner/snapshot-build.ts
|
|
1706
|
+
var BUILD_SANDBOX_TIMEOUT_MS = 30 * 6e4;
|
|
1707
|
+
var BASE_INDEX_LABEL = "Committing the base's files";
|
|
1708
|
+
async function buildSnapshot(context, request2, control, progress) {
|
|
1709
|
+
const { prepared, access } = request2;
|
|
1710
|
+
const { recipe, repoRoot, base } = prepared;
|
|
1711
|
+
const { scope, signal } = control;
|
|
1712
|
+
const now = () => context.clock.now().getTime();
|
|
1713
|
+
const startedAt = now();
|
|
1714
|
+
await progress.emit({
|
|
1715
|
+
kind: "snapshot-build-started",
|
|
1716
|
+
base,
|
|
1717
|
+
reason: request2.reason,
|
|
1718
|
+
summary: recipe.snapshot.summary ?? [...prepared.toolchains, ...prepared.prebuild].map(({ label }) => label).join(", ")
|
|
1719
|
+
});
|
|
1720
|
+
const [started, archive] = await Promise.all([
|
|
1721
|
+
scope.startBuildSandbox(access, {
|
|
1722
|
+
region: recipe.region,
|
|
1723
|
+
runtime: recipe.runtime,
|
|
1724
|
+
vcpus: recipe.snapshot.vcpus,
|
|
1725
|
+
timeoutMs: BUILD_SANDBOX_TIMEOUT_MS,
|
|
1726
|
+
tags: runnerTags(recipe.name, "snapshot-build", request2.user)
|
|
1727
|
+
}),
|
|
1728
|
+
context.checkout.baseArchive({ repoRoot, base })
|
|
1729
|
+
]);
|
|
1730
|
+
if (!started.ok) return sandboxStop("start-build-sandbox", started.failure);
|
|
1731
|
+
const sandbox = started.value;
|
|
1732
|
+
await progress.emit({
|
|
1733
|
+
kind: "sandbox-started",
|
|
1734
|
+
role: "snapshot-build",
|
|
1735
|
+
name: sandbox.name,
|
|
1736
|
+
region: recipe.region,
|
|
1737
|
+
vcpus: recipe.snapshot.vcpus,
|
|
1738
|
+
ms: now() - startedAt
|
|
1739
|
+
});
|
|
1740
|
+
if (!archive.ok) return { kind: "failed", failure: { kind: "checkout-failed", failure: archive.failure } };
|
|
1741
|
+
const staged = await context.runnerSandboxes.upload(
|
|
1742
|
+
sandbox,
|
|
1743
|
+
[
|
|
1744
|
+
{ name: STAGED_FILES.baseTarball, content: archive.value.tarball },
|
|
1745
|
+
{ name: STAGED_FILES.baseFileList, content: archive.value.fileList }
|
|
1746
|
+
],
|
|
1747
|
+
signal
|
|
1748
|
+
);
|
|
1749
|
+
if (!staged.ok) return sandboxStop("upload", staged.failure);
|
|
1750
|
+
const recipeStep = ({ label, script, secrets }) => ({
|
|
1751
|
+
label,
|
|
1752
|
+
script,
|
|
1753
|
+
secrets: stepSecrets(request2.secrets, secrets)
|
|
1754
|
+
});
|
|
1755
|
+
const steps = [
|
|
1756
|
+
...prepared.toolchains.map(recipeStep),
|
|
1757
|
+
{ label: BASE_INDEX_LABEL, script: baseIndexScript(base, staged.value.directory) },
|
|
1758
|
+
...prepared.prebuild.map(recipeStep)
|
|
1759
|
+
];
|
|
1760
|
+
await progress.emit({ kind: "output-started", section: "snapshot", sandbox: sandbox.name, region: recipe.region });
|
|
1761
|
+
for (const step of steps) {
|
|
1762
|
+
const ran = await runStep(context, { sandbox, phase: "snapshot", ...step }, progress, signal);
|
|
1763
|
+
if (ran.kind === "succeeded") continue;
|
|
1764
|
+
const stop = ran.kind === "exited" ? {
|
|
1765
|
+
kind: "failed",
|
|
1766
|
+
failure: { kind: "snapshot-build-step-failed", label: step.label, exitCode: ran.exitCode, tail: ran.tail }
|
|
1767
|
+
} : sandboxStop("run-script", ran.failure);
|
|
1768
|
+
await progress.emit({
|
|
1769
|
+
kind: "output-ended",
|
|
1770
|
+
section: "snapshot",
|
|
1771
|
+
outcome: stop.kind === "aborted" ? "stopped" : "failed"
|
|
1772
|
+
});
|
|
1773
|
+
return stop;
|
|
1774
|
+
}
|
|
1775
|
+
await progress.emit({ kind: "output-ended", section: "snapshot", outcome: "finished" });
|
|
1776
|
+
if (signal.aborted) return { kind: "aborted" };
|
|
1777
|
+
await progress.emit({ kind: "snapshot-saving" });
|
|
1778
|
+
const saved = await scope.saveSnapshot(sandbox, { expirationMs: SNAPSHOT_EXPIRATION_MS });
|
|
1779
|
+
if (!saved.ok) return sandboxStop("save-snapshot", saved.failure);
|
|
1780
|
+
const savedAt = context.clock.now();
|
|
1781
|
+
const entry = {
|
|
1782
|
+
teamId: access.teamId,
|
|
1783
|
+
projectId: access.projectId,
|
|
1784
|
+
region: recipe.region,
|
|
1785
|
+
runtime: recipe.runtime,
|
|
1786
|
+
recipeName: recipe.name,
|
|
1787
|
+
snapshotKey: prepared.snapshotKey,
|
|
1788
|
+
base,
|
|
1789
|
+
snapshotId: saved.value.snapshotId,
|
|
1790
|
+
createdAt: savedAt.toISOString(),
|
|
1791
|
+
expiresAt: saved.value.expiresAt ?? new Date(savedAt.getTime() + SNAPSHOT_EXPIRATION_MS).toISOString()
|
|
1792
|
+
};
|
|
1793
|
+
const written = await context.runnerSnapshots.writeEntry(entry);
|
|
1794
|
+
if (!written.ok) await progress.emit({ kind: "snapshot-entry-not-written", failure: written.failure });
|
|
1795
|
+
const { branch } = prepared.head;
|
|
1796
|
+
if (request2.reason === "rebuild" && branch !== null) {
|
|
1797
|
+
const dropped = await dropBranchSnapshots(context.runnerSnapshots, { branch, repoRoot, owner: access, recipe });
|
|
1798
|
+
if (dropped.snapshotIds.length > 0)
|
|
1799
|
+
await progress.emit({ kind: "branch-snapshots-dropped", branch, snapshotIds: dropped.snapshotIds });
|
|
1800
|
+
for (const failure of dropped.failures)
|
|
1801
|
+
await progress.emit({ kind: "branch-snapshots-not-dropped", branch, failure });
|
|
1802
|
+
}
|
|
1803
|
+
const ms = now() - startedAt;
|
|
1804
|
+
await progress.emit({
|
|
1805
|
+
kind: "snapshot-built",
|
|
1806
|
+
snapshotId: entry.snapshotId,
|
|
1807
|
+
base,
|
|
1808
|
+
ms,
|
|
1809
|
+
sizeBytes: saved.value.sizeBytes
|
|
1810
|
+
});
|
|
1811
|
+
return { kind: "ok", value: { entry, ms, sizeBytes: saved.value.sizeBytes } };
|
|
1812
|
+
}
|
|
1813
|
+
|
|
1814
|
+
// src/runner/ready.ts
|
|
1815
|
+
var APPLY_LABEL = "Applying your changes";
|
|
1816
|
+
async function readyRunner(context, request2, control, progress) {
|
|
1817
|
+
const { prepared, access } = request2;
|
|
1818
|
+
const { recipe, repoRoot } = prepared;
|
|
1819
|
+
const { scope, signal } = control;
|
|
1820
|
+
const now = () => context.clock.now().getTime();
|
|
1821
|
+
if (signal.aborted) return { kind: "aborted" };
|
|
1822
|
+
const picked = prepared.rebuild ? void 0 : pickSnapshot(prepared.candidates, access);
|
|
1823
|
+
let entry;
|
|
1824
|
+
if (picked !== void 0) {
|
|
1825
|
+
entry = picked.entry;
|
|
1826
|
+
await progress.emit({
|
|
1827
|
+
kind: "snapshot-reused",
|
|
1828
|
+
snapshotId: entry.snapshotId,
|
|
1829
|
+
base: entry.base,
|
|
1830
|
+
branch: entry.branch ?? null,
|
|
1831
|
+
head: entry.head ?? null
|
|
1832
|
+
});
|
|
1833
|
+
} else {
|
|
1834
|
+
const built2 = await buildSnapshot(
|
|
1835
|
+
context,
|
|
1836
|
+
{
|
|
1837
|
+
prepared,
|
|
1838
|
+
access,
|
|
1839
|
+
user: request2.user,
|
|
1840
|
+
secrets: request2.secrets,
|
|
1841
|
+
reason: prepared.rebuild ? "rebuild" : "no-snapshot"
|
|
1842
|
+
},
|
|
1843
|
+
control,
|
|
1844
|
+
progress
|
|
1845
|
+
);
|
|
1846
|
+
if (built2.kind !== "ok") return built2;
|
|
1847
|
+
entry = built2.value.entry;
|
|
1848
|
+
}
|
|
1849
|
+
if (signal.aborted) return { kind: "aborted" };
|
|
1850
|
+
await progress.emit({ kind: "runner-sandbox-starting", snapshotId: entry.snapshotId });
|
|
1851
|
+
const startedAt = now();
|
|
1852
|
+
const started = await scope.startRunnerSandbox(access, {
|
|
1853
|
+
snapshotId: entry.snapshotId,
|
|
1854
|
+
region: recipe.region,
|
|
1855
|
+
vcpus: prepared.vcpus,
|
|
1856
|
+
timeoutMs: recipe.timeoutMinutes * 6e4,
|
|
1857
|
+
tags: runnerTags(recipe.name, "runner", request2.user)
|
|
1858
|
+
});
|
|
1859
|
+
if (!started.ok) {
|
|
1860
|
+
if (started.failure.kind === "snapshot-gone") {
|
|
1861
|
+
const removed = await context.runnerSnapshots.removeEntry(entry);
|
|
1862
|
+
return { kind: "snapshot-gone", entry, removal: removed.ok ? void 0 : removed.failure };
|
|
1863
|
+
}
|
|
1864
|
+
return sandboxStop("start-runner-sandbox", started.failure);
|
|
1865
|
+
}
|
|
1866
|
+
const sandbox = started.value;
|
|
1867
|
+
await progress.emit({
|
|
1868
|
+
kind: "sandbox-started",
|
|
1869
|
+
role: "runner",
|
|
1870
|
+
name: sandbox.name,
|
|
1871
|
+
region: recipe.region,
|
|
1872
|
+
vcpus: prepared.vcpus,
|
|
1873
|
+
ms: now() - startedAt
|
|
1874
|
+
});
|
|
1875
|
+
const changes = await uploadChanges(context, { prepared, sandbox, base: entry.base }, signal, progress);
|
|
1876
|
+
if (changes.kind !== "ok") return changes;
|
|
1877
|
+
const applied = await stage(
|
|
1878
|
+
context,
|
|
1879
|
+
{
|
|
1880
|
+
sandbox,
|
|
1881
|
+
phase: "apply",
|
|
1882
|
+
step: { label: APPLY_LABEL, script: applyScript(changes.value.directory) },
|
|
1883
|
+
region: recipe.region
|
|
1884
|
+
},
|
|
1885
|
+
signal,
|
|
1886
|
+
progress
|
|
1887
|
+
);
|
|
1888
|
+
if (applied.kind !== "ok") return applied;
|
|
1889
|
+
const loginPath = await context.runnerSandboxes.loginPath(sandbox, signal);
|
|
1890
|
+
if (!loginPath.ok) return sandboxStop("login-path", loginPath.failure);
|
|
1891
|
+
const installed = await stage(
|
|
1892
|
+
context,
|
|
1893
|
+
{
|
|
1894
|
+
sandbox,
|
|
1895
|
+
phase: "install",
|
|
1896
|
+
step: recipe.run.install,
|
|
1897
|
+
secrets: stepSecrets(request2.secrets, recipe.run.install.secrets),
|
|
1898
|
+
region: recipe.region
|
|
1899
|
+
},
|
|
1900
|
+
signal,
|
|
1901
|
+
progress
|
|
1902
|
+
);
|
|
1903
|
+
if (installed.kind !== "ok") return installed;
|
|
1904
|
+
const built = await stage(
|
|
1905
|
+
context,
|
|
1906
|
+
{
|
|
1907
|
+
sandbox,
|
|
1908
|
+
phase: "build",
|
|
1909
|
+
step: recipe.run.build,
|
|
1910
|
+
secrets: stepSecrets(request2.secrets, recipe.run.build.secrets),
|
|
1911
|
+
region: recipe.region
|
|
1912
|
+
},
|
|
1913
|
+
signal,
|
|
1914
|
+
progress
|
|
1915
|
+
);
|
|
1916
|
+
if (built.kind !== "ok") return built;
|
|
1917
|
+
return {
|
|
1918
|
+
kind: "ready",
|
|
1919
|
+
runner: {
|
|
1920
|
+
sandbox,
|
|
1921
|
+
startedFrom: entry,
|
|
1922
|
+
built: picked === void 0,
|
|
1923
|
+
buildMs: built.value,
|
|
1924
|
+
vcpus: prepared.vcpus,
|
|
1925
|
+
region: recipe.region,
|
|
1926
|
+
runtime: recipe.runtime,
|
|
1927
|
+
repoRoot,
|
|
1928
|
+
cwd: posix.join(SANDBOX_ROOT, recipe.cwd),
|
|
1929
|
+
env: recipe.env,
|
|
1930
|
+
loginPath: loginPath.value
|
|
1931
|
+
}
|
|
1932
|
+
};
|
|
1933
|
+
}
|
|
1934
|
+
async function uploadChanges(context, request2, signal, progress) {
|
|
1935
|
+
const { prepared } = request2;
|
|
1936
|
+
await progress.emit({ kind: "uploading" });
|
|
1937
|
+
const startedAt = context.clock.now().getTime();
|
|
1938
|
+
let upload = prepared.upload;
|
|
1939
|
+
if (request2.base !== prepared.base) {
|
|
1940
|
+
const assembled = await context.checkout.assembleUpload({ repoRoot: prepared.repoRoot, base: request2.base });
|
|
1941
|
+
if (!assembled.ok) return { kind: "failed", failure: { kind: "checkout-failed", failure: assembled.failure } };
|
|
1942
|
+
upload = assembled.value;
|
|
1943
|
+
}
|
|
1944
|
+
const files = stagedChanges(upload);
|
|
1945
|
+
const staged = await context.runnerSandboxes.upload(request2.sandbox, files, signal);
|
|
1946
|
+
if (!staged.ok) return sandboxStop("upload", staged.failure);
|
|
1947
|
+
const bytes = files.reduce((sum, file) => sum + file.content.byteLength, 0);
|
|
1948
|
+
await progress.emit({ kind: "uploaded", bytes, ms: context.clock.now().getTime() - startedAt });
|
|
1949
|
+
return { kind: "ok", value: { directory: staged.value.directory } };
|
|
1950
|
+
}
|
|
1951
|
+
function stagedChanges(upload) {
|
|
1952
|
+
const encoder = new TextEncoder();
|
|
1953
|
+
return [
|
|
1954
|
+
{ name: STAGED_FILES.patch, content: upload.patch },
|
|
1955
|
+
{
|
|
1956
|
+
name: STAGED_FILES.untrackedFileList,
|
|
1957
|
+
content: encoder.encode(upload.untracked.map((path) => `${path}\0`).join(""))
|
|
1958
|
+
},
|
|
1959
|
+
...upload.untrackedTarball === void 0 ? [] : [{ name: STAGED_FILES.untrackedTarball, content: upload.untrackedTarball }]
|
|
1960
|
+
];
|
|
1961
|
+
}
|
|
1962
|
+
async function stage(context, request2, signal, progress) {
|
|
1963
|
+
if (signal.aborted) return { kind: "aborted" };
|
|
1964
|
+
const { sandbox, phase, step } = request2;
|
|
1965
|
+
const section = phase === "apply" ? void 0 : phase;
|
|
1966
|
+
if (section !== void 0)
|
|
1967
|
+
await progress.emit({ kind: "output-started", section, sandbox: sandbox.name, region: request2.region });
|
|
1968
|
+
const ran = await runStep(
|
|
1969
|
+
context,
|
|
1970
|
+
{
|
|
1971
|
+
sandbox,
|
|
1972
|
+
phase,
|
|
1973
|
+
label: step.label,
|
|
1974
|
+
script: step.script,
|
|
1975
|
+
...request2.secrets === void 0 ? {} : { secrets: request2.secrets }
|
|
1976
|
+
},
|
|
1977
|
+
progress,
|
|
1978
|
+
signal
|
|
1979
|
+
);
|
|
1980
|
+
if (ran.kind === "succeeded") {
|
|
1981
|
+
if (section !== void 0) await progress.emit({ kind: "output-ended", section, outcome: "finished" });
|
|
1982
|
+
return { kind: "ok", value: ran.ms };
|
|
1983
|
+
}
|
|
1984
|
+
const stop = ran.kind === "exited" ? {
|
|
1985
|
+
kind: "failed",
|
|
1986
|
+
failure: { kind: `${phase}-failed`, label: step.label, exitCode: ran.exitCode, tail: ran.tail }
|
|
1987
|
+
} : sandboxStop("run-script", ran.failure);
|
|
1988
|
+
if (section !== void 0)
|
|
1989
|
+
await progress.emit({ kind: "output-ended", section, outcome: stop.kind === "aborted" ? "stopped" : "failed" });
|
|
1990
|
+
return stop;
|
|
1991
|
+
}
|
|
1992
|
+
|
|
1993
|
+
// src/runner/sandboxed-command.ts
|
|
1994
|
+
import { posix as posix2 } from "node:path";
|
|
1995
|
+
function sandboxedCommand(request2) {
|
|
1996
|
+
const [first = "", ...rest] = request2.argv.map((argument) => rewritePaths(argument, request2.repoRoot, SANDBOX_ROOT));
|
|
1997
|
+
const cmd = first.includes("/") && !first.startsWith("/") ? posix2.join(request2.cwd, first) : first;
|
|
1998
|
+
return { cmd, args: rest };
|
|
1999
|
+
}
|
|
2000
|
+
function sandboxEnvironment(request2) {
|
|
2001
|
+
const bins = [
|
|
2002
|
+
.../* @__PURE__ */ new Set([posix2.join(request2.cwd, "node_modules/.bin"), posix2.join(SANDBOX_ROOT, "node_modules/.bin")])
|
|
2003
|
+
];
|
|
2004
|
+
return {
|
|
2005
|
+
PATH: [...bins, request2.loginPath].filter((part) => part !== "").join(":"),
|
|
2006
|
+
NO_UPDATE_NOTIFIER: "1",
|
|
2007
|
+
...request2.color ? { FORCE_COLOR: "1" } : { NO_COLOR: "1" },
|
|
2008
|
+
...request2.env,
|
|
2009
|
+
[RUN_PAYLOAD_VARIABLE]: request2.runPayload
|
|
2010
|
+
};
|
|
2011
|
+
}
|
|
2012
|
+
var SANDBOX_TEST_EVENTS_PATH = "/tmp/storm-test-events.jsonl";
|
|
2013
|
+
async function runCommandInSandbox(context, request2, control, progress) {
|
|
2014
|
+
const { runner } = request2;
|
|
2015
|
+
const terminal = context.runnerTerminal;
|
|
2016
|
+
const command = sandboxedCommand({ argv: request2.argv, repoRoot: runner.repoRoot, cwd: runner.cwd });
|
|
2017
|
+
const env = sandboxEnvironment({
|
|
2018
|
+
cwd: runner.cwd,
|
|
2019
|
+
loginPath: runner.loginPath,
|
|
2020
|
+
color: terminal.color,
|
|
2021
|
+
env: runner.env,
|
|
2022
|
+
runPayload: request2.runPayload
|
|
2023
|
+
});
|
|
2024
|
+
await progress.emit({ kind: "command-output-started", sandbox: runner.sandbox.name, region: runner.region });
|
|
2025
|
+
const startedAt = context.clock.now().getTime();
|
|
2026
|
+
const splitters = { stdout: lineSplitter(), stderr: lineSplitter() };
|
|
2027
|
+
const write = (stream, text) => {
|
|
2028
|
+
if (text === "") return;
|
|
2029
|
+
const local = rewritePaths(text, SANDBOX_ROOT, runner.repoRoot);
|
|
2030
|
+
if (stream === "stdout") terminal.writeStdout(local);
|
|
2031
|
+
else terminal.writeStderr(local);
|
|
2032
|
+
};
|
|
2033
|
+
const following = followTestEvents(context, runner, request2.testEvents, control.kill);
|
|
2034
|
+
const ran = await context.runnerSandboxes.runCommand(
|
|
2035
|
+
runner.sandbox,
|
|
2036
|
+
{ cmd: command.cmd, args: command.args, cwd: runner.cwd, env },
|
|
2037
|
+
({ stream, data }) => write(stream, splitters[stream].push(data)),
|
|
2038
|
+
control.kill
|
|
2039
|
+
);
|
|
2040
|
+
const ms = context.clock.now().getTime() - startedAt;
|
|
2041
|
+
write("stdout", splitters.stdout.flush());
|
|
2042
|
+
write("stderr", splitters.stderr.flush());
|
|
2043
|
+
await following?.end(ran.ok && !control.kill.aborted);
|
|
2044
|
+
if (!ran.ok) {
|
|
2045
|
+
if (ran.failure.kind !== "aborted")
|
|
2046
|
+
return { kind: "failed", failure: sandboxApiFailure("run-command", ran.failure) };
|
|
2047
|
+
await progress.emit({ kind: "command-stopped", command: posix2.basename(command.cmd) });
|
|
2048
|
+
return { kind: "killed" };
|
|
2049
|
+
}
|
|
2050
|
+
return { kind: "exited", exitCode: ran.value.exitCode, ms };
|
|
2051
|
+
}
|
|
2052
|
+
function followTestEvents(context, runner, testEvents, kill) {
|
|
2053
|
+
if (testEvents === void 0) return void 0;
|
|
2054
|
+
const stop = new AbortController();
|
|
2055
|
+
const splitter = lineSplitter();
|
|
2056
|
+
let handed = 0;
|
|
2057
|
+
const hand = (lines) => {
|
|
2058
|
+
for (const line2 of lines) {
|
|
2059
|
+
handed += 1;
|
|
2060
|
+
testEvents.onLine(line2);
|
|
2061
|
+
}
|
|
2062
|
+
};
|
|
2063
|
+
const followed = context.runnerSandboxes.followTestEvents(
|
|
2064
|
+
runner.sandbox,
|
|
2065
|
+
{ path: SANDBOX_TEST_EVENTS_PATH },
|
|
2066
|
+
({ data }) => hand(splitLines(splitter.push(data))),
|
|
2067
|
+
stop.signal
|
|
2068
|
+
);
|
|
2069
|
+
return {
|
|
2070
|
+
async end(complete) {
|
|
2071
|
+
stop.abort();
|
|
2072
|
+
await followed;
|
|
2073
|
+
if (!complete) {
|
|
2074
|
+
hand(splitLines(splitter.flush()));
|
|
2075
|
+
return;
|
|
2076
|
+
}
|
|
2077
|
+
const reader = lineSplitter();
|
|
2078
|
+
let read = false;
|
|
2079
|
+
const result = await context.runnerSandboxes.readTestEvents(
|
|
2080
|
+
runner.sandbox,
|
|
2081
|
+
{ path: SANDBOX_TEST_EVENTS_PATH, fromLine: handed + 1 },
|
|
2082
|
+
({ data }) => {
|
|
2083
|
+
if (!read) {
|
|
2084
|
+
splitter.flush();
|
|
2085
|
+
read = true;
|
|
2086
|
+
}
|
|
2087
|
+
hand(splitLines(reader.push(data)));
|
|
2088
|
+
},
|
|
2089
|
+
kill
|
|
2090
|
+
);
|
|
2091
|
+
hand(splitLines(read ? reader.flush() : splitter.flush()));
|
|
2092
|
+
if (!result.ok && result.failure.kind === "api") testEvents.onIncomplete(result.failure.message);
|
|
2093
|
+
}
|
|
2094
|
+
};
|
|
2095
|
+
}
|
|
2096
|
+
|
|
2097
|
+
// src/runner/scope.ts
|
|
2098
|
+
var CREATE_SETTLE_MS = 2e4;
|
|
2099
|
+
var SNAPSHOT_SETTLE_MS = 2 * 6e4;
|
|
2100
|
+
function keptMs(plan) {
|
|
2101
|
+
return plan.kind === "keep" ? plan.ms : 0;
|
|
2102
|
+
}
|
|
2103
|
+
function runnerSandboxScope(context, progress, keep) {
|
|
2104
|
+
const { runnerSandboxes: sandboxes, timer, clock } = context;
|
|
2105
|
+
const live = /* @__PURE__ */ new Set();
|
|
2106
|
+
const creating2 = /* @__PURE__ */ new Set();
|
|
2107
|
+
const saving = /* @__PURE__ */ new Set();
|
|
2108
|
+
const notStopped = [];
|
|
2109
|
+
const notDeleted = [];
|
|
2110
|
+
let kept = null;
|
|
2111
|
+
let notKept = null;
|
|
2112
|
+
let closing;
|
|
2113
|
+
const track = (set, task) => {
|
|
2114
|
+
set.add(task);
|
|
2115
|
+
const forget = () => set.delete(task);
|
|
2116
|
+
void task.then(forget, forget);
|
|
2117
|
+
return task;
|
|
2118
|
+
};
|
|
2119
|
+
const remove = async (sandbox) => {
|
|
2120
|
+
const deleted = await sandboxes.delete(sandbox);
|
|
2121
|
+
if (!deleted.ok)
|
|
2122
|
+
notDeleted.push({ name: sandbox.name, role: sandbox.role, message: failureMessage(deleted.failure) });
|
|
2123
|
+
};
|
|
2124
|
+
const stopAndRemove = async (sandbox) => {
|
|
2125
|
+
const stopped = await sandboxes.stop(sandbox);
|
|
2126
|
+
if (!stopped.ok) {
|
|
2127
|
+
notStopped.push({
|
|
2128
|
+
name: sandbox.name,
|
|
2129
|
+
role: sandbox.role,
|
|
2130
|
+
timeoutMinutes: Math.round(sandbox.timeoutMs / 6e4),
|
|
2131
|
+
message: failureMessage(stopped.failure)
|
|
2132
|
+
});
|
|
2133
|
+
return;
|
|
2134
|
+
}
|
|
2135
|
+
await remove(sandbox);
|
|
2136
|
+
};
|
|
2137
|
+
const keepOrRemove = async (sandbox) => {
|
|
2138
|
+
if (sandbox.role !== "runner" || keep.keepMs <= 0) return await stopAndRemove(sandbox);
|
|
2139
|
+
const keeping = await sandboxes.keepRunning(sandbox, { until: new Date(clock.now().getTime() + keep.keepMs) });
|
|
2140
|
+
if (!keeping.ok) {
|
|
2141
|
+
notKept = { name: sandbox.name, message: failureMessage(keeping.failure) };
|
|
2142
|
+
return await stopAndRemove(sandbox);
|
|
2143
|
+
}
|
|
2144
|
+
kept = { name: sandbox.name, stopsAt: keeping.value.stopsAt.toISOString() };
|
|
2145
|
+
await progress.emit({ kind: "sandbox-kept", ...kept });
|
|
2146
|
+
};
|
|
2147
|
+
const owned = (start) => {
|
|
2148
|
+
if (closing !== void 0) return Promise.resolve({ ok: false, failure: { kind: "aborted" } });
|
|
2149
|
+
return track(
|
|
2150
|
+
creating2,
|
|
2151
|
+
(async () => {
|
|
2152
|
+
const started = await start();
|
|
2153
|
+
if (!started.ok) return started;
|
|
2154
|
+
if (closing !== void 0) {
|
|
2155
|
+
await stopAndRemove(started.value);
|
|
2156
|
+
return { ok: false, failure: { kind: "aborted" } };
|
|
2157
|
+
}
|
|
2158
|
+
live.add(started.value);
|
|
2159
|
+
return started;
|
|
2160
|
+
})()
|
|
2161
|
+
);
|
|
2162
|
+
};
|
|
2163
|
+
return {
|
|
2164
|
+
get closed() {
|
|
2165
|
+
return closing !== void 0;
|
|
2166
|
+
},
|
|
2167
|
+
startBuildSandbox: (access, request2) => owned(() => sandboxes.startBuildSandbox(access, request2)),
|
|
2168
|
+
startRunnerSandbox: (access, request2) => owned(() => sandboxes.startRunnerSandbox(access, request2)),
|
|
2169
|
+
saveSnapshot: (sandbox, request2) => track(
|
|
2170
|
+
saving,
|
|
2171
|
+
(async () => {
|
|
2172
|
+
const saved = await sandboxes.saveSnapshot(sandbox, request2);
|
|
2173
|
+
if (saved.ok && live.delete(sandbox)) await remove(sandbox);
|
|
2174
|
+
return saved;
|
|
2175
|
+
})()
|
|
2176
|
+
),
|
|
2177
|
+
close() {
|
|
2178
|
+
closing ??= (async () => {
|
|
2179
|
+
if (saving.size > 0) await progress.emit({ kind: "waiting-for-snapshot", settleMs: SNAPSHOT_SETTLE_MS });
|
|
2180
|
+
await Promise.all([
|
|
2181
|
+
settleWithin(timer, creating2, CREATE_SETTLE_MS),
|
|
2182
|
+
settleWithin(timer, saving, SNAPSHOT_SETTLE_MS)
|
|
2183
|
+
]);
|
|
2184
|
+
const held = [...live];
|
|
2185
|
+
live.clear();
|
|
2186
|
+
await Promise.all(held.map(keepOrRemove));
|
|
2187
|
+
return { kept, notKept, notStopped: [...notStopped], notDeleted: [...notDeleted] };
|
|
2188
|
+
})();
|
|
2189
|
+
return closing;
|
|
2190
|
+
}
|
|
2191
|
+
};
|
|
2192
|
+
}
|
|
2193
|
+
async function settleWithin(timer, tasks, ms) {
|
|
2194
|
+
if (tasks.size === 0) return;
|
|
2195
|
+
const done = new AbortController();
|
|
2196
|
+
await Promise.race([Promise.allSettled(tasks), timer.sleep(ms, done.signal)]);
|
|
2197
|
+
done.abort();
|
|
2198
|
+
}
|
|
2199
|
+
function failureMessage(failure) {
|
|
2200
|
+
return failure.message ?? failure.kind;
|
|
2201
|
+
}
|
|
2202
|
+
|
|
2203
|
+
// src/runner/snapshot-save.ts
|
|
2204
|
+
var FAILURE_TAIL_LINES = 3;
|
|
2205
|
+
var TEMP_DIRECTORIES = ["/tmp", "/var/tmp", '"${TMPDIR:-}"'];
|
|
2206
|
+
function scrubGitScript(root = SANDBOX_ROOT) {
|
|
2207
|
+
return ["set -euo pipefail", `cd ${root}`, ...RESET_TO_BASE].join("\n");
|
|
2208
|
+
}
|
|
2209
|
+
function scrubTempScript(directories = TEMP_DIRECTORIES) {
|
|
2210
|
+
return [
|
|
2211
|
+
"set -euo pipefail",
|
|
2212
|
+
`for dir in ${directories.join(" ")}; do`,
|
|
2213
|
+
' [ -n "$dir" ] && [ -d "$dir" ] || continue',
|
|
2214
|
+
' find "$dir" -mindepth 1 -maxdepth 1 -exec rm -rf -- {} + 2>/dev/null || true',
|
|
2215
|
+
' if [ -n "$(find "$dir" -mindepth 1 -maxdepth 1 -print -quit)" ]; then',
|
|
2216
|
+
' sudo -n find "$dir" -mindepth 1 -maxdepth 1 -exec rm -rf -- {} + 2>/dev/null || true',
|
|
2217
|
+
" fi",
|
|
2218
|
+
' left=$(find "$dir" -mindepth 1 -maxdepth 1 -print -quit)',
|
|
2219
|
+
` if [ -n "$left" ]; then echo "couldn't empty $dir: $left is left" >&2; exit 1; fi`,
|
|
2220
|
+
"done"
|
|
2221
|
+
].join("\n");
|
|
2222
|
+
}
|
|
2223
|
+
async function saveBranchSnapshot(context, request2, control, progress) {
|
|
2224
|
+
const save = await saveOnce(context, request2, control, progress);
|
|
2225
|
+
if (save.kind !== "saved") await progress.emit({ kind: "branch-snapshot-not-saved", save });
|
|
2226
|
+
return save;
|
|
2227
|
+
}
|
|
2228
|
+
async function saveOnce(context, request2, control, progress) {
|
|
2229
|
+
const { ready, branch, head: head2 } = request2;
|
|
2230
|
+
const { scope, signal } = control;
|
|
2231
|
+
const stopped = () => signal.aborted || scope.closed;
|
|
2232
|
+
if (stopped()) return { kind: "stopped" };
|
|
2233
|
+
const { sandbox, startedFrom } = ready;
|
|
2234
|
+
const startedAt = context.clock.now().getTime();
|
|
2235
|
+
await progress.emit({ kind: "branch-snapshot-saving", branch });
|
|
2236
|
+
for (const script of [scrubGitScript(), scrubTempScript()]) {
|
|
2237
|
+
if (stopped()) return { kind: "stopped" };
|
|
2238
|
+
const ran = await runSaveScript(context, sandbox, script, signal);
|
|
2239
|
+
if (ran.kind === "stopped") return ran;
|
|
2240
|
+
if (ran.kind === "failed") return { kind: "failed", step: "scrub", message: ran.message };
|
|
2241
|
+
}
|
|
2242
|
+
if (stopped()) return { kind: "stopped" };
|
|
2243
|
+
const saved = await scope.saveSnapshot(sandbox, { expirationMs: SNAPSHOT_EXPIRATION_MS });
|
|
2244
|
+
if (!saved.ok)
|
|
2245
|
+
return saved.failure.kind === "aborted" ? { kind: "stopped" } : { kind: "failed", step: "save-snapshot", message: saved.failure.message };
|
|
2246
|
+
if (signal.aborted) return { kind: "stopped" };
|
|
2247
|
+
const savedAt = context.clock.now();
|
|
2248
|
+
const entry = {
|
|
2249
|
+
teamId: startedFrom.teamId,
|
|
2250
|
+
projectId: startedFrom.projectId,
|
|
2251
|
+
region: startedFrom.region,
|
|
2252
|
+
runtime: startedFrom.runtime,
|
|
2253
|
+
recipeName: startedFrom.recipeName,
|
|
2254
|
+
snapshotKey: startedFrom.snapshotKey,
|
|
2255
|
+
base: startedFrom.base,
|
|
2256
|
+
branch,
|
|
2257
|
+
head: head2,
|
|
2258
|
+
repoRoot: ready.repoRoot,
|
|
2259
|
+
snapshotId: saved.value.snapshotId,
|
|
2260
|
+
createdAt: savedAt.toISOString(),
|
|
2261
|
+
expiresAt: saved.value.expiresAt ?? new Date(savedAt.getTime() + SNAPSHOT_EXPIRATION_MS).toISOString()
|
|
2262
|
+
};
|
|
2263
|
+
const written = await context.runnerSnapshots.writeEntry(entry);
|
|
2264
|
+
if (!written.ok) await progress.emit({ kind: "snapshot-entry-not-written", failure: written.failure });
|
|
2265
|
+
const ms = savedAt.getTime() - startedAt;
|
|
2266
|
+
await progress.emit({
|
|
2267
|
+
kind: "branch-snapshot-saved",
|
|
2268
|
+
snapshotId: entry.snapshotId,
|
|
2269
|
+
branch,
|
|
2270
|
+
head: head2,
|
|
2271
|
+
ms,
|
|
2272
|
+
sizeBytes: saved.value.sizeBytes
|
|
2273
|
+
});
|
|
2274
|
+
return {
|
|
2275
|
+
kind: "saved",
|
|
2276
|
+
snapshotId: entry.snapshotId,
|
|
2277
|
+
base: entry.base,
|
|
2278
|
+
branch,
|
|
2279
|
+
head: head2,
|
|
2280
|
+
ms,
|
|
2281
|
+
sizeBytes: saved.value.sizeBytes,
|
|
2282
|
+
entryWritten: written.ok
|
|
2283
|
+
};
|
|
2284
|
+
}
|
|
2285
|
+
async function runSaveScript(context, sandbox, script, signal) {
|
|
2286
|
+
const splitters = { stdout: lineSplitter(), stderr: lineSplitter() };
|
|
2287
|
+
const tail = outputTail(FAILURE_TAIL_LINES);
|
|
2288
|
+
const keep = (text) => {
|
|
2289
|
+
for (const line2 of splitLines(text)) tail.add(line2);
|
|
2290
|
+
};
|
|
2291
|
+
const ran = await context.runnerSandboxes.runScript(
|
|
2292
|
+
sandbox,
|
|
2293
|
+
{ script, env: STEP_ENV },
|
|
2294
|
+
({ stream, data }) => keep(splitters[stream].push(data)),
|
|
2295
|
+
signal
|
|
2296
|
+
);
|
|
2297
|
+
keep(splitters.stdout.flush());
|
|
2298
|
+
keep(splitters.stderr.flush());
|
|
2299
|
+
if (!ran.ok)
|
|
2300
|
+
return ran.failure.kind === "aborted" ? { kind: "stopped" } : { kind: "failed", message: ran.failure.message };
|
|
2301
|
+
const { exitCode } = ran.value;
|
|
2302
|
+
if (exitCode === 0) return { kind: "ok" };
|
|
2303
|
+
const lines = tail.lines();
|
|
2304
|
+
const ended2 = exitCode === null ? "ended without an exit code" : `exited ${exitCode}`;
|
|
2305
|
+
return { kind: "failed", message: lines.length === 0 ? ended2 : `${ended2}: ${lines.join(" / ")}` };
|
|
2306
|
+
}
|
|
2307
|
+
|
|
2308
|
+
// src/config/load.ts
|
|
2309
|
+
import { dirname, join as join2 } from "node:path";
|
|
2310
|
+
|
|
2311
|
+
// src/config/schema.ts
|
|
2312
|
+
var CONFIG_FILE_NAME = "storm.config.ts";
|
|
2313
|
+
function checkWith(schema, value) {
|
|
2314
|
+
const parsed = schema.safeParse(value);
|
|
2315
|
+
if (parsed.success) return { ok: true, value: parsed.data };
|
|
2316
|
+
return {
|
|
2317
|
+
ok: false,
|
|
2318
|
+
problems: parsed.error.issues.map(({ path, message }) => ({ path: path.map(String), problem: message }))
|
|
2319
|
+
};
|
|
2320
|
+
}
|
|
2321
|
+
var SETTING_CHECKS = {
|
|
2322
|
+
scope: (value) => checkWith(nonEmptyString, value),
|
|
2323
|
+
project: (value) => checkWith(nonEmptyString, value),
|
|
2324
|
+
runner: checkRecipe
|
|
2325
|
+
};
|
|
2326
|
+
function isConfigSettingKey(key) {
|
|
2327
|
+
return Object.hasOwn(SETTING_CHECKS, key);
|
|
2328
|
+
}
|
|
2329
|
+
function checkSettingValue(key, value) {
|
|
2330
|
+
return SETTING_CHECKS[key](value);
|
|
2331
|
+
}
|
|
2332
|
+
|
|
2333
|
+
// src/config/load.ts
|
|
2334
|
+
async function findConfigFile(gateway, startDirectory) {
|
|
2335
|
+
if (await gateway.hasConfigFile(startDirectory)) return join2(startDirectory, CONFIG_FILE_NAME);
|
|
2336
|
+
const root = await worktreeRoot(gateway, startDirectory);
|
|
2337
|
+
if (root === void 0) return void 0;
|
|
2338
|
+
for (let directory = startDirectory; directory !== root; ) {
|
|
2339
|
+
directory = dirname(directory);
|
|
2340
|
+
if (await gateway.hasConfigFile(directory)) return join2(directory, CONFIG_FILE_NAME);
|
|
2341
|
+
}
|
|
2342
|
+
return void 0;
|
|
2343
|
+
}
|
|
2344
|
+
async function worktreeRoot(gateway, directory) {
|
|
2345
|
+
for (let current = directory; ; current = dirname(current)) {
|
|
2346
|
+
if (await gateway.isWorktreeRoot(current)) return current;
|
|
2347
|
+
if (dirname(current) === current) return void 0;
|
|
2348
|
+
}
|
|
2349
|
+
}
|
|
2350
|
+
async function loadConfig(gateway, startDirectory, definitions) {
|
|
2351
|
+
const path = await findConfigFile(gateway, startDirectory);
|
|
2352
|
+
if (path === void 0) return { kind: "none" };
|
|
2353
|
+
const imported = await gateway.importConfig(path);
|
|
2354
|
+
switch (imported.kind) {
|
|
2355
|
+
case "import-failed":
|
|
2356
|
+
return {
|
|
2357
|
+
kind: "invalid",
|
|
2358
|
+
path,
|
|
2359
|
+
problems: [{ key: null, location: imported.location ?? null, problem: imported.message }]
|
|
2360
|
+
};
|
|
2361
|
+
case "no-default-export":
|
|
2362
|
+
return {
|
|
2363
|
+
kind: "invalid",
|
|
2364
|
+
path,
|
|
2365
|
+
problems: [fileProblem("has no default export; export default defineConfig({ \u2026 })")]
|
|
2366
|
+
};
|
|
2367
|
+
case "default-export":
|
|
2368
|
+
return checkFile(path, imported.value, definitions);
|
|
2369
|
+
}
|
|
2370
|
+
}
|
|
2371
|
+
function checkFile(path, value, definitions) {
|
|
2372
|
+
if (!isRecord2(value))
|
|
2373
|
+
return {
|
|
2374
|
+
kind: "invalid",
|
|
2375
|
+
path,
|
|
2376
|
+
problems: [fileProblem(`must default-export an object, not ${describeValue(value)}`)]
|
|
2377
|
+
};
|
|
2378
|
+
const settings = {};
|
|
2379
|
+
const problems = [];
|
|
2380
|
+
let resources = {};
|
|
2381
|
+
for (const [key, keyValue] of Object.entries(value)) {
|
|
2382
|
+
if (key === "resources") resources = checkResources(keyValue, definitions, problems);
|
|
2383
|
+
else if (isConfigSettingKey(key)) {
|
|
2384
|
+
if (keyValue !== void 0) checkSetting(key, keyValue, settings, problems);
|
|
2385
|
+
} else problems.push({ key, location: null, problem: `is not a ${CONFIG_FILE_NAME} key` });
|
|
2386
|
+
}
|
|
2387
|
+
if (problems.length > 0) return { kind: "invalid", path, problems };
|
|
2388
|
+
return { kind: "loaded", path, values: { settings, resources } };
|
|
2389
|
+
}
|
|
2390
|
+
function checkSetting(key, value, settings, problems) {
|
|
2391
|
+
const checked = checkSettingValue(key, value);
|
|
2392
|
+
if (checked.ok) Object.assign(settings, { [key]: checked.value });
|
|
2393
|
+
else
|
|
2394
|
+
for (const { path: inside, problem: problem2 } of checked.problems)
|
|
2395
|
+
problems.push({ key: [key, ...inside].join("."), location: null, problem: problem2 });
|
|
2396
|
+
}
|
|
2397
|
+
function checkResources(value, definitions, problems) {
|
|
2398
|
+
if (value === void 0) return {};
|
|
2399
|
+
if (!isRecord2(value)) {
|
|
2400
|
+
problems.push({ key: "resources", location: null, problem: `must be an object, not ${describeValue(value)}` });
|
|
2401
|
+
return {};
|
|
2402
|
+
}
|
|
2403
|
+
const byName = new Map(definitions.map((definition) => [definition.name, definition]));
|
|
2404
|
+
const holds = definitions.length === 0 ? "none" : definitions.map((each) => each.name).join(", ");
|
|
2405
|
+
const found = {};
|
|
2406
|
+
for (const [key, resource] of Object.entries(value)) {
|
|
2407
|
+
const named = entryName(resource);
|
|
2408
|
+
const definition = byName.get(named !== void 0 && byName.has(named) ? named : key);
|
|
2409
|
+
if (named !== void 0 && definition !== void 0 && key !== defaultResourceKey(definition)) {
|
|
2410
|
+
problems.push({
|
|
2411
|
+
key: `resources.${key}`,
|
|
2412
|
+
location: null,
|
|
2413
|
+
problem: `holds a ${named} resource; for now a resource's key must be its definition's name: name its key ${defaultResourceKey(definition)}`
|
|
2414
|
+
});
|
|
2415
|
+
continue;
|
|
2416
|
+
}
|
|
2417
|
+
if (definition === void 0) {
|
|
2418
|
+
problems.push({
|
|
2419
|
+
key: `resources.${key}`,
|
|
2420
|
+
location: null,
|
|
2421
|
+
problem: `is not a resource; resources holds ${holds}`
|
|
2422
|
+
});
|
|
2423
|
+
continue;
|
|
2424
|
+
}
|
|
2425
|
+
if (resource === void 0) continue;
|
|
2426
|
+
const options = checkResource(definition, key, resource, problems);
|
|
2427
|
+
if (options !== void 0) found[key] = { definition: definition.name, options };
|
|
2428
|
+
}
|
|
2429
|
+
return found;
|
|
2430
|
+
}
|
|
2431
|
+
function entryName(value) {
|
|
2432
|
+
return isRecord2(value) && typeof value["name"] === "string" ? value["name"] : void 0;
|
|
2433
|
+
}
|
|
2434
|
+
function checkResource(definition, key, value, problems) {
|
|
2435
|
+
const { name } = definition;
|
|
2436
|
+
const options = isRecord2(value) && value["name"] === name ? value["options"] : void 0;
|
|
2437
|
+
if (!isRecord2(options)) {
|
|
2438
|
+
problems.push({
|
|
2439
|
+
key: `resources.${key}`,
|
|
2440
|
+
location: null,
|
|
2441
|
+
problem: `must be made by ${resourceCall(name)}, not ${describeValue(value)}`
|
|
2442
|
+
});
|
|
2443
|
+
return void 0;
|
|
2444
|
+
}
|
|
2445
|
+
const checked = {};
|
|
2446
|
+
let valid = true;
|
|
2447
|
+
for (const [option, optionValue] of Object.entries(options)) {
|
|
2448
|
+
const path = `resources.${key}.${option}`;
|
|
2449
|
+
const rule = Object.hasOwn(definition.options, option) ? definition.options[option] : void 0;
|
|
2450
|
+
if (rule === void 0) {
|
|
2451
|
+
valid = false;
|
|
2452
|
+
problems.push({ key: path, location: null, problem: `is not a ${name} option` });
|
|
2453
|
+
continue;
|
|
2454
|
+
}
|
|
2455
|
+
if (optionValue === void 0) continue;
|
|
2456
|
+
const result = checkWith(rule.schema, optionValue);
|
|
2457
|
+
if (result.ok) checked[option] = result.value;
|
|
2458
|
+
else {
|
|
2459
|
+
valid = false;
|
|
2460
|
+
for (const { path: inside, problem: problem2 } of result.problems)
|
|
2461
|
+
problems.push({ key: [path, ...inside].join("."), location: null, problem: problem2 });
|
|
2462
|
+
}
|
|
2463
|
+
}
|
|
2464
|
+
return valid ? checked : void 0;
|
|
2465
|
+
}
|
|
2466
|
+
function isRecord2(value) {
|
|
2467
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2468
|
+
}
|
|
2469
|
+
function fileProblem(problem2) {
|
|
2470
|
+
return { key: null, location: null, problem: problem2 };
|
|
2471
|
+
}
|
|
2472
|
+
|
|
2473
|
+
// src/config/credential-resolver.ts
|
|
2474
|
+
import { z as z5 } from "zod";
|
|
2475
|
+
|
|
2476
|
+
// src/credential/live/github-actions-token-response.ts
|
|
2477
|
+
var SAID_LIMIT = 200;
|
|
2478
|
+
var JWT_PATTERN = /eyJ[A-Za-z0-9_-]*(?:\.[A-Za-z0-9_-]*){0,2}/g;
|
|
2479
|
+
function classifyTokenResponse(response, requestToken) {
|
|
2480
|
+
const { status, body } = response;
|
|
2481
|
+
if (status < 200 || status >= 300)
|
|
2482
|
+
return { ok: false, failure: { kind: "http-error", status, said: said(body, requestToken) } };
|
|
2483
|
+
let parsed;
|
|
2484
|
+
try {
|
|
2485
|
+
parsed = JSON.parse(body);
|
|
2486
|
+
} catch {
|
|
2487
|
+
return {
|
|
2488
|
+
ok: false,
|
|
2489
|
+
failure: { kind: "bad-response", said: `an answer that isn't JSON (${body.length} characters)` }
|
|
2490
|
+
};
|
|
2491
|
+
}
|
|
2492
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed))
|
|
2493
|
+
return { ok: false, failure: { kind: "bad-response", said: "a JSON answer that isn't an object" } };
|
|
2494
|
+
const { value } = parsed;
|
|
2495
|
+
if (typeof value === "string" && value !== "") return { ok: true, credential: new Credential(value) };
|
|
2496
|
+
const keys = Object.keys(parsed);
|
|
2497
|
+
return {
|
|
2498
|
+
ok: false,
|
|
2499
|
+
failure: {
|
|
2500
|
+
kind: "bad-response",
|
|
2501
|
+
said: said(
|
|
2502
|
+
`a JSON answer with no token in "value" (${keys.length === 0 ? "no keys" : `keys: ${keys.join(", ")}`})`,
|
|
2503
|
+
requestToken
|
|
2504
|
+
)
|
|
2505
|
+
}
|
|
2506
|
+
};
|
|
2507
|
+
}
|
|
2508
|
+
function said(text, requestToken) {
|
|
2509
|
+
const redacted = (requestToken === "" ? text : text.replaceAll(requestToken, "[redacted]")).replace(
|
|
2510
|
+
JWT_PATTERN,
|
|
2511
|
+
"[redacted]"
|
|
2512
|
+
);
|
|
2513
|
+
const line2 = redacted.replace(/\s+/g, " ").trim();
|
|
2514
|
+
return line2.length <= SAID_LIMIT ? line2 : `${line2.slice(0, SAID_LIMIT - 1)}\u2026`;
|
|
2515
|
+
}
|
|
2516
|
+
|
|
2517
|
+
// src/credential/live/github-actions-token-gateway.ts
|
|
2518
|
+
function liveGitHubActionsTokenGateway(options) {
|
|
2519
|
+
const timeoutMs = options.timeoutMs ?? 1e4;
|
|
2520
|
+
return { request: () => request(options.env, timeoutMs) };
|
|
2521
|
+
}
|
|
2522
|
+
async function request(env, timeoutMs) {
|
|
2523
|
+
const url = env["ACTIONS_ID_TOKEN_REQUEST_URL"];
|
|
2524
|
+
const token = env["ACTIONS_ID_TOKEN_REQUEST_TOKEN"];
|
|
2525
|
+
const missing = [
|
|
2526
|
+
...url === void 0 || url === "" ? ["ACTIONS_ID_TOKEN_REQUEST_URL"] : [],
|
|
2527
|
+
...token === void 0 || token === "" ? ["ACTIONS_ID_TOKEN_REQUEST_TOKEN"] : []
|
|
2528
|
+
];
|
|
2529
|
+
if (url === void 0 || token === void 0 || missing.length > 0)
|
|
2530
|
+
return { ok: false, failure: { kind: "variables-missing", missing } };
|
|
2531
|
+
const signal = AbortSignal.timeout(timeoutMs);
|
|
2532
|
+
const seconds = timeoutMs / 1e3;
|
|
2533
|
+
try {
|
|
2534
|
+
const response = await fetch(url, {
|
|
2535
|
+
headers: { authorization: `Bearer ${token}`, accept: "application/json" },
|
|
2536
|
+
signal
|
|
2537
|
+
});
|
|
2538
|
+
return classifyTokenResponse({ status: response.status, body: await response.text() }, token);
|
|
2539
|
+
} catch (error) {
|
|
2540
|
+
if (signal.aborted) return { ok: false, failure: { kind: "timeout", seconds } };
|
|
2541
|
+
return { ok: false, failure: { kind: "unreachable", said: said(errorMessage2(error), token) } };
|
|
2542
|
+
}
|
|
2543
|
+
}
|
|
2544
|
+
function errorMessage2(error) {
|
|
2545
|
+
if (!(error instanceof Error)) return String(error);
|
|
2546
|
+
const cause = error.cause;
|
|
2547
|
+
return cause instanceof Error && cause.message !== "" ? `${error.message}: ${cause.message}` : error.message;
|
|
2548
|
+
}
|
|
2549
|
+
|
|
2550
|
+
// src/credential/live/vercel-cli-gateway.ts
|
|
2551
|
+
import { execFile as execFile2 } from "node:child_process";
|
|
2552
|
+
import { tmpdir } from "node:os";
|
|
2553
|
+
|
|
2554
|
+
// src/credential/live/vercel-process.ts
|
|
2555
|
+
var VERCEL_TIMEOUT_MS = 3e4;
|
|
2556
|
+
var VERCEL_TIMEOUT_SECONDS = VERCEL_TIMEOUT_MS / 1e3;
|
|
2557
|
+
|
|
2558
|
+
// src/credential/live/vercel-output.ts
|
|
2559
|
+
var OUTDATED = /unknown or unexpected option: --format|Please specify a valid subcommand/;
|
|
2560
|
+
var UNREACHABLE = /internet connectivity|could not be resolved|\b(?:ENOTFOUND|EAI_AGAIN|ECONNREFUSED|ECONNRESET|ETIMEDOUT|ENETUNREACH)\b|fetch failed|socket hang up/i;
|
|
2561
|
+
var PROJECT_NOT_FOUND = /There is no project for|No such project exists/;
|
|
2562
|
+
var SCOPE_NOT_FOUND = "The specified scope does not exist";
|
|
2563
|
+
var ACCOUNT_ACCESS = "You do not have access to the specified account";
|
|
2564
|
+
var ERROR_LINE = /^(?:> )?Error: (.*)$/m;
|
|
2565
|
+
function parseToken(stdout) {
|
|
2566
|
+
const parsed = parseJsonObject(stdout);
|
|
2567
|
+
const token = parsed?.["token"];
|
|
2568
|
+
return typeof token === "string" && token !== "" ? token : void 0;
|
|
2569
|
+
}
|
|
2570
|
+
function errorText(run) {
|
|
2571
|
+
const parsed = parseJsonObject(run.stdout);
|
|
2572
|
+
const message = parsed?.["message"];
|
|
2573
|
+
if (typeof message === "string") {
|
|
2574
|
+
const reason = parsed?.["reason"];
|
|
2575
|
+
return typeof reason === "string" && reason !== "" ? `${message} (${reason})` : message;
|
|
2576
|
+
}
|
|
2577
|
+
const errorLine = ERROR_LINE.exec(run.stderr)?.[1]?.trim();
|
|
2578
|
+
if (errorLine !== void 0 && errorLine !== "") return errorLine;
|
|
2579
|
+
return lastLine(run.stderr) ?? "";
|
|
2580
|
+
}
|
|
2581
|
+
function whoamiUser(stdout) {
|
|
2582
|
+
return lastLine(stdout);
|
|
2583
|
+
}
|
|
2584
|
+
var MINT_STEP = { command: "project token" };
|
|
2585
|
+
function classifyMint(run) {
|
|
2586
|
+
if (run.ok) {
|
|
2587
|
+
const token = parseToken(run.stdout);
|
|
2588
|
+
if (token !== void 0) return { kind: "token", token };
|
|
2589
|
+
} else if (run.reason === "not-found") {
|
|
2590
|
+
return { kind: "failure", failure: { kind: "vercel-not-found" } };
|
|
2591
|
+
} else if (run.reason === "timeout") {
|
|
2592
|
+
return { kind: "failure", failure: { kind: "timeout", step: MINT_STEP, seconds: VERCEL_TIMEOUT_SECONDS } };
|
|
2593
|
+
}
|
|
2594
|
+
const said2 = errorText(run) || "`vercel project token` printed no token";
|
|
2595
|
+
const output = `${run.stdout}
|
|
2596
|
+
${run.stderr}`;
|
|
2597
|
+
if (UNREACHABLE.test(output)) return { kind: "failure", failure: { kind: "unreachable", step: MINT_STEP, said: said2 } };
|
|
2598
|
+
if (OUTDATED.test(output)) return { kind: "failure", failure: { kind: "outdated-cli", said: said2 } };
|
|
2599
|
+
if (PROJECT_NOT_FOUND.test(output)) return { kind: "failure", failure: { kind: "project-not-found", said: said2 } };
|
|
2600
|
+
if (output.includes(SCOPE_NOT_FOUND) || output.includes(ACCOUNT_ACCESS)) return { kind: "needs-whoami", said: said2 };
|
|
2601
|
+
return { kind: "failure", failure: { kind: "unrecognized", said: said2 } };
|
|
2602
|
+
}
|
|
2603
|
+
function classifyWhoami(run, mintSaid) {
|
|
2604
|
+
if (run.ok) return { kind: "no-team-access", said: mintSaid, user: whoamiUser(run.stdout) };
|
|
2605
|
+
const step = { command: "whoami", mintSaid };
|
|
2606
|
+
if (run.reason === "not-found") return { kind: "vercel-not-found" };
|
|
2607
|
+
if (run.reason === "timeout") return { kind: "timeout", step, seconds: VERCEL_TIMEOUT_SECONDS };
|
|
2608
|
+
const whoamiSaid = errorText(run) || "it failed without an error message";
|
|
2609
|
+
if (UNREACHABLE.test(`${run.stdout}
|
|
2610
|
+
${run.stderr}`)) return { kind: "unreachable", step, said: whoamiSaid };
|
|
2611
|
+
return { kind: "login-lapsed", said: mintSaid, whoamiSaid };
|
|
2612
|
+
}
|
|
2613
|
+
function parseJsonObject(text) {
|
|
2614
|
+
try {
|
|
2615
|
+
const parsed = JSON.parse(text);
|
|
2616
|
+
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : void 0;
|
|
2617
|
+
} catch {
|
|
2618
|
+
return void 0;
|
|
2619
|
+
}
|
|
2620
|
+
}
|
|
2621
|
+
function lastLine(text) {
|
|
2622
|
+
return text.split("\n").map((line2) => line2.trim()).filter((line2) => line2 !== "").at(-1);
|
|
2623
|
+
}
|
|
2624
|
+
|
|
2625
|
+
// src/credential/live/vercel-cli-gateway.ts
|
|
2626
|
+
function mintArgs(target) {
|
|
2627
|
+
return ["project", "token", target.project, "--scope", target.team, "--format=json"];
|
|
2628
|
+
}
|
|
2629
|
+
function liveCredentialGateway() {
|
|
2630
|
+
return {
|
|
2631
|
+
async mint(target) {
|
|
2632
|
+
const minted = classifyMint(await runVercel(mintArgs(target)));
|
|
2633
|
+
switch (minted.kind) {
|
|
2634
|
+
case "token":
|
|
2635
|
+
return { ok: true, credential: new Credential(minted.token) };
|
|
2636
|
+
case "failure":
|
|
2637
|
+
return { ok: false, failure: minted.failure };
|
|
2638
|
+
case "needs-whoami":
|
|
2639
|
+
return { ok: false, failure: classifyWhoami(await runVercel(["whoami"]), minted.said) };
|
|
2640
|
+
}
|
|
2641
|
+
}
|
|
2642
|
+
};
|
|
2643
|
+
}
|
|
2644
|
+
function runVercel(args) {
|
|
2645
|
+
return new Promise((resolve) => {
|
|
2646
|
+
try {
|
|
2647
|
+
execFile2(
|
|
2648
|
+
"vercel",
|
|
2649
|
+
args,
|
|
2650
|
+
{
|
|
2651
|
+
cwd: tmpdir(),
|
|
2652
|
+
env: { ...process.env, NO_COLOR: "1", NO_UPDATE_NOTIFIER: "1" },
|
|
2653
|
+
timeout: VERCEL_TIMEOUT_MS,
|
|
2654
|
+
maxBuffer: 16 * 1024 * 1024,
|
|
2655
|
+
encoding: "utf8"
|
|
2656
|
+
},
|
|
2657
|
+
(error, stdout, stderr) => {
|
|
2658
|
+
resolve(error === null ? { ok: true, stdout, stderr } : failedRun(error, stdout, stderr));
|
|
2659
|
+
}
|
|
2660
|
+
);
|
|
2661
|
+
} catch (error) {
|
|
2662
|
+
resolve(failedRun(error, "", ""));
|
|
2663
|
+
}
|
|
2664
|
+
});
|
|
2665
|
+
}
|
|
2666
|
+
function failedRun(error, stdout, stderr) {
|
|
2667
|
+
const fields = typeof error === "object" && error !== null ? error : {};
|
|
2668
|
+
const out = typeof stdout === "string" ? stdout : "";
|
|
2669
|
+
const err = typeof stderr === "string" ? stderr : "";
|
|
2670
|
+
if (fields["killed"] === true) return { ok: false, reason: "timeout", stdout: out, stderr: err };
|
|
2671
|
+
if (fields["code"] === "ENOENT") return { ok: false, reason: "not-found", stdout: out, stderr: err };
|
|
2672
|
+
return { ok: false, reason: "exit", stdout: out, stderr: err };
|
|
2673
|
+
}
|
|
2674
|
+
|
|
2675
|
+
// src/credential/source.ts
|
|
2676
|
+
var REQUESTING_TOKEN_LINE = "Requesting a GitHub Actions OIDC token\u2026";
|
|
2677
|
+
function mintSource(target, mint) {
|
|
2678
|
+
let outcome;
|
|
2679
|
+
return {
|
|
2680
|
+
obtain() {
|
|
2681
|
+
outcome ??= (async () => {
|
|
2682
|
+
const minted = await mint();
|
|
2683
|
+
return minted.ok ? minted : { ok: false, failure: { source: "mint", failure: minted.failure, target } };
|
|
2684
|
+
})();
|
|
2685
|
+
return outcome;
|
|
2686
|
+
},
|
|
2687
|
+
origin() {
|
|
2688
|
+
return { source: "mint", target };
|
|
2689
|
+
}
|
|
2690
|
+
};
|
|
2691
|
+
}
|
|
2692
|
+
function obtainedSource(target, credential) {
|
|
2693
|
+
const outcome = Promise.resolve({ ok: true, credential });
|
|
2694
|
+
return {
|
|
2695
|
+
obtain: () => outcome,
|
|
2696
|
+
origin: () => ({ source: "mint", target })
|
|
2697
|
+
};
|
|
2698
|
+
}
|
|
2699
|
+
function credentialSourceFor(choice, context, report) {
|
|
2700
|
+
if (choice.source === "github-actions")
|
|
2701
|
+
return githubActionsSource({
|
|
2702
|
+
gateway: context.githubActionsTokens,
|
|
2703
|
+
clock: context.clock,
|
|
2704
|
+
timer: context.timer,
|
|
2705
|
+
onRequest: report.onRequest
|
|
2706
|
+
});
|
|
2707
|
+
const { target } = choice;
|
|
2708
|
+
return mintSource(target, async () => {
|
|
2709
|
+
await report.onMint(target);
|
|
2710
|
+
return await context.credentials.mint(target);
|
|
2711
|
+
});
|
|
2712
|
+
}
|
|
2713
|
+
var TOKEN_REFRESH_MS = 4 * 6e4;
|
|
2714
|
+
var RETRY_WAITS_MS = [1e3, 2e3];
|
|
2715
|
+
function githubActionsSource(context) {
|
|
2716
|
+
let held;
|
|
2717
|
+
let inFlight;
|
|
2718
|
+
const request2 = async () => {
|
|
2719
|
+
await context.onRequest?.();
|
|
2720
|
+
for (let attempt = 1; ; attempt += 1) {
|
|
2721
|
+
const sentAt = context.clock.now().getTime();
|
|
2722
|
+
const outcome = await context.gateway.request();
|
|
2723
|
+
if (outcome.ok) {
|
|
2724
|
+
held = { credential: outcome.credential, sentAt };
|
|
2725
|
+
return outcome;
|
|
2726
|
+
}
|
|
2727
|
+
const { failure } = outcome;
|
|
2728
|
+
if (failure.kind === "variables-missing") return { ok: false, failure: { source: "github-actions", failure } };
|
|
2729
|
+
const wait = RETRY_WAITS_MS[attempt - 1];
|
|
2730
|
+
if (wait === void 0 || !isRetryable(failure))
|
|
2731
|
+
return {
|
|
2732
|
+
ok: false,
|
|
2733
|
+
failure: { source: "github-actions", failure: { kind: "request-failed", attempts: attempt, last: failure } }
|
|
2734
|
+
};
|
|
2735
|
+
await context.timer.sleep(wait);
|
|
2736
|
+
}
|
|
2737
|
+
};
|
|
2738
|
+
return {
|
|
2739
|
+
obtain() {
|
|
2740
|
+
if (held !== void 0 && context.clock.now().getTime() - held.sentAt < TOKEN_REFRESH_MS)
|
|
2741
|
+
return Promise.resolve({ ok: true, credential: held.credential });
|
|
2742
|
+
if (inFlight === void 0) {
|
|
2743
|
+
held = void 0;
|
|
2744
|
+
inFlight = (async () => {
|
|
2745
|
+
try {
|
|
2746
|
+
return await request2();
|
|
2747
|
+
} finally {
|
|
2748
|
+
inFlight = void 0;
|
|
2749
|
+
}
|
|
2750
|
+
})();
|
|
2751
|
+
}
|
|
2752
|
+
return inFlight;
|
|
2753
|
+
},
|
|
2754
|
+
origin(credential) {
|
|
2755
|
+
return { source: "github-actions", claims: credential.githubActionsClaims() };
|
|
2756
|
+
}
|
|
2757
|
+
};
|
|
2758
|
+
}
|
|
2759
|
+
function isRetryable(failure) {
|
|
2760
|
+
switch (failure.kind) {
|
|
2761
|
+
case "unreachable":
|
|
2762
|
+
case "timeout":
|
|
2763
|
+
return true;
|
|
2764
|
+
case "http-error":
|
|
2765
|
+
return failure.status === 502 || failure.status === 503 || failure.status === 504;
|
|
2766
|
+
case "bad-response":
|
|
2767
|
+
return false;
|
|
2768
|
+
}
|
|
2769
|
+
}
|
|
2770
|
+
|
|
2771
|
+
// src/credential/target.ts
|
|
2772
|
+
function mintTargetText(target) {
|
|
2773
|
+
return `Vercel project ${target.project} on team ${target.team}`;
|
|
2774
|
+
}
|
|
2775
|
+
|
|
2776
|
+
// src/config/credential-settle.ts
|
|
2777
|
+
import { z as z4 } from "zod";
|
|
2778
|
+
var credentialErrors = defineErrors({
|
|
2779
|
+
missingTarget: {
|
|
2780
|
+
exitCode: 2,
|
|
2781
|
+
description: "The command may mint a credential, and neither a flag nor storm.config.ts names the control plane team or project.",
|
|
2782
|
+
schema: z4.object({
|
|
2783
|
+
/** The settings no flag or config file gave. */
|
|
2784
|
+
missing: z4.array(z4.enum(["scope", "project"]))
|
|
2785
|
+
}),
|
|
2786
|
+
render: ({ missing }) => ({
|
|
2787
|
+
message: `No control plane ${missing.map((key) => key === "scope" ? "team" : "project").join(" or ")} to mint a credential for.`,
|
|
2788
|
+
next: [
|
|
2789
|
+
{
|
|
2790
|
+
type: "text",
|
|
2791
|
+
text: `Give ${missing.map((key) => `--${key}`).join(" and ")}, or set ${missing.join(" and ")} in storm.config.ts.`
|
|
2792
|
+
}
|
|
2793
|
+
]
|
|
2794
|
+
})
|
|
2795
|
+
}
|
|
2796
|
+
});
|
|
2797
|
+
function requireTarget(scope, project) {
|
|
2798
|
+
if (scope === void 0 || project === void 0)
|
|
2799
|
+
return refused(
|
|
2800
|
+
credentialErrors.missingTarget({
|
|
2801
|
+
missing: [
|
|
2802
|
+
...scope === void 0 ? ["scope"] : [],
|
|
2803
|
+
...project === void 0 ? ["project"] : []
|
|
2804
|
+
]
|
|
2805
|
+
})
|
|
2806
|
+
);
|
|
2807
|
+
return { ok: true, target: { team: scope.value, project: project.value } };
|
|
2808
|
+
}
|
|
2809
|
+
function settleCredential(source, scope, project) {
|
|
2810
|
+
if (source === "github-actions") return { ok: true, credential: { source } };
|
|
2811
|
+
const required = requireTarget(scope, project);
|
|
2812
|
+
if (!required.ok) return required;
|
|
2813
|
+
return { ok: true, credential: { source, target: required.target } };
|
|
2814
|
+
}
|
|
2815
|
+
|
|
2816
|
+
// src/config/credential-resolver.ts
|
|
2817
|
+
var credentialSourceErrors = defineErrors({
|
|
2818
|
+
mintFailed: {
|
|
2819
|
+
exitCode: 1,
|
|
2820
|
+
description: "The vercel CLI couldn't mint a credential for the team and project.",
|
|
2821
|
+
schema: z5.object({ team: z5.string(), project: z5.string(), cause: z5.string(), fix: z5.string() }),
|
|
2822
|
+
render: ({ cause, fix }) => ({
|
|
2823
|
+
message: `Couldn't mint a credential: ${cause}.`,
|
|
2824
|
+
next: [{ type: "text", text: fix }]
|
|
2825
|
+
})
|
|
2826
|
+
},
|
|
2827
|
+
tokenRequestFailed: {
|
|
2828
|
+
exitCode: 1,
|
|
2829
|
+
description: "With --credential github-actions, the GitHub Actions OIDC token request failed.",
|
|
2830
|
+
schema: z5.object(tokenRequestFailureShape),
|
|
2831
|
+
render: ({ detail, fix }) => ({
|
|
2832
|
+
message: `Couldn't request a GitHub Actions OIDC token: ${detail}.`,
|
|
2833
|
+
next: [{ type: "text", text: fix }]
|
|
2834
|
+
})
|
|
2835
|
+
}
|
|
2836
|
+
});
|
|
2837
|
+
function credentialSourceError(failure) {
|
|
2838
|
+
return failure.source === "mint" ? credentialSourceErrors.mintFailed({ ...failure.target, ...describeMintFailure(failure.failure, failure.target) }) : credentialSourceErrors.tokenRequestFailed(tokenRequestFailureFacts(failure.failure));
|
|
2839
|
+
}
|
|
2840
|
+
function credentialResolver(gateways) {
|
|
2841
|
+
return {
|
|
2842
|
+
source(choice, target, report = {}) {
|
|
2843
|
+
const chosen = settleCredential(choice, target.scope, target.project);
|
|
2844
|
+
if (!chosen.ok) return chosen;
|
|
2845
|
+
const { progress } = report;
|
|
2846
|
+
const source = credentialSourceFor(chosen.credential, gateways, {
|
|
2847
|
+
onMint: async (mintTarget) => {
|
|
2848
|
+
await progress?.(`Minting a credential for ${mintTargetText(mintTarget)}\u2026`);
|
|
2849
|
+
},
|
|
2850
|
+
onRequest: async () => {
|
|
2851
|
+
await progress?.(REQUESTING_TOKEN_LINE);
|
|
2852
|
+
}
|
|
2853
|
+
});
|
|
2854
|
+
return {
|
|
2855
|
+
ok: true,
|
|
2856
|
+
source: {
|
|
2857
|
+
async obtain() {
|
|
2858
|
+
const got = await source.obtain();
|
|
2859
|
+
return got.ok ? got : { ok: false, refusal: credentialSourceError(got.failure) };
|
|
2860
|
+
},
|
|
2861
|
+
origin: (credential) => source.origin(credential)
|
|
2862
|
+
}
|
|
2863
|
+
};
|
|
2864
|
+
}
|
|
2865
|
+
};
|
|
2866
|
+
}
|
|
2867
|
+
|
|
2868
|
+
// src/config/errors.ts
|
|
2869
|
+
import { z as z6 } from "zod";
|
|
2870
|
+
var problemSchema = z6.object({
|
|
2871
|
+
/** The key the problem is about; null when it is about the whole file. */
|
|
2872
|
+
key: z6.string().nullable(),
|
|
2873
|
+
/** Where Node said the import failed; null otherwise. */
|
|
2874
|
+
location: z6.object({ line: z6.number(), column: z6.number().nullable() }).nullable(),
|
|
2875
|
+
/** What is wrong, worded to follow the key, or the file name when there is no key. */
|
|
2876
|
+
problem: z6.string()
|
|
2877
|
+
});
|
|
2878
|
+
function configProblemLine(file, { key, location, problem: problem2 }) {
|
|
2879
|
+
const sentence2 = `${problem2.replace(/\.$/, "")}.`;
|
|
2880
|
+
if (key !== null) return `${file}: ${key} ${sentence2}`;
|
|
2881
|
+
if (location !== null)
|
|
2882
|
+
return `${file}:${location.line}${location.column === null ? "" : `:${location.column}`} ${sentence2}`;
|
|
2883
|
+
return `${file}: ${sentence2}`;
|
|
2884
|
+
}
|
|
2885
|
+
var optionValueSchema = z6.object({
|
|
2886
|
+
/** The option's key path, such as resources.<key>.ttl. */
|
|
2887
|
+
key: z6.string(),
|
|
2888
|
+
/** Its value, as text. */
|
|
2889
|
+
value: z6.string(),
|
|
2890
|
+
/** Where it came from: the command's own flag for the option, the config file or the default. */
|
|
2891
|
+
source: z6.enum(["flag", "file", "default"])
|
|
2892
|
+
});
|
|
2893
|
+
var optionProblemSchema = z6.object({
|
|
2894
|
+
/** The key path of the option the problem is about, such as resources.<key>.ttl. */
|
|
2895
|
+
key: z6.string(),
|
|
2896
|
+
/** What is wrong, worded to follow the key path, as the resource's rule words it. */
|
|
2897
|
+
problem: z6.string(),
|
|
2898
|
+
/** Each value the problem is about, with its source; empty for a required option nothing gave. */
|
|
2899
|
+
values: z6.array(optionValueSchema)
|
|
2900
|
+
});
|
|
2901
|
+
function optionValueText({ key, value, source }, configFile) {
|
|
2902
|
+
switch (source) {
|
|
2903
|
+
case "flag":
|
|
2904
|
+
return `${key} is ${value} from the command line`;
|
|
2905
|
+
case "file":
|
|
2906
|
+
return `${key} is ${value} in ${configFile ?? "storm.config.ts"}`;
|
|
2907
|
+
case "default":
|
|
2908
|
+
return `${key} is ${value} by default`;
|
|
2909
|
+
}
|
|
2910
|
+
}
|
|
2911
|
+
function optionProblemLine({ key, problem: problem2, values }, configFile) {
|
|
2912
|
+
const where2 = values.map((value) => optionValueText(value, configFile));
|
|
2913
|
+
const sources = where2.length === 0 ? "" : `: ${where2.length === 1 ? where2.join("") : `${where2.slice(0, -1).join(", ")} and ${where2.at(-1) ?? ""}`}`;
|
|
2914
|
+
return `${key} ${problem2.replace(/\.$/, "")}${sources}.`;
|
|
2915
|
+
}
|
|
2916
|
+
var configErrors = defineErrors({
|
|
2917
|
+
invalidConfig: {
|
|
2918
|
+
exitCode: 2,
|
|
2919
|
+
description: "storm.config.ts can't be used: it can't be imported, doesn't default-export an object, has an unknown key, or a value in it is invalid. storm checks the whole file whenever a command loads it.",
|
|
2920
|
+
schema: z6.object({
|
|
2921
|
+
/** The config file's absolute path. */
|
|
2922
|
+
file: z6.string(),
|
|
2923
|
+
problems: z6.array(problemSchema)
|
|
2924
|
+
}),
|
|
2925
|
+
render: ({ file, problems }) => {
|
|
2926
|
+
const [first, ...rest] = problems;
|
|
2927
|
+
return {
|
|
2928
|
+
message: first === void 0 ? `${file} can't be used.` : configProblemLine(file, first),
|
|
2929
|
+
...rest.length === 0 ? {} : { rows: [["Also", rest.map((problem2) => configProblemLine(file, problem2))]] },
|
|
2930
|
+
next: [{ type: "text", text: `Fix ${file}, then retry.` }]
|
|
2931
|
+
};
|
|
2932
|
+
}
|
|
2933
|
+
},
|
|
2934
|
+
invalidResourceOptions: {
|
|
2935
|
+
exitCode: 2,
|
|
2936
|
+
description: "A resource's options, once its defaults, storm.config.ts and the flags are merged, don't fit together, as the resource's own checks say, or one it requires is missing: such as resources.<key>.ttl not longer than its minTimeLeft. Each problem names the values it is about and where each came from.",
|
|
2937
|
+
schema: z6.object({
|
|
2938
|
+
/** The config file that applied; null when none did. */
|
|
2939
|
+
configFile: z6.string().nullable(),
|
|
2940
|
+
problems: z6.array(optionProblemSchema)
|
|
2941
|
+
}),
|
|
2942
|
+
render: ({ configFile, problems }) => {
|
|
2943
|
+
const [first, ...rest] = problems;
|
|
2944
|
+
return {
|
|
2945
|
+
message: first === void 0 ? "A resource's options don't fit together." : optionProblemLine(first, configFile),
|
|
2946
|
+
...rest.length === 0 ? {} : { rows: [["Also", rest.map((problem2) => optionProblemLine(problem2, configFile))]] },
|
|
2947
|
+
next: [
|
|
2948
|
+
{
|
|
2949
|
+
type: "text",
|
|
2950
|
+
text: `Change the options on the command line or in ${configFile ?? "storm.config.ts"}, then retry.`
|
|
2951
|
+
}
|
|
2952
|
+
]
|
|
2953
|
+
};
|
|
2954
|
+
}
|
|
2955
|
+
}
|
|
2956
|
+
});
|
|
2957
|
+
|
|
2958
|
+
// src/config/live/config-gateway.ts
|
|
2959
|
+
import { stat } from "node:fs/promises";
|
|
2960
|
+
import { basename, join as join3 } from "node:path";
|
|
2961
|
+
import { pathToFileURL } from "node:url";
|
|
2962
|
+
function liveConfigGateway() {
|
|
2963
|
+
return {
|
|
2964
|
+
hasConfigFile: async (directory) => await kind(join3(directory, CONFIG_FILE_NAME)) === "file",
|
|
2965
|
+
isWorktreeRoot: async (directory) => await kind(join3(directory, ".git")) !== void 0,
|
|
2966
|
+
importConfig: async (path) => {
|
|
2967
|
+
try {
|
|
2968
|
+
const module = await import(pathToFileURL(path).href);
|
|
2969
|
+
return "default" in module ? { kind: "default-export", value: module["default"] } : { kind: "no-default-export" };
|
|
2970
|
+
} catch (error) {
|
|
2971
|
+
return importFailure(error, path);
|
|
2972
|
+
}
|
|
2973
|
+
}
|
|
2974
|
+
};
|
|
2975
|
+
}
|
|
2976
|
+
async function kind(path) {
|
|
2977
|
+
try {
|
|
2978
|
+
return (await stat(path)).isFile() ? "file" : "other";
|
|
2979
|
+
} catch {
|
|
2980
|
+
return void 0;
|
|
2981
|
+
}
|
|
2982
|
+
}
|
|
2983
|
+
function importFailure(error, path) {
|
|
2984
|
+
if (!(error instanceof Error)) return { kind: "import-failed", message: String(error) };
|
|
2985
|
+
const location = errorLocation(error, basename(path));
|
|
2986
|
+
return { kind: "import-failed", message: error.message, ...location === void 0 ? {} : { location } };
|
|
2987
|
+
}
|
|
2988
|
+
function errorLocation(error, name) {
|
|
2989
|
+
const lines = (error.stack ?? "").split("\n");
|
|
2990
|
+
const escaped = name.replaceAll(".", "\\.");
|
|
2991
|
+
if (error instanceof SyntaxError) {
|
|
2992
|
+
const line2 = new RegExp(`${escaped}:(\\d+)$`).exec(lines[0] ?? "")?.[1];
|
|
2993
|
+
if (line2 === void 0) return void 0;
|
|
2994
|
+
const frame = lines.slice(1);
|
|
2995
|
+
const carets = frame.slice(0, frame.indexOf("")).find((text) => /^ *\^+$/.test(text));
|
|
2996
|
+
return carets === void 0 ? { line: Number(line2) } : { line: Number(line2), column: carets.indexOf("^") + 1 };
|
|
2997
|
+
}
|
|
2998
|
+
for (const text of lines) {
|
|
2999
|
+
const frame = new RegExp(`${escaped}:(\\d+):(\\d+)\\)?$`).exec(text);
|
|
3000
|
+
if (frame !== null) return { line: Number(frame[1]), column: Number(frame[2]) };
|
|
3001
|
+
}
|
|
3002
|
+
return void 0;
|
|
3003
|
+
}
|
|
3004
|
+
|
|
3005
|
+
// src/config/typed-options.ts
|
|
3006
|
+
function givenOptionsOf(_definition, values) {
|
|
3007
|
+
return values;
|
|
3008
|
+
}
|
|
3009
|
+
function settingsOf(_definition, settings) {
|
|
3010
|
+
return settings;
|
|
3011
|
+
}
|
|
3012
|
+
function resourceOptionsOf(_definition, value) {
|
|
3013
|
+
return value;
|
|
3014
|
+
}
|
|
3015
|
+
|
|
3016
|
+
// src/config/recipe-run.ts
|
|
3017
|
+
var NOT_PRESENT = Object.freeze({ present: false });
|
|
3018
|
+
function recipeRun(resources) {
|
|
3019
|
+
const run = {
|
|
3020
|
+
get: ({ definition }) => {
|
|
3021
|
+
const key = defaultResourceKey(definition);
|
|
3022
|
+
const resource = Object.hasOwn(resources, key) ? resources[key] : void 0;
|
|
3023
|
+
if (resource === void 0 || resource.definition !== definition.name) return NOT_PRESENT;
|
|
3024
|
+
return Object.freeze({
|
|
3025
|
+
present: true,
|
|
3026
|
+
value: resourceOptionsOf(definition, Object.freeze({ ...resource.options }))
|
|
3027
|
+
});
|
|
3028
|
+
}
|
|
3029
|
+
};
|
|
3030
|
+
return { run: Object.freeze(run), resourceKeys: Object.keys(resources) };
|
|
3031
|
+
}
|
|
3032
|
+
|
|
3033
|
+
// src/config/resolve.ts
|
|
3034
|
+
function resolveSettings(flags, file) {
|
|
3035
|
+
const pick = (flag, fromFile) => flag !== void 0 ? { value: flag, source: "flag" } : fromFile === void 0 ? void 0 : { value: fromFile, source: "file" };
|
|
3036
|
+
return {
|
|
3037
|
+
scope: pick(flags.scope, file?.scope),
|
|
3038
|
+
project: pick(flags.project, file?.project),
|
|
3039
|
+
runner: pick(void 0, file?.runner)
|
|
3040
|
+
};
|
|
3041
|
+
}
|
|
3042
|
+
function optionSource(definition, option, file, flags) {
|
|
3043
|
+
const fromFile = file ?? {};
|
|
3044
|
+
const fromFlags = flags ?? {};
|
|
3045
|
+
if (fromFlags[option] !== void 0) return "flag";
|
|
3046
|
+
if (fromFile[option] !== void 0) return "file";
|
|
3047
|
+
return definition.options[option]?.default === void 0 ? void 0 : "default";
|
|
3048
|
+
}
|
|
3049
|
+
function mergeResourceOptions(definition, key, file, flags) {
|
|
3050
|
+
const fromFile = file ?? {};
|
|
3051
|
+
const fromFlags = flags ?? {};
|
|
3052
|
+
const merged = [];
|
|
3053
|
+
const problems = [];
|
|
3054
|
+
for (const [option, rule] of Object.entries(definition.options)) {
|
|
3055
|
+
const source = optionSource(definition, option, file, flags);
|
|
3056
|
+
if (source === "flag") merged.push([option, { value: fromFlags[option], source }]);
|
|
3057
|
+
else if (source === "file") merged.push([option, { value: fromFile[option], source }]);
|
|
3058
|
+
else if (source === "default") merged.push([option, "default"]);
|
|
3059
|
+
else if (rule.required === true) {
|
|
3060
|
+
problems.push({
|
|
3061
|
+
key: optionKeyPath(key, option),
|
|
3062
|
+
problem: `is required; give it in ${resourceCall(definition.name)}`,
|
|
3063
|
+
values: []
|
|
3064
|
+
});
|
|
3065
|
+
}
|
|
3066
|
+
}
|
|
3067
|
+
if (problems.length > 0) return { ok: false, problems };
|
|
3068
|
+
return {
|
|
3069
|
+
ok: true,
|
|
3070
|
+
settings: (run) => (
|
|
3071
|
+
// Every option with a default or marked required is in `merged`, so it is what `definition.check` takes.
|
|
3072
|
+
settingsOf(
|
|
3073
|
+
definition,
|
|
3074
|
+
Object.fromEntries(
|
|
3075
|
+
merged.map(([option, given]) => [
|
|
3076
|
+
option,
|
|
3077
|
+
given === "default" ? { value: defaultValue(definition, option, run), source: "default" } : given
|
|
3078
|
+
])
|
|
3079
|
+
)
|
|
3080
|
+
)
|
|
3081
|
+
)
|
|
3082
|
+
};
|
|
3083
|
+
}
|
|
3084
|
+
function isDefaultFunction(given) {
|
|
3085
|
+
return typeof given === "function";
|
|
3086
|
+
}
|
|
3087
|
+
function defaultValue(definition, option, run) {
|
|
3088
|
+
const rule = definition.options[option];
|
|
3089
|
+
if (rule === void 0 || !isDefaultFunction(rule.default)) return rule?.default;
|
|
3090
|
+
const checked = rule.schema.safeParse(rule.default(run));
|
|
3091
|
+
if (checked.success) return checked.data;
|
|
3092
|
+
const problems = checked.error.issues.map(({ message }) => message).join("; ");
|
|
3093
|
+
throw new Error(
|
|
3094
|
+
`${definition.name}'s option ${option} has a default that gave a value its schema refuses: ${problems}`
|
|
3095
|
+
);
|
|
3096
|
+
}
|
|
3097
|
+
function mergeRunResources(definitions, file, flags) {
|
|
3098
|
+
const resources = [];
|
|
3099
|
+
const problems = [];
|
|
3100
|
+
for (const { key, definition, given, flagged } of runResources(definitions, file, flags)) {
|
|
3101
|
+
const merged = mergeResourceOptions(definition, key, given, flagged);
|
|
3102
|
+
if (merged.ok) resources.push({ key, definition, settings: merged.settings });
|
|
3103
|
+
else problems.push(...merged.problems);
|
|
3104
|
+
}
|
|
3105
|
+
if (problems.length > 0) return { ok: false, problems };
|
|
3106
|
+
const options = Object.fromEntries(
|
|
3107
|
+
resources.map(({ key, definition, settings }) => [
|
|
3108
|
+
key,
|
|
3109
|
+
{ definition: definition.name, options: plainValues(settings(NOT_COUNTED)) }
|
|
3110
|
+
])
|
|
3111
|
+
);
|
|
3112
|
+
return { ok: true, options, plan: (run) => planResources(resources, run) };
|
|
3113
|
+
}
|
|
3114
|
+
function planResources(resources, run) {
|
|
3115
|
+
const resolved = {};
|
|
3116
|
+
const planned = [];
|
|
3117
|
+
const problems = [];
|
|
3118
|
+
for (const { key, definition, settings: settingsFor } of resources) {
|
|
3119
|
+
const merged = settingsFor(run);
|
|
3120
|
+
const settings = merged;
|
|
3121
|
+
planned.push(...plannedOptions(definition, key, settings));
|
|
3122
|
+
const refused2 = definition.check(merged);
|
|
3123
|
+
if (refused2.length === 0)
|
|
3124
|
+
resolved[key] = {
|
|
3125
|
+
definition: definition.name,
|
|
3126
|
+
options: plainValues(settings),
|
|
3127
|
+
sources: Object.fromEntries(
|
|
3128
|
+
Object.keys(definition.options).map((option) => [option, settings[option]?.source])
|
|
3129
|
+
)
|
|
3130
|
+
};
|
|
3131
|
+
else
|
|
3132
|
+
for (const { option, problem: problem2, involves } of refused2)
|
|
3133
|
+
problems.push({
|
|
3134
|
+
key: optionKeyPath(key, option),
|
|
3135
|
+
problem: problem2,
|
|
3136
|
+
values: involves.flatMap((each) => {
|
|
3137
|
+
const setting = settings[each];
|
|
3138
|
+
return setting === void 0 ? [] : [{ key: optionKeyPath(key, each), value: setting.value, source: setting.source }];
|
|
3139
|
+
})
|
|
3140
|
+
});
|
|
3141
|
+
}
|
|
3142
|
+
if (problems.length > 0) return { ok: false, problems };
|
|
3143
|
+
return { ok: true, value: resolved, planned };
|
|
3144
|
+
}
|
|
3145
|
+
function runResources(definitions, file, flags) {
|
|
3146
|
+
const resources = Object.entries(file ?? {});
|
|
3147
|
+
return definitions.flatMap((definition) => {
|
|
3148
|
+
const defaultKey = defaultResourceKey(definition);
|
|
3149
|
+
const flagged = flags[definition.name];
|
|
3150
|
+
const fromFile = resources.flatMap(
|
|
3151
|
+
([key, resource]) => resource.definition === definition.name ? [{ key, definition, given: resource.options, flagged: key === defaultKey ? flagged : void 0 }] : []
|
|
3152
|
+
);
|
|
3153
|
+
const flagOnly = flagged !== void 0 && !fromFile.some(({ key }) => key === defaultKey) ? [{ key: defaultKey, definition, given: void 0, flagged }] : [];
|
|
3154
|
+
return [...fromFile, ...flagOnly];
|
|
3155
|
+
});
|
|
3156
|
+
}
|
|
3157
|
+
function plainValues(settings) {
|
|
3158
|
+
return Object.fromEntries(
|
|
3159
|
+
Object.entries(settings).flatMap(([option, setting]) => setting === void 0 ? [] : [[option, setting.value]])
|
|
3160
|
+
);
|
|
3161
|
+
}
|
|
3162
|
+
function plannedOptions(definition, key, settings) {
|
|
3163
|
+
return Object.entries(definition.options).flatMap(([option, rule]) => {
|
|
3164
|
+
const setting = settings[option];
|
|
3165
|
+
if (!isDefaultFunction(rule.default) || setting === void 0) return [];
|
|
3166
|
+
const { value, source } = setting;
|
|
3167
|
+
const path = optionKeyPath(key, option);
|
|
3168
|
+
if (typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean")
|
|
3169
|
+
throw new Error(`${path} has a default that is a function, so it must take a string, number or boolean`);
|
|
3170
|
+
return [{ path, value, source }];
|
|
3171
|
+
});
|
|
3172
|
+
}
|
|
3173
|
+
|
|
3174
|
+
// src/config/settings-file.ts
|
|
3175
|
+
async function loadSettingsFile(gateway, cwd, definitions) {
|
|
3176
|
+
const loaded = await loadConfig(gateway, cwd, definitions);
|
|
3177
|
+
if (loaded.kind === "invalid") return refused(invalidConfig(loaded.path, loaded.problems));
|
|
3178
|
+
return loaded.kind === "loaded" ? { ok: true, path: loaded.path, values: loaded.values, definitions } : { ok: true, path: null, values: void 0, definitions };
|
|
3179
|
+
}
|
|
3180
|
+
function fileSettings(file, flags) {
|
|
3181
|
+
return resolveSettings(flags, file.values?.settings);
|
|
3182
|
+
}
|
|
3183
|
+
function fileOptions(file, definition) {
|
|
3184
|
+
if (!file.definitions.includes(definition))
|
|
3185
|
+
throw new Error(`The config file wasn't checked against ${definition.name}`);
|
|
3186
|
+
const given = file.values?.resources[defaultResourceKey(definition)];
|
|
3187
|
+
return given === void 0 || given.definition !== definition.name ? void 0 : givenOptionsOf(definition, given.options);
|
|
3188
|
+
}
|
|
3189
|
+
function settleRunResources(file, flags) {
|
|
3190
|
+
const merged = mergeRunResources(file.definitions, file.values?.resources, flags);
|
|
3191
|
+
if (!merged.ok) return refused(invalidResourceOptions(file.path, merged.problems));
|
|
3192
|
+
return {
|
|
3193
|
+
ok: true,
|
|
3194
|
+
options: merged.options,
|
|
3195
|
+
plan(run) {
|
|
3196
|
+
const resolved = merged.plan(run);
|
|
3197
|
+
if (!resolved.ok) return refused(invalidResourceOptions(file.path, resolved.problems));
|
|
3198
|
+
return { ok: true, resources: resolved.value, planned: resolved.planned };
|
|
3199
|
+
}
|
|
3200
|
+
};
|
|
3201
|
+
}
|
|
3202
|
+
function invalidConfig(file, problems) {
|
|
3203
|
+
return configErrors.invalidConfig({
|
|
3204
|
+
file,
|
|
3205
|
+
problems: problems.map(({ key, location, problem: problem2 }) => ({
|
|
3206
|
+
key,
|
|
3207
|
+
location: location === null ? null : { line: location.line, column: location.column ?? null },
|
|
3208
|
+
problem: problem2
|
|
3209
|
+
}))
|
|
3210
|
+
});
|
|
3211
|
+
}
|
|
3212
|
+
function invalidResourceOptions(configFile, problems) {
|
|
3213
|
+
return configErrors.invalidResourceOptions({
|
|
3214
|
+
configFile,
|
|
3215
|
+
problems: problems.map(({ key, problem: problem2, values }) => ({
|
|
3216
|
+
key,
|
|
3217
|
+
problem: problem2,
|
|
3218
|
+
values: values.map(({ key: valueKey, value, source }) => ({ key: valueKey, value: valueText(value), source }))
|
|
3219
|
+
}))
|
|
3220
|
+
});
|
|
3221
|
+
}
|
|
3222
|
+
function valueText(value) {
|
|
3223
|
+
return typeof value === "string" ? value : describeValue(value);
|
|
3224
|
+
}
|
|
3225
|
+
|
|
3226
|
+
// src/config/resolver.ts
|
|
3227
|
+
function configResolver(launcher) {
|
|
3228
|
+
return {
|
|
3229
|
+
async load(definition, options, target) {
|
|
3230
|
+
const file = await loadSettingsFile(launcher.gateway, launcher.cwd, launcher.definitions);
|
|
3231
|
+
if (!file.ok) return file;
|
|
3232
|
+
const settings = fileSettings(file, target);
|
|
3233
|
+
const key = defaultResourceKey(definition);
|
|
3234
|
+
const merged = mergeResourceOptions(definition, key, fileOptions(file, definition), options);
|
|
3235
|
+
if (!merged.ok) return { ok: false, refusal: invalidResourceOptions(file.path, merged.problems) };
|
|
3236
|
+
return {
|
|
3237
|
+
ok: true,
|
|
3238
|
+
options: merged.settings(NOT_COUNTED),
|
|
3239
|
+
target: { scope: settings.scope, project: settings.project },
|
|
3240
|
+
configFile: file.path
|
|
3241
|
+
};
|
|
3242
|
+
}
|
|
3243
|
+
};
|
|
3244
|
+
}
|
|
3245
|
+
|
|
3246
|
+
// src/extensions/testserver/credential-facts.ts
|
|
3247
|
+
import { z as z7 } from "zod";
|
|
3248
|
+
var credentialOriginSchema = z7.discriminatedUnion("source", [
|
|
3249
|
+
z7.object({
|
|
3250
|
+
/** The mint. */
|
|
3251
|
+
source: z7.literal("mint"),
|
|
3252
|
+
/** The control plane team the credential was minted for. */
|
|
3253
|
+
team: z7.string(),
|
|
3254
|
+
/** The control plane project the credential was minted for. */
|
|
3255
|
+
project: z7.string()
|
|
3256
|
+
}),
|
|
3257
|
+
z7.object({
|
|
3258
|
+
/** A GitHub Actions OIDC token request. */
|
|
3259
|
+
source: z7.literal("github-actions"),
|
|
3260
|
+
/** The token's aud and repository claims; null when they can't be read. */
|
|
3261
|
+
claims: z7.object({ aud: z7.string(), repository: z7.string() }).nullable()
|
|
3262
|
+
})
|
|
3263
|
+
]);
|
|
3264
|
+
var rejectedCredentialShape = {
|
|
3265
|
+
origin: credentialOriginSchema,
|
|
3266
|
+
/** The one fix: a trusted team and project for the mint, a Trusted Source rule for a GitHub Actions OIDC token. */
|
|
3267
|
+
fix: z7.string()
|
|
3268
|
+
};
|
|
3269
|
+
function rejectedCredentialFacts(origin) {
|
|
3270
|
+
return {
|
|
3271
|
+
origin: origin.source === "mint" ? { source: "mint", ...origin.target } : { source: "github-actions", claims: origin.claims === void 0 ? null : { ...origin.claims } },
|
|
3272
|
+
fix: rejectedCredentialFix(origin)
|
|
3273
|
+
};
|
|
3274
|
+
}
|
|
3275
|
+
function rejectedCredentialFix(origin) {
|
|
3276
|
+
if (origin.source === "mint")
|
|
3277
|
+
return "The Testserver control plane trusts development OIDC tokens only from projects in its Trusted Sources; vercel-internal mints for project vercel on team vercel. Use a trusted team and project, then retry.";
|
|
3278
|
+
const aud = origin.claims?.aud ?? "https://github.com/<owner>";
|
|
3279
|
+
const repository = origin.claims?.repository ?? "<owner>/<repo>";
|
|
3280
|
+
return `The Testserver control plane trusts GitHub Actions OIDC tokens only from repositories in its Trusted Sources. Ask the \`vercel/testserver\` owners for a Trusted Source rule matching \`aud: ${aud}\` and \`repository: ${repository}\`, then rerun the job.`;
|
|
3281
|
+
}
|
|
3282
|
+
function rejectedCredentialText(origin) {
|
|
3283
|
+
return origin.source === "mint" ? `the credential minted for project ${origin.project} on team ${origin.team}` : "the GitHub Actions OIDC token";
|
|
3284
|
+
}
|
|
3285
|
+
function credentialOriginRows(origin) {
|
|
3286
|
+
return origin.source === "mint" ? [["Team", origin.team], ["Project", origin.project]] : [
|
|
3287
|
+
["aud", origin.claims?.aud ?? "unreadable"],
|
|
3288
|
+
["repository", origin.claims?.repository ?? "unreadable"]
|
|
3289
|
+
];
|
|
3290
|
+
}
|
|
3291
|
+
|
|
3292
|
+
// src/extensions/testserver/pr-build-facts.ts
|
|
3293
|
+
import { z as z8 } from "zod";
|
|
3294
|
+
var pullRequestFailureKinds = [
|
|
3295
|
+
"no-token",
|
|
3296
|
+
"not-found",
|
|
3297
|
+
"rejected",
|
|
3298
|
+
"http-error",
|
|
3299
|
+
"connect-failed",
|
|
3300
|
+
"timeout",
|
|
3301
|
+
"malformed"
|
|
3302
|
+
];
|
|
3303
|
+
var prBuildsFailureKinds = ["not-found", "rejected", "http-error", "connect-failed", "timeout", "malformed"];
|
|
3304
|
+
var pullRequestUnreadableSchema = z8.object({
|
|
3305
|
+
/** The pull request number. */
|
|
3306
|
+
pr: z8.number(),
|
|
3307
|
+
/** The repository, vercel/api. */
|
|
3308
|
+
repo: z8.string(),
|
|
3309
|
+
/** Why: no GitHub token on the launch machine, or how reading the pull request from GitHub failed. */
|
|
3310
|
+
kind: z8.enum(pullRequestFailureKinds),
|
|
3311
|
+
/** The HTTP status GitHub answered with; null when it answered none, or with no-token. */
|
|
3312
|
+
status: z8.number().nullable(),
|
|
3313
|
+
/** What GitHub or the connection said, with no token in it; null when nothing. */
|
|
3314
|
+
message: z8.string().nullable(),
|
|
3315
|
+
/** Where the GitHub token came from: GITHUB_TOKEN, GH_TOKEN or gh auth token; null with no-token. */
|
|
3316
|
+
tokenOrigin: z8.enum(["GITHUB_TOKEN", "GH_TOKEN", "gh auth token"]).nullable()
|
|
3317
|
+
});
|
|
3318
|
+
var prBuildsUnlistedSchema = z8.object({
|
|
3319
|
+
pr: z8.number(),
|
|
3320
|
+
/** How reading the runs of vercel/api's Testserver workflow on the pull request, or a run's PR build, from GitHub failed. */
|
|
3321
|
+
failure: z8.object({
|
|
3322
|
+
kind: z8.enum(prBuildsFailureKinds),
|
|
3323
|
+
/** The HTTP status GitHub answered with; null when it answered none. */
|
|
3324
|
+
status: z8.number().nullable(),
|
|
3325
|
+
/** What GitHub or the connection said, with no token in it. */
|
|
3326
|
+
detail: z8.string()
|
|
3327
|
+
})
|
|
3328
|
+
});
|
|
3329
|
+
var prBuildNotReadySchema = z8.object({
|
|
3330
|
+
pr: z8.number(),
|
|
3331
|
+
/** The pull request's head commit, 40 hex characters. */
|
|
3332
|
+
headSha: z8.string(),
|
|
3333
|
+
/** The newest PR build of an older head commit of the pull request; null when it has none. */
|
|
3334
|
+
newest: z8.object({
|
|
3335
|
+
build: z8.string(),
|
|
3336
|
+
/** The head commit the build was made from. */
|
|
3337
|
+
headSha: z8.string(),
|
|
3338
|
+
createdAt: z8.string()
|
|
3339
|
+
}).nullable()
|
|
3340
|
+
});
|
|
3341
|
+
var prBuildExpiredSchema = z8.object({
|
|
3342
|
+
pr: z8.number(),
|
|
3343
|
+
headSha: z8.string(),
|
|
3344
|
+
/** The newest PR build made from the head commit. */
|
|
3345
|
+
build: z8.string(),
|
|
3346
|
+
/** When the Testserver control plane stopped creating Testserver sandboxes from it. */
|
|
3347
|
+
expiresAt: z8.string()
|
|
3348
|
+
});
|
|
3349
|
+
function prBuildRefusalFacts(refusal) {
|
|
3350
|
+
switch (refusal.kind) {
|
|
3351
|
+
case "pull-request-unreadable": {
|
|
3352
|
+
const { failure } = refusal;
|
|
3353
|
+
const said2 = pullRequestSaid(failure);
|
|
3354
|
+
return {
|
|
3355
|
+
key: "pullRequestUnreadable",
|
|
3356
|
+
data: {
|
|
3357
|
+
pr: refusal.pr,
|
|
3358
|
+
repo: TESTSERVER_REPO,
|
|
3359
|
+
kind: failure.kind,
|
|
3360
|
+
status: "status" in failure ? failure.status : null,
|
|
3361
|
+
message: said2,
|
|
3362
|
+
tokenOrigin: refusal.tokenOrigin ?? null
|
|
3363
|
+
}
|
|
3364
|
+
};
|
|
3365
|
+
}
|
|
3366
|
+
case "pr-builds-unlisted": {
|
|
3367
|
+
const { failure } = refusal;
|
|
3368
|
+
return {
|
|
3369
|
+
key: "prBuildsUnlisted",
|
|
3370
|
+
data: {
|
|
3371
|
+
pr: refusal.pr,
|
|
3372
|
+
failure: {
|
|
3373
|
+
kind: failure.kind,
|
|
3374
|
+
status: "status" in failure ? failure.status : null,
|
|
3375
|
+
detail: gitHubSaid(failure)
|
|
3376
|
+
}
|
|
3377
|
+
}
|
|
3378
|
+
};
|
|
3379
|
+
}
|
|
3380
|
+
case "pr-build-not-ready": {
|
|
3381
|
+
const { newest } = refusal;
|
|
3382
|
+
return {
|
|
3383
|
+
key: "prBuildNotReady",
|
|
3384
|
+
data: {
|
|
3385
|
+
pr: refusal.pr,
|
|
3386
|
+
headSha: refusal.headSha,
|
|
3387
|
+
newest: newest === void 0 ? null : { build: newest.build, headSha: newest.headSha, createdAt: newest.createdAt }
|
|
3388
|
+
}
|
|
3389
|
+
};
|
|
3390
|
+
}
|
|
3391
|
+
case "pr-build-expired":
|
|
3392
|
+
return {
|
|
3393
|
+
key: "prBuildExpired",
|
|
3394
|
+
data: { pr: refusal.pr, headSha: refusal.headSha, build: refusal.build, expiresAt: refusal.expiresAt }
|
|
3395
|
+
};
|
|
3396
|
+
}
|
|
3397
|
+
}
|
|
3398
|
+
function pullRequestSaid(failure) {
|
|
3399
|
+
return failure.kind === "no-token" || failure.kind === "not-found" ? null : gitHubSaid(failure);
|
|
3400
|
+
}
|
|
3401
|
+
function gitHubSaid(failure) {
|
|
3402
|
+
switch (failure.kind) {
|
|
3403
|
+
case "not-found":
|
|
3404
|
+
return "HTTP 404";
|
|
3405
|
+
case "rejected":
|
|
3406
|
+
case "http-error":
|
|
3407
|
+
return failure.message;
|
|
3408
|
+
case "connect-failed":
|
|
3409
|
+
return failure.code;
|
|
3410
|
+
case "timeout":
|
|
3411
|
+
return `no answer within ${failure.seconds}s`;
|
|
3412
|
+
case "malformed":
|
|
3413
|
+
return failure.detail;
|
|
3414
|
+
}
|
|
3415
|
+
}
|
|
3416
|
+
function sentence(text) {
|
|
3417
|
+
return /[.!?]$/.test(text) ? text : `${text}.`;
|
|
3418
|
+
}
|
|
3419
|
+
function pullRequestName(pr) {
|
|
3420
|
+
return `${TESTSERVER_REPO}#${pr}`;
|
|
3421
|
+
}
|
|
3422
|
+
function pullRequestUrl(pr) {
|
|
3423
|
+
return `https://github.com/${TESTSERVER_REPO}/pull/${pr}`;
|
|
3424
|
+
}
|
|
3425
|
+
function checksStep(pr) {
|
|
3426
|
+
return {
|
|
3427
|
+
type: "external",
|
|
3428
|
+
argv: ["gh", "pr", "checks", String(pr), "--repo", TESTSERVER_REPO],
|
|
3429
|
+
label: "Show the pull request's checks"
|
|
3430
|
+
};
|
|
3431
|
+
}
|
|
3432
|
+
function pullRequestUnreadableContent({ pr, kind: kind2, status, message, tokenOrigin }, outcome) {
|
|
3433
|
+
const name = pullRequestName(pr);
|
|
3434
|
+
const origin = tokenOrigin ?? "the launch machine";
|
|
3435
|
+
const text = (() => {
|
|
3436
|
+
switch (kind2) {
|
|
3437
|
+
case "no-token":
|
|
3438
|
+
return `storm needs a GitHub token to read ${name}. Set GITHUB_TOKEN or GH_TOKEN, or run gh auth login.`;
|
|
3439
|
+
case "not-found":
|
|
3440
|
+
return `${name} doesn't exist, or the token from ${origin} can't read ${TESTSERVER_REPO}.`;
|
|
3441
|
+
case "rejected":
|
|
3442
|
+
return `GitHub refused the token from ${origin} (HTTP ${status ?? "error"}): ${message ?? ""}`;
|
|
3443
|
+
case "http-error":
|
|
3444
|
+
return `GitHub couldn't read ${name} (HTTP ${status ?? "error"}): ${message ?? ""}`;
|
|
3445
|
+
case "connect-failed":
|
|
3446
|
+
return `Couldn't reach GitHub to read ${name} (${message ?? "no connection"}).`;
|
|
3447
|
+
case "timeout":
|
|
3448
|
+
return `GitHub didn't answer the request for ${name}: ${message ?? "timeout"}.`;
|
|
3449
|
+
case "malformed":
|
|
3450
|
+
return `GitHub's answer for ${name} isn't a pull request: ${message ?? ""}`;
|
|
3451
|
+
}
|
|
3452
|
+
})();
|
|
3453
|
+
return {
|
|
3454
|
+
message: `${sentence(text)} ${outcome}`,
|
|
3455
|
+
rows: [
|
|
3456
|
+
["Pull request", pullRequestUrl(pr)],
|
|
3457
|
+
...tokenOrigin === null ? [] : [["GitHub token from", tokenOrigin]]
|
|
3458
|
+
],
|
|
3459
|
+
next: [
|
|
3460
|
+
{ type: "external", argv: ["gh", "auth", "status"], label: "Check the GitHub login" },
|
|
3461
|
+
{
|
|
3462
|
+
type: "text",
|
|
3463
|
+
text: `Run gh auth login, or set GITHUB_TOKEN to a token that can read ${TESTSERVER_REPO}. Then retry.`
|
|
3464
|
+
}
|
|
3465
|
+
]
|
|
3466
|
+
};
|
|
3467
|
+
}
|
|
3468
|
+
function prBuildsUnlistedContent({ pr, failure }, outcome) {
|
|
3469
|
+
return {
|
|
3470
|
+
message: `${sentence(`Couldn't read ${pullRequestName(pr)}'s Testserver builds from GitHub Actions: ${failure.kind}${failure.status === null ? "" : ` (HTTP ${failure.status})`}: ${failure.detail}`)} ${outcome}`,
|
|
3471
|
+
next: [
|
|
3472
|
+
{ type: "external", argv: ["gh", "auth", "status"], label: "Check the GitHub login" },
|
|
3473
|
+
{ type: "text", text: `Make sure that the token can read ${TESTSERVER_REPO}'s Actions, then retry.` }
|
|
3474
|
+
]
|
|
3475
|
+
};
|
|
3476
|
+
}
|
|
3477
|
+
function prBuildNotReadyContent({ pr, headSha, newest }, outcome) {
|
|
3478
|
+
const name = pullRequestName(pr);
|
|
3479
|
+
const text = newest === null ? `${name} has no Testserver build from its head, ${shortSha(headSha)}, yet.` : `${name}'s newest Testserver build, ${newest.build}, is from ${shortSha(newest.headSha)}; the PR's head is ${shortSha(headSha)}.`;
|
|
3480
|
+
return {
|
|
3481
|
+
message: `${text} ${outcome}`,
|
|
3482
|
+
rows: [
|
|
3483
|
+
["Pull request", pullRequestUrl(pr)],
|
|
3484
|
+
["Head commit", headSha],
|
|
3485
|
+
["Newest build", newest === null ? "none" : `${newest.build} (${newest.createdAt})`]
|
|
3486
|
+
],
|
|
3487
|
+
next: [
|
|
3488
|
+
{
|
|
3489
|
+
type: "text",
|
|
3490
|
+
text: "Wait for the Bundle & Publish check on the PR's head to pass, then retry. If the check failed, push a fix to the PR."
|
|
3491
|
+
},
|
|
3492
|
+
checksStep(pr)
|
|
3493
|
+
]
|
|
3494
|
+
};
|
|
3495
|
+
}
|
|
3496
|
+
function prBuildExpiredContent({ pr, headSha, build, expiresAt }, outcome) {
|
|
3497
|
+
return {
|
|
3498
|
+
message: `${pullRequestName(pr)}'s build for its head, ${build}, expired at ${expiresAt}. ${outcome}`,
|
|
3499
|
+
rows: [
|
|
3500
|
+
["Pull request", pullRequestUrl(pr)],
|
|
3501
|
+
["Head commit", headSha]
|
|
3502
|
+
],
|
|
3503
|
+
next: [
|
|
3504
|
+
{
|
|
3505
|
+
type: "text",
|
|
3506
|
+
text: `Push to the PR, or rerun its Testserver workflow (gh run rerun <run-id> --repo ${TESTSERVER_REPO}, or the PR's Checks page). Then retry.`
|
|
3507
|
+
},
|
|
3508
|
+
checksStep(pr)
|
|
3509
|
+
]
|
|
3510
|
+
};
|
|
3511
|
+
}
|
|
3512
|
+
var PR_BUILD_REFUSAL_DESCRIPTIONS = {
|
|
3513
|
+
pullRequestUnreadable: "storm couldn't read the vercel/api pull request that the PR build reference names from GitHub. It has no GitHub token, or GitHub refused the request. storm reads the token from GITHUB_TOKEN, then GH_TOKEN, then gh auth token.",
|
|
3514
|
+
prBuildsUnlisted: "storm couldn't read from GitHub the runs of vercel/api's Testserver workflow on the pull request that the PR build reference names, or the PR build a run published.",
|
|
3515
|
+
prBuildNotReady: "No run of vercel/api's Testserver workflow for the pull request's head commit has published a Testserver build: the Bundle & Publish check of the newest push has not finished, or it failed. storm never runs on a build from an older commit.",
|
|
3516
|
+
prBuildExpired: "The newest Testserver build from the vercel/api pull request's head commit was published 7 days ago or more, so the Testserver control plane creates no Testserver sandbox from it."
|
|
3517
|
+
};
|
|
3518
|
+
function prBuildRefusalErrors(outcome) {
|
|
3519
|
+
return {
|
|
3520
|
+
pullRequestUnreadable: {
|
|
3521
|
+
exitCode: 1,
|
|
3522
|
+
description: PR_BUILD_REFUSAL_DESCRIPTIONS.pullRequestUnreadable,
|
|
3523
|
+
schema: pullRequestUnreadableSchema,
|
|
3524
|
+
render: (data) => pullRequestUnreadableContent(data, outcome)
|
|
3525
|
+
},
|
|
3526
|
+
prBuildsUnlisted: {
|
|
3527
|
+
exitCode: 1,
|
|
3528
|
+
description: PR_BUILD_REFUSAL_DESCRIPTIONS.prBuildsUnlisted,
|
|
3529
|
+
schema: prBuildsUnlistedSchema,
|
|
3530
|
+
render: (data) => prBuildsUnlistedContent(data, outcome)
|
|
3531
|
+
},
|
|
3532
|
+
prBuildNotReady: {
|
|
3533
|
+
exitCode: 1,
|
|
3534
|
+
description: PR_BUILD_REFUSAL_DESCRIPTIONS.prBuildNotReady,
|
|
3535
|
+
schema: prBuildNotReadySchema,
|
|
3536
|
+
render: (data) => prBuildNotReadyContent(data, outcome)
|
|
3537
|
+
},
|
|
3538
|
+
prBuildExpired: {
|
|
3539
|
+
exitCode: 1,
|
|
3540
|
+
description: PR_BUILD_REFUSAL_DESCRIPTIONS.prBuildExpired,
|
|
3541
|
+
schema: prBuildExpiredSchema,
|
|
3542
|
+
render: (data) => prBuildExpiredContent(data, outcome)
|
|
3543
|
+
}
|
|
3544
|
+
};
|
|
3545
|
+
}
|
|
3546
|
+
function prBuildRefusal(refusal, outcome) {
|
|
3547
|
+
const facts = prBuildRefusalFacts(refusal);
|
|
3548
|
+
const content = (() => {
|
|
3549
|
+
switch (facts.key) {
|
|
3550
|
+
case "pullRequestUnreadable":
|
|
3551
|
+
return pullRequestUnreadableContent(facts.data, outcome);
|
|
3552
|
+
case "prBuildsUnlisted":
|
|
3553
|
+
return prBuildsUnlistedContent(facts.data, outcome);
|
|
3554
|
+
case "prBuildNotReady":
|
|
3555
|
+
return prBuildNotReadyContent(facts.data, outcome);
|
|
3556
|
+
case "prBuildExpired":
|
|
3557
|
+
return prBuildExpiredContent(facts.data, outcome);
|
|
3558
|
+
}
|
|
3559
|
+
})();
|
|
3560
|
+
return { refused: PR_BUILD_REASONS[facts.key], data: { ...facts.data }, ...content };
|
|
3561
|
+
}
|
|
3562
|
+
var PR_BUILD_REASONS = {
|
|
3563
|
+
pullRequestUnreadable: "pull_request_unreadable",
|
|
3564
|
+
prBuildsUnlisted: "pr_builds_unlisted",
|
|
3565
|
+
prBuildNotReady: "pr_build_not_ready",
|
|
3566
|
+
prBuildExpired: "pr_build_expired"
|
|
3567
|
+
};
|
|
3568
|
+
|
|
3569
|
+
// src/extensions/testserver/run/connection.ts
|
|
3570
|
+
var TESTSERVER_POOL_NAME = "testserverPool";
|
|
3571
|
+
function checkTestserverConnection(section) {
|
|
3572
|
+
if (!isObject(section)) return problem([], "must be an object");
|
|
3573
|
+
const { sandboxes } = section;
|
|
3574
|
+
if (!Array.isArray(sandboxes)) return problem(["sandboxes"], "must be an array");
|
|
3575
|
+
const checked = [];
|
|
3576
|
+
for (const [index, sandbox] of sandboxes.entries()) {
|
|
3577
|
+
if (!isObject(sandbox)) return problem(["sandboxes", index], "must be an object");
|
|
3578
|
+
const { url } = sandbox;
|
|
3579
|
+
if (typeof url !== "string" || url === "") {
|
|
3580
|
+
return problem(["sandboxes", index, "url"], "must be a non-empty string");
|
|
3581
|
+
}
|
|
3582
|
+
checked.push({ url });
|
|
3583
|
+
}
|
|
3584
|
+
return { ok: true, value: { sandboxes: checked } };
|
|
3585
|
+
}
|
|
3586
|
+
function isObject(value) {
|
|
3587
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3588
|
+
}
|
|
3589
|
+
function problem(at, text) {
|
|
3590
|
+
return { ok: false, at, problem: text };
|
|
3591
|
+
}
|
|
3592
|
+
var testserverConnection = Object.freeze({ name: TESTSERVER_POOL_NAME, payload: checkTestserverConnection });
|
|
3593
|
+
|
|
3594
|
+
// src/extensions/testserver/canceled.ts
|
|
3595
|
+
function testserverCanceledLines(facts) {
|
|
3596
|
+
const { pooled, unpooled, failedCreates, ttlMinutes: ttlMinutes2 } = facts;
|
|
3597
|
+
const ttl = ttlMinutes2 === void 0 ? "its TTL" : describeTtl(ttlMinutes2);
|
|
3598
|
+
const lines = [];
|
|
3599
|
+
if (pooled > 0) {
|
|
3600
|
+
const sandboxes = pooled === 1 ? "Testserver sandbox" : `${pooled} Testserver sandboxes`;
|
|
3601
|
+
lines.push(`It added the ${sandboxes} it created to the pool.`);
|
|
3602
|
+
}
|
|
3603
|
+
if (unpooled.length > 0) {
|
|
3604
|
+
const one = unpooled.length === 1;
|
|
3605
|
+
lines.push(
|
|
3606
|
+
`It couldn't add ${one ? "a" : unpooled.length} Testserver ${one ? "sandbox" : "sandboxes"} it created to the pool; ${one ? "it expires" : "they expire"} within ${ttl}:`,
|
|
3607
|
+
...unpooled.map(({ testserverUrl, failure }) => ` ${testserverUrl}: ${failure.message}`)
|
|
3608
|
+
);
|
|
3609
|
+
}
|
|
3610
|
+
if (failedCreates.some(mayLeaveSandbox))
|
|
3611
|
+
lines.push(
|
|
3612
|
+
`A create that reached the Testserver control plane may have left a Testserver sandbox; nothing can delete it, and it expires within ${ttl}.`
|
|
3613
|
+
);
|
|
3614
|
+
return lines;
|
|
3615
|
+
}
|
|
3616
|
+
|
|
3617
|
+
// src/extensions/testserver/limit.ts
|
|
3618
|
+
async function runLimited(count2, limit, proceed, task) {
|
|
3619
|
+
const results = Array.from({ length: count2 }, () => void 0);
|
|
3620
|
+
let failure;
|
|
3621
|
+
let next = 0;
|
|
3622
|
+
const worker = async () => {
|
|
3623
|
+
while (failure === void 0 && next < count2 && proceed()) {
|
|
3624
|
+
const index = next;
|
|
3625
|
+
next += 1;
|
|
3626
|
+
try {
|
|
3627
|
+
results[index] = await task(index);
|
|
3628
|
+
} catch (error) {
|
|
3629
|
+
failure ??= { error };
|
|
3630
|
+
}
|
|
3631
|
+
}
|
|
3632
|
+
};
|
|
3633
|
+
await Promise.all(Array.from({ length: Math.min(limit, count2) }, worker));
|
|
3634
|
+
if (failure !== void 0) throw failure.error;
|
|
3635
|
+
return results;
|
|
3636
|
+
}
|
|
3637
|
+
|
|
3638
|
+
// src/extensions/testserver/provision.ts
|
|
3639
|
+
function unpooledFacts(unpooled) {
|
|
3640
|
+
return unpooled.map(({ testserverUrl, failure }) => ({
|
|
3641
|
+
testserverUrl,
|
|
3642
|
+
path: failure.path,
|
|
3643
|
+
message: failure.message
|
|
3644
|
+
}));
|
|
3645
|
+
}
|
|
3646
|
+
function failedCreateFacts(failures) {
|
|
3647
|
+
return failures.map((failure) => {
|
|
3648
|
+
const { kind: kind2, detail } = describeCreateFailure(failure);
|
|
3649
|
+
return { kind: kind2, detail };
|
|
3650
|
+
});
|
|
3651
|
+
}
|
|
3652
|
+
function createWith(options, credential) {
|
|
3653
|
+
if (!options.create) return void 0;
|
|
3654
|
+
if (credential === void 0)
|
|
3655
|
+
throw new Error("A Testserver pool that creates needs the Vercel credential, so its run chooses a source.");
|
|
3656
|
+
return { source: credential, ttlMinutes: ttlMinutes(options) };
|
|
3657
|
+
}
|
|
3658
|
+
function credentialFailed(failure, ttlMinutes2, failedCreates) {
|
|
3659
|
+
return failure.source === "mint" ? { kind: "mint-failed", failed: failure } : { kind: "token-request-failed", failure: failure.failure, ttlMinutes: ttlMinutes2, failedCreates };
|
|
3660
|
+
}
|
|
3661
|
+
function testserverCanceledFacts(options, facts) {
|
|
3662
|
+
return canceledAfter(facts, options.create ? ttlMinutes(options) : void 0);
|
|
3663
|
+
}
|
|
3664
|
+
function canceledAfter(facts, ttlMinutes2) {
|
|
3665
|
+
const created = facts.sandboxes.filter((sandbox) => sandbox.origin === "created").length;
|
|
3666
|
+
return {
|
|
3667
|
+
pooled: created - facts.unpooled.length,
|
|
3668
|
+
unpooled: facts.unpooled,
|
|
3669
|
+
failedCreates: facts.failedCreates,
|
|
3670
|
+
ttlMinutes: ttlMinutes2
|
|
3671
|
+
};
|
|
3672
|
+
}
|
|
3673
|
+
async function provision(world, options, create, signal, report, take) {
|
|
3674
|
+
let tally = { created: [], failedCreates: [], unpooled: [] };
|
|
3675
|
+
const canceled = () => ({
|
|
3676
|
+
kind: "canceled",
|
|
3677
|
+
pooled: tally.created.length - tally.unpooled.length,
|
|
3678
|
+
unpooled: tally.unpooled,
|
|
3679
|
+
failedCreates: tally.failedCreates,
|
|
3680
|
+
ttlMinutes: create?.ttlMinutes
|
|
3681
|
+
});
|
|
3682
|
+
if (signal.aborted) return canceled();
|
|
3683
|
+
const reference = parseBuildReference(options.build);
|
|
3684
|
+
let resolution;
|
|
3685
|
+
if (reference.ok && reference.reference.kind === "pull-request") {
|
|
3686
|
+
const resolved = await resolvePullRequestBuild(world, reference.reference.number, report);
|
|
3687
|
+
if (resolved.kind !== "resolved") return resolved;
|
|
3688
|
+
resolution = resolved.resolution;
|
|
3689
|
+
} else {
|
|
3690
|
+
resolution = await resolveBuild(world, { build: options.build, credential: create?.source });
|
|
3691
|
+
if (resolution.kind === "as-written")
|
|
3692
|
+
await report.progress({ kind: "build-unresolved", channel: resolution.channel, reason: resolution.reason });
|
|
3693
|
+
if (resolution.kind === "old-channel-resolution")
|
|
3694
|
+
await report.progress({
|
|
3695
|
+
kind: "old-channel-resolution",
|
|
3696
|
+
channel: resolution.channel,
|
|
3697
|
+
build: resolution.build,
|
|
3698
|
+
ageMinutes: minutesSince(resolution.learnedAt, world.clock.now())
|
|
3699
|
+
});
|
|
3700
|
+
}
|
|
3701
|
+
if (signal.aborted) return canceled();
|
|
3702
|
+
const match = buildMatch(resolution);
|
|
3703
|
+
await report.progress({ kind: "leasing", match, requested: options.sandboxes });
|
|
3704
|
+
const leasedOutcome = await leaseUsable(world, {
|
|
3705
|
+
match,
|
|
3706
|
+
count: options.sandboxes,
|
|
3707
|
+
minTimeLeftMinutes: minTimeLeftMinutes(options)
|
|
3708
|
+
});
|
|
3709
|
+
if (!leasedOutcome.ok) return { kind: "pool-unreadable", failure: leasedOutcome.failure };
|
|
3710
|
+
const upkeep = leasedOutcome.report;
|
|
3711
|
+
for (const { host } of upkeep.leased) take(host);
|
|
3712
|
+
await report.progress({ kind: "leased", match, requested: options.sandboxes, report: upkeep });
|
|
3713
|
+
const reused = upkeep.leased.map(({ entry }) => ({
|
|
3714
|
+
testserverUrl: entry.testserverUrl,
|
|
3715
|
+
logViewerUrl: entry.logViewerUrl,
|
|
3716
|
+
origin: "reused"
|
|
3717
|
+
}));
|
|
3718
|
+
let uncreated;
|
|
3719
|
+
let notCreated = 0;
|
|
3720
|
+
const missing = options.sandboxes - reused.length;
|
|
3721
|
+
if (missing > 0 && create === void 0) {
|
|
3722
|
+
if (reused.length === 0) return { kind: "no-usable-sandboxes", requested: options.sandboxes, match };
|
|
3723
|
+
notCreated = missing;
|
|
3724
|
+
} else if (missing > 0 && create !== void 0) {
|
|
3725
|
+
if (signal.aborted) return canceled();
|
|
3726
|
+
const { rejected, credentialFailure, uncreatedCount, ...made } = await createMissing(
|
|
3727
|
+
world,
|
|
3728
|
+
{
|
|
3729
|
+
source: create.source,
|
|
3730
|
+
target: createTarget(options.build, resolution),
|
|
3731
|
+
ttlMinutes: create.ttlMinutes,
|
|
3732
|
+
count: missing
|
|
3733
|
+
},
|
|
3734
|
+
signal,
|
|
3735
|
+
report,
|
|
3736
|
+
take
|
|
3737
|
+
);
|
|
3738
|
+
tally = made;
|
|
3739
|
+
if (rejected !== void 0)
|
|
3740
|
+
return {
|
|
3741
|
+
kind: "credential-rejected",
|
|
3742
|
+
failure: rejected.failure,
|
|
3743
|
+
origin: create.source.origin(rejected.credential),
|
|
3744
|
+
ttlMinutes: create.ttlMinutes,
|
|
3745
|
+
failedCreates: tally.failedCreates,
|
|
3746
|
+
unpooled: tally.unpooled
|
|
3747
|
+
};
|
|
3748
|
+
if (signal.aborted) return canceled();
|
|
3749
|
+
if (credentialFailure !== void 0) {
|
|
3750
|
+
if (reused.length === 0 && tally.created.length === 0)
|
|
3751
|
+
return credentialFailed(credentialFailure, create.ttlMinutes, tally.failedCreates);
|
|
3752
|
+
uncreated = { count: uncreatedCount, failure: credentialFailure };
|
|
3753
|
+
}
|
|
3754
|
+
if (reused.length === 0 && tally.created.length === 0)
|
|
3755
|
+
return {
|
|
3756
|
+
kind: "no-sandboxes",
|
|
3757
|
+
requested: options.sandboxes,
|
|
3758
|
+
ttlMinutes: create.ttlMinutes,
|
|
3759
|
+
failedCreates: tally.failedCreates
|
|
3760
|
+
};
|
|
3761
|
+
}
|
|
3762
|
+
const sandboxes = [...reused, ...tally.created];
|
|
3763
|
+
if (signal.aborted) return canceled();
|
|
3764
|
+
return {
|
|
3765
|
+
kind: "provisioned",
|
|
3766
|
+
resolution,
|
|
3767
|
+
sandboxes,
|
|
3768
|
+
failedCreates: tally.failedCreates,
|
|
3769
|
+
unpooled: tally.unpooled,
|
|
3770
|
+
uncreated,
|
|
3771
|
+
notCreated
|
|
3772
|
+
};
|
|
3773
|
+
}
|
|
3774
|
+
async function resolvePullRequestBuild(world, pr, report) {
|
|
3775
|
+
const outcome = await resolvePrBuild(world, { pr });
|
|
3776
|
+
if (!outcome.ok) return outcome.refusal;
|
|
3777
|
+
const { resolution } = outcome;
|
|
3778
|
+
const { headSha, build, merged, from } = resolution;
|
|
3779
|
+
await report.progress({ kind: "pr-build-resolved", pr, headSha, build, merged, from });
|
|
3780
|
+
return { kind: "resolved", resolution };
|
|
3781
|
+
}
|
|
3782
|
+
function createTarget(requestedBuild, resolution) {
|
|
3783
|
+
return resolution.kind === "pull-request" ? { build: resolution.build, requestedBuild, headSha: resolution.headSha } : { build: requestedBuild, requestedBuild };
|
|
3784
|
+
}
|
|
3785
|
+
async function createMissing(world, request2, signal, report, take) {
|
|
3786
|
+
const { source, target, ttlMinutes: ttlMinutes2, count: count2 } = request2;
|
|
3787
|
+
const first = await source.obtain();
|
|
3788
|
+
if (!first.ok)
|
|
3789
|
+
return {
|
|
3790
|
+
created: [],
|
|
3791
|
+
failedCreates: [],
|
|
3792
|
+
unpooled: [],
|
|
3793
|
+
rejected: void 0,
|
|
3794
|
+
credentialFailure: first.failure,
|
|
3795
|
+
uncreatedCount: count2
|
|
3796
|
+
};
|
|
3797
|
+
await report.progress({ kind: "creating", count: count2, build: target.build });
|
|
3798
|
+
let rejected;
|
|
3799
|
+
let credentialFailure;
|
|
3800
|
+
const mayCreate = () => rejected === void 0 && credentialFailure === void 0 && !signal.aborted;
|
|
3801
|
+
const outcomes = await runLimited(
|
|
3802
|
+
count2,
|
|
3803
|
+
CREATE_CONCURRENCY,
|
|
3804
|
+
mayCreate,
|
|
3805
|
+
async (index) => {
|
|
3806
|
+
const got = await source.obtain();
|
|
3807
|
+
if (!got.ok) {
|
|
3808
|
+
credentialFailure ??= got.failure;
|
|
3809
|
+
return void 0;
|
|
3810
|
+
}
|
|
3811
|
+
if (!mayCreate()) return void 0;
|
|
3812
|
+
const { credential } = got;
|
|
3813
|
+
await report.progress({ kind: "create-started", index, count: count2 });
|
|
3814
|
+
const outcome = await createPooledSandbox(
|
|
3815
|
+
world,
|
|
3816
|
+
{ credential, ...target, ttlMinutes: ttlMinutes2, lease: true },
|
|
3817
|
+
{ onProgress: (message) => report.progress({ kind: "create-progress", index, count: count2, message }) }
|
|
3818
|
+
);
|
|
3819
|
+
if (outcome.kind === "pooled") take(outcome.host);
|
|
3820
|
+
if (outcome.kind === "create-failed" && outcome.failure.kind === "rejected")
|
|
3821
|
+
rejected ??= { failure: outcome.failure, credential };
|
|
3822
|
+
await report.progress({ kind: "create-finished", index, count: count2, outcome });
|
|
3823
|
+
return outcome;
|
|
3824
|
+
}
|
|
3825
|
+
);
|
|
3826
|
+
const created = [];
|
|
3827
|
+
const failedCreates = [];
|
|
3828
|
+
const unpooled = [];
|
|
3829
|
+
let uncreatedCount = 0;
|
|
3830
|
+
for (const outcome of outcomes) {
|
|
3831
|
+
if (outcome === void 0) {
|
|
3832
|
+
uncreatedCount += 1;
|
|
3833
|
+
continue;
|
|
3834
|
+
}
|
|
3835
|
+
if (outcome.kind === "create-failed") {
|
|
3836
|
+
const { failure } = outcome;
|
|
3837
|
+
if (failure.kind !== "rejected") failedCreates.push(failure);
|
|
3838
|
+
continue;
|
|
3839
|
+
}
|
|
3840
|
+
const { testserverUrl, logViewerUrl } = outcome.entry;
|
|
3841
|
+
created.push({ testserverUrl, logViewerUrl, origin: "created" });
|
|
3842
|
+
if (outcome.kind === "pool-write-failed") unpooled.push({ testserverUrl, failure: outcome.failure });
|
|
3843
|
+
}
|
|
3844
|
+
return { created, failedCreates, unpooled, rejected, credentialFailure, uncreatedCount };
|
|
3845
|
+
}
|
|
3846
|
+
|
|
3847
|
+
// src/extensions/testserver/refusals.ts
|
|
3848
|
+
var NOT_RUN = "The command didn't run.";
|
|
3849
|
+
function unpooledRows(unpooled) {
|
|
3850
|
+
return unpooled.length === 0 ? [] : [["Unpooled Testserver sandboxes", unpooled.map(({ testserverUrl, message }) => `${testserverUrl}: ${message}`)]];
|
|
3851
|
+
}
|
|
3852
|
+
function failedCreateRows(failedCreates) {
|
|
3853
|
+
return failedCreates.length === 0 ? [] : [["Failed creates", failedCreates.map(createFailureText)]];
|
|
3854
|
+
}
|
|
3855
|
+
function sandboxMayExist(ttlMinutes2) {
|
|
3856
|
+
return `A create that reached the Testserver control plane may have left a Testserver sandbox anyway; nothing can delete it, and it expires within ${describeTtl(ttlMinutes2)}.`;
|
|
3857
|
+
}
|
|
3858
|
+
function mayExistSteps(mayExist, ttlMinutes2) {
|
|
3859
|
+
return mayExist ? [{ type: "text", text: sandboxMayExist(ttlMinutes2) }] : [];
|
|
3860
|
+
}
|
|
3861
|
+
var CREATE_KEY_PATH = optionKeyPath("testserverPool", "create");
|
|
3862
|
+
function poolUnavailable(data) {
|
|
3863
|
+
return {
|
|
3864
|
+
refused: "pool_unavailable",
|
|
3865
|
+
data: { path: data.path, message: data.message },
|
|
3866
|
+
message: `Couldn't prepare the pool: ${data.message}`,
|
|
3867
|
+
rows: [["Pool path", data.path]],
|
|
3868
|
+
next: [{ type: "text", text: `Fix the pool path, then retry. ${NOT_RUN}` }]
|
|
3869
|
+
};
|
|
3870
|
+
}
|
|
3871
|
+
function poolUnreadable(data) {
|
|
3872
|
+
return {
|
|
3873
|
+
refused: "pool_unreadable",
|
|
3874
|
+
data: { path: data.path, message: data.message },
|
|
3875
|
+
message: `Couldn't read the pool: ${data.message}`,
|
|
3876
|
+
rows: [["Pool path", data.path]],
|
|
3877
|
+
next: [{ type: "text", text: `Fix the pool path, then retry. ${NOT_RUN}` }]
|
|
3878
|
+
};
|
|
3879
|
+
}
|
|
3880
|
+
function tokenRequestFailed(failure, data) {
|
|
3881
|
+
const facts = tokenRequestFailureFacts(failure);
|
|
3882
|
+
const { ttlMinutes: ttlMinutes2, failedCreates, sandboxMayExist: mayExist } = data;
|
|
3883
|
+
return {
|
|
3884
|
+
refused: "token_request_failed",
|
|
3885
|
+
data: { ...facts, ...data },
|
|
3886
|
+
message: `Couldn't request a GitHub Actions OIDC token: ${facts.detail}. The pool had no usable Testserver sandbox, so the command didn't run.`,
|
|
3887
|
+
rows: failedCreateRows(failedCreates),
|
|
3888
|
+
next: [{ type: "text", text: facts.fix }, ...mayExistSteps(mayExist, ttlMinutes2)]
|
|
3889
|
+
};
|
|
3890
|
+
}
|
|
3891
|
+
function credentialRejected(credential, data) {
|
|
3892
|
+
const { origin, fix } = rejectedCredentialFacts(credential);
|
|
3893
|
+
const { status, vercelId, ttlMinutes: ttlMinutes2, failedCreates, unpooled, sandboxMayExist: mayExist } = data;
|
|
3894
|
+
return {
|
|
3895
|
+
refused: "credential_rejected",
|
|
3896
|
+
data: { origin, fix, ...data },
|
|
3897
|
+
message: `The Testserver control plane rejected ${rejectedCredentialText(origin)} (HTTP ${status}, x-vercel-id ${vercelId ?? "unknown"}). ${NOT_RUN}`,
|
|
3898
|
+
rows: [...credentialOriginRows(origin), ...unpooledRows(unpooled), ...failedCreateRows(failedCreates)],
|
|
3899
|
+
next: [{ type: "text", text: fix }, ...mayExistSteps(mayExist, ttlMinutes2)]
|
|
3900
|
+
};
|
|
3901
|
+
}
|
|
3902
|
+
function noSandboxes(data) {
|
|
3903
|
+
const { requested, ttlMinutes: ttlMinutes2, failedCreates, sandboxMayExist: mayExist } = data;
|
|
3904
|
+
return {
|
|
3905
|
+
refused: "no_sandboxes",
|
|
3906
|
+
data: { ...data },
|
|
3907
|
+
message: `Got none of the ${requested} Testserver sandboxes asked for: the pool had no usable one, and all ${failedCreates.length} creates failed. ${NOT_RUN}`,
|
|
3908
|
+
rows: [["Failed creates", failedCreates.map(createFailureText)]],
|
|
3909
|
+
...mayExist ? { next: mayExistSteps(mayExist, ttlMinutes2) } : {}
|
|
3910
|
+
};
|
|
3911
|
+
}
|
|
3912
|
+
function noUsableSandboxes(data) {
|
|
3913
|
+
const { requested, build } = data;
|
|
3914
|
+
return {
|
|
3915
|
+
refused: "no_usable_sandboxes",
|
|
3916
|
+
data: { ...data },
|
|
3917
|
+
message: `${requested === 1 ? "Got no Testserver sandbox" : `Got none of the ${requested} Testserver sandboxes asked for`}: the pool has no usable one on ${build}, and with create false the run creates none. ${NOT_RUN}`,
|
|
3918
|
+
next: [
|
|
3919
|
+
{
|
|
3920
|
+
type: "text",
|
|
3921
|
+
text: `Set ${CREATE_KEY_PATH} to true to create Testserver sandboxes, or check the pool with storm ext testserver pool list.`
|
|
3922
|
+
}
|
|
3923
|
+
]
|
|
3924
|
+
};
|
|
3925
|
+
}
|
|
3926
|
+
|
|
3927
|
+
// src/extensions/testserver/release.ts
|
|
3928
|
+
function testserverPoolReleasedText(leased, releaseFailures) {
|
|
3929
|
+
const released = leased.length - releaseFailures.length;
|
|
3930
|
+
return released <= 0 ? void 0 : `released ${released} ${released === 1 ? "lease" : "leases"}`;
|
|
3931
|
+
}
|
|
3932
|
+
function testserverPoolReleaseWarnings(releaseFailures) {
|
|
3933
|
+
return releaseFailures.map(({ path, message }) => ({
|
|
3934
|
+
reason: "release_failed",
|
|
3935
|
+
message: `Couldn't release the lease at ${path}: ${message}. A later run reclaims it once this one has exited.`
|
|
3936
|
+
}));
|
|
3937
|
+
}
|
|
3938
|
+
function testserverPoolReleased(releaseFailures) {
|
|
3939
|
+
return { done: releaseFailures.length === 0 ? ["The run holds no lease."] : [] };
|
|
3940
|
+
}
|
|
3941
|
+
|
|
3942
|
+
// src/extensions/testserver/result.ts
|
|
3943
|
+
function testserverPoolResult(provisioned, options) {
|
|
3944
|
+
const facts = resultFacts(provisioned, options);
|
|
3945
|
+
return { facts, rows: resultRows(facts) };
|
|
3946
|
+
}
|
|
3947
|
+
function resultFacts(provisioned, options) {
|
|
3948
|
+
const { resolution, sandboxes } = provisioned;
|
|
3949
|
+
return {
|
|
3950
|
+
build: {
|
|
3951
|
+
requested: options.build,
|
|
3952
|
+
resolved: resolution.kind === "as-written" ? null : resolution.build,
|
|
3953
|
+
pullRequest: resolution.kind === "pull-request" ? { repo: TESTSERVER_REPO, number: resolution.pr, headSha: resolution.headSha } : null
|
|
3954
|
+
},
|
|
3955
|
+
sandboxes: sandboxes.map(({ testserverUrl, logViewerUrl, origin }) => ({ testserverUrl, logViewerUrl, origin })),
|
|
3956
|
+
reused: sandboxes.filter((sandbox) => sandbox.origin === "reused").length,
|
|
3957
|
+
created: sandboxes.filter((sandbox) => sandbox.origin === "created").length,
|
|
3958
|
+
failedCreates: failedCreateFacts(provisioned.failedCreates),
|
|
3959
|
+
unpooled: unpooledFacts(provisioned.unpooled),
|
|
3960
|
+
uncreated: provisioned.uncreated === void 0 ? null : {
|
|
3961
|
+
count: provisioned.uncreated.count,
|
|
3962
|
+
source: provisioned.uncreated.failure.source,
|
|
3963
|
+
...describeCredentialFailure(provisioned.uncreated.failure)
|
|
3964
|
+
},
|
|
3965
|
+
notCreated: provisioned.notCreated
|
|
3966
|
+
};
|
|
3967
|
+
}
|
|
3968
|
+
function testserverPoolResultWarnings(facts) {
|
|
3969
|
+
return [
|
|
3970
|
+
...facts.failedCreates.length === 0 ? [] : [
|
|
3971
|
+
{
|
|
3972
|
+
reason: "creates_failed",
|
|
3973
|
+
message: `${facts.failedCreates.length} of ${facts.failedCreates.length + facts.created} creates failed (${facts.failedCreates.map(createFailureText).join("; ")}); the command ran on ${facts.sandboxes.length} Testserver sandboxes.`
|
|
3974
|
+
}
|
|
3975
|
+
],
|
|
3976
|
+
...facts.unpooled.map(({ testserverUrl, message }) => ({
|
|
3977
|
+
reason: "sandbox_not_pooled",
|
|
3978
|
+
message: `Used the Testserver sandbox ${testserverUrl}, but couldn't add it to the pool: ${message}`
|
|
3979
|
+
})),
|
|
3980
|
+
...facts.uncreated === null ? [] : [
|
|
3981
|
+
facts.uncreated.source === "mint" ? {
|
|
3982
|
+
reason: "mint_failed",
|
|
3983
|
+
message: `Couldn't create ${facts.uncreated.count} more Testserver sandboxes: couldn't mint a credential: ${facts.uncreated.cause}. ${facts.uncreated.fix}`
|
|
3984
|
+
} : {
|
|
3985
|
+
reason: "token_request_failed",
|
|
3986
|
+
message: `Couldn't create ${facts.uncreated.count} more Testserver sandboxes: couldn't request a GitHub Actions OIDC token: ${facts.uncreated.cause}. ${facts.uncreated.fix}`
|
|
3987
|
+
}
|
|
3988
|
+
],
|
|
3989
|
+
...facts.notCreated === 0 ? [] : [
|
|
3990
|
+
{
|
|
3991
|
+
reason: "sandboxes_not_created",
|
|
3992
|
+
message: `create is false: ${facts.notCreated} of ${facts.notCreated + facts.sandboxes.length} Testserver sandboxes couldn't be leased, and none were created; the command ran on ${facts.sandboxes.length}.`
|
|
3993
|
+
}
|
|
3994
|
+
]
|
|
3995
|
+
];
|
|
3996
|
+
}
|
|
3997
|
+
function resultRows(facts) {
|
|
3998
|
+
return facts.sandboxes.length === 0 ? [] : [
|
|
3999
|
+
[
|
|
4000
|
+
"Testserver",
|
|
4001
|
+
facts.sandboxes.flatMap(({ testserverUrl, logViewerUrl, origin }) => [
|
|
4002
|
+
`${testserverUrl} (${origin})`,
|
|
4003
|
+
` logs ${logViewerUrl}`
|
|
4004
|
+
])
|
|
4005
|
+
]
|
|
4006
|
+
];
|
|
4007
|
+
}
|
|
4008
|
+
|
|
4009
|
+
// src/extensions/testserver/run-sandbox.ts
|
|
4010
|
+
function testserverConnectionOf(sandboxes) {
|
|
4011
|
+
return { sandboxes: [...new Set(sandboxes.map((sandbox) => sandbox.testserverUrl))].map((url) => ({ url })) };
|
|
4012
|
+
}
|
|
4013
|
+
var STALE_TESTSERVER_VARIABLES = ["TESTSERVER_BASES", "TESTSERVER_BASE"];
|
|
4014
|
+
|
|
4015
|
+
// src/extensions/testserver/lifecycle.ts
|
|
4016
|
+
function testserverPoolLifecycle(world) {
|
|
4017
|
+
return {
|
|
4018
|
+
beforeRun: async ({
|
|
4019
|
+
options
|
|
4020
|
+
}) => {
|
|
4021
|
+
const prepared = await world.pool.prepare();
|
|
4022
|
+
if (!prepared.ok) return poolUnavailable(prepared.failure);
|
|
4023
|
+
return {
|
|
4024
|
+
use: { secrets: {}, needsVercelCredential: options.create, hiddenVariables: STALE_TESTSERVER_VARIABLES }
|
|
4025
|
+
};
|
|
4026
|
+
},
|
|
4027
|
+
acquireForRun: async ({
|
|
4028
|
+
options,
|
|
4029
|
+
credential,
|
|
4030
|
+
take,
|
|
4031
|
+
report,
|
|
4032
|
+
signal
|
|
4033
|
+
}) => {
|
|
4034
|
+
const provisioned = await provision(world, options, createWith(options, credential), signal, report, take);
|
|
4035
|
+
if (provisioned.kind === "canceled") {
|
|
4036
|
+
const { kind: _kind2, ...facts2 } = provisioned;
|
|
4037
|
+
return { canceled: testserverCanceledLines(facts2) };
|
|
4038
|
+
}
|
|
4039
|
+
if (provisioned.kind === "mint-failed") return { mintFailed: provisioned.failed };
|
|
4040
|
+
if (provisioned.kind !== "provisioned") return acquireRefusal(provisioned);
|
|
4041
|
+
const { kind: _kind, ...facts } = provisioned;
|
|
4042
|
+
const sandboxes = facts.sandboxes.map(({ testserverUrl, logViewerUrl, origin }) => ({
|
|
4043
|
+
testserverUrl,
|
|
4044
|
+
logViewerUrl,
|
|
4045
|
+
origin
|
|
4046
|
+
}));
|
|
4047
|
+
const result = testserverPoolResult(facts, options);
|
|
4048
|
+
for (const { reason, message } of testserverPoolResultWarnings(result.facts))
|
|
4049
|
+
await report.warning(reason, message);
|
|
4050
|
+
return {
|
|
4051
|
+
acquired: {
|
|
4052
|
+
payload: testserverConnectionOf(facts.sandboxes),
|
|
4053
|
+
result,
|
|
4054
|
+
announce: { kind: "acquired", sandboxes },
|
|
4055
|
+
canceled: testserverCanceledLines(testserverCanceledFacts(options, facts))
|
|
4056
|
+
}
|
|
4057
|
+
};
|
|
4058
|
+
},
|
|
4059
|
+
releaseAfterRun: async ({
|
|
4060
|
+
taken,
|
|
4061
|
+
report
|
|
4062
|
+
}) => {
|
|
4063
|
+
const releaseFailures = await releaseLeases(world, taken);
|
|
4064
|
+
const released = testserverPoolReleasedText(taken, releaseFailures);
|
|
4065
|
+
if (released !== void 0) await report.cleanup(released);
|
|
4066
|
+
for (const { reason, message } of testserverPoolReleaseWarnings(releaseFailures))
|
|
4067
|
+
await report.warning(reason, message);
|
|
4068
|
+
return testserverPoolReleased(releaseFailures);
|
|
4069
|
+
}
|
|
4070
|
+
};
|
|
4071
|
+
}
|
|
4072
|
+
function acquireRefusal(refusal) {
|
|
4073
|
+
switch (refusal.kind) {
|
|
4074
|
+
case "pool-unreadable":
|
|
4075
|
+
return poolUnreadable(refusal.failure);
|
|
4076
|
+
case "token-request-failed":
|
|
4077
|
+
return tokenRequestFailed(refusal.failure, {
|
|
4078
|
+
ttlMinutes: refusal.ttlMinutes,
|
|
4079
|
+
failedCreates: failedCreateFacts(refusal.failedCreates),
|
|
4080
|
+
sandboxMayExist: refusal.failedCreates.some(mayLeaveSandbox)
|
|
4081
|
+
});
|
|
4082
|
+
case "credential-rejected":
|
|
4083
|
+
return credentialRejected(refusal.origin, {
|
|
4084
|
+
status: refusal.failure.status,
|
|
4085
|
+
vercelId: refusal.failure.vercelId ?? null,
|
|
4086
|
+
ttlMinutes: refusal.ttlMinutes,
|
|
4087
|
+
failedCreates: failedCreateFacts(refusal.failedCreates),
|
|
4088
|
+
unpooled: unpooledFacts(refusal.unpooled),
|
|
4089
|
+
sandboxMayExist: refusal.failedCreates.some(mayLeaveSandbox)
|
|
4090
|
+
});
|
|
4091
|
+
case "no-sandboxes":
|
|
4092
|
+
return noSandboxes({
|
|
4093
|
+
requested: refusal.requested,
|
|
4094
|
+
ttlMinutes: refusal.ttlMinutes,
|
|
4095
|
+
failedCreates: failedCreateFacts(refusal.failedCreates),
|
|
4096
|
+
sandboxMayExist: refusal.failedCreates.some(mayLeaveSandbox)
|
|
4097
|
+
});
|
|
4098
|
+
case "no-usable-sandboxes":
|
|
4099
|
+
return noUsableSandboxes({
|
|
4100
|
+
requested: refusal.requested,
|
|
4101
|
+
build: "resolvedBuild" in refusal.match ? refusal.match.resolvedBuild : refusal.match.requestedBuild
|
|
4102
|
+
});
|
|
4103
|
+
case "pull-request-unreadable":
|
|
4104
|
+
case "pr-builds-unlisted":
|
|
4105
|
+
case "pr-build-not-ready":
|
|
4106
|
+
case "pr-build-expired":
|
|
4107
|
+
return prBuildRefusal(refusal, "The command didn't run.");
|
|
4108
|
+
}
|
|
4109
|
+
}
|
|
4110
|
+
|
|
4111
|
+
// src/extensions/testserver/pull-request/live/github-rest.ts
|
|
4112
|
+
import { z as z9 } from "zod";
|
|
4113
|
+
var errorSchema = z9.object({ message: z9.string() });
|
|
4114
|
+
function headers(token) {
|
|
4115
|
+
return {
|
|
4116
|
+
accept: "application/vnd.github+json",
|
|
4117
|
+
authorization: `Bearer ${token}`,
|
|
4118
|
+
"x-github-api-version": "2022-11-28",
|
|
4119
|
+
"user-agent": "storm"
|
|
4120
|
+
};
|
|
4121
|
+
}
|
|
4122
|
+
function hideToken(text, token) {
|
|
4123
|
+
return token === "" ? text : text.replaceAll(token, "<token>");
|
|
4124
|
+
}
|
|
4125
|
+
async function getJson(options, token, path, schema) {
|
|
4126
|
+
const signal = AbortSignal.timeout(options.timeoutMs);
|
|
4127
|
+
try {
|
|
4128
|
+
const response = await fetch(`${options.origin}/${path}`, { headers: headers(token), redirect: "manual", signal });
|
|
4129
|
+
const text = await response.text();
|
|
4130
|
+
if (response.status < 200 || response.status >= 300)
|
|
4131
|
+
return {
|
|
4132
|
+
ok: false,
|
|
4133
|
+
failure: statusFailure(response.status, hideToken(githubMessage(text, response.status), token))
|
|
4134
|
+
};
|
|
4135
|
+
let json;
|
|
4136
|
+
try {
|
|
4137
|
+
json = JSON.parse(text);
|
|
4138
|
+
} catch {
|
|
4139
|
+
return { ok: false, failure: { kind: "malformed", detail: "the answer isn't JSON" } };
|
|
4140
|
+
}
|
|
4141
|
+
const parsed = schema.safeParse(json);
|
|
4142
|
+
if (!parsed.success) {
|
|
4143
|
+
const issue = parsed.error.issues[0];
|
|
4144
|
+
const where2 = issue === void 0 || issue.path.length === 0 ? "the answer" : issue.path.join(".");
|
|
4145
|
+
return {
|
|
4146
|
+
ok: false,
|
|
4147
|
+
failure: { kind: "malformed", detail: hideToken(`${where2}: ${issue?.message ?? "unexpected"}`, token) }
|
|
4148
|
+
};
|
|
4149
|
+
}
|
|
4150
|
+
return { ok: true, value: parsed.data };
|
|
4151
|
+
} catch (error) {
|
|
4152
|
+
return { ok: false, failure: thrownFailure(error, signal, options, token) };
|
|
4153
|
+
}
|
|
4154
|
+
}
|
|
4155
|
+
async function getRedirectedText(options, token, path) {
|
|
4156
|
+
const signal = AbortSignal.timeout(options.timeoutMs);
|
|
4157
|
+
try {
|
|
4158
|
+
const response = await fetch(`${options.origin}/${path}`, { headers: headers(token), redirect: "manual", signal });
|
|
4159
|
+
if (response.status >= 200 && response.status < 300) return { ok: true, value: await response.text() };
|
|
4160
|
+
const location = response.headers.get("location");
|
|
4161
|
+
if (response.status < 300 || response.status >= 400 || location === null) {
|
|
4162
|
+
const text2 = await response.text();
|
|
4163
|
+
return {
|
|
4164
|
+
ok: false,
|
|
4165
|
+
failure: statusFailure(response.status, hideToken(githubMessage(text2, response.status), token))
|
|
4166
|
+
};
|
|
4167
|
+
}
|
|
4168
|
+
await response.body?.cancel().catch(() => {
|
|
4169
|
+
});
|
|
4170
|
+
const redirected = await fetch(location, { redirect: "follow", signal });
|
|
4171
|
+
const text = await redirected.text();
|
|
4172
|
+
if (!redirected.ok) return { ok: false, failure: statusFailure(redirected.status, `HTTP ${redirected.status}`) };
|
|
4173
|
+
return { ok: true, value: text };
|
|
4174
|
+
} catch (error) {
|
|
4175
|
+
return { ok: false, failure: thrownFailure(error, signal, options, token) };
|
|
4176
|
+
}
|
|
4177
|
+
}
|
|
4178
|
+
function statusFailure(status, message) {
|
|
4179
|
+
if (status === 404) return { kind: "not-found", status };
|
|
4180
|
+
if (status === 401 || status === 403) return { kind: "rejected", status, message };
|
|
4181
|
+
return { kind: "http-error", status, message };
|
|
4182
|
+
}
|
|
4183
|
+
function githubMessage(text, status) {
|
|
4184
|
+
try {
|
|
4185
|
+
const parsed = errorSchema.safeParse(JSON.parse(text));
|
|
4186
|
+
if (parsed.success) return parsed.data.message;
|
|
4187
|
+
} catch {
|
|
4188
|
+
}
|
|
4189
|
+
return `HTTP ${status}`;
|
|
4190
|
+
}
|
|
4191
|
+
function thrownFailure(error, signal, options, token) {
|
|
4192
|
+
if (signal.aborted) return { kind: "timeout", seconds: options.timeoutMs / 1e3 };
|
|
4193
|
+
return { kind: "connect-failed", code: hideToken(errorCode2(error), token) };
|
|
4194
|
+
}
|
|
4195
|
+
function errorCode2(error) {
|
|
4196
|
+
if (!(error instanceof Error)) return String(error);
|
|
4197
|
+
const cause = error.cause;
|
|
4198
|
+
const code = typeof cause === "object" && cause !== null ? cause.code : void 0;
|
|
4199
|
+
return typeof code === "string" ? code : error.message;
|
|
4200
|
+
}
|
|
4201
|
+
|
|
4202
|
+
// src/extensions/testserver/pull-request/live/github-token-gateway.ts
|
|
4203
|
+
import { execFile as execFile3 } from "node:child_process";
|
|
4204
|
+
var GH_TOKEN_TIMEOUT_MS = 5e3;
|
|
4205
|
+
function liveGitHubTokenGateway(options) {
|
|
4206
|
+
return {
|
|
4207
|
+
token: async () => {
|
|
4208
|
+
for (const origin of ["GITHUB_TOKEN", "GH_TOKEN"]) {
|
|
4209
|
+
const token2 = options.env[origin]?.trim();
|
|
4210
|
+
if (token2 !== void 0 && token2 !== "") return { token: token2, origin };
|
|
4211
|
+
}
|
|
4212
|
+
const token = await ghAuthToken(options.env);
|
|
4213
|
+
return token === void 0 ? void 0 : { token, origin: "gh auth token" };
|
|
4214
|
+
}
|
|
4215
|
+
};
|
|
4216
|
+
}
|
|
4217
|
+
function ghAuthToken(env) {
|
|
4218
|
+
return new Promise((resolve) => {
|
|
4219
|
+
try {
|
|
4220
|
+
execFile3(
|
|
4221
|
+
"gh",
|
|
4222
|
+
["auth", "token", "--hostname", "github.com"],
|
|
4223
|
+
{ env: { ...env }, timeout: GH_TOKEN_TIMEOUT_MS, encoding: "utf8" },
|
|
4224
|
+
(error, stdout) => {
|
|
4225
|
+
const token = typeof stdout === "string" ? stdout.trim() : "";
|
|
4226
|
+
resolve(error === null && token !== "" ? token : void 0);
|
|
4227
|
+
}
|
|
4228
|
+
);
|
|
4229
|
+
} catch {
|
|
4230
|
+
resolve(void 0);
|
|
4231
|
+
}
|
|
4232
|
+
});
|
|
4233
|
+
}
|
|
4234
|
+
|
|
4235
|
+
// src/extensions/testserver/pull-request/live/pull-request-gateway.ts
|
|
4236
|
+
import { z as z10 } from "zod";
|
|
4237
|
+
var pullSchema = z10.object({
|
|
4238
|
+
head: z10.object({ sha: z10.string().regex(/^[0-9a-f]{40}$/), ref: z10.string().min(1) }),
|
|
4239
|
+
state: z10.enum(["open", "closed"]),
|
|
4240
|
+
merged: z10.boolean()
|
|
4241
|
+
});
|
|
4242
|
+
function livePullRequestGateway(options) {
|
|
4243
|
+
return {
|
|
4244
|
+
head: async ({ repo, number, token }) => {
|
|
4245
|
+
const answered = await getJson(options, token, `repos/${repoPath(repo)}/pulls/${number}`, pullSchema);
|
|
4246
|
+
if (!answered.ok) return answered;
|
|
4247
|
+
const { head: head2, state: state2, merged } = answered.value;
|
|
4248
|
+
return { ok: true, head: { headSha: head2.sha, headRef: head2.ref, state: state2, merged } };
|
|
4249
|
+
}
|
|
4250
|
+
};
|
|
4251
|
+
}
|
|
4252
|
+
function repoPath(repo) {
|
|
4253
|
+
return repo.split("/").map(encodeURIComponent).join("/");
|
|
4254
|
+
}
|
|
4255
|
+
|
|
4256
|
+
// src/extensions/testserver/pull-request/live/testserver-workflow-gateway.ts
|
|
4257
|
+
import { z as z11 } from "zod";
|
|
4258
|
+
var TESTSERVER_WORKFLOW = "testserver-bundle-publish.yml";
|
|
4259
|
+
var BUNDLE_JOB = "Bundle & Publish";
|
|
4260
|
+
var RUNS_LISTED = 30;
|
|
4261
|
+
var BUNDLE_LINE = /📦 Bundle will be: builds\/pr-([1-9][0-9]*)\/([^\s/]+)/;
|
|
4262
|
+
var runsSchema = z11.object({
|
|
4263
|
+
workflow_runs: z11.array(
|
|
4264
|
+
z11.object({
|
|
4265
|
+
id: z11.number(),
|
|
4266
|
+
head_sha: z11.string().regex(/^[0-9a-f]{40}$/),
|
|
4267
|
+
created_at: z11.string().min(1)
|
|
4268
|
+
})
|
|
4269
|
+
)
|
|
4270
|
+
});
|
|
4271
|
+
var jobsSchema = z11.object({
|
|
4272
|
+
jobs: z11.array(z11.object({ id: z11.number(), name: z11.string(), conclusion: z11.string().nullable() }))
|
|
4273
|
+
});
|
|
4274
|
+
function liveTestserverWorkflowGateway(options) {
|
|
4275
|
+
return {
|
|
4276
|
+
runs: async ({ repo, branch, token }) => {
|
|
4277
|
+
const query = new URLSearchParams({ event: "pull_request", branch, per_page: String(RUNS_LISTED) });
|
|
4278
|
+
const answered = await getJson(
|
|
4279
|
+
options,
|
|
4280
|
+
token,
|
|
4281
|
+
`repos/${repoPath(repo)}/actions/workflows/${TESTSERVER_WORKFLOW}/runs?${query.toString()}`,
|
|
4282
|
+
runsSchema
|
|
4283
|
+
);
|
|
4284
|
+
if (!answered.ok) return answered;
|
|
4285
|
+
const runs = answered.value.workflow_runs.map((run) => ({
|
|
4286
|
+
id: run.id,
|
|
4287
|
+
headSha: run.head_sha,
|
|
4288
|
+
createdAt: run.created_at
|
|
4289
|
+
}));
|
|
4290
|
+
return { ok: true, runs };
|
|
4291
|
+
},
|
|
4292
|
+
publishedBuild: async ({ repo, runId, token }) => {
|
|
4293
|
+
const jobs = await getJson(options, token, `repos/${repoPath(repo)}/actions/runs/${runId}/jobs`, jobsSchema);
|
|
4294
|
+
if (!jobs.ok) return jobs;
|
|
4295
|
+
const job = jobs.value.jobs.find(({ name: name2 }) => name2 === BUNDLE_JOB);
|
|
4296
|
+
if (job === void 0 || job.conclusion !== "success") return { ok: true, build: void 0 };
|
|
4297
|
+
const log = await getRedirectedText(
|
|
4298
|
+
{ origin: options.origin, timeoutMs: options.logTimeoutMs },
|
|
4299
|
+
token,
|
|
4300
|
+
`repos/${repoPath(repo)}/actions/jobs/${job.id}/logs`
|
|
4301
|
+
);
|
|
4302
|
+
if (!log.ok) return log;
|
|
4303
|
+
const match = BUNDLE_LINE.exec(log.value);
|
|
4304
|
+
const [, pr, name] = match ?? [];
|
|
4305
|
+
return { ok: true, build: pr === void 0 || name === void 0 ? void 0 : { pr: Number(pr), name } };
|
|
4306
|
+
}
|
|
4307
|
+
};
|
|
4308
|
+
}
|
|
4309
|
+
|
|
4310
|
+
// src/extensions/testserver/live/world.ts
|
|
4311
|
+
var TESTSERVER_ORIGIN = "https://testserver.vercel.sh";
|
|
4312
|
+
var GITHUB_API_ORIGIN = "https://api.github.com";
|
|
4313
|
+
function liveTestserverWorld(supplies) {
|
|
4314
|
+
const { stateDirectory } = supplies;
|
|
4315
|
+
return {
|
|
4316
|
+
controlPlane: liveControlPlaneGateway({
|
|
4317
|
+
origin: TESTSERVER_ORIGIN,
|
|
4318
|
+
streamTimeoutMs: 18e4,
|
|
4319
|
+
buildsTimeoutMs: 1e4
|
|
4320
|
+
}),
|
|
4321
|
+
healthChecks: liveHealthCheckGateway({ timeoutMs: 5e3 }),
|
|
4322
|
+
pool: stateDirectory.ok ? livePoolStoreGateway({ directory: stateDirectory.directory }) : unavailablePoolStoreGateway(stateDirectory.pattern, stateDirectory.reason),
|
|
4323
|
+
pullRequests: livePullRequestGateway({ origin: GITHUB_API_ORIGIN, timeoutMs: 1e4 }),
|
|
4324
|
+
testserverWorkflow: liveTestserverWorkflowGateway({
|
|
4325
|
+
origin: GITHUB_API_ORIGIN,
|
|
4326
|
+
timeoutMs: 1e4,
|
|
4327
|
+
logTimeoutMs: 3e4
|
|
4328
|
+
}),
|
|
4329
|
+
githubToken: liveGitHubTokenGateway({ env: supplies.env }),
|
|
4330
|
+
timer: supplies.timer,
|
|
4331
|
+
clock: supplies.clock
|
|
4332
|
+
};
|
|
4333
|
+
}
|
|
4334
|
+
|
|
4335
|
+
// src/extensions/testserver/presentation.ts
|
|
4336
|
+
function line(text) {
|
|
4337
|
+
return { lane: "testserver", text };
|
|
4338
|
+
}
|
|
4339
|
+
function poolUpkeepTexts(report) {
|
|
4340
|
+
return [
|
|
4341
|
+
...report.reclaimed.length === 0 ? [] : [`reclaimed ${count(report.reclaimed.length, "stale lease")}`],
|
|
4342
|
+
...report.dropped.length === 0 ? [] : [`dropped ${count(report.dropped.length, "Testserver sandbox")} from the pool`],
|
|
4343
|
+
...report.storeFailures.map(({ path, message }) => `a pool operation failed on ${path}: ${message}`)
|
|
4344
|
+
];
|
|
4345
|
+
}
|
|
4346
|
+
function createFinishedText(event) {
|
|
4347
|
+
const which = `create ${event.index + 1} of ${event.count}`;
|
|
4348
|
+
const { outcome } = event;
|
|
4349
|
+
switch (outcome.kind) {
|
|
4350
|
+
case "pooled":
|
|
4351
|
+
return `${which} done: ${outcome.entry.testserverUrl}`;
|
|
4352
|
+
case "pool-write-failed":
|
|
4353
|
+
return `${which} done: ${outcome.entry.testserverUrl}, not added to the pool`;
|
|
4354
|
+
case "create-failed":
|
|
4355
|
+
return `${which} failed: ${describeCreateFailure(outcome.failure).text}`;
|
|
4356
|
+
}
|
|
4357
|
+
}
|
|
4358
|
+
function createProgressText(event) {
|
|
4359
|
+
return `create ${event.index + 1} of ${event.count}: ${event.message}`;
|
|
4360
|
+
}
|
|
4361
|
+
function unresolvedBuildText(event) {
|
|
4362
|
+
return `couldn't resolve ${event.channel} (${unresolvedWhy(event.reason)}); using Testserver sandboxes requested as ${event.channel}`;
|
|
4363
|
+
}
|
|
4364
|
+
function oldChannelResolutionText(event) {
|
|
4365
|
+
return event.ageMinutes < 0 ? `using ${event.channel}'s channel resolution, recorded later than now (create is false)` : `using ${event.channel}'s channel resolution from ${age(event.ageMinutes)} ago (create is false)`;
|
|
4366
|
+
}
|
|
4367
|
+
function prBuildResolvedText(event) {
|
|
4368
|
+
const pooled = event.from === "pool" ? " (from the pool)" : "";
|
|
4369
|
+
const merged = event.merged ? " (merged; latest_main or stable may have it)" : "";
|
|
4370
|
+
return `Build: ${TESTSERVER_REPO}#${event.pr} at ${shortSha(event.headSha)} \u2192 ${event.build}${pooled}${merged}`;
|
|
4371
|
+
}
|
|
4372
|
+
function unresolvedWhy(reason) {
|
|
4373
|
+
switch (reason.kind) {
|
|
4374
|
+
case "credential-failed": {
|
|
4375
|
+
const { cause } = describeCredentialFailure(reason.failure);
|
|
4376
|
+
return reason.failure.source === "mint" ? `couldn't mint a credential: ${cause}` : `couldn't request a GitHub Actions OIDC token: ${cause}`;
|
|
4377
|
+
}
|
|
4378
|
+
case "builds-failed":
|
|
4379
|
+
return `GET /builds failed: ${reason.failure.kind}`;
|
|
4380
|
+
case "no-build":
|
|
4381
|
+
return "the Testserver control plane names no build for it";
|
|
4382
|
+
case "not-recorded":
|
|
4383
|
+
return "no channel resolution is recorded, and with create false the run doesn't ask the Testserver control plane";
|
|
4384
|
+
}
|
|
4385
|
+
}
|
|
4386
|
+
function age(minutes) {
|
|
4387
|
+
if (minutes < 60) return `${minutes}m`;
|
|
4388
|
+
if (minutes < 48 * 60) return `${Math.floor(minutes / 60)}h`;
|
|
4389
|
+
return `${Math.floor(minutes / (24 * 60))}d`;
|
|
4390
|
+
}
|
|
4391
|
+
function count(n, noun) {
|
|
4392
|
+
const plural = { "stale lease": "stale leases", "Testserver sandbox": "Testserver sandboxes" }[noun];
|
|
4393
|
+
return `${n} ${n === 1 ? noun : plural}`;
|
|
4394
|
+
}
|
|
4395
|
+
function onBuild(testserver) {
|
|
4396
|
+
return testserver.build === void 0 ? "" : ` on ${testserver.build}`;
|
|
4397
|
+
}
|
|
4398
|
+
function reusedCount(testserver) {
|
|
4399
|
+
return testserver.sandboxes.filter(({ origin }) => origin === "reused").length;
|
|
4400
|
+
}
|
|
4401
|
+
function originCounts(testserver) {
|
|
4402
|
+
const reused = reusedCount(testserver);
|
|
4403
|
+
return `${reused} reused, ${testserver.sandboxes.length - reused} created`;
|
|
4404
|
+
}
|
|
4405
|
+
function leasingText(testserver) {
|
|
4406
|
+
return testserver.requested === void 0 ? "resolving the build" : `leasing ${testserver.requested}${onBuild(testserver)}`;
|
|
4407
|
+
}
|
|
4408
|
+
function createsText(creates, paint) {
|
|
4409
|
+
const failed = creates.failed === 0 ? "" : ` \xB7 ${paint.failed(`${creates.failed} failed`)}`;
|
|
4410
|
+
return `creating ${creates.count} \xB7 ${creates.started} started \xB7 ${creates.finished - creates.failed} done${failed}`;
|
|
4411
|
+
}
|
|
4412
|
+
function creating(testserver) {
|
|
4413
|
+
const { creates } = testserver;
|
|
4414
|
+
return creates !== void 0 && creates.finished < creates.count && testserver.status === "running";
|
|
4415
|
+
}
|
|
4416
|
+
function testserverOutcome(testserver) {
|
|
4417
|
+
const counts = `${originCounts(testserver)}${onBuild(testserver)}`;
|
|
4418
|
+
return testserver.status === "done" ? counts : `${counts} \xB7 ${testserver.status}`;
|
|
4419
|
+
}
|
|
4420
|
+
function sandboxLines(testserver, draw) {
|
|
4421
|
+
return testserver.sandboxes.map(
|
|
4422
|
+
({ testserverUrl, logViewerUrl }) => draw.line(` ${sandboxName(testserverUrl)} ${draw.paint.faint("logs")} ${logViewerUrl}`)
|
|
4423
|
+
);
|
|
4424
|
+
}
|
|
4425
|
+
function sandboxName(testserverUrl) {
|
|
4426
|
+
try {
|
|
4427
|
+
return new URL(testserverUrl).hostname.split(".")[0] ?? testserverUrl;
|
|
4428
|
+
} catch {
|
|
4429
|
+
return testserverUrl;
|
|
4430
|
+
}
|
|
4431
|
+
}
|
|
4432
|
+
var testserverPoolDrawing = {
|
|
4433
|
+
plain: ({ verbose, seconds }) => {
|
|
4434
|
+
let leasingAt;
|
|
4435
|
+
return (event, now) => {
|
|
4436
|
+
switch (event.kind) {
|
|
4437
|
+
case "build-unresolved":
|
|
4438
|
+
return [line(unresolvedBuildText(event))];
|
|
4439
|
+
case "old-channel-resolution":
|
|
4440
|
+
return [line(oldChannelResolutionText(event))];
|
|
4441
|
+
case "pr-build-resolved":
|
|
4442
|
+
return [line(prBuildResolvedText(event))];
|
|
4443
|
+
case "leasing":
|
|
4444
|
+
leasingAt = now;
|
|
4445
|
+
return [];
|
|
4446
|
+
case "leased": {
|
|
4447
|
+
const { report, requested } = event;
|
|
4448
|
+
const build = "resolvedBuild" in event.match ? event.match.resolvedBuild : event.match.requestedBuild;
|
|
4449
|
+
return [
|
|
4450
|
+
...poolUpkeepTexts(report).map(line),
|
|
4451
|
+
line(
|
|
4452
|
+
`leased ${report.leased.length} of ${count(requested, "Testserver sandbox")} from the pool on ${build} (${seconds(now - (leasingAt ?? now))})`
|
|
4453
|
+
)
|
|
4454
|
+
];
|
|
4455
|
+
}
|
|
4456
|
+
case "creating":
|
|
4457
|
+
return [line(`creating ${count(event.count, "Testserver sandbox")} on ${event.build}\u2026`)];
|
|
4458
|
+
case "create-started":
|
|
4459
|
+
return [line(`create ${event.index + 1} of ${event.count} started`)];
|
|
4460
|
+
case "create-progress":
|
|
4461
|
+
return verbose ? [line(createProgressText(event))] : [];
|
|
4462
|
+
case "create-finished":
|
|
4463
|
+
return [line(createFinishedText(event))];
|
|
4464
|
+
// The Testserver sandboxes the run uses, reused first, just before its command starts.
|
|
4465
|
+
case "acquired":
|
|
4466
|
+
return event.sandboxes.map(
|
|
4467
|
+
({ testserverUrl, logViewerUrl, origin }) => line(`${testserverUrl} logs ${logViewerUrl} (${origin})`)
|
|
4468
|
+
);
|
|
4469
|
+
}
|
|
4470
|
+
};
|
|
4471
|
+
},
|
|
4472
|
+
notices: (event, { verbose }) => {
|
|
4473
|
+
switch (event.kind) {
|
|
4474
|
+
case "build-unresolved":
|
|
4475
|
+
return [line(unresolvedBuildText(event))];
|
|
4476
|
+
case "old-channel-resolution":
|
|
4477
|
+
return [line(oldChannelResolutionText(event))];
|
|
4478
|
+
case "pr-build-resolved":
|
|
4479
|
+
return [line(prBuildResolvedText(event))];
|
|
4480
|
+
case "leased":
|
|
4481
|
+
return poolUpkeepTexts(event.report).map(line);
|
|
4482
|
+
case "create-finished":
|
|
4483
|
+
return event.outcome.kind === "create-failed" ? [line(createFinishedText(event))] : [];
|
|
4484
|
+
case "create-progress":
|
|
4485
|
+
return verbose ? [line(createProgressText(event))] : [];
|
|
4486
|
+
case "leasing":
|
|
4487
|
+
case "creating":
|
|
4488
|
+
case "create-started":
|
|
4489
|
+
// The live view draws the sandbox list from the lane.
|
|
4490
|
+
case "acquired":
|
|
4491
|
+
return [];
|
|
4492
|
+
}
|
|
4493
|
+
},
|
|
4494
|
+
label: "testserver-setup",
|
|
4495
|
+
steps: ["lease", "create"],
|
|
4496
|
+
live: (testserver, draw) => ({
|
|
4497
|
+
text: testserver.status !== "running" ? testserverOutcome(testserver) : testserver.creates === void 0 ? leasingText(testserver) : `${reusedCount(testserver)} reused, creating ${testserver.creates.count}${onBuild(testserver)}`,
|
|
4498
|
+
...creating(testserver) && testserver.creates !== void 0 ? { detail: createsText(testserver.creates, draw.paint) } : {}
|
|
4499
|
+
}),
|
|
4500
|
+
record: (testserver, draw) => ({ text: testserverOutcome(testserver), lines: sandboxLines(testserver, draw) })
|
|
4501
|
+
};
|
|
4502
|
+
|
|
4503
|
+
// src/extensions/testserver/progress.ts
|
|
4504
|
+
var testserverPoolProgress = {
|
|
4505
|
+
lane: "testserver",
|
|
4506
|
+
...testserverPoolDrawing,
|
|
4507
|
+
start: (startedAt) => ({
|
|
4508
|
+
status: "running",
|
|
4509
|
+
startedAt,
|
|
4510
|
+
endedAt: void 0,
|
|
4511
|
+
build: void 0,
|
|
4512
|
+
requested: void 0,
|
|
4513
|
+
sandboxes: [],
|
|
4514
|
+
creates: void 0,
|
|
4515
|
+
steps: { lease: void 0, create: void 0 }
|
|
4516
|
+
}),
|
|
4517
|
+
apply: (testserver, event, at) => applyTestserverEvent(testserver, event, at),
|
|
4518
|
+
ended: (testserver, outcome, at) => {
|
|
4519
|
+
const status = outcome === "ready" ? "done" : outcome;
|
|
4520
|
+
const settle = (span) => settled(span, outcome, status, at);
|
|
4521
|
+
return {
|
|
4522
|
+
...testserver,
|
|
4523
|
+
status,
|
|
4524
|
+
endedAt: at,
|
|
4525
|
+
steps: { lease: settle(testserver.steps.lease), create: settle(testserver.steps.create) }
|
|
4526
|
+
};
|
|
4527
|
+
},
|
|
4528
|
+
row: (testserver) => {
|
|
4529
|
+
const reused = testserver.sandboxes.filter(({ origin }) => origin === "reused").length;
|
|
4530
|
+
const { lease, create } = testserver.steps;
|
|
4531
|
+
return {
|
|
4532
|
+
steps: [
|
|
4533
|
+
...lease === void 0 ? [] : [{ name: "lease", span: lease }],
|
|
4534
|
+
...create === void 0 ? [] : [{ name: "create", span: create }]
|
|
4535
|
+
],
|
|
4536
|
+
sandboxes: { reused, created: testserver.sandboxes.length - reused }
|
|
4537
|
+
};
|
|
4538
|
+
}
|
|
4539
|
+
};
|
|
4540
|
+
function applyTestserverEvent(testserver, event, at) {
|
|
4541
|
+
switch (event.kind) {
|
|
4542
|
+
// Resolving the build is part of the lane, but changes nothing it shows.
|
|
4543
|
+
case "build-unresolved":
|
|
4544
|
+
case "old-channel-resolution":
|
|
4545
|
+
case "pr-build-resolved":
|
|
4546
|
+
case "create-progress":
|
|
4547
|
+
return testserver;
|
|
4548
|
+
// The run acquired the pool: the lane holds the sandbox list.
|
|
4549
|
+
case "acquired":
|
|
4550
|
+
return {
|
|
4551
|
+
...testserver,
|
|
4552
|
+
sandboxes: event.sandboxes.map(({ testserverUrl, logViewerUrl, origin }) => ({
|
|
4553
|
+
testserverUrl,
|
|
4554
|
+
logViewerUrl,
|
|
4555
|
+
origin
|
|
4556
|
+
}))
|
|
4557
|
+
};
|
|
4558
|
+
case "leasing":
|
|
4559
|
+
return {
|
|
4560
|
+
...testserver,
|
|
4561
|
+
build: buildName(event.match),
|
|
4562
|
+
requested: event.requested,
|
|
4563
|
+
steps: { ...testserver.steps, lease: { status: "running", startedAt: at, endedAt: void 0 } }
|
|
4564
|
+
};
|
|
4565
|
+
case "leased":
|
|
4566
|
+
return {
|
|
4567
|
+
...testserver,
|
|
4568
|
+
sandboxes: event.report.leased.map(({ entry }) => ({
|
|
4569
|
+
testserverUrl: entry.testserverUrl,
|
|
4570
|
+
logViewerUrl: entry.logViewerUrl,
|
|
4571
|
+
origin: "reused"
|
|
4572
|
+
})),
|
|
4573
|
+
steps: { ...testserver.steps, lease: ended(testserver.steps.lease, "done", at) }
|
|
4574
|
+
};
|
|
4575
|
+
case "creating":
|
|
4576
|
+
return {
|
|
4577
|
+
...testserver,
|
|
4578
|
+
creates: { count: event.count, started: 0, finished: 0, failed: 0 },
|
|
4579
|
+
steps: { ...testserver.steps, create: { status: "running", startedAt: at, endedAt: void 0 } }
|
|
4580
|
+
};
|
|
4581
|
+
case "create-started":
|
|
4582
|
+
return {
|
|
4583
|
+
...testserver,
|
|
4584
|
+
creates: testserver.creates === void 0 ? void 0 : { ...testserver.creates, started: testserver.creates.started + 1 }
|
|
4585
|
+
};
|
|
4586
|
+
case "create-finished": {
|
|
4587
|
+
const { outcome } = event;
|
|
4588
|
+
const creates = testserver.creates === void 0 ? void 0 : {
|
|
4589
|
+
...testserver.creates,
|
|
4590
|
+
finished: testserver.creates.finished + 1,
|
|
4591
|
+
failed: testserver.creates.failed + (outcome.kind === "create-failed" ? 1 : 0)
|
|
4592
|
+
};
|
|
4593
|
+
const create = testserver.steps.create;
|
|
4594
|
+
return {
|
|
4595
|
+
...testserver,
|
|
4596
|
+
sandboxes: outcome.kind === "create-failed" ? testserver.sandboxes : [
|
|
4597
|
+
...testserver.sandboxes,
|
|
4598
|
+
{
|
|
4599
|
+
testserverUrl: outcome.entry.testserverUrl,
|
|
4600
|
+
logViewerUrl: outcome.entry.logViewerUrl,
|
|
4601
|
+
origin: "created"
|
|
4602
|
+
}
|
|
4603
|
+
],
|
|
4604
|
+
creates,
|
|
4605
|
+
steps: {
|
|
4606
|
+
...testserver.steps,
|
|
4607
|
+
// The create step ends with the last create; until then it runs, its end at the latest create's.
|
|
4608
|
+
create: create === void 0 ? void 0 : {
|
|
4609
|
+
...create,
|
|
4610
|
+
endedAt: at,
|
|
4611
|
+
status: creates !== void 0 && creates.finished >= creates.count ? "done" : create.status
|
|
4612
|
+
}
|
|
4613
|
+
}
|
|
4614
|
+
};
|
|
4615
|
+
}
|
|
4616
|
+
}
|
|
4617
|
+
}
|
|
4618
|
+
function settled(span, outcome, status, at) {
|
|
4619
|
+
return outcome === "ready" || span === void 0 || span.status !== "running" ? span : ended(span, status, at);
|
|
4620
|
+
}
|
|
4621
|
+
function ended(span, status, at) {
|
|
4622
|
+
return span === void 0 ? void 0 : { ...span, status, endedAt: at };
|
|
4623
|
+
}
|
|
4624
|
+
function buildName(match) {
|
|
4625
|
+
return "resolvedBuild" in match ? match.resolvedBuild : match.requestedBuild;
|
|
4626
|
+
}
|
|
4627
|
+
|
|
4628
|
+
// src/extensions/testserver/definition.ts
|
|
4629
|
+
var NAME = TESTSERVER_POOL_NAME;
|
|
4630
|
+
var testserverPoolDefinition = defineResource({
|
|
4631
|
+
name: NAME,
|
|
4632
|
+
flagPrefix: "testserver",
|
|
4633
|
+
options: testserverPoolRules,
|
|
4634
|
+
check: ({ minTimeLeft, ttl, create }) => {
|
|
4635
|
+
if (!create.value)
|
|
4636
|
+
return ttl.source === "flag" ? [
|
|
4637
|
+
{
|
|
4638
|
+
option: "ttl",
|
|
4639
|
+
problem: `doesn't apply with ${optionKeyPath(NAME, "create")}=false, which creates no Testserver sandbox`,
|
|
4640
|
+
involves: ["ttl", "create"]
|
|
4641
|
+
}
|
|
4642
|
+
] : [];
|
|
4643
|
+
if (ttlMinutes({ ttl: ttl.value }) > minTimeLeftMinutes({ minTimeLeft: minTimeLeft.value })) return [];
|
|
4644
|
+
const problem2 = ttl.source === "default" && minTimeLeft.source !== "default" ? {
|
|
4645
|
+
option: "minTimeLeft",
|
|
4646
|
+
problem: `must be shorter than ${optionKeyPath(NAME, "ttl")} (${ttl.value}), not ${minTimeLeft.value}`,
|
|
4647
|
+
involves: ["minTimeLeft", "ttl"]
|
|
4648
|
+
} : {
|
|
4649
|
+
option: "ttl",
|
|
4650
|
+
problem: `must be longer than ${optionKeyPath(NAME, "minTimeLeft")} (${minTimeLeft.value}), not ${ttl.value}`,
|
|
4651
|
+
involves: ["ttl", "minTimeLeft"]
|
|
4652
|
+
};
|
|
4653
|
+
return [problem2];
|
|
4654
|
+
},
|
|
4655
|
+
// Not the extension's own: the SDK's Testserver connection (`src/sdk/testserver/connection.ts`), its name and payload
|
|
4656
|
+
// check, which the Vitest adapter reads too. Every other value here is the extension's (`ResourceSpec`).
|
|
4657
|
+
payload: testserverConnection,
|
|
4658
|
+
world: liveTestserverWorld,
|
|
4659
|
+
lifecycle: testserverPoolLifecycle,
|
|
4660
|
+
progress: testserverPoolProgress
|
|
4661
|
+
});
|
|
4662
|
+
|
|
4663
|
+
export {
|
|
4664
|
+
liveGitHubActionsTokenGateway,
|
|
4665
|
+
liveCredentialGateway,
|
|
4666
|
+
mintSource,
|
|
4667
|
+
obtainedSource,
|
|
4668
|
+
credentialSourceFor,
|
|
4669
|
+
mintTargetText,
|
|
4670
|
+
credentialErrors,
|
|
4671
|
+
requireTarget,
|
|
4672
|
+
settleCredential,
|
|
4673
|
+
credentialSourceErrors,
|
|
4674
|
+
credentialResolver,
|
|
4675
|
+
configErrors,
|
|
4676
|
+
liveCheckoutGateway,
|
|
4677
|
+
parseKeepTime,
|
|
4678
|
+
systemTimer,
|
|
4679
|
+
systemClock,
|
|
4680
|
+
RUN_PAYLOAD_VARIABLE,
|
|
4681
|
+
testEventLine,
|
|
4682
|
+
parseTestEvent,
|
|
4683
|
+
redactSecrets,
|
|
4684
|
+
lineSplitter,
|
|
4685
|
+
liveRunnerSandboxGateway,
|
|
4686
|
+
liveRunnerTerminal,
|
|
4687
|
+
localUserName,
|
|
4688
|
+
RUNNER_SNAPSHOTS_SUBPATH,
|
|
4689
|
+
liveRunnerSnapshotCacheGateway,
|
|
4690
|
+
unavailableRunnerSnapshotCacheGateway,
|
|
4691
|
+
prepareRunner,
|
|
4692
|
+
RUNNER_SECRET_MIN_LENGTH,
|
|
4693
|
+
readRunnerSecrets,
|
|
4694
|
+
readyRunner,
|
|
4695
|
+
SANDBOX_TEST_EVENTS_PATH,
|
|
4696
|
+
runCommandInSandbox,
|
|
4697
|
+
keptMs,
|
|
4698
|
+
runnerSandboxScope,
|
|
4699
|
+
saveBranchSnapshot,
|
|
4700
|
+
CONFIG_FILE_NAME,
|
|
4701
|
+
liveConfigGateway,
|
|
4702
|
+
findConfigFile,
|
|
4703
|
+
recipeRun,
|
|
4704
|
+
loadSettingsFile,
|
|
4705
|
+
fileSettings,
|
|
4706
|
+
settleRunResources,
|
|
4707
|
+
invalidConfig,
|
|
4708
|
+
configResolver,
|
|
4709
|
+
rejectedCredentialShape,
|
|
4710
|
+
rejectedCredentialFacts,
|
|
4711
|
+
rejectedCredentialText,
|
|
4712
|
+
credentialOriginRows,
|
|
4713
|
+
prBuildRefusalFacts,
|
|
4714
|
+
prBuildRefusalErrors,
|
|
4715
|
+
testserverPoolDefinition
|
|
4716
|
+
};
|