@cnc-tools/storm 0.16.0 → 0.18.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/bin/storm.js +54 -40
- package/dist/build-info.js +1 -1
- package/dist/chunks/{chunk-VL7WFTVQ.js → chunk-24UYAK4R.js} +465 -365
- package/dist/chunks/{chunk-DC2CDHNK.js → chunk-2JMWUKH3.js} +2074 -473
- package/dist/chunks/{chunk-FOZWA52V.js → chunk-3VXZONGE.js} +481 -376
- package/dist/chunks/{chunk-ZG3WQ4UF.js → chunk-55O4FCN4.js} +1 -1
- package/dist/chunks/{chunk-CN4EFA5J.js → chunk-72ZFEMAW.js} +1 -1
- package/dist/chunks/chunk-AS37D43E.js +2173 -0
- package/dist/chunks/chunk-CQAY6GLP.js +1260 -0
- package/dist/chunks/chunk-DZLU7BYK.js +340 -0
- package/dist/chunks/{chunk-R7XVBZOY.js → chunk-EEENLQHE.js} +59 -11
- package/dist/chunks/{chunk-TJNFVNKR.js → chunk-EI3XDCEI.js} +1 -1
- package/dist/chunks/{chunk-HVNK3I45.js → chunk-FDUY3BNF.js} +1 -1
- package/dist/chunks/{chunk-FCQUJDA4.js → chunk-GUCCYCIO.js} +4 -189
- package/dist/chunks/{chunk-OIY3DMF2.js → chunk-HBI4LEMH.js} +3 -3
- package/dist/chunks/{chunk-2MAD5NKK.js → chunk-K4MDQPLW.js} +1 -18
- package/dist/chunks/chunk-KK7PAWIZ.js +198 -0
- package/dist/chunks/{chunk-G3PHMXH5.js → chunk-KQ5FXRUD.js} +18 -1
- package/dist/chunks/{chunk-5VXBKPW6.js → chunk-LKXHGGGX.js} +1 -1
- package/dist/chunks/{chunk-P357TZAY.js → chunk-LOGHIUUB.js} +21 -18
- package/dist/chunks/{chunk-CK2GZEPK.js → chunk-OEPFINFT.js} +2 -2
- package/dist/chunks/{chunk-DWEAHX4T.js → chunk-OI4AP6Z7.js} +5 -5
- package/dist/chunks/{chunk-V4IKA3WI.js → chunk-PMBQWVTW.js} +26 -19
- package/dist/chunks/chunk-SZMYIIG2.js +88 -0
- package/dist/chunks/{chunk-5CCP36QQ.js → chunk-TXCOFC7N.js} +1 -1
- package/dist/chunks/{chunk-VUPZH7J2.js → chunk-UXD3TVWM.js} +1 -1
- package/dist/chunks/{chunk-3L52KNQA.js → chunk-WNW2QXQK.js} +8 -8
- package/dist/chunks/{chunk-AWBSONHB.js → chunk-XBDRVFEV.js} +55 -16
- package/dist/chunks/{live-app-WECQOQ4C.js → live-app-UY7BEDUN.js} +17 -13
- package/dist/cli.d.ts +28 -0
- package/dist/cli.js +64 -0
- package/dist/commands/exec/across-sandboxes-outcomes.d.ts +2 -2
- package/dist/commands/exec/across-sandboxes-outcomes.js +3 -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 +67 -14
- 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 +104 -22
- package/dist/commands/exec/outcomes.js +73 -26
- package/dist/commands/exec/plan-run.d.ts +58 -150
- package/dist/commands/exec/plan-run.js +239 -90
- 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 +4 -4
- 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 +8 -4
- package/dist/commands/runs/facts.js +19 -10
- package/dist/commands/runs/list/command.d.ts +16 -8
- package/dist/commands/runs/list/command.js +10 -10
- package/dist/commands/runs/list/outcomes.d.ts +8 -4
- package/dist/commands/runs/logs/command.js +10 -10
- package/dist/commands/runs/show/command.d.ts +16 -8
- package/dist/commands/runs/show/command.js +31 -29
- package/dist/commands/runs/show/metadata.js +1 -1
- package/dist/commands/runs/show/outcomes.d.ts +8 -4
- package/dist/commands/runs/show/outcomes.js +8 -6
- 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 +376 -101
- package/dist/commands/snapshots/build/command.js +447 -149
- 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 +242 -47
- 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 +298 -68
- 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 +247 -15
- package/dist/commands/snapshots/list/outcomes.js +223 -52
- 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 +17 -17
- package/dist/commands/suites/list/outcomes.js +2 -2
- package/dist/commands/test/command.d.ts +67 -14
- package/dist/commands/test/command.js +49 -252
- package/dist/commands/test/outcomes.d.ts +33 -7
- package/dist/config/check-runner.d.ts +3 -3
- package/dist/config/check-runner.js +8 -7
- 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/index.d.ts +2 -2
- package/dist/config/index.js +1 -1
- package/dist/config/runner.d.ts +5 -5
- package/dist/config/runner.js +1 -1
- package/dist/config/schema.d.ts +2 -2
- package/dist/config/schema.js +1 -1
- package/dist/config-file/define.d.ts +1 -1
- package/dist/config-file/define.js +1 -1
- package/dist/config-file/runner.d.ts +5 -5
- package/dist/config-file/toolchain.d.ts +14 -4
- package/dist/config-file/toolchain.js +43 -7
- package/dist/context.d.ts +10 -6
- package/dist/context.js +8 -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 +107 -267
- 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 +1 -1
- package/dist/extension-commands.js +2 -2
- 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 +1 -1
- package/dist/extensions/testserver/resource.js +1 -1
- 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 +3 -14
- package/dist/planning/plan-only.js +11 -20
- package/dist/planning/run-kind-flags.js +2 -2
- package/dist/planning/run-plan.d.ts +45 -12
- 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 +9 -0
- package/dist/run-directory/recording.js +3 -3
- package/dist/run-directory/run-record.d.ts +26 -11
- package/dist/run-directory/run-record.js +16 -13
- package/dist/runner/base.js +1 -1
- package/dist/runner/build-snapshots.d.ts +60 -29
- package/dist/runner/build-snapshots.js +136 -29
- 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 +122 -23
- package/dist/runner/gateways.js +1 -1
- package/dist/runner/gh.d.ts +42 -0
- package/dist/runner/gh.js +58 -0
- package/dist/runner/index.d.ts +13 -8
- package/dist/runner/index.js +12 -6
- package/dist/runner/live/checkout-gateway.js +7 -0
- package/dist/runner/live/gh-output.d.ts +17 -0
- package/dist/runner/live/gh-output.js +37 -0
- package/dist/runner/live/gh-token-gateway.d.ts +13 -0
- package/dist/runner/live/gh-token-gateway.js +51 -0
- 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 +140 -4
- 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 +12 -12
- package/dist/runner/local-snapshot-index.d.ts +205 -0
- package/dist/runner/local-snapshot-index.js +210 -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 +14 -14
- package/dist/runner/prepare.js +20 -11
- package/dist/runner/ready.d.ts +19 -11
- 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 +15 -8
- package/dist/runner/scope.js +16 -5
- package/dist/runner/secrets.d.ts +41 -18
- package/dist/runner/secrets.js +226 -30
- package/dist/runner/session.d.ts +8 -8
- package/dist/runner/session.js +6 -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 +79 -47
- package/dist/runner/snapshot-choice.js +2 -1
- package/dist/runner/snapshot-inspect.d.ts +39 -40
- package/dist/runner/snapshot-inspect.js +52 -35
- package/dist/runner/snapshot-key.d.ts +32 -17
- package/dist/runner/snapshot-key.js +43 -18
- package/dist/runner/snapshot-source.d.ts +31 -0
- package/dist/runner/snapshot-source.js +122 -0
- 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} +4 -2
- package/dist/runner/{recipe-check.js → vercel-sandbox-check.js} +7 -2
- package/dist/runner/{recipe.d.ts → vercel-sandbox-options.d.ts} +59 -28
- package/dist/runner/{recipe.js → vercel-sandbox-options.js} +128 -84
- package/dist/runner/vercel-sandbox-secrets.d.ts +116 -0
- package/dist/runner/{recipe-secrets.js → vercel-sandbox-secrets.js} +159 -26
- 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 +1 -1
- 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/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 +5 -3
- package/skills/overview.md +4 -4
- package/skills/plan-runs.md +1 -1
- package/skills/read-run-output.md +6 -6
- package/dist/application.d.ts +0 -21
- package/dist/application.js +0 -30
- package/dist/chunks/chunk-7EENF73W.js +0 -782
- package/dist/chunks/chunk-Z5PBVG3Y.js +0 -2599
- 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 -45
- package/dist/commands/exec/run-command.d.ts +0 -475
- package/dist/commands/exec/run-command.js +0 -603
- 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 -125
- package/dist/core/sandbox-end.d.ts +0 -64
- package/dist/runner/live/snapshot-cache-gateway.d.ts +0 -12
- package/dist/runner/recipe-secrets.d.ts +0 -67
- package/dist/runner/snapshot-cache.d.ts +0 -148
- package/dist/runner/snapshot-cache.js +0 -126
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
ENV_VAR_NAME_PATTERN,
|
|
4
4
|
ENV_VAR_NAME_RULE,
|
|
5
5
|
NOT_COUNTED,
|
|
6
|
+
SECRET_MIN_LENGTH,
|
|
6
7
|
booleanOption,
|
|
7
8
|
defaultResourceKey,
|
|
8
9
|
describeMintFailure,
|
|
@@ -15,52 +16,14 @@ import {
|
|
|
15
16
|
resourceCall,
|
|
16
17
|
secretSourceId,
|
|
17
18
|
tokenRequestFailureFacts,
|
|
18
|
-
tokenRequestFailureShape
|
|
19
|
-
|
|
19
|
+
tokenRequestFailureShape,
|
|
20
|
+
vercelOidcTokenFailureFacts,
|
|
21
|
+
vercelOidcTokenFailureShape
|
|
22
|
+
} from "./chunk-XBDRVFEV.js";
|
|
20
23
|
import {
|
|
21
24
|
defineErrors,
|
|
22
25
|
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
|
-
}
|
|
26
|
+
} from "./chunk-24UYAK4R.js";
|
|
64
27
|
|
|
65
28
|
// src/runner/base.ts
|
|
66
29
|
async function resolveBase(checkout, request2) {
|
|
@@ -90,6 +53,171 @@ async function resolveBase(checkout, request2) {
|
|
|
90
53
|
return best === void 0 ? { kind: "no-base-ref", refs: refused2 } : { kind: "resolved", ...best };
|
|
91
54
|
}
|
|
92
55
|
|
|
56
|
+
// src/runner/context.ts
|
|
57
|
+
function runnerPurpose(runnerName) {
|
|
58
|
+
return `storm-runner-${runnerName}`;
|
|
59
|
+
}
|
|
60
|
+
function runnerTags(runnerName, role, user) {
|
|
61
|
+
return { purpose: runnerPurpose(runnerName), user, role };
|
|
62
|
+
}
|
|
63
|
+
function snapshotIndexTags(runnerName, user, base, expiresAt) {
|
|
64
|
+
return {
|
|
65
|
+
purpose: runnerPurpose(runnerName),
|
|
66
|
+
user,
|
|
67
|
+
role: "snapshot-index",
|
|
68
|
+
base,
|
|
69
|
+
"expires-at": expiresAt
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// src/runner/local-snapshot-index.ts
|
|
74
|
+
import { createHash } from "node:crypto";
|
|
75
|
+
var RUNNER_SNAPSHOTS_SUBPATH = ["runner", "snapshots"];
|
|
76
|
+
var SNAPSHOT_EXPIRATION_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
77
|
+
var SNAPSHOT_MIN_REMAINING_MS = 60 * 60 * 1e3;
|
|
78
|
+
function sameRunnerTarget(a, b) {
|
|
79
|
+
return a.name === b.name && a.region === b.region && a.image === b.image;
|
|
80
|
+
}
|
|
81
|
+
function matchesRunnerTarget(entry, target) {
|
|
82
|
+
return sameRunnerTarget({ name: entry.runnerName, region: entry.region, image: entry.image }, target);
|
|
83
|
+
}
|
|
84
|
+
function snapshotEntryIdentity(entry) {
|
|
85
|
+
return createHash("sha256").update(
|
|
86
|
+
[entry.teamId, entry.projectId, entry.region, entry.image, entry.runnerName, entry.snapshotKey, entry.base].join(
|
|
87
|
+
"\0"
|
|
88
|
+
)
|
|
89
|
+
).digest("hex").slice(0, 32);
|
|
90
|
+
}
|
|
91
|
+
function snapshotEntryFileName(entry) {
|
|
92
|
+
return `${snapshotEntryIdentity(entry)}.json`;
|
|
93
|
+
}
|
|
94
|
+
function isExpiredEntry(entry, now) {
|
|
95
|
+
return Date.parse(entry.expiresAt) <= now.getTime();
|
|
96
|
+
}
|
|
97
|
+
function hasTimeLeft(entry, now) {
|
|
98
|
+
return Date.parse(entry.expiresAt) - now.getTime() > SNAPSHOT_MIN_REMAINING_MS;
|
|
99
|
+
}
|
|
100
|
+
async function removeExpiredEntries(context) {
|
|
101
|
+
const { runnerSnapshots } = context;
|
|
102
|
+
const listed = await runnerSnapshots.listEntries();
|
|
103
|
+
if (!listed.ok) return { entries: [], notes: [{ kind: "local-index-unreadable", failure: listed.failure }] };
|
|
104
|
+
const now = context.clock.now();
|
|
105
|
+
const entries = [];
|
|
106
|
+
const notes = [];
|
|
107
|
+
for (const entry of listed.value.entries) {
|
|
108
|
+
if (!isExpiredEntry(entry, now)) {
|
|
109
|
+
entries.push(entry);
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
const removed = await runnerSnapshots.removeEntry(entry);
|
|
113
|
+
if (!removed.ok) notes.push({ kind: "expired-entry-not-removed", entry, failure: removed.failure });
|
|
114
|
+
}
|
|
115
|
+
return { entries, notes };
|
|
116
|
+
}
|
|
117
|
+
async function resolveAncestorDistances(context, request2) {
|
|
118
|
+
const { checkout, clock } = context;
|
|
119
|
+
const { repoRoot, entries, options, mergeBase } = request2;
|
|
120
|
+
const now = clock.now();
|
|
121
|
+
const seen = /* @__PURE__ */ new Set([mergeBase]);
|
|
122
|
+
const distances = {};
|
|
123
|
+
for (const entry of entries) {
|
|
124
|
+
if (!matchesRunnerTarget(entry, options)) continue;
|
|
125
|
+
if (isExpiredEntry(entry, now) || !hasTimeLeft(entry, now)) continue;
|
|
126
|
+
if (seen.has(entry.base)) continue;
|
|
127
|
+
seen.add(entry.base);
|
|
128
|
+
const contained = await checkout.contains({ repoRoot, ancestor: entry.base, descendant: mergeBase });
|
|
129
|
+
if (!contained.ok) return contained;
|
|
130
|
+
if (!contained.value) continue;
|
|
131
|
+
const behindMergeBase = await checkout.commitCount({ repoRoot, from: entry.base, to: mergeBase });
|
|
132
|
+
if (!behindMergeBase.ok) return behindMergeBase;
|
|
133
|
+
distances[entry.base] = behindMergeBase.value;
|
|
134
|
+
}
|
|
135
|
+
return { ok: true, value: distances };
|
|
136
|
+
}
|
|
137
|
+
function classifySnapshotEntries(context, request2) {
|
|
138
|
+
const { entries, options, base, snapshotKey: snapshotKey2, commitsAfterBase, ancestorDistances } = request2;
|
|
139
|
+
const now = context.clock.now();
|
|
140
|
+
const candidates = [];
|
|
141
|
+
const rejected = [];
|
|
142
|
+
const verdicts = [];
|
|
143
|
+
const reject = (entry, reason) => {
|
|
144
|
+
const rejection = { entry, reason };
|
|
145
|
+
rejected.push(rejection);
|
|
146
|
+
verdicts.push({ kind: "rejected", entry, rejection });
|
|
147
|
+
};
|
|
148
|
+
for (const entry of entries) {
|
|
149
|
+
if (!matchesRunnerTarget(entry, options)) {
|
|
150
|
+
verdicts.push({ kind: "other-runner", entry });
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
if (isExpiredEntry(entry, now)) {
|
|
154
|
+
reject(entry, "expired");
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
if (!hasTimeLeft(entry, now)) {
|
|
158
|
+
reject(entry, "expires-soon");
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
const commitsBehindMergeBase = entry.base === base ? 0 : ancestorDistances !== void 0 && Object.hasOwn(ancestorDistances, entry.base) ? ancestorDistances[entry.base] : void 0;
|
|
162
|
+
if (commitsBehindMergeBase === void 0) {
|
|
163
|
+
reject(entry, "other-base");
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
if (entry.snapshotKey !== snapshotKey2) {
|
|
167
|
+
reject(entry, "steps-changed");
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
const candidate = {
|
|
171
|
+
entry,
|
|
172
|
+
builtBehind: commitsAfterBase + commitsBehindMergeBase,
|
|
173
|
+
commitsBehindMergeBase
|
|
174
|
+
};
|
|
175
|
+
candidates.push(candidate);
|
|
176
|
+
verdicts.push({ kind: "candidate", entry, candidate });
|
|
177
|
+
}
|
|
178
|
+
candidates.sort(
|
|
179
|
+
(a, b) => compareSnapshotCandidates(
|
|
180
|
+
{
|
|
181
|
+
commitsBehindMergeBase: a.commitsBehindMergeBase,
|
|
182
|
+
createdAt: a.entry.createdAt,
|
|
183
|
+
tieBreaker: a.entry.snapshotId
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
commitsBehindMergeBase: b.commitsBehindMergeBase,
|
|
187
|
+
createdAt: b.entry.createdAt,
|
|
188
|
+
tieBreaker: b.entry.snapshotId
|
|
189
|
+
}
|
|
190
|
+
)
|
|
191
|
+
);
|
|
192
|
+
return { candidates, rejected, verdicts };
|
|
193
|
+
}
|
|
194
|
+
function parseTimestampMs(iso) {
|
|
195
|
+
const ms = Date.parse(iso);
|
|
196
|
+
return Number.isNaN(ms) ? Number.NEGATIVE_INFINITY : ms;
|
|
197
|
+
}
|
|
198
|
+
function compareSnapshotCandidates(a, b) {
|
|
199
|
+
if (a.commitsBehindMergeBase !== b.commitsBehindMergeBase) {
|
|
200
|
+
return a.commitsBehindMergeBase - b.commitsBehindMergeBase;
|
|
201
|
+
}
|
|
202
|
+
const aCreated = parseTimestampMs(a.createdAt);
|
|
203
|
+
const bCreated = parseTimestampMs(b.createdAt);
|
|
204
|
+
if (aCreated !== bCreated) return bCreated - aCreated;
|
|
205
|
+
return a.tieBreaker < b.tieBreaker ? -1 : a.tieBreaker > b.tieBreaker ? 1 : 0;
|
|
206
|
+
}
|
|
207
|
+
function sharedBeatsLocal(sharedCommitsBehindMergeBase, localCommitsBehindMergeBase) {
|
|
208
|
+
return localCommitsBehindMergeBase === void 0 || sharedCommitsBehindMergeBase < localCommitsBehindMergeBase;
|
|
209
|
+
}
|
|
210
|
+
function snapshotRejections(read, owner) {
|
|
211
|
+
const owned = (entry) => entry.teamId === owner.teamId && entry.projectId === owner.projectId;
|
|
212
|
+
return [
|
|
213
|
+
...read.candidates.map(({ entry }) => ({ entry, reason: "other-owner" })),
|
|
214
|
+
...read.rejected.map(({ entry, reason }) => ({ entry, reason: owned(entry) ? reason : "other-owner" }))
|
|
215
|
+
];
|
|
216
|
+
}
|
|
217
|
+
function pickSnapshot(candidates, owner) {
|
|
218
|
+
return candidates.find(({ entry }) => entry.teamId === owner.teamId && entry.projectId === owner.projectId);
|
|
219
|
+
}
|
|
220
|
+
|
|
93
221
|
// src/runner/time-limit.ts
|
|
94
222
|
function callWithin(timer, ms, call) {
|
|
95
223
|
const abort = new AbortController();
|
|
@@ -133,9 +261,9 @@ function untilAborted(promise, signal) {
|
|
|
133
261
|
|
|
134
262
|
// src/runner/network-policy.ts
|
|
135
263
|
var NETWORK_POLICY_WRITE_LIMIT_MS = 1e4;
|
|
136
|
-
function runnerNetworkPolicy(
|
|
137
|
-
if (
|
|
138
|
-
return { kind: "custom", allowedDomains: [...
|
|
264
|
+
function runnerNetworkPolicy(options) {
|
|
265
|
+
if (options.allowedDomains === void 0) return { kind: "allow-all", credentials: [] };
|
|
266
|
+
return { kind: "custom", allowedDomains: [...options.allowedDomains], credentials: [] };
|
|
139
267
|
}
|
|
140
268
|
function withCredentials(base, credentials2) {
|
|
141
269
|
return { ...base, credentials: credentials2 };
|
|
@@ -243,6 +371,9 @@ var SNAPSHOT_SETTLE_MS = 2 * 6e4;
|
|
|
243
371
|
var SANDBOX_CALL_LIMIT_MS = 3e4;
|
|
244
372
|
var KEEP_RUNNING_LIMIT_MS = 6e4;
|
|
245
373
|
function runnerSandboxScope(context, progress, settings) {
|
|
374
|
+
const managedCredentials = settings.managedCredentials ?? [];
|
|
375
|
+
if (managedCredentials.length > 0 && settings.keepMs > 0)
|
|
376
|
+
throw new Error("a sandbox scope with managedCredentials can't keep its runner sandbox");
|
|
246
377
|
const { runnerSandboxes: sandboxes, timer, clock } = context;
|
|
247
378
|
let phase = { kind: "open", sandboxes: /* @__PURE__ */ new Map(), creating: /* @__PURE__ */ new Set() };
|
|
248
379
|
const saving = /* @__PURE__ */ new Set();
|
|
@@ -439,9 +570,13 @@ function runnerSandboxScope(context, progress, settings) {
|
|
|
439
570
|
}
|
|
440
571
|
if (settings.signal.aborted) onSignal();
|
|
441
572
|
else settings.signal.addEventListener("abort", onSignal, { once: true });
|
|
573
|
+
const managed = managedCredentials.length === 0 ? {} : { managedCredentials };
|
|
442
574
|
return {
|
|
443
|
-
startBuildSandbox: (access, request2) => owned(() => sandboxes.startBuildSandbox(access, { ...request2, networkPolicy: settings.basePolicy })),
|
|
444
|
-
startRunnerSandbox: (access, request2) => owned(
|
|
575
|
+
startBuildSandbox: (access, request2) => owned(() => sandboxes.startBuildSandbox(access, { ...request2, networkPolicy: settings.basePolicy, ...managed })),
|
|
576
|
+
startRunnerSandbox: (access, request2) => owned(
|
|
577
|
+
() => sandboxes.startRunnerSandbox(access, { ...request2, networkPolicy: settings.basePolicy, ...managed }),
|
|
578
|
+
true
|
|
579
|
+
),
|
|
445
580
|
grantCredentials,
|
|
446
581
|
revokeCredentials,
|
|
447
582
|
saveSnapshot: (sandbox, request2) => track(
|
|
@@ -452,9 +587,15 @@ function runnerSandboxScope(context, progress, settings) {
|
|
|
452
587
|
if (!removed.ok)
|
|
453
588
|
return { ok: false, failure: { kind: "credential-not-revoked", failure: removed.failure } };
|
|
454
589
|
}
|
|
455
|
-
const saved = await sandboxes.saveSnapshot(sandbox, request2);
|
|
590
|
+
const saved = await sandboxes.saveSnapshot(sandbox, { expirationMs: request2.expirationMs });
|
|
456
591
|
const now = currentPhase();
|
|
457
|
-
if (saved.ok
|
|
592
|
+
if (saved.ok) {
|
|
593
|
+
if (request2.keepStopped === true) {
|
|
594
|
+
if (now.kind === "open") now.sandboxes.delete(sandbox);
|
|
595
|
+
} else if (now.kind !== "closing" && now.sandboxes.delete(sandbox)) {
|
|
596
|
+
await deleteSandbox(sandbox);
|
|
597
|
+
}
|
|
598
|
+
}
|
|
458
599
|
return saved;
|
|
459
600
|
})()
|
|
460
601
|
),
|
|
@@ -488,97 +629,6 @@ function callFailureMessage(answer, limitMs) {
|
|
|
488
629
|
return answer === null ? `no answer within ${limitMs / 1e3} seconds` : failureMessage(answer.failure);
|
|
489
630
|
}
|
|
490
631
|
|
|
491
|
-
// src/runner/context.ts
|
|
492
|
-
function runnerPurpose(recipeName) {
|
|
493
|
-
return `storm-runner-${recipeName}`;
|
|
494
|
-
}
|
|
495
|
-
function runnerTags(recipeName, role, user) {
|
|
496
|
-
return { purpose: runnerPurpose(recipeName), user, role };
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
// src/runner/snapshot-cache.ts
|
|
500
|
-
import { createHash } from "node:crypto";
|
|
501
|
-
var RUNNER_SNAPSHOTS_SUBPATH = ["runner", "snapshots"];
|
|
502
|
-
var SNAPSHOT_EXPIRATION_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
503
|
-
var SNAPSHOT_MIN_REMAINING_MS = 60 * 60 * 1e3;
|
|
504
|
-
function snapshotEntryIdentity(entry) {
|
|
505
|
-
return createHash("sha256").update(
|
|
506
|
-
[
|
|
507
|
-
entry.teamId,
|
|
508
|
-
entry.projectId,
|
|
509
|
-
entry.region,
|
|
510
|
-
entry.runtime,
|
|
511
|
-
entry.recipeName,
|
|
512
|
-
entry.snapshotKey,
|
|
513
|
-
entry.base
|
|
514
|
-
].join("\0")
|
|
515
|
-
).digest("hex").slice(0, 32);
|
|
516
|
-
}
|
|
517
|
-
function snapshotEntryFileName(entry) {
|
|
518
|
-
return `${snapshotEntryIdentity(entry)}.json`;
|
|
519
|
-
}
|
|
520
|
-
function isExpiredEntry(entry, now) {
|
|
521
|
-
return Date.parse(entry.expiresAt) <= now.getTime();
|
|
522
|
-
}
|
|
523
|
-
function hasTimeLeft(entry, now) {
|
|
524
|
-
return Date.parse(entry.expiresAt) - now.getTime() > SNAPSHOT_MIN_REMAINING_MS;
|
|
525
|
-
}
|
|
526
|
-
async function removeExpiredEntries(context) {
|
|
527
|
-
const { runnerSnapshots } = context;
|
|
528
|
-
const listed = await runnerSnapshots.listEntries();
|
|
529
|
-
if (!listed.ok) return { entries: [], notes: [{ kind: "cache-unreadable", failure: listed.failure }] };
|
|
530
|
-
const now = context.clock.now();
|
|
531
|
-
const entries = [];
|
|
532
|
-
const notes = [];
|
|
533
|
-
for (const entry of listed.value.entries) {
|
|
534
|
-
if (!isExpiredEntry(entry, now)) {
|
|
535
|
-
entries.push(entry);
|
|
536
|
-
continue;
|
|
537
|
-
}
|
|
538
|
-
const removed = await runnerSnapshots.removeEntry(entry);
|
|
539
|
-
if (!removed.ok) notes.push({ kind: "expired-entry-not-removed", entry, failure: removed.failure });
|
|
540
|
-
}
|
|
541
|
-
return { entries, notes };
|
|
542
|
-
}
|
|
543
|
-
function classifySnapshotEntries(context, request2) {
|
|
544
|
-
const { entries, recipe, base, snapshotKey: snapshotKey2, commitsAfterBase } = request2;
|
|
545
|
-
const now = context.clock.now();
|
|
546
|
-
const candidates = [];
|
|
547
|
-
const rejected = [];
|
|
548
|
-
const verdicts = [];
|
|
549
|
-
const reject = (entry, reason) => {
|
|
550
|
-
const rejection = { entry, reason };
|
|
551
|
-
rejected.push(rejection);
|
|
552
|
-
verdicts.push({ kind: "rejected", entry, rejection });
|
|
553
|
-
};
|
|
554
|
-
for (const entry of entries) {
|
|
555
|
-
if (entry.region !== recipe.region || entry.runtime !== recipe.runtime || entry.recipeName !== recipe.name) {
|
|
556
|
-
verdicts.push({ kind: "other-recipe", entry });
|
|
557
|
-
continue;
|
|
558
|
-
}
|
|
559
|
-
if (isExpiredEntry(entry, now)) reject(entry, "expired");
|
|
560
|
-
else if (!hasTimeLeft(entry, now)) reject(entry, "expires-soon");
|
|
561
|
-
else if (entry.base !== base) reject(entry, "other-base");
|
|
562
|
-
else if (entry.snapshotKey !== snapshotKey2) reject(entry, "steps-changed");
|
|
563
|
-
else {
|
|
564
|
-
const candidate = { entry, builtBehind: commitsAfterBase };
|
|
565
|
-
candidates.push(candidate);
|
|
566
|
-
verdicts.push({ kind: "candidate", entry, candidate });
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
return { candidates, rejected, verdicts };
|
|
570
|
-
}
|
|
571
|
-
function snapshotRejections(read, owner) {
|
|
572
|
-
const owned = (entry) => entry.teamId === owner.teamId && entry.projectId === owner.projectId;
|
|
573
|
-
return [
|
|
574
|
-
...read.candidates.map(({ entry }) => ({ entry, reason: "other-owner" })),
|
|
575
|
-
...read.rejected.map(({ entry, reason }) => ({ entry, reason: owned(entry) ? reason : "other-owner" }))
|
|
576
|
-
];
|
|
577
|
-
}
|
|
578
|
-
function pickSnapshot(candidates, owner) {
|
|
579
|
-
return candidates.find(({ entry }) => entry.teamId === owner.teamId && entry.projectId === owner.projectId);
|
|
580
|
-
}
|
|
581
|
-
|
|
582
632
|
// src/runner/snapshot-key.ts
|
|
583
633
|
import { createHash as createHash2 } from "node:crypto";
|
|
584
634
|
|
|
@@ -623,67 +673,67 @@ var systemClock = {
|
|
|
623
673
|
};
|
|
624
674
|
|
|
625
675
|
// src/sdk/run/payload.ts
|
|
626
|
-
import { z
|
|
676
|
+
import { z } from "zod";
|
|
627
677
|
var RUN_PAYLOAD_VARIABLE = "STORM_RUN";
|
|
628
678
|
var RUN_PAYLOAD_VERSION = 3;
|
|
629
|
-
var runPayloadSandboxSchema =
|
|
630
|
-
index:
|
|
631
|
-
count:
|
|
632
|
-
files:
|
|
679
|
+
var runPayloadSandboxSchema = z.object({
|
|
680
|
+
index: z.number().int().nonnegative(),
|
|
681
|
+
count: z.number().int().positive(),
|
|
682
|
+
files: z.array(z.string().min(1)).optional()
|
|
633
683
|
});
|
|
634
|
-
var runPayloadSchema =
|
|
635
|
-
version:
|
|
636
|
-
resources:
|
|
637
|
-
testEvents:
|
|
638
|
-
verbose:
|
|
684
|
+
var runPayloadSchema = z.object({
|
|
685
|
+
version: z.literal(RUN_PAYLOAD_VERSION),
|
|
686
|
+
resources: z.record(z.string(), z.object({ definition: z.string().min(1), payload: z.unknown() })),
|
|
687
|
+
testEvents: z.string().min(1).optional(),
|
|
688
|
+
verbose: z.literal(true).optional(),
|
|
639
689
|
sandbox: runPayloadSandboxSchema.optional()
|
|
640
690
|
});
|
|
641
691
|
|
|
642
692
|
// src/sdk/run/test-events.ts
|
|
643
|
-
import { z as
|
|
644
|
-
var where = { file:
|
|
645
|
-
var fileWhere = { file:
|
|
646
|
-
var attempt = { id:
|
|
647
|
-
var setup = { label:
|
|
648
|
-
var state =
|
|
649
|
-
var testEventSchema =
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
kind:
|
|
693
|
+
import { z as z2 } from "zod";
|
|
694
|
+
var where = { file: z2.string(), worker: z2.number().int().nonnegative(), at: z2.number() };
|
|
695
|
+
var fileWhere = { file: z2.string(), worker: z2.number().int().nonnegative().exactOptional(), at: z2.number() };
|
|
696
|
+
var attempt = { id: z2.string().min(1), test: z2.string() };
|
|
697
|
+
var setup = { label: z2.string().min(1), resource: z2.string().min(1) };
|
|
698
|
+
var state = z2.enum(["pass", "fail", "skip"]);
|
|
699
|
+
var testEventSchema = z2.discriminatedUnion("kind", [
|
|
700
|
+
z2.object({ kind: z2.literal("file-started"), ...fileWhere }),
|
|
701
|
+
z2.object({ kind: z2.literal("file-finished"), ...fileWhere }),
|
|
702
|
+
z2.object({ kind: z2.literal("test-started"), ...where, ...attempt, fileTests: z2.number().int().nonnegative() }),
|
|
703
|
+
z2.object({
|
|
704
|
+
kind: z2.literal("test-attempt-finished"),
|
|
655
705
|
...where,
|
|
656
706
|
...attempt,
|
|
657
707
|
state,
|
|
658
|
-
ms:
|
|
708
|
+
ms: z2.number().nonnegative()
|
|
659
709
|
}),
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
kind:
|
|
710
|
+
z2.object({ kind: z2.literal("setup-started"), ...where, ...setup }),
|
|
711
|
+
z2.object({
|
|
712
|
+
kind: z2.literal("setup-finished"),
|
|
663
713
|
...where,
|
|
664
714
|
...setup,
|
|
665
|
-
ms:
|
|
666
|
-
ok:
|
|
667
|
-
warmupMs:
|
|
715
|
+
ms: z2.number().nonnegative(),
|
|
716
|
+
ok: z2.boolean(),
|
|
717
|
+
warmupMs: z2.number().nonnegative().exactOptional()
|
|
668
718
|
}),
|
|
669
|
-
|
|
670
|
-
kind:
|
|
671
|
-
id:
|
|
672
|
-
file:
|
|
673
|
-
test:
|
|
719
|
+
z2.object({
|
|
720
|
+
kind: z2.literal("test-result"),
|
|
721
|
+
id: z2.string().min(1),
|
|
722
|
+
file: z2.string(),
|
|
723
|
+
test: z2.string(),
|
|
674
724
|
state,
|
|
675
|
-
retryCount:
|
|
676
|
-
flaky:
|
|
677
|
-
at:
|
|
678
|
-
errors:
|
|
679
|
-
|
|
680
|
-
name:
|
|
681
|
-
message:
|
|
682
|
-
stack:
|
|
683
|
-
diff:
|
|
725
|
+
retryCount: z2.number().int().nonnegative(),
|
|
726
|
+
flaky: z2.boolean(),
|
|
727
|
+
at: z2.number(),
|
|
728
|
+
errors: z2.array(
|
|
729
|
+
z2.object({
|
|
730
|
+
name: z2.string(),
|
|
731
|
+
message: z2.string(),
|
|
732
|
+
stack: z2.string().exactOptional(),
|
|
733
|
+
diff: z2.string().exactOptional()
|
|
684
734
|
})
|
|
685
735
|
).exactOptional(),
|
|
686
|
-
output:
|
|
736
|
+
output: z2.object({ text: z2.string(), droppedChars: z2.number().int().nonnegative() }).exactOptional()
|
|
687
737
|
})
|
|
688
738
|
]);
|
|
689
739
|
function testEventLine(event) {
|
|
@@ -707,7 +757,7 @@ function redactSecrets(text, secrets) {
|
|
|
707
757
|
return ordered.reduce((redacted, secret) => redacted.split(secret).join(REDACTED), text);
|
|
708
758
|
}
|
|
709
759
|
|
|
710
|
-
// src/runner/
|
|
760
|
+
// src/runner/vercel-sandbox-check.ts
|
|
711
761
|
function reportUnknownKeys(value, known, path, what, report) {
|
|
712
762
|
let ok = true;
|
|
713
763
|
for (const key of Object.keys(value))
|
|
@@ -717,7 +767,7 @@ function reportUnknownKeys(value, known, path, what, report) {
|
|
|
717
767
|
}
|
|
718
768
|
return ok;
|
|
719
769
|
}
|
|
720
|
-
function
|
|
770
|
+
function describeOptionValue(value) {
|
|
721
771
|
if (typeof value === "string") return JSON.stringify(value);
|
|
722
772
|
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
723
773
|
if (value === null) return "null";
|
|
@@ -727,13 +777,139 @@ function describeRecipeValue(value) {
|
|
|
727
777
|
if (typeof value === "object") return "an object";
|
|
728
778
|
return `a ${typeof value}`;
|
|
729
779
|
}
|
|
780
|
+
function isRecord(value) {
|
|
781
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
// src/runner/snapshot-source.ts
|
|
785
|
+
var SNAPSHOT_SOURCE_KEYS = /* @__PURE__ */ new Set(["kind", "remote"]);
|
|
786
|
+
var DEFAULT_REMOTE = "origin";
|
|
787
|
+
var REMOTE_NAME_PATTERN = /^[A-Za-z0-9_][A-Za-z0-9._/-]*$/;
|
|
788
|
+
function checkSnapshotSource(value, report) {
|
|
789
|
+
if (value === void 0) return void 0;
|
|
790
|
+
const path = ["snapshot", "source"];
|
|
791
|
+
if (!isRecord(value)) {
|
|
792
|
+
const actual = typeof value === "string" ? "a string" : describeOptionValue(value);
|
|
793
|
+
report(path, `must be { kind: "git-fetch", remote? }, not ${actual}`);
|
|
794
|
+
return false;
|
|
795
|
+
}
|
|
796
|
+
let ok = reportUnknownKeys(value, SNAPSHOT_SOURCE_KEYS, path, "a vercelSandbox snapshot source key", report);
|
|
797
|
+
const kind2 = value["kind"];
|
|
798
|
+
if (kind2 !== "git-fetch") {
|
|
799
|
+
report([...path, "kind"], `must be "git-fetch", not ${describeOptionValue(kind2)}`);
|
|
800
|
+
ok = false;
|
|
801
|
+
}
|
|
802
|
+
const remote = value["remote"] === void 0 ? DEFAULT_REMOTE : value["remote"];
|
|
803
|
+
if (typeof remote !== "string" || !REMOTE_NAME_PATTERN.test(remote)) {
|
|
804
|
+
const rule = 'must be a Git remote name such as "origin" (letters, digits, ".", "_", "-", and "/", starting with a letter, digit, or "_")';
|
|
805
|
+
report([...path, "remote"], typeof remote === "string" ? rule : `${rule}, not ${describeOptionValue(remote)}`);
|
|
806
|
+
ok = false;
|
|
807
|
+
}
|
|
808
|
+
return ok ? { kind: "git-fetch", remote } : false;
|
|
809
|
+
}
|
|
810
|
+
var UNSAFE_URL_CHARS = /[\s'"`$\\;|&<>(){}[\]*?!#~]/;
|
|
811
|
+
var SCHEME_URL_PATTERN = /^([A-Za-z][A-Za-z0-9+.-]*):\/\/([^/]*)(.*)$/;
|
|
812
|
+
var SCP_URL_PATTERN = /^(?:([^@/]*)@)?([^@/:]+):(.*)$/;
|
|
813
|
+
var HOST_PORT_PATTERN = /^([^:]+)(?::(\d{1,5}))?$/;
|
|
814
|
+
var HOST_PATTERN = /^(?=.{1,253}$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+$/;
|
|
815
|
+
var CREDENTIALS_PROBLEM = "holds credentials; remove them from the remote URL and declare a sandbox credential in runner.credentials instead";
|
|
816
|
+
function normalizeGitFetchUrl(raw) {
|
|
817
|
+
if (raw.length === 0) return { ok: false, problem: "is empty" };
|
|
818
|
+
if (hasControlChar(raw) || UNSAFE_URL_CHARS.test(raw))
|
|
819
|
+
return { ok: false, problem: "holds whitespace, a control character, a quote, or a shell metacharacter" };
|
|
820
|
+
let https;
|
|
821
|
+
let userInfo2;
|
|
822
|
+
let hostPort;
|
|
823
|
+
let host;
|
|
824
|
+
let port;
|
|
825
|
+
let path;
|
|
826
|
+
const schemed = SCHEME_URL_PATTERN.exec(raw);
|
|
827
|
+
if (schemed !== null) {
|
|
828
|
+
const scheme = (schemed[1] ?? "").toLowerCase();
|
|
829
|
+
if (scheme !== "https" && scheme !== "ssh")
|
|
830
|
+
return { ok: false, problem: `uses ${scheme}://; git-fetch takes an HTTPS or SSH remote` };
|
|
831
|
+
https = scheme === "https";
|
|
832
|
+
const authority = schemed[2] ?? "";
|
|
833
|
+
const at = authority.lastIndexOf("@");
|
|
834
|
+
userInfo2 = at === -1 ? void 0 : authority.slice(0, at);
|
|
835
|
+
hostPort = at === -1 ? authority : authority.slice(at + 1);
|
|
836
|
+
host = "";
|
|
837
|
+
path = schemed[3] ?? "";
|
|
838
|
+
} else {
|
|
839
|
+
const scp = SCP_URL_PATTERN.exec(raw);
|
|
840
|
+
if (scp === null) return { ok: false, problem: "is not an HTTPS or SSH Git URL" };
|
|
841
|
+
https = false;
|
|
842
|
+
[, userInfo2, host = "", path = ""] = scp;
|
|
843
|
+
if (!path.startsWith("/")) path = `/${path}`;
|
|
844
|
+
}
|
|
845
|
+
if (userInfo2 !== void 0 && (https || userInfo2.includes(":") || userInfo2.includes("@")))
|
|
846
|
+
return { ok: false, problem: CREDENTIALS_PROBLEM };
|
|
847
|
+
if (hostPort !== void 0) {
|
|
848
|
+
const parsed = HOST_PORT_PATTERN.exec(hostPort);
|
|
849
|
+
if (parsed === null) return { ok: false, problem: "names no valid host or port" };
|
|
850
|
+
[, host = "", port] = parsed;
|
|
851
|
+
}
|
|
852
|
+
host = host.toLowerCase();
|
|
853
|
+
if (!HOST_PATTERN.test(host)) return { ok: false, problem: "names no valid host" };
|
|
854
|
+
if (port !== void 0 && (Number(port) < 1 || Number(port) > 65535))
|
|
855
|
+
return { ok: false, problem: "names no valid port" };
|
|
856
|
+
if (!isRepositoryPath(path)) return { ok: false, problem: "names no valid repository path" };
|
|
857
|
+
const httpsPort = https && port !== void 0 && Number(port) !== 443 ? `:${Number(port)}` : "";
|
|
858
|
+
return { ok: true, url: `https://${host}${httpsPort}${path}` };
|
|
859
|
+
}
|
|
860
|
+
function hasControlChar(value) {
|
|
861
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
862
|
+
const code = value.charCodeAt(index);
|
|
863
|
+
if (code <= 31 || code === 127) return true;
|
|
864
|
+
}
|
|
865
|
+
return false;
|
|
866
|
+
}
|
|
867
|
+
function isRepositoryPath(path) {
|
|
868
|
+
if (!path.startsWith("/") || path.includes("@") || path.includes(":")) return false;
|
|
869
|
+
return path.slice(1).split("/").every((segment) => segment.length > 0 && segment !== "." && segment !== "..");
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
// src/runner/gh.ts
|
|
873
|
+
var DEFAULT_GH_HOST = "github.com";
|
|
874
|
+
function resolveGhHost(source) {
|
|
875
|
+
return source.host ?? DEFAULT_GH_HOST;
|
|
876
|
+
}
|
|
877
|
+
function resolveGhFormat(domain, source) {
|
|
878
|
+
if (source.format !== void 0) return source.format;
|
|
879
|
+
return domain === resolveGhHost(source) ? "basic" : "bearer";
|
|
880
|
+
}
|
|
881
|
+
function ghBasicCredential(token) {
|
|
882
|
+
return Buffer.from(`x-access-token:${token}`, "utf8").toString("base64");
|
|
883
|
+
}
|
|
884
|
+
function frameGhToken(token, format) {
|
|
885
|
+
if (/[\r\n]/.test(token)) return { ok: false, problem: "multiline" };
|
|
886
|
+
if (/^(?:bearer|basic)\s/i.test(token)) return { ok: false, problem: "gh-preframed" };
|
|
887
|
+
if (token.length < SECRET_MIN_LENGTH) return { ok: false, problem: "short" };
|
|
888
|
+
if (format === "bearer") {
|
|
889
|
+
const headerValue2 = `Bearer ${token}`;
|
|
890
|
+
return { ok: true, headerValue: headerValue2, secrets: uniqueNonEmpty([headerValue2, token]) };
|
|
891
|
+
}
|
|
892
|
+
const basic = ghBasicCredential(token);
|
|
893
|
+
const headerValue = `Basic ${basic}`;
|
|
894
|
+
return { ok: true, headerValue, secrets: uniqueNonEmpty([headerValue, basic, token]) };
|
|
895
|
+
}
|
|
896
|
+
function ghEnvRedactionForms(raw) {
|
|
897
|
+
const basic = ghBasicCredential(raw);
|
|
898
|
+
return uniqueNonEmpty([`Basic ${basic}`, basic, `Bearer ${raw}`, raw]);
|
|
899
|
+
}
|
|
900
|
+
function uniqueNonEmpty(values) {
|
|
901
|
+
return [...new Set(values.filter((value) => value.length > 0))];
|
|
902
|
+
}
|
|
730
903
|
|
|
731
|
-
// src/runner/
|
|
904
|
+
// src/runner/vercel-sandbox-secrets.ts
|
|
732
905
|
var CREDENTIAL_KEYS = /* @__PURE__ */ new Set(["domain", "header", "source", "requests"]);
|
|
906
|
+
var MANAGED_CREDENTIALS = /* @__PURE__ */ new Set(["npm"]);
|
|
907
|
+
var MANAGED_NPM_DOMAIN = "registry.npmjs.org";
|
|
733
908
|
var UNSAFE_SECRET_ENV_VAR_KEYS = /* @__PURE__ */ new Set(["name", "source"]);
|
|
734
909
|
var ENV_SOURCE_KEYS = /* @__PURE__ */ new Set(["kind", "name"]);
|
|
910
|
+
var GH_SOURCE_KEYS = /* @__PURE__ */ new Set(["kind", "env", "host", "format"]);
|
|
735
911
|
var DEFAULT_CREDENTIAL_HEADER = "authorization";
|
|
736
|
-
var
|
|
912
|
+
var HOST_PATTERN2 = /^(?=.{1,253}$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+$/;
|
|
737
913
|
var HEADER_PATTERN = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
|
|
738
914
|
var REFUSED_HEADERS = /* @__PURE__ */ new Set(["host", "content-length", "transfer-encoding", "connection"]);
|
|
739
915
|
var RESERVED_UNSAFE_SECRET_ENV_VAR_NAMES = /* @__PURE__ */ new Set([
|
|
@@ -753,15 +929,73 @@ var RESERVED_UNSAFE_SECRET_ENV_VAR_NAMES = /* @__PURE__ */ new Set([
|
|
|
753
929
|
"NO_COLOR"
|
|
754
930
|
]);
|
|
755
931
|
var RESERVED_UNSAFE_SECRET_ENV_VAR_PREFIXES = ["LD_", "DYLD_"];
|
|
756
|
-
function
|
|
757
|
-
|
|
932
|
+
function sandboxCredentialSourceId(source) {
|
|
933
|
+
switch (source.kind) {
|
|
934
|
+
case "env":
|
|
935
|
+
return secretSourceId(source);
|
|
936
|
+
case "gh": {
|
|
937
|
+
const parts = ["gh"];
|
|
938
|
+
if (source.host !== void 0 && source.host !== DEFAULT_GH_HOST) parts.push(`host=${source.host}`);
|
|
939
|
+
if (source.env !== void 0) parts.push(`env=${source.env}`);
|
|
940
|
+
if (source.format !== void 0) parts.push(`format=${source.format}`);
|
|
941
|
+
return parts.join(":");
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
function credentialSourceIds(options) {
|
|
946
|
+
return [
|
|
947
|
+
.../* @__PURE__ */ new Set([
|
|
948
|
+
...options.credentials.map(({ source }) => sandboxCredentialSourceId(source)),
|
|
949
|
+
...(options.managedCredentials ?? []).map((provider) => `managed:${provider}`)
|
|
950
|
+
])
|
|
951
|
+
].toSorted();
|
|
952
|
+
}
|
|
953
|
+
function checkManagedCredentials(value, credentials2, report) {
|
|
954
|
+
if (value === void 0) return [];
|
|
955
|
+
if (!Array.isArray(value)) {
|
|
956
|
+
report(
|
|
957
|
+
["managedCredentials"],
|
|
958
|
+
`must be a list of Vercel-managed credentials, such as ["npm"], not ${describeOptionValue(value)}`
|
|
959
|
+
);
|
|
960
|
+
return void 0;
|
|
961
|
+
}
|
|
962
|
+
let ok = true;
|
|
963
|
+
const checked = [];
|
|
964
|
+
const seen = /* @__PURE__ */ new Set();
|
|
965
|
+
value.forEach((entry, index) => {
|
|
966
|
+
const path = ["managedCredentials", String(index)];
|
|
967
|
+
if (typeof entry !== "string" || !MANAGED_CREDENTIALS.has(entry)) {
|
|
968
|
+
report(path, `must be "npm", not ${describeOptionValue(entry)}`);
|
|
969
|
+
ok = false;
|
|
970
|
+
return;
|
|
971
|
+
}
|
|
972
|
+
if (seen.has(entry)) {
|
|
973
|
+
report(path, `names ${entry} again`);
|
|
974
|
+
ok = false;
|
|
975
|
+
return;
|
|
976
|
+
}
|
|
977
|
+
seen.add(entry);
|
|
978
|
+
checked.push(entry);
|
|
979
|
+
});
|
|
980
|
+
if (checked.includes("npm") && credentials2 !== void 0) {
|
|
981
|
+
credentials2.forEach((credential, index) => {
|
|
982
|
+
if (credential.domain === MANAGED_NPM_DOMAIN && credential.header === DEFAULT_CREDENTIAL_HEADER) {
|
|
983
|
+
report(
|
|
984
|
+
["credentials", String(index)],
|
|
985
|
+
`can't set ${DEFAULT_CREDENTIAL_HEADER} on ${MANAGED_NPM_DOMAIN} when runner.managedCredentials includes "npm": a sandbox credential on ${MANAGED_NPM_DOMAIN} overrides the Vercel-managed npm token`
|
|
986
|
+
);
|
|
987
|
+
ok = false;
|
|
988
|
+
}
|
|
989
|
+
});
|
|
990
|
+
}
|
|
991
|
+
return ok ? checked : void 0;
|
|
758
992
|
}
|
|
759
993
|
function checkCredentials(value, report) {
|
|
760
994
|
if (value === void 0) return [];
|
|
761
995
|
if (!Array.isArray(value)) {
|
|
762
996
|
report(
|
|
763
997
|
["credentials"],
|
|
764
|
-
`must be a list of credentials, each { domain, header?, source, requests? }, not ${
|
|
998
|
+
`must be a list of credentials, each { domain, header?, source, requests? }, not ${describeOptionValue(value)}`
|
|
765
999
|
);
|
|
766
1000
|
return void 0;
|
|
767
1001
|
}
|
|
@@ -800,34 +1034,41 @@ function checkCredentials(value, report) {
|
|
|
800
1034
|
}
|
|
801
1035
|
function checkCredential(value, path, report) {
|
|
802
1036
|
if (!isPlainObject(value)) {
|
|
803
|
-
report(path, `must be { domain, header?, source, requests? }, not ${
|
|
1037
|
+
report(path, `must be { domain, header?, source, requests? }, not ${describeOptionValue(value)}`);
|
|
804
1038
|
return void 0;
|
|
805
1039
|
}
|
|
806
1040
|
let ok = reportUnknownKeys(value, CREDENTIAL_KEYS, path, "a credential key", report);
|
|
807
1041
|
const domain = value["domain"];
|
|
808
|
-
if (typeof domain !== "string" || !
|
|
1042
|
+
if (typeof domain !== "string" || !HOST_PATTERN2.test(domain)) {
|
|
809
1043
|
report(
|
|
810
1044
|
[...path, "domain"],
|
|
811
|
-
`must be a bare hostname, such as registry.example.com: lowercase letters, digits, dots, and hyphens, with at least one dot, and no scheme, port, path, or wildcard, not ${
|
|
1045
|
+
`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)}`
|
|
812
1046
|
);
|
|
813
1047
|
ok = false;
|
|
814
1048
|
}
|
|
815
1049
|
const header = value["header"] === void 0 ? DEFAULT_CREDENTIAL_HEADER : value["header"];
|
|
1050
|
+
let headerValid = true;
|
|
816
1051
|
if (typeof header !== "string" || !HEADER_PATTERN.test(header)) {
|
|
817
1052
|
report(
|
|
818
1053
|
[...path, "header"],
|
|
819
|
-
`must be an HTTP header name, such as authorization, not ${
|
|
1054
|
+
`must be an HTTP header name, such as authorization, not ${describeOptionValue(header)}`
|
|
820
1055
|
);
|
|
821
1056
|
ok = false;
|
|
1057
|
+
headerValid = false;
|
|
822
1058
|
} else if (REFUSED_HEADERS.has(header.toLowerCase())) {
|
|
823
1059
|
report([...path, "header"], `can't be ${header}: the firewall or HTTP sets it`);
|
|
824
1060
|
ok = false;
|
|
1061
|
+
headerValid = false;
|
|
1062
|
+
}
|
|
1063
|
+
const source = checkSandboxCredentialSource(value["source"], [...path, "source"], report);
|
|
1064
|
+
if (source === void 0) ok = false;
|
|
1065
|
+
else if (headerValid && source.kind === "gh" && header.toLowerCase() !== DEFAULT_CREDENTIAL_HEADER) {
|
|
1066
|
+
report([...path, "header"], `can't be ${header}: a gh credential always sets the authorization header`);
|
|
1067
|
+
ok = false;
|
|
825
1068
|
}
|
|
826
|
-
const source = checkSecretSource(value["source"], [...path, "source"], report);
|
|
827
|
-
if (source === void 0) ok = false;
|
|
828
1069
|
const requests = value["requests"] === void 0 ? "read" : value["requests"];
|
|
829
1070
|
if (requests !== "read" && requests !== "all") {
|
|
830
|
-
report([...path, "requests"], `must be "read" or "all", not ${
|
|
1071
|
+
report([...path, "requests"], `must be "read" or "all", not ${describeOptionValue(requests)}`);
|
|
831
1072
|
ok = false;
|
|
832
1073
|
}
|
|
833
1074
|
return ok && source !== void 0 ? {
|
|
@@ -837,21 +1078,70 @@ function checkCredential(value, path, report) {
|
|
|
837
1078
|
requests
|
|
838
1079
|
} : void 0;
|
|
839
1080
|
}
|
|
1081
|
+
function checkSandboxCredentialSource(value, path, report) {
|
|
1082
|
+
if (!isPlainObject(value)) {
|
|
1083
|
+
report(
|
|
1084
|
+
path,
|
|
1085
|
+
`must be a sandbox credential source, { kind: "env", name } or { kind: "gh", env?, host?, format? }, not ${describeOptionValue(value)}`
|
|
1086
|
+
);
|
|
1087
|
+
return void 0;
|
|
1088
|
+
}
|
|
1089
|
+
const kind2 = value["kind"];
|
|
1090
|
+
if (kind2 === "env") {
|
|
1091
|
+
return checkEnvSecretSource(value, path, report);
|
|
1092
|
+
}
|
|
1093
|
+
if (kind2 === "gh") {
|
|
1094
|
+
return checkGhCredentialSource(value, path, report);
|
|
1095
|
+
}
|
|
1096
|
+
report([...path, "kind"], `must be "env" or "gh", not ${describeOptionValue(kind2)}`);
|
|
1097
|
+
return void 0;
|
|
1098
|
+
}
|
|
1099
|
+
function checkGhCredentialSource(value, path, report) {
|
|
1100
|
+
let ok = reportUnknownKeys(value, GH_SOURCE_KEYS, path, "a sandbox credential source key", report);
|
|
1101
|
+
const env = value["env"];
|
|
1102
|
+
if (env !== void 0 && (typeof env !== "string" || !ENV_VAR_NAME_PATTERN.test(env))) {
|
|
1103
|
+
report([...path, "env"], `must be ${ENV_VAR_NAME_RULE}, not ${describeOptionValue(env)}`);
|
|
1104
|
+
ok = false;
|
|
1105
|
+
}
|
|
1106
|
+
const host = value["host"];
|
|
1107
|
+
if (host !== void 0 && (typeof host !== "string" || !HOST_PATTERN2.test(host))) {
|
|
1108
|
+
report(
|
|
1109
|
+
[...path, "host"],
|
|
1110
|
+
`must be a bare hostname, such as github.com: lowercase letters, digits, dots, and hyphens, with at least one dot, and no scheme, port, path, or wildcard, not ${describeOptionValue(host)}`
|
|
1111
|
+
);
|
|
1112
|
+
ok = false;
|
|
1113
|
+
}
|
|
1114
|
+
const format = value["format"];
|
|
1115
|
+
if (format !== void 0 && format !== "basic" && format !== "bearer") {
|
|
1116
|
+
report([...path, "format"], `must be "basic" or "bearer", not ${describeOptionValue(format)}`);
|
|
1117
|
+
ok = false;
|
|
1118
|
+
}
|
|
1119
|
+
if (!ok) return void 0;
|
|
1120
|
+
return {
|
|
1121
|
+
kind: "gh",
|
|
1122
|
+
...env === void 0 ? {} : { env },
|
|
1123
|
+
...host === void 0 ? {} : { host },
|
|
1124
|
+
...format === void 0 ? {} : { format }
|
|
1125
|
+
};
|
|
1126
|
+
}
|
|
840
1127
|
function checkSecretSource(value, path, report) {
|
|
841
1128
|
if (!isPlainObject(value)) {
|
|
842
|
-
report(path, `must be a secret source, { kind: "env", name }, not ${
|
|
1129
|
+
report(path, `must be a secret source, { kind: "env", name }, not ${describeOptionValue(value)}`);
|
|
843
1130
|
return void 0;
|
|
844
1131
|
}
|
|
845
1132
|
const kind2 = value["kind"];
|
|
846
1133
|
if (kind2 !== "env") {
|
|
847
|
-
report([...path, "kind"], `must be "env", not ${
|
|
1134
|
+
report([...path, "kind"], `must be "env", not ${describeOptionValue(kind2)}`);
|
|
848
1135
|
if (kind2 !== void 0) return void 0;
|
|
849
1136
|
}
|
|
850
|
-
|
|
1137
|
+
return checkEnvSecretSource(value, path, report, kind2 === "env");
|
|
1138
|
+
}
|
|
1139
|
+
function checkEnvSecretSource(value, path, report, kindOk = true) {
|
|
1140
|
+
let ok = kindOk;
|
|
851
1141
|
if (!reportUnknownKeys(value, ENV_SOURCE_KEYS, path, "a secret source key", report)) ok = false;
|
|
852
1142
|
const name = value["name"];
|
|
853
1143
|
if (typeof name !== "string" || !ENV_VAR_NAME_PATTERN.test(name)) {
|
|
854
|
-
report([...path, "name"], `must be ${ENV_VAR_NAME_RULE}, not ${
|
|
1144
|
+
report([...path, "name"], `must be ${ENV_VAR_NAME_RULE}, not ${describeOptionValue(name)}`);
|
|
855
1145
|
ok = false;
|
|
856
1146
|
}
|
|
857
1147
|
return ok ? { kind: "env", name } : void 0;
|
|
@@ -861,18 +1151,27 @@ function checkUnsafeSecretEnvVars(value, env, credentials2, report) {
|
|
|
861
1151
|
if (!Array.isArray(value)) {
|
|
862
1152
|
report(
|
|
863
1153
|
["unsafeSecretEnvVars"],
|
|
864
|
-
`must be a list of unsafe secret environment variables, each { name, source }, not ${
|
|
1154
|
+
`must be a list of unsafe secret environment variables, each { name, source }, not ${describeOptionValue(value)}`
|
|
865
1155
|
);
|
|
866
1156
|
return void 0;
|
|
867
1157
|
}
|
|
868
1158
|
let ok = true;
|
|
869
1159
|
const checked = [];
|
|
870
1160
|
const seen = /* @__PURE__ */ new Set();
|
|
871
|
-
const
|
|
1161
|
+
const credentialEnvSources = new Set(
|
|
1162
|
+
(credentials2 ?? []).flatMap(({ source }) => {
|
|
1163
|
+
switch (source.kind) {
|
|
1164
|
+
case "env":
|
|
1165
|
+
return [secretSourceId(source)];
|
|
1166
|
+
case "gh":
|
|
1167
|
+
return source.env === void 0 ? [] : [`env:${source.env}`];
|
|
1168
|
+
}
|
|
1169
|
+
})
|
|
1170
|
+
);
|
|
872
1171
|
value.forEach((entry, index) => {
|
|
873
1172
|
const path = ["unsafeSecretEnvVars", String(index)];
|
|
874
1173
|
if (!isPlainObject(entry)) {
|
|
875
|
-
report(path, `must be { name, source }, not ${
|
|
1174
|
+
report(path, `must be { name, source }, not ${describeOptionValue(entry)}`);
|
|
876
1175
|
ok = false;
|
|
877
1176
|
return;
|
|
878
1177
|
}
|
|
@@ -886,7 +1185,7 @@ function checkUnsafeSecretEnvVars(value, env, credentials2, report) {
|
|
|
886
1185
|
const name = entry["name"];
|
|
887
1186
|
const namePath = [...path, "name"];
|
|
888
1187
|
if (typeof name !== "string" || !ENV_VAR_NAME_PATTERN.test(name)) {
|
|
889
|
-
report(namePath, `must be ${ENV_VAR_NAME_RULE}, not ${
|
|
1188
|
+
report(namePath, `must be ${ENV_VAR_NAME_RULE}, not ${describeOptionValue(name)}`);
|
|
890
1189
|
entryOk = false;
|
|
891
1190
|
} else if (name === RUN_PAYLOAD_VARIABLE) {
|
|
892
1191
|
report(namePath, `can't be ${name}: storm sets it for the command`);
|
|
@@ -911,7 +1210,7 @@ function checkUnsafeSecretEnvVars(value, env, credentials2, report) {
|
|
|
911
1210
|
const source = checkSecretSource(entry["source"], [...path, "source"], report);
|
|
912
1211
|
if (source === void 0) {
|
|
913
1212
|
entryOk = false;
|
|
914
|
-
} else if (
|
|
1213
|
+
} else if (credentialEnvSources.has(secretSourceId(source))) {
|
|
915
1214
|
report([...path, "source"], `can't use ${secretSourceId(source)}: runner.credentials already reads it`);
|
|
916
1215
|
entryOk = false;
|
|
917
1216
|
}
|
|
@@ -929,16 +1228,16 @@ function isPlainObject(value) {
|
|
|
929
1228
|
return proto === Object.prototype || proto === null;
|
|
930
1229
|
}
|
|
931
1230
|
|
|
932
|
-
// src/runner/
|
|
1231
|
+
// src/runner/vercel-sandbox-options.ts
|
|
933
1232
|
var MAX_RUNNER_SANDBOXES = 32;
|
|
934
|
-
var
|
|
1233
|
+
var VERCEL_SANDBOX_DEFAULTS = {
|
|
935
1234
|
cwd: ".",
|
|
936
1235
|
timeout: "60m",
|
|
937
1236
|
baseRefs: ["main", "origin/main"],
|
|
938
1237
|
region: "iad1",
|
|
939
|
-
|
|
1238
|
+
image: "vercel/sandbox/node:al-24"
|
|
940
1239
|
};
|
|
941
|
-
var
|
|
1240
|
+
var VERCEL_SANDBOX_OPTION_KEYS = /* @__PURE__ */ new Set([
|
|
942
1241
|
"name",
|
|
943
1242
|
"snapshot",
|
|
944
1243
|
"run",
|
|
@@ -946,75 +1245,85 @@ var RECIPE_KEYS = /* @__PURE__ */ new Set([
|
|
|
946
1245
|
"vcpus",
|
|
947
1246
|
"env",
|
|
948
1247
|
"credentials",
|
|
1248
|
+
"managedCredentials",
|
|
949
1249
|
"unsafeSecretEnvVars",
|
|
950
1250
|
"allowedDomains",
|
|
951
1251
|
"timeout",
|
|
952
1252
|
"keepSandbox",
|
|
953
1253
|
"baseRefs",
|
|
954
1254
|
"region",
|
|
955
|
-
"
|
|
1255
|
+
"image",
|
|
956
1256
|
"sandboxes"
|
|
957
1257
|
]);
|
|
958
1258
|
var SANDBOXES_KEYS = /* @__PURE__ */ new Set(["max", "default"]);
|
|
959
1259
|
var SANDBOXES_DEFAULT_RULE_KEYS = /* @__PURE__ */ new Set(["filesPerSandbox", "max"]);
|
|
960
1260
|
var VCPUS_RULE_KEYS = /* @__PURE__ */ new Set(["resource", "option", "per", "min", "max"]);
|
|
961
|
-
var SNAPSHOT_KEYS = /* @__PURE__ */ new Set(["vcpus", "summary", "toolchains", "prebuild"]);
|
|
1261
|
+
var SNAPSHOT_KEYS = /* @__PURE__ */ new Set(["vcpus", "summary", "source", "toolchains", "prebuild"]);
|
|
962
1262
|
var RUN_KEYS = /* @__PURE__ */ new Set(["install", "build"]);
|
|
963
1263
|
var STEP_KEYS = /* @__PURE__ */ new Set(["label", "script"]);
|
|
964
1264
|
var TOOLCHAIN_STEP_KEYS = /* @__PURE__ */ new Set(["label", "script", "baseFiles"]);
|
|
965
1265
|
var NAME_PATTERN = /^[a-z0-9][a-z0-9-]*$/;
|
|
1266
|
+
var VCR_HOST_PREFIX = "vcr.vercel.com/";
|
|
1267
|
+
var MANAGED_IMAGE_PREFIX = "vercel/sandbox/";
|
|
1268
|
+
var IMAGE_DIGEST_PATTERN = /^sha256:[0-9a-f]{64}$/;
|
|
966
1269
|
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])?)+$/;
|
|
967
|
-
function
|
|
1270
|
+
function checkVercelSandboxOptions(value) {
|
|
968
1271
|
const problems = [];
|
|
969
1272
|
const report = (path, problem) => problems.push({ path, problem });
|
|
970
1273
|
if (!isRecord(value)) {
|
|
971
|
-
report([], `must be an object, not ${
|
|
1274
|
+
report([], `must be an object, not ${describeOptionValue(value)}`);
|
|
972
1275
|
return { ok: false, problems };
|
|
973
1276
|
}
|
|
974
|
-
reportUnknownKeys(value,
|
|
1277
|
+
reportUnknownKeys(value, VERCEL_SANDBOX_OPTION_KEYS, [], "a vercelSandbox option key", report);
|
|
975
1278
|
const name = value["name"];
|
|
976
1279
|
if (typeof name !== "string" || !NAME_PATTERN.test(name))
|
|
977
1280
|
report(
|
|
978
1281
|
["name"],
|
|
979
|
-
`must be lowercase letters, digits and dashes, starting with a letter or digit, not ${
|
|
1282
|
+
`must be lowercase letters, digits and dashes, starting with a letter or digit, not ${describeOptionValue(name)}`
|
|
980
1283
|
);
|
|
981
1284
|
const snapshot = checkSnapshot(value["snapshot"], report);
|
|
982
1285
|
const run = checkRun(value["run"], report);
|
|
983
|
-
const cwd = orDefault(value["cwd"],
|
|
1286
|
+
const cwd = orDefault(value["cwd"], VERCEL_SANDBOX_DEFAULTS.cwd);
|
|
984
1287
|
if (!isRelativePath(cwd))
|
|
985
|
-
report(["cwd"], `must be a path relative to the repository's root, without "..", not ${
|
|
1288
|
+
report(["cwd"], `must be a path relative to the repository's root, without "..", not ${describeOptionValue(cwd)}`);
|
|
986
1289
|
const vcpus = checkVcpus(value["vcpus"], report);
|
|
987
1290
|
const env = checkEnv(value["env"], report);
|
|
988
1291
|
const credentials2 = checkCredentials(value["credentials"], report);
|
|
1292
|
+
const managedCredentials = checkManagedCredentials(value["managedCredentials"], credentials2, report);
|
|
989
1293
|
const unsafeSecretEnvVars = checkUnsafeSecretEnvVars(value["unsafeSecretEnvVars"], env, credentials2, report);
|
|
990
1294
|
const allowedDomains = checkAllowedDomains(value["allowedDomains"], report);
|
|
991
|
-
const timeout = orDefault(value["timeout"],
|
|
1295
|
+
const timeout = orDefault(value["timeout"], VERCEL_SANDBOX_DEFAULTS.timeout);
|
|
992
1296
|
const timeoutMinutes = typeof timeout === "string" ? parseTtl(timeout) : void 0;
|
|
993
1297
|
if (timeoutMinutes === void 0)
|
|
994
1298
|
report(
|
|
995
1299
|
["timeout"],
|
|
996
|
-
`must be a whole number of minutes or hours from 10m to 5h, not ${
|
|
1300
|
+
`must be a whole number of minutes or hours from 10m to 5h, not ${describeOptionValue(timeout)}`
|
|
997
1301
|
);
|
|
998
1302
|
const keepSandbox = value["keepSandbox"];
|
|
999
1303
|
const keepSandboxMinutes = typeof keepSandbox === "string" ? parseKeepTime(keepSandbox) : void 0;
|
|
1000
1304
|
if (keepSandbox !== void 0 && keepSandboxMinutes === void 0)
|
|
1001
1305
|
report(
|
|
1002
1306
|
["keepSandbox"],
|
|
1003
|
-
`must be 0, or a whole number of minutes or hours up to 5h, not ${
|
|
1004
|
-
);
|
|
1005
|
-
else if (unsafeSecretEnvVars !== void 0 && unsafeSecretEnvVars.length > 0 && keepSandboxMinutes !== void 0 && keepSandboxMinutes > 0)
|
|
1006
|
-
report(
|
|
1007
|
-
["keepSandbox"],
|
|
1008
|
-
"can't be above 0 when runner.unsafeSecretEnvVars is set: a run that passes secrets into the runner sandbox's environment never keeps its runner sandbox"
|
|
1307
|
+
`must be 0, or a whole number of minutes or hours up to 5h, not ${describeOptionValue(keepSandbox)}`
|
|
1009
1308
|
);
|
|
1309
|
+
else if (keepSandboxMinutes !== void 0 && keepSandboxMinutes > 0) {
|
|
1310
|
+
if (unsafeSecretEnvVars !== void 0 && unsafeSecretEnvVars.length > 0)
|
|
1311
|
+
report(
|
|
1312
|
+
["keepSandbox"],
|
|
1313
|
+
"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"
|
|
1314
|
+
);
|
|
1315
|
+
if (managedCredentials !== void 0 && managedCredentials.length > 0)
|
|
1316
|
+
report(
|
|
1317
|
+
["keepSandbox"],
|
|
1318
|
+
"can't be above 0 when runner.managedCredentials is set: Vercel Sandbox rejects deny-all on a sandbox with managed credentials, so storm cannot fence a kept runner sandbox"
|
|
1319
|
+
);
|
|
1320
|
+
}
|
|
1010
1321
|
const baseRefs = checkBaseRefs(value["baseRefs"], report);
|
|
1011
|
-
const region = orDefault(value["region"],
|
|
1012
|
-
if (!isNonEmptyString(region)) report(["region"], `must be a non-empty string, not ${
|
|
1013
|
-
const
|
|
1014
|
-
if (!isNonEmptyString(runtime))
|
|
1015
|
-
report(["runtime"], `must be a non-empty string, not ${describeRecipeValue(runtime)}`);
|
|
1322
|
+
const region = orDefault(value["region"], VERCEL_SANDBOX_DEFAULTS.region);
|
|
1323
|
+
if (!isNonEmptyString(region)) report(["region"], `must be a non-empty string, not ${describeOptionValue(region)}`);
|
|
1324
|
+
const image = checkImage(orDefault(value["image"], VERCEL_SANDBOX_DEFAULTS.image), report);
|
|
1016
1325
|
const sandboxes = checkSandboxes(value["sandboxes"], report);
|
|
1017
|
-
if (problems.length > 0 || snapshot === void 0 || run === void 0 || vcpus === void 0 || env === void 0 || credentials2 === void 0 || unsafeSecretEnvVars === void 0 || allowedDomains === null || baseRefs === void 0 || timeoutMinutes === void 0 || sandboxes === false)
|
|
1326
|
+
if (problems.length > 0 || snapshot === void 0 || run === void 0 || vcpus === void 0 || env === void 0 || credentials2 === void 0 || managedCredentials === void 0 || unsafeSecretEnvVars === void 0 || allowedDomains === null || baseRefs === void 0 || timeoutMinutes === void 0 || image === void 0 || sandboxes === false)
|
|
1018
1327
|
return { ok: false, problems };
|
|
1019
1328
|
return {
|
|
1020
1329
|
ok: true,
|
|
@@ -1026,6 +1335,7 @@ function checkRecipe(value) {
|
|
|
1026
1335
|
vcpus,
|
|
1027
1336
|
env,
|
|
1028
1337
|
credentials: credentials2,
|
|
1338
|
+
managedCredentials,
|
|
1029
1339
|
unsafeSecretEnvVars,
|
|
1030
1340
|
...allowedDomains === void 0 ? {} : { allowedDomains },
|
|
1031
1341
|
timeout,
|
|
@@ -1033,11 +1343,47 @@ function checkRecipe(value) {
|
|
|
1033
1343
|
keepSandboxMinutes,
|
|
1034
1344
|
baseRefs,
|
|
1035
1345
|
region,
|
|
1036
|
-
|
|
1346
|
+
image,
|
|
1037
1347
|
...sandboxes === void 0 ? {} : { sandboxes }
|
|
1038
1348
|
}
|
|
1039
1349
|
};
|
|
1040
1350
|
}
|
|
1351
|
+
function checkImage(value, report) {
|
|
1352
|
+
if (!isNonEmptyString(value)) {
|
|
1353
|
+
report(["image"], `must be a non-empty string, not ${describeOptionValue(value)}`);
|
|
1354
|
+
return void 0;
|
|
1355
|
+
}
|
|
1356
|
+
if (/\s/.test(value)) {
|
|
1357
|
+
report(["image"], `must be an image reference with no whitespace, not ${describeOptionValue(value)}`);
|
|
1358
|
+
return void 0;
|
|
1359
|
+
}
|
|
1360
|
+
const at = value.indexOf("@");
|
|
1361
|
+
const name = at === -1 ? value : value.slice(0, at);
|
|
1362
|
+
const digest = at === -1 ? void 0 : value.slice(at + 1);
|
|
1363
|
+
if (digest !== void 0 && (name === "" || !IMAGE_DIGEST_PATTERN.test(digest))) {
|
|
1364
|
+
report(
|
|
1365
|
+
["image"],
|
|
1366
|
+
`must be "<repository>@sha256:<64 lowercase hex characters>" when it names a digest, not ${describeOptionValue(value)}`
|
|
1367
|
+
);
|
|
1368
|
+
return void 0;
|
|
1369
|
+
}
|
|
1370
|
+
const repo = name.startsWith(VCR_HOST_PREFIX) ? name.slice(VCR_HOST_PREFIX.length) : name;
|
|
1371
|
+
if (repo === MANAGED_IMAGE_PREFIX) {
|
|
1372
|
+
report(
|
|
1373
|
+
["image"],
|
|
1374
|
+
`must name a Vercel-managed image after "${MANAGED_IMAGE_PREFIX}", not ${describeOptionValue(value)}`
|
|
1375
|
+
);
|
|
1376
|
+
return void 0;
|
|
1377
|
+
}
|
|
1378
|
+
if (digest === void 0 && !repo.startsWith(MANAGED_IMAGE_PREFIX)) {
|
|
1379
|
+
report(
|
|
1380
|
+
["image"],
|
|
1381
|
+
`must be a Vercel-managed image ("${MANAGED_IMAGE_PREFIX}...") or a digest-pinned custom VCR image ("<repository>@sha256:...") so runner snapshots cannot go stale, not ${describeOptionValue(value)}`
|
|
1382
|
+
);
|
|
1383
|
+
return void 0;
|
|
1384
|
+
}
|
|
1385
|
+
return value;
|
|
1386
|
+
}
|
|
1041
1387
|
function checkVcpus(value, report) {
|
|
1042
1388
|
if (isPositiveInteger(value)) return value;
|
|
1043
1389
|
if (typeof value === "function") {
|
|
@@ -1047,34 +1393,34 @@ function checkVcpus(value, report) {
|
|
|
1047
1393
|
if (!isRecord(value)) {
|
|
1048
1394
|
report(
|
|
1049
1395
|
["vcpus"],
|
|
1050
|
-
`must be a positive whole number, or { resource, option, per, min, max }, not ${
|
|
1396
|
+
`must be a positive whole number, or { resource, option, per, min, max }, not ${describeOptionValue(value)}`
|
|
1051
1397
|
);
|
|
1052
1398
|
return void 0;
|
|
1053
1399
|
}
|
|
1054
|
-
let ok = reportUnknownKeys(value, VCPUS_RULE_KEYS, ["vcpus"], "a
|
|
1400
|
+
let ok = reportUnknownKeys(value, VCPUS_RULE_KEYS, ["vcpus"], "a vercelSandbox vcpus rule key", report);
|
|
1055
1401
|
const resource = value["resource"];
|
|
1056
1402
|
if (!isNonEmptyString(resource)) {
|
|
1057
|
-
report(["vcpus", "resource"], `must be a non-empty string, not ${
|
|
1403
|
+
report(["vcpus", "resource"], `must be a non-empty string, not ${describeOptionValue(resource)}`);
|
|
1058
1404
|
ok = false;
|
|
1059
1405
|
}
|
|
1060
1406
|
const option = value["option"];
|
|
1061
1407
|
if (!isNonEmptyString(option)) {
|
|
1062
|
-
report(["vcpus", "option"], `must be a non-empty string, not ${
|
|
1408
|
+
report(["vcpus", "option"], `must be a non-empty string, not ${describeOptionValue(option)}`);
|
|
1063
1409
|
ok = false;
|
|
1064
1410
|
}
|
|
1065
1411
|
const per = value["per"];
|
|
1066
1412
|
if (!isPositiveInteger(per)) {
|
|
1067
|
-
report(["vcpus", "per"], `must be a positive whole number, not ${
|
|
1413
|
+
report(["vcpus", "per"], `must be a positive whole number, not ${describeOptionValue(per)}`);
|
|
1068
1414
|
ok = false;
|
|
1069
1415
|
}
|
|
1070
1416
|
const min = value["min"];
|
|
1071
1417
|
if (!isPositiveInteger(min)) {
|
|
1072
|
-
report(["vcpus", "min"], `must be a positive whole number, not ${
|
|
1418
|
+
report(["vcpus", "min"], `must be a positive whole number, not ${describeOptionValue(min)}`);
|
|
1073
1419
|
ok = false;
|
|
1074
1420
|
}
|
|
1075
1421
|
const max = value["max"];
|
|
1076
1422
|
if (!isPositiveInteger(max)) {
|
|
1077
|
-
report(["vcpus", "max"], `must be a positive whole number, not ${
|
|
1423
|
+
report(["vcpus", "max"], `must be a positive whole number, not ${describeOptionValue(max)}`);
|
|
1078
1424
|
ok = false;
|
|
1079
1425
|
} else if (isPositiveInteger(min) && max < min) {
|
|
1080
1426
|
report(["vcpus", "max"], `must be at least vcpus.min (${min}), not ${max}`);
|
|
@@ -1091,15 +1437,15 @@ function checkVcpus(value, report) {
|
|
|
1091
1437
|
function checkSandboxes(value, report) {
|
|
1092
1438
|
if (value === void 0) return void 0;
|
|
1093
1439
|
if (!isRecord(value)) {
|
|
1094
|
-
report(["sandboxes"], `must be an object with max, not ${
|
|
1440
|
+
report(["sandboxes"], `must be an object with max, not ${describeOptionValue(value)}`);
|
|
1095
1441
|
return false;
|
|
1096
1442
|
}
|
|
1097
|
-
let ok = reportUnknownKeys(value, SANDBOXES_KEYS, ["sandboxes"], "a
|
|
1443
|
+
let ok = reportUnknownKeys(value, SANDBOXES_KEYS, ["sandboxes"], "a vercelSandbox sandboxes key", report);
|
|
1098
1444
|
const max = value["max"];
|
|
1099
1445
|
if (!isPositiveInteger(max) || max > MAX_RUNNER_SANDBOXES) {
|
|
1100
1446
|
report(
|
|
1101
1447
|
["sandboxes", "max"],
|
|
1102
|
-
`must be a whole number from 1 to ${MAX_RUNNER_SANDBOXES}, not ${
|
|
1448
|
+
`must be a whole number from 1 to ${MAX_RUNNER_SANDBOXES}, not ${describeOptionValue(max)}`
|
|
1103
1449
|
);
|
|
1104
1450
|
ok = false;
|
|
1105
1451
|
}
|
|
@@ -1128,7 +1474,7 @@ function checkSandboxesDefault(value, report) {
|
|
|
1128
1474
|
if (!isRecord(value)) {
|
|
1129
1475
|
report(
|
|
1130
1476
|
["sandboxes", "default"],
|
|
1131
|
-
`must be a whole number from 1 to ${MAX_RUNNER_SANDBOXES}, or { filesPerSandbox, max? }, not ${
|
|
1477
|
+
`must be a whole number from 1 to ${MAX_RUNNER_SANDBOXES}, or { filesPerSandbox, max? }, not ${describeOptionValue(value)}`
|
|
1132
1478
|
);
|
|
1133
1479
|
return void 0;
|
|
1134
1480
|
}
|
|
@@ -1136,14 +1482,14 @@ function checkSandboxesDefault(value, report) {
|
|
|
1136
1482
|
value,
|
|
1137
1483
|
SANDBOXES_DEFAULT_RULE_KEYS,
|
|
1138
1484
|
["sandboxes", "default"],
|
|
1139
|
-
"a
|
|
1485
|
+
"a vercelSandbox sandboxes default rule key",
|
|
1140
1486
|
report
|
|
1141
1487
|
);
|
|
1142
1488
|
const filesPerSandbox = value["filesPerSandbox"];
|
|
1143
1489
|
if (!isPositiveInteger(filesPerSandbox)) {
|
|
1144
1490
|
report(
|
|
1145
1491
|
["sandboxes", "default", "filesPerSandbox"],
|
|
1146
|
-
`must be a positive whole number, not ${
|
|
1492
|
+
`must be a positive whole number, not ${describeOptionValue(filesPerSandbox)}`
|
|
1147
1493
|
);
|
|
1148
1494
|
ok = false;
|
|
1149
1495
|
}
|
|
@@ -1151,7 +1497,7 @@ function checkSandboxesDefault(value, report) {
|
|
|
1151
1497
|
if (max !== void 0 && (!isPositiveInteger(max) || max > MAX_RUNNER_SANDBOXES)) {
|
|
1152
1498
|
report(
|
|
1153
1499
|
["sandboxes", "default", "max"],
|
|
1154
|
-
`must be a whole number from 1 to ${MAX_RUNNER_SANDBOXES}, not ${
|
|
1500
|
+
`must be a whole number from 1 to ${MAX_RUNNER_SANDBOXES}, not ${describeOptionValue(max)}`
|
|
1155
1501
|
);
|
|
1156
1502
|
ok = false;
|
|
1157
1503
|
}
|
|
@@ -1165,37 +1511,39 @@ function checkSnapshot(value, report) {
|
|
|
1165
1511
|
if (!isRecord(value)) {
|
|
1166
1512
|
report(
|
|
1167
1513
|
["snapshot"],
|
|
1168
|
-
`must be an object of vcpus, toolchains, prebuild, and an optional summary, not ${
|
|
1514
|
+
`must be an object of vcpus, toolchains, prebuild, and an optional summary, not ${describeOptionValue(value)}`
|
|
1169
1515
|
);
|
|
1170
1516
|
return void 0;
|
|
1171
1517
|
}
|
|
1172
|
-
let ok = reportUnknownKeys(value, SNAPSHOT_KEYS, ["snapshot"], "a
|
|
1518
|
+
let ok = reportUnknownKeys(value, SNAPSHOT_KEYS, ["snapshot"], "a vercelSandbox snapshot key", report);
|
|
1173
1519
|
const vcpus = value["vcpus"];
|
|
1174
1520
|
if (!isPositiveInteger(vcpus)) {
|
|
1175
|
-
report(["snapshot", "vcpus"], `must be a positive whole number, not ${
|
|
1521
|
+
report(["snapshot", "vcpus"], `must be a positive whole number, not ${describeOptionValue(vcpus)}`);
|
|
1176
1522
|
ok = false;
|
|
1177
1523
|
}
|
|
1178
1524
|
const summary = value["summary"];
|
|
1179
1525
|
if (summary !== void 0 && !isNonEmptyString(summary)) {
|
|
1180
|
-
report(["snapshot", "summary"], `must be a non-empty string, not ${
|
|
1526
|
+
report(["snapshot", "summary"], `must be a non-empty string, not ${describeOptionValue(summary)}`);
|
|
1181
1527
|
ok = false;
|
|
1182
1528
|
}
|
|
1529
|
+
const source = checkSnapshotSource(value["source"], report);
|
|
1183
1530
|
const toolchains = checkSteps(value["toolchains"], ["snapshot", "toolchains"], true, report);
|
|
1184
1531
|
const prebuild = checkSteps(value["prebuild"], ["snapshot", "prebuild"], false, report);
|
|
1185
|
-
if (!ok || toolchains === void 0 || prebuild === void 0) return void 0;
|
|
1532
|
+
if (!ok || source === false || toolchains === void 0 || prebuild === void 0) return void 0;
|
|
1186
1533
|
return {
|
|
1187
1534
|
vcpus,
|
|
1188
1535
|
...summary === void 0 ? {} : { summary },
|
|
1536
|
+
...source === void 0 ? {} : { source },
|
|
1189
1537
|
toolchains,
|
|
1190
1538
|
prebuild
|
|
1191
1539
|
};
|
|
1192
1540
|
}
|
|
1193
1541
|
function checkRun(value, report) {
|
|
1194
1542
|
if (!isRecord(value)) {
|
|
1195
|
-
report(["run"], `must be an object of install and build steps, not ${
|
|
1543
|
+
report(["run"], `must be an object of install and build steps, not ${describeOptionValue(value)}`);
|
|
1196
1544
|
return void 0;
|
|
1197
1545
|
}
|
|
1198
|
-
const ok = reportUnknownKeys(value, RUN_KEYS, ["run"], "a
|
|
1546
|
+
const ok = reportUnknownKeys(value, RUN_KEYS, ["run"], "a vercelSandbox run key", report);
|
|
1199
1547
|
const install = checkStep(value["install"], ["run", "install"], false, report);
|
|
1200
1548
|
const build = checkStep(value["build"], ["run", "build"], false, report);
|
|
1201
1549
|
return ok && install !== void 0 && build !== void 0 ? { install, build } : void 0;
|
|
@@ -1209,7 +1557,7 @@ function checkSteps(value, path, allowBaseFiles, report) {
|
|
|
1209
1557
|
return void 0;
|
|
1210
1558
|
}
|
|
1211
1559
|
if (!Array.isArray(value)) {
|
|
1212
|
-
report(path, `must be a list of steps, not ${
|
|
1560
|
+
report(path, `must be a list of steps, not ${describeOptionValue(value)}`);
|
|
1213
1561
|
return void 0;
|
|
1214
1562
|
}
|
|
1215
1563
|
const steps = value.map(
|
|
@@ -1220,7 +1568,7 @@ function checkSteps(value, path, allowBaseFiles, report) {
|
|
|
1220
1568
|
function checkStep(value, path, allowBaseFiles, report) {
|
|
1221
1569
|
if (!isRecord(value)) {
|
|
1222
1570
|
const shape = allowBaseFiles ? "{ label, script, baseFiles? }" : "{ label, script }";
|
|
1223
|
-
report(path, `must be a step, ${shape}, not ${
|
|
1571
|
+
report(path, `must be a step, ${shape}, not ${describeOptionValue(value)}`);
|
|
1224
1572
|
return void 0;
|
|
1225
1573
|
}
|
|
1226
1574
|
const allowedKeys = allowBaseFiles ? TOOLCHAIN_STEP_KEYS : STEP_KEYS;
|
|
@@ -1229,18 +1577,18 @@ function checkStep(value, path, allowBaseFiles, report) {
|
|
|
1229
1577
|
if (allowedKeys.has(key)) continue;
|
|
1230
1578
|
report(
|
|
1231
1579
|
[...path, key],
|
|
1232
|
-
key === "secrets" ? "is not a step key: every
|
|
1580
|
+
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"
|
|
1233
1581
|
);
|
|
1234
1582
|
ok = false;
|
|
1235
1583
|
}
|
|
1236
1584
|
const label = value["label"];
|
|
1237
1585
|
const script = value["script"];
|
|
1238
1586
|
if (!isNonEmptyString(label)) {
|
|
1239
|
-
report([...path, "label"], `must be a non-empty string, not ${
|
|
1587
|
+
report([...path, "label"], `must be a non-empty string, not ${describeOptionValue(label)}`);
|
|
1240
1588
|
ok = false;
|
|
1241
1589
|
}
|
|
1242
1590
|
if (!isNonEmptyString(script)) {
|
|
1243
|
-
report([...path, "script"], `must be a non-empty string, not ${
|
|
1591
|
+
report([...path, "script"], `must be a non-empty string, not ${describeOptionValue(script)}`);
|
|
1244
1592
|
ok = false;
|
|
1245
1593
|
}
|
|
1246
1594
|
if (!allowBaseFiles) return ok ? { label, script } : void 0;
|
|
@@ -1256,7 +1604,7 @@ function checkStep(value, path, allowBaseFiles, report) {
|
|
|
1256
1604
|
function checkBaseFiles(value, path, report) {
|
|
1257
1605
|
if (value === void 0) return void 0;
|
|
1258
1606
|
if (!Array.isArray(value)) {
|
|
1259
|
-
report(path, `must be a list of relative file paths, not ${
|
|
1607
|
+
report(path, `must be a list of relative file paths, not ${describeOptionValue(value)}`);
|
|
1260
1608
|
return null;
|
|
1261
1609
|
}
|
|
1262
1610
|
let ok = true;
|
|
@@ -1267,7 +1615,7 @@ function checkBaseFiles(value, path, report) {
|
|
|
1267
1615
|
if (!isRelativeFilePath(entry)) {
|
|
1268
1616
|
report(
|
|
1269
1617
|
at,
|
|
1270
|
-
`must be a relative file path without leading "/", "./", "..", or trailing "/", not ${
|
|
1618
|
+
`must be a relative file path without leading "/", "./", "..", or trailing "/", not ${describeOptionValue(entry)}`
|
|
1271
1619
|
);
|
|
1272
1620
|
ok = false;
|
|
1273
1621
|
} else if (seen.has(entry)) {
|
|
@@ -1283,7 +1631,7 @@ function checkBaseFiles(value, path, report) {
|
|
|
1283
1631
|
function checkEnv(value, report) {
|
|
1284
1632
|
if (value === void 0) return {};
|
|
1285
1633
|
if (!isRecord(value)) {
|
|
1286
|
-
report(["env"], `must be an object of strings, not ${
|
|
1634
|
+
report(["env"], `must be an object of strings, not ${describeOptionValue(value)}`);
|
|
1287
1635
|
return void 0;
|
|
1288
1636
|
}
|
|
1289
1637
|
let ok = true;
|
|
@@ -1293,7 +1641,7 @@ function checkEnv(value, report) {
|
|
|
1293
1641
|
report(["env", key], "can't be set: storm sets it for the command");
|
|
1294
1642
|
ok = false;
|
|
1295
1643
|
} else if (typeof variable !== "string") {
|
|
1296
|
-
report(["env", key], `must be a string, not ${
|
|
1644
|
+
report(["env", key], `must be a string, not ${describeOptionValue(variable)}`);
|
|
1297
1645
|
ok = false;
|
|
1298
1646
|
} else env[key] = variable;
|
|
1299
1647
|
}
|
|
@@ -1304,7 +1652,7 @@ function checkAllowedDomains(value, report) {
|
|
|
1304
1652
|
if (!Array.isArray(value)) {
|
|
1305
1653
|
report(
|
|
1306
1654
|
["allowedDomains"],
|
|
1307
|
-
`must be a list of domains, such as ["registry.npmjs.org", "*.example.com"], not ${
|
|
1655
|
+
`must be a list of domains, such as ["registry.npmjs.org", "*.example.com"], not ${describeOptionValue(value)}`
|
|
1308
1656
|
);
|
|
1309
1657
|
return null;
|
|
1310
1658
|
}
|
|
@@ -1322,7 +1670,7 @@ function checkAllowedDomains(value, report) {
|
|
|
1322
1670
|
} else if (typeof domain !== "string" || !ALLOWED_DOMAIN_PATTERN.test(domain)) {
|
|
1323
1671
|
report(
|
|
1324
1672
|
at,
|
|
1325
|
-
`must be a hostname, such as example.com, or a wildcard with one leading *., such as *.example.com: lowercase letters, digits, dots, and hyphens, with at least one dot, and no scheme, port, or path, not ${
|
|
1673
|
+
`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)}`
|
|
1326
1674
|
);
|
|
1327
1675
|
ok = false;
|
|
1328
1676
|
} else if (seen.has(domain)) {
|
|
@@ -1334,15 +1682,15 @@ function checkAllowedDomains(value, report) {
|
|
|
1334
1682
|
return ok ? [...value] : null;
|
|
1335
1683
|
}
|
|
1336
1684
|
function checkBaseRefs(value, report) {
|
|
1337
|
-
if (value === void 0) return [...
|
|
1685
|
+
if (value === void 0) return [...VERCEL_SANDBOX_DEFAULTS.baseRefs];
|
|
1338
1686
|
if (!Array.isArray(value) || value.length === 0) {
|
|
1339
|
-
report(["baseRefs"], `must be a non-empty list of refs, not ${
|
|
1687
|
+
report(["baseRefs"], `must be a non-empty list of refs, not ${describeOptionValue(value)}`);
|
|
1340
1688
|
return void 0;
|
|
1341
1689
|
}
|
|
1342
1690
|
let ok = true;
|
|
1343
1691
|
value.forEach((ref, index) => {
|
|
1344
1692
|
if (!isNonEmptyString(ref)) {
|
|
1345
|
-
report(["baseRefs", String(index)], `must be a non-empty string, not ${
|
|
1693
|
+
report(["baseRefs", String(index)], `must be a non-empty string, not ${describeOptionValue(ref)}`);
|
|
1346
1694
|
ok = false;
|
|
1347
1695
|
}
|
|
1348
1696
|
});
|
|
@@ -1356,16 +1704,16 @@ function declaredBaseFilePaths(toolchains) {
|
|
|
1356
1704
|
}
|
|
1357
1705
|
return [...paths].toSorted((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
1358
1706
|
}
|
|
1359
|
-
function resolveVcpus(
|
|
1360
|
-
if (typeof
|
|
1361
|
-
const { resource, option, per, min, max } =
|
|
1362
|
-
const
|
|
1363
|
-
if (
|
|
1364
|
-
const raw = Object.hasOwn(
|
|
1707
|
+
function resolveVcpus(options, run) {
|
|
1708
|
+
if (typeof options.vcpus === "number") return { ok: true, vcpus: options.vcpus };
|
|
1709
|
+
const { resource, option, per, min, max } = options.vcpus;
|
|
1710
|
+
const resourceOptions = Object.hasOwn(run.resources, resource) ? run.resources[resource] : void 0;
|
|
1711
|
+
if (resourceOptions === void 0) return { ok: true, vcpus: min };
|
|
1712
|
+
const raw = Object.hasOwn(resourceOptions, option) ? resourceOptions[option] : void 0;
|
|
1365
1713
|
if (typeof raw !== "number" || !Number.isFinite(raw) || raw < 0) {
|
|
1366
1714
|
return {
|
|
1367
1715
|
ok: false,
|
|
1368
|
-
problem: `resource "${resource}" option "${option}" must be a non-negative number, not ${
|
|
1716
|
+
problem: `resource "${resource}" option "${option}" must be a non-negative number, not ${describeOptionValue(raw)}`
|
|
1369
1717
|
};
|
|
1370
1718
|
}
|
|
1371
1719
|
const perSandbox = Math.ceil(raw / Math.max(1, run.sandboxes));
|
|
@@ -1380,9 +1728,6 @@ function resolveSandboxCountDefault(sandboxesDefault, testPlan) {
|
|
|
1380
1728
|
function orDefault(value, fallback) {
|
|
1381
1729
|
return value === void 0 ? fallback : value;
|
|
1382
1730
|
}
|
|
1383
|
-
function isRecord(value) {
|
|
1384
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1385
|
-
}
|
|
1386
1731
|
function isNonEmptyString(value) {
|
|
1387
1732
|
return typeof value === "string" && value.length > 0;
|
|
1388
1733
|
}
|
|
@@ -1400,7 +1745,7 @@ function isRelativeFilePath(value) {
|
|
|
1400
1745
|
}
|
|
1401
1746
|
|
|
1402
1747
|
// src/runner/snapshot-key.ts
|
|
1403
|
-
var SNAPSHOT_FORMAT =
|
|
1748
|
+
var SNAPSHOT_FORMAT = 6;
|
|
1404
1749
|
var SANDBOX_ROOT = "/vercel/sandbox";
|
|
1405
1750
|
var STAGED_FILES = {
|
|
1406
1751
|
baseTarball: "base.tgz",
|
|
@@ -1410,6 +1755,9 @@ var STAGED_FILES = {
|
|
|
1410
1755
|
untrackedFileList: "untracked-files"
|
|
1411
1756
|
};
|
|
1412
1757
|
var GIT_IDENTITY = "-c user.email=storm-runner@vercel.invalid -c user.name='storm runner' -c commit.gpgsign=false";
|
|
1758
|
+
function shellQuote(value) {
|
|
1759
|
+
return `'${value.replaceAll("'", "'\\''")}'`;
|
|
1760
|
+
}
|
|
1413
1761
|
function bashScript(lines, root = SANDBOX_ROOT) {
|
|
1414
1762
|
return ["set -euo pipefail", `cd ${root}`, ...lines].join("\n");
|
|
1415
1763
|
}
|
|
@@ -1425,6 +1773,16 @@ function baseIndexScript(base, staging) {
|
|
|
1425
1773
|
`git ${GIT_IDENTITY} commit -q --no-verify -m 'base ${base}'`
|
|
1426
1774
|
]);
|
|
1427
1775
|
}
|
|
1776
|
+
function gitFetchBaseIndexScript(url, base, root = SANDBOX_ROOT) {
|
|
1777
|
+
return bashScript(
|
|
1778
|
+
[
|
|
1779
|
+
"git -c init.defaultBranch=main init -q",
|
|
1780
|
+
`GIT_TERMINAL_PROMPT=0 git -c credential.helper= -c core.autocrlf=false -c core.eol=lf fetch --depth 1 --no-tags -- ${shellQuote(url)} ${shellQuote(base)}`,
|
|
1781
|
+
"git -c core.autocrlf=false -c core.eol=lf checkout --detach --force FETCH_HEAD"
|
|
1782
|
+
],
|
|
1783
|
+
root
|
|
1784
|
+
);
|
|
1785
|
+
}
|
|
1428
1786
|
function applyScript(staging, root = SANDBOX_ROOT) {
|
|
1429
1787
|
const patch = `${staging}/${STAGED_FILES.patch}`;
|
|
1430
1788
|
const tarball = `${staging}/${STAGED_FILES.untrackedTarball}`;
|
|
@@ -1457,14 +1815,14 @@ function snapshotKey(steps) {
|
|
|
1457
1815
|
`baseFiles=${baseFiles.length}`,
|
|
1458
1816
|
...baseFiles.flatMap(({ path, text: content }) => [path, content]),
|
|
1459
1817
|
...text(steps.toolchains),
|
|
1460
|
-
baseIndexScript("<base>", "<staging>"),
|
|
1818
|
+
steps.source === void 0 ? baseIndexScript("<base>", "<staging>") : gitFetchBaseIndexScript("<url>", "<base>"),
|
|
1461
1819
|
...text(steps.prebuild)
|
|
1462
1820
|
].join("\0")
|
|
1463
1821
|
).digest("hex");
|
|
1464
1822
|
}
|
|
1465
1823
|
async function snapshotInputsAt(checkout, request2) {
|
|
1466
|
-
const { repoRoot, base,
|
|
1467
|
-
const { snapshot } =
|
|
1824
|
+
const { repoRoot, base, options } = request2;
|
|
1825
|
+
const { snapshot } = options;
|
|
1468
1826
|
const baseFiles = [];
|
|
1469
1827
|
for (const path of declaredBaseFilePaths(snapshot.toolchains)) {
|
|
1470
1828
|
const file = await checkout.readFileAt({ repoRoot, commit: base, path });
|
|
@@ -1488,10 +1846,11 @@ async function snapshotInputsAt(checkout, request2) {
|
|
|
1488
1846
|
ok: true,
|
|
1489
1847
|
baseFiles,
|
|
1490
1848
|
key: snapshotKey({
|
|
1491
|
-
credentials: credentialSourceIds(
|
|
1849
|
+
credentials: credentialSourceIds(options),
|
|
1492
1850
|
baseFiles,
|
|
1493
1851
|
toolchains: snapshot.toolchains,
|
|
1494
|
-
prebuild: snapshot.prebuild
|
|
1852
|
+
prebuild: snapshot.prebuild,
|
|
1853
|
+
source: snapshot.source
|
|
1495
1854
|
})
|
|
1496
1855
|
};
|
|
1497
1856
|
}
|
|
@@ -1621,46 +1980,61 @@ var BUILD_SANDBOX_TIMEOUT_MS = 30 * 6e4;
|
|
|
1621
1980
|
var BASE_INDEX_LABEL = "Committing the base's files";
|
|
1622
1981
|
async function buildSnapshot(context, request2, control, progress) {
|
|
1623
1982
|
const { prepared, access } = request2;
|
|
1624
|
-
const {
|
|
1983
|
+
const { options, repoRoot, base } = prepared;
|
|
1625
1984
|
const { scope, signal } = control;
|
|
1985
|
+
const { publish } = request2;
|
|
1626
1986
|
const now = () => context.clock.now().getTime();
|
|
1627
1987
|
const startedAt = now();
|
|
1628
1988
|
await progress.emit({
|
|
1629
1989
|
kind: "snapshot-build-started",
|
|
1630
1990
|
base,
|
|
1631
1991
|
why: request2.why,
|
|
1632
|
-
summary:
|
|
1992
|
+
summary: options.snapshot.summary ?? [...options.snapshot.toolchains, ...options.snapshot.prebuild].map(({ label }) => label).join(", ")
|
|
1633
1993
|
});
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1994
|
+
let fetchUrl;
|
|
1995
|
+
if (options.snapshot.source !== void 0) {
|
|
1996
|
+
const resolved = await resolveGitFetchUrl(context.checkout, {
|
|
1997
|
+
repoRoot,
|
|
1998
|
+
remote: options.snapshot.source.remote
|
|
1999
|
+
});
|
|
2000
|
+
if (!resolved.ok) return { kind: "failed", failure: { kind: "checkout-failed", failure: resolved.failure } };
|
|
2001
|
+
fetchUrl = resolved.value;
|
|
2002
|
+
}
|
|
2003
|
+
const startBuild = () => scope.startBuildSandbox(access, {
|
|
2004
|
+
region: options.region,
|
|
2005
|
+
image: options.image,
|
|
2006
|
+
vcpus: options.snapshot.vcpus,
|
|
2007
|
+
timeoutMs: BUILD_SANDBOX_TIMEOUT_MS,
|
|
2008
|
+
...publish === void 0 ? { tags: runnerTags(options.name, "snapshot-build", request2.user) } : { name: publish.name, tags: publish.tags }
|
|
2009
|
+
});
|
|
2010
|
+
const [started, baseStep] = fetchUrl === void 0 ? await Promise.all([startBuild(), context.checkout.baseArchive({ repoRoot, base })]) : [await startBuild(), fetchUrl];
|
|
2011
|
+
if (!started.ok)
|
|
2012
|
+
return started.failure.kind === "name-taken" ? { kind: "name-taken", name: started.failure.name, message: started.failure.message } : sandboxStop("start-build-sandbox", started.failure);
|
|
1645
2013
|
const sandbox = started.value;
|
|
1646
2014
|
await progress.emit({
|
|
1647
2015
|
kind: "sandbox-started",
|
|
1648
2016
|
role: "snapshot-build",
|
|
1649
2017
|
name: sandbox.name,
|
|
1650
|
-
region:
|
|
1651
|
-
vcpus:
|
|
2018
|
+
region: options.region,
|
|
2019
|
+
vcpus: options.snapshot.vcpus,
|
|
1652
2020
|
ms: now() - startedAt
|
|
1653
2021
|
});
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
2022
|
+
let baseStepScript;
|
|
2023
|
+
if (typeof baseStep === "string") {
|
|
2024
|
+
baseStepScript = gitFetchBaseIndexScript(baseStep, base);
|
|
2025
|
+
} else {
|
|
2026
|
+
if (!baseStep.ok) return { kind: "failed", failure: { kind: "checkout-failed", failure: baseStep.failure } };
|
|
2027
|
+
const staged = await context.runnerSandboxes.upload(
|
|
2028
|
+
sandbox,
|
|
2029
|
+
[
|
|
2030
|
+
{ name: STAGED_FILES.baseTarball, content: baseStep.value.tarball },
|
|
2031
|
+
{ name: STAGED_FILES.baseFileList, content: baseStep.value.fileList }
|
|
2032
|
+
],
|
|
2033
|
+
signal
|
|
2034
|
+
);
|
|
2035
|
+
if (!staged.ok) return sandboxStop("upload", staged.failure);
|
|
2036
|
+
baseStepScript = baseIndexScript(base, staged.value.directory);
|
|
2037
|
+
}
|
|
1664
2038
|
if (prepared.baseFiles.length > 0) {
|
|
1665
2039
|
const encoder = new TextEncoder();
|
|
1666
2040
|
const placed = await context.runnerSandboxes.placeBaseFiles(
|
|
@@ -1671,11 +2045,11 @@ async function buildSnapshot(context, request2, control, progress) {
|
|
|
1671
2045
|
if (!placed.ok) return sandboxStop("upload", placed.failure);
|
|
1672
2046
|
}
|
|
1673
2047
|
const steps = [
|
|
1674
|
-
...
|
|
1675
|
-
{ label: BASE_INDEX_LABEL, script:
|
|
1676
|
-
...
|
|
2048
|
+
...options.snapshot.toolchains,
|
|
2049
|
+
{ label: BASE_INDEX_LABEL, script: baseStepScript },
|
|
2050
|
+
...options.snapshot.prebuild
|
|
1677
2051
|
];
|
|
1678
|
-
await progress.emit({ kind: "output-started", section: "snapshot", sandbox: sandbox.name, region:
|
|
2052
|
+
await progress.emit({ kind: "output-started", section: "snapshot", sandbox: sandbox.name, region: options.region });
|
|
1679
2053
|
let stop;
|
|
1680
2054
|
if (request2.credentials.length > 0) {
|
|
1681
2055
|
const granted = await scope.grantCredentials(sandbox, request2.credentials, signal);
|
|
@@ -1709,16 +2083,19 @@ async function buildSnapshot(context, request2, control, progress) {
|
|
|
1709
2083
|
if (stop !== void 0) return stop;
|
|
1710
2084
|
if (signal.aborted) return { kind: "aborted" };
|
|
1711
2085
|
await progress.emit({ kind: "snapshot-saving" });
|
|
1712
|
-
const saved = await scope.saveSnapshot(sandbox, {
|
|
2086
|
+
const saved = await scope.saveSnapshot(sandbox, {
|
|
2087
|
+
expirationMs: SNAPSHOT_EXPIRATION_MS,
|
|
2088
|
+
...publish === void 0 ? {} : { keepStopped: true }
|
|
2089
|
+
});
|
|
1713
2090
|
if (!saved.ok)
|
|
1714
2091
|
return saved.failure.kind === "credential-not-revoked" ? networkPolicyStop("remove", "snapshot-save", saved.failure.failure) : sandboxStop("save-snapshot", saved.failure);
|
|
1715
2092
|
const savedAt = context.clock.now();
|
|
1716
2093
|
const entry = {
|
|
1717
2094
|
teamId: access.teamId,
|
|
1718
2095
|
projectId: access.projectId,
|
|
1719
|
-
region:
|
|
1720
|
-
|
|
1721
|
-
|
|
2096
|
+
region: options.region,
|
|
2097
|
+
image: options.image,
|
|
2098
|
+
runnerName: options.name,
|
|
1722
2099
|
snapshotKey: prepared.snapshotKey,
|
|
1723
2100
|
base,
|
|
1724
2101
|
snapshotId: saved.value.snapshotId,
|
|
@@ -1738,20 +2115,151 @@ async function buildSnapshot(context, request2, control, progress) {
|
|
|
1738
2115
|
});
|
|
1739
2116
|
return {
|
|
1740
2117
|
kind: "ok",
|
|
1741
|
-
value: { entry, ms, sizeBytes: saved.value.sizeBytes,
|
|
2118
|
+
value: { entry, ms, sizeBytes: saved.value.sizeBytes, localIndexFailure: written.ok ? null : written.failure }
|
|
2119
|
+
};
|
|
2120
|
+
}
|
|
2121
|
+
async function resolveGitFetchUrl(checkout, request2) {
|
|
2122
|
+
const remote = await checkout.remoteUrl(request2);
|
|
2123
|
+
if (!remote.ok) return remote;
|
|
2124
|
+
const fetchUrl = normalizeGitFetchUrl(remote.value);
|
|
2125
|
+
if (fetchUrl.ok) return { ok: true, value: fetchUrl.url };
|
|
2126
|
+
return { ok: false, failure: { message: `the URL of Git remote "${request2.remote}" ${fetchUrl.problem}` } };
|
|
2127
|
+
}
|
|
2128
|
+
|
|
2129
|
+
// src/runner/shared-snapshot-entry.ts
|
|
2130
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
2131
|
+
var SHARED_SNAPSHOT_SANDBOX_PREFIX = "storm-snap-";
|
|
2132
|
+
var SHARED_SNAPSHOT_NAME_PATTERN = /^storm-snap-([0-9a-f]{16})-([0-9a-f]{40})$/;
|
|
2133
|
+
var INDEX_CONCURRENCY = 8;
|
|
2134
|
+
function isBuildingSandboxStatus(status) {
|
|
2135
|
+
switch (status) {
|
|
2136
|
+
case "pending":
|
|
2137
|
+
case "running":
|
|
2138
|
+
case "snapshotting":
|
|
2139
|
+
case "stopping":
|
|
2140
|
+
return true;
|
|
2141
|
+
case "stopped":
|
|
2142
|
+
case "failed":
|
|
2143
|
+
case "aborted":
|
|
2144
|
+
return false;
|
|
2145
|
+
}
|
|
2146
|
+
}
|
|
2147
|
+
function hasSnapshotId(row) {
|
|
2148
|
+
return row.currentSnapshotId !== void 0 && row.currentSnapshotId !== "";
|
|
2149
|
+
}
|
|
2150
|
+
function sharedSnapshotBucket(input) {
|
|
2151
|
+
return createHash3("sha256").update([input.teamId, input.projectId, input.region, input.image, input.runnerName, input.snapshotKey].join("\0")).digest("hex").slice(0, 16);
|
|
2152
|
+
}
|
|
2153
|
+
function sharedSnapshotSandboxPrefix(bucket) {
|
|
2154
|
+
return `${SHARED_SNAPSHOT_SANDBOX_PREFIX}${bucket}-`;
|
|
2155
|
+
}
|
|
2156
|
+
function sharedSnapshotSandboxName(bucket, base) {
|
|
2157
|
+
return `${SHARED_SNAPSHOT_SANDBOX_PREFIX}${bucket}-${base}`;
|
|
2158
|
+
}
|
|
2159
|
+
function parseSharedSnapshotSandboxName(name) {
|
|
2160
|
+
const match = SHARED_SNAPSHOT_NAME_PATTERN.exec(name);
|
|
2161
|
+
if (match === null) return null;
|
|
2162
|
+
const [, bucket, base] = match;
|
|
2163
|
+
if (bucket === void 0 || base === void 0) return null;
|
|
2164
|
+
return { bucket, base };
|
|
2165
|
+
}
|
|
2166
|
+
function classifyUnverifiedSharedSandbox(row) {
|
|
2167
|
+
if (isBuildingSandboxStatus(row.status)) return { kind: "settled", status: "building" };
|
|
2168
|
+
if (row.status === "failed" || row.status === "aborted") return { kind: "settled", status: "failed" };
|
|
2169
|
+
if (!hasSnapshotId(row)) return { kind: "settled", status: "no-snapshot" };
|
|
2170
|
+
return { kind: "needs-snapshot", snapshotId: row.currentSnapshotId };
|
|
2171
|
+
}
|
|
2172
|
+
function classifyVerifiedSharedSnapshot(row, lookup, now) {
|
|
2173
|
+
if (lookup.kind === "not-found") {
|
|
2174
|
+
return {
|
|
2175
|
+
status: "missing",
|
|
2176
|
+
snapshotId: row.currentSnapshotId,
|
|
2177
|
+
snapshotStatus: void 0,
|
|
2178
|
+
createdAt: row.createdAt,
|
|
2179
|
+
expiresAt: row.tags["expires-at"]
|
|
2180
|
+
};
|
|
2181
|
+
}
|
|
2182
|
+
const { snapshot } = lookup;
|
|
2183
|
+
const expiresAt = snapshot.expiresAt ?? row.tags["expires-at"];
|
|
2184
|
+
if (snapshot.status !== "created") {
|
|
2185
|
+
return {
|
|
2186
|
+
status: "missing",
|
|
2187
|
+
snapshotId: snapshot.snapshotId,
|
|
2188
|
+
snapshotStatus: snapshot.status,
|
|
2189
|
+
createdAt: snapshot.createdAt,
|
|
2190
|
+
expiresAt
|
|
2191
|
+
};
|
|
2192
|
+
}
|
|
2193
|
+
const expiresAtMs = expiresAt === void 0 ? Number.NaN : Date.parse(expiresAt);
|
|
2194
|
+
if (Number.isNaN(expiresAtMs)) {
|
|
2195
|
+
return {
|
|
2196
|
+
status: "unknown-expiry",
|
|
2197
|
+
snapshotId: snapshot.snapshotId,
|
|
2198
|
+
snapshotStatus: snapshot.status,
|
|
2199
|
+
createdAt: snapshot.createdAt,
|
|
2200
|
+
expiresAt
|
|
2201
|
+
};
|
|
2202
|
+
}
|
|
2203
|
+
const nowMs = now.getTime();
|
|
2204
|
+
const status = expiresAtMs <= nowMs ? "expired" : expiresAtMs - nowMs > SNAPSHOT_MIN_REMAINING_MS ? "ready" : "expires-soon";
|
|
2205
|
+
return {
|
|
2206
|
+
status,
|
|
2207
|
+
snapshotId: snapshot.snapshotId,
|
|
2208
|
+
snapshotStatus: snapshot.status,
|
|
2209
|
+
createdAt: snapshot.createdAt,
|
|
2210
|
+
expiresAt
|
|
2211
|
+
};
|
|
2212
|
+
}
|
|
2213
|
+
function usableSharedEntry(access, runner, snapshotKey2, base, sandbox, snapshot, now) {
|
|
2214
|
+
const verified = classifyVerifiedSharedSnapshot(
|
|
2215
|
+
{ ...sandbox, currentSnapshotId: snapshot.snapshotId },
|
|
2216
|
+
{ kind: "found", snapshot },
|
|
2217
|
+
now
|
|
2218
|
+
);
|
|
2219
|
+
if (verified.status !== "ready" || verified.expiresAt === void 0) return null;
|
|
2220
|
+
return {
|
|
2221
|
+
teamId: access.teamId,
|
|
2222
|
+
projectId: access.projectId,
|
|
2223
|
+
region: runner.region,
|
|
2224
|
+
image: runner.image,
|
|
2225
|
+
runnerName: runner.name,
|
|
2226
|
+
snapshotKey: snapshotKey2,
|
|
2227
|
+
base,
|
|
2228
|
+
snapshotId: verified.snapshotId,
|
|
2229
|
+
createdAt: verified.createdAt,
|
|
2230
|
+
expiresAt: verified.expiresAt
|
|
2231
|
+
};
|
|
2232
|
+
}
|
|
2233
|
+
async function runLimited(count, limit, proceed, task) {
|
|
2234
|
+
const results = Array.from({ length: count }, () => void 0);
|
|
2235
|
+
let failure;
|
|
2236
|
+
let next = 0;
|
|
2237
|
+
const worker = async () => {
|
|
2238
|
+
while (failure === void 0 && next < count && proceed()) {
|
|
2239
|
+
const index = next;
|
|
2240
|
+
next += 1;
|
|
2241
|
+
try {
|
|
2242
|
+
results[index] = await task(index);
|
|
2243
|
+
} catch (error) {
|
|
2244
|
+
failure ??= { error };
|
|
2245
|
+
}
|
|
2246
|
+
}
|
|
1742
2247
|
};
|
|
2248
|
+
await Promise.all(Array.from({ length: Math.min(limit, count) }, worker));
|
|
2249
|
+
if (failure !== void 0) throw failure.error;
|
|
2250
|
+
return results;
|
|
1743
2251
|
}
|
|
1744
2252
|
|
|
1745
2253
|
// src/runner/build-snapshots.ts
|
|
1746
2254
|
async function prepareSnapshotBuild(context, request2) {
|
|
1747
2255
|
const { checkout } = context;
|
|
1748
|
-
const {
|
|
2256
|
+
const { options, ref } = request2;
|
|
1749
2257
|
const root = await checkout.repositoryRoot({ cwd: request2.cwd });
|
|
1750
2258
|
if (!root.ok) return { kind: "checkout-failed", failure: root.failure };
|
|
1751
2259
|
const repoRoot = root.value;
|
|
1752
2260
|
const head2 = await checkout.head({ repoRoot });
|
|
1753
2261
|
if (!head2.ok) return { kind: "checkout-failed", failure: head2.failure };
|
|
1754
|
-
const resolved = await resolveBase(checkout, { repoRoot, baseRefs:
|
|
2262
|
+
const resolved = await resolveBase(checkout, { repoRoot, baseRefs: options.baseRefs });
|
|
1755
2263
|
if (resolved.kind === "failed") return { kind: "checkout-failed", failure: resolved.failure };
|
|
1756
2264
|
const mergeBase = resolved.kind === "resolved" ? { commit: resolved.base, ref: resolved.ref } : null;
|
|
1757
2265
|
const submodules2 = await checkout.submodules({ repoRoot });
|
|
@@ -1767,12 +2275,12 @@ async function prepareSnapshotBuild(context, request2) {
|
|
|
1767
2275
|
if (commit.value === null) return { kind: "ref-not-found", ref };
|
|
1768
2276
|
base = commit.value;
|
|
1769
2277
|
}
|
|
1770
|
-
const inputs = await snapshotInputsAt(checkout, { repoRoot, base,
|
|
1771
|
-
if (!inputs.ok) return { kind: "invalid-
|
|
2278
|
+
const inputs = await snapshotInputsAt(checkout, { repoRoot, base, options });
|
|
2279
|
+
if (!inputs.ok) return { kind: "invalid-runner", path: inputs.path, problem: inputs.problem };
|
|
1772
2280
|
const listed = await context.runnerSnapshots.listEntries();
|
|
1773
2281
|
const now = context.clock.now();
|
|
1774
|
-
const
|
|
1775
|
-
(entry) => entry.base === base && entry
|
|
2282
|
+
const indexed = (listed.ok ? listed.value.entries : []).filter(
|
|
2283
|
+
(entry) => entry.base === base && matchesRunnerTarget(entry, options) && entry.snapshotKey === inputs.key && hasTimeLeft(entry, now)
|
|
1776
2284
|
);
|
|
1777
2285
|
const atMergeBase = base === mergeBase?.commit;
|
|
1778
2286
|
let commitsAfterBase = null;
|
|
@@ -1781,11 +2289,17 @@ async function prepareSnapshotBuild(context, request2) {
|
|
|
1781
2289
|
if (!counted.ok) return { kind: "checkout-failed", failure: counted.failure };
|
|
1782
2290
|
commitsAfterBase = counted.value;
|
|
1783
2291
|
}
|
|
2292
|
+
let ancestorOfMergeBase = false;
|
|
2293
|
+
if (!atMergeBase && mergeBase !== null) {
|
|
2294
|
+
const contained = await checkout.contains({ repoRoot, ancestor: base, descendant: mergeBase.commit });
|
|
2295
|
+
if (!contained.ok) return { kind: "checkout-failed", failure: contained.failure };
|
|
2296
|
+
ancestorOfMergeBase = contained.value;
|
|
2297
|
+
}
|
|
1784
2298
|
return {
|
|
1785
2299
|
kind: "ok",
|
|
1786
2300
|
build: {
|
|
1787
2301
|
plan: {
|
|
1788
|
-
|
|
2302
|
+
options,
|
|
1789
2303
|
repoRoot,
|
|
1790
2304
|
base,
|
|
1791
2305
|
baseFiles: inputs.baseFiles,
|
|
@@ -1796,16 +2310,21 @@ async function prepareSnapshotBuild(context, request2) {
|
|
|
1796
2310
|
ref: ref ?? null,
|
|
1797
2311
|
mergeBase,
|
|
1798
2312
|
atMergeBase,
|
|
1799
|
-
|
|
2313
|
+
ancestorOfMergeBase,
|
|
2314
|
+
indexed,
|
|
1800
2315
|
full: request2.full
|
|
1801
2316
|
}
|
|
1802
2317
|
};
|
|
1803
2318
|
}
|
|
2319
|
+
function sameSnapshotBuild(a, b) {
|
|
2320
|
+
return sameRunnerTarget(a.options, b.options) && a.snapshotKey === b.snapshotKey;
|
|
2321
|
+
}
|
|
1804
2322
|
async function buildSnapshots(context, request2, control, progress) {
|
|
1805
2323
|
const { signal } = control;
|
|
1806
2324
|
const scope = runnerSandboxScope(context, progress, {
|
|
1807
2325
|
keepMs: 0,
|
|
1808
|
-
basePolicy: runnerNetworkPolicy(request2.build.plan.
|
|
2326
|
+
basePolicy: runnerNetworkPolicy(request2.build.plan.options),
|
|
2327
|
+
managedCredentials: request2.build.plan.options.managedCredentials,
|
|
1809
2328
|
signal
|
|
1810
2329
|
});
|
|
1811
2330
|
try {
|
|
@@ -1820,26 +2339,99 @@ async function buildIn(context, request2, control, progress) {
|
|
|
1820
2339
|
const { build, access, user, credentials: credentials2 } = request2;
|
|
1821
2340
|
const { signal } = control;
|
|
1822
2341
|
if (signal.aborted) return { kind: "aborted", snapshot: null };
|
|
1823
|
-
|
|
1824
|
-
|
|
2342
|
+
if (request2.publish === true) return await publishIn(context, request2, control, progress);
|
|
2343
|
+
const indexed = build.indexed.find((entry2) => entry2.teamId === access.teamId && entry2.projectId === access.projectId);
|
|
2344
|
+
if (!build.full && indexed !== void 0) return { kind: "up-to-date", snapshot: indexed };
|
|
2345
|
+
const built = await buildSnapshot(
|
|
2346
|
+
context,
|
|
2347
|
+
{ prepared: build.plan, access, user, credentials: credentials2, why: buildReason(build) },
|
|
2348
|
+
control,
|
|
2349
|
+
progress
|
|
2350
|
+
);
|
|
2351
|
+
if (built.kind === "aborted") return { kind: "aborted", snapshot: null };
|
|
2352
|
+
if (built.kind !== "ok") return built;
|
|
2353
|
+
const { entry, localIndexFailure, ms, sizeBytes } = built.value;
|
|
2354
|
+
if (signal.aborted) return { kind: "aborted", snapshot: { entry, indexed: localIndexFailure === null } };
|
|
2355
|
+
return localIndexFailure === null ? { kind: "built", snapshot: entry, ms, sizeBytes } : { kind: "not-indexed", snapshot: entry, failure: localIndexFailure };
|
|
2356
|
+
}
|
|
2357
|
+
function buildReason(build) {
|
|
1825
2358
|
const why = build.full ? "full" : build.ref === null ? "no-snapshot" : "base";
|
|
2359
|
+
return why === "no-snapshot" ? { kind: why, rejected: [] } : { kind: why };
|
|
2360
|
+
}
|
|
2361
|
+
async function publishIn(context, request2, control, progress) {
|
|
2362
|
+
const { build, access, user, credentials: credentials2 } = request2;
|
|
2363
|
+
const { plan } = build;
|
|
2364
|
+
const { options } = plan;
|
|
2365
|
+
const { signal } = control;
|
|
2366
|
+
const { runnerSandboxes } = context;
|
|
2367
|
+
const bucket = sharedSnapshotBucket({
|
|
2368
|
+
teamId: access.teamId,
|
|
2369
|
+
projectId: access.projectId,
|
|
2370
|
+
region: options.region,
|
|
2371
|
+
image: options.image,
|
|
2372
|
+
runnerName: options.name,
|
|
2373
|
+
snapshotKey: plan.snapshotKey
|
|
2374
|
+
});
|
|
2375
|
+
const name = sharedSnapshotSandboxName(bucket, plan.base);
|
|
2376
|
+
const found = await runnerSandboxes.getNamedSandbox(access, { name }, signal);
|
|
2377
|
+
if (!found.ok) return callStop("get-named-sandbox", found.failure);
|
|
2378
|
+
if (found.value.kind === "found") {
|
|
2379
|
+
const { sandbox } = found.value;
|
|
2380
|
+
const unverified = classifyUnverifiedSharedSandbox(sandbox);
|
|
2381
|
+
if (unverified.kind === "settled" && unverified.status === "building")
|
|
2382
|
+
return { kind: "already-building", sandboxName: name, status: sandbox.status };
|
|
2383
|
+
if (!build.full && unverified.kind === "needs-snapshot") {
|
|
2384
|
+
const verified = await runnerSandboxes.getSnapshot(access, { snapshotId: unverified.snapshotId }, signal);
|
|
2385
|
+
if (!verified.ok) return callStop("get-snapshot", verified.failure);
|
|
2386
|
+
const entry2 = verified.value.kind === "found" ? usableSharedEntry(
|
|
2387
|
+
access,
|
|
2388
|
+
options,
|
|
2389
|
+
plan.snapshotKey,
|
|
2390
|
+
plan.base,
|
|
2391
|
+
sandbox,
|
|
2392
|
+
verified.value.snapshot,
|
|
2393
|
+
context.clock.now()
|
|
2394
|
+
) : null;
|
|
2395
|
+
if (entry2 !== null) {
|
|
2396
|
+
const written = await context.runnerSnapshots.writeEntry(entry2);
|
|
2397
|
+
if (!written.ok) await progress.emit({ kind: "snapshot-entry-not-written", failure: written.failure });
|
|
2398
|
+
return { kind: "up-to-date", snapshot: entry2, sandboxName: name };
|
|
2399
|
+
}
|
|
2400
|
+
}
|
|
2401
|
+
const removed = await runnerSandboxes.deleteNamedSandbox(access, { name }, signal);
|
|
2402
|
+
if (!removed.ok) return callStop("delete-named-sandbox", removed.failure);
|
|
2403
|
+
}
|
|
2404
|
+
if (signal.aborted) return { kind: "aborted", snapshot: null };
|
|
2405
|
+
const expiresAt = new Date(context.clock.now().getTime() + SNAPSHOT_EXPIRATION_MS).toISOString();
|
|
1826
2406
|
const built = await buildSnapshot(
|
|
1827
2407
|
context,
|
|
1828
2408
|
{
|
|
1829
|
-
prepared:
|
|
2409
|
+
prepared: plan,
|
|
1830
2410
|
access,
|
|
1831
2411
|
user,
|
|
1832
2412
|
credentials: credentials2,
|
|
1833
|
-
why:
|
|
2413
|
+
why: buildReason(build),
|
|
2414
|
+
publish: { name, tags: snapshotIndexTags(options.name, user, plan.base, expiresAt) }
|
|
1834
2415
|
},
|
|
1835
2416
|
control,
|
|
1836
2417
|
progress
|
|
1837
2418
|
);
|
|
2419
|
+
if (built.kind === "name-taken") return { kind: "already-building", sandboxName: name, status: null };
|
|
1838
2420
|
if (built.kind === "aborted") return { kind: "aborted", snapshot: null };
|
|
1839
2421
|
if (built.kind !== "ok") return built;
|
|
1840
|
-
const { entry,
|
|
1841
|
-
if (signal.aborted) return { kind: "aborted", snapshot: { entry,
|
|
1842
|
-
return
|
|
2422
|
+
const { entry, localIndexFailure, ms, sizeBytes } = built.value;
|
|
2423
|
+
if (signal.aborted) return { kind: "aborted", snapshot: { entry, indexed: localIndexFailure === null } };
|
|
2424
|
+
return {
|
|
2425
|
+
kind: "built",
|
|
2426
|
+
snapshot: entry,
|
|
2427
|
+
ms,
|
|
2428
|
+
sizeBytes,
|
|
2429
|
+
sandboxName: name,
|
|
2430
|
+
...localIndexFailure === null ? {} : { localIndexFailure }
|
|
2431
|
+
};
|
|
2432
|
+
}
|
|
2433
|
+
function callStop(operation, failure) {
|
|
2434
|
+
return failure.kind === "aborted" ? { kind: "aborted", snapshot: null } : { kind: "failed", failure: sandboxApiFailure(operation, failure) };
|
|
1843
2435
|
}
|
|
1844
2436
|
|
|
1845
2437
|
// src/runner/live/user.ts
|
|
@@ -1853,30 +2445,173 @@ function localUserName() {
|
|
|
1853
2445
|
}
|
|
1854
2446
|
|
|
1855
2447
|
// src/runner/secrets.ts
|
|
1856
|
-
|
|
1857
|
-
|
|
2448
|
+
var CREDENTIAL_PROBLEM_KINDS = [
|
|
2449
|
+
"missing",
|
|
2450
|
+
"multiline",
|
|
2451
|
+
"short",
|
|
2452
|
+
"gh-not-installed",
|
|
2453
|
+
"gh-not-authenticated",
|
|
2454
|
+
"gh-timed-out",
|
|
2455
|
+
"gh-failed",
|
|
2456
|
+
"gh-preframed"
|
|
2457
|
+
];
|
|
2458
|
+
function declaredSecretValues(options, env) {
|
|
2459
|
+
if (options === void 0) return [];
|
|
1858
2460
|
const seen = /* @__PURE__ */ new Set();
|
|
1859
2461
|
const values = [];
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
2462
|
+
const add = (value) => {
|
|
2463
|
+
if (value.length === 0 || seen.has(value)) return;
|
|
2464
|
+
seen.add(value);
|
|
2465
|
+
values.push(value);
|
|
2466
|
+
};
|
|
2467
|
+
for (const { source } of options.credentials) {
|
|
2468
|
+
switch (source.kind) {
|
|
2469
|
+
case "env": {
|
|
2470
|
+
const value = readSecretSourceValue(source, env);
|
|
2471
|
+
if (value !== void 0) add(value);
|
|
2472
|
+
break;
|
|
2473
|
+
}
|
|
2474
|
+
case "gh": {
|
|
2475
|
+
if (source.env !== void 0) {
|
|
2476
|
+
const raw = ownNonEmpty(env, source.env);
|
|
2477
|
+
if (raw !== void 0) {
|
|
2478
|
+
for (const form of ghEnvRedactionForms(raw)) add(form);
|
|
2479
|
+
}
|
|
2480
|
+
}
|
|
2481
|
+
break;
|
|
2482
|
+
}
|
|
2483
|
+
}
|
|
2484
|
+
}
|
|
2485
|
+
for (const { source } of options.unsafeSecretEnvVars) {
|
|
1864
2486
|
const value = readSecretSourceValue(source, env);
|
|
1865
|
-
if (value !== void 0)
|
|
2487
|
+
if (value !== void 0) add(value);
|
|
1866
2488
|
}
|
|
1867
2489
|
return values;
|
|
1868
2490
|
}
|
|
1869
|
-
function readCredentials(
|
|
1870
|
-
const
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
2491
|
+
async function readCredentials(options, env, context) {
|
|
2492
|
+
const envCache = /* @__PURE__ */ new Map();
|
|
2493
|
+
const overrideEnvFailures = /* @__PURE__ */ new Set();
|
|
2494
|
+
const ghCache = /* @__PURE__ */ new Map();
|
|
2495
|
+
const ghFailureSeen = /* @__PURE__ */ new Set();
|
|
2496
|
+
const problems = [];
|
|
2497
|
+
const credentials2 = [];
|
|
2498
|
+
const secretSet = /* @__PURE__ */ new Set();
|
|
2499
|
+
const addSecrets = (forms) => {
|
|
2500
|
+
for (const form of forms) {
|
|
2501
|
+
if (form.length > 0) secretSet.add(form);
|
|
2502
|
+
}
|
|
2503
|
+
};
|
|
2504
|
+
for (const entry of options.credentials) {
|
|
2505
|
+
const { domain, header, source, requests } = entry;
|
|
2506
|
+
switch (source.kind) {
|
|
2507
|
+
case "env": {
|
|
2508
|
+
const id = secretSourceId(source);
|
|
2509
|
+
let read = envCache.get(id);
|
|
2510
|
+
if (read === void 0) {
|
|
2511
|
+
read = readSecretSource(source, env);
|
|
2512
|
+
envCache.set(id, read);
|
|
2513
|
+
if (!read.ok) {
|
|
2514
|
+
problems.push(envVariableProblem(describeSecretSource(source), read.problem));
|
|
2515
|
+
}
|
|
2516
|
+
}
|
|
2517
|
+
if (read.ok) {
|
|
2518
|
+
credentials2.push({ domain, header, value: read.value, requests });
|
|
2519
|
+
addSecrets([read.value]);
|
|
2520
|
+
}
|
|
2521
|
+
break;
|
|
2522
|
+
}
|
|
2523
|
+
case "gh": {
|
|
2524
|
+
const host = resolveGhHost(source);
|
|
2525
|
+
const format = resolveGhFormat(domain, source);
|
|
2526
|
+
const envOverride = source.env === void 0 ? void 0 : ownNonEmpty(env, source.env);
|
|
2527
|
+
if (envOverride !== void 0 && source.env !== void 0) {
|
|
2528
|
+
const framed2 = frameGhToken(envOverride, format);
|
|
2529
|
+
if (!framed2.ok) {
|
|
2530
|
+
const key = `env:${source.env}:${framed2.problem}`;
|
|
2531
|
+
if (!overrideEnvFailures.has(key)) {
|
|
2532
|
+
overrideEnvFailures.add(key);
|
|
2533
|
+
if (framed2.problem === "gh-preframed") {
|
|
2534
|
+
problems.push({
|
|
2535
|
+
name: source.env,
|
|
2536
|
+
problem: "gh-preframed",
|
|
2537
|
+
detail: `${source.env} must hold a raw token, not a pre-framed Authorization header`,
|
|
2538
|
+
hint: `Set ${source.env} to the raw token: storm frames it as ${format === "basic" ? "Basic" : "Bearer"} automatically.`
|
|
2539
|
+
});
|
|
2540
|
+
} else {
|
|
2541
|
+
problems.push(envVariableProblem(source.env, framed2.problem));
|
|
2542
|
+
}
|
|
2543
|
+
}
|
|
2544
|
+
} else {
|
|
2545
|
+
credentials2.push({ domain, header, value: framed2.headerValue, requests });
|
|
2546
|
+
addSecrets(framed2.secrets);
|
|
2547
|
+
}
|
|
2548
|
+
break;
|
|
2549
|
+
}
|
|
2550
|
+
let ghRead = ghCache.get(host);
|
|
2551
|
+
if (ghRead === void 0) {
|
|
2552
|
+
ghRead = await context.ghTokens.readToken({ host });
|
|
2553
|
+
ghCache.set(host, ghRead);
|
|
2554
|
+
}
|
|
2555
|
+
const label = `gh (${host})`;
|
|
2556
|
+
if (!ghRead.ok) {
|
|
2557
|
+
const failureKey = `gh:${host}:${source.env ?? ""}`;
|
|
2558
|
+
if (!ghFailureSeen.has(failureKey)) {
|
|
2559
|
+
ghFailureSeen.add(failureKey);
|
|
2560
|
+
const { failure } = ghRead;
|
|
2561
|
+
const problemKind = failure.kind === "not-installed" ? "gh-not-installed" : failure.kind === "not-authenticated" ? "gh-not-authenticated" : failure.kind === "timed-out" ? "gh-timed-out" : "gh-failed";
|
|
2562
|
+
const baseHint = failure.kind === "not-installed" ? "Install the GitHub CLI (gh) and run `gh auth login`" : failure.kind === "not-authenticated" ? `Run \`gh auth login --hostname ${host}\`` : `Check that \`gh auth token --hostname ${host}\` succeeds on this machine`;
|
|
2563
|
+
problems.push({
|
|
2564
|
+
name: label,
|
|
2565
|
+
problem: problemKind,
|
|
2566
|
+
detail: failure.message,
|
|
2567
|
+
hint: withEnvFallback(baseHint, source.env)
|
|
2568
|
+
});
|
|
2569
|
+
}
|
|
2570
|
+
break;
|
|
2571
|
+
}
|
|
2572
|
+
const framed = frameGhToken(ghRead.token, format);
|
|
2573
|
+
if (!framed.ok) {
|
|
2574
|
+
const failureKey = `gh-token:${host}:${framed.problem}`;
|
|
2575
|
+
if (!ghFailureSeen.has(failureKey)) {
|
|
2576
|
+
ghFailureSeen.add(failureKey);
|
|
2577
|
+
if (framed.problem === "gh-preframed") {
|
|
2578
|
+
problems.push({
|
|
2579
|
+
name: label,
|
|
2580
|
+
problem: "gh-preframed",
|
|
2581
|
+
detail: `gh auth token --hostname ${host} returned a pre-framed Authorization header instead of a raw token`,
|
|
2582
|
+
hint: withEnvFallback(`Re-authenticate with \`gh auth login --hostname ${host}\``, source.env)
|
|
2583
|
+
});
|
|
2584
|
+
} else if (framed.problem === "multiline") {
|
|
2585
|
+
problems.push({
|
|
2586
|
+
name: label,
|
|
2587
|
+
problem: "multiline",
|
|
2588
|
+
detail: `gh auth token --hostname ${host} returned a value with a carriage return or a line feed`,
|
|
2589
|
+
hint: withEnvFallback(`Re-authenticate with \`gh auth login --hostname ${host}\``, source.env)
|
|
2590
|
+
});
|
|
2591
|
+
} else {
|
|
2592
|
+
problems.push({
|
|
2593
|
+
name: label,
|
|
2594
|
+
problem: "short",
|
|
2595
|
+
detail: `gh auth token --hostname ${host} returned fewer than ${SECRET_MIN_LENGTH} characters`,
|
|
2596
|
+
hint: withEnvFallback(`Re-authenticate with \`gh auth login --hostname ${host}\``, source.env)
|
|
2597
|
+
});
|
|
2598
|
+
}
|
|
2599
|
+
}
|
|
2600
|
+
break;
|
|
2601
|
+
}
|
|
2602
|
+
credentials2.push({ domain, header, value: framed.headerValue, requests });
|
|
2603
|
+
addSecrets(framed.secrets);
|
|
2604
|
+
break;
|
|
2605
|
+
}
|
|
2606
|
+
}
|
|
2607
|
+
}
|
|
2608
|
+
return problems.length === 0 ? { ok: true, credentials: credentials2, secrets: [...secretSet] } : { ok: false, problems };
|
|
1877
2609
|
}
|
|
1878
|
-
function readUnsafeSecretEnvVars(
|
|
1879
|
-
const read = readUniqueSources(
|
|
2610
|
+
function readUnsafeSecretEnvVars(options, env) {
|
|
2611
|
+
const read = readUniqueSources(options.unsafeSecretEnvVars, env, ({ name }, value) => [
|
|
2612
|
+
name,
|
|
2613
|
+
value
|
|
2614
|
+
]);
|
|
1880
2615
|
return read.ok ? { ok: true, values: Object.fromEntries(read.items) } : read;
|
|
1881
2616
|
}
|
|
1882
2617
|
function readUniqueSources(entries, env, map) {
|
|
@@ -1895,17 +2630,49 @@ function readUniqueSources(entries, env, map) {
|
|
|
1895
2630
|
}
|
|
1896
2631
|
return variables.length === 0 ? { ok: true, items } : { ok: false, variables };
|
|
1897
2632
|
}
|
|
2633
|
+
function envVariableProblem(name, problem) {
|
|
2634
|
+
switch (problem) {
|
|
2635
|
+
case "missing":
|
|
2636
|
+
return {
|
|
2637
|
+
name,
|
|
2638
|
+
problem,
|
|
2639
|
+
detail: `${name} is not set`,
|
|
2640
|
+
hint: `Set ${name} in this machine's environment.`
|
|
2641
|
+
};
|
|
2642
|
+
case "multiline":
|
|
2643
|
+
return {
|
|
2644
|
+
name,
|
|
2645
|
+
problem,
|
|
2646
|
+
detail: `${name} holds a carriage return or a line feed`,
|
|
2647
|
+
hint: `Set ${name} to a value on one line: storm hides each value in output a line at a time, and doesn't trim one.`
|
|
2648
|
+
};
|
|
2649
|
+
case "short":
|
|
2650
|
+
return {
|
|
2651
|
+
name,
|
|
2652
|
+
problem,
|
|
2653
|
+
detail: `${name} holds fewer than ${SECRET_MIN_LENGTH} characters`,
|
|
2654
|
+
hint: `Set ${name} to the whole secret.`
|
|
2655
|
+
};
|
|
2656
|
+
}
|
|
2657
|
+
}
|
|
2658
|
+
function withEnvFallback(base, envVar) {
|
|
2659
|
+
return envVar === void 0 ? `${base}.` : `${base}, or set ${envVar} in this machine's environment.`;
|
|
2660
|
+
}
|
|
2661
|
+
function ownNonEmpty(env, name) {
|
|
2662
|
+
const value = Object.hasOwn(env, name) ? env[name] : void 0;
|
|
2663
|
+
return value === void 0 || value.length === 0 ? void 0 : value;
|
|
2664
|
+
}
|
|
1898
2665
|
|
|
1899
2666
|
// src/runner/snapshot-inspect.ts
|
|
1900
|
-
async function
|
|
2667
|
+
async function inspectLocalSnapshotIndex(context, request2) {
|
|
1901
2668
|
const { checkout, runnerSnapshots } = context;
|
|
1902
|
-
const {
|
|
2669
|
+
const { options } = request2;
|
|
1903
2670
|
const listed = await runnerSnapshots.listEntries();
|
|
1904
|
-
if (!listed.ok) return { kind: "
|
|
2671
|
+
if (!listed.ok) return { kind: "local-index-unreadable", ...listed.failure };
|
|
1905
2672
|
const { directory, entries, unreadable } = listed.value;
|
|
1906
2673
|
const now = context.clock.now();
|
|
1907
|
-
const
|
|
1908
|
-
const shows = (entry) => request2.all ||
|
|
2674
|
+
const ofRunner = (entry) => options !== void 0 && matchesRunnerTarget(entry, options);
|
|
2675
|
+
const shows = (entry) => request2.all || options === void 0 || ofRunner(entry);
|
|
1909
2676
|
const shown = entries.filter(shows);
|
|
1910
2677
|
const root = await checkout.repositoryRoot({ cwd: request2.cwd });
|
|
1911
2678
|
const head2 = root.ok ? await checkout.head({ repoRoot: root.value }) : void 0;
|
|
@@ -1916,37 +2683,47 @@ async function inspectSnapshotCache(context, request2) {
|
|
|
1916
2683
|
directory,
|
|
1917
2684
|
checkout: null,
|
|
1918
2685
|
picking: { kind: "none", why: "no-checkout" },
|
|
2686
|
+
snapshotKey: null,
|
|
1919
2687
|
snapshots: shown.map((entry) => unchecked(entry, now)),
|
|
1920
2688
|
unreadable
|
|
1921
2689
|
}
|
|
1922
2690
|
};
|
|
1923
2691
|
}
|
|
1924
2692
|
const repoRoot = root.value;
|
|
1925
|
-
const resolved =
|
|
2693
|
+
const resolved = options === void 0 ? void 0 : await resolveBase(checkout, { repoRoot, baseRefs: options.baseRefs });
|
|
1926
2694
|
if (resolved?.kind === "failed") return { kind: "checkout-failed", failure: resolved.failure };
|
|
1927
|
-
if (
|
|
2695
|
+
if (options === void 0 || resolved === void 0 || resolved.kind !== "resolved") {
|
|
1928
2696
|
return {
|
|
1929
2697
|
kind: "ok",
|
|
1930
2698
|
inspection: {
|
|
1931
2699
|
directory,
|
|
1932
2700
|
checkout: { repoRoot, head: head2.value, mergeBase: null },
|
|
1933
|
-
picking: { kind: "none", why:
|
|
2701
|
+
picking: { kind: "none", why: options === void 0 ? "no-runner" : "no-base" },
|
|
2702
|
+
snapshotKey: null,
|
|
1934
2703
|
snapshots: shown.map((entry) => unchecked(entry, now)),
|
|
1935
2704
|
unreadable
|
|
1936
2705
|
}
|
|
1937
2706
|
};
|
|
1938
2707
|
}
|
|
1939
2708
|
const mergeBase = resolved.base;
|
|
1940
|
-
const inputs = await snapshotInputsAt(checkout, { repoRoot, base: mergeBase,
|
|
1941
|
-
if (!inputs.ok) return { kind: "invalid-
|
|
2709
|
+
const inputs = await snapshotInputsAt(checkout, { repoRoot, base: mergeBase, options });
|
|
2710
|
+
if (!inputs.ok) return { kind: "invalid-runner", path: inputs.path, problem: inputs.problem };
|
|
1942
2711
|
const afterBase = await checkout.commitCount({ repoRoot, from: mergeBase, to: "HEAD" });
|
|
1943
2712
|
if (!afterBase.ok) return { kind: "checkout-failed", failure: afterBase.failure };
|
|
2713
|
+
const ancestorDistances = await resolveAncestorDistances(context, {
|
|
2714
|
+
repoRoot,
|
|
2715
|
+
entries,
|
|
2716
|
+
options,
|
|
2717
|
+
mergeBase
|
|
2718
|
+
});
|
|
2719
|
+
if (!ancestorDistances.ok) return { kind: "checkout-failed", failure: ancestorDistances.failure };
|
|
1944
2720
|
const read = classifySnapshotEntries(context, {
|
|
1945
2721
|
entries,
|
|
1946
|
-
|
|
2722
|
+
options,
|
|
1947
2723
|
base: mergeBase,
|
|
1948
2724
|
snapshotKey: inputs.key,
|
|
1949
|
-
commitsAfterBase: afterBase.value
|
|
2725
|
+
commitsAfterBase: afterBase.value,
|
|
2726
|
+
ancestorDistances: ancestorDistances.value
|
|
1950
2727
|
});
|
|
1951
2728
|
const owners = new Map(read.candidates.map(({ entry }) => [`${entry.teamId}\0${entry.projectId}`, entry]));
|
|
1952
2729
|
const picked = /* @__PURE__ */ new Set();
|
|
@@ -1954,7 +2731,12 @@ async function inspectSnapshotCache(context, request2) {
|
|
|
1954
2731
|
const pick = pickSnapshot(read.candidates, owner);
|
|
1955
2732
|
if (pick !== void 0) picked.add(pick);
|
|
1956
2733
|
}
|
|
1957
|
-
const place = historyPlacer(context, {
|
|
2734
|
+
const place = historyPlacer(context, {
|
|
2735
|
+
repoRoot,
|
|
2736
|
+
mergeBase,
|
|
2737
|
+
commitsAfterBase: afterBase.value,
|
|
2738
|
+
ancestorDistances: ancestorDistances.value
|
|
2739
|
+
});
|
|
1958
2740
|
const snapshots = [];
|
|
1959
2741
|
for (const verdict of read.verdicts) {
|
|
1960
2742
|
const { entry } = verdict;
|
|
@@ -1966,6 +2748,7 @@ async function inspectSnapshotCache(context, request2) {
|
|
|
1966
2748
|
entry,
|
|
1967
2749
|
inHistory: true,
|
|
1968
2750
|
builtBehind: candidate.builtBehind,
|
|
2751
|
+
commitsBehindMergeBase: candidate.commitsBehindMergeBase,
|
|
1969
2752
|
expired,
|
|
1970
2753
|
picked: picked.has(candidate),
|
|
1971
2754
|
reason: null
|
|
@@ -1977,17 +2760,23 @@ async function inspectSnapshotCache(context, request2) {
|
|
|
1977
2760
|
snapshots.push({
|
|
1978
2761
|
entry,
|
|
1979
2762
|
...placed.value,
|
|
2763
|
+
commitsBehindMergeBase: null,
|
|
1980
2764
|
expired,
|
|
1981
2765
|
picked: false,
|
|
1982
|
-
reason: verdict.kind === "rejected" ? verdict.rejection.reason : "other-
|
|
2766
|
+
reason: verdict.kind === "rejected" ? verdict.rejection.reason : "other-runner"
|
|
1983
2767
|
});
|
|
1984
2768
|
}
|
|
1985
2769
|
return {
|
|
1986
2770
|
kind: "ok",
|
|
1987
2771
|
inspection: {
|
|
1988
2772
|
directory,
|
|
1989
|
-
checkout: {
|
|
1990
|
-
|
|
2773
|
+
checkout: {
|
|
2774
|
+
repoRoot,
|
|
2775
|
+
head: head2.value,
|
|
2776
|
+
mergeBase: { commit: mergeBase, ref: resolved.ref, commitsAfterBase: afterBase.value }
|
|
2777
|
+
},
|
|
2778
|
+
picking: { kind: "runner", runner: options.name },
|
|
2779
|
+
snapshotKey: inputs.key,
|
|
1991
2780
|
snapshots,
|
|
1992
2781
|
unreadable
|
|
1993
2782
|
}
|
|
@@ -1998,6 +2787,7 @@ function unchecked(entry, now) {
|
|
|
1998
2787
|
entry,
|
|
1999
2788
|
inHistory: null,
|
|
2000
2789
|
builtBehind: null,
|
|
2790
|
+
commitsBehindMergeBase: null,
|
|
2001
2791
|
expired: isExpiredEntry(entry, now),
|
|
2002
2792
|
picked: false,
|
|
2003
2793
|
reason: null
|
|
@@ -2005,8 +2795,14 @@ function unchecked(entry, now) {
|
|
|
2005
2795
|
}
|
|
2006
2796
|
function historyPlacer(context, request2) {
|
|
2007
2797
|
const { repoRoot } = request2;
|
|
2008
|
-
const known =
|
|
2009
|
-
[request2.mergeBase, { inHistory: true, builtBehind: request2.commitsAfterBase }]
|
|
2798
|
+
const known = new Map([
|
|
2799
|
+
[request2.mergeBase, { inHistory: true, builtBehind: request2.commitsAfterBase }],
|
|
2800
|
+
...Object.entries(request2.ancestorDistances).map(
|
|
2801
|
+
([base, commitsBehindMergeBase]) => [
|
|
2802
|
+
base,
|
|
2803
|
+
{ inHistory: true, builtBehind: request2.commitsAfterBase + commitsBehindMergeBase }
|
|
2804
|
+
]
|
|
2805
|
+
)
|
|
2010
2806
|
]);
|
|
2011
2807
|
return async (base) => {
|
|
2012
2808
|
const answer = known.get(base);
|
|
@@ -2019,10 +2815,281 @@ function historyPlacer(context, request2) {
|
|
|
2019
2815
|
if (!counted.ok) return counted;
|
|
2020
2816
|
placed = { inHistory: true, builtBehind: counted.value };
|
|
2021
2817
|
}
|
|
2022
|
-
known.set(base, placed);
|
|
2023
|
-
return { ok: true, value: placed };
|
|
2818
|
+
known.set(base, placed);
|
|
2819
|
+
return { ok: true, value: placed };
|
|
2820
|
+
};
|
|
2821
|
+
}
|
|
2822
|
+
|
|
2823
|
+
// src/runner/shared-snapshot-list.ts
|
|
2824
|
+
async function listSharedSnapshots(context, request2, signal) {
|
|
2825
|
+
const { runnerSandboxes, clock } = context;
|
|
2826
|
+
const { access, runner, snapshotKey: snapshotKey2 } = request2;
|
|
2827
|
+
const bucket = sharedSnapshotBucket({
|
|
2828
|
+
teamId: access.teamId,
|
|
2829
|
+
projectId: access.projectId,
|
|
2830
|
+
region: runner.region,
|
|
2831
|
+
image: runner.image,
|
|
2832
|
+
runnerName: runner.name,
|
|
2833
|
+
snapshotKey: snapshotKey2
|
|
2834
|
+
});
|
|
2835
|
+
const listed = await runnerSandboxes.listNamedSandboxes(
|
|
2836
|
+
access,
|
|
2837
|
+
{ namePrefix: sharedSnapshotSandboxPrefix(bucket) },
|
|
2838
|
+
signal
|
|
2839
|
+
);
|
|
2840
|
+
if (!listed.ok) {
|
|
2841
|
+
return listed.failure.kind === "aborted" ? { kind: "aborted" } : { kind: "failed", message: listed.failure.message };
|
|
2842
|
+
}
|
|
2843
|
+
const now = clock.now();
|
|
2844
|
+
const matched = [];
|
|
2845
|
+
for (const row of listed.value) {
|
|
2846
|
+
const parsed = parseSharedSnapshotSandboxName(row.name);
|
|
2847
|
+
if (parsed === null || parsed.bucket !== bucket) continue;
|
|
2848
|
+
matched.push({ row, base: parsed.base });
|
|
2849
|
+
}
|
|
2850
|
+
let stop = false;
|
|
2851
|
+
const outcomes = await runLimited(
|
|
2852
|
+
matched.length,
|
|
2853
|
+
INDEX_CONCURRENCY,
|
|
2854
|
+
() => !stop && signal?.aborted !== true,
|
|
2855
|
+
async (index) => {
|
|
2856
|
+
const { row, base } = matched[index];
|
|
2857
|
+
const unverified = classifyUnverifiedSharedSandbox(row);
|
|
2858
|
+
if (unverified.kind === "settled") {
|
|
2859
|
+
return {
|
|
2860
|
+
kind: "entry",
|
|
2861
|
+
entry: indexEntryOf(row, base, {
|
|
2862
|
+
status: unverified.status,
|
|
2863
|
+
snapshotId: unverified.status === "no-snapshot" ? void 0 : row.currentSnapshotId,
|
|
2864
|
+
snapshotStatus: void 0,
|
|
2865
|
+
createdAt: row.createdAt,
|
|
2866
|
+
expiresAt: row.tags["expires-at"],
|
|
2867
|
+
expired: false
|
|
2868
|
+
})
|
|
2869
|
+
};
|
|
2870
|
+
}
|
|
2871
|
+
const verified = await runnerSandboxes.getSnapshot(access, { snapshotId: unverified.snapshotId }, signal);
|
|
2872
|
+
if (!verified.ok) {
|
|
2873
|
+
stop = true;
|
|
2874
|
+
return verified.failure.kind === "aborted" ? { kind: "aborted" } : { kind: "failed", message: verified.failure.message };
|
|
2875
|
+
}
|
|
2876
|
+
const classified = classifyVerifiedSharedSnapshot(
|
|
2877
|
+
{ ...row, currentSnapshotId: unverified.snapshotId },
|
|
2878
|
+
verified.value,
|
|
2879
|
+
now
|
|
2880
|
+
);
|
|
2881
|
+
return {
|
|
2882
|
+
kind: "entry",
|
|
2883
|
+
entry: indexEntryOf(row, base, {
|
|
2884
|
+
status: classified.status,
|
|
2885
|
+
snapshotId: classified.snapshotId,
|
|
2886
|
+
snapshotStatus: classified.snapshotStatus,
|
|
2887
|
+
createdAt: classified.createdAt,
|
|
2888
|
+
expiresAt: classified.expiresAt,
|
|
2889
|
+
expired: classified.status === "expired"
|
|
2890
|
+
})
|
|
2891
|
+
};
|
|
2892
|
+
}
|
|
2893
|
+
);
|
|
2894
|
+
if (signal?.aborted === true) return { kind: "aborted" };
|
|
2895
|
+
const entries = [];
|
|
2896
|
+
for (const outcome of outcomes) {
|
|
2897
|
+
if (outcome === void 0) continue;
|
|
2898
|
+
if (outcome.kind === "aborted") return { kind: "aborted" };
|
|
2899
|
+
if (outcome.kind === "failed") return outcome;
|
|
2900
|
+
entries.push(outcome.entry);
|
|
2901
|
+
}
|
|
2902
|
+
return { kind: "ok", bucket, entries };
|
|
2903
|
+
}
|
|
2904
|
+
function indexEntryOf(row, base, fields) {
|
|
2905
|
+
return {
|
|
2906
|
+
sandboxName: row.name,
|
|
2907
|
+
base,
|
|
2908
|
+
sandboxStatus: row.status,
|
|
2909
|
+
sandboxCreatedAt: row.createdAt,
|
|
2910
|
+
...fields
|
|
2911
|
+
};
|
|
2912
|
+
}
|
|
2913
|
+
async function pickSnapshotAcrossIndexes(context, request2) {
|
|
2914
|
+
const { checkout } = context;
|
|
2915
|
+
const { repoRoot, mergeBase, commitsAfterBase, owner, local, entries } = request2;
|
|
2916
|
+
const owned = (snapshot) => snapshot.entry.teamId === owner.teamId && snapshot.entry.projectId === owner.projectId;
|
|
2917
|
+
const localPick = local.find((snapshot) => snapshot.picked && owned(snapshot));
|
|
2918
|
+
const behindMergeBaseByBase = /* @__PURE__ */ new Map([[mergeBase, 0]]);
|
|
2919
|
+
const qualifying = [];
|
|
2920
|
+
for (const entry of entries) {
|
|
2921
|
+
if (entry.status !== "ready") continue;
|
|
2922
|
+
let commitsBehindMergeBase = behindMergeBaseByBase.get(entry.base);
|
|
2923
|
+
if (commitsBehindMergeBase === void 0) {
|
|
2924
|
+
const ancestor = await checkout.contains({ repoRoot, ancestor: entry.base, descendant: mergeBase });
|
|
2925
|
+
if (!ancestor.ok) return { kind: "checkout-failed", failure: ancestor.failure };
|
|
2926
|
+
commitsBehindMergeBase = null;
|
|
2927
|
+
if (ancestor.value) {
|
|
2928
|
+
const counted = await checkout.commitCount({ repoRoot, from: entry.base, to: mergeBase });
|
|
2929
|
+
if (!counted.ok) return { kind: "checkout-failed", failure: counted.failure };
|
|
2930
|
+
commitsBehindMergeBase = counted.value;
|
|
2931
|
+
}
|
|
2932
|
+
behindMergeBaseByBase.set(entry.base, commitsBehindMergeBase);
|
|
2933
|
+
}
|
|
2934
|
+
if (commitsBehindMergeBase !== null) qualifying.push({ entry, commitsBehindMergeBase });
|
|
2935
|
+
}
|
|
2936
|
+
const best = qualifying.toSorted(
|
|
2937
|
+
(a, b) => compareSnapshotCandidates(
|
|
2938
|
+
{
|
|
2939
|
+
commitsBehindMergeBase: a.commitsBehindMergeBase,
|
|
2940
|
+
createdAt: a.entry.sandboxCreatedAt,
|
|
2941
|
+
tieBreaker: a.entry.sandboxName
|
|
2942
|
+
},
|
|
2943
|
+
{
|
|
2944
|
+
commitsBehindMergeBase: b.commitsBehindMergeBase,
|
|
2945
|
+
createdAt: b.entry.sandboxCreatedAt,
|
|
2946
|
+
tieBreaker: b.entry.sandboxName
|
|
2947
|
+
}
|
|
2948
|
+
)
|
|
2949
|
+
)[0];
|
|
2950
|
+
const sharedPick = best !== void 0 && sharedBeatsLocal(best.commitsBehindMergeBase, localPick?.commitsBehindMergeBase ?? void 0) ? best.entry : void 0;
|
|
2951
|
+
const readyBehind = new Map(qualifying.map(({ entry, commitsBehindMergeBase }) => [entry, commitsBehindMergeBase]));
|
|
2952
|
+
return {
|
|
2953
|
+
kind: "ok",
|
|
2954
|
+
local: sharedPick === void 0 || localPick === void 0 ? local : local.map((snapshot) => snapshot === localPick ? { ...snapshot, picked: false } : snapshot),
|
|
2955
|
+
shared: entries.map((entry) => {
|
|
2956
|
+
const commitsBehindMergeBase = readyBehind.get(entry);
|
|
2957
|
+
return {
|
|
2958
|
+
entry,
|
|
2959
|
+
picked: entry === sharedPick,
|
|
2960
|
+
builtBehind: commitsBehindMergeBase === void 0 ? null : commitsAfterBase + commitsBehindMergeBase
|
|
2961
|
+
};
|
|
2962
|
+
})
|
|
2963
|
+
};
|
|
2964
|
+
}
|
|
2965
|
+
|
|
2966
|
+
// src/runner/shared-snapshot-prune.ts
|
|
2967
|
+
async function pruneSharedSnapshots(context, request2, signal) {
|
|
2968
|
+
const { runnerSandboxes, clock } = context;
|
|
2969
|
+
const { access, dryRun } = request2;
|
|
2970
|
+
const listed = await runnerSandboxes.listNamedSandboxes(
|
|
2971
|
+
access,
|
|
2972
|
+
{ namePrefix: SHARED_SNAPSHOT_SANDBOX_PREFIX },
|
|
2973
|
+
signal
|
|
2974
|
+
);
|
|
2975
|
+
if (!listed.ok) {
|
|
2976
|
+
return listed.failure.kind === "aborted" ? { kind: "aborted" } : { kind: "failed", message: listed.failure.message };
|
|
2977
|
+
}
|
|
2978
|
+
const validRows = listed.value.filter((row) => parseSharedSnapshotSandboxName(row.name) !== null);
|
|
2979
|
+
const now = clock.now();
|
|
2980
|
+
const nowMs = now.getTime();
|
|
2981
|
+
let aborted = false;
|
|
2982
|
+
const checked = await runLimited(
|
|
2983
|
+
validRows.length,
|
|
2984
|
+
INDEX_CONCURRENCY,
|
|
2985
|
+
() => !aborted && !isAborted(signal),
|
|
2986
|
+
async (index) => {
|
|
2987
|
+
const row = validRows[index];
|
|
2988
|
+
const unverified = classifyUnverifiedSharedSandbox(row);
|
|
2989
|
+
if (unverified.kind === "settled") {
|
|
2990
|
+
switch (unverified.status) {
|
|
2991
|
+
case "building":
|
|
2992
|
+
return { kind: "skip" };
|
|
2993
|
+
case "failed":
|
|
2994
|
+
return { kind: "mark", entry: { name: row.name, reason: "failed" } };
|
|
2995
|
+
case "no-snapshot":
|
|
2996
|
+
return { kind: "mark", entry: { name: row.name, reason: "no-snapshot" } };
|
|
2997
|
+
}
|
|
2998
|
+
}
|
|
2999
|
+
const tagExpiresAt = row.tags["expires-at"];
|
|
3000
|
+
if (tagExpiresAt !== void 0) {
|
|
3001
|
+
const tagMs = Date.parse(tagExpiresAt);
|
|
3002
|
+
if (!Number.isNaN(tagMs) && tagMs > nowMs) return { kind: "skip" };
|
|
3003
|
+
}
|
|
3004
|
+
const verified = await runnerSandboxes.getSnapshot(access, { snapshotId: unverified.snapshotId }, signal);
|
|
3005
|
+
if (!verified.ok) {
|
|
3006
|
+
if (verified.failure.kind === "aborted") {
|
|
3007
|
+
aborted = true;
|
|
3008
|
+
return void 0;
|
|
3009
|
+
}
|
|
3010
|
+
return { kind: "failed", failure: { name: row.name, message: verified.failure.message } };
|
|
3011
|
+
}
|
|
3012
|
+
const classified = classifyVerifiedSharedSnapshot(
|
|
3013
|
+
{ ...row, currentSnapshotId: unverified.snapshotId },
|
|
3014
|
+
verified.value,
|
|
3015
|
+
now
|
|
3016
|
+
);
|
|
3017
|
+
switch (classified.status) {
|
|
3018
|
+
case "missing":
|
|
3019
|
+
return { kind: "mark", entry: { name: row.name, reason: "missing", snapshotId: unverified.snapshotId } };
|
|
3020
|
+
case "expired":
|
|
3021
|
+
return { kind: "mark", entry: { name: row.name, reason: "expired", snapshotId: unverified.snapshotId } };
|
|
3022
|
+
case "ready":
|
|
3023
|
+
case "expires-soon":
|
|
3024
|
+
case "unknown-expiry":
|
|
3025
|
+
return { kind: "skip" };
|
|
3026
|
+
}
|
|
3027
|
+
}
|
|
3028
|
+
);
|
|
3029
|
+
if (aborted || isAborted(signal)) return { kind: "aborted" };
|
|
3030
|
+
const marked = [];
|
|
3031
|
+
const failed = [];
|
|
3032
|
+
let skipped = 0;
|
|
3033
|
+
for (const outcome of checked) {
|
|
3034
|
+
if (outcome === void 0) continue;
|
|
3035
|
+
switch (outcome.kind) {
|
|
3036
|
+
case "skip":
|
|
3037
|
+
skipped += 1;
|
|
3038
|
+
break;
|
|
3039
|
+
case "mark":
|
|
3040
|
+
marked.push(outcome.entry);
|
|
3041
|
+
break;
|
|
3042
|
+
case "failed":
|
|
3043
|
+
failed.push(outcome.failure);
|
|
3044
|
+
break;
|
|
3045
|
+
}
|
|
3046
|
+
}
|
|
3047
|
+
const deleted = [];
|
|
3048
|
+
if (dryRun) {
|
|
3049
|
+
deleted.push(...marked);
|
|
3050
|
+
} else {
|
|
3051
|
+
const deleteResults = await runLimited(
|
|
3052
|
+
marked.length,
|
|
3053
|
+
INDEX_CONCURRENCY,
|
|
3054
|
+
() => !aborted && !isAborted(signal),
|
|
3055
|
+
async (index) => {
|
|
3056
|
+
const entry = marked[index];
|
|
3057
|
+
const removed = await runnerSandboxes.deleteNamedSandbox(access, { name: entry.name }, signal);
|
|
3058
|
+
if (removed.ok) return { kind: "deleted", entry };
|
|
3059
|
+
if (removed.failure.kind === "aborted") {
|
|
3060
|
+
aborted = true;
|
|
3061
|
+
return void 0;
|
|
3062
|
+
}
|
|
3063
|
+
return { kind: "failed", failure: { name: entry.name, message: removed.failure.message } };
|
|
3064
|
+
}
|
|
3065
|
+
);
|
|
3066
|
+
if (aborted || isAborted(signal)) return { kind: "aborted" };
|
|
3067
|
+
for (const outcome of deleteResults) {
|
|
3068
|
+
if (outcome === void 0) continue;
|
|
3069
|
+
switch (outcome.kind) {
|
|
3070
|
+
case "deleted":
|
|
3071
|
+
deleted.push(outcome.entry);
|
|
3072
|
+
break;
|
|
3073
|
+
case "failed":
|
|
3074
|
+
failed.push(outcome.failure);
|
|
3075
|
+
break;
|
|
3076
|
+
}
|
|
3077
|
+
}
|
|
3078
|
+
}
|
|
3079
|
+
return {
|
|
3080
|
+
kind: "ok",
|
|
3081
|
+
summary: {
|
|
3082
|
+
scanned: validRows.length,
|
|
3083
|
+
deleted,
|
|
3084
|
+
skipped,
|
|
3085
|
+
failed,
|
|
3086
|
+
dryRun
|
|
3087
|
+
}
|
|
2024
3088
|
};
|
|
2025
3089
|
}
|
|
3090
|
+
function isAborted(signal) {
|
|
3091
|
+
return signal?.aborted === true;
|
|
3092
|
+
}
|
|
2026
3093
|
|
|
2027
3094
|
// src/runner/live/checkout-gateway.ts
|
|
2028
3095
|
import { execFile, spawn } from "node:child_process";
|
|
@@ -2045,9 +3112,9 @@ function partitionUntracked(entries) {
|
|
|
2045
3112
|
return { files, nestedRepositories };
|
|
2046
3113
|
}
|
|
2047
3114
|
function displayCommand(command, args) {
|
|
2048
|
-
return [command, ...args].map(
|
|
3115
|
+
return [command, ...args].map(shellQuote2).join(" ");
|
|
2049
3116
|
}
|
|
2050
|
-
function
|
|
3117
|
+
function shellQuote2(argument) {
|
|
2051
3118
|
return /^[\w@%+=:,./^{}-]+$/.test(argument) ? argument : `'${argument.replaceAll("'", `'\\''`)}'`;
|
|
2052
3119
|
}
|
|
2053
3120
|
|
|
@@ -2072,7 +3139,8 @@ function liveCheckoutGateway() {
|
|
|
2072
3139
|
readFileAt: ({ repoRoot, commit, path }) => readFileAt(repoRoot, commit, path),
|
|
2073
3140
|
submodules: ({ repoRoot }) => submodules(repoRoot),
|
|
2074
3141
|
assembleUpload: ({ repoRoot, base }) => assembleUpload(repoRoot, base),
|
|
2075
|
-
baseArchive: ({ repoRoot, base }) => baseArchive(repoRoot, base)
|
|
3142
|
+
baseArchive: ({ repoRoot, base }) => baseArchive(repoRoot, base),
|
|
3143
|
+
remoteUrl: ({ repoRoot, remote }) => remoteUrl(repoRoot, remote)
|
|
2076
3144
|
};
|
|
2077
3145
|
}
|
|
2078
3146
|
async function repositoryRoot(cwd) {
|
|
@@ -2173,6 +3241,10 @@ async function baseArchive(repoRoot, base) {
|
|
|
2173
3241
|
value: { tarball: tarball.stdout, fileList: fileList.stdout, files: splitNul(fileList.stdout).length }
|
|
2174
3242
|
};
|
|
2175
3243
|
}
|
|
3244
|
+
async function remoteUrl(repoRoot, remote) {
|
|
3245
|
+
const run = await git(repoRoot, ["remote", "get-url", "--", remote]);
|
|
3246
|
+
return run.ok ? { ok: true, value: run.stdout.toString("utf8").replace(/\r?\n$/, "") } : run;
|
|
3247
|
+
}
|
|
2176
3248
|
function git(repoRoot, args) {
|
|
2177
3249
|
const argv = ["-C", repoRoot, ...args];
|
|
2178
3250
|
return new Promise((resolve) => {
|
|
@@ -2236,6 +3308,86 @@ function createTarball(repoRoot, paths) {
|
|
|
2236
3308
|
});
|
|
2237
3309
|
}
|
|
2238
3310
|
|
|
3311
|
+
// src/runner/live/gh-token-gateway.ts
|
|
3312
|
+
import { execFile as execFile2 } from "node:child_process";
|
|
3313
|
+
|
|
3314
|
+
// src/runner/live/gh-output.ts
|
|
3315
|
+
function stripSingleTrailingLineBreak(stdout) {
|
|
3316
|
+
if (stdout.endsWith("\r\n")) return stdout.slice(0, -2);
|
|
3317
|
+
if (stdout.endsWith("\n")) return stdout.slice(0, -1);
|
|
3318
|
+
return stdout;
|
|
3319
|
+
}
|
|
3320
|
+
function classifyGhTokenError(info) {
|
|
3321
|
+
const { host, code, killed, stderr, timeoutMs } = info;
|
|
3322
|
+
if (code === "ENOENT") {
|
|
3323
|
+
return { kind: "not-installed", host, message: "gh CLI is not installed or not on PATH" };
|
|
3324
|
+
}
|
|
3325
|
+
if (killed || code === "ETIMEDOUT") {
|
|
3326
|
+
return { kind: "timed-out", host, message: `gh auth token --hostname ${host} timed out after ${timeoutMs}ms` };
|
|
3327
|
+
}
|
|
3328
|
+
if (NOT_AUTHENTICATED_PATTERN.test(stderr)) {
|
|
3329
|
+
return { kind: "not-authenticated", host, message: `gh is not authenticated for ${host}` };
|
|
3330
|
+
}
|
|
3331
|
+
return {
|
|
3332
|
+
kind: "failed",
|
|
3333
|
+
host,
|
|
3334
|
+
message: typeof code === "number" ? `gh auth token --hostname ${host} exited ${code}` : `gh auth token --hostname ${host} failed`
|
|
3335
|
+
};
|
|
3336
|
+
}
|
|
3337
|
+
var NOT_AUTHENTICATED_PATTERN = /not logged in|no oauth token|no token|gh auth login|authentication failed|to get started with github cli/i;
|
|
3338
|
+
|
|
3339
|
+
// src/runner/live/gh-token-gateway.ts
|
|
3340
|
+
var GH_TOKEN_TIMEOUT_MS = 1e4;
|
|
3341
|
+
var GH_MAX_BUFFER = 64 * 1024;
|
|
3342
|
+
function liveGhTokenGateway(options = {}) {
|
|
3343
|
+
const command = options.command ?? "gh";
|
|
3344
|
+
const timeoutMs = options.timeoutMs ?? GH_TOKEN_TIMEOUT_MS;
|
|
3345
|
+
const env = options.env;
|
|
3346
|
+
return {
|
|
3347
|
+
readToken: ({ host }) => new Promise((resolve) => {
|
|
3348
|
+
execFile2(
|
|
3349
|
+
command,
|
|
3350
|
+
["auth", "token", "--hostname", host],
|
|
3351
|
+
{
|
|
3352
|
+
encoding: "utf8",
|
|
3353
|
+
timeout: timeoutMs,
|
|
3354
|
+
maxBuffer: GH_MAX_BUFFER,
|
|
3355
|
+
...env === void 0 ? {} : { env: { ...env } }
|
|
3356
|
+
},
|
|
3357
|
+
(error, stdout, stderr) => {
|
|
3358
|
+
if (error === null) {
|
|
3359
|
+
const token = stripSingleTrailingLineBreak(stdout);
|
|
3360
|
+
if (token.length === 0) {
|
|
3361
|
+
resolve({
|
|
3362
|
+
ok: false,
|
|
3363
|
+
failure: {
|
|
3364
|
+
kind: "not-authenticated",
|
|
3365
|
+
host,
|
|
3366
|
+
message: `gh is not authenticated for ${host}`
|
|
3367
|
+
}
|
|
3368
|
+
});
|
|
3369
|
+
return;
|
|
3370
|
+
}
|
|
3371
|
+
resolve({ ok: true, token });
|
|
3372
|
+
return;
|
|
3373
|
+
}
|
|
3374
|
+
const err = error;
|
|
3375
|
+
resolve({
|
|
3376
|
+
ok: false,
|
|
3377
|
+
failure: classifyGhTokenError({
|
|
3378
|
+
host,
|
|
3379
|
+
code: err.code,
|
|
3380
|
+
killed: err.killed === true,
|
|
3381
|
+
stderr: typeof stderr === "string" ? stderr : "",
|
|
3382
|
+
timeoutMs
|
|
3383
|
+
})
|
|
3384
|
+
});
|
|
3385
|
+
}
|
|
3386
|
+
);
|
|
3387
|
+
})
|
|
3388
|
+
};
|
|
3389
|
+
}
|
|
3390
|
+
|
|
2239
3391
|
// src/runner/live/sandbox-errors.ts
|
|
2240
3392
|
function apiStatus(error) {
|
|
2241
3393
|
if (typeof error !== "object" || error === null) return void 0;
|
|
@@ -2247,6 +3399,9 @@ function apiStatus(error) {
|
|
|
2247
3399
|
function isAbortError(error) {
|
|
2248
3400
|
return typeof error === "object" && error !== null && error.name === "AbortError";
|
|
2249
3401
|
}
|
|
3402
|
+
function isNameTakenError(error, message) {
|
|
3403
|
+
return apiStatus(error) === 400 && /already exists/i.test(message);
|
|
3404
|
+
}
|
|
2250
3405
|
function sandboxFailure(error, signal) {
|
|
2251
3406
|
if (signal?.aborted === true || isAbortError(error)) return { kind: "aborted" };
|
|
2252
3407
|
return { kind: "api", status: apiStatus(error), message: error instanceof Error ? error.message : String(error) };
|
|
@@ -2256,7 +3411,9 @@ function sandboxFailure(error, signal) {
|
|
|
2256
3411
|
var TERMINATE_GRACE_MS = 1e4;
|
|
2257
3412
|
var KILL_GRACE_MS = 5e3;
|
|
2258
3413
|
var STDERR_MESSAGE_CHARS = 1e3;
|
|
3414
|
+
var NOT_FOUND_STATUS = 404;
|
|
2259
3415
|
var SNAPSHOT_GONE_STATUS = 410;
|
|
3416
|
+
var LIST_SANDBOXES_PAGE_LIMIT = 50;
|
|
2260
3417
|
var DROP_CAPABILITIES_ARGS = [
|
|
2261
3418
|
"--inh-caps=-all",
|
|
2262
3419
|
"--ambient-caps=-all",
|
|
@@ -2284,14 +3441,17 @@ function liveRunnerSandboxGateway() {
|
|
|
2284
3441
|
const { Sandbox } = await sdk();
|
|
2285
3442
|
const sandbox = await Sandbox.create({
|
|
2286
3443
|
...credentials(access),
|
|
2287
|
-
|
|
2288
|
-
|
|
3444
|
+
image: request2.image,
|
|
3445
|
+
...request2.name === void 0 ? {} : { name: request2.name },
|
|
2289
3446
|
...placement(request2),
|
|
2290
3447
|
...signal === void 0 ? {} : { signal }
|
|
2291
3448
|
});
|
|
2292
3449
|
return { ok: true, value: adopt(sandbox, "snapshot-build", request2.timeoutMs) };
|
|
2293
3450
|
} catch (error) {
|
|
2294
|
-
|
|
3451
|
+
const failure = sandboxFailure(error, signal);
|
|
3452
|
+
if (request2.name !== void 0 && failure.kind === "api" && isNameTakenError(error, failure.message))
|
|
3453
|
+
return { ok: false, failure: { kind: "name-taken", name: request2.name, message: failure.message } };
|
|
3454
|
+
return { ok: false, failure };
|
|
2295
3455
|
}
|
|
2296
3456
|
},
|
|
2297
3457
|
async startRunnerSandbox(access, request2, signal) {
|
|
@@ -2311,6 +3471,112 @@ function liveRunnerSandboxGateway() {
|
|
|
2311
3471
|
return { ok: false, failure };
|
|
2312
3472
|
}
|
|
2313
3473
|
},
|
|
3474
|
+
async getNamedSandbox(access, request2, signal) {
|
|
3475
|
+
if (isAborted2(signal)) return { ok: false, failure: { kind: "aborted" } };
|
|
3476
|
+
try {
|
|
3477
|
+
const { Sandbox } = await sdk();
|
|
3478
|
+
const sandbox = await Sandbox.get({
|
|
3479
|
+
...credentials(access),
|
|
3480
|
+
name: request2.name,
|
|
3481
|
+
...signal === void 0 ? {} : { signal }
|
|
3482
|
+
});
|
|
3483
|
+
return {
|
|
3484
|
+
ok: true,
|
|
3485
|
+
value: {
|
|
3486
|
+
kind: "found",
|
|
3487
|
+
sandbox: {
|
|
3488
|
+
name: sandbox.name,
|
|
3489
|
+
status: sandbox.status,
|
|
3490
|
+
currentSnapshotId: sandbox.currentSnapshotId,
|
|
3491
|
+
createdAt: sandbox.createdAt.toISOString(),
|
|
3492
|
+
tags: { ...sandbox.tags }
|
|
3493
|
+
}
|
|
3494
|
+
}
|
|
3495
|
+
};
|
|
3496
|
+
} catch (error) {
|
|
3497
|
+
const failure = sandboxFailure(error, signal);
|
|
3498
|
+
if (failure.kind === "api" && apiStatus(error) === NOT_FOUND_STATUS)
|
|
3499
|
+
return { ok: true, value: { kind: "not-found" } };
|
|
3500
|
+
return { ok: false, failure };
|
|
3501
|
+
}
|
|
3502
|
+
},
|
|
3503
|
+
async listNamedSandboxes(access, request2, signal) {
|
|
3504
|
+
if (isAborted2(signal)) return { ok: false, failure: { kind: "aborted" } };
|
|
3505
|
+
try {
|
|
3506
|
+
const { Sandbox } = await sdk();
|
|
3507
|
+
const paginator = await Sandbox.list({
|
|
3508
|
+
...credentials(access),
|
|
3509
|
+
namePrefix: request2.namePrefix,
|
|
3510
|
+
sortBy: "name",
|
|
3511
|
+
limit: LIST_SANDBOXES_PAGE_LIMIT,
|
|
3512
|
+
...signal === void 0 ? {} : { signal }
|
|
3513
|
+
});
|
|
3514
|
+
const listed = [];
|
|
3515
|
+
for await (const page of paginator.pages()) {
|
|
3516
|
+
if (isAborted2(signal)) return { ok: false, failure: { kind: "aborted" } };
|
|
3517
|
+
for (const item of page.sandboxes) {
|
|
3518
|
+
listed.push({
|
|
3519
|
+
name: item.name,
|
|
3520
|
+
status: item.status,
|
|
3521
|
+
currentSnapshotId: item.currentSnapshotId,
|
|
3522
|
+
createdAt: new Date(item.createdAt).toISOString(),
|
|
3523
|
+
tags: { ...item.tags }
|
|
3524
|
+
});
|
|
3525
|
+
}
|
|
3526
|
+
}
|
|
3527
|
+
return { ok: true, value: listed };
|
|
3528
|
+
} catch (error) {
|
|
3529
|
+
return { ok: false, failure: sandboxFailure(error, signal) };
|
|
3530
|
+
}
|
|
3531
|
+
},
|
|
3532
|
+
async getSnapshot(access, request2, signal) {
|
|
3533
|
+
if (isAborted2(signal)) return { ok: false, failure: { kind: "aborted" } };
|
|
3534
|
+
try {
|
|
3535
|
+
const { Snapshot } = await sdk();
|
|
3536
|
+
const snapshot = await Snapshot.get({
|
|
3537
|
+
...credentials(access),
|
|
3538
|
+
snapshotId: request2.snapshotId,
|
|
3539
|
+
...signal === void 0 ? {} : { signal }
|
|
3540
|
+
});
|
|
3541
|
+
return {
|
|
3542
|
+
ok: true,
|
|
3543
|
+
value: {
|
|
3544
|
+
kind: "found",
|
|
3545
|
+
snapshot: {
|
|
3546
|
+
snapshotId: snapshot.snapshotId,
|
|
3547
|
+
status: snapshot.status,
|
|
3548
|
+
createdAt: snapshot.createdAt.toISOString(),
|
|
3549
|
+
expiresAt: snapshot.expiresAt?.toISOString(),
|
|
3550
|
+
sizeBytes: snapshot.sizeBytes
|
|
3551
|
+
}
|
|
3552
|
+
}
|
|
3553
|
+
};
|
|
3554
|
+
} catch (error) {
|
|
3555
|
+
const failure = sandboxFailure(error, signal);
|
|
3556
|
+
const status = apiStatus(error);
|
|
3557
|
+
if (failure.kind === "api" && (status === NOT_FOUND_STATUS || status === SNAPSHOT_GONE_STATUS))
|
|
3558
|
+
return { ok: true, value: { kind: "not-found" } };
|
|
3559
|
+
return { ok: false, failure };
|
|
3560
|
+
}
|
|
3561
|
+
},
|
|
3562
|
+
async deleteNamedSandbox(access, request2, signal) {
|
|
3563
|
+
if (isAborted2(signal)) return { ok: false, failure: { kind: "aborted" } };
|
|
3564
|
+
try {
|
|
3565
|
+
const { Sandbox } = await sdk();
|
|
3566
|
+
const sandbox = await Sandbox.get({
|
|
3567
|
+
...credentials(access),
|
|
3568
|
+
name: request2.name,
|
|
3569
|
+
...signal === void 0 ? {} : { signal }
|
|
3570
|
+
});
|
|
3571
|
+
if (isAborted2(signal)) return { ok: false, failure: { kind: "aborted" } };
|
|
3572
|
+
await sandbox.delete({ deleteOrphanSnapshots: false, ...signal === void 0 ? {} : { signal } });
|
|
3573
|
+
return { ok: true };
|
|
3574
|
+
} catch (error) {
|
|
3575
|
+
const failure = sandboxFailure(error, signal);
|
|
3576
|
+
if (failure.kind === "api" && apiStatus(error) === NOT_FOUND_STATUS) return { ok: true };
|
|
3577
|
+
return { ok: false, failure };
|
|
3578
|
+
}
|
|
3579
|
+
},
|
|
2314
3580
|
async upload(sandbox, files, signal) {
|
|
2315
3581
|
const holder = holding(sandbox);
|
|
2316
3582
|
try {
|
|
@@ -2450,7 +3716,7 @@ function liveRunnerSandboxGateway() {
|
|
|
2450
3716
|
command.kill("SIGTERM").catch(() => {
|
|
2451
3717
|
});
|
|
2452
3718
|
};
|
|
2453
|
-
if (
|
|
3719
|
+
if (isAborted2(signal)) end();
|
|
2454
3720
|
else signal?.addEventListener("abort", end, { once: true });
|
|
2455
3721
|
let stderr = "";
|
|
2456
3722
|
try {
|
|
@@ -2524,7 +3790,7 @@ function liveRunnerSandboxGateway() {
|
|
|
2524
3790
|
holder.keeping = true;
|
|
2525
3791
|
if (!await settledUnlessAborted(holder.starting, signal)) return { ok: false, failure: { kind: "aborted" } };
|
|
2526
3792
|
const stillRunning = (await Promise.all([...holder.running].map((command) => endProcess(holder, command, signal)))).filter((ended) => !ended).length;
|
|
2527
|
-
if (
|
|
3793
|
+
if (isAborted2(signal)) return { ok: false, failure: { kind: "aborted" } };
|
|
2528
3794
|
if (stillRunning > 0)
|
|
2529
3795
|
return {
|
|
2530
3796
|
ok: false,
|
|
@@ -2546,7 +3812,7 @@ function liveRunnerSandboxGateway() {
|
|
|
2546
3812
|
},
|
|
2547
3813
|
async stop(sandbox, signal) {
|
|
2548
3814
|
const holder = holding(sandbox);
|
|
2549
|
-
if (
|
|
3815
|
+
if (isAborted2(signal)) return { ok: false, failure: { kind: "aborted" } };
|
|
2550
3816
|
try {
|
|
2551
3817
|
if (signal === void 0) await holder.sandbox.stop();
|
|
2552
3818
|
else await holder.sandbox.stop({ signal });
|
|
@@ -2557,7 +3823,7 @@ function liveRunnerSandboxGateway() {
|
|
|
2557
3823
|
},
|
|
2558
3824
|
async delete(sandbox, signal) {
|
|
2559
3825
|
const holder = holding(sandbox);
|
|
2560
|
-
if (
|
|
3826
|
+
if (isAborted2(signal)) return { ok: false, failure: { kind: "aborted" } };
|
|
2561
3827
|
try {
|
|
2562
3828
|
await holder.sandbox.delete({ deleteOrphanSnapshots: false, ...signal === void 0 ? {} : { signal } });
|
|
2563
3829
|
return { ok: true };
|
|
@@ -2577,9 +3843,17 @@ function placement(request2) {
|
|
|
2577
3843
|
timeout: request2.timeoutMs,
|
|
2578
3844
|
persistent: false,
|
|
2579
3845
|
tags: { ...request2.tags },
|
|
2580
|
-
networkPolicy: sdkNetworkPolicy(request2.networkPolicy)
|
|
3846
|
+
networkPolicy: sdkNetworkPolicy(request2.networkPolicy),
|
|
3847
|
+
...request2.managedCredentials !== void 0 && request2.managedCredentials.length > 0 ? { credentials: sdkManagedCredentials(request2.managedCredentials) } : {}
|
|
2581
3848
|
};
|
|
2582
3849
|
}
|
|
3850
|
+
function sdkManagedCredentials(providers) {
|
|
3851
|
+
const result = {};
|
|
3852
|
+
for (const provider of providers) {
|
|
3853
|
+
if (provider === "npm") result.npm = true;
|
|
3854
|
+
}
|
|
3855
|
+
return result;
|
|
3856
|
+
}
|
|
2583
3857
|
function sdkNetworkPolicy(policy) {
|
|
2584
3858
|
switch (policy.kind) {
|
|
2585
3859
|
case "allow-all":
|
|
@@ -2668,7 +3942,7 @@ async function endProcess(holder, command, signal) {
|
|
|
2668
3942
|
["SIGTERM", TERMINATE_GRACE_MS],
|
|
2669
3943
|
["SIGKILL", KILL_GRACE_MS]
|
|
2670
3944
|
]) {
|
|
2671
|
-
if (
|
|
3945
|
+
if (isAborted2(signal)) return false;
|
|
2672
3946
|
await withinLimit(graceMs, signal, (limit) => command.kill(kill, { abortSignal: limit })).catch(() => void 0);
|
|
2673
3947
|
if (await endsWithin(command, graceMs, signal)) {
|
|
2674
3948
|
holder.running.delete(command);
|
|
@@ -2686,7 +3960,7 @@ async function endsWithin(command, ms, signal) {
|
|
|
2686
3960
|
}
|
|
2687
3961
|
}
|
|
2688
3962
|
async function withinLimit(ms, signal, call) {
|
|
2689
|
-
if (
|
|
3963
|
+
if (isAborted2(signal)) throw new DOMException("This operation was aborted", "AbortError");
|
|
2690
3964
|
const limit = new AbortController();
|
|
2691
3965
|
const timer = setTimeout(() => limit.abort(), ms);
|
|
2692
3966
|
const onAbort = () => limit.abort();
|
|
@@ -2704,14 +3978,14 @@ async function withinLimit(ms, signal, call) {
|
|
|
2704
3978
|
}
|
|
2705
3979
|
}
|
|
2706
3980
|
async function settledUnlessAborted(tasks, signal) {
|
|
2707
|
-
if (
|
|
3981
|
+
if (isAborted2(signal)) return false;
|
|
2708
3982
|
if (signal === void 0 || tasks.size === 0) {
|
|
2709
3983
|
await Promise.allSettled(tasks);
|
|
2710
3984
|
return true;
|
|
2711
3985
|
}
|
|
2712
3986
|
return await untilAborted(Promise.allSettled(tasks), signal) !== ABORTED;
|
|
2713
3987
|
}
|
|
2714
|
-
function
|
|
3988
|
+
function isAborted2(signal) {
|
|
2715
3989
|
return signal?.aborted === true;
|
|
2716
3990
|
}
|
|
2717
3991
|
|
|
@@ -2758,22 +4032,22 @@ function liveRunnerTerminal(options) {
|
|
|
2758
4032
|
};
|
|
2759
4033
|
}
|
|
2760
4034
|
|
|
2761
|
-
// src/runner/live/snapshot-
|
|
4035
|
+
// src/runner/live/snapshot-index-gateway.ts
|
|
2762
4036
|
import { randomBytes } from "node:crypto";
|
|
2763
4037
|
import { mkdir, readdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
|
|
2764
4038
|
import { join } from "node:path";
|
|
2765
4039
|
|
|
2766
4040
|
// src/runner/live/snapshot-records.ts
|
|
2767
|
-
import { z as
|
|
2768
|
-
var isoTime =
|
|
2769
|
-
var nonEmpty =
|
|
2770
|
-
var entrySchema =
|
|
2771
|
-
version:
|
|
4041
|
+
import { z as z3 } from "zod";
|
|
4042
|
+
var isoTime = z3.string().refine((value) => !Number.isNaN(Date.parse(value)), { message: "not a time" });
|
|
4043
|
+
var nonEmpty = z3.string().min(1);
|
|
4044
|
+
var entrySchema = z3.object({
|
|
4045
|
+
version: z3.literal(2),
|
|
2772
4046
|
teamId: nonEmpty,
|
|
2773
4047
|
projectId: nonEmpty,
|
|
2774
4048
|
region: nonEmpty,
|
|
2775
|
-
|
|
2776
|
-
|
|
4049
|
+
image: nonEmpty,
|
|
4050
|
+
runnerName: nonEmpty,
|
|
2777
4051
|
snapshotKey: nonEmpty,
|
|
2778
4052
|
base: nonEmpty,
|
|
2779
4053
|
snapshotId: nonEmpty,
|
|
@@ -2788,7 +4062,7 @@ function parseSnapshotEntry(text) {
|
|
|
2788
4062
|
return { ok: false, reason: "not JSON" };
|
|
2789
4063
|
}
|
|
2790
4064
|
const version = typeof json === "object" && json !== null ? json.version : void 0;
|
|
2791
|
-
if (version !==
|
|
4065
|
+
if (version !== 2) return { ok: false, reason: `unknown version ${JSON.stringify(version) ?? "(none)"}` };
|
|
2792
4066
|
const parsed = entrySchema.safeParse(json);
|
|
2793
4067
|
if (!parsed.success) {
|
|
2794
4068
|
const issue = parsed.error.issues[0];
|
|
@@ -2799,15 +4073,15 @@ function parseSnapshotEntry(text) {
|
|
|
2799
4073
|
return { ok: true, value: entry };
|
|
2800
4074
|
}
|
|
2801
4075
|
function snapshotEntryText(entry) {
|
|
2802
|
-
const { teamId, projectId, region,
|
|
4076
|
+
const { teamId, projectId, region, image, runnerName, snapshotKey: snapshotKey2, base } = entry;
|
|
2803
4077
|
const { snapshotId, createdAt, expiresAt } = entry;
|
|
2804
4078
|
const record = {
|
|
2805
|
-
version:
|
|
4079
|
+
version: 2,
|
|
2806
4080
|
teamId,
|
|
2807
4081
|
projectId,
|
|
2808
4082
|
region,
|
|
2809
|
-
|
|
2810
|
-
|
|
4083
|
+
image,
|
|
4084
|
+
runnerName,
|
|
2811
4085
|
snapshotKey: snapshotKey2,
|
|
2812
4086
|
base,
|
|
2813
4087
|
snapshotId,
|
|
@@ -2818,11 +4092,11 @@ function snapshotEntryText(entry) {
|
|
|
2818
4092
|
`;
|
|
2819
4093
|
}
|
|
2820
4094
|
|
|
2821
|
-
// src/runner/live/snapshot-
|
|
4095
|
+
// src/runner/live/snapshot-index-gateway.ts
|
|
2822
4096
|
var DIRECTORY_MODE = 448;
|
|
2823
4097
|
var FILE_MODE = 384;
|
|
2824
4098
|
var ENTRY_FILE_NAME = /^[0-9a-f]{32}\.json$/;
|
|
2825
|
-
function
|
|
4099
|
+
function liveRunnerSnapshotIndexGateway(options) {
|
|
2826
4100
|
const { directory } = options;
|
|
2827
4101
|
return {
|
|
2828
4102
|
listEntries: () => listEntries(directory),
|
|
@@ -2830,7 +4104,7 @@ function liveRunnerSnapshotCacheGateway(options) {
|
|
|
2830
4104
|
removeEntry: (entry) => removeEntry(directory, entry)
|
|
2831
4105
|
};
|
|
2832
4106
|
}
|
|
2833
|
-
function
|
|
4107
|
+
function unavailableRunnerSnapshotIndexGateway(location, reason) {
|
|
2834
4108
|
const failure = { path: location, message: reason };
|
|
2835
4109
|
const fail = async () => ({ ok: false, failure });
|
|
2836
4110
|
return { listEntries: fail, writeEntry: fail, removeEntry: fail };
|
|
@@ -2903,37 +4177,45 @@ function failureAt(path, error) {
|
|
|
2903
4177
|
// src/runner/prepare.ts
|
|
2904
4178
|
async function prepareRunner(context, request2) {
|
|
2905
4179
|
const { checkout } = context;
|
|
2906
|
-
const {
|
|
4180
|
+
const { options } = request2;
|
|
2907
4181
|
const root = await checkout.repositoryRoot({ cwd: request2.cwd });
|
|
2908
4182
|
if (!root.ok) return { kind: "checkout-failed", failure: root.failure };
|
|
2909
4183
|
const repoRoot = root.value;
|
|
2910
|
-
const resolved = await resolveBase(checkout, { repoRoot, baseRefs:
|
|
4184
|
+
const resolved = await resolveBase(checkout, { repoRoot, baseRefs: options.baseRefs });
|
|
2911
4185
|
if (resolved.kind === "failed") return { kind: "checkout-failed", failure: resolved.failure };
|
|
2912
4186
|
if (resolved.kind === "no-base-ref") return resolved;
|
|
2913
4187
|
const { base } = resolved;
|
|
2914
4188
|
const submodules2 = await checkout.submodules({ repoRoot });
|
|
2915
4189
|
if (!submodules2.ok) return { kind: "checkout-failed", failure: submodules2.failure };
|
|
2916
4190
|
if (submodules2.value.length > 0) return { kind: "submodules", paths: [...submodules2.value] };
|
|
2917
|
-
const inputs = await snapshotInputsAt(checkout, { repoRoot, base,
|
|
2918
|
-
if (!inputs.ok) return { kind: "invalid-
|
|
2919
|
-
const vcpus = resolveVcpus(
|
|
2920
|
-
if (!vcpus.ok) return { kind: "invalid-
|
|
4191
|
+
const inputs = await snapshotInputsAt(checkout, { repoRoot, base, options });
|
|
4192
|
+
if (!inputs.ok) return { kind: "invalid-runner", path: inputs.path, problem: inputs.problem };
|
|
4193
|
+
const vcpus = resolveVcpus(options, request2.vcpuRun);
|
|
4194
|
+
if (!vcpus.ok) return { kind: "invalid-runner", path: ["vcpus"], problem: vcpus.problem };
|
|
2921
4195
|
const upload = await checkout.assembleUpload({ repoRoot, base });
|
|
2922
4196
|
if (!upload.ok) return { kind: "checkout-failed", failure: upload.failure };
|
|
2923
4197
|
const afterBase = await checkout.commitCount({ repoRoot, from: base, to: "HEAD" });
|
|
2924
4198
|
if (!afterBase.ok) return { kind: "checkout-failed", failure: afterBase.failure };
|
|
2925
4199
|
const listing = await removeExpiredEntries(context);
|
|
4200
|
+
const ancestorDistances = await resolveAncestorDistances(context, {
|
|
4201
|
+
repoRoot,
|
|
4202
|
+
entries: listing.entries,
|
|
4203
|
+
options,
|
|
4204
|
+
mergeBase: base
|
|
4205
|
+
});
|
|
4206
|
+
if (!ancestorDistances.ok) return { kind: "checkout-failed", failure: ancestorDistances.failure };
|
|
2926
4207
|
const cache = classifySnapshotEntries(context, {
|
|
2927
4208
|
entries: listing.entries,
|
|
2928
|
-
|
|
4209
|
+
options,
|
|
2929
4210
|
base,
|
|
2930
4211
|
snapshotKey: inputs.key,
|
|
2931
|
-
commitsAfterBase: afterBase.value
|
|
4212
|
+
commitsAfterBase: afterBase.value,
|
|
4213
|
+
ancestorDistances: ancestorDistances.value
|
|
2932
4214
|
});
|
|
2933
4215
|
return {
|
|
2934
4216
|
kind: "ok",
|
|
2935
4217
|
prepared: {
|
|
2936
|
-
|
|
4218
|
+
options,
|
|
2937
4219
|
repoRoot,
|
|
2938
4220
|
base,
|
|
2939
4221
|
baseRef: resolved.ref,
|
|
@@ -2951,6 +4233,133 @@ async function prepareRunner(context, request2) {
|
|
|
2951
4233
|
|
|
2952
4234
|
// src/runner/ready.ts
|
|
2953
4235
|
import { posix } from "node:path";
|
|
4236
|
+
|
|
4237
|
+
// src/runner/shared-snapshot-lookup.ts
|
|
4238
|
+
async function lookupSharedSnapshot(context, request2, signal) {
|
|
4239
|
+
const { runnerSandboxes, checkout, clock } = context;
|
|
4240
|
+
const { access, repoRoot, runner, snapshotKey: snapshotKey2, mergeBase, maxCommitsBehindMergeBase } = request2;
|
|
4241
|
+
if (!sharedBeatsLocal(0, maxCommitsBehindMergeBase)) return { kind: "miss" };
|
|
4242
|
+
const bucket = sharedSnapshotBucket({
|
|
4243
|
+
teamId: access.teamId,
|
|
4244
|
+
projectId: access.projectId,
|
|
4245
|
+
region: runner.region,
|
|
4246
|
+
image: runner.image,
|
|
4247
|
+
runnerName: runner.name,
|
|
4248
|
+
snapshotKey: snapshotKey2
|
|
4249
|
+
});
|
|
4250
|
+
const exactName = sharedSnapshotSandboxName(bucket, mergeBase);
|
|
4251
|
+
const exact = await runnerSandboxes.getNamedSandbox(access, { name: exactName }, signal);
|
|
4252
|
+
if (!exact.ok) {
|
|
4253
|
+
return unavailable(exact.failure);
|
|
4254
|
+
}
|
|
4255
|
+
if (exact.value.kind === "found") {
|
|
4256
|
+
const { sandbox } = exact.value;
|
|
4257
|
+
const unverified = classifyUnverifiedSharedSandbox(sandbox);
|
|
4258
|
+
if (unverified.kind === "needs-snapshot") {
|
|
4259
|
+
const verified = await runnerSandboxes.getSnapshot(access, { snapshotId: unverified.snapshotId }, signal);
|
|
4260
|
+
if (!verified.ok) {
|
|
4261
|
+
return unavailable(verified.failure);
|
|
4262
|
+
}
|
|
4263
|
+
if (verified.value.kind === "found") {
|
|
4264
|
+
const entry = usableSharedEntry(
|
|
4265
|
+
access,
|
|
4266
|
+
runner,
|
|
4267
|
+
snapshotKey2,
|
|
4268
|
+
mergeBase,
|
|
4269
|
+
sandbox,
|
|
4270
|
+
verified.value.snapshot,
|
|
4271
|
+
clock.now()
|
|
4272
|
+
);
|
|
4273
|
+
if (entry !== null) {
|
|
4274
|
+
return { kind: "hit", entry, commitsBehindMergeBase: 0, sandboxName: sandbox.name };
|
|
4275
|
+
}
|
|
4276
|
+
}
|
|
4277
|
+
}
|
|
4278
|
+
}
|
|
4279
|
+
if (!sharedBeatsLocal(1, maxCommitsBehindMergeBase)) return { kind: "miss" };
|
|
4280
|
+
const listed = await runnerSandboxes.listNamedSandboxes(
|
|
4281
|
+
access,
|
|
4282
|
+
{ namePrefix: sharedSnapshotSandboxPrefix(bucket) },
|
|
4283
|
+
signal
|
|
4284
|
+
);
|
|
4285
|
+
if (!listed.ok) {
|
|
4286
|
+
return unavailable(listed.failure);
|
|
4287
|
+
}
|
|
4288
|
+
const stoppedRows = [];
|
|
4289
|
+
for (const row of listed.value) {
|
|
4290
|
+
const unverified = classifyUnverifiedSharedSandbox(row);
|
|
4291
|
+
if (unverified.kind !== "needs-snapshot") continue;
|
|
4292
|
+
const parsed = parseSharedSnapshotSandboxName(row.name);
|
|
4293
|
+
if (parsed === null || parsed.bucket !== bucket || parsed.base === mergeBase) continue;
|
|
4294
|
+
stoppedRows.push({ row, base: parsed.base, snapshotId: unverified.snapshotId });
|
|
4295
|
+
}
|
|
4296
|
+
const checked = await runLimited(
|
|
4297
|
+
stoppedRows.length,
|
|
4298
|
+
INDEX_CONCURRENCY,
|
|
4299
|
+
() => signal?.aborted !== true,
|
|
4300
|
+
async (index) => {
|
|
4301
|
+
const item = stoppedRows[index];
|
|
4302
|
+
const ancestor = await checkout.contains({ repoRoot, ancestor: item.base, descendant: mergeBase });
|
|
4303
|
+
if (!ancestor.ok || !ancestor.value) return null;
|
|
4304
|
+
if (signal?.aborted === true) return null;
|
|
4305
|
+
const counted = await checkout.commitCount({ repoRoot, from: item.base, to: mergeBase });
|
|
4306
|
+
if (!counted.ok) return null;
|
|
4307
|
+
if (!sharedBeatsLocal(counted.value, maxCommitsBehindMergeBase)) return null;
|
|
4308
|
+
return {
|
|
4309
|
+
row: item.row,
|
|
4310
|
+
base: item.base,
|
|
4311
|
+
snapshotId: item.snapshotId,
|
|
4312
|
+
commitsBehindMergeBase: counted.value
|
|
4313
|
+
};
|
|
4314
|
+
}
|
|
4315
|
+
);
|
|
4316
|
+
if (signal?.aborted === true) return { kind: "aborted" };
|
|
4317
|
+
const candidates = checked.filter((candidate) => candidate != null);
|
|
4318
|
+
candidates.sort(
|
|
4319
|
+
(a, b) => compareSnapshotCandidates(
|
|
4320
|
+
{
|
|
4321
|
+
commitsBehindMergeBase: a.commitsBehindMergeBase,
|
|
4322
|
+
createdAt: a.row.createdAt,
|
|
4323
|
+
tieBreaker: a.row.name
|
|
4324
|
+
},
|
|
4325
|
+
{
|
|
4326
|
+
commitsBehindMergeBase: b.commitsBehindMergeBase,
|
|
4327
|
+
createdAt: b.row.createdAt,
|
|
4328
|
+
tieBreaker: b.row.name
|
|
4329
|
+
}
|
|
4330
|
+
)
|
|
4331
|
+
);
|
|
4332
|
+
for (const candidate of candidates) {
|
|
4333
|
+
const verified = await runnerSandboxes.getSnapshot(access, { snapshotId: candidate.snapshotId }, signal);
|
|
4334
|
+
if (!verified.ok) {
|
|
4335
|
+
return unavailable(verified.failure);
|
|
4336
|
+
}
|
|
4337
|
+
if (verified.value.kind !== "found") continue;
|
|
4338
|
+
const entry = usableSharedEntry(
|
|
4339
|
+
access,
|
|
4340
|
+
runner,
|
|
4341
|
+
snapshotKey2,
|
|
4342
|
+
candidate.base,
|
|
4343
|
+
candidate.row,
|
|
4344
|
+
verified.value.snapshot,
|
|
4345
|
+
clock.now()
|
|
4346
|
+
);
|
|
4347
|
+
if (entry !== null) {
|
|
4348
|
+
return {
|
|
4349
|
+
kind: "hit",
|
|
4350
|
+
entry,
|
|
4351
|
+
commitsBehindMergeBase: candidate.commitsBehindMergeBase,
|
|
4352
|
+
sandboxName: candidate.row.name
|
|
4353
|
+
};
|
|
4354
|
+
}
|
|
4355
|
+
}
|
|
4356
|
+
return { kind: "miss" };
|
|
4357
|
+
}
|
|
4358
|
+
function unavailable(failure) {
|
|
4359
|
+
return failure.kind === "aborted" ? { kind: "aborted" } : { kind: "unavailable", message: failure.message };
|
|
4360
|
+
}
|
|
4361
|
+
|
|
4362
|
+
// src/runner/ready.ts
|
|
2954
4363
|
var APPLY_LABEL = "Applying your changes";
|
|
2955
4364
|
async function readyRunner(context, request2, control, progress) {
|
|
2956
4365
|
const chosen = await chooseSnapshot(context, request2, control, progress);
|
|
@@ -2959,17 +4368,62 @@ async function readyRunner(context, request2, control, progress) {
|
|
|
2959
4368
|
}
|
|
2960
4369
|
async function chooseSnapshot(context, request2, control, progress) {
|
|
2961
4370
|
const { prepared, access } = request2;
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
4371
|
+
const { signal } = control;
|
|
4372
|
+
if (signal.aborted) return { kind: "aborted" };
|
|
4373
|
+
const localCandidate = pickSnapshot(prepared.candidates, access);
|
|
4374
|
+
if (localCandidate !== void 0 && localCandidate.commitsBehindMergeBase === 0) {
|
|
4375
|
+
const { entry, builtBehind } = localCandidate;
|
|
4376
|
+
await progress.emit({
|
|
4377
|
+
kind: "snapshot-reused",
|
|
4378
|
+
snapshotId: entry.snapshotId,
|
|
4379
|
+
base: entry.base,
|
|
4380
|
+
builtBehind,
|
|
4381
|
+
source: "local"
|
|
4382
|
+
});
|
|
4383
|
+
return { kind: "ok", value: { entry, built: false, builtBehind, upload: prepared.upload } };
|
|
4384
|
+
}
|
|
4385
|
+
const shared = await lookupSharedSnapshot(
|
|
4386
|
+
context,
|
|
4387
|
+
{
|
|
4388
|
+
access,
|
|
4389
|
+
repoRoot: prepared.repoRoot,
|
|
4390
|
+
runner: prepared.options,
|
|
4391
|
+
snapshotKey: prepared.snapshotKey,
|
|
4392
|
+
mergeBase: prepared.base,
|
|
4393
|
+
...localCandidate === void 0 ? {} : { maxCommitsBehindMergeBase: localCandidate.commitsBehindMergeBase }
|
|
4394
|
+
},
|
|
4395
|
+
signal
|
|
4396
|
+
);
|
|
4397
|
+
if (shared.kind === "aborted") return { kind: "aborted" };
|
|
4398
|
+
if (shared.kind === "unavailable") {
|
|
4399
|
+
await progress.emit({ kind: "shared-snapshot-lookup-failed", message: shared.message });
|
|
4400
|
+
}
|
|
4401
|
+
const sharedHit = shared.kind === "hit" ? shared : void 0;
|
|
4402
|
+
const useShared = sharedHit !== void 0 && sharedBeatsLocal(sharedHit.commitsBehindMergeBase, localCandidate?.commitsBehindMergeBase);
|
|
4403
|
+
const winner = useShared ? { source: "shared", hit: sharedHit } : localCandidate !== void 0 ? { source: "local", candidate: localCandidate } : void 0;
|
|
4404
|
+
if (winner !== void 0) {
|
|
4405
|
+
let entry;
|
|
4406
|
+
let builtBehind;
|
|
4407
|
+
if (winner.source === "shared") {
|
|
4408
|
+
entry = winner.hit.entry;
|
|
4409
|
+
const written = await context.runnerSnapshots.writeEntry(entry);
|
|
4410
|
+
if (!written.ok) await progress.emit({ kind: "snapshot-entry-not-written", failure: written.failure });
|
|
4411
|
+
builtBehind = prepared.commitsAfterBase + winner.hit.commitsBehindMergeBase;
|
|
4412
|
+
} else {
|
|
4413
|
+
entry = winner.candidate.entry;
|
|
4414
|
+
builtBehind = winner.candidate.builtBehind;
|
|
4415
|
+
}
|
|
4416
|
+
const upload = await uploadForBase(context, prepared, entry.base);
|
|
4417
|
+
if (!upload.ok) return { kind: "failed", failure: { kind: "checkout-failed", failure: upload.failure } };
|
|
4418
|
+
if (signal.aborted) return { kind: "aborted" };
|
|
2966
4419
|
await progress.emit({
|
|
2967
4420
|
kind: "snapshot-reused",
|
|
2968
4421
|
snapshotId: entry.snapshotId,
|
|
2969
4422
|
base: entry.base,
|
|
2970
|
-
builtBehind
|
|
4423
|
+
builtBehind,
|
|
4424
|
+
source: winner.source
|
|
2971
4425
|
});
|
|
2972
|
-
return { kind: "ok", value: { entry, built: false } };
|
|
4426
|
+
return { kind: "ok", value: { entry, built: false, builtBehind, upload: upload.value } };
|
|
2973
4427
|
}
|
|
2974
4428
|
const why = { kind: "no-snapshot", rejected: snapshotRejections(prepared, access) };
|
|
2975
4429
|
const building = await buildSnapshot(
|
|
@@ -2979,12 +4433,24 @@ async function chooseSnapshot(context, request2, control, progress) {
|
|
|
2979
4433
|
progress
|
|
2980
4434
|
);
|
|
2981
4435
|
if (building.kind !== "ok") return building;
|
|
2982
|
-
return {
|
|
4436
|
+
return {
|
|
4437
|
+
kind: "ok",
|
|
4438
|
+
value: {
|
|
4439
|
+
entry: building.value.entry,
|
|
4440
|
+
built: true,
|
|
4441
|
+
builtBehind: prepared.commitsAfterBase,
|
|
4442
|
+
upload: prepared.upload
|
|
4443
|
+
}
|
|
4444
|
+
};
|
|
4445
|
+
}
|
|
4446
|
+
async function uploadForBase(context, prepared, base) {
|
|
4447
|
+
if (base === prepared.base) return { ok: true, value: prepared.upload };
|
|
4448
|
+
return await context.checkout.assembleUpload({ repoRoot: prepared.repoRoot, base });
|
|
2983
4449
|
}
|
|
2984
4450
|
async function readyFromSnapshot(context, request2, control, progress) {
|
|
2985
4451
|
const { prepared, access } = request2;
|
|
2986
|
-
const { entry, built } = request2.snapshot;
|
|
2987
|
-
const {
|
|
4452
|
+
const { entry, built, builtBehind, upload } = request2.snapshot;
|
|
4453
|
+
const { options, repoRoot } = prepared;
|
|
2988
4454
|
const { scope, signal } = control;
|
|
2989
4455
|
const now = () => context.clock.now().getTime();
|
|
2990
4456
|
if (signal.aborted) return { kind: "aborted" };
|
|
@@ -2992,10 +4458,10 @@ async function readyFromSnapshot(context, request2, control, progress) {
|
|
|
2992
4458
|
const startedAt = now();
|
|
2993
4459
|
const started = await scope.startRunnerSandbox(access, {
|
|
2994
4460
|
snapshotId: entry.snapshotId,
|
|
2995
|
-
region:
|
|
4461
|
+
region: options.region,
|
|
2996
4462
|
vcpus: prepared.vcpus,
|
|
2997
|
-
timeoutMs:
|
|
2998
|
-
tags: runnerTags(
|
|
4463
|
+
timeoutMs: options.timeoutMinutes * 6e4,
|
|
4464
|
+
tags: runnerTags(options.name, "runner", request2.user)
|
|
2999
4465
|
});
|
|
3000
4466
|
if (!started.ok) {
|
|
3001
4467
|
if (started.failure.kind === "snapshot-gone") {
|
|
@@ -3009,11 +4475,11 @@ async function readyFromSnapshot(context, request2, control, progress) {
|
|
|
3009
4475
|
kind: "sandbox-started",
|
|
3010
4476
|
role: "runner",
|
|
3011
4477
|
name: sandbox.name,
|
|
3012
|
-
region:
|
|
4478
|
+
region: options.region,
|
|
3013
4479
|
vcpus: prepared.vcpus,
|
|
3014
4480
|
ms: now() - startedAt
|
|
3015
4481
|
});
|
|
3016
|
-
const changes = await uploadChanges(context, {
|
|
4482
|
+
const changes = await uploadChanges(context, { upload, sandbox }, signal, progress);
|
|
3017
4483
|
if (changes.kind !== "ok") return changes;
|
|
3018
4484
|
const applied = await stage(
|
|
3019
4485
|
context,
|
|
@@ -3021,7 +4487,7 @@ async function readyFromSnapshot(context, request2, control, progress) {
|
|
|
3021
4487
|
sandbox,
|
|
3022
4488
|
phase: "apply",
|
|
3023
4489
|
step: { label: APPLY_LABEL, script: applyScript(changes.value.directory) },
|
|
3024
|
-
region:
|
|
4490
|
+
region: options.region
|
|
3025
4491
|
},
|
|
3026
4492
|
signal,
|
|
3027
4493
|
progress
|
|
@@ -3035,14 +4501,14 @@ async function readyFromSnapshot(context, request2, control, progress) {
|
|
|
3035
4501
|
}
|
|
3036
4502
|
const installed = await stage(
|
|
3037
4503
|
context,
|
|
3038
|
-
{ sandbox, phase: "install", step:
|
|
4504
|
+
{ sandbox, phase: "install", step: options.run.install, region: options.region },
|
|
3039
4505
|
signal,
|
|
3040
4506
|
progress
|
|
3041
4507
|
);
|
|
3042
4508
|
if (installed.kind !== "ok") return installed;
|
|
3043
4509
|
const builtOutputs = await stage(
|
|
3044
4510
|
context,
|
|
3045
|
-
{ sandbox, phase: "build", step:
|
|
4511
|
+
{ sandbox, phase: "build", step: options.run.build, region: options.region },
|
|
3046
4512
|
signal,
|
|
3047
4513
|
progress
|
|
3048
4514
|
);
|
|
@@ -3054,15 +4520,15 @@ async function readyFromSnapshot(context, request2, control, progress) {
|
|
|
3054
4520
|
snapshotId: entry.snapshotId,
|
|
3055
4521
|
base: entry.base,
|
|
3056
4522
|
built,
|
|
3057
|
-
builtBehind
|
|
4523
|
+
builtBehind,
|
|
3058
4524
|
uploadBytes: changes.value.bytes,
|
|
3059
4525
|
buildMs: builtOutputs.value,
|
|
3060
4526
|
vcpus: prepared.vcpus,
|
|
3061
|
-
region:
|
|
3062
|
-
|
|
4527
|
+
region: options.region,
|
|
4528
|
+
image: options.image,
|
|
3063
4529
|
repoRoot,
|
|
3064
|
-
cwd: posix.join(SANDBOX_ROOT,
|
|
3065
|
-
env:
|
|
4530
|
+
cwd: posix.join(SANDBOX_ROOT, options.cwd),
|
|
4531
|
+
env: options.env,
|
|
3066
4532
|
loginPath: loginPath.value
|
|
3067
4533
|
}
|
|
3068
4534
|
};
|
|
@@ -3070,7 +4536,7 @@ async function readyFromSnapshot(context, request2, control, progress) {
|
|
|
3070
4536
|
async function uploadChanges(context, request2, signal, progress) {
|
|
3071
4537
|
await progress.emit({ kind: "uploading" });
|
|
3072
4538
|
const startedAt = context.clock.now().getTime();
|
|
3073
|
-
const files = stagedChanges(request2.
|
|
4539
|
+
const files = stagedChanges(request2.upload);
|
|
3074
4540
|
const staged = await context.runnerSandboxes.upload(request2.sandbox, files, signal);
|
|
3075
4541
|
if (!staged.ok) return sandboxStop("upload", staged.failure);
|
|
3076
4542
|
const bytes = files.reduce((sum, file) => sum + file.content.byteLength, 0);
|
|
@@ -3114,7 +4580,8 @@ async function chooseSnapshotForRun(context, request2, control, progress) {
|
|
|
3114
4580
|
const stageSignal = stop === void 0 ? signal : AbortSignal.any([signal, stop]);
|
|
3115
4581
|
const scope = runnerSandboxScope(context, progress, {
|
|
3116
4582
|
keepMs: 0,
|
|
3117
|
-
basePolicy: runnerNetworkPolicy(request2.prepared.
|
|
4583
|
+
basePolicy: runnerNetworkPolicy(request2.prepared.options),
|
|
4584
|
+
managedCredentials: request2.prepared.options.managedCredentials,
|
|
3118
4585
|
signal
|
|
3119
4586
|
});
|
|
3120
4587
|
try {
|
|
@@ -3257,10 +4724,13 @@ function openRunnerSession(context, request2, control, progress) {
|
|
|
3257
4724
|
const hasUnsafeSecretEnvVars = Object.keys(unsafeSecretEnvVars).length > 0;
|
|
3258
4725
|
if (hasUnsafeSecretEnvVars && request2.keepMs > 0)
|
|
3259
4726
|
throw new Error("a runner session with unsafeSecretEnvVars can't keep its runner sandbox");
|
|
4727
|
+
if (request2.prepared.options.managedCredentials.length > 0 && request2.keepMs > 0)
|
|
4728
|
+
throw new Error("a runner session with managedCredentials can't keep its runner sandbox");
|
|
3260
4729
|
let commandRunning = false;
|
|
3261
4730
|
const scope = runnerSandboxScope(context, progress, {
|
|
3262
4731
|
keepMs: request2.keepMs,
|
|
3263
|
-
basePolicy: runnerNetworkPolicy(request2.prepared.
|
|
4732
|
+
basePolicy: runnerNetworkPolicy(request2.prepared.options),
|
|
4733
|
+
managedCredentials: request2.prepared.options.managedCredentials,
|
|
3264
4734
|
signal,
|
|
3265
4735
|
commandRunning: () => commandRunning
|
|
3266
4736
|
});
|
|
@@ -3366,11 +4836,11 @@ function checkRunner(value, inherited, definitions = []) {
|
|
|
3366
4836
|
...inherited,
|
|
3367
4837
|
...Object.fromEntries(Object.entries(options).filter(([, entry]) => entry !== void 0))
|
|
3368
4838
|
};
|
|
3369
|
-
const checked =
|
|
4839
|
+
const checked = checkVercelSandboxOptions(rawOptions);
|
|
3370
4840
|
if (!checked.ok) return checked;
|
|
3371
4841
|
const vcpusProblems = checkVcpusRuleDefinitions(checked.value.vcpus, definitions);
|
|
3372
4842
|
if (vcpusProblems.length > 0) return { ok: false, problems: vcpusProblems };
|
|
3373
|
-
return { ok: true, value: { kind: "vercel-sandbox",
|
|
4843
|
+
return { ok: true, value: { kind: "vercel-sandbox", options: checked.value } };
|
|
3374
4844
|
}
|
|
3375
4845
|
return { ok: false, problems: [{ path: [], problem: `${FACTORY_HINT}, not ${describeValue(value)}` }] };
|
|
3376
4846
|
}
|
|
@@ -3797,14 +5267,14 @@ function fileProblem(problem) {
|
|
|
3797
5267
|
}
|
|
3798
5268
|
|
|
3799
5269
|
// src/config/errors.ts
|
|
3800
|
-
import { z as
|
|
3801
|
-
var problemSchema =
|
|
5270
|
+
import { z as z4 } from "zod";
|
|
5271
|
+
var problemSchema = z4.object({
|
|
3802
5272
|
/** The key the problem is about; null when it is about the whole file. */
|
|
3803
|
-
key:
|
|
5273
|
+
key: z4.string().nullable(),
|
|
3804
5274
|
/** Where Node said the import failed; null otherwise. */
|
|
3805
|
-
location:
|
|
5275
|
+
location: z4.object({ line: z4.number(), column: z4.number().nullable() }).nullable(),
|
|
3806
5276
|
/** What is wrong, worded to follow the key, or the file name when there is no key. */
|
|
3807
|
-
problem:
|
|
5277
|
+
problem: z4.string()
|
|
3808
5278
|
});
|
|
3809
5279
|
function configProblemLine(file, { key, location, problem }) {
|
|
3810
5280
|
const sentence = `${problem.replace(/\.$/, "")}.`;
|
|
@@ -3813,21 +5283,21 @@ function configProblemLine(file, { key, location, problem }) {
|
|
|
3813
5283
|
return `${file}:${location.line}${location.column === null ? "" : `:${location.column}`} ${sentence}`;
|
|
3814
5284
|
return `${file}: ${sentence}`;
|
|
3815
5285
|
}
|
|
3816
|
-
var optionValueSchema =
|
|
5286
|
+
var optionValueSchema = z4.object({
|
|
3817
5287
|
/** The option's key path, such as resources.<key>.ttl. */
|
|
3818
|
-
key:
|
|
5288
|
+
key: z4.string(),
|
|
3819
5289
|
/** Its value, as text. */
|
|
3820
|
-
value:
|
|
5290
|
+
value: z4.string(),
|
|
3821
5291
|
/** Where it came from: the command's own flag for the option, the config file or the default. */
|
|
3822
|
-
source:
|
|
5292
|
+
source: z4.enum(["flag", "file", "default"])
|
|
3823
5293
|
});
|
|
3824
|
-
var optionProblemSchema =
|
|
5294
|
+
var optionProblemSchema = z4.object({
|
|
3825
5295
|
/** The key path of the option the problem is about, such as resources.<key>.ttl. */
|
|
3826
|
-
key:
|
|
5296
|
+
key: z4.string(),
|
|
3827
5297
|
/** What is wrong, worded to follow the key path, as the resource's rule words it. */
|
|
3828
|
-
problem:
|
|
5298
|
+
problem: z4.string(),
|
|
3829
5299
|
/** Each value the problem is about, with its source; empty for a required option nothing gave. */
|
|
3830
|
-
values:
|
|
5300
|
+
values: z4.array(optionValueSchema)
|
|
3831
5301
|
});
|
|
3832
5302
|
function optionValueText({ key, value, source }, configFile) {
|
|
3833
5303
|
switch (source) {
|
|
@@ -3848,10 +5318,10 @@ var configErrors = defineErrors({
|
|
|
3848
5318
|
invalidConfig: {
|
|
3849
5319
|
exitCode: 2,
|
|
3850
5320
|
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.",
|
|
3851
|
-
schema:
|
|
5321
|
+
schema: z4.object({
|
|
3852
5322
|
/** The config file's absolute path. */
|
|
3853
|
-
file:
|
|
3854
|
-
problems:
|
|
5323
|
+
file: z4.string(),
|
|
5324
|
+
problems: z4.array(problemSchema)
|
|
3855
5325
|
}),
|
|
3856
5326
|
render: ({ file, problems }) => {
|
|
3857
5327
|
const [first, ...rest] = problems;
|
|
@@ -3865,10 +5335,10 @@ var configErrors = defineErrors({
|
|
|
3865
5335
|
invalidResourceOptions: {
|
|
3866
5336
|
exitCode: 2,
|
|
3867
5337
|
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.",
|
|
3868
|
-
schema:
|
|
5338
|
+
schema: z4.object({
|
|
3869
5339
|
/** The config file that applied; null when none did. */
|
|
3870
|
-
configFile:
|
|
3871
|
-
problems:
|
|
5340
|
+
configFile: z4.string().nullable(),
|
|
5341
|
+
problems: z4.array(optionProblemSchema)
|
|
3872
5342
|
}),
|
|
3873
5343
|
render: ({ configFile, problems }) => {
|
|
3874
5344
|
const [first, ...rest] = problems;
|
|
@@ -4194,7 +5664,7 @@ function errorMessage(error) {
|
|
|
4194
5664
|
}
|
|
4195
5665
|
|
|
4196
5666
|
// src/credential/live/vercel-cli-gateway.ts
|
|
4197
|
-
import { execFile as
|
|
5667
|
+
import { execFile as execFile3 } from "node:child_process";
|
|
4198
5668
|
import { tmpdir } from "node:os";
|
|
4199
5669
|
|
|
4200
5670
|
// src/credential/live/vercel-process.ts
|
|
@@ -4290,7 +5760,7 @@ function liveCredentialGateway() {
|
|
|
4290
5760
|
function runVercel(args) {
|
|
4291
5761
|
return new Promise((resolve) => {
|
|
4292
5762
|
try {
|
|
4293
|
-
|
|
5763
|
+
execFile3(
|
|
4294
5764
|
"vercel",
|
|
4295
5765
|
args,
|
|
4296
5766
|
{
|
|
@@ -4323,6 +5793,17 @@ function failedRun(error, stdout, stderr) {
|
|
|
4323
5793
|
return { ok: false, reason: "exit", stdout: out, stderr: err };
|
|
4324
5794
|
}
|
|
4325
5795
|
|
|
5796
|
+
// src/credential/live/vercel-oidc-token-gateway.ts
|
|
5797
|
+
function liveVercelOidcTokenGateway(options) {
|
|
5798
|
+
return {
|
|
5799
|
+
async read() {
|
|
5800
|
+
const token = Object.hasOwn(options.env, "VERCEL_OIDC_TOKEN") ? options.env["VERCEL_OIDC_TOKEN"] : void 0;
|
|
5801
|
+
if (token === void 0 || token === "") return { ok: false, failure: { kind: "missing-token" } };
|
|
5802
|
+
return { ok: true, credential: new Credential(token) };
|
|
5803
|
+
}
|
|
5804
|
+
};
|
|
5805
|
+
}
|
|
5806
|
+
|
|
4326
5807
|
// src/credential/source.ts
|
|
4327
5808
|
var REQUESTING_TOKEN_LINE = "Requesting a GitHub Actions OIDC token\u2026";
|
|
4328
5809
|
function credentialSourceFor(choice, context, progress) {
|
|
@@ -4333,6 +5814,7 @@ function credentialSourceFor(choice, context, progress) {
|
|
|
4333
5814
|
timer: context.timer,
|
|
4334
5815
|
progress
|
|
4335
5816
|
});
|
|
5817
|
+
if (choice.source === "vercel-oidc") return vercelOidcSource(context.vercelOidcTokens);
|
|
4336
5818
|
const { target } = choice;
|
|
4337
5819
|
return mintSource(target, async () => {
|
|
4338
5820
|
await progress.emit({ kind: "minting", target });
|
|
@@ -4413,12 +5895,90 @@ function isRetryable(failure) {
|
|
|
4413
5895
|
return false;
|
|
4414
5896
|
}
|
|
4415
5897
|
}
|
|
5898
|
+
function vercelOidcSource(gateway) {
|
|
5899
|
+
let outcome;
|
|
5900
|
+
return {
|
|
5901
|
+
obtain() {
|
|
5902
|
+
outcome ??= (async () => {
|
|
5903
|
+
const read = await gateway.read();
|
|
5904
|
+
if (!read.ok) return { ok: false, failure: { source: "vercel-oidc", failure: read.failure } };
|
|
5905
|
+
const project = read.credential.vercelProject();
|
|
5906
|
+
if (project === void 0)
|
|
5907
|
+
return { ok: false, failure: { source: "vercel-oidc", failure: { kind: "invalid-token" } } };
|
|
5908
|
+
return { ok: true, credential: read.credential, project };
|
|
5909
|
+
})();
|
|
5910
|
+
return outcome;
|
|
5911
|
+
},
|
|
5912
|
+
origin() {
|
|
5913
|
+
return { source: "vercel-oidc" };
|
|
5914
|
+
}
|
|
5915
|
+
};
|
|
5916
|
+
}
|
|
5917
|
+
function vercelProjectSource(choice, context, progress) {
|
|
5918
|
+
if (choice.source === "vercel-oidc") {
|
|
5919
|
+
const source2 = credentialSourceFor(choice, context, progress);
|
|
5920
|
+
return { source: source2, obtain: () => source2.obtain() };
|
|
5921
|
+
}
|
|
5922
|
+
const source = credentialSourceFor(choice, context, progress);
|
|
5923
|
+
return {
|
|
5924
|
+
source,
|
|
5925
|
+
obtain: async () => {
|
|
5926
|
+
const got = await source.obtain();
|
|
5927
|
+
if (!got.ok) return got;
|
|
5928
|
+
const project = got.credential.vercelProject();
|
|
5929
|
+
return project === void 0 ? { ok: false, failure: { source: "claims-missing", target: choice.target } } : { ok: true, credential: got.credential, project };
|
|
5930
|
+
}
|
|
5931
|
+
};
|
|
5932
|
+
}
|
|
4416
5933
|
|
|
4417
5934
|
// src/credential/target.ts
|
|
4418
5935
|
function mintTargetText(target) {
|
|
4419
5936
|
return `Vercel project ${target.project} on team ${target.team}`;
|
|
4420
5937
|
}
|
|
4421
5938
|
|
|
5939
|
+
// src/config/credential-settle.ts
|
|
5940
|
+
import { z as z5 } from "zod";
|
|
5941
|
+
var credentialErrors = defineErrors({
|
|
5942
|
+
missingTarget: {
|
|
5943
|
+
exitCode: 2,
|
|
5944
|
+
description: "The command may mint a credential, and neither a flag nor storm.config.ts names the control plane team or project.",
|
|
5945
|
+
schema: z5.object({
|
|
5946
|
+
/** The settings no flag or config file gave. */
|
|
5947
|
+
missing: z5.array(z5.enum(["scope", "project"]))
|
|
5948
|
+
}),
|
|
5949
|
+
render: ({ missing }) => ({
|
|
5950
|
+
message: `No control plane ${missing.map((key) => key === "scope" ? "team" : "project").join(" or ")} to mint a credential for.`,
|
|
5951
|
+
next: [
|
|
5952
|
+
{
|
|
5953
|
+
type: "text",
|
|
5954
|
+
text: `Give ${missing.map((key) => `--${key}`).join(" and ")}, or set ${missing.join(" and ")} in storm.config.ts.`
|
|
5955
|
+
}
|
|
5956
|
+
]
|
|
5957
|
+
})
|
|
5958
|
+
}
|
|
5959
|
+
});
|
|
5960
|
+
function requireTarget(scope, project) {
|
|
5961
|
+
if (scope === void 0 || project === void 0)
|
|
5962
|
+
return refused(
|
|
5963
|
+
credentialErrors.missingTarget({
|
|
5964
|
+
missing: [
|
|
5965
|
+
...scope === void 0 ? ["scope"] : [],
|
|
5966
|
+
...project === void 0 ? ["project"] : []
|
|
5967
|
+
]
|
|
5968
|
+
})
|
|
5969
|
+
);
|
|
5970
|
+
return { ok: true, target: { team: scope.value, project: project.value } };
|
|
5971
|
+
}
|
|
5972
|
+
function givenTarget(scope, project) {
|
|
5973
|
+
return scope === void 0 || project === void 0 ? null : { team: scope.value, project: project.value };
|
|
5974
|
+
}
|
|
5975
|
+
function settleCredential(source, scope, project) {
|
|
5976
|
+
if (source === "github-actions" || source === "vercel-oidc") return { ok: true, credential: { source } };
|
|
5977
|
+
const required = requireTarget(scope, project);
|
|
5978
|
+
if (!required.ok) return required;
|
|
5979
|
+
return { ok: true, credential: { source, target: required.target } };
|
|
5980
|
+
}
|
|
5981
|
+
|
|
4422
5982
|
// src/config/credential-resolver.ts
|
|
4423
5983
|
var credentialSourceErrors = defineErrors({
|
|
4424
5984
|
mintFailed: {
|
|
@@ -4438,23 +5998,36 @@ var credentialSourceErrors = defineErrors({
|
|
|
4438
5998
|
message: `Couldn't request a GitHub Actions OIDC token: ${detail}.`,
|
|
4439
5999
|
next: [{ type: "text", text: fix }]
|
|
4440
6000
|
})
|
|
6001
|
+
},
|
|
6002
|
+
vercelOidcTokenFailed: {
|
|
6003
|
+
exitCode: 1,
|
|
6004
|
+
description: "With --credential vercel-oidc, VERCEL_OIDC_TOKEN is missing, empty, or not a valid Vercel project OIDC token.",
|
|
6005
|
+
schema: z6.object(vercelOidcTokenFailureShape),
|
|
6006
|
+
render: ({ detail, fix }) => ({
|
|
6007
|
+
message: `Couldn't use VERCEL_OIDC_TOKEN: ${detail}.`,
|
|
6008
|
+
next: [{ type: "text", text: fix }]
|
|
6009
|
+
})
|
|
4441
6010
|
}
|
|
4442
6011
|
});
|
|
4443
6012
|
function credentialSourceError(failure) {
|
|
4444
|
-
|
|
6013
|
+
switch (failure.source) {
|
|
6014
|
+
case "mint":
|
|
6015
|
+
return credentialSourceErrors.mintFailed({
|
|
6016
|
+
...failure.target,
|
|
6017
|
+
...describeMintFailure(failure.failure, failure.target)
|
|
6018
|
+
});
|
|
6019
|
+
case "github-actions":
|
|
6020
|
+
return credentialSourceErrors.tokenRequestFailed(tokenRequestFailureFacts(failure.failure));
|
|
6021
|
+
case "vercel-oidc":
|
|
6022
|
+
return credentialSourceErrors.vercelOidcTokenFailed(vercelOidcTokenFailureFacts(failure.failure));
|
|
6023
|
+
}
|
|
4445
6024
|
}
|
|
4446
6025
|
function credentialResolver(gateways) {
|
|
4447
6026
|
return {
|
|
4448
6027
|
source(choice, target, report = {}) {
|
|
4449
6028
|
const chosen = settleCredential(choice, target.scope, target.project);
|
|
4450
6029
|
if (!chosen.ok) return chosen;
|
|
4451
|
-
const
|
|
4452
|
-
const source = credentialSourceFor(chosen.credential, gateways, {
|
|
4453
|
-
emit: async (event) => {
|
|
4454
|
-
if (event.kind === "minting") await progress?.(`Minting a credential for ${mintTargetText(event.target)}\u2026`);
|
|
4455
|
-
else if (event.kind === "requesting-token") await progress?.(REQUESTING_TOKEN_LINE);
|
|
4456
|
-
}
|
|
4457
|
-
});
|
|
6030
|
+
const source = credentialSourceFor(chosen.credential, gateways, commandLines(report));
|
|
4458
6031
|
return {
|
|
4459
6032
|
ok: true,
|
|
4460
6033
|
source: {
|
|
@@ -4465,6 +6038,25 @@ function credentialResolver(gateways) {
|
|
|
4465
6038
|
origin: (credential) => source.origin(credential)
|
|
4466
6039
|
}
|
|
4467
6040
|
};
|
|
6041
|
+
},
|
|
6042
|
+
vercelProjectSource(choice, target, report = {}) {
|
|
6043
|
+
let credential;
|
|
6044
|
+
if (choice === "vercel-oidc") credential = { source: choice };
|
|
6045
|
+
else {
|
|
6046
|
+
const required = requireTarget(target.scope, target.project);
|
|
6047
|
+
if (!required.ok) return required;
|
|
6048
|
+
credential = { source: choice, target: required.target };
|
|
6049
|
+
}
|
|
6050
|
+
const { obtain } = vercelProjectSource(credential, gateways, commandLines(report));
|
|
6051
|
+
return { ok: true, source: { obtain } };
|
|
6052
|
+
}
|
|
6053
|
+
};
|
|
6054
|
+
}
|
|
6055
|
+
function commandLines({ progress }) {
|
|
6056
|
+
return {
|
|
6057
|
+
emit: async (event) => {
|
|
6058
|
+
if (event.kind === "minting") await progress?.(`Minting a credential for ${mintTargetText(event.target)}\u2026`);
|
|
6059
|
+
else if (event.kind === "requesting-token") await progress?.(REQUESTING_TOKEN_LINE);
|
|
4468
6060
|
}
|
|
4469
6061
|
};
|
|
4470
6062
|
}
|
|
@@ -4569,12 +6161,15 @@ function configResolver(launcher) {
|
|
|
4569
6161
|
export {
|
|
4570
6162
|
liveGitHubActionsTokenGateway,
|
|
4571
6163
|
liveCredentialGateway,
|
|
6164
|
+
liveVercelOidcTokenGateway,
|
|
4572
6165
|
credentialSourceFor,
|
|
6166
|
+
vercelProjectSource,
|
|
4573
6167
|
mintTargetText,
|
|
4574
6168
|
credentialErrors,
|
|
4575
|
-
|
|
6169
|
+
givenTarget,
|
|
4576
6170
|
settleCredential,
|
|
4577
6171
|
credentialSourceErrors,
|
|
6172
|
+
credentialSourceError,
|
|
4578
6173
|
credentialResolver,
|
|
4579
6174
|
configErrors,
|
|
4580
6175
|
RUNNER_SNAPSHOTS_SUBPATH,
|
|
@@ -4589,21 +6184,27 @@ export {
|
|
|
4589
6184
|
resolveSandboxCountDefault,
|
|
4590
6185
|
lineSplitter,
|
|
4591
6186
|
prepareSnapshotBuild,
|
|
6187
|
+
sameSnapshotBuild,
|
|
4592
6188
|
buildSnapshots,
|
|
4593
6189
|
liveCheckoutGateway,
|
|
6190
|
+
liveGhTokenGateway,
|
|
4594
6191
|
liveRunnerSandboxGateway,
|
|
4595
6192
|
liveRunnerTerminal,
|
|
4596
6193
|
localUserName,
|
|
4597
|
-
|
|
4598
|
-
|
|
6194
|
+
liveRunnerSnapshotIndexGateway,
|
|
6195
|
+
unavailableRunnerSnapshotIndexGateway,
|
|
4599
6196
|
prepareRunner,
|
|
4600
6197
|
chooseSnapshotForRun,
|
|
4601
6198
|
SANDBOX_TEST_EVENTS_PATH,
|
|
6199
|
+
CREDENTIAL_PROBLEM_KINDS,
|
|
4602
6200
|
declaredSecretValues,
|
|
4603
6201
|
readCredentials,
|
|
4604
6202
|
readUnsafeSecretEnvVars,
|
|
4605
6203
|
openRunnerSession,
|
|
4606
|
-
|
|
6204
|
+
inspectLocalSnapshotIndex,
|
|
6205
|
+
listSharedSnapshots,
|
|
6206
|
+
pickSnapshotAcrossIndexes,
|
|
6207
|
+
pruneSharedSnapshots,
|
|
4607
6208
|
CONFIG_FILE_NAME,
|
|
4608
6209
|
CONFIG_FILE_NAMES_TEXT,
|
|
4609
6210
|
liveConfigGateway,
|