@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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// What a run records about itself in its run directory's `run.json`, which `storm runs` reads back: written as
|
|
2
2
|
// the run directory opens, then replaced with how the run ended once it is over. The run directory gateway stores the
|
|
3
|
-
// text; this file owns its shape, version
|
|
3
|
+
// text; this file owns its shape, version 6, and what goes in it: where the command runs, as the run starts and
|
|
4
4
|
// once it is over, and how the run ended. Reading it back asks the resource definition set nothing: each resource
|
|
5
5
|
// instance's facts read as recorded, beside its definition's name, and `runs show` lists the rows storm rendered for
|
|
6
6
|
// them when the run ended, so a past run reads the same after a resource definition is renamed or its extension
|
|
@@ -30,15 +30,17 @@ const snapshotSchema = z.object({
|
|
|
30
30
|
base: z.string(),
|
|
31
31
|
built: z.boolean(),
|
|
32
32
|
builtBehind: z.number().nullable(),
|
|
33
|
+
/** Where a reused snapshot came from (`local` or `shared`); null when built, or absent in older records. */
|
|
34
|
+
source: z.enum(["local", "shared"]).nullable().exactOptional(),
|
|
33
35
|
});
|
|
34
36
|
const whereSchema = z.discriminatedUnion("kind", [
|
|
35
37
|
z.object({ kind: z.literal("launch-machine") }),
|
|
36
38
|
z.object({
|
|
37
39
|
kind: z.literal("vercel-sandbox"),
|
|
38
|
-
team: z.string(),
|
|
39
|
-
project: z.string(),
|
|
40
|
+
team: z.string().nullable(),
|
|
41
|
+
project: z.string().nullable(),
|
|
40
42
|
region: z.string(),
|
|
41
|
-
|
|
43
|
+
image: z.string(),
|
|
42
44
|
vcpus: z.number().int().positive(),
|
|
43
45
|
base: z.string(),
|
|
44
46
|
baseRef: z.string(),
|
|
@@ -88,7 +90,7 @@ export const sandboxRecordSchema = z.object({
|
|
|
88
90
|
/** How many of its command log's last lines a runner sandbox record keeps. */
|
|
89
91
|
export const SANDBOX_TAIL_LINES = 20;
|
|
90
92
|
const runRecordSchema = z.object({
|
|
91
|
-
version: z.literal(
|
|
93
|
+
version: z.literal(6),
|
|
92
94
|
startedAt: z.string(),
|
|
93
95
|
cwd: z.string(),
|
|
94
96
|
configFile: z.string().nullable(),
|
|
@@ -109,7 +111,7 @@ const runRecordSchema = z.object({
|
|
|
109
111
|
export function runRecordText(record) {
|
|
110
112
|
return JSON.stringify(record);
|
|
111
113
|
}
|
|
112
|
-
/** The run `text` records; undefined when there is no text, or it isn't a version
|
|
114
|
+
/** The run `text` records; undefined when there is no text, or it isn't a version 6 `run.json`. */
|
|
113
115
|
export function parseRunRecord(text) {
|
|
114
116
|
if (text === undefined)
|
|
115
117
|
return undefined;
|
|
@@ -178,16 +180,16 @@ function commandMs(ran) {
|
|
|
178
180
|
* Where the command runs, as `run.json` records it as the run starts: on the launch machine (`launch-machine`), or in
|
|
179
181
|
* a Vercel Sandbox (`vercel-sandbox`), with no sandbox or snapshot yet.
|
|
180
182
|
*/
|
|
181
|
-
export function startedWhere(
|
|
182
|
-
if (
|
|
183
|
+
export function startedWhere(runner) {
|
|
184
|
+
if (runner.kind === "launch-machine")
|
|
183
185
|
return { kind: "launch-machine" };
|
|
184
|
-
const { prepared, target } =
|
|
186
|
+
const { prepared, target } = runner.session;
|
|
185
187
|
return {
|
|
186
188
|
kind: "vercel-sandbox",
|
|
187
|
-
team: target
|
|
188
|
-
project: target
|
|
189
|
-
region: prepared.
|
|
190
|
-
|
|
189
|
+
team: target?.team ?? null,
|
|
190
|
+
project: target?.project ?? null,
|
|
191
|
+
region: prepared.options.region,
|
|
192
|
+
image: prepared.options.image,
|
|
191
193
|
vcpus: prepared.vcpus,
|
|
192
194
|
base: prepared.base,
|
|
193
195
|
baseRef: prepared.baseRef,
|
|
@@ -216,6 +218,7 @@ export function endedWhere(where, runner) {
|
|
|
216
218
|
base: snapshot.base,
|
|
217
219
|
built: snapshot.kind === "built",
|
|
218
220
|
builtBehind: snapshot.builtBehind,
|
|
221
|
+
source: snapshot.kind === "reused" ? snapshot.source : null,
|
|
219
222
|
},
|
|
220
223
|
keptUntil: runner?.kept?.stopsAt ?? null,
|
|
221
224
|
uploadBytes: runner?.uploadBytes ?? null,
|
package/dist/runner/base.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// The base the runner builds on: HEAD's merge-base with one of the
|
|
1
|
+
// The base the runner builds on: HEAD's merge-base with one of the runner's `baseRefs`, from local refs only.
|
|
2
2
|
/**
|
|
3
3
|
* Resolves a run's base from `baseRefs`, local refs only. Of the refs that exist and share history with HEAD, the
|
|
4
4
|
* newest merge-base wins: a later ref's merge-base replaces the best so far only when the best is its ancestor, so a
|
|
@@ -1,31 +1,33 @@
|
|
|
1
1
|
import type { SandboxCredential } from "../sdk/extension/index.ts";
|
|
2
|
-
import type
|
|
2
|
+
import { type RunnerContext } from "./context.ts";
|
|
3
3
|
import type { RunnerFailure, RunnerProgress } from "./events.ts";
|
|
4
|
-
import type { CheckoutHead,
|
|
4
|
+
import type { CheckoutHead, RunnerSnapshotEntry, RunnerSnapshotIndexFailure, SandboxAccess } from "./gateways.ts";
|
|
5
5
|
import type { PrepareRunnerOutcome, RunnerPrepareContext } from "./prepare.ts";
|
|
6
|
-
import type {
|
|
6
|
+
import type { CheckedVercelSandboxOptions } from "./vercel-sandbox-options.ts";
|
|
7
7
|
import { type RunnerScopeFacts } from "./scope.ts";
|
|
8
|
-
import { type
|
|
9
|
-
/** What `prepareSnapshotBuild` checks: where, which
|
|
8
|
+
import { type RunnerSnapshotPlan } from "./snapshot-build.ts";
|
|
9
|
+
/** What `prepareSnapshotBuild` checks: where, which runner, and what to build. */
|
|
10
10
|
export interface SnapshotBuildRequest {
|
|
11
11
|
/** The directory the command started in, inside the checkout. */
|
|
12
12
|
readonly cwd: string;
|
|
13
|
-
readonly
|
|
13
|
+
readonly options: CheckedVercelSandboxOptions;
|
|
14
14
|
/** The ref `--base` names; undefined builds at the merge-base. */
|
|
15
15
|
readonly ref: string | undefined;
|
|
16
|
-
/** `--full`: build whatever the
|
|
16
|
+
/** `--full`: build whatever the local snapshot index holds. */
|
|
17
17
|
readonly full: boolean;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
|
-
* A build, checked on this machine: the
|
|
21
|
-
* has uncommitted changes, which a
|
|
22
|
-
* merge-base and its ref (null for a `--base` build in a checkout where no base ref shares history with HEAD),
|
|
23
|
-
* the commit it builds at is that merge-base (`atMergeBase
|
|
24
|
-
*
|
|
25
|
-
*
|
|
20
|
+
* A build, checked on this machine: the runner snapshot it builds (`plan`), HEAD, whose `dirty` says the working tree
|
|
21
|
+
* has uncommitted changes, which a runner snapshot doesn't hold, the ref `--base` named (null for the merge-base),
|
|
22
|
+
* HEAD's merge-base and its ref (null for a `--base` build in a checkout where no base ref shares history with HEAD),
|
|
23
|
+
* whether the commit it builds at is that merge-base (`atMergeBase`) or an ancestor of it (`ancestorOfMergeBase`, false
|
|
24
|
+
* at the merge-base itself: a run here starts only from a snapshot at its merge-base or at a commit behind it on the
|
|
25
|
+
* base ref, though a run in another checkout, or after a later merge-base, still might), and the runner snapshots of
|
|
26
|
+
* `plan`'s base and key the local snapshot index holds with more than an hour left (`indexed`, at exactly that base,
|
|
27
|
+
* before the team and project filter).
|
|
26
28
|
*/
|
|
27
29
|
export interface PreparedSnapshotBuild {
|
|
28
|
-
readonly plan:
|
|
30
|
+
readonly plan: RunnerSnapshotPlan;
|
|
29
31
|
readonly head: CheckoutHead;
|
|
30
32
|
readonly ref: string | null;
|
|
31
33
|
readonly mergeBase: {
|
|
@@ -33,11 +35,12 @@ export interface PreparedSnapshotBuild {
|
|
|
33
35
|
readonly ref: string;
|
|
34
36
|
} | null;
|
|
35
37
|
readonly atMergeBase: boolean;
|
|
36
|
-
readonly
|
|
38
|
+
readonly ancestorOfMergeBase: boolean;
|
|
39
|
+
readonly indexed: readonly RunnerSnapshotEntry[];
|
|
37
40
|
readonly full: boolean;
|
|
38
41
|
}
|
|
39
42
|
/**
|
|
40
|
-
* How a build's local checks ended: a run's refusals,
|
|
43
|
+
* How a build's local checks ended: a run's refusals, including `submodules`, `invalid-runner`, and `checkout-failed`
|
|
41
44
|
* that the build shares, or `ref-not-found` when `--base` names no local commit.
|
|
42
45
|
*/
|
|
43
46
|
export type PrepareSnapshotBuildOutcome = {
|
|
@@ -53,9 +56,15 @@ export type PrepareSnapshotBuildOutcome = {
|
|
|
53
56
|
* Runs a build's local checks, before anything is minted or started: the repository's root, HEAD, the submodule
|
|
54
57
|
* refusal, HEAD's merge-base (`resolveBase`, which refuses with `no-base-ref` only without `--base`), the commit
|
|
55
58
|
* `--base` resolves to locally, the snapshot steps and key at the commit it builds, the cache's base snapshots of it,
|
|
56
|
-
*
|
|
59
|
+
* whether a commit other than the merge-base is an ancestor of it, and, when it builds at the merge-base, HEAD's count
|
|
60
|
+
* of commits after it. It never mints, acquires or creates, and removes no cache file.
|
|
57
61
|
*/
|
|
58
62
|
export declare function prepareSnapshotBuild(context: RunnerPrepareContext, request: SnapshotBuildRequest): Promise<PrepareSnapshotBuildOutcome>;
|
|
63
|
+
/**
|
|
64
|
+
* Whether two snapshot build plans build the same runner snapshot: same runner target (`name`, `region`, and `image`)
|
|
65
|
+
* and same `snapshotKey`. Used to deduplicate `--all-suites` builds.
|
|
66
|
+
*/
|
|
67
|
+
export declare function sameSnapshotBuild(a: Pick<RunnerSnapshotPlan, "options" | "snapshotKey">, b: Pick<RunnerSnapshotPlan, "options" | "snapshotKey">): boolean;
|
|
59
68
|
/** What `buildSnapshots` is handed: the checked build, where its sandboxes run, who starts them, and the credentials. */
|
|
60
69
|
export interface BuildSnapshotsRequest {
|
|
61
70
|
readonly build: PreparedSnapshotBuild;
|
|
@@ -63,32 +72,52 @@ export interface BuildSnapshotsRequest {
|
|
|
63
72
|
readonly access: SandboxAccess;
|
|
64
73
|
/** The local user, for each sandbox's `user` tag. */
|
|
65
74
|
readonly user: string;
|
|
66
|
-
/** The
|
|
75
|
+
/** The runner's credentials, with their values: the firewall adds every one while the runner's snapshot steps run. */
|
|
67
76
|
readonly credentials: readonly Required<SandboxCredential>[];
|
|
77
|
+
/**
|
|
78
|
+
* `--publish`: check the shared snapshot index instead of the local snapshot index, and publish the build there,
|
|
79
|
+
* keeping its build sandbox stopped under the index entry's name. By default it neither reads nor writes the shared
|
|
80
|
+
* snapshot index.
|
|
81
|
+
*/
|
|
82
|
+
readonly publish?: boolean;
|
|
68
83
|
}
|
|
69
84
|
/**
|
|
70
85
|
* How a build ended, before its sandbox scope closed.
|
|
71
86
|
*
|
|
72
|
-
* - `up-to-date`: the
|
|
73
|
-
* nothing started.
|
|
74
|
-
*
|
|
75
|
-
* - `
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
87
|
+
* - `up-to-date`: the local snapshot index holds `snapshot`, a runner snapshot at the commit for the access's team and
|
|
88
|
+
* project, so nothing started. With `publish`, the shared snapshot index holds it instead, in the stopped sandbox
|
|
89
|
+
* `sandboxName`, and the local snapshot index now records it too, unless the write failed.
|
|
90
|
+
* - `built`: it built `snapshot` in `ms` (`sizeBytes`), and the local snapshot index recorded it. With `publish`, the
|
|
91
|
+
* shared snapshot index holds it in the stopped sandbox `sandboxName`, so a local snapshot index entry that couldn't
|
|
92
|
+
* be written (`localIndexFailure`) doesn't fail the build: a run finds the snapshot in the shared snapshot index.
|
|
93
|
+
* - `already-building`: with `publish`, the index entry's sandbox `sandboxName` already exists with a status a build
|
|
94
|
+
* still owns (`status`; null when another build took the name first while this one started), so nothing started.
|
|
95
|
+
* - `not-indexed`: it built `snapshot`, but the local snapshot index couldn't write its entry (`failure`), so no run
|
|
96
|
+
* finds it.
|
|
97
|
+
* - `failed`: a step, a Sandbox call, or the checkout failed.
|
|
98
|
+
* - `aborted`: the signal aborted. A runner snapshot's save runs to its end once started, so a signal during it still
|
|
99
|
+
* leaves a saved snapshot, which `snapshot` names with whether the local snapshot index wrote its entry; null when it
|
|
100
|
+
* saved none.
|
|
79
101
|
*/
|
|
80
102
|
export type SnapshotBuildEnd = {
|
|
81
103
|
readonly kind: "up-to-date";
|
|
82
104
|
readonly snapshot: RunnerSnapshotEntry;
|
|
105
|
+
readonly sandboxName?: string;
|
|
83
106
|
} | {
|
|
84
107
|
readonly kind: "built";
|
|
85
108
|
readonly snapshot: RunnerSnapshotEntry;
|
|
86
109
|
readonly ms: number;
|
|
87
110
|
readonly sizeBytes: number;
|
|
111
|
+
readonly sandboxName?: string;
|
|
112
|
+
readonly localIndexFailure?: RunnerSnapshotIndexFailure;
|
|
113
|
+
} | {
|
|
114
|
+
readonly kind: "already-building";
|
|
115
|
+
readonly sandboxName: string;
|
|
116
|
+
readonly status: string | null;
|
|
88
117
|
} | {
|
|
89
|
-
readonly kind: "not-
|
|
118
|
+
readonly kind: "not-indexed";
|
|
90
119
|
readonly snapshot: RunnerSnapshotEntry;
|
|
91
|
-
readonly failure:
|
|
120
|
+
readonly failure: RunnerSnapshotIndexFailure;
|
|
92
121
|
} | {
|
|
93
122
|
readonly kind: "failed";
|
|
94
123
|
readonly failure: RunnerFailure;
|
|
@@ -96,7 +125,7 @@ export type SnapshotBuildEnd = {
|
|
|
96
125
|
readonly kind: "aborted";
|
|
97
126
|
readonly snapshot: {
|
|
98
127
|
readonly entry: RunnerSnapshotEntry;
|
|
99
|
-
readonly
|
|
128
|
+
readonly indexed: boolean;
|
|
100
129
|
} | null;
|
|
101
130
|
};
|
|
102
131
|
/** How a build ended (`SnapshotBuildEnd`), with what closing its sandbox scope left (`cleanup`). */
|
|
@@ -108,7 +137,9 @@ export type SnapshotBuildOutcome = SnapshotBuildEnd & {
|
|
|
108
137
|
* ends, keeping none. A cached base snapshot at the commit for the access's team and project is up to date, unless
|
|
109
138
|
* `full`, which builds a new one that replaces its cache entry. `signal` cancels it in any stage: the scope says so,
|
|
110
139
|
* revokes every credential at once, and stops its sandboxes. A base snapshot's save isn't stopped by the signal, so
|
|
111
|
-
* after it the build checks the signal once and ends `aborted` with what it saved.
|
|
140
|
+
* after it the build checks the signal once and ends `aborted` with what it saved. With `publish`, it checks the shared
|
|
141
|
+
* snapshot index instead of the cache (`publishIn`), and the build sandbox it saves stays in the project, stopped, as
|
|
142
|
+
* the index entry.
|
|
112
143
|
*/
|
|
113
144
|
export declare function buildSnapshots(context: RunnerContext, request: BuildSnapshotsRequest, control: {
|
|
114
145
|
readonly signal: AbortSignal;
|
|
@@ -1,22 +1,28 @@
|
|
|
1
|
-
// `storm snapshots build`: building one
|
|
1
|
+
// `storm snapshots build`: building one runner snapshot that the local snapshot index lacks, with no run: at the
|
|
2
2
|
// merge-base by default, or at the commit `--base <ref>` names, which a run starts from only once that commit is its
|
|
3
|
-
// merge-base. It owns its sandbox scope from its first stage to its end, as a run's
|
|
4
|
-
// acquires no resource, runs no command, and keeps no sandbox.
|
|
3
|
+
// merge-base or an ancestor of its merge-base. It owns its sandbox scope from its first stage to its end, as a run's
|
|
4
|
+
// runner session does. It acquires no resource, runs no command, and keeps no running sandbox. With `publish`, it also
|
|
5
|
+
// publishes the build to the shared snapshot index: the build sandbox takes the index entry's name and stays in the
|
|
6
|
+
// project, stopped.
|
|
5
7
|
import { resolveBase } from "./base.js";
|
|
8
|
+
import { snapshotIndexTags } from "./context.js";
|
|
9
|
+
import { hasTimeLeft, matchesRunnerTarget, sameRunnerTarget, SNAPSHOT_EXPIRATION_MS } from "./local-snapshot-index.js";
|
|
6
10
|
import { runnerNetworkPolicy } from "./network-policy.js";
|
|
7
11
|
import { runnerSandboxScope } from "./scope.js";
|
|
8
12
|
import { buildSnapshot } from "./snapshot-build.js";
|
|
9
|
-
import {
|
|
13
|
+
import { classifyUnverifiedSharedSandbox, sharedSnapshotBucket, sharedSnapshotSandboxName, usableSharedEntry, } from "./shared-snapshot-entry.js";
|
|
10
14
|
import { snapshotInputsAt } from "./snapshot-key.js";
|
|
15
|
+
import { sandboxApiFailure } from "./steps.js";
|
|
11
16
|
/**
|
|
12
17
|
* Runs a build's local checks, before anything is minted or started: the repository's root, HEAD, the submodule
|
|
13
18
|
* refusal, HEAD's merge-base (`resolveBase`, which refuses with `no-base-ref` only without `--base`), the commit
|
|
14
19
|
* `--base` resolves to locally, the snapshot steps and key at the commit it builds, the cache's base snapshots of it,
|
|
15
|
-
*
|
|
20
|
+
* whether a commit other than the merge-base is an ancestor of it, and, when it builds at the merge-base, HEAD's count
|
|
21
|
+
* of commits after it. It never mints, acquires or creates, and removes no cache file.
|
|
16
22
|
*/
|
|
17
23
|
export async function prepareSnapshotBuild(context, request) {
|
|
18
24
|
const { checkout } = context;
|
|
19
|
-
const {
|
|
25
|
+
const { options, ref } = request;
|
|
20
26
|
const root = await checkout.repositoryRoot({ cwd: request.cwd });
|
|
21
27
|
if (!root.ok)
|
|
22
28
|
return { kind: "checkout-failed", failure: root.failure };
|
|
@@ -24,7 +30,7 @@ export async function prepareSnapshotBuild(context, request) {
|
|
|
24
30
|
const head = await checkout.head({ repoRoot });
|
|
25
31
|
if (!head.ok)
|
|
26
32
|
return { kind: "checkout-failed", failure: head.failure };
|
|
27
|
-
const resolved = await resolveBase(checkout, { repoRoot, baseRefs:
|
|
33
|
+
const resolved = await resolveBase(checkout, { repoRoot, baseRefs: options.baseRefs });
|
|
28
34
|
if (resolved.kind === "failed")
|
|
29
35
|
return { kind: "checkout-failed", failure: resolved.failure };
|
|
30
36
|
const mergeBase = resolved.kind === "resolved" ? { commit: resolved.base, ref: resolved.ref } : null;
|
|
@@ -47,20 +53,18 @@ export async function prepareSnapshotBuild(context, request) {
|
|
|
47
53
|
return { kind: "ref-not-found", ref };
|
|
48
54
|
base = commit.value;
|
|
49
55
|
}
|
|
50
|
-
const inputs = await snapshotInputsAt(checkout, { repoRoot, base,
|
|
56
|
+
const inputs = await snapshotInputsAt(checkout, { repoRoot, base, options });
|
|
51
57
|
if (!inputs.ok)
|
|
52
|
-
return { kind: "invalid-
|
|
53
|
-
// An unreadable
|
|
58
|
+
return { kind: "invalid-runner", path: inputs.path, problem: inputs.problem };
|
|
59
|
+
// An unreadable local snapshot index holds nothing to reuse: the build goes on, and builds.
|
|
54
60
|
const listed = await context.runnerSnapshots.listEntries();
|
|
55
61
|
const now = context.clock.now();
|
|
56
|
-
const
|
|
57
|
-
entry
|
|
58
|
-
entry.region === recipe.region &&
|
|
59
|
-
entry.runtime === recipe.runtime &&
|
|
62
|
+
const indexed = (listed.ok ? listed.value.entries : []).filter((entry) => entry.base === base &&
|
|
63
|
+
matchesRunnerTarget(entry, options) &&
|
|
60
64
|
entry.snapshotKey === inputs.key &&
|
|
61
65
|
hasTimeLeft(entry, now));
|
|
62
66
|
const atMergeBase = base === mergeBase?.commit;
|
|
63
|
-
// The built snapshot's count behind HEAD, for a build at the merge-base, the
|
|
67
|
+
// The built snapshot's count behind HEAD, for a build at the merge-base, the snapshot a run here starts from first.
|
|
64
68
|
let commitsAfterBase = null;
|
|
65
69
|
if (atMergeBase) {
|
|
66
70
|
const counted = await checkout.commitCount({ repoRoot, from: base, to: "HEAD" });
|
|
@@ -68,11 +72,19 @@ export async function prepareSnapshotBuild(context, request) {
|
|
|
68
72
|
return { kind: "checkout-failed", failure: counted.failure };
|
|
69
73
|
commitsAfterBase = counted.value;
|
|
70
74
|
}
|
|
75
|
+
// Whether a run here may start from a snapshot at another commit: one behind the merge-base on its base ref's line.
|
|
76
|
+
let ancestorOfMergeBase = false;
|
|
77
|
+
if (!atMergeBase && mergeBase !== null) {
|
|
78
|
+
const contained = await checkout.contains({ repoRoot, ancestor: base, descendant: mergeBase.commit });
|
|
79
|
+
if (!contained.ok)
|
|
80
|
+
return { kind: "checkout-failed", failure: contained.failure };
|
|
81
|
+
ancestorOfMergeBase = contained.value;
|
|
82
|
+
}
|
|
71
83
|
return {
|
|
72
84
|
kind: "ok",
|
|
73
85
|
build: {
|
|
74
86
|
plan: {
|
|
75
|
-
|
|
87
|
+
options,
|
|
76
88
|
repoRoot,
|
|
77
89
|
base,
|
|
78
90
|
baseFiles: inputs.baseFiles,
|
|
@@ -83,24 +95,35 @@ export async function prepareSnapshotBuild(context, request) {
|
|
|
83
95
|
ref: ref ?? null,
|
|
84
96
|
mergeBase,
|
|
85
97
|
atMergeBase,
|
|
86
|
-
|
|
98
|
+
ancestorOfMergeBase,
|
|
99
|
+
indexed,
|
|
87
100
|
full: request.full,
|
|
88
101
|
},
|
|
89
102
|
};
|
|
90
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* Whether two snapshot build plans build the same runner snapshot: same runner target (`name`, `region`, and `image`)
|
|
106
|
+
* and same `snapshotKey`. Used to deduplicate `--all-suites` builds.
|
|
107
|
+
*/
|
|
108
|
+
export function sameSnapshotBuild(a, b) {
|
|
109
|
+
return sameRunnerTarget(a.options, b.options) && a.snapshotKey === b.snapshotKey;
|
|
110
|
+
}
|
|
91
111
|
/**
|
|
92
112
|
* Builds the checked build's base snapshot, reporting to `progress`, and closes every sandbox it started however it
|
|
93
113
|
* ends, keeping none. A cached base snapshot at the commit for the access's team and project is up to date, unless
|
|
94
114
|
* `full`, which builds a new one that replaces its cache entry. `signal` cancels it in any stage: the scope says so,
|
|
95
115
|
* revokes every credential at once, and stops its sandboxes. A base snapshot's save isn't stopped by the signal, so
|
|
96
|
-
* after it the build checks the signal once and ends `aborted` with what it saved.
|
|
116
|
+
* after it the build checks the signal once and ends `aborted` with what it saved. With `publish`, it checks the shared
|
|
117
|
+
* snapshot index instead of the cache (`publishIn`), and the build sandbox it saves stays in the project, stopped, as
|
|
118
|
+
* the index entry.
|
|
97
119
|
*/
|
|
98
120
|
export async function buildSnapshots(context, request, control, progress) {
|
|
99
121
|
const { signal } = control;
|
|
100
122
|
// When the build is canceled, the scope stops its sandboxes and revokes every credential at once.
|
|
101
123
|
const scope = runnerSandboxScope(context, progress, {
|
|
102
124
|
keepMs: 0,
|
|
103
|
-
basePolicy: runnerNetworkPolicy(request.build.plan.
|
|
125
|
+
basePolicy: runnerNetworkPolicy(request.build.plan.options),
|
|
126
|
+
managedCredentials: request.build.plan.options.managedCredentials,
|
|
104
127
|
signal,
|
|
105
128
|
});
|
|
106
129
|
try {
|
|
@@ -117,25 +140,109 @@ async function buildIn(context, request, control, progress) {
|
|
|
117
140
|
const { signal } = control;
|
|
118
141
|
if (signal.aborted)
|
|
119
142
|
return { kind: "aborted", snapshot: null };
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
143
|
+
if (request.publish === true)
|
|
144
|
+
return await publishIn(context, request, control, progress);
|
|
145
|
+
const indexed = build.indexed.find((entry) => entry.teamId === access.teamId && entry.projectId === access.projectId);
|
|
146
|
+
if (!build.full && indexed !== undefined)
|
|
147
|
+
return { kind: "up-to-date", snapshot: indexed };
|
|
148
|
+
const built = await buildSnapshot(context, { prepared: build.plan, access, user, credentials, why: buildReason(build) }, control, progress);
|
|
149
|
+
if (built.kind === "aborted")
|
|
150
|
+
return { kind: "aborted", snapshot: null };
|
|
151
|
+
if (built.kind !== "ok")
|
|
152
|
+
return built;
|
|
153
|
+
const { entry, localIndexFailure, ms, sizeBytes } = built.value;
|
|
154
|
+
if (signal.aborted)
|
|
155
|
+
return { kind: "aborted", snapshot: { entry, indexed: localIndexFailure === null } };
|
|
156
|
+
return localIndexFailure === null
|
|
157
|
+
? { kind: "built", snapshot: entry, ms, sizeBytes }
|
|
158
|
+
: { kind: "not-indexed", snapshot: entry, failure: localIndexFailure };
|
|
159
|
+
}
|
|
160
|
+
/** Why a build builds, for the line that says so. */
|
|
161
|
+
function buildReason(build) {
|
|
123
162
|
const why = build.full ? "full" : build.ref === null ? "no-snapshot" : "base";
|
|
163
|
+
return why === "no-snapshot" ? { kind: why, rejected: [] } : { kind: why };
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* A published build: it reads the shared snapshot index entry for the plan's base (`sharedSnapshotSandboxName`). An
|
|
167
|
+
* entry whose sandbox a build still owns ends `already-building`. A stopped entry whose snapshot is `created` with
|
|
168
|
+
* more than an hour left is up to date, unless `full`, and the cache records it. Any other entry (expired, gone, not
|
|
169
|
+
* `created`, without a snapshot, failed, or aborted, or any entry under `full`) is deleted to free its name, keeping
|
|
170
|
+
* its snapshot. Then it builds under that name and keeps the build sandbox stopped as the new entry.
|
|
171
|
+
*/
|
|
172
|
+
async function publishIn(context, request, control, progress) {
|
|
173
|
+
const { build, access, user, credentials } = request;
|
|
174
|
+
const { plan } = build;
|
|
175
|
+
const { options } = plan;
|
|
176
|
+
const { signal } = control;
|
|
177
|
+
const { runnerSandboxes } = context;
|
|
178
|
+
const bucket = sharedSnapshotBucket({
|
|
179
|
+
teamId: access.teamId,
|
|
180
|
+
projectId: access.projectId,
|
|
181
|
+
region: options.region,
|
|
182
|
+
image: options.image,
|
|
183
|
+
runnerName: options.name,
|
|
184
|
+
snapshotKey: plan.snapshotKey,
|
|
185
|
+
});
|
|
186
|
+
const name = sharedSnapshotSandboxName(bucket, plan.base);
|
|
187
|
+
const found = await runnerSandboxes.getNamedSandbox(access, { name }, signal);
|
|
188
|
+
if (!found.ok)
|
|
189
|
+
return callStop("get-named-sandbox", found.failure);
|
|
190
|
+
if (found.value.kind === "found") {
|
|
191
|
+
const { sandbox } = found.value;
|
|
192
|
+
const unverified = classifyUnverifiedSharedSandbox(sandbox);
|
|
193
|
+
if (unverified.kind === "settled" && unverified.status === "building")
|
|
194
|
+
return { kind: "already-building", sandboxName: name, status: sandbox.status };
|
|
195
|
+
if (!build.full && unverified.kind === "needs-snapshot") {
|
|
196
|
+
const verified = await runnerSandboxes.getSnapshot(access, { snapshotId: unverified.snapshotId }, signal);
|
|
197
|
+
if (!verified.ok)
|
|
198
|
+
return callStop("get-snapshot", verified.failure);
|
|
199
|
+
const entry = verified.value.kind === "found"
|
|
200
|
+
? usableSharedEntry(access, options, plan.snapshotKey, plan.base, sandbox, verified.value.snapshot, context.clock.now())
|
|
201
|
+
: null;
|
|
202
|
+
if (entry !== null) {
|
|
203
|
+
// Best effort: a run that misses the cache finds the snapshot in the index.
|
|
204
|
+
const written = await context.runnerSnapshots.writeEntry(entry);
|
|
205
|
+
if (!written.ok)
|
|
206
|
+
await progress.emit({ kind: "snapshot-entry-not-written", failure: written.failure });
|
|
207
|
+
return { kind: "up-to-date", snapshot: entry, sandboxName: name };
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
const removed = await runnerSandboxes.deleteNamedSandbox(access, { name }, signal);
|
|
211
|
+
if (!removed.ok)
|
|
212
|
+
return callStop("delete-named-sandbox", removed.failure);
|
|
213
|
+
}
|
|
214
|
+
if (signal.aborted)
|
|
215
|
+
return { kind: "aborted", snapshot: null };
|
|
216
|
+
const expiresAt = new Date(context.clock.now().getTime() + SNAPSHOT_EXPIRATION_MS).toISOString();
|
|
124
217
|
const built = await buildSnapshot(context, {
|
|
125
|
-
prepared:
|
|
218
|
+
prepared: plan,
|
|
126
219
|
access,
|
|
127
220
|
user,
|
|
128
221
|
credentials,
|
|
129
|
-
why:
|
|
222
|
+
why: buildReason(build),
|
|
223
|
+
publish: { name, tags: snapshotIndexTags(options.name, user, plan.base, expiresAt) },
|
|
130
224
|
}, control, progress);
|
|
225
|
+
if (built.kind === "name-taken")
|
|
226
|
+
return { kind: "already-building", sandboxName: name, status: null };
|
|
131
227
|
if (built.kind === "aborted")
|
|
132
228
|
return { kind: "aborted", snapshot: null };
|
|
133
229
|
if (built.kind !== "ok")
|
|
134
230
|
return built;
|
|
135
|
-
const { entry,
|
|
231
|
+
const { entry, localIndexFailure, ms, sizeBytes } = built.value;
|
|
136
232
|
if (signal.aborted)
|
|
137
|
-
return { kind: "aborted", snapshot: { entry,
|
|
138
|
-
return
|
|
139
|
-
|
|
140
|
-
|
|
233
|
+
return { kind: "aborted", snapshot: { entry, indexed: localIndexFailure === null } };
|
|
234
|
+
return {
|
|
235
|
+
kind: "built",
|
|
236
|
+
snapshot: entry,
|
|
237
|
+
ms,
|
|
238
|
+
sizeBytes,
|
|
239
|
+
sandboxName: name,
|
|
240
|
+
...(localIndexFailure === null ? {} : { localIndexFailure }),
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
/** How a build ends on a failed Sandbox call about the index entry: aborted for the signal, failed otherwise. */
|
|
244
|
+
function callStop(operation, failure) {
|
|
245
|
+
return failure.kind === "aborted"
|
|
246
|
+
? { kind: "aborted", snapshot: null }
|
|
247
|
+
: { kind: "failed", failure: sandboxApiFailure(operation, failure) };
|
|
141
248
|
}
|
package/dist/runner/context.d.ts
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
import type { Timer } from "../time/index.ts";
|
|
2
2
|
import type { RunnerSandboxGateway, RunnerSandboxRole, RunnerTerminal } from "./gateways.ts";
|
|
3
|
-
import type {
|
|
4
|
-
/**
|
|
5
|
-
|
|
3
|
+
import type { LocalSnapshotIndexContext } from "./local-snapshot-index.ts";
|
|
4
|
+
/**
|
|
5
|
+
* The runner's gateways and seams: the checkout, the local snapshot index, Vercel Sandbox, the terminal, the clock,
|
|
6
|
+
* and the timer.
|
|
7
|
+
*/
|
|
8
|
+
export interface RunnerContext extends LocalSnapshotIndexContext {
|
|
6
9
|
readonly runnerSandboxes: RunnerSandboxGateway;
|
|
7
10
|
readonly runnerTerminal: RunnerTerminal;
|
|
8
11
|
readonly timer: Timer;
|
|
9
12
|
}
|
|
10
|
-
/** The `purpose` tag of a
|
|
11
|
-
export declare function runnerPurpose(
|
|
12
|
-
/** The tags of a sandbox: the
|
|
13
|
-
export declare function runnerTags(
|
|
13
|
+
/** The `purpose` tag of a Vercel Sandbox runner's sandboxes. */
|
|
14
|
+
export declare function runnerPurpose(runnerName: string): string;
|
|
15
|
+
/** The tags of a sandbox: the runner's `purpose`, the local `user` who started it, and its `role`. */
|
|
16
|
+
export declare function runnerTags(runnerName: string, role: RunnerSandboxRole, user: string): Readonly<Record<string, string>>;
|
|
17
|
+
/**
|
|
18
|
+
* The 5 tags of a named build sandbox kept stopped as a shared snapshot index entry: the runner's `purpose`, the
|
|
19
|
+
* `user` who built it, `role: "snapshot-index"`, its `base` commit SHA, and `expires-at`.
|
|
20
|
+
*/
|
|
21
|
+
export declare function snapshotIndexTags(runnerName: string, user: string, base: string, expiresAt: string): Readonly<Record<string, string>>;
|
package/dist/runner/context.js
CHANGED
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
// What the runner reaches the world through as it readies and uses a runner sandbox, and the tags every sandbox it
|
|
2
2
|
// creates carries.
|
|
3
|
-
/** The `purpose` tag of a
|
|
4
|
-
export function runnerPurpose(
|
|
5
|
-
return `storm-runner-${
|
|
3
|
+
/** The `purpose` tag of a Vercel Sandbox runner's sandboxes. */
|
|
4
|
+
export function runnerPurpose(runnerName) {
|
|
5
|
+
return `storm-runner-${runnerName}`;
|
|
6
6
|
}
|
|
7
|
-
/** The tags of a sandbox: the
|
|
8
|
-
export function runnerTags(
|
|
9
|
-
return { purpose: runnerPurpose(
|
|
7
|
+
/** The tags of a sandbox: the runner's `purpose`, the local `user` who started it, and its `role`. */
|
|
8
|
+
export function runnerTags(runnerName, role, user) {
|
|
9
|
+
return { purpose: runnerPurpose(runnerName), user, role };
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The 5 tags of a named build sandbox kept stopped as a shared snapshot index entry: the runner's `purpose`, the
|
|
13
|
+
* `user` who built it, `role: "snapshot-index"`, its `base` commit SHA, and `expires-at`.
|
|
14
|
+
*/
|
|
15
|
+
export function snapshotIndexTags(runnerName, user, base, expiresAt) {
|
|
16
|
+
return {
|
|
17
|
+
purpose: runnerPurpose(runnerName),
|
|
18
|
+
user,
|
|
19
|
+
role: "snapshot-index",
|
|
20
|
+
base,
|
|
21
|
+
"expires-at": expiresAt,
|
|
22
|
+
};
|
|
10
23
|
}
|