@cnc-tools/storm 0.16.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/storm.js +54 -40
- package/dist/build-info.js +1 -1
- package/dist/chunks/{chunk-VL7WFTVQ.js → chunk-24UYAK4R.js} +465 -365
- package/dist/chunks/{chunk-DC2CDHNK.js → chunk-2JMWUKH3.js} +2074 -473
- package/dist/chunks/{chunk-FOZWA52V.js → chunk-3VXZONGE.js} +481 -376
- package/dist/chunks/{chunk-ZG3WQ4UF.js → chunk-55O4FCN4.js} +1 -1
- package/dist/chunks/{chunk-CN4EFA5J.js → chunk-72ZFEMAW.js} +1 -1
- package/dist/chunks/chunk-AS37D43E.js +2173 -0
- package/dist/chunks/chunk-CQAY6GLP.js +1260 -0
- package/dist/chunks/chunk-DZLU7BYK.js +340 -0
- package/dist/chunks/{chunk-R7XVBZOY.js → chunk-EEENLQHE.js} +59 -11
- package/dist/chunks/{chunk-TJNFVNKR.js → chunk-EI3XDCEI.js} +1 -1
- package/dist/chunks/{chunk-HVNK3I45.js → chunk-FDUY3BNF.js} +1 -1
- package/dist/chunks/{chunk-FCQUJDA4.js → chunk-GUCCYCIO.js} +4 -189
- package/dist/chunks/{chunk-OIY3DMF2.js → chunk-HBI4LEMH.js} +3 -3
- package/dist/chunks/{chunk-2MAD5NKK.js → chunk-K4MDQPLW.js} +1 -18
- package/dist/chunks/chunk-KK7PAWIZ.js +198 -0
- package/dist/chunks/{chunk-G3PHMXH5.js → chunk-KQ5FXRUD.js} +18 -1
- package/dist/chunks/{chunk-5VXBKPW6.js → chunk-LKXHGGGX.js} +1 -1
- package/dist/chunks/{chunk-P357TZAY.js → chunk-LOGHIUUB.js} +21 -18
- package/dist/chunks/{chunk-CK2GZEPK.js → chunk-OEPFINFT.js} +2 -2
- package/dist/chunks/{chunk-DWEAHX4T.js → chunk-OI4AP6Z7.js} +5 -5
- package/dist/chunks/{chunk-V4IKA3WI.js → chunk-PMBQWVTW.js} +26 -19
- package/dist/chunks/chunk-SZMYIIG2.js +88 -0
- package/dist/chunks/{chunk-5CCP36QQ.js → chunk-TXCOFC7N.js} +1 -1
- package/dist/chunks/{chunk-VUPZH7J2.js → chunk-UXD3TVWM.js} +1 -1
- package/dist/chunks/{chunk-3L52KNQA.js → chunk-WNW2QXQK.js} +8 -8
- package/dist/chunks/{chunk-AWBSONHB.js → chunk-XBDRVFEV.js} +55 -16
- package/dist/chunks/{live-app-WECQOQ4C.js → live-app-UY7BEDUN.js} +17 -13
- package/dist/cli.d.ts +28 -0
- package/dist/cli.js +64 -0
- package/dist/commands/exec/across-sandboxes-outcomes.d.ts +2 -2
- package/dist/commands/exec/across-sandboxes-outcomes.js +3 -3
- package/dist/commands/exec/before-run.d.ts +123 -0
- package/dist/commands/exec/before-run.js +105 -0
- package/dist/commands/exec/command.d.ts +67 -14
- package/dist/commands/exec/command.js +31 -95
- package/dist/commands/exec/driver-plan.d.ts +9 -4
- package/dist/commands/exec/driver-plan.js +8 -8
- package/dist/commands/exec/exec-words.js +1 -1
- package/dist/commands/exec/execute-run.d.ts +39 -0
- package/dist/commands/exec/execute-run.js +325 -0
- package/dist/commands/exec/live-view.d.ts +3 -3
- package/dist/commands/exec/live-view.js +16 -15
- package/dist/commands/exec/metadata.js +1 -1
- package/dist/commands/exec/mint-failed.d.ts +38 -0
- package/dist/commands/exec/mint-failed.js +27 -4
- package/dist/commands/exec/outcomes.d.ts +104 -22
- package/dist/commands/exec/outcomes.js +73 -26
- package/dist/commands/exec/plan-run.d.ts +58 -150
- package/dist/commands/exec/plan-run.js +239 -90
- package/dist/commands/exec/progress.d.ts +10 -6
- package/dist/commands/exec/progress.js +38 -25
- package/dist/commands/exec/run-bin.d.ts +11 -11
- package/dist/commands/exec/run-bin.js +9 -9
- package/dist/commands/exec/run-flags.d.ts +69 -0
- package/dist/commands/exec/run-flags.js +58 -0
- package/dist/commands/exec/run-metadata.js +4 -4
- package/dist/commands/exec/run-summary.d.ts +58 -0
- package/dist/commands/exec/run-summary.js +205 -0
- package/dist/commands/exec/runner-refusals.d.ts +82 -0
- package/dist/commands/exec/runner-refusals.js +71 -0
- package/dist/commands/exec/sandbox-progress.js +3 -0
- package/dist/commands/exec/stopped-outcome.d.ts +12 -0
- package/dist/commands/exec/stopped-outcome.js +77 -0
- package/dist/commands/exec/view.d.ts +20 -11
- package/dist/commands/exec/view.js +103 -47
- package/dist/commands/runs/facts.d.ts +8 -4
- package/dist/commands/runs/facts.js +19 -10
- package/dist/commands/runs/list/command.d.ts +16 -8
- package/dist/commands/runs/list/command.js +10 -10
- package/dist/commands/runs/list/outcomes.d.ts +8 -4
- package/dist/commands/runs/logs/command.js +10 -10
- package/dist/commands/runs/show/command.d.ts +16 -8
- package/dist/commands/runs/show/command.js +31 -29
- package/dist/commands/runs/show/metadata.js +1 -1
- package/dist/commands/runs/show/outcomes.d.ts +8 -4
- package/dist/commands/runs/show/outcomes.js +8 -6
- package/dist/commands/snapshots/access.d.ts +111 -0
- package/dist/commands/snapshots/access.js +96 -0
- package/dist/commands/snapshots/build/command.d.ts +376 -101
- package/dist/commands/snapshots/build/command.js +447 -149
- package/dist/commands/snapshots/build/metadata.d.ts +10 -0
- package/dist/commands/snapshots/build/metadata.js +31 -11
- package/dist/commands/snapshots/build/outcomes.d.ts +242 -47
- package/dist/commands/snapshots/build/outcomes.js +200 -36
- package/dist/commands/snapshots/list/command.d.ts +368 -27
- package/dist/commands/snapshots/list/command.js +298 -68
- package/dist/commands/snapshots/list/metadata.d.ts +16 -0
- package/dist/commands/snapshots/list/metadata.js +29 -6
- package/dist/commands/snapshots/list/outcomes.d.ts +247 -15
- package/dist/commands/snapshots/list/outcomes.js +223 -52
- package/dist/commands/snapshots/metadata.js +1 -1
- package/dist/commands/snapshots/prune/command.d.ts +430 -0
- package/dist/commands/snapshots/prune/command.js +161 -0
- package/dist/commands/snapshots/prune/metadata.d.ts +28 -0
- package/dist/commands/snapshots/prune/metadata.js +39 -0
- package/dist/commands/snapshots/prune/outcomes.d.ts +208 -0
- package/dist/commands/snapshots/prune/outcomes.js +78 -0
- package/dist/commands/suites/list/command.js +17 -17
- package/dist/commands/suites/list/outcomes.js +2 -2
- package/dist/commands/test/command.d.ts +67 -14
- package/dist/commands/test/command.js +49 -252
- package/dist/commands/test/outcomes.d.ts +33 -7
- package/dist/config/check-runner.d.ts +3 -3
- package/dist/config/check-runner.js +8 -7
- package/dist/config/credential-resolver.d.ts +50 -5
- package/dist/config/credential-resolver.js +51 -19
- package/dist/config/credential-settle.d.ts +6 -2
- package/dist/config/credential-settle.js +11 -5
- package/dist/config/index.d.ts +2 -2
- package/dist/config/index.js +1 -1
- package/dist/config/runner.d.ts +5 -5
- package/dist/config/runner.js +1 -1
- package/dist/config/schema.d.ts +2 -2
- package/dist/config/schema.js +1 -1
- package/dist/config-file/define.d.ts +1 -1
- package/dist/config-file/define.js +1 -1
- package/dist/config-file/runner.d.ts +5 -5
- package/dist/config-file/toolchain.d.ts +14 -4
- package/dist/config-file/toolchain.js +43 -7
- package/dist/context.d.ts +10 -6
- package/dist/context.js +8 -6
- package/dist/core/across-sandboxes.d.ts +7 -6
- package/dist/core/across-sandboxes.js +123 -152
- package/dist/core/coordinator.d.ts +166 -0
- package/dist/core/coordinator.js +233 -0
- package/dist/core/events.d.ts +2 -2
- package/dist/core/index.d.ts +4 -2
- package/dist/core/index.js +1 -1
- package/dist/core/outcomes.d.ts +148 -0
- package/dist/core/{sandbox-end.js → outcomes.js} +28 -4
- package/dist/core/resources.d.ts +31 -53
- package/dist/core/resources.js +32 -70
- package/dist/core/run-state.d.ts +7 -1
- package/dist/core/run-state.js +2 -0
- package/dist/core/run.d.ts +32 -236
- package/dist/core/run.js +107 -267
- package/dist/core/state-directory.d.ts +1 -1
- package/dist/core/state-directory.js +2 -2
- package/dist/credential/gateways.d.ts +15 -1
- package/dist/credential/index.d.ts +4 -3
- package/dist/credential/index.js +3 -2
- package/dist/credential/live/vercel-cli-gateway.d.ts +1 -1
- package/dist/credential/live/vercel-cli-gateway.js +1 -1
- package/dist/credential/live/vercel-oidc-token-gateway.d.ts +11 -0
- package/dist/credential/live/vercel-oidc-token-gateway.js +16 -0
- package/dist/credential/source.d.ts +73 -6
- package/dist/credential/source.js +55 -2
- package/dist/extension-commands.d.ts +1 -1
- package/dist/extension-commands.js +2 -2
- package/dist/extensions/testserver/commands/pool/create/command.d.ts +35 -2
- package/dist/extensions/testserver/commands/pool/create/command.js +7 -7
- package/dist/extensions/testserver/commands/pool/create/metadata.js +5 -5
- package/dist/extensions/testserver/commands/pool/create/outcomes.d.ts +17 -1
- package/dist/extensions/testserver/commands/pool/list/command.js +4 -4
- package/dist/extensions/testserver/credential-facts.d.ts +6 -2
- package/dist/extensions/testserver/credential-facts.js +29 -11
- package/dist/extensions/testserver/lifecycle.js +7 -1
- package/dist/extensions/testserver/limit.d.ts +3 -0
- package/dist/extensions/testserver/limit.js +3 -0
- package/dist/extensions/testserver/provision.d.ts +8 -1
- package/dist/extensions/testserver/provision.js +8 -3
- package/dist/extensions/testserver/refusals.d.ts +6 -1
- package/dist/extensions/testserver/refusals.js +16 -1
- package/dist/extensions/testserver/resource.d.ts +1 -1
- package/dist/extensions/testserver/resource.js +1 -1
- package/dist/extensions/testserver/result.d.ts +1 -1
- package/dist/extensions/testserver/result.js +9 -4
- package/dist/planning/driver-file-lists.d.ts +0 -15
- package/dist/planning/driver-file-lists.js +2 -21
- package/dist/planning/plan-only.d.ts +3 -14
- package/dist/planning/plan-only.js +11 -20
- package/dist/planning/run-kind-flags.js +2 -2
- package/dist/planning/run-plan.d.ts +45 -12
- package/dist/planning/run-plan.js +4 -3
- package/dist/planning/suites.d.ts +1 -1
- package/dist/planning/suites.js +2 -2
- package/dist/planning/test-plan.d.ts +9 -0
- package/dist/planning/test-plan.js +9 -0
- package/dist/run-directory/recording.js +3 -3
- package/dist/run-directory/run-record.d.ts +26 -11
- package/dist/run-directory/run-record.js +16 -13
- package/dist/runner/base.js +1 -1
- package/dist/runner/build-snapshots.d.ts +60 -29
- package/dist/runner/build-snapshots.js +136 -29
- package/dist/runner/context.d.ts +15 -7
- package/dist/runner/context.js +19 -6
- package/dist/runner/events.d.ts +16 -10
- package/dist/runner/gateways.d.ts +122 -23
- package/dist/runner/gateways.js +1 -1
- package/dist/runner/gh.d.ts +42 -0
- package/dist/runner/gh.js +58 -0
- package/dist/runner/index.d.ts +13 -8
- package/dist/runner/index.js +12 -6
- package/dist/runner/live/checkout-gateway.js +7 -0
- package/dist/runner/live/gh-output.d.ts +17 -0
- package/dist/runner/live/gh-output.js +37 -0
- package/dist/runner/live/gh-token-gateway.d.ts +13 -0
- package/dist/runner/live/gh-token-gateway.js +51 -0
- package/dist/runner/live/sandbox-errors.d.ts +2 -0
- package/dist/runner/live/sandbox-errors.js +4 -0
- package/dist/runner/live/sandbox-gateway.js +140 -4
- package/dist/runner/live/snapshot-index-gateway.d.ts +12 -0
- package/dist/runner/live/{snapshot-cache-gateway.js → snapshot-index-gateway.js} +11 -11
- package/dist/runner/live/snapshot-records.js +12 -12
- package/dist/runner/local-snapshot-index.d.ts +205 -0
- package/dist/runner/local-snapshot-index.js +210 -0
- package/dist/runner/network-policy.d.ts +6 -6
- package/dist/runner/network-policy.js +7 -7
- package/dist/runner/policy-writes.d.ts +1 -1
- package/dist/runner/policy-writes.js +1 -1
- package/dist/runner/prepare.d.ts +14 -14
- package/dist/runner/prepare.js +20 -11
- package/dist/runner/ready.d.ts +19 -11
- package/dist/runner/ready.js +104 -33
- package/dist/runner/sandboxed-command.d.ts +3 -3
- package/dist/runner/sandboxed-command.js +3 -3
- package/dist/runner/scope.d.ts +15 -8
- package/dist/runner/scope.js +16 -5
- package/dist/runner/secrets.d.ts +41 -18
- package/dist/runner/secrets.js +226 -30
- package/dist/runner/session.d.ts +8 -8
- package/dist/runner/session.js +6 -3
- package/dist/runner/shared-snapshot-entry.d.ts +92 -0
- package/dist/runner/shared-snapshot-entry.js +168 -0
- package/dist/runner/shared-snapshot-list.d.ts +81 -0
- package/dist/runner/shared-snapshot-list.js +155 -0
- package/dist/runner/shared-snapshot-lookup.d.ts +51 -0
- package/dist/runner/shared-snapshot-lookup.js +118 -0
- package/dist/runner/shared-snapshot-prune.d.ts +58 -0
- package/dist/runner/shared-snapshot-prune.js +133 -0
- package/dist/runner/snapshot-build.d.ts +42 -14
- package/dist/runner/snapshot-build.js +79 -47
- package/dist/runner/snapshot-choice.js +2 -1
- package/dist/runner/snapshot-inspect.d.ts +39 -40
- package/dist/runner/snapshot-inspect.js +52 -35
- package/dist/runner/snapshot-key.d.ts +32 -17
- package/dist/runner/snapshot-key.js +43 -18
- package/dist/runner/snapshot-source.d.ts +31 -0
- package/dist/runner/snapshot-source.js +122 -0
- package/dist/runner/steps.d.ts +1 -1
- package/dist/runner/steps.js +1 -1
- package/dist/runner/{recipe-check.d.ts → vercel-sandbox-check.d.ts} +4 -2
- package/dist/runner/{recipe-check.js → vercel-sandbox-check.js} +7 -2
- package/dist/runner/{recipe.d.ts → vercel-sandbox-options.d.ts} +59 -28
- package/dist/runner/{recipe.js → vercel-sandbox-options.js} +128 -84
- package/dist/runner/vercel-sandbox-secrets.d.ts +116 -0
- package/dist/runner/{recipe-secrets.js → vercel-sandbox-secrets.js} +159 -26
- package/dist/sdk/extension/credential-diagnosis.d.ts +3 -1
- package/dist/sdk/extension/credential-diagnosis.js +25 -5
- package/dist/sdk/extension/credential-source.d.ts +20 -3
- package/dist/sdk/extension/credential-source.js +4 -4
- package/dist/sdk/extension/index.d.ts +3 -2
- package/dist/sdk/extension/index.js +2 -1
- package/dist/sdk/extension/resource-definition.d.ts +1 -1
- package/dist/sdk/extension/secret-source.d.ts +1 -1
- package/dist/sdk/extension/secret-source.js +1 -1
- package/dist/sdk/extension/vercel-oidc-facts.d.ts +20 -0
- package/dist/sdk/extension/vercel-oidc-facts.js +20 -0
- package/dist/shared/cleanup.d.ts +3 -3
- package/dist/shared/cleanup.js +15 -5
- package/dist/shared/snapshot-text.d.ts +4 -4
- package/dist/shared/snapshot-text.js +11 -11
- package/dist/time/duration.js +1 -1
- package/package.json +5 -3
- package/skills/overview.md +4 -4
- package/skills/plan-runs.md +1 -1
- package/skills/read-run-output.md +6 -6
- package/dist/application.d.ts +0 -21
- package/dist/application.js +0 -30
- package/dist/chunks/chunk-7EENF73W.js +0 -782
- package/dist/chunks/chunk-Z5PBVG3Y.js +0 -2599
- package/dist/commands/exec/across-sandboxes-run.d.ts +0 -180
- package/dist/commands/exec/across-sandboxes-run.js +0 -339
- package/dist/commands/exec/plan-only.d.ts +0 -10
- package/dist/commands/exec/plan-only.js +0 -45
- package/dist/commands/exec/run-command.d.ts +0 -475
- package/dist/commands/exec/run-command.js +0 -603
- package/dist/commands/exec/run-planned.d.ts +0 -20
- package/dist/commands/exec/run-planned.js +0 -22
- package/dist/commands/exec/sandbox-view.d.ts +0 -19
- package/dist/commands/exec/sandbox-view.js +0 -72
- package/dist/commands/test/plan.d.ts +0 -92
- package/dist/commands/test/plan.js +0 -125
- package/dist/core/sandbox-end.d.ts +0 -64
- package/dist/runner/live/snapshot-cache-gateway.d.ts +0 -12
- package/dist/runner/recipe-secrets.d.ts +0 -67
- package/dist/runner/snapshot-cache.d.ts +0 -148
- package/dist/runner/snapshot-cache.js +0 -126
|
@@ -3,5 +3,7 @@ import type { RunnerSandboxFailure } from "../gateways.ts";
|
|
|
3
3
|
export declare function apiStatus(error: unknown): number | undefined;
|
|
4
4
|
/** Whether `error` is an abort: a DOM `AbortError`, as `fetch` and the SDK throw when a signal aborts. */
|
|
5
5
|
export declare function isAbortError(error: unknown): boolean;
|
|
6
|
+
/** Whether a Sandbox API error means a sandbox with the requested name already exists (HTTP 400). */
|
|
7
|
+
export declare function isNameTakenError(error: unknown, message: string): boolean;
|
|
6
8
|
/** What a thrown Sandbox error means: an abort when `signal` aborted or the error is one, otherwise an API failure. */
|
|
7
9
|
export declare function sandboxFailure(error: unknown, signal: AbortSignal | undefined): RunnerSandboxFailure;
|
|
@@ -13,6 +13,10 @@ export function apiStatus(error) {
|
|
|
13
13
|
export function isAbortError(error) {
|
|
14
14
|
return typeof error === "object" && error !== null && error.name === "AbortError";
|
|
15
15
|
}
|
|
16
|
+
/** Whether a Sandbox API error means a sandbox with the requested name already exists (HTTP 400). */
|
|
17
|
+
export function isNameTakenError(error, message) {
|
|
18
|
+
return apiStatus(error) === 400 && /already exists/i.test(message);
|
|
19
|
+
}
|
|
16
20
|
/** What a thrown Sandbox error means: an abort when `signal` aborted or the error is one, otherwise an API failure. */
|
|
17
21
|
export function sandboxFailure(error, signal) {
|
|
18
22
|
if (signal?.aborted === true || isAbortError(error))
|
|
@@ -12,15 +12,19 @@
|
|
|
12
12
|
import { policyCredentials } from "../network-policy.js";
|
|
13
13
|
import { SANDBOX_ROOT } from "../snapshot-key.js";
|
|
14
14
|
import { ABORTED, untilAborted } from "../time-limit.js";
|
|
15
|
-
import { apiStatus, sandboxFailure } from "./sandbox-errors.js";
|
|
15
|
+
import { apiStatus, isNameTakenError, sandboxFailure } from "./sandbox-errors.js";
|
|
16
16
|
/** How long a process has to end after SIGTERM before it gets SIGKILL: 10 seconds. */
|
|
17
17
|
export const TERMINATE_GRACE_MS = 10_000;
|
|
18
18
|
/** How long a process has to end after SIGKILL before keeping its sandbox fails: 5 seconds. */
|
|
19
19
|
export const KILL_GRACE_MS = 5_000;
|
|
20
20
|
/** The most stderr characters a failed test events read reports. */
|
|
21
21
|
const STDERR_MESSAGE_CHARS = 1000;
|
|
22
|
+
/** The Sandbox API's answer when a sandbox or snapshot does not exist. */
|
|
23
|
+
const NOT_FOUND_STATUS = 404;
|
|
22
24
|
/** The Sandbox API's answer when a snapshot to start from has expired or been deleted. */
|
|
23
25
|
const SNAPSHOT_GONE_STATUS = 410;
|
|
26
|
+
/** Page size for `Sandbox.list` calls. */
|
|
27
|
+
const LIST_SANDBOXES_PAGE_LIMIT = 50;
|
|
24
28
|
/**
|
|
25
29
|
* `setpriv` flags used to drop every Linux capability and block privilege escalation before `execve` of the user
|
|
26
30
|
* command. Vercel Sandbox's default `vercel-sandbox` user (uid 1000) holds full capabilities (`CAP_DAC_OVERRIDE`,
|
|
@@ -57,15 +61,18 @@ export function liveRunnerSandboxGateway() {
|
|
|
57
61
|
const { Sandbox } = await sdk();
|
|
58
62
|
const sandbox = await Sandbox.create({
|
|
59
63
|
...credentials(access),
|
|
60
|
-
|
|
61
|
-
|
|
64
|
+
image: request.image,
|
|
65
|
+
...(request.name === undefined ? {} : { name: request.name }),
|
|
62
66
|
...placement(request),
|
|
63
67
|
...(signal === undefined ? {} : { signal }),
|
|
64
68
|
});
|
|
65
69
|
return { ok: true, value: adopt(sandbox, "snapshot-build", request.timeoutMs) };
|
|
66
70
|
}
|
|
67
71
|
catch (error) {
|
|
68
|
-
|
|
72
|
+
const failure = sandboxFailure(error, signal);
|
|
73
|
+
if (request.name !== undefined && failure.kind === "api" && isNameTakenError(error, failure.message))
|
|
74
|
+
return { ok: false, failure: { kind: "name-taken", name: request.name, message: failure.message } };
|
|
75
|
+
return { ok: false, failure };
|
|
69
76
|
}
|
|
70
77
|
},
|
|
71
78
|
async startRunnerSandbox(access, request, signal) {
|
|
@@ -86,6 +93,124 @@ export function liveRunnerSandboxGateway() {
|
|
|
86
93
|
return { ok: false, failure };
|
|
87
94
|
}
|
|
88
95
|
},
|
|
96
|
+
async getNamedSandbox(access, request, signal) {
|
|
97
|
+
if (isAborted(signal))
|
|
98
|
+
return { ok: false, failure: { kind: "aborted" } };
|
|
99
|
+
try {
|
|
100
|
+
const { Sandbox } = await sdk();
|
|
101
|
+
const sandbox = await Sandbox.get({
|
|
102
|
+
...credentials(access),
|
|
103
|
+
name: request.name,
|
|
104
|
+
...(signal === undefined ? {} : { signal }),
|
|
105
|
+
});
|
|
106
|
+
return {
|
|
107
|
+
ok: true,
|
|
108
|
+
value: {
|
|
109
|
+
kind: "found",
|
|
110
|
+
sandbox: {
|
|
111
|
+
name: sandbox.name,
|
|
112
|
+
status: sandbox.status,
|
|
113
|
+
currentSnapshotId: sandbox.currentSnapshotId,
|
|
114
|
+
createdAt: sandbox.createdAt.toISOString(),
|
|
115
|
+
tags: { ...sandbox.tags },
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
const failure = sandboxFailure(error, signal);
|
|
122
|
+
if (failure.kind === "api" && apiStatus(error) === NOT_FOUND_STATUS)
|
|
123
|
+
return { ok: true, value: { kind: "not-found" } };
|
|
124
|
+
return { ok: false, failure };
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
async listNamedSandboxes(access, request, signal) {
|
|
128
|
+
if (isAborted(signal))
|
|
129
|
+
return { ok: false, failure: { kind: "aborted" } };
|
|
130
|
+
try {
|
|
131
|
+
const { Sandbox } = await sdk();
|
|
132
|
+
// `namePrefix` requires `sortBy: "name"`; omitting it causes Vercel Sandbox to reject with HTTP 400.
|
|
133
|
+
const paginator = await Sandbox.list({
|
|
134
|
+
...credentials(access),
|
|
135
|
+
namePrefix: request.namePrefix,
|
|
136
|
+
sortBy: "name",
|
|
137
|
+
limit: LIST_SANDBOXES_PAGE_LIMIT,
|
|
138
|
+
...(signal === undefined ? {} : { signal }),
|
|
139
|
+
});
|
|
140
|
+
const listed = [];
|
|
141
|
+
for await (const page of paginator.pages()) {
|
|
142
|
+
if (isAborted(signal))
|
|
143
|
+
return { ok: false, failure: { kind: "aborted" } };
|
|
144
|
+
for (const item of page.sandboxes) {
|
|
145
|
+
listed.push({
|
|
146
|
+
name: item.name,
|
|
147
|
+
status: item.status,
|
|
148
|
+
currentSnapshotId: item.currentSnapshotId,
|
|
149
|
+
createdAt: new Date(item.createdAt).toISOString(),
|
|
150
|
+
tags: { ...item.tags },
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return { ok: true, value: listed };
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
return { ok: false, failure: sandboxFailure(error, signal) };
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
async getSnapshot(access, request, signal) {
|
|
161
|
+
if (isAborted(signal))
|
|
162
|
+
return { ok: false, failure: { kind: "aborted" } };
|
|
163
|
+
try {
|
|
164
|
+
const { Snapshot } = await sdk();
|
|
165
|
+
const snapshot = await Snapshot.get({
|
|
166
|
+
...credentials(access),
|
|
167
|
+
snapshotId: request.snapshotId,
|
|
168
|
+
...(signal === undefined ? {} : { signal }),
|
|
169
|
+
});
|
|
170
|
+
return {
|
|
171
|
+
ok: true,
|
|
172
|
+
value: {
|
|
173
|
+
kind: "found",
|
|
174
|
+
snapshot: {
|
|
175
|
+
snapshotId: snapshot.snapshotId,
|
|
176
|
+
status: snapshot.status,
|
|
177
|
+
createdAt: snapshot.createdAt.toISOString(),
|
|
178
|
+
expiresAt: snapshot.expiresAt?.toISOString(),
|
|
179
|
+
sizeBytes: snapshot.sizeBytes,
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
const failure = sandboxFailure(error, signal);
|
|
186
|
+
const status = apiStatus(error);
|
|
187
|
+
if (failure.kind === "api" && (status === NOT_FOUND_STATUS || status === SNAPSHOT_GONE_STATUS))
|
|
188
|
+
return { ok: true, value: { kind: "not-found" } };
|
|
189
|
+
return { ok: false, failure };
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
async deleteNamedSandbox(access, request, signal) {
|
|
193
|
+
if (isAborted(signal))
|
|
194
|
+
return { ok: false, failure: { kind: "aborted" } };
|
|
195
|
+
try {
|
|
196
|
+
const { Sandbox } = await sdk();
|
|
197
|
+
const sandbox = await Sandbox.get({
|
|
198
|
+
...credentials(access),
|
|
199
|
+
name: request.name,
|
|
200
|
+
...(signal === undefined ? {} : { signal }),
|
|
201
|
+
});
|
|
202
|
+
if (isAborted(signal))
|
|
203
|
+
return { ok: false, failure: { kind: "aborted" } };
|
|
204
|
+
await sandbox.delete({ deleteOrphanSnapshots: false, ...(signal === undefined ? {} : { signal }) });
|
|
205
|
+
return { ok: true };
|
|
206
|
+
}
|
|
207
|
+
catch (error) {
|
|
208
|
+
const failure = sandboxFailure(error, signal);
|
|
209
|
+
if (failure.kind === "api" && apiStatus(error) === NOT_FOUND_STATUS)
|
|
210
|
+
return { ok: true };
|
|
211
|
+
return { ok: false, failure };
|
|
212
|
+
}
|
|
213
|
+
},
|
|
89
214
|
async upload(sandbox, files, signal) {
|
|
90
215
|
const holder = holding(sandbox);
|
|
91
216
|
try {
|
|
@@ -388,8 +513,19 @@ function placement(request) {
|
|
|
388
513
|
persistent: false,
|
|
389
514
|
tags: { ...request.tags },
|
|
390
515
|
networkPolicy: sdkNetworkPolicy(request.networkPolicy),
|
|
516
|
+
...(request.managedCredentials !== undefined && request.managedCredentials.length > 0
|
|
517
|
+
? { credentials: sdkManagedCredentials(request.managedCredentials) }
|
|
518
|
+
: {}),
|
|
391
519
|
};
|
|
392
520
|
}
|
|
521
|
+
function sdkManagedCredentials(providers) {
|
|
522
|
+
const result = {};
|
|
523
|
+
for (const provider of providers) {
|
|
524
|
+
if (provider === "npm")
|
|
525
|
+
result.npm = true;
|
|
526
|
+
}
|
|
527
|
+
return result;
|
|
528
|
+
}
|
|
393
529
|
/**
|
|
394
530
|
* storm's network policy as the SDK takes it. `allow-all` with no credential is the SDK's `allow-all`. With
|
|
395
531
|
* credentials, every domain stays reachable (`"*": []`). `custom` allows each allowed domain with no rule (`[]`), and
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { RunnerSnapshotIndexGateway } from "../gateways.ts";
|
|
2
|
+
export interface LiveRunnerSnapshotIndexOptions {
|
|
3
|
+
/** The local snapshot index directory, `$XDG_STATE_HOME/storm/runner/snapshots`. */
|
|
4
|
+
readonly directory: string;
|
|
5
|
+
}
|
|
6
|
+
/** The local snapshot index in `options.directory`. */
|
|
7
|
+
export declare function liveRunnerSnapshotIndexGateway(options: LiveRunnerSnapshotIndexOptions): RunnerSnapshotIndexGateway;
|
|
8
|
+
/**
|
|
9
|
+
* A local snapshot index that can't be found, because neither `XDG_STATE_HOME` nor `HOME` names a place for it. Every
|
|
10
|
+
* operation fails with `reason`, at `location`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function unavailableRunnerSnapshotIndexGateway(location: string, reason: string): RunnerSnapshotIndexGateway;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
// The
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
1
|
+
// The local snapshot index on disk: one `<identity>.json` file per runner snapshot in one directory, named after the
|
|
2
|
+
// entry's identity (`snapshotEntryIdentity`). An entry is written to a temp file in the same directory and renamed into
|
|
3
|
+
// place, so a write with the same identity replaces the file whole and the last write wins. Files are mode 0600 and
|
|
4
|
+
// directories 0700.
|
|
5
5
|
import { randomBytes } from "node:crypto";
|
|
6
6
|
import { mkdir, readdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
|
|
7
7
|
import { join } from "node:path";
|
|
8
|
-
import { snapshotEntryFileName } from "../snapshot-
|
|
8
|
+
import { snapshotEntryFileName } from "../local-snapshot-index.js";
|
|
9
9
|
import { parseSnapshotEntry, snapshotEntryText } from "./snapshot-records.js";
|
|
10
10
|
const DIRECTORY_MODE = 0o700;
|
|
11
11
|
const FILE_MODE = 0o600;
|
|
12
|
-
/** A
|
|
12
|
+
/** A local snapshot index file's name: 32 hex characters and `.json`. Temp files start with a dot and never match. */
|
|
13
13
|
const ENTRY_FILE_NAME = /^[0-9a-f]{32}\.json$/;
|
|
14
|
-
/** The
|
|
15
|
-
export function
|
|
14
|
+
/** The local snapshot index in `options.directory`. */
|
|
15
|
+
export function liveRunnerSnapshotIndexGateway(options) {
|
|
16
16
|
const { directory } = options;
|
|
17
17
|
return {
|
|
18
18
|
listEntries: () => listEntries(directory),
|
|
@@ -21,10 +21,10 @@ export function liveRunnerSnapshotCacheGateway(options) {
|
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
|
-
* A
|
|
25
|
-
* fails with `reason`, at `location`.
|
|
24
|
+
* A local snapshot index that can't be found, because neither `XDG_STATE_HOME` nor `HOME` names a place for it. Every
|
|
25
|
+
* operation fails with `reason`, at `location`.
|
|
26
26
|
*/
|
|
27
|
-
export function
|
|
27
|
+
export function unavailableRunnerSnapshotIndexGateway(location, reason) {
|
|
28
28
|
const failure = { path: location, message: reason };
|
|
29
29
|
const fail = async () => ({ ok: false, failure });
|
|
30
30
|
return { listEntries: fail, writeEntry: fail, removeEntry: fail };
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
// The
|
|
1
|
+
// The local snapshot index's file format: one JSON object per runner snapshot, carrying `version: 2`. A reader
|
|
2
2
|
// rejects a version it doesn't know, and drops keys it doesn't know. A file is named for its entry's identity
|
|
3
|
-
// (`snapshotEntryIdentity`), and the gateway lists a file whose name isn't as unreadable.
|
|
4
|
-
//
|
|
5
|
-
//
|
|
3
|
+
// (`snapshotEntryIdentity`), and the gateway lists a file whose name isn't as unreadable. Older files (such as
|
|
4
|
+
// version 1 entries carrying the retired `runtime` field) are listed as unreadable, and no run starts from them:
|
|
5
|
+
// there is no migration.
|
|
6
6
|
import { z } from "zod";
|
|
7
7
|
const isoTime = z.string().refine((value) => !Number.isNaN(Date.parse(value)), { message: "not a time" });
|
|
8
8
|
const nonEmpty = z.string().min(1);
|
|
9
9
|
const entrySchema = z.object({
|
|
10
|
-
version: z.literal(
|
|
10
|
+
version: z.literal(2),
|
|
11
11
|
teamId: nonEmpty,
|
|
12
12
|
projectId: nonEmpty,
|
|
13
13
|
region: nonEmpty,
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
image: nonEmpty,
|
|
15
|
+
runnerName: nonEmpty,
|
|
16
16
|
snapshotKey: nonEmpty,
|
|
17
17
|
base: nonEmpty,
|
|
18
18
|
snapshotId: nonEmpty,
|
|
@@ -29,7 +29,7 @@ export function parseSnapshotEntry(text) {
|
|
|
29
29
|
return { ok: false, reason: "not JSON" };
|
|
30
30
|
}
|
|
31
31
|
const version = typeof json === "object" && json !== null ? json.version : undefined;
|
|
32
|
-
if (version !==
|
|
32
|
+
if (version !== 2)
|
|
33
33
|
return { ok: false, reason: `unknown version ${JSON.stringify(version) ?? "(none)"}` };
|
|
34
34
|
const parsed = entrySchema.safeParse(json);
|
|
35
35
|
if (!parsed.success) {
|
|
@@ -42,15 +42,15 @@ export function parseSnapshotEntry(text) {
|
|
|
42
42
|
}
|
|
43
43
|
/** The text of the file that records `entry`. */
|
|
44
44
|
export function snapshotEntryText(entry) {
|
|
45
|
-
const { teamId, projectId, region,
|
|
45
|
+
const { teamId, projectId, region, image, runnerName, snapshotKey, base } = entry;
|
|
46
46
|
const { snapshotId, createdAt, expiresAt } = entry;
|
|
47
47
|
const record = {
|
|
48
|
-
version:
|
|
48
|
+
version: 2,
|
|
49
49
|
teamId,
|
|
50
50
|
projectId,
|
|
51
51
|
region,
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
image,
|
|
53
|
+
runnerName,
|
|
54
54
|
snapshotKey,
|
|
55
55
|
base,
|
|
56
56
|
snapshotId,
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import type { Clock } from "../time/index.ts";
|
|
2
|
+
import type { CheckoutGateway, CheckoutResult, RunnerSnapshotEntry, RunnerSnapshotIndexFailure, RunnerSnapshotIndexGateway } from "./gateways.ts";
|
|
3
|
+
import type { CheckedVercelSandboxOptions } from "./vercel-sandbox-options.ts";
|
|
4
|
+
/** The subpath of storm's state directory that holds the local snapshot index. */
|
|
5
|
+
export declare const RUNNER_SNAPSHOTS_SUBPATH: readonly string[];
|
|
6
|
+
/** How long a runner snapshot lives after it is built: 7 days. The Sandbox API needs 0 or at least a day. */
|
|
7
|
+
export declare const SNAPSHOT_EXPIRATION_MS: number;
|
|
8
|
+
/** A run never picks a runner snapshot with this little left or less, 1 hour, so it can't expire before the start. */
|
|
9
|
+
export declare const SNAPSHOT_MIN_REMAINING_MS: number;
|
|
10
|
+
/** The runner fields that scope which snapshots belong to one runner target. */
|
|
11
|
+
export type RunnerSnapshotTarget = Pick<CheckedVercelSandboxOptions, "name" | "region" | "image">;
|
|
12
|
+
/** Whether two runner targets share the same snapshot scope (`name`, `region`, and `image`). */
|
|
13
|
+
export declare function sameRunnerTarget(a: RunnerSnapshotTarget, b: RunnerSnapshotTarget): boolean;
|
|
14
|
+
/** Whether local snapshot index `entry` belongs to runner `target`. */
|
|
15
|
+
export declare function matchesRunnerTarget(entry: Pick<RunnerSnapshotEntry, "runnerName" | "region" | "image">, target: RunnerSnapshotTarget): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* An entry's identity: the first 32 hex characters of sha256 over its team id, project id, region, image, runner
|
|
18
|
+
* name, snapshot key, and base, joined with NUL. Entries with one identity replace each other, so a team and project
|
|
19
|
+
* have one entry per runner, key, and base.
|
|
20
|
+
*/
|
|
21
|
+
export declare function snapshotEntryIdentity(entry: RunnerSnapshotEntry): string;
|
|
22
|
+
/** The name of the file that records `entry`: its identity and `.json`. */
|
|
23
|
+
export declare function snapshotEntryFileName(entry: RunnerSnapshotEntry): string;
|
|
24
|
+
/** Whether `entry`'s snapshot has expired at `now`. */
|
|
25
|
+
export declare function isExpiredEntry(entry: RunnerSnapshotEntry, now: Date): boolean;
|
|
26
|
+
/** Whether `entry`'s snapshot has more than `SNAPSHOT_MIN_REMAINING_MS` left at `now`. */
|
|
27
|
+
export declare function hasTimeLeft(entry: RunnerSnapshotEntry, now: Date): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* A cache entry a run may start from, before the team and project are known: its base is the run's merge-base or an
|
|
30
|
+
* ancestor of it, and its snapshot key is the run's, with how far that base is behind HEAD and behind the merge-base.
|
|
31
|
+
*/
|
|
32
|
+
export interface RunnerSnapshotCandidate {
|
|
33
|
+
readonly entry: RunnerSnapshotEntry;
|
|
34
|
+
/**
|
|
35
|
+
* How many commits HEAD has that this snapshot's base lacks: what the install and the build have left to do. 0 when
|
|
36
|
+
* HEAD is this snapshot's base.
|
|
37
|
+
*/
|
|
38
|
+
readonly builtBehind: number;
|
|
39
|
+
/**
|
|
40
|
+
* How many commits the run's merge-base has that this snapshot's base lacks: 0 for an exact match at the merge-base,
|
|
41
|
+
* and greater than 0 for an ancestor of the merge-base.
|
|
42
|
+
*/
|
|
43
|
+
readonly commitsBehindMergeBase: number;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Ancestor bases of the run's merge-base, keyed by full base commit SHA, each with how many commits the merge-base has
|
|
47
|
+
* that the base lacks. How many commits HEAD has that the base lacks is that count plus the merge-base's own count
|
|
48
|
+
* behind HEAD: the base is an ancestor of the merge-base, and the merge-base an ancestor of HEAD.
|
|
49
|
+
*/
|
|
50
|
+
export type SnapshotAncestorDistanceMap = Readonly<Record<string, number>>;
|
|
51
|
+
/**
|
|
52
|
+
* Why a run doesn't start from a cached snapshot of its runner.
|
|
53
|
+
*
|
|
54
|
+
* - `expired`: it has expired. A run's path removes the file first (`removeExpiredEntries`), so only a list of
|
|
55
|
+
* entries that still holds it, as `storm snapshots list`'s does, gets this reason.
|
|
56
|
+
* - `expires-soon`: it has `SNAPSHOT_MIN_REMAINING_MS` or less left.
|
|
57
|
+
* - `other-base`: its base is neither the run's merge-base nor an ancestor of it. A run starts only from a snapshot
|
|
58
|
+
* built at its merge-base or an ancestor of its merge-base, so no snapshot built from a branch's own commits carries
|
|
59
|
+
* over into a run.
|
|
60
|
+
* - `steps-changed`: its snapshot key isn't the run's, the one the runner's snapshot steps give at the merge-base.
|
|
61
|
+
* - `other-owner`: it was built for another team or project than the run's credential names.
|
|
62
|
+
*
|
|
63
|
+
* The classification gives all but the last, in that order of checks (`classifySnapshotEntries`); `other-owner`
|
|
64
|
+
* needs the team and project (`snapshotRejections`).
|
|
65
|
+
*/
|
|
66
|
+
export type SnapshotRejectionReason = "expired" | "expires-soon" | "other-base" | "steps-changed" | "other-owner";
|
|
67
|
+
/** A cached snapshot of the run's runner that the run doesn't start from, and why. */
|
|
68
|
+
export interface RejectedSnapshot {
|
|
69
|
+
readonly entry: RunnerSnapshotEntry;
|
|
70
|
+
readonly reason: SnapshotRejectionReason;
|
|
71
|
+
}
|
|
72
|
+
/** What the local snapshot index read found: the candidates, and the runner's other entries with why each isn't one. */
|
|
73
|
+
export interface LocalSnapshotIndexRead {
|
|
74
|
+
readonly candidates: readonly RunnerSnapshotCandidate[];
|
|
75
|
+
readonly rejected: readonly RejectedSnapshot[];
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* What the classification says of one `entry` it was given: a candidate, a rejection with its reason, or that the
|
|
79
|
+
* entry is of another runner, region, or image (`other-runner`), which no run of the runner looks at.
|
|
80
|
+
*/
|
|
81
|
+
export type SnapshotVerdict = {
|
|
82
|
+
readonly kind: "candidate";
|
|
83
|
+
readonly entry: RunnerSnapshotEntry;
|
|
84
|
+
readonly candidate: RunnerSnapshotCandidate;
|
|
85
|
+
} | {
|
|
86
|
+
readonly kind: "rejected";
|
|
87
|
+
readonly entry: RunnerSnapshotEntry;
|
|
88
|
+
readonly rejection: RejectedSnapshot;
|
|
89
|
+
} | {
|
|
90
|
+
readonly kind: "other-runner";
|
|
91
|
+
readonly entry: RunnerSnapshotEntry;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* What `classifySnapshotEntries` found: the index read's candidates and rejections, and one verdict per entry it was
|
|
95
|
+
* given, in the order given. Each verdict holds the same candidate or rejection object as the lists.
|
|
96
|
+
*/
|
|
97
|
+
export interface SnapshotClassification extends LocalSnapshotIndexRead {
|
|
98
|
+
readonly verdicts: readonly SnapshotVerdict[];
|
|
99
|
+
}
|
|
100
|
+
/** What `removeExpiredEntries` left: the local snapshot index's unexpired entries, and its notes. */
|
|
101
|
+
export interface LocalSnapshotIndexListing {
|
|
102
|
+
readonly entries: readonly RunnerSnapshotEntry[];
|
|
103
|
+
readonly notes: readonly SnapshotIndexNote[];
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Something removing expired entries noticed (`removeExpiredEntries`), which the run reports and goes on from.
|
|
107
|
+
*
|
|
108
|
+
* - `local-index-unreadable`: the local snapshot index couldn't be listed, so the run treats it as empty.
|
|
109
|
+
* - `expired-entry-not-removed`: an expired entry's file couldn't be removed.
|
|
110
|
+
*/
|
|
111
|
+
export type SnapshotIndexNote = {
|
|
112
|
+
readonly kind: "local-index-unreadable";
|
|
113
|
+
readonly failure: RunnerSnapshotIndexFailure;
|
|
114
|
+
} | {
|
|
115
|
+
readonly kind: "expired-entry-not-removed";
|
|
116
|
+
readonly entry: RunnerSnapshotEntry;
|
|
117
|
+
readonly failure: RunnerSnapshotIndexFailure;
|
|
118
|
+
};
|
|
119
|
+
/** What the local snapshot index context needs: the checkout, the local snapshot index, and the clock. */
|
|
120
|
+
export interface LocalSnapshotIndexContext {
|
|
121
|
+
readonly checkout: CheckoutGateway;
|
|
122
|
+
readonly runnerSnapshots: RunnerSnapshotIndexGateway;
|
|
123
|
+
readonly clock: Clock;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Lists the local snapshot index and removes the files of expired entries, as a run's read does before it classifies
|
|
127
|
+
* the rest (`classifySnapshotEntries`). It gives the unexpired entries, and notes `expired-entry-not-removed` for a
|
|
128
|
+
* file it couldn't remove, whose entry it leaves out all the same. An index it can't list is empty, with the note
|
|
129
|
+
* `local-index-unreadable`. Only a run's path calls it: `storm snapshots list` removes no file.
|
|
130
|
+
*/
|
|
131
|
+
export declare function removeExpiredEntries(context: Pick<LocalSnapshotIndexContext, "runnerSnapshots" | "clock">): Promise<LocalSnapshotIndexListing>;
|
|
132
|
+
/**
|
|
133
|
+
* Checks which non-merge-base commits among `entries` (for `options`, unexpired with time left) are ancestors of
|
|
134
|
+
* `mergeBase`, returning each qualifying ancestor's commit distance behind `mergeBase`. Each distinct base SHA is
|
|
135
|
+
* queried in Git at most once.
|
|
136
|
+
*/
|
|
137
|
+
export declare function resolveAncestorDistances(context: Pick<LocalSnapshotIndexContext, "checkout" | "clock">, request: {
|
|
138
|
+
readonly repoRoot: string;
|
|
139
|
+
readonly entries: readonly RunnerSnapshotEntry[];
|
|
140
|
+
readonly options: RunnerSnapshotTarget;
|
|
141
|
+
readonly mergeBase: string;
|
|
142
|
+
}): Promise<CheckoutResult<SnapshotAncestorDistanceMap>>;
|
|
143
|
+
/**
|
|
144
|
+
* Classifies `entries`, cache entries a caller listed, for a run of `options`: which ones it may start from, and why
|
|
145
|
+
* not from each other one of the runner's. It changes no file and asks Git nothing. Of the entries for the runner's
|
|
146
|
+
* region, image, and name, it keeps the ones with more than an hour left whose base is the run's merge-base (or an
|
|
147
|
+
* ancestor in `ancestorDistances`) and whose snapshot key is the run's. Candidates are sorted by
|
|
148
|
+
* `commitsBehindMergeBase` ascending, newest `createdAt` descending, and `snapshotId` ascending. Every other entry of
|
|
149
|
+
* the runner is `rejected`, with the first reason that rules it out, an expired one as `expired`. Each entry gets
|
|
150
|
+
* exactly one verdict, in the order given.
|
|
151
|
+
*/
|
|
152
|
+
export declare function classifySnapshotEntries(context: Pick<LocalSnapshotIndexContext, "clock">, request: {
|
|
153
|
+
readonly entries: readonly RunnerSnapshotEntry[];
|
|
154
|
+
readonly options: RunnerSnapshotTarget;
|
|
155
|
+
/** The run's base, HEAD's merge-base with a base ref. */
|
|
156
|
+
readonly base: string;
|
|
157
|
+
/** The run's snapshot key, the runner's snapshot steps at `base`: a candidate's key is this one. */
|
|
158
|
+
readonly snapshotKey: string;
|
|
159
|
+
/** How many commits HEAD has that `base` lacks: the `builtBehind` of a candidate at `base`. */
|
|
160
|
+
readonly commitsAfterBase: number;
|
|
161
|
+
/**
|
|
162
|
+
* Ancestors of `base` that qualify as fallback bases (`resolveAncestorDistances`), keyed by full commit SHA.
|
|
163
|
+
* Omit when only exact matches at `base` qualify.
|
|
164
|
+
*/
|
|
165
|
+
readonly ancestorDistances?: SnapshotAncestorDistanceMap;
|
|
166
|
+
}): SnapshotClassification;
|
|
167
|
+
/** Parses an ISO timestamp to milliseconds since epoch, or `-Infinity` when unparseable. */
|
|
168
|
+
export declare function parseTimestampMs(iso: string): number;
|
|
169
|
+
/**
|
|
170
|
+
* Orders snapshot candidates by preference: fewest commits behind the merge-base first, then newest `createdAt`,
|
|
171
|
+
* then ascending tie-breaker (`snapshotId` or `sandboxName`).
|
|
172
|
+
*/
|
|
173
|
+
export declare function compareSnapshotCandidates(a: {
|
|
174
|
+
readonly commitsBehindMergeBase: number;
|
|
175
|
+
readonly createdAt: string;
|
|
176
|
+
readonly tieBreaker: string;
|
|
177
|
+
}, b: {
|
|
178
|
+
readonly commitsBehindMergeBase: number;
|
|
179
|
+
readonly createdAt: string;
|
|
180
|
+
readonly tieBreaker: string;
|
|
181
|
+
}): number;
|
|
182
|
+
/**
|
|
183
|
+
* Whether a shared snapshot index entry `sharedCommitsBehindMergeBase` commits behind the run's merge-base beats the
|
|
184
|
+
* local snapshot index's pick, `localCommitsBehindMergeBase` behind it (undefined when the local snapshot index has
|
|
185
|
+
* none): only when it is strictly closer, so a tie keeps the local pick. A run (`chooseSnapshot`), its shared lookup
|
|
186
|
+
* (`lookupSharedSnapshot`), and `storm snapshots list --shared` (`pickSnapshotAcrossIndexes`) all decide with it.
|
|
187
|
+
*/
|
|
188
|
+
export declare function sharedBeatsLocal(sharedCommitsBehindMergeBase: number, localCommitsBehindMergeBase: number | undefined): boolean;
|
|
189
|
+
/**
|
|
190
|
+
* Why a run for `owner`'s team and project starts from none of the runner's cached snapshots, when the pick found no
|
|
191
|
+
* candidate of theirs: every candidate is then another team's or project's, `other-owner`; an entry for another team
|
|
192
|
+
* or project is `other-owner`, whatever else rules it out; and any other entry keeps the classification's reason.
|
|
193
|
+
*/
|
|
194
|
+
export declare function snapshotRejections(read: LocalSnapshotIndexRead, owner: {
|
|
195
|
+
readonly teamId: string;
|
|
196
|
+
readonly projectId: string;
|
|
197
|
+
}): RejectedSnapshot[];
|
|
198
|
+
/**
|
|
199
|
+
* Picks the runner snapshot a run starts from, once the credential names its team and project: the first candidate in
|
|
200
|
+
* preference order (`classifySnapshotEntries`) for that team and project, or `undefined` when none matches.
|
|
201
|
+
*/
|
|
202
|
+
export declare function pickSnapshot(candidates: readonly RunnerSnapshotCandidate[], owner: {
|
|
203
|
+
readonly teamId: string;
|
|
204
|
+
readonly projectId: string;
|
|
205
|
+
}): RunnerSnapshotCandidate | undefined;
|