@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
|
@@ -11,11 +11,8 @@ export const SNAPSHOT_EXPIRATION_MS = 7 * 24 * 60 * 60 * 1000;
|
|
|
11
11
|
export const SNAPSHOT_MIN_REMAINING_MS = 60 * 60 * 1000;
|
|
12
12
|
/**
|
|
13
13
|
* An entry's identity: the first 32 hex characters of sha256 over its team id, project id, region, runtime, recipe
|
|
14
|
-
* name
|
|
15
|
-
*
|
|
16
|
-
* snapshot's at its base, and a dev snapshot's replaces only the one its checkout saved at the same commit. The
|
|
17
|
-
* 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
|
|
18
|
-
* snapshots existed.
|
|
14
|
+
* name, snapshot key and base, joined with NUL. Entries with one identity replace each other, so a team and project
|
|
15
|
+
* have one entry per recipe, key and base.
|
|
19
16
|
*/
|
|
20
17
|
export function snapshotEntryIdentity(entry) {
|
|
21
18
|
return createHash("sha256")
|
|
@@ -26,19 +23,11 @@ export function snapshotEntryIdentity(entry) {
|
|
|
26
23
|
entry.runtime,
|
|
27
24
|
entry.recipeName,
|
|
28
25
|
entry.snapshotKey,
|
|
29
|
-
|
|
26
|
+
entry.base,
|
|
30
27
|
].join("\0"))
|
|
31
28
|
.digest("hex")
|
|
32
29
|
.slice(0, 32);
|
|
33
30
|
}
|
|
34
|
-
/** Whether `entry` records a dev snapshot, saved from a runner sandbox, rather than a base snapshot. */
|
|
35
|
-
export function isDevEntry(entry) {
|
|
36
|
-
return entry.head !== undefined && entry.repoRoot !== undefined;
|
|
37
|
-
}
|
|
38
|
-
/** The commit `entry`'s snapshot was built at: a dev snapshot's is the commit that saved it, a base snapshot's its base. */
|
|
39
|
-
export function builtAtCommit(entry) {
|
|
40
|
-
return isDevEntry(entry) ? entry.head : entry.base;
|
|
41
|
-
}
|
|
42
31
|
/** The name of the file that records `entry`: its identity and `.json`. */
|
|
43
32
|
export function snapshotEntryFileName(entry) {
|
|
44
33
|
return `${snapshotEntryIdentity(entry)}.json`;
|
|
@@ -78,19 +67,13 @@ export async function removeExpiredEntries(context) {
|
|
|
78
67
|
}
|
|
79
68
|
/**
|
|
80
69
|
* Classifies `entries`, cache entries a caller listed, for a run of `recipe`: which ones it may start from, and why
|
|
81
|
-
* not from each other one of the recipe's. It changes no file. Of the entries for the recipe's
|
|
82
|
-
* name it keeps the ones with more than an hour left whose base is the run's merge-base
|
|
83
|
-
* key is the run's
|
|
84
|
-
*
|
|
85
|
-
* longer counts, and none unless `devSnapshots` is `reuse`. HEAD's branch is no part of it: another checkout may hold
|
|
86
|
-
* other code, so its dev snapshot never carries over, whatever its branch. Every other entry of the recipe is
|
|
87
|
-
* `rejected`, with the first reason that rules it out, an expired one as `expired`. Each entry gets exactly one
|
|
88
|
-
* verdict. Git is asked once per dev snapshot commit whether HEAD holds it and, for a candidate, how far behind HEAD it
|
|
89
|
-
* is; a git failure ends the classification with that failure.
|
|
70
|
+
* not from each other one of the recipe's. It changes no file and asks Git nothing. Of the entries for the recipe's
|
|
71
|
+
* region, runtime and name it keeps the ones with more than an hour left whose base is the run's merge-base and whose
|
|
72
|
+
* snapshot key is the run's. Every other entry of the recipe is `rejected`, with the first reason that rules it out,
|
|
73
|
+
* an expired one as `expired`. Each entry gets exactly one verdict, in the order given.
|
|
90
74
|
*/
|
|
91
|
-
export
|
|
92
|
-
const {
|
|
93
|
-
const { entries, repoRoot, recipe, base, snapshotKey, commitsAfterBase, devSnapshots } = request;
|
|
75
|
+
export function classifySnapshotEntries(context, request) {
|
|
76
|
+
const { entries, recipe, base, snapshotKey, commitsAfterBase } = request;
|
|
94
77
|
const now = context.clock.now();
|
|
95
78
|
const candidates = [];
|
|
96
79
|
const rejected = [];
|
|
@@ -100,60 +83,26 @@ export async function classifySnapshotEntries(context, request) {
|
|
|
100
83
|
rejected.push(rejection);
|
|
101
84
|
verdicts.push({ kind: "rejected", entry, rejection });
|
|
102
85
|
};
|
|
103
|
-
// Whether HEAD holds each dev snapshot's commit, and how far behind HEAD it is, asked once per commit.
|
|
104
|
-
const inHistory = new Map();
|
|
105
|
-
const behind = new Map();
|
|
106
86
|
for (const entry of entries) {
|
|
107
87
|
if (entry.region !== recipe.region || entry.runtime !== recipe.runtime || entry.recipeName !== recipe.name) {
|
|
108
88
|
verdicts.push({ kind: "other-recipe", entry });
|
|
109
89
|
continue;
|
|
110
90
|
}
|
|
111
|
-
const dev = isDevEntry(entry);
|
|
112
91
|
if (isExpiredEntry(entry, now))
|
|
113
92
|
reject(entry, "expired");
|
|
114
93
|
else if (!hasTimeLeft(entry, now))
|
|
115
94
|
reject(entry, "expires-soon");
|
|
116
|
-
else if (dev && entry.repoRoot !== repoRoot)
|
|
117
|
-
reject(entry, "other-checkout");
|
|
118
|
-
else if (dev && devSnapshots !== "reuse")
|
|
119
|
-
reject(entry, devSnapshots);
|
|
120
95
|
else if (entry.base !== base)
|
|
121
96
|
reject(entry, "other-base");
|
|
122
97
|
else if (entry.snapshotKey !== snapshotKey)
|
|
123
98
|
reject(entry, "steps-changed");
|
|
124
|
-
else if (!dev) {
|
|
125
|
-
const candidate = { entry, builtAt: entry.base, builtBehind: commitsAfterBase };
|
|
126
|
-
candidates.push(candidate);
|
|
127
|
-
verdicts.push({ kind: "candidate", entry, candidate });
|
|
128
|
-
}
|
|
129
99
|
else {
|
|
130
|
-
const
|
|
131
|
-
let contained = inHistory.get(builtAt);
|
|
132
|
-
if (contained === undefined) {
|
|
133
|
-
const asked = await checkout.contains({ repoRoot, ancestor: builtAt, descendant: "HEAD" });
|
|
134
|
-
if (!asked.ok)
|
|
135
|
-
return asked;
|
|
136
|
-
contained = asked.value;
|
|
137
|
-
inHistory.set(builtAt, contained);
|
|
138
|
-
}
|
|
139
|
-
if (!contained) {
|
|
140
|
-
reject(entry, "not-in-history");
|
|
141
|
-
continue;
|
|
142
|
-
}
|
|
143
|
-
let builtBehind = behind.get(builtAt);
|
|
144
|
-
if (builtBehind === undefined) {
|
|
145
|
-
const counted = await checkout.commitCount({ repoRoot, from: builtAt, to: "HEAD" });
|
|
146
|
-
if (!counted.ok)
|
|
147
|
-
return counted;
|
|
148
|
-
builtBehind = counted.value;
|
|
149
|
-
behind.set(builtAt, builtBehind);
|
|
150
|
-
}
|
|
151
|
-
const candidate = { entry, builtAt, builtBehind };
|
|
100
|
+
const candidate = { entry, builtBehind: commitsAfterBase };
|
|
152
101
|
candidates.push(candidate);
|
|
153
102
|
verdicts.push({ kind: "candidate", entry, candidate });
|
|
154
103
|
}
|
|
155
104
|
}
|
|
156
|
-
return {
|
|
105
|
+
return { candidates, rejected, verdicts };
|
|
157
106
|
}
|
|
158
107
|
/**
|
|
159
108
|
* Why a run for `owner`'s team and project starts from none of the recipe's cached snapshots, when the pick found no
|
|
@@ -168,51 +117,10 @@ export function snapshotRejections(read, owner) {
|
|
|
168
117
|
];
|
|
169
118
|
}
|
|
170
119
|
/**
|
|
171
|
-
* Picks the runner snapshot a run starts from, once the credential names its team and project
|
|
172
|
-
* them
|
|
173
|
-
*
|
|
174
|
-
* an ancestor of is the fewest commits behind; on separate lines of a merged history, the one with the least left to
|
|
175
|
-
* install and build wins. Identities make the answer unique: a team and project have one base snapshot at the
|
|
176
|
-
* merge-base, and one dev snapshot of this checkout per commit. `undefined` when none is for them.
|
|
120
|
+
* Picks the runner snapshot a run starts from, once the credential names its team and project: the candidate for
|
|
121
|
+
* them. Every candidate has the run's merge-base and snapshot key, and identities make the answer unique: a team and
|
|
122
|
+
* project have one entry per recipe, key and base. `undefined` when none is for them.
|
|
177
123
|
*/
|
|
178
124
|
export function pickSnapshot(candidates, owner) {
|
|
179
|
-
return candidates
|
|
180
|
-
.filter(({ entry }) => entry.teamId === owner.teamId && entry.projectId === owner.projectId)
|
|
181
|
-
.toSorted((a, b) => a.builtBehind - b.builtBehind || Number(isDevEntry(b.entry)) - Number(isDevEntry(a.entry)))[0];
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Removes every cached dev snapshot entry built on the base snapshot `replaced` names: of its team and project, its
|
|
185
|
-
* recipe's region, runtime and name, its snapshot key and its base, from any checkout, since each started from that
|
|
186
|
-
* base snapshot or from a dev snapshot built on it, and holds its toolchains. `storm snapshots build --full` calls it
|
|
187
|
-
* once its new base snapshot replaced that one, so no run starts from the old toolchains. The snapshots themselves are
|
|
188
|
-
* left to expire. A failure is reported, never a refusal.
|
|
189
|
-
*/
|
|
190
|
-
export async function dropDevSnapshotsOn(context, replaced) {
|
|
191
|
-
const { runnerSnapshots } = context;
|
|
192
|
-
const listed = await runnerSnapshots.listEntries();
|
|
193
|
-
if (!listed.ok)
|
|
194
|
-
return { snapshotIds: [], failures: [{ message: cacheFailureText(listed.failure) }] };
|
|
195
|
-
const snapshotIds = [];
|
|
196
|
-
const failures = [];
|
|
197
|
-
for (const entry of listed.value.entries) {
|
|
198
|
-
if (!isDevEntry(entry) ||
|
|
199
|
-
entry.teamId !== replaced.teamId ||
|
|
200
|
-
entry.projectId !== replaced.projectId ||
|
|
201
|
-
entry.region !== replaced.region ||
|
|
202
|
-
entry.runtime !== replaced.runtime ||
|
|
203
|
-
entry.recipeName !== replaced.recipeName ||
|
|
204
|
-
entry.snapshotKey !== replaced.snapshotKey ||
|
|
205
|
-
entry.base !== replaced.base)
|
|
206
|
-
continue;
|
|
207
|
-
const removed = await runnerSnapshots.removeEntry(entry);
|
|
208
|
-
if (removed.ok)
|
|
209
|
-
snapshotIds.push(entry.snapshotId);
|
|
210
|
-
else
|
|
211
|
-
failures.push({ message: cacheFailureText(removed.failure) });
|
|
212
|
-
}
|
|
213
|
-
return { snapshotIds, failures };
|
|
214
|
-
}
|
|
215
|
-
/** A cache failure in words: the path it failed on and what the OS said. */
|
|
216
|
-
function cacheFailureText(failure) {
|
|
217
|
-
return `${failure.path}: ${failure.message}`;
|
|
125
|
+
return candidates.find(({ entry }) => entry.teamId === owner.teamId && entry.projectId === owner.projectId);
|
|
218
126
|
}
|
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
import type { CheckoutFailure, CheckoutHead, RunnerSnapshotEntry, UnreadableSnapshotEntry } from "./gateways.ts";
|
|
2
|
-
import {
|
|
2
|
+
import type { CheckedRecipe } from "./recipe.ts";
|
|
3
3
|
import { type SnapshotCacheContext, type SnapshotRejectionReason } from "./snapshot-cache.ts";
|
|
4
4
|
/**
|
|
5
|
-
* One cached runner snapshot, as a checkout sees it:
|
|
6
|
-
*
|
|
7
|
-
* (`
|
|
8
|
-
*
|
|
9
|
-
*
|
|
5
|
+
* One cached runner snapshot, as a checkout sees it: from the checkout's Git history, whether HEAD is its base or
|
|
6
|
+
* holds it (`inHistory`), which an amend or a rebase can change, and how many commits HEAD has that its base lacks
|
|
7
|
+
* (`builtBehind`). `inHistory` is null when storm didn't check it: outside a Git checkout, or without a recipe or a
|
|
8
|
+
* base; `builtBehind` is null then too, and when the base isn't in HEAD's history. `picked` says a run here starts
|
|
9
|
+
* from it, for its team and project.
|
|
10
10
|
* `reason` says why a run here doesn't (`SnapshotRejectionReason`), `other-recipe` for another recipe's, or null for
|
|
11
11
|
* a picked one and when storm checked nothing.
|
|
12
12
|
*/
|
|
13
13
|
export interface InspectedSnapshot {
|
|
14
14
|
readonly entry: RunnerSnapshotEntry;
|
|
15
|
-
readonly kind: "base" | "dev";
|
|
16
|
-
readonly builtAt: string;
|
|
17
15
|
readonly inHistory: boolean | null;
|
|
18
16
|
readonly builtBehind: number | null;
|
|
19
|
-
/** For a dev snapshot, whether this checkout saved it; null for a base snapshot, and outside a Git checkout. */
|
|
20
|
-
readonly savedHere: boolean | null;
|
|
21
17
|
readonly expired: boolean;
|
|
22
18
|
readonly picked: boolean;
|
|
23
19
|
readonly reason: SnapshotRejectionReason | "other-recipe" | null;
|
|
@@ -75,9 +71,9 @@ export type SnapshotCacheInspectionOutcome = {
|
|
|
75
71
|
/**
|
|
76
72
|
* Inspects the cache from `cwd` for `recipe`, the runner recipe that applies there, if any. With a recipe, in a Git
|
|
77
73
|
* checkout whose HEAD shares history with one of its base refs, it marks for each team and project the snapshot a run
|
|
78
|
-
* here starts from, by a run's own rule (`classifySnapshotEntries`, `
|
|
79
|
-
*
|
|
80
|
-
*
|
|
74
|
+
* here starts from, by a run's own rule (`classifySnapshotEntries`, `pickSnapshot`), and gives each other
|
|
75
|
+
* snapshot of the recipe the reason it isn't picked. It runs the recipe's snapshot steps at the merge-base for the
|
|
76
|
+
* run's snapshot key, as a run does. Otherwise it picks none and
|
|
81
77
|
* says why. `all` adds the snapshots of other recipes, and of the recipe's other regions and runtimes, as
|
|
82
78
|
* `other-recipe`. It lists the cache once and classifies that listing, which removes no file, so an expired entry of
|
|
83
79
|
* the recipe stays and is `expired`. A git failure ends it with `checkout-failed`, as it ends a run.
|
|
@@ -2,16 +2,14 @@
|
|
|
2
2
|
// commits, and for the checkout's recipe which one a run here starts from and why not from each other one. It reads
|
|
3
3
|
// the cache and Git, and changes nothing: no file is removed, nothing is minted, and no sandbox starts.
|
|
4
4
|
import { resolveBase } from "./base.js";
|
|
5
|
-
import {
|
|
6
|
-
import { builtAtCommit, classifySnapshotEntries, isDevEntry, isExpiredEntry, } from "./snapshot-cache.js";
|
|
5
|
+
import { classifySnapshotEntries, isExpiredEntry, pickSnapshot, } from "./snapshot-cache.js";
|
|
7
6
|
import { snapshotStepsAt } from "./snapshot-key.js";
|
|
8
|
-
import { chooseSnapshotStart } from "./snapshot-start.js";
|
|
9
7
|
/**
|
|
10
8
|
* Inspects the cache from `cwd` for `recipe`, the runner recipe that applies there, if any. With a recipe, in a Git
|
|
11
9
|
* checkout whose HEAD shares history with one of its base refs, it marks for each team and project the snapshot a run
|
|
12
|
-
* here starts from, by a run's own rule (`classifySnapshotEntries`, `
|
|
13
|
-
*
|
|
14
|
-
*
|
|
10
|
+
* here starts from, by a run's own rule (`classifySnapshotEntries`, `pickSnapshot`), and gives each other
|
|
11
|
+
* snapshot of the recipe the reason it isn't picked. It runs the recipe's snapshot steps at the merge-base for the
|
|
12
|
+
* run's snapshot key, as a run does. Otherwise it picks none and
|
|
15
13
|
* says why. `all` adds the snapshots of other recipes, and of the recipe's other regions and runtimes, as
|
|
16
14
|
* `other-recipe`. It lists the cache once and classifies that listing, which removes no file, so an expired entry of
|
|
17
15
|
* the recipe stays and is `expired`. A git failure ends it with `checkout-failed`, as it ends a run.
|
|
@@ -39,13 +37,12 @@ export async function inspectSnapshotCache(context, request) {
|
|
|
39
37
|
directory,
|
|
40
38
|
checkout: null,
|
|
41
39
|
picking: { kind: "none", why: "no-checkout" },
|
|
42
|
-
snapshots: shown.map((entry) => unchecked(entry, now
|
|
40
|
+
snapshots: shown.map((entry) => unchecked(entry, now)),
|
|
43
41
|
unreadable,
|
|
44
42
|
},
|
|
45
43
|
};
|
|
46
44
|
}
|
|
47
45
|
const repoRoot = root.value;
|
|
48
|
-
const savedHere = (entry) => (isDevEntry(entry) ? entry.repoRoot === repoRoot : null);
|
|
49
46
|
const resolved = recipe === undefined ? undefined : await resolveBase(checkout, { repoRoot, baseRefs: recipe.baseRefs });
|
|
50
47
|
if (resolved?.kind === "failed")
|
|
51
48
|
return { kind: "checkout-failed", failure: resolved.failure };
|
|
@@ -56,7 +53,7 @@ export async function inspectSnapshotCache(context, request) {
|
|
|
56
53
|
directory,
|
|
57
54
|
checkout: { repoRoot, head: head.value, mergeBase: null },
|
|
58
55
|
picking: { kind: "none", why: recipe === undefined ? "no-recipe" : "no-base" },
|
|
59
|
-
snapshots: shown.map((entry) => unchecked(entry, now
|
|
56
|
+
snapshots: shown.map((entry) => unchecked(entry, now)),
|
|
60
57
|
unreadable,
|
|
61
58
|
},
|
|
62
59
|
};
|
|
@@ -69,78 +66,48 @@ export async function inspectSnapshotCache(context, request) {
|
|
|
69
66
|
if (!afterBase.ok)
|
|
70
67
|
return { kind: "checkout-failed", failure: afterBase.failure };
|
|
71
68
|
// The one listing above is classified as a run would, but nothing is removed: an expired entry is `expired`.
|
|
72
|
-
const
|
|
69
|
+
const read = classifySnapshotEntries(context, {
|
|
73
70
|
entries,
|
|
74
|
-
repoRoot,
|
|
75
71
|
recipe,
|
|
76
72
|
base: mergeBase,
|
|
77
73
|
snapshotKey: steps.key,
|
|
78
74
|
commitsAfterBase: afterBase.value,
|
|
79
|
-
devSnapshots: devSnapshotReuse(recipe, recipe.reuseDevSnapshot),
|
|
80
75
|
});
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const read = classified.value;
|
|
84
|
-
// The choice is per team and project, since the credential that names them isn't minted here. A candidate a run
|
|
85
|
-
// doesn't start from is `not-picked`, and every entry that isn't a candidate keeps the classification's reason,
|
|
86
|
-
// since it is ruled out whoever the run's credential names.
|
|
76
|
+
// The choice is per team and project, since the credential that names them isn't minted here. Every entry that isn't
|
|
77
|
+
// a candidate keeps the classification's reason, since it is ruled out whoever the run's credential names.
|
|
87
78
|
const owners = new Map(read.candidates.map(({ entry }) => [`${entry.teamId}\0${entry.projectId}`, entry]));
|
|
88
79
|
const picked = new Set();
|
|
89
80
|
for (const owner of owners.values()) {
|
|
90
|
-
const
|
|
91
|
-
if (
|
|
92
|
-
picked.add(
|
|
81
|
+
const pick = pickSnapshot(read.candidates, owner);
|
|
82
|
+
if (pick !== undefined)
|
|
83
|
+
picked.add(pick);
|
|
93
84
|
}
|
|
94
|
-
|
|
95
|
-
const inHistory = new Map();
|
|
96
|
-
const behind = new Map();
|
|
85
|
+
const place = historyPlacer(context, { repoRoot, mergeBase, commitsAfterBase: afterBase.value });
|
|
97
86
|
const snapshots = [];
|
|
98
87
|
for (const verdict of read.verdicts) {
|
|
99
88
|
const { entry } = verdict;
|
|
100
89
|
if (!shows(entry))
|
|
101
90
|
continue;
|
|
102
|
-
const builtAt = builtAtCommit(entry);
|
|
103
|
-
const kind = isDevEntry(entry) ? "dev" : "base";
|
|
104
91
|
const expired = isExpiredEntry(entry, now);
|
|
105
92
|
if (verdict.kind === "candidate") {
|
|
106
93
|
const { candidate } = verdict;
|
|
107
|
-
const isPicked = picked.has(candidate);
|
|
108
94
|
snapshots.push({
|
|
109
95
|
entry,
|
|
110
|
-
kind,
|
|
111
|
-
builtAt,
|
|
112
96
|
inHistory: true,
|
|
113
97
|
builtBehind: candidate.builtBehind,
|
|
114
|
-
savedHere: savedHere(entry),
|
|
115
98
|
expired,
|
|
116
|
-
picked:
|
|
117
|
-
reason:
|
|
99
|
+
picked: picked.has(candidate),
|
|
100
|
+
reason: null,
|
|
118
101
|
});
|
|
119
102
|
continue;
|
|
120
103
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
return { kind: "checkout-failed", failure: asked.failure };
|
|
126
|
-
contained = asked.value;
|
|
127
|
-
inHistory.set(builtAt, contained);
|
|
128
|
-
}
|
|
129
|
-
let builtBehind = contained ? behind.get(builtAt) : undefined;
|
|
130
|
-
if (contained && builtBehind === undefined) {
|
|
131
|
-
const counted = await checkout.commitCount({ repoRoot, from: builtAt, to: "HEAD" });
|
|
132
|
-
if (!counted.ok)
|
|
133
|
-
return { kind: "checkout-failed", failure: counted.failure };
|
|
134
|
-
builtBehind = counted.value;
|
|
135
|
-
behind.set(builtAt, builtBehind);
|
|
136
|
-
}
|
|
104
|
+
// Where a snapshot no run here starts from sits in HEAD's history, for the list only.
|
|
105
|
+
const placed = await place(entry.base);
|
|
106
|
+
if (!placed.ok)
|
|
107
|
+
return { kind: "checkout-failed", failure: placed.failure };
|
|
137
108
|
snapshots.push({
|
|
138
109
|
entry,
|
|
139
|
-
|
|
140
|
-
builtAt,
|
|
141
|
-
inHistory: contained,
|
|
142
|
-
builtBehind: builtBehind ?? null,
|
|
143
|
-
savedHere: savedHere(entry),
|
|
110
|
+
...placed.value,
|
|
144
111
|
expired,
|
|
145
112
|
picked: false,
|
|
146
113
|
reason: verdict.kind === "rejected" ? verdict.rejection.reason : "other-recipe",
|
|
@@ -158,16 +125,40 @@ export async function inspectSnapshotCache(context, request) {
|
|
|
158
125
|
};
|
|
159
126
|
}
|
|
160
127
|
/** An entry storm checked nothing of: outside a Git checkout, or with no recipe or no base to pick for. */
|
|
161
|
-
function unchecked(entry, now
|
|
128
|
+
function unchecked(entry, now) {
|
|
162
129
|
return {
|
|
163
130
|
entry,
|
|
164
|
-
kind: isDevEntry(entry) ? "dev" : "base",
|
|
165
|
-
builtAt: builtAtCommit(entry),
|
|
166
131
|
inHistory: null,
|
|
167
132
|
builtBehind: null,
|
|
168
|
-
savedHere,
|
|
169
133
|
expired: isExpiredEntry(entry, now),
|
|
170
134
|
picked: false,
|
|
171
135
|
reason: null,
|
|
172
136
|
};
|
|
173
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* Where a base sits in HEAD's history, for the list: whether HEAD is it or holds it, and if so how many commits HEAD
|
|
140
|
+
* has that it lacks. Git is asked at most once per base, and nothing for the merge-base, whose count the caller has.
|
|
141
|
+
*/
|
|
142
|
+
function historyPlacer(context, request) {
|
|
143
|
+
const { repoRoot } = request;
|
|
144
|
+
const known = new Map([
|
|
145
|
+
[request.mergeBase, { inHistory: true, builtBehind: request.commitsAfterBase }],
|
|
146
|
+
]);
|
|
147
|
+
return async (base) => {
|
|
148
|
+
const answer = known.get(base);
|
|
149
|
+
if (answer !== undefined)
|
|
150
|
+
return { ok: true, value: answer };
|
|
151
|
+
const contained = await context.checkout.contains({ repoRoot, ancestor: base, descendant: "HEAD" });
|
|
152
|
+
if (!contained.ok)
|
|
153
|
+
return contained;
|
|
154
|
+
let placed = { inHistory: false, builtBehind: null };
|
|
155
|
+
if (contained.value) {
|
|
156
|
+
const counted = await context.checkout.commitCount({ repoRoot, from: base, to: "HEAD" });
|
|
157
|
+
if (!counted.ok)
|
|
158
|
+
return counted;
|
|
159
|
+
placed = { inHistory: true, builtBehind: counted.value };
|
|
160
|
+
}
|
|
161
|
+
known.set(base, placed);
|
|
162
|
+
return { ok: true, value: placed };
|
|
163
|
+
};
|
|
164
|
+
}
|
|
@@ -3,9 +3,9 @@ import { type CheckedRecipe, type ResolvedRunnerStep, type RunnerStep } from "./
|
|
|
3
3
|
/**
|
|
4
4
|
* Bump when a runner snapshot changes in a way its steps' text doesn't show (the scripts between the steps, what is
|
|
5
5
|
* uploaded, the build sandbox), or the key's encoding changes, so earlier snapshots stop matching. 2 added each step's
|
|
6
|
-
* runner secret names.
|
|
6
|
+
* runner secret names. 3 dropped dev snapshots.
|
|
7
7
|
*/
|
|
8
|
-
export declare const SNAPSHOT_FORMAT =
|
|
8
|
+
export declare const SNAPSHOT_FORMAT = 3;
|
|
9
9
|
/** Where the repository lives in every runner and build sandbox. */
|
|
10
10
|
export declare const SANDBOX_ROOT = "/vercel/sandbox";
|
|
11
11
|
/** The names of the files uploaded to a sandbox's staging directory. */
|
|
@@ -16,14 +16,8 @@ export declare const STAGED_FILES: {
|
|
|
16
16
|
readonly untrackedTarball: "untracked.tgz";
|
|
17
17
|
readonly untrackedFileList: "untracked-files";
|
|
18
18
|
};
|
|
19
|
-
/**
|
|
20
|
-
|
|
21
|
-
* commit isn't in a sandbox's repository. Then removes untracked files and directories, nested Git repositories
|
|
22
|
-
* included, keeping ignored ones such as `node_modules` and build outputs.
|
|
23
|
-
*/
|
|
24
|
-
export declare const RESET_TO_BASE: readonly string[];
|
|
25
|
-
/** A bash script that stops at the first failure and runs in the repository's root. */
|
|
26
|
-
export declare function bashScript(lines: readonly string[]): string;
|
|
19
|
+
/** A bash script that stops at the first failure and runs in the repository's root, `/vercel/sandbox` by default. */
|
|
20
|
+
export declare function bashScript(lines: readonly string[], root?: string): string;
|
|
27
21
|
/**
|
|
28
22
|
* Extracts the base's files from `<staging>/base.tgz` and commits exactly its tracked files
|
|
29
23
|
* (`<staging>/base-files`), before the prebuild steps. `git add -A` would drop tracked files `.gitignore` matches.
|
|
@@ -31,11 +25,12 @@ export declare function bashScript(lines: readonly string[]): string;
|
|
|
31
25
|
export declare function baseIndexScript(base: string, staging: string): string;
|
|
32
26
|
/**
|
|
33
27
|
* Applies and commits a run's patch and untracked files, uploaded to `staging`, in a runner sandbox. It first resets
|
|
34
|
-
* the repository to its root commit, the base's tracked files,
|
|
35
|
-
*
|
|
36
|
-
*
|
|
28
|
+
* the repository to its root commit, which holds the base's tracked files (`baseIndexScript`), since the real base
|
|
29
|
+
* commit isn't in a sandbox's repository, and removes untracked files and nested Git repositories `.gitignore`
|
|
30
|
+
* doesn't match, keeping ignored ones such as `node_modules` and build outputs. `root` is the repository, which an
|
|
31
|
+
* integration test points at a temporary checkout.
|
|
37
32
|
*/
|
|
38
|
-
export declare function applyScript(staging: string): string;
|
|
33
|
+
export declare function applyScript(staging: string, root?: string): string;
|
|
39
34
|
/**
|
|
40
35
|
* The snapshot key: sha256 hex over `format=<SNAPSHOT_FORMAT>`, each toolchain step's label, script and
|
|
41
36
|
* `secrets=<its runner secret names, sorted, joined with ",">`, the base-index script with the placeholders `<base>`
|
|
@@ -7,9 +7,9 @@ import { resolveSteps } from "./recipe.js";
|
|
|
7
7
|
/**
|
|
8
8
|
* Bump when a runner snapshot changes in a way its steps' text doesn't show (the scripts between the steps, what is
|
|
9
9
|
* uploaded, the build sandbox), or the key's encoding changes, so earlier snapshots stop matching. 2 added each step's
|
|
10
|
-
* runner secret names.
|
|
10
|
+
* runner secret names. 3 dropped dev snapshots.
|
|
11
11
|
*/
|
|
12
|
-
export const SNAPSHOT_FORMAT =
|
|
12
|
+
export const SNAPSHOT_FORMAT = 3;
|
|
13
13
|
/** Where the repository lives in every runner and build sandbox. */
|
|
14
14
|
export const SANDBOX_ROOT = "/vercel/sandbox";
|
|
15
15
|
/** The names of the files uploaded to a sandbox's staging directory. */
|
|
@@ -22,19 +22,9 @@ export const STAGED_FILES = {
|
|
|
22
22
|
};
|
|
23
23
|
/** The identity of the commits the scripts make, with no hook or signing in the way. */
|
|
24
24
|
const GIT_IDENTITY = "-c user.email=storm-runner@vercel.invalid -c user.name='storm runner' -c commit.gpgsign=false";
|
|
25
|
-
/**
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
* included, keeping ignored ones such as `node_modules` and build outputs.
|
|
29
|
-
*/
|
|
30
|
-
export const RESET_TO_BASE = [
|
|
31
|
-
"root=$(git rev-list --max-parents=0 HEAD)",
|
|
32
|
-
'git reset -q --hard "$root"',
|
|
33
|
-
"git clean -ffdq",
|
|
34
|
-
];
|
|
35
|
-
/** A bash script that stops at the first failure and runs in the repository's root. */
|
|
36
|
-
export function bashScript(lines) {
|
|
37
|
-
return ["set -euo pipefail", `cd ${SANDBOX_ROOT}`, ...lines].join("\n");
|
|
25
|
+
/** A bash script that stops at the first failure and runs in the repository's root, `/vercel/sandbox` by default. */
|
|
26
|
+
export function bashScript(lines, root = SANDBOX_ROOT) {
|
|
27
|
+
return ["set -euo pipefail", `cd ${root}`, ...lines].join("\n");
|
|
38
28
|
}
|
|
39
29
|
/**
|
|
40
30
|
* Extracts the base's files from `<staging>/base.tgz` and commits exactly its tracked files
|
|
@@ -54,26 +44,29 @@ export function baseIndexScript(base, staging) {
|
|
|
54
44
|
}
|
|
55
45
|
/**
|
|
56
46
|
* Applies and commits a run's patch and untracked files, uploaded to `staging`, in a runner sandbox. It first resets
|
|
57
|
-
* the repository to its root commit, the base's tracked files,
|
|
58
|
-
*
|
|
59
|
-
*
|
|
47
|
+
* the repository to its root commit, which holds the base's tracked files (`baseIndexScript`), since the real base
|
|
48
|
+
* commit isn't in a sandbox's repository, and removes untracked files and nested Git repositories `.gitignore`
|
|
49
|
+
* doesn't match, keeping ignored ones such as `node_modules` and build outputs. `root` is the repository, which an
|
|
50
|
+
* integration test points at a temporary checkout.
|
|
60
51
|
*/
|
|
61
|
-
export function applyScript(staging) {
|
|
52
|
+
export function applyScript(staging, root = SANDBOX_ROOT) {
|
|
62
53
|
const patch = `${staging}/${STAGED_FILES.patch}`;
|
|
63
54
|
const tarball = `${staging}/${STAGED_FILES.untrackedTarball}`;
|
|
64
55
|
const fileList = `${staging}/${STAGED_FILES.untrackedFileList}`;
|
|
65
56
|
return bashScript([
|
|
66
|
-
|
|
57
|
+
"root=$(git rev-list --max-parents=0 HEAD)",
|
|
58
|
+
'git reset -q --hard "$root"',
|
|
59
|
+
"git clean -ffdq",
|
|
67
60
|
// A build may have rewritten tracked files with the same content.
|
|
68
61
|
"git update-index -q --refresh || true",
|
|
69
62
|
`if [ -s ${patch} ]; then git apply --index --binary ${patch}; fi`,
|
|
70
63
|
`if [ -s ${tarball} ]; then`,
|
|
71
|
-
` tar --warning=no-unknown-keyword -xzf ${tarball} -C ${
|
|
64
|
+
` tar --warning=no-unknown-keyword -xzf ${tarball} -C ${root}`,
|
|
72
65
|
` git --literal-pathspecs add -f --pathspec-from-file=${fileList} --pathspec-file-nul`,
|
|
73
66
|
"fi",
|
|
74
67
|
`git ${GIT_IDENTITY} commit -q --no-verify --allow-empty -m run`,
|
|
75
68
|
`rm -f ${patch} ${tarball} ${fileList}`,
|
|
76
|
-
]);
|
|
69
|
+
], root);
|
|
77
70
|
}
|
|
78
71
|
/**
|
|
79
72
|
* The snapshot key: sha256 hex over `format=<SNAPSHOT_FORMAT>`, each toolchain step's label, script and
|
package/package.json
CHANGED
|
@@ -49,25 +49,24 @@ In a sandboxed run, storm installs and builds before it runs the command.
|
|
|
49
49
|
|
|
50
50
|
## 6. Read why the setup was fast or slow
|
|
51
51
|
|
|
52
|
-
In a sandboxed run, the runner sandbox starts from a runner snapshot: a base snapshot, or a
|
|
52
|
+
In a sandboxed run, the runner sandbox starts from a runner snapshot: a base snapshot at the merge-base, or one at a commit on the branch that `storm snapshots build --base` built. The snapshot decides how much the run uploads, installs and builds.
|
|
53
53
|
|
|
54
54
|
1. Run `storm runs show <run-id> --json`. Read `where.snapshot`.
|
|
55
|
-
2. Read `
|
|
56
|
-
3. Read `builtBehind`: how many commits HEAD has after `
|
|
57
|
-
4. Read `where.uploadBytes`: how many bytes of changes the run uploaded on top of the snapshot's base
|
|
55
|
+
2. Read `base`: the commit the snapshot was built at.
|
|
56
|
+
3. Read `builtBehind`: how many commits HEAD has after `base`, the run's merge-base. A large number means more work for the install and build.
|
|
57
|
+
4. Read `where.uploadBytes`: how many bytes of changes the run uploaded on top of the snapshot's base. The run's merge-base is `where.base`.
|
|
58
58
|
5. Read `built`. If it is `true`, the run built a base snapshot first, which takes a few minutes.
|
|
59
|
-
6.
|
|
60
|
-
7. To
|
|
61
|
-
8. To build that snapshot before the next run, without a test run, run `storm snapshots build --json`. Read `outcome`: `built` or `up_to_date`.
|
|
59
|
+
6. To see which snapshot the next run here starts from, and why it does not start from each other one, run `storm snapshots list --json`. Read `snapshots`: the one with `picked` `true` is the snapshot, and `reason` says why each other one is not. When none has `picked` `true`, a run here builds a base snapshot at the merge-base. A snapshot with `reason` `other-base` has a base that is not the merge-base, so no run here starts from it: a run starts only from a snapshot at its merge-base.
|
|
60
|
+
7. To build a base snapshot before the next run, without a test run, run `storm snapshots build --json`. Read `outcome`: `built` or `up_to_date`.
|
|
62
61
|
|
|
63
62
|
A field is `null` when storm does not know it, such as in a run that an older storm recorded.
|
|
64
63
|
|
|
65
64
|
## 7. Run one test again in the runner sandbox
|
|
66
65
|
|
|
67
|
-
A sandboxed run can keep its runner sandbox running after it ends
|
|
66
|
+
A sandboxed run can keep its runner sandbox running after it ends, for the keep time.
|
|
68
67
|
|
|
69
68
|
1. Run `storm runs show <run-id> --json`.
|
|
70
|
-
2. Read `where.keptMinutesLeft`. If it is `null` or 0, the runner sandbox is not running. Start a new run with `storm vitest` or `storm exec`, and add `--keep-sandbox 30m`. With that flag, the run
|
|
69
|
+
2. Read `where.keptMinutesLeft`. If it is `null` or 0, the runner sandbox is not running. Start a new run with `storm vitest` or `storm exec`, and add `--keep-sandbox 30m`. With that flag, the run keeps its runner sandbox for 30 minutes.
|
|
71
70
|
3. Read `where.sandboxUrl`. Give a person the Connect page, `<sandboxUrl>/connect`. In it, a person can run one test again.
|
|
72
71
|
|
|
73
72
|
## 8. Read what a resource could not do
|