@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
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { CheckoutFailure, NamedSandboxStatus, SandboxAccess } from "./gateways.ts";
|
|
2
|
+
import { type SharedSnapshotStatus } from "./shared-snapshot-entry.ts";
|
|
3
|
+
import type { SharedSnapshotLookupContext } from "./shared-snapshot-lookup.ts";
|
|
4
|
+
import type { InspectedSnapshot } from "./snapshot-inspect.ts";
|
|
5
|
+
import type { CheckedVercelSandboxOptions } from "./vercel-sandbox-options.ts";
|
|
6
|
+
/** What `listSharedSnapshots` queries in the shared snapshot index. */
|
|
7
|
+
export interface SharedSnapshotListRequest {
|
|
8
|
+
readonly access: SandboxAccess;
|
|
9
|
+
readonly runner: Pick<CheckedVercelSandboxOptions, "name" | "region" | "image">;
|
|
10
|
+
readonly snapshotKey: string;
|
|
11
|
+
}
|
|
12
|
+
/** One entry returned by `listSharedSnapshots`, verified against the Sandbox API when stopped with a snapshot ID. */
|
|
13
|
+
export interface SharedSnapshotIndexEntry {
|
|
14
|
+
readonly sandboxName: string;
|
|
15
|
+
readonly base: string;
|
|
16
|
+
readonly sandboxStatus: NamedSandboxStatus;
|
|
17
|
+
/** When the named sandbox was created, which ranks entries as `lookupSharedSnapshot` does. */
|
|
18
|
+
readonly sandboxCreatedAt: string;
|
|
19
|
+
readonly status: SharedSnapshotStatus;
|
|
20
|
+
readonly snapshotId: string | undefined;
|
|
21
|
+
readonly snapshotStatus: string | undefined;
|
|
22
|
+
readonly createdAt: string;
|
|
23
|
+
readonly expiresAt: string | undefined;
|
|
24
|
+
readonly expired: boolean;
|
|
25
|
+
}
|
|
26
|
+
/** How `listSharedSnapshots` ended. */
|
|
27
|
+
export type SharedSnapshotListResult = {
|
|
28
|
+
readonly kind: "ok";
|
|
29
|
+
readonly bucket: string;
|
|
30
|
+
readonly entries: readonly SharedSnapshotIndexEntry[];
|
|
31
|
+
} | {
|
|
32
|
+
readonly kind: "failed";
|
|
33
|
+
readonly message: string;
|
|
34
|
+
} | {
|
|
35
|
+
readonly kind: "aborted";
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Lists every valid `storm-snap-<bucket>-<base>` entry in `request`'s bucket and verifies stopped entries that hold a
|
|
39
|
+
* `currentSnapshotId` via `getSnapshot` with bounded concurrency.
|
|
40
|
+
*/
|
|
41
|
+
export declare function listSharedSnapshots(context: Pick<SharedSnapshotLookupContext, "runnerSandboxes" | "clock">, request: SharedSnapshotListRequest, signal?: AbortSignal): Promise<SharedSnapshotListResult>;
|
|
42
|
+
/** One entry of the shared snapshot index, with what the pick across both indexes says of it. */
|
|
43
|
+
export interface SharedSnapshotSelection {
|
|
44
|
+
readonly entry: SharedSnapshotIndexEntry;
|
|
45
|
+
/** Whether a run here, for the listed team and project, starts from it. */
|
|
46
|
+
readonly picked: boolean;
|
|
47
|
+
/** How many commits HEAD has that its base lacks, when it is ready and at or behind the merge-base; else null. */
|
|
48
|
+
readonly builtBehind: number | null;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* How `pickSnapshotAcrossIndexes` ended: the local snapshot index's snapshots, with the team and project's pick
|
|
52
|
+
* un-marked when a shared entry beats it, and each shared entry with whether a run here starts from it.
|
|
53
|
+
*/
|
|
54
|
+
export type SnapshotAcrossIndexesResult = {
|
|
55
|
+
readonly kind: "ok";
|
|
56
|
+
readonly local: readonly InspectedSnapshot[];
|
|
57
|
+
readonly shared: readonly SharedSnapshotSelection[];
|
|
58
|
+
} | {
|
|
59
|
+
readonly kind: "checkout-failed";
|
|
60
|
+
readonly failure: CheckoutFailure;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Decides which snapshot a run at `request.mergeBase` for `request.owner` starts from, across the local snapshot
|
|
64
|
+
* index's inspected snapshots (`request.local`) and the shared snapshot index's entries (`request.entries`), with the
|
|
65
|
+
* rule `chooseSnapshot` follows: the closest `ready` shared entry at the merge-base or an ancestor of it (ranked by
|
|
66
|
+
* `compareSnapshotCandidates` on the sandbox's `createdAt`, as `lookupSharedSnapshot` ranks before it reads a
|
|
67
|
+
* snapshot), which wins only when it beats the local pick (`sharedBeatsLocal`). Every other team and project's local
|
|
68
|
+
* pick stands. Git is asked once per ancestor base, for its distance behind the merge-base.
|
|
69
|
+
*/
|
|
70
|
+
export declare function pickSnapshotAcrossIndexes(context: Pick<SharedSnapshotLookupContext, "checkout">, request: {
|
|
71
|
+
readonly repoRoot: string;
|
|
72
|
+
readonly mergeBase: string;
|
|
73
|
+
/** How many commits HEAD has that the merge-base lacks. */
|
|
74
|
+
readonly commitsAfterBase: number;
|
|
75
|
+
readonly owner: {
|
|
76
|
+
readonly teamId: string;
|
|
77
|
+
readonly projectId: string;
|
|
78
|
+
};
|
|
79
|
+
readonly local: readonly InspectedSnapshot[];
|
|
80
|
+
readonly entries: readonly SharedSnapshotIndexEntry[];
|
|
81
|
+
}): Promise<SnapshotAcrossIndexesResult>;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// Listing and selecting entries from the shared snapshot index for `storm snapshots list --shared`.
|
|
2
|
+
import { compareSnapshotCandidates, sharedBeatsLocal } from "./local-snapshot-index.js";
|
|
3
|
+
import { classifyUnverifiedSharedSandbox, classifyVerifiedSharedSnapshot, INDEX_CONCURRENCY, parseSharedSnapshotSandboxName, runLimited, sharedSnapshotBucket, sharedSnapshotSandboxPrefix, } from "./shared-snapshot-entry.js";
|
|
4
|
+
/**
|
|
5
|
+
* Lists every valid `storm-snap-<bucket>-<base>` entry in `request`'s bucket and verifies stopped entries that hold a
|
|
6
|
+
* `currentSnapshotId` via `getSnapshot` with bounded concurrency.
|
|
7
|
+
*/
|
|
8
|
+
export async function listSharedSnapshots(context, request, signal) {
|
|
9
|
+
const { runnerSandboxes, clock } = context;
|
|
10
|
+
const { access, runner, snapshotKey } = request;
|
|
11
|
+
const bucket = sharedSnapshotBucket({
|
|
12
|
+
teamId: access.teamId,
|
|
13
|
+
projectId: access.projectId,
|
|
14
|
+
region: runner.region,
|
|
15
|
+
image: runner.image,
|
|
16
|
+
runnerName: runner.name,
|
|
17
|
+
snapshotKey,
|
|
18
|
+
});
|
|
19
|
+
const listed = await runnerSandboxes.listNamedSandboxes(access, { namePrefix: sharedSnapshotSandboxPrefix(bucket) }, signal);
|
|
20
|
+
if (!listed.ok) {
|
|
21
|
+
return listed.failure.kind === "aborted"
|
|
22
|
+
? { kind: "aborted" }
|
|
23
|
+
: { kind: "failed", message: listed.failure.message };
|
|
24
|
+
}
|
|
25
|
+
const now = clock.now();
|
|
26
|
+
const matched = [];
|
|
27
|
+
for (const row of listed.value) {
|
|
28
|
+
const parsed = parseSharedSnapshotSandboxName(row.name);
|
|
29
|
+
if (parsed === null || parsed.bucket !== bucket)
|
|
30
|
+
continue;
|
|
31
|
+
matched.push({ row, base: parsed.base });
|
|
32
|
+
}
|
|
33
|
+
let stop = false;
|
|
34
|
+
const outcomes = await runLimited(matched.length, INDEX_CONCURRENCY, () => !stop && signal?.aborted !== true, async (index) => {
|
|
35
|
+
const { row, base } = matched[index];
|
|
36
|
+
const unverified = classifyUnverifiedSharedSandbox(row);
|
|
37
|
+
if (unverified.kind === "settled") {
|
|
38
|
+
return {
|
|
39
|
+
kind: "entry",
|
|
40
|
+
entry: indexEntryOf(row, base, {
|
|
41
|
+
status: unverified.status,
|
|
42
|
+
snapshotId: unverified.status === "no-snapshot" ? undefined : row.currentSnapshotId,
|
|
43
|
+
snapshotStatus: undefined,
|
|
44
|
+
createdAt: row.createdAt,
|
|
45
|
+
expiresAt: row.tags["expires-at"],
|
|
46
|
+
expired: false,
|
|
47
|
+
}),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const verified = await runnerSandboxes.getSnapshot(access, { snapshotId: unverified.snapshotId }, signal);
|
|
51
|
+
if (!verified.ok) {
|
|
52
|
+
stop = true;
|
|
53
|
+
return verified.failure.kind === "aborted"
|
|
54
|
+
? { kind: "aborted" }
|
|
55
|
+
: { kind: "failed", message: verified.failure.message };
|
|
56
|
+
}
|
|
57
|
+
const classified = classifyVerifiedSharedSnapshot({ ...row, currentSnapshotId: unverified.snapshotId }, verified.value, now);
|
|
58
|
+
return {
|
|
59
|
+
kind: "entry",
|
|
60
|
+
entry: indexEntryOf(row, base, {
|
|
61
|
+
status: classified.status,
|
|
62
|
+
snapshotId: classified.snapshotId,
|
|
63
|
+
snapshotStatus: classified.snapshotStatus,
|
|
64
|
+
createdAt: classified.createdAt,
|
|
65
|
+
expiresAt: classified.expiresAt,
|
|
66
|
+
expired: classified.status === "expired",
|
|
67
|
+
}),
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
if (signal?.aborted === true)
|
|
71
|
+
return { kind: "aborted" };
|
|
72
|
+
const entries = [];
|
|
73
|
+
for (const outcome of outcomes) {
|
|
74
|
+
if (outcome === undefined)
|
|
75
|
+
continue;
|
|
76
|
+
if (outcome.kind === "aborted")
|
|
77
|
+
return { kind: "aborted" };
|
|
78
|
+
if (outcome.kind === "failed")
|
|
79
|
+
return outcome;
|
|
80
|
+
entries.push(outcome.entry);
|
|
81
|
+
}
|
|
82
|
+
return { kind: "ok", bucket, entries };
|
|
83
|
+
}
|
|
84
|
+
function indexEntryOf(row, base, fields) {
|
|
85
|
+
return {
|
|
86
|
+
sandboxName: row.name,
|
|
87
|
+
base,
|
|
88
|
+
sandboxStatus: row.status,
|
|
89
|
+
sandboxCreatedAt: row.createdAt,
|
|
90
|
+
...fields,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Decides which snapshot a run at `request.mergeBase` for `request.owner` starts from, across the local snapshot
|
|
95
|
+
* index's inspected snapshots (`request.local`) and the shared snapshot index's entries (`request.entries`), with the
|
|
96
|
+
* rule `chooseSnapshot` follows: the closest `ready` shared entry at the merge-base or an ancestor of it (ranked by
|
|
97
|
+
* `compareSnapshotCandidates` on the sandbox's `createdAt`, as `lookupSharedSnapshot` ranks before it reads a
|
|
98
|
+
* snapshot), which wins only when it beats the local pick (`sharedBeatsLocal`). Every other team and project's local
|
|
99
|
+
* pick stands. Git is asked once per ancestor base, for its distance behind the merge-base.
|
|
100
|
+
*/
|
|
101
|
+
export async function pickSnapshotAcrossIndexes(context, request) {
|
|
102
|
+
const { checkout } = context;
|
|
103
|
+
const { repoRoot, mergeBase, commitsAfterBase, owner, local, entries } = request;
|
|
104
|
+
const owned = (snapshot) => snapshot.entry.teamId === owner.teamId && snapshot.entry.projectId === owner.projectId;
|
|
105
|
+
const localPick = local.find((snapshot) => snapshot.picked && owned(snapshot));
|
|
106
|
+
const behindMergeBaseByBase = new Map([[mergeBase, 0]]);
|
|
107
|
+
const qualifying = [];
|
|
108
|
+
for (const entry of entries) {
|
|
109
|
+
if (entry.status !== "ready")
|
|
110
|
+
continue;
|
|
111
|
+
let commitsBehindMergeBase = behindMergeBaseByBase.get(entry.base);
|
|
112
|
+
if (commitsBehindMergeBase === undefined) {
|
|
113
|
+
const ancestor = await checkout.contains({ repoRoot, ancestor: entry.base, descendant: mergeBase });
|
|
114
|
+
if (!ancestor.ok)
|
|
115
|
+
return { kind: "checkout-failed", failure: ancestor.failure };
|
|
116
|
+
commitsBehindMergeBase = null;
|
|
117
|
+
if (ancestor.value) {
|
|
118
|
+
const counted = await checkout.commitCount({ repoRoot, from: entry.base, to: mergeBase });
|
|
119
|
+
if (!counted.ok)
|
|
120
|
+
return { kind: "checkout-failed", failure: counted.failure };
|
|
121
|
+
commitsBehindMergeBase = counted.value;
|
|
122
|
+
}
|
|
123
|
+
behindMergeBaseByBase.set(entry.base, commitsBehindMergeBase);
|
|
124
|
+
}
|
|
125
|
+
if (commitsBehindMergeBase !== null)
|
|
126
|
+
qualifying.push({ entry, commitsBehindMergeBase });
|
|
127
|
+
}
|
|
128
|
+
const best = qualifying.toSorted((a, b) => compareSnapshotCandidates({
|
|
129
|
+
commitsBehindMergeBase: a.commitsBehindMergeBase,
|
|
130
|
+
createdAt: a.entry.sandboxCreatedAt,
|
|
131
|
+
tieBreaker: a.entry.sandboxName,
|
|
132
|
+
}, {
|
|
133
|
+
commitsBehindMergeBase: b.commitsBehindMergeBase,
|
|
134
|
+
createdAt: b.entry.sandboxCreatedAt,
|
|
135
|
+
tieBreaker: b.entry.sandboxName,
|
|
136
|
+
}))[0];
|
|
137
|
+
const sharedPick = best !== undefined && sharedBeatsLocal(best.commitsBehindMergeBase, localPick?.commitsBehindMergeBase ?? undefined)
|
|
138
|
+
? best.entry
|
|
139
|
+
: undefined;
|
|
140
|
+
const readyBehind = new Map(qualifying.map(({ entry, commitsBehindMergeBase }) => [entry, commitsBehindMergeBase]));
|
|
141
|
+
return {
|
|
142
|
+
kind: "ok",
|
|
143
|
+
local: sharedPick === undefined || localPick === undefined
|
|
144
|
+
? local
|
|
145
|
+
: local.map((snapshot) => (snapshot === localPick ? { ...snapshot, picked: false } : snapshot)),
|
|
146
|
+
shared: entries.map((entry) => {
|
|
147
|
+
const commitsBehindMergeBase = readyBehind.get(entry);
|
|
148
|
+
return {
|
|
149
|
+
entry,
|
|
150
|
+
picked: entry === sharedPick,
|
|
151
|
+
builtBehind: commitsBehindMergeBase === undefined ? null : commitsAfterBase + commitsBehindMergeBase,
|
|
152
|
+
};
|
|
153
|
+
}),
|
|
154
|
+
};
|
|
155
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Clock } from "../time/index.ts";
|
|
2
|
+
import type { CheckoutGateway, RunnerSandboxGateway, RunnerSnapshotEntry, SandboxAccess } from "./gateways.ts";
|
|
3
|
+
import type { CheckedVercelSandboxOptions } from "./vercel-sandbox-options.ts";
|
|
4
|
+
/** Gateways and seams used to look up, list, or prune shared snapshots. */
|
|
5
|
+
export interface SharedSnapshotLookupContext {
|
|
6
|
+
readonly runnerSandboxes: RunnerSandboxGateway;
|
|
7
|
+
readonly checkout: CheckoutGateway;
|
|
8
|
+
readonly clock: Clock;
|
|
9
|
+
}
|
|
10
|
+
/** What `lookupSharedSnapshot` searches for in the shared snapshot index. */
|
|
11
|
+
export interface SharedSnapshotLookupRequest {
|
|
12
|
+
readonly access: SandboxAccess;
|
|
13
|
+
readonly repoRoot: string;
|
|
14
|
+
readonly runner: Pick<CheckedVercelSandboxOptions, "name" | "region" | "image">;
|
|
15
|
+
readonly snapshotKey: string;
|
|
16
|
+
readonly mergeBase: string;
|
|
17
|
+
/**
|
|
18
|
+
* When set, the commit distance behind `mergeBase` of the local snapshot index's candidate: only shared snapshots that
|
|
19
|
+
* beat it (`sharedBeatsLocal`) qualify. When no ancestor can beat it, the bucket listing is skipped after the exact
|
|
20
|
+
* check misses.
|
|
21
|
+
*/
|
|
22
|
+
readonly maxCommitsBehindMergeBase?: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* What `lookupSharedSnapshot` found:
|
|
26
|
+
*
|
|
27
|
+
* - `hit`: a verified, unexpired snapshot with time left at the merge-base (`commitsBehindMergeBase === 0`) or its
|
|
28
|
+
* closest qualifying ancestor.
|
|
29
|
+
* - `miss`: no usable shared snapshot was found in the bucket.
|
|
30
|
+
* - `unavailable`: a Sandbox API call failed, so the caller can degrade gracefully.
|
|
31
|
+
* - `aborted`: the caller's signal aborted the lookup.
|
|
32
|
+
*/
|
|
33
|
+
export type SharedSnapshotLookupResult = {
|
|
34
|
+
readonly kind: "hit";
|
|
35
|
+
readonly entry: RunnerSnapshotEntry;
|
|
36
|
+
readonly commitsBehindMergeBase: number;
|
|
37
|
+
readonly sandboxName: string;
|
|
38
|
+
} | {
|
|
39
|
+
readonly kind: "miss";
|
|
40
|
+
} | {
|
|
41
|
+
readonly kind: "unavailable";
|
|
42
|
+
readonly message: string;
|
|
43
|
+
} | {
|
|
44
|
+
readonly kind: "aborted";
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Looks up a usable shared snapshot for `request`: first checks the exact named sandbox for `request.mergeBase`
|
|
48
|
+
* without listing, and falls back to listing the bucket and selecting the closest verified ancestor of
|
|
49
|
+
* `request.mergeBase` (tie-breaking by newest `createdAt`, then ascending `name`).
|
|
50
|
+
*/
|
|
51
|
+
export declare function lookupSharedSnapshot(context: SharedSnapshotLookupContext, request: SharedSnapshotLookupRequest, signal?: AbortSignal): Promise<SharedSnapshotLookupResult>;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// Live run lookup against the shared snapshot index: checks the exact merge-base named sandbox first without
|
|
2
|
+
// listing, then falls back to scanning the bucket for the closest verified ancestor of the merge-base.
|
|
3
|
+
import { compareSnapshotCandidates, sharedBeatsLocal } from "./local-snapshot-index.js";
|
|
4
|
+
import { classifyUnverifiedSharedSandbox, INDEX_CONCURRENCY, parseSharedSnapshotSandboxName, runLimited, sharedSnapshotBucket, sharedSnapshotSandboxName, sharedSnapshotSandboxPrefix, usableSharedEntry, } from "./shared-snapshot-entry.js";
|
|
5
|
+
/**
|
|
6
|
+
* Looks up a usable shared snapshot for `request`: first checks the exact named sandbox for `request.mergeBase`
|
|
7
|
+
* without listing, and falls back to listing the bucket and selecting the closest verified ancestor of
|
|
8
|
+
* `request.mergeBase` (tie-breaking by newest `createdAt`, then ascending `name`).
|
|
9
|
+
*/
|
|
10
|
+
export async function lookupSharedSnapshot(context, request, signal) {
|
|
11
|
+
const { runnerSandboxes, checkout, clock } = context;
|
|
12
|
+
const { access, repoRoot, runner, snapshotKey, mergeBase, maxCommitsBehindMergeBase } = request;
|
|
13
|
+
// Even an entry at the merge-base can't beat the caller's candidate.
|
|
14
|
+
if (!sharedBeatsLocal(0, maxCommitsBehindMergeBase))
|
|
15
|
+
return { kind: "miss" };
|
|
16
|
+
const bucket = sharedSnapshotBucket({
|
|
17
|
+
teamId: access.teamId,
|
|
18
|
+
projectId: access.projectId,
|
|
19
|
+
region: runner.region,
|
|
20
|
+
image: runner.image,
|
|
21
|
+
runnerName: runner.name,
|
|
22
|
+
snapshotKey,
|
|
23
|
+
});
|
|
24
|
+
// Step 1: fast exact check for `mergeBase` without calling `listNamedSandboxes`.
|
|
25
|
+
const exactName = sharedSnapshotSandboxName(bucket, mergeBase);
|
|
26
|
+
const exact = await runnerSandboxes.getNamedSandbox(access, { name: exactName }, signal);
|
|
27
|
+
if (!exact.ok) {
|
|
28
|
+
return unavailable(exact.failure);
|
|
29
|
+
}
|
|
30
|
+
if (exact.value.kind === "found") {
|
|
31
|
+
const { sandbox } = exact.value;
|
|
32
|
+
const unverified = classifyUnverifiedSharedSandbox(sandbox);
|
|
33
|
+
if (unverified.kind === "needs-snapshot") {
|
|
34
|
+
const verified = await runnerSandboxes.getSnapshot(access, { snapshotId: unverified.snapshotId }, signal);
|
|
35
|
+
if (!verified.ok) {
|
|
36
|
+
return unavailable(verified.failure);
|
|
37
|
+
}
|
|
38
|
+
if (verified.value.kind === "found") {
|
|
39
|
+
const entry = usableSharedEntry(access, runner, snapshotKey, mergeBase, sandbox, verified.value.snapshot, clock.now());
|
|
40
|
+
if (entry !== null) {
|
|
41
|
+
return { kind: "hit", entry, commitsBehindMergeBase: 0, sandboxName: sandbox.name };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// Only the exact match above can beat the caller's candidate when no ancestor, 1 commit behind or more, can.
|
|
47
|
+
if (!sharedBeatsLocal(1, maxCommitsBehindMergeBase))
|
|
48
|
+
return { kind: "miss" };
|
|
49
|
+
// Step 2: ancestor scan across the bucket.
|
|
50
|
+
const listed = await runnerSandboxes.listNamedSandboxes(access, { namePrefix: sharedSnapshotSandboxPrefix(bucket) }, signal);
|
|
51
|
+
if (!listed.ok) {
|
|
52
|
+
return unavailable(listed.failure);
|
|
53
|
+
}
|
|
54
|
+
const stoppedRows = [];
|
|
55
|
+
for (const row of listed.value) {
|
|
56
|
+
const unverified = classifyUnverifiedSharedSandbox(row);
|
|
57
|
+
if (unverified.kind !== "needs-snapshot")
|
|
58
|
+
continue;
|
|
59
|
+
const parsed = parseSharedSnapshotSandboxName(row.name);
|
|
60
|
+
if (parsed === null || parsed.bucket !== bucket || parsed.base === mergeBase)
|
|
61
|
+
continue;
|
|
62
|
+
stoppedRows.push({ row, base: parsed.base, snapshotId: unverified.snapshotId });
|
|
63
|
+
}
|
|
64
|
+
const checked = await runLimited(stoppedRows.length, INDEX_CONCURRENCY, () => signal?.aborted !== true, async (index) => {
|
|
65
|
+
const item = stoppedRows[index];
|
|
66
|
+
const ancestor = await checkout.contains({ repoRoot, ancestor: item.base, descendant: mergeBase });
|
|
67
|
+
if (!ancestor.ok || !ancestor.value)
|
|
68
|
+
return null;
|
|
69
|
+
if (signal?.aborted === true)
|
|
70
|
+
return null;
|
|
71
|
+
const counted = await checkout.commitCount({ repoRoot, from: item.base, to: mergeBase });
|
|
72
|
+
if (!counted.ok)
|
|
73
|
+
return null;
|
|
74
|
+
if (!sharedBeatsLocal(counted.value, maxCommitsBehindMergeBase))
|
|
75
|
+
return null;
|
|
76
|
+
return {
|
|
77
|
+
row: item.row,
|
|
78
|
+
base: item.base,
|
|
79
|
+
snapshotId: item.snapshotId,
|
|
80
|
+
commitsBehindMergeBase: counted.value,
|
|
81
|
+
};
|
|
82
|
+
});
|
|
83
|
+
if (signal?.aborted === true)
|
|
84
|
+
return { kind: "aborted" };
|
|
85
|
+
const candidates = checked.filter((candidate) => candidate != null);
|
|
86
|
+
candidates.sort((a, b) => compareSnapshotCandidates({
|
|
87
|
+
commitsBehindMergeBase: a.commitsBehindMergeBase,
|
|
88
|
+
createdAt: a.row.createdAt,
|
|
89
|
+
tieBreaker: a.row.name,
|
|
90
|
+
}, {
|
|
91
|
+
commitsBehindMergeBase: b.commitsBehindMergeBase,
|
|
92
|
+
createdAt: b.row.createdAt,
|
|
93
|
+
tieBreaker: b.row.name,
|
|
94
|
+
}));
|
|
95
|
+
// Verify candidates sequentially in closest-first order so we stop on the first usable snapshot.
|
|
96
|
+
for (const candidate of candidates) {
|
|
97
|
+
const verified = await runnerSandboxes.getSnapshot(access, { snapshotId: candidate.snapshotId }, signal);
|
|
98
|
+
if (!verified.ok) {
|
|
99
|
+
return unavailable(verified.failure);
|
|
100
|
+
}
|
|
101
|
+
if (verified.value.kind !== "found")
|
|
102
|
+
continue;
|
|
103
|
+
const entry = usableSharedEntry(access, runner, snapshotKey, candidate.base, candidate.row, verified.value.snapshot, clock.now());
|
|
104
|
+
if (entry !== null) {
|
|
105
|
+
return {
|
|
106
|
+
kind: "hit",
|
|
107
|
+
entry,
|
|
108
|
+
commitsBehindMergeBase: candidate.commitsBehindMergeBase,
|
|
109
|
+
sandboxName: candidate.row.name,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return { kind: "miss" };
|
|
114
|
+
}
|
|
115
|
+
/** How the lookup ends on a failed Sandbox call: aborted for the signal, and `unavailable` otherwise. */
|
|
116
|
+
function unavailable(failure) {
|
|
117
|
+
return failure.kind === "aborted" ? { kind: "aborted" } : { kind: "unavailable", message: failure.message };
|
|
118
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { SandboxAccess } from "./gateways.ts";
|
|
2
|
+
import type { SharedSnapshotLookupContext } from "./shared-snapshot-lookup.ts";
|
|
3
|
+
/** What `pruneSharedSnapshots` deletes or previews across the project's shared snapshot index. */
|
|
4
|
+
export interface SharedSnapshotPruneRequest {
|
|
5
|
+
readonly access: SandboxAccess;
|
|
6
|
+
readonly dryRun: boolean;
|
|
7
|
+
}
|
|
8
|
+
/** Why a shared snapshot index sandbox is eligible for pruning. */
|
|
9
|
+
export type SharedSnapshotPruneReason = "no-snapshot" | "expired" | "missing" | "failed";
|
|
10
|
+
/** One shared snapshot index sandbox deleted (or marked for deletion under `dryRun`). */
|
|
11
|
+
export type PrunedSharedSnapshot = {
|
|
12
|
+
readonly name: string;
|
|
13
|
+
readonly reason: "no-snapshot";
|
|
14
|
+
} | {
|
|
15
|
+
readonly name: string;
|
|
16
|
+
readonly reason: "failed";
|
|
17
|
+
} | {
|
|
18
|
+
readonly name: string;
|
|
19
|
+
readonly reason: "expired";
|
|
20
|
+
readonly snapshotId: string;
|
|
21
|
+
} | {
|
|
22
|
+
readonly name: string;
|
|
23
|
+
readonly reason: "missing";
|
|
24
|
+
readonly snapshotId: string;
|
|
25
|
+
};
|
|
26
|
+
/** One shared snapshot index sandbox whose verification or deletion failed during pruning. */
|
|
27
|
+
export interface SharedSnapshotPruneFailure {
|
|
28
|
+
readonly name: string;
|
|
29
|
+
readonly message: string;
|
|
30
|
+
}
|
|
31
|
+
/** What `pruneSharedSnapshots` scanned, deleted, skipped, and failed on. */
|
|
32
|
+
export interface SharedSnapshotPruneSummary {
|
|
33
|
+
readonly scanned: number;
|
|
34
|
+
readonly deleted: readonly PrunedSharedSnapshot[];
|
|
35
|
+
readonly skipped: number;
|
|
36
|
+
readonly failed: readonly SharedSnapshotPruneFailure[];
|
|
37
|
+
readonly dryRun: boolean;
|
|
38
|
+
}
|
|
39
|
+
/** How `pruneSharedSnapshots` ended. */
|
|
40
|
+
export type SharedSnapshotPruneResult = {
|
|
41
|
+
readonly kind: "ok";
|
|
42
|
+
readonly summary: SharedSnapshotPruneSummary;
|
|
43
|
+
} | {
|
|
44
|
+
readonly kind: "failed";
|
|
45
|
+
readonly message: string;
|
|
46
|
+
} | {
|
|
47
|
+
readonly kind: "aborted";
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Scans every valid `storm-snap-<bucket>-<base>` named sandbox in the project and deletes entries that ended failed or
|
|
51
|
+
* aborted (`failed`), stopped entries without a `currentSnapshotId` (`no-snapshot`), or stopped entries whose snapshot
|
|
52
|
+
* is verified missing or not `created` (`missing`) or expired (`expired`). Active builds (`pending`, `running`,
|
|
53
|
+
* `snapshotting`, or `stopping`) and stopped entries whose `expires-at` tag is still in the future are skipped without
|
|
54
|
+
* calling `getSnapshot` (including entries that expire within the hour and are not yet expired). Non-index sandboxes
|
|
55
|
+
* whose names do not match `storm-snap-<16-hex>-<40-hex>` are ignored. Verification and deletion run with bounded
|
|
56
|
+
* concurrency.
|
|
57
|
+
*/
|
|
58
|
+
export declare function pruneSharedSnapshots(context: Pick<SharedSnapshotLookupContext, "runnerSandboxes" | "clock">, request: SharedSnapshotPruneRequest, signal?: AbortSignal): Promise<SharedSnapshotPruneResult>;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// Pruning dead entries from the shared snapshot index (`storm snapshots prune`): scans valid
|
|
2
|
+
// `storm-snap-<bucket>-<base>` named sandboxes, skips active builds and stopped entries whose `expires-at` tag is
|
|
3
|
+
// still in the future, classifies the remaining entries through the canonical shared-snapshot classifier, and deletes
|
|
4
|
+
// `failed`, `no-snapshot`, `missing`, and `expired` entries.
|
|
5
|
+
import { classifyUnverifiedSharedSandbox, classifyVerifiedSharedSnapshot, INDEX_CONCURRENCY, parseSharedSnapshotSandboxName, runLimited, SHARED_SNAPSHOT_SANDBOX_PREFIX, } from "./shared-snapshot-entry.js";
|
|
6
|
+
/**
|
|
7
|
+
* Scans every valid `storm-snap-<bucket>-<base>` named sandbox in the project and deletes entries that ended failed or
|
|
8
|
+
* aborted (`failed`), stopped entries without a `currentSnapshotId` (`no-snapshot`), or stopped entries whose snapshot
|
|
9
|
+
* is verified missing or not `created` (`missing`) or expired (`expired`). Active builds (`pending`, `running`,
|
|
10
|
+
* `snapshotting`, or `stopping`) and stopped entries whose `expires-at` tag is still in the future are skipped without
|
|
11
|
+
* calling `getSnapshot` (including entries that expire within the hour and are not yet expired). Non-index sandboxes
|
|
12
|
+
* whose names do not match `storm-snap-<16-hex>-<40-hex>` are ignored. Verification and deletion run with bounded
|
|
13
|
+
* concurrency.
|
|
14
|
+
*/
|
|
15
|
+
export async function pruneSharedSnapshots(context, request, signal) {
|
|
16
|
+
const { runnerSandboxes, clock } = context;
|
|
17
|
+
const { access, dryRun } = request;
|
|
18
|
+
const listed = await runnerSandboxes.listNamedSandboxes(access, { namePrefix: SHARED_SNAPSHOT_SANDBOX_PREFIX }, signal);
|
|
19
|
+
if (!listed.ok) {
|
|
20
|
+
return listed.failure.kind === "aborted"
|
|
21
|
+
? { kind: "aborted" }
|
|
22
|
+
: { kind: "failed", message: listed.failure.message };
|
|
23
|
+
}
|
|
24
|
+
const validRows = listed.value.filter((row) => parseSharedSnapshotSandboxName(row.name) !== null);
|
|
25
|
+
const now = clock.now();
|
|
26
|
+
const nowMs = now.getTime();
|
|
27
|
+
let aborted = false;
|
|
28
|
+
const checked = await runLimited(validRows.length, INDEX_CONCURRENCY, () => !aborted && !isAborted(signal), async (index) => {
|
|
29
|
+
const row = validRows[index];
|
|
30
|
+
const unverified = classifyUnverifiedSharedSandbox(row);
|
|
31
|
+
if (unverified.kind === "settled") {
|
|
32
|
+
switch (unverified.status) {
|
|
33
|
+
case "building":
|
|
34
|
+
return { kind: "skip" };
|
|
35
|
+
case "failed":
|
|
36
|
+
return { kind: "mark", entry: { name: row.name, reason: "failed" } };
|
|
37
|
+
case "no-snapshot":
|
|
38
|
+
return { kind: "mark", entry: { name: row.name, reason: "no-snapshot" } };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// Fast-path: skip stopped entries whose `expires-at` tag is still in the future without calling `getSnapshot`.
|
|
42
|
+
const tagExpiresAt = row.tags["expires-at"];
|
|
43
|
+
if (tagExpiresAt !== undefined) {
|
|
44
|
+
const tagMs = Date.parse(tagExpiresAt);
|
|
45
|
+
if (!Number.isNaN(tagMs) && tagMs > nowMs)
|
|
46
|
+
return { kind: "skip" };
|
|
47
|
+
}
|
|
48
|
+
const verified = await runnerSandboxes.getSnapshot(access, { snapshotId: unverified.snapshotId }, signal);
|
|
49
|
+
if (!verified.ok) {
|
|
50
|
+
if (verified.failure.kind === "aborted") {
|
|
51
|
+
aborted = true;
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
return { kind: "failed", failure: { name: row.name, message: verified.failure.message } };
|
|
55
|
+
}
|
|
56
|
+
const classified = classifyVerifiedSharedSnapshot({ ...row, currentSnapshotId: unverified.snapshotId }, verified.value, now);
|
|
57
|
+
switch (classified.status) {
|
|
58
|
+
case "missing":
|
|
59
|
+
return { kind: "mark", entry: { name: row.name, reason: "missing", snapshotId: unverified.snapshotId } };
|
|
60
|
+
case "expired":
|
|
61
|
+
return { kind: "mark", entry: { name: row.name, reason: "expired", snapshotId: unverified.snapshotId } };
|
|
62
|
+
case "ready":
|
|
63
|
+
case "expires-soon":
|
|
64
|
+
case "unknown-expiry":
|
|
65
|
+
return { kind: "skip" };
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
if (aborted || isAborted(signal))
|
|
69
|
+
return { kind: "aborted" };
|
|
70
|
+
const marked = [];
|
|
71
|
+
const failed = [];
|
|
72
|
+
let skipped = 0;
|
|
73
|
+
for (const outcome of checked) {
|
|
74
|
+
if (outcome === undefined)
|
|
75
|
+
continue;
|
|
76
|
+
switch (outcome.kind) {
|
|
77
|
+
case "skip":
|
|
78
|
+
skipped += 1;
|
|
79
|
+
break;
|
|
80
|
+
case "mark":
|
|
81
|
+
marked.push(outcome.entry);
|
|
82
|
+
break;
|
|
83
|
+
case "failed":
|
|
84
|
+
failed.push(outcome.failure);
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const deleted = [];
|
|
89
|
+
if (dryRun) {
|
|
90
|
+
deleted.push(...marked);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
const deleteResults = await runLimited(marked.length, INDEX_CONCURRENCY, () => !aborted && !isAborted(signal), async (index) => {
|
|
94
|
+
const entry = marked[index];
|
|
95
|
+
const removed = await runnerSandboxes.deleteNamedSandbox(access, { name: entry.name }, signal);
|
|
96
|
+
if (removed.ok)
|
|
97
|
+
return { kind: "deleted", entry };
|
|
98
|
+
if (removed.failure.kind === "aborted") {
|
|
99
|
+
aborted = true;
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
return { kind: "failed", failure: { name: entry.name, message: removed.failure.message } };
|
|
103
|
+
});
|
|
104
|
+
if (aborted || isAborted(signal))
|
|
105
|
+
return { kind: "aborted" };
|
|
106
|
+
for (const outcome of deleteResults) {
|
|
107
|
+
if (outcome === undefined)
|
|
108
|
+
continue;
|
|
109
|
+
switch (outcome.kind) {
|
|
110
|
+
case "deleted":
|
|
111
|
+
deleted.push(outcome.entry);
|
|
112
|
+
break;
|
|
113
|
+
case "failed":
|
|
114
|
+
failed.push(outcome.failure);
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
kind: "ok",
|
|
121
|
+
summary: {
|
|
122
|
+
scanned: validRows.length,
|
|
123
|
+
deleted,
|
|
124
|
+
skipped,
|
|
125
|
+
failed,
|
|
126
|
+
dryRun,
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
/** Whether `signal` has aborted now. */
|
|
131
|
+
function isAborted(signal) {
|
|
132
|
+
return signal?.aborted === true;
|
|
133
|
+
}
|