@cnc-tools/storm 0.12.0 → 0.13.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 +1 -1
- package/dist/build-info.js +1 -1
- package/dist/chunks/{chunk-4XT5RC5T.js → chunk-2NZXL6OH.js} +6 -42
- package/dist/chunks/{chunk-ISGQJIQM.js → chunk-5UMJNVKT.js} +1 -1
- package/dist/chunks/{chunk-FSP3SJ35.js → chunk-6EQKA7LI.js} +16 -46
- package/dist/chunks/{chunk-Y3BUNNRG.js → chunk-AX4EQZUS.js} +4 -4
- package/dist/chunks/{chunk-RYRJNHL7.js → chunk-DOFB2ACU.js} +3 -9
- package/dist/chunks/{chunk-SXW6XN4R.js → chunk-EGNP3S6C.js} +3 -3
- package/dist/chunks/{chunk-FK4RLDEK.js → chunk-N7E6DAUE.js} +1 -1
- package/dist/chunks/{chunk-U7M3ZB3Z.js → chunk-Q4TKRILH.js} +33 -167
- package/dist/chunks/{chunk-TMQQYHUX.js → chunk-RTILVSYQ.js} +1 -1
- package/dist/chunks/{chunk-7D6LC5JY.js → chunk-X4WBJIOF.js} +7 -39
- package/dist/chunks/{chunk-TEEZL3GA.js → chunk-YGS5VRQT.js} +11 -68
- package/dist/chunks/{chunk-ODQHQJLE.js → chunk-ZDJLKF2G.js} +742 -1117
- package/dist/chunks/{live-app-AZ5N5HBD.js → live-app-QFHS54SX.js} +4 -4
- package/dist/commands/exec/command.d.ts +2 -90
- package/dist/commands/exec/command.js +10 -10
- package/dist/commands/exec/define-run-command.d.ts +2 -90
- package/dist/commands/exec/live-view.js +18 -22
- package/dist/commands/exec/outcomes.d.ts +2 -106
- package/dist/commands/exec/outcomes.js +4 -35
- package/dist/commands/exec/progress.d.ts +3 -19
- package/dist/commands/exec/progress.js +16 -60
- package/dist/commands/exec/run-command.d.ts +4 -23
- package/dist/commands/exec/run-command.js +5 -79
- package/dist/commands/exec/run-metadata.d.ts +0 -6
- package/dist/commands/exec/run-metadata.js +2 -8
- package/dist/commands/exec/snapshot-text.d.ts +7 -16
- package/dist/commands/exec/snapshot-text.js +9 -49
- package/dist/commands/exec/view.js +2 -12
- package/dist/commands/playwright/command.d.ts +2 -90
- package/dist/commands/playwright/command.js +11 -11
- package/dist/commands/runs/facts.d.ts +1 -37
- package/dist/commands/runs/facts.js +4 -36
- package/dist/commands/runs/list/command.d.ts +0 -72
- package/dist/commands/runs/list/command.js +5 -5
- package/dist/commands/runs/list/outcomes.d.ts +0 -36
- package/dist/commands/runs/logs/command.js +5 -5
- package/dist/commands/runs/show/command.d.ts +0 -72
- package/dist/commands/runs/show/command.js +13 -40
- package/dist/commands/runs/show/metadata.js +1 -1
- package/dist/commands/runs/show/outcomes.d.ts +0 -36
- package/dist/commands/runs/show/outcomes.js +8 -42
- package/dist/commands/snapshots/build/command.d.ts +14 -411
- package/dist/commands/snapshots/build/command.js +56 -231
- package/dist/commands/snapshots/build/metadata.js +10 -7
- package/dist/commands/snapshots/build/outcomes.d.ts +11 -241
- package/dist/commands/snapshots/build/outcomes.js +29 -196
- package/dist/commands/snapshots/list/command.d.ts +2 -36
- package/dist/commands/snapshots/list/command.js +17 -53
- package/dist/commands/snapshots/list/metadata.js +1 -1
- package/dist/commands/snapshots/list/outcomes.d.ts +2 -37
- package/dist/commands/snapshots/list/outcomes.js +13 -53
- package/dist/commands/vitest/command.d.ts +2 -90
- package/dist/commands/vitest/command.js +11 -11
- package/dist/core/events.d.ts +5 -6
- package/dist/core/run-state.d.ts +7 -29
- package/dist/core/run-state.js +3 -26
- package/dist/core/run.d.ts +6 -14
- package/dist/core/run.js +17 -28
- package/dist/extensions/testserver/commands/pool/create/command.js +1 -1
- package/dist/run-directory/index.d.ts +1 -1
- package/dist/run-directory/index.js +0 -1
- package/dist/run-directory/recording.js +2 -2
- package/dist/run-directory/run-record.d.ts +14 -132
- package/dist/run-directory/run-record.js +8 -68
- package/dist/runner/build-snapshots.d.ts +50 -114
- package/dist/runner/build-snapshots.js +70 -159
- package/dist/runner/events.d.ts +4 -88
- package/dist/runner/gateways.d.ts +5 -23
- package/dist/runner/index.d.ts +5 -6
- package/dist/runner/index.js +1 -1
- package/dist/runner/live/snapshot-records.js +7 -18
- package/dist/runner/prepare.d.ts +11 -22
- package/dist/runner/prepare.js +6 -17
- package/dist/runner/ready.d.ts +16 -45
- package/dist/runner/ready.js +34 -59
- package/dist/runner/recipe.d.ts +0 -44
- package/dist/runner/recipe.js +0 -41
- package/dist/runner/scope.d.ts +8 -25
- package/dist/runner/scope.js +4 -8
- package/dist/runner/session.d.ts +18 -65
- package/dist/runner/session.js +15 -83
- package/dist/runner/snapshot-build.d.ts +2 -2
- package/dist/runner/snapshot-cache.d.ts +22 -74
- package/dist/runner/snapshot-cache.js +15 -107
- package/dist/runner/snapshot-inspect.d.ts +9 -13
- package/dist/runner/snapshot-inspect.js +48 -57
- package/dist/runner/snapshot-key.d.ts +9 -14
- package/dist/runner/snapshot-key.js +15 -22
- package/package.json +1 -1
- package/skills/read-run-output.md +8 -9
- package/dist/runner/snapshot-save.d.ts +0 -70
- package/dist/runner/snapshot-save.js +0 -160
- package/dist/runner/snapshot-start.d.ts +0 -25
- package/dist/runner/snapshot-start.js +0 -16
package/dist/runner/session.d.ts
CHANGED
|
@@ -1,32 +1,12 @@
|
|
|
1
1
|
import type { MintTarget } from "../credential/index.ts";
|
|
2
2
|
import type { RunnerContext } from "./context.ts";
|
|
3
|
-
import type {
|
|
3
|
+
import type { RunnerProgress } from "./events.ts";
|
|
4
4
|
import type { SandboxAccess } from "./gateways.ts";
|
|
5
5
|
import type { PreparedRunner } from "./prepare.ts";
|
|
6
6
|
import { type ReadyRunnerOutcome } from "./ready.ts";
|
|
7
7
|
import { type SandboxedCommandOutcome, type SandboxTestEvents } from "./sandboxed-command.ts";
|
|
8
|
-
import { type
|
|
8
|
+
import { type RunnerScopeFacts } from "./scope.ts";
|
|
9
9
|
import type { RunnerSecrets } from "./secrets.ts";
|
|
10
|
-
/**
|
|
11
|
-
* Whether a run saves its runner sandbox as a dev snapshot at HEAD's commit once the command ends on its own. A
|
|
12
|
-
* detached HEAD saves as any HEAD does.
|
|
13
|
-
*
|
|
14
|
-
* - `new-head`: when the command exited 0 and the run didn't start from a dev snapshot built at HEAD's commit. What
|
|
15
|
-
* a run does when neither `--save-dev-snapshot` nor the recipe's `saveDevSnapshot` is given.
|
|
16
|
-
* - `always`: whatever the command's exit code and whatever runner snapshot the run started from
|
|
17
|
-
* (`--save-dev-snapshot`, or the recipe's `saveDevSnapshot: true`).
|
|
18
|
-
* - `never`: `--save-dev-snapshot=false`, or the recipe's `saveDevSnapshot: false`; with neither given, `CI` set, a
|
|
19
|
-
* `--keep-sandbox` above 0, or a recipe whose install or build step names a runner secret and that doesn't set
|
|
20
|
-
* `trustDevSnapshots`. `reason` says which, for the line the run prints.
|
|
21
|
-
*/
|
|
22
|
-
export type RunnerSaveMode = {
|
|
23
|
-
readonly kind: "new-head";
|
|
24
|
-
} | {
|
|
25
|
-
readonly kind: "always";
|
|
26
|
-
} | {
|
|
27
|
-
readonly kind: "never";
|
|
28
|
-
readonly reason: NeverSaveReason;
|
|
29
|
-
};
|
|
30
10
|
/** What a run's runner session runs: the runner checked on this machine, where its sandboxes run, and what it keeps. */
|
|
31
11
|
export interface RunnerSessionRequest {
|
|
32
12
|
/** The runner checked on this machine (`prepareRunner`). */
|
|
@@ -40,42 +20,22 @@ export interface RunnerSessionRequest {
|
|
|
40
20
|
* ones it names, the command gets none, and storm writes none to the run directory, the snapshot cache or `run.json`.
|
|
41
21
|
*/
|
|
42
22
|
readonly secrets: RunnerSecrets;
|
|
43
|
-
/**
|
|
44
|
-
readonly save: RunnerSaveMode;
|
|
45
|
-
/**
|
|
46
|
-
* How long the runner sandbox keeps running once the run ends, in milliseconds, when no save starts; 0 stops and
|
|
47
|
-
* deletes it. A run whose save starts keeps no runner sandbox, however the save ends.
|
|
48
|
-
*/
|
|
23
|
+
/** How long the runner sandbox keeps running once the run ends, in milliseconds; 0 stops and deletes it. */
|
|
49
24
|
readonly keepMs: number;
|
|
50
25
|
}
|
|
51
26
|
/**
|
|
52
27
|
* What the run hands its runner session for its cleanup. Each is the run's own, and each acts once, however often the
|
|
53
|
-
* session calls it: `startCleanup` reports cleanup's start,
|
|
54
|
-
*
|
|
28
|
+
* session calls it: `startCleanup` reports cleanup's start, and `release` releases the run's resources, reporting
|
|
29
|
+
* cleanup's start first.
|
|
55
30
|
*/
|
|
56
31
|
export interface RunnerSessionCleanup {
|
|
57
|
-
readonly startCleanup: (
|
|
58
|
-
readonly release: (
|
|
32
|
+
readonly startCleanup: () => Promise<void>;
|
|
33
|
+
readonly release: () => Promise<void>;
|
|
59
34
|
}
|
|
60
35
|
/** What closing a session's sandbox scope left, and the team and project its sandboxes are in: the run's target. */
|
|
61
36
|
export interface RunnerCleanupFacts extends RunnerScopeFacts {
|
|
62
37
|
readonly target: MintTarget;
|
|
63
38
|
}
|
|
64
|
-
/** How a session ended: how saving the runner sandbox as a dev snapshot did, and what closing left. */
|
|
65
|
-
export interface RunnerSessionEnd {
|
|
66
|
-
/**
|
|
67
|
-
* How the save ended; null when the run's save mode saves never, or its save never started: the command didn't end
|
|
68
|
-
* on its own, or the mode doesn't save always and the command didn't exit 0 or the run started from a dev snapshot
|
|
69
|
-
* built at HEAD's commit.
|
|
70
|
-
*/
|
|
71
|
-
readonly save: RunnerSave | null;
|
|
72
|
-
/**
|
|
73
|
-
* Why no save started, in a run whose command ended on its own and that no signal stopped; null when a save
|
|
74
|
-
* started, and when the command never ran or didn't end on its own.
|
|
75
|
-
*/
|
|
76
|
-
readonly noSave: RunnerNoSaveReason | null;
|
|
77
|
-
readonly cleanup: RunnerCleanupFacts;
|
|
78
|
-
}
|
|
79
39
|
/**
|
|
80
40
|
* One run's runner session, open from before the run mints. Its stages run in this order: `ready`, then `runCommand`
|
|
81
41
|
* in the runner sandbox `ready` readied, then `finish`; `close` ends it however the run went. A signal stops the
|
|
@@ -83,9 +43,9 @@ export interface RunnerSessionEnd {
|
|
|
83
43
|
*/
|
|
84
44
|
export interface RunnerSession {
|
|
85
45
|
/**
|
|
86
|
-
* Readies the runner sandbox:
|
|
87
|
-
*
|
|
88
|
-
*
|
|
46
|
+
* Readies the runner sandbox (`readyRunner`): reuses the cached runner snapshot it picks or builds a base snapshot,
|
|
47
|
+
* starts the runner sandbox from it, uploads and applies the run's changes, and runs the install and build. `signal`
|
|
48
|
+
* stops it. Called once.
|
|
89
49
|
*/
|
|
90
50
|
ready(access: SandboxAccess, signal: AbortSignal): Promise<ReadyRunnerOutcome>;
|
|
91
51
|
/**
|
|
@@ -98,29 +58,22 @@ export interface RunnerSession {
|
|
|
98
58
|
readonly testEvents?: SandboxTestEvents;
|
|
99
59
|
}): Promise<SandboxedCommandOutcome>;
|
|
100
60
|
/**
|
|
101
|
-
* Ends the session once the run is done in the runner sandbox
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
* releasing them throws; a mode that doesn't save always saves nothing when the command didn't exit 0, so a person
|
|
105
|
-
* can connect to the runner sandbox a failed command ran in, or when the run started from a dev snapshot HEAD's
|
|
106
|
-
* commit saved. Then it reports cleanup's start, with the plan it acted on, closes the scope, and releases the
|
|
107
|
-
* resources, which a run without a save does only once the scope is closed. A run whose save never started keeps
|
|
108
|
-
* its runner sandbox for the keep time.
|
|
61
|
+
* Ends the session once the run is done in the runner sandbox: it reports cleanup's start, closes the scope, which
|
|
62
|
+
* keeps the runner sandbox for the keep time, and then releases the run's resources. It answers what closing the
|
|
63
|
+
* scope left.
|
|
109
64
|
*/
|
|
110
|
-
finish(): Promise<
|
|
65
|
+
finish(): Promise<RunnerCleanupFacts>;
|
|
111
66
|
/**
|
|
112
|
-
* Stops listening for the signal, closes the scope and releases the run's resources,
|
|
113
|
-
* whose save never started, even when closing throws. Closing is memoized: once `finish` closed the scope, it
|
|
67
|
+
* Stops listening for the signal, closes the scope and releases the run's resources, even when closing throws. Closing is memoized: once `finish` closed the scope, it
|
|
114
68
|
* answers that close's report, and once the resources are released, releasing them does nothing. For a run that
|
|
115
69
|
* throws.
|
|
116
70
|
*/
|
|
117
71
|
close(): Promise<RunnerCleanupFacts>;
|
|
118
72
|
}
|
|
119
73
|
/**
|
|
120
|
-
* Opens a run's runner session over `context`, reporting to `progress`: it opens the sandbox scope, which
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
* the session reports `stopping`, with whether the command runs and that keep time, before the scope starts to close.
|
|
74
|
+
* Opens a run's runner session over `context`, reporting to `progress`: it opens the sandbox scope, which keeps the
|
|
75
|
+
* runner sandbox for the request's keep time as it closes, and listens for `signal`. On its first abort, the session
|
|
76
|
+
* reports `stopping`, with whether the command runs and the keep time, before the scope starts to close.
|
|
124
77
|
*/
|
|
125
78
|
export declare function openRunnerSession(context: RunnerContext, request: RunnerSessionRequest, control: {
|
|
126
79
|
readonly signal: AbortSignal;
|
package/dist/runner/session.js
CHANGED
|
@@ -1,57 +1,25 @@
|
|
|
1
1
|
// A runner session: everything one run does in its runner sandbox, in order. It owns the run's sandbox scope from
|
|
2
|
-
// before the run mints to the run's end, readies the runner sandbox, runs the command in the sandbox it readied,
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
|
|
6
|
-
import { obtainSnapshot, readyRunner } from "./ready.js";
|
|
2
|
+
// before the run mints to the run's end, readies the runner sandbox, runs the command in the sandbox it readied, and
|
|
3
|
+
// closes the scope before it releases the run's resources. The run hands it what releasing its resources and reporting
|
|
4
|
+
// cleanup's start take. The scope and the stopping line take the keep time from the session's request.
|
|
5
|
+
import { readyRunner } from "./ready.js";
|
|
7
6
|
import { runCommandInSandbox } from "./sandboxed-command.js";
|
|
8
7
|
import { runnerSandboxScope } from "./scope.js";
|
|
9
|
-
import { isDevEntry } from "./snapshot-cache.js";
|
|
10
|
-
import { saveDevSnapshot } from "./snapshot-save.js";
|
|
11
|
-
import { chooseSnapshotStart } from "./snapshot-start.js";
|
|
12
|
-
/** Whether `runner` started from a dev snapshot a run at HEAD commit `head` saved. */
|
|
13
|
-
function savedAt(runner, head) {
|
|
14
|
-
const { startedFrom } = runner;
|
|
15
|
-
return isDevEntry(startedFrom) && startedFrom.head === head;
|
|
16
|
-
}
|
|
17
|
-
/** Decides, from how the command ended, the signal, the save mode, and HEAD's commit, whether `finish` saves. */
|
|
18
|
-
function saveDecision(ended, signal, mode, head) {
|
|
19
|
-
if (ended === undefined || signal.aborted)
|
|
20
|
-
return { kind: "none" };
|
|
21
|
-
if (mode.kind === "never")
|
|
22
|
-
return { kind: "skip", reason: mode.reason };
|
|
23
|
-
if (mode.kind === "always")
|
|
24
|
-
return { kind: "save", runner: ended.runner };
|
|
25
|
-
if (ended.exitCode !== 0)
|
|
26
|
-
return { kind: "skip", reason: "command-failed" };
|
|
27
|
-
if (savedAt(ended.runner, head))
|
|
28
|
-
return { kind: "skip", reason: "already-saved" };
|
|
29
|
-
return { kind: "save", runner: ended.runner };
|
|
30
|
-
}
|
|
31
8
|
/**
|
|
32
|
-
* Opens a run's runner session over `context`, reporting to `progress`: it opens the sandbox scope, which
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* the session reports `stopping`, with whether the command runs and that keep time, before the scope starts to close.
|
|
9
|
+
* Opens a run's runner session over `context`, reporting to `progress`: it opens the sandbox scope, which keeps the
|
|
10
|
+
* runner sandbox for the request's keep time as it closes, and listens for `signal`. On its first abort, the session
|
|
11
|
+
* reports `stopping`, with whether the command runs and the keep time, before the scope starts to close.
|
|
36
12
|
*/
|
|
37
13
|
export function openRunnerSession(context, request, control, progress) {
|
|
38
14
|
const { signal, cleanup } = control;
|
|
39
|
-
|
|
40
|
-
const unsaved = { kind: "keep", ms: request.keepMs };
|
|
41
|
-
// Set in the same turn as the decision that starts a save, so the stopping line and the scope, which both read
|
|
42
|
-
// `keepMs`, never disagree about the runner sandbox.
|
|
43
|
-
let saveStarted = false;
|
|
44
|
-
const keepMs = () => (saveStarted ? 0 : request.keepMs);
|
|
45
|
-
const scope = runnerSandboxScope(context, progress, { keepMs });
|
|
15
|
+
const scope = runnerSandboxScope(context, progress, { keepMs: request.keepMs });
|
|
46
16
|
const closeScope = async () => ({ ...(await scope.close()), target: request.target });
|
|
47
17
|
let readying = false;
|
|
48
18
|
let readied;
|
|
49
19
|
let commandRunning = false;
|
|
50
|
-
// The runner sandbox the command ended in on its own, the one a save saves, and the exit code it ended with.
|
|
51
|
-
let ended;
|
|
52
20
|
// Said before the close starts, so the stopping line comes before any line the close's waits print.
|
|
53
21
|
const stop = () => {
|
|
54
|
-
void progress.emit({ kind: "stopping", commandRunning, keepMs: keepMs
|
|
22
|
+
void progress.emit({ kind: "stopping", commandRunning, keepMs: request.keepMs }).catch(() => undefined);
|
|
55
23
|
void scope.close().catch(() => undefined);
|
|
56
24
|
};
|
|
57
25
|
if (signal.aborted)
|
|
@@ -64,12 +32,7 @@ export function openRunnerSession(context, request, control, progress) {
|
|
|
64
32
|
throw new Error("the runner session readies its runner sandbox once");
|
|
65
33
|
readying = true;
|
|
66
34
|
const { prepared, user, secrets } = request;
|
|
67
|
-
const
|
|
68
|
-
const start = chooseSnapshotStart(prepared, access);
|
|
69
|
-
const obtained = await obtainSnapshot(context, { prepared, access, user, secrets, start }, lane, progress);
|
|
70
|
-
if (obtained.kind !== "ok")
|
|
71
|
-
return obtained;
|
|
72
|
-
const outcome = await readyRunner(context, { prepared, access, user, secrets, start: obtained.value }, lane, progress);
|
|
35
|
+
const outcome = await readyRunner(context, { prepared, access, user, secrets }, { scope, signal: laneSignal }, progress);
|
|
73
36
|
if (outcome.kind === "ready")
|
|
74
37
|
readied = outcome.runner;
|
|
75
38
|
return outcome;
|
|
@@ -78,51 +41,20 @@ export function openRunnerSession(context, request, control, progress) {
|
|
|
78
41
|
if (readied === undefined)
|
|
79
42
|
throw new Error("the runner session's runner sandbox isn't ready");
|
|
80
43
|
commandRunning = true;
|
|
81
|
-
|
|
44
|
+
return await runCommandInSandbox(context, {
|
|
82
45
|
runner: readied,
|
|
83
46
|
argv: command.argv,
|
|
84
47
|
runPayload: command.runPayload,
|
|
85
48
|
...(command.testEvents === undefined ? {} : { testEvents: command.testEvents }),
|
|
86
49
|
}, { kill: signal }, progress);
|
|
87
|
-
if (ran.kind === "exited")
|
|
88
|
-
ended = { runner: readied, exitCode: ran.exitCode };
|
|
89
|
-
return ran;
|
|
90
50
|
},
|
|
91
51
|
async finish() {
|
|
92
52
|
commandRunning = false;
|
|
93
|
-
|
|
94
|
-
let save = null;
|
|
95
|
-
let noSave = null;
|
|
96
|
-
let action = unsaved;
|
|
97
|
-
const decision = saveDecision(ended, signal, request.save, prepared.head.commit);
|
|
98
|
-
switch (decision.kind) {
|
|
99
|
-
case "none":
|
|
100
|
-
break;
|
|
101
|
-
case "skip":
|
|
102
|
-
noSave = decision.reason;
|
|
103
|
-
await progress.emit({ kind: "dev-snapshot-skipped", reason: noSave });
|
|
104
|
-
break;
|
|
105
|
-
case "save": {
|
|
106
|
-
saveStarted = true;
|
|
107
|
-
const plan = { kind: "save", branch: prepared.head.branch };
|
|
108
|
-
action = plan;
|
|
109
|
-
const saving = saveDevSnapshot(context, { ready: decision.runner, branch: plan.branch, head: prepared.head.commit }, { scope, signal }, progress);
|
|
110
|
-
// The save settles before the scope closes, even when releasing the resources threw.
|
|
111
|
-
try {
|
|
112
|
-
await cleanup.release(plan);
|
|
113
|
-
}
|
|
114
|
-
finally {
|
|
115
|
-
save = (await saving).save;
|
|
116
|
-
}
|
|
117
|
-
break;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
await cleanup.startCleanup(action);
|
|
53
|
+
await cleanup.startCleanup();
|
|
121
54
|
const facts = await closeScope();
|
|
122
55
|
signal.removeEventListener("abort", stop);
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
return { save, noSave, cleanup: facts };
|
|
56
|
+
await cleanup.release();
|
|
57
|
+
return facts;
|
|
126
58
|
},
|
|
127
59
|
async close() {
|
|
128
60
|
signal.removeEventListener("abort", stop);
|
|
@@ -131,7 +63,7 @@ export function openRunnerSession(context, request, control, progress) {
|
|
|
131
63
|
return await closeScope();
|
|
132
64
|
}
|
|
133
65
|
finally {
|
|
134
|
-
await cleanup.release(
|
|
66
|
+
await cleanup.release();
|
|
135
67
|
}
|
|
136
68
|
},
|
|
137
69
|
};
|
|
@@ -18,11 +18,11 @@ export interface BuiltSnapshot {
|
|
|
18
18
|
readonly cacheFailure: RunnerSnapshotCacheFailure | null;
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
|
-
* What a base snapshot build reads of a prepared run, or of a `storm snapshots build
|
|
21
|
+
* What a base snapshot build reads of a prepared run, or of a `storm snapshots build` plan: the recipe, the
|
|
22
22
|
* checkout, the base, its snapshot steps and key, and how many commits HEAD has after the base.
|
|
23
23
|
*/
|
|
24
24
|
export interface BaseSnapshotPlan extends Pick<PreparedRunner, "recipe" | "repoRoot" | "base" | "toolchains" | "prebuild" | "snapshotKey"> {
|
|
25
|
-
/** How many commits HEAD has after the base; null for a `--base` commit that isn't
|
|
25
|
+
/** How many commits HEAD has after the base; null for a `--base` commit that isn't HEAD's merge-base. */
|
|
26
26
|
readonly commitsAfterBase: number | null;
|
|
27
27
|
}
|
|
28
28
|
/** What a snapshot build needs to know: what it builds, who it runs as, the runner secrets, and why it builds. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Clock } from "../time/index.ts";
|
|
2
|
-
import type { CheckoutGateway,
|
|
3
|
-
import type { CheckedRecipe
|
|
2
|
+
import type { CheckoutGateway, RunnerSnapshotCacheFailure, RunnerSnapshotCacheGateway, RunnerSnapshotEntry } from "./gateways.ts";
|
|
3
|
+
import type { CheckedRecipe } from "./recipe.ts";
|
|
4
4
|
/** The subpath of storm's state directory that holds the runner snapshot cache. */
|
|
5
5
|
export declare const RUNNER_SNAPSHOTS_SUBPATH: readonly string[];
|
|
6
6
|
/** How long a runner snapshot lives after it is built: 7 days. The Sandbox API needs 0 or at least a day. */
|
|
@@ -9,22 +9,10 @@ export declare const SNAPSHOT_EXPIRATION_MS: number;
|
|
|
9
9
|
export declare const SNAPSHOT_MIN_REMAINING_MS: number;
|
|
10
10
|
/**
|
|
11
11
|
* An entry's identity: the first 32 hex characters of sha256 over its team id, project id, region, runtime, recipe
|
|
12
|
-
* name
|
|
13
|
-
*
|
|
14
|
-
* snapshot's at its base, and a dev snapshot's replaces only the one its checkout saved at the same commit. The
|
|
15
|
-
* branch and, for a dev snapshot, the base are no part of it. A base snapshot's identity is the one it had before dev
|
|
16
|
-
* snapshots existed.
|
|
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 recipe, key and base.
|
|
17
14
|
*/
|
|
18
15
|
export declare function snapshotEntryIdentity(entry: RunnerSnapshotEntry): string;
|
|
19
|
-
/** A cache entry that records a dev snapshot: it has the commit that saved it and the checkout's root. */
|
|
20
|
-
export type DevSnapshotEntry = RunnerSnapshotEntry & {
|
|
21
|
-
readonly head: string;
|
|
22
|
-
readonly repoRoot: string;
|
|
23
|
-
};
|
|
24
|
-
/** Whether `entry` records a dev snapshot, saved from a runner sandbox, rather than a base snapshot. */
|
|
25
|
-
export declare function isDevEntry(entry: RunnerSnapshotEntry): entry is DevSnapshotEntry;
|
|
26
|
-
/** The commit `entry`'s snapshot was built at: a dev snapshot's is the commit that saved it, a base snapshot's its base. */
|
|
27
|
-
export declare function builtAtCommit(entry: RunnerSnapshotEntry): string;
|
|
28
16
|
/** The name of the file that records `entry`: its identity and `.json`. */
|
|
29
17
|
export declare function snapshotEntryFileName(entry: RunnerSnapshotEntry): string;
|
|
30
18
|
/** Whether `entry`'s snapshot has expired at `now`. */
|
|
@@ -32,17 +20,14 @@ export declare function isExpiredEntry(entry: RunnerSnapshotEntry, now: Date): b
|
|
|
32
20
|
/** Whether `entry`'s snapshot has more than `SNAPSHOT_MIN_REMAINING_MS` left at `now`. */
|
|
33
21
|
export declare function hasTimeLeft(entry: RunnerSnapshotEntry, now: Date): boolean;
|
|
34
22
|
/**
|
|
35
|
-
* A cache entry a run may start from, before the team and project are known: its base is the run's merge-base
|
|
36
|
-
* snapshot key is the run's,
|
|
37
|
-
* behind HEAD.
|
|
23
|
+
* A cache entry a run may start from, before the team and project are known: its base is the run's merge-base and its
|
|
24
|
+
* snapshot key is the run's, with how far that base is behind HEAD.
|
|
38
25
|
*/
|
|
39
26
|
export interface RunnerSnapshotCandidate {
|
|
40
27
|
readonly entry: RunnerSnapshotEntry;
|
|
41
|
-
/** The commit the snapshot was built at (`builtAtCommit`), a full SHA. */
|
|
42
|
-
readonly builtAt: string;
|
|
43
28
|
/**
|
|
44
|
-
* How many commits HEAD has that the
|
|
45
|
-
*
|
|
29
|
+
* How many commits HEAD has that the merge-base lacks: what the install and the build have left to do. 0 when HEAD
|
|
30
|
+
* is the merge-base.
|
|
46
31
|
*/
|
|
47
32
|
readonly builtBehind: number;
|
|
48
33
|
}
|
|
@@ -52,21 +37,15 @@ export interface RunnerSnapshotCandidate {
|
|
|
52
37
|
* - `expired`: it has expired. A run's path removes the file first (`removeExpiredEntries`), so only a list of
|
|
53
38
|
* entries that still holds it, as `storm snapshots list`'s does, gets this reason.
|
|
54
39
|
* - `expires-soon`: it has `SNAPSHOT_MIN_REMAINING_MS` or less left.
|
|
55
|
-
* - `other-
|
|
56
|
-
*
|
|
57
|
-
* - `not-trusted`: it is a dev snapshot, and the recipe doesn't trust dev snapshots (`DevSnapshotReuse`).
|
|
58
|
-
* - `other-base`: its base isn't the run's merge-base.
|
|
40
|
+
* - `other-base`: its base isn't the run's merge-base. A run starts only from a snapshot built at its merge-base,
|
|
41
|
+
* which a base ref holds, so no snapshot built from a branch's own commits carries over into a run.
|
|
59
42
|
* - `steps-changed`: its snapshot key isn't the run's, the one the recipe's snapshot steps give at the merge-base.
|
|
60
|
-
* - `not-in-history`: it is a dev snapshot, and the commit that saved it is neither HEAD nor in HEAD's history.
|
|
61
43
|
* - `other-owner`: it was built for another team or project than the run's credential names.
|
|
62
|
-
* - `not-picked`: it is a candidate that a run here doesn't start from, since the pick preferred another one: one
|
|
63
|
-
* built at a commit fewer commits behind HEAD, or at the same commit a dev snapshot. Only the inspection gives it
|
|
64
|
-
* (`inspectSnapshotCache`): a run that builds picked none, so it passed over none of its own.
|
|
65
44
|
*
|
|
66
|
-
* The classification gives all but the last
|
|
45
|
+
* The classification gives all but the last, in that order of checks (`classifySnapshotEntries`); `other-owner`
|
|
67
46
|
* needs the team and project (`snapshotRejections`).
|
|
68
47
|
*/
|
|
69
|
-
export type SnapshotRejectionReason = "expired" | "expires-soon" | "other-
|
|
48
|
+
export type SnapshotRejectionReason = "expired" | "expires-soon" | "other-base" | "steps-changed" | "other-owner";
|
|
70
49
|
/** A cached snapshot of the run's recipe that the run doesn't start from, and why. */
|
|
71
50
|
export interface RejectedSnapshot {
|
|
72
51
|
readonly entry: RunnerSnapshotEntry;
|
|
@@ -134,29 +113,21 @@ export interface SnapshotCacheContext {
|
|
|
134
113
|
export declare function removeExpiredEntries(context: Pick<SnapshotCacheContext, "runnerSnapshots" | "clock">): Promise<SnapshotCacheListing>;
|
|
135
114
|
/**
|
|
136
115
|
* Classifies `entries`, cache entries a caller listed, for a run of `recipe`: which ones it may start from, and why
|
|
137
|
-
* not from each other one of the recipe's. It changes no file. Of the entries for the recipe's
|
|
138
|
-
* name it keeps the ones with more than an hour left whose base is the run's merge-base
|
|
139
|
-
* key is the run's
|
|
140
|
-
*
|
|
141
|
-
* longer counts, and none unless `devSnapshots` is `reuse`. HEAD's branch is no part of it: another checkout may hold
|
|
142
|
-
* other code, so its dev snapshot never carries over, whatever its branch. Every other entry of the recipe is
|
|
143
|
-
* `rejected`, with the first reason that rules it out, an expired one as `expired`. Each entry gets exactly one
|
|
144
|
-
* verdict. Git is asked once per dev snapshot commit whether HEAD holds it and, for a candidate, how far behind HEAD it
|
|
145
|
-
* is; a git failure ends the classification with that failure.
|
|
116
|
+
* not from each other one of the recipe's. It changes no file and asks Git nothing. Of the entries for the recipe's
|
|
117
|
+
* region, runtime and name it keeps the ones with more than an hour left whose base is the run's merge-base and whose
|
|
118
|
+
* snapshot key is the run's. Every other entry of the recipe is `rejected`, with the first reason that rules it out,
|
|
119
|
+
* an expired one as `expired`. Each entry gets exactly one verdict, in the order given.
|
|
146
120
|
*/
|
|
147
|
-
export declare function classifySnapshotEntries(context: Pick<SnapshotCacheContext, "
|
|
121
|
+
export declare function classifySnapshotEntries(context: Pick<SnapshotCacheContext, "clock">, request: {
|
|
148
122
|
readonly entries: readonly RunnerSnapshotEntry[];
|
|
149
|
-
readonly repoRoot: string;
|
|
150
123
|
readonly recipe: Pick<CheckedRecipe, "name" | "region" | "runtime">;
|
|
151
124
|
/** The run's base, HEAD's merge-base with a base ref: a candidate's base is this one. */
|
|
152
125
|
readonly base: string;
|
|
153
126
|
/** The run's snapshot key, the recipe's snapshot steps at `base`: a candidate's key is this one. */
|
|
154
127
|
readonly snapshotKey: string;
|
|
155
|
-
/** How many commits HEAD has that `base` lacks:
|
|
128
|
+
/** How many commits HEAD has that `base` lacks: each candidate's `builtBehind`. */
|
|
156
129
|
readonly commitsAfterBase: number;
|
|
157
|
-
|
|
158
|
-
readonly devSnapshots: DevSnapshotReuse;
|
|
159
|
-
}): Promise<CheckoutResult<SnapshotClassification>>;
|
|
130
|
+
}): SnapshotClassification;
|
|
160
131
|
/**
|
|
161
132
|
* Why a run for `owner`'s team and project starts from none of the recipe's cached snapshots, when the pick found no
|
|
162
133
|
* candidate of theirs: every candidate is then another team's or project's, `other-owner`; an entry for another team
|
|
@@ -167,34 +138,11 @@ export declare function snapshotRejections(read: SnapshotCacheRead, owner: {
|
|
|
167
138
|
readonly projectId: string;
|
|
168
139
|
}): RejectedSnapshot[];
|
|
169
140
|
/**
|
|
170
|
-
* Picks the runner snapshot a run starts from, once the credential names its team and project
|
|
171
|
-
* them
|
|
172
|
-
*
|
|
173
|
-
* an ancestor of is the fewest commits behind; on separate lines of a merged history, the one with the least left to
|
|
174
|
-
* install and build wins. Identities make the answer unique: a team and project have one base snapshot at the
|
|
175
|
-
* merge-base, and one dev snapshot of this checkout per commit. `undefined` when none is for them.
|
|
141
|
+
* Picks the runner snapshot a run starts from, once the credential names its team and project: the candidate for
|
|
142
|
+
* them. Every candidate has the run's merge-base and snapshot key, and identities make the answer unique: a team and
|
|
143
|
+
* project have one entry per recipe, key and base. `undefined` when none is for them.
|
|
176
144
|
*/
|
|
177
145
|
export declare function pickSnapshot(candidates: readonly RunnerSnapshotCandidate[], owner: {
|
|
178
146
|
readonly teamId: string;
|
|
179
147
|
readonly projectId: string;
|
|
180
148
|
}): RunnerSnapshotCandidate | undefined;
|
|
181
|
-
/**
|
|
182
|
-
* What dropping dev snapshots from the cache did: the snapshot ids of the entries it removed, and why it couldn't list
|
|
183
|
-
* the cache or remove an entry, if it couldn't.
|
|
184
|
-
*/
|
|
185
|
-
export interface DevSnapshotDrop {
|
|
186
|
-
readonly snapshotIds: readonly string[];
|
|
187
|
-
readonly failures: readonly DevSnapshotDropFailure[];
|
|
188
|
-
}
|
|
189
|
-
/** Why a drop couldn't list the cache or remove an entry: what failed, in words. */
|
|
190
|
-
export interface DevSnapshotDropFailure {
|
|
191
|
-
readonly message: string;
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Removes every cached dev snapshot entry built on the base snapshot `replaced` names: of its team and project, its
|
|
195
|
-
* recipe's region, runtime and name, its snapshot key and its base, from any checkout, since each started from that
|
|
196
|
-
* base snapshot or from a dev snapshot built on it, and holds its toolchains. `storm snapshots build --full` calls it
|
|
197
|
-
* once its new base snapshot replaced that one, so no run starts from the old toolchains. The snapshots themselves are
|
|
198
|
-
* left to expire. A failure is reported, never a refusal.
|
|
199
|
-
*/
|
|
200
|
-
export declare function dropDevSnapshotsOn(context: Pick<SnapshotCacheContext, "runnerSnapshots">, replaced: Pick<RunnerSnapshotEntry, "teamId" | "projectId" | "region" | "runtime" | "recipeName" | "snapshotKey" | "base">): Promise<DevSnapshotDrop>;
|