@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
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
// The
|
|
1
|
+
// The local snapshot index's file format: one JSON object per runner snapshot, carrying `version: 1`. 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
|
-
// and no run starts from it: there is no migration.
|
|
3
|
+
// (`snapshotEntryIdentity`), and the gateway lists a file whose name isn't as unreadable. Older files (such as ones
|
|
4
|
+
// using the retired runner-name field) are listed as unreadable, and no run starts from them: there is no migration.
|
|
6
5
|
import { z } from "zod";
|
|
7
6
|
const isoTime = z.string().refine((value) => !Number.isNaN(Date.parse(value)), { message: "not a time" });
|
|
8
7
|
const nonEmpty = z.string().min(1);
|
|
@@ -12,7 +11,7 @@ const entrySchema = z.object({
|
|
|
12
11
|
projectId: nonEmpty,
|
|
13
12
|
region: nonEmpty,
|
|
14
13
|
runtime: nonEmpty,
|
|
15
|
-
|
|
14
|
+
runnerName: nonEmpty,
|
|
16
15
|
snapshotKey: nonEmpty,
|
|
17
16
|
base: nonEmpty,
|
|
18
17
|
snapshotId: nonEmpty,
|
|
@@ -42,7 +41,7 @@ export function parseSnapshotEntry(text) {
|
|
|
42
41
|
}
|
|
43
42
|
/** The text of the file that records `entry`. */
|
|
44
43
|
export function snapshotEntryText(entry) {
|
|
45
|
-
const { teamId, projectId, region, runtime,
|
|
44
|
+
const { teamId, projectId, region, runtime, runnerName, snapshotKey, base } = entry;
|
|
46
45
|
const { snapshotId, createdAt, expiresAt } = entry;
|
|
47
46
|
const record = {
|
|
48
47
|
version: 1,
|
|
@@ -50,7 +49,7 @@ export function snapshotEntryText(entry) {
|
|
|
50
49
|
projectId,
|
|
51
50
|
region,
|
|
52
51
|
runtime,
|
|
53
|
-
|
|
52
|
+
runnerName,
|
|
54
53
|
snapshotKey,
|
|
55
54
|
base,
|
|
56
55
|
snapshotId,
|
|
@@ -0,0 +1,199 @@
|
|
|
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
|
+
/**
|
|
11
|
+
* An entry's identity: the first 32 hex characters of sha256 over its team id, project id, region, runtime, runner
|
|
12
|
+
* name, snapshot key, and base, joined with NUL. Entries with one identity replace each other, so a team and project
|
|
13
|
+
* have one entry per runner, key, and base.
|
|
14
|
+
*/
|
|
15
|
+
export declare function snapshotEntryIdentity(entry: RunnerSnapshotEntry): string;
|
|
16
|
+
/** The name of the file that records `entry`: its identity and `.json`. */
|
|
17
|
+
export declare function snapshotEntryFileName(entry: RunnerSnapshotEntry): string;
|
|
18
|
+
/** Whether `entry`'s snapshot has expired at `now`. */
|
|
19
|
+
export declare function isExpiredEntry(entry: RunnerSnapshotEntry, now: Date): boolean;
|
|
20
|
+
/** Whether `entry`'s snapshot has more than `SNAPSHOT_MIN_REMAINING_MS` left at `now`. */
|
|
21
|
+
export declare function hasTimeLeft(entry: RunnerSnapshotEntry, now: Date): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* 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
|
|
24
|
+
* ancestor of it, and its snapshot key is the run's, with how far that base is behind HEAD and behind the merge-base.
|
|
25
|
+
*/
|
|
26
|
+
export interface RunnerSnapshotCandidate {
|
|
27
|
+
readonly entry: RunnerSnapshotEntry;
|
|
28
|
+
/**
|
|
29
|
+
* How many commits HEAD has that this snapshot's base lacks: what the install and the build have left to do. 0 when
|
|
30
|
+
* HEAD is this snapshot's base.
|
|
31
|
+
*/
|
|
32
|
+
readonly builtBehind: number;
|
|
33
|
+
/**
|
|
34
|
+
* How many commits the run's merge-base has that this snapshot's base lacks: 0 for an exact match at the merge-base,
|
|
35
|
+
* and greater than 0 for an ancestor of the merge-base.
|
|
36
|
+
*/
|
|
37
|
+
readonly commitsBehindMergeBase: number;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Ancestor bases of the run's merge-base, keyed by full base commit SHA, each with how many commits the merge-base has
|
|
41
|
+
* that the base lacks. How many commits HEAD has that the base lacks is that count plus the merge-base's own count
|
|
42
|
+
* behind HEAD: the base is an ancestor of the merge-base, and the merge-base an ancestor of HEAD.
|
|
43
|
+
*/
|
|
44
|
+
export type SnapshotAncestorDistanceMap = Readonly<Record<string, number>>;
|
|
45
|
+
/**
|
|
46
|
+
* Why a run doesn't start from a cached snapshot of its runner.
|
|
47
|
+
*
|
|
48
|
+
* - `expired`: it has expired. A run's path removes the file first (`removeExpiredEntries`), so only a list of
|
|
49
|
+
* entries that still holds it, as `storm snapshots list`'s does, gets this reason.
|
|
50
|
+
* - `expires-soon`: it has `SNAPSHOT_MIN_REMAINING_MS` or less left.
|
|
51
|
+
* - `other-base`: its base is neither the run's merge-base nor an ancestor of it. A run starts only from a snapshot
|
|
52
|
+
* built at its merge-base or an ancestor of its merge-base, so no snapshot built from a branch's own commits carries
|
|
53
|
+
* over into a run.
|
|
54
|
+
* - `steps-changed`: its snapshot key isn't the run's, the one the runner's snapshot steps give at the merge-base.
|
|
55
|
+
* - `other-owner`: it was built for another team or project than the run's credential names.
|
|
56
|
+
*
|
|
57
|
+
* The classification gives all but the last, in that order of checks (`classifySnapshotEntries`); `other-owner`
|
|
58
|
+
* needs the team and project (`snapshotRejections`).
|
|
59
|
+
*/
|
|
60
|
+
export type SnapshotRejectionReason = "expired" | "expires-soon" | "other-base" | "steps-changed" | "other-owner";
|
|
61
|
+
/** A cached snapshot of the run's runner that the run doesn't start from, and why. */
|
|
62
|
+
export interface RejectedSnapshot {
|
|
63
|
+
readonly entry: RunnerSnapshotEntry;
|
|
64
|
+
readonly reason: SnapshotRejectionReason;
|
|
65
|
+
}
|
|
66
|
+
/** What the local snapshot index read found: the candidates, and the runner's other entries with why each isn't one. */
|
|
67
|
+
export interface LocalSnapshotIndexRead {
|
|
68
|
+
readonly candidates: readonly RunnerSnapshotCandidate[];
|
|
69
|
+
readonly rejected: readonly RejectedSnapshot[];
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* What the classification says of one `entry` it was given: a candidate, a rejection with its reason, or that the
|
|
73
|
+
* entry is of another runner, region, or runtime (`other-runner`), which no run of the runner looks at.
|
|
74
|
+
*/
|
|
75
|
+
export type SnapshotVerdict = {
|
|
76
|
+
readonly kind: "candidate";
|
|
77
|
+
readonly entry: RunnerSnapshotEntry;
|
|
78
|
+
readonly candidate: RunnerSnapshotCandidate;
|
|
79
|
+
} | {
|
|
80
|
+
readonly kind: "rejected";
|
|
81
|
+
readonly entry: RunnerSnapshotEntry;
|
|
82
|
+
readonly rejection: RejectedSnapshot;
|
|
83
|
+
} | {
|
|
84
|
+
readonly kind: "other-runner";
|
|
85
|
+
readonly entry: RunnerSnapshotEntry;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* What `classifySnapshotEntries` found: the index read's candidates and rejections, and one verdict per entry it was
|
|
89
|
+
* given, in the order given. Each verdict holds the same candidate or rejection object as the lists.
|
|
90
|
+
*/
|
|
91
|
+
export interface SnapshotClassification extends LocalSnapshotIndexRead {
|
|
92
|
+
readonly verdicts: readonly SnapshotVerdict[];
|
|
93
|
+
}
|
|
94
|
+
/** What `removeExpiredEntries` left: the local snapshot index's unexpired entries, and its notes. */
|
|
95
|
+
export interface LocalSnapshotIndexListing {
|
|
96
|
+
readonly entries: readonly RunnerSnapshotEntry[];
|
|
97
|
+
readonly notes: readonly SnapshotIndexNote[];
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Something removing expired entries noticed (`removeExpiredEntries`), which the run reports and goes on from.
|
|
101
|
+
*
|
|
102
|
+
* - `local-index-unreadable`: the local snapshot index couldn't be listed, so the run treats it as empty.
|
|
103
|
+
* - `expired-entry-not-removed`: an expired entry's file couldn't be removed.
|
|
104
|
+
*/
|
|
105
|
+
export type SnapshotIndexNote = {
|
|
106
|
+
readonly kind: "local-index-unreadable";
|
|
107
|
+
readonly failure: RunnerSnapshotIndexFailure;
|
|
108
|
+
} | {
|
|
109
|
+
readonly kind: "expired-entry-not-removed";
|
|
110
|
+
readonly entry: RunnerSnapshotEntry;
|
|
111
|
+
readonly failure: RunnerSnapshotIndexFailure;
|
|
112
|
+
};
|
|
113
|
+
/** What the local snapshot index context needs: the checkout, the local snapshot index, and the clock. */
|
|
114
|
+
export interface LocalSnapshotIndexContext {
|
|
115
|
+
readonly checkout: CheckoutGateway;
|
|
116
|
+
readonly runnerSnapshots: RunnerSnapshotIndexGateway;
|
|
117
|
+
readonly clock: Clock;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Lists the local snapshot index and removes the files of expired entries, as a run's read does before it classifies
|
|
121
|
+
* the rest (`classifySnapshotEntries`). It gives the unexpired entries, and notes `expired-entry-not-removed` for a
|
|
122
|
+
* file it couldn't remove, whose entry it leaves out all the same. An index it can't list is empty, with the note
|
|
123
|
+
* `local-index-unreadable`. Only a run's path calls it: `storm snapshots list` removes no file.
|
|
124
|
+
*/
|
|
125
|
+
export declare function removeExpiredEntries(context: Pick<LocalSnapshotIndexContext, "runnerSnapshots" | "clock">): Promise<LocalSnapshotIndexListing>;
|
|
126
|
+
/**
|
|
127
|
+
* Checks which non-merge-base commits among `entries` (for `options`, unexpired with time left) are ancestors of
|
|
128
|
+
* `mergeBase`, returning each qualifying ancestor's commit distance behind `mergeBase`. Each distinct base SHA is
|
|
129
|
+
* queried in Git at most once.
|
|
130
|
+
*/
|
|
131
|
+
export declare function resolveAncestorDistances(context: Pick<LocalSnapshotIndexContext, "checkout" | "clock">, request: {
|
|
132
|
+
readonly repoRoot: string;
|
|
133
|
+
readonly entries: readonly RunnerSnapshotEntry[];
|
|
134
|
+
readonly options: Pick<CheckedVercelSandboxOptions, "name" | "region" | "runtime">;
|
|
135
|
+
readonly mergeBase: string;
|
|
136
|
+
}): Promise<CheckoutResult<SnapshotAncestorDistanceMap>>;
|
|
137
|
+
/**
|
|
138
|
+
* Classifies `entries`, cache entries a caller listed, for a run of `options`: which ones it may start from, and why
|
|
139
|
+
* not from each other one of the runner's. It changes no file and asks Git nothing. Of the entries for the runner's
|
|
140
|
+
* region, runtime, and name, it keeps the ones with more than an hour left whose base is the run's merge-base (or an
|
|
141
|
+
* ancestor in `ancestorDistances`) and whose snapshot key is the run's. Candidates are sorted by
|
|
142
|
+
* `commitsBehindMergeBase` ascending, newest `createdAt` descending, and `snapshotId` ascending. Every other entry of
|
|
143
|
+
* the runner is `rejected`, with the first reason that rules it out, an expired one as `expired`. Each entry gets
|
|
144
|
+
* exactly one verdict, in the order given.
|
|
145
|
+
*/
|
|
146
|
+
export declare function classifySnapshotEntries(context: Pick<LocalSnapshotIndexContext, "clock">, request: {
|
|
147
|
+
readonly entries: readonly RunnerSnapshotEntry[];
|
|
148
|
+
readonly options: Pick<CheckedVercelSandboxOptions, "name" | "region" | "runtime">;
|
|
149
|
+
/** The run's base, HEAD's merge-base with a base ref. */
|
|
150
|
+
readonly base: string;
|
|
151
|
+
/** The run's snapshot key, the runner's snapshot steps at `base`: a candidate's key is this one. */
|
|
152
|
+
readonly snapshotKey: string;
|
|
153
|
+
/** How many commits HEAD has that `base` lacks: the `builtBehind` of a candidate at `base`. */
|
|
154
|
+
readonly commitsAfterBase: number;
|
|
155
|
+
/**
|
|
156
|
+
* Ancestors of `base` that qualify as fallback bases (`resolveAncestorDistances`), keyed by full commit SHA.
|
|
157
|
+
* Omit when only exact matches at `base` qualify.
|
|
158
|
+
*/
|
|
159
|
+
readonly ancestorDistances?: SnapshotAncestorDistanceMap;
|
|
160
|
+
}): SnapshotClassification;
|
|
161
|
+
/** Parses an ISO timestamp to milliseconds since epoch, or `-Infinity` when unparseable. */
|
|
162
|
+
export declare function parseTimestampMs(iso: string): number;
|
|
163
|
+
/**
|
|
164
|
+
* Orders snapshot candidates by preference: fewest commits behind the merge-base first, then newest `createdAt`,
|
|
165
|
+
* then ascending tie-breaker (`snapshotId` or `sandboxName`).
|
|
166
|
+
*/
|
|
167
|
+
export declare function compareSnapshotCandidates(a: {
|
|
168
|
+
readonly commitsBehindMergeBase: number;
|
|
169
|
+
readonly createdAt: string;
|
|
170
|
+
readonly tieBreaker: string;
|
|
171
|
+
}, b: {
|
|
172
|
+
readonly commitsBehindMergeBase: number;
|
|
173
|
+
readonly createdAt: string;
|
|
174
|
+
readonly tieBreaker: string;
|
|
175
|
+
}): number;
|
|
176
|
+
/**
|
|
177
|
+
* Whether a shared snapshot index entry `sharedCommitsBehindMergeBase` commits behind the run's merge-base beats the
|
|
178
|
+
* local snapshot index's pick, `localCommitsBehindMergeBase` behind it (undefined when the local snapshot index has
|
|
179
|
+
* none): only when it is strictly closer, so a tie keeps the local pick. A run (`chooseSnapshot`), its shared lookup
|
|
180
|
+
* (`lookupSharedSnapshot`), and `storm snapshots list --shared` (`pickSnapshotAcrossIndexes`) all decide with it.
|
|
181
|
+
*/
|
|
182
|
+
export declare function sharedBeatsLocal(sharedCommitsBehindMergeBase: number, localCommitsBehindMergeBase: number | undefined): boolean;
|
|
183
|
+
/**
|
|
184
|
+
* Why a run for `owner`'s team and project starts from none of the runner's cached snapshots, when the pick found no
|
|
185
|
+
* candidate of theirs: every candidate is then another team's or project's, `other-owner`; an entry for another team
|
|
186
|
+
* or project is `other-owner`, whatever else rules it out; and any other entry keeps the classification's reason.
|
|
187
|
+
*/
|
|
188
|
+
export declare function snapshotRejections(read: LocalSnapshotIndexRead, owner: {
|
|
189
|
+
readonly teamId: string;
|
|
190
|
+
readonly projectId: string;
|
|
191
|
+
}): RejectedSnapshot[];
|
|
192
|
+
/**
|
|
193
|
+
* Picks the runner snapshot a run starts from, once the credential names its team and project: the first candidate in
|
|
194
|
+
* preference order (`classifySnapshotEntries`) for that team and project, or `undefined` when none matches.
|
|
195
|
+
*/
|
|
196
|
+
export declare function pickSnapshot(candidates: readonly RunnerSnapshotCandidate[], owner: {
|
|
197
|
+
readonly teamId: string;
|
|
198
|
+
readonly projectId: string;
|
|
199
|
+
}): RunnerSnapshotCandidate | undefined;
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
// Which runner snapshots in the local snapshot index a run may start from, and which one it picks. The index's files
|
|
2
|
+
// are the gateway's; their identity, expiry, and the choice among them are here: a run's path removes expired entries'
|
|
3
|
+
// files (`removeExpiredEntries`), and the classification of a list of entries changes no file
|
|
4
|
+
// (`classifySnapshotEntries`).
|
|
5
|
+
import { createHash } from "node:crypto";
|
|
6
|
+
/** The subpath of storm's state directory that holds the local snapshot index. */
|
|
7
|
+
export const RUNNER_SNAPSHOTS_SUBPATH = ["runner", "snapshots"];
|
|
8
|
+
/** How long a runner snapshot lives after it is built: 7 days. The Sandbox API needs 0 or at least a day. */
|
|
9
|
+
export const SNAPSHOT_EXPIRATION_MS = 7 * 24 * 60 * 60 * 1000;
|
|
10
|
+
/** A run never picks a runner snapshot with this little left or less, 1 hour, so it can't expire before the start. */
|
|
11
|
+
export const SNAPSHOT_MIN_REMAINING_MS = 60 * 60 * 1000;
|
|
12
|
+
/**
|
|
13
|
+
* An entry's identity: the first 32 hex characters of sha256 over its team id, project id, region, runtime, runner
|
|
14
|
+
* name, snapshot key, and base, joined with NUL. Entries with one identity replace each other, so a team and project
|
|
15
|
+
* have one entry per runner, key, and base.
|
|
16
|
+
*/
|
|
17
|
+
export function snapshotEntryIdentity(entry) {
|
|
18
|
+
return createHash("sha256")
|
|
19
|
+
.update([
|
|
20
|
+
entry.teamId,
|
|
21
|
+
entry.projectId,
|
|
22
|
+
entry.region,
|
|
23
|
+
entry.runtime,
|
|
24
|
+
entry.runnerName,
|
|
25
|
+
entry.snapshotKey,
|
|
26
|
+
entry.base,
|
|
27
|
+
].join("\0"))
|
|
28
|
+
.digest("hex")
|
|
29
|
+
.slice(0, 32);
|
|
30
|
+
}
|
|
31
|
+
/** The name of the file that records `entry`: its identity and `.json`. */
|
|
32
|
+
export function snapshotEntryFileName(entry) {
|
|
33
|
+
return `${snapshotEntryIdentity(entry)}.json`;
|
|
34
|
+
}
|
|
35
|
+
/** Whether `entry`'s snapshot has expired at `now`. */
|
|
36
|
+
export function isExpiredEntry(entry, now) {
|
|
37
|
+
return Date.parse(entry.expiresAt) <= now.getTime();
|
|
38
|
+
}
|
|
39
|
+
/** Whether `entry`'s snapshot has more than `SNAPSHOT_MIN_REMAINING_MS` left at `now`. */
|
|
40
|
+
export function hasTimeLeft(entry, now) {
|
|
41
|
+
return Date.parse(entry.expiresAt) - now.getTime() > SNAPSHOT_MIN_REMAINING_MS;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Lists the local snapshot index and removes the files of expired entries, as a run's read does before it classifies
|
|
45
|
+
* the rest (`classifySnapshotEntries`). It gives the unexpired entries, and notes `expired-entry-not-removed` for a
|
|
46
|
+
* file it couldn't remove, whose entry it leaves out all the same. An index it can't list is empty, with the note
|
|
47
|
+
* `local-index-unreadable`. Only a run's path calls it: `storm snapshots list` removes no file.
|
|
48
|
+
*/
|
|
49
|
+
export async function removeExpiredEntries(context) {
|
|
50
|
+
const { runnerSnapshots } = context;
|
|
51
|
+
const listed = await runnerSnapshots.listEntries();
|
|
52
|
+
if (!listed.ok)
|
|
53
|
+
return { entries: [], notes: [{ kind: "local-index-unreadable", failure: listed.failure }] };
|
|
54
|
+
const now = context.clock.now();
|
|
55
|
+
const entries = [];
|
|
56
|
+
const notes = [];
|
|
57
|
+
for (const entry of listed.value.entries) {
|
|
58
|
+
if (!isExpiredEntry(entry, now)) {
|
|
59
|
+
entries.push(entry);
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
const removed = await runnerSnapshots.removeEntry(entry);
|
|
63
|
+
if (!removed.ok)
|
|
64
|
+
notes.push({ kind: "expired-entry-not-removed", entry, failure: removed.failure });
|
|
65
|
+
}
|
|
66
|
+
return { entries, notes };
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Checks which non-merge-base commits among `entries` (for `options`, unexpired with time left) are ancestors of
|
|
70
|
+
* `mergeBase`, returning each qualifying ancestor's commit distance behind `mergeBase`. Each distinct base SHA is
|
|
71
|
+
* queried in Git at most once.
|
|
72
|
+
*/
|
|
73
|
+
export async function resolveAncestorDistances(context, request) {
|
|
74
|
+
const { checkout, clock } = context;
|
|
75
|
+
const { repoRoot, entries, options, mergeBase } = request;
|
|
76
|
+
const now = clock.now();
|
|
77
|
+
const seen = new Set([mergeBase]);
|
|
78
|
+
const distances = {};
|
|
79
|
+
for (const entry of entries) {
|
|
80
|
+
if (entry.region !== options.region || entry.runtime !== options.runtime || entry.runnerName !== options.name) {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (isExpiredEntry(entry, now) || !hasTimeLeft(entry, now))
|
|
84
|
+
continue;
|
|
85
|
+
if (seen.has(entry.base))
|
|
86
|
+
continue;
|
|
87
|
+
seen.add(entry.base);
|
|
88
|
+
const contained = await checkout.contains({ repoRoot, ancestor: entry.base, descendant: mergeBase });
|
|
89
|
+
if (!contained.ok)
|
|
90
|
+
return contained;
|
|
91
|
+
if (!contained.value)
|
|
92
|
+
continue;
|
|
93
|
+
const behindMergeBase = await checkout.commitCount({ repoRoot, from: entry.base, to: mergeBase });
|
|
94
|
+
if (!behindMergeBase.ok)
|
|
95
|
+
return behindMergeBase;
|
|
96
|
+
distances[entry.base] = behindMergeBase.value;
|
|
97
|
+
}
|
|
98
|
+
return { ok: true, value: distances };
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Classifies `entries`, cache entries a caller listed, for a run of `options`: which ones it may start from, and why
|
|
102
|
+
* not from each other one of the runner's. It changes no file and asks Git nothing. Of the entries for the runner's
|
|
103
|
+
* region, runtime, and name, it keeps the ones with more than an hour left whose base is the run's merge-base (or an
|
|
104
|
+
* ancestor in `ancestorDistances`) and whose snapshot key is the run's. Candidates are sorted by
|
|
105
|
+
* `commitsBehindMergeBase` ascending, newest `createdAt` descending, and `snapshotId` ascending. Every other entry of
|
|
106
|
+
* the runner is `rejected`, with the first reason that rules it out, an expired one as `expired`. Each entry gets
|
|
107
|
+
* exactly one verdict, in the order given.
|
|
108
|
+
*/
|
|
109
|
+
export function classifySnapshotEntries(context, request) {
|
|
110
|
+
const { entries, options, base, snapshotKey, commitsAfterBase, ancestorDistances } = request;
|
|
111
|
+
const now = context.clock.now();
|
|
112
|
+
const candidates = [];
|
|
113
|
+
const rejected = [];
|
|
114
|
+
const verdicts = [];
|
|
115
|
+
const reject = (entry, reason) => {
|
|
116
|
+
const rejection = { entry, reason };
|
|
117
|
+
rejected.push(rejection);
|
|
118
|
+
verdicts.push({ kind: "rejected", entry, rejection });
|
|
119
|
+
};
|
|
120
|
+
for (const entry of entries) {
|
|
121
|
+
if (entry.region !== options.region || entry.runtime !== options.runtime || entry.runnerName !== options.name) {
|
|
122
|
+
verdicts.push({ kind: "other-runner", entry });
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
if (isExpiredEntry(entry, now)) {
|
|
126
|
+
reject(entry, "expired");
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if (!hasTimeLeft(entry, now)) {
|
|
130
|
+
reject(entry, "expires-soon");
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
const commitsBehindMergeBase = entry.base === base
|
|
134
|
+
? 0
|
|
135
|
+
: ancestorDistances !== undefined && Object.hasOwn(ancestorDistances, entry.base)
|
|
136
|
+
? ancestorDistances[entry.base]
|
|
137
|
+
: undefined;
|
|
138
|
+
if (commitsBehindMergeBase === undefined) {
|
|
139
|
+
reject(entry, "other-base");
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
if (entry.snapshotKey !== snapshotKey) {
|
|
143
|
+
reject(entry, "steps-changed");
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
const candidate = {
|
|
147
|
+
entry,
|
|
148
|
+
builtBehind: commitsAfterBase + commitsBehindMergeBase,
|
|
149
|
+
commitsBehindMergeBase,
|
|
150
|
+
};
|
|
151
|
+
candidates.push(candidate);
|
|
152
|
+
verdicts.push({ kind: "candidate", entry, candidate });
|
|
153
|
+
}
|
|
154
|
+
candidates.sort((a, b) => compareSnapshotCandidates({
|
|
155
|
+
commitsBehindMergeBase: a.commitsBehindMergeBase,
|
|
156
|
+
createdAt: a.entry.createdAt,
|
|
157
|
+
tieBreaker: a.entry.snapshotId,
|
|
158
|
+
}, {
|
|
159
|
+
commitsBehindMergeBase: b.commitsBehindMergeBase,
|
|
160
|
+
createdAt: b.entry.createdAt,
|
|
161
|
+
tieBreaker: b.entry.snapshotId,
|
|
162
|
+
}));
|
|
163
|
+
return { candidates, rejected, verdicts };
|
|
164
|
+
}
|
|
165
|
+
/** Parses an ISO timestamp to milliseconds since epoch, or `-Infinity` when unparseable. */
|
|
166
|
+
export function parseTimestampMs(iso) {
|
|
167
|
+
const ms = Date.parse(iso);
|
|
168
|
+
return Number.isNaN(ms) ? Number.NEGATIVE_INFINITY : ms;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Orders snapshot candidates by preference: fewest commits behind the merge-base first, then newest `createdAt`,
|
|
172
|
+
* then ascending tie-breaker (`snapshotId` or `sandboxName`).
|
|
173
|
+
*/
|
|
174
|
+
export function compareSnapshotCandidates(a, b) {
|
|
175
|
+
if (a.commitsBehindMergeBase !== b.commitsBehindMergeBase) {
|
|
176
|
+
return a.commitsBehindMergeBase - b.commitsBehindMergeBase;
|
|
177
|
+
}
|
|
178
|
+
const aCreated = parseTimestampMs(a.createdAt);
|
|
179
|
+
const bCreated = parseTimestampMs(b.createdAt);
|
|
180
|
+
if (aCreated !== bCreated)
|
|
181
|
+
return bCreated - aCreated;
|
|
182
|
+
return a.tieBreaker < b.tieBreaker ? -1 : a.tieBreaker > b.tieBreaker ? 1 : 0;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Whether a shared snapshot index entry `sharedCommitsBehindMergeBase` commits behind the run's merge-base beats the
|
|
186
|
+
* local snapshot index's pick, `localCommitsBehindMergeBase` behind it (undefined when the local snapshot index has
|
|
187
|
+
* none): only when it is strictly closer, so a tie keeps the local pick. A run (`chooseSnapshot`), its shared lookup
|
|
188
|
+
* (`lookupSharedSnapshot`), and `storm snapshots list --shared` (`pickSnapshotAcrossIndexes`) all decide with it.
|
|
189
|
+
*/
|
|
190
|
+
export function sharedBeatsLocal(sharedCommitsBehindMergeBase, localCommitsBehindMergeBase) {
|
|
191
|
+
return localCommitsBehindMergeBase === undefined || sharedCommitsBehindMergeBase < localCommitsBehindMergeBase;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Why a run for `owner`'s team and project starts from none of the runner's cached snapshots, when the pick found no
|
|
195
|
+
* candidate of theirs: every candidate is then another team's or project's, `other-owner`; an entry for another team
|
|
196
|
+
* or project is `other-owner`, whatever else rules it out; and any other entry keeps the classification's reason.
|
|
197
|
+
*/
|
|
198
|
+
export function snapshotRejections(read, owner) {
|
|
199
|
+
const owned = (entry) => entry.teamId === owner.teamId && entry.projectId === owner.projectId;
|
|
200
|
+
return [
|
|
201
|
+
...read.candidates.map(({ entry }) => ({ entry, reason: "other-owner" })),
|
|
202
|
+
...read.rejected.map(({ entry, reason }) => ({ entry, reason: owned(entry) ? reason : "other-owner" })),
|
|
203
|
+
];
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Picks the runner snapshot a run starts from, once the credential names its team and project: the first candidate in
|
|
207
|
+
* preference order (`classifySnapshotEntries`) for that team and project, or `undefined` when none matches.
|
|
208
|
+
*/
|
|
209
|
+
export function pickSnapshot(candidates, owner) {
|
|
210
|
+
return candidates.find(({ entry }) => entry.teamId === owner.teamId && entry.projectId === owner.projectId);
|
|
211
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { SandboxCredential } from "../sdk/extension/index.ts";
|
|
2
2
|
import type { Timer } from "../time/index.ts";
|
|
3
3
|
import type { RunnerNetworkPolicy, RunnerSandbox, RunnerSandboxFailure, RunnerSandboxGateway } from "./gateways.ts";
|
|
4
|
-
import type {
|
|
4
|
+
import type { CheckedVercelSandboxOptions } from "./vercel-sandbox-options.ts";
|
|
5
5
|
/**
|
|
6
6
|
* How long a policy write may take: 10 seconds. Writes take well under a second. A write with no answer by then is
|
|
7
7
|
* aborted, and may still take effect at any time.
|
|
@@ -27,12 +27,12 @@ export type RunnerReachPolicy = Exclude<RunnerNetworkPolicy, {
|
|
|
27
27
|
readonly kind: "deny-all";
|
|
28
28
|
}>;
|
|
29
29
|
/**
|
|
30
|
-
* The network policy of a sandbox storm creates for `
|
|
31
|
-
* credentials gives again: `allow-all` when the
|
|
32
|
-
* `custom` with exactly those domains. A credential's domain is reachable only while the credential is in
|
|
33
|
-
* (`withCredentials`).
|
|
30
|
+
* The network policy of a sandbox storm creates for `options`, with no credential, which every write without
|
|
31
|
+
* credentials gives again: `allow-all` when the runner options list no allowed domains (`allowedDomains`), and
|
|
32
|
+
* otherwise `custom` with exactly those domains. A credential's domain is reachable only while the credential is in
|
|
33
|
+
* place (`withCredentials`).
|
|
34
34
|
*/
|
|
35
|
-
export declare function runnerNetworkPolicy(
|
|
35
|
+
export declare function runnerNetworkPolicy(options: Pick<CheckedVercelSandboxOptions, "allowedDomains">): RunnerReachPolicy;
|
|
36
36
|
/**
|
|
37
37
|
* `base` with `credentials` in place of its own, each with its own `requests`. Under `custom`, each credential's
|
|
38
38
|
* domain is reachable while the policy holds it, beside the allowed domains.
|
|
@@ -8,15 +8,15 @@ import { callWithin } from "./time-limit.js";
|
|
|
8
8
|
*/
|
|
9
9
|
export const NETWORK_POLICY_WRITE_LIMIT_MS = 10_000;
|
|
10
10
|
/**
|
|
11
|
-
* The network policy of a sandbox storm creates for `
|
|
12
|
-
* credentials gives again: `allow-all` when the
|
|
13
|
-
* `custom` with exactly those domains. A credential's domain is reachable only while the credential is in
|
|
14
|
-
* (`withCredentials`).
|
|
11
|
+
* The network policy of a sandbox storm creates for `options`, with no credential, which every write without
|
|
12
|
+
* credentials gives again: `allow-all` when the runner options list no allowed domains (`allowedDomains`), and
|
|
13
|
+
* otherwise `custom` with exactly those domains. A credential's domain is reachable only while the credential is in
|
|
14
|
+
* place (`withCredentials`).
|
|
15
15
|
*/
|
|
16
|
-
export function runnerNetworkPolicy(
|
|
17
|
-
if (
|
|
16
|
+
export function runnerNetworkPolicy(options) {
|
|
17
|
+
if (options.allowedDomains === undefined)
|
|
18
18
|
return { kind: "allow-all", credentials: [] };
|
|
19
|
-
return { kind: "custom", allowedDomains: [...
|
|
19
|
+
return { kind: "custom", allowedDomains: [...options.allowedDomains], credentials: [] };
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
22
|
* `base` with `credentials` in place of its own, each with its own `requests`. Under `custom`, each credential's
|
|
@@ -22,7 +22,7 @@ export interface SandboxPolicyWriter {
|
|
|
22
22
|
/**
|
|
23
23
|
* A policy writer over `context.runnerSandboxes`, waiting with `context.timer`. `basePolicy` is the policy the run's
|
|
24
24
|
* sandboxes are created with, which holds no injection: it writes it whenever it removes an injection, so a removal
|
|
25
|
-
* keeps the
|
|
25
|
+
* keeps the runner's allowed domains. `onTimedOut` hears of each sandbox once, as its first write times out.
|
|
26
26
|
*/
|
|
27
27
|
export declare function sandboxPolicyWriter(context: {
|
|
28
28
|
readonly runnerSandboxes: RunnerSandboxGateway;
|
|
@@ -7,7 +7,7 @@ import { ABORTED, untilAborted } from "./time-limit.js";
|
|
|
7
7
|
/**
|
|
8
8
|
* A policy writer over `context.runnerSandboxes`, waiting with `context.timer`. `basePolicy` is the policy the run's
|
|
9
9
|
* sandboxes are created with, which holds no injection: it writes it whenever it removes an injection, so a removal
|
|
10
|
-
* keeps the
|
|
10
|
+
* keeps the runner's allowed domains. `onTimedOut` hears of each sandbox once, as its first write times out.
|
|
11
11
|
*/
|
|
12
12
|
export function sandboxPolicyWriter(context, basePolicy, onTimedOut) {
|
|
13
13
|
/** Each sandbox's policy writes, for the sandboxes it wrote one to. */
|
package/dist/runner/prepare.d.ts
CHANGED
|
@@ -1,43 +1,44 @@
|
|
|
1
1
|
import { type RefusedBaseRef } from "./base.ts";
|
|
2
2
|
import type { CheckoutFailure, CheckoutUpload } from "./gateways.ts";
|
|
3
|
-
import { type
|
|
4
|
-
import { type
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
import { type CheckedVercelSandboxOptions, type VcpuRun } from "./vercel-sandbox-options.ts";
|
|
4
|
+
import { type LocalSnapshotIndexContext, type RejectedSnapshot, type RunnerSnapshotCandidate, type SnapshotIndexNote } from "./local-snapshot-index.ts";
|
|
5
|
+
import { type DeclaredBaseFile } from "./snapshot-key.ts";
|
|
6
|
+
/** What `prepareRunner` needs: the checkout, the local snapshot index, and the clock. */
|
|
7
|
+
export type RunnerPrepareContext = LocalSnapshotIndexContext;
|
|
8
|
+
/** What `prepareRunner` checks a run with. */
|
|
9
|
+
export interface PrepareRunnerRequest {
|
|
9
10
|
/** The directory the run started in, inside the checkout. */
|
|
10
11
|
readonly cwd: string;
|
|
11
|
-
readonly
|
|
12
|
-
/** The run
|
|
13
|
-
readonly
|
|
12
|
+
readonly options: CheckedVercelSandboxOptions;
|
|
13
|
+
/** The run's resolved resource options and sandbox count, for evaluating a declared `vcpus` rule. */
|
|
14
|
+
readonly vcpuRun: VcpuRun;
|
|
14
15
|
}
|
|
15
16
|
/** The runner, checked on this machine, ready for the runner sandbox. */
|
|
16
17
|
export interface PreparedRunner {
|
|
17
|
-
readonly
|
|
18
|
+
readonly options: CheckedVercelSandboxOptions;
|
|
18
19
|
readonly repoRoot: string;
|
|
19
20
|
/** The run's base, HEAD's merge-base with a base ref, as a full SHA, and that ref. */
|
|
20
21
|
readonly base: string;
|
|
21
22
|
readonly baseRef: string;
|
|
22
|
-
/**
|
|
23
|
-
readonly
|
|
24
|
-
|
|
23
|
+
/** Declared base files read at the base, to stage in `/vercel/sandbox/<path>` before toolchain steps. */
|
|
24
|
+
readonly baseFiles: readonly DeclaredBaseFile[];
|
|
25
|
+
/** The runner's snapshot key at the base. */
|
|
25
26
|
readonly snapshotKey: string;
|
|
26
27
|
/** The runner sandbox's vCPUs for the run. */
|
|
27
28
|
readonly vcpus: number;
|
|
28
29
|
/** What the run uploads on top of the base. */
|
|
29
30
|
readonly upload: CheckoutUpload;
|
|
30
31
|
/**
|
|
31
|
-
* The cached runner snapshots the run may start from, each at the run's base
|
|
32
|
-
* and project filter (`pickSnapshot`).
|
|
32
|
+
* The cached runner snapshots the run may start from, each at the run's base or an ancestor of it with the run's
|
|
33
|
+
* snapshot key, sorted closest first, before the team and project filter (`pickSnapshot`).
|
|
33
34
|
*/
|
|
34
35
|
readonly candidates: readonly RunnerSnapshotCandidate[];
|
|
35
|
-
/** The
|
|
36
|
+
/** The runner's other cached snapshots, each with why the run doesn't start from it, before that filter. */
|
|
36
37
|
readonly rejected: readonly RejectedSnapshot[];
|
|
37
38
|
/** How many commits HEAD has that the run's base lacks. */
|
|
38
39
|
readonly commitsAfterBase: number;
|
|
39
40
|
/** What removing expired entries noticed (`removeExpiredEntries`), for the run to report. */
|
|
40
|
-
readonly notes: readonly
|
|
41
|
+
readonly notes: readonly SnapshotIndexNote[];
|
|
41
42
|
}
|
|
42
43
|
/**
|
|
43
44
|
* How the local checks ended.
|
|
@@ -45,8 +46,8 @@ export interface PreparedRunner {
|
|
|
45
46
|
* - `ok`: the checks passed, so the runner can ready the runner sandbox.
|
|
46
47
|
* - `no-base-ref`: no ref in `baseRefs` exists locally and shares history with HEAD; `refs` says why for each.
|
|
47
48
|
* - `submodules`: the checkout has Git submodules, at `paths`.
|
|
48
|
-
* - `invalid-
|
|
49
|
-
*
|
|
49
|
+
* - `invalid-runner`: a declared base file couldn't be read at the run's base or a `vcpus` rule's resource option
|
|
50
|
+
* wasn't a non-negative number for the run; `path` is the key inside the runner options.
|
|
50
51
|
* - `checkout-failed`: git or tar failed, such as outside a Git checkout.
|
|
51
52
|
*/
|
|
52
53
|
export type PrepareRunnerOutcome = {
|
|
@@ -59,7 +60,7 @@ export type PrepareRunnerOutcome = {
|
|
|
59
60
|
readonly kind: "submodules";
|
|
60
61
|
readonly paths: readonly string[];
|
|
61
62
|
} | {
|
|
62
|
-
readonly kind: "invalid-
|
|
63
|
+
readonly kind: "invalid-runner";
|
|
63
64
|
readonly path: readonly string[];
|
|
64
65
|
readonly problem: string;
|
|
65
66
|
} | {
|
|
@@ -67,10 +68,10 @@ export type PrepareRunnerOutcome = {
|
|
|
67
68
|
readonly failure: CheckoutFailure;
|
|
68
69
|
};
|
|
69
70
|
/**
|
|
70
|
-
* Runs the local checks in order: the repository's root, the base, the submodule refusal, the snapshot
|
|
71
|
+
* Runs the local checks in order: the repository's root, the base, the submodule refusal, the snapshot inputs at
|
|
71
72
|
* the base and their key, the runner's vCPUs, the upload, HEAD's count of commits after the base, and the cache read,
|
|
72
73
|
* which removes expired entries' files (`removeExpiredEntries`) and classifies the rest (`classifySnapshotEntries`)
|
|
73
|
-
* against the merge-base and its snapshot key. So every git call and
|
|
74
|
-
* is minted. It never mints, acquires or creates.
|
|
74
|
+
* against the merge-base and its snapshot key. So every git call and declared base-file read happens here, before
|
|
75
|
+
* anything is minted. It never mints, acquires, or creates.
|
|
75
76
|
*/
|
|
76
|
-
export declare function prepareRunner
|
|
77
|
+
export declare function prepareRunner(context: RunnerPrepareContext, request: PrepareRunnerRequest): Promise<PrepareRunnerOutcome>;
|