@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
|
@@ -1,35 +1,21 @@
|
|
|
1
|
-
// `storm snapshots build`: building
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
// resource, runs no command, and keeps no sandbox.
|
|
5
|
-
import {
|
|
6
|
-
import { obtainSnapshot, readyRunner } from "./ready.js";
|
|
1
|
+
// `storm snapshots build`: building one base snapshot that the runner snapshot cache lacks, with no run: at the
|
|
2
|
+
// merge-base by default, or at the commit `--base <ref>` names, which a run starts from only once that commit is its
|
|
3
|
+
// merge-base. It owns its sandbox scope from its first stage to its end, as a run's runner session does. It
|
|
4
|
+
// acquires no resource, runs no command, and keeps no sandbox.
|
|
5
|
+
import { resolveBase } from "./base.js";
|
|
7
6
|
import { runnerSandboxScope } from "./scope.js";
|
|
8
7
|
import { buildSnapshot } from "./snapshot-build.js";
|
|
9
|
-
import {
|
|
8
|
+
import { hasTimeLeft } from "./snapshot-cache.js";
|
|
10
9
|
import { snapshotStepsAt } from "./snapshot-key.js";
|
|
11
|
-
import { saveDevSnapshot } from "./snapshot-save.js";
|
|
12
|
-
import { chooseSnapshotStart } from "./snapshot-start.js";
|
|
13
10
|
/**
|
|
14
|
-
* Runs a build's local checks, before anything is minted or started
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* base
|
|
11
|
+
* Runs a build's local checks, before anything is minted or started: the repository's root, HEAD, the submodule
|
|
12
|
+
* refusal, HEAD's merge-base (`resolveBase`, which refuses with `no-base-ref` only without `--base`), the commit
|
|
13
|
+
* `--base` resolves to locally, the snapshot steps and key at the commit it builds, the cache's base snapshots of it,
|
|
14
|
+
* and, when it builds at the merge-base, HEAD's count of commits after it. It never mints, acquires or creates, and removes no cache file.
|
|
18
15
|
*/
|
|
19
16
|
export async function prepareSnapshotBuild(context, request) {
|
|
20
|
-
const { recipe, mode } = request;
|
|
21
|
-
if (mode.kind === "checkout") {
|
|
22
|
-
const prepared = await prepareRunner(context, {
|
|
23
|
-
cwd: request.cwd,
|
|
24
|
-
recipe,
|
|
25
|
-
vcpusRun: request.vcpusRun,
|
|
26
|
-
reuseDevSnapshots: recipe.reuseDevSnapshot,
|
|
27
|
-
});
|
|
28
|
-
if (prepared.kind !== "ok")
|
|
29
|
-
return prepared;
|
|
30
|
-
return { kind: "ok", build: { kind: "checkout", prepared: prepared.prepared, full: mode.full } };
|
|
31
|
-
}
|
|
32
17
|
const { checkout } = context;
|
|
18
|
+
const { recipe, ref } = request;
|
|
33
19
|
const root = await checkout.repositoryRoot({ cwd: request.cwd });
|
|
34
20
|
if (!root.ok)
|
|
35
21
|
return { kind: "checkout-failed", failure: root.failure };
|
|
@@ -37,47 +23,53 @@ export async function prepareSnapshotBuild(context, request) {
|
|
|
37
23
|
const head = await checkout.head({ repoRoot });
|
|
38
24
|
if (!head.ok)
|
|
39
25
|
return { kind: "checkout-failed", failure: head.failure };
|
|
26
|
+
const resolved = await resolveBase(checkout, { repoRoot, baseRefs: recipe.baseRefs });
|
|
27
|
+
if (resolved.kind === "failed")
|
|
28
|
+
return { kind: "checkout-failed", failure: resolved.failure };
|
|
29
|
+
const mergeBase = resolved.kind === "resolved" ? { commit: resolved.base, ref: resolved.ref } : null;
|
|
40
30
|
const submodules = await checkout.submodules({ repoRoot });
|
|
41
31
|
if (!submodules.ok)
|
|
42
32
|
return { kind: "checkout-failed", failure: submodules.failure };
|
|
43
33
|
if (submodules.value.length > 0)
|
|
44
34
|
return { kind: "submodules", paths: [...submodules.value] };
|
|
45
|
-
|
|
46
|
-
if (
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
35
|
+
let base;
|
|
36
|
+
if (ref === undefined) {
|
|
37
|
+
if (resolved.kind !== "resolved")
|
|
38
|
+
return resolved;
|
|
39
|
+
base = resolved.base;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
const commit = await checkout.resolveCommit({ repoRoot, ref });
|
|
43
|
+
if (!commit.ok)
|
|
44
|
+
return { kind: "checkout-failed", failure: commit.failure };
|
|
45
|
+
if (commit.value === null)
|
|
46
|
+
return { kind: "ref-not-found", ref };
|
|
47
|
+
base = commit.value;
|
|
48
|
+
}
|
|
51
49
|
const steps = await snapshotStepsAt(checkout, { repoRoot, base, recipe });
|
|
52
50
|
if (!steps.ok)
|
|
53
51
|
return { kind: "invalid-recipe", path: steps.path, problem: steps.problem };
|
|
54
52
|
// An unreadable cache holds nothing to reuse: the build goes on, and builds.
|
|
55
53
|
const listed = await context.runnerSnapshots.listEntries();
|
|
56
54
|
const now = context.clock.now();
|
|
57
|
-
const cached = (listed.ok ? listed.value.entries : []).filter((entry) =>
|
|
58
|
-
entry.base === base &&
|
|
55
|
+
const cached = (listed.ok ? listed.value.entries : []).filter((entry) => entry.base === base &&
|
|
59
56
|
entry.recipeName === recipe.name &&
|
|
60
57
|
entry.region === recipe.region &&
|
|
61
58
|
entry.runtime === recipe.runtime &&
|
|
62
59
|
entry.snapshotKey === steps.key &&
|
|
63
60
|
hasTimeLeft(entry, now));
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
61
|
+
const atMergeBase = base === mergeBase?.commit;
|
|
62
|
+
// The built snapshot's count behind HEAD, for a build at the merge-base, the one snapshot a run here starts from.
|
|
63
|
+
let commitsAfterBase = null;
|
|
64
|
+
if (atMergeBase) {
|
|
65
|
+
const counted = await checkout.commitCount({ repoRoot, from: base, to: "HEAD" });
|
|
66
|
+
if (!counted.ok)
|
|
67
|
+
return { kind: "checkout-failed", failure: counted.failure };
|
|
68
|
+
commitsAfterBase = counted.value;
|
|
72
69
|
}
|
|
73
|
-
if (!onBaseRef)
|
|
74
|
-
warnings.push({ kind: "not-on-base-ref", refs: recipe.baseRefs });
|
|
75
|
-
const inHistory = await checkout.contains({ repoRoot, ancestor: base, descendant: "HEAD" });
|
|
76
|
-
const afterBase = inHistory.ok && inHistory.value ? await checkout.commitCount({ repoRoot, from: base, to: "HEAD" }) : undefined;
|
|
77
70
|
return {
|
|
78
71
|
kind: "ok",
|
|
79
72
|
build: {
|
|
80
|
-
kind: "base",
|
|
81
73
|
plan: {
|
|
82
74
|
recipe,
|
|
83
75
|
repoRoot,
|
|
@@ -85,37 +77,27 @@ export async function prepareSnapshotBuild(context, request) {
|
|
|
85
77
|
toolchains: steps.toolchains,
|
|
86
78
|
prebuild: steps.prebuild,
|
|
87
79
|
snapshotKey: steps.key,
|
|
88
|
-
commitsAfterBase
|
|
80
|
+
commitsAfterBase,
|
|
89
81
|
},
|
|
90
|
-
ref: mode.ref,
|
|
91
82
|
head: head.value,
|
|
83
|
+
ref: ref ?? null,
|
|
84
|
+
mergeBase,
|
|
85
|
+
atMergeBase,
|
|
92
86
|
cached,
|
|
93
|
-
full:
|
|
94
|
-
warnings,
|
|
87
|
+
full: request.full,
|
|
95
88
|
},
|
|
96
89
|
};
|
|
97
90
|
}
|
|
98
|
-
/** A build that stopped on the signal before it saved anything. */
|
|
99
|
-
const ABORTED_EARLY = { kind: "aborted", baseSnapshot: null, dropped: null };
|
|
100
91
|
/**
|
|
101
|
-
* Builds
|
|
102
|
-
* keeping none.
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
* saves no dev snapshot, any snapshot, it is up to date. Otherwise it obtains the start (`obtainSnapshot`), building a
|
|
107
|
-
* base snapshot at the merge-base when it chose to; under `full`, once the cache holds the new base snapshot's entry,
|
|
108
|
-
* it then drops the dev snapshots built on the base snapshot it replaced (`dropDevSnapshotsOn`), before any runner
|
|
109
|
-
* sandbox starts. A build that saves no dev snapshot ends there. Otherwise it readies a runner sandbox on the start
|
|
110
|
-
* (`readyRunner`) and saves it as a dev snapshot at HEAD's commit (`saveDevSnapshot`). For `--base`: a cached base
|
|
111
|
-
* snapshot of the commit for the access's team and project is up to date, unless `full`; otherwise it builds one, and
|
|
112
|
-
* under `full`, once its entry is cached, drops the dev snapshots built on the one it replaced. A base snapshot's save
|
|
113
|
-
* isn't stopped by the signal, so after it the build checks the signal once, after any drop, and ends `aborted` with
|
|
114
|
-
* what it saved.
|
|
92
|
+
* Builds the checked build's base snapshot, reporting to `progress`, and closes every sandbox it started however it
|
|
93
|
+
* ends, keeping none. A cached base snapshot at the commit for the access's team and project is up to date, unless
|
|
94
|
+
* `full`, which builds a new one that replaces its cache entry. `signal` stops it in any stage: it says so, then
|
|
95
|
+
* closes the scope at once. A base snapshot's save isn't stopped by the signal, so after it the build checks the signal
|
|
96
|
+
* once and ends `aborted` with what it saved.
|
|
115
97
|
*/
|
|
116
98
|
export async function buildSnapshots(context, request, control, progress) {
|
|
117
99
|
const { signal } = control;
|
|
118
|
-
const scope = runnerSandboxScope(context, progress, { keepMs:
|
|
100
|
+
const scope = runnerSandboxScope(context, progress, { keepMs: 0 });
|
|
119
101
|
const stop = () => {
|
|
120
102
|
void progress.emit({ kind: "stopping", commandRunning: false, keepMs: 0 }).catch(() => undefined);
|
|
121
103
|
void scope.close().catch(() => undefined);
|
|
@@ -139,97 +121,26 @@ async function buildIn(context, request, control, progress) {
|
|
|
139
121
|
const { build, access, user, secrets } = request;
|
|
140
122
|
const { signal } = control;
|
|
141
123
|
if (signal.aborted)
|
|
142
|
-
return
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
const {
|
|
159
|
-
const start = build.full
|
|
160
|
-
? { kind: "build", why: { kind: "full" } }
|
|
161
|
-
: chooseSnapshotStart(prepared, access);
|
|
162
|
-
if (start.kind === "reuse") {
|
|
163
|
-
const { entry } = start.candidate;
|
|
164
|
-
if (isDevEntry(entry) && entry.head === prepared.head.commit && !prepared.head.dirty)
|
|
165
|
-
return { kind: "up-to-date", snapshot: entry };
|
|
166
|
-
// A build that saves no dev snapshot needs only a snapshot that fits.
|
|
167
|
-
if (prepared.devSnapshots !== "reuse")
|
|
168
|
-
return { kind: "up-to-date", snapshot: entry };
|
|
169
|
-
}
|
|
170
|
-
const obtained = await obtainSnapshot(context, { prepared, access, user, secrets, start }, control, progress);
|
|
171
|
-
if (obtained.kind === "aborted")
|
|
172
|
-
return ABORTED_EARLY;
|
|
173
|
-
if (obtained.kind !== "ok")
|
|
174
|
-
return obtained;
|
|
175
|
-
const { built } = obtained.value;
|
|
176
|
-
// The base snapshot this build built, if any. Only a cached one replaces the old one.
|
|
177
|
-
const baseSnapshot = built === null ? null : savedBaseOf(built);
|
|
178
|
-
const dropped = build.full && baseSnapshot?.cached === true ? await dropOn(context, baseSnapshot.entry, progress) : null;
|
|
179
|
-
const aborted = { kind: "aborted", baseSnapshot, dropped };
|
|
124
|
+
return { kind: "aborted", snapshot: null };
|
|
125
|
+
const cached = build.cached.find((entry) => entry.teamId === access.teamId && entry.projectId === access.projectId);
|
|
126
|
+
if (!build.full && cached !== undefined)
|
|
127
|
+
return { kind: "up-to-date", snapshot: cached };
|
|
128
|
+
const why = build.full ? "full" : build.ref === null ? "no-snapshot" : "base";
|
|
129
|
+
const built = await buildSnapshot(context, {
|
|
130
|
+
prepared: build.plan,
|
|
131
|
+
access,
|
|
132
|
+
user,
|
|
133
|
+
secrets,
|
|
134
|
+
why: why === "no-snapshot" ? { kind: why, rejected: [] } : { kind: why },
|
|
135
|
+
}, control, progress);
|
|
136
|
+
if (built.kind === "aborted")
|
|
137
|
+
return { kind: "aborted", snapshot: null };
|
|
138
|
+
if (built.kind !== "ok")
|
|
139
|
+
return built;
|
|
140
|
+
const { entry, cacheFailure, ms, sizeBytes } = built.value;
|
|
180
141
|
if (signal.aborted)
|
|
181
|
-
return aborted;
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
const ready = await readyRunner(context, { prepared, access, user, secrets, start: obtained.value }, control, progress);
|
|
186
|
-
if (ready.kind === "aborted")
|
|
187
|
-
return aborted;
|
|
188
|
-
if (ready.kind !== "ready")
|
|
189
|
-
return ready;
|
|
190
|
-
const { runner } = ready;
|
|
191
|
-
const saved = await saveDevSnapshot(context, { ready: runner, branch: prepared.head.branch, head: prepared.head.commit }, control, progress);
|
|
192
|
-
if (saved.entry === null) {
|
|
193
|
-
const { save } = saved;
|
|
194
|
-
// Only a signal stops a save: its handler is what closes the scope.
|
|
195
|
-
return save.kind === "stopped"
|
|
196
|
-
? aborted
|
|
197
|
-
: { kind: "dev-snapshot-not-saved", step: save.step, message: save.message, baseSnapshot };
|
|
198
|
-
}
|
|
199
|
-
const { entry, cacheFailure, save } = saved;
|
|
200
|
-
if (cacheFailure !== null)
|
|
201
|
-
return { kind: "not-cached", snapshot: entry, failure: cacheFailure, baseSnapshot, dropped };
|
|
202
|
-
return {
|
|
203
|
-
kind: "built",
|
|
204
|
-
baseSnapshot,
|
|
205
|
-
startedFrom: runner.startedFrom,
|
|
206
|
-
devSnapshot: { entry, ms: save.ms, sizeBytes: save.sizeBytes },
|
|
207
|
-
dropped,
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
/** A base snapshot this build built, and whether the cache wrote its entry. */
|
|
211
|
-
function savedBaseOf(built) {
|
|
212
|
-
return { entry: built.entry, cached: built.cacheFailure === null };
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* How a build that saves no dev snapshot ends once it built base snapshot `built`: `built` when the cache wrote its
|
|
216
|
-
* entry, else `not-cached`, since no run finds it. It takes the base snapshot it built, never one it reused.
|
|
217
|
-
*/
|
|
218
|
-
function baseOnlyEnd(built, dropped) {
|
|
219
|
-
const baseSnapshot = savedBaseOf(built);
|
|
220
|
-
return built.cacheFailure === null
|
|
221
|
-
? { kind: "built", baseSnapshot, startedFrom: null, devSnapshot: null, dropped }
|
|
222
|
-
: { kind: "not-cached", snapshot: built.entry, failure: built.cacheFailure, baseSnapshot, dropped };
|
|
223
|
-
}
|
|
224
|
-
/**
|
|
225
|
-
* Drops the dev snapshots built on the base snapshot `built` replaced, the cache entry of the same identity, and
|
|
226
|
-
* reports what it dropped and what it couldn't.
|
|
227
|
-
*/
|
|
228
|
-
async function dropOn(context, built, progress) {
|
|
229
|
-
const dropped = await dropDevSnapshotsOn(context, built);
|
|
230
|
-
if (dropped.snapshotIds.length > 0)
|
|
231
|
-
await progress.emit({ kind: "dev-snapshots-dropped", snapshotIds: dropped.snapshotIds });
|
|
232
|
-
for (const { message } of dropped.failures)
|
|
233
|
-
await progress.emit({ kind: "dev-snapshots-not-dropped", message });
|
|
234
|
-
return dropped;
|
|
142
|
+
return { kind: "aborted", snapshot: { entry, cached: cacheFailure === null } };
|
|
143
|
+
return cacheFailure === null
|
|
144
|
+
? { kind: "built", snapshot: entry, ms, sizeBytes }
|
|
145
|
+
: { kind: "not-cached", snapshot: entry, failure: cacheFailure };
|
|
235
146
|
}
|
package/dist/runner/events.d.ts
CHANGED
|
@@ -47,9 +47,8 @@ export type SnapshotBuildReason = {
|
|
|
47
47
|
/**
|
|
48
48
|
* What the runner reports, in order.
|
|
49
49
|
*
|
|
50
|
-
* - `snapshot-reused`: the run starts from cached runner snapshot `snapshotId`,
|
|
51
|
-
*
|
|
52
|
-
* for a base snapshot. `snapshot` says its kind, its built-at commit and how far it is behind the run.
|
|
50
|
+
* - `snapshot-reused`: the run starts from cached runner snapshot `snapshotId`, built at `base`; `builtBehind` is how
|
|
51
|
+
* many commits HEAD has that `base` lacks.
|
|
53
52
|
* - `snapshot-build-started`: a base snapshot of `base` is being built, and `why` (`SnapshotBuildReason`); `summary`
|
|
54
53
|
* says what the build does.
|
|
55
54
|
* - `runner-sandbox-starting`: the runner sandbox is starting from runner snapshot `snapshotId`.
|
|
@@ -58,7 +57,7 @@ export type SnapshotBuildReason = {
|
|
|
58
57
|
* - `step-started`, `step-output` (one line, without its newline) and `step-finished`: a step's progress.
|
|
59
58
|
* - `snapshot-saving`: the build sandbox is being saved as a runner snapshot.
|
|
60
59
|
* - `snapshot-built`: it was, in `ms` from the build's start; `builtBehind` is how many commits HEAD has that `base`
|
|
61
|
-
* lacks, null for a `storm snapshots build --base` commit that isn't
|
|
60
|
+
* lacks, null for a `storm snapshots build --base` commit that isn't HEAD's merge-base.
|
|
62
61
|
* - `snapshot-entry-not-written`: the cache couldn't record the new snapshot; the run goes on.
|
|
63
62
|
* - `uploading`: the run's changes are being uploaded to the runner sandbox.
|
|
64
63
|
* - `uploaded`: the run's changes, `bytes` in all, reached the runner sandbox.
|
|
@@ -70,22 +69,12 @@ export type SnapshotBuildReason = {
|
|
|
70
69
|
* and releasing the run's resources.
|
|
71
70
|
* - `waiting-for-snapshot`: closing waits up to `settleMs` for a runner snapshot still saving.
|
|
72
71
|
* - `sandbox-kept`: closing kept runner sandbox `name` running until `stopsAt`, an ISO time.
|
|
73
|
-
* - `dev-snapshot-saving`: the run saves the runner sandbox as a dev snapshot, once the command ended; `branch` is
|
|
74
|
-
* HEAD's branch, null when detached.
|
|
75
|
-
* - `dev-snapshot-saved`: it did, as runner snapshot `snapshotId` at HEAD commit `head`, in `ms`.
|
|
76
|
-
* - `dev-snapshot-not-saved`: it didn't, and `save` says why.
|
|
77
|
-
* - `dev-snapshot-skipped`: the command ended on its own and the run starts no save, for `reason`.
|
|
78
|
-
* - `dev-snapshots-dropped`: `storm snapshots build --full` removed the cache entries of the dev snapshots built on
|
|
79
|
-
* the base snapshot it replaced, from any checkout.
|
|
80
|
-
* - `dev-snapshots-not-dropped`: it couldn't list the cache or remove an entry; `message` says which.
|
|
81
72
|
*/
|
|
82
73
|
export type RunnerEvent = {
|
|
83
74
|
readonly kind: "snapshot-reused";
|
|
84
75
|
readonly snapshotId: string;
|
|
85
76
|
readonly base: string;
|
|
86
|
-
readonly
|
|
87
|
-
readonly head: string | null;
|
|
88
|
-
readonly snapshot: StartedFromSnapshot;
|
|
77
|
+
readonly builtBehind: number;
|
|
89
78
|
} | {
|
|
90
79
|
readonly kind: "snapshot-build-started";
|
|
91
80
|
readonly base: string;
|
|
@@ -160,30 +149,6 @@ export type RunnerEvent = {
|
|
|
160
149
|
readonly kind: "sandbox-kept";
|
|
161
150
|
readonly name: string;
|
|
162
151
|
readonly stopsAt: string;
|
|
163
|
-
} | {
|
|
164
|
-
readonly kind: "dev-snapshot-saving";
|
|
165
|
-
readonly branch: string | null;
|
|
166
|
-
} | {
|
|
167
|
-
readonly kind: "dev-snapshot-saved";
|
|
168
|
-
readonly snapshotId: string;
|
|
169
|
-
readonly branch: string | null;
|
|
170
|
-
readonly head: string;
|
|
171
|
-
readonly ms: number;
|
|
172
|
-
readonly sizeBytes: number;
|
|
173
|
-
} | {
|
|
174
|
-
readonly kind: "dev-snapshot-not-saved";
|
|
175
|
-
readonly save: Exclude<RunnerSave, {
|
|
176
|
-
readonly kind: "saved";
|
|
177
|
-
}>;
|
|
178
|
-
} | {
|
|
179
|
-
readonly kind: "dev-snapshot-skipped";
|
|
180
|
-
readonly reason: RunnerNoSaveReason;
|
|
181
|
-
} | {
|
|
182
|
-
readonly kind: "dev-snapshots-dropped";
|
|
183
|
-
readonly snapshotIds: readonly string[];
|
|
184
|
-
} | {
|
|
185
|
-
readonly kind: "dev-snapshots-not-dropped";
|
|
186
|
-
readonly message: string;
|
|
187
152
|
};
|
|
188
153
|
/** Hears the runner's events as they happen. */
|
|
189
154
|
export interface RunnerProgress {
|
|
@@ -213,55 +178,6 @@ export type RunnerFailure = {
|
|
|
213
178
|
readonly kind: "checkout-failed";
|
|
214
179
|
readonly failure: CheckoutFailure;
|
|
215
180
|
};
|
|
216
|
-
/**
|
|
217
|
-
* The runner snapshot a run starts from, in commits: its kind, the commit it was built at (a base snapshot's base, or
|
|
218
|
-
* the commit that saved a dev snapshot), and how many commits HEAD has that its built-at commit lacks
|
|
219
|
-
* (`builtBehind`). The count is null when the commit isn't in HEAD's history, as for a `storm snapshots build --base`
|
|
220
|
-
* build, or when an older run record holds none.
|
|
221
|
-
*/
|
|
222
|
-
export interface StartedFromSnapshot {
|
|
223
|
-
readonly kind: "base" | "dev";
|
|
224
|
-
readonly builtAt: string;
|
|
225
|
-
readonly builtBehind: number | null;
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* Why a run saves never, decided before it starts: `--save-dev-snapshot=false` (`no-save-flag`), the recipe's
|
|
229
|
-
* `saveDevSnapshot: false` (`recipe`), a `--keep-sandbox` above 0 (`keep-sandbox`), `CI` set (`ci`), or a recipe
|
|
230
|
-
* whose install or build step names a runner secret and that doesn't set `trustDevSnapshots` (`not-trusted`).
|
|
231
|
-
*/
|
|
232
|
-
export type NeverSaveReason = "no-save-flag" | "recipe" | "keep-sandbox" | "ci" | "not-trusted";
|
|
233
|
-
/**
|
|
234
|
-
* Why a run whose command ended on its own started no save: it saves never (`NeverSaveReason`), the command didn't
|
|
235
|
-
* exit 0 (`command-failed`), or the run started from a dev snapshot built at HEAD's commit (`already-saved`).
|
|
236
|
-
*/
|
|
237
|
-
export type RunnerNoSaveReason = NeverSaveReason | "command-failed" | "already-saved";
|
|
238
|
-
/**
|
|
239
|
-
* How saving the runner sandbox as a dev snapshot ended.
|
|
240
|
-
*
|
|
241
|
-
* - `saved`: it is runner snapshot `snapshotId` of `base`, at HEAD commit `head` on `branch`, null when HEAD was
|
|
242
|
-
* detached, saved in `ms` from the save's start; `entryWritten` says whether the cache recorded it.
|
|
243
|
-
* - `failed`: the scrub or the save failed with `message`.
|
|
244
|
-
* - `stopped`: a signal stopped it before it saved, or before the cache recorded the snapshot.
|
|
245
|
-
*
|
|
246
|
-
* A run whose save started never keeps its runner sandbox, however the save ended; a run whose save never started
|
|
247
|
-
* has none of these, and keeps its runner sandbox for the keep time (`RunnerSandboxPlan`).
|
|
248
|
-
*/
|
|
249
|
-
export type RunnerSave = {
|
|
250
|
-
readonly kind: "saved";
|
|
251
|
-
readonly snapshotId: string;
|
|
252
|
-
readonly base: string;
|
|
253
|
-
readonly branch: string | null;
|
|
254
|
-
readonly head: string;
|
|
255
|
-
readonly ms: number;
|
|
256
|
-
readonly sizeBytes: number;
|
|
257
|
-
readonly entryWritten: boolean;
|
|
258
|
-
} | {
|
|
259
|
-
readonly kind: "failed";
|
|
260
|
-
readonly step: "scrub" | "save-snapshot";
|
|
261
|
-
readonly message: string;
|
|
262
|
-
} | {
|
|
263
|
-
readonly kind: "stopped";
|
|
264
|
-
};
|
|
265
181
|
/** How one stage of readying the runner ended: its value, a failure, or a stop because the run was aborted. */
|
|
266
182
|
export type RunnerStage<T> = {
|
|
267
183
|
readonly kind: "ok";
|
|
@@ -134,9 +134,7 @@ export interface CheckoutGateway {
|
|
|
134
134
|
}
|
|
135
135
|
/**
|
|
136
136
|
* One runner snapshot the cache records: who it belongs to, what it was built from, and when it expires. Times
|
|
137
|
-
* are ISO strings.
|
|
138
|
-
* without them records a base snapshot, built from its base. An entry has both or neither, and `branch` only with
|
|
139
|
-
* them.
|
|
137
|
+
* are ISO strings. Every entry records a base snapshot, built at its base, which may be any commit.
|
|
140
138
|
*/
|
|
141
139
|
export interface RunnerSnapshotEntry {
|
|
142
140
|
readonly teamId: string;
|
|
@@ -146,23 +144,8 @@ export interface RunnerSnapshotEntry {
|
|
|
146
144
|
readonly recipeName: string;
|
|
147
145
|
/** The snapshot key at `base` (`snapshotKey`). */
|
|
148
146
|
readonly snapshotKey: string;
|
|
149
|
-
/** The base commit's full SHA
|
|
147
|
+
/** The base commit's full SHA: the commit the snapshot was built at, whose tracked files its repository commits. */
|
|
150
148
|
readonly base: string;
|
|
151
|
-
/**
|
|
152
|
-
* For a dev snapshot, the local branch of the run that saved it, for display; absent when that run's HEAD was
|
|
153
|
-
* detached. No lookup reads it.
|
|
154
|
-
*/
|
|
155
|
-
readonly branch?: string;
|
|
156
|
-
/**
|
|
157
|
-
* For a dev snapshot, the full SHA of the HEAD commit of the run that saved it, the commit it was built at. A run
|
|
158
|
-
* starts from it only while that commit is HEAD or in HEAD's history.
|
|
159
|
-
*/
|
|
160
|
-
readonly head?: string;
|
|
161
|
-
/**
|
|
162
|
-
* For a dev snapshot, the root of the checkout the run that saved it ran from. Only a run from that checkout
|
|
163
|
-
* starts from it, so another checkout never inherits what this run left.
|
|
164
|
-
*/
|
|
165
|
-
readonly repoRoot?: string;
|
|
166
149
|
readonly snapshotId: string;
|
|
167
150
|
readonly createdAt: string;
|
|
168
151
|
readonly expiresAt: string;
|
|
@@ -199,8 +182,7 @@ export type RunnerSnapshotCacheOperation = {
|
|
|
199
182
|
};
|
|
200
183
|
/**
|
|
201
184
|
* The per-machine runner snapshot cache: one record per runner snapshot, keyed by the entry's identity (team,
|
|
202
|
-
* project, region, runtime, recipe name, snapshot key
|
|
203
|
-
* and commit).
|
|
185
|
+
* project, region, runtime, recipe name, snapshot key and base).
|
|
204
186
|
* Every method returns its expected failures and never rejects. Which entries a run may use, and when one has
|
|
205
187
|
* expired, is the caller's.
|
|
206
188
|
*/
|
|
@@ -291,7 +273,7 @@ export interface StagedFile {
|
|
|
291
273
|
readonly name: string;
|
|
292
274
|
readonly content: Uint8Array;
|
|
293
275
|
}
|
|
294
|
-
/** A runner snapshot a build sandbox
|
|
276
|
+
/** A runner snapshot a build sandbox was saved as. */
|
|
295
277
|
export interface SavedSnapshot {
|
|
296
278
|
readonly snapshotId: string;
|
|
297
279
|
/** When the Sandbox API says it expires, as an ISO string, when it says. */
|
|
@@ -350,7 +332,7 @@ export interface RunnerSandboxGateway {
|
|
|
350
332
|
readonly path: string;
|
|
351
333
|
readonly fromLine: number;
|
|
352
334
|
}, onOutput: (chunk: SandboxOutputChunk) => void, signal?: AbortSignal): Promise<RunnerSandboxOperation>;
|
|
353
|
-
/** Saves a build
|
|
335
|
+
/** Saves a build sandbox as a runner snapshot that expires after `expirationMs`; that stops the sandbox. */
|
|
354
336
|
saveSnapshot(sandbox: RunnerSandbox, request: {
|
|
355
337
|
readonly expirationMs: number;
|
|
356
338
|
}): Promise<RunnerSandboxResult<SavedSnapshot>>;
|
package/dist/runner/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type { RunnerContext } from "./context.ts";
|
|
2
|
-
export { buildSnapshots, prepareSnapshotBuild, type PrepareSnapshotBuildOutcome, type
|
|
3
|
-
export { type KeptSandbox, type
|
|
2
|
+
export { buildSnapshots, prepareSnapshotBuild, type PrepareSnapshotBuildOutcome, type SnapshotBuildOutcome, } from "./build-snapshots.ts";
|
|
3
|
+
export { type KeptSandbox, type RunnerEvent, type RunnerFailure, type RunnerProgress, type RunnerStepPhase, type SnapshotBuildReason, } from "./events.ts";
|
|
4
4
|
export type { CheckoutFailure, CheckoutGateway, RunnerSandboxGateway, RunnerSnapshotCacheFailure, RunnerSnapshotCacheGateway, RunnerSnapshotEntry, RunnerTerminal, } from "./gateways.ts";
|
|
5
5
|
export { liveCheckoutGateway } from "./live/checkout-gateway.ts";
|
|
6
6
|
export { liveRunnerSandboxGateway } from "./live/sandbox-gateway.ts";
|
|
@@ -10,10 +10,9 @@ export { liveRunnerSnapshotCacheGateway, unavailableRunnerSnapshotCacheGateway,
|
|
|
10
10
|
export { lineSplitter } from "./output.ts";
|
|
11
11
|
export { prepareRunner, type PrepareRunnerOutcome } from "./prepare.ts";
|
|
12
12
|
export type { ReadyRunnerOutcome } from "./ready.ts";
|
|
13
|
-
export { type CheckedRecipe, checkRecipe
|
|
13
|
+
export { type CheckedRecipe, checkRecipe } from "./recipe.ts";
|
|
14
14
|
export { SANDBOX_TEST_EVENTS_PATH } from "./sandboxed-command.ts";
|
|
15
15
|
export { declaredSecretValues, readRunnerSecrets, RUNNER_SECRET_MIN_LENGTH, type RunnerSecrets } from "./secrets.ts";
|
|
16
|
-
export type
|
|
17
|
-
export { type RunnerCleanupFacts, openRunnerSession, type RunnerSaveMode, type RunnerSession, type RunnerSessionRequest, } from "./session.ts";
|
|
16
|
+
export { type RunnerCleanupFacts, openRunnerSession, type RunnerSession, type RunnerSessionCleanup, type RunnerSessionRequest, } from "./session.ts";
|
|
18
17
|
export { type InspectedSnapshot, inspectSnapshotCache, type SnapshotCacheInspection, type UnpickedReason, } from "./snapshot-inspect.ts";
|
|
19
|
-
export { type
|
|
18
|
+
export { type RejectedSnapshot, RUNNER_SNAPSHOTS_SUBPATH, type SnapshotCacheNote, type SnapshotRejectionReason, } from "./snapshot-cache.ts";
|
package/dist/runner/index.js
CHANGED
|
@@ -10,7 +10,7 @@ export { localUserName } from "./live/user.js";
|
|
|
10
10
|
export { liveRunnerSnapshotCacheGateway, unavailableRunnerSnapshotCacheGateway, } from "./live/snapshot-cache-gateway.js";
|
|
11
11
|
export { lineSplitter } from "./output.js";
|
|
12
12
|
export { prepareRunner } from "./prepare.js";
|
|
13
|
-
export { checkRecipe
|
|
13
|
+
export { checkRecipe } from "./recipe.js";
|
|
14
14
|
export { SANDBOX_TEST_EVENTS_PATH } from "./sandboxed-command.js";
|
|
15
15
|
export { declaredSecretValues, readRunnerSecrets, RUNNER_SECRET_MIN_LENGTH } from "./secrets.js";
|
|
16
16
|
export { openRunnerSession, } from "./session.js";
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
// The runner snapshot cache's file format: one JSON object per runner snapshot, carrying `version: 1`. A reader
|
|
2
|
-
// rejects a version it doesn't know
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
// predates dev snapshots and drops the fields as it reads, never starts from it, and this storm never starts from an
|
|
7
|
-
// older storm's dev snapshot file: there is no migration, and each file stays until its snapshot expires.
|
|
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. So a file an older storm
|
|
4
|
+
// wrote for a dev snapshot, named for an identity that held its checkout's root and commit, is listed as unreadable,
|
|
5
|
+
// and no run starts from it: there is no migration.
|
|
8
6
|
import { z } from "zod";
|
|
9
7
|
const isoTime = z.string().refine((value) => !Number.isNaN(Date.parse(value)), { message: "not a time" });
|
|
10
8
|
const nonEmpty = z.string().min(1);
|
|
11
|
-
const entrySchema = z
|
|
12
|
-
.object({
|
|
9
|
+
const entrySchema = z.object({
|
|
13
10
|
version: z.literal(1),
|
|
14
11
|
teamId: nonEmpty,
|
|
15
12
|
projectId: nonEmpty,
|
|
@@ -18,15 +15,10 @@ const entrySchema = z
|
|
|
18
15
|
recipeName: nonEmpty,
|
|
19
16
|
snapshotKey: nonEmpty,
|
|
20
17
|
base: nonEmpty,
|
|
21
|
-
branch: nonEmpty.exactOptional(),
|
|
22
|
-
head: nonEmpty.exactOptional(),
|
|
23
|
-
repoRoot: nonEmpty.exactOptional(),
|
|
24
18
|
snapshotId: nonEmpty,
|
|
25
19
|
createdAt: isoTime,
|
|
26
20
|
expiresAt: isoTime,
|
|
27
|
-
})
|
|
28
|
-
.refine((entry) => (entry.head === undefined) === (entry.repoRoot === undefined) &&
|
|
29
|
-
(entry.branch === undefined || entry.head !== undefined), { message: "has some of branch, head and repoRoot without head and repoRoot together" });
|
|
21
|
+
});
|
|
30
22
|
/** The entry a cache file holds, or why it holds none. */
|
|
31
23
|
export function parseSnapshotEntry(text) {
|
|
32
24
|
let json;
|
|
@@ -50,7 +42,7 @@ export function parseSnapshotEntry(text) {
|
|
|
50
42
|
}
|
|
51
43
|
/** The text of the file that records `entry`. */
|
|
52
44
|
export function snapshotEntryText(entry) {
|
|
53
|
-
const { teamId, projectId, region, runtime, recipeName, snapshotKey, base
|
|
45
|
+
const { teamId, projectId, region, runtime, recipeName, snapshotKey, base } = entry;
|
|
54
46
|
const { snapshotId, createdAt, expiresAt } = entry;
|
|
55
47
|
const record = {
|
|
56
48
|
version: 1,
|
|
@@ -61,9 +53,6 @@ export function snapshotEntryText(entry) {
|
|
|
61
53
|
recipeName,
|
|
62
54
|
snapshotKey,
|
|
63
55
|
base,
|
|
64
|
-
...(branch === undefined ? {} : { branch }),
|
|
65
|
-
...(head === undefined ? {} : { head }),
|
|
66
|
-
...(repoRoot === undefined ? {} : { repoRoot }),
|
|
67
56
|
snapshotId,
|
|
68
57
|
createdAt,
|
|
69
58
|
expiresAt,
|