@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
|
@@ -15,52 +15,14 @@ import {
|
|
|
15
15
|
resourceCall,
|
|
16
16
|
secretSourceId,
|
|
17
17
|
tokenRequestFailureFacts,
|
|
18
|
-
tokenRequestFailureShape
|
|
19
|
-
|
|
18
|
+
tokenRequestFailureShape,
|
|
19
|
+
vercelOidcTokenFailureFacts,
|
|
20
|
+
vercelOidcTokenFailureShape
|
|
21
|
+
} from "./chunk-XBDRVFEV.js";
|
|
20
22
|
import {
|
|
21
23
|
defineErrors,
|
|
22
24
|
refused
|
|
23
|
-
} from "./chunk-
|
|
24
|
-
|
|
25
|
-
// src/config/credential-settle.ts
|
|
26
|
-
import { z } from "zod";
|
|
27
|
-
var credentialErrors = defineErrors({
|
|
28
|
-
missingTarget: {
|
|
29
|
-
exitCode: 2,
|
|
30
|
-
description: "The command may mint a credential, and neither a flag nor storm.config.ts names the control plane team or project.",
|
|
31
|
-
schema: z.object({
|
|
32
|
-
/** The settings no flag or config file gave. */
|
|
33
|
-
missing: z.array(z.enum(["scope", "project"]))
|
|
34
|
-
}),
|
|
35
|
-
render: ({ missing }) => ({
|
|
36
|
-
message: `No control plane ${missing.map((key) => key === "scope" ? "team" : "project").join(" or ")} to mint a credential for.`,
|
|
37
|
-
next: [
|
|
38
|
-
{
|
|
39
|
-
type: "text",
|
|
40
|
-
text: `Give ${missing.map((key) => `--${key}`).join(" and ")}, or set ${missing.join(" and ")} in storm.config.ts.`
|
|
41
|
-
}
|
|
42
|
-
]
|
|
43
|
-
})
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
function requireTarget(scope, project) {
|
|
47
|
-
if (scope === void 0 || project === void 0)
|
|
48
|
-
return refused(
|
|
49
|
-
credentialErrors.missingTarget({
|
|
50
|
-
missing: [
|
|
51
|
-
...scope === void 0 ? ["scope"] : [],
|
|
52
|
-
...project === void 0 ? ["project"] : []
|
|
53
|
-
]
|
|
54
|
-
})
|
|
55
|
-
);
|
|
56
|
-
return { ok: true, target: { team: scope.value, project: project.value } };
|
|
57
|
-
}
|
|
58
|
-
function settleCredential(source, scope, project) {
|
|
59
|
-
if (source === "github-actions") return { ok: true, credential: { source } };
|
|
60
|
-
const required = requireTarget(scope, project);
|
|
61
|
-
if (!required.ok) return required;
|
|
62
|
-
return { ok: true, credential: { source, target: required.target } };
|
|
63
|
-
}
|
|
25
|
+
} from "./chunk-4WAMTUWZ.js";
|
|
64
26
|
|
|
65
27
|
// src/runner/base.ts
|
|
66
28
|
async function resolveBase(checkout, request2) {
|
|
@@ -89,17 +51,172 @@ async function resolveBase(checkout, request2) {
|
|
|
89
51
|
}
|
|
90
52
|
return best === void 0 ? { kind: "no-base-ref", refs: refused2 } : { kind: "resolved", ...best };
|
|
91
53
|
}
|
|
92
|
-
|
|
93
|
-
|
|
54
|
+
|
|
55
|
+
// src/runner/context.ts
|
|
56
|
+
function runnerPurpose(runnerName) {
|
|
57
|
+
return `storm-runner-${runnerName}`;
|
|
58
|
+
}
|
|
59
|
+
function runnerTags(runnerName, role, user) {
|
|
60
|
+
return { purpose: runnerPurpose(runnerName), user, role };
|
|
61
|
+
}
|
|
62
|
+
function snapshotIndexTags(runnerName, user, base, expiresAt) {
|
|
94
63
|
return {
|
|
64
|
+
purpose: runnerPurpose(runnerName),
|
|
65
|
+
user,
|
|
66
|
+
role: "snapshot-index",
|
|
95
67
|
base,
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
68
|
+
"expires-at": expiresAt
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// src/runner/local-snapshot-index.ts
|
|
73
|
+
import { createHash } from "node:crypto";
|
|
74
|
+
var RUNNER_SNAPSHOTS_SUBPATH = ["runner", "snapshots"];
|
|
75
|
+
var SNAPSHOT_EXPIRATION_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
76
|
+
var SNAPSHOT_MIN_REMAINING_MS = 60 * 60 * 1e3;
|
|
77
|
+
function snapshotEntryIdentity(entry) {
|
|
78
|
+
return createHash("sha256").update(
|
|
79
|
+
[
|
|
80
|
+
entry.teamId,
|
|
81
|
+
entry.projectId,
|
|
82
|
+
entry.region,
|
|
83
|
+
entry.runtime,
|
|
84
|
+
entry.runnerName,
|
|
85
|
+
entry.snapshotKey,
|
|
86
|
+
entry.base
|
|
87
|
+
].join("\0")
|
|
88
|
+
).digest("hex").slice(0, 32);
|
|
89
|
+
}
|
|
90
|
+
function snapshotEntryFileName(entry) {
|
|
91
|
+
return `${snapshotEntryIdentity(entry)}.json`;
|
|
92
|
+
}
|
|
93
|
+
function isExpiredEntry(entry, now) {
|
|
94
|
+
return Date.parse(entry.expiresAt) <= now.getTime();
|
|
95
|
+
}
|
|
96
|
+
function hasTimeLeft(entry, now) {
|
|
97
|
+
return Date.parse(entry.expiresAt) - now.getTime() > SNAPSHOT_MIN_REMAINING_MS;
|
|
98
|
+
}
|
|
99
|
+
async function removeExpiredEntries(context) {
|
|
100
|
+
const { runnerSnapshots } = context;
|
|
101
|
+
const listed = await runnerSnapshots.listEntries();
|
|
102
|
+
if (!listed.ok) return { entries: [], notes: [{ kind: "local-index-unreadable", failure: listed.failure }] };
|
|
103
|
+
const now = context.clock.now();
|
|
104
|
+
const entries = [];
|
|
105
|
+
const notes = [];
|
|
106
|
+
for (const entry of listed.value.entries) {
|
|
107
|
+
if (!isExpiredEntry(entry, now)) {
|
|
108
|
+
entries.push(entry);
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
const removed = await runnerSnapshots.removeEntry(entry);
|
|
112
|
+
if (!removed.ok) notes.push({ kind: "expired-entry-not-removed", entry, failure: removed.failure });
|
|
113
|
+
}
|
|
114
|
+
return { entries, notes };
|
|
115
|
+
}
|
|
116
|
+
async function resolveAncestorDistances(context, request2) {
|
|
117
|
+
const { checkout, clock } = context;
|
|
118
|
+
const { repoRoot, entries, options, mergeBase } = request2;
|
|
119
|
+
const now = clock.now();
|
|
120
|
+
const seen = /* @__PURE__ */ new Set([mergeBase]);
|
|
121
|
+
const distances = {};
|
|
122
|
+
for (const entry of entries) {
|
|
123
|
+
if (entry.region !== options.region || entry.runtime !== options.runtime || entry.runnerName !== options.name) {
|
|
124
|
+
continue;
|
|
101
125
|
}
|
|
126
|
+
if (isExpiredEntry(entry, now) || !hasTimeLeft(entry, now)) continue;
|
|
127
|
+
if (seen.has(entry.base)) continue;
|
|
128
|
+
seen.add(entry.base);
|
|
129
|
+
const contained = await checkout.contains({ repoRoot, ancestor: entry.base, descendant: mergeBase });
|
|
130
|
+
if (!contained.ok) return contained;
|
|
131
|
+
if (!contained.value) continue;
|
|
132
|
+
const behindMergeBase = await checkout.commitCount({ repoRoot, from: entry.base, to: mergeBase });
|
|
133
|
+
if (!behindMergeBase.ok) return behindMergeBase;
|
|
134
|
+
distances[entry.base] = behindMergeBase.value;
|
|
135
|
+
}
|
|
136
|
+
return { ok: true, value: distances };
|
|
137
|
+
}
|
|
138
|
+
function classifySnapshotEntries(context, request2) {
|
|
139
|
+
const { entries, options, base, snapshotKey: snapshotKey2, commitsAfterBase, ancestorDistances } = request2;
|
|
140
|
+
const now = context.clock.now();
|
|
141
|
+
const candidates = [];
|
|
142
|
+
const rejected = [];
|
|
143
|
+
const verdicts = [];
|
|
144
|
+
const reject = (entry, reason) => {
|
|
145
|
+
const rejection = { entry, reason };
|
|
146
|
+
rejected.push(rejection);
|
|
147
|
+
verdicts.push({ kind: "rejected", entry, rejection });
|
|
102
148
|
};
|
|
149
|
+
for (const entry of entries) {
|
|
150
|
+
if (entry.region !== options.region || entry.runtime !== options.runtime || entry.runnerName !== options.name) {
|
|
151
|
+
verdicts.push({ kind: "other-runner", entry });
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
if (isExpiredEntry(entry, now)) {
|
|
155
|
+
reject(entry, "expired");
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
if (!hasTimeLeft(entry, now)) {
|
|
159
|
+
reject(entry, "expires-soon");
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
const commitsBehindMergeBase = entry.base === base ? 0 : ancestorDistances !== void 0 && Object.hasOwn(ancestorDistances, entry.base) ? ancestorDistances[entry.base] : void 0;
|
|
163
|
+
if (commitsBehindMergeBase === void 0) {
|
|
164
|
+
reject(entry, "other-base");
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
if (entry.snapshotKey !== snapshotKey2) {
|
|
168
|
+
reject(entry, "steps-changed");
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
const candidate = {
|
|
172
|
+
entry,
|
|
173
|
+
builtBehind: commitsAfterBase + commitsBehindMergeBase,
|
|
174
|
+
commitsBehindMergeBase
|
|
175
|
+
};
|
|
176
|
+
candidates.push(candidate);
|
|
177
|
+
verdicts.push({ kind: "candidate", entry, candidate });
|
|
178
|
+
}
|
|
179
|
+
candidates.sort(
|
|
180
|
+
(a, b) => compareSnapshotCandidates(
|
|
181
|
+
{
|
|
182
|
+
commitsBehindMergeBase: a.commitsBehindMergeBase,
|
|
183
|
+
createdAt: a.entry.createdAt,
|
|
184
|
+
tieBreaker: a.entry.snapshotId
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
commitsBehindMergeBase: b.commitsBehindMergeBase,
|
|
188
|
+
createdAt: b.entry.createdAt,
|
|
189
|
+
tieBreaker: b.entry.snapshotId
|
|
190
|
+
}
|
|
191
|
+
)
|
|
192
|
+
);
|
|
193
|
+
return { candidates, rejected, verdicts };
|
|
194
|
+
}
|
|
195
|
+
function parseTimestampMs(iso) {
|
|
196
|
+
const ms = Date.parse(iso);
|
|
197
|
+
return Number.isNaN(ms) ? Number.NEGATIVE_INFINITY : ms;
|
|
198
|
+
}
|
|
199
|
+
function compareSnapshotCandidates(a, b) {
|
|
200
|
+
if (a.commitsBehindMergeBase !== b.commitsBehindMergeBase) {
|
|
201
|
+
return a.commitsBehindMergeBase - b.commitsBehindMergeBase;
|
|
202
|
+
}
|
|
203
|
+
const aCreated = parseTimestampMs(a.createdAt);
|
|
204
|
+
const bCreated = parseTimestampMs(b.createdAt);
|
|
205
|
+
if (aCreated !== bCreated) return bCreated - aCreated;
|
|
206
|
+
return a.tieBreaker < b.tieBreaker ? -1 : a.tieBreaker > b.tieBreaker ? 1 : 0;
|
|
207
|
+
}
|
|
208
|
+
function sharedBeatsLocal(sharedCommitsBehindMergeBase, localCommitsBehindMergeBase) {
|
|
209
|
+
return localCommitsBehindMergeBase === void 0 || sharedCommitsBehindMergeBase < localCommitsBehindMergeBase;
|
|
210
|
+
}
|
|
211
|
+
function snapshotRejections(read, owner) {
|
|
212
|
+
const owned = (entry) => entry.teamId === owner.teamId && entry.projectId === owner.projectId;
|
|
213
|
+
return [
|
|
214
|
+
...read.candidates.map(({ entry }) => ({ entry, reason: "other-owner" })),
|
|
215
|
+
...read.rejected.map(({ entry, reason }) => ({ entry, reason: owned(entry) ? reason : "other-owner" }))
|
|
216
|
+
];
|
|
217
|
+
}
|
|
218
|
+
function pickSnapshot(candidates, owner) {
|
|
219
|
+
return candidates.find(({ entry }) => entry.teamId === owner.teamId && entry.projectId === owner.projectId);
|
|
103
220
|
}
|
|
104
221
|
|
|
105
222
|
// src/runner/time-limit.ts
|
|
@@ -145,9 +262,9 @@ function untilAborted(promise, signal) {
|
|
|
145
262
|
|
|
146
263
|
// src/runner/network-policy.ts
|
|
147
264
|
var NETWORK_POLICY_WRITE_LIMIT_MS = 1e4;
|
|
148
|
-
function runnerNetworkPolicy(
|
|
149
|
-
if (
|
|
150
|
-
return { kind: "custom", allowedDomains: [...
|
|
265
|
+
function runnerNetworkPolicy(options) {
|
|
266
|
+
if (options.allowedDomains === void 0) return { kind: "allow-all", credentials: [] };
|
|
267
|
+
return { kind: "custom", allowedDomains: [...options.allowedDomains], credentials: [] };
|
|
151
268
|
}
|
|
152
269
|
function withCredentials(base, credentials2) {
|
|
153
270
|
return { ...base, credentials: credentials2 };
|
|
@@ -464,9 +581,15 @@ function runnerSandboxScope(context, progress, settings) {
|
|
|
464
581
|
if (!removed.ok)
|
|
465
582
|
return { ok: false, failure: { kind: "credential-not-revoked", failure: removed.failure } };
|
|
466
583
|
}
|
|
467
|
-
const saved = await sandboxes.saveSnapshot(sandbox, request2);
|
|
584
|
+
const saved = await sandboxes.saveSnapshot(sandbox, { expirationMs: request2.expirationMs });
|
|
468
585
|
const now = currentPhase();
|
|
469
|
-
if (saved.ok
|
|
586
|
+
if (saved.ok) {
|
|
587
|
+
if (request2.keepStopped === true) {
|
|
588
|
+
if (now.kind === "open") now.sandboxes.delete(sandbox);
|
|
589
|
+
} else if (now.kind !== "closing" && now.sandboxes.delete(sandbox)) {
|
|
590
|
+
await deleteSandbox(sandbox);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
470
593
|
return saved;
|
|
471
594
|
})()
|
|
472
595
|
),
|
|
@@ -500,97 +623,6 @@ function callFailureMessage(answer, limitMs) {
|
|
|
500
623
|
return answer === null ? `no answer within ${limitMs / 1e3} seconds` : failureMessage(answer.failure);
|
|
501
624
|
}
|
|
502
625
|
|
|
503
|
-
// src/runner/context.ts
|
|
504
|
-
function runnerPurpose(recipeName) {
|
|
505
|
-
return `storm-runner-${recipeName}`;
|
|
506
|
-
}
|
|
507
|
-
function runnerTags(recipeName, role, user) {
|
|
508
|
-
return { purpose: runnerPurpose(recipeName), user, role };
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
// src/runner/snapshot-cache.ts
|
|
512
|
-
import { createHash } from "node:crypto";
|
|
513
|
-
var RUNNER_SNAPSHOTS_SUBPATH = ["runner", "snapshots"];
|
|
514
|
-
var SNAPSHOT_EXPIRATION_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
515
|
-
var SNAPSHOT_MIN_REMAINING_MS = 60 * 60 * 1e3;
|
|
516
|
-
function snapshotEntryIdentity(entry) {
|
|
517
|
-
return createHash("sha256").update(
|
|
518
|
-
[
|
|
519
|
-
entry.teamId,
|
|
520
|
-
entry.projectId,
|
|
521
|
-
entry.region,
|
|
522
|
-
entry.runtime,
|
|
523
|
-
entry.recipeName,
|
|
524
|
-
entry.snapshotKey,
|
|
525
|
-
entry.base
|
|
526
|
-
].join("\0")
|
|
527
|
-
).digest("hex").slice(0, 32);
|
|
528
|
-
}
|
|
529
|
-
function snapshotEntryFileName(entry) {
|
|
530
|
-
return `${snapshotEntryIdentity(entry)}.json`;
|
|
531
|
-
}
|
|
532
|
-
function isExpiredEntry(entry, now) {
|
|
533
|
-
return Date.parse(entry.expiresAt) <= now.getTime();
|
|
534
|
-
}
|
|
535
|
-
function hasTimeLeft(entry, now) {
|
|
536
|
-
return Date.parse(entry.expiresAt) - now.getTime() > SNAPSHOT_MIN_REMAINING_MS;
|
|
537
|
-
}
|
|
538
|
-
async function removeExpiredEntries(context) {
|
|
539
|
-
const { runnerSnapshots } = context;
|
|
540
|
-
const listed = await runnerSnapshots.listEntries();
|
|
541
|
-
if (!listed.ok) return { entries: [], notes: [{ kind: "cache-unreadable", failure: listed.failure }] };
|
|
542
|
-
const now = context.clock.now();
|
|
543
|
-
const entries = [];
|
|
544
|
-
const notes = [];
|
|
545
|
-
for (const entry of listed.value.entries) {
|
|
546
|
-
if (!isExpiredEntry(entry, now)) {
|
|
547
|
-
entries.push(entry);
|
|
548
|
-
continue;
|
|
549
|
-
}
|
|
550
|
-
const removed = await runnerSnapshots.removeEntry(entry);
|
|
551
|
-
if (!removed.ok) notes.push({ kind: "expired-entry-not-removed", entry, failure: removed.failure });
|
|
552
|
-
}
|
|
553
|
-
return { entries, notes };
|
|
554
|
-
}
|
|
555
|
-
function classifySnapshotEntries(context, request2) {
|
|
556
|
-
const { entries, recipe, base, snapshotKey: snapshotKey2, commitsAfterBase } = request2;
|
|
557
|
-
const now = context.clock.now();
|
|
558
|
-
const candidates = [];
|
|
559
|
-
const rejected = [];
|
|
560
|
-
const verdicts = [];
|
|
561
|
-
const reject = (entry, reason) => {
|
|
562
|
-
const rejection = { entry, reason };
|
|
563
|
-
rejected.push(rejection);
|
|
564
|
-
verdicts.push({ kind: "rejected", entry, rejection });
|
|
565
|
-
};
|
|
566
|
-
for (const entry of entries) {
|
|
567
|
-
if (entry.region !== recipe.region || entry.runtime !== recipe.runtime || entry.recipeName !== recipe.name) {
|
|
568
|
-
verdicts.push({ kind: "other-recipe", entry });
|
|
569
|
-
continue;
|
|
570
|
-
}
|
|
571
|
-
if (isExpiredEntry(entry, now)) reject(entry, "expired");
|
|
572
|
-
else if (!hasTimeLeft(entry, now)) reject(entry, "expires-soon");
|
|
573
|
-
else if (entry.base !== base) reject(entry, "other-base");
|
|
574
|
-
else if (entry.snapshotKey !== snapshotKey2) reject(entry, "steps-changed");
|
|
575
|
-
else {
|
|
576
|
-
const candidate = { entry, builtBehind: commitsAfterBase };
|
|
577
|
-
candidates.push(candidate);
|
|
578
|
-
verdicts.push({ kind: "candidate", entry, candidate });
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
return { candidates, rejected, verdicts };
|
|
582
|
-
}
|
|
583
|
-
function snapshotRejections(read, owner) {
|
|
584
|
-
const owned = (entry) => entry.teamId === owner.teamId && entry.projectId === owner.projectId;
|
|
585
|
-
return [
|
|
586
|
-
...read.candidates.map(({ entry }) => ({ entry, reason: "other-owner" })),
|
|
587
|
-
...read.rejected.map(({ entry, reason }) => ({ entry, reason: owned(entry) ? reason : "other-owner" }))
|
|
588
|
-
];
|
|
589
|
-
}
|
|
590
|
-
function pickSnapshot(candidates, owner) {
|
|
591
|
-
return candidates.find(({ entry }) => entry.teamId === owner.teamId && entry.projectId === owner.projectId);
|
|
592
|
-
}
|
|
593
|
-
|
|
594
626
|
// src/runner/snapshot-key.ts
|
|
595
627
|
import { createHash as createHash2 } from "node:crypto";
|
|
596
628
|
|
|
@@ -635,67 +667,67 @@ var systemClock = {
|
|
|
635
667
|
};
|
|
636
668
|
|
|
637
669
|
// src/sdk/run/payload.ts
|
|
638
|
-
import { z
|
|
670
|
+
import { z } from "zod";
|
|
639
671
|
var RUN_PAYLOAD_VARIABLE = "STORM_RUN";
|
|
640
672
|
var RUN_PAYLOAD_VERSION = 3;
|
|
641
|
-
var runPayloadSandboxSchema =
|
|
642
|
-
index:
|
|
643
|
-
count:
|
|
644
|
-
files:
|
|
673
|
+
var runPayloadSandboxSchema = z.object({
|
|
674
|
+
index: z.number().int().nonnegative(),
|
|
675
|
+
count: z.number().int().positive(),
|
|
676
|
+
files: z.array(z.string().min(1)).optional()
|
|
645
677
|
});
|
|
646
|
-
var runPayloadSchema =
|
|
647
|
-
version:
|
|
648
|
-
resources:
|
|
649
|
-
testEvents:
|
|
650
|
-
verbose:
|
|
678
|
+
var runPayloadSchema = z.object({
|
|
679
|
+
version: z.literal(RUN_PAYLOAD_VERSION),
|
|
680
|
+
resources: z.record(z.string(), z.object({ definition: z.string().min(1), payload: z.unknown() })),
|
|
681
|
+
testEvents: z.string().min(1).optional(),
|
|
682
|
+
verbose: z.literal(true).optional(),
|
|
651
683
|
sandbox: runPayloadSandboxSchema.optional()
|
|
652
684
|
});
|
|
653
685
|
|
|
654
686
|
// src/sdk/run/test-events.ts
|
|
655
|
-
import { z as
|
|
656
|
-
var where = { file:
|
|
657
|
-
var fileWhere = { file:
|
|
658
|
-
var attempt = { id:
|
|
659
|
-
var setup = { label:
|
|
660
|
-
var state =
|
|
661
|
-
var testEventSchema =
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
kind:
|
|
687
|
+
import { z as z2 } from "zod";
|
|
688
|
+
var where = { file: z2.string(), worker: z2.number().int().nonnegative(), at: z2.number() };
|
|
689
|
+
var fileWhere = { file: z2.string(), worker: z2.number().int().nonnegative().exactOptional(), at: z2.number() };
|
|
690
|
+
var attempt = { id: z2.string().min(1), test: z2.string() };
|
|
691
|
+
var setup = { label: z2.string().min(1), resource: z2.string().min(1) };
|
|
692
|
+
var state = z2.enum(["pass", "fail", "skip"]);
|
|
693
|
+
var testEventSchema = z2.discriminatedUnion("kind", [
|
|
694
|
+
z2.object({ kind: z2.literal("file-started"), ...fileWhere }),
|
|
695
|
+
z2.object({ kind: z2.literal("file-finished"), ...fileWhere }),
|
|
696
|
+
z2.object({ kind: z2.literal("test-started"), ...where, ...attempt, fileTests: z2.number().int().nonnegative() }),
|
|
697
|
+
z2.object({
|
|
698
|
+
kind: z2.literal("test-attempt-finished"),
|
|
667
699
|
...where,
|
|
668
700
|
...attempt,
|
|
669
701
|
state,
|
|
670
|
-
ms:
|
|
702
|
+
ms: z2.number().nonnegative()
|
|
671
703
|
}),
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
kind:
|
|
704
|
+
z2.object({ kind: z2.literal("setup-started"), ...where, ...setup }),
|
|
705
|
+
z2.object({
|
|
706
|
+
kind: z2.literal("setup-finished"),
|
|
675
707
|
...where,
|
|
676
708
|
...setup,
|
|
677
|
-
ms:
|
|
678
|
-
ok:
|
|
679
|
-
warmupMs:
|
|
709
|
+
ms: z2.number().nonnegative(),
|
|
710
|
+
ok: z2.boolean(),
|
|
711
|
+
warmupMs: z2.number().nonnegative().exactOptional()
|
|
680
712
|
}),
|
|
681
|
-
|
|
682
|
-
kind:
|
|
683
|
-
id:
|
|
684
|
-
file:
|
|
685
|
-
test:
|
|
713
|
+
z2.object({
|
|
714
|
+
kind: z2.literal("test-result"),
|
|
715
|
+
id: z2.string().min(1),
|
|
716
|
+
file: z2.string(),
|
|
717
|
+
test: z2.string(),
|
|
686
718
|
state,
|
|
687
|
-
retryCount:
|
|
688
|
-
flaky:
|
|
689
|
-
at:
|
|
690
|
-
errors:
|
|
691
|
-
|
|
692
|
-
name:
|
|
693
|
-
message:
|
|
694
|
-
stack:
|
|
695
|
-
diff:
|
|
719
|
+
retryCount: z2.number().int().nonnegative(),
|
|
720
|
+
flaky: z2.boolean(),
|
|
721
|
+
at: z2.number(),
|
|
722
|
+
errors: z2.array(
|
|
723
|
+
z2.object({
|
|
724
|
+
name: z2.string(),
|
|
725
|
+
message: z2.string(),
|
|
726
|
+
stack: z2.string().exactOptional(),
|
|
727
|
+
diff: z2.string().exactOptional()
|
|
696
728
|
})
|
|
697
729
|
).exactOptional(),
|
|
698
|
-
output:
|
|
730
|
+
output: z2.object({ text: z2.string(), droppedChars: z2.number().int().nonnegative() }).exactOptional()
|
|
699
731
|
})
|
|
700
732
|
]);
|
|
701
733
|
function testEventLine(event) {
|
|
@@ -719,7 +751,7 @@ function redactSecrets(text, secrets) {
|
|
|
719
751
|
return ordered.reduce((redacted, secret) => redacted.split(secret).join(REDACTED), text);
|
|
720
752
|
}
|
|
721
753
|
|
|
722
|
-
// src/runner/
|
|
754
|
+
// src/runner/vercel-sandbox-check.ts
|
|
723
755
|
function reportUnknownKeys(value, known, path, what, report) {
|
|
724
756
|
let ok = true;
|
|
725
757
|
for (const key of Object.keys(value))
|
|
@@ -729,7 +761,7 @@ function reportUnknownKeys(value, known, path, what, report) {
|
|
|
729
761
|
}
|
|
730
762
|
return ok;
|
|
731
763
|
}
|
|
732
|
-
function
|
|
764
|
+
function describeOptionValue(value) {
|
|
733
765
|
if (typeof value === "string") return JSON.stringify(value);
|
|
734
766
|
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
735
767
|
if (value === null) return "null";
|
|
@@ -740,7 +772,7 @@ function describeRecipeValue(value) {
|
|
|
740
772
|
return `a ${typeof value}`;
|
|
741
773
|
}
|
|
742
774
|
|
|
743
|
-
// src/runner/
|
|
775
|
+
// src/runner/vercel-sandbox-secrets.ts
|
|
744
776
|
var CREDENTIAL_KEYS = /* @__PURE__ */ new Set(["domain", "header", "source", "requests"]);
|
|
745
777
|
var UNSAFE_SECRET_ENV_VAR_KEYS = /* @__PURE__ */ new Set(["name", "source"]);
|
|
746
778
|
var ENV_SOURCE_KEYS = /* @__PURE__ */ new Set(["kind", "name"]);
|
|
@@ -765,15 +797,15 @@ var RESERVED_UNSAFE_SECRET_ENV_VAR_NAMES = /* @__PURE__ */ new Set([
|
|
|
765
797
|
"NO_COLOR"
|
|
766
798
|
]);
|
|
767
799
|
var RESERVED_UNSAFE_SECRET_ENV_VAR_PREFIXES = ["LD_", "DYLD_"];
|
|
768
|
-
function credentialSourceIds(
|
|
769
|
-
return [...new Set(
|
|
800
|
+
function credentialSourceIds(options) {
|
|
801
|
+
return [...new Set(options.credentials.map(({ source }) => secretSourceId(source)))].toSorted();
|
|
770
802
|
}
|
|
771
803
|
function checkCredentials(value, report) {
|
|
772
804
|
if (value === void 0) return [];
|
|
773
805
|
if (!Array.isArray(value)) {
|
|
774
806
|
report(
|
|
775
807
|
["credentials"],
|
|
776
|
-
`must be a list of credentials, each { domain, header?, source, requests? }, not ${
|
|
808
|
+
`must be a list of credentials, each { domain, header?, source, requests? }, not ${describeOptionValue(value)}`
|
|
777
809
|
);
|
|
778
810
|
return void 0;
|
|
779
811
|
}
|
|
@@ -812,7 +844,7 @@ function checkCredentials(value, report) {
|
|
|
812
844
|
}
|
|
813
845
|
function checkCredential(value, path, report) {
|
|
814
846
|
if (!isPlainObject(value)) {
|
|
815
|
-
report(path, `must be { domain, header?, source, requests? }, not ${
|
|
847
|
+
report(path, `must be { domain, header?, source, requests? }, not ${describeOptionValue(value)}`);
|
|
816
848
|
return void 0;
|
|
817
849
|
}
|
|
818
850
|
let ok = reportUnknownKeys(value, CREDENTIAL_KEYS, path, "a credential key", report);
|
|
@@ -820,7 +852,7 @@ function checkCredential(value, path, report) {
|
|
|
820
852
|
if (typeof domain !== "string" || !HOST_PATTERN.test(domain)) {
|
|
821
853
|
report(
|
|
822
854
|
[...path, "domain"],
|
|
823
|
-
`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 ${
|
|
855
|
+
`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)}`
|
|
824
856
|
);
|
|
825
857
|
ok = false;
|
|
826
858
|
}
|
|
@@ -828,7 +860,7 @@ function checkCredential(value, path, report) {
|
|
|
828
860
|
if (typeof header !== "string" || !HEADER_PATTERN.test(header)) {
|
|
829
861
|
report(
|
|
830
862
|
[...path, "header"],
|
|
831
|
-
`must be an HTTP header name, such as authorization, not ${
|
|
863
|
+
`must be an HTTP header name, such as authorization, not ${describeOptionValue(header)}`
|
|
832
864
|
);
|
|
833
865
|
ok = false;
|
|
834
866
|
} else if (REFUSED_HEADERS.has(header.toLowerCase())) {
|
|
@@ -839,7 +871,7 @@ function checkCredential(value, path, report) {
|
|
|
839
871
|
if (source === void 0) ok = false;
|
|
840
872
|
const requests = value["requests"] === void 0 ? "read" : value["requests"];
|
|
841
873
|
if (requests !== "read" && requests !== "all") {
|
|
842
|
-
report([...path, "requests"], `must be "read" or "all", not ${
|
|
874
|
+
report([...path, "requests"], `must be "read" or "all", not ${describeOptionValue(requests)}`);
|
|
843
875
|
ok = false;
|
|
844
876
|
}
|
|
845
877
|
return ok && source !== void 0 ? {
|
|
@@ -851,19 +883,19 @@ function checkCredential(value, path, report) {
|
|
|
851
883
|
}
|
|
852
884
|
function checkSecretSource(value, path, report) {
|
|
853
885
|
if (!isPlainObject(value)) {
|
|
854
|
-
report(path, `must be a secret source, { kind: "env", name }, not ${
|
|
886
|
+
report(path, `must be a secret source, { kind: "env", name }, not ${describeOptionValue(value)}`);
|
|
855
887
|
return void 0;
|
|
856
888
|
}
|
|
857
889
|
const kind2 = value["kind"];
|
|
858
890
|
if (kind2 !== "env") {
|
|
859
|
-
report([...path, "kind"], `must be "env", not ${
|
|
891
|
+
report([...path, "kind"], `must be "env", not ${describeOptionValue(kind2)}`);
|
|
860
892
|
if (kind2 !== void 0) return void 0;
|
|
861
893
|
}
|
|
862
894
|
let ok = kind2 === "env";
|
|
863
895
|
if (!reportUnknownKeys(value, ENV_SOURCE_KEYS, path, "a secret source key", report)) ok = false;
|
|
864
896
|
const name = value["name"];
|
|
865
897
|
if (typeof name !== "string" || !ENV_VAR_NAME_PATTERN.test(name)) {
|
|
866
|
-
report([...path, "name"], `must be ${ENV_VAR_NAME_RULE}, not ${
|
|
898
|
+
report([...path, "name"], `must be ${ENV_VAR_NAME_RULE}, not ${describeOptionValue(name)}`);
|
|
867
899
|
ok = false;
|
|
868
900
|
}
|
|
869
901
|
return ok ? { kind: "env", name } : void 0;
|
|
@@ -873,7 +905,7 @@ function checkUnsafeSecretEnvVars(value, env, credentials2, report) {
|
|
|
873
905
|
if (!Array.isArray(value)) {
|
|
874
906
|
report(
|
|
875
907
|
["unsafeSecretEnvVars"],
|
|
876
|
-
`must be a list of unsafe secret environment variables, each { name, source }, not ${
|
|
908
|
+
`must be a list of unsafe secret environment variables, each { name, source }, not ${describeOptionValue(value)}`
|
|
877
909
|
);
|
|
878
910
|
return void 0;
|
|
879
911
|
}
|
|
@@ -884,7 +916,7 @@ function checkUnsafeSecretEnvVars(value, env, credentials2, report) {
|
|
|
884
916
|
value.forEach((entry, index) => {
|
|
885
917
|
const path = ["unsafeSecretEnvVars", String(index)];
|
|
886
918
|
if (!isPlainObject(entry)) {
|
|
887
|
-
report(path, `must be { name, source }, not ${
|
|
919
|
+
report(path, `must be { name, source }, not ${describeOptionValue(entry)}`);
|
|
888
920
|
ok = false;
|
|
889
921
|
return;
|
|
890
922
|
}
|
|
@@ -898,7 +930,7 @@ function checkUnsafeSecretEnvVars(value, env, credentials2, report) {
|
|
|
898
930
|
const name = entry["name"];
|
|
899
931
|
const namePath = [...path, "name"];
|
|
900
932
|
if (typeof name !== "string" || !ENV_VAR_NAME_PATTERN.test(name)) {
|
|
901
|
-
report(namePath, `must be ${ENV_VAR_NAME_RULE}, not ${
|
|
933
|
+
report(namePath, `must be ${ENV_VAR_NAME_RULE}, not ${describeOptionValue(name)}`);
|
|
902
934
|
entryOk = false;
|
|
903
935
|
} else if (name === RUN_PAYLOAD_VARIABLE) {
|
|
904
936
|
report(namePath, `can't be ${name}: storm sets it for the command`);
|
|
@@ -941,16 +973,16 @@ function isPlainObject(value) {
|
|
|
941
973
|
return proto === Object.prototype || proto === null;
|
|
942
974
|
}
|
|
943
975
|
|
|
944
|
-
// src/runner/
|
|
976
|
+
// src/runner/vercel-sandbox-options.ts
|
|
945
977
|
var MAX_RUNNER_SANDBOXES = 32;
|
|
946
|
-
var
|
|
978
|
+
var VERCEL_SANDBOX_DEFAULTS = {
|
|
947
979
|
cwd: ".",
|
|
948
980
|
timeout: "60m",
|
|
949
981
|
baseRefs: ["main", "origin/main"],
|
|
950
982
|
region: "iad1",
|
|
951
983
|
runtime: "node22"
|
|
952
984
|
};
|
|
953
|
-
var
|
|
985
|
+
var VERCEL_SANDBOX_OPTION_KEYS = /* @__PURE__ */ new Set([
|
|
954
986
|
"name",
|
|
955
987
|
"snapshot",
|
|
956
988
|
"run",
|
|
@@ -968,50 +1000,51 @@ var RECIPE_KEYS = /* @__PURE__ */ new Set([
|
|
|
968
1000
|
"sandboxes"
|
|
969
1001
|
]);
|
|
970
1002
|
var SANDBOXES_KEYS = /* @__PURE__ */ new Set(["max", "default"]);
|
|
1003
|
+
var SANDBOXES_DEFAULT_RULE_KEYS = /* @__PURE__ */ new Set(["filesPerSandbox", "max"]);
|
|
1004
|
+
var VCPUS_RULE_KEYS = /* @__PURE__ */ new Set(["resource", "option", "per", "min", "max"]);
|
|
971
1005
|
var SNAPSHOT_KEYS = /* @__PURE__ */ new Set(["vcpus", "summary", "toolchains", "prebuild"]);
|
|
972
1006
|
var RUN_KEYS = /* @__PURE__ */ new Set(["install", "build"]);
|
|
973
1007
|
var STEP_KEYS = /* @__PURE__ */ new Set(["label", "script"]);
|
|
1008
|
+
var TOOLCHAIN_STEP_KEYS = /* @__PURE__ */ new Set(["label", "script", "baseFiles"]);
|
|
974
1009
|
var NAME_PATTERN = /^[a-z0-9][a-z0-9-]*$/;
|
|
975
1010
|
var ALLOWED_DOMAIN_PATTERN = /^(?:\*\.)?(?=.{1,253}$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+$/;
|
|
976
|
-
function
|
|
1011
|
+
function checkVercelSandboxOptions(value) {
|
|
977
1012
|
const problems = [];
|
|
978
1013
|
const report = (path, problem) => problems.push({ path, problem });
|
|
979
1014
|
if (!isRecord(value)) {
|
|
980
|
-
report([], `must be an object, not ${
|
|
1015
|
+
report([], `must be an object, not ${describeOptionValue(value)}`);
|
|
981
1016
|
return { ok: false, problems };
|
|
982
1017
|
}
|
|
983
|
-
reportUnknownKeys(value,
|
|
1018
|
+
reportUnknownKeys(value, VERCEL_SANDBOX_OPTION_KEYS, [], "a vercelSandbox option key", report);
|
|
984
1019
|
const name = value["name"];
|
|
985
1020
|
if (typeof name !== "string" || !NAME_PATTERN.test(name))
|
|
986
1021
|
report(
|
|
987
1022
|
["name"],
|
|
988
|
-
`must be lowercase letters, digits and dashes, starting with a letter or digit, not ${
|
|
1023
|
+
`must be lowercase letters, digits and dashes, starting with a letter or digit, not ${describeOptionValue(name)}`
|
|
989
1024
|
);
|
|
990
1025
|
const snapshot = checkSnapshot(value["snapshot"], report);
|
|
991
1026
|
const run = checkRun(value["run"], report);
|
|
992
|
-
const cwd = orDefault(value["cwd"],
|
|
1027
|
+
const cwd = orDefault(value["cwd"], VERCEL_SANDBOX_DEFAULTS.cwd);
|
|
993
1028
|
if (!isRelativePath(cwd))
|
|
994
|
-
report(["cwd"], `must be a path relative to the repository's root, without "..", not ${
|
|
995
|
-
const vcpus = value["vcpus"];
|
|
996
|
-
if (typeof vcpus !== "function" && !isPositiveInteger(vcpus))
|
|
997
|
-
report(["vcpus"], `must be a positive whole number, or a function of the run, not ${describeRecipeValue(vcpus)}`);
|
|
1029
|
+
report(["cwd"], `must be a path relative to the repository's root, without "..", not ${describeOptionValue(cwd)}`);
|
|
1030
|
+
const vcpus = checkVcpus(value["vcpus"], report);
|
|
998
1031
|
const env = checkEnv(value["env"], report);
|
|
999
1032
|
const credentials2 = checkCredentials(value["credentials"], report);
|
|
1000
1033
|
const unsafeSecretEnvVars = checkUnsafeSecretEnvVars(value["unsafeSecretEnvVars"], env, credentials2, report);
|
|
1001
1034
|
const allowedDomains = checkAllowedDomains(value["allowedDomains"], report);
|
|
1002
|
-
const timeout = orDefault(value["timeout"],
|
|
1035
|
+
const timeout = orDefault(value["timeout"], VERCEL_SANDBOX_DEFAULTS.timeout);
|
|
1003
1036
|
const timeoutMinutes = typeof timeout === "string" ? parseTtl(timeout) : void 0;
|
|
1004
1037
|
if (timeoutMinutes === void 0)
|
|
1005
1038
|
report(
|
|
1006
1039
|
["timeout"],
|
|
1007
|
-
`must be a whole number of minutes or hours from 10m to 5h, not ${
|
|
1040
|
+
`must be a whole number of minutes or hours from 10m to 5h, not ${describeOptionValue(timeout)}`
|
|
1008
1041
|
);
|
|
1009
1042
|
const keepSandbox = value["keepSandbox"];
|
|
1010
1043
|
const keepSandboxMinutes = typeof keepSandbox === "string" ? parseKeepTime(keepSandbox) : void 0;
|
|
1011
1044
|
if (keepSandbox !== void 0 && keepSandboxMinutes === void 0)
|
|
1012
1045
|
report(
|
|
1013
1046
|
["keepSandbox"],
|
|
1014
|
-
`must be 0, or a whole number of minutes or hours up to 5h, not ${
|
|
1047
|
+
`must be 0, or a whole number of minutes or hours up to 5h, not ${describeOptionValue(keepSandbox)}`
|
|
1015
1048
|
);
|
|
1016
1049
|
else if (unsafeSecretEnvVars !== void 0 && unsafeSecretEnvVars.length > 0 && keepSandboxMinutes !== void 0 && keepSandboxMinutes > 0)
|
|
1017
1050
|
report(
|
|
@@ -1019,13 +1052,13 @@ function checkRecipe(value) {
|
|
|
1019
1052
|
"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"
|
|
1020
1053
|
);
|
|
1021
1054
|
const baseRefs = checkBaseRefs(value["baseRefs"], report);
|
|
1022
|
-
const region = orDefault(value["region"],
|
|
1023
|
-
if (!isNonEmptyString(region)) report(["region"], `must be a non-empty string, not ${
|
|
1024
|
-
const runtime = orDefault(value["runtime"],
|
|
1055
|
+
const region = orDefault(value["region"], VERCEL_SANDBOX_DEFAULTS.region);
|
|
1056
|
+
if (!isNonEmptyString(region)) report(["region"], `must be a non-empty string, not ${describeOptionValue(region)}`);
|
|
1057
|
+
const runtime = orDefault(value["runtime"], VERCEL_SANDBOX_DEFAULTS.runtime);
|
|
1025
1058
|
if (!isNonEmptyString(runtime))
|
|
1026
|
-
report(["runtime"], `must be a non-empty string, not ${
|
|
1059
|
+
report(["runtime"], `must be a non-empty string, not ${describeOptionValue(runtime)}`);
|
|
1027
1060
|
const sandboxes = checkSandboxes(value["sandboxes"], report);
|
|
1028
|
-
if (problems.length > 0 || snapshot === void 0 || run === void 0 || env === void 0 || credentials2 === void 0 || unsafeSecretEnvVars === void 0 || allowedDomains === null || baseRefs === void 0 || timeoutMinutes === void 0 || sandboxes === false)
|
|
1061
|
+
if (problems.length > 0 || snapshot === void 0 || run === void 0 || vcpus === void 0 || env === void 0 || credentials2 === void 0 || unsafeSecretEnvVars === void 0 || allowedDomains === null || baseRefs === void 0 || timeoutMinutes === void 0 || sandboxes === false)
|
|
1029
1062
|
return { ok: false, problems };
|
|
1030
1063
|
return {
|
|
1031
1064
|
ok: true,
|
|
@@ -1049,56 +1082,150 @@ function checkRecipe(value) {
|
|
|
1049
1082
|
}
|
|
1050
1083
|
};
|
|
1051
1084
|
}
|
|
1085
|
+
function checkVcpus(value, report) {
|
|
1086
|
+
if (isPositiveInteger(value)) return value;
|
|
1087
|
+
if (typeof value === "function") {
|
|
1088
|
+
report(["vcpus"], "can't be a function: use a positive whole number, or { resource, option, per, min, max }");
|
|
1089
|
+
return void 0;
|
|
1090
|
+
}
|
|
1091
|
+
if (!isRecord(value)) {
|
|
1092
|
+
report(
|
|
1093
|
+
["vcpus"],
|
|
1094
|
+
`must be a positive whole number, or { resource, option, per, min, max }, not ${describeOptionValue(value)}`
|
|
1095
|
+
);
|
|
1096
|
+
return void 0;
|
|
1097
|
+
}
|
|
1098
|
+
let ok = reportUnknownKeys(value, VCPUS_RULE_KEYS, ["vcpus"], "a vercelSandbox vcpus rule key", report);
|
|
1099
|
+
const resource = value["resource"];
|
|
1100
|
+
if (!isNonEmptyString(resource)) {
|
|
1101
|
+
report(["vcpus", "resource"], `must be a non-empty string, not ${describeOptionValue(resource)}`);
|
|
1102
|
+
ok = false;
|
|
1103
|
+
}
|
|
1104
|
+
const option = value["option"];
|
|
1105
|
+
if (!isNonEmptyString(option)) {
|
|
1106
|
+
report(["vcpus", "option"], `must be a non-empty string, not ${describeOptionValue(option)}`);
|
|
1107
|
+
ok = false;
|
|
1108
|
+
}
|
|
1109
|
+
const per = value["per"];
|
|
1110
|
+
if (!isPositiveInteger(per)) {
|
|
1111
|
+
report(["vcpus", "per"], `must be a positive whole number, not ${describeOptionValue(per)}`);
|
|
1112
|
+
ok = false;
|
|
1113
|
+
}
|
|
1114
|
+
const min = value["min"];
|
|
1115
|
+
if (!isPositiveInteger(min)) {
|
|
1116
|
+
report(["vcpus", "min"], `must be a positive whole number, not ${describeOptionValue(min)}`);
|
|
1117
|
+
ok = false;
|
|
1118
|
+
}
|
|
1119
|
+
const max = value["max"];
|
|
1120
|
+
if (!isPositiveInteger(max)) {
|
|
1121
|
+
report(["vcpus", "max"], `must be a positive whole number, not ${describeOptionValue(max)}`);
|
|
1122
|
+
ok = false;
|
|
1123
|
+
} else if (isPositiveInteger(min) && max < min) {
|
|
1124
|
+
report(["vcpus", "max"], `must be at least vcpus.min (${min}), not ${max}`);
|
|
1125
|
+
ok = false;
|
|
1126
|
+
}
|
|
1127
|
+
return ok ? {
|
|
1128
|
+
resource,
|
|
1129
|
+
option,
|
|
1130
|
+
per,
|
|
1131
|
+
min,
|
|
1132
|
+
max
|
|
1133
|
+
} : void 0;
|
|
1134
|
+
}
|
|
1052
1135
|
function checkSandboxes(value, report) {
|
|
1053
1136
|
if (value === void 0) return void 0;
|
|
1054
1137
|
if (!isRecord(value)) {
|
|
1055
|
-
report(["sandboxes"], `must be an object with max, not ${
|
|
1138
|
+
report(["sandboxes"], `must be an object with max, not ${describeOptionValue(value)}`);
|
|
1056
1139
|
return false;
|
|
1057
1140
|
}
|
|
1058
|
-
let ok = reportUnknownKeys(value, SANDBOXES_KEYS, ["sandboxes"], "a
|
|
1141
|
+
let ok = reportUnknownKeys(value, SANDBOXES_KEYS, ["sandboxes"], "a vercelSandbox sandboxes key", report);
|
|
1059
1142
|
const max = value["max"];
|
|
1060
1143
|
if (!isPositiveInteger(max) || max > MAX_RUNNER_SANDBOXES) {
|
|
1061
1144
|
report(
|
|
1062
1145
|
["sandboxes", "max"],
|
|
1063
|
-
`must be a whole number from 1 to ${MAX_RUNNER_SANDBOXES}, not ${
|
|
1146
|
+
`must be a whole number from 1 to ${MAX_RUNNER_SANDBOXES}, not ${describeOptionValue(max)}`
|
|
1064
1147
|
);
|
|
1065
1148
|
ok = false;
|
|
1066
1149
|
}
|
|
1067
|
-
const
|
|
1068
|
-
|
|
1150
|
+
const rawDefault = value["default"];
|
|
1151
|
+
let sandboxesDefault;
|
|
1152
|
+
if (rawDefault !== void 0) {
|
|
1153
|
+
const checkedDefault = checkSandboxesDefault(rawDefault, report);
|
|
1154
|
+
if (checkedDefault === void 0) ok = false;
|
|
1155
|
+
else sandboxesDefault = checkedDefault;
|
|
1156
|
+
}
|
|
1157
|
+
if (!ok) return false;
|
|
1158
|
+
return {
|
|
1159
|
+
max,
|
|
1160
|
+
...sandboxesDefault === void 0 ? {} : { default: sandboxesDefault }
|
|
1161
|
+
};
|
|
1162
|
+
}
|
|
1163
|
+
function checkSandboxesDefault(value, report) {
|
|
1164
|
+
if (isPositiveInteger(value) && value <= MAX_RUNNER_SANDBOXES) return value;
|
|
1165
|
+
if (typeof value === "function") {
|
|
1069
1166
|
report(
|
|
1070
1167
|
["sandboxes", "default"],
|
|
1071
|
-
`
|
|
1168
|
+
`can't be a function: use a whole number from 1 to ${MAX_RUNNER_SANDBOXES}, or { filesPerSandbox, max? }`
|
|
1169
|
+
);
|
|
1170
|
+
return void 0;
|
|
1171
|
+
}
|
|
1172
|
+
if (!isRecord(value)) {
|
|
1173
|
+
report(
|
|
1174
|
+
["sandboxes", "default"],
|
|
1175
|
+
`must be a whole number from 1 to ${MAX_RUNNER_SANDBOXES}, or { filesPerSandbox, max? }, not ${describeOptionValue(value)}`
|
|
1176
|
+
);
|
|
1177
|
+
return void 0;
|
|
1178
|
+
}
|
|
1179
|
+
let ok = reportUnknownKeys(
|
|
1180
|
+
value,
|
|
1181
|
+
SANDBOXES_DEFAULT_RULE_KEYS,
|
|
1182
|
+
["sandboxes", "default"],
|
|
1183
|
+
"a vercelSandbox sandboxes default rule key",
|
|
1184
|
+
report
|
|
1185
|
+
);
|
|
1186
|
+
const filesPerSandbox = value["filesPerSandbox"];
|
|
1187
|
+
if (!isPositiveInteger(filesPerSandbox)) {
|
|
1188
|
+
report(
|
|
1189
|
+
["sandboxes", "default", "filesPerSandbox"],
|
|
1190
|
+
`must be a positive whole number, not ${describeOptionValue(filesPerSandbox)}`
|
|
1072
1191
|
);
|
|
1073
1192
|
ok = false;
|
|
1074
1193
|
}
|
|
1075
|
-
|
|
1194
|
+
const max = value["max"];
|
|
1195
|
+
if (max !== void 0 && (!isPositiveInteger(max) || max > MAX_RUNNER_SANDBOXES)) {
|
|
1196
|
+
report(
|
|
1197
|
+
["sandboxes", "default", "max"],
|
|
1198
|
+
`must be a whole number from 1 to ${MAX_RUNNER_SANDBOXES}, not ${describeOptionValue(max)}`
|
|
1199
|
+
);
|
|
1200
|
+
ok = false;
|
|
1201
|
+
}
|
|
1202
|
+
if (!ok) return void 0;
|
|
1076
1203
|
return {
|
|
1077
|
-
|
|
1078
|
-
...
|
|
1204
|
+
filesPerSandbox,
|
|
1205
|
+
...max === void 0 ? {} : { max }
|
|
1079
1206
|
};
|
|
1080
1207
|
}
|
|
1081
1208
|
function checkSnapshot(value, report) {
|
|
1082
1209
|
if (!isRecord(value)) {
|
|
1083
1210
|
report(
|
|
1084
1211
|
["snapshot"],
|
|
1085
|
-
`must be an object of vcpus, toolchains, prebuild, and an optional summary, not ${
|
|
1212
|
+
`must be an object of vcpus, toolchains, prebuild, and an optional summary, not ${describeOptionValue(value)}`
|
|
1086
1213
|
);
|
|
1087
1214
|
return void 0;
|
|
1088
1215
|
}
|
|
1089
|
-
let ok = reportUnknownKeys(value, SNAPSHOT_KEYS, ["snapshot"], "a
|
|
1216
|
+
let ok = reportUnknownKeys(value, SNAPSHOT_KEYS, ["snapshot"], "a vercelSandbox snapshot key", report);
|
|
1090
1217
|
const vcpus = value["vcpus"];
|
|
1091
1218
|
if (!isPositiveInteger(vcpus)) {
|
|
1092
|
-
report(["snapshot", "vcpus"], `must be a positive whole number, not ${
|
|
1219
|
+
report(["snapshot", "vcpus"], `must be a positive whole number, not ${describeOptionValue(vcpus)}`);
|
|
1093
1220
|
ok = false;
|
|
1094
1221
|
}
|
|
1095
1222
|
const summary = value["summary"];
|
|
1096
1223
|
if (summary !== void 0 && !isNonEmptyString(summary)) {
|
|
1097
|
-
report(["snapshot", "summary"], `must be a non-empty string, not ${
|
|
1224
|
+
report(["snapshot", "summary"], `must be a non-empty string, not ${describeOptionValue(summary)}`);
|
|
1098
1225
|
ok = false;
|
|
1099
1226
|
}
|
|
1100
|
-
const toolchains = checkSteps(value["toolchains"], ["snapshot", "toolchains"], report);
|
|
1101
|
-
const prebuild = checkSteps(value["prebuild"], ["snapshot", "prebuild"], report);
|
|
1227
|
+
const toolchains = checkSteps(value["toolchains"], ["snapshot", "toolchains"], true, report);
|
|
1228
|
+
const prebuild = checkSteps(value["prebuild"], ["snapshot", "prebuild"], false, report);
|
|
1102
1229
|
if (!ok || toolchains === void 0 || prebuild === void 0) return void 0;
|
|
1103
1230
|
return {
|
|
1104
1231
|
vcpus,
|
|
@@ -1109,53 +1236,98 @@ function checkSnapshot(value, report) {
|
|
|
1109
1236
|
}
|
|
1110
1237
|
function checkRun(value, report) {
|
|
1111
1238
|
if (!isRecord(value)) {
|
|
1112
|
-
report(["run"], `must be an object of install and build steps, not ${
|
|
1239
|
+
report(["run"], `must be an object of install and build steps, not ${describeOptionValue(value)}`);
|
|
1113
1240
|
return void 0;
|
|
1114
1241
|
}
|
|
1115
|
-
const ok = reportUnknownKeys(value, RUN_KEYS, ["run"], "a
|
|
1116
|
-
const install = checkStep(value["install"], ["run", "install"], report);
|
|
1117
|
-
const build = checkStep(value["build"], ["run", "build"], report);
|
|
1242
|
+
const ok = reportUnknownKeys(value, RUN_KEYS, ["run"], "a vercelSandbox run key", report);
|
|
1243
|
+
const install = checkStep(value["install"], ["run", "install"], false, report);
|
|
1244
|
+
const build = checkStep(value["build"], ["run", "build"], false, report);
|
|
1118
1245
|
return ok && install !== void 0 && build !== void 0 ? { install, build } : void 0;
|
|
1119
1246
|
}
|
|
1120
|
-
function checkSteps(value, path, report) {
|
|
1121
|
-
if (typeof value === "function")
|
|
1247
|
+
function checkSteps(value, path, allowBaseFiles, report) {
|
|
1248
|
+
if (typeof value === "function") {
|
|
1249
|
+
report(
|
|
1250
|
+
path,
|
|
1251
|
+
allowBaseFiles ? "can't be a function: use a list of { label, script, baseFiles? } steps and declare the base files each step reads" : "can't be a function: use a list of { label, script } steps (prebuild steps already see the base's files)"
|
|
1252
|
+
);
|
|
1253
|
+
return void 0;
|
|
1254
|
+
}
|
|
1122
1255
|
if (!Array.isArray(value)) {
|
|
1123
|
-
report(path, `must be a list of steps,
|
|
1256
|
+
report(path, `must be a list of steps, not ${describeOptionValue(value)}`);
|
|
1124
1257
|
return void 0;
|
|
1125
1258
|
}
|
|
1126
|
-
const steps = value.map(
|
|
1259
|
+
const steps = value.map(
|
|
1260
|
+
(step, index) => allowBaseFiles ? checkStep(step, [...path, String(index)], true, report) : checkStep(step, [...path, String(index)], false, report)
|
|
1261
|
+
);
|
|
1127
1262
|
return steps.every((step) => step !== void 0) ? steps : void 0;
|
|
1128
1263
|
}
|
|
1129
|
-
function checkStep(value, path, report) {
|
|
1264
|
+
function checkStep(value, path, allowBaseFiles, report) {
|
|
1130
1265
|
if (!isRecord(value)) {
|
|
1131
|
-
|
|
1266
|
+
const shape = allowBaseFiles ? "{ label, script, baseFiles? }" : "{ label, script }";
|
|
1267
|
+
report(path, `must be a step, ${shape}, not ${describeOptionValue(value)}`);
|
|
1132
1268
|
return void 0;
|
|
1133
1269
|
}
|
|
1270
|
+
const allowedKeys = allowBaseFiles ? TOOLCHAIN_STEP_KEYS : STEP_KEYS;
|
|
1134
1271
|
let ok = true;
|
|
1135
1272
|
for (const key of Object.keys(value)) {
|
|
1136
|
-
if (
|
|
1273
|
+
if (allowedKeys.has(key)) continue;
|
|
1137
1274
|
report(
|
|
1138
1275
|
[...path, key],
|
|
1139
|
-
key === "secrets" ? "is not a step key: every
|
|
1276
|
+
key === "secrets" ? "is not a step key: every step of the runner gets every credential runner.credentials declares" : key === "baseFiles" ? "is only allowed on snapshot.toolchains steps: this step already sees the base's files" : "is not a step key"
|
|
1140
1277
|
);
|
|
1141
1278
|
ok = false;
|
|
1142
1279
|
}
|
|
1143
1280
|
const label = value["label"];
|
|
1144
1281
|
const script = value["script"];
|
|
1145
1282
|
if (!isNonEmptyString(label)) {
|
|
1146
|
-
report([...path, "label"], `must be a non-empty string, not ${
|
|
1283
|
+
report([...path, "label"], `must be a non-empty string, not ${describeOptionValue(label)}`);
|
|
1147
1284
|
ok = false;
|
|
1148
1285
|
}
|
|
1149
1286
|
if (!isNonEmptyString(script)) {
|
|
1150
|
-
report([...path, "script"], `must be a non-empty string, not ${
|
|
1287
|
+
report([...path, "script"], `must be a non-empty string, not ${describeOptionValue(script)}`);
|
|
1151
1288
|
ok = false;
|
|
1152
1289
|
}
|
|
1153
|
-
return ok ? { label, script } : void 0;
|
|
1290
|
+
if (!allowBaseFiles) return ok ? { label, script } : void 0;
|
|
1291
|
+
const baseFiles = checkBaseFiles(value["baseFiles"], [...path, "baseFiles"], report);
|
|
1292
|
+
if (baseFiles === null) ok = false;
|
|
1293
|
+
if (!ok || baseFiles === null) return void 0;
|
|
1294
|
+
return {
|
|
1295
|
+
label,
|
|
1296
|
+
script,
|
|
1297
|
+
...baseFiles === void 0 || baseFiles.length === 0 ? {} : { baseFiles }
|
|
1298
|
+
};
|
|
1299
|
+
}
|
|
1300
|
+
function checkBaseFiles(value, path, report) {
|
|
1301
|
+
if (value === void 0) return void 0;
|
|
1302
|
+
if (!Array.isArray(value)) {
|
|
1303
|
+
report(path, `must be a list of relative file paths, not ${describeOptionValue(value)}`);
|
|
1304
|
+
return null;
|
|
1305
|
+
}
|
|
1306
|
+
let ok = true;
|
|
1307
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1308
|
+
const checked = [];
|
|
1309
|
+
value.forEach((entry, index) => {
|
|
1310
|
+
const at = [...path, String(index)];
|
|
1311
|
+
if (!isRelativeFilePath(entry)) {
|
|
1312
|
+
report(
|
|
1313
|
+
at,
|
|
1314
|
+
`must be a relative file path without leading "/", "./", "..", or trailing "/", not ${describeOptionValue(entry)}`
|
|
1315
|
+
);
|
|
1316
|
+
ok = false;
|
|
1317
|
+
} else if (seen.has(entry)) {
|
|
1318
|
+
report(at, `lists ${entry} again`);
|
|
1319
|
+
ok = false;
|
|
1320
|
+
} else {
|
|
1321
|
+
seen.add(entry);
|
|
1322
|
+
checked.push(entry);
|
|
1323
|
+
}
|
|
1324
|
+
});
|
|
1325
|
+
return ok ? checked : null;
|
|
1154
1326
|
}
|
|
1155
1327
|
function checkEnv(value, report) {
|
|
1156
1328
|
if (value === void 0) return {};
|
|
1157
1329
|
if (!isRecord(value)) {
|
|
1158
|
-
report(["env"], `must be an object of strings, not ${
|
|
1330
|
+
report(["env"], `must be an object of strings, not ${describeOptionValue(value)}`);
|
|
1159
1331
|
return void 0;
|
|
1160
1332
|
}
|
|
1161
1333
|
let ok = true;
|
|
@@ -1165,7 +1337,7 @@ function checkEnv(value, report) {
|
|
|
1165
1337
|
report(["env", key], "can't be set: storm sets it for the command");
|
|
1166
1338
|
ok = false;
|
|
1167
1339
|
} else if (typeof variable !== "string") {
|
|
1168
|
-
report(["env", key], `must be a string, not ${
|
|
1340
|
+
report(["env", key], `must be a string, not ${describeOptionValue(variable)}`);
|
|
1169
1341
|
ok = false;
|
|
1170
1342
|
} else env[key] = variable;
|
|
1171
1343
|
}
|
|
@@ -1176,7 +1348,7 @@ function checkAllowedDomains(value, report) {
|
|
|
1176
1348
|
if (!Array.isArray(value)) {
|
|
1177
1349
|
report(
|
|
1178
1350
|
["allowedDomains"],
|
|
1179
|
-
`must be a list of domains, such as ["registry.npmjs.org", "*.example.com"], not ${
|
|
1351
|
+
`must be a list of domains, such as ["registry.npmjs.org", "*.example.com"], not ${describeOptionValue(value)}`
|
|
1180
1352
|
);
|
|
1181
1353
|
return null;
|
|
1182
1354
|
}
|
|
@@ -1194,7 +1366,7 @@ function checkAllowedDomains(value, report) {
|
|
|
1194
1366
|
} else if (typeof domain !== "string" || !ALLOWED_DOMAIN_PATTERN.test(domain)) {
|
|
1195
1367
|
report(
|
|
1196
1368
|
at,
|
|
1197
|
-
`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 ${
|
|
1369
|
+
`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)}`
|
|
1198
1370
|
);
|
|
1199
1371
|
ok = false;
|
|
1200
1372
|
} else if (seen.has(domain)) {
|
|
@@ -1206,80 +1378,48 @@ function checkAllowedDomains(value, report) {
|
|
|
1206
1378
|
return ok ? [...value] : null;
|
|
1207
1379
|
}
|
|
1208
1380
|
function checkBaseRefs(value, report) {
|
|
1209
|
-
if (value === void 0) return [...
|
|
1381
|
+
if (value === void 0) return [...VERCEL_SANDBOX_DEFAULTS.baseRefs];
|
|
1210
1382
|
if (!Array.isArray(value) || value.length === 0) {
|
|
1211
|
-
report(["baseRefs"], `must be a non-empty list of refs, not ${
|
|
1383
|
+
report(["baseRefs"], `must be a non-empty list of refs, not ${describeOptionValue(value)}`);
|
|
1212
1384
|
return void 0;
|
|
1213
1385
|
}
|
|
1214
1386
|
let ok = true;
|
|
1215
1387
|
value.forEach((ref, index) => {
|
|
1216
1388
|
if (!isNonEmptyString(ref)) {
|
|
1217
|
-
report(["baseRefs", String(index)], `must be a non-empty string, not ${
|
|
1389
|
+
report(["baseRefs", String(index)], `must be a non-empty string, not ${describeOptionValue(ref)}`);
|
|
1218
1390
|
ok = false;
|
|
1219
1391
|
}
|
|
1220
1392
|
});
|
|
1221
1393
|
return ok ? [...value] : void 0;
|
|
1222
1394
|
}
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
} catch (error) {
|
|
1229
|
-
return { ok: false, problem: `threw at base ${context.base.slice(0, 12)}: ${errorMessage(error)}` };
|
|
1395
|
+
function declaredBaseFilePaths(toolchains) {
|
|
1396
|
+
const paths = /* @__PURE__ */ new Set();
|
|
1397
|
+
for (const step of toolchains) {
|
|
1398
|
+
if (step.baseFiles === void 0) continue;
|
|
1399
|
+
for (const file of step.baseFiles) paths.add(file);
|
|
1230
1400
|
}
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
);
|
|
1237
|
-
|
|
1238
|
-
|
|
1401
|
+
return [...paths].toSorted((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
1402
|
+
}
|
|
1403
|
+
function resolveVcpus(options, run) {
|
|
1404
|
+
if (typeof options.vcpus === "number") return { ok: true, vcpus: options.vcpus };
|
|
1405
|
+
const { resource, option, per, min, max } = options.vcpus;
|
|
1406
|
+
const resourceOptions = Object.hasOwn(run.resources, resource) ? run.resources[resource] : void 0;
|
|
1407
|
+
if (resourceOptions === void 0) return { ok: true, vcpus: min };
|
|
1408
|
+
const raw = Object.hasOwn(resourceOptions, option) ? resourceOptions[option] : void 0;
|
|
1409
|
+
if (typeof raw !== "number" || !Number.isFinite(raw) || raw < 0) {
|
|
1239
1410
|
return {
|
|
1240
1411
|
ok: false,
|
|
1241
|
-
problem: `
|
|
1412
|
+
problem: `resource "${resource}" option "${option}" must be a non-negative number, not ${describeOptionValue(raw)}`
|
|
1242
1413
|
};
|
|
1243
|
-
return { ok: true, steps: checked };
|
|
1244
|
-
}
|
|
1245
|
-
function resolveVcpus(recipe, { run, resourceKeys }) {
|
|
1246
|
-
if (typeof recipe.vcpus !== "function") return { ok: true, vcpus: recipe.vcpus };
|
|
1247
|
-
let returned;
|
|
1248
|
-
try {
|
|
1249
|
-
returned = recipe.vcpus(run);
|
|
1250
|
-
} catch (error) {
|
|
1251
|
-
return { ok: false, problem: `threw for ${describeResourceKeys(resourceKeys)}: ${errorMessage(error)}` };
|
|
1252
1414
|
}
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
problem: `must return a positive whole number, not ${describeRecipeValue(returned)} for ${describeResourceKeys(resourceKeys)}`
|
|
1256
|
-
};
|
|
1415
|
+
const perSandbox = Math.ceil(raw / Math.max(1, run.sandboxes));
|
|
1416
|
+
return { ok: true, vcpus: Math.min(max, Math.max(min, per * perSandbox)) };
|
|
1257
1417
|
}
|
|
1258
1418
|
function resolveSandboxCountDefault(sandboxesDefault, testPlan) {
|
|
1259
|
-
if (typeof sandboxesDefault
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
} catch (error) {
|
|
1264
|
-
return { ok: false, problem: `threw for ${describeTestPlan(testPlan)}: ${errorMessage(error)}` };
|
|
1265
|
-
}
|
|
1266
|
-
return isPositiveInteger(returned) ? { ok: true, sandboxes: returned } : {
|
|
1267
|
-
ok: false,
|
|
1268
|
-
problem: `must return a whole number from 1, not ${describeRecipeValue(returned)} for ${describeTestPlan(testPlan)}`
|
|
1269
|
-
};
|
|
1270
|
-
}
|
|
1271
|
-
function describeTestPlan(testPlan) {
|
|
1272
|
-
if (testPlan.kind !== "counted") return "a test plan that counted nothing";
|
|
1273
|
-
const files = `${testPlan.files} test ${testPlan.files === 1 ? "file" : "files"}`;
|
|
1274
|
-
return testPlan.tests === void 0 ? `a test plan of ${files}` : `a test plan of ${testPlan.tests} ${testPlan.tests === 1 ? "test" : "tests"} in ${files}`;
|
|
1275
|
-
}
|
|
1276
|
-
function describeResourceKeys(names) {
|
|
1277
|
-
const last = names.at(-1);
|
|
1278
|
-
if (last === void 0) return "a run with no resource";
|
|
1279
|
-
return `a run with ${names.length === 1 ? last : `${names.slice(0, -1).join(", ")} and ${last}`}`;
|
|
1280
|
-
}
|
|
1281
|
-
function errorMessage(error) {
|
|
1282
|
-
return error instanceof Error ? error.message : String(error);
|
|
1419
|
+
if (typeof sandboxesDefault === "number") return sandboxesDefault;
|
|
1420
|
+
if (testPlan.kind !== "counted") return 1;
|
|
1421
|
+
const limit = sandboxesDefault.max ?? MAX_RUNNER_SANDBOXES;
|
|
1422
|
+
return Math.max(1, Math.min(limit, Math.ceil(testPlan.files / sandboxesDefault.filesPerSandbox)));
|
|
1283
1423
|
}
|
|
1284
1424
|
function orDefault(value, fallback) {
|
|
1285
1425
|
return value === void 0 ? fallback : value;
|
|
@@ -1296,9 +1436,15 @@ function isPositiveInteger(value) {
|
|
|
1296
1436
|
function isRelativePath(value) {
|
|
1297
1437
|
return typeof value === "string" && value.length > 0 && !value.startsWith("/") && !value.split(/[/\\]/).includes("..");
|
|
1298
1438
|
}
|
|
1439
|
+
function isRelativeFilePath(value) {
|
|
1440
|
+
if (typeof value !== "string" || value.length === 0) return false;
|
|
1441
|
+
if (value.startsWith("/") || value.endsWith("/") || value.includes("\\") || value.includes("\0")) return false;
|
|
1442
|
+
const segments = value.split("/");
|
|
1443
|
+
return segments.every((segment) => segment.length > 0 && segment !== "." && segment !== "..");
|
|
1444
|
+
}
|
|
1299
1445
|
|
|
1300
1446
|
// src/runner/snapshot-key.ts
|
|
1301
|
-
var SNAPSHOT_FORMAT =
|
|
1447
|
+
var SNAPSHOT_FORMAT = 5;
|
|
1302
1448
|
var SANDBOX_ROOT = "/vercel/sandbox";
|
|
1303
1449
|
var STAGED_FILES = {
|
|
1304
1450
|
baseTarball: "base.tgz",
|
|
@@ -1347,31 +1493,49 @@ function applyScript(staging, root = SANDBOX_ROOT) {
|
|
|
1347
1493
|
}
|
|
1348
1494
|
function snapshotKey(steps) {
|
|
1349
1495
|
const text = (list) => list.flatMap(({ label, script }) => [label, script]);
|
|
1496
|
+
const baseFiles = [...steps.baseFiles].toSorted((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0);
|
|
1350
1497
|
return createHash2("sha256").update(
|
|
1351
1498
|
[
|
|
1352
1499
|
`format=${SNAPSHOT_FORMAT}`,
|
|
1353
1500
|
`credentials=${[...new Set(steps.credentials)].toSorted().join(",")}`,
|
|
1501
|
+
`baseFiles=${baseFiles.length}`,
|
|
1502
|
+
...baseFiles.flatMap(({ path, text: content }) => [path, content]),
|
|
1354
1503
|
...text(steps.toolchains),
|
|
1355
1504
|
baseIndexScript("<base>", "<staging>"),
|
|
1356
1505
|
...text(steps.prebuild)
|
|
1357
1506
|
].join("\0")
|
|
1358
1507
|
).digest("hex");
|
|
1359
1508
|
}
|
|
1360
|
-
async function
|
|
1361
|
-
const
|
|
1362
|
-
const { snapshot } =
|
|
1363
|
-
const
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1509
|
+
async function snapshotInputsAt(checkout, request2) {
|
|
1510
|
+
const { repoRoot, base, options } = request2;
|
|
1511
|
+
const { snapshot } = options;
|
|
1512
|
+
const baseFiles = [];
|
|
1513
|
+
for (const path of declaredBaseFilePaths(snapshot.toolchains)) {
|
|
1514
|
+
const file = await checkout.readFileAt({ repoRoot, commit: base, path });
|
|
1515
|
+
if (file.kind === "missing") {
|
|
1516
|
+
return {
|
|
1517
|
+
ok: false,
|
|
1518
|
+
path: ["snapshot", "toolchains"],
|
|
1519
|
+
problem: `declared base file "${path}" doesn't exist at base ${base.slice(0, 12)}`
|
|
1520
|
+
};
|
|
1521
|
+
}
|
|
1522
|
+
if (file.kind === "failed") {
|
|
1523
|
+
return {
|
|
1524
|
+
ok: false,
|
|
1525
|
+
path: ["snapshot", "toolchains"],
|
|
1526
|
+
problem: `can't read declared base file "${path}" at base ${base.slice(0, 12)}: ${file.failure.message}`
|
|
1527
|
+
};
|
|
1528
|
+
}
|
|
1529
|
+
baseFiles.push({ path, text: file.text });
|
|
1530
|
+
}
|
|
1367
1531
|
return {
|
|
1368
1532
|
ok: true,
|
|
1369
|
-
|
|
1370
|
-
prebuild: prebuild.steps,
|
|
1533
|
+
baseFiles,
|
|
1371
1534
|
key: snapshotKey({
|
|
1372
|
-
credentials: credentialSourceIds(
|
|
1373
|
-
|
|
1374
|
-
|
|
1535
|
+
credentials: credentialSourceIds(options),
|
|
1536
|
+
baseFiles,
|
|
1537
|
+
toolchains: snapshot.toolchains,
|
|
1538
|
+
prebuild: snapshot.prebuild
|
|
1375
1539
|
})
|
|
1376
1540
|
};
|
|
1377
1541
|
}
|
|
@@ -1501,34 +1665,36 @@ var BUILD_SANDBOX_TIMEOUT_MS = 30 * 6e4;
|
|
|
1501
1665
|
var BASE_INDEX_LABEL = "Committing the base's files";
|
|
1502
1666
|
async function buildSnapshot(context, request2, control, progress) {
|
|
1503
1667
|
const { prepared, access } = request2;
|
|
1504
|
-
const {
|
|
1668
|
+
const { options, repoRoot, base } = prepared;
|
|
1505
1669
|
const { scope, signal } = control;
|
|
1670
|
+
const { publish } = request2;
|
|
1506
1671
|
const now = () => context.clock.now().getTime();
|
|
1507
1672
|
const startedAt = now();
|
|
1508
1673
|
await progress.emit({
|
|
1509
1674
|
kind: "snapshot-build-started",
|
|
1510
1675
|
base,
|
|
1511
1676
|
why: request2.why,
|
|
1512
|
-
summary:
|
|
1677
|
+
summary: options.snapshot.summary ?? [...options.snapshot.toolchains, ...options.snapshot.prebuild].map(({ label }) => label).join(", ")
|
|
1513
1678
|
});
|
|
1514
1679
|
const [started, archive] = await Promise.all([
|
|
1515
1680
|
scope.startBuildSandbox(access, {
|
|
1516
|
-
region:
|
|
1517
|
-
runtime:
|
|
1518
|
-
vcpus:
|
|
1681
|
+
region: options.region,
|
|
1682
|
+
runtime: options.runtime,
|
|
1683
|
+
vcpus: options.snapshot.vcpus,
|
|
1519
1684
|
timeoutMs: BUILD_SANDBOX_TIMEOUT_MS,
|
|
1520
|
-
tags: runnerTags(
|
|
1685
|
+
...publish === void 0 ? { tags: runnerTags(options.name, "snapshot-build", request2.user) } : { name: publish.name, tags: publish.tags }
|
|
1521
1686
|
}),
|
|
1522
1687
|
context.checkout.baseArchive({ repoRoot, base })
|
|
1523
1688
|
]);
|
|
1524
|
-
if (!started.ok)
|
|
1689
|
+
if (!started.ok)
|
|
1690
|
+
return started.failure.kind === "name-taken" ? { kind: "name-taken", name: started.failure.name, message: started.failure.message } : sandboxStop("start-build-sandbox", started.failure);
|
|
1525
1691
|
const sandbox = started.value;
|
|
1526
1692
|
await progress.emit({
|
|
1527
1693
|
kind: "sandbox-started",
|
|
1528
1694
|
role: "snapshot-build",
|
|
1529
1695
|
name: sandbox.name,
|
|
1530
|
-
region:
|
|
1531
|
-
vcpus:
|
|
1696
|
+
region: options.region,
|
|
1697
|
+
vcpus: options.snapshot.vcpus,
|
|
1532
1698
|
ms: now() - startedAt
|
|
1533
1699
|
});
|
|
1534
1700
|
if (!archive.ok) return { kind: "failed", failure: { kind: "checkout-failed", failure: archive.failure } };
|
|
@@ -1541,12 +1707,21 @@ async function buildSnapshot(context, request2, control, progress) {
|
|
|
1541
1707
|
signal
|
|
1542
1708
|
);
|
|
1543
1709
|
if (!staged.ok) return sandboxStop("upload", staged.failure);
|
|
1710
|
+
if (prepared.baseFiles.length > 0) {
|
|
1711
|
+
const encoder = new TextEncoder();
|
|
1712
|
+
const placed = await context.runnerSandboxes.placeBaseFiles(
|
|
1713
|
+
sandbox,
|
|
1714
|
+
prepared.baseFiles.map(({ path, text }) => ({ name: path, content: encoder.encode(text) })),
|
|
1715
|
+
signal
|
|
1716
|
+
);
|
|
1717
|
+
if (!placed.ok) return sandboxStop("upload", placed.failure);
|
|
1718
|
+
}
|
|
1544
1719
|
const steps = [
|
|
1545
|
-
...
|
|
1720
|
+
...options.snapshot.toolchains,
|
|
1546
1721
|
{ label: BASE_INDEX_LABEL, script: baseIndexScript(base, staged.value.directory) },
|
|
1547
|
-
...
|
|
1722
|
+
...options.snapshot.prebuild
|
|
1548
1723
|
];
|
|
1549
|
-
await progress.emit({ kind: "output-started", section: "snapshot", sandbox: sandbox.name, region:
|
|
1724
|
+
await progress.emit({ kind: "output-started", section: "snapshot", sandbox: sandbox.name, region: options.region });
|
|
1550
1725
|
let stop;
|
|
1551
1726
|
if (request2.credentials.length > 0) {
|
|
1552
1727
|
const granted = await scope.grantCredentials(sandbox, request2.credentials, signal);
|
|
@@ -1580,16 +1755,19 @@ async function buildSnapshot(context, request2, control, progress) {
|
|
|
1580
1755
|
if (stop !== void 0) return stop;
|
|
1581
1756
|
if (signal.aborted) return { kind: "aborted" };
|
|
1582
1757
|
await progress.emit({ kind: "snapshot-saving" });
|
|
1583
|
-
const saved = await scope.saveSnapshot(sandbox, {
|
|
1758
|
+
const saved = await scope.saveSnapshot(sandbox, {
|
|
1759
|
+
expirationMs: SNAPSHOT_EXPIRATION_MS,
|
|
1760
|
+
...publish === void 0 ? {} : { keepStopped: true }
|
|
1761
|
+
});
|
|
1584
1762
|
if (!saved.ok)
|
|
1585
1763
|
return saved.failure.kind === "credential-not-revoked" ? networkPolicyStop("remove", "snapshot-save", saved.failure.failure) : sandboxStop("save-snapshot", saved.failure);
|
|
1586
1764
|
const savedAt = context.clock.now();
|
|
1587
1765
|
const entry = {
|
|
1588
1766
|
teamId: access.teamId,
|
|
1589
1767
|
projectId: access.projectId,
|
|
1590
|
-
region:
|
|
1591
|
-
runtime:
|
|
1592
|
-
|
|
1768
|
+
region: options.region,
|
|
1769
|
+
runtime: options.runtime,
|
|
1770
|
+
runnerName: options.name,
|
|
1593
1771
|
snapshotKey: prepared.snapshotKey,
|
|
1594
1772
|
base,
|
|
1595
1773
|
snapshotId: saved.value.snapshotId,
|
|
@@ -1609,20 +1787,146 @@ async function buildSnapshot(context, request2, control, progress) {
|
|
|
1609
1787
|
});
|
|
1610
1788
|
return {
|
|
1611
1789
|
kind: "ok",
|
|
1612
|
-
value: { entry, ms, sizeBytes: saved.value.sizeBytes,
|
|
1790
|
+
value: { entry, ms, sizeBytes: saved.value.sizeBytes, localIndexFailure: written.ok ? null : written.failure }
|
|
1791
|
+
};
|
|
1792
|
+
}
|
|
1793
|
+
|
|
1794
|
+
// src/runner/shared-snapshot-entry.ts
|
|
1795
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
1796
|
+
var SHARED_SNAPSHOT_SANDBOX_PREFIX = "storm-snap-";
|
|
1797
|
+
var SHARED_SNAPSHOT_NAME_PATTERN = /^storm-snap-([0-9a-f]{16})-([0-9a-f]{40})$/;
|
|
1798
|
+
var INDEX_CONCURRENCY = 8;
|
|
1799
|
+
function isBuildingSandboxStatus(status) {
|
|
1800
|
+
switch (status) {
|
|
1801
|
+
case "pending":
|
|
1802
|
+
case "running":
|
|
1803
|
+
case "snapshotting":
|
|
1804
|
+
case "stopping":
|
|
1805
|
+
return true;
|
|
1806
|
+
case "stopped":
|
|
1807
|
+
case "failed":
|
|
1808
|
+
case "aborted":
|
|
1809
|
+
return false;
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
function hasSnapshotId(row) {
|
|
1813
|
+
return row.currentSnapshotId !== void 0 && row.currentSnapshotId !== "";
|
|
1814
|
+
}
|
|
1815
|
+
function sharedSnapshotBucket(input) {
|
|
1816
|
+
return createHash3("sha256").update(
|
|
1817
|
+
[input.teamId, input.projectId, input.region, input.runtime, input.runnerName, input.snapshotKey].join("\0")
|
|
1818
|
+
).digest("hex").slice(0, 16);
|
|
1819
|
+
}
|
|
1820
|
+
function sharedSnapshotSandboxPrefix(bucket) {
|
|
1821
|
+
return `${SHARED_SNAPSHOT_SANDBOX_PREFIX}${bucket}-`;
|
|
1822
|
+
}
|
|
1823
|
+
function sharedSnapshotSandboxName(bucket, base) {
|
|
1824
|
+
return `${SHARED_SNAPSHOT_SANDBOX_PREFIX}${bucket}-${base}`;
|
|
1825
|
+
}
|
|
1826
|
+
function parseSharedSnapshotSandboxName(name) {
|
|
1827
|
+
const match = SHARED_SNAPSHOT_NAME_PATTERN.exec(name);
|
|
1828
|
+
if (match === null) return null;
|
|
1829
|
+
const [, bucket, base] = match;
|
|
1830
|
+
if (bucket === void 0 || base === void 0) return null;
|
|
1831
|
+
return { bucket, base };
|
|
1832
|
+
}
|
|
1833
|
+
function classifyUnverifiedSharedSandbox(row) {
|
|
1834
|
+
if (isBuildingSandboxStatus(row.status)) return { kind: "settled", status: "building" };
|
|
1835
|
+
if (row.status === "failed" || row.status === "aborted") return { kind: "settled", status: "failed" };
|
|
1836
|
+
if (!hasSnapshotId(row)) return { kind: "settled", status: "no-snapshot" };
|
|
1837
|
+
return { kind: "needs-snapshot", snapshotId: row.currentSnapshotId };
|
|
1838
|
+
}
|
|
1839
|
+
function classifyVerifiedSharedSnapshot(row, lookup, now) {
|
|
1840
|
+
if (lookup.kind === "not-found") {
|
|
1841
|
+
return {
|
|
1842
|
+
status: "missing",
|
|
1843
|
+
snapshotId: row.currentSnapshotId,
|
|
1844
|
+
snapshotStatus: void 0,
|
|
1845
|
+
createdAt: row.createdAt,
|
|
1846
|
+
expiresAt: row.tags["expires-at"]
|
|
1847
|
+
};
|
|
1848
|
+
}
|
|
1849
|
+
const { snapshot } = lookup;
|
|
1850
|
+
const expiresAt = snapshot.expiresAt ?? row.tags["expires-at"];
|
|
1851
|
+
if (snapshot.status !== "created") {
|
|
1852
|
+
return {
|
|
1853
|
+
status: "missing",
|
|
1854
|
+
snapshotId: snapshot.snapshotId,
|
|
1855
|
+
snapshotStatus: snapshot.status,
|
|
1856
|
+
createdAt: snapshot.createdAt,
|
|
1857
|
+
expiresAt
|
|
1858
|
+
};
|
|
1859
|
+
}
|
|
1860
|
+
const expiresAtMs = expiresAt === void 0 ? Number.NaN : Date.parse(expiresAt);
|
|
1861
|
+
if (Number.isNaN(expiresAtMs)) {
|
|
1862
|
+
return {
|
|
1863
|
+
status: "unknown-expiry",
|
|
1864
|
+
snapshotId: snapshot.snapshotId,
|
|
1865
|
+
snapshotStatus: snapshot.status,
|
|
1866
|
+
createdAt: snapshot.createdAt,
|
|
1867
|
+
expiresAt
|
|
1868
|
+
};
|
|
1869
|
+
}
|
|
1870
|
+
const nowMs = now.getTime();
|
|
1871
|
+
const status = expiresAtMs <= nowMs ? "expired" : expiresAtMs - nowMs > SNAPSHOT_MIN_REMAINING_MS ? "ready" : "expires-soon";
|
|
1872
|
+
return {
|
|
1873
|
+
status,
|
|
1874
|
+
snapshotId: snapshot.snapshotId,
|
|
1875
|
+
snapshotStatus: snapshot.status,
|
|
1876
|
+
createdAt: snapshot.createdAt,
|
|
1877
|
+
expiresAt
|
|
1878
|
+
};
|
|
1879
|
+
}
|
|
1880
|
+
function usableSharedEntry(access, runner, snapshotKey2, base, sandbox, snapshot, now) {
|
|
1881
|
+
const verified = classifyVerifiedSharedSnapshot(
|
|
1882
|
+
{ ...sandbox, currentSnapshotId: snapshot.snapshotId },
|
|
1883
|
+
{ kind: "found", snapshot },
|
|
1884
|
+
now
|
|
1885
|
+
);
|
|
1886
|
+
if (verified.status !== "ready" || verified.expiresAt === void 0) return null;
|
|
1887
|
+
return {
|
|
1888
|
+
teamId: access.teamId,
|
|
1889
|
+
projectId: access.projectId,
|
|
1890
|
+
region: runner.region,
|
|
1891
|
+
runtime: runner.runtime,
|
|
1892
|
+
runnerName: runner.name,
|
|
1893
|
+
snapshotKey: snapshotKey2,
|
|
1894
|
+
base,
|
|
1895
|
+
snapshotId: verified.snapshotId,
|
|
1896
|
+
createdAt: verified.createdAt,
|
|
1897
|
+
expiresAt: verified.expiresAt
|
|
1898
|
+
};
|
|
1899
|
+
}
|
|
1900
|
+
async function runLimited(count, limit, proceed, task) {
|
|
1901
|
+
const results = Array.from({ length: count }, () => void 0);
|
|
1902
|
+
let failure;
|
|
1903
|
+
let next = 0;
|
|
1904
|
+
const worker = async () => {
|
|
1905
|
+
while (failure === void 0 && next < count && proceed()) {
|
|
1906
|
+
const index = next;
|
|
1907
|
+
next += 1;
|
|
1908
|
+
try {
|
|
1909
|
+
results[index] = await task(index);
|
|
1910
|
+
} catch (error) {
|
|
1911
|
+
failure ??= { error };
|
|
1912
|
+
}
|
|
1913
|
+
}
|
|
1613
1914
|
};
|
|
1915
|
+
await Promise.all(Array.from({ length: Math.min(limit, count) }, worker));
|
|
1916
|
+
if (failure !== void 0) throw failure.error;
|
|
1917
|
+
return results;
|
|
1614
1918
|
}
|
|
1615
1919
|
|
|
1616
1920
|
// src/runner/build-snapshots.ts
|
|
1617
1921
|
async function prepareSnapshotBuild(context, request2) {
|
|
1618
1922
|
const { checkout } = context;
|
|
1619
|
-
const {
|
|
1923
|
+
const { options, ref } = request2;
|
|
1620
1924
|
const root = await checkout.repositoryRoot({ cwd: request2.cwd });
|
|
1621
1925
|
if (!root.ok) return { kind: "checkout-failed", failure: root.failure };
|
|
1622
1926
|
const repoRoot = root.value;
|
|
1623
1927
|
const head2 = await checkout.head({ repoRoot });
|
|
1624
1928
|
if (!head2.ok) return { kind: "checkout-failed", failure: head2.failure };
|
|
1625
|
-
const resolved = await resolveBase(checkout, { repoRoot, baseRefs:
|
|
1929
|
+
const resolved = await resolveBase(checkout, { repoRoot, baseRefs: options.baseRefs });
|
|
1626
1930
|
if (resolved.kind === "failed") return { kind: "checkout-failed", failure: resolved.failure };
|
|
1627
1931
|
const mergeBase = resolved.kind === "resolved" ? { commit: resolved.base, ref: resolved.ref } : null;
|
|
1628
1932
|
const submodules2 = await checkout.submodules({ repoRoot });
|
|
@@ -1638,12 +1942,12 @@ async function prepareSnapshotBuild(context, request2) {
|
|
|
1638
1942
|
if (commit.value === null) return { kind: "ref-not-found", ref };
|
|
1639
1943
|
base = commit.value;
|
|
1640
1944
|
}
|
|
1641
|
-
const
|
|
1642
|
-
if (!
|
|
1945
|
+
const inputs = await snapshotInputsAt(checkout, { repoRoot, base, options });
|
|
1946
|
+
if (!inputs.ok) return { kind: "invalid-runner", path: inputs.path, problem: inputs.problem };
|
|
1643
1947
|
const listed = await context.runnerSnapshots.listEntries();
|
|
1644
1948
|
const now = context.clock.now();
|
|
1645
|
-
const
|
|
1646
|
-
(entry) => entry.base === base && entry.
|
|
1949
|
+
const indexed = (listed.ok ? listed.value.entries : []).filter(
|
|
1950
|
+
(entry) => entry.base === base && entry.runnerName === options.name && entry.region === options.region && entry.runtime === options.runtime && entry.snapshotKey === inputs.key && hasTimeLeft(entry, now)
|
|
1647
1951
|
);
|
|
1648
1952
|
const atMergeBase = base === mergeBase?.commit;
|
|
1649
1953
|
let commitsAfterBase = null;
|
|
@@ -1652,23 +1956,29 @@ async function prepareSnapshotBuild(context, request2) {
|
|
|
1652
1956
|
if (!counted.ok) return { kind: "checkout-failed", failure: counted.failure };
|
|
1653
1957
|
commitsAfterBase = counted.value;
|
|
1654
1958
|
}
|
|
1959
|
+
let ancestorOfMergeBase = false;
|
|
1960
|
+
if (!atMergeBase && mergeBase !== null) {
|
|
1961
|
+
const contained = await checkout.contains({ repoRoot, ancestor: base, descendant: mergeBase.commit });
|
|
1962
|
+
if (!contained.ok) return { kind: "checkout-failed", failure: contained.failure };
|
|
1963
|
+
ancestorOfMergeBase = contained.value;
|
|
1964
|
+
}
|
|
1655
1965
|
return {
|
|
1656
1966
|
kind: "ok",
|
|
1657
1967
|
build: {
|
|
1658
1968
|
plan: {
|
|
1659
|
-
|
|
1969
|
+
options,
|
|
1660
1970
|
repoRoot,
|
|
1661
1971
|
base,
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
snapshotKey: steps.key,
|
|
1972
|
+
baseFiles: inputs.baseFiles,
|
|
1973
|
+
snapshotKey: inputs.key,
|
|
1665
1974
|
commitsAfterBase
|
|
1666
1975
|
},
|
|
1667
1976
|
head: head2.value,
|
|
1668
1977
|
ref: ref ?? null,
|
|
1669
1978
|
mergeBase,
|
|
1670
1979
|
atMergeBase,
|
|
1671
|
-
|
|
1980
|
+
ancestorOfMergeBase,
|
|
1981
|
+
indexed,
|
|
1672
1982
|
full: request2.full
|
|
1673
1983
|
}
|
|
1674
1984
|
};
|
|
@@ -1677,7 +1987,7 @@ async function buildSnapshots(context, request2, control, progress) {
|
|
|
1677
1987
|
const { signal } = control;
|
|
1678
1988
|
const scope = runnerSandboxScope(context, progress, {
|
|
1679
1989
|
keepMs: 0,
|
|
1680
|
-
basePolicy: runnerNetworkPolicy(request2.build.plan.
|
|
1990
|
+
basePolicy: runnerNetworkPolicy(request2.build.plan.options),
|
|
1681
1991
|
signal
|
|
1682
1992
|
});
|
|
1683
1993
|
try {
|
|
@@ -1692,26 +2002,99 @@ async function buildIn(context, request2, control, progress) {
|
|
|
1692
2002
|
const { build, access, user, credentials: credentials2 } = request2;
|
|
1693
2003
|
const { signal } = control;
|
|
1694
2004
|
if (signal.aborted) return { kind: "aborted", snapshot: null };
|
|
1695
|
-
|
|
1696
|
-
|
|
2005
|
+
if (request2.publish === true) return await publishIn(context, request2, control, progress);
|
|
2006
|
+
const indexed = build.indexed.find((entry2) => entry2.teamId === access.teamId && entry2.projectId === access.projectId);
|
|
2007
|
+
if (!build.full && indexed !== void 0) return { kind: "up-to-date", snapshot: indexed };
|
|
2008
|
+
const built = await buildSnapshot(
|
|
2009
|
+
context,
|
|
2010
|
+
{ prepared: build.plan, access, user, credentials: credentials2, why: buildReason(build) },
|
|
2011
|
+
control,
|
|
2012
|
+
progress
|
|
2013
|
+
);
|
|
2014
|
+
if (built.kind === "aborted") return { kind: "aborted", snapshot: null };
|
|
2015
|
+
if (built.kind !== "ok") return built;
|
|
2016
|
+
const { entry, localIndexFailure, ms, sizeBytes } = built.value;
|
|
2017
|
+
if (signal.aborted) return { kind: "aborted", snapshot: { entry, indexed: localIndexFailure === null } };
|
|
2018
|
+
return localIndexFailure === null ? { kind: "built", snapshot: entry, ms, sizeBytes } : { kind: "not-indexed", snapshot: entry, failure: localIndexFailure };
|
|
2019
|
+
}
|
|
2020
|
+
function buildReason(build) {
|
|
1697
2021
|
const why = build.full ? "full" : build.ref === null ? "no-snapshot" : "base";
|
|
2022
|
+
return why === "no-snapshot" ? { kind: why, rejected: [] } : { kind: why };
|
|
2023
|
+
}
|
|
2024
|
+
async function publishIn(context, request2, control, progress) {
|
|
2025
|
+
const { build, access, user, credentials: credentials2 } = request2;
|
|
2026
|
+
const { plan } = build;
|
|
2027
|
+
const { options } = plan;
|
|
2028
|
+
const { signal } = control;
|
|
2029
|
+
const { runnerSandboxes } = context;
|
|
2030
|
+
const bucket = sharedSnapshotBucket({
|
|
2031
|
+
teamId: access.teamId,
|
|
2032
|
+
projectId: access.projectId,
|
|
2033
|
+
region: options.region,
|
|
2034
|
+
runtime: options.runtime,
|
|
2035
|
+
runnerName: options.name,
|
|
2036
|
+
snapshotKey: plan.snapshotKey
|
|
2037
|
+
});
|
|
2038
|
+
const name = sharedSnapshotSandboxName(bucket, plan.base);
|
|
2039
|
+
const found = await runnerSandboxes.getNamedSandbox(access, { name }, signal);
|
|
2040
|
+
if (!found.ok) return callStop("get-named-sandbox", found.failure);
|
|
2041
|
+
if (found.value.kind === "found") {
|
|
2042
|
+
const { sandbox } = found.value;
|
|
2043
|
+
const unverified = classifyUnverifiedSharedSandbox(sandbox);
|
|
2044
|
+
if (unverified.kind === "settled" && unverified.status === "building")
|
|
2045
|
+
return { kind: "already-building", sandboxName: name, status: sandbox.status };
|
|
2046
|
+
if (!build.full && unverified.kind === "needs-snapshot") {
|
|
2047
|
+
const verified = await runnerSandboxes.getSnapshot(access, { snapshotId: unverified.snapshotId }, signal);
|
|
2048
|
+
if (!verified.ok) return callStop("get-snapshot", verified.failure);
|
|
2049
|
+
const entry2 = verified.value.kind === "found" ? usableSharedEntry(
|
|
2050
|
+
access,
|
|
2051
|
+
options,
|
|
2052
|
+
plan.snapshotKey,
|
|
2053
|
+
plan.base,
|
|
2054
|
+
sandbox,
|
|
2055
|
+
verified.value.snapshot,
|
|
2056
|
+
context.clock.now()
|
|
2057
|
+
) : null;
|
|
2058
|
+
if (entry2 !== null) {
|
|
2059
|
+
const written = await context.runnerSnapshots.writeEntry(entry2);
|
|
2060
|
+
if (!written.ok) await progress.emit({ kind: "snapshot-entry-not-written", failure: written.failure });
|
|
2061
|
+
return { kind: "up-to-date", snapshot: entry2, sandboxName: name };
|
|
2062
|
+
}
|
|
2063
|
+
}
|
|
2064
|
+
const removed = await runnerSandboxes.deleteNamedSandbox(access, { name }, signal);
|
|
2065
|
+
if (!removed.ok) return callStop("delete-named-sandbox", removed.failure);
|
|
2066
|
+
}
|
|
2067
|
+
if (signal.aborted) return { kind: "aborted", snapshot: null };
|
|
2068
|
+
const expiresAt = new Date(context.clock.now().getTime() + SNAPSHOT_EXPIRATION_MS).toISOString();
|
|
1698
2069
|
const built = await buildSnapshot(
|
|
1699
2070
|
context,
|
|
1700
2071
|
{
|
|
1701
|
-
prepared:
|
|
2072
|
+
prepared: plan,
|
|
1702
2073
|
access,
|
|
1703
2074
|
user,
|
|
1704
2075
|
credentials: credentials2,
|
|
1705
|
-
why:
|
|
2076
|
+
why: buildReason(build),
|
|
2077
|
+
publish: { name, tags: snapshotIndexTags(options.name, user, plan.base, expiresAt) }
|
|
1706
2078
|
},
|
|
1707
2079
|
control,
|
|
1708
2080
|
progress
|
|
1709
2081
|
);
|
|
2082
|
+
if (built.kind === "name-taken") return { kind: "already-building", sandboxName: name, status: null };
|
|
1710
2083
|
if (built.kind === "aborted") return { kind: "aborted", snapshot: null };
|
|
1711
2084
|
if (built.kind !== "ok") return built;
|
|
1712
|
-
const { entry,
|
|
1713
|
-
if (signal.aborted) return { kind: "aborted", snapshot: { entry,
|
|
1714
|
-
return
|
|
2085
|
+
const { entry, localIndexFailure, ms, sizeBytes } = built.value;
|
|
2086
|
+
if (signal.aborted) return { kind: "aborted", snapshot: { entry, indexed: localIndexFailure === null } };
|
|
2087
|
+
return {
|
|
2088
|
+
kind: "built",
|
|
2089
|
+
snapshot: entry,
|
|
2090
|
+
ms,
|
|
2091
|
+
sizeBytes,
|
|
2092
|
+
sandboxName: name,
|
|
2093
|
+
...localIndexFailure === null ? {} : { localIndexFailure }
|
|
2094
|
+
};
|
|
2095
|
+
}
|
|
2096
|
+
function callStop(operation, failure) {
|
|
2097
|
+
return failure.kind === "aborted" ? { kind: "aborted", snapshot: null } : { kind: "failed", failure: sandboxApiFailure(operation, failure) };
|
|
1715
2098
|
}
|
|
1716
2099
|
|
|
1717
2100
|
// src/runner/live/user.ts
|
|
@@ -1725,11 +2108,11 @@ function localUserName() {
|
|
|
1725
2108
|
}
|
|
1726
2109
|
|
|
1727
2110
|
// src/runner/secrets.ts
|
|
1728
|
-
function declaredSecretValues(
|
|
1729
|
-
if (
|
|
2111
|
+
function declaredSecretValues(options, env) {
|
|
2112
|
+
if (options === void 0) return [];
|
|
1730
2113
|
const seen = /* @__PURE__ */ new Set();
|
|
1731
2114
|
const values = [];
|
|
1732
|
-
for (const { source } of [...
|
|
2115
|
+
for (const { source } of [...options.credentials, ...options.unsafeSecretEnvVars]) {
|
|
1733
2116
|
const id = secretSourceId(source);
|
|
1734
2117
|
if (seen.has(id)) continue;
|
|
1735
2118
|
seen.add(id);
|
|
@@ -1738,8 +2121,8 @@ function declaredSecretValues(recipe, env) {
|
|
|
1738
2121
|
}
|
|
1739
2122
|
return values;
|
|
1740
2123
|
}
|
|
1741
|
-
function readCredentials(
|
|
1742
|
-
const read = readUniqueSources(
|
|
2124
|
+
function readCredentials(options, env) {
|
|
2125
|
+
const read = readUniqueSources(options.credentials, env, ({ domain, header, requests }, value) => ({
|
|
1743
2126
|
domain,
|
|
1744
2127
|
header,
|
|
1745
2128
|
value,
|
|
@@ -1747,8 +2130,11 @@ function readCredentials(recipe, env) {
|
|
|
1747
2130
|
}));
|
|
1748
2131
|
return read.ok ? { ok: true, credentials: read.items } : read;
|
|
1749
2132
|
}
|
|
1750
|
-
function readUnsafeSecretEnvVars(
|
|
1751
|
-
const read = readUniqueSources(
|
|
2133
|
+
function readUnsafeSecretEnvVars(options, env) {
|
|
2134
|
+
const read = readUniqueSources(options.unsafeSecretEnvVars, env, ({ name }, value) => [
|
|
2135
|
+
name,
|
|
2136
|
+
value
|
|
2137
|
+
]);
|
|
1752
2138
|
return read.ok ? { ok: true, values: Object.fromEntries(read.items) } : read;
|
|
1753
2139
|
}
|
|
1754
2140
|
function readUniqueSources(entries, env, map) {
|
|
@@ -1769,15 +2155,15 @@ function readUniqueSources(entries, env, map) {
|
|
|
1769
2155
|
}
|
|
1770
2156
|
|
|
1771
2157
|
// src/runner/snapshot-inspect.ts
|
|
1772
|
-
async function
|
|
2158
|
+
async function inspectLocalSnapshotIndex(context, request2) {
|
|
1773
2159
|
const { checkout, runnerSnapshots } = context;
|
|
1774
|
-
const {
|
|
2160
|
+
const { options } = request2;
|
|
1775
2161
|
const listed = await runnerSnapshots.listEntries();
|
|
1776
|
-
if (!listed.ok) return { kind: "
|
|
2162
|
+
if (!listed.ok) return { kind: "local-index-unreadable", ...listed.failure };
|
|
1777
2163
|
const { directory, entries, unreadable } = listed.value;
|
|
1778
2164
|
const now = context.clock.now();
|
|
1779
|
-
const
|
|
1780
|
-
const shows = (entry) => request2.all ||
|
|
2165
|
+
const ofRunner = (entry) => options !== void 0 && entry.runnerName === options.name && entry.region === options.region && entry.runtime === options.runtime;
|
|
2166
|
+
const shows = (entry) => request2.all || options === void 0 || ofRunner(entry);
|
|
1781
2167
|
const shown = entries.filter(shows);
|
|
1782
2168
|
const root = await checkout.repositoryRoot({ cwd: request2.cwd });
|
|
1783
2169
|
const head2 = root.ok ? await checkout.head({ repoRoot: root.value }) : void 0;
|
|
@@ -1788,37 +2174,47 @@ async function inspectSnapshotCache(context, request2) {
|
|
|
1788
2174
|
directory,
|
|
1789
2175
|
checkout: null,
|
|
1790
2176
|
picking: { kind: "none", why: "no-checkout" },
|
|
2177
|
+
snapshotKey: null,
|
|
1791
2178
|
snapshots: shown.map((entry) => unchecked(entry, now)),
|
|
1792
2179
|
unreadable
|
|
1793
2180
|
}
|
|
1794
2181
|
};
|
|
1795
2182
|
}
|
|
1796
2183
|
const repoRoot = root.value;
|
|
1797
|
-
const resolved =
|
|
2184
|
+
const resolved = options === void 0 ? void 0 : await resolveBase(checkout, { repoRoot, baseRefs: options.baseRefs });
|
|
1798
2185
|
if (resolved?.kind === "failed") return { kind: "checkout-failed", failure: resolved.failure };
|
|
1799
|
-
if (
|
|
2186
|
+
if (options === void 0 || resolved === void 0 || resolved.kind !== "resolved") {
|
|
1800
2187
|
return {
|
|
1801
2188
|
kind: "ok",
|
|
1802
2189
|
inspection: {
|
|
1803
2190
|
directory,
|
|
1804
2191
|
checkout: { repoRoot, head: head2.value, mergeBase: null },
|
|
1805
|
-
picking: { kind: "none", why:
|
|
2192
|
+
picking: { kind: "none", why: options === void 0 ? "no-runner" : "no-base" },
|
|
2193
|
+
snapshotKey: null,
|
|
1806
2194
|
snapshots: shown.map((entry) => unchecked(entry, now)),
|
|
1807
2195
|
unreadable
|
|
1808
2196
|
}
|
|
1809
2197
|
};
|
|
1810
2198
|
}
|
|
1811
2199
|
const mergeBase = resolved.base;
|
|
1812
|
-
const
|
|
1813
|
-
if (!
|
|
2200
|
+
const inputs = await snapshotInputsAt(checkout, { repoRoot, base: mergeBase, options });
|
|
2201
|
+
if (!inputs.ok) return { kind: "invalid-runner", path: inputs.path, problem: inputs.problem };
|
|
1814
2202
|
const afterBase = await checkout.commitCount({ repoRoot, from: mergeBase, to: "HEAD" });
|
|
1815
2203
|
if (!afterBase.ok) return { kind: "checkout-failed", failure: afterBase.failure };
|
|
2204
|
+
const ancestorDistances = await resolveAncestorDistances(context, {
|
|
2205
|
+
repoRoot,
|
|
2206
|
+
entries,
|
|
2207
|
+
options,
|
|
2208
|
+
mergeBase
|
|
2209
|
+
});
|
|
2210
|
+
if (!ancestorDistances.ok) return { kind: "checkout-failed", failure: ancestorDistances.failure };
|
|
1816
2211
|
const read = classifySnapshotEntries(context, {
|
|
1817
2212
|
entries,
|
|
1818
|
-
|
|
2213
|
+
options,
|
|
1819
2214
|
base: mergeBase,
|
|
1820
|
-
snapshotKey:
|
|
1821
|
-
commitsAfterBase: afterBase.value
|
|
2215
|
+
snapshotKey: inputs.key,
|
|
2216
|
+
commitsAfterBase: afterBase.value,
|
|
2217
|
+
ancestorDistances: ancestorDistances.value
|
|
1822
2218
|
});
|
|
1823
2219
|
const owners = new Map(read.candidates.map(({ entry }) => [`${entry.teamId}\0${entry.projectId}`, entry]));
|
|
1824
2220
|
const picked = /* @__PURE__ */ new Set();
|
|
@@ -1826,7 +2222,12 @@ async function inspectSnapshotCache(context, request2) {
|
|
|
1826
2222
|
const pick = pickSnapshot(read.candidates, owner);
|
|
1827
2223
|
if (pick !== void 0) picked.add(pick);
|
|
1828
2224
|
}
|
|
1829
|
-
const place = historyPlacer(context, {
|
|
2225
|
+
const place = historyPlacer(context, {
|
|
2226
|
+
repoRoot,
|
|
2227
|
+
mergeBase,
|
|
2228
|
+
commitsAfterBase: afterBase.value,
|
|
2229
|
+
ancestorDistances: ancestorDistances.value
|
|
2230
|
+
});
|
|
1830
2231
|
const snapshots = [];
|
|
1831
2232
|
for (const verdict of read.verdicts) {
|
|
1832
2233
|
const { entry } = verdict;
|
|
@@ -1838,6 +2239,7 @@ async function inspectSnapshotCache(context, request2) {
|
|
|
1838
2239
|
entry,
|
|
1839
2240
|
inHistory: true,
|
|
1840
2241
|
builtBehind: candidate.builtBehind,
|
|
2242
|
+
commitsBehindMergeBase: candidate.commitsBehindMergeBase,
|
|
1841
2243
|
expired,
|
|
1842
2244
|
picked: picked.has(candidate),
|
|
1843
2245
|
reason: null
|
|
@@ -1849,17 +2251,23 @@ async function inspectSnapshotCache(context, request2) {
|
|
|
1849
2251
|
snapshots.push({
|
|
1850
2252
|
entry,
|
|
1851
2253
|
...placed.value,
|
|
2254
|
+
commitsBehindMergeBase: null,
|
|
1852
2255
|
expired,
|
|
1853
2256
|
picked: false,
|
|
1854
|
-
reason: verdict.kind === "rejected" ? verdict.rejection.reason : "other-
|
|
2257
|
+
reason: verdict.kind === "rejected" ? verdict.rejection.reason : "other-runner"
|
|
1855
2258
|
});
|
|
1856
2259
|
}
|
|
1857
2260
|
return {
|
|
1858
2261
|
kind: "ok",
|
|
1859
2262
|
inspection: {
|
|
1860
2263
|
directory,
|
|
1861
|
-
checkout: {
|
|
1862
|
-
|
|
2264
|
+
checkout: {
|
|
2265
|
+
repoRoot,
|
|
2266
|
+
head: head2.value,
|
|
2267
|
+
mergeBase: { commit: mergeBase, ref: resolved.ref, commitsAfterBase: afterBase.value }
|
|
2268
|
+
},
|
|
2269
|
+
picking: { kind: "runner", runner: options.name },
|
|
2270
|
+
snapshotKey: inputs.key,
|
|
1863
2271
|
snapshots,
|
|
1864
2272
|
unreadable
|
|
1865
2273
|
}
|
|
@@ -1870,6 +2278,7 @@ function unchecked(entry, now) {
|
|
|
1870
2278
|
entry,
|
|
1871
2279
|
inHistory: null,
|
|
1872
2280
|
builtBehind: null,
|
|
2281
|
+
commitsBehindMergeBase: null,
|
|
1873
2282
|
expired: isExpiredEntry(entry, now),
|
|
1874
2283
|
picked: false,
|
|
1875
2284
|
reason: null
|
|
@@ -1877,8 +2286,14 @@ function unchecked(entry, now) {
|
|
|
1877
2286
|
}
|
|
1878
2287
|
function historyPlacer(context, request2) {
|
|
1879
2288
|
const { repoRoot } = request2;
|
|
1880
|
-
const known =
|
|
1881
|
-
[request2.mergeBase, { inHistory: true, builtBehind: request2.commitsAfterBase }]
|
|
2289
|
+
const known = new Map([
|
|
2290
|
+
[request2.mergeBase, { inHistory: true, builtBehind: request2.commitsAfterBase }],
|
|
2291
|
+
...Object.entries(request2.ancestorDistances).map(
|
|
2292
|
+
([base, commitsBehindMergeBase]) => [
|
|
2293
|
+
base,
|
|
2294
|
+
{ inHistory: true, builtBehind: request2.commitsAfterBase + commitsBehindMergeBase }
|
|
2295
|
+
]
|
|
2296
|
+
)
|
|
1882
2297
|
]);
|
|
1883
2298
|
return async (base) => {
|
|
1884
2299
|
const answer = known.get(base);
|
|
@@ -1896,6 +2311,277 @@ function historyPlacer(context, request2) {
|
|
|
1896
2311
|
};
|
|
1897
2312
|
}
|
|
1898
2313
|
|
|
2314
|
+
// src/runner/shared-snapshot-list.ts
|
|
2315
|
+
async function listSharedSnapshots(context, request2, signal) {
|
|
2316
|
+
const { runnerSandboxes, clock } = context;
|
|
2317
|
+
const { access, runner, snapshotKey: snapshotKey2 } = request2;
|
|
2318
|
+
const bucket = sharedSnapshotBucket({
|
|
2319
|
+
teamId: access.teamId,
|
|
2320
|
+
projectId: access.projectId,
|
|
2321
|
+
region: runner.region,
|
|
2322
|
+
runtime: runner.runtime,
|
|
2323
|
+
runnerName: runner.name,
|
|
2324
|
+
snapshotKey: snapshotKey2
|
|
2325
|
+
});
|
|
2326
|
+
const listed = await runnerSandboxes.listNamedSandboxes(
|
|
2327
|
+
access,
|
|
2328
|
+
{ namePrefix: sharedSnapshotSandboxPrefix(bucket) },
|
|
2329
|
+
signal
|
|
2330
|
+
);
|
|
2331
|
+
if (!listed.ok) {
|
|
2332
|
+
return listed.failure.kind === "aborted" ? { kind: "aborted" } : { kind: "failed", message: listed.failure.message };
|
|
2333
|
+
}
|
|
2334
|
+
const now = clock.now();
|
|
2335
|
+
const matched = [];
|
|
2336
|
+
for (const row of listed.value) {
|
|
2337
|
+
const parsed = parseSharedSnapshotSandboxName(row.name);
|
|
2338
|
+
if (parsed === null || parsed.bucket !== bucket) continue;
|
|
2339
|
+
matched.push({ row, base: parsed.base });
|
|
2340
|
+
}
|
|
2341
|
+
let stop = false;
|
|
2342
|
+
const outcomes = await runLimited(
|
|
2343
|
+
matched.length,
|
|
2344
|
+
INDEX_CONCURRENCY,
|
|
2345
|
+
() => !stop && signal?.aborted !== true,
|
|
2346
|
+
async (index) => {
|
|
2347
|
+
const { row, base } = matched[index];
|
|
2348
|
+
const unverified = classifyUnverifiedSharedSandbox(row);
|
|
2349
|
+
if (unverified.kind === "settled") {
|
|
2350
|
+
return {
|
|
2351
|
+
kind: "entry",
|
|
2352
|
+
entry: indexEntryOf(row, base, {
|
|
2353
|
+
status: unverified.status,
|
|
2354
|
+
snapshotId: unverified.status === "no-snapshot" ? void 0 : row.currentSnapshotId,
|
|
2355
|
+
snapshotStatus: void 0,
|
|
2356
|
+
createdAt: row.createdAt,
|
|
2357
|
+
expiresAt: row.tags["expires-at"],
|
|
2358
|
+
expired: false
|
|
2359
|
+
})
|
|
2360
|
+
};
|
|
2361
|
+
}
|
|
2362
|
+
const verified = await runnerSandboxes.getSnapshot(access, { snapshotId: unverified.snapshotId }, signal);
|
|
2363
|
+
if (!verified.ok) {
|
|
2364
|
+
stop = true;
|
|
2365
|
+
return verified.failure.kind === "aborted" ? { kind: "aborted" } : { kind: "failed", message: verified.failure.message };
|
|
2366
|
+
}
|
|
2367
|
+
const classified = classifyVerifiedSharedSnapshot(
|
|
2368
|
+
{ ...row, currentSnapshotId: unverified.snapshotId },
|
|
2369
|
+
verified.value,
|
|
2370
|
+
now
|
|
2371
|
+
);
|
|
2372
|
+
return {
|
|
2373
|
+
kind: "entry",
|
|
2374
|
+
entry: indexEntryOf(row, base, {
|
|
2375
|
+
status: classified.status,
|
|
2376
|
+
snapshotId: classified.snapshotId,
|
|
2377
|
+
snapshotStatus: classified.snapshotStatus,
|
|
2378
|
+
createdAt: classified.createdAt,
|
|
2379
|
+
expiresAt: classified.expiresAt,
|
|
2380
|
+
expired: classified.status === "expired"
|
|
2381
|
+
})
|
|
2382
|
+
};
|
|
2383
|
+
}
|
|
2384
|
+
);
|
|
2385
|
+
if (signal?.aborted === true) return { kind: "aborted" };
|
|
2386
|
+
const entries = [];
|
|
2387
|
+
for (const outcome of outcomes) {
|
|
2388
|
+
if (outcome === void 0) continue;
|
|
2389
|
+
if (outcome.kind === "aborted") return { kind: "aborted" };
|
|
2390
|
+
if (outcome.kind === "failed") return outcome;
|
|
2391
|
+
entries.push(outcome.entry);
|
|
2392
|
+
}
|
|
2393
|
+
return { kind: "ok", bucket, entries };
|
|
2394
|
+
}
|
|
2395
|
+
function indexEntryOf(row, base, fields) {
|
|
2396
|
+
return {
|
|
2397
|
+
sandboxName: row.name,
|
|
2398
|
+
base,
|
|
2399
|
+
sandboxStatus: row.status,
|
|
2400
|
+
sandboxCreatedAt: row.createdAt,
|
|
2401
|
+
...fields
|
|
2402
|
+
};
|
|
2403
|
+
}
|
|
2404
|
+
async function pickSnapshotAcrossIndexes(context, request2) {
|
|
2405
|
+
const { checkout } = context;
|
|
2406
|
+
const { repoRoot, mergeBase, commitsAfterBase, owner, local, entries } = request2;
|
|
2407
|
+
const owned = (snapshot) => snapshot.entry.teamId === owner.teamId && snapshot.entry.projectId === owner.projectId;
|
|
2408
|
+
const localPick = local.find((snapshot) => snapshot.picked && owned(snapshot));
|
|
2409
|
+
const behindMergeBaseByBase = /* @__PURE__ */ new Map([[mergeBase, 0]]);
|
|
2410
|
+
const qualifying = [];
|
|
2411
|
+
for (const entry of entries) {
|
|
2412
|
+
if (entry.status !== "ready") continue;
|
|
2413
|
+
let commitsBehindMergeBase = behindMergeBaseByBase.get(entry.base);
|
|
2414
|
+
if (commitsBehindMergeBase === void 0) {
|
|
2415
|
+
const ancestor = await checkout.contains({ repoRoot, ancestor: entry.base, descendant: mergeBase });
|
|
2416
|
+
if (!ancestor.ok) return { kind: "checkout-failed", failure: ancestor.failure };
|
|
2417
|
+
commitsBehindMergeBase = null;
|
|
2418
|
+
if (ancestor.value) {
|
|
2419
|
+
const counted = await checkout.commitCount({ repoRoot, from: entry.base, to: mergeBase });
|
|
2420
|
+
if (!counted.ok) return { kind: "checkout-failed", failure: counted.failure };
|
|
2421
|
+
commitsBehindMergeBase = counted.value;
|
|
2422
|
+
}
|
|
2423
|
+
behindMergeBaseByBase.set(entry.base, commitsBehindMergeBase);
|
|
2424
|
+
}
|
|
2425
|
+
if (commitsBehindMergeBase !== null) qualifying.push({ entry, commitsBehindMergeBase });
|
|
2426
|
+
}
|
|
2427
|
+
const best = qualifying.toSorted(
|
|
2428
|
+
(a, b) => compareSnapshotCandidates(
|
|
2429
|
+
{
|
|
2430
|
+
commitsBehindMergeBase: a.commitsBehindMergeBase,
|
|
2431
|
+
createdAt: a.entry.sandboxCreatedAt,
|
|
2432
|
+
tieBreaker: a.entry.sandboxName
|
|
2433
|
+
},
|
|
2434
|
+
{
|
|
2435
|
+
commitsBehindMergeBase: b.commitsBehindMergeBase,
|
|
2436
|
+
createdAt: b.entry.sandboxCreatedAt,
|
|
2437
|
+
tieBreaker: b.entry.sandboxName
|
|
2438
|
+
}
|
|
2439
|
+
)
|
|
2440
|
+
)[0];
|
|
2441
|
+
const sharedPick = best !== void 0 && sharedBeatsLocal(best.commitsBehindMergeBase, localPick?.commitsBehindMergeBase ?? void 0) ? best.entry : void 0;
|
|
2442
|
+
const readyBehind = new Map(qualifying.map(({ entry, commitsBehindMergeBase }) => [entry, commitsBehindMergeBase]));
|
|
2443
|
+
return {
|
|
2444
|
+
kind: "ok",
|
|
2445
|
+
local: sharedPick === void 0 || localPick === void 0 ? local : local.map((snapshot) => snapshot === localPick ? { ...snapshot, picked: false } : snapshot),
|
|
2446
|
+
shared: entries.map((entry) => {
|
|
2447
|
+
const commitsBehindMergeBase = readyBehind.get(entry);
|
|
2448
|
+
return {
|
|
2449
|
+
entry,
|
|
2450
|
+
picked: entry === sharedPick,
|
|
2451
|
+
builtBehind: commitsBehindMergeBase === void 0 ? null : commitsAfterBase + commitsBehindMergeBase
|
|
2452
|
+
};
|
|
2453
|
+
})
|
|
2454
|
+
};
|
|
2455
|
+
}
|
|
2456
|
+
|
|
2457
|
+
// src/runner/shared-snapshot-prune.ts
|
|
2458
|
+
async function pruneSharedSnapshots(context, request2, signal) {
|
|
2459
|
+
const { runnerSandboxes, clock } = context;
|
|
2460
|
+
const { access, dryRun } = request2;
|
|
2461
|
+
const listed = await runnerSandboxes.listNamedSandboxes(
|
|
2462
|
+
access,
|
|
2463
|
+
{ namePrefix: SHARED_SNAPSHOT_SANDBOX_PREFIX },
|
|
2464
|
+
signal
|
|
2465
|
+
);
|
|
2466
|
+
if (!listed.ok) {
|
|
2467
|
+
return listed.failure.kind === "aborted" ? { kind: "aborted" } : { kind: "failed", message: listed.failure.message };
|
|
2468
|
+
}
|
|
2469
|
+
const validRows = listed.value.filter((row) => parseSharedSnapshotSandboxName(row.name) !== null);
|
|
2470
|
+
const now = clock.now();
|
|
2471
|
+
const nowMs = now.getTime();
|
|
2472
|
+
let aborted = false;
|
|
2473
|
+
const checked = await runLimited(
|
|
2474
|
+
validRows.length,
|
|
2475
|
+
INDEX_CONCURRENCY,
|
|
2476
|
+
() => !aborted && !isAborted(signal),
|
|
2477
|
+
async (index) => {
|
|
2478
|
+
const row = validRows[index];
|
|
2479
|
+
const unverified = classifyUnverifiedSharedSandbox(row);
|
|
2480
|
+
if (unverified.kind === "settled") {
|
|
2481
|
+
switch (unverified.status) {
|
|
2482
|
+
case "building":
|
|
2483
|
+
return { kind: "skip" };
|
|
2484
|
+
case "failed":
|
|
2485
|
+
return { kind: "mark", entry: { name: row.name, reason: "failed" } };
|
|
2486
|
+
case "no-snapshot":
|
|
2487
|
+
return { kind: "mark", entry: { name: row.name, reason: "no-snapshot" } };
|
|
2488
|
+
}
|
|
2489
|
+
}
|
|
2490
|
+
const tagExpiresAt = row.tags["expires-at"];
|
|
2491
|
+
if (tagExpiresAt !== void 0) {
|
|
2492
|
+
const tagMs = Date.parse(tagExpiresAt);
|
|
2493
|
+
if (!Number.isNaN(tagMs) && tagMs > nowMs) return { kind: "skip" };
|
|
2494
|
+
}
|
|
2495
|
+
const verified = await runnerSandboxes.getSnapshot(access, { snapshotId: unverified.snapshotId }, signal);
|
|
2496
|
+
if (!verified.ok) {
|
|
2497
|
+
if (verified.failure.kind === "aborted") {
|
|
2498
|
+
aborted = true;
|
|
2499
|
+
return void 0;
|
|
2500
|
+
}
|
|
2501
|
+
return { kind: "failed", failure: { name: row.name, message: verified.failure.message } };
|
|
2502
|
+
}
|
|
2503
|
+
const classified = classifyVerifiedSharedSnapshot(
|
|
2504
|
+
{ ...row, currentSnapshotId: unverified.snapshotId },
|
|
2505
|
+
verified.value,
|
|
2506
|
+
now
|
|
2507
|
+
);
|
|
2508
|
+
switch (classified.status) {
|
|
2509
|
+
case "missing":
|
|
2510
|
+
return { kind: "mark", entry: { name: row.name, reason: "missing", snapshotId: unverified.snapshotId } };
|
|
2511
|
+
case "expired":
|
|
2512
|
+
return { kind: "mark", entry: { name: row.name, reason: "expired", snapshotId: unverified.snapshotId } };
|
|
2513
|
+
case "ready":
|
|
2514
|
+
case "expires-soon":
|
|
2515
|
+
case "unknown-expiry":
|
|
2516
|
+
return { kind: "skip" };
|
|
2517
|
+
}
|
|
2518
|
+
}
|
|
2519
|
+
);
|
|
2520
|
+
if (aborted || isAborted(signal)) return { kind: "aborted" };
|
|
2521
|
+
const marked = [];
|
|
2522
|
+
const failed = [];
|
|
2523
|
+
let skipped = 0;
|
|
2524
|
+
for (const outcome of checked) {
|
|
2525
|
+
if (outcome === void 0) continue;
|
|
2526
|
+
switch (outcome.kind) {
|
|
2527
|
+
case "skip":
|
|
2528
|
+
skipped += 1;
|
|
2529
|
+
break;
|
|
2530
|
+
case "mark":
|
|
2531
|
+
marked.push(outcome.entry);
|
|
2532
|
+
break;
|
|
2533
|
+
case "failed":
|
|
2534
|
+
failed.push(outcome.failure);
|
|
2535
|
+
break;
|
|
2536
|
+
}
|
|
2537
|
+
}
|
|
2538
|
+
const deleted = [];
|
|
2539
|
+
if (dryRun) {
|
|
2540
|
+
deleted.push(...marked);
|
|
2541
|
+
} else {
|
|
2542
|
+
const deleteResults = await runLimited(
|
|
2543
|
+
marked.length,
|
|
2544
|
+
INDEX_CONCURRENCY,
|
|
2545
|
+
() => !aborted && !isAborted(signal),
|
|
2546
|
+
async (index) => {
|
|
2547
|
+
const entry = marked[index];
|
|
2548
|
+
const removed = await runnerSandboxes.deleteNamedSandbox(access, { name: entry.name }, signal);
|
|
2549
|
+
if (removed.ok) return { kind: "deleted", entry };
|
|
2550
|
+
if (removed.failure.kind === "aborted") {
|
|
2551
|
+
aborted = true;
|
|
2552
|
+
return void 0;
|
|
2553
|
+
}
|
|
2554
|
+
return { kind: "failed", failure: { name: entry.name, message: removed.failure.message } };
|
|
2555
|
+
}
|
|
2556
|
+
);
|
|
2557
|
+
if (aborted || isAborted(signal)) return { kind: "aborted" };
|
|
2558
|
+
for (const outcome of deleteResults) {
|
|
2559
|
+
if (outcome === void 0) continue;
|
|
2560
|
+
switch (outcome.kind) {
|
|
2561
|
+
case "deleted":
|
|
2562
|
+
deleted.push(outcome.entry);
|
|
2563
|
+
break;
|
|
2564
|
+
case "failed":
|
|
2565
|
+
failed.push(outcome.failure);
|
|
2566
|
+
break;
|
|
2567
|
+
}
|
|
2568
|
+
}
|
|
2569
|
+
}
|
|
2570
|
+
return {
|
|
2571
|
+
kind: "ok",
|
|
2572
|
+
summary: {
|
|
2573
|
+
scanned: validRows.length,
|
|
2574
|
+
deleted,
|
|
2575
|
+
skipped,
|
|
2576
|
+
failed,
|
|
2577
|
+
dryRun
|
|
2578
|
+
}
|
|
2579
|
+
};
|
|
2580
|
+
}
|
|
2581
|
+
function isAborted(signal) {
|
|
2582
|
+
return signal?.aborted === true;
|
|
2583
|
+
}
|
|
2584
|
+
|
|
1899
2585
|
// src/runner/live/checkout-gateway.ts
|
|
1900
2586
|
import { execFile, spawn } from "node:child_process";
|
|
1901
2587
|
|
|
@@ -2119,6 +2805,9 @@ function apiStatus(error) {
|
|
|
2119
2805
|
function isAbortError(error) {
|
|
2120
2806
|
return typeof error === "object" && error !== null && error.name === "AbortError";
|
|
2121
2807
|
}
|
|
2808
|
+
function isNameTakenError(error, message) {
|
|
2809
|
+
return apiStatus(error) === 400 && /already exists/i.test(message);
|
|
2810
|
+
}
|
|
2122
2811
|
function sandboxFailure(error, signal) {
|
|
2123
2812
|
if (signal?.aborted === true || isAbortError(error)) return { kind: "aborted" };
|
|
2124
2813
|
return { kind: "api", status: apiStatus(error), message: error instanceof Error ? error.message : String(error) };
|
|
@@ -2128,7 +2817,9 @@ function sandboxFailure(error, signal) {
|
|
|
2128
2817
|
var TERMINATE_GRACE_MS = 1e4;
|
|
2129
2818
|
var KILL_GRACE_MS = 5e3;
|
|
2130
2819
|
var STDERR_MESSAGE_CHARS = 1e3;
|
|
2820
|
+
var NOT_FOUND_STATUS = 404;
|
|
2131
2821
|
var SNAPSHOT_GONE_STATUS = 410;
|
|
2822
|
+
var LIST_SANDBOXES_PAGE_LIMIT = 50;
|
|
2132
2823
|
var DROP_CAPABILITIES_ARGS = [
|
|
2133
2824
|
"--inh-caps=-all",
|
|
2134
2825
|
"--ambient-caps=-all",
|
|
@@ -2156,14 +2847,18 @@ function liveRunnerSandboxGateway() {
|
|
|
2156
2847
|
const { Sandbox } = await sdk();
|
|
2157
2848
|
const sandbox = await Sandbox.create({
|
|
2158
2849
|
...credentials(access),
|
|
2159
|
-
// oxlint-disable-next-line typescript/no-deprecated -- the
|
|
2850
|
+
// oxlint-disable-next-line typescript/no-deprecated -- the runner options name a runtime; moving to `image` changes the config file's format.
|
|
2160
2851
|
runtime: request2.runtime,
|
|
2852
|
+
...request2.name === void 0 ? {} : { name: request2.name },
|
|
2161
2853
|
...placement(request2),
|
|
2162
2854
|
...signal === void 0 ? {} : { signal }
|
|
2163
2855
|
});
|
|
2164
2856
|
return { ok: true, value: adopt(sandbox, "snapshot-build", request2.timeoutMs) };
|
|
2165
2857
|
} catch (error) {
|
|
2166
|
-
|
|
2858
|
+
const failure = sandboxFailure(error, signal);
|
|
2859
|
+
if (request2.name !== void 0 && failure.kind === "api" && isNameTakenError(error, failure.message))
|
|
2860
|
+
return { ok: false, failure: { kind: "name-taken", name: request2.name, message: failure.message } };
|
|
2861
|
+
return { ok: false, failure };
|
|
2167
2862
|
}
|
|
2168
2863
|
},
|
|
2169
2864
|
async startRunnerSandbox(access, request2, signal) {
|
|
@@ -2183,6 +2878,112 @@ function liveRunnerSandboxGateway() {
|
|
|
2183
2878
|
return { ok: false, failure };
|
|
2184
2879
|
}
|
|
2185
2880
|
},
|
|
2881
|
+
async getNamedSandbox(access, request2, signal) {
|
|
2882
|
+
if (isAborted2(signal)) return { ok: false, failure: { kind: "aborted" } };
|
|
2883
|
+
try {
|
|
2884
|
+
const { Sandbox } = await sdk();
|
|
2885
|
+
const sandbox = await Sandbox.get({
|
|
2886
|
+
...credentials(access),
|
|
2887
|
+
name: request2.name,
|
|
2888
|
+
...signal === void 0 ? {} : { signal }
|
|
2889
|
+
});
|
|
2890
|
+
return {
|
|
2891
|
+
ok: true,
|
|
2892
|
+
value: {
|
|
2893
|
+
kind: "found",
|
|
2894
|
+
sandbox: {
|
|
2895
|
+
name: sandbox.name,
|
|
2896
|
+
status: sandbox.status,
|
|
2897
|
+
currentSnapshotId: sandbox.currentSnapshotId,
|
|
2898
|
+
createdAt: sandbox.createdAt.toISOString(),
|
|
2899
|
+
tags: { ...sandbox.tags }
|
|
2900
|
+
}
|
|
2901
|
+
}
|
|
2902
|
+
};
|
|
2903
|
+
} catch (error) {
|
|
2904
|
+
const failure = sandboxFailure(error, signal);
|
|
2905
|
+
if (failure.kind === "api" && apiStatus(error) === NOT_FOUND_STATUS)
|
|
2906
|
+
return { ok: true, value: { kind: "not-found" } };
|
|
2907
|
+
return { ok: false, failure };
|
|
2908
|
+
}
|
|
2909
|
+
},
|
|
2910
|
+
async listNamedSandboxes(access, request2, signal) {
|
|
2911
|
+
if (isAborted2(signal)) return { ok: false, failure: { kind: "aborted" } };
|
|
2912
|
+
try {
|
|
2913
|
+
const { Sandbox } = await sdk();
|
|
2914
|
+
const paginator = await Sandbox.list({
|
|
2915
|
+
...credentials(access),
|
|
2916
|
+
namePrefix: request2.namePrefix,
|
|
2917
|
+
sortBy: "name",
|
|
2918
|
+
limit: LIST_SANDBOXES_PAGE_LIMIT,
|
|
2919
|
+
...signal === void 0 ? {} : { signal }
|
|
2920
|
+
});
|
|
2921
|
+
const listed = [];
|
|
2922
|
+
for await (const page of paginator.pages()) {
|
|
2923
|
+
if (isAborted2(signal)) return { ok: false, failure: { kind: "aborted" } };
|
|
2924
|
+
for (const item of page.sandboxes) {
|
|
2925
|
+
listed.push({
|
|
2926
|
+
name: item.name,
|
|
2927
|
+
status: item.status,
|
|
2928
|
+
currentSnapshotId: item.currentSnapshotId,
|
|
2929
|
+
createdAt: new Date(item.createdAt).toISOString(),
|
|
2930
|
+
tags: { ...item.tags }
|
|
2931
|
+
});
|
|
2932
|
+
}
|
|
2933
|
+
}
|
|
2934
|
+
return { ok: true, value: listed };
|
|
2935
|
+
} catch (error) {
|
|
2936
|
+
return { ok: false, failure: sandboxFailure(error, signal) };
|
|
2937
|
+
}
|
|
2938
|
+
},
|
|
2939
|
+
async getSnapshot(access, request2, signal) {
|
|
2940
|
+
if (isAborted2(signal)) return { ok: false, failure: { kind: "aborted" } };
|
|
2941
|
+
try {
|
|
2942
|
+
const { Snapshot } = await sdk();
|
|
2943
|
+
const snapshot = await Snapshot.get({
|
|
2944
|
+
...credentials(access),
|
|
2945
|
+
snapshotId: request2.snapshotId,
|
|
2946
|
+
...signal === void 0 ? {} : { signal }
|
|
2947
|
+
});
|
|
2948
|
+
return {
|
|
2949
|
+
ok: true,
|
|
2950
|
+
value: {
|
|
2951
|
+
kind: "found",
|
|
2952
|
+
snapshot: {
|
|
2953
|
+
snapshotId: snapshot.snapshotId,
|
|
2954
|
+
status: snapshot.status,
|
|
2955
|
+
createdAt: snapshot.createdAt.toISOString(),
|
|
2956
|
+
expiresAt: snapshot.expiresAt?.toISOString(),
|
|
2957
|
+
sizeBytes: snapshot.sizeBytes
|
|
2958
|
+
}
|
|
2959
|
+
}
|
|
2960
|
+
};
|
|
2961
|
+
} catch (error) {
|
|
2962
|
+
const failure = sandboxFailure(error, signal);
|
|
2963
|
+
const status = apiStatus(error);
|
|
2964
|
+
if (failure.kind === "api" && (status === NOT_FOUND_STATUS || status === SNAPSHOT_GONE_STATUS))
|
|
2965
|
+
return { ok: true, value: { kind: "not-found" } };
|
|
2966
|
+
return { ok: false, failure };
|
|
2967
|
+
}
|
|
2968
|
+
},
|
|
2969
|
+
async deleteNamedSandbox(access, request2, signal) {
|
|
2970
|
+
if (isAborted2(signal)) return { ok: false, failure: { kind: "aborted" } };
|
|
2971
|
+
try {
|
|
2972
|
+
const { Sandbox } = await sdk();
|
|
2973
|
+
const sandbox = await Sandbox.get({
|
|
2974
|
+
...credentials(access),
|
|
2975
|
+
name: request2.name,
|
|
2976
|
+
...signal === void 0 ? {} : { signal }
|
|
2977
|
+
});
|
|
2978
|
+
if (isAborted2(signal)) return { ok: false, failure: { kind: "aborted" } };
|
|
2979
|
+
await sandbox.delete({ deleteOrphanSnapshots: false, ...signal === void 0 ? {} : { signal } });
|
|
2980
|
+
return { ok: true };
|
|
2981
|
+
} catch (error) {
|
|
2982
|
+
const failure = sandboxFailure(error, signal);
|
|
2983
|
+
if (failure.kind === "api" && apiStatus(error) === NOT_FOUND_STATUS) return { ok: true };
|
|
2984
|
+
return { ok: false, failure };
|
|
2985
|
+
}
|
|
2986
|
+
},
|
|
2186
2987
|
async upload(sandbox, files, signal) {
|
|
2187
2988
|
const holder = holding(sandbox);
|
|
2188
2989
|
try {
|
|
@@ -2194,6 +2995,16 @@ function liveRunnerSandboxGateway() {
|
|
|
2194
2995
|
return { ok: false, failure: sandboxFailure(error, signal) };
|
|
2195
2996
|
}
|
|
2196
2997
|
},
|
|
2998
|
+
async placeBaseFiles(sandbox, files, signal) {
|
|
2999
|
+
if (files.length === 0) return { ok: true };
|
|
3000
|
+
const holder = holding(sandbox);
|
|
3001
|
+
try {
|
|
3002
|
+
await holder.sandbox.writeFiles(writes(SANDBOX_ROOT, files), signal === void 0 ? void 0 : { signal });
|
|
3003
|
+
return { ok: true };
|
|
3004
|
+
} catch (error) {
|
|
3005
|
+
return { ok: false, failure: sandboxFailure(error, signal) };
|
|
3006
|
+
}
|
|
3007
|
+
},
|
|
2197
3008
|
async runScript(sandbox, request2, onOutput, signal) {
|
|
2198
3009
|
const holder = holding(sandbox);
|
|
2199
3010
|
try {
|
|
@@ -2312,7 +3123,7 @@ function liveRunnerSandboxGateway() {
|
|
|
2312
3123
|
command.kill("SIGTERM").catch(() => {
|
|
2313
3124
|
});
|
|
2314
3125
|
};
|
|
2315
|
-
if (
|
|
3126
|
+
if (isAborted2(signal)) end();
|
|
2316
3127
|
else signal?.addEventListener("abort", end, { once: true });
|
|
2317
3128
|
let stderr = "";
|
|
2318
3129
|
try {
|
|
@@ -2386,7 +3197,7 @@ function liveRunnerSandboxGateway() {
|
|
|
2386
3197
|
holder.keeping = true;
|
|
2387
3198
|
if (!await settledUnlessAborted(holder.starting, signal)) return { ok: false, failure: { kind: "aborted" } };
|
|
2388
3199
|
const stillRunning = (await Promise.all([...holder.running].map((command) => endProcess(holder, command, signal)))).filter((ended) => !ended).length;
|
|
2389
|
-
if (
|
|
3200
|
+
if (isAborted2(signal)) return { ok: false, failure: { kind: "aborted" } };
|
|
2390
3201
|
if (stillRunning > 0)
|
|
2391
3202
|
return {
|
|
2392
3203
|
ok: false,
|
|
@@ -2408,7 +3219,7 @@ function liveRunnerSandboxGateway() {
|
|
|
2408
3219
|
},
|
|
2409
3220
|
async stop(sandbox, signal) {
|
|
2410
3221
|
const holder = holding(sandbox);
|
|
2411
|
-
if (
|
|
3222
|
+
if (isAborted2(signal)) return { ok: false, failure: { kind: "aborted" } };
|
|
2412
3223
|
try {
|
|
2413
3224
|
if (signal === void 0) await holder.sandbox.stop();
|
|
2414
3225
|
else await holder.sandbox.stop({ signal });
|
|
@@ -2419,7 +3230,7 @@ function liveRunnerSandboxGateway() {
|
|
|
2419
3230
|
},
|
|
2420
3231
|
async delete(sandbox, signal) {
|
|
2421
3232
|
const holder = holding(sandbox);
|
|
2422
|
-
if (
|
|
3233
|
+
if (isAborted2(signal)) return { ok: false, failure: { kind: "aborted" } };
|
|
2423
3234
|
try {
|
|
2424
3235
|
await holder.sandbox.delete({ deleteOrphanSnapshots: false, ...signal === void 0 ? {} : { signal } });
|
|
2425
3236
|
return { ok: true };
|
|
@@ -2530,7 +3341,7 @@ async function endProcess(holder, command, signal) {
|
|
|
2530
3341
|
["SIGTERM", TERMINATE_GRACE_MS],
|
|
2531
3342
|
["SIGKILL", KILL_GRACE_MS]
|
|
2532
3343
|
]) {
|
|
2533
|
-
if (
|
|
3344
|
+
if (isAborted2(signal)) return false;
|
|
2534
3345
|
await withinLimit(graceMs, signal, (limit) => command.kill(kill, { abortSignal: limit })).catch(() => void 0);
|
|
2535
3346
|
if (await endsWithin(command, graceMs, signal)) {
|
|
2536
3347
|
holder.running.delete(command);
|
|
@@ -2548,7 +3359,7 @@ async function endsWithin(command, ms, signal) {
|
|
|
2548
3359
|
}
|
|
2549
3360
|
}
|
|
2550
3361
|
async function withinLimit(ms, signal, call) {
|
|
2551
|
-
if (
|
|
3362
|
+
if (isAborted2(signal)) throw new DOMException("This operation was aborted", "AbortError");
|
|
2552
3363
|
const limit = new AbortController();
|
|
2553
3364
|
const timer = setTimeout(() => limit.abort(), ms);
|
|
2554
3365
|
const onAbort = () => limit.abort();
|
|
@@ -2566,14 +3377,14 @@ async function withinLimit(ms, signal, call) {
|
|
|
2566
3377
|
}
|
|
2567
3378
|
}
|
|
2568
3379
|
async function settledUnlessAborted(tasks, signal) {
|
|
2569
|
-
if (
|
|
3380
|
+
if (isAborted2(signal)) return false;
|
|
2570
3381
|
if (signal === void 0 || tasks.size === 0) {
|
|
2571
3382
|
await Promise.allSettled(tasks);
|
|
2572
3383
|
return true;
|
|
2573
3384
|
}
|
|
2574
3385
|
return await untilAborted(Promise.allSettled(tasks), signal) !== ABORTED;
|
|
2575
3386
|
}
|
|
2576
|
-
function
|
|
3387
|
+
function isAborted2(signal) {
|
|
2577
3388
|
return signal?.aborted === true;
|
|
2578
3389
|
}
|
|
2579
3390
|
|
|
@@ -2620,22 +3431,22 @@ function liveRunnerTerminal(options) {
|
|
|
2620
3431
|
};
|
|
2621
3432
|
}
|
|
2622
3433
|
|
|
2623
|
-
// src/runner/live/snapshot-
|
|
3434
|
+
// src/runner/live/snapshot-index-gateway.ts
|
|
2624
3435
|
import { randomBytes } from "node:crypto";
|
|
2625
3436
|
import { mkdir, readdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
|
|
2626
3437
|
import { join } from "node:path";
|
|
2627
3438
|
|
|
2628
3439
|
// src/runner/live/snapshot-records.ts
|
|
2629
|
-
import { z as
|
|
2630
|
-
var isoTime =
|
|
2631
|
-
var nonEmpty =
|
|
2632
|
-
var entrySchema =
|
|
2633
|
-
version:
|
|
3440
|
+
import { z as z3 } from "zod";
|
|
3441
|
+
var isoTime = z3.string().refine((value) => !Number.isNaN(Date.parse(value)), { message: "not a time" });
|
|
3442
|
+
var nonEmpty = z3.string().min(1);
|
|
3443
|
+
var entrySchema = z3.object({
|
|
3444
|
+
version: z3.literal(1),
|
|
2634
3445
|
teamId: nonEmpty,
|
|
2635
3446
|
projectId: nonEmpty,
|
|
2636
3447
|
region: nonEmpty,
|
|
2637
3448
|
runtime: nonEmpty,
|
|
2638
|
-
|
|
3449
|
+
runnerName: nonEmpty,
|
|
2639
3450
|
snapshotKey: nonEmpty,
|
|
2640
3451
|
base: nonEmpty,
|
|
2641
3452
|
snapshotId: nonEmpty,
|
|
@@ -2661,7 +3472,7 @@ function parseSnapshotEntry(text) {
|
|
|
2661
3472
|
return { ok: true, value: entry };
|
|
2662
3473
|
}
|
|
2663
3474
|
function snapshotEntryText(entry) {
|
|
2664
|
-
const { teamId, projectId, region, runtime,
|
|
3475
|
+
const { teamId, projectId, region, runtime, runnerName, snapshotKey: snapshotKey2, base } = entry;
|
|
2665
3476
|
const { snapshotId, createdAt, expiresAt } = entry;
|
|
2666
3477
|
const record = {
|
|
2667
3478
|
version: 1,
|
|
@@ -2669,7 +3480,7 @@ function snapshotEntryText(entry) {
|
|
|
2669
3480
|
projectId,
|
|
2670
3481
|
region,
|
|
2671
3482
|
runtime,
|
|
2672
|
-
|
|
3483
|
+
runnerName,
|
|
2673
3484
|
snapshotKey: snapshotKey2,
|
|
2674
3485
|
base,
|
|
2675
3486
|
snapshotId,
|
|
@@ -2680,11 +3491,11 @@ function snapshotEntryText(entry) {
|
|
|
2680
3491
|
`;
|
|
2681
3492
|
}
|
|
2682
3493
|
|
|
2683
|
-
// src/runner/live/snapshot-
|
|
3494
|
+
// src/runner/live/snapshot-index-gateway.ts
|
|
2684
3495
|
var DIRECTORY_MODE = 448;
|
|
2685
3496
|
var FILE_MODE = 384;
|
|
2686
3497
|
var ENTRY_FILE_NAME = /^[0-9a-f]{32}\.json$/;
|
|
2687
|
-
function
|
|
3498
|
+
function liveRunnerSnapshotIndexGateway(options) {
|
|
2688
3499
|
const { directory } = options;
|
|
2689
3500
|
return {
|
|
2690
3501
|
listEntries: () => listEntries(directory),
|
|
@@ -2692,7 +3503,7 @@ function liveRunnerSnapshotCacheGateway(options) {
|
|
|
2692
3503
|
removeEntry: (entry) => removeEntry(directory, entry)
|
|
2693
3504
|
};
|
|
2694
3505
|
}
|
|
2695
|
-
function
|
|
3506
|
+
function unavailableRunnerSnapshotIndexGateway(location, reason) {
|
|
2696
3507
|
const failure = { path: location, message: reason };
|
|
2697
3508
|
const fail = async () => ({ ok: false, failure });
|
|
2698
3509
|
return { listEntries: fail, writeEntry: fail, removeEntry: fail };
|
|
@@ -2765,43 +3576,50 @@ function failureAt(path, error) {
|
|
|
2765
3576
|
// src/runner/prepare.ts
|
|
2766
3577
|
async function prepareRunner(context, request2) {
|
|
2767
3578
|
const { checkout } = context;
|
|
2768
|
-
const {
|
|
3579
|
+
const { options } = request2;
|
|
2769
3580
|
const root = await checkout.repositoryRoot({ cwd: request2.cwd });
|
|
2770
3581
|
if (!root.ok) return { kind: "checkout-failed", failure: root.failure };
|
|
2771
3582
|
const repoRoot = root.value;
|
|
2772
|
-
const resolved = await resolveBase(checkout, { repoRoot, baseRefs:
|
|
3583
|
+
const resolved = await resolveBase(checkout, { repoRoot, baseRefs: options.baseRefs });
|
|
2773
3584
|
if (resolved.kind === "failed") return { kind: "checkout-failed", failure: resolved.failure };
|
|
2774
3585
|
if (resolved.kind === "no-base-ref") return resolved;
|
|
2775
3586
|
const { base } = resolved;
|
|
2776
3587
|
const submodules2 = await checkout.submodules({ repoRoot });
|
|
2777
3588
|
if (!submodules2.ok) return { kind: "checkout-failed", failure: submodules2.failure };
|
|
2778
3589
|
if (submodules2.value.length > 0) return { kind: "submodules", paths: [...submodules2.value] };
|
|
2779
|
-
const
|
|
2780
|
-
if (!
|
|
2781
|
-
const vcpus = resolveVcpus(
|
|
2782
|
-
if (!vcpus.ok) return { kind: "invalid-
|
|
3590
|
+
const inputs = await snapshotInputsAt(checkout, { repoRoot, base, options });
|
|
3591
|
+
if (!inputs.ok) return { kind: "invalid-runner", path: inputs.path, problem: inputs.problem };
|
|
3592
|
+
const vcpus = resolveVcpus(options, request2.vcpuRun);
|
|
3593
|
+
if (!vcpus.ok) return { kind: "invalid-runner", path: ["vcpus"], problem: vcpus.problem };
|
|
2783
3594
|
const upload = await checkout.assembleUpload({ repoRoot, base });
|
|
2784
3595
|
if (!upload.ok) return { kind: "checkout-failed", failure: upload.failure };
|
|
2785
3596
|
const afterBase = await checkout.commitCount({ repoRoot, from: base, to: "HEAD" });
|
|
2786
3597
|
if (!afterBase.ok) return { kind: "checkout-failed", failure: afterBase.failure };
|
|
2787
3598
|
const listing = await removeExpiredEntries(context);
|
|
3599
|
+
const ancestorDistances = await resolveAncestorDistances(context, {
|
|
3600
|
+
repoRoot,
|
|
3601
|
+
entries: listing.entries,
|
|
3602
|
+
options,
|
|
3603
|
+
mergeBase: base
|
|
3604
|
+
});
|
|
3605
|
+
if (!ancestorDistances.ok) return { kind: "checkout-failed", failure: ancestorDistances.failure };
|
|
2788
3606
|
const cache = classifySnapshotEntries(context, {
|
|
2789
3607
|
entries: listing.entries,
|
|
2790
|
-
|
|
3608
|
+
options,
|
|
2791
3609
|
base,
|
|
2792
|
-
snapshotKey:
|
|
2793
|
-
commitsAfterBase: afterBase.value
|
|
3610
|
+
snapshotKey: inputs.key,
|
|
3611
|
+
commitsAfterBase: afterBase.value,
|
|
3612
|
+
ancestorDistances: ancestorDistances.value
|
|
2794
3613
|
});
|
|
2795
3614
|
return {
|
|
2796
3615
|
kind: "ok",
|
|
2797
3616
|
prepared: {
|
|
2798
|
-
|
|
3617
|
+
options,
|
|
2799
3618
|
repoRoot,
|
|
2800
3619
|
base,
|
|
2801
3620
|
baseRef: resolved.ref,
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
snapshotKey: steps.key,
|
|
3621
|
+
baseFiles: inputs.baseFiles,
|
|
3622
|
+
snapshotKey: inputs.key,
|
|
2805
3623
|
vcpus: vcpus.vcpus,
|
|
2806
3624
|
upload: upload.value,
|
|
2807
3625
|
candidates: cache.candidates,
|
|
@@ -2814,6 +3632,133 @@ async function prepareRunner(context, request2) {
|
|
|
2814
3632
|
|
|
2815
3633
|
// src/runner/ready.ts
|
|
2816
3634
|
import { posix } from "node:path";
|
|
3635
|
+
|
|
3636
|
+
// src/runner/shared-snapshot-lookup.ts
|
|
3637
|
+
async function lookupSharedSnapshot(context, request2, signal) {
|
|
3638
|
+
const { runnerSandboxes, checkout, clock } = context;
|
|
3639
|
+
const { access, repoRoot, runner, snapshotKey: snapshotKey2, mergeBase, maxCommitsBehindMergeBase } = request2;
|
|
3640
|
+
if (!sharedBeatsLocal(0, maxCommitsBehindMergeBase)) return { kind: "miss" };
|
|
3641
|
+
const bucket = sharedSnapshotBucket({
|
|
3642
|
+
teamId: access.teamId,
|
|
3643
|
+
projectId: access.projectId,
|
|
3644
|
+
region: runner.region,
|
|
3645
|
+
runtime: runner.runtime,
|
|
3646
|
+
runnerName: runner.name,
|
|
3647
|
+
snapshotKey: snapshotKey2
|
|
3648
|
+
});
|
|
3649
|
+
const exactName = sharedSnapshotSandboxName(bucket, mergeBase);
|
|
3650
|
+
const exact = await runnerSandboxes.getNamedSandbox(access, { name: exactName }, signal);
|
|
3651
|
+
if (!exact.ok) {
|
|
3652
|
+
return unavailable(exact.failure);
|
|
3653
|
+
}
|
|
3654
|
+
if (exact.value.kind === "found") {
|
|
3655
|
+
const { sandbox } = exact.value;
|
|
3656
|
+
const unverified = classifyUnverifiedSharedSandbox(sandbox);
|
|
3657
|
+
if (unverified.kind === "needs-snapshot") {
|
|
3658
|
+
const verified = await runnerSandboxes.getSnapshot(access, { snapshotId: unverified.snapshotId }, signal);
|
|
3659
|
+
if (!verified.ok) {
|
|
3660
|
+
return unavailable(verified.failure);
|
|
3661
|
+
}
|
|
3662
|
+
if (verified.value.kind === "found") {
|
|
3663
|
+
const entry = usableSharedEntry(
|
|
3664
|
+
access,
|
|
3665
|
+
runner,
|
|
3666
|
+
snapshotKey2,
|
|
3667
|
+
mergeBase,
|
|
3668
|
+
sandbox,
|
|
3669
|
+
verified.value.snapshot,
|
|
3670
|
+
clock.now()
|
|
3671
|
+
);
|
|
3672
|
+
if (entry !== null) {
|
|
3673
|
+
return { kind: "hit", entry, commitsBehindMergeBase: 0, sandboxName: sandbox.name };
|
|
3674
|
+
}
|
|
3675
|
+
}
|
|
3676
|
+
}
|
|
3677
|
+
}
|
|
3678
|
+
if (!sharedBeatsLocal(1, maxCommitsBehindMergeBase)) return { kind: "miss" };
|
|
3679
|
+
const listed = await runnerSandboxes.listNamedSandboxes(
|
|
3680
|
+
access,
|
|
3681
|
+
{ namePrefix: sharedSnapshotSandboxPrefix(bucket) },
|
|
3682
|
+
signal
|
|
3683
|
+
);
|
|
3684
|
+
if (!listed.ok) {
|
|
3685
|
+
return unavailable(listed.failure);
|
|
3686
|
+
}
|
|
3687
|
+
const stoppedRows = [];
|
|
3688
|
+
for (const row of listed.value) {
|
|
3689
|
+
const unverified = classifyUnverifiedSharedSandbox(row);
|
|
3690
|
+
if (unverified.kind !== "needs-snapshot") continue;
|
|
3691
|
+
const parsed = parseSharedSnapshotSandboxName(row.name);
|
|
3692
|
+
if (parsed === null || parsed.bucket !== bucket || parsed.base === mergeBase) continue;
|
|
3693
|
+
stoppedRows.push({ row, base: parsed.base, snapshotId: unverified.snapshotId });
|
|
3694
|
+
}
|
|
3695
|
+
const checked = await runLimited(
|
|
3696
|
+
stoppedRows.length,
|
|
3697
|
+
INDEX_CONCURRENCY,
|
|
3698
|
+
() => signal?.aborted !== true,
|
|
3699
|
+
async (index) => {
|
|
3700
|
+
const item = stoppedRows[index];
|
|
3701
|
+
const ancestor = await checkout.contains({ repoRoot, ancestor: item.base, descendant: mergeBase });
|
|
3702
|
+
if (!ancestor.ok || !ancestor.value) return null;
|
|
3703
|
+
if (signal?.aborted === true) return null;
|
|
3704
|
+
const counted = await checkout.commitCount({ repoRoot, from: item.base, to: mergeBase });
|
|
3705
|
+
if (!counted.ok) return null;
|
|
3706
|
+
if (!sharedBeatsLocal(counted.value, maxCommitsBehindMergeBase)) return null;
|
|
3707
|
+
return {
|
|
3708
|
+
row: item.row,
|
|
3709
|
+
base: item.base,
|
|
3710
|
+
snapshotId: item.snapshotId,
|
|
3711
|
+
commitsBehindMergeBase: counted.value
|
|
3712
|
+
};
|
|
3713
|
+
}
|
|
3714
|
+
);
|
|
3715
|
+
if (signal?.aborted === true) return { kind: "aborted" };
|
|
3716
|
+
const candidates = checked.filter((candidate) => candidate != null);
|
|
3717
|
+
candidates.sort(
|
|
3718
|
+
(a, b) => compareSnapshotCandidates(
|
|
3719
|
+
{
|
|
3720
|
+
commitsBehindMergeBase: a.commitsBehindMergeBase,
|
|
3721
|
+
createdAt: a.row.createdAt,
|
|
3722
|
+
tieBreaker: a.row.name
|
|
3723
|
+
},
|
|
3724
|
+
{
|
|
3725
|
+
commitsBehindMergeBase: b.commitsBehindMergeBase,
|
|
3726
|
+
createdAt: b.row.createdAt,
|
|
3727
|
+
tieBreaker: b.row.name
|
|
3728
|
+
}
|
|
3729
|
+
)
|
|
3730
|
+
);
|
|
3731
|
+
for (const candidate of candidates) {
|
|
3732
|
+
const verified = await runnerSandboxes.getSnapshot(access, { snapshotId: candidate.snapshotId }, signal);
|
|
3733
|
+
if (!verified.ok) {
|
|
3734
|
+
return unavailable(verified.failure);
|
|
3735
|
+
}
|
|
3736
|
+
if (verified.value.kind !== "found") continue;
|
|
3737
|
+
const entry = usableSharedEntry(
|
|
3738
|
+
access,
|
|
3739
|
+
runner,
|
|
3740
|
+
snapshotKey2,
|
|
3741
|
+
candidate.base,
|
|
3742
|
+
candidate.row,
|
|
3743
|
+
verified.value.snapshot,
|
|
3744
|
+
clock.now()
|
|
3745
|
+
);
|
|
3746
|
+
if (entry !== null) {
|
|
3747
|
+
return {
|
|
3748
|
+
kind: "hit",
|
|
3749
|
+
entry,
|
|
3750
|
+
commitsBehindMergeBase: candidate.commitsBehindMergeBase,
|
|
3751
|
+
sandboxName: candidate.row.name
|
|
3752
|
+
};
|
|
3753
|
+
}
|
|
3754
|
+
}
|
|
3755
|
+
return { kind: "miss" };
|
|
3756
|
+
}
|
|
3757
|
+
function unavailable(failure) {
|
|
3758
|
+
return failure.kind === "aborted" ? { kind: "aborted" } : { kind: "unavailable", message: failure.message };
|
|
3759
|
+
}
|
|
3760
|
+
|
|
3761
|
+
// src/runner/ready.ts
|
|
2817
3762
|
var APPLY_LABEL = "Applying your changes";
|
|
2818
3763
|
async function readyRunner(context, request2, control, progress) {
|
|
2819
3764
|
const chosen = await chooseSnapshot(context, request2, control, progress);
|
|
@@ -2822,17 +3767,62 @@ async function readyRunner(context, request2, control, progress) {
|
|
|
2822
3767
|
}
|
|
2823
3768
|
async function chooseSnapshot(context, request2, control, progress) {
|
|
2824
3769
|
const { prepared, access } = request2;
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
3770
|
+
const { signal } = control;
|
|
3771
|
+
if (signal.aborted) return { kind: "aborted" };
|
|
3772
|
+
const localCandidate = pickSnapshot(prepared.candidates, access);
|
|
3773
|
+
if (localCandidate !== void 0 && localCandidate.commitsBehindMergeBase === 0) {
|
|
3774
|
+
const { entry, builtBehind } = localCandidate;
|
|
3775
|
+
await progress.emit({
|
|
3776
|
+
kind: "snapshot-reused",
|
|
3777
|
+
snapshotId: entry.snapshotId,
|
|
3778
|
+
base: entry.base,
|
|
3779
|
+
builtBehind,
|
|
3780
|
+
source: "local"
|
|
3781
|
+
});
|
|
3782
|
+
return { kind: "ok", value: { entry, built: false, builtBehind, upload: prepared.upload } };
|
|
3783
|
+
}
|
|
3784
|
+
const shared = await lookupSharedSnapshot(
|
|
3785
|
+
context,
|
|
3786
|
+
{
|
|
3787
|
+
access,
|
|
3788
|
+
repoRoot: prepared.repoRoot,
|
|
3789
|
+
runner: prepared.options,
|
|
3790
|
+
snapshotKey: prepared.snapshotKey,
|
|
3791
|
+
mergeBase: prepared.base,
|
|
3792
|
+
...localCandidate === void 0 ? {} : { maxCommitsBehindMergeBase: localCandidate.commitsBehindMergeBase }
|
|
3793
|
+
},
|
|
3794
|
+
signal
|
|
3795
|
+
);
|
|
3796
|
+
if (shared.kind === "aborted") return { kind: "aborted" };
|
|
3797
|
+
if (shared.kind === "unavailable") {
|
|
3798
|
+
await progress.emit({ kind: "shared-snapshot-lookup-failed", message: shared.message });
|
|
3799
|
+
}
|
|
3800
|
+
const sharedHit = shared.kind === "hit" ? shared : void 0;
|
|
3801
|
+
const useShared = sharedHit !== void 0 && sharedBeatsLocal(sharedHit.commitsBehindMergeBase, localCandidate?.commitsBehindMergeBase);
|
|
3802
|
+
const winner = useShared ? { source: "shared", hit: sharedHit } : localCandidate !== void 0 ? { source: "local", candidate: localCandidate } : void 0;
|
|
3803
|
+
if (winner !== void 0) {
|
|
3804
|
+
let entry;
|
|
3805
|
+
let builtBehind;
|
|
3806
|
+
if (winner.source === "shared") {
|
|
3807
|
+
entry = winner.hit.entry;
|
|
3808
|
+
const written = await context.runnerSnapshots.writeEntry(entry);
|
|
3809
|
+
if (!written.ok) await progress.emit({ kind: "snapshot-entry-not-written", failure: written.failure });
|
|
3810
|
+
builtBehind = prepared.commitsAfterBase + winner.hit.commitsBehindMergeBase;
|
|
3811
|
+
} else {
|
|
3812
|
+
entry = winner.candidate.entry;
|
|
3813
|
+
builtBehind = winner.candidate.builtBehind;
|
|
3814
|
+
}
|
|
3815
|
+
const upload = await uploadForBase(context, prepared, entry.base);
|
|
3816
|
+
if (!upload.ok) return { kind: "failed", failure: { kind: "checkout-failed", failure: upload.failure } };
|
|
3817
|
+
if (signal.aborted) return { kind: "aborted" };
|
|
2829
3818
|
await progress.emit({
|
|
2830
3819
|
kind: "snapshot-reused",
|
|
2831
3820
|
snapshotId: entry.snapshotId,
|
|
2832
3821
|
base: entry.base,
|
|
2833
|
-
builtBehind
|
|
3822
|
+
builtBehind,
|
|
3823
|
+
source: winner.source
|
|
2834
3824
|
});
|
|
2835
|
-
return { kind: "ok", value: { entry, built: false } };
|
|
3825
|
+
return { kind: "ok", value: { entry, built: false, builtBehind, upload: upload.value } };
|
|
2836
3826
|
}
|
|
2837
3827
|
const why = { kind: "no-snapshot", rejected: snapshotRejections(prepared, access) };
|
|
2838
3828
|
const building = await buildSnapshot(
|
|
@@ -2842,12 +3832,24 @@ async function chooseSnapshot(context, request2, control, progress) {
|
|
|
2842
3832
|
progress
|
|
2843
3833
|
);
|
|
2844
3834
|
if (building.kind !== "ok") return building;
|
|
2845
|
-
return {
|
|
3835
|
+
return {
|
|
3836
|
+
kind: "ok",
|
|
3837
|
+
value: {
|
|
3838
|
+
entry: building.value.entry,
|
|
3839
|
+
built: true,
|
|
3840
|
+
builtBehind: prepared.commitsAfterBase,
|
|
3841
|
+
upload: prepared.upload
|
|
3842
|
+
}
|
|
3843
|
+
};
|
|
3844
|
+
}
|
|
3845
|
+
async function uploadForBase(context, prepared, base) {
|
|
3846
|
+
if (base === prepared.base) return { ok: true, value: prepared.upload };
|
|
3847
|
+
return await context.checkout.assembleUpload({ repoRoot: prepared.repoRoot, base });
|
|
2846
3848
|
}
|
|
2847
3849
|
async function readyFromSnapshot(context, request2, control, progress) {
|
|
2848
3850
|
const { prepared, access } = request2;
|
|
2849
|
-
const { entry, built } = request2.snapshot;
|
|
2850
|
-
const {
|
|
3851
|
+
const { entry, built, builtBehind, upload } = request2.snapshot;
|
|
3852
|
+
const { options, repoRoot } = prepared;
|
|
2851
3853
|
const { scope, signal } = control;
|
|
2852
3854
|
const now = () => context.clock.now().getTime();
|
|
2853
3855
|
if (signal.aborted) return { kind: "aborted" };
|
|
@@ -2855,10 +3857,10 @@ async function readyFromSnapshot(context, request2, control, progress) {
|
|
|
2855
3857
|
const startedAt = now();
|
|
2856
3858
|
const started = await scope.startRunnerSandbox(access, {
|
|
2857
3859
|
snapshotId: entry.snapshotId,
|
|
2858
|
-
region:
|
|
3860
|
+
region: options.region,
|
|
2859
3861
|
vcpus: prepared.vcpus,
|
|
2860
|
-
timeoutMs:
|
|
2861
|
-
tags: runnerTags(
|
|
3862
|
+
timeoutMs: options.timeoutMinutes * 6e4,
|
|
3863
|
+
tags: runnerTags(options.name, "runner", request2.user)
|
|
2862
3864
|
});
|
|
2863
3865
|
if (!started.ok) {
|
|
2864
3866
|
if (started.failure.kind === "snapshot-gone") {
|
|
@@ -2872,11 +3874,11 @@ async function readyFromSnapshot(context, request2, control, progress) {
|
|
|
2872
3874
|
kind: "sandbox-started",
|
|
2873
3875
|
role: "runner",
|
|
2874
3876
|
name: sandbox.name,
|
|
2875
|
-
region:
|
|
3877
|
+
region: options.region,
|
|
2876
3878
|
vcpus: prepared.vcpus,
|
|
2877
3879
|
ms: now() - startedAt
|
|
2878
3880
|
});
|
|
2879
|
-
const changes = await uploadChanges(context, {
|
|
3881
|
+
const changes = await uploadChanges(context, { upload, sandbox }, signal, progress);
|
|
2880
3882
|
if (changes.kind !== "ok") return changes;
|
|
2881
3883
|
const applied = await stage(
|
|
2882
3884
|
context,
|
|
@@ -2884,7 +3886,7 @@ async function readyFromSnapshot(context, request2, control, progress) {
|
|
|
2884
3886
|
sandbox,
|
|
2885
3887
|
phase: "apply",
|
|
2886
3888
|
step: { label: APPLY_LABEL, script: applyScript(changes.value.directory) },
|
|
2887
|
-
region:
|
|
3889
|
+
region: options.region
|
|
2888
3890
|
},
|
|
2889
3891
|
signal,
|
|
2890
3892
|
progress
|
|
@@ -2898,14 +3900,14 @@ async function readyFromSnapshot(context, request2, control, progress) {
|
|
|
2898
3900
|
}
|
|
2899
3901
|
const installed = await stage(
|
|
2900
3902
|
context,
|
|
2901
|
-
{ sandbox, phase: "install", step:
|
|
3903
|
+
{ sandbox, phase: "install", step: options.run.install, region: options.region },
|
|
2902
3904
|
signal,
|
|
2903
3905
|
progress
|
|
2904
3906
|
);
|
|
2905
3907
|
if (installed.kind !== "ok") return installed;
|
|
2906
3908
|
const builtOutputs = await stage(
|
|
2907
3909
|
context,
|
|
2908
|
-
{ sandbox, phase: "build", step:
|
|
3910
|
+
{ sandbox, phase: "build", step: options.run.build, region: options.region },
|
|
2909
3911
|
signal,
|
|
2910
3912
|
progress
|
|
2911
3913
|
);
|
|
@@ -2917,15 +3919,15 @@ async function readyFromSnapshot(context, request2, control, progress) {
|
|
|
2917
3919
|
snapshotId: entry.snapshotId,
|
|
2918
3920
|
base: entry.base,
|
|
2919
3921
|
built,
|
|
2920
|
-
builtBehind
|
|
3922
|
+
builtBehind,
|
|
2921
3923
|
uploadBytes: changes.value.bytes,
|
|
2922
3924
|
buildMs: builtOutputs.value,
|
|
2923
3925
|
vcpus: prepared.vcpus,
|
|
2924
|
-
region:
|
|
2925
|
-
runtime:
|
|
3926
|
+
region: options.region,
|
|
3927
|
+
runtime: options.runtime,
|
|
2926
3928
|
repoRoot,
|
|
2927
|
-
cwd: posix.join(SANDBOX_ROOT,
|
|
2928
|
-
env:
|
|
3929
|
+
cwd: posix.join(SANDBOX_ROOT, options.cwd),
|
|
3930
|
+
env: options.env,
|
|
2929
3931
|
loginPath: loginPath.value
|
|
2930
3932
|
}
|
|
2931
3933
|
};
|
|
@@ -2933,7 +3935,7 @@ async function readyFromSnapshot(context, request2, control, progress) {
|
|
|
2933
3935
|
async function uploadChanges(context, request2, signal, progress) {
|
|
2934
3936
|
await progress.emit({ kind: "uploading" });
|
|
2935
3937
|
const startedAt = context.clock.now().getTime();
|
|
2936
|
-
const files = stagedChanges(request2.
|
|
3938
|
+
const files = stagedChanges(request2.upload);
|
|
2937
3939
|
const staged = await context.runnerSandboxes.upload(request2.sandbox, files, signal);
|
|
2938
3940
|
if (!staged.ok) return sandboxStop("upload", staged.failure);
|
|
2939
3941
|
const bytes = files.reduce((sum, file) => sum + file.content.byteLength, 0);
|
|
@@ -2977,7 +3979,7 @@ async function chooseSnapshotForRun(context, request2, control, progress) {
|
|
|
2977
3979
|
const stageSignal = stop === void 0 ? signal : AbortSignal.any([signal, stop]);
|
|
2978
3980
|
const scope = runnerSandboxScope(context, progress, {
|
|
2979
3981
|
keepMs: 0,
|
|
2980
|
-
basePolicy: runnerNetworkPolicy(request2.prepared.
|
|
3982
|
+
basePolicy: runnerNetworkPolicy(request2.prepared.options),
|
|
2981
3983
|
signal
|
|
2982
3984
|
});
|
|
2983
3985
|
try {
|
|
@@ -3123,7 +4125,7 @@ function openRunnerSession(context, request2, control, progress) {
|
|
|
3123
4125
|
let commandRunning = false;
|
|
3124
4126
|
const scope = runnerSandboxScope(context, progress, {
|
|
3125
4127
|
keepMs: request2.keepMs,
|
|
3126
|
-
basePolicy: runnerNetworkPolicy(request2.prepared.
|
|
4128
|
+
basePolicy: runnerNetworkPolicy(request2.prepared.options),
|
|
3127
4129
|
signal,
|
|
3128
4130
|
commandRunning: () => commandRunning
|
|
3129
4131
|
});
|
|
@@ -3203,11 +4205,11 @@ function openRunnerSession(context, request2, control, progress) {
|
|
|
3203
4205
|
}
|
|
3204
4206
|
|
|
3205
4207
|
// src/config/load.ts
|
|
3206
|
-
import { dirname, join as join2 } from "node:path";
|
|
4208
|
+
import { basename, dirname, join as join2 } from "node:path";
|
|
3207
4209
|
|
|
3208
4210
|
// src/config/check-runner.ts
|
|
3209
4211
|
var FACTORY_HINT = "must be made by vercelSandbox({ \u2026 }) or launchMachine()";
|
|
3210
|
-
function checkRunner(value, inherited) {
|
|
4212
|
+
function checkRunner(value, inherited, definitions = []) {
|
|
3211
4213
|
if (!isRecord2(value)) {
|
|
3212
4214
|
return { ok: false, problems: [{ path: [], problem: `${FACTORY_HINT}, not ${describeValue(value)}` }] };
|
|
3213
4215
|
}
|
|
@@ -3229,12 +4231,33 @@ function checkRunner(value, inherited) {
|
|
|
3229
4231
|
...inherited,
|
|
3230
4232
|
...Object.fromEntries(Object.entries(options).filter(([, entry]) => entry !== void 0))
|
|
3231
4233
|
};
|
|
3232
|
-
const checked =
|
|
4234
|
+
const checked = checkVercelSandboxOptions(rawOptions);
|
|
3233
4235
|
if (!checked.ok) return checked;
|
|
3234
|
-
|
|
4236
|
+
const vcpusProblems = checkVcpusRuleDefinitions(checked.value.vcpus, definitions);
|
|
4237
|
+
if (vcpusProblems.length > 0) return { ok: false, problems: vcpusProblems };
|
|
4238
|
+
return { ok: true, value: { kind: "vercel-sandbox", options: checked.value } };
|
|
3235
4239
|
}
|
|
3236
4240
|
return { ok: false, problems: [{ path: [], problem: `${FACTORY_HINT}, not ${describeValue(value)}` }] };
|
|
3237
4241
|
}
|
|
4242
|
+
function checkVcpusRuleDefinitions(vcpus, definitions) {
|
|
4243
|
+
if (typeof vcpus === "number") return [];
|
|
4244
|
+
const definition = definitions.find((each) => each.name === vcpus.resource);
|
|
4245
|
+
if (definition === void 0) {
|
|
4246
|
+
const known = definitions.length === 0 ? "none" : definitions.map((each) => each.name).join(", ");
|
|
4247
|
+
return [{ path: ["vcpus", "resource"], problem: `is not a resource; storm has ${known}` }];
|
|
4248
|
+
}
|
|
4249
|
+
if (!Object.hasOwn(definition.options, vcpus.option)) {
|
|
4250
|
+
const optionNames = Object.keys(definition.options);
|
|
4251
|
+
const available = optionNames.length === 0 ? "none" : optionNames.join(", ");
|
|
4252
|
+
return [
|
|
4253
|
+
{
|
|
4254
|
+
path: ["vcpus", "option"],
|
|
4255
|
+
problem: `is not a ${definition.name} option; ${definition.name} has ${available}`
|
|
4256
|
+
}
|
|
4257
|
+
];
|
|
4258
|
+
}
|
|
4259
|
+
return [];
|
|
4260
|
+
}
|
|
3238
4261
|
function rawVercelSandboxOptions(value) {
|
|
3239
4262
|
if (!isRecord2(value) || value["kind"] !== "vercel-sandbox") return void 0;
|
|
3240
4263
|
const options = value["options"];
|
|
@@ -3246,6 +4269,8 @@ function isRecord2(value) {
|
|
|
3246
4269
|
|
|
3247
4270
|
// src/config/schema.ts
|
|
3248
4271
|
var CONFIG_FILE_NAME = "storm.config.ts";
|
|
4272
|
+
var CONFIG_FILE_NAMES = [CONFIG_FILE_NAME, "storm.config.mts"];
|
|
4273
|
+
var CONFIG_FILE_NAMES_TEXT = CONFIG_FILE_NAMES.join(" or ");
|
|
3249
4274
|
function checkWith(schema, value) {
|
|
3250
4275
|
const parsed = schema.safeParse(value);
|
|
3251
4276
|
if (parsed.success) return { ok: true, value: parsed.data };
|
|
@@ -3280,7 +4305,7 @@ var SETTING_CHECKS = {
|
|
|
3280
4305
|
project: (value) => checkWith(nonEmptyString, value),
|
|
3281
4306
|
driver: (value, { drivers }) => checkDriver(value, drivers),
|
|
3282
4307
|
args: checkStringList,
|
|
3283
|
-
runner: (value, { topLevelRunnerOptions }) => checkRunner(value, topLevelRunnerOptions),
|
|
4308
|
+
runner: (value, { topLevelRunnerOptions, definitions }) => checkRunner(value, topLevelRunnerOptions, definitions),
|
|
3284
4309
|
testPlan: (value) => checkWith(booleanOption, value)
|
|
3285
4310
|
};
|
|
3286
4311
|
function isConfigSettingKey(key) {
|
|
@@ -3376,6 +4401,7 @@ function checkSuites(value, options, problems) {
|
|
|
3376
4401
|
return {};
|
|
3377
4402
|
}
|
|
3378
4403
|
const settingContext = {
|
|
4404
|
+
definitions: options.definitions,
|
|
3379
4405
|
drivers: options.drivers,
|
|
3380
4406
|
topLevelRunnerOptions: options.topLevelRunnerOptions
|
|
3381
4407
|
};
|
|
@@ -3449,14 +4475,22 @@ function isRecord4(value) {
|
|
|
3449
4475
|
|
|
3450
4476
|
// src/config/load.ts
|
|
3451
4477
|
async function findConfigFile(gateway, startDirectory) {
|
|
3452
|
-
|
|
4478
|
+
const here = await lookIn(gateway, startDirectory);
|
|
4479
|
+
if (here !== void 0) return here;
|
|
3453
4480
|
const root = await worktreeRoot(gateway, startDirectory);
|
|
3454
|
-
if (root === void 0) return
|
|
4481
|
+
if (root === void 0) return { kind: "none" };
|
|
3455
4482
|
for (let directory = startDirectory; directory !== root; ) {
|
|
3456
4483
|
directory = dirname(directory);
|
|
3457
|
-
|
|
4484
|
+
const found = await lookIn(gateway, directory);
|
|
4485
|
+
if (found !== void 0) return found;
|
|
3458
4486
|
}
|
|
3459
|
-
return
|
|
4487
|
+
return { kind: "none" };
|
|
4488
|
+
}
|
|
4489
|
+
async function lookIn(gateway, directory) {
|
|
4490
|
+
const [first, second, ...rest] = (await gateway.configFileNames(directory)).map((name) => join2(directory, name));
|
|
4491
|
+
if (first === void 0) return void 0;
|
|
4492
|
+
if (second === void 0) return { kind: "found", path: first };
|
|
4493
|
+
return { kind: "conflict", paths: [first, second, ...rest] };
|
|
3460
4494
|
}
|
|
3461
4495
|
async function worktreeRoot(gateway, directory) {
|
|
3462
4496
|
for (let current = directory; ; current = dirname(current)) {
|
|
@@ -3465,8 +4499,22 @@ async function worktreeRoot(gateway, directory) {
|
|
|
3465
4499
|
}
|
|
3466
4500
|
}
|
|
3467
4501
|
async function loadConfig(gateway, startDirectory, definitions, drivers) {
|
|
3468
|
-
const
|
|
3469
|
-
if (
|
|
4502
|
+
const found = await findConfigFile(gateway, startDirectory);
|
|
4503
|
+
if (found.kind === "none") return { kind: "none" };
|
|
4504
|
+
if (found.kind === "conflict") {
|
|
4505
|
+
const [path2, ...others] = found.paths;
|
|
4506
|
+
const names = others.map((other) => basename(other)).join(" and ");
|
|
4507
|
+
return {
|
|
4508
|
+
kind: "invalid",
|
|
4509
|
+
path: path2,
|
|
4510
|
+
problems: [
|
|
4511
|
+
fileProblem(
|
|
4512
|
+
`is in the same directory as ${names}, so storm can't tell which config file applies; keep one of them`
|
|
4513
|
+
)
|
|
4514
|
+
]
|
|
4515
|
+
};
|
|
4516
|
+
}
|
|
4517
|
+
const { path } = found;
|
|
3470
4518
|
const imported = await gateway.importConfig(path);
|
|
3471
4519
|
switch (imported.kind) {
|
|
3472
4520
|
case "import-failed":
|
|
@@ -3497,7 +4545,7 @@ function checkFile(path, value, definitions, drivers) {
|
|
|
3497
4545
|
let resources = {};
|
|
3498
4546
|
let rawSuites;
|
|
3499
4547
|
let hasSuitesKey = false;
|
|
3500
|
-
const settingContext = { drivers };
|
|
4548
|
+
const settingContext = { definitions, drivers };
|
|
3501
4549
|
const hasTopLevelDriver = value["driver"] !== void 0;
|
|
3502
4550
|
for (const [key, keyValue] of Object.entries(value)) {
|
|
3503
4551
|
if (key === "resources") resources = checkResources(keyValue, definitions, problems, "resources");
|
|
@@ -3506,7 +4554,7 @@ function checkFile(path, value, definitions, drivers) {
|
|
|
3506
4554
|
rawSuites = keyValue;
|
|
3507
4555
|
} else if (isConfigSettingKey(key)) {
|
|
3508
4556
|
if (keyValue !== void 0) checkSetting(key, keyValue, settings, settingContext, problems);
|
|
3509
|
-
} else problems.push({ key, location: null, problem: `is not a ${
|
|
4557
|
+
} else problems.push({ key, location: null, problem: `is not a ${basename(path)} key` });
|
|
3510
4558
|
}
|
|
3511
4559
|
if (settings.args !== void 0 && !hasTopLevelDriver) {
|
|
3512
4560
|
problems.push({ key: "args", location: null, problem: "requires a top-level driver" });
|
|
@@ -3521,9 +4569,84 @@ function checkFile(path, value, definitions, drivers) {
|
|
|
3521
4569
|
},
|
|
3522
4570
|
problems
|
|
3523
4571
|
) : {};
|
|
4572
|
+
checkPlainData(value, problems);
|
|
3524
4573
|
if (problems.length > 0) return { kind: "invalid", path, problems };
|
|
3525
4574
|
return { kind: "loaded", path, values: { settings, resources, suites } };
|
|
3526
4575
|
}
|
|
4576
|
+
function checkPlainData(root, problems) {
|
|
4577
|
+
const reported = new Set(problems.map(({ key }) => key).filter((key) => key !== null));
|
|
4578
|
+
const visiting = /* @__PURE__ */ new Set();
|
|
4579
|
+
const addProblem = (path, problem) => {
|
|
4580
|
+
const key = path.join(".");
|
|
4581
|
+
if (reported.has(key)) return;
|
|
4582
|
+
reported.add(key);
|
|
4583
|
+
problems.push({ key: key.length === 0 ? null : key, location: null, problem });
|
|
4584
|
+
};
|
|
4585
|
+
const visit = (current, path) => {
|
|
4586
|
+
if (current === null || typeof current === "string" || typeof current === "boolean") return;
|
|
4587
|
+
if (current === void 0) {
|
|
4588
|
+
addProblem(path, "must be plain data (JSON cannot hold undefined in an array)");
|
|
4589
|
+
return;
|
|
4590
|
+
}
|
|
4591
|
+
if (typeof current === "number") {
|
|
4592
|
+
if (!Number.isFinite(current)) addProblem(path, `must be plain data (JSON cannot hold ${String(current)})`);
|
|
4593
|
+
return;
|
|
4594
|
+
}
|
|
4595
|
+
if (typeof current === "function") {
|
|
4596
|
+
addProblem(path, "must be plain data (JSON cannot hold a function)");
|
|
4597
|
+
return;
|
|
4598
|
+
}
|
|
4599
|
+
if (typeof current === "symbol") {
|
|
4600
|
+
addProblem(path, "must be plain data (JSON cannot hold a symbol)");
|
|
4601
|
+
return;
|
|
4602
|
+
}
|
|
4603
|
+
if (typeof current === "bigint") {
|
|
4604
|
+
addProblem(path, "must be plain data (JSON cannot hold a bigint)");
|
|
4605
|
+
return;
|
|
4606
|
+
}
|
|
4607
|
+
if (typeof current !== "object") return;
|
|
4608
|
+
if (visiting.has(current)) {
|
|
4609
|
+
addProblem(path, "must be plain data (circular reference)");
|
|
4610
|
+
return;
|
|
4611
|
+
}
|
|
4612
|
+
if (Array.isArray(current)) {
|
|
4613
|
+
visiting.add(current);
|
|
4614
|
+
for (let index = 0; index < current.length; index += 1) visit(current[index], [...path, String(index)]);
|
|
4615
|
+
visiting.delete(current);
|
|
4616
|
+
return;
|
|
4617
|
+
}
|
|
4618
|
+
const proto = Object.getPrototypeOf(current);
|
|
4619
|
+
if (proto !== Object.prototype && proto !== null) {
|
|
4620
|
+
addProblem(path, `must be plain data (expected a plain object, not ${describeNonPlainObject(proto)})`);
|
|
4621
|
+
return;
|
|
4622
|
+
}
|
|
4623
|
+
visiting.add(current);
|
|
4624
|
+
const isRunnerWrapper = path.length === 1 && path[0] === "runner" || path.length === 3 && path[0] === "suites" && path[2] === "runner";
|
|
4625
|
+
const unwrapRunnerOptions = isRunnerWrapper && current["kind"] === "vercel-sandbox";
|
|
4626
|
+
const isResourceWrapper = path.length === 2 && path[0] === "resources" || path.length === 4 && path[0] === "suites" && path[2] === "resources";
|
|
4627
|
+
const unwrapResourceOptions = isResourceWrapper && typeof current["name"] === "string";
|
|
4628
|
+
for (const [key, entry] of Object.entries(current)) {
|
|
4629
|
+
if (entry === void 0) continue;
|
|
4630
|
+
if ((unwrapRunnerOptions || unwrapResourceOptions) && key === "options" && isPlainObject2(entry)) {
|
|
4631
|
+
visit(entry, path);
|
|
4632
|
+
continue;
|
|
4633
|
+
}
|
|
4634
|
+
visit(entry, [...path, key]);
|
|
4635
|
+
}
|
|
4636
|
+
visiting.delete(current);
|
|
4637
|
+
};
|
|
4638
|
+
visit(root, []);
|
|
4639
|
+
}
|
|
4640
|
+
function isPlainObject2(value) {
|
|
4641
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
4642
|
+
const proto = Object.getPrototypeOf(value);
|
|
4643
|
+
return proto === Object.prototype || proto === null;
|
|
4644
|
+
}
|
|
4645
|
+
function describeNonPlainObject(proto) {
|
|
4646
|
+
const ctor = typeof proto === "object" && proto !== null ? proto.constructor : void 0;
|
|
4647
|
+
if (typeof ctor === "function" && ctor.name.length > 0 && ctor.name !== "Object") return ctor.name;
|
|
4648
|
+
return "a non-plain object";
|
|
4649
|
+
}
|
|
3527
4650
|
function checkSetting(key, value, settings, context, problems) {
|
|
3528
4651
|
const checked = checkSettingValue(key, value, context);
|
|
3529
4652
|
if (checked.ok) Object.assign(settings, { [key]: checked.value });
|
|
@@ -3539,14 +4662,14 @@ function fileProblem(problem) {
|
|
|
3539
4662
|
}
|
|
3540
4663
|
|
|
3541
4664
|
// src/config/errors.ts
|
|
3542
|
-
import { z as
|
|
3543
|
-
var problemSchema =
|
|
4665
|
+
import { z as z4 } from "zod";
|
|
4666
|
+
var problemSchema = z4.object({
|
|
3544
4667
|
/** The key the problem is about; null when it is about the whole file. */
|
|
3545
|
-
key:
|
|
4668
|
+
key: z4.string().nullable(),
|
|
3546
4669
|
/** Where Node said the import failed; null otherwise. */
|
|
3547
|
-
location:
|
|
4670
|
+
location: z4.object({ line: z4.number(), column: z4.number().nullable() }).nullable(),
|
|
3548
4671
|
/** What is wrong, worded to follow the key, or the file name when there is no key. */
|
|
3549
|
-
problem:
|
|
4672
|
+
problem: z4.string()
|
|
3550
4673
|
});
|
|
3551
4674
|
function configProblemLine(file, { key, location, problem }) {
|
|
3552
4675
|
const sentence = `${problem.replace(/\.$/, "")}.`;
|
|
@@ -3555,21 +4678,21 @@ function configProblemLine(file, { key, location, problem }) {
|
|
|
3555
4678
|
return `${file}:${location.line}${location.column === null ? "" : `:${location.column}`} ${sentence}`;
|
|
3556
4679
|
return `${file}: ${sentence}`;
|
|
3557
4680
|
}
|
|
3558
|
-
var optionValueSchema =
|
|
4681
|
+
var optionValueSchema = z4.object({
|
|
3559
4682
|
/** The option's key path, such as resources.<key>.ttl. */
|
|
3560
|
-
key:
|
|
4683
|
+
key: z4.string(),
|
|
3561
4684
|
/** Its value, as text. */
|
|
3562
|
-
value:
|
|
4685
|
+
value: z4.string(),
|
|
3563
4686
|
/** Where it came from: the command's own flag for the option, the config file or the default. */
|
|
3564
|
-
source:
|
|
4687
|
+
source: z4.enum(["flag", "file", "default"])
|
|
3565
4688
|
});
|
|
3566
|
-
var optionProblemSchema =
|
|
4689
|
+
var optionProblemSchema = z4.object({
|
|
3567
4690
|
/** The key path of the option the problem is about, such as resources.<key>.ttl. */
|
|
3568
|
-
key:
|
|
4691
|
+
key: z4.string(),
|
|
3569
4692
|
/** What is wrong, worded to follow the key path, as the resource's rule words it. */
|
|
3570
|
-
problem:
|
|
4693
|
+
problem: z4.string(),
|
|
3571
4694
|
/** Each value the problem is about, with its source; empty for a required option nothing gave. */
|
|
3572
|
-
values:
|
|
4695
|
+
values: z4.array(optionValueSchema)
|
|
3573
4696
|
});
|
|
3574
4697
|
function optionValueText({ key, value, source }, configFile) {
|
|
3575
4698
|
switch (source) {
|
|
@@ -3590,10 +4713,10 @@ var configErrors = defineErrors({
|
|
|
3590
4713
|
invalidConfig: {
|
|
3591
4714
|
exitCode: 2,
|
|
3592
4715
|
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.",
|
|
3593
|
-
schema:
|
|
4716
|
+
schema: z4.object({
|
|
3594
4717
|
/** The config file's absolute path. */
|
|
3595
|
-
file:
|
|
3596
|
-
problems:
|
|
4718
|
+
file: z4.string(),
|
|
4719
|
+
problems: z4.array(problemSchema)
|
|
3597
4720
|
}),
|
|
3598
4721
|
render: ({ file, problems }) => {
|
|
3599
4722
|
const [first, ...rest] = problems;
|
|
@@ -3607,10 +4730,10 @@ var configErrors = defineErrors({
|
|
|
3607
4730
|
invalidResourceOptions: {
|
|
3608
4731
|
exitCode: 2,
|
|
3609
4732
|
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.",
|
|
3610
|
-
schema:
|
|
4733
|
+
schema: z4.object({
|
|
3611
4734
|
/** The config file that applied; null when none did. */
|
|
3612
|
-
configFile:
|
|
3613
|
-
problems:
|
|
4735
|
+
configFile: z4.string().nullable(),
|
|
4736
|
+
problems: z4.array(optionProblemSchema)
|
|
3614
4737
|
}),
|
|
3615
4738
|
render: ({ configFile, problems }) => {
|
|
3616
4739
|
const [first, ...rest] = problems;
|
|
@@ -3635,9 +4758,6 @@ function givenOptionsOf(_definition, values) {
|
|
|
3635
4758
|
function settingsOf(_definition, settings) {
|
|
3636
4759
|
return settings;
|
|
3637
4760
|
}
|
|
3638
|
-
function resourceOptionsOf(_definition, value) {
|
|
3639
|
-
return value;
|
|
3640
|
-
}
|
|
3641
4761
|
|
|
3642
4762
|
// src/config/resolve.ts
|
|
3643
4763
|
function resolveSettings(flags, file) {
|
|
@@ -3929,10 +5049,10 @@ async function request(env, timeoutMs) {
|
|
|
3929
5049
|
return classifyTokenResponse({ status: response.status, body: await response.text() }, token);
|
|
3930
5050
|
} catch (error) {
|
|
3931
5051
|
if (signal.aborted) return { ok: false, failure: { kind: "timeout", seconds } };
|
|
3932
|
-
return { ok: false, failure: { kind: "unreachable", said: said(
|
|
5052
|
+
return { ok: false, failure: { kind: "unreachable", said: said(errorMessage(error), token) } };
|
|
3933
5053
|
}
|
|
3934
5054
|
}
|
|
3935
|
-
function
|
|
5055
|
+
function errorMessage(error) {
|
|
3936
5056
|
if (!(error instanceof Error)) return String(error);
|
|
3937
5057
|
const cause = error.cause;
|
|
3938
5058
|
return cause instanceof Error && cause.message !== "" ? `${error.message}: ${cause.message}` : error.message;
|
|
@@ -4068,6 +5188,17 @@ function failedRun(error, stdout, stderr) {
|
|
|
4068
5188
|
return { ok: false, reason: "exit", stdout: out, stderr: err };
|
|
4069
5189
|
}
|
|
4070
5190
|
|
|
5191
|
+
// src/credential/live/vercel-oidc-token-gateway.ts
|
|
5192
|
+
function liveVercelOidcTokenGateway(options) {
|
|
5193
|
+
return {
|
|
5194
|
+
async read() {
|
|
5195
|
+
const token = Object.hasOwn(options.env, "VERCEL_OIDC_TOKEN") ? options.env["VERCEL_OIDC_TOKEN"] : void 0;
|
|
5196
|
+
if (token === void 0 || token === "") return { ok: false, failure: { kind: "missing-token" } };
|
|
5197
|
+
return { ok: true, credential: new Credential(token) };
|
|
5198
|
+
}
|
|
5199
|
+
};
|
|
5200
|
+
}
|
|
5201
|
+
|
|
4071
5202
|
// src/credential/source.ts
|
|
4072
5203
|
var REQUESTING_TOKEN_LINE = "Requesting a GitHub Actions OIDC token\u2026";
|
|
4073
5204
|
function credentialSourceFor(choice, context, progress) {
|
|
@@ -4078,6 +5209,7 @@ function credentialSourceFor(choice, context, progress) {
|
|
|
4078
5209
|
timer: context.timer,
|
|
4079
5210
|
progress
|
|
4080
5211
|
});
|
|
5212
|
+
if (choice.source === "vercel-oidc") return vercelOidcSource(context.vercelOidcTokens);
|
|
4081
5213
|
const { target } = choice;
|
|
4082
5214
|
return mintSource(target, async () => {
|
|
4083
5215
|
await progress.emit({ kind: "minting", target });
|
|
@@ -4158,12 +5290,90 @@ function isRetryable(failure) {
|
|
|
4158
5290
|
return false;
|
|
4159
5291
|
}
|
|
4160
5292
|
}
|
|
5293
|
+
function vercelOidcSource(gateway) {
|
|
5294
|
+
let outcome;
|
|
5295
|
+
return {
|
|
5296
|
+
obtain() {
|
|
5297
|
+
outcome ??= (async () => {
|
|
5298
|
+
const read = await gateway.read();
|
|
5299
|
+
if (!read.ok) return { ok: false, failure: { source: "vercel-oidc", failure: read.failure } };
|
|
5300
|
+
const project = read.credential.vercelProject();
|
|
5301
|
+
if (project === void 0)
|
|
5302
|
+
return { ok: false, failure: { source: "vercel-oidc", failure: { kind: "invalid-token" } } };
|
|
5303
|
+
return { ok: true, credential: read.credential, project };
|
|
5304
|
+
})();
|
|
5305
|
+
return outcome;
|
|
5306
|
+
},
|
|
5307
|
+
origin() {
|
|
5308
|
+
return { source: "vercel-oidc" };
|
|
5309
|
+
}
|
|
5310
|
+
};
|
|
5311
|
+
}
|
|
5312
|
+
function vercelProjectSource(choice, context, progress) {
|
|
5313
|
+
if (choice.source === "vercel-oidc") {
|
|
5314
|
+
const source2 = credentialSourceFor(choice, context, progress);
|
|
5315
|
+
return { source: source2, obtain: () => source2.obtain() };
|
|
5316
|
+
}
|
|
5317
|
+
const source = credentialSourceFor(choice, context, progress);
|
|
5318
|
+
return {
|
|
5319
|
+
source,
|
|
5320
|
+
obtain: async () => {
|
|
5321
|
+
const got = await source.obtain();
|
|
5322
|
+
if (!got.ok) return got;
|
|
5323
|
+
const project = got.credential.vercelProject();
|
|
5324
|
+
return project === void 0 ? { ok: false, failure: { source: "claims-missing", target: choice.target } } : { ok: true, credential: got.credential, project };
|
|
5325
|
+
}
|
|
5326
|
+
};
|
|
5327
|
+
}
|
|
4161
5328
|
|
|
4162
5329
|
// src/credential/target.ts
|
|
4163
5330
|
function mintTargetText(target) {
|
|
4164
5331
|
return `Vercel project ${target.project} on team ${target.team}`;
|
|
4165
5332
|
}
|
|
4166
5333
|
|
|
5334
|
+
// src/config/credential-settle.ts
|
|
5335
|
+
import { z as z5 } from "zod";
|
|
5336
|
+
var credentialErrors = defineErrors({
|
|
5337
|
+
missingTarget: {
|
|
5338
|
+
exitCode: 2,
|
|
5339
|
+
description: "The command may mint a credential, and neither a flag nor storm.config.ts names the control plane team or project.",
|
|
5340
|
+
schema: z5.object({
|
|
5341
|
+
/** The settings no flag or config file gave. */
|
|
5342
|
+
missing: z5.array(z5.enum(["scope", "project"]))
|
|
5343
|
+
}),
|
|
5344
|
+
render: ({ missing }) => ({
|
|
5345
|
+
message: `No control plane ${missing.map((key) => key === "scope" ? "team" : "project").join(" or ")} to mint a credential for.`,
|
|
5346
|
+
next: [
|
|
5347
|
+
{
|
|
5348
|
+
type: "text",
|
|
5349
|
+
text: `Give ${missing.map((key) => `--${key}`).join(" and ")}, or set ${missing.join(" and ")} in storm.config.ts.`
|
|
5350
|
+
}
|
|
5351
|
+
]
|
|
5352
|
+
})
|
|
5353
|
+
}
|
|
5354
|
+
});
|
|
5355
|
+
function requireTarget(scope, project) {
|
|
5356
|
+
if (scope === void 0 || project === void 0)
|
|
5357
|
+
return refused(
|
|
5358
|
+
credentialErrors.missingTarget({
|
|
5359
|
+
missing: [
|
|
5360
|
+
...scope === void 0 ? ["scope"] : [],
|
|
5361
|
+
...project === void 0 ? ["project"] : []
|
|
5362
|
+
]
|
|
5363
|
+
})
|
|
5364
|
+
);
|
|
5365
|
+
return { ok: true, target: { team: scope.value, project: project.value } };
|
|
5366
|
+
}
|
|
5367
|
+
function givenTarget(scope, project) {
|
|
5368
|
+
return scope === void 0 || project === void 0 ? null : { team: scope.value, project: project.value };
|
|
5369
|
+
}
|
|
5370
|
+
function settleCredential(source, scope, project) {
|
|
5371
|
+
if (source === "github-actions" || source === "vercel-oidc") return { ok: true, credential: { source } };
|
|
5372
|
+
const required = requireTarget(scope, project);
|
|
5373
|
+
if (!required.ok) return required;
|
|
5374
|
+
return { ok: true, credential: { source, target: required.target } };
|
|
5375
|
+
}
|
|
5376
|
+
|
|
4167
5377
|
// src/config/credential-resolver.ts
|
|
4168
5378
|
var credentialSourceErrors = defineErrors({
|
|
4169
5379
|
mintFailed: {
|
|
@@ -4183,23 +5393,36 @@ var credentialSourceErrors = defineErrors({
|
|
|
4183
5393
|
message: `Couldn't request a GitHub Actions OIDC token: ${detail}.`,
|
|
4184
5394
|
next: [{ type: "text", text: fix }]
|
|
4185
5395
|
})
|
|
5396
|
+
},
|
|
5397
|
+
vercelOidcTokenFailed: {
|
|
5398
|
+
exitCode: 1,
|
|
5399
|
+
description: "With --credential vercel-oidc, VERCEL_OIDC_TOKEN is missing, empty, or not a valid Vercel project OIDC token.",
|
|
5400
|
+
schema: z6.object(vercelOidcTokenFailureShape),
|
|
5401
|
+
render: ({ detail, fix }) => ({
|
|
5402
|
+
message: `Couldn't use VERCEL_OIDC_TOKEN: ${detail}.`,
|
|
5403
|
+
next: [{ type: "text", text: fix }]
|
|
5404
|
+
})
|
|
4186
5405
|
}
|
|
4187
5406
|
});
|
|
4188
5407
|
function credentialSourceError(failure) {
|
|
4189
|
-
|
|
5408
|
+
switch (failure.source) {
|
|
5409
|
+
case "mint":
|
|
5410
|
+
return credentialSourceErrors.mintFailed({
|
|
5411
|
+
...failure.target,
|
|
5412
|
+
...describeMintFailure(failure.failure, failure.target)
|
|
5413
|
+
});
|
|
5414
|
+
case "github-actions":
|
|
5415
|
+
return credentialSourceErrors.tokenRequestFailed(tokenRequestFailureFacts(failure.failure));
|
|
5416
|
+
case "vercel-oidc":
|
|
5417
|
+
return credentialSourceErrors.vercelOidcTokenFailed(vercelOidcTokenFailureFacts(failure.failure));
|
|
5418
|
+
}
|
|
4190
5419
|
}
|
|
4191
5420
|
function credentialResolver(gateways) {
|
|
4192
5421
|
return {
|
|
4193
5422
|
source(choice, target, report = {}) {
|
|
4194
5423
|
const chosen = settleCredential(choice, target.scope, target.project);
|
|
4195
5424
|
if (!chosen.ok) return chosen;
|
|
4196
|
-
const
|
|
4197
|
-
const source = credentialSourceFor(chosen.credential, gateways, {
|
|
4198
|
-
emit: async (event) => {
|
|
4199
|
-
if (event.kind === "minting") await progress?.(`Minting a credential for ${mintTargetText(event.target)}\u2026`);
|
|
4200
|
-
else if (event.kind === "requesting-token") await progress?.(REQUESTING_TOKEN_LINE);
|
|
4201
|
-
}
|
|
4202
|
-
});
|
|
5425
|
+
const source = credentialSourceFor(chosen.credential, gateways, commandLines(report));
|
|
4203
5426
|
return {
|
|
4204
5427
|
ok: true,
|
|
4205
5428
|
source: {
|
|
@@ -4210,17 +5433,39 @@ function credentialResolver(gateways) {
|
|
|
4210
5433
|
origin: (credential) => source.origin(credential)
|
|
4211
5434
|
}
|
|
4212
5435
|
};
|
|
5436
|
+
},
|
|
5437
|
+
vercelProjectSource(choice, target, report = {}) {
|
|
5438
|
+
let credential;
|
|
5439
|
+
if (choice === "vercel-oidc") credential = { source: choice };
|
|
5440
|
+
else {
|
|
5441
|
+
const required = requireTarget(target.scope, target.project);
|
|
5442
|
+
if (!required.ok) return required;
|
|
5443
|
+
credential = { source: choice, target: required.target };
|
|
5444
|
+
}
|
|
5445
|
+
const { obtain } = vercelProjectSource(credential, gateways, commandLines(report));
|
|
5446
|
+
return { ok: true, source: { obtain } };
|
|
5447
|
+
}
|
|
5448
|
+
};
|
|
5449
|
+
}
|
|
5450
|
+
function commandLines({ progress }) {
|
|
5451
|
+
return {
|
|
5452
|
+
emit: async (event) => {
|
|
5453
|
+
if (event.kind === "minting") await progress?.(`Minting a credential for ${mintTargetText(event.target)}\u2026`);
|
|
5454
|
+
else if (event.kind === "requesting-token") await progress?.(REQUESTING_TOKEN_LINE);
|
|
4213
5455
|
}
|
|
4214
5456
|
};
|
|
4215
5457
|
}
|
|
4216
5458
|
|
|
4217
5459
|
// src/config/live/config-gateway.ts
|
|
4218
5460
|
import { stat } from "node:fs/promises";
|
|
4219
|
-
import { basename, join as join3 } from "node:path";
|
|
5461
|
+
import { basename as basename2, join as join3 } from "node:path";
|
|
4220
5462
|
import { pathToFileURL } from "node:url";
|
|
4221
5463
|
function liveConfigGateway() {
|
|
4222
5464
|
return {
|
|
4223
|
-
|
|
5465
|
+
configFileNames: async (directory) => {
|
|
5466
|
+
const kinds = await Promise.all(CONFIG_FILE_NAMES.map((name) => kind(join3(directory, name))));
|
|
5467
|
+
return CONFIG_FILE_NAMES.filter((_, index) => kinds[index] === "file");
|
|
5468
|
+
},
|
|
4224
5469
|
isWorktreeRoot: async (directory) => await kind(join3(directory, ".git")) !== void 0,
|
|
4225
5470
|
importConfig: async (path) => {
|
|
4226
5471
|
try {
|
|
@@ -4241,7 +5486,7 @@ async function kind(path) {
|
|
|
4241
5486
|
}
|
|
4242
5487
|
function importFailure(error, path) {
|
|
4243
5488
|
if (!(error instanceof Error)) return { kind: "import-failed", message: String(error) };
|
|
4244
|
-
const location = errorLocation(error,
|
|
5489
|
+
const location = errorLocation(error, basename2(path));
|
|
4245
5490
|
return { kind: "import-failed", message: error.message, ...location === void 0 ? {} : { location } };
|
|
4246
5491
|
}
|
|
4247
5492
|
function errorLocation(error, name) {
|
|
@@ -4286,24 +5531,6 @@ function liveFileListsFileGateway(stdin = process.stdin) {
|
|
|
4286
5531
|
};
|
|
4287
5532
|
}
|
|
4288
5533
|
|
|
4289
|
-
// src/config/recipe-run.ts
|
|
4290
|
-
var NOT_PRESENT = Object.freeze({ present: false });
|
|
4291
|
-
function recipeRun(resources, sandboxes = 1) {
|
|
4292
|
-
const run = {
|
|
4293
|
-
sandboxes,
|
|
4294
|
-
get: ({ definition }) => {
|
|
4295
|
-
const key = defaultResourceKey(definition);
|
|
4296
|
-
const resource = Object.hasOwn(resources, key) ? resources[key] : void 0;
|
|
4297
|
-
if (resource === void 0 || resource.definition !== definition.name) return NOT_PRESENT;
|
|
4298
|
-
return Object.freeze({
|
|
4299
|
-
present: true,
|
|
4300
|
-
value: resourceOptionsOf(definition, Object.freeze({ ...resource.options }))
|
|
4301
|
-
});
|
|
4302
|
-
}
|
|
4303
|
-
};
|
|
4304
|
-
return { run: Object.freeze(run), resourceKeys: Object.keys(resources) };
|
|
4305
|
-
}
|
|
4306
|
-
|
|
4307
5534
|
// src/config/resolver.ts
|
|
4308
5535
|
function configResolver(launcher) {
|
|
4309
5536
|
const loadFile = () => loadSettingsFile(launcher.gateway, launcher.cwd, launcher.definitions, launcher.drivers);
|
|
@@ -4329,12 +5556,15 @@ function configResolver(launcher) {
|
|
|
4329
5556
|
export {
|
|
4330
5557
|
liveGitHubActionsTokenGateway,
|
|
4331
5558
|
liveCredentialGateway,
|
|
5559
|
+
liveVercelOidcTokenGateway,
|
|
4332
5560
|
credentialSourceFor,
|
|
5561
|
+
vercelProjectSource,
|
|
4333
5562
|
mintTargetText,
|
|
4334
5563
|
credentialErrors,
|
|
4335
|
-
|
|
5564
|
+
givenTarget,
|
|
4336
5565
|
settleCredential,
|
|
4337
5566
|
credentialSourceErrors,
|
|
5567
|
+
credentialSourceError,
|
|
4338
5568
|
credentialResolver,
|
|
4339
5569
|
configErrors,
|
|
4340
5570
|
RUNNER_SNAPSHOTS_SUBPATH,
|
|
@@ -4354,8 +5584,8 @@ export {
|
|
|
4354
5584
|
liveRunnerSandboxGateway,
|
|
4355
5585
|
liveRunnerTerminal,
|
|
4356
5586
|
localUserName,
|
|
4357
|
-
|
|
4358
|
-
|
|
5587
|
+
liveRunnerSnapshotIndexGateway,
|
|
5588
|
+
unavailableRunnerSnapshotIndexGateway,
|
|
4359
5589
|
prepareRunner,
|
|
4360
5590
|
chooseSnapshotForRun,
|
|
4361
5591
|
SANDBOX_TEST_EVENTS_PATH,
|
|
@@ -4363,12 +5593,15 @@ export {
|
|
|
4363
5593
|
readCredentials,
|
|
4364
5594
|
readUnsafeSecretEnvVars,
|
|
4365
5595
|
openRunnerSession,
|
|
4366
|
-
|
|
5596
|
+
inspectLocalSnapshotIndex,
|
|
5597
|
+
listSharedSnapshots,
|
|
5598
|
+
pickSnapshotAcrossIndexes,
|
|
5599
|
+
pruneSharedSnapshots,
|
|
4367
5600
|
CONFIG_FILE_NAME,
|
|
5601
|
+
CONFIG_FILE_NAMES_TEXT,
|
|
4368
5602
|
liveConfigGateway,
|
|
4369
5603
|
liveFileListsFileGateway,
|
|
4370
5604
|
findConfigFile,
|
|
4371
|
-
recipeRun,
|
|
4372
5605
|
effectiveConfig,
|
|
4373
5606
|
fileSettings,
|
|
4374
5607
|
settleRunResources,
|