@cnc-tools/storm 0.15.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/application.d.ts +22 -13
- package/dist/application.js +21 -10
- package/dist/bin/run.d.ts +18 -0
- package/dist/bin/run.js +31 -0
- package/dist/bin/storm.js +42 -26
- package/dist/build-info.js +1 -1
- package/dist/chunks/{chunk-5CCP36QQ.js → chunk-2RNDPDTJ.js} +2 -2
- package/dist/chunks/chunk-2VP4GRJM.js +1219 -0
- package/dist/chunks/{chunk-SZEURWRS.js → chunk-4O5C2XGJ.js} +18 -15
- package/dist/chunks/{chunk-VL7WFTVQ.js → chunk-4WAMTUWZ.js} +419 -340
- package/dist/chunks/{chunk-QVS7HRU7.js → chunk-6UHIJXZG.js} +3 -3
- package/dist/chunks/{chunk-CN4EFA5J.js → chunk-72ZFEMAW.js} +1 -1
- package/dist/chunks/{chunk-4U4DZ7VG.js → chunk-7DZE67QM.js} +2 -2
- package/dist/chunks/{chunk-VUPZH7J2.js → chunk-BCBKYOHW.js} +1 -1
- package/dist/chunks/{chunk-QUHY6FGN.js → chunk-CKGZA25H.js} +1 -18
- package/dist/chunks/{chunk-ZG3WQ4UF.js → chunk-D27KILIA.js} +1 -1
- package/dist/chunks/{chunk-KC4KDJ5K.js → chunk-DADEYJDW.js} +174 -153
- package/dist/chunks/{chunk-R7XVBZOY.js → chunk-EEENLQHE.js} +59 -11
- package/dist/chunks/chunk-F4MOYHRY.js +198 -0
- package/dist/chunks/{chunk-CXAT7ZKP.js → chunk-FNBB6V4R.js} +1 -1
- package/dist/chunks/{chunk-OX7X4B2L.js → chunk-GRT3UIBV.js} +18 -1
- package/dist/chunks/chunk-HP3CURSZ.js +88 -0
- package/dist/chunks/{chunk-PN5ULTTH.js → chunk-HWIQ2S7K.js} +5 -5
- package/dist/chunks/chunk-JN3YY6ZH.js +2166 -0
- package/dist/chunks/{chunk-TJNFVNKR.js → chunk-LKTZ5OXS.js} +1 -1
- package/dist/chunks/{chunk-XEVHP5ZW.js → chunk-M7EKRGVD.js} +8 -8
- package/dist/chunks/chunk-MR77L2GK.js +340 -0
- package/dist/chunks/{chunk-L36GBUBB.js → chunk-RNAS7JHE.js} +1755 -522
- package/dist/chunks/{chunk-5GBMR4HM.js → chunk-RWIXDDCK.js} +4 -192
- package/dist/chunks/{chunk-5VXBKPW6.js → chunk-WV3DP6NR.js} +1 -1
- package/dist/chunks/{chunk-AWBSONHB.js → chunk-XBDRVFEV.js} +55 -16
- package/dist/chunks/{chunk-YV7GE6EV.js → chunk-YEPFSLQR.js} +480 -375
- package/dist/chunks/{live-app-PI3BAN6Y.js → live-app-R76JQXZL.js} +15 -13
- package/dist/commands/exec/across-sandboxes-outcomes.d.ts +1 -1
- package/dist/commands/exec/across-sandboxes-outcomes.js +4 -3
- package/dist/commands/exec/before-run.d.ts +123 -0
- package/dist/commands/exec/before-run.js +105 -0
- package/dist/commands/exec/command.d.ts +39 -4
- package/dist/commands/exec/command.js +31 -95
- package/dist/commands/exec/driver-plan.d.ts +9 -4
- package/dist/commands/exec/driver-plan.js +8 -8
- package/dist/commands/exec/exec-words.js +1 -1
- package/dist/commands/exec/execute-run.d.ts +39 -0
- package/dist/commands/exec/execute-run.js +325 -0
- package/dist/commands/exec/live-view.d.ts +3 -3
- package/dist/commands/exec/live-view.js +16 -15
- package/dist/commands/exec/metadata.js +1 -1
- package/dist/commands/exec/mint-failed.d.ts +38 -0
- package/dist/commands/exec/mint-failed.js +27 -4
- package/dist/commands/exec/outcomes.d.ts +38 -9
- package/dist/commands/exec/outcomes.js +32 -25
- package/dist/commands/exec/plan-run.d.ts +58 -150
- package/dist/commands/exec/plan-run.js +232 -88
- package/dist/commands/exec/planned-outcome.js +8 -1
- package/dist/commands/exec/progress.d.ts +10 -6
- package/dist/commands/exec/progress.js +38 -25
- package/dist/commands/exec/run-bin.d.ts +11 -11
- package/dist/commands/exec/run-bin.js +9 -9
- package/dist/commands/exec/run-flags.d.ts +69 -0
- package/dist/commands/exec/run-flags.js +58 -0
- package/dist/commands/exec/run-metadata.js +5 -5
- package/dist/commands/exec/run-summary.d.ts +58 -0
- package/dist/commands/exec/run-summary.js +205 -0
- package/dist/commands/exec/runner-refusals.d.ts +82 -0
- package/dist/commands/exec/runner-refusals.js +71 -0
- package/dist/commands/exec/sandbox-progress.js +3 -0
- package/dist/commands/exec/stopped-outcome.d.ts +12 -0
- package/dist/commands/exec/stopped-outcome.js +77 -0
- package/dist/commands/exec/view.d.ts +20 -11
- package/dist/commands/exec/view.js +103 -47
- package/dist/commands/runs/facts.d.ts +9 -4
- package/dist/commands/runs/facts.js +28 -11
- package/dist/commands/runs/list/command.d.ts +16 -6
- package/dist/commands/runs/list/command.js +10 -10
- package/dist/commands/runs/list/outcomes.d.ts +8 -3
- package/dist/commands/runs/logs/command.d.ts +6 -2
- package/dist/commands/runs/logs/command.js +10 -10
- package/dist/commands/runs/logs/outcomes.d.ts +3 -1
- package/dist/commands/runs/past-run.d.ts +14 -5
- package/dist/commands/runs/past-run.js +16 -5
- package/dist/commands/runs/show/command.d.ts +20 -8
- package/dist/commands/runs/show/command.js +30 -28
- package/dist/commands/runs/show/outcomes.d.ts +10 -4
- package/dist/commands/runs/show/outcomes.js +7 -5
- package/dist/commands/snapshots/access.d.ts +111 -0
- package/dist/commands/snapshots/access.js +96 -0
- package/dist/commands/snapshots/build/command.d.ts +360 -93
- package/dist/commands/snapshots/build/command.js +446 -150
- package/dist/commands/snapshots/build/metadata.d.ts +10 -0
- package/dist/commands/snapshots/build/metadata.js +31 -11
- package/dist/commands/snapshots/build/outcomes.d.ts +234 -43
- package/dist/commands/snapshots/build/outcomes.js +200 -36
- package/dist/commands/snapshots/list/command.d.ts +368 -27
- package/dist/commands/snapshots/list/command.js +296 -66
- package/dist/commands/snapshots/list/metadata.d.ts +16 -0
- package/dist/commands/snapshots/list/metadata.js +29 -6
- package/dist/commands/snapshots/list/outcomes.d.ts +245 -13
- package/dist/commands/snapshots/list/outcomes.js +221 -50
- package/dist/commands/snapshots/metadata.js +1 -1
- package/dist/commands/snapshots/prune/command.d.ts +430 -0
- package/dist/commands/snapshots/prune/command.js +161 -0
- package/dist/commands/snapshots/prune/metadata.d.ts +28 -0
- package/dist/commands/snapshots/prune/metadata.js +39 -0
- package/dist/commands/snapshots/prune/outcomes.d.ts +208 -0
- package/dist/commands/snapshots/prune/outcomes.js +78 -0
- package/dist/commands/suites/list/command.js +19 -18
- package/dist/commands/suites/list/outcomes.js +4 -4
- package/dist/commands/test/command.d.ts +39 -4
- package/dist/commands/test/command.js +50 -255
- package/dist/commands/test/metadata.js +1 -1
- package/dist/commands/test/outcomes.d.ts +19 -2
- package/dist/commands/test/outcomes.js +2 -2
- package/dist/config/check-runner.d.ts +5 -3
- package/dist/config/check-runner.js +33 -7
- package/dist/config/check-suites.js +1 -0
- package/dist/config/credential-resolver.d.ts +50 -5
- package/dist/config/credential-resolver.js +51 -19
- package/dist/config/credential-settle.d.ts +6 -2
- package/dist/config/credential-settle.js +11 -5
- package/dist/config/gateways.d.ts +7 -3
- package/dist/config/index.d.ts +4 -5
- package/dist/config/index.js +3 -4
- package/dist/config/live/config-gateway.js +5 -2
- package/dist/config/load.d.ts +21 -4
- package/dist/config/load.js +129 -15
- package/dist/config/runner.d.ts +7 -8
- package/dist/config/runner.js +1 -1
- package/dist/config/schema.d.ts +17 -5
- package/dist/config/schema.js +11 -3
- package/dist/config/typed-options.d.ts +1 -6
- package/dist/config/typed-options.js +2 -10
- package/dist/config-file/define.d.ts +1 -11
- package/dist/config-file/define.js +3 -3
- package/dist/config-file/runner.d.ts +5 -6
- package/dist/config-file/toolchain.d.ts +13 -7
- package/dist/config-file/toolchain.js +53 -37
- package/dist/context.d.ts +8 -6
- package/dist/context.js +7 -6
- package/dist/core/across-sandboxes.d.ts +7 -6
- package/dist/core/across-sandboxes.js +123 -152
- package/dist/core/coordinator.d.ts +166 -0
- package/dist/core/coordinator.js +233 -0
- package/dist/core/events.d.ts +2 -2
- package/dist/core/index.d.ts +4 -2
- package/dist/core/index.js +1 -1
- package/dist/core/outcomes.d.ts +148 -0
- package/dist/core/{sandbox-end.js → outcomes.js} +28 -4
- package/dist/core/resources.d.ts +31 -53
- package/dist/core/resources.js +32 -70
- package/dist/core/run-state.d.ts +7 -1
- package/dist/core/run-state.js +2 -0
- package/dist/core/run.d.ts +32 -236
- package/dist/core/run.js +106 -266
- package/dist/core/state-directory.d.ts +1 -1
- package/dist/core/state-directory.js +2 -2
- package/dist/credential/gateways.d.ts +15 -1
- package/dist/credential/index.d.ts +4 -3
- package/dist/credential/index.js +3 -2
- package/dist/credential/live/vercel-cli-gateway.d.ts +1 -1
- package/dist/credential/live/vercel-cli-gateway.js +1 -1
- package/dist/credential/live/vercel-oidc-token-gateway.d.ts +11 -0
- package/dist/credential/live/vercel-oidc-token-gateway.js +16 -0
- package/dist/credential/source.d.ts +73 -6
- package/dist/credential/source.js +55 -2
- package/dist/extension-commands.d.ts +6 -1
- package/dist/extension-commands.js +15 -1
- package/dist/extensions/github/resource.d.ts +1 -1
- package/dist/extensions/github/resource.js +1 -1
- package/dist/extensions/testserver/commands/pool/create/command.d.ts +35 -2
- package/dist/extensions/testserver/commands/pool/create/command.js +7 -7
- package/dist/extensions/testserver/commands/pool/create/metadata.js +5 -5
- package/dist/extensions/testserver/commands/pool/create/outcomes.d.ts +17 -1
- package/dist/extensions/testserver/commands/pool/list/command.js +4 -4
- package/dist/extensions/testserver/credential-facts.d.ts +6 -2
- package/dist/extensions/testserver/credential-facts.js +29 -11
- package/dist/extensions/testserver/lifecycle.js +7 -1
- package/dist/extensions/testserver/limit.d.ts +3 -0
- package/dist/extensions/testserver/limit.js +3 -0
- package/dist/extensions/testserver/provision.d.ts +8 -1
- package/dist/extensions/testserver/provision.js +8 -3
- package/dist/extensions/testserver/refusals.d.ts +6 -1
- package/dist/extensions/testserver/refusals.js +16 -1
- package/dist/extensions/testserver/resource.d.ts +2 -2
- package/dist/extensions/testserver/resource.js +2 -2
- package/dist/extensions/testserver/result.d.ts +1 -1
- package/dist/extensions/testserver/result.js +9 -4
- package/dist/planning/driver-file-lists.d.ts +0 -15
- package/dist/planning/driver-file-lists.js +2 -21
- package/dist/planning/plan-only.d.ts +7 -15
- package/dist/planning/plan-only.js +16 -22
- package/dist/planning/run-kind-flags.js +2 -2
- package/dist/planning/run-plan.d.ts +45 -13
- package/dist/planning/run-plan.js +4 -3
- package/dist/planning/suites.d.ts +1 -1
- package/dist/planning/suites.js +2 -2
- package/dist/planning/test-plan.d.ts +9 -0
- package/dist/planning/test-plan.js +10 -2
- package/dist/run-directory/recording.js +2 -2
- package/dist/run-directory/run-record.d.ts +21 -6
- package/dist/run-directory/run-record.js +12 -9
- package/dist/runner/base.d.ts +0 -6
- package/dist/runner/base.js +1 -16
- package/dist/runner/build-snapshots.d.ts +55 -29
- package/dist/runner/build-snapshots.js +135 -35
- package/dist/runner/context.d.ts +15 -7
- package/dist/runner/context.js +19 -6
- package/dist/runner/events.d.ts +16 -10
- package/dist/runner/gateways.d.ts +92 -21
- package/dist/runner/gateways.js +1 -1
- package/dist/runner/index.d.ts +11 -7
- package/dist/runner/index.js +9 -4
- package/dist/runner/live/sandbox-errors.d.ts +2 -0
- package/dist/runner/live/sandbox-errors.js +4 -0
- package/dist/runner/live/sandbox-gateway.js +141 -3
- package/dist/runner/live/snapshot-index-gateway.d.ts +12 -0
- package/dist/runner/live/{snapshot-cache-gateway.js → snapshot-index-gateway.js} +11 -11
- package/dist/runner/live/snapshot-records.js +6 -7
- package/dist/runner/local-snapshot-index.d.ts +199 -0
- package/dist/runner/local-snapshot-index.js +211 -0
- package/dist/runner/network-policy.d.ts +6 -6
- package/dist/runner/network-policy.js +7 -7
- package/dist/runner/policy-writes.d.ts +1 -1
- package/dist/runner/policy-writes.js +1 -1
- package/dist/runner/prepare.d.ts +25 -24
- package/dist/runner/prepare.js +28 -20
- package/dist/runner/ready.d.ts +18 -10
- package/dist/runner/ready.js +104 -33
- package/dist/runner/sandboxed-command.d.ts +3 -3
- package/dist/runner/sandboxed-command.js +3 -3
- package/dist/runner/scope.d.ts +10 -6
- package/dist/runner/scope.js +10 -3
- package/dist/runner/secrets.d.ts +13 -13
- package/dist/runner/secrets.js +18 -15
- package/dist/runner/session.d.ts +8 -8
- package/dist/runner/session.js +3 -3
- package/dist/runner/shared-snapshot-entry.d.ts +92 -0
- package/dist/runner/shared-snapshot-entry.js +168 -0
- package/dist/runner/shared-snapshot-list.d.ts +81 -0
- package/dist/runner/shared-snapshot-list.js +155 -0
- package/dist/runner/shared-snapshot-lookup.d.ts +51 -0
- package/dist/runner/shared-snapshot-lookup.js +118 -0
- package/dist/runner/shared-snapshot-prune.d.ts +58 -0
- package/dist/runner/shared-snapshot-prune.js +133 -0
- package/dist/runner/snapshot-build.d.ts +42 -14
- package/dist/runner/snapshot-build.js +38 -28
- package/dist/runner/snapshot-choice.js +1 -1
- package/dist/runner/snapshot-inspect.d.ts +39 -40
- package/dist/runner/snapshot-inspect.js +58 -38
- package/dist/runner/snapshot-key.d.ts +30 -21
- package/dist/runner/snapshot-key.js +49 -29
- package/dist/runner/steps.d.ts +1 -1
- package/dist/runner/steps.js +1 -1
- package/dist/runner/{recipe-check.d.ts → vercel-sandbox-check.d.ts} +2 -2
- package/dist/runner/{recipe-check.js → vercel-sandbox-check.js} +3 -2
- package/dist/runner/{recipe.d.ts → vercel-sandbox-options.d.ts} +82 -82
- package/dist/runner/vercel-sandbox-options.js +510 -0
- package/dist/runner/{recipe-secrets.d.ts → vercel-sandbox-secrets.d.ts} +6 -6
- package/dist/runner/{recipe-secrets.js → vercel-sandbox-secrets.js} +20 -20
- package/dist/sdk/extension/commands.d.ts +8 -3
- package/dist/sdk/extension/commands.js +3 -1
- package/dist/sdk/extension/credential-diagnosis.d.ts +3 -1
- package/dist/sdk/extension/credential-diagnosis.js +25 -5
- package/dist/sdk/extension/credential-source.d.ts +20 -3
- package/dist/sdk/extension/credential-source.js +4 -4
- package/dist/sdk/extension/index.d.ts +3 -2
- package/dist/sdk/extension/index.js +2 -1
- package/dist/sdk/extension/resource-definition.d.ts +4 -3
- package/dist/sdk/extension/resource-definition.js +3 -2
- package/dist/sdk/extension/resource-factory.js +3 -4
- package/dist/sdk/extension/secret-source.d.ts +1 -1
- package/dist/sdk/extension/secret-source.js +1 -1
- package/dist/sdk/extension/vercel-oidc-facts.d.ts +20 -0
- package/dist/sdk/extension/vercel-oidc-facts.js +20 -0
- package/dist/sdk/run/present.d.ts +3 -3
- package/dist/sdk/run/present.js +1 -3
- package/dist/shared/cleanup.d.ts +3 -3
- package/dist/shared/cleanup.js +15 -5
- package/dist/shared/snapshot-text.d.ts +4 -4
- package/dist/shared/snapshot-text.js +11 -11
- package/dist/time/duration.js +1 -1
- package/package.json +3 -2
- package/skills/overview.md +6 -4
- package/skills/plan-runs.md +2 -2
- package/skills/read-run-output.md +6 -6
- package/dist/chunks/chunk-E4PJNZVG.js +0 -783
- package/dist/chunks/chunk-RAQEXKL6.js +0 -2591
- package/dist/commands/exec/across-sandboxes-run.d.ts +0 -180
- package/dist/commands/exec/across-sandboxes-run.js +0 -339
- package/dist/commands/exec/plan-only.d.ts +0 -10
- package/dist/commands/exec/plan-only.js +0 -46
- package/dist/commands/exec/run-command.d.ts +0 -476
- package/dist/commands/exec/run-command.js +0 -604
- package/dist/commands/exec/run-planned.d.ts +0 -20
- package/dist/commands/exec/run-planned.js +0 -22
- package/dist/commands/exec/sandbox-view.d.ts +0 -19
- package/dist/commands/exec/sandbox-view.js +0 -72
- package/dist/commands/test/plan.d.ts +0 -92
- package/dist/commands/test/plan.js +0 -128
- package/dist/config/recipe-run.d.ts +0 -33
- package/dist/config/recipe-run.js +0 -28
- package/dist/core/sandbox-end.d.ts +0 -64
- package/dist/runner/live/snapshot-cache-gateway.d.ts +0 -12
- package/dist/runner/recipe.js +0 -425
- package/dist/runner/snapshot-cache.d.ts +0 -148
- package/dist/runner/snapshot-cache.js +0 -126
package/dist/runner/secrets.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
// The values of the
|
|
1
|
+
// The values of the runner's credentials and unsafe secret environment variables: read from each entry's secret source
|
|
2
2
|
// on this machine as the run settles, turned into the sandbox credentials the Sandbox firewall adds to the requests of
|
|
3
3
|
// everything the run does in a sandbox (the steps and the command, for `credentials`) or passed into the command's
|
|
4
4
|
// environment alone (for `unsafeSecretEnvVars`), and hidden as `<token>` in what the run prints and writes (`README.md`).
|
|
5
5
|
import { describeSecretSource, readSecretSource, readSecretSourceValue, SECRET_MIN_LENGTH, secretSourceId, } from "../sdk/extension/index.js";
|
|
6
6
|
export { SECRET_MIN_LENGTH };
|
|
7
7
|
/**
|
|
8
|
-
* The value of each credential and unsafe secret environment variable `
|
|
8
|
+
* The value of each credential and unsafe secret environment variable `options` declares that `env` sets, whatever a
|
|
9
9
|
* run would say of it: for a command that hides the values in what it prints but needs none, such as `storm snapshots
|
|
10
10
|
* list` or `storm snapshots build`. A short or multiline value is kept, since hiding it there is safer than showing it.
|
|
11
11
|
*/
|
|
12
|
-
export function declaredSecretValues(
|
|
13
|
-
if (
|
|
12
|
+
export function declaredSecretValues(options, env) {
|
|
13
|
+
if (options === undefined)
|
|
14
14
|
return [];
|
|
15
15
|
const seen = new Set();
|
|
16
16
|
const values = [];
|
|
17
|
-
for (const { source } of [...
|
|
17
|
+
for (const { source } of [...options.credentials, ...options.unsafeSecretEnvVars]) {
|
|
18
18
|
const id = secretSourceId(source);
|
|
19
19
|
if (seen.has(id))
|
|
20
20
|
continue;
|
|
@@ -26,15 +26,15 @@ export function declaredSecretValues(recipe, env) {
|
|
|
26
26
|
return values;
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
|
-
* Reads each of `
|
|
29
|
+
* Reads each of `options`'s credentials' values from `env`, the environment of the machine the run starts on, through
|
|
30
30
|
* `readSecretSource`: each `{ kind: "env", name }` source holds the whole header value, such as `Bearer …`. It answers
|
|
31
|
-
* the sandbox credentials the
|
|
32
|
-
* order, each with its domain, header, and `requests` from the
|
|
33
|
-
* `missing`, `multiline`, and `short`, and a source two credentials share is read and reported once in
|
|
34
|
-
* order. A value is used as it is, never trimmed.
|
|
31
|
+
* the sandbox credentials the runner's steps and the command run under, one per declared credential, in the runner's
|
|
32
|
+
* order, each with its domain, header, and `requests` from the runner options. A source's problem is the first that
|
|
33
|
+
* holds of `missing`, `multiline`, and `short`, and a source two credentials share is read and reported once in
|
|
34
|
+
* first-seen order. A value is used as it is, never trimmed.
|
|
35
35
|
*/
|
|
36
|
-
export function readCredentials(
|
|
37
|
-
const read = readUniqueSources(
|
|
36
|
+
export function readCredentials(options, env) {
|
|
37
|
+
const read = readUniqueSources(options.credentials, env, ({ domain, header, requests }, value) => ({
|
|
38
38
|
domain,
|
|
39
39
|
header,
|
|
40
40
|
value,
|
|
@@ -43,13 +43,16 @@ export function readCredentials(recipe, env) {
|
|
|
43
43
|
return read.ok ? { ok: true, credentials: read.items } : read;
|
|
44
44
|
}
|
|
45
45
|
/**
|
|
46
|
-
* Reads each of `
|
|
46
|
+
* Reads each of `options`'s unsafe secret environment variables (`runner.unsafeSecretEnvVars`) from `env`, the
|
|
47
47
|
* environment of the machine the run starts on, through `readSecretSource`, and maps each value to `entry.name` for
|
|
48
48
|
* the command's environment. A source's problem is the first that holds of `missing`, `multiline`, and `short`, and a
|
|
49
49
|
* source two entries share is read and reported once in first-seen order. A value is used as it is, never trimmed.
|
|
50
50
|
*/
|
|
51
|
-
export function readUnsafeSecretEnvVars(
|
|
52
|
-
const read = readUniqueSources(
|
|
51
|
+
export function readUnsafeSecretEnvVars(options, env) {
|
|
52
|
+
const read = readUniqueSources(options.unsafeSecretEnvVars, env, ({ name }, value) => [
|
|
53
|
+
name,
|
|
54
|
+
value,
|
|
55
|
+
]);
|
|
53
56
|
return read.ok ? { ok: true, values: Object.fromEntries(read.items) } : read;
|
|
54
57
|
}
|
|
55
58
|
/**
|
package/dist/runner/session.d.ts
CHANGED
|
@@ -12,12 +12,12 @@ import type { UnsafeSecretEnvVarMap } from "./secrets.ts";
|
|
|
12
12
|
export interface RunnerSessionRequest {
|
|
13
13
|
/** The runner checked on this machine (`prepareRunner`). */
|
|
14
14
|
readonly prepared: PreparedRunner;
|
|
15
|
-
/** The team and project the run's credential is minted for
|
|
16
|
-
readonly target: MintTarget;
|
|
15
|
+
/** The team and project the run's credential is minted for, or null when using `vercel-oidc` without `--scope`/`--project`. */
|
|
16
|
+
readonly target: MintTarget | null;
|
|
17
17
|
/** The local user name, for each sandbox's `user` tag. */
|
|
18
18
|
readonly user: string;
|
|
19
19
|
/**
|
|
20
|
-
* The
|
|
20
|
+
* The runner's credentials, with their values read from this machine's environment as the run started
|
|
21
21
|
* (`readCredentials`): the firewall adds every one to the requests of everything the run does in a sandbox—a build's
|
|
22
22
|
* toolchain and prebuild steps, and the install, build, and command. No value enters a sandbox, and storm writes none
|
|
23
23
|
* to the run directory, the snapshot cache, or `run.json`.
|
|
@@ -51,9 +51,9 @@ export interface RunnerSessionCleanup {
|
|
|
51
51
|
readonly startCleanup: () => Promise<void>;
|
|
52
52
|
readonly release: (runner: RunnerFenceOutcome) => Promise<void>;
|
|
53
53
|
}
|
|
54
|
-
/** What closing a session's sandbox scope left, and the team and project its sandboxes are in
|
|
54
|
+
/** What closing a session's sandbox scope left, and the team and project its sandboxes are in when known. */
|
|
55
55
|
export interface RunnerCleanupFacts extends RunnerScopeFacts {
|
|
56
|
-
readonly target: MintTarget;
|
|
56
|
+
readonly target: MintTarget | null;
|
|
57
57
|
}
|
|
58
58
|
/**
|
|
59
59
|
* One run's runner session, open from before the run mints. Its stages run in this order: `ready`, then `runCommand` in
|
|
@@ -64,7 +64,7 @@ export interface RunnerCleanupFacts extends RunnerScopeFacts {
|
|
|
64
64
|
export interface RunnerSession {
|
|
65
65
|
/**
|
|
66
66
|
* Readies the runner sandbox (`readyRunner`): reuses the cached runner snapshot it picks or builds a base snapshot,
|
|
67
|
-
* starts the runner sandbox from it, uploads and applies the run's changes, grants it the
|
|
67
|
+
* starts the runner sandbox from it, uploads and applies the run's changes, grants it the runner's credentials, and
|
|
68
68
|
* runs the install and build. With a snapshot the run already chose, it picks and builds none (`readyFromSnapshot`).
|
|
69
69
|
* The credentials stay in place for the command; when the run ends before the command, the scope's fence revokes
|
|
70
70
|
* them. `signal` stops it. Called once.
|
|
@@ -74,9 +74,9 @@ export interface RunnerSession {
|
|
|
74
74
|
* Runs the command in the runner sandbox `ready` readied (`runCommandInSandbox`); canceling the run kills it. It
|
|
75
75
|
* throws when `ready` hasn't answered `ready`, a mistake in the caller.
|
|
76
76
|
*
|
|
77
|
-
* The
|
|
77
|
+
* The runner's credentials, which `ready` granted, are still in place as the command starts. With `credentials`, the
|
|
78
78
|
* sandbox credentials the run's resources give the command, each with its own `requests`, the sandbox scope first
|
|
79
|
-
* grants the
|
|
79
|
+
* grants the runner's and the resources' together, in one write (`RunnerSandboxScope.grantCredentials`); with none,
|
|
80
80
|
* it writes no policy before the command. A failed grant means the command doesn't run: it answers `failed` with
|
|
81
81
|
* `network-policy-failed` (`operation: "inject"`, `around: "command"`), or `killed` when the signal stopped it. Once
|
|
82
82
|
* the command has ended, or didn't run, the scope revokes every credential in the runner sandbox when anything was
|
package/dist/runner/session.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// A runner session: owns a run's sandbox scope from before minting through cleanup, readying the runner sandbox,
|
|
2
|
-
// running the command with
|
|
2
|
+
// running the command with runner and resource credentials, and running cleanup in order (`startCleanup`,
|
|
3
3
|
// `scope.fence`, resource `release`, `scope.close`). See `README.md` ("Runner session, readying, and command").
|
|
4
4
|
import { runnerNetworkPolicy } from "./network-policy.js";
|
|
5
5
|
import { readyFromSnapshot, readyRunner, } from "./ready.js";
|
|
@@ -22,7 +22,7 @@ export function openRunnerSession(context, request, control, progress) {
|
|
|
22
22
|
// When the run is canceled, the scope reports `stopping` and revokes every credential at once.
|
|
23
23
|
const scope = runnerSandboxScope(context, progress, {
|
|
24
24
|
keepMs: request.keepMs,
|
|
25
|
-
basePolicy: runnerNetworkPolicy(request.prepared.
|
|
25
|
+
basePolicy: runnerNetworkPolicy(request.prepared.options),
|
|
26
26
|
signal,
|
|
27
27
|
commandRunning: () => commandRunning,
|
|
28
28
|
});
|
|
@@ -79,7 +79,7 @@ export function openRunnerSession(context, request, control, progress) {
|
|
|
79
79
|
...(command.testEvents === undefined ? {} : { testEvents: command.testEvents }),
|
|
80
80
|
}, { kill: signal }, progress);
|
|
81
81
|
const resourceCredentials = command.credentials ?? [];
|
|
82
|
-
// `ready` answered `ready`, so it granted the
|
|
82
|
+
// `ready` answered `ready`, so it granted the runner's credentials, when there are any.
|
|
83
83
|
const granted = request.credentials.length > 0 || resourceCredentials.length > 0;
|
|
84
84
|
try {
|
|
85
85
|
if (resourceCredentials.length > 0) {
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { NamedSandboxInfo, RunnerSnapshotEntry, SandboxAccess, SnapshotInfo, SnapshotLookup } from "./gateways.ts";
|
|
2
|
+
import type { CheckedVercelSandboxOptions } from "./vercel-sandbox-options.ts";
|
|
3
|
+
/** The name prefix of every named sandbox that serves as a shared snapshot index entry. */
|
|
4
|
+
export declare const SHARED_SNAPSHOT_SANDBOX_PREFIX = "storm-snap-";
|
|
5
|
+
/** Maximum number of concurrent Sandbox API or Git calls when scanning shared snapshot index entries. */
|
|
6
|
+
export declare const INDEX_CONCURRENCY = 8;
|
|
7
|
+
/** What identifies one bucket of shared runner snapshots in a Vercel project. */
|
|
8
|
+
export interface SharedSnapshotBucketInput {
|
|
9
|
+
readonly teamId: string;
|
|
10
|
+
readonly projectId: string;
|
|
11
|
+
readonly region: string;
|
|
12
|
+
readonly runtime: string;
|
|
13
|
+
readonly runnerName: string;
|
|
14
|
+
readonly snapshotKey: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The 16-hex-character bucket identifier for `input`: the first 16 hex characters of sha256 over its team ID, project
|
|
18
|
+
* ID, region, runtime, runner name, and snapshot key, joined with NUL.
|
|
19
|
+
*/
|
|
20
|
+
export declare function sharedSnapshotBucket(input: SharedSnapshotBucketInput): string;
|
|
21
|
+
/** The name prefix shared by every named sandbox in `bucket`. */
|
|
22
|
+
export declare function sharedSnapshotSandboxPrefix(bucket: string): string;
|
|
23
|
+
/** The named sandbox name for a shared snapshot at commit `base` in `bucket`. */
|
|
24
|
+
export declare function sharedSnapshotSandboxName(bucket: string, base: string): string;
|
|
25
|
+
/** The bucket and base commit SHA parsed from a shared snapshot sandbox name. */
|
|
26
|
+
export interface ParsedSharedSnapshotName {
|
|
27
|
+
readonly bucket: string;
|
|
28
|
+
readonly base: string;
|
|
29
|
+
}
|
|
30
|
+
/** Parses `name` as `storm-snap-<16-hex-bucket>-<40-hex-base>`, or null when it does not match. */
|
|
31
|
+
export declare function parseSharedSnapshotSandboxName(name: string): ParsedSharedSnapshotName | null;
|
|
32
|
+
/**
|
|
33
|
+
* The verified state of one shared snapshot index entry:
|
|
34
|
+
*
|
|
35
|
+
* - `ready`: the sandbox is stopped and its snapshot exists with status `created` and more than an hour left.
|
|
36
|
+
* - `expires-soon`: the sandbox is stopped and its snapshot exists with status `created` and has not expired, but has
|
|
37
|
+
* an hour or less left (so a run will not start from it).
|
|
38
|
+
* - `unknown-expiry`: the sandbox is stopped and its snapshot exists with status `created`, but neither the snapshot
|
|
39
|
+
* nor the sandbox's `expires-at` tag carries a valid expiry timestamp (so runs do not start from it and pruning
|
|
40
|
+
* skips it).
|
|
41
|
+
* - `building`: a build still owns the sandbox (`pending`, `running`, `snapshotting`, or `stopping`).
|
|
42
|
+
* - `expired`: the sandbox is stopped and its snapshot exists with status `created`, but has expired.
|
|
43
|
+
* - `missing`: the sandbox is stopped with a snapshot ID, but the snapshot is not found or not `created` (`deleted` or
|
|
44
|
+
* `failed`).
|
|
45
|
+
* - `no-snapshot`: the sandbox is stopped without a `currentSnapshotId`.
|
|
46
|
+
* - `failed`: the build sandbox ended in terminal `failed` or `aborted` status.
|
|
47
|
+
*/
|
|
48
|
+
export type SharedSnapshotStatus = "ready" | "expires-soon" | "unknown-expiry" | "building" | "expired" | "missing" | "no-snapshot" | "failed";
|
|
49
|
+
/**
|
|
50
|
+
* What can be determined from a named sandbox row before calling `getSnapshot`: either a final status (`building`,
|
|
51
|
+
* `failed`, or `no-snapshot`), or `needs-snapshot` with the `snapshotId` to verify.
|
|
52
|
+
*/
|
|
53
|
+
export type UnverifiedSharedSandboxState = {
|
|
54
|
+
readonly kind: "settled";
|
|
55
|
+
readonly status: "building" | "failed" | "no-snapshot";
|
|
56
|
+
} | {
|
|
57
|
+
readonly kind: "needs-snapshot";
|
|
58
|
+
readonly snapshotId: string;
|
|
59
|
+
};
|
|
60
|
+
/** Classifies `row` from its own sandbox status and `currentSnapshotId`, without calling `getSnapshot`. */
|
|
61
|
+
export declare function classifyUnverifiedSharedSandbox(row: NamedSandboxInfo): UnverifiedSharedSandboxState;
|
|
62
|
+
/** The canonical classification of a stopped named sandbox after looking up its snapshot via `getSnapshot`. */
|
|
63
|
+
export interface VerifiedSharedSnapshotState {
|
|
64
|
+
readonly status: "ready" | "expires-soon" | "unknown-expiry" | "expired" | "missing";
|
|
65
|
+
readonly snapshotId: string;
|
|
66
|
+
readonly snapshotStatus: string | undefined;
|
|
67
|
+
readonly createdAt: string;
|
|
68
|
+
readonly expiresAt: string | undefined;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Classifies a stopped named sandbox `row` (holding `currentSnapshotId`) given its `getSnapshot` `lookup` at `now`.
|
|
72
|
+
* Expiry always falls back from `snapshot.expiresAt` to `row.tags["expires-at"]`, so lookup, listing, and pruning
|
|
73
|
+
* agree on every entry.
|
|
74
|
+
*/
|
|
75
|
+
export declare function classifyVerifiedSharedSnapshot(row: NamedSandboxInfo & {
|
|
76
|
+
readonly currentSnapshotId: string;
|
|
77
|
+
}, lookup: SnapshotLookup, now: Date): VerifiedSharedSnapshotState;
|
|
78
|
+
/**
|
|
79
|
+
* The local snapshot index entry a shared snapshot index entry stands for: the named sandbox `sandbox`, kept stopped at
|
|
80
|
+
* `base`, and its snapshot `snapshot`. Null unless the canonical classifier marks it `ready` (status `created`, known
|
|
81
|
+
* expiry from `snapshot.expiresAt ?? sandbox.tags["expires-at"]`, and more than an hour left).
|
|
82
|
+
*/
|
|
83
|
+
export declare function usableSharedEntry(access: SandboxAccess, runner: Pick<CheckedVercelSandboxOptions, "name" | "region" | "runtime">, snapshotKey: string, base: string, sandbox: NamedSandboxInfo, snapshot: SnapshotInfo, now: Date): RunnerSnapshotEntry | null;
|
|
84
|
+
/**
|
|
85
|
+
* Runs `task` for indexes `0` to `count - 1`, at most `limit` at a time, in index order. Before starting each task it
|
|
86
|
+
* asks `proceed`; once that says no, no further task starts, and the ones in flight still finish.
|
|
87
|
+
*
|
|
88
|
+
* Its twin is the `runLimited` of an extension folder's `limit.ts`, with the same body. The layering leaves them no
|
|
89
|
+
* shared home: an extension folder imports storm only through the extension API, and the runner names no resource and
|
|
90
|
+
* imports no extension. Change both together.
|
|
91
|
+
*/
|
|
92
|
+
export declare function runLimited<T>(count: number, limit: number, proceed: () => boolean, task: (index: number) => Promise<T>): Promise<readonly (T | undefined)[]>;
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
// Shared snapshot index naming, bucketing, concurrency, and canonical entry classification. Each bucket hashes
|
|
2
|
+
// the team, project, region, runtime, runner name, and snapshot key into 16 hex characters, and each entry's named
|
|
3
|
+
// sandbox is `storm-snap-<bucket>-<base>`. Lookup, listing, publishing, and pruning share one status and expiry
|
|
4
|
+
// classifier so they never disagree on whether an entry is usable or expired.
|
|
5
|
+
import { createHash } from "node:crypto";
|
|
6
|
+
import { SNAPSHOT_MIN_REMAINING_MS } from "./local-snapshot-index.js";
|
|
7
|
+
/** The name prefix of every named sandbox that serves as a shared snapshot index entry. */
|
|
8
|
+
export const SHARED_SNAPSHOT_SANDBOX_PREFIX = "storm-snap-";
|
|
9
|
+
const SHARED_SNAPSHOT_NAME_PATTERN = /^storm-snap-([0-9a-f]{16})-([0-9a-f]{40})$/;
|
|
10
|
+
/** Maximum number of concurrent Sandbox API or Git calls when scanning shared snapshot index entries. */
|
|
11
|
+
export const INDEX_CONCURRENCY = 8;
|
|
12
|
+
/**
|
|
13
|
+
* Whether `status` means a build still owns the named sandbox (active or in progress). Exhaustive over
|
|
14
|
+
* `NamedSandboxStatus`: `stopped` is a completed entry, and `failed`/`aborted` are dead entries eligible for pruning
|
|
15
|
+
* or replacement.
|
|
16
|
+
*/
|
|
17
|
+
function isBuildingSandboxStatus(status) {
|
|
18
|
+
switch (status) {
|
|
19
|
+
case "pending":
|
|
20
|
+
case "running":
|
|
21
|
+
case "snapshotting":
|
|
22
|
+
case "stopping":
|
|
23
|
+
return true;
|
|
24
|
+
case "stopped":
|
|
25
|
+
case "failed":
|
|
26
|
+
case "aborted":
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/** Whether `row` holds a non-empty `currentSnapshotId`. */
|
|
31
|
+
function hasSnapshotId(row) {
|
|
32
|
+
return row.currentSnapshotId !== undefined && row.currentSnapshotId !== "";
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The 16-hex-character bucket identifier for `input`: the first 16 hex characters of sha256 over its team ID, project
|
|
36
|
+
* ID, region, runtime, runner name, and snapshot key, joined with NUL.
|
|
37
|
+
*/
|
|
38
|
+
export function sharedSnapshotBucket(input) {
|
|
39
|
+
return createHash("sha256")
|
|
40
|
+
.update([input.teamId, input.projectId, input.region, input.runtime, input.runnerName, input.snapshotKey].join("\0"))
|
|
41
|
+
.digest("hex")
|
|
42
|
+
.slice(0, 16);
|
|
43
|
+
}
|
|
44
|
+
/** The name prefix shared by every named sandbox in `bucket`. */
|
|
45
|
+
export function sharedSnapshotSandboxPrefix(bucket) {
|
|
46
|
+
return `${SHARED_SNAPSHOT_SANDBOX_PREFIX}${bucket}-`;
|
|
47
|
+
}
|
|
48
|
+
/** The named sandbox name for a shared snapshot at commit `base` in `bucket`. */
|
|
49
|
+
export function sharedSnapshotSandboxName(bucket, base) {
|
|
50
|
+
return `${SHARED_SNAPSHOT_SANDBOX_PREFIX}${bucket}-${base}`;
|
|
51
|
+
}
|
|
52
|
+
/** Parses `name` as `storm-snap-<16-hex-bucket>-<40-hex-base>`, or null when it does not match. */
|
|
53
|
+
export function parseSharedSnapshotSandboxName(name) {
|
|
54
|
+
const match = SHARED_SNAPSHOT_NAME_PATTERN.exec(name);
|
|
55
|
+
if (match === null)
|
|
56
|
+
return null;
|
|
57
|
+
const [, bucket, base] = match;
|
|
58
|
+
if (bucket === undefined || base === undefined)
|
|
59
|
+
return null;
|
|
60
|
+
return { bucket, base };
|
|
61
|
+
}
|
|
62
|
+
/** Classifies `row` from its own sandbox status and `currentSnapshotId`, without calling `getSnapshot`. */
|
|
63
|
+
export function classifyUnverifiedSharedSandbox(row) {
|
|
64
|
+
if (isBuildingSandboxStatus(row.status))
|
|
65
|
+
return { kind: "settled", status: "building" };
|
|
66
|
+
if (row.status === "failed" || row.status === "aborted")
|
|
67
|
+
return { kind: "settled", status: "failed" };
|
|
68
|
+
if (!hasSnapshotId(row))
|
|
69
|
+
return { kind: "settled", status: "no-snapshot" };
|
|
70
|
+
return { kind: "needs-snapshot", snapshotId: row.currentSnapshotId };
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Classifies a stopped named sandbox `row` (holding `currentSnapshotId`) given its `getSnapshot` `lookup` at `now`.
|
|
74
|
+
* Expiry always falls back from `snapshot.expiresAt` to `row.tags["expires-at"]`, so lookup, listing, and pruning
|
|
75
|
+
* agree on every entry.
|
|
76
|
+
*/
|
|
77
|
+
export function classifyVerifiedSharedSnapshot(row, lookup, now) {
|
|
78
|
+
if (lookup.kind === "not-found") {
|
|
79
|
+
return {
|
|
80
|
+
status: "missing",
|
|
81
|
+
snapshotId: row.currentSnapshotId,
|
|
82
|
+
snapshotStatus: undefined,
|
|
83
|
+
createdAt: row.createdAt,
|
|
84
|
+
expiresAt: row.tags["expires-at"],
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
const { snapshot } = lookup;
|
|
88
|
+
const expiresAt = snapshot.expiresAt ?? row.tags["expires-at"];
|
|
89
|
+
if (snapshot.status !== "created") {
|
|
90
|
+
return {
|
|
91
|
+
status: "missing",
|
|
92
|
+
snapshotId: snapshot.snapshotId,
|
|
93
|
+
snapshotStatus: snapshot.status,
|
|
94
|
+
createdAt: snapshot.createdAt,
|
|
95
|
+
expiresAt,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
const expiresAtMs = expiresAt === undefined ? Number.NaN : Date.parse(expiresAt);
|
|
99
|
+
if (Number.isNaN(expiresAtMs)) {
|
|
100
|
+
return {
|
|
101
|
+
status: "unknown-expiry",
|
|
102
|
+
snapshotId: snapshot.snapshotId,
|
|
103
|
+
snapshotStatus: snapshot.status,
|
|
104
|
+
createdAt: snapshot.createdAt,
|
|
105
|
+
expiresAt,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
const nowMs = now.getTime();
|
|
109
|
+
const status = expiresAtMs <= nowMs ? "expired" : expiresAtMs - nowMs > SNAPSHOT_MIN_REMAINING_MS ? "ready" : "expires-soon";
|
|
110
|
+
return {
|
|
111
|
+
status,
|
|
112
|
+
snapshotId: snapshot.snapshotId,
|
|
113
|
+
snapshotStatus: snapshot.status,
|
|
114
|
+
createdAt: snapshot.createdAt,
|
|
115
|
+
expiresAt,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* The local snapshot index entry a shared snapshot index entry stands for: the named sandbox `sandbox`, kept stopped at
|
|
120
|
+
* `base`, and its snapshot `snapshot`. Null unless the canonical classifier marks it `ready` (status `created`, known
|
|
121
|
+
* expiry from `snapshot.expiresAt ?? sandbox.tags["expires-at"]`, and more than an hour left).
|
|
122
|
+
*/
|
|
123
|
+
export function usableSharedEntry(access, runner, snapshotKey, base, sandbox, snapshot, now) {
|
|
124
|
+
const verified = classifyVerifiedSharedSnapshot({ ...sandbox, currentSnapshotId: snapshot.snapshotId }, { kind: "found", snapshot }, now);
|
|
125
|
+
if (verified.status !== "ready" || verified.expiresAt === undefined)
|
|
126
|
+
return null;
|
|
127
|
+
return {
|
|
128
|
+
teamId: access.teamId,
|
|
129
|
+
projectId: access.projectId,
|
|
130
|
+
region: runner.region,
|
|
131
|
+
runtime: runner.runtime,
|
|
132
|
+
runnerName: runner.name,
|
|
133
|
+
snapshotKey,
|
|
134
|
+
base,
|
|
135
|
+
snapshotId: verified.snapshotId,
|
|
136
|
+
createdAt: verified.createdAt,
|
|
137
|
+
expiresAt: verified.expiresAt,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Runs `task` for indexes `0` to `count - 1`, at most `limit` at a time, in index order. Before starting each task it
|
|
142
|
+
* asks `proceed`; once that says no, no further task starts, and the ones in flight still finish.
|
|
143
|
+
*
|
|
144
|
+
* Its twin is the `runLimited` of an extension folder's `limit.ts`, with the same body. The layering leaves them no
|
|
145
|
+
* shared home: an extension folder imports storm only through the extension API, and the runner names no resource and
|
|
146
|
+
* imports no extension. Change both together.
|
|
147
|
+
*/
|
|
148
|
+
export async function runLimited(count, limit, proceed, task) {
|
|
149
|
+
const results = Array.from({ length: count }, () => undefined);
|
|
150
|
+
let failure;
|
|
151
|
+
let next = 0;
|
|
152
|
+
const worker = async () => {
|
|
153
|
+
while (failure === undefined && next < count && proceed()) {
|
|
154
|
+
const index = next;
|
|
155
|
+
next += 1;
|
|
156
|
+
try {
|
|
157
|
+
results[index] = await task(index);
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
failure ??= { error };
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
await Promise.all(Array.from({ length: Math.min(limit, count) }, worker));
|
|
165
|
+
if (failure !== undefined)
|
|
166
|
+
throw failure.error;
|
|
167
|
+
return results;
|
|
168
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { CheckoutFailure, NamedSandboxStatus, SandboxAccess } from "./gateways.ts";
|
|
2
|
+
import { type SharedSnapshotStatus } from "./shared-snapshot-entry.ts";
|
|
3
|
+
import type { SharedSnapshotLookupContext } from "./shared-snapshot-lookup.ts";
|
|
4
|
+
import type { InspectedSnapshot } from "./snapshot-inspect.ts";
|
|
5
|
+
import type { CheckedVercelSandboxOptions } from "./vercel-sandbox-options.ts";
|
|
6
|
+
/** What `listSharedSnapshots` queries in the shared snapshot index. */
|
|
7
|
+
export interface SharedSnapshotListRequest {
|
|
8
|
+
readonly access: SandboxAccess;
|
|
9
|
+
readonly runner: Pick<CheckedVercelSandboxOptions, "name" | "region" | "runtime">;
|
|
10
|
+
readonly snapshotKey: string;
|
|
11
|
+
}
|
|
12
|
+
/** One entry returned by `listSharedSnapshots`, verified against the Sandbox API when stopped with a snapshot ID. */
|
|
13
|
+
export interface SharedSnapshotIndexEntry {
|
|
14
|
+
readonly sandboxName: string;
|
|
15
|
+
readonly base: string;
|
|
16
|
+
readonly sandboxStatus: NamedSandboxStatus;
|
|
17
|
+
/** When the named sandbox was created, which ranks entries as `lookupSharedSnapshot` does. */
|
|
18
|
+
readonly sandboxCreatedAt: string;
|
|
19
|
+
readonly status: SharedSnapshotStatus;
|
|
20
|
+
readonly snapshotId: string | undefined;
|
|
21
|
+
readonly snapshotStatus: string | undefined;
|
|
22
|
+
readonly createdAt: string;
|
|
23
|
+
readonly expiresAt: string | undefined;
|
|
24
|
+
readonly expired: boolean;
|
|
25
|
+
}
|
|
26
|
+
/** How `listSharedSnapshots` ended. */
|
|
27
|
+
export type SharedSnapshotListResult = {
|
|
28
|
+
readonly kind: "ok";
|
|
29
|
+
readonly bucket: string;
|
|
30
|
+
readonly entries: readonly SharedSnapshotIndexEntry[];
|
|
31
|
+
} | {
|
|
32
|
+
readonly kind: "failed";
|
|
33
|
+
readonly message: string;
|
|
34
|
+
} | {
|
|
35
|
+
readonly kind: "aborted";
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Lists every valid `storm-snap-<bucket>-<base>` entry in `request`'s bucket and verifies stopped entries that hold a
|
|
39
|
+
* `currentSnapshotId` via `getSnapshot` with bounded concurrency.
|
|
40
|
+
*/
|
|
41
|
+
export declare function listSharedSnapshots(context: Pick<SharedSnapshotLookupContext, "runnerSandboxes" | "clock">, request: SharedSnapshotListRequest, signal?: AbortSignal): Promise<SharedSnapshotListResult>;
|
|
42
|
+
/** One entry of the shared snapshot index, with what the pick across both indexes says of it. */
|
|
43
|
+
export interface SharedSnapshotSelection {
|
|
44
|
+
readonly entry: SharedSnapshotIndexEntry;
|
|
45
|
+
/** Whether a run here, for the listed team and project, starts from it. */
|
|
46
|
+
readonly picked: boolean;
|
|
47
|
+
/** How many commits HEAD has that its base lacks, when it is ready and at or behind the merge-base; else null. */
|
|
48
|
+
readonly builtBehind: number | null;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* How `pickSnapshotAcrossIndexes` ended: the local snapshot index's snapshots, with the team and project's pick
|
|
52
|
+
* un-marked when a shared entry beats it, and each shared entry with whether a run here starts from it.
|
|
53
|
+
*/
|
|
54
|
+
export type SnapshotAcrossIndexesResult = {
|
|
55
|
+
readonly kind: "ok";
|
|
56
|
+
readonly local: readonly InspectedSnapshot[];
|
|
57
|
+
readonly shared: readonly SharedSnapshotSelection[];
|
|
58
|
+
} | {
|
|
59
|
+
readonly kind: "checkout-failed";
|
|
60
|
+
readonly failure: CheckoutFailure;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Decides which snapshot a run at `request.mergeBase` for `request.owner` starts from, across the local snapshot
|
|
64
|
+
* index's inspected snapshots (`request.local`) and the shared snapshot index's entries (`request.entries`), with the
|
|
65
|
+
* rule `chooseSnapshot` follows: the closest `ready` shared entry at the merge-base or an ancestor of it (ranked by
|
|
66
|
+
* `compareSnapshotCandidates` on the sandbox's `createdAt`, as `lookupSharedSnapshot` ranks before it reads a
|
|
67
|
+
* snapshot), which wins only when it beats the local pick (`sharedBeatsLocal`). Every other team and project's local
|
|
68
|
+
* pick stands. Git is asked once per ancestor base, for its distance behind the merge-base.
|
|
69
|
+
*/
|
|
70
|
+
export declare function pickSnapshotAcrossIndexes(context: Pick<SharedSnapshotLookupContext, "checkout">, request: {
|
|
71
|
+
readonly repoRoot: string;
|
|
72
|
+
readonly mergeBase: string;
|
|
73
|
+
/** How many commits HEAD has that the merge-base lacks. */
|
|
74
|
+
readonly commitsAfterBase: number;
|
|
75
|
+
readonly owner: {
|
|
76
|
+
readonly teamId: string;
|
|
77
|
+
readonly projectId: string;
|
|
78
|
+
};
|
|
79
|
+
readonly local: readonly InspectedSnapshot[];
|
|
80
|
+
readonly entries: readonly SharedSnapshotIndexEntry[];
|
|
81
|
+
}): Promise<SnapshotAcrossIndexesResult>;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// Listing and selecting entries from the shared snapshot index for `storm snapshots list --shared`.
|
|
2
|
+
import { compareSnapshotCandidates, sharedBeatsLocal } from "./local-snapshot-index.js";
|
|
3
|
+
import { classifyUnverifiedSharedSandbox, classifyVerifiedSharedSnapshot, INDEX_CONCURRENCY, parseSharedSnapshotSandboxName, runLimited, sharedSnapshotBucket, sharedSnapshotSandboxPrefix, } from "./shared-snapshot-entry.js";
|
|
4
|
+
/**
|
|
5
|
+
* Lists every valid `storm-snap-<bucket>-<base>` entry in `request`'s bucket and verifies stopped entries that hold a
|
|
6
|
+
* `currentSnapshotId` via `getSnapshot` with bounded concurrency.
|
|
7
|
+
*/
|
|
8
|
+
export async function listSharedSnapshots(context, request, signal) {
|
|
9
|
+
const { runnerSandboxes, clock } = context;
|
|
10
|
+
const { access, runner, snapshotKey } = request;
|
|
11
|
+
const bucket = sharedSnapshotBucket({
|
|
12
|
+
teamId: access.teamId,
|
|
13
|
+
projectId: access.projectId,
|
|
14
|
+
region: runner.region,
|
|
15
|
+
runtime: runner.runtime,
|
|
16
|
+
runnerName: runner.name,
|
|
17
|
+
snapshotKey,
|
|
18
|
+
});
|
|
19
|
+
const listed = await runnerSandboxes.listNamedSandboxes(access, { namePrefix: sharedSnapshotSandboxPrefix(bucket) }, signal);
|
|
20
|
+
if (!listed.ok) {
|
|
21
|
+
return listed.failure.kind === "aborted"
|
|
22
|
+
? { kind: "aborted" }
|
|
23
|
+
: { kind: "failed", message: listed.failure.message };
|
|
24
|
+
}
|
|
25
|
+
const now = clock.now();
|
|
26
|
+
const matched = [];
|
|
27
|
+
for (const row of listed.value) {
|
|
28
|
+
const parsed = parseSharedSnapshotSandboxName(row.name);
|
|
29
|
+
if (parsed === null || parsed.bucket !== bucket)
|
|
30
|
+
continue;
|
|
31
|
+
matched.push({ row, base: parsed.base });
|
|
32
|
+
}
|
|
33
|
+
let stop = false;
|
|
34
|
+
const outcomes = await runLimited(matched.length, INDEX_CONCURRENCY, () => !stop && signal?.aborted !== true, async (index) => {
|
|
35
|
+
const { row, base } = matched[index];
|
|
36
|
+
const unverified = classifyUnverifiedSharedSandbox(row);
|
|
37
|
+
if (unverified.kind === "settled") {
|
|
38
|
+
return {
|
|
39
|
+
kind: "entry",
|
|
40
|
+
entry: indexEntryOf(row, base, {
|
|
41
|
+
status: unverified.status,
|
|
42
|
+
snapshotId: unverified.status === "no-snapshot" ? undefined : row.currentSnapshotId,
|
|
43
|
+
snapshotStatus: undefined,
|
|
44
|
+
createdAt: row.createdAt,
|
|
45
|
+
expiresAt: row.tags["expires-at"],
|
|
46
|
+
expired: false,
|
|
47
|
+
}),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const verified = await runnerSandboxes.getSnapshot(access, { snapshotId: unverified.snapshotId }, signal);
|
|
51
|
+
if (!verified.ok) {
|
|
52
|
+
stop = true;
|
|
53
|
+
return verified.failure.kind === "aborted"
|
|
54
|
+
? { kind: "aborted" }
|
|
55
|
+
: { kind: "failed", message: verified.failure.message };
|
|
56
|
+
}
|
|
57
|
+
const classified = classifyVerifiedSharedSnapshot({ ...row, currentSnapshotId: unverified.snapshotId }, verified.value, now);
|
|
58
|
+
return {
|
|
59
|
+
kind: "entry",
|
|
60
|
+
entry: indexEntryOf(row, base, {
|
|
61
|
+
status: classified.status,
|
|
62
|
+
snapshotId: classified.snapshotId,
|
|
63
|
+
snapshotStatus: classified.snapshotStatus,
|
|
64
|
+
createdAt: classified.createdAt,
|
|
65
|
+
expiresAt: classified.expiresAt,
|
|
66
|
+
expired: classified.status === "expired",
|
|
67
|
+
}),
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
if (signal?.aborted === true)
|
|
71
|
+
return { kind: "aborted" };
|
|
72
|
+
const entries = [];
|
|
73
|
+
for (const outcome of outcomes) {
|
|
74
|
+
if (outcome === undefined)
|
|
75
|
+
continue;
|
|
76
|
+
if (outcome.kind === "aborted")
|
|
77
|
+
return { kind: "aborted" };
|
|
78
|
+
if (outcome.kind === "failed")
|
|
79
|
+
return outcome;
|
|
80
|
+
entries.push(outcome.entry);
|
|
81
|
+
}
|
|
82
|
+
return { kind: "ok", bucket, entries };
|
|
83
|
+
}
|
|
84
|
+
function indexEntryOf(row, base, fields) {
|
|
85
|
+
return {
|
|
86
|
+
sandboxName: row.name,
|
|
87
|
+
base,
|
|
88
|
+
sandboxStatus: row.status,
|
|
89
|
+
sandboxCreatedAt: row.createdAt,
|
|
90
|
+
...fields,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Decides which snapshot a run at `request.mergeBase` for `request.owner` starts from, across the local snapshot
|
|
95
|
+
* index's inspected snapshots (`request.local`) and the shared snapshot index's entries (`request.entries`), with the
|
|
96
|
+
* rule `chooseSnapshot` follows: the closest `ready` shared entry at the merge-base or an ancestor of it (ranked by
|
|
97
|
+
* `compareSnapshotCandidates` on the sandbox's `createdAt`, as `lookupSharedSnapshot` ranks before it reads a
|
|
98
|
+
* snapshot), which wins only when it beats the local pick (`sharedBeatsLocal`). Every other team and project's local
|
|
99
|
+
* pick stands. Git is asked once per ancestor base, for its distance behind the merge-base.
|
|
100
|
+
*/
|
|
101
|
+
export async function pickSnapshotAcrossIndexes(context, request) {
|
|
102
|
+
const { checkout } = context;
|
|
103
|
+
const { repoRoot, mergeBase, commitsAfterBase, owner, local, entries } = request;
|
|
104
|
+
const owned = (snapshot) => snapshot.entry.teamId === owner.teamId && snapshot.entry.projectId === owner.projectId;
|
|
105
|
+
const localPick = local.find((snapshot) => snapshot.picked && owned(snapshot));
|
|
106
|
+
const behindMergeBaseByBase = new Map([[mergeBase, 0]]);
|
|
107
|
+
const qualifying = [];
|
|
108
|
+
for (const entry of entries) {
|
|
109
|
+
if (entry.status !== "ready")
|
|
110
|
+
continue;
|
|
111
|
+
let commitsBehindMergeBase = behindMergeBaseByBase.get(entry.base);
|
|
112
|
+
if (commitsBehindMergeBase === undefined) {
|
|
113
|
+
const ancestor = await checkout.contains({ repoRoot, ancestor: entry.base, descendant: mergeBase });
|
|
114
|
+
if (!ancestor.ok)
|
|
115
|
+
return { kind: "checkout-failed", failure: ancestor.failure };
|
|
116
|
+
commitsBehindMergeBase = null;
|
|
117
|
+
if (ancestor.value) {
|
|
118
|
+
const counted = await checkout.commitCount({ repoRoot, from: entry.base, to: mergeBase });
|
|
119
|
+
if (!counted.ok)
|
|
120
|
+
return { kind: "checkout-failed", failure: counted.failure };
|
|
121
|
+
commitsBehindMergeBase = counted.value;
|
|
122
|
+
}
|
|
123
|
+
behindMergeBaseByBase.set(entry.base, commitsBehindMergeBase);
|
|
124
|
+
}
|
|
125
|
+
if (commitsBehindMergeBase !== null)
|
|
126
|
+
qualifying.push({ entry, commitsBehindMergeBase });
|
|
127
|
+
}
|
|
128
|
+
const best = qualifying.toSorted((a, b) => compareSnapshotCandidates({
|
|
129
|
+
commitsBehindMergeBase: a.commitsBehindMergeBase,
|
|
130
|
+
createdAt: a.entry.sandboxCreatedAt,
|
|
131
|
+
tieBreaker: a.entry.sandboxName,
|
|
132
|
+
}, {
|
|
133
|
+
commitsBehindMergeBase: b.commitsBehindMergeBase,
|
|
134
|
+
createdAt: b.entry.sandboxCreatedAt,
|
|
135
|
+
tieBreaker: b.entry.sandboxName,
|
|
136
|
+
}))[0];
|
|
137
|
+
const sharedPick = best !== undefined && sharedBeatsLocal(best.commitsBehindMergeBase, localPick?.commitsBehindMergeBase ?? undefined)
|
|
138
|
+
? best.entry
|
|
139
|
+
: undefined;
|
|
140
|
+
const readyBehind = new Map(qualifying.map(({ entry, commitsBehindMergeBase }) => [entry, commitsBehindMergeBase]));
|
|
141
|
+
return {
|
|
142
|
+
kind: "ok",
|
|
143
|
+
local: sharedPick === undefined || localPick === undefined
|
|
144
|
+
? local
|
|
145
|
+
: local.map((snapshot) => (snapshot === localPick ? { ...snapshot, picked: false } : snapshot)),
|
|
146
|
+
shared: entries.map((entry) => {
|
|
147
|
+
const commitsBehindMergeBase = readyBehind.get(entry);
|
|
148
|
+
return {
|
|
149
|
+
entry,
|
|
150
|
+
picked: entry === sharedPick,
|
|
151
|
+
builtBehind: commitsBehindMergeBase === undefined ? null : commitsAfterBase + commitsBehindMergeBase,
|
|
152
|
+
};
|
|
153
|
+
}),
|
|
154
|
+
};
|
|
155
|
+
}
|