@cnc-tools/storm 0.15.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/application.d.ts +22 -13
- package/dist/application.js +21 -10
- package/dist/bin/run.d.ts +18 -0
- package/dist/bin/run.js +31 -0
- package/dist/bin/storm.js +42 -26
- package/dist/build-info.js +1 -1
- package/dist/chunks/{chunk-5CCP36QQ.js → chunk-2RNDPDTJ.js} +2 -2
- package/dist/chunks/chunk-2VP4GRJM.js +1219 -0
- package/dist/chunks/{chunk-SZEURWRS.js → chunk-4O5C2XGJ.js} +18 -15
- package/dist/chunks/{chunk-VL7WFTVQ.js → chunk-4WAMTUWZ.js} +419 -340
- package/dist/chunks/{chunk-QVS7HRU7.js → chunk-6UHIJXZG.js} +3 -3
- package/dist/chunks/{chunk-CN4EFA5J.js → chunk-72ZFEMAW.js} +1 -1
- package/dist/chunks/{chunk-4U4DZ7VG.js → chunk-7DZE67QM.js} +2 -2
- package/dist/chunks/{chunk-VUPZH7J2.js → chunk-BCBKYOHW.js} +1 -1
- package/dist/chunks/{chunk-QUHY6FGN.js → chunk-CKGZA25H.js} +1 -18
- package/dist/chunks/{chunk-ZG3WQ4UF.js → chunk-D27KILIA.js} +1 -1
- package/dist/chunks/{chunk-KC4KDJ5K.js → chunk-DADEYJDW.js} +174 -153
- package/dist/chunks/{chunk-R7XVBZOY.js → chunk-EEENLQHE.js} +59 -11
- package/dist/chunks/chunk-F4MOYHRY.js +198 -0
- package/dist/chunks/{chunk-CXAT7ZKP.js → chunk-FNBB6V4R.js} +1 -1
- package/dist/chunks/{chunk-OX7X4B2L.js → chunk-GRT3UIBV.js} +18 -1
- package/dist/chunks/chunk-HP3CURSZ.js +88 -0
- package/dist/chunks/{chunk-PN5ULTTH.js → chunk-HWIQ2S7K.js} +5 -5
- package/dist/chunks/chunk-JN3YY6ZH.js +2166 -0
- package/dist/chunks/{chunk-TJNFVNKR.js → chunk-LKTZ5OXS.js} +1 -1
- package/dist/chunks/{chunk-XEVHP5ZW.js → chunk-M7EKRGVD.js} +8 -8
- package/dist/chunks/chunk-MR77L2GK.js +340 -0
- package/dist/chunks/{chunk-L36GBUBB.js → chunk-RNAS7JHE.js} +1755 -522
- package/dist/chunks/{chunk-5GBMR4HM.js → chunk-RWIXDDCK.js} +4 -192
- package/dist/chunks/{chunk-5VXBKPW6.js → chunk-WV3DP6NR.js} +1 -1
- package/dist/chunks/{chunk-AWBSONHB.js → chunk-XBDRVFEV.js} +55 -16
- package/dist/chunks/{chunk-YV7GE6EV.js → chunk-YEPFSLQR.js} +480 -375
- package/dist/chunks/{live-app-PI3BAN6Y.js → live-app-R76JQXZL.js} +15 -13
- package/dist/commands/exec/across-sandboxes-outcomes.d.ts +1 -1
- package/dist/commands/exec/across-sandboxes-outcomes.js +4 -3
- package/dist/commands/exec/before-run.d.ts +123 -0
- package/dist/commands/exec/before-run.js +105 -0
- package/dist/commands/exec/command.d.ts +39 -4
- package/dist/commands/exec/command.js +31 -95
- package/dist/commands/exec/driver-plan.d.ts +9 -4
- package/dist/commands/exec/driver-plan.js +8 -8
- package/dist/commands/exec/exec-words.js +1 -1
- package/dist/commands/exec/execute-run.d.ts +39 -0
- package/dist/commands/exec/execute-run.js +325 -0
- package/dist/commands/exec/live-view.d.ts +3 -3
- package/dist/commands/exec/live-view.js +16 -15
- package/dist/commands/exec/metadata.js +1 -1
- package/dist/commands/exec/mint-failed.d.ts +38 -0
- package/dist/commands/exec/mint-failed.js +27 -4
- package/dist/commands/exec/outcomes.d.ts +38 -9
- package/dist/commands/exec/outcomes.js +32 -25
- package/dist/commands/exec/plan-run.d.ts +58 -150
- package/dist/commands/exec/plan-run.js +232 -88
- package/dist/commands/exec/planned-outcome.js +8 -1
- package/dist/commands/exec/progress.d.ts +10 -6
- package/dist/commands/exec/progress.js +38 -25
- package/dist/commands/exec/run-bin.d.ts +11 -11
- package/dist/commands/exec/run-bin.js +9 -9
- package/dist/commands/exec/run-flags.d.ts +69 -0
- package/dist/commands/exec/run-flags.js +58 -0
- package/dist/commands/exec/run-metadata.js +5 -5
- package/dist/commands/exec/run-summary.d.ts +58 -0
- package/dist/commands/exec/run-summary.js +205 -0
- package/dist/commands/exec/runner-refusals.d.ts +82 -0
- package/dist/commands/exec/runner-refusals.js +71 -0
- package/dist/commands/exec/sandbox-progress.js +3 -0
- package/dist/commands/exec/stopped-outcome.d.ts +12 -0
- package/dist/commands/exec/stopped-outcome.js +77 -0
- package/dist/commands/exec/view.d.ts +20 -11
- package/dist/commands/exec/view.js +103 -47
- package/dist/commands/runs/facts.d.ts +9 -4
- package/dist/commands/runs/facts.js +28 -11
- package/dist/commands/runs/list/command.d.ts +16 -6
- package/dist/commands/runs/list/command.js +10 -10
- package/dist/commands/runs/list/outcomes.d.ts +8 -3
- package/dist/commands/runs/logs/command.d.ts +6 -2
- package/dist/commands/runs/logs/command.js +10 -10
- package/dist/commands/runs/logs/outcomes.d.ts +3 -1
- package/dist/commands/runs/past-run.d.ts +14 -5
- package/dist/commands/runs/past-run.js +16 -5
- package/dist/commands/runs/show/command.d.ts +20 -8
- package/dist/commands/runs/show/command.js +30 -28
- package/dist/commands/runs/show/outcomes.d.ts +10 -4
- package/dist/commands/runs/show/outcomes.js +7 -5
- package/dist/commands/snapshots/access.d.ts +111 -0
- package/dist/commands/snapshots/access.js +96 -0
- package/dist/commands/snapshots/build/command.d.ts +360 -93
- package/dist/commands/snapshots/build/command.js +446 -150
- package/dist/commands/snapshots/build/metadata.d.ts +10 -0
- package/dist/commands/snapshots/build/metadata.js +31 -11
- package/dist/commands/snapshots/build/outcomes.d.ts +234 -43
- package/dist/commands/snapshots/build/outcomes.js +200 -36
- package/dist/commands/snapshots/list/command.d.ts +368 -27
- package/dist/commands/snapshots/list/command.js +296 -66
- package/dist/commands/snapshots/list/metadata.d.ts +16 -0
- package/dist/commands/snapshots/list/metadata.js +29 -6
- package/dist/commands/snapshots/list/outcomes.d.ts +245 -13
- package/dist/commands/snapshots/list/outcomes.js +221 -50
- package/dist/commands/snapshots/metadata.js +1 -1
- package/dist/commands/snapshots/prune/command.d.ts +430 -0
- package/dist/commands/snapshots/prune/command.js +161 -0
- package/dist/commands/snapshots/prune/metadata.d.ts +28 -0
- package/dist/commands/snapshots/prune/metadata.js +39 -0
- package/dist/commands/snapshots/prune/outcomes.d.ts +208 -0
- package/dist/commands/snapshots/prune/outcomes.js +78 -0
- package/dist/commands/suites/list/command.js +19 -18
- package/dist/commands/suites/list/outcomes.js +4 -4
- package/dist/commands/test/command.d.ts +39 -4
- package/dist/commands/test/command.js +50 -255
- package/dist/commands/test/metadata.js +1 -1
- package/dist/commands/test/outcomes.d.ts +19 -2
- package/dist/commands/test/outcomes.js +2 -2
- package/dist/config/check-runner.d.ts +5 -3
- package/dist/config/check-runner.js +33 -7
- package/dist/config/check-suites.js +1 -0
- package/dist/config/credential-resolver.d.ts +50 -5
- package/dist/config/credential-resolver.js +51 -19
- package/dist/config/credential-settle.d.ts +6 -2
- package/dist/config/credential-settle.js +11 -5
- package/dist/config/gateways.d.ts +7 -3
- package/dist/config/index.d.ts +4 -5
- package/dist/config/index.js +3 -4
- package/dist/config/live/config-gateway.js +5 -2
- package/dist/config/load.d.ts +21 -4
- package/dist/config/load.js +129 -15
- package/dist/config/runner.d.ts +7 -8
- package/dist/config/runner.js +1 -1
- package/dist/config/schema.d.ts +17 -5
- package/dist/config/schema.js +11 -3
- package/dist/config/typed-options.d.ts +1 -6
- package/dist/config/typed-options.js +2 -10
- package/dist/config-file/define.d.ts +1 -11
- package/dist/config-file/define.js +3 -3
- package/dist/config-file/runner.d.ts +5 -6
- package/dist/config-file/toolchain.d.ts +13 -7
- package/dist/config-file/toolchain.js +53 -37
- package/dist/context.d.ts +8 -6
- package/dist/context.js +7 -6
- package/dist/core/across-sandboxes.d.ts +7 -6
- package/dist/core/across-sandboxes.js +123 -152
- package/dist/core/coordinator.d.ts +166 -0
- package/dist/core/coordinator.js +233 -0
- package/dist/core/events.d.ts +2 -2
- package/dist/core/index.d.ts +4 -2
- package/dist/core/index.js +1 -1
- package/dist/core/outcomes.d.ts +148 -0
- package/dist/core/{sandbox-end.js → outcomes.js} +28 -4
- package/dist/core/resources.d.ts +31 -53
- package/dist/core/resources.js +32 -70
- package/dist/core/run-state.d.ts +7 -1
- package/dist/core/run-state.js +2 -0
- package/dist/core/run.d.ts +32 -236
- package/dist/core/run.js +106 -266
- package/dist/core/state-directory.d.ts +1 -1
- package/dist/core/state-directory.js +2 -2
- package/dist/credential/gateways.d.ts +15 -1
- package/dist/credential/index.d.ts +4 -3
- package/dist/credential/index.js +3 -2
- package/dist/credential/live/vercel-cli-gateway.d.ts +1 -1
- package/dist/credential/live/vercel-cli-gateway.js +1 -1
- package/dist/credential/live/vercel-oidc-token-gateway.d.ts +11 -0
- package/dist/credential/live/vercel-oidc-token-gateway.js +16 -0
- package/dist/credential/source.d.ts +73 -6
- package/dist/credential/source.js +55 -2
- package/dist/extension-commands.d.ts +6 -1
- package/dist/extension-commands.js +15 -1
- package/dist/extensions/github/resource.d.ts +1 -1
- package/dist/extensions/github/resource.js +1 -1
- package/dist/extensions/testserver/commands/pool/create/command.d.ts +35 -2
- package/dist/extensions/testserver/commands/pool/create/command.js +7 -7
- package/dist/extensions/testserver/commands/pool/create/metadata.js +5 -5
- package/dist/extensions/testserver/commands/pool/create/outcomes.d.ts +17 -1
- package/dist/extensions/testserver/commands/pool/list/command.js +4 -4
- package/dist/extensions/testserver/credential-facts.d.ts +6 -2
- package/dist/extensions/testserver/credential-facts.js +29 -11
- package/dist/extensions/testserver/lifecycle.js +7 -1
- package/dist/extensions/testserver/limit.d.ts +3 -0
- package/dist/extensions/testserver/limit.js +3 -0
- package/dist/extensions/testserver/provision.d.ts +8 -1
- package/dist/extensions/testserver/provision.js +8 -3
- package/dist/extensions/testserver/refusals.d.ts +6 -1
- package/dist/extensions/testserver/refusals.js +16 -1
- package/dist/extensions/testserver/resource.d.ts +2 -2
- package/dist/extensions/testserver/resource.js +2 -2
- package/dist/extensions/testserver/result.d.ts +1 -1
- package/dist/extensions/testserver/result.js +9 -4
- package/dist/planning/driver-file-lists.d.ts +0 -15
- package/dist/planning/driver-file-lists.js +2 -21
- package/dist/planning/plan-only.d.ts +7 -15
- package/dist/planning/plan-only.js +16 -22
- package/dist/planning/run-kind-flags.js +2 -2
- package/dist/planning/run-plan.d.ts +45 -13
- package/dist/planning/run-plan.js +4 -3
- package/dist/planning/suites.d.ts +1 -1
- package/dist/planning/suites.js +2 -2
- package/dist/planning/test-plan.d.ts +9 -0
- package/dist/planning/test-plan.js +10 -2
- package/dist/run-directory/recording.js +2 -2
- package/dist/run-directory/run-record.d.ts +21 -6
- package/dist/run-directory/run-record.js +12 -9
- package/dist/runner/base.d.ts +0 -6
- package/dist/runner/base.js +1 -16
- package/dist/runner/build-snapshots.d.ts +55 -29
- package/dist/runner/build-snapshots.js +135 -35
- package/dist/runner/context.d.ts +15 -7
- package/dist/runner/context.js +19 -6
- package/dist/runner/events.d.ts +16 -10
- package/dist/runner/gateways.d.ts +92 -21
- package/dist/runner/gateways.js +1 -1
- package/dist/runner/index.d.ts +11 -7
- package/dist/runner/index.js +9 -4
- package/dist/runner/live/sandbox-errors.d.ts +2 -0
- package/dist/runner/live/sandbox-errors.js +4 -0
- package/dist/runner/live/sandbox-gateway.js +141 -3
- package/dist/runner/live/snapshot-index-gateway.d.ts +12 -0
- package/dist/runner/live/{snapshot-cache-gateway.js → snapshot-index-gateway.js} +11 -11
- package/dist/runner/live/snapshot-records.js +6 -7
- package/dist/runner/local-snapshot-index.d.ts +199 -0
- package/dist/runner/local-snapshot-index.js +211 -0
- package/dist/runner/network-policy.d.ts +6 -6
- package/dist/runner/network-policy.js +7 -7
- package/dist/runner/policy-writes.d.ts +1 -1
- package/dist/runner/policy-writes.js +1 -1
- package/dist/runner/prepare.d.ts +25 -24
- package/dist/runner/prepare.js +28 -20
- package/dist/runner/ready.d.ts +18 -10
- package/dist/runner/ready.js +104 -33
- package/dist/runner/sandboxed-command.d.ts +3 -3
- package/dist/runner/sandboxed-command.js +3 -3
- package/dist/runner/scope.d.ts +10 -6
- package/dist/runner/scope.js +10 -3
- package/dist/runner/secrets.d.ts +13 -13
- package/dist/runner/secrets.js +18 -15
- package/dist/runner/session.d.ts +8 -8
- package/dist/runner/session.js +3 -3
- package/dist/runner/shared-snapshot-entry.d.ts +92 -0
- package/dist/runner/shared-snapshot-entry.js +168 -0
- package/dist/runner/shared-snapshot-list.d.ts +81 -0
- package/dist/runner/shared-snapshot-list.js +155 -0
- package/dist/runner/shared-snapshot-lookup.d.ts +51 -0
- package/dist/runner/shared-snapshot-lookup.js +118 -0
- package/dist/runner/shared-snapshot-prune.d.ts +58 -0
- package/dist/runner/shared-snapshot-prune.js +133 -0
- package/dist/runner/snapshot-build.d.ts +42 -14
- package/dist/runner/snapshot-build.js +38 -28
- package/dist/runner/snapshot-choice.js +1 -1
- package/dist/runner/snapshot-inspect.d.ts +39 -40
- package/dist/runner/snapshot-inspect.js +58 -38
- package/dist/runner/snapshot-key.d.ts +30 -21
- package/dist/runner/snapshot-key.js +49 -29
- package/dist/runner/steps.d.ts +1 -1
- package/dist/runner/steps.js +1 -1
- package/dist/runner/{recipe-check.d.ts → vercel-sandbox-check.d.ts} +2 -2
- package/dist/runner/{recipe-check.js → vercel-sandbox-check.js} +3 -2
- package/dist/runner/{recipe.d.ts → vercel-sandbox-options.d.ts} +82 -82
- package/dist/runner/vercel-sandbox-options.js +510 -0
- package/dist/runner/{recipe-secrets.d.ts → vercel-sandbox-secrets.d.ts} +6 -6
- package/dist/runner/{recipe-secrets.js → vercel-sandbox-secrets.js} +20 -20
- package/dist/sdk/extension/commands.d.ts +8 -3
- package/dist/sdk/extension/commands.js +3 -1
- package/dist/sdk/extension/credential-diagnosis.d.ts +3 -1
- package/dist/sdk/extension/credential-diagnosis.js +25 -5
- package/dist/sdk/extension/credential-source.d.ts +20 -3
- package/dist/sdk/extension/credential-source.js +4 -4
- package/dist/sdk/extension/index.d.ts +3 -2
- package/dist/sdk/extension/index.js +2 -1
- package/dist/sdk/extension/resource-definition.d.ts +4 -3
- package/dist/sdk/extension/resource-definition.js +3 -2
- package/dist/sdk/extension/resource-factory.js +3 -4
- package/dist/sdk/extension/secret-source.d.ts +1 -1
- package/dist/sdk/extension/secret-source.js +1 -1
- package/dist/sdk/extension/vercel-oidc-facts.d.ts +20 -0
- package/dist/sdk/extension/vercel-oidc-facts.js +20 -0
- package/dist/sdk/run/present.d.ts +3 -3
- package/dist/sdk/run/present.js +1 -3
- package/dist/shared/cleanup.d.ts +3 -3
- package/dist/shared/cleanup.js +15 -5
- package/dist/shared/snapshot-text.d.ts +4 -4
- package/dist/shared/snapshot-text.js +11 -11
- package/dist/time/duration.js +1 -1
- package/package.json +3 -2
- package/skills/overview.md +6 -4
- package/skills/plan-runs.md +2 -2
- package/skills/read-run-output.md +6 -6
- package/dist/chunks/chunk-E4PJNZVG.js +0 -783
- package/dist/chunks/chunk-RAQEXKL6.js +0 -2591
- package/dist/commands/exec/across-sandboxes-run.d.ts +0 -180
- package/dist/commands/exec/across-sandboxes-run.js +0 -339
- package/dist/commands/exec/plan-only.d.ts +0 -10
- package/dist/commands/exec/plan-only.js +0 -46
- package/dist/commands/exec/run-command.d.ts +0 -476
- package/dist/commands/exec/run-command.js +0 -604
- package/dist/commands/exec/run-planned.d.ts +0 -20
- package/dist/commands/exec/run-planned.js +0 -22
- package/dist/commands/exec/sandbox-view.d.ts +0 -19
- package/dist/commands/exec/sandbox-view.js +0 -72
- package/dist/commands/test/plan.d.ts +0 -92
- package/dist/commands/test/plan.js +0 -128
- package/dist/config/recipe-run.d.ts +0 -33
- package/dist/config/recipe-run.js +0 -28
- package/dist/core/sandbox-end.d.ts +0 -64
- package/dist/runner/live/snapshot-cache-gateway.d.ts +0 -12
- package/dist/runner/recipe.js +0 -425
- package/dist/runner/snapshot-cache.d.ts +0 -148
- package/dist/runner/snapshot-cache.js +0 -126
|
@@ -0,0 +1,510 @@
|
|
|
1
|
+
// The Vercel Sandbox runner options, the `runner` key of `storm.config.ts`: what a repository's runner snapshot holds and what
|
|
2
|
+
// each run does on top of it. `checkVercelSandboxOptions` holds the runner's static rules; `resolveVcpus` and
|
|
3
|
+
// `resolveSandboxCountDefault` evaluate the declared scaling rules for a run. Every option value is plain data
|
|
4
|
+
// (no functions), and the module names no resource.
|
|
5
|
+
import { parseKeepTime, parseTtl } from "../time/index.js";
|
|
6
|
+
import { RUN_PAYLOAD_VARIABLE } from "../sdk/run/launcher.js";
|
|
7
|
+
import { describeOptionValue, reportUnknownKeys } from "./vercel-sandbox-check.js";
|
|
8
|
+
import { checkCredentials, checkUnsafeSecretEnvVars, credentialSourceIds, } from "./vercel-sandbox-secrets.js";
|
|
9
|
+
export { credentialSourceIds };
|
|
10
|
+
/**
|
|
11
|
+
* storm's own limit on the number of runner sandboxes, which `runner.sandboxes.max` can't pass: a guard against a
|
|
12
|
+
* typing mistake that would start hundreds of runner sandboxes, not a claim about what Vercel Sandbox holds.
|
|
13
|
+
*/
|
|
14
|
+
export const MAX_RUNNER_SANDBOXES = 32;
|
|
15
|
+
/** The defaults of a runner's optional keys. */
|
|
16
|
+
export const VERCEL_SANDBOX_DEFAULTS = {
|
|
17
|
+
cwd: ".",
|
|
18
|
+
timeout: "60m",
|
|
19
|
+
baseRefs: ["main", "origin/main"],
|
|
20
|
+
region: "iad1",
|
|
21
|
+
runtime: "node22",
|
|
22
|
+
};
|
|
23
|
+
const VERCEL_SANDBOX_OPTION_KEYS = new Set([
|
|
24
|
+
"name",
|
|
25
|
+
"snapshot",
|
|
26
|
+
"run",
|
|
27
|
+
"cwd",
|
|
28
|
+
"vcpus",
|
|
29
|
+
"env",
|
|
30
|
+
"credentials",
|
|
31
|
+
"unsafeSecretEnvVars",
|
|
32
|
+
"allowedDomains",
|
|
33
|
+
"timeout",
|
|
34
|
+
"keepSandbox",
|
|
35
|
+
"baseRefs",
|
|
36
|
+
"region",
|
|
37
|
+
"runtime",
|
|
38
|
+
"sandboxes",
|
|
39
|
+
]);
|
|
40
|
+
const SANDBOXES_KEYS = new Set(["max", "default"]);
|
|
41
|
+
const SANDBOXES_DEFAULT_RULE_KEYS = new Set(["filesPerSandbox", "max"]);
|
|
42
|
+
const VCPUS_RULE_KEYS = new Set(["resource", "option", "per", "min", "max"]);
|
|
43
|
+
const SNAPSHOT_KEYS = new Set(["vcpus", "summary", "toolchains", "prebuild"]);
|
|
44
|
+
const RUN_KEYS = new Set(["install", "build"]);
|
|
45
|
+
const STEP_KEYS = new Set(["label", "script"]);
|
|
46
|
+
const TOOLCHAIN_STEP_KEYS = new Set(["label", "script", "baseFiles"]);
|
|
47
|
+
const NAME_PATTERN = /^[a-z0-9][a-z0-9-]*$/;
|
|
48
|
+
/** A domain the runner's `allowedDomains` lists: a bare hostname, or one with a leading `*.`. */
|
|
49
|
+
const ALLOWED_DOMAIN_PATTERN = /^(?:\*\.)?(?=.{1,253}$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+$/;
|
|
50
|
+
/**
|
|
51
|
+
* Checks Vercel Sandbox runner options against their static rules: the keys they may hold and each value's shape.
|
|
52
|
+
* Every value must be plain
|
|
53
|
+
* data; functions are refused with the declared form to use instead. Every problem is reported.
|
|
54
|
+
*/
|
|
55
|
+
export function checkVercelSandboxOptions(value) {
|
|
56
|
+
const problems = [];
|
|
57
|
+
const report = (path, problem) => problems.push({ path, problem });
|
|
58
|
+
if (!isRecord(value)) {
|
|
59
|
+
report([], `must be an object, not ${describeOptionValue(value)}`);
|
|
60
|
+
return { ok: false, problems };
|
|
61
|
+
}
|
|
62
|
+
reportUnknownKeys(value, VERCEL_SANDBOX_OPTION_KEYS, [], "a vercelSandbox option key", report);
|
|
63
|
+
const name = value["name"];
|
|
64
|
+
if (typeof name !== "string" || !NAME_PATTERN.test(name))
|
|
65
|
+
report(["name"], `must be lowercase letters, digits and dashes, starting with a letter or digit, not ${describeOptionValue(name)}`);
|
|
66
|
+
const snapshot = checkSnapshot(value["snapshot"], report);
|
|
67
|
+
const run = checkRun(value["run"], report);
|
|
68
|
+
const cwd = orDefault(value["cwd"], VERCEL_SANDBOX_DEFAULTS.cwd);
|
|
69
|
+
if (!isRelativePath(cwd))
|
|
70
|
+
report(["cwd"], `must be a path relative to the repository's root, without "..", not ${describeOptionValue(cwd)}`);
|
|
71
|
+
const vcpus = checkVcpus(value["vcpus"], report);
|
|
72
|
+
const env = checkEnv(value["env"], report);
|
|
73
|
+
const credentials = checkCredentials(value["credentials"], report);
|
|
74
|
+
const unsafeSecretEnvVars = checkUnsafeSecretEnvVars(value["unsafeSecretEnvVars"], env, credentials, report);
|
|
75
|
+
const allowedDomains = checkAllowedDomains(value["allowedDomains"], report);
|
|
76
|
+
const timeout = orDefault(value["timeout"], VERCEL_SANDBOX_DEFAULTS.timeout);
|
|
77
|
+
const timeoutMinutes = typeof timeout === "string" ? parseTtl(timeout) : undefined;
|
|
78
|
+
if (timeoutMinutes === undefined)
|
|
79
|
+
report(["timeout"], `must be a whole number of minutes or hours from 10m to 5h, not ${describeOptionValue(timeout)}`);
|
|
80
|
+
const keepSandbox = value["keepSandbox"];
|
|
81
|
+
const keepSandboxMinutes = typeof keepSandbox === "string" ? parseKeepTime(keepSandbox) : undefined;
|
|
82
|
+
if (keepSandbox !== undefined && keepSandboxMinutes === undefined)
|
|
83
|
+
report(["keepSandbox"], `must be 0, or a whole number of minutes or hours up to 5h, not ${describeOptionValue(keepSandbox)}`);
|
|
84
|
+
else if (unsafeSecretEnvVars !== undefined &&
|
|
85
|
+
unsafeSecretEnvVars.length > 0 &&
|
|
86
|
+
keepSandboxMinutes !== undefined &&
|
|
87
|
+
keepSandboxMinutes > 0)
|
|
88
|
+
report(["keepSandbox"], "can't be above 0 when runner.unsafeSecretEnvVars is set: a run that passes secrets into the runner sandbox's environment never keeps its runner sandbox");
|
|
89
|
+
const baseRefs = checkBaseRefs(value["baseRefs"], report);
|
|
90
|
+
const region = orDefault(value["region"], VERCEL_SANDBOX_DEFAULTS.region);
|
|
91
|
+
if (!isNonEmptyString(region))
|
|
92
|
+
report(["region"], `must be a non-empty string, not ${describeOptionValue(region)}`);
|
|
93
|
+
const runtime = orDefault(value["runtime"], VERCEL_SANDBOX_DEFAULTS.runtime);
|
|
94
|
+
if (!isNonEmptyString(runtime))
|
|
95
|
+
report(["runtime"], `must be a non-empty string, not ${describeOptionValue(runtime)}`);
|
|
96
|
+
const sandboxes = checkSandboxes(value["sandboxes"], report);
|
|
97
|
+
if (problems.length > 0 ||
|
|
98
|
+
snapshot === undefined ||
|
|
99
|
+
run === undefined ||
|
|
100
|
+
vcpus === undefined ||
|
|
101
|
+
env === undefined ||
|
|
102
|
+
credentials === undefined ||
|
|
103
|
+
unsafeSecretEnvVars === undefined ||
|
|
104
|
+
allowedDomains === null ||
|
|
105
|
+
baseRefs === undefined ||
|
|
106
|
+
timeoutMinutes === undefined ||
|
|
107
|
+
sandboxes === false)
|
|
108
|
+
return { ok: false, problems };
|
|
109
|
+
return {
|
|
110
|
+
ok: true,
|
|
111
|
+
value: {
|
|
112
|
+
name: name,
|
|
113
|
+
snapshot,
|
|
114
|
+
run,
|
|
115
|
+
cwd: cwd,
|
|
116
|
+
vcpus,
|
|
117
|
+
env,
|
|
118
|
+
credentials,
|
|
119
|
+
unsafeSecretEnvVars,
|
|
120
|
+
...(allowedDomains === undefined ? {} : { allowedDomains }),
|
|
121
|
+
timeout: timeout,
|
|
122
|
+
timeoutMinutes,
|
|
123
|
+
keepSandboxMinutes,
|
|
124
|
+
baseRefs,
|
|
125
|
+
region: region,
|
|
126
|
+
runtime: runtime,
|
|
127
|
+
...(sandboxes === undefined ? {} : { sandboxes }),
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
function checkVcpus(value, report) {
|
|
132
|
+
if (isPositiveInteger(value))
|
|
133
|
+
return value;
|
|
134
|
+
if (typeof value === "function") {
|
|
135
|
+
report(["vcpus"], "can't be a function: use a positive whole number, or { resource, option, per, min, max }");
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
138
|
+
if (!isRecord(value)) {
|
|
139
|
+
report(["vcpus"], `must be a positive whole number, or { resource, option, per, min, max }, not ${describeOptionValue(value)}`);
|
|
140
|
+
return undefined;
|
|
141
|
+
}
|
|
142
|
+
let ok = reportUnknownKeys(value, VCPUS_RULE_KEYS, ["vcpus"], "a vercelSandbox vcpus rule key", report);
|
|
143
|
+
const resource = value["resource"];
|
|
144
|
+
if (!isNonEmptyString(resource)) {
|
|
145
|
+
report(["vcpus", "resource"], `must be a non-empty string, not ${describeOptionValue(resource)}`);
|
|
146
|
+
ok = false;
|
|
147
|
+
}
|
|
148
|
+
const option = value["option"];
|
|
149
|
+
if (!isNonEmptyString(option)) {
|
|
150
|
+
report(["vcpus", "option"], `must be a non-empty string, not ${describeOptionValue(option)}`);
|
|
151
|
+
ok = false;
|
|
152
|
+
}
|
|
153
|
+
const per = value["per"];
|
|
154
|
+
if (!isPositiveInteger(per)) {
|
|
155
|
+
report(["vcpus", "per"], `must be a positive whole number, not ${describeOptionValue(per)}`);
|
|
156
|
+
ok = false;
|
|
157
|
+
}
|
|
158
|
+
const min = value["min"];
|
|
159
|
+
if (!isPositiveInteger(min)) {
|
|
160
|
+
report(["vcpus", "min"], `must be a positive whole number, not ${describeOptionValue(min)}`);
|
|
161
|
+
ok = false;
|
|
162
|
+
}
|
|
163
|
+
const max = value["max"];
|
|
164
|
+
if (!isPositiveInteger(max)) {
|
|
165
|
+
report(["vcpus", "max"], `must be a positive whole number, not ${describeOptionValue(max)}`);
|
|
166
|
+
ok = false;
|
|
167
|
+
}
|
|
168
|
+
else if (isPositiveInteger(min) && max < min) {
|
|
169
|
+
report(["vcpus", "max"], `must be at least vcpus.min (${min}), not ${max}`);
|
|
170
|
+
ok = false;
|
|
171
|
+
}
|
|
172
|
+
return ok
|
|
173
|
+
? {
|
|
174
|
+
resource: resource,
|
|
175
|
+
option: option,
|
|
176
|
+
per: per,
|
|
177
|
+
min: min,
|
|
178
|
+
max: max,
|
|
179
|
+
}
|
|
180
|
+
: undefined;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* The runner's `sandboxes`: an object whose `max` is a whole number from 1 to `MAX_RUNNER_SANDBOXES`, and whose
|
|
184
|
+
* optional `default` is a whole number from 1 to `MAX_RUNNER_SANDBOXES` or a declared `{ filesPerSandbox, max? }` rule;
|
|
185
|
+
* undefined when absent, and false when it is wrong, which is reported.
|
|
186
|
+
*/
|
|
187
|
+
function checkSandboxes(value, report) {
|
|
188
|
+
if (value === undefined)
|
|
189
|
+
return undefined;
|
|
190
|
+
if (!isRecord(value)) {
|
|
191
|
+
report(["sandboxes"], `must be an object with max, not ${describeOptionValue(value)}`);
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
let ok = reportUnknownKeys(value, SANDBOXES_KEYS, ["sandboxes"], "a vercelSandbox sandboxes key", report);
|
|
195
|
+
const max = value["max"];
|
|
196
|
+
if (!isPositiveInteger(max) || max > MAX_RUNNER_SANDBOXES) {
|
|
197
|
+
report(["sandboxes", "max"], `must be a whole number from 1 to ${MAX_RUNNER_SANDBOXES}, not ${describeOptionValue(max)}`);
|
|
198
|
+
ok = false;
|
|
199
|
+
}
|
|
200
|
+
const rawDefault = value["default"];
|
|
201
|
+
let sandboxesDefault;
|
|
202
|
+
if (rawDefault !== undefined) {
|
|
203
|
+
const checkedDefault = checkSandboxesDefault(rawDefault, report);
|
|
204
|
+
if (checkedDefault === undefined)
|
|
205
|
+
ok = false;
|
|
206
|
+
else
|
|
207
|
+
sandboxesDefault = checkedDefault;
|
|
208
|
+
}
|
|
209
|
+
if (!ok)
|
|
210
|
+
return false;
|
|
211
|
+
return {
|
|
212
|
+
max: max,
|
|
213
|
+
...(sandboxesDefault === undefined ? {} : { default: sandboxesDefault }),
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
function checkSandboxesDefault(value, report) {
|
|
217
|
+
if (isPositiveInteger(value) && value <= MAX_RUNNER_SANDBOXES)
|
|
218
|
+
return value;
|
|
219
|
+
if (typeof value === "function") {
|
|
220
|
+
report(["sandboxes", "default"], `can't be a function: use a whole number from 1 to ${MAX_RUNNER_SANDBOXES}, or { filesPerSandbox, max? }`);
|
|
221
|
+
return undefined;
|
|
222
|
+
}
|
|
223
|
+
if (!isRecord(value)) {
|
|
224
|
+
report(["sandboxes", "default"], `must be a whole number from 1 to ${MAX_RUNNER_SANDBOXES}, or { filesPerSandbox, max? }, not ${describeOptionValue(value)}`);
|
|
225
|
+
return undefined;
|
|
226
|
+
}
|
|
227
|
+
let ok = reportUnknownKeys(value, SANDBOXES_DEFAULT_RULE_KEYS, ["sandboxes", "default"], "a vercelSandbox sandboxes default rule key", report);
|
|
228
|
+
const filesPerSandbox = value["filesPerSandbox"];
|
|
229
|
+
if (!isPositiveInteger(filesPerSandbox)) {
|
|
230
|
+
report(["sandboxes", "default", "filesPerSandbox"], `must be a positive whole number, not ${describeOptionValue(filesPerSandbox)}`);
|
|
231
|
+
ok = false;
|
|
232
|
+
}
|
|
233
|
+
const max = value["max"];
|
|
234
|
+
if (max !== undefined && (!isPositiveInteger(max) || max > MAX_RUNNER_SANDBOXES)) {
|
|
235
|
+
report(["sandboxes", "default", "max"], `must be a whole number from 1 to ${MAX_RUNNER_SANDBOXES}, not ${describeOptionValue(max)}`);
|
|
236
|
+
ok = false;
|
|
237
|
+
}
|
|
238
|
+
if (!ok)
|
|
239
|
+
return undefined;
|
|
240
|
+
return {
|
|
241
|
+
filesPerSandbox: filesPerSandbox,
|
|
242
|
+
...(max === undefined ? {} : { max: max }),
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
function checkSnapshot(value, report) {
|
|
246
|
+
if (!isRecord(value)) {
|
|
247
|
+
report(["snapshot"], `must be an object of vcpus, toolchains, prebuild, and an optional summary, not ${describeOptionValue(value)}`);
|
|
248
|
+
return undefined;
|
|
249
|
+
}
|
|
250
|
+
let ok = reportUnknownKeys(value, SNAPSHOT_KEYS, ["snapshot"], "a vercelSandbox snapshot key", report);
|
|
251
|
+
const vcpus = value["vcpus"];
|
|
252
|
+
if (!isPositiveInteger(vcpus)) {
|
|
253
|
+
report(["snapshot", "vcpus"], `must be a positive whole number, not ${describeOptionValue(vcpus)}`);
|
|
254
|
+
ok = false;
|
|
255
|
+
}
|
|
256
|
+
const summary = value["summary"];
|
|
257
|
+
if (summary !== undefined && !isNonEmptyString(summary)) {
|
|
258
|
+
report(["snapshot", "summary"], `must be a non-empty string, not ${describeOptionValue(summary)}`);
|
|
259
|
+
ok = false;
|
|
260
|
+
}
|
|
261
|
+
const toolchains = checkSteps(value["toolchains"], ["snapshot", "toolchains"], true, report);
|
|
262
|
+
const prebuild = checkSteps(value["prebuild"], ["snapshot", "prebuild"], false, report);
|
|
263
|
+
if (!ok || toolchains === undefined || prebuild === undefined)
|
|
264
|
+
return undefined;
|
|
265
|
+
return {
|
|
266
|
+
vcpus: vcpus,
|
|
267
|
+
...(summary === undefined ? {} : { summary: summary }),
|
|
268
|
+
toolchains,
|
|
269
|
+
prebuild,
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
function checkRun(value, report) {
|
|
273
|
+
if (!isRecord(value)) {
|
|
274
|
+
report(["run"], `must be an object of install and build steps, not ${describeOptionValue(value)}`);
|
|
275
|
+
return undefined;
|
|
276
|
+
}
|
|
277
|
+
const ok = reportUnknownKeys(value, RUN_KEYS, ["run"], "a vercelSandbox run key", report);
|
|
278
|
+
const install = checkStep(value["install"], ["run", "install"], false, report);
|
|
279
|
+
const build = checkStep(value["build"], ["run", "build"], false, report);
|
|
280
|
+
return ok && install !== undefined && build !== undefined ? { install, build } : undefined;
|
|
281
|
+
}
|
|
282
|
+
function checkSteps(value, path, allowBaseFiles, report) {
|
|
283
|
+
if (typeof value === "function") {
|
|
284
|
+
report(path, allowBaseFiles
|
|
285
|
+
? "can't be a function: use a list of { label, script, baseFiles? } steps and declare the base files each step reads"
|
|
286
|
+
: "can't be a function: use a list of { label, script } steps (prebuild steps already see the base's files)");
|
|
287
|
+
return undefined;
|
|
288
|
+
}
|
|
289
|
+
if (!Array.isArray(value)) {
|
|
290
|
+
report(path, `must be a list of steps, not ${describeOptionValue(value)}`);
|
|
291
|
+
return undefined;
|
|
292
|
+
}
|
|
293
|
+
const steps = value.map((step, index) => allowBaseFiles
|
|
294
|
+
? checkStep(step, [...path, String(index)], true, report)
|
|
295
|
+
: checkStep(step, [...path, String(index)], false, report));
|
|
296
|
+
return steps.every((step) => step !== undefined) ? steps : undefined;
|
|
297
|
+
}
|
|
298
|
+
function checkStep(value, path, allowBaseFiles, report) {
|
|
299
|
+
if (!isRecord(value)) {
|
|
300
|
+
const shape = allowBaseFiles ? "{ label, script, baseFiles? }" : "{ label, script }";
|
|
301
|
+
report(path, `must be a step, ${shape}, not ${describeOptionValue(value)}`);
|
|
302
|
+
return undefined;
|
|
303
|
+
}
|
|
304
|
+
const allowedKeys = allowBaseFiles ? TOOLCHAIN_STEP_KEYS : STEP_KEYS;
|
|
305
|
+
let ok = true;
|
|
306
|
+
for (const key of Object.keys(value)) {
|
|
307
|
+
if (allowedKeys.has(key))
|
|
308
|
+
continue;
|
|
309
|
+
report([...path, key], key === "secrets"
|
|
310
|
+
? "is not a step key: every step of the runner gets every credential runner.credentials declares"
|
|
311
|
+
: key === "baseFiles"
|
|
312
|
+
? "is only allowed on snapshot.toolchains steps: this step already sees the base's files"
|
|
313
|
+
: "is not a step key");
|
|
314
|
+
ok = false;
|
|
315
|
+
}
|
|
316
|
+
const label = value["label"];
|
|
317
|
+
const script = value["script"];
|
|
318
|
+
if (!isNonEmptyString(label)) {
|
|
319
|
+
report([...path, "label"], `must be a non-empty string, not ${describeOptionValue(label)}`);
|
|
320
|
+
ok = false;
|
|
321
|
+
}
|
|
322
|
+
if (!isNonEmptyString(script)) {
|
|
323
|
+
report([...path, "script"], `must be a non-empty string, not ${describeOptionValue(script)}`);
|
|
324
|
+
ok = false;
|
|
325
|
+
}
|
|
326
|
+
if (!allowBaseFiles)
|
|
327
|
+
return ok ? { label: label, script: script } : undefined;
|
|
328
|
+
const baseFiles = checkBaseFiles(value["baseFiles"], [...path, "baseFiles"], report);
|
|
329
|
+
if (baseFiles === null)
|
|
330
|
+
ok = false;
|
|
331
|
+
if (!ok || baseFiles === null)
|
|
332
|
+
return undefined;
|
|
333
|
+
return {
|
|
334
|
+
label: label,
|
|
335
|
+
script: script,
|
|
336
|
+
...(baseFiles === undefined || baseFiles.length === 0 ? {} : { baseFiles }),
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
function checkBaseFiles(value, path, report) {
|
|
340
|
+
if (value === undefined)
|
|
341
|
+
return undefined;
|
|
342
|
+
if (!Array.isArray(value)) {
|
|
343
|
+
report(path, `must be a list of relative file paths, not ${describeOptionValue(value)}`);
|
|
344
|
+
return null;
|
|
345
|
+
}
|
|
346
|
+
let ok = true;
|
|
347
|
+
const seen = new Set();
|
|
348
|
+
const checked = [];
|
|
349
|
+
value.forEach((entry, index) => {
|
|
350
|
+
const at = [...path, String(index)];
|
|
351
|
+
if (!isRelativeFilePath(entry)) {
|
|
352
|
+
report(at, `must be a relative file path without leading "/", "./", "..", or trailing "/", not ${describeOptionValue(entry)}`);
|
|
353
|
+
ok = false;
|
|
354
|
+
}
|
|
355
|
+
else if (seen.has(entry)) {
|
|
356
|
+
report(at, `lists ${entry} again`);
|
|
357
|
+
ok = false;
|
|
358
|
+
}
|
|
359
|
+
else {
|
|
360
|
+
seen.add(entry);
|
|
361
|
+
checked.push(entry);
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
return ok ? checked : null;
|
|
365
|
+
}
|
|
366
|
+
function checkEnv(value, report) {
|
|
367
|
+
if (value === undefined)
|
|
368
|
+
return {};
|
|
369
|
+
if (!isRecord(value)) {
|
|
370
|
+
report(["env"], `must be an object of strings, not ${describeOptionValue(value)}`);
|
|
371
|
+
return undefined;
|
|
372
|
+
}
|
|
373
|
+
let ok = true;
|
|
374
|
+
const env = {};
|
|
375
|
+
for (const [key, variable] of Object.entries(value)) {
|
|
376
|
+
if (key === RUN_PAYLOAD_VARIABLE) {
|
|
377
|
+
report(["env", key], "can't be set: storm sets it for the command");
|
|
378
|
+
ok = false;
|
|
379
|
+
}
|
|
380
|
+
else if (typeof variable !== "string") {
|
|
381
|
+
report(["env", key], `must be a string, not ${describeOptionValue(variable)}`);
|
|
382
|
+
ok = false;
|
|
383
|
+
}
|
|
384
|
+
else
|
|
385
|
+
env[key] = variable;
|
|
386
|
+
}
|
|
387
|
+
return ok ? env : undefined;
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* The runner's `allowedDomains`: a non-empty list of domains (`ALLOWED_DOMAIN_PATTERN`), none listed twice; undefined
|
|
391
|
+
* when absent, for full access, and null when it is wrong.
|
|
392
|
+
*/
|
|
393
|
+
function checkAllowedDomains(value, report) {
|
|
394
|
+
if (value === undefined)
|
|
395
|
+
return undefined;
|
|
396
|
+
if (!Array.isArray(value)) {
|
|
397
|
+
report(["allowedDomains"], `must be a list of domains, such as ["registry.npmjs.org", "*.example.com"], not ${describeOptionValue(value)}`);
|
|
398
|
+
return null;
|
|
399
|
+
}
|
|
400
|
+
if (value.length === 0) {
|
|
401
|
+
report(["allowedDomains"], "must list at least one domain: leave the key out for full access");
|
|
402
|
+
return null;
|
|
403
|
+
}
|
|
404
|
+
let ok = true;
|
|
405
|
+
const seen = new Set();
|
|
406
|
+
value.forEach((domain, index) => {
|
|
407
|
+
const at = ["allowedDomains", String(index)];
|
|
408
|
+
if (domain === "*") {
|
|
409
|
+
report(at, "can't be *, which would allow every domain: leave runner.allowedDomains out for full access");
|
|
410
|
+
ok = false;
|
|
411
|
+
}
|
|
412
|
+
else if (typeof domain !== "string" || !ALLOWED_DOMAIN_PATTERN.test(domain)) {
|
|
413
|
+
report(at, `must be a hostname, such as example.com, or a wildcard with one leading *., such as *.example.com: lowercase letters, digits, dots, and hyphens, with at least one dot, and no scheme, port, or path, not ${describeOptionValue(domain)}`);
|
|
414
|
+
ok = false;
|
|
415
|
+
}
|
|
416
|
+
else if (seen.has(domain)) {
|
|
417
|
+
report(at, `lists ${domain} again`);
|
|
418
|
+
ok = false;
|
|
419
|
+
}
|
|
420
|
+
if (typeof domain === "string")
|
|
421
|
+
seen.add(domain);
|
|
422
|
+
});
|
|
423
|
+
return ok ? [...value] : null;
|
|
424
|
+
}
|
|
425
|
+
function checkBaseRefs(value, report) {
|
|
426
|
+
if (value === undefined)
|
|
427
|
+
return [...VERCEL_SANDBOX_DEFAULTS.baseRefs];
|
|
428
|
+
if (!Array.isArray(value) || value.length === 0) {
|
|
429
|
+
report(["baseRefs"], `must be a non-empty list of refs, not ${describeOptionValue(value)}`);
|
|
430
|
+
return undefined;
|
|
431
|
+
}
|
|
432
|
+
let ok = true;
|
|
433
|
+
value.forEach((ref, index) => {
|
|
434
|
+
if (!isNonEmptyString(ref)) {
|
|
435
|
+
report(["baseRefs", String(index)], `must be a non-empty string, not ${describeOptionValue(ref)}`);
|
|
436
|
+
ok = false;
|
|
437
|
+
}
|
|
438
|
+
});
|
|
439
|
+
return ok ? [...value] : undefined;
|
|
440
|
+
}
|
|
441
|
+
/** The sorted, unique repository-relative base file paths declared across `toolchains`. */
|
|
442
|
+
export function declaredBaseFilePaths(toolchains) {
|
|
443
|
+
const paths = new Set();
|
|
444
|
+
for (const step of toolchains) {
|
|
445
|
+
if (step.baseFiles === undefined)
|
|
446
|
+
continue;
|
|
447
|
+
for (const file of step.baseFiles)
|
|
448
|
+
paths.add(file);
|
|
449
|
+
}
|
|
450
|
+
return [...paths].toSorted((a, b) => (a < b ? -1 : a > b ? 1 : 0));
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* The runner sandbox's vCPUs for `run`: the runner's number, or the declared resource-scaling rule evaluated against
|
|
454
|
+
* `run.resources` and `run.sandboxes`. When the named resource is absent from the run, `min` is used. When the named
|
|
455
|
+
* resource is present and its named option is missing or not a non-negative finite number, returns a problem.
|
|
456
|
+
*/
|
|
457
|
+
export function resolveVcpus(options, run) {
|
|
458
|
+
if (typeof options.vcpus === "number")
|
|
459
|
+
return { ok: true, vcpus: options.vcpus };
|
|
460
|
+
const { resource, option, per, min, max } = options.vcpus;
|
|
461
|
+
const resourceOptions = Object.hasOwn(run.resources, resource) ? run.resources[resource] : undefined;
|
|
462
|
+
if (resourceOptions === undefined)
|
|
463
|
+
return { ok: true, vcpus: min };
|
|
464
|
+
const raw = Object.hasOwn(resourceOptions, option) ? resourceOptions[option] : undefined;
|
|
465
|
+
if (typeof raw !== "number" || !Number.isFinite(raw) || raw < 0) {
|
|
466
|
+
return {
|
|
467
|
+
ok: false,
|
|
468
|
+
problem: `resource "${resource}" option "${option}" must be a non-negative number, not ${describeOptionValue(raw)}`,
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
const perSandbox = Math.ceil(raw / Math.max(1, run.sandboxes));
|
|
472
|
+
return { ok: true, vcpus: Math.min(max, Math.max(min, per * perSandbox)) };
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* The number of runner sandboxes `runner.sandboxes.default` gives a run with test plan `testPlan`: the runner's number,
|
|
476
|
+
* or the declared `{ filesPerSandbox, max? }` rule evaluated against `testPlan`. A number above `sandboxes.max` is not
|
|
477
|
+
* a problem here: the run lowers it to `sandboxes.max` and says so.
|
|
478
|
+
*/
|
|
479
|
+
export function resolveSandboxCountDefault(sandboxesDefault, testPlan) {
|
|
480
|
+
if (typeof sandboxesDefault === "number")
|
|
481
|
+
return sandboxesDefault;
|
|
482
|
+
if (testPlan.kind !== "counted")
|
|
483
|
+
return 1;
|
|
484
|
+
const limit = sandboxesDefault.max ?? MAX_RUNNER_SANDBOXES;
|
|
485
|
+
return Math.max(1, Math.min(limit, Math.ceil(testPlan.files / sandboxesDefault.filesPerSandbox)));
|
|
486
|
+
}
|
|
487
|
+
/** `value`, or `fallback` when the key is absent or set to `undefined`. A `null` stays, to be refused. */
|
|
488
|
+
function orDefault(value, fallback) {
|
|
489
|
+
return value === undefined ? fallback : value;
|
|
490
|
+
}
|
|
491
|
+
function isRecord(value) {
|
|
492
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
493
|
+
}
|
|
494
|
+
function isNonEmptyString(value) {
|
|
495
|
+
return typeof value === "string" && value.length > 0;
|
|
496
|
+
}
|
|
497
|
+
function isPositiveInteger(value) {
|
|
498
|
+
return typeof value === "number" && Number.isInteger(value) && value > 0;
|
|
499
|
+
}
|
|
500
|
+
function isRelativePath(value) {
|
|
501
|
+
return (typeof value === "string" && value.length > 0 && !value.startsWith("/") && !value.split(/[/\\]/).includes(".."));
|
|
502
|
+
}
|
|
503
|
+
function isRelativeFilePath(value) {
|
|
504
|
+
if (typeof value !== "string" || value.length === 0)
|
|
505
|
+
return false;
|
|
506
|
+
if (value.startsWith("/") || value.endsWith("/") || value.includes("\\") || value.includes("\0"))
|
|
507
|
+
return false;
|
|
508
|
+
const segments = value.split("/");
|
|
509
|
+
return segments.every((segment) => segment.length > 0 && segment !== "." && segment !== "..");
|
|
510
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type SecretSource } from "../sdk/extension/index.ts";
|
|
2
|
-
import { type Report } from "./
|
|
2
|
+
import { type Report } from "./vercel-sandbox-check.ts";
|
|
3
3
|
/**
|
|
4
4
|
* One sandbox credential declared in `runner.credentials`: a header the Sandbox firewall adds to a sandbox's requests
|
|
5
|
-
* to one domain while the
|
|
5
|
+
* to one domain while the runner's steps and the command run, with its value read from `source` as the run starts. The
|
|
6
6
|
* value never enters the sandbox.
|
|
7
7
|
*/
|
|
8
8
|
export interface CredentialDeclaration {
|
|
@@ -46,10 +46,10 @@ export interface UnsafeSecretEnvVar {
|
|
|
46
46
|
readonly source: SecretSource;
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
|
-
* The sorted, unique secret source identities
|
|
50
|
-
* hashing into the runner snapshot key.
|
|
49
|
+
* The sorted, unique secret source identities checked runner options' credentials read from (such as
|
|
50
|
+
* `"env:NPM_AUTH"`), for hashing into the runner snapshot key.
|
|
51
51
|
*/
|
|
52
|
-
export declare function credentialSourceIds(
|
|
52
|
+
export declare function credentialSourceIds(options: {
|
|
53
53
|
readonly credentials: readonly Required<CredentialDeclaration>[];
|
|
54
54
|
}): readonly string[];
|
|
55
55
|
/**
|
|
@@ -60,7 +60,7 @@ export declare function credentialSourceIds(recipe: {
|
|
|
60
60
|
*/
|
|
61
61
|
export declare function checkCredentials(value: unknown, report: Report): readonly Required<CredentialDeclaration>[] | undefined;
|
|
62
62
|
/**
|
|
63
|
-
* The
|
|
63
|
+
* The runner's `unsafeSecretEnvVars`: a list of `{ name, source }` plain objects, each exposing a distinct environment
|
|
64
64
|
* variable `name` that neither storm sets for the command (`STORM_RUN`, `RESERVED_UNSAFE_SECRET_ENV_VAR_NAMES`,
|
|
65
65
|
* `LD_*`, `DYLD_*`) nor `runner.env` sets, read from a `SecretSource` that `runner.credentials` doesn't already read.
|
|
66
66
|
*/
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
// Secret declarations on a runner
|
|
2
|
-
// and `runner.unsafeSecretEnvVars` (environment variables exposed to the command alone).
|
|
3
|
-
// `
|
|
1
|
+
// Secret declarations on a Vercel Sandbox runner: `runner.credentials` (sandbox credentials injected by the Sandbox
|
|
2
|
+
// firewall) and `runner.unsafeSecretEnvVars` (environment variables exposed to the command alone).
|
|
3
|
+
// `vercel-sandbox-options.ts` coordinates `checkVercelSandboxOptions` and delegates both secret keys here.
|
|
4
4
|
import { ENV_VAR_NAME_PATTERN, ENV_VAR_NAME_RULE, secretSourceId } from "../sdk/extension/index.js";
|
|
5
5
|
import { RUN_PAYLOAD_VARIABLE } from "../sdk/run/launcher.js";
|
|
6
|
-
import {
|
|
6
|
+
import { describeOptionValue, reportUnknownKeys } from "./vercel-sandbox-check.js";
|
|
7
7
|
const CREDENTIAL_KEYS = new Set(["domain", "header", "source", "requests"]);
|
|
8
8
|
const UNSAFE_SECRET_ENV_VAR_KEYS = new Set(["name", "source"]);
|
|
9
9
|
const ENV_SOURCE_KEYS = new Set(["kind", "name"]);
|
|
@@ -38,11 +38,11 @@ const RESERVED_UNSAFE_SECRET_ENV_VAR_NAMES = new Set([
|
|
|
38
38
|
/** Prefixes of the dynamic loader's variables, which an unsafe secret environment variable's name can't start with. */
|
|
39
39
|
const RESERVED_UNSAFE_SECRET_ENV_VAR_PREFIXES = ["LD_", "DYLD_"];
|
|
40
40
|
/**
|
|
41
|
-
* The sorted, unique secret source identities
|
|
42
|
-
* hashing into the runner snapshot key.
|
|
41
|
+
* The sorted, unique secret source identities checked runner options' credentials read from (such as
|
|
42
|
+
* `"env:NPM_AUTH"`), for hashing into the runner snapshot key.
|
|
43
43
|
*/
|
|
44
|
-
export function credentialSourceIds(
|
|
45
|
-
return [...new Set(
|
|
44
|
+
export function credentialSourceIds(options) {
|
|
45
|
+
return [...new Set(options.credentials.map(({ source }) => secretSourceId(source)))].toSorted();
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
48
48
|
* The sandbox credentials: a list of `{ domain, header?, source, requests? }` (`checkCredential`), with no two going
|
|
@@ -54,7 +54,7 @@ export function checkCredentials(value, report) {
|
|
|
54
54
|
if (value === undefined)
|
|
55
55
|
return [];
|
|
56
56
|
if (!Array.isArray(value)) {
|
|
57
|
-
report(["credentials"], `must be a list of credentials, each { domain, header?, source, requests? }, not ${
|
|
57
|
+
report(["credentials"], `must be a list of credentials, each { domain, header?, source, requests? }, not ${describeOptionValue(value)}`);
|
|
58
58
|
return undefined;
|
|
59
59
|
}
|
|
60
60
|
let ok = true;
|
|
@@ -94,18 +94,18 @@ export function checkCredentials(value, report) {
|
|
|
94
94
|
*/
|
|
95
95
|
function checkCredential(value, path, report) {
|
|
96
96
|
if (!isPlainObject(value)) {
|
|
97
|
-
report(path, `must be { domain, header?, source, requests? }, not ${
|
|
97
|
+
report(path, `must be { domain, header?, source, requests? }, not ${describeOptionValue(value)}`);
|
|
98
98
|
return undefined;
|
|
99
99
|
}
|
|
100
100
|
let ok = reportUnknownKeys(value, CREDENTIAL_KEYS, path, "a credential key", report);
|
|
101
101
|
const domain = value["domain"];
|
|
102
102
|
if (typeof domain !== "string" || !HOST_PATTERN.test(domain)) {
|
|
103
|
-
report([...path, "domain"], `must be a bare hostname, such as registry.example.com: lowercase letters, digits, dots, and hyphens, with at least one dot, and no scheme, port, path, or wildcard, not ${
|
|
103
|
+
report([...path, "domain"], `must be a bare hostname, such as registry.example.com: lowercase letters, digits, dots, and hyphens, with at least one dot, and no scheme, port, path, or wildcard, not ${describeOptionValue(domain)}`);
|
|
104
104
|
ok = false;
|
|
105
105
|
}
|
|
106
106
|
const header = value["header"] === undefined ? DEFAULT_CREDENTIAL_HEADER : value["header"];
|
|
107
107
|
if (typeof header !== "string" || !HEADER_PATTERN.test(header)) {
|
|
108
|
-
report([...path, "header"], `must be an HTTP header name, such as authorization, not ${
|
|
108
|
+
report([...path, "header"], `must be an HTTP header name, such as authorization, not ${describeOptionValue(header)}`);
|
|
109
109
|
ok = false;
|
|
110
110
|
}
|
|
111
111
|
else if (REFUSED_HEADERS.has(header.toLowerCase())) {
|
|
@@ -117,7 +117,7 @@ function checkCredential(value, path, report) {
|
|
|
117
117
|
ok = false;
|
|
118
118
|
const requests = value["requests"] === undefined ? "read" : value["requests"];
|
|
119
119
|
if (requests !== "read" && requests !== "all") {
|
|
120
|
-
report([...path, "requests"], `must be "read" or "all", not ${
|
|
120
|
+
report([...path, "requests"], `must be "read" or "all", not ${describeOptionValue(requests)}`);
|
|
121
121
|
ok = false;
|
|
122
122
|
}
|
|
123
123
|
return ok && source !== undefined
|
|
@@ -132,12 +132,12 @@ function checkCredential(value, path, report) {
|
|
|
132
132
|
/** One secret source: a plain object with exact keys `{ kind: "env", name: <environment variable name> }`. */
|
|
133
133
|
function checkSecretSource(value, path, report) {
|
|
134
134
|
if (!isPlainObject(value)) {
|
|
135
|
-
report(path, `must be a secret source, { kind: "env", name }, not ${
|
|
135
|
+
report(path, `must be a secret source, { kind: "env", name }, not ${describeOptionValue(value)}`);
|
|
136
136
|
return undefined;
|
|
137
137
|
}
|
|
138
138
|
const kind = value["kind"];
|
|
139
139
|
if (kind !== "env") {
|
|
140
|
-
report([...path, "kind"], `must be "env", not ${
|
|
140
|
+
report([...path, "kind"], `must be "env", not ${describeOptionValue(kind)}`);
|
|
141
141
|
if (kind !== undefined)
|
|
142
142
|
return undefined;
|
|
143
143
|
}
|
|
@@ -146,13 +146,13 @@ function checkSecretSource(value, path, report) {
|
|
|
146
146
|
ok = false;
|
|
147
147
|
const name = value["name"];
|
|
148
148
|
if (typeof name !== "string" || !ENV_VAR_NAME_PATTERN.test(name)) {
|
|
149
|
-
report([...path, "name"], `must be ${ENV_VAR_NAME_RULE}, not ${
|
|
149
|
+
report([...path, "name"], `must be ${ENV_VAR_NAME_RULE}, not ${describeOptionValue(name)}`);
|
|
150
150
|
ok = false;
|
|
151
151
|
}
|
|
152
152
|
return ok ? { kind: "env", name: name } : undefined;
|
|
153
153
|
}
|
|
154
154
|
/**
|
|
155
|
-
* The
|
|
155
|
+
* The runner's `unsafeSecretEnvVars`: a list of `{ name, source }` plain objects, each exposing a distinct environment
|
|
156
156
|
* variable `name` that neither storm sets for the command (`STORM_RUN`, `RESERVED_UNSAFE_SECRET_ENV_VAR_NAMES`,
|
|
157
157
|
* `LD_*`, `DYLD_*`) nor `runner.env` sets, read from a `SecretSource` that `runner.credentials` doesn't already read.
|
|
158
158
|
*/
|
|
@@ -160,7 +160,7 @@ export function checkUnsafeSecretEnvVars(value, env, credentials, report) {
|
|
|
160
160
|
if (value === undefined)
|
|
161
161
|
return [];
|
|
162
162
|
if (!Array.isArray(value)) {
|
|
163
|
-
report(["unsafeSecretEnvVars"], `must be a list of unsafe secret environment variables, each { name, source }, not ${
|
|
163
|
+
report(["unsafeSecretEnvVars"], `must be a list of unsafe secret environment variables, each { name, source }, not ${describeOptionValue(value)}`);
|
|
164
164
|
return undefined;
|
|
165
165
|
}
|
|
166
166
|
let ok = true;
|
|
@@ -170,7 +170,7 @@ export function checkUnsafeSecretEnvVars(value, env, credentials, report) {
|
|
|
170
170
|
value.forEach((entry, index) => {
|
|
171
171
|
const path = ["unsafeSecretEnvVars", String(index)];
|
|
172
172
|
if (!isPlainObject(entry)) {
|
|
173
|
-
report(path, `must be { name, source }, not ${
|
|
173
|
+
report(path, `must be { name, source }, not ${describeOptionValue(entry)}`);
|
|
174
174
|
ok = false;
|
|
175
175
|
return;
|
|
176
176
|
}
|
|
@@ -178,7 +178,7 @@ export function checkUnsafeSecretEnvVars(value, env, credentials, report) {
|
|
|
178
178
|
const name = entry["name"];
|
|
179
179
|
const namePath = [...path, "name"];
|
|
180
180
|
if (typeof name !== "string" || !ENV_VAR_NAME_PATTERN.test(name)) {
|
|
181
|
-
report(namePath, `must be ${ENV_VAR_NAME_RULE}, not ${
|
|
181
|
+
report(namePath, `must be ${ENV_VAR_NAME_RULE}, not ${describeOptionValue(name)}`);
|
|
182
182
|
entryOk = false;
|
|
183
183
|
}
|
|
184
184
|
else if (name === RUN_PAYLOAD_VARIABLE) {
|